
<?php
error_reporting(0);

$this->load->view("common/header"); 

$page_no=1;
$page_no_item=1;
?>
<!-- 
<div style="top:5px;" class="panel-tools open">
<button data-toggle="dropdown" class="btn btn-blue dropdown-toggle" onClick="window.print()">
<i class="fa fa-print"></i>
</button>
</div> -->

<style type="text/css">
th{
	//text-align:center !important;
}
.report_view_th{
	color:#000 !important;
	//text-align:center !important;	
}
body{
	background-color:#fff !important;
	font-size:11px;
	line-height: 1.35;
}
p{
	margin:0;
}
.modal-body {
  padding: 2px 15px 15px;
  position: relative;
}
body .modal {
/* new custom width */
width: 750px;
/* must be half of the width, minus scrollbar on the left (30px) */
margin-left: -375px;
}
.print-table td, th{
	padding:0px;
	vertical-align:top !important;
}
thead { display: table-header-group; }
tfoot { display: table-footer-group; }


.right_wap_td td{
    line-height:1;
}
.right_wap_td_2 td{
    line-height:1.5;
    padding-bottom:2px;
}
</style>


<style type="text/css">

.print-table {
	/*page-break-before:avoid;
	page-break-after: avoid;*/
	/*page-break-inside: avoid;*/
	/*page-break-inside:avoid;*/
	width:100%;
	
}
.td_border_bottom_1{
	border-bottom:1px solid #666 !important;	
}
.td_border_bottom_2{
	border-bottom:4px double #666 !important;	
}
.td_border_top_1{
	border-top:1px double #666 !important;	
}
.logo_smart_wap{
	text-align:center;
	
}
h1, .h1, h2, .h2, h3, .h3 {
  margin-bottom: 0 !important;
  margin-top: 0 !important;
}

.table_border{
    border:1px solid black  !important;
}



.item_wap {
   /* height: 311px !important;*/
}

.table_2 td, th {
    padding: 2px;
    vertical-align: top !important;
}
.col_width{
   width: 400px;
}
.print-start{
    margin-right:20px;
}
</style>
<!--https://css-tricks.com/almanac/properties/p/page-break/-->

<!--onLoad="window.print()-->
<?php
$print_txt='';
if($this->session->userdata('ss_user_id')==1 ){
    
    $print_txt="onLoad='window.print()'";
	$print_txt="";
}else {
    $print_txt="onLoad='window.print()'";
}



$this->load->model('User_Model');
$ref_id = new User_Model();
	  $data['user_details']=$ref_id->get_user_info($sale_details['user']);
	// echo '<br/>Checked by: '; 
	 $user_first_name=$data['user_details']['user_first_name']; //.$data['user_details']['user_last_name'];*
	 
	 
?>
<body <?php  echo $print_txt; ?>>

    

<div class="print-start">

<?php
/*
$footer_top_mergin=0;
$footer_top_mergin="335px";
if($headercount==4){
    $footer_top_mergin="635px";
}
*/

?>
  
<div class="item_wap" style="height:335px" id="footer_total_wap">
<table class="print-table" width="100%">
<thead>
 <?php 

 

 $tmpcount=0;

 $headercount=0;
  $sale_mod=new Sales_Model();

  foreach ($sale_item_list as $row)

 {
      if($page_no_item>4){
      $page_no=2;
       }
       
        if($page_no_item>8){
      $page_no=3;
       }
       

	 $tmpcount++;
	 
	 $page_no_item++;

      $headercount++;
      
      

      if($headercount==4 || $tmpcount==1){

 ?>
<tr class="report_view_th">
  <th colspan="6" class="col-xs-1">
      <div class="row">&nbsp;</div>
      <div class="logo_smart_wap text-center">
 <!--          
<img src="<?php echo base_url();?>thems/images/logo_s.png" width="170" class=""> -->
</div>
  <!--header start-->
  <?php //$this->load->view("common/report_header.php"); ?>
  
  
 <!-- start logo -->
 <div class="row">
<div class="col-xs-12 text-center">
 
<div class="col-xs-5 text-left" style="margin-left: -37px; width: 48%; padding-right: 0;">
    
   <!--  <h3>	<?php echo $warehouse_details['name']; ?></h3> -->
 <!-- <img src="<?php echo base_url();?>thems/images/logo_s.png" width="100%" class=""> -->
</div>   

<div class="col-xs-4 text-left" style="width: 30%; padding-right: 0;">
    <!-- 
    <br>
    <table class="table_2">
    <tr>
        <td> <?php echo $warehouse_details['address']; ?> </td>
       
    </tr>
    <tr>
        <td> <?php echo $warehouse_details['phone']; ?></td>
       
    </tr>
    </table>
    -->
     
</div> 

<div class="col-xs-3 text-left" style="width: 24%; padding-right: 0;"><br>

   
</div> 
    
    
<!-- 
 

  <p style="font-size:;">
  <?php //print_r($warehouse_details);?>
  <?php echo $warehouse_details['address']; ?><br>
Hot	Line: <?php echo $warehouse_details['phone']; ?> 
<!--<br>
All Kinds Of Mobile Phones, Unloking, Software Updating Genuine Mobile Phone Accssories.-->
<?php /*?>&nbsp;&nbsp; Email: <?php echo $warehouse_details['email']; ?> <?php */?>
<br>


</p>
   </div><!--col-xs-12-->
</div><!--row-->
 
 <!-- end logo -->
  
  
  
  
  
  
  
  <div class="row">
  <div class="">
<div class="" style="height:0px">



</div>




<div class="col-xs-8 pull-left" style="padding-top:98px; padding-bottom:5px;">
    <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>
      </div>
      <div class="col-xs-4 pull-right right_wap_td" style="margin-top:12px;">
    <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>
     <?php
    $tech_id=$sale_details['tech_id'];
    if($tech_id){
    $data['tech_user_details']=$ref_id->get_user_info($sale_details['tech_id']);
    ?>
    <tr>
        <td>Technician</td>
        <td></td>
        <td><?php 
		//echo $user_first_name;
		 if(isset($data['tech_user_details']['user_first_name']))
		 {
		echo $data['tech_user_details']['user_first_name'];
		 }
		 
		 ?></td>
    </tr>
    <?php } ?>
</table>
      </div>
      
      </p>
</div>
</div>
<!--</div> -->
  
  <!--header end-->
   </tr>
<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>
</thead>
<tbody>
  </th>
  <?php 

  $headercount=0;

  } ?>
 

<tr style="border:solid 0px">
<td style="text-align:center; width:40px; vertical-align:middle; border-right:solid 0px; border-left:solid 0px"><?php echo $row['product_code']; //echo ":".$page_no_item.":".$page_no ?></td>
<td style="vertical-align:middle; 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/> ";
$sn_count=0;
foreach ($sn_list as $sn) { 
    $sn_count++;
echo "<span style='font-size:9px'>$sn->sis_number , </span>";

if($sn_count==3){
   //  $page_no_item++;
}

}
}

