<?php require_once('header.php'); ?>
<?php 
$list_id=array();
$list_id=$_GET['list_id'];


$li=explode(",",$list_id);
?>
<style>
.brmedium { 
            display: block; 
            margin-bottom: 5px; 
        } 
    @media print {
    body{
        width: 80mm;
        height: 50mm;
        /*margin: 30mm 45mm 30mm 45mm; */
         /*change the margins as you want them to be. */
   } 
}
</style>
<script>
function goBack() {
  window.history.back();
}
</script>
<br>
<center>
     <button class="btn btn-md btn-success" onclick="goBack()">&laquo; Back</button>&ensp;
    <input type="button" class="btn btn-info" onclick="printDiv('printableArea')" value="Print Lable" />&ensp;
    <a href="pk_awb_number_print.php?list_id=<?php echo $list_id; ?>" ><button class="btn btn-md btn-danger">Print AWB Number</button></a>
    </center><br>
<body>
     <?php
     
      function custom_echo($x, $length)
        {
          if(strlen($x)<=$length)
          {
            echo $x;
          }
          else
          {
            $y=substr($x,0,$length);
            echo $y;
          }
        }
     
      foreach($li as $lid){
     $list_id1=100001;
            $i=0;
    			$statement = $pdo->prepare("SELECT tu.address as cust_address,tcu.cust_code as cust_code,pk.ref_no as bar,pk.ref_no as awb,tcu.destination_city as dest,mat.short_desc as content,tu.phone as cust_phone,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 FROM pickup_entry as pk INNER JOIN tbl_user as tu INNER JOIN tbl_customer as tcu 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.awb_no='$lid'");
    		
    		$statement->execute();
    		$result = $statement->fetchAll(PDO::FETCH_ASSOC);
     
     foreach ($result as $row) {
     $cust_address=$row['cust_address'];
     $cust_code=$row['cust_code'];
     $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'];
     $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'];
     $n=$row['awb'];
     $bar=$row['bar'];
     $day=date_create($row['created']);
     $date=date_format($day,'d-m-Y');
     }?>

	<div id="printableArea">
	  
	 <?php for($i=$pieces;$i>0;$i--){?>
	    <center>
	        <!--<div style="border: 1px solid black;">-->
<table style="width:70mm;height:38mm;margin-top:0px;">
    <tr>
        <td>
            <img src="img/Logo_1.png" width="90px" height="80px" style="padding-left: 10px;padding-top: 3px">
        </td>
        <td style="margin-left:14px;">
            <!--<img src="unnamed.png" width="100px" height="20%" style="padding-left: 10px;padding-top: 3px">-->
             <?php 
                 echo "<img alt='testing' src='barcode/barcode.php?codetype=Code39&size=24&text=".$bar."&print=true'/>";
    		    ?>
        </td>
    </tr>
     <tr>
        <td><b>Date</b></td>
        <td><b> : <?php echo $date; ?></b></td>
    </tr>
    <tr>
        <td><b>Code</td>
        <td><b> : <?php echo $cust_code; ?></b></td>
    </tr>
    <tr>
        <td><b>Name</td>
        <td> <b>:
<?php 
        custom_echo($client_name, 12);
        
        // echo $client_name;
        ?></b></td>
    </tr>
    <tr>
        <td><b>City</td>
        <td> <b>: <?php echo $dest; ?></b></td>
    </tr><tr>
        <td><b>No Of Boxes</td>
        <td><b> :<?php echo $i; ?>/<?php echo $pieces; ?></b></td>
    </tr>
    
</table>
<!--</div>-->
<span class="brmedium"></span>


<?php 
 }?>
 
   
 <?php }
?>
</div>
</body>
<!-- page script -->
<script>

var doc = new jsPDF();
var specialElementHandlers = {
    '#print-btn': function (element, renderer) {
        return true;
    }
};

$('#submit').click(function () {
    doc.fromHTML($('#print').html(), 15, 15, {
        'width': 1070,
            'elementHandlers': specialElementHandlers
    });
    doc.save('pdf-version.pdf');
});
 
  function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

     document.body.innerHTML = printContents;

     window.print();

     document.body.innerHTML = originalContents;
}

  $(function () {
    $("#example1").DataTable();
    $('#example2').DataTable({
      "paging": true,
      "lengthChange": false,
      "searching": false,
      "ordering": true,
      "info": true,
      "autoWidth": false,
    });
  });
</script>
</html>