<?php

include 'load.php';

?>

<!DOCTYPE html>
<html lang="en">

<head>

	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
	<meta name="description" content="POS - Payroll | Pos & Invetory System | Dashboard

">
	<meta name="keywords" content="Payroll | Pos & Invetory System | Dashboard

">
	<meta name="author" content="Payroll | Pos & Invetory System | Dashboard

">
	<meta name="robots" content="noindex, nofollow">

	<title>View Sales Items List | Payroll | Pos & Invetory System | Dashboard

</title>

	<?php
	require_once 'headercss.php';
	?>
</head>

<body>

	<div class="main-wrapper">
		<?php
		require_once 'header.php';
		?>

		<?php
		require_once 'navbar.php';
		?>

		<div class="page-wrapper">
			<div class="content">
				<div class="page-header">
					<div class="page-title">
						<h4>View Sales Items List</h4>
						<h6>Manage your sales</h6>
					</div>
				</div>

				<div class="card">
					<div class="card-body">
						<div class="table-top">
							<div class="search-set">

							</div>
							<div class="wordset">

							</div>
						</div>

						<div class="table-responsive">
							<table class="table" id="betable">
								<thead>
										<th>#ID</th>
										<th>Item Name/Code</th>
										<th>Status</th>
										<th>Actual Amount</th>
										<th>Cost Price</th>
										<th>Sell Price</th>
										<th>Qty</th>
										<th>Per Discount</th>																				
										<th>Sell Amount</th>
										<th>Total Discount</th>
										<th>Total</th>
									</tr>
								</thead>
								<tbody>
									<?php
									if (isset($_GET['order_id'])) {
										$order_id = $_GET['order_id'];																				
										$totalrowdisamount="0";										
										$totalrowamount="0";
										$sql = "SELECT * FROM mobiletemporarycart LEFT JOIN mobileproducts ON mobileproducts.prid=mobiletemporarycart.proid
										WHERE mobiletemporarycart.orderid='$order_id' GROUP BY mobiletemporarycart.proid,mobiletemporarycart.pro_dis ORDER BY mobiletemporarycart.tempid DESC";

										$result = $conn->query($sql);
										$rowCount = 0;
										$pamount = 0;
										$total_discount = 0;
										$total_amount = 0;
										if ($result->num_rows > 0) {
											while ($row = $result->fetch_assoc()) {
												$rowCount = $rowCount + 1;
												$tempid = $row["tempid"];
												$proid = $row["proid"];
												$pro_name = $row["proname"];
												$cover = $row["cover"];
												$costprice = $row["price"];	
												$sellprice = $row["sellprice"];	
												$pro_price = $row["pro_price"];																								
												$pro_dis_price = $row["pro_dis_price"];
												$pro_discount = $row["pro_discount"];
												$pro_qty = $row["pro_qty"];
												$totaldiscount=$pro_qty * $pro_discount;
												//$pamount = $pro_dis_price * $pro_qty;
												$total_discount = $total_discount + $pro_discount;
												$total_amount = $pro_dis_price * $pro_qty;																								
												$totalrowdisamount=$totalrowdisamount+$totaldiscount;												
												$totalrowamount=$totalrowamount+$total_amount;
												?>
												<tr>
													<td>#<?php echo $tempid; ?></td>
													<td><?php echo $pro_name; ?>(<?php echo $row["prcode"]; ?>) | <?php echo number_format((float) $pro_price, 2); ?> X <?php echo number_format((int)$pro_qty); ?></td>
													<td><?php 
														if($pro_qty==0){
															echo '<a class="badges bg-secondary text-white">Return</a>';
														}else{
															echo '<a class="badges bg-success text-white">Issued</a>';
														}
													
													?></td>
													<td><?php echo number_format((float) $pro_price, 2); ?></td>
													<td><?php echo number_format((float) $costprice, 2); ?></td>
													<td><?php echo number_format((float) $sellprice, 2); ?></td>
													<td><?php echo number_format((int)$pro_qty); ?></td>
													<td><?php echo number_format((int)$pro_discount); ?></td>																										
													<td><?php echo number_format((int)$pro_dis_price); ?></td>
													<td><?php echo number_format((int)$totaldiscount); ?></td>
													<td><?php echo number_format((float) $total_amount, 2); ?></td>
												<?php
											}
										}
									}
									?>
								</tbody>
								<tfoot style="background-color:#008b0b;color:#ffffff;">									
								<tr>										
								<th></th>										
								<th></th>										
								<th></th>										
								<th></th>										
								<th></th>
								<th></th>										
								<th></th>	
								<th></th>	
								<th><strong>All Total</strong></th>										
								<th>Rs.<?php echo number_format((float)$totalrowdisamount,2); ?></th>										
								<th>Rs.<?php echo number_format((float)$totalrowamount,2); ?></th>									
								</tr>								
								</tfoot>
							</table>
						</div>
					</div>
				</div>

			</div>
		</div>
	</div>

	<!-- end -->

	<script>
		function printDiv(printableArea) {

			var printContents = document.getElementById(printableArea).innerHTML;
			var originalContents = document.body.innerHTML;

			document.body.innerHTML = printContents;

			window.print();

			document.body.innerHTML = originalContents;

		}
	</script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.1.0-rc.0/js/select2.min.js"></script>

	
	
	<script data-cfasync="false" src="../../cdn-cgi/scripts/5c5dd728/cloudflare-static/email-decode.min.js"></script>
							
	<script src="assets/js/jquery-3.6.0.min.js"></script>

	<script src="assets/js/feather.min.js" defer></script>

	<script src="assets/js/jquery.slimscroll.min.js" defer></script>

	<script src="assets/js/jquery.dataTables.min.js"></script>
	<script src="assets/js/buttons.dataTables.js"></script>
	<script src="assets/js/dataTables.bootstrap4.min.js"></script>

	<script src="assets/js/bootstrap.bundle.min.js" defer></script>

	<script src="assets/js/moment.min.js" defer></script>
	<script src="assets/js/bootstrap-datetimepicker.min.js"></script>
	<script src="assets/js/pdfmake.min.js"></script>
	<script src="assets/plugins/select2/js/select2.min.js" defer></script>
	<script src="assets/js/vfs_fonts.js" defer></script>

	<script src="assets/plugins/sweetalert/sweetalert2.all.min.js" defer></script>
	<script src="assets/plugins/sweetalert/sweetalerts.min.js" defer></script>
	<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js" defer></script>
	<script src="assets/js/dataTables.buttons.min.js"></script>
	<script src="assets/js/jszip.min.js" defer></script>
	<script src="assets/js/buttons.html5.min.js" defer></script>
	<script src="assets/js/script.js"></script>
	
	<link href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css" rel="stylesheet">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
	<script>
	// Initialize Select2 plugin with typing search functionality
	$('.select2').select2();
	</script>
	<script>
		

		$(document).ready( function() {
			$('#betable').DataTable({
        dom: 'Bfrtip', 
        buttons: [
            'copy', 
            'csv',  
            {
                extend: 'excelHtml5', 
                customize: function(xlsx) {
                    var sheet = xlsx.xl.worksheets['sheet1.xml']; 
                    $('row c[r^="C"]', sheet).attr('s', '2'); 
                }
            },
            'pdf',  
            'print' 
        ]
    });
	} );
	</script>
	
	<style>
	#betable_filter{
		margin-bottom: 20px;
	}
	</style>

	
</body>

</html>