<?php
ob_start();
session_start();
include "inc/config.php";
$statement = $pdo->prepare("SELECT * FROM tbl_settings WHERE id=1");   
$statement->execute();
$query = $statement->fetchAll(PDO::FETCH_ASSOC);
$totalData = $statement->rowCount();
if($totalData>0){
    $site_name = $query[0]['name'];
    $logo = $query[0]['logo'];
    $favicon = $query[0]['favicon'];
    $short_name = $query[0]['short_name'];
}


$statement = $pdo->prepare("SELECT manifest.*,
origin_branch.name as origin_branch_name,destination_branch.name as destination_branch_name,tbl_coloader.name as coloader_name
FROM `manifest` 
left join tbl_branch origin_branch on origin_branch.id=manifest.origin

left join tbl_branch destination_branch on destination_branch.id=manifest.destination 
left join tbl_coloader on tbl_coloader.id=manifest.coloader_id  
WHERE manifest.id=".$_GET['id']);
$statement->execute();
$manifest_result = $statement->fetchAll(PDO::FETCH_ASSOC);
$totalFiltered = $statement->rowCount();
if($totalFiltered){?>

<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;font-size:20px;">Venus Cargo & Logistics Pvt Ltd</center>
            <center><b>REG OF</b> &nbsp;&nbsp;U 2069, Akshar Business Park, Plot No 3, </center>
            <center>Sector 25, Vashi, Nav, Mumbai-400703</center><br>
            <center><b style="font-size:18px;">MANIFEST COPY</b></center>
        </td>
    </tr>
</table>
<table style="width:100%;border:none;">
    <tr>
        <td style="width:15%;border:none;"></td><td style="width:25%;border:none;"></td>
        <td style="width:20%;border:none;">MANIFEST ID </td><td style="width:25%;border:none;">:  <?=$manifest_result[0]['manifest_id']?> </td>
    </tr>
    <tr>
        <td style="width:15%;border:none;">Origin </td><td style="width:25%;border:none;">: <?=$manifest_result[0]['origin_branch_name']?> </td>
        <td style="width:15%;border:none;">Vehicle No </td><td style="width:25%;border:none;">:  <?=$manifest_result[0]['vehicle_no']?></td>
    </tr>
     <tr>
        <td style="width:15%;border:none;">Destination </td><td style="width:25%;border:none;">:  <?=$manifest_result[0]['destination_branch_name']?></td>
        <td style="width:15%;border:none;">Driver Name </td><td style="width:25%;border:none;">:  <?=$manifest_result[0]['driver_name']?></td>
    </tr>
    <tr>
        <td style="width:15%;border:none;">Transport Name </td><td style="width:25%;border:none;">:  <?=$manifest_result[0]['coloader_name']?></td>
        <td style="width:15%;border:none;">Mobile No </td><td style="width:25%;border:none;">:  <?=$manifest_result[0]['driver_mobile_no']?></td>
        
    </tr>
    <tr>
        <td style="width:15%;border:none;">Date </td><td style="width:25%;border:none;">:  <?=date('d-m-Y', strtotime($manifest_result[0]['entry_date']))?></td>
        <td style="width:20%;border:none;">Total No Shipment </td><td style="width:25%;border:none;">:  <?=$manifest_result[0]['no_of_entry']?> </td>
    </tr>
   
 
    
</table>

<table style="width:100%;">
    <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;">Sender</th>
        <th style="border-top:none;">Consignee</th>
        <th style="border-top:none;">Destination</th>
        <th style="border-top:none;">Date</th>
        <th style="border-top:none;">Pcs</th>
        <th style="border-top:none;">Weight</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` INNER JOIN tbl_client_new ON pickup_entry.new_client_id=tbl_client_new.id where 1=1 and pickup_entry.id in (".$manifest_result[0]['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 (".$manifest_result[0]['ids'].")");
    $statements->execute();
    $querys = $statements->fetchAll(PDO::FETCH_ASSOC);
    $totalFiltered = $statements->rowCount();
    $i=1;
    $tot_box=0;$tot_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;"><?=$data['new_client_name']?></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;width:10%;"><?=date('d-m-Y', strtotime($data['date_added']))?></td>
        <td style="border-top:none;font-size:12px;"><?=$data['boxes']?></td>
        <td style="border-top:none;font-size:12px;"><?=$data['a_weight']?></td>
    </tr>
    <?php $i++; $tot_box=$tot_box+$data['boxes'];$tot_wt=$tot_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;"></td>
        <td style="border-top:none;font-size:12px;text-align:center;font-weight:bold;"><?=$tot_box?></td>
        <td style="border-top:none;font-size:12px;text-align:center;font-weight:bold;"><?=$tot_wt?></td>
    </tr>
</table>
<table style="width:100%;border:none;">
    <tr>
        <td style="width:50%;border:none;"></td>
        <td style="width:50%;border:none;text-align:center;">
            <br><b><?=$site_name?></b>
            <br><br><br><br><br><br>
            Seal & Signature
        </td>
    </tr>
</table>
<script>
     setTimeout(function () { window.print(); }, 0);
        window.onfocus = function () { setTimeout(function () { window.close(); }, 0); }
</script>


<style>
    table,th,td{
        border:1px solid black;
        border-collapse:collapse;
        padding:3px 5px;
    }
    @page  
{ 
    size: auto; 
    margin: 10mm 5mm 10mm 5mm;  
} 
body  
{ 
    margin: 0px;  
} 

</style>

<?php } ?>
