<!DOCTYPE html>
<html>
<head>
    <title>PACKING LIST</title>
	<style type="text/css">
    .table td {
        border: 1px solid #1f67b2; 
    }
	.whole {
	margin:10px;
	padding:5px;
	.table {
	border-collapse: collapse !important;
	font-size: 12px;
	color: #101010;
	width: 100%;
}
.table thead th{
	background: #e4e3e3;
	color: #000;
}
.table th,
.table td {
	border: 1px solid #000 !important;
	text-align: left;
	padding: 3px 6px;
}
.table th.text-left,
.table td.text-left{
	text-align: left;
	text-align: left !important;
}
.table th.text-right,
.table td.text-right{
	text-align: right;
	text-align: right !important;
}
.table th.text-center,
.table td.text-center{
	text-align: center;
	text-align: center !important;
}
.table tbody tr:nth-child(even){
	background: #fff;
}
.table th.Table-Title,
.table td.Table-Title{
    padding:7px 6px !important;
    font-size:1.15rem;
    color:green;
    font-weight:500;
    text-transform:uppercase;
}
.table th.total,
.table td.total{
	background: #e4e3e3;
	color: #fff;
	font-size: 11px;
}
	}
	
 .div{
      padding-top: 15px!important;
      padding-right: 15px!important;
      padding-bottom: 15px!important;
      padding-left: 15px!important;
    }
