<?php
	session_start();
	include("library/conn.php");
?>
<!DOCTYPE html>
<html lang="en">
	<head>
        <?php include("library/head.php");?>
        <title>My POS | <?php echo $_SESSION['systemName']; ?></title>
	</head>
	<body class="app sidebar-mini pace-done sidenav-toggled">

		<?php include("models/admin_config.php");?>
		<?php include("models/system_config.php");?>

		<!-- Navbar-->
		<?php include("library/waiter-header.php");?>
		<!-- Sidebar menu-->
		<?php
			date_default_timezone_set('Africa/Mogadishu');
			if ((isset($_SESSION['userName']) == true) && ($_SESSION['userName']) != "") {
				if ((time() - $_SESSION['lastLoginTimeStamp']) < 900) $_SESSION["lastLoginTimeStamp"] = time();
				else echo "<script>location ='logout'</script>";
			} else echo "<script>location ='logout'</script>";
		?>
  
		<main class="app-content" style="margin-left: 0px;">

			<div class="row">

				<div class="col-md-8">

                    <div class="row mb-4">
                        <div class="col-md-12">
							<button class="btn btn-primary btn-lg mr-1 mb-2 shadow restaurant_categories_waiter_pos" id="all_category_name_waiter_pos" category-id="All">
								<i class="fa fa-list-ul" style="font-size: 20px;"></i>
								<b>All</b>
							</button>
                            <?php
                                $getRestaurantCategories = mysqli_query($conn, "SELECT * FROM restaurant_categories WHERE workingAreaID = '". $_SESSION['workingAreaID'] ."' OR workingAreaID = 'WAR0001' ORDER BY categoryName ASC") or die(mysqli_error($conn));
                                while ($category_rs = mysqli_fetch_array($getRestaurantCategories)) { ?>
                                    <button class="btn btn-primary btn-lg mr-1 mb-2 shadow restaurant_categories_waiter_pos" id="<?php echo $category_rs[1]; ?>_category_name_waiter_pos" category-id="<?php echo $category_rs[1]; ?>">
                                        <img class="img-fluid rounded" src="<?php echo $category_rs[9]; ?>" width="25px" height="25px" />
                                        <b><?php echo $category_rs[2]; ?></b>
                                    </button><?php
                                }
                            ?>
                        </div>
                    </div>

					<div class="tile">
						<div class="tile-body">
							<div class="row">
								<div class="col-md-12">
                                    <div class="row mb-2 mt-1 pull-right">
                                        <div class="col-md-12">
											<div class="form-group has-search">
												<span class="fa fa-search form-control-feedback text-warning"></span>
												<input type="text" class="form-control rounded-pill" name="txtSearchRestaurantProductLiveWaiterPOS" id="txtSearchRestaurantProductLiveWaiterPOS" placeholder="Search product" autocomplete="off">
											</div>                                       
										</div>
                                    </div>
								</div>
    							<div class="col-md-12" style="overflow: auto; height: 1200px;">

                                    <div class="row restaurantProductsWaiterPOSPageArea">
										<?php
											$getCategoryProducts = mysqli_query($conn, "SELECT restaurant_products.productID, restaurant_products.productName, restaurant_products.productPrice, restaurant_products.productStatus, restaurant_products.productPhoto 
											FROM restaurant_products 
											WHERE restaurant_products.workingAreaID = '". $_SESSION['workingAreaID'] ."' OR restaurant_products.workingAreaID = 'WAR0001' AND restaurant_products.productStatus = 1 ORDER BY restaurant_products.productName ASC") or die(mysqli_error($conn));
											if ($getCategoryProducts) {
												if (mysqli_num_rows($getCategoryProducts) > 0) {
													while ($category_products_rs = mysqli_fetch_array($getCategoryProducts)) { ?>
														<div class="col-md-3">
															<div class="bs-component mt-2 mb-3 singleProductWaiterPOSPageArea" style="cursor: pointer;" product-id="<?php echo $category_products_rs[0]; ?>" product-name="<?php echo $category_products_rs[1]; ?>" product-price="<?php echo $category_products_rs[2]; ?>">
																<div class="card rounded-lg">
																	<img class="rounded-top rounded-lg" style="height: 140px; width: 100%; display: block;" src="<?php echo $category_products_rs[4]; ?>" alt="Card image">
																	<div class="card-body">
																		<div class="row">
																			<div class="col-md-12">
                                                                                <h5 class="text-primary text-center font-weight-normal">
                                                                                    <?php echo $category_products_rs[1]; ?>
                                                                                    <span class="text-success font-weight-bold mt-1" style="display: block"><?php echo "$". number_format($category_products_rs[2], 2); ?></span>
                                                                                </h5>
                                                                            </div>
																		</div>
																	</div>
																</div>
															</div>
														</div><?php
													}
												}
											}
										?>
									</div>
									 							
					            </div>
						    </div>
					    </div>
				    </div>
			    </div>
			
			    <div class="col-md-4">
					<div class="tile">
						<div class="tile-body">
							<div class="row">
								<div class="col-md-12 border-bottom border-primary mb-3">
									<h5 class="text-primary"><i class="fa fa-shopping-cart"></i> Checkout</h5>
								</div>
                                <div class="col-md-12 pb-2">
                                    <button class="btn btn-outline-success mr-1 btnSeatInWaiterPOSPage" id="btnSeatInWaiterPOSPage"><i class="fa fa-hotel"></i> Seat In</button>
                                    <button class="btn btn-outline-primary mr-1 btnTakeAwayWaiterPOSPage" id="btnTakeAwayWaiterPOSPage"><i class="fa fa-shopping-basket"></i> Take Away</button>
                                </div>
                                <div class="form-group col-md-12 pt-3">
                                    <select id="cmbCustomerIddNewOrderWaiterPOSPage" name="cmbCustomerIddNewOrderWaiterPOSPage" class="form-control" style="width:100%" required />

									</select>
                                </div>
                                <div class="form-group col-md-12 pt-1 pb-2 orderedProductsWaiterPOSPageArea">
                                    <div class="row p-2 bg-light text-dark rounded-top font-weight-bold" style="margin: 0px;">
										<div class="col-md-1 text-left">&nbsp;</div>
										<div class="col-md-5">Name</div>
                                        <div class="col-md-4 text-center">Quantity</div>
                                        <div class="col-md-2">Price</div>
                                    </div>
                                </div>
                                <div class="form-group col-md-12">
									<textarea class="form-control pt-2" style="resize: none;" rows="2" name="txtKitchenNoteNewOrderWaiterPOSPage" id="txtKitchenNoteNewOrderWaiterPOSPage" placeholder="Leave kitchen notes" required></textarea>
								</div>
								<div class="form-group col-md-12 pt-3 pb-1">
									<div class="row align-items-center font-weight-bold pt-1 pb-1" style="margin: 0px;">
										<div class="col-md-8"><h5 class="text-primary">Subtotal</h5></div>
                                        <div class="col-md-4 text-center"><h5>$<span id="orderedProductsSubtotalWaiterPOS">0.00</span><h5></div>
                                    </div>
                                    <div class="row align-items-center font-weight-bold pt-1 pb-1" style="margin: 0px;">
										<div class="col-md-8"><h5 class="text-danger">VAT Tax (%5)</h5></div>
                                        <div class="col-md-4 text-center"><h5 class="text-danger">$<span id="txtOrderedProductsVATWaiterPOS">0.00</span><h5></div>
                                    </div>
									<div class="row align-items-center font-weight-bold pt-2 pb-1" style="margin: 0px;">
										<div class="col-md-8"><h5 class="text-primary">Total</h5></div>
                                        <div class="col-md-4 text-center"><h5 class="text-success">$<span id="orderedProductsTotalWaiterPOS">0.00</span><h5></div>
                                    </div>
								</div>

								<div class="form-group col-md-12 pt-1 pb-1">
									<div class="row pt-2 pull-right">
										<div class="col-md-12">
											<button class="btn btn-primary btn-lg pl-5 pr-5" name="btnHoldOrderWaiterPOSPage" id="btnHoldOrderWaiterPOSPage"><i class="fa fa-pause"></i>Hold Order</button>
										</div>
									</div>
								</div>

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

					
				</div>


			</div>
			
		</main>

		<!-- Essential javascripts for application to work-->
		<?php include("library/scripts.php");?>
		
		<script type="text/javascript">
			$(document).ready(function () {
				// Active the POS Button
				$(".btnWaiterPOSWaiterDashboard").removeClass("btn-outline-light")
				$(".btnWaiterPOSWaiterDashboard").addClass("btn-light")
			})
            $("#cmbCustomerIddNewOrderWaiterPOSPage").select2({ tags: false})
		</script>

	</body>
</html>