<?php
	include("includes/dbconfig.php");
	$thedate = "2023-08%";
?>
<!DOCTYPE html>
<html>
	<head>
	<meta charset="UTF-8">
	<title>Sales Receipt</title>
	<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
	<!-- Bootstrap 3.3.2 -->
	<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
	<!-- Font Awesome Icons -->
	<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
	<!-- Ionicons -->
	<link href="http://code.ionicframework.com/ionicons/2.0.0/css/ionicons.min.css" rel="stylesheet" type="text/css" />
	<!-- Theme style -->
	<link href="dist/css/AdminLTE.min.css" rel="stylesheet" type="text/css" />
	<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
	<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
	<!--[if lt IE 9]>
	<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
	<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
	<![endif]-->
	</head>
	<!-- 
	<body onload="location.href='shopreceiptsview.php'; window.print();"> -->
	<body onload="  window.print()x;"> 
		<div class="wrapper">
		    <div class="wrapper">
			<!-- Main content -->
			<section class="content">
		    <?php
	$therecipts = DB::query('SELECT cash_receipt.id, shop.full_name, shop.logo_file, shop.address_line_1, shop.address_line_2, shop.address_line_3, shop.zip_code, shop.city, shop.country, tin, shop.phone, shop.fax, shop.email, personnel_details.display_name, personnel_details.first_name, cash_receipt.created_date, cash_receipt.value_date, cash_receipt.receipt_number, cash_receipt.customer_name, cash_receipt.amount, cash_receipt.customer_change, cash_receipt.memo, cash_receipt.is_cancelled FROM cash_receipt LEFT JOIN  personnel_details ON cash_receipt.created_by = personnel_details.id LEFT JOIN shop ON cash_receipt.shop = shop.id WHERE cash_receipt.id >0' );	 
	foreach($therecipts as $receipt){
		$receiptitems = DB::query("SELECT stock_item.item_name, stock_item.item_code, stock_item.bar_code, stock_item.alt_barcode, cash_sale_item.sell_price, cash_sale_item.quantity, cash_sale_item.serial_number FROM cash_sale_item INNER JOIN item_price ON cash_sale_item.price_id = item_price.id INNER JOIN stock_item ON item_price.item = stock_item.id WHERE cash_sale_item.receipt=%i", $receipt['id']);
		?>
			 <div class="row">
				<div class="col-sm-3">
		<table>
						<tr>
							<td style="vertical-align:top; width: 35%">
							</td>
							<td style="vertical-align:top; width: 35%">
								<div class="text-center" style="height: 60px width: 60px">
								<img class="img-thumbnail" id="itemphoto" src="<?php echo ($receipt['logo_file'] != "") ? "images/shoplogos/" . $receipt['logo_file'] : "images/shoplogos/noimage.gif" ?>" alt="..." width="100%"; height="100%" >
								</div>
							</td>
							<td class="pull-right" style="vertical-align:top; width: 30%">
							</td>
						</tr>
					</table>
						<div class="text-center">
						<b><font face="Arial" size="1"><?php echo $receipt['full_name']; ?></font></b><br>
						<font face="Arial" size="1"><?php echo $detailedreceiptaddress; ?></font>
						<font face="Arial" size="1"><?php echo $detailedcontactinfo; ?></font>
						<font face="Arial" size="1">TIN: <?php echo $receipt['tin']; ?></font><br>
						<font face="Arial" size="1">SALES: <?php echo $receipt['customer_name']; ?></font><br>
						<font face="Arial" size="1">Receipt No:<?php echo $receipt['receipt_number']; ?></font><br>
						<font face="Arial" size="1">Date: <?php echo date("d-m-Y H:i", strtotime($receipt['created_date'])); ?></font>
					</div>
					<table style="width: 100%; margin: 0 auto;">
						<tr>
							<td class="text-center" colspan="4" >
								<font face="Arial" size="1">
									---------------------------------------------------------------------
								</font>
							</td>
						</tr>
						<tr>
							<td><font face="Arial" size="1"><b>Item</b></font></td>
							<td class="text-center"><font face="Arial" size="1"><b>Qty</b></font></td>
							<td class="text-right"><font face="Arial" size="1"><b>Price</b></font></td>
							<td class="text-right"><font face="Arial" size="1"><b>Amount</b></font></td>
						</tr>
						<tr>
							<td class="text-center" colspan="4" >
								<font face="Arial" size="1">
									---------------------------------------------------------------------
								</font>
							</td>
						</tr>											
						<?php
							$itemscount = 0;
							$itemstotalcost = 0;
							foreach($receiptitems as $receiptrow)
							{  
								$userowtotal = ($receiptrow['quantity'] * $receiptrow['sell_price']);
								$itemscount += $receiptrow['quantity'];
								$itemstotalcost += $userowtotal;
						?>
						<tr>
							<td colspan="4" ><font face="Arial" size="1"><?php echo substr($receiptrow['item_name'], 0, 30); ?></font></td>
						</tr>
						<tr>
							<!--<td><font face="Arial" size="1"><?php echo substr($receiptrow['item_name'], 0, 15); ?></font></td>-->
							<td></td>
							<td class="text-center"><font face="Arial" size="1"><?php echo $receiptrow['quantity']; ?></font></td>
							<td class="text-right"><font face="Arial" size="1"><?php echo number_format($receiptrow['sell_price'], 2); ?></font></td>
							<td class="text-right"><font face="Arial" size="1"><?php echo number_format($userowtotal, 2); ?></font></td>
						</tr>
						<?php
								if($receiptrow['serial_number'] != "")
								{
						?>
						<tr>
							<td class="text-center" colspan="4" ><font face="Arial" size="1"><?php echo "Serial: ".$receiptrow['serial_number']; ?></font></td>
						</tr>
						<?php
								}
							}
						?>
						<tr>
							<td class="text-center" colspan="4" >
								<font face="Arial" size="1">
									---------------------------------------------------------------------
								</font>
							</td>
						</tr>
						<tr>
							<td><font face="Arial" size="1"><b>Totals</b></font></td>
							<td class="text-center"><font face="Arial" size="1"><b><?php echo $itemscount; ?></b></font></td>
							<td class="text-right"></td>
							<td class="text-right"><font face="Arial" size="1"><b><?php echo number_format($itemstotalcost, 2); ?></b></font></td>
						</tr>
					</table>
					<table style="width: 100%; margin: 0 auto;">
						<tr>
							<td class="lead"><b><font face="Arial" size="1">Paid</font></b></td>
							<td class="text-center lead"><b><font face="Arial" size="1">:</font></b></td>
							<td class="text-right lead"><b><font face="Arial" size="1"><?php echo number_format($receipt['amount'], 2); ?></font></b></td>
						</tr>
						<tr>
							<td class="lead"><b><font face="Arial" size="1">Change</font></b></td>
							<td class="text-center lead"><b><font face="Arial" size="1">:</font></b></td>
							<td class="text-right lead"><b><font face="Arial" size="1"><?php echo number_format($receipt['customer_change'], 2); ?></font></b></td>
						</tr>
						<tr>
							<td class="text-center" colspan="3" >
								<font face="Arial" size="1">
									---------------------------------------------------------------------
								</font>
							</td>
						</tr>
					</table>
					<div class="text-center">
						<font face="Arial" size="1">Goods once sold will not be taken back or exchanged</font><br>
						<font face="Arial" size="1">Thank you. Please come again.</font><br>
						<font face="Arial" size="1">Served By: <?php echo $receipt['display_name']; ?></font><br>
						<font face="Arial" size="1">
							xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx<br>
							<h1> <br /></h1>
							 
						</font>
					</div>
				</div>
			</div>		
		<?php
	}
exit();	
?>
	</section>
</div>
					</div>
					</body>
					</html>