<?php include 'header.php';
$track_id=$_REQUEST['track_id'];
$type=$_REQUEST['type'];
$pick_id="";
	
	if($type=='cscs_awb'){ $given='CSCS AWB'; }elseif($type=='3pl_awb'){ $given='3PL AWB'; }elseif($type=='ref_no'){ $given='Ref No'; }						

						
							$statement = $pdo->prepare("SELECT * FROM `pickup_entry` WHERE $type=? ");
							$statement->execute(array($track_id));
							$total_id = $statement->rowCount();
							$result = $statement->fetchAll(PDO::FETCH_ASSOC);
							if(!$result)
							{
							    echo "<script>alert('Incorrect $given Number.');window.location = 'shipment_tracking.php';</script>";
							}
								?>
<style>
    table {
  border-collapse: collapse;
}

table, td, th {
  border: 1px solid black;
}
</style>
<script>
    function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

     document.body.innerHTML = printContents;

     window.print();

     document.body.innerHTML = originalContents;
}
</script>

<section class="content-header">
	<div class="content-header-left">
		<h1>View Shipment Tracking</h1>
	</div>
	<div class="content-header-right" style="margin-right: 1%;">
		<a href="shipment_tracking.php" class="btn btn-primary btn-sm">Back</a>
	</div>
	
</section>
<section class="content">
<div id="printableArea">
    <b><center><h4>Shipment Tracking</h4></center>
    <?php foreach ($result as $row) { 
        $mani_fest=$row['manifest_id'];
        $pick_id=$row['id'];
        ?>
    <table  style="width: 100%;line-height: 34px; font-size: 12px;" border=1>
         <tr>
			            <td style="text-align:left;padding-left: 2%;"><?php if($clientType=="Admin"){ ?>3PL AWB :&emsp;<?php echo $row['3pl_awb']; } ?></td>
			            <td style="text-align:left;padding-left: 2%;">CSCS AWB :&emsp;<?php echo $row['cscs_awb']; ?> </td>
			            <td style="text-align:left;padding-left: 2%;">Ref No :&emsp;<?php echo $row['ref_no']; ?> </td>
			            <td style="text-align:left;padding-left: 2%;" >Book Date :&emsp;  <?php $day=date_create($row['date_added']); $new_date=date_format($day,'d-m-Y');  echo $new_date; ?></td>
			            <td style="text-align:left;padding-left: 2%;">Order Type :&emsp;<?php  echo strtoupper($row['order_type']);  ?> </td>
			            <td style="text-align:left;padding-left: 2%;">Status :&emsp;<?php  echo strtoupper($row['status']);  ?> </td>
		</tr>
		 <tr>
			            <td style="text-align:left;padding-left: 2%;"> Consign.Name :&emsp;<?php echo $row['consignee_name']; ?></td>
			            <td style="text-align:left;padding-left: 2%;" colspan=3>Consign.Address :&emsp;<?php echo $row['consignee_address'].', &emsp;'.$row['consignee_city'].', &emsp;'.$row['consignee_state']; ?></td>
			            <td style="text-align:left;padding-left: 2%;">Consign.Phone :&emsp;<?php echo $row['consignee_phone']; ?></td>
			             <td style="text-align:left;padding-left: 2%;">Consign.Pinode :&emsp;<?php echo $row['consignee_pincode']; ?></td>
		</tr>
        
    </table>
     <?php } ?>  
  
	<div class="row">
		<div class="col-md-12">
		    <div >
				<div >
			  
					<table style="width: 100%;line-height: 34px; font-size: 12px;" border=1>
			        	<thead>
			        <tr>
			            <th style="text-align:center">S.No</th>
			            <th style="text-align:center">Status </th>
			            <th style="text-align:center">Date</th>
			            <th style="text-align:center">Location</th>
			            <th style="text-align:center">Description</th>
			        </tr>
			        	</thead>
			        <tbody>
			       <?php 
			       $i=0;
			                $statement = $pdo->prepare("SELECT * FROM tbl_tracking where pickup_entry_id=?");
							$statement->execute(array($pick_id));
							$result = $statement->fetchAll(PDO::FETCH_ASSOC); 
							foreach ($result as $row) {
							    $i++;
							?>
			        <tr>
			            <td style="text-align:center"><?php echo $i; ?></td>
			            <td style="text-align:center"><?php echo strtoupper($row['status']); ?></td>
			            <td style="text-align:center"><?php  $day=date_create($row['created_at']);
                        $new_date=date_format($day,'d-m-Y');                        
                         echo $new_date;  ?></td>
			            <td style="text-align:center"><?php echo $row['location']; ?></td>
			            <td style="text-align:center">
			                <?php  if($row['description']!=''){ echo $row['description'];} ?>
			                <?php  if($row['receiver_name']!=''){echo "Receiver Name : "; echo $row['receiver_name']; echo "&emsp;";}?>
			                <?php  if($row['receiver_mobile']!=''){echo "Receiver Mobile : "; echo $row['receiver_mobile']; echo "&emsp;";}?>
			                <?php  if($row['relation']!=''){echo "Relation : "; echo $row['relation']; } ?>
			                <?php  if($row['reason']!=''){echo "Reason : "; echo $row['reason']; }?>
			               
			            </td>
			        </tr>
			        <?php } ?>
			       
			        </tbody>
			    </table>
			    

			</div>
			</div>
	</div>
	</div>
</div>
	

	<br><br>

	<div class="content-footer-right" style="margin-left:45%">
		<input type="button" class="btn btn-danger" onclick="printDiv('printableArea')" value="Print" />
	</div>
</section>



<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Delete Confirmation</h4>
            </div>
            <div class="modal-body">
                <p>Are you sure want to delete this item?</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                <a class="btn btn-danger btn-ok">Delete</a>
            </div>
        </div>
    </div>
</div>


<?php require_once('footer.php'); ?>