<?php $this->load->view("common/header"); ?>
<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">
h3 {
	margin-top: 10px;
}
th {
	text-align: center !important;
}
.report_view_th {
	color: #000 !important;
	text-align: center !important;
}
body {
	background-color: #fff !important;
	font-size: 12px;
}
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: 1px;
	vertical-align: top !important;
}
thead {
	display: table-header-group;
}
tfoot {
	display: table-footer-group;
}
.width_cus {
	width: 100px !important;
}
.width_qty {
	width: 100px !important;
}
</style>
<?php 

$ref_usr=new User_Model;



$user_details=$ref_usr->get_user_info($sale_details['user']);
//print_r($user_details);
$inv_name='';
$inv_name=$user_details['invoice_name'];
$inv_user_name=$user_details['user_first_name'];
$discount_enable=false;


$cr_limit_name='';
if($sale_details['cr_interest']){
//get unit cr limit name
$ref_cr_lmt=new Common_Model();
$cr_limit_des=$ref_cr_lmt->get_cr_limit_name_by_val($sale_details['cr_interest']);
$cr_limit_name=$cr_limit_des[0]['cr_limit_name'];
}
?>
<!--https://css-tricks.com/almanac/properties/p/page-break/-->
<!--onLoad="window.print()-->
<body onLoad="window.print()">
<?php $this->load->view("common/report_header.php"); ?>
<div class="row">
  <div class="col-xs-12">
    <div class="col-xs-5" style="border:solid 1px;">
        
        
        
        <table class="print-table" width="100%" style="border:none">
        <tr>
          <td > Customer: </td>
          <td ><?php echo $customer_details['cus_name']."(".$customer_details['cus_code'].")"; ?></td>
        </tr>
        <?php 
		if($customer_details['cus_phone']){ ?>
        <tr>
          <td > Tel: </td>
          <td ><?php echo $customer_details['cus_phone']; ?></td>
        </tr>
        <?php }else { ?>
        
        <?php } ?>
        <tr>
          <?php if($vehicle_name){ ?>
          <td > &nbsp;&nbsp;&nbsp; </td>
          <td >&nbsp;&nbsp;&nbsp;</td>
          <?php } ?>
        </tr>
        <tr>
          <?php if($fname){ ?>
          <td >&nbsp;&nbsp;&nbsp; </td>
          <td >&nbsp;&nbsp;&nbsp;</td>
          <?php } ?>
        </tr>
         <?php if($sale_details['in_type'] == "Credit"){ ?>
        <tr>
          <td >&nbsp;&nbsp;&nbsp; </td>
          <td >&nbsp;&nbsp;&nbsp;</td>
        </tr>
         <?php } ?>
      </table>
        
        

    </div>
    <div class="col-xs-6 pull-right">
      <table class="print-table" width="100%" style="border:none">
        <tr>
          <td style="border:1px solid #000"> Date: </td>
          <td style="border:1px solid #000"><?php echo display_date_time_format($sale_details['sale_datetime']); ?></td>
        </tr>
        <tr>
          <td style="border:1px solid #000"> Invoice: </td>
          <td style="border:1px solid #000"><strong><?php echo $sale_details['sale_reference_no']; ?></strong> &nbsp;&nbsp;&nbsp;(<?php echo $inv_user_name;?>) </td>
        </tr>
        <tr>
          <?php if($vehicle_name){ ?>
          <td style="border:1px solid #000"> Lorry: </td>
          <td style="border:1px solid #000"><strong><?php echo $vehicle_name; ?></strong></td>
          <?php } ?>
        </tr>
        <tr>
          <?php if($fname){ ?>
          <td style="border:1px solid #000"> Rep Name: </td>
          <td style="border:1px solid #000"><strong><?php echo $fname." ".$lname; ?></strong></td>
          <?php } ?>
        </tr>
         <?php if($sale_details['in_type'] == "Credit"){ ?>
        <tr>
          <td style="border:1px solid #000"> Due Date: </td>
          <td style="border:1px solid #000"><?php if($sale_details['due_date'])echo $sale_details['due_date']; else echo date('Y-m-d', strtotime("+3 months", strtotime($sale_details['sale_datetime']))); ?></td>
        </tr>
         <?php } ?>
      </table>
      
      <!--<p>Reg No.:<?php //echo $warehouse_details['reg_no']; ?>  <br>  </p>-->
      <?php /*?><p style="display:none">Sales Terms: <?php echo $sale_details['in_type']; ?>
        <?php if($cr_limit_name) echo "($cr_limit_name)" ?>
      </p>
      <p>Date: <?php echo display_date_time_format($sale_details['sale_datetime']); ?></p>
      <p>Invoice: <strong><?php echo $sale_details['sale_reference_no']; ?></strong> &nbsp;&nbsp;&nbsp;(<?php echo $inv_user_name;?>)</p>
      <?php if($vehicle_name){ ?><p>Lorry: <strong><?php echo $vehicle_name; ?></strong></p><?php } ?>
      <?php if($fname){ ?><p>Rep Name: <strong><?php echo $fname." ".$lname; ?></strong></p><?php } ?>
      <p>Due Date: <strong><?php echo date('Y-m-d', strtotime("+3 months", strtotime($sale_details['sale_datetime']))); ?></strong></p>
      <?php */?>
    </div>
  </div>
