<?php 
	$type = $this->input->get('type');
	$this->load->helper('az_config');
?>
<!DOCTYPE html>
<html>
<head>
	<title>Faktur</title>
	<style type="text/css">
		html {
			margin: 0;
		}
		body {
			font-family: 'Tahoma';
			font-size: 14px;
			width: 21cm;
			margin: 0;
		}
		.separate {
			border-bottom: 1px dashed #000;
		}

		@media print {
			body {
				width: 100%;
			}
		}
	</style>
</head>
<body onload="window.print();">
	<div>
		<table width="100%">
			<tr>
				<td valign="top" width="40%">
					<table>
						<tr>
							<td colspan="3"><b><?php echo az_get_config('store_name');?></b></td>
						</tr>
						<tr>
							<td>Faktur</td>
							<td>:</td>
							<td><?php echo $data->code;?></td>
						</tr>
					</table>
				</td>
				<td valign="top" width="40%">
					<table>
						<tr>
							<td valign="top">Customer</td>
							<td valign="top">:</td>
							<td valign="top"><?php echo $data->customer_name.'<br>'.$data->customer_address;?></td>
						</tr>
					</table>
				</td>
				<td valign="top" width="20%" align="right">
					<?php echo Date('d-m-Y', strtotime($data->transaction_date));?>
				</td>
			</tr>
		</table>
	</div>
	<div class="separate" style="margin-top:10px;margin-bottom:3px;"></div>
	<div class="separate"></div>
	<table width="100%">
		<tr>
			<td width="10px" align="center">No</td>
			<td>Item</td>
			<td>Description</td>
			<td align="center">Qty</td>
			<td align="right">Harga</td>
			<td align="right">Diskon</td>
			<td align="right">Total</td>
		</tr>
		<tr>
			<td colspan="7"><div class="separate"></div>
		</tr>
		<?php 
			$arr_discount = array();
            foreach ($transaction->result() as $key => $value) {
                echo "<tr>";
                echo "	<td align='center'>".($key + 1)."</td>";
                echo "	<td>".$value->barcode."</td>";
                echo "  <td class='name'>".$value->product_name."</td>";
                echo "  <td class='qty' align='center'>".$value->qty.' '.$value->unit_name."</td>";
                echo "  <td class='sell-price' align='right'>".az_thousand_separator($value->sell_price)."</td>";
                echo "	<td align='right'>".$value->discount."</td>";
                echo "  <td class='final-price' align='right'>".az_thousand_separator($value->final_price)."</td>";
                echo "</tr>";    
            }
		?>
	</table>
	<div style="min-height: 70px;margin-bottom:10px;" class="separate"></div>
	<table width="100%">
		<tr>
			<td valign="top" width="70%">
				<div>Brg yg dibeli tdk dpt dikembalikan, kecuali dg perjanjian.</div>
				<table width="100%">
					<tr>
						<td>Hormat Kami,</td>
						<td>Yang Menerima,</td>
						<td>Yang Mengirim,</td>
					</tr>
				</table>
			</td>
			<td valign="top">
				<table width="100%">
					<tr>
						<td>Grand Total</td>
						<td>:</td>
						<td>Rp</td>
						<td align="right"><?php echo az_thousand_separator($data->total_sell_price);?></td>
					</tr>
					<tr>
						<td>Diskon</td>
						<td>:</td>
						<td>Rp</td>
						<td align="right"><?php echo az_thousand_separator($data->total_discount);?></td>
					</tr>
					<tr>
						<td>PPN</td>
						<td>:</td>
						<td>Rp</td>
						<td align="right">0</td>
					</tr>
					<tr>
						<td colspan="4">
							<div class="separate"></div>
						</td>
					</tr>
					<tr>
						<td>Harga Netto</td>
						<td>:</td>
						<td>Rp</td>
						<td align="right"><?php echo az_thousand_separator($data->total_final_price);?></td>
					</tr>
					<tr>
                        <td>
                            <?php echo azlang('Pay');?>
                        </td>
                        <td>:</td>
						<td>Rp</td>
                        <td align="right">
                            <?php echo az_thousand_separator($data->total_cash);?>
                        </td>
                    </tr>
					<tr>
                        <td>
                            <?php 
                                if ($data->payment_type == 'cash') {
                                    echo 'Kembalian';
                                }
                                else {
                                    echo 'Kekurangan';
                                }
                            ?>
                        </td>
                        <td>:</td>
						<td>Rp</td>
                        <td align="right">
                            <?php echo az_thousand_separator($data->total_change);?>
                        </td>
                    </tr>
				</table>
			</td>
		</tr>
	</table>

</body>
</html>

<script type="text/javascript">
    var type = "<?php echo $type;?>";
    if (type == 'back') {
        document.body.onkeydown = function(e){
            location.href = "<?php echo app_url();?>" + "transaction";
        };        
    }
    else {
        document.body.onkeydown = function(e){
            location.href = "<?php echo app_url();?>" + "transaction_list";
        };
    }
</script>