<?php
	session_start();
	include("library/conn.php");
?>
<!DOCTYPE html>
<html lang="en">
	<head>
        <?php include("library/head.php");?>
        <title>POS | <?php echo $_SESSION['systemName']; ?></title>
		<style>
			/* .modal { overflow: auto !important; } */
		</style>
	</head>
	<body class="app sidebar-mini">

		<!-- Navbar-->
		<?php include("library/header.php");?>
		<!-- Sidebar menu-->
		<div class="app-sidebar__overlay" data-toggle="sidebar"></div>
		<?php include("library/sidebar.php");?>
  
		<main class="app-content">
			<div class="app-title">
				<div>
					<h4 class="text-primary"><i class="fa fa-shopping-cart fa-lg"></i> POS</h4>
				</div>
				<ul class="app-breadcrumb breadcrumb">
					<li class="breadcrumb-item"><i class="fa fa-home"></i></li>
					<li class="breadcrumb-item"><a href="pos">POS</a></li>
				</ul>
			</div>
      
			<?php include("models/admin_config.php");?>
			<?php include("models/system_config.php");?>

			<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_admin_pos" id="all_category_name_admin_pos" category-id="All">
								<i class="fa fa-list-ul" style="font-size: 20px;"></i>
								<b>All</b>
							</button>
                            <?php
								if (($_SESSION['userTypeID'] == 'PS0001') || ($_SESSION['userTypeID'] == 'PS0002') || ($_SESSION['userTypeID'] == 'PS0003')) {
									$restaurantCategories = "SELECT * FROM restaurant_categories ORDER BY categoryName ASC";
								} else {
									$restaurantCategories = "SELECT * FROM restaurant_categories WHERE workingAreaID = '". $_SESSION['workingAreaID'] ."' OR workingAreaID = 'WAR0001' ORDER BY categoryName ASC";
								}
                                $getRestaurantCategories = mysqli_query($conn, $restaurantCategories) 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_admin_pos" id="<?php echo $category_rs[1]; ?>_category_name_admin_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="txtSearchRestaurantProductLiveAdminPOS" id="txtSearchRestaurantProductLiveAdminPOS" placeholder="Search product" autocomplete="off">
											</div>                                       
										</div>
                                    </div>
								</div>
    							<div class="col-md-12" style="overflow: auto; height: 1200px;">

                                    <div class="row restaurantProductsAdminPOSPageArea">
										<?php


											if (($_SESSION['userTypeID'] == 'PS0001') || ($_SESSION['userTypeID'] == 'PS0002') || ($_SESSION['userTypeID'] == 'PS0003')) {
												$restaurantProducts = "SELECT restaurant_products.productID, restaurant_products.productName, restaurant_products.productPrice, restaurant_products.productStatus, restaurant_products.productPhoto FROM restaurant_products WHERE restaurant_products.productStatus = 1 ORDER BY restaurant_products.productName ASC";
											} else {
												$restaurantProducts = "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";
											}

											$getCategoryProducts = mysqli_query($conn, $restaurantProducts) 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 singleProductAdminPOSPageArea" 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 btnSeatInAdminPOSPage" id="btnSeatInAdminPOSPage"><i class="fa fa-hotel"></i> Seat In</button>
                                    <button class="btn btn-outline-primary mr-1 btnTakeAwayAdminPOSPage" id="btnTakeAwayAdminPOSPage"><i class="fa fa-shopping-basket"></i> Take Away</button>
                                    <button class="btn btn-outline-dark mr-1 btnDeliveryAdminPOSPage" id="btnDeliveryAdminPOSPage"><i class="fa fa-motorcycle"></i> Delivery</button>
                                </div>
                                <div class="form-group col-md-12 pt-3">
                                    <select id="cmbCustomerIddNewOrderAdminPOSPage" name="cmbCustomerIddNewOrderAdminPOSPage" class="form-control" style="width:100%" required />
									
									</select>
                                </div>
								<div class="form-group col-md-12">
									<input type="text" class="form-control" name="txtDeliveryAddressNewOrderAdminPOSPage" id="txtDeliveryAddressNewOrderAdminPOSPage" placeholder="Delivery address"/>
                                </div>
                                <div class="form-group col-md-12 pt-1 pb-2 orderedProductsAdminPOSPageArea">
                                    <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 pt-2 pb-1">
									<div class="row">
										<div class="col-md-12 pb-2 font-weight-bold">
											<p>Serving Waiter</p>
										</div>
									</div>
									<div class="row">
										<?php
											if (($_SESSION['userTypeID'] == 'PS0001') || ($_SESSION['userTypeID'] == 'PS0002') || ($_SESSION['userTypeID'] == 'PS0003')) $fetchCriteria = "WHERE employees.employeePosition = 'PS0008' AND employees.employeeStatus = '1'";
											else $fetchCriteria = "WHERE employees.employeePosition = 'PS0008' AND employees.workingAreaID = '". $_SESSION['workingAreaID'] ."' AND employees.employeeStatus = '1'";
											$getWaiters = mysqli_query($conn, "SELECT employees.employeeID, system_users.Username, employees.employeePhoto
											FROM employees
											JOIN system_users ON employees.employeeID = system_users.employeeID
											$fetchCriteria
											ORDER BY system_users.Username ASC") or die(mysqli_error($conn));
											if ($getWaiters) {
												if (mysqli_num_rows($getWaiters) > 0) {
													while ($waiters_rs = mysqli_fetch_array($getWaiters)) { ?>
														<div class="col-md-3 mb-3 text-center">
															<div class="custom-control custom-checkbox image-checkbox">
																<input type="checkbox" class="custom-control-input cbxServingWaiterAdminPOSPageArea" id="<?php echo $waiters_rs[0] ?>" serving-waiter-id="<?php echo $waiters_rs[0] ?>">
																<label class="custom-control-label pb-2" for="<?php echo $waiters_rs[0] ?>">
																	<img src="<?php echo $waiters_rs[2] ?>" alt="#" class="img-fluid">
																</label>
																
																<span><?php $get_name = explode(" ", $waiters_rs[1]); echo $get_name[0]; ?></span>
															</div>
														</div><?php
													}
												} else {
													?><div class="row">
														<div class="col-md-12 ml-3">
															<p>Waiters Not Found</p>
														</div>
													</div><?php
												}
											} else {
												?><div class="row">
													<div class="col-md-12 ml-3">
														<p><?php echo mysqli_error($conn); ?></p>
													</div>
												</div><?php
											}
										?>
									</div>
								</div>
								
								<div class="form-group col-sm-12">
									<textarea class="form-control pt-2" style="resize: none;" rows="2" name="txtKitchenNoteNewOrderAdminPOSPage" id="txtKitchenNoteNewOrderAdminPOSPage" 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="orderedProductsSubtotalAdminPOS">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-primary">Discount</h5></div>
                                        <div class="col-md-4 text-center"><input type="number" class="form-control input-lg h5 text-center font-weight-bold" name="txtOrderedProductsDiscountAdminPOS" id="txtOrderedProductsDiscountAdminPOS" value="0" step="0.01" autocomplete="off" required /></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-primary">VAT Tax (%5)</h5></div>
                                        <div class="col-md-4 text-center"><input type="number" class="form-control input-lg h5 text-center font-weight-bold" name="txtOrderedProductsVATAdminPOS" id="txtOrderedProductsVATAdminPOS" value="0" step="0.01" autocomplete="off" required /></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="orderedProductsTotalAdminPOS">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-3 pr-3 mr-1" name="btnHoldOrderAdminPOSPage" id="btnHoldOrderAdminPOSPage"><i class="fa fa-pause"></i>Hold Order</button>
											<button class="btn btn-success btn-lg pl-4 pr-4" name="btnRegisterAndPayAdminPOSPage" id="btnRegisterAndPayAdminPOSPage"><i class="fa fa-save"></i>Register & Pay</button>
										</div>
									</div>
								</div>

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

					
				</div>


			</div>
			
		</main>
  
		<!-- Essential javascripts for application to work-->
		<?php include("library/footer.php");?>  
		<?php include("library/scripts.php");?>
		
		<script type="text/javascript">
            $(".btnAdminPOSWaiterDashboard").removeClass("btn-outline-light")
			$(".btnAdminPOSWaiterDashboard").addClass("btn-light")
            $("#cmbCustomerIddNewOrderAdminPOSPage").select2({ tags: false})

		</script>

	</body>
</html>