<?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>Purchase Receipt |s Dashboard</title>


<?php
require_once 'headercss.php';
?>
</head>
<body>
<div id="global-loader">
<div class="whirly-loader"> </div>
</div>

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

<?php
require_once 'navbar.php';
?>
<?php 
require_once 'db_connection.php'; 
$quotation_no = $_GET['id'];

$sql = "SELECT *  FROM purchase WHERE q_id = '$quotation_no' ORDER BY q_id  DESC";

		$result = $conn->query($sql);
		$rowCount = 0;
		if ($result->num_rows > 0) {
			while($row = $result->fetch_assoc()) {
				$rowCount = $rowCount+1;
				$q_id = $row["q_id"];
				$q_customer = $row["q_customer"];
				$q_amount = $row["q_amount"];
				$q_user = $row["q_user"];
				$q_date = $row["q_date"];
			}
			}


?>				
<div class="page-wrapper">
<div class="content">
<div class="page-header">
<div class="page-title">
<h4>Purchase Receipt</h4>
<h6>View Purchase Receipt</h6>
</div>
</div>
<div class="card">

<div class="card-body">
<div class="card-sales-split">
<h2>Purchase Number : <?php echo $quotation_no; ?></h2>
<ul>
<li>
<a href="javascript:void(0);"><img src="assets/img/icons/edit.svg" alt="img"></a>
</li>
<li>
<a href="javascript:void(0);"><img src="assets/img/icons/pdf.svg" alt="img"></a>
</li>
<li>
<a href="javascript:void(0);"><img src="assets/img/icons/excel.svg" alt="img"></a>
</li>
<li>
<a href="javascript:void(0);"><img src="assets/img/icons/printer.svg" alt="img"></a>
</li>
</ul>
</div>
<div class="invoice-box table-height" id="printdv" 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; ">Supplier/Vender Info</font></font><br>
<?php

												$id = $q_customer;  

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

												$query->execute();

												$result = $query->fetch();

												echo $result['spname'];

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

												$id = $q_customer;   

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

												$query->execute();

												$result = $query->fetch();

												echo $result['spaddress'];

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

												$id = $q_customer;  

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

												$query->execute();

												$result = $query->fetch();

												echo $result['spphone'];

												?></font></font><br>
<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; ">Company Info</font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> DGT </font></font>
<br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;">6315996770</font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> 3618 Abia Martin Drive</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; ">Purchase Info</font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> Purchase No :  <?php echo $quotation_no; ?></font></font><br>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;font-size: 14px;color:#000;font-weight: 400;"> <?php echo $q_date; ?></font></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; ">
##
</td>
<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
		$total_amount = 0; 

		$sql = "SELECT *  FROM purchase_items LEFT JOIN mobileproducts ON mobileproducts.prid=purchase_items.qi_pro_id
		WHERE purchase_items.qi_no='$purchase_no'  ORDER BY purchase_items.qi_id  ASC";

		$result = $conn->query($sql);
		$rowCount = 0;
		if ($result->num_rows > 0) {
			while($row = $result->fetch_assoc()) {
				$rowCount = $rowCount+1;
				$qi_id = $row["qi_id"];
				$qi_pro_id = $row["qi_pro_id"];
				$proname = $row["proname"];
				$cover = $row["cover"];
				$qi_pro_discount = $row["qi_pro_discount"];
				$qi_pro_price = $row["qi_pro_price"];
				$qi_pro_qty = $row["qi_pro_qty"];

				$discounted_price = ($qi_pro_price/100) * $qi_pro_discount;
				$product_price = ($qi_pro_price - $discounted_price)*$qi_pro_qty;

				$total_amount = $total_amount + $product_price;
				?>

<tr class="details" style="border-bottom:1px solid #E9ECEF ;">
	<td scope="row"><?php echo $rowCount; ?></td>
<td style="padding: 10px;vertical-align: top; display: flex;align-items: center;">
<img src="images/products/cover/<?php echo $cover; ?>" alt="img" class="me-2" style="width:40px;height:40px;">
<?php echo $proname; ?>
</td>
<td style="padding: 10px;vertical-align: top; ">
<?php echo $qi_pro_qty; ?>
</td>
<td style="padding: 10px;vertical-align: top; ">
<?php echo number_format((float)$qi_pro_price,2); ?>
</td>
<td style="padding: 10px;vertical-align: top; ">
<?php echo $qi_pro_discount; ?>%
</td>
<td style="padding: 10px;vertical-align: top; ">
<?php echo number_format((float)$product_price,2); ?>
</td>
</tr>
<?php } } ?>

</tbody>
<tfoot>
	<td colspan="5">
		Total
	</td>
	<td>
		<?php echo number_format((float)$total_amount,2); ?>
	</td>
</tfoot>

</table>
</div>

<button class="btn btn-success mt-4 btn-sm" onclick="printDiv('printdv')">Print Purchase</button>

</div>
</div>

</div>
</div>
</div>
</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>