<?php 
	$total_change = $data['total_pay'] - $data['grand_total_final'];
	if ($data['payment_status'] == 'PANJAR') {
		$total_change = $data['total_pay'] - $data['total_panjar'];
	}
?>
<!DOCTYPE html>
<html>
<head>
	<title>Bill</title>
	<style type="text/css">
		body {
			width: 80mm;
			/*border: 1px solid black;*/
			font-family: 'helvetica';
			font-size: 12px;
		}
		.tr-note td.lbl{
			font-size: 10px;
		}
	</style>
	<script type="text/javascript" src="<?php echo base_url(); ?>assets/plugins/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="<?php echo base_url(); ?>assets/plugins/barcode/barcode.js"></script>
</head>
<body onload="window.print();">
	<div style="vertical-align: middle;">
		<?php
			if (@$type != 'old') {
		?>
		<div style="display: inline-block;vertical-align: middle;">
			<img style="display:inline-block" src="https://quickchart.io/qr?size=80&text=<?php echo $data['code'];?>">
		</div>
		<div style="display: inline-block;vertical-align: middle;">
			<div id="barcode"></div>
			<div align="center">
			   <div style="font-size:16px">
			    	<?php echo $data['code'];?>
			   </div>
			</div>
		</div>
		<?php
			}
			else {
		?>
	  <!--<div style="margin-top:25px;">
		   <div align="center">
			   <div style="font-size:16px">
		         <?php echo $data['code'];?><br>
		       </div>
		   </div>
		<?php
		?>
		<div align="center">
		Diprint pada tanggal: <?php echo Date('d-m-Y').' Jam: '.Date('H:i');?>
		</div>
	  </div>
	</div>
	<hr>-->
   <div style="margin-top:25px;">
	<div align="center">
	        <div style="font-weight:bold;font-size: 20px">
			    STOPWASH <br>
		    </div>
		<div style="font-size: 12px">
			<?php echo $outlet['outlet_name'];?>
		</div>
		<?php 
			echo $outlet['address']."<br>";
			echo $outlet['phone'];
		?>
	</div>
	<hr>
		   <div align="center">
			   <div style="font-weight:bold;font-size:16px">
		         <?php echo $data['code'];?><br>
		       </div>
		   </div>
		<?php
			}
		?>
		<div align="center">
		Diprint pada tanggal: <?php echo Date('d-m-Y').' Jam: '.Date('H:i');?>
		</div>
	  </div>
	</div>
	<div style="margin-top:5px;">
		<table>
			<tr>
				<td valign="top">Nama</td>
				<td valign="top" width="10px" align="center">:</td>
				<td valign="top"><?php echo $data['customer_name'];?></td>
			</tr>
			<tr>
				<td valign="top">No HP</td>
				<td valign="top" width="10px" align="center">:</td>
				<td valign="top"><?php  $phone = $data['customer_phone'];$maskedPhone = substr($phone, 0, -4) . '****';echo $maskedPhone;?></td>
			</tr>
			<tr>
				<td valign="top">Alamat</td>
				<td valign="top" width="10px" align="center">:</td>
				<td valign="top"><?php  echo $data['customer_address'];?></td>
			</tr>
			<tr>
				<td valign="top">Tgl Transaksi</td>
				<td valign="top" width="10px" align="center">:</td>
				<td valign="top"><?php echo Date('d-m-Y H:i', strtotime($data['date']));?></td>
			</tr>
		</table>
	</div>
	<div style="margin-top:5px;">
		<table>
			<?php 
				$tot = count($trx);
				$lack = 0;
				if ($data['total_panjar'] > 0) {
					$lack = $data['grand_total_final'] - $data['total_panjar'];
				}
				foreach ($trx as $key => $value) {
			?>
			<tr>
				<td valign="top"><?php echo ($key + 1).'/'.$tot;?>
				<td valign="top"><?php echo $value['product_name'];?></td>
				<td valign="top" style="padding-left:20px;"><?php echo $value['colour'].'. '.$value['hue'].'. '.$value['spot'];?></td>
				<td valign="top" width="60px" align="right">Rp <?php echo az_thousand_separator($value['price']);?></td>
			</tr>
			<?php 
					foreach ((array) $value['arr_cost'] as $cost_key => $cost_value) {
			?>
			<tr class="tr-note">
				<td></td>
				<td colspan="2" class="lbl">+<?php echo $cost_value['name'];?></td>
				<td align="right">Rp <?php echo az_thousand_separator($cost_value['price']);?></td>
			</tr>
			<?php
					}
			?>
			<?php 
				if (strlen($value['trx_note']) > 0) {
			?>
			<tr class="tr-note hide">
				<td></td>
				<td colspan="3" class="lbl">Ket: <?php echo $value['trx_note'];?></td>
			</tr>
			<?php
				}
			?>
			<tr>
				<td colspan="4"></td>
			</tr>
			<?php
				}
			?>	
		</table>
	</div>
	<div style="margin-top:3px">
		<table width="100%">
			<tr>
				<td valign="top" width="50%">
					<div style="font-size:18px;font-weight: bold"><?php echo $data['payment_status'];?></div>
					<div style="font-size:14px;">Tgl Selesai:<br><?php echo Date('d-m-Y H:i', strtotime($data['duedate']));?></div>
				</td>
				<td valign="top">
					<table width="100%" cellpadding="0" cellspacing="0">
						<?php
							if ($data['grand_discount'] > 0 || $data['grand_add_cost'] > 0) {
						?>
						<tr>
							<td align="right" width="100px">Subtotal</td>
							<td width="10px"></td>
							<td align="right"><?php echo az_thousand_separator($data['grand_total']);?></td>
						</tr>
						<?php
								if ($data['grand_discount'] > 0) {
						?>
						<tr>
							<td align="right" width="100px">Diskon</td>
							<td width="10px"></td>
							<td align="right"><?php echo az_thousand_separator($data['grand_discount']);?></td>
						</tr>
						<?php
								}
						?>
						<?php
								if ($data['grand_add_cost'] > 0) {
						?>
						<tr>
							<td align="right" width="100px"><?php echo $data['add_cost_note'];?></td>
							<td width="10px"></td>
							<td align="right"><?php echo az_thousand_separator($data['grand_add_cost']);?></td>
						</tr>
						<?php
								}
						?>
						<?php
							}
						?>
						<tr>
							<td align="right" width="100px">Total Tagihan</td>
							<td width="10px"></td>
							<td align="right"><?php echo az_thousand_separator($data['grand_total_final']);?></td>
						</tr>
						<?php 
							if ($data['payment_status'] == 'PANJAR') {
						?>
						<tr>
							<td align="right">Panjar</td>
							<td></td>
							<td align="right"><?php echo az_thousand_separator($data['total_panjar']);?></td>
						</tr>
						<?php
							}
							if ($data['payment_status'] != 'BELUM BAYAR') {
						?>
						<tr>
							<td align="right">Bayar</td>
							<td></td>
							<td align="right"><?php echo az_thousand_separator($data['total_pay']);?></td>
						</tr>
						<tr>
							<td align="right">Kembalian</td>
							<td></td>
							<td align="right"><?php echo az_thousand_separator($total_change);?></td>
						</tr>
						<?php
							}
						?>
					</table>
				</td>
			</tr>
			<?php
				if ($lack > 0) {
			?>
			<tr>
				<td colspan="2">
					<div style="text-align:center;font-size:14px;font-weight:bold;margin-top:10px;">SISA PEMBAYARAN: Rp <?php echo az_thousand_separator($lack);?></div>
				</td>
			</tr>
			<?php
				}
			?>
			<?php
				$txt_setuju = 'bawah';
				if (@$type == 'old') {
					$txt_setuju = 'belakang';
				}
			?>
			<tr>
				<td>
					<div style="margin-top:15px" align="center">
						(<?php echo $data['customer_name'];?>)
						<div style="font-size:10px">Telah menyetujui semua ketentuan di <?php echo $txt_setuju;?> ini</div>
					</div>
				</td>
				<td align="right" valign="bottom">
					CS: <?php echo $data['cashier_name'];?>
				</td>
			</tr>
		</table>
	</div>

	<?php
		if (@$type != 'old') {
	?>
	<div style="margin-top:20px;font-size:12px;">
		<?php echo az_get_config('app_footer_nota');?>
	</div>
	<?php
		}
	?>
</body>
</html>

<script type="text/javascript">
    $("#barcode").barcode("<?php echo $data['code'];?>", "code128", {barWidth:1, barHeight:30, output:"bmp", bgColor:"white", showHRI:false}); 
        
    $("#barcode object").css("width", "100%");
    $("#barcode object").css("height", "30px");
</script>