//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:middle; border-right:solid 0px"><?php echo number_format($row['quantity'], 0, '.', ''); ?></td>
<td style="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:middle;"> <!-- (<?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:110px; border-right:solid 0px"><?php echo number_format($row['gross_total'], 2, '.', ','); ?>


<?php
if($page_no_item==5){
    echo "<div style='height:180px'> &nbsp;</div>";
}



?>

</td>
</tr>
<?php }?>


</table>
</div>


<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;"><?php if($sale_details['sale_pymnt_given_amount_cash']!='0.00') echo number_format($sale_details['sale_pymnt_given_amount_cash'], 2, '.', ',') ?></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;"><?php if($sale_details['sale_pymnt_given_amount_cash']!='0.00') echo number_format($sale_details['sale_pymnt_given_amount_cash']-$row->sale_pymnt_amount, 2, '.', ',') ?></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>
</div>



                 
 <div class="row">
 
   <!--BF Start--> 
   <?php if($customer_details['cus_id']=='test'){ ?>
<div class="row">
<div class="col-xs-12">
<br>
<div class="col-xs-5 pull-right" style="border:1px solid #000;"><strong style="font-size:14px;">CF Balance :
<?php echo number_format($total_sales[0] ['sum(sale_total)']-$total_return[0]['sum(sl_rtn_total)']-$total_payments[0]['sum(p.sale_pymnt_amount)'] , 2, '.', ',');?>
</strong>
</div>

<div class="col-xs-6 " style="border:1px solid #000;"><strong style="font-size:14px;">&nbsp;&nbsp;BF Balance : 
<?php
$bf_balance=0;
//$tot_advnc_paid=1000;
//echo "$tot_advnc_paid";
$bf_balance=$total_sales[0] ['sum(sale_total)']-$sale_details['sale_total']-$total_return[0]['sum(sl_rtn_total)']-$total_payments[0]['sum(p.sale_pymnt_amount)']+$tot_advnc_paid;
echo number_format($bf_balance, 2, '.', ',');
 //echo number_format($total_sales[0] ['sum(sale_total)']-$total_return[0]['sum(sl_rtn_total)']-$total_payments[0]['sum(p.sale_pymnt_amount)']-$sale_details['sale_total'], 2, '.', ','); ?></strong>
</div>
</div>
</div>
<?php } ?>
  <!--BF End--> 
  


<div class="col-xs-12">
   








   </div><!--col-xs-12-->
   
   <!-- 
   <div class="col-xs-12 text-center text-bold"><b>THANK YOU COME AGAIN</b></div>
   -->
                
     <?php //$this->load->view("common/print_footer.php"); ?>   
    
</div><!--print-start-->   
<?php if ($sale_type == "pos_sale") { ?>
<div class="no-print" style="padding-top:10px; text-transform:uppercase;" id="buttons">
   <hr>
   <div class="alert alert-success">
      <button type="button" class="close" data-dismiss="alert">×</button>
      POS Sale successfully added 
   </div>
   <span class="pull-right col-xs-12">
   <a onClick="window.print();return false;" class="btn btn-block btn-primary" id="web_print" href="javascript:window.print()">Web Print</a>
   </span>
   <span class="col-xs-12">
   <a href="<?php echo base_url('pos'); ?>" class="btn btn-block btn-warning">Back to POS</a>
   </span>
   <div style="clear:both;"></div>
</div>

<?php } ?>
 </body>


<script>
<?php 
if($print_txt!='') { ?>
	setTimeout(function(){
		window.close();
		},30000);
		
		<?php } ?>
		
		document.addEventListener('DOMContentLoaded', function() {
   // your code here
   //alert();
   
   <?php if($page_no==2){ ?>
   document.getElementById('footer_total_wap').style.height = "872px";
   <?php } ?>
   
    <?php if($page_no==3){ ?>
   document.getElementById('footer_total_wap').style.height = "1500px";
   <?php } ?>
   
}, false);

		
	
</script> 
