<?php
ob_start();
session_start();
include("inc/config.php");

$statement = $pdo->prepare("SELECT tbl_delivery_run_sheet.*,tbl_delivery_boy.address as delivery_boy_address,pickup_entry.invoice_no,(select sum(boxes) from pickup_entry where id in (tbl_delivery_run_sheet.shipment_ids)) as box,(select sum(a_weight) from pickup_entry where id in (tbl_delivery_run_sheet.shipment_ids)) as wt FROM `tbl_delivery_run_sheet` 
left join tbl_delivery_boy on tbl_delivery_boy.id=tbl_delivery_run_sheet.delivery_boy_id
LEFT JOIN pickup_entry ON FIND_IN_SET(pickup_entry.id,tbl_delivery_run_sheet.shipment_ids) > 0
where 1=1 and tbl_delivery_run_sheet.id=".$_GET['id']);
$statement->execute();
$query = $statement->fetchAll(PDO::FETCH_ASSOC);
$totalFiltered = $statement->rowCount();
?>


<table style="width:100%;border:none;">
    <tr>
        <td style="width:10%;text-align:left;border:none;">
            <img src="../assets/uploads/user-1.png">
            
        </td>
        <td style="width:90%;border:none;">
            <center style="font-weight:bolder;">Venus Cargo & Logistics Pvt Ltd</center>
            <center><b>REG OF</b> &nbsp;&nbsp;U 2069, Akshar Business Park, Plot No 3, Sector 25, Vashi, Nav</center>
            <center>Mumbai-400703</center><br>
            <center><b style="vertical-align:bottom;">Delivery Run Sheet</b></center>
        </td>
    </tr>
</table>

<table style="width:100%">
    <tr> 
        <td style="width:15%;vertical-align:top;"><b>D.Boy Name</b><br><b>Phone No.1</b><br><b>Area</b></td>
        <td style="width:30%;vertical-align:top;">:&nbsp; <?=$query[0]['delivery_boy_name']?><br>:&nbsp; <?=$query[0]['delivery_boy_mobile_no']?><br>: &nbsp; <?=$query[0]['delivery_boy_address']?></td>
        <td style="width:10%;vertical-align:top;"><b>Drs No</b><br><b>Drs Date</b><br><b>Branch</b></td>
        <td style="vertical-align:top;">:&nbsp; <?=$query[0]['drs_no']?><br>:&nbsp; <?=date('d-m-Y', strtotime($query[0]['date']));?><br> </td>
        <td style="width:12%;vertical-align:top;"><b>Vehicle No</b> </td>
        <td style="vertical-align:top;">:&nbsp; <?=$query[0]['vehicle_no']?>
        <td style="width:12%;vertical-align:top;"><b>Invoice No</b> </td>
        <td style="vertical-align:top;">:&nbsp; <?=$query[0]['invoice_no']?><br> </td>
   
    </tr>
</table>


<table style="width:100%;border-top:none;">
    <tr style="border-top:none;">
        <th style="border-top:none;">S.No</th>
        <th style="border-top:none;">Doc No</th>
        <th style="border-top:none;">Invoice No</th>        
        <th style="border-top:none;">Date</th>
        <th style="border-top:none;">Sender</th>
        <th style="border-top:none;">Consignee</th>
        <th style="border-top:none;">Dst</th>
        <th style="border-top:none;">Pcs</th>
        <th style="border-top:none;">Weight</th>
        <th style="border-top:none;">Receiver/Sign/Stamp</th>
    </tr>
    <?php 
    /*error_log("SELECT pickup_entry.*,tbl_client_new.name as new_client_name,tbl_client_new.phone_no as new_client_phone FROM `pickup_entry`
    left JOIN tbl_client_new ON pickup_entry.new_client_id=tbl_client_new.id where 1=1 and pickup_entry.id in (".$query[0]['shipment_ids'].")");*/
    
    $statements = $pdo->prepare("SELECT pickup_entry.*,tbl_client_new.name as new_client_name,tbl_client_new.phone_no as new_client_phone FROM `pickup_entry`
    left JOIN tbl_client_new ON pickup_entry.new_client_id=tbl_client_new.id where 1=1 and pickup_entry.id in (".$query[0]['shipment_ids'].")");
    
    $statements->execute();
    $querys = $statements->fetchAll(PDO::FETCH_ASSOC);
    $totalFiltered = $statements->rowCount();
    $i=1;
    $bo=0;$wt=0;
    foreach($querys as $data){
    ?>
    <tr style="border-top:none;">
        <td style="border-top:none;font-size:12px;"><?=$i?></td>
        <td style="border-top:none;font-size:12px;"><?=$data['cscs_awb']?></td>
        <td style="border-top:none;font-size:12px;"><?=$data['invoice_no']?></td>
        <td style="border-top:none;font-size:12px;width:10%;"><?=date('d-m-Y', strtotime($data['date_added']))?></td>
        <td style="border-top:none;font-size:12px;"><?=$data['new_client_name']?> - <?=$data['new_client_phone']?></td>
        <td style="border-top:none;font-size:12px;"><?=$data['consignee_name']?></td>
        <td style="border-top:none;font-size:12px;"><?=$data['consignee_city']?>  <?=$data['consignee_pincode']?></td>
        <td style="border-top:none;font-size:12px;"><?=$data['boxes']?></td>
        <td style="border-top:none;font-size:12px;"><?=$data['a_weight']?></td>
        <td style="border-top:none;font-size:12px;">&nbsp;</td>
    </tr>
    <?php $i++; $bo=$bo+$data['boxes'];$wt=$wt+$data['a_weight'];} ?>
     <tr style="border-top:none;">
        <td style="border-top:none;font-size:12px;"></td>
       <td style="border-top:none;font-size:12px;"></td>
       <td style="border-top:none;font-size:12px;"></td>
       <td style="border-top:none;font-size:12px;"></td>
       <td style="border-top:none;font-size:12px;"></td>
       <td style="border-top:none;font-size:12px;"></td>
        <td style="border-top:none;font-size:12px;text-align:center;font-weight:bold;"><?=$bo?></td>
        <td style="border-top:none;font-size:12px;text-align:center;font-weight:bold;"><?=$wt?></td>
        <td style="border-top:none;font-size:12px;">&nbsp;</td>
    </tr>
</table>

<style>
    table,th,td{
        border:1px solid black;
        border-collapse:collapse;
        padding:2px 5px;
    }
    @page  
{ 
    size: auto; 
    margin: 5mm 5mm 5mm 5mm;  
} 
body  
{ 
    margin: 0px;  
} 
</style>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready(function () {
    window.print();
    printWindow.close();
});

</script>