</div>
<!--lorry rep; due date;--> 
<br>
<div class="print-start" style="border:solid 1px; min-height:560px;" >
  <table class="print-table" width="100%" style="border:none">
    <thead>
      <tr class="report_view_th text-center"  style="border:1px solid #000">
        <th style="border:1px solid #000; width:40px;" class='width_cus'><br>
          No</th>
        <th class="col-xs-7" style="border:1px solid #000"><br>
          Description</th>
        <th class="width_qty" style="border:1px solid #000";><br>
          Qty</th>
        <th class="" style="border:1px solid #000">Unit Price<br>
          (Rs.)</th>
        <?php //if($discount_enable){ ?>
        <th class="col-xs-1"  style="border:1px solid #000">Discount<br>
          (Rs.)</th>
        <?php //} ?>
        <th class="" align="center"  style="border:1px solid #000"> Net Amount<br>
          (Rs.)</th>
      </tr>
    </thead>
    <tbody>
      <?php 

 $tmpcount=0;

 $tot_qty=0;

  foreach ($sale_item_list as $row)

 {

	 $tmpcount++;

	 $tot_qty=$tot_qty+$row['quantity'];

 ?>
      <tr style="line-height:18px">
        <td style="text-align:center; vertical-align:middle; border:none"><?php echo $tmpcount ?>)</td>
        <td  style="border:none"><?php echo $row['product_name']; ?>
          <?php //echo $row['product_code']; ?></td>
        <td style="text-align:right; vertical-align:middle; border:none"><strong><?php echo number_format($row['quantity'], 0, '.', ','); ?></strong></td>
        <td style="text-align:right; width:100px; border:none;"><?php echo number_format($row['unit_price'], 2, '.', ','); ?></td>
        <?php //if($discount_enable){ ?>
        <td style="width: 100px; text-align:right; vertical-align:middle; border:none"> (<?php echo $row['discount'] ?>) <?php echo number_format($row['discount_val'], 2, '.', ',') ?></td>
        <?php //}?>
        <td style="text-align:right; width:120px;  border:none"><?php echo $row['gross_total']; ?></td>
      </tr>
      <?php }?>
    </tbody>
  </table>
</div>
<div class="row">
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;No. Items (<?php echo $tmpcount ?>), 

 Total Qty (<?php echo rtrim(str_replace('.00', '', number_format($tot_qty, 2)), '0'); ?>)
 <div class="col-xs-12">
  <div class="col-xs-5 pull-right" id="border_print" style="border:1px solid #000;">
     <table width="100%" border="0">
      <tr>
         <td><strong style="font-size:14px;">Sub Total RS</strong></td>
         <td style="text-align:right"><strong style="font-size:14px;"><?php echo number_format($sale_details['sale_total']-$sale_details['cr_interest_amt']+$sale_details['sale_inv_discount_amount'], 2, '.', ',') ?></strong></td>
       </tr>
      <?php //if ($sale_details['sale_inv_discount']){ ?>
      <tr>
         <td>Group Discount(<?php echo $sale_details['sale_inv_discount'] ?>)</td>
         <td style="text-align:right;"><?php echo number_format($sale_details['sale_inv_discount_amount'], 2, '.', ',') ?></td>
       </tr>
      <!--<tr>
        <td>After Discount Sub Total RS</td>
        <td style="text-align:right;"><?php echo number_format($sale_details['sale_total']-$sale_details['cr_interest_amt'], 2, '.', ',') ?></td>
      </tr>
      <?php //}?>
      <tr>
        <td>Credit Sur Charge RS(<?php echo $sale_details['cr_interest'] ?>%)</td>
        <td style="text-align:right"><?php echo number_format($sale_details['cr_interest_amt'], 2, '.', ',') ?></td>
      </tr>-->
      <tr style="border-top:1px solid #000;">
         <td><strong style="font-size:14px;">Total</strong></td>
         <td class="rext-right" style="border-top:1px solid #000; text-align:right"><strong style="font-size:14px;"><?php echo number_format($old_payments+$sale_details['sale_total'], 2, '.', ',') ?></strong></td>
       </tr>
    </table>
   </div>
  <div class="col-xs-6" id="border_print" style="border:1px solid #000; display:none">
     <p class="text-center"><strong>1</strong> Any text </p>
   </div>
</div>
 <!--col-xs-12-->
 <div class="col-xs-12">
  <p style="font-size:14px;">*සෑම භාණ්ඩයක්ම මිලදීගැනීමේදී හොඳින් පරීක්ෂා කර ලබාගන්න </p>
  <div class="col-xs-2" style="border-top:dashed 1px; margin:50px 5px 0px 25px">
     <center>
      Printed By
    </center>
   </div>
  <div class="col-xs-2" style="border-top:dashed 1px; margin:50px 5px 0px 25px">
     <center>
      Checked By
    </center>
   </div>
  <div class="col-xs-2" style="border-top:dashed 1px; margin:50px 5px 0px 25px">
     <center>
      Customer Signature
    </center>
   </div>
  <div class="col-xs-2" style="border-top:dashed 1px; margin:50px 5px 0px 25px">
     <center>
      Customer Seal
    </center>
   </div>
</div>
 <div class="col-xs-12">
  <p class="text-center" style="font-size:17px;"><br>
     <strong>Thank You! </strong></p>
</div>

 <!--print-start-->

 </body>
