<?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 - Eat More Resturant   | Pos & Invetory System | Dashboard

">
	<meta name="keywords" content="Eat More Resturant   | Pos & Invetory System | Dashboard

">
	<meta name="author" content="Eat More Resturant   | Pos & Invetory System | Dashboard

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

	<title>Home | Eat More Resturant   | Pos & Invetory System | 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';
		?>
		<div class="page-wrapper">
			<div class="content">
				<div class="page-header">
					<div class="page-title">
						<h4>Create Sales Purchase</h4>
						<h6>Add Purchase</h6>
					</div>
				</div>
				<div class="card">
					<div class="card-body">

						<div class="row">
							<div class="col-md-4">
								<label>Select Product</label>
								<select class="select selectpicker" id="product" onchange="getProductPrice(this.value);" data-live-search="true" style="width: 100%">
									<option value="">Select Product to Add Purchase</option>
									<?php
									$pro = "SELECT * FROM mobileproducts WHERE status=1";
									$result = $conn->query($pro);
									if ($result->num_rows > 0) {
										while($row = $result->fetch_assoc()) {
											$prid = $row["prid"];
											$proname = $row["proname"];
											$price = $row["price"];
											echo '<option value="'.$prid.'">'.$proname.' | '.number_format((float)$price,2).'</option>';
										}
									}
									?>
								</select>
							</div>
							<div class="col-md-2">
							<a href="addproduct.php" class="btn btn-block btn-outline-info active btn-md text-white" title="Add New Product" onClick="JavaScript:return confirm('Are your sure change this add new product ?');" target="_blank" style="margin-top:20px;"><i class="fa fa-check-circle" data-bs-toggle="tooltip" title="" data-bs-original-title="fa fa-check-circle" aria-label="fa fa-check-circle"></i> Add Product</a>
							</div>
							<div class="col-md-2">
								<label>Price</label>
								<input type="number" class="form-control" id="price" placeholder="Price" onKeyDown="if(event.keyCode==13) addQuotationItem();">
							</div>

							<div class="col-md-2">
								<label>Quantity</label>
								<input type="number" class="form-control" id="qty" placeholder="Quantity" value="1" onKeyDown="if(event.keyCode==13) addQuotationItem();">
							</div>

							<div class="col-md-2">
								<label>Discount%</label>
								<input type="number" class="form-control" id="dis" placeholder="Discount" value="0" onKeyDown="if(event.keyCode==13) addQuotationItem();">
							</div>
						</div>

						<div class="row mt-5" id="msgView">
							
						</div>
						
						
					</div>
				</div>
			</div>
		</div>
	</div>


	<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/js/moment.min.js"></script>
	<script src="assets/js/bootstrap-datetimepicker.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/alertify/alertify.js"></script>
	<script src="assets/alertify/alertify.min.js"></script>

	<script src="assets/js/script.js"></script>
	<script src="process.js"></script>

</body>
</html>
<style type="text/css">
	.bootstrap-select:not([class*=col-]):not([class*=form-control]):not(.input-group-btn) {
    width: 100%;
}
</style>

<script type="text/javascript">
	document.body.onload = function(){
    loadQuotationItems();
  }

	function addQuotationItem() {
	var product = document.getElementById("product").value;
	var price = document.getElementById("price").value;
	var qty = document.getElementById("qty").value;
	var dis = document.getElementById("dis").value;

	$.ajax({
		url : "load-add-purchase-items.php",
		type : "POST",
		data : "product="+product+"& price="+price+"&  qty="+qty+"&  dis="+dis+"& ",
		success: function(data){
			if(data>0){
				loadQuotationItems();
			}else{
alertify.error(data);
			}
		},
		error: function(jXHR, textStatus, errorThrown){
			alert(jXHR.responseText);
		}
	})
	}


	function loadQuotationItems() {
	$.ajax({
		url : "load-view-purchase-items.php",
		type : "POST",
		success: function(data){
			$('#msgView').html(data);
		},
		error: function(jXHR, textStatus, errorThrown){
			alert(jXHR.responseText);
		}
	})
}
</script>