<?php
error_reporting(0);
$no_of_page=3;
//$this->load->view("common/header"); ?>

<!-- <link rel="stylesheet" href="http://lasermt.viableerp.com/thems/plugins/bootstrap/css/bootstrap.min.css"> -->


<style>
body{
	background-color:#fff !important;
	font-size:11px;
	line-height: 1.35;
		margin-right:250px  !important;
		 width:100%;

}
.content{
    width:96%;
}
.main_wap{
 width:100%;
}
td{
    font-size:11px;
}

    .header, .header-space,
.footer, .footer-space {
  height: 135px;
  width:800px;
  margin-top:38px;
}
.header {
  position: fixed;
  top: 0;
}
.footer {
  position: fixed;
  bottom: 0;
}
.customer_top_height{
    height:90px;
}
</style>

<!-- https://medium.com/@Idan_Co/the-ultimate-print-html-template-with-header-footer-568f415f6d2a -->
<div class="main_wap">
<table>
  <thead><tr><td>
    <div class="header-space">&nbsp;</div>
  </td></tr></thead>
  <tbody><tr><td>
      
      <!-- start Content -->
    <div class="content"> <!-- Content... -->
    
    <table class="print-table" width="100%">
        
        <?php 
        error_reporting(0);
         $tmpcount=0;

 $headercount=0;
  $sale_mod=new Sales_Model();
  
         foreach ($sale_item_list as $row)

 {
     $headercount++;
      $w_des=$sale_mod->get_warranty_types_des_by_id($row['w_id']);
     ?>
     <tr class="report_view_th text-center"   style="border:solid 0px">
<th class="col-xs-2" style="border:solid 0px; width:120px">&nbsp; <!-- Code--></th>
<th class="col-xs-5 "  style="border:solid 0px"><!-- Description--></th>
<!-- <th class="col-xs-1">Code</th> -->
<th class="col-xs-1  text-center" style="border:solid 0px"><!-- Quantity--></th>
<th class="col-xs-1  text-center" style="border:solid 0px; widht:8%"> <!-- Price--></th>
 <th class="col-xs-1"> <!-- Discount --></th>  
<th class="col-xs-  text-center col_width_del" align="center" style="border:solid 0px; width:90px"><!--  Subtotal --></th>
</tr>

<tr style="border:solid 0px">
<td style="text-align:center; width:40px; vertical-align:top; border-right:solid 0px; border-left:solid 0px"><?php echo $row['product_code'];//echo $tmpcount ?></td>
<td style="vertical-align:top; border-right:solid 0px">
  <?php echo $row['product_name']; ?>
 <?php 
 $w_des=$sale_mod->get_warranty_types_des_by_id($row['w_id']);
//print_r($w_des);
if($w_des['w_name']) echo "<br/> ".$w_des['w_name'];

 $sn_list=$sale_mod->get_sales_serial_by_id($sale_details['sale_id'],$row['id']);
 
 //print_r($sn_list);
if(!empty($sn_list)){
//echo "<br/> Serial No. ";
echo "<br/> ";
foreach ($sn_list as $sn) { 
echo "$sn->sis_number , ";

}
}

//if($row['product_w']) echo " <br/> Warranty: ".$row['product_w']. " Months";
?> 
   </td>
<!-- <td style="width: 80px; text-align:center; vertical-align:middle;"><?php echo $row['product_code']; ?></td> -->
<td style="width: 80px; text-align:center; vertical-align:top; border-right:solid 0px"><?php echo number_format($row['quantity'], 0, '.', ''); ?></td>
<td style=" vertical-align:top; text-align:right; width:100px; border-right:solid 0px">
    
    
    
    <?php 
    
    if($row['discount_val']<0){
        echo number_format($row['unit_price']-($row['discount_val']), 2, '.', ','); 
    }else{
          echo number_format($row['unit_price'], 2, '.', ','); 
    }
    
  ?></td>

<td style="width: 100px; text-align:right; vertical-align:top;"> <!-- (<?php echo $row['discount'] ?>)  --> <?php if($row['discount_val'] > 0)echo number_format($row['discount_val'], 2, '.', ',');else echo number_format(0, 2, '.', ',') ?></td> 
<td style="text-align:right; width:120px; border-right:solid 0px;  vertical-align:top;"><?php echo number_format($row['gross_total'], 2, '.', ','); ?>


</td>
</tr>
     
     <?php } ?>
    </table>    
    <?php
    /*
    for($i=0; $i<30; $i++){
        echo "<br/> ". $i;
    }
    */
    ?>
    
    </div>
      <!-- end Content -->
  </td></tr></tbody>
  <tfoot><tr><td>
    <div class="footer-space">&nbsp;</div>
  </td></tr></tfoot>
</table>
<!-- start head -->
<div class="header"><!-- HEAD... -->



