<?php $this->load->view("partial/header"); ?>
<?php
if (isset($error_message))
{
	echo '<h1 style="text-align: center;">'.$error_message.'</h1>';
	exit;
}

?>
<div id="receipt_wrapper">
	
	<div id="receipt_header">
		<div id="company_name" style="display:none"><?php echo $this->config->item('company'); ?></div>
		<div id="company_address" style="display:none"><?php echo nl2br($this->Location->get_info_for_key('address')); ?></div>
		<?php if($this->config->item('company_logo')) {?>
		<div id="company_logo"><?php echo img(array('src' => $this->Appconfig->get_logo_image())); ?></div>
		<?php } ?>
		<div id="sale_receipt"><h3><?php echo $receipt_title; ?></h3></div>
		<div class="pull-right"><button style="display:none" class="btn btn-primary text-white hidden-print" id="new_receiving_button_1" onclick="window.location='<?php echo site_url('receivings'); ?>'" > <?php echo lang('receivings_new_receiving'); ?> </button></div>
	</div>
	<div id="receipt_general_info">
    	<div style="width:50%; float:left">
		
		<div id="sale_id"><?php echo lang('receivings_id').": ".$receiving_id; ?></div>
		<div id="employee"><?php echo 'Created By'.": ".$employee; ?></div>
		<div id="employee"><?php echo 'Location'.": ".$location; ?></div>
		<div id="employee"><?php echo 'MRO'.": ".$mro_id; ?></div>
        <div id="employee">Phone:<?php echo $this->Location->get_info_for_key('phone'); ?></div>
      
        </div>
    	<div style="width:35%; float:right">
        	<table id="receipt_items" >
            	<tr>
                	<td align="left">Supplier:<?php echo $supplier_info ?></td>
                </tr>
                <tr>
                	<td align="left">Request Location:<?php echo $req_location ?></td>
                </tr>
                <tr>
                	<td align="left">Transaction Date:<?php echo $transaction_time ?></td>
                </tr>
               
            </table>
        		

        </div>
        
	</div>

	<table id="receipt_items">
	<tr>
	<th >Product Id</th>
	<th ><?php echo lang('items_item'); ?></th>
	<th style="width:16%;text-align:center;"><?php echo lang('sales_quantity'); ?></th>
	<th style="text-align:center;"><?php echo lang('common_price'); ?></th>
	<th style="width:16%;text-align:center;"><?php echo lang('sales_discount'); ?></th>
	<th style="width:17%;text-align:right;"><?php echo 'Total'; ?></th>
	</tr>
	<?php
	foreach(array_reverse($cart, true) as $line=>$item)
	{
	?>
		<tr>
		<td style='text-align:left;'><?php echo $item['product_id']; ?></td>
		<td style="text-align:left;"><?php echo character_limiter(H($item['name']),25); ?></td>
		<td style='text-align:center;'><?php echo number_format($item['quantity'],2); ?></td>
		<td style="text-align:center;"><?php echo to_currency($item['price']); ?></td>
		<td style='text-align:center;'><?php echo $item['discount']; ?></td>
		<td style='text-align:right;' style="display:none"><?php echo to_currency($item['price']*$item['quantity']-$item['price']*$item['quantity']*$item['discount']/100); ?></td>
		</tr>
	    <tr>
		<td></td>
	    <td colspan="2" align="left"><?php echo H($item['description']); ?></td>
		<td colspan="2" ><?php echo H($item['serialnumber']); ?></td>
		<td colspan="1"><?php echo '---'; ?></td>
	    </tr>
	<?php
	}
	?>	
	<tr >
	<td colspan="4" style='text-align:right;'><b><?php echo 'Sum '; ?></b></td>
	<td colspan="2" style='text-align:right'><?php echo to_currency($total); ?></td>
	</tr>

	<tr>
	<td colspan="4" style='text-align:right;'><b><?php echo 'TERMS & CONDITIONS'; ?></b></td>
	<td colspan="2" style='text-align:right'><b><?php echo $po_purpos; ?></b></td>
	</tr>

	<?php if(isset($amount_change))
	{
	?>
		<tr>
		<td colspan="4" style='text-align:right;'><b><?php echo lang('sales_amount_tendered'); ?></b></td>
		<td colspan="2" style='text-align:right'><?php echo to_currency($amount_tendered); ?></td>
		</tr>

		<tr>
		<td colspan="4" style='text-align:right;'><b><?php echo lang('sales_change_due'); ?></b></td>
		<td colspan="2" style='text-align:right'><?php echo $amount_change; ?></td>
		</tr>
	<?php
	}
	?>
    <?php if(isset($comment) && $comment){ ?>
    <tr>
		<td colspan="6" style='text-align:left;'><?php echo '<b>Remarks:</b>'; ?> <?php echo $comment; ?></td>
		</tr>
     <?php } ?>
     
     <tr>
     	<td colspan="6" style="text-align:"><br /><br /><br />Requester name: ____________________  Manager Name: ______________________  Approval Name:___________________</td>
     </tr>
     
      <tr>
     	<td colspan="6" style="text-align:right"><br />Signature:________________ </td>
     </tr>
	</table>

	<div id="sale_return_policy">
	<?php echo nl2br($this->config->item('return_policy')); ?>
	</div>
	<div id='barcode'>
	<?php echo "<img src='".site_url('barcode')."?barcode=$receiving_id&text=$receiving_id' />"; ?>
	</div>
	<button class="btn btn-primary text-white hidden-print" id="print_button" onClick="window.print()" > <?php echo lang('sales_print'); ?> </button>
	<!--<br />-->
	<button style="display:none" class="btn btn-primary text-white hidden-print" id="new_receiving_button_2" onclick="window.location='<?php echo site_url('receivings'); ?>'" > <?php echo lang('receivings_new_receiving'); ?> </button>
	
</div>
<?php $this->load->view("partial/footer"); ?>

<?php if ($this->config->item('print_after_sale'))
{
?>
<script type="text/javascript">
$(window).load(function()
{
	window.print();
});
</script>
<?php
}
?>