</style>
</head>
<body>
    <div class="div">
        <?php  $invoice = OutboundInvoice::model()->with('items')->findByPk($id); ?>
        <?php  $invoiceItems = OutboundInvoiceItems::model()->findAll(array('condition'=>'invoice_id='.$id,'group'=>'brand_id,category_id,id')); ?>
        <?php  $outbound = Outbound::model()->findByPk($invoice->outbound_id); ?>
		<div class="col-12">
					<div class="text-right"  style="line-height:7px;font-size:11px;font-family:space grotesk; color:#525252;">
				   <?php if($logo_display==0){?>
                 <br><br><br><br><br><br><br><br><br><br>
                 <?php } ?>
				 <?php if($logo_display> 0 ){?>
                        <?php echo $formatted_address; ?>
                <?php } ?>
				<!--<p><?php //echo str_replace('|', '<br>', $company_address); ?></p>-->
                </div>
				 <div class="text-left" style="padding-top:-100px;line-height:10px;font-size:9px;font-weight:600;">
				        <?php if($logo_display>0){?>
                 <img src="<?php echo 'images/pdf/'.$logo; ?>" style="width:27%;">
                 <?php }else{ ?>
                 <?php } ?>
                 <?php if($logo_display>0){?>
                 <br><br><br>
                 <?php } ?>
                
                </div><br><br>
                 <hr style="width:100%;">
			<div class="col-12">
				<div class="text-left" style="font-size:12px;font-weight:bold;padding-top:0px;">
				<p><?php echo $invoice->customer->name; ?></p>
				</div>
                <div class="text-left" style="font-size:9px;font-weight:bold;padding-top:-0px;">
                    <?php echo nl2br($invoice->customer->billing_adds); ?>
				</div>
				<div class="text-right" style="font-size:9px;padding-top:-50px !important;">
				<p><b>INVOICE : <?php echo $invoice->invoice_no; ?></b><br>
				   <b>DATE : <?php echo date('d M Y', strtotime($invoice->invoice_date)); ?></b><br>
				   <!-- <b>REF# : <?php //echo $invoice->id; ?></b></p> -->
				</div>
					<div class="text-left" style="font-size:9px;font-weight:bold;">
					 <p>
                        BRANDS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;<?php echo $invoice->brands_used ?></p>
					</div>
					<br>
					<div class="h3" style="text-align:center;padding-bottom:5px;">
						<u><?php echo "PACKING LIST"; ?></u>
					</div>
			</div>
		</div>
	</div>
	<div class="col-md-12 div">
        <table id="" class="table">
            <thead>
              
                <tr>
				    <th class="text-center" style="width:8%;">CONTAINER &<br>SEAL NUMBER.</th>
                    <th class="text-center" style="width:16%;">MODEL</th>
                    <th class="text-center" style="width:16%;">ORIGIN</th>
                    <th class="text-center" style="width:13%;">QTY<br>SETS</th>
                    <th class="text-center" style="width:13%;">PACKAGE/<br>CTNS.</th>
					<th class="text-center" style="width:17%;">N.WEIGHT<br>KGS.</th>
				    <th class="text-center" style="width:17%;">G.WEIGHT<br>KGS.</th>
					<th class="text-center" style="width:17%;">MEASUREMENT<br>CBM</th>
                </tr>
            </thead>
            <tbody>
                <?php 
                    $grand_total_qty= 0;
                    $grand_total_pckg= 0;
                    $grand_total_net_wt = 0;
                    $grand_total_gross_wt = 0;
                    $grand_total_cbm = 0;
   
                    $x =1;
                    $query = 'SELECT outb_container_no, GROUP_CONCAT(id) AS ids, COUNT(id) AS counts FROM nia_outbound_invoice_items WHERE invoice_id='.$id.' GROUP BY outb_container_no ORDER BY outb_container_no';
                    $outbound_containers = Yii::app()->db->createCommand($query)->queryAll();
                    
                    foreach( $outbound_containers as $i => $each ){ 
                        
                        $query_products = 'SELECT * FROM nia_outbound_invoice_items OI LEFT JOIN nia_outbound_invoice O ON O.id = OI.invoice_id WHERE OI.id IN ('.$each['ids'].') ORDER BY OI.outb_part_number';
                        $query_products_count= 'SELECT COUNT(id) AS value FROM nia_outbound_invoice_items WHERE id IN ('.$each['ids'].')';
                        
                        $items = Yii::app()->db->createCommand($query_products)->queryAll();
                        $count = Yii::app()->db->createCommand($query_products_count)->queryScalar();
                        
                        $total_qty= 0;
                        $total_pckg= 0;
                        $total_net_wt = 0;
                        $total_gross_wt = 0;
                        $total_cbm = 0;
                        
                        foreach( $items as $c => $eachItem ) : 
                            
                            $total_qty +=$eachItem['outb_quantity'];
                            $total_pckg += $eachItem['outb_remarks'];
                            $total_net_wt  += $eachItem['outb_net_wt'];
                            $total_gross_wt  += $eachItem['outb_gross_wt'];
                            $total_cbm  += $eachItem['outb_cbm'];

                            $grand_total_qty +=$eachItem['outb_quantity'];
                            $grand_total_pckg += $eachItem['outb_remarks'];
                            $grand_total_net_wt  += $eachItem['outb_net_wt'];
                            $grand_total_gross_wt  += $eachItem['outb_gross_wt'];
                            $grand_total_cbm  += $eachItem['outb_cbm'];
                        ?>
                        <tr>
                            <?php if( $c == 0 ) : ?>
                                <td rowspan="<?php echo $count; ?>" style="text-align:center;font-size:11px;"><?php echo $each['outb_container_no']; ?></td>
                            <?php endif; ?>
                            <td style="text-align:center;font-size:11px;"><?php echo $eachItem['outb_part_number']; ?></td>
                            <td style="text-align:center;font-size:11px;"><?php echo $eachItem['outb_contry_of_origin']; ?></td>
                            <td style="text-align:center;font-size:11px;"><?php echo (float) $eachItem['outb_quantity'];?></td>
                            <td style="text-align:center;font-size:11px;"><?php echo $eachItem['outb_remarks']; ?><br></td>
                            <td style="text-align:center;font-size:11px;"><?php echo $eachItem['outb_net_wt']; ?></td>
                            <td style="text-align:center;font-size:11px;"><?php echo $eachItem['outb_gross_wt']; ?></td>
                            <td style="text-align:center;font-size:11px;"><?php echo $eachItem['outb_cbm']; ?></td>
                        </tr>
                    <?php   $x++;
                            endforeach; ?>

                            <tr bgcolor="#e3e4e4">
                                <td colspan="3" style="text-align:right;background-color:#e4e3e3;text-transform:capitalize;"><b>Subtotal&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></td>
                                <td style="text-align:center;background-color:#e4e3e3;"><b><?php echo (float) $total_qty;?></b></td>
                                <td style="text-align:center;background-color:#e4e3e3;"><b><?php echo (float) $total_pckg;?></b></td>
                                <td style="text-align:center;background-color:#e4e3e3;"><b><?php echo number_format($total_net_wt, 3, '.', '');?></b></td>
                                <td style="text-align:center;background-color:#e4e3e3;"><b><?php echo number_format($total_gross_wt, 3, '.', '');?></b></td>
                                <td style="text-align:center;background-color:#e4e3e3;"><b><?php echo number_format($total_cbm, 3, '.', '');?></b></td>   
                            </tr>
                  
                <?php 

                } ?>
				<tr bgcolor="#e3e4e4">
				   <td height="20" colspan="3" style="background-color:#e4e3e3;"><b>TOTAL</b></td>
				   <td height="20" style="text-align:center;background-color:#e4e3e3;"><b><?php echo $grand_total_qty;?></b></td>
				   <td height="20" style="text-align:center;background-color:#e4e3e3;"><b><?php echo $grand_total_pckg;?><br><?php echo $invoice->unit_label ?></b></td>
				   <td height="20" style="text-align:center;background-color:#e4e3e3;"><b><?php echo number_format($grand_total_net_wt, 3, '.', '');?><br>NET WT.</b></td>
				   <td height="20" style="text-align:center;background-color:#e4e3e3;"><b><?php echo number_format($grand_total_gross_wt, 3, '.', '');?><br>KGS.</b></td>
				    <td height="20" style="text-align:center;background-color:#e4e3e3;"><b><?php echo number_format($grand_total_cbm, 3, '.', '');?><br>CBM.</b></td>   
				</tr>
            </tbody>
        </table>
		</div>
	  <div class="col-md-12">
	  <p style="font-size:9px;"> <strong><?php echo $invoice->destination ?><br>
	  <?php echo nl2br($invoice->invoice_note); ?><br><br>
	  Beneficiary bank details  :   :</strong></p>
	  </div>
      <div style="font-size:9px;text-align:left;padding-top:-23px;padding-left:175px;">
	  	<?php echo nl2br($invoice->bank_details); ?>
	 </div><br><br>
	  <p style="font-size:12px;padding-top:-10px;"><strong>FOR <?php echo $company_name; ?></strong><br><br>_____________________</p>
  


   <htmlpagefooter name="myfooter" class="newfoot">

            <div style="text-align:center;width:100%;font-size:10px;">
    </div>

    
        <div style="border-top: 1px dotted #000000; font-size: 12px; text-align: center; padding-top: 10px; background-color: #d7faeb;">
            <div style="text-align:center;width:100%">
              This is a system generated document (
        <?php
                  date_default_timezone_set("Asia/Dubai");
                 echo date('d/m/Y')."  & ".date("h:i:sa"); ?>)
            </div>
            <div style="text-align:center;width:100%">Page {PAGENO} of {nb} </div>
        </div>
    </htmlpagefooter>


    <style type="text/css">
   div { 
    page-break-inside:avoid;

      }


</style>

</body>

</html>