<table width="100%">
    <tr>
        <td>
            <div class="customer_top_height">&nbsp</div>
            <table class="table_2">
    <tr>
        <td width="55px"></td>
        <td></td>
        <td><?php echo $customer_details['cus_name']; ?></td>
    </tr>
     <tr>
        <td></td>
        <td></td>
        <td><?php echo $customer_details['cus_address']; ?></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td>
            <div style="width:275px; float:left"><?php echo $customer_details['cus_phone']; ?></div>
            <div style="width:140px; float:left"><!-- NIC No: --> <?php echo $customer_details['cus_nic']; ?></div>
            
            
    </tr>
    </table>
        </td>
        <td></td>
        <td><table class="table_2">
         <tr>
        <td width="100px">&nbsp </td>
        <td></td>
        <td>0</td>
    </tr>
    <tr>
        <td> </td>
        <td></td>
        <td><?php echo display_time_format($sale_details['sale_datetime']); ?></td>
    </tr>
    <tr>
        <td> &nbsp</td>
        <td></td>
        <td><?php echo $sale_details['in_type']; ?></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td><?php echo $sale_details['sale_reference_no']; ?></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td><?php echo site_date($sale_details['sale_datetime']); ?></td>
    </tr>
    <tr>
        <td>&nbsp </td>
        <td></td>
        <td></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td><?php 
		$ref_id = new User_Model();
	 	 $data['user_details']=$ref_id->get_user_info($sale_details['rep_id']);
		 if(isset($data['user_details']['user_first_name']))
		 {
		echo $data['user_details']['user_first_name'];
		 }
		 ?></td>
    </tr>
    
    <tr>
        <td></td>
        <td></td>
        <td><?php 
		echo $user_first_name;
		 
		 ?></td>
    </tr>
</table></td>
    </tr>
    
</table>
 
   

</div>
<!-- end head -->


<div class="footer">
    
    <table width="100%">
    <tr>
        <td></td>
        <td></td>
        <td>
            <table width="100%" class="right_wap_td_2" >
<?php if ($sale_details['sale_inv_discount']){ ?>
<tr>
    <td width="60%"></td>  
  <td style="text-align:right; padding-right:10px;">Order Discount</td>
  <td style="text-align:right; padding-right:10px;"><?php echo number_format($sale_details['sale_inv_discount_amount'], 2, '.', ',') ?></td>
</tr>
<?php }?>
<tr>
    <td width="60%" style="text-align:left; font-weight:bold; border-top:0px solid #000; "></td>
<td style="text-align:left; font-weight:bold; border-top:0px solid #000; "><!-- S T -->
</td>
<td style="text-align:right; padding-right:3px; font-weight:bold; border-top:0px solid #000; border-bottom:0px double #000;"><?php echo number_format($sale_details['sale_total'], 2, '.', ',') ?></td>
</tr>


<tr>
    <td > &nbsp </td>
<td > <!-- Ta -->
</td>
<td style="text-align:right; font-weight:bold; border-bottom:0px solid #000;"></td>
</tr>
<tr>
    <td > &nbsp </td>
<td > 
</td>
<td style="text-align:right; font-weight:bold; border-bottom:0px solid #000;"></td>
</tr>

<tr>
    <td width="60%" style="text-align:center; font-weight:bold; border-top:0px solid #000; "><?php echo $sale_details['remarks'] ?></td>
<td style="text-align:left; font-weight:bold; border-top:0px solid #000; "> <!-- To -->
</td>
<td style="text-align:right; padding-right:0px; font-weight:bold; border-top:0px solid #000; border-bottom:0px double #000;"><?php echo number_format($sale_details['sale_total'], 2, '.', ',') ?></td>
</tr>



<?php
$Sales_Model = new Sales_Model();
$sale_paid = $Sales_Model->get_total_paid_by_sale_id($sale_details['sale_id']);

$bal=$sale_details['sale_total']-$sale_paid;
 //if ($bal>0)
 { ?>
 
 <?php  
	 $balance_amt=0;
	 $tot_advnc_paid=0;
	// print_r($sale_payments_list);
 foreach ($sale_payments_list as $row){
	$tot_advnc_paid+=$row->sale_pymnt_amount;

if($row->sale_pymnt_amount!='0.00'){
	 ?>  
<tr>
     <td></td>
<td style="text-align:left; font-weight:bold; padding-left:100px" > <!--  A/--> <?php echo $row->sale_pymnt_paying_by ?>
 <!--   [Date:<?php echo date('d/M/Y', strtotime($row->sale_pymnt_date_time));?>] -->
</td>
<td style="text-align:right; font-weight:bold; border-bottom:0px solid #000;">


<?php echo number_format($row->sale_pymnt_amount, 2, '.', ',') ?></td>
</tr>
<?php }
}?>

<?php }?>

<tr>
    <td  style="text-align:right; font-weight:bold; border-bottom:0px solid #000;">  </td>
<td > <!-- B D --> &nbsp
</td>
<td style="text-align:right; font-weight:bold; border-bottom:0px solid #000;"><?php if ($bal>0) echo number_format($bal, 2, '.', ',');?></td>
</tr>

<tr>
    <td  style="text-align:right; font-weight:bold; border-bottom:0px solid #000;">  </td>
<td > <!-- C R --> &nbsp
</td>
<td style="text-align:right; font-weight:bold; border-bottom:0px solid #000;"></td>
</tr>

<tr>
    <td  style="text-align:right; font-weight:bold; border-bottom:0px solid #000;">  </td>
<td ><!-- B P --> &nbsp
</td>
<td style="text-align:right; font-weight:bold; border-bottom:0px solid #000;"></td>
</tr>






<?php if ($sale_details['customer_id']!=1){ ?>
<?php if ($old_payments){ ?>
<!-- 
<tr>
     <td></td>
<td style="text-align:left; font-weight:bold;"><?php echo $old_payments_dis_msg ?>
</td>
<td style="text-align:right; font-weight:bold; border-top:0px solid #000; border-bottom:0px double #000;"><?php echo number_format($old_payments, 2, '.', ',') ?></td>
</tr>
<tr>

</tr> -->
<?php }?>
<?php }?>
</tbody>
</table> 
        </td>
    </tr>
    
</table>

    
    <!-- start footer -->
    
    <!-- end footer -->
    </div>
    </div>
