<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
           
<?php
$totalrow = 1;
$totalamount = 0;
$mobileno = "";
if(is_array($transinfo4view) && count(array_filter($transinfo4view))>0)
{
	$mobile = $info4view->fld_mobile;
	if($mobile!="")
	{
		$mobileno = mobilemasking($mobile);
	}
?>
<html>
<head>
	<title>Print Bill</title>
	<style>
	body { font-family: 'arial' sans-serif; margin-top:0; }
	</style>
</head>
<body>
		<table  style="width:350px;font-size:14px;" align="center" cellpadding="5"  cellspacing="0">
                                            <thead>
                                                <tr>
                                                    <th  align="center"><h3>CASH MEMO</h3></th>
                                                   
                                                </tr>
                                                <?php
                                                if($tasktype=="printbill")
                                                {
                                                ?>
                                                <tr>
                                                    <th  align="center"><i>Printed by Manager</i></th>
                                                   
                                                </tr>
                                             <?php
												}
                                             ?>

                                            </thead>
                                            </table>
  <hr style="width:350px;font-size:14px;" align="center">                                      
<table  style="width:350px;font-size:14px;" align="center" cellpadding="5"  cellspacing="0">
	<thead>
	</thead>
		<tbody>
				<tr>
					<td style="vertical-align:top;width:57%"><strong>Customer:</strong> <?php if($info4view) { echo $info4view->fld_name; }?></td>
					<td style="vertical-align:top;width:43%"><strong>BillNo:</strong> <?php if($info4view) { echo $info4view->fld_billno; }?></td>
				</tr>			
				<tr>
					<td style="vertical-align:top;"><strong>Mobile:</strong> <?php if($info4view) { echo $mobileno; }?></td>
					<td style="vertical-align:top;"><strong>Bill Date:</strong> <?php if($info4view->fld_billdate!="") { echo date("d-M-Y", strtotime($info4view->fld_billdate)); }?></td>
				</tr>
				<tr>
					<td style="vertical-align:top;"><strong>Operator:</strong> <?php if($dbuserinfo) { echo $dbuserinfo->fld_name; }?></td>
					<td style="vertical-align:top;"><strong>Time:</strong> <?php if($info4view) { echo date("H:i:s", strtotime($info4view->fld_datetime));; }?></td>
				</tr>					
		  </tbody>
		</table>
		<hr style="width:350px;font-size:14px;" align="center">
		<table  style="width:350px;font-size:14px;" align="center" cellpadding="5"  cellspacing="0">
                                            <thead>
                                                <tr>
                                                    <th  align="left" width="46%">Description</th>
                                                    <th align="left" width="18%">Qty.</th>                                                    
                                                    <th align="center"  width="18%">Rate (<?php echo CURRENCY;?>)</th>
                                                    <th  align="right"  width="18%">Amt (<?php echo CURRENCY;?>)</th>
                                                </tr>
                                            </thead>
                                            </table>
											<hr style="width:350px;font-size:14px;" align="center">
<table  style="width:350px;font-size:14px;" align="center" cellpadding="5" cellspacing="0">
       
                                            <tbody>

<?php
		$poindex = 1;
		$totalqty = 0;
		$totalmrp = 0;
		$totalsubtotal = 0;
		foreach($transinfo4view as $row)
		{
			$subtotal = ($row->fld_qty*$row->fld_price);
			$totalamount += $subtotal;
			$totalqty += $row->fld_qty;
			$totalmrp += ($row->fld_qty*$row->fld_mrp);
			$totalsubtotal += $subtotal;
?>
			<tr>
				<td align="left"  width="40%"><?php echo $row->fld_name;?></td>
				<td align="center"  width="20%"><?php echo number_format($row->fld_qty);?></td>
				<td align="center"  width="20%"><?php echo number_format($row->fld_mrp, 2);?></td>
				<td align="right"  width="20%"><?php echo number_format($subtotal, 2);?></td>
			</tr>
<?php
		$poindex++;
		}	
	$discountpercent = "";
	if($info4view->fld_discounttype=="percent")
	{
		$discountpercent  = "<br>(".round($info4view->fld_discount,2)."%)";
	}
		
?>

</tbody>
</table>
<hr style="width:350px;font-size:14px;" align="center">
<table  style="width:350px;font-size:14px;" align="center" cellpadding="5" cellspacing="0">
	<tr>
		<td align="left"  width="40%"><strong>Total:</strong></td>
		<td align="center" width="20%"><?php echo number_format($totalqty);?></td>
		<td align="center" width="20%"><?php echo number_format($totalmrp);?></td>
		<td align="right" width="20%"><?php echo number_format($totalsubtotal, 2);?></td>
	</tr>
</table>

<hr style="width:350px;font-size:14px;" align="center">
<table  style="width:350px;font-size:14px;" align="center" cellpadding="5" cellspacing="0">
<thead>
<tr>
<th align="right" colspan="3"  width="70%">Sub Total</th>
<th align="right"  width="30%"><?php echo number_format($totalamount, 2);?></th>
</tr>
<?php
if($info4view->fld_discount>0)
{
?>
<tr>
<th align="right" colspan="3"  width="70%">Discount
<?php echo $discountpercent;?></th>
<th align="right"  width="30%"><?php echo number_format((abs($info4view->fld_amount - $info4view->fld_netamount)), 2);?></th>
</tr> 
<?php
}
?>
<tr>
<td colspan="2" width="40%"></td>
<th align="right" width="30%">Grand Total</th>
<th align="right"  width="30%"><?php echo number_format((abs($info4view->fld_netamount)), 2);?></th>
</tr> 												
<?php
	$billtotal = abs($info4view->fld_netamount);
	if($totalmrp>$billtotal)
	{
?>
<tr>
<td colspan="4" width="40%">You Saved: <?php echo CURRENCY;?> <?php echo number_format(($totalmrp - $billtotal), 2);?></td>
</tr>
<?php
	}
?> 												
<tr>
<td colspan="4" width="40%">Total of Item(s): <?php echo $totalqty;?></td>
</tr> 												
</thead>
</table>

<?php
	 if($info4view->fld_discount>0)
	{
	 ?>
	<hr style="width:350px;font-size:14px;" align="center">
	<table  style="width:350px;font-size:14px;" align="center" cellpadding="5" cellspacing="5">
		<tbody>
		<tr>
		<td align="left"  width="100%"> <strong>Remarks:</strong> <?php if($info4view) { echo $info4view->fld_givenname; }?></td>
		</tr> 
	</tbody>
	</table>
<?php
	}
	?>
										
 
<?php
	 if($info4view->fld_gqty)
	{
	 ?>
	<hr style="width:350px;font-size:14px;" align="center">
	<table  style="width:350px;font-size:14px;" align="center" cellpadding="5" cellspacing="5">
		<tbody>
		<tr>
		<td align="right"  width="100%"> <strong>You are eligible to  <?php echo $info4view->fld_giftname;?></strong></td>
		</tr> 
	</tbody>
	</table>
<?php
	}
	?>


<?php
	 if($info4view->fld_remarks)
	{
	 ?>
	<hr style="width:350px;font-size:14px;" align="center">
	<table  style="width:350px;font-size:14px;" align="center" cellpadding="5" cellspacing="5">
		<tbody>
		<tr>
		<td align="left"  width="100%"> <strong>Additional Remarks:</strong> <?php echo $info4view->fld_remarks;?></td>
		</tr> 
	</tbody>
	</table>
<?php
	}
	?>

										
	<hr style="width:350px;font-size:14px;" align="center">
	<table  style="width:350px;font-size:14px;" align="center" cellpadding="5" cellspacing="5">
	<tbody>
	<tr>
	<td align="left" colspan="3"  width="100%"><strong>Terms & Conditions:</strong><br>
	No cash refund.<br>
	Goods may be exchanged with in the same day.</td>
	</tr>
	<tr><td colspan="3">&nbsp;</td></tr>
	<tr><td colspan="3">&nbsp;</td></tr>
	</tbody>
	</table>

<?php
}													
?>			
		
<?php
if($tasktype=="printbill")
{
	?>

 <script type="text/javascript">
        window.print();
        setTimeout("closePrintView()", 1000);
    function closePrintView() {
        document.location.href = '<?php echo base_url();?>outlet/billing';
    }
</script>

<?php
}
?>
</body>
</html>
