<!DOCTYPE html>
<html>

    <head>
        <title>Daily Schedule</title>
    </head>

    <body>
        <div class="heading">
            <div class="logo col-6">
                <img src="images/pdf/logo.png">
            </div>
            <div class="companay_name col-6 text-right">
                <?php
                $model_Company = MasCompany::model()->find();
                ?>

                <h3><?php echo $model_Company->company_name; ?></h3>
                <p><?php echo $model_Company->company_address; ?>
                    <?php echo ', ' . $model_Company->company_location; ?>
                    <?php echo ', ' . $model_Company->country->country_name; ?></p>
                <p><?php echo 'Phone : ' . $model_Company->company_phone_no; ?></p>
                <p><?php echo 'Email : ' . $model_Company->company_email_id; ?></p>
            </div>
        </div>
        <div class="clearfix"></div>
        <div class="title">
            <div class="col-6">
                <div style="height: 10px;"></div>
            </div>
            <div class="col-6 text-right">
                <h1>DAILY SCHEDULE</h1>
                <div class="details-box">
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
        <?php
        $modelTeamLeader = User::model()->find(array('condition' => 'id = "' . $team_member_id . '"'));
        ?>

        <div class="table-body">
            <div class="row">
                <div class="col-md-6 text-right" style="padding-right: 20px;"><b>Team Leader : <?php echo $modelTeamLeader->first_name . ' ' . $modelTeamLeader->last_name; ?><br>
                        Date : <?php echo $date; ?></b></div>
            </div>
            <table id="tbl_enquiry_table" class="table table-fixed table-primary dataTable">
                <thead>
                    <tr>
                        <th>No</th>
                        <th>Job No /  File No</th>
                        <th>Customer Name</th>
                        <th> Complaint </th>
                        <th> Description </th>
                        <th> Schedule </th>

                    </tr>
                </thead>
                <tbody>
                    <?php
                    $condition = '1=1';
                    if ($team_member_id != '')
                        $condition .= ' AND t.team_member_id ="' . $team_member_id . '"';

                    if ($date != '') {
                        $date = str_replace('/', '-', $date);
                        $date = date('Y-m-d', strtotime($date));
                        $condition .= ' AND t.allocated_date ="' . $date . '"';
                    }
                    $modelAllocate = RegistrationMemberAllocate::model()->with('customer')->findAll(array('condition' => $condition));
                    if (empty($modelAllocate)) {
                        ?>
                        <tr><td colspan="6" class="text-center">No date Available</td></tr>
                        <?php
                    }
                    foreach ($modelAllocate as $i => $model) {
                        if (!empty($model->time_slot)) {
                            ?>

                            <tr>
                                <td><?php echo $i + 1; ?></td>
                                <td><?php echo $model->file_id; ?></td>
                                <td><?php echo $model->customer->customer_name; ?></td>
                                <td><?php echo $model->complaint->problem; ?></td>
                                <td><?php echo $model->complaint->problem_description; ?></td>
                                <td>
                                    <?php
                                    $time_slot = trim($model->time_slot, '!');

                                    $explode_time_slot = explode('!', $time_slot);

                                    rsort($explode_time_slot);



                                    $explode_time_slot = mySort($explode_time_slot);
                                    $explode_time_slot = mySort($explode_time_slot);
                                    foreach ($explode_time_slot as $itm) {
                                        if ($itm != 'a-c') {
                                            echo '<br>' . $itm;
                                        }
                                    }
                                    ?></td>   
                            </tr>
                            <?php
                        }
                    }
                    ?>
                </tbody>
            </table>
        </div>

    <htmlpagefooter name="myfooter">
        <div style="border-top: 1px dotted #000000; font-size: 12px; text-align: center; padding-top: 10px; ">
            <div style="text-align:center;width:100%">This report is auto generated by Bluesky project on <?php
                date_default_timezone_set("Asia/Dubai");
                echo date('d/m/Y') . " " . date("h:i:sa");
                ?> </div>
            <div style="text-align:center;width:100%">Page {PAGENO} of {nb} </div>
        </div>
    </htmlpagefooter>
    <sethtmlpagefooter name="myfooter" page="all" value="on" />

</body>

</html>
<?php

function mySort($explode_time_slot) {
    $count = count($explode_time_slot);


    for ($i = 0; $i < $count; $i++) {
        $a = explode('-', $explode_time_slot[$i]);

        for ($k = 1; $k < $count; $k++) {
            $b = explode('-', $explode_time_slot[$k]);

            if (strcmp($a[0], $b[1]) == 0) {
                $explode_time_slot[$i] = $b[0] . '-' . $a[1];
                $a[0] = $b[0];
                $explode_time_slot[$k] = 'a-c';
            }
            if (strcmp($a[1], $b[0]) == 0) {
                $explode_time_slot[$i] = $a[0] . '-' . $b[1];
                $a[1] = $b[1];
                $explode_time_slot[$k] = 'a-c';
            }
        }
    }
    return $explode_time_slot;
}
?>