<?php

include 'load.php';

require_once 'db_connection.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>Delivery Label | 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';
?>
<?php 
	
if (isset($_GET['receiptno']))	
{
	
$order_id=$_GET['receiptno'];
$total_discount = 0;
$stmt2 = $DB_con->prepare("SELECT o.order_id,o.pay_option,o.amount,o.card_no,o.customer,o.user_id,o.create_at,o.status ostatus,t.tempid,t.orderid torderid,t.proid,t.pro_price,t.pro_dis,t.pro_qty,t.user_id tuser_id FROM mobileorders o INNER JOIN mobiletemporarycart t ON o.order_id=t.orderid  WHERE o.order_id='".$_GET['receiptno']."' group BY o.order_id DESC");

$stmt2->execute();

if($stmt2->rowCount() > 0)

{

while($row2=$stmt2->fetch(PDO::FETCH_ASSOC))

{

extract($row2);

?>				
<div class="page-wrapper">
<div class="content">
<div class="page-header">
<div class="page-title">
<h4>Sales Receipt</h4>
<h6>View Sales Receipt</h6>
</div>
</div>
<div class="card">
<div class="card-body">
<div class="card-sales-split">
<h2>Date/Time : <?php echo date_format(date_create($row2['create_at']),"M d, Y | h:i:s "); ?></h2>
<ul>
<li>
<?php

$stmt4 = $DB_con->prepare('SELECT * FROM mobilesettings where status="1" ORDER BY stid');

$stmt4->execute();

if($stmt4->rowCount() > 0)

{

while($row4=$stmt4->fetch(PDO::FETCH_ASSOC))

{

extract($row4);

?>
<p class="text-center" style="font-weight;color:#2ecc40;"><?php if($row4['systemlogo']==""){$pro_img="assets/img/empty.png";}else{$pro_img="images/settings/".$row4['systemlogo'];} ?>
<img src="<?php echo $pro_img; ?>" alt="<?php echo $row4['systemname']; ?>" style="width:100px;" /></p>
<?php 
} 
}
?>								
</li>
<li>
<h3 class="text-center" style="font-weight:bold;color:#000000;">Brandz Root</h3>
</li>
<li>
<a href="javascript:void(0);"><img src="https://seoprodesigner.com/vishanpos/assets/img/icons/pdf.svg" alt="img"></a>
</li>
<li>
<a href="javascript:void(0);"><img src="https://seoprodesigner.com/vishanpos/assets/img/icons/excel.svg" alt="img"></a>
</li>
<li>
<a href="javascript:void(0);"><img src="assets/img/icons/printer.svg" alt="img" onclick="printDiv('printableArea')"></a>
</li>
</ul>
</div>
<div class="invoice-box table-height" style="max-width: 1600px;width:100%;overflow: auto;margin:15px auto;padding: 0;font-size: 14px;line-height: 24px;color: #555;">
<table cellpadding="0" cellspacing="0" style="width: 100%;line-height: inherit;text-align: left;">
<tbody><tr class="top">
<td colspan="6" style="padding: 5px;vertical-align: top;">
<table style="width: 100%;line-height: inherit;text-align: left;">
<tbody><tr>
<td style="padding:5px;vertical-align:top;text-align:left;padding-bottom:20px">
<font style="vertical-align: inherit;margin-bottom:25px;"><font style="vertical-align: inherit;font-size:14px;color:#7367F0;font-weight:600;line-height: 35px; ">Customer Info</font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> <?php
if($row2['customer'] == "0"){
	
?>	
<p>Walk-in Customer</p>
 <?php	
}else if($row2['customer'] == "dc"){
?>	
<p>Delivery Customer</p>
 <?php	
}else{
?>
<?php

												$id = $row2['customer'];  

												$query = $DB_con->prepare('SELECT cname FROM mobilecustomers WHERE coid='.$id);

												$query->execute();

												$result = $query->fetch();

												echo $result['cname'];

												?></font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> <?php

												$id = $row2['customer'];  

												$query = $DB_con->prepare('SELECT cphone FROM mobilecustomers WHERE coid='.$id);

												$query->execute();

												$result = $query->fetch();

												echo $result['cphone'];

												?></font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> <?php

												$id = $row2['customer'];  

												$query = $DB_con->prepare('SELECT caddress FROM mobilecustomers WHERE coid='.$id);

												$query->execute();

												$result = $query->fetch();

												echo $result['caddress'];

												?></font></font><br>
<?php	
}
?>
</td>

<td style="padding:5px;vertical-align:top;text-align:left;padding-bottom:20px">
<font style="vertical-align: inherit;margin-bottom:25px;"><font style="vertical-align: inherit;font-size:14px;color:#7367F0;font-weight:600;line-height: 35px; ">Shop Info</font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> Brandz Root</font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> 0112 044 080</font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> Info@brandzroot.lk</font></font><br>
</td>
<td style="padding:5px;vertical-align:top;text-align:left;padding-bottom:20px">
<font style="vertical-align: inherit;margin-bottom:25px;"><font style="vertical-align: inherit;font-size:14px;color:#7367F0;font-weight:600;line-height: 35px; ">Invoice Info</font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> Order ID</font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> Payment Status</font></font><br>
 <font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> Status</font></font><br>
</td>
<td style="padding:5px;vertical-align:top;text-align:right;padding-bottom:20px">
<font style="vertical-align: inherit;margin-bottom:25px;"><font style="vertical-align: inherit;font-size:14px;color:#7367F0;font-weight:600;line-height: 35px; ">&nbsp;</font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: bold;">#<?php echo $row2['order_id']; ?></font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#2E7D32;font-weight: bold;"> 
<?php 
						
if($row2['pay_option'] == "cash"){

echo 'Pay By Cash';

}else if($row2['pay_option'] == "card"){

echo 'Pay By Card';

}else if($row2['pay_option'] == "credit"){

echo 'Pay By Credit';

}
											
?>
</font>
</font>
<br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#2E7D32;font-weight: bold;">
<?php 
						
if($row2['ostatus'] == "1"){

echo 'Completed';

}else if($row2['ostatus'] == "0"){

echo 'Pending';

}
											
?>
</font>
<br>
</td>
</tr>
</tbody></table>
</td>
</tr>
<tr class="heading " style="background: #F3F2F7;">
<td style="padding: 5px;vertical-align: middle;font-weight: 600;color: #5E5873;font-size: 14px;padding: 10px; ">
Product Name
</td>
<td style="padding: 5px;vertical-align: middle;font-weight: 600;color: #5E5873;font-size: 14px;padding: 10px; ">
QTY
</td>
<td style="padding: 5px;vertical-align: middle;font-weight: 600;color: #5E5873;font-size: 14px;padding: 10px; ">
Price
</td>
<td style="padding: 5px;vertical-align: middle;font-weight: 600;color: #5E5873;font-size: 14px;padding: 10px; ">
Discount
</td>
<td style="padding: 5px;vertical-align: middle;font-weight: 600;color: #5E5873;font-size: 14px;padding: 10px; ">
Subtotal
</td>
</tr>


<?php
$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;
				$proid = $row["proid"];
				$proname = $row["proname"];
				$cover = $row["cover"];
				$pro_price = $row["pro_price"];
				$pro_dis = $row["pro_dis"];
				$pro_qty = $row["pro_qty"];
				$pamount = ($pro_price * $pro_qty) - $pro_dis;
				$total_discount = $total_discount + $pro_dis;
				$total_amount = $total_amount + $pamount;
				
			?>

<tr class="details" style="border-bottom:1px solid #E9ECEF ;">
<td style="padding: 10px;vertical-align: top; display: flex;align-items: center;">
<?php if($cover==""){$pro_img="https://seoprodesigner.com/vishanpos/assets/img/empty.png";}else{$pro_img="https://seoprodesigner.com/vishanpos/images/products/cover/".$cover;} ?><img src="<?php echo $pro_img; ?>" alt="img" class="me-2" style="width:40px;height:40px;">
<?php echo $proname; ?>
</td>
<td style="padding: 10px;vertical-align: top; ">
<?php echo $pro_qty; ?>
</td>
<td style="padding: 10px;vertical-align: top; ">
<?php echo number_format((float)$pro_price,2); ?>
</td>
<td style="padding: 10px;vertical-align: top; ">
<?php echo $pro_dis; ?>
</td>
<td style="padding: 10px;vertical-align: top; ">
<?php echo number_format((float)$pamount,2); ?>
</td>
</tr>
<?php } } ?>
</tbody></table>
</div>
<div class="row">
<div class="col-lg-6 ">
<div class="total-order w-100 max-widthauto m-auto mb-4">
<ul>
<li>
<h4>Discount</h4>
<h5>Rs.<?php echo number_format((float)$total_discount,2); ?></h5>
</li>
</ul>
</div>
</div>
<div class="col-lg-6 ">
<div class="total-order w-100 max-widthauto m-auto mb-4">
<ul>
<li class="total">
<h4>Grand Total</h4>
<h5>Rs.<?php echo number_format((float)$total_amount,2); ?></h5>
</li>
</ul>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-3">
<a class="btn btn-secondary btn-block" href="home.php">BACK TO HOME</a>
</div>
<div class="col-lg-3">
<button class="btn btn-success btn-block" onclick="printDiv('printableArea')">PRINT POS</button>
</div>
</div>
</div>
</div>
<div id="printableArea" style="display:none;">
<div class="card">
<div class="card-body">
<div class="card-sales-split">
<h2>Date/Time : <?php echo date_format(date_create($row2['create_at']),"M d, Y | h:i:s "); ?></h2>
<ul>
<li>
<?php

$stmt4 = $DB_con->prepare('SELECT * FROM mobilesettings where status="1" ORDER BY stid');

$stmt4->execute();

if($stmt4->rowCount() > 0)

{

while($row4=$stmt4->fetch(PDO::FETCH_ASSOC))

{

extract($row4);

?>
<p class="text-center" style="font-weight;color:#2ecc40;"><?php if($row4['systemlogo']==""){$pro_img="https://seoprodesigner.com/vishanpos/assets/img/empty.png";}else{$pro_img="https://seoprodesigner.com/vishanpos/images/settings/".$row4['systemlogo'];} ?>
<img src="<?php echo $pro_img; ?>" alt="<?php echo $row4['systemname']; ?>" style="width:100px;" /></p>
<?php 
} 
}
?>								
</li>
<li>
<h3 class="text-center" style="font-weight:bold;color:#000000;">Brandz Root</h3>
</li>
</ul>
</div>
<div class="invoice-box table-height" style="max-width: 1600px;width:100%;overflow: auto;margin:15px auto;padding: 0;font-size: 14px;line-height: 24px;color: #555;">
<table cellpadding="0" cellspacing="0" style="width: 100%;line-height: inherit;text-align: left;">
<tbody><tr class="top">
<td colspan="6" style="padding: 5px;vertical-align: top;">
<table style="width: 100%;line-height: inherit;text-align: left;">
<tbody><tr>
<td style="padding:5px;vertical-align:top;text-align:left;padding-bottom:20px">
<font style="vertical-align: inherit;margin-bottom:25px;"><font style="vertical-align: inherit;font-size:14px;color:#7367F0;font-weight:600;line-height: 35px; ">Customer Info</font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> <?php
if($row2['customer'] == "0"){
	
?>	
<p>Walk-in Customer</p>
 <?php	
}else if($row2['customer'] == "dc"){
?>	
<p>Delivery Customer</p>
 <?php	
}else{
?>
<?php

												$id = $row2['customer'];  

												$query = $DB_con->prepare('SELECT cname FROM mobilecustomers WHERE coid='.$id);

												$query->execute();

												$result = $query->fetch();

												echo $result['cname'];

												?></font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> <?php

												$id = $row2['customer'];  

												$query = $DB_con->prepare('SELECT cphone FROM mobilecustomers WHERE coid='.$id);

												$query->execute();

												$result = $query->fetch();

												echo $result['cphone'];

												?></font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> <?php

												$id = $row2['customer'];  

												$query = $DB_con->prepare('SELECT caddress FROM mobilecustomers WHERE coid='.$id);

												$query->execute();

												$result = $query->fetch();

												echo $result['caddress'];

												?></font></font><br>
<?php	
}
?>
</td>

<td style="padding:5px;vertical-align:top;text-align:left;padding-bottom:20px">
<font style="vertical-align: inherit;margin-bottom:25px;"><font style="vertical-align: inherit;font-size:14px;color:#7367F0;font-weight:600;line-height: 35px; ">Shop Info</font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> Brandz Root</font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> 0112 044 080</font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> Info@brandzroot.lk</font></font><br>
</td>
<td style="padding:5px;vertical-align:top;text-align:left;padding-bottom:20px">
<font style="vertical-align: inherit;margin-bottom:25px;"><font style="vertical-align: inherit;font-size:14px;color:#7367F0;font-weight:600;line-height: 35px; ">Invoice Info</font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> Order ID</font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> Payment Status</font></font><br>
 <font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> Status</font></font><br>
</td>
<td style="padding:5px;vertical-align:top;text-align:right;padding-bottom:20px">
<font style="vertical-align: inherit;margin-bottom:25px;"><font style="vertical-align: inherit;font-size:14px;color:#7367F0;font-weight:600;line-height: 35px; ">&nbsp;</font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: bold;">#<?php echo $row2['order_id']; ?></font></font><br>
<?php 
						
if($row2['pay_option'] == "cash"){

echo 'Pay By Cash';

}else if($row2['pay_option'] == "card"){

echo 'Pay By Card';

}else if($row2['pay_option'] == "credit"){

echo 'Pay By Credit';

}
											
?>
</font>
</font>
<br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#2E7D32;font-weight: bold;">
<?php 
						
if($row2['ostatus'] == "1"){

echo 'Completed';

}else if($row2['ostatus'] == "0"){

echo 'Pending';

}
											
?>
</font>
<br>
</td>
</tr>
</tbody></table>
</td>
</tr>
<tr class="heading " style="background: #F3F2F7;">
<td style="padding: 5px;vertical-align: middle;font-weight: 600;color: #5E5873;font-size: 14px;padding: 10px; ">
Product Name
</td>
<td style="padding: 5px;vertical-align: middle;font-weight: 600;color: #5E5873;font-size: 14px;padding: 10px; ">
QTY
</td>
<td style="padding: 5px;vertical-align: middle;font-weight: 600;color: #5E5873;font-size: 14px;padding: 10px; ">
Price
</td>
<td style="padding: 5px;vertical-align: middle;font-weight: 600;color: #5E5873;font-size: 14px;padding: 10px; ">
Discount
</td>
<td style="padding: 5px;vertical-align: middle;font-weight: 600;color: #5E5873;font-size: 14px;padding: 10px; ">
Subtotal
</td>
</tr>


<?php
$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;
				$proid = $row["proid"];
				$proname = $row["proname"];
				$cover = $row["cover"];
				$pro_price = $row["pro_price"];
				$pro_dis = $row["pro_dis"];
				$pro_qty = $row["pro_qty"];
				$pamount = ($pro_price * $pro_qty) - $pro_dis;
				$total_discount = $total_discount + $pro_dis;
				$total_amount = $total_amount + $pro_price;
				
			?>

<tr class="details" style="border-bottom:1px solid #E9ECEF ;">
<td style="padding: 10px;vertical-align: top; display: flex;align-items: center;">
<?php if($cover==""){$pro_img="https://seoprodesigner.com/vishanpos/assets/img/empty.png";}else{$pro_img="https://seoprodesigner.com/vishanpos/images/products/cover/".$cover;} ?><img src="<?php echo $pro_img; ?>" alt="img" class="me-2" style="width:40px;height:40px;">
<?php echo $proname; ?>
</td>
<td style="padding: 10px;vertical-align: top; ">
<?php echo $pro_qty; ?>
</td>
<td style="padding: 10px;vertical-align: top; ">
<?php echo number_format((float)$pro_price,2); ?>
</td>
<td style="padding: 10px;vertical-align: top; ">
<?php echo $pro_dis; ?>
</td>
<td style="padding: 10px;vertical-align: top; ">
<?php echo number_format((float)$pamount,2); ?>
</td>
</tr>
<?php } } ?>
</tbody></table>
</div>
<div class="row">
<div class="col-lg-6 ">
<div class="total-order w-100 max-widthauto m-auto mb-4">
<ul>
<li>
<h4>Discount</h4>
<h5>Rs.<?php echo number_format((float)$total_discount,2); ?></h5>
</li>
</ul>
</div>
</div>
<div class="col-lg-6 ">
<div class="total-order w-100 max-widthauto m-auto mb-4">
<ul>
<li class="total">
<h4>Grand Total</h4>
<h5>Rs.<?php echo number_format((float)$total_amount,2); ?></h5>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php 
} 
}
}
?>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/Dropify/0.2.2/js/dropify.min.js" integrity="sha512-8QFTrG0oeOiyWo/VM9Y8kgxdlCryqhIxVeRpWSezdRRAvarxVtwLnGroJgnVW9/XBRduxO/z1GblzPrMQoeuew==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<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 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"></script>

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

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

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

<script src="assets/plugins/select2/js/select2.min.js"></script>

<script src="assets/plugins/sweetalert/sweetalert2.all.min.js"></script>
<script src="assets/plugins/sweetalert/sweetalerts.min.js"></script>

<script src="assets/js/script.js"></script>
</body>
</html>