<?php require_once('header.php');
$list_id=array();
$list_id=$_GET['list_id'];
$li=explode(",",$list_id);
$k=0;
function custom_echo($x, $length)
        {
          if(strlen($x)<=$length)
          {
            echo $x;
          }
          else
          {
            $y=substr($x,0,$length);
            echo $y."...";
          }
        }
        
foreach($li as $lid)
{
    $k++;
    $statement = $pdo->prepare("SELECT 
    c_loc.name as location_name, c_loc.mobile_no as location_mobile, c_loc.address as location_address, c_loc.state as location_state, c_loc.email as location_email, c_loc.gst_no as location_gst_no,
    tu.logistic_partner_id,pk.pickup_customer_name,pk.pickup_customer_dbcode,pk.entry_type,pk.destination,pk.picklist_no,pk.client_id,pk.invoice_no,pk.office_customer_name,pk.office_customer_address,
    pk.pincode,pk.invoice_value,pk.e_way_bill_no,tu.address as cust_address,tcu.cust_code as code,pk.read_status as read_status,pk.ref_no as bar,pk.destination as dest,mat.short_desc as content,tu.phone as cust_phone,
    tu.short_location as short_location,tu.location as location,tu.full_name as cust_name,tcu.cust_name as client_name,pk.address as client_address,pk.city as client_city,pk.state as client_state,pk.phone as client_phone, 
    pk.pics as pieces,pk.c_weight as c_weights,pk.a_weight as a_weights,pk.created_at as created,pk.content_desc as descrp,pk.total_charges as tc,pk.other_charges as oc,pk.payment_mode as pay_mode,pk.gst_no as gst,
    (SELECT full_desc FROM `material_desc` where id=pk.content_desc) as content_descs,
    pk.* FROM pickup_entry as pk 
    INNER JOIN tbl_user as tu 
    INNER JOIN tbl_customer as tcu 
    LEFT JOIN tbl_locations as c_loc ON c_loc.id=tu.location_id 
    INNER JOIN material_desc as mat on pk.client_id=tu.id AND pk.customer_id=tcu.cust_id AND mat.id=pk.content_desc 
    WHERE pk.id='$lid'");
    $statement->execute();
    $result = $statement->fetchAll(PDO::FETCH_ASSOC);
    
    foreach ($result as $row) {
         
         $read_stat=$row['read_status'];
     
     if($read_stat==0){ 
          $statement_update = $pdo->prepare("UPDATE pickup_entry set read_status=2 WHERE id='$lid'");
    	  $statement_update->execute();
     }
     
     // Location Details Starts Here
     $location_name[] = $row['location_name'];
     $location_mobile[] = $row['location_mobile']; 
     $location_address[] = $row['location_address'];
     $location_state[] = $row['location_state'];
     $location_email[] = $row['location_email']; 
     $location_gst_no[] = $row['location_gst_no'];
     // Location Details Endsss Here
     
         
     $logistic_partner_id[]=$row['logistic_partner_id'];   
     $read_status[]=$row['read_status'];
     $cust_address[]=$row['cust_address'];
     $cust_phone[]=$row['cust_phone'];
     $cust_name[]=$row['cust_name'];
     //$client_name[]=$row['client_name'];
     $client_address[]=$row['client_address'];
     $client_city[]=$row['client_city'];
     $client_state[]=$row['client_state'];
     $client_phone[]=$row['client_phone'];
     $pincode[]=$row['pincode'];
     
     
     $is_return_awb[]=$row['is_return_awb'];
     $client_destination[]=$row['location'];
     
     $pieces[]=$row['pieces'];
     $c_weights[]=$row['c_weights'];
     $gst[]=$row['gst'];
     $a_weights[]=$row['a_weights'];
     $total_charges[]=$row['tc'];
     $other_charges[]=$row['oc'];
     $desc[]=$row['content'];
     $pay_mode[]=$row['pay_mode'];
     $dest[]=$row['dest'];
     $destination[]=$row['destination'];
          $picklist_no[]=$row['picklist_no'];
     $day=date_create($row['created']);
     $date[]=date_format($day,'d-m-Y');
     $bar[]=$row['bar'];
     //$code[]=$row['code'];
     $short_location[]=$row['short_location'];
     $location[]=$row['location'];
     $invoice_no[]=$row['invoice_no'];
     $invoice_value[]=$row['invoice_value'];
     $e_way_bill_no[]=$row['e_way_bill_no'];
     $content_desc[]=$row['content_descs'];
     
     $office_customer_name[]=$row['office_customer_name'];
     $office_customer_address[]=$row['office_customer_address'];
     $client_id[]=$row['client_id'];
      $entry_type[]=$row['entry_type'];
      
      
      if($row['pickup_customer_dbcode']!=''){
          $code[]=$row['pickup_customer_dbcode'];
          $client_name[]=$row['pickup_customer_name'];
     }else{
          $code[]=$row['code'];
          $client_name[]=$row['client_name'];
     }
     }
}

function address_limit($addr){
      // strip tags to avoid breaking any html
    $string = strip_tags($addr);
    if (strlen($string) > 110) {
    
        // truncate string
        $stringCut = substr($string, 0, 110);
        $endPoint = strrpos($stringCut, ' ');
    
        //if the string doesn't contain any space then it will cut without word basis.
        $string = $endPoint? substr($stringCut, 0, $endPoint) : substr($stringCut, 0);
        $string .= '...';
    }
    echo $string;
}
?>


<style>

/*div {
  height: 1042px;
  width: 100%;
}*/


.watermarks {
  display: block;
  position: relative;
}

.watermarks::after {
    content: "RECEIVED IN GOOD CONDITION";
    opacity: 0.25;
    top: 47%;
    left: 2%;
    transform: rotate(353deg);
    bottom: 0%;
    font-size: 20px;
    background-repeat: no-repeat;
    right: 0%;
    text-align: center;
    position: absolute;
    z-index: -1;
}

</style>
<style type="text/css">
	table,th {
  border: 1px solid;
}
td {
  border: 1px solid;
  padding: 0px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

.dashed {border-style: dashed;
margin-top: 10px;
margin-bottom: 10px;
}
.dasheds {border-style: dashed;
border-color:white;
margin-top: 10px;
margin-bottom: 10px;
}

 @page{
     size: auto;   /* auto is the initial value */ 
    margin: 5mm 5mm 5mm 5mm;
 }
@media print  
{ 
    * {
         
        -webkit-print-color-adjust: exact;
    }
     
    
} 
</style>

<br>
<center>
      <a class="btn btn-sm btn-danger" href="modicare-pickup-entry-add.php">Add Pickup</a>
     <a href="modicare-pickup-entry.php"><button class="btn btn-sm btn-success">Back</button></a>
     
    <!--<input type="button" class="btn btn-info" onclick="printDiv('printableArea')" value="Print Lable" />&ensp;-->
    <a href="awb_number_confirm_print.php?list_id=<?php echo $list_id; ?>" target="_blank"><button class="btn btn-sm btn-primary"><i class="fa fa-print"></i> Print Docket Now</button></a>
    <!--<a href="lable_print.php?list_id=<?php echo $list_id; ?>" ><button class="btn btn-md btn-info">Print Label</button></a>
    <a href="lable-print-with-address.php?list_id=<?php echo $list_id; ?>" ><button class="btn btn-sm btn-warning"> <i class="fa fa-print"></i>Lable Print With Address</button></a>-->
    <a href="sls-shipment-invoice-label.php?list_id=<?php echo $list_id; ?>" target="_blank" ><button class="btn btn-sm btn-warning"> <i class="fa fa-print"></i> Invoice Label Print</button></a>
    <a href="sls-shipment-box-label.php?list_id=<?php echo $list_id; ?>" target="_blank" ><button class="btn btn-sm btn-danger"> <i class="fa fa-print"></i> Box Label Print</button></a>
    </center><br>
    
    
<br>

<div style="padding:10px;background:white">
<?php 
for($i=0;$i<$k;$i++) {

$statement = $pdo->prepare("SELECT * FROM `logistic_partner` where id='$logistic_partner_id[$i]'");
$statement->execute();
$logistic_partner_result = $statement->fetchAll(PDO::FETCH_ASSOC);
if($logistic_partner_result){ ?>
<style>
    .watermark<?=$logistic_partner_id[$i]?> {
  display: block;
  position: relative;
}

.watermark<?=$logistic_partner_id[$i]?>::after {
  content: "";
    background: url(img/new-logo.png);
    opacity: 0.09;
    top: 22%;
    left: 0%;
    bottom: 0%;
    background-size: 400px 250px;
    background-repeat: no-repeat;
    right: 0%;
    text-align: center;
    position: absolute;
    z-index: -1; 
}
.partner_watermark_<?=$logistic_partner_id[$i]?> {
  display: block;
  position: relative;
}
.partner_watermark_<?=$logistic_partner_id[$i]?>::after {
  content: "";
    background: url(<?=$logistic_partner_result[0]['logo']?>);
    opacity: 0.09;
    top: 22%;
    left: 50%;
    bottom: 0%;
    background-size: 300px 250px;
    background-repeat: no-repeat;
    right: 0%;
    text-align: center;
    position: absolute;
    z-index: -1; 
}
</style>
<?php }else{ $logistic_partner_id[$i]='';?>
<style>
      .watermark {
  display: block;
  position: relative;
}

.watermark::after {
  content: "";
    background: url(img/new-logo.png);
    opacity: 0.09;
    top: 22%;
    left: 22%;
    bottom: 0%;
    background-size: 400px 250px;
    background-repeat: no-repeat;
    right: 0%;
    text-align: center;
    position: absolute;
    z-index: -1; 
}
</style>
<?php } ?>

    
<?php for($ids=1;$ids<=3;$ids++){ ?>
<div class="partner_watermark_<?=$logistic_partner_id[$i]?>">
<table style="border: none;padding:0px;" class="watermark<?=$logistic_partner_id[$i]?>"><tr><td style="border: none;padding:0px;">
<table style="border-bottom: none;">
	<tr>
		<td width="20%" style="border-right: none;padding-left: 2px;border-bottom: none;">
		<center>	<?php   
		
		if($logistic_partner_result){ ?>
		<table style="width:100%;border:none;">
		    <tr>
		        <td style="border:none;"><img src="img/new-logo.png" style="width: 80px;"></td><td style="border:none;"></td>
		    </tr>
		    <tr>
		        <td style="border:none;"></td><td style="border:none;"><img src="<?=$logistic_partner_result[0]['logo']?>" style="width: 80px;margin-top:0;"></td>
		    </tr>
		</table>
		    
	<?php	}else{
	    echo '<img src="img/new-logo.png" style="width: 65%;">';
	}
		
		?>
		
		</center>	
		</td>
		
<?php 
if($location_mobile[$i]!=""){
    $phone_loc = 'Ph : '.$location_mobile[$i].',<br>';
}else{
    $phone_loc = "";
}

if($location_email[$i]!=""){
    $email_loc = ''.$location_email[$i].'<br>';
}else{
    $email_loc = "";
}

$location_full_address = '<b style="font-size:12px;font-weight: 900;text-transform: uppercase;">'.$print_company_name.'</b><br>
		        '.$location_address[$i].'<br>
				'.$phone_loc.'
				'.$email_loc.'';
?>
		<td width="20%" style="border-left: none;padding: 2px;vertical-align: center;border-bottom: none;">
	         <p style="font-size:10px;margin-left:2%;">
	        	<?=$location_full_address?></p>
		</td>
		<td width="30%" style="padding: 2px;vertical-align: top;border-bottom: none;">
			<table style="vertical-align: top;">
				<tr style="vertical-align: top;">
					<td style="padding: 2px;vertical-align: top;border-bottom:none;" class="bg">
						<center style="font-size:12px;">BOOKING DATE</center>
					</td>				
				</tr>
				<tr style="border: none;text-align:center">
					<td style="padding: 3px;border-top:none;">
						<!--<b><?=$location[$i]?></b>-->
						<b><?=$date[$i]?></b>
					</td>				
				</tr>
				
			    <tr style="border: none;vertical-align: top;">
					<td style="padding: 2px;vertical-align: top;border-bottom:none;" class="bg">
						<center style="font-size:12px;">DESTINATION</center>
					</td>				
				</tr>
				<tr style="border: none;text-align:center">
					<td style="padding: 3px;border-top:none;">
						<!--<b><?=$date[$i]?></b>-->
						<b><?php 
						
				if($is_return_awb[$i]==0){//forward Entry		
						if($entry_type[$i]==2 || $client_id[$i]==22 || $client_id[$i]==28){ echo custom_echo($destination[$i], 15); }else  { echo custom_echo($dest[$i], 15); }
				}else{
				    //Reverse Entry
				    
				    echo custom_echo($client_destination[$i], 15);
				}			
						
						?></b>
					</td>				
				</tr>
			</table>
			
		</td>
		<td width="23%" style="vertical-align: top;border-bottom: none;">
			<table style="border: none;vertical-align: top;border-bottom: none;">
				<tr style="border: none;vertical-align: top;">
					
					<td style="border: none;text-align:center" >
					    <center>AWB No:<br>
						<img alt="testing" class="img_bar" src="barcode/barcode.php?codetype=Code128&amp;size=40&amp;text=<?=$bar[$i]?>&amp;" style="width: 80%;height:40px"><br><b style="font-size:20px;font-weight:900;"><?=$bar[$i]?></b>
					</center></td>
				</tr>
			<!--	<tr style="border: none;">
									
				</tr>-->
			</table>
		</td>
	</tr>
</table>
<table style="border:none;">
	<tr>
		<td width="38%" style="">
			<table style="border:none;font-size:10px;">
				<tr>
					<td class="bg" width="10%" rowspan="7" style="text-align: center;font-size:12px;border-left: none;border-bottom: none;"><b style="font-weight:bold;writing-mode: vertical-rl;">CONSIGNOR</b></td>
					
					<td style="border:none ;padding:3px;padding-left:10px;">
					<p style="line-height: 14px;font-weight: bold;">
					    
					  <?php if($is_return_awb[$i]==0){//forward Entry ?>  
					    <b><?php if($client_id[$i]==1) { echo $office_customer_name[$i]."<br>"; }else{ echo $cust_name[$i]."<br>"; }?></b>
					    <b><?php if($client_id[$i]==1) {
					        echo nl2br($office_customer_address[$i]);
					    }else{
					    echo nl2br($cust_address[$i]);
					    if($gst[$i]!=""){ echo "<br>GST NO: ".$gst[$i]; } }?>
					    
					  <?php }else{ ?>
					            <?php if($code[$i]!="" && $code[$i]!="0"){ echo "<b style='font-size:14px;font-weight:900;'>DP CODE : ".$code[$i]."</b><br>"; }else if($picklist_no[$i]!=""){ echo "<b style='padding:10px;font-size:14px;font-weight:900;'>DP CODE : ".$picklist_no[$i]."</b><br>"; } ?><b style='font-size:12px'><?php if($client_id[$i]==0) { echo $office_customer_name[$i]; }else{ echo $client_name[$i]; }?></b><br>
					    <?=custom_echo($client_address[$i], 150)?>
					    <?php if($client_city[$i]!=""){ echo "<br>".$client_city[$i]; } ?>
					    <?php if($client_state[$i]!=""){ echo ",".$client_state[$i]; }?>
					    <?php if($pincode[$i]!=""){ echo "-".$pincode[$i]; }?>
					    <?php if($client_phone[$i]!=""){ echo "<br><b>Phone : ".$client_phone[$i]."</b>"; } ?>
					  
					  <?php } ?>
					    
			
					</p>
					</td>
					<td width="0%" style="border:none ;padding:0px;">
					    <p style="border:none ;padding:0px;min-height:125px;"></p>
					</td>
				</tr>
				
			</table>
		</td>
		<td width="50%" style="">
			<table style="border:none;font-size:10px;">
				<tr>
					<td class="bg" width="7%" rowspan="7" style="text-align: center;font-size:12px;border-left: none;border-bottom: none;"><b style="font-weight:bold;writing-mode: vertical-lr;">CONSIGNEE</b></td>
				    <td style="border:none ;padding:3px;padding-left:10px;padding-top:0px;">
					<p style="line-height: 14px;font-weight: bold;">
					    
					    
					   <?php if($is_return_awb[$i]==0){//forward Entry ?>  
					   
					   <?php if($code[$i]!="" && $code[$i]!="0"){ echo "<b style='font-size:14px;font-weight:900;'>DP CODE : ".$code[$i]."</b><br>"; }else if($picklist_no[$i]!=""){ echo "<b style='padding:10px;font-size:14px;font-weight:900;'>DP CODE : ".$picklist_no[$i]."</b><br>"; } ?><b style='font-size:12px'><?php if($client_id[$i]==0) { echo $office_customer_name[$i]; }else{ echo $client_name[$i]; }?></b><br>
					    <?=custom_echo($client_address[$i], 150)?>
					    <?php if($client_city[$i]!=""){ echo "<br>".$client_city[$i]; } ?>
					    <?php if($client_state[$i]!=""){ echo ",".$client_state[$i]; }?>
					    <?php if($pincode[$i]!=""){ echo "-".$pincode[$i]; }?>
					    <?php if($client_phone[$i]!=""){ echo "<br><b>Phone : ".$client_phone[$i]."</b>"; } ?>
					  
					  

					  <?php }else{ ?>
					             <b><?php if($client_id[$i]==1) { echo $office_customer_name[$i]."<br>"; }else{ echo $cust_name[$i]."<br>"; }?></b>
					    <b><?php if($client_id[$i]==1) {
					        echo nl2br($office_customer_address[$i]);
					    }else{
					    echo nl2br($cust_address[$i]);
					    if($gst[$i]!=""){ echo "<br>GST NO: ".$gst[$i]; } }?>
					    
					  <?php } ?>
					    
					    
					</p>
					</td>
					<td width="0%" style="border:none ;padding:0px;">
					    <p style="border:none ;padding:0px;min-height:125px;"></p>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<table style="text-align: center;font-size:12px;">	
				<tr  style="vertical-align: center;">
					<td class="bg" width="13%" style="padding:2px;">NO Of PCS</td><td width="7%" style="padding:0px;"><b style="font-size:16px;"><?=$pieces[$i]?></b>&nbsp;</td>
					<td width="15%" class="bg" style="padding:2px;">ACTUAL WEIGHT</td>
					<td width="8%" style="padding:2px;"><b style="font-size:16px;"><?=$a_weights[$i]?></b>&nbsp;</td>
			        <td width="12%" class="bg" style="padding:2px;">INVOICE NO</td>
					<td width="22%" style="padding:2px;"><b style="font-size:14px;"><?=$invoice_no[$i]?></b>&nbsp;</td>
					<td width="14%" class="bg" style="padding:2px;">INVOICE VALUE</td>
					<td width="12%" style="padding:2px;"><b style="font-size:14px;"><?=$invoice_value[$i]?></b>&nbsp;</td>
				    <!--<td width="34%" colspan="2" style="text-align:center;"><b style="padding:2px;font-size: 12px;">RECEIVED IN GOODS CONDITION</b></td>-->
				
				</tr>
</table>
 <table style="text-align: center;font-size: 10px;vertical-align:top;">
					    <tr>
					        <td style="padding-left: 5px;padding: 2px;border-top: none;border-left: none;vertical-align:top;" width="10%">
					            <!--<img src="img/qrcode.png" >-->
					            <!--<img width="80%" src="https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=https://speedlinkservices.com/track_details.php?track_id=<?php echo $bar[$i] ?>&choe=UTF-8" title="Speedlink Services" />-->
					            <img width="80%" src="qr/index.php?text=https://speedconnectservices.com/tracking.php?track_id=<?php echo $bar[$i] ?>&choe=UTF-8" title="Speedconnect Logistic" />
					        <span style="font-size:9px;">Scan QR Code For Your Shipment Tracking...</span>
					        </td>
						<td style="padding-left: 5px;padding: 2px;border-top: none;border-left: none;vertical-align:top;" width="33%">
							<table style="border:none;font-size: 10px;">
							    
							    <tr>
									<td  colspan="2" style="border:none;text-align: center;padding: 2px;">
										<b style="font-size: 10px;text-align: center;">Consignor's Declaretion</b>
									</td>
								</tr>
								<tr>
									<td colspan="2" style="font-size: 9px;border:none;text-align: left;padding-left: 5px;padding: 2px;"><p>I / We have read carefully & verified the contents filled in this Docket and agree to the terms and coditions printed overleaf of the Docket and will pay all charges as per tariff mentioned in this Docket or as per the agreement.</p></td>
								</tr>
								<!--<tr>
									<td style="border:none;text-align: left;padding: 2px;height: 35px;vertical-align: bottom;text-align:center;"><b>Signature</b></td>
									<td style="border:none;text-align: left;padding: 2px;height: 35px;vertical-align: bottom;text-align:center;"><b>Date : </b></td>
								</tr>-->
								<tr>
									<td style="border:none;text-align: left;padding: 2px;height: 15px;vertical-align: bottom;text-align:center;" colspan="2"><b>For </b></td>
								</tr>
								<tr>
									<td style="border:none;text-align: left;padding: 2px;height: 15px;vertical-align: bottom;text-align:center;" colspan="2"><b><?php if($client_id[$i]==1) { echo $office_customer_name[$i]; }else{ echo $cust_name[$i]; }?> </b></td>
								</tr>
								
							</table>
</td>
						<td rowspan="3" class="watermarks" style="vertical-align:top;padding: 2px;border-top: none;border-right: none;border-bottom: none;">
							
							<table style="border:none;font-size: 8px;font-weight: bold;text-align:left;">
							    <!--<tr>
									<td width="100%" colspan="2" style="border:none;border-bottom:1px solid gray;padding: 2px;padding-top: 5px;opacity: 1.5;font-weight: 900;text-align:center;">RECEIVED IN GOODS CONDITION</td>
								</tr>-->
								<tr>
									<td width="50%" style="border:none;padding: 2px;padding-top: 5px;opacity: 1.5;font-weight: 900;">NAME</td>
									<td style="border:none;padding: 2px;padding-top: 5px;padding-left: 30px;font-weight: 900;opacity: 1.5;text-align:right;">DATE & TIME</td>
								</tr>
								<tr>
									<td style="border:none;padding: 2px;height: 50px;opacity: 1.5;font-weight: 900;">SEAL</td>
									<td style="border:none;padding: 2px;height: 50px;padding-left: 30px;opacity: 1.5;font-weight: 900;text-align:right;">RELATION</td>
								</tr>
								
								<tr>
									<td style="border:none;padding: 1px;padding-bottom: 3px;vertical-align:bottom;opacity: 1.5;font-weight: 900;">SIGNATURE</td>
									<td style="border:none;padding: 2px;padding-bottom: 1px;padding-left: 30px;vertical-align:bottom;opacity: 1.5;font-weight: 900;text-align:right;">REMARK</td>
								</tr>
							</table>

						</td>
					</tr>
				
</table>  
</td></tr></table>
</div>
<?php if($ids%3!=0){ ?>
<hr class="dashed">
<?php }else{ echo "<hr class='dasheds'>"; } ?>


<?php } ?>  

    
<?php  }?>
</div>

<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>
<?php require_once('footer.php'); ?>