<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<?php
$sessiondata = \Config\Services::session();
$uri = service('uri');
$menuname = $uri->getSegment(3);
?>

<div class="container-fluid">
    <table style="width:50%; margin: 0 auto; border-collapse:collapse; font-family:Arial, sans-serif; font-size:14px;">
        <tr>
            <td colspan="6" style="text-align:center; font-size:18px; font-weight:bold; padding:4px 0;">Busvalley</td>
        </tr>
    </table>
    <table style="width:100%; margin: 0 auto; border-collapse:collapse; font-family:Arial, sans-serif; font-size:14px;">
        <td style="width:50%; vertical-align:top;">
            <table style="border-collapse:collapse; margin-bottom: 10px;margin-left:30px;width: 90%;">
                <tr>
                    <td colspan="3" style="text-align:center; border:1px solid #999; padding:2px 5px;">
                        <strong><?php echo lang("Localize.company").lang("Localize.name"). " : " ?></strong> <?= $pretrip[0]->company_name ?? '' ?>
                    </td>
                </tr>
                <tr>
                    <td colspan="3" style="text-align:center; border:1px solid #999; padding:2px 5px;">
                        <strong><?php echo lang("Localize.pre-trip");?>:</strong> <?= $pretrip[0]->pretrip_id ?? '' ?>
                    </td>
                </tr>
            </table>
        </td>
        <td style="width:50%; vertical-align:top;">
            <table style="border-collapse:collapse; margin-bottom:10px;margin-left:auto;margin-right:20px;width:90%;">
                <tr>
                    <td colspan="2" style="text-align:center; border:1px solid #999; padding:2px 5px;">
                        <strong>Bus plate no </strong>
                    </td>
                    <td colspan="2" style="text-align:center; border:1px solid #999; padding:2px 5px;">
                        <strong>Bus Number </strong>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" style="text-align:center; border:1px solid #999; padding:2px 5px;height:25px;">
                        <?= $pretrip[0]->reg_no ?? '' ?>
                    </td>
                    <td colspan="2" style="text-align:center; border:1px solid #999; padding:2px 5px;">
                        <?php echo "000". $pretrip[0]->bus_plate_no ?? '' ?>
                    </td>
                </tr>
            </table>
        </td>
    </table>

    <table style="width:100%; border-collapse:collapse; margin-top:20px;">
        <tr>
            <td style="width:50%; vertical-align: top;">
                <table style="width:95%; margin: 0 auto; border-collapse:collapse; font-family:Arial, sans-serif; font-size:14px;">
                    <?php //print_r($pretrip);?>
                    <tr>
                        <td colspan="2" style="padding:6px 10px; border:1px solid #999;"><strong>From: pickup point </strong></td>
                        <td style="padding:6px 10px; border:1px solid #999;">
                            
                            <?= $pretrip[0]->pic_location_name ??"" ?>        
                        </td>
                        <td colspan="2" style="padding:6px 10px; border:1px solid #999;"><strong>To: drop point </strong></td>
                        <td style="padding:6px 10px; border:1px solid #999;">
                            
                            <?= $pretrip[0]->drop_location_name ??"" ?>        
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" style="padding:6px 10px; border:1px solid #999;"><strong>Boarding point </strong></td>
                        <td style="padding:6px 10px; border:1px solid #999;"><?= $pretrip[0]->boarding ??"" ?></td>
                        <td colspan="2" style="padding:6px 10px; border:1px solid #999;"><strong>Dropping Point</strong></td>
                        <td style="padding:6px 10px; border:1px solid #999;"><?= $pretrip[0]->dropping ??"" ?></td>
                    </tr>
                    <tr>
                        <td colspan="2" style="padding:6px 10px; border:1px solid #999;"><strong>Driver Name </strong></td>
                        <td style="padding:6px 10px; border:1px solid #999;"><?= $pretrip[0]->driverName ??"" ?></td>
                        <td colspan="2" style="padding:6px 10px; border:1px solid #999;"><strong>Mobile </strong></td>
                        <td style="padding:6px 10px; border:1px solid #999;"><?= $pretrip[0]->driverphone ??"" ?></td>
                    </tr>
                    <tr>
                        <td colspan="2" style="padding:6px 10px; border:1px solid #999;"><strong>Assistant Name </strong></td>
                        <td style="padding:6px 10px; border:1px solid #999;"><?= $pretrip[0]->assistanceName ??"" ?></td>
                        <td colspan="2" style="padding:6px 10px; border:1px solid #999;"><strong>Mobile </strong></td>
                        <td style="padding:6px 10px; border:1px solid #999;"><?= $pretrip[0]->assistancephone ??"" ?></td>
                    </tr>
                </table>
            </td>
            <td style="width:50%; vertical-align: top;">
                <table style="width:95%; margin: 0 auto; border-collapse:collapse; font-family:Arial, sans-serif; font-size:14px;">
                    <tr>
                        <td colspan="2" style="padding:6px 10px; border:1px solid #999;"><strong>Trip ID</strong></td>
                        <td style="padding:6px 10px; border:1px solid #999;"><strong> Date </strong> </td>
                        <td style="padding:6px 10px; border:1px solid #999;"><strong> Time </strong> </td>
                    </tr>
                    <tr>
                        <td colspan="2" style="padding:6px 10px; border:1px solid #999;"><?php echo $pretrip[0]->trip_id??""; ?></td>
                        <td style="padding:6px 10px; border:1px solid #999;"><?= date('Y-m-d', strtotime($pretrip[0]->pretrip_created_at ?? '')) ?></td>
                        <td style="padding:6px 10px; border:1px solid #999;"><?= date('g:i A', strtotime($pretrip[0]->start_time ?? '')) ?></td>
                    </tr>
                    <tr>
                        <td colspan="4" style="height: 20px;"></td> 
                    </tr>
                    <tr>
                        <td style="padding:6px 10px; border:1px solid #999;"><strong>Bus Start Mater</strong></td>
                        <td colspan="3" style="padding:6px 10px; border:1px solid #999;"><?= $pretrip[0]->bus_meter ?? '' ?></td>
                    </tr>
                    <tr>
                        <td style="padding:6px 10px; border:1px solid #999;"><strong>Bus End Mater</strong></td>
                        <td colspan="3" style="padding:6px 10px; border:1px solid #999;"></td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>


    <table style="width:100%; border-collapse:collapse; font-family:Arial, sans-serif; font-size:14px; margin-top:20px; border:1px solid #999;">
        <tr>
            <td colspan="18" style="padding:6px 10px; border:1px solid #999;"><strong>All Points</strong></td>
        </tr>
        <tr>
            <?php
            $points = isset($pretrip[0]->dropLocations) ? explode(',', $pretrip[0]->dropLocations) : ['A', 'B', 'C', 'D', 'E'];
            // print_r(count($points));
            foreach ($points as $point) {
                echo '<td style="padding:6px 10px; text-align:center; border:1px solid #999;">' . trim($point) . '</td>';
            }
            $remaining = 2 - count($points);
            // print_r($remaining);
            for ($i = 0; $i < $remaining; $i++) {
                echo '<td style="padding:6px 10px; border:1px solid #999;"></td>';
            }
            ?>
        </tr>
    </table>
    <table style="width:100%; border-collapse:collapse; font-family:Arial, sans-serif; font-size:14px; margin-top:20px; border:1px solid #999;">
        <tr>
            <td colspan="6" style="padding:6px 10px; border:1px solid #999;"><strong><?php echo lang("Localize.note"). " : " ?></strong></td>
        </tr>
        <tr>
            <td colspan="6" style="padding:6px 10px; border:1px solid #999;">
                <?= $pretrip[0]->notes ?? '' ?>
            </td>
        </tr>
    </table>
    <table style="width:100%; border-collapse:collapse; font-family:Arial, sans-serif; font-size:14px; margin-top:20px; border:1px solid #999;">
        <tr>
            <td colspan="2" style="padding:6px 10px; border:1px solid #999;"><strong>By: </strong></td>
            <td colspan="2" style="padding:6px 10px; border:1px solid #999;">
                <?= $pretrip[0]->createdBy ?? '' ?>
                <?= $pretrip[0]->booker_id ? ' (Agent)' : (($pretrip[0]->booker_agents_emp_id && $pretrip[0]->booker_agents_emp_role !=1) ? ' (Employee- '.$pretrip[0]->role_name.')' : ' (Admin)') ?>
            </td>
            <td colspan="2" style="padding:6px 10px; border:1px solid #999;"><?= $pretrip[0]->pretrip_updated_at ?? '' ?></td>
        </tr>
    </table>

    <table style="width:100%; border-collapse:collapse; font-family:Arial, sans-serif; font-size:14px; margin-top:20px; border:1px solid #999;">
        <tr style="background-color:#e0e0e0;">
            <th style="padding:6px 10px; border:1px solid #999;"></th>
            <th style="padding:6px 10px; border:1px solid #999;">Name</th>
            <th style="padding:6px 10px; border:1px solid #999;">Date</th>
            <th colspan="3" style="padding:6px 10px; border:1px solid #999;">Signature</th>
        </tr>
        <tr>
            <td style="padding:6px 10px; border:1px solid #999;">Driver</td>
            <td style="padding:6px 10px; border:1px solid #999;"><?= $pretrip[0]->driverName ?? '' ?></td>
            <td style="padding:6px 10px; border:1px solid #999;"><?= date('Y-m-d', strtotime($pretrip[0]->start_time ?? '')) ?></td>
            <td colspan="3" style="padding:6px 10px; border:1px solid #999;"></td>
        </tr>
        <tr>
            <td style="padding:6px 10px; border:1px solid #999;">Assist</td>
            <td style="padding:6px 10px; border:1px solid #999;"><?= $pretrip[0]->assistanceName ?? '' ?></td>
            <td style="padding:6px 10px; border:1px solid #999;"></td>
            <td colspan="3" style="padding:6px 10px; border:1px solid #999;"></td>
        </tr>
        <tr>
            <td style="padding:6px 10px; border:1px solid #999;">Issue By</td>
            <td style="padding:6px 10px; border:1px solid #999;"><?= $pretrip[0]->createdBy ?? '' ?></td>
            <td style="padding:6px 10px; border:1px solid #999;"><?= date('Y-m-d', strtotime($pretrip[0]->start_time ?? '')) ?></td>
            <td colspan="3" style="padding:6px 10px; border:1px solid #999;"></td>
        </tr>
        <tr>
            <td style="padding:6px 10px; border:1px solid #999;">Operation</td>
            <td style="padding:6px 10px; border:1px solid #999;"></td>
            <td style="padding:6px 10px; border:1px solid #999;"></td>
            <td colspan="3" style="padding:6px 10px; border:1px solid #999;"></td>
        </tr>
    </table>
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>

<script type="text/javascript">
    $(document).ready(function () {
        window.print();
    });
</script>
</html>
