<?php
    session_start();
    date_default_timezone_set('Africa/Mogadishu');
    include("library/conn.php");
	// This is getting the start date today
    $start_date_time = (date("H") > 6) ? date("Y-m-d 06:00:00") : date('Y-m-d 06:00:00', strtotime("-1 days"));
	
	// This is getting the start date of yesterday
	$yesterday_start_date = (date("H") > 6) ? date("Y-m-d 06:00:00", strtotime("-1 days")) : date('Y-m-d 06:00:00', strtotime("-2 days"));
	$yesterday_end_date = (date("H") > 6) ? date("Y-m-d 06:00:00") : date('Y-m-d 06:00:00', strtotime("-1 days"));
	
    $shown_today_date = (date("H") > 6) ? date("Y-m-d") : date('Y-m-d', strtotime("-1 days"));
    
    // Last week start and end day calculation
    $last_week_start_day = strtotime("last saturday", strtotime("-1 week +1 day"));
    $last_week_end_day = strtotime("next friday midnight", $last_week_start_day);
    $last_week_start_day = date("Y-m-d 06:00", $last_week_start_day);
    $last_week_end_day = date("Y-m-d 23:59", $last_week_end_day);
    
    // Last month start and end day calculation
    $last_month_start_day = date("Y-m-d 06:00", strtotime("first day of last month"));
    $last_month_end_day = date("Y-m-d 23:59", strtotime("last day of last month"));
    
    // Last year start and end day calculation
    $last_year_start_day = date("Y-m-d", strtotime("last year January 1st"));
    $last_year_end_day = date("Y-m-d", strtotime("last year December 31st"));
    
    // Random Background Color Generator
    function random_color_part() {
        return str_pad(dechex(mt_rand(0, 255)), 2, '0', STR_PAD_LEFT);
    }
    
    // Generate Random Background Color
    function random_color() {
        return "#". random_color_part() . random_color_part() . random_color_part();
    }

?>
<!DOCTYPE html>
<html lang="en">
  <head>
        <?php include("library/head.php");?>
        <title>Dashboard | <?php echo $_SESSION["systemName"]; ?></title>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"></script>
  </head>
  <body class="app sidebar-mini">
   
    <?php
		include("library/header.php");
		include("library/sidebar.php");
		include("models/admin_config.php");
		include("models/system_config.php");        
    ?>

	<main class="app-content">
	    
		<div class="app-title">
		    
			<div>
			    <?php $dashboard_header = explode("##**##", $_SESSION["dashboardHeader"]); ?>
			    <h4 class="text-primary"><i class="<?php echo $dashboard_header[0]; ?>"></i> <b><?php echo $dashboard_header[1]; ?></b></h4>
			</div>
			<!--<div class='backup'>-->
			<!--    <a href="backup.php" class="btn btn-primary">Backup Now<i class="fa fa-download"></i></a>-->
			<!--</div>-->
			<ul class="app-breadcrumb breadcrumb">
				<li class="breadcrumb-item"><i class="fa fa-home fa-lg"></i></li>
				<li class="breadcrumb-item"><a href="dashboard">Dashboard</a></li>
			</ul>
			
		</div>
   
		<div class="row mt-5">
			<div class="col-md-12">
				<h2 class="text-primary">Analytics <span class="font-weight-normal">Dashboard</span></h2>
			</div>
		</div>
		<div class="row mt-3">
			<div class="col-md-6 col-lg-3">
			    <?php
			        
			    ?>
				<div class="widget-small primary coloured-icon shadow"><i class="icon bi-people-fill" style="font-size: 3.3rem;"></i><?php 
					$countUsers = mysqli_query($conn, "SELECT COUNT(rowNo) FROM system_users WHERE userID != 'US2100001'");
					$totalUsers = mysqli_fetch_array($countUsers);
					?><div class="info">
						<h5><small class="font-weight-bold">ACTIVE USERS</small></h5>
						<p class="text-primary" style="font-size: 0.95rem;"><?php echo ($totalUsers[0] >= 0) ? $totalUsers[0] : 0 ?></p>
					</div>
				</div>
			</div>
			<div class="col-md-6 col-lg-3">
				<div class="widget-small info coloured-icon shadow"><i class="icon bi-person-walking" style="font-size: 3.3rem;"></i><?php 
						$countEmployees = mysqli_query($conn, "SELECT COUNT(rowNo) FROM employees WHERE employeePosition <> 'PS0001' AND employeeStatus = '1'");
						$totalEmployees = mysqli_fetch_array($countEmployees);
					?><div class="info">
						<h5><small class="font-weight-bold">ACTIVE EMPLOYEES</small></h5>
						<p class="text-primary" style="font-size: 0.95rem;"><?php echo ($totalEmployees[0] >= 0) ? $totalEmployees[0] : 0 ?></p>
					</div>
				</div>
			</div>
			<div class="col-md-6 col-lg-3">
				<div class="widget-small warning coloured-icon shadow"><i class="icon bi-person-check" style="font-size: 3.3rem;"></i><?php 
						$countActiveWaiters = mysqli_query($conn, "SELECT COUNT(rowNo) FROM employees WHERE employeePosition = 'PS0008' AND employeeStatus = '1'");
						$totalActiveWaiters = mysqli_fetch_array($countActiveWaiters);
					?><div class="info">
						<h5><small class="font-weight-bold">ACTIVE WAITERS</small></h5>
						<p class="text-primary" style="font-size: 0.95rem;"><?php echo ($totalActiveWaiters[0] >= 0) ? $totalActiveWaiters[0] : 0 ?></p>
					</div>
				</div>
			</div>
			<div class="col-md-6 col-lg-3">
				<div class="widget-small danger coloured-icon shadow"><i class="icon bi-person-check" style="font-size: 3.3rem;"></i><?php 
						$countCustomers = mysqli_query($conn, "SELECT COUNT(rowNo) FROM customers WHERE customerStatus = '1'");
						$totalCustomers = mysqli_fetch_array($countCustomers);
					?><div class="info">
						<h5><small class="font-weight-bold">TOTAL CUSTOMERS</small></h5>
						<p class="text-primary" style="font-size: 0.95rem;"><?php echo ($totalCustomers[0] >= 0) ? $totalCustomers[0] : 0 ?></p>
					</div>
				</div>
			</div>
		</div>

		<!-- <div class="row">
			<div class="col-md-6 col-lg-2">
				<div class="widget-small primary coloured-icon shadow"><i class="icon bi-people-fill p-2" style="font-size: 2.2rem;"></i><?php 
					$countUsers = mysqli_query($conn, "SELECT COUNT(rowNo) FROM system_users WHERE userID != 'US2100001'");
					$totalUsers = mysqli_fetch_array($countUsers);
					?><div class="info pt-2">
						<h5>
							<small class="font-weight-bold" style="display: block;">ACTIVE USERS</small>
							<span class="font-weight-normal" style="font-size: 0.80rem;"><?php echo ($totalUsers[0] >= 0) ? $totalUsers[0] : 0 ?></span>
						</h5>
					</div>
				</div>
			</div>
			<div class="col-md-6 col-lg-2">
				<div class="widget-small info coloured-icon shadow"><i class="icon bi-person-walking p-2" style="font-size: 2.2rem;"></i><?php 
					$countUsers = mysqli_query($conn, "SELECT COUNT(rowNo) FROM system_users WHERE userID != 'US2100001'");
					$totalUsers = mysqli_fetch_array($countUsers);
					?><div class="info pt-2">
						<h5>
							<small class="font-weight-bold" style="display: block;">TOTAL EMPLOYEES</small>
							<span class="font-weight-normal" style="font-size: 0.80rem;"><?php echo ($totalUsers[0] >= 0) ? $totalUsers[0] : 0 ?></span>
						</h5>
					</div>
				</div>
			</div>

			<div class="col-md-6 col-lg-2">
				<div class="widget-small warning coloured-icon shadow"><i class="icon bi-person-check p-2" style="font-size: 2.2rem;"></i><?php 
						$countActiveWaiters = mysqli_query($conn, "SELECT COUNT(rowNo) FROM employees WHERE employeePosition = 'PS0008' AND employeeStatus = '1'");
						$totalActiveWaiters = mysqli_fetch_array($countActiveWaiters);
					?><div class="info pt-2">
						<h5>
							<small class="font-weight-bold" style="display: block;">ACTIVE WAITERS</small>
							<span class="font-weight-normal" style="font-size: 0.80rem;"><?php echo ($totalActiveWaiters[0] >= 0) ? $totalActiveWaiters[0] : 0 ?></span>
						</h5>
					</div>
				</div>
			</div>

			<div class="col-md-6 col-lg-2">
				<div class="widget-small danger coloured-icon shadow"><i class="icon bi-person-check p-2" style="font-size: 2.2rem;"></i><?php 
						$countActiveWaiters = mysqli_query($conn, "SELECT COUNT(rowNo) FROM employees WHERE employeePosition = 'PS0008' AND employeeStatus = '1'");
						$totalActiveWaiters = mysqli_fetch_array($countActiveWaiters);
					?><div class="info pt-2">
						<h5>
							<small class="font-weight-bold" style="display: block;">ACTIVE WAITERS</small>
							<span class="font-weight-normal" style="font-size: 0.80rem;"><?php echo ($totalActiveWaiters[0] >= 0) ? $totalActiveWaiters[0] : 0 ?></span>
						</h5>
					</div>
				</div>
			</div>

			<div class="col-md-6 col-lg-2">
				<div class="widget-small warning coloured-icon shadow"><i class="icon bi-person-check p-2" style="font-size: 2.2rem;"></i><?php 
						$countActiveWaiters = mysqli_query($conn, "SELECT COUNT(rowNo) FROM employees WHERE employeePosition = 'PS0008' AND employeeStatus = '1'");
						$totalActiveWaiters = mysqli_fetch_array($countActiveWaiters);
					?><div class="info pt-2">
						<h5>
							<small class="font-weight-bold" style="display: block;">ACTIVE WAITERS</small>
							<span class="font-weight-normal" style="font-size: 0.80rem;"><?php echo ($totalActiveWaiters[0] >= 0) ? $totalActiveWaiters[0] : 0 ?></span>
						</h5>
					</div>
				</div>
			</div>

			<div class="col-md-6 col-lg-2">
				<div class="widget-small danger coloured-icon shadow"><i class="icon bi-person-check p-2" style="font-size: 2.2rem;"></i><?php 
						$countActiveWaiters = mysqli_query($conn, "SELECT COUNT(rowNo) FROM employees WHERE employeePosition = 'PS0008' AND employeeStatus = '1'");
						$totalActiveWaiters = mysqli_fetch_array($countActiveWaiters);
					?><div class="info pt-2">
						<h5>
							<small class="font-weight-bold" style="display: block;">ACTIVE WAITERS</small>
							<span class="font-weight-normal" style="font-size: 0.80rem;"><?php echo ($totalActiveWaiters[0] >= 0) ? $totalActiveWaiters[0] : 0 ?></span>
						</h5>
					</div>
				</div>
			</div>

		</div> -->

		<div class="row mt-5">
			<div class="col-md-7">
				<h2 class="text-primary">Daily <span class="font-weight-normal text-primary">Analytics <sup class="font-weight-normal text-success" style="font-size: 1.19rem;"><?php echo $shown_today_date; ?></sup></span></h2>
			</div>
			<div class="col-md-5 text-right">
				<button type="button" class="btn btn-md btn-primary">Choose Section</button>
				<button type="button" class="btn btn-md btn-primary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown">
					<span class="caret"></span>
				</button>
				<div class="dropdown-menu mt-1 mr-4" style="min-width: 12rem;">
					<?php
						$getWorkingAreas = mysqli_query($conn, "SELECT workingAreaID, workingAreaName FROM working_areas ORDER BY workingAreaID ASC");
						if ($getWorkingAreas) {
							if (mysqli_num_rows($getWorkingAreas) > 0) {
								while ($work_areas_rs = mysqli_fetch_array($getWorkingAreas)) {
									?><a href="#" class="dropdown-item text-primary btnSectionDailyAnalyticsDashboard" id="<?php echo "Delete". $work_areas_rs[0]; ?>" data-id="<?php echo $work_areas_rs[0]; ?>"><i class="fa fa-th-large"></i> <?php echo $work_areas_rs[1]; ?></a><?php
								}
							} else { ?><p><?php echo "Sections Not Found"; ?></p><?php }
						} else { ?><p><?php echo mysqli_error($conn); ?></p><?php }
					?>
				</div>
			</div>
		</div>
		<div class="tile shadow mt-3">
			<div class="row">
				<div class="col-md-6 col-lg-12 pb-3">
					<div class="row">

						<div class="col-md-6 col-lg-3">
							<div class="tile bg-light-info p-0 shadow">
								<div class="row p-3">
									<div class="col-md-3">
										<i class="fa fa-shopping-cart fa-2x text-white bg-strong-info p-3 rounded-lg shadow"></i>
									</div>
									<div class="col-md-9 pt-1">
										<h5 class="text-dark">
											<small class="font-weight-bold pb-2" style="display: block;">TOTAL ORDERS</small>
											<?php
												// Growth increase or decrease ratio formula$todays_total_orders_rs[0]. " - ".$waiter_yesterday_total_orders_rs[0] . " = ". (($todays_total_orders_rs[0]-$yesterday_total_orders_rs[0])/($yesterday_total_orders_rs[0]) * 100)
												$yesterday_total_orders = mysqli_query($conn, "SELECT IFNULL(COUNT(orderID), 0) FROM restaurant_orders WHERE orderStatus != '4' AND registerDate BETWEEN '$yesterday_start_date' AND '$yesterday_end_date'") or die(mysqli_error($conn));
												$yesterday_total_orders_rs = mysqli_fetch_array($yesterday_total_orders); 
												$todays_total_orders = mysqli_query($conn, "SELECT IFNULL(COUNT(orderID), 0) FROM restaurant_orders WHERE orderStatus != '4' AND registerDate BETWEEN '$start_date_time' AND '". date("Y-m-d H:i") ."'") or die(mysqli_error($conn));
												$todays_total_orders_rs = mysqli_fetch_array($todays_total_orders);
											?>
											<span class="font-weight-normal" style="font-size: 0.95rem; display: block;"><?php echo $todays_total_orders_rs[0]; ?></span>
											<span class="pull-right">
												<?php
													if ($todays_total_orders_rs[0] > $yesterday_total_orders_rs[0]) { ?>
														<span class="font-weight-bold text-success" style="font-size: 0.80rem;"><i class="fa fa-arrow-up text-success"></i> <?php echo abs((float)$todays_total_orders_rs[0] - (float)$yesterday_total_orders_rs[0]); ?></span>
														<span class="font-weight-normal text-primary" style="font-size: 0.80rem;"> since yesterday</span><?php
													} else if ($todays_total_orders_rs[0] < $yesterday_total_orders_rs[0]) { ?>
														<span class="font-weight-bold text-danger" style="font-size: 0.80rem;"><i class="fa fa-arrow-down text-danger"></i> <?php echo abs((float)$todays_total_orders_rs[0] - (float)$yesterday_total_orders_rs[0]); ?></span>
														<span class="font-weight-normal text-primary" style="font-size: 0.80rem;"> since yesterday</span><?php
													}
												?>
											</span>
										</h5>
									</div>
								</div>
							</div>
						</div>

						<div class="col-md-6 col-lg-3">
							<div class="tile bg-light-success p-0 shadow">
								<div class="row p-3">
									<div class="col-md-3">
										<i class="fa fa-hotel fa-2x text-white bg-strong-success p-3 rounded-lg shadow"></i>
									</div>
									<div class="col-md-9 pt-1">
										<h5 class="text-dark">
											<small class="font-weight-bold pb-2" style="display: block;">SEAT IN ORDERS</small>
											<?php
												$todays_seat_in_orders = mysqli_query($conn, "SELECT IFNULL(COUNT(orderID), 0) FROM restaurant_orders WHERE orderTypeID = 'OT0001' AND orderStatus != '4' AND registerDate BETWEEN '$start_date_time' AND '". date("Y-m-d H:i") ."'") or die(mysqli_error($conn));
												$todays_seat_in_orders_rs = mysqli_fetch_array($todays_seat_in_orders);
												$yesterday_seat_in_orders = mysqli_query($conn, "SELECT IFNULL(COUNT(orderID), 0) FROM restaurant_orders WHERE orderTypeID = 'OT0001' AND orderStatus != '4' AND registerDate BETWEEN '$yesterday_start_date' AND '$yesterday_end_date'") or die(mysqli_error($conn));
												$yesterday_seat_in_orders_rs = mysqli_fetch_array($yesterday_seat_in_orders); 
											?>
											<span class="font-weight-normal" style="font-size: 0.95rem; display: block;"><?php echo $todays_seat_in_orders_rs[0]; ?></span>
											<span class="pull-right">
												<?php
													if ($todays_seat_in_orders_rs[0] > $yesterday_seat_in_orders_rs[0]) { ?>
														<span class="font-weight-bold text-success" style="font-size: 0.80rem;"><i class="fa fa-arrow-up text-success"></i> <?php echo abs((float)$todays_seat_in_orders_rs[0] - (float)$yesterday_seat_in_orders_rs[0]); ?></span>
														<span class="font-weight-normal text-primary" style="font-size: 0.80rem;"> since yesterday</span><?php
													} else if ($todays_seat_in_orders_rs[0] < $yesterday_seat_in_orders_rs[0]) { ?>
														<span class="font-weight-bold text-danger" style="font-size: 0.80rem;"><i class="fa fa-arrow-down text-danger"></i> <?php echo abs((float)$todays_seat_in_orders_rs[0] - (float)$yesterday_seat_in_orders_rs[0]); ?></span>
														<span class="font-weight-normal text-primary" style="font-size: 0.80rem;"> since yesterday</span><?php
													}
												?>
											</span>
										</h5>
									</div>
								</div>
							</div>
						</div>

						<div class="col-md-6 col-lg-3">
							<div class="tile bg-light-warning p-0 shadow">
								<div class="row p-3">
									<div class="col-md-3">
										<i class="fa fa-shopping-basket fa-2x text-white bg-strong-warning p-3 rounded-lg shadow"></i>
									</div>
									<div class="col-md-9 pt-1">
										<h5 class="text-dark">
											<small class="font-weight-bold pb-2" style="display: block;">TAKE AWAY ORDERS</small>
											<?php
												$todays_take_away_orders = mysqli_query($conn, "SELECT IFNULL(COUNT(orderID), 0) FROM restaurant_orders WHERE orderTypeID = 'OT0002' AND orderStatus != '4' AND registerDate BETWEEN '$start_date_time' AND '". date("Y-m-d H:i") ."'") or die(mysqli_error($conn));
												$todays_take_away_orders_rs = mysqli_fetch_array($todays_take_away_orders);
												$yesterday_take_away_orders = mysqli_query($conn, "SELECT IFNULL(COUNT(orderID), 0) FROM restaurant_orders WHERE orderTypeID = 'OT0002' AND orderStatus != '4' AND registerDate BETWEEN '$yesterday_start_date' AND '$yesterday_end_date'") or die(mysqli_error($conn));
												$yesterday_take_away_orders_rs = mysqli_fetch_array($yesterday_take_away_orders); 
											?>
											<span class="font-weight-normal" style="font-size: 0.95rem; display: block;"><?php echo $todays_take_away_orders_rs[0]; ?></span>
											<span class="pull-right">
												<?php
													if ($todays_take_away_orders_rs[0] > $yesterday_take_away_orders_rs[0]) { ?>
														<span class="font-weight-bold text-success" style="font-size: 0.80rem;"><i class="fa fa-arrow-up text-success"></i> <?php echo abs((float)$todays_take_away_orders_rs[0] - (float)$yesterday_take_away_orders_rs[0]); ?></span>
														<span class="font-weight-normal text-primary" style="font-size: 0.80rem;"> since yesterday</span><?php
													} else if ($todays_take_away_orders_rs[0] < $yesterday_take_away_orders_rs[0]) { ?>
														<span class="font-weight-bold text-danger" style="font-size: 0.80rem;"><i class="fa fa-arrow-down text-danger"></i> <?php echo abs((float)$todays_take_away_orders_rs[0] - (float)$yesterday_take_away_orders_rs[0]); ?></span>
														<span class="font-weight-normal text-primary" style="font-size: 0.80rem;"> since yesterday</span><?php
													}
												?>
											</span>
										</h5>
									</div>
								</div>
							</div>
						</div>

						<div class="col-md-6 col-lg-3">
							<div class="tile bg-light-primary p-0 shadow">
								<div class="row p-3">
									<div class="col-md-3">
										<i class="fa fa-motorcycle fa-2x text-white bg-strong-primary p-3 rounded-lg shadow"></i>
									</div>
									<div class="col-md-9 pt-1">
										<h5 class="text-white">
											<small class="font-weight-bold pb-2" style="display: block;">DELIVERY ORDERS</small>
											<?php
												$todays_delivery_orders = mysqli_query($conn, "SELECT IFNULL(COUNT(orderID), 0) FROM restaurant_orders WHERE orderTypeID = 'OT0003' AND orderStatus != '4' AND registerDate BETWEEN '$start_date_time' AND '". date("Y-m-d H:i") ."'") or die(mysqli_error($conn));
												$todays_delivery_orders_rs = mysqli_fetch_array($todays_delivery_orders);
												$yesterday_delivery_orders = mysqli_query($conn, "SELECT IFNULL(COUNT(orderID), 0) FROM restaurant_orders WHERE orderTypeID = 'OT0003' AND orderStatus != '4' AND registerDate BETWEEN '$yesterday_start_date' AND '$yesterday_end_date'") or die(mysqli_error($conn));
												$yesterday_delivery_orders_rs = mysqli_fetch_array($yesterday_delivery_orders); 
											?>
											<span class="font-weight-normal" style="font-size: 0.95rem; display: block;"><?php echo $todays_delivery_orders_rs[0]; ?></span>
											<span class="pull-right">
												<?php
													if ($todays_delivery_orders_rs[0] > $yesterday_delivery_orders_rs[0]) { ?>
														<span class="font-weight-bold text-success" style="font-size: 0.80rem;"><i class="fa fa-arrow-up text-success"></i> <?php echo abs((float)$todays_delivery_orders_rs[0] - (float)$yesterday_delivery_orders_rs[0]); ?></span>
														<span class="font-weight-normal text-white" style="font-size: 0.80rem;"> since yesterday</span><?php
													} else if ($todays_delivery_orders_rs[0] < $yesterday_delivery_orders_rs[0]) { ?>
														<span class="font-weight-bold text-danger" style="font-size: 0.80rem;"><i class="fa fa-arrow-down text-danger"></i> <?php echo abs((float)$todays_delivery_orders_rs[0] - (float)$yesterday_delivery_orders_rs[0]); ?></span>
														<span class="font-weight-normal text-white" style="font-size: 0.80rem;"> since yesterday</span><?php
													}
												?>
											</span>
										</h5>
									</div>
								</div>
							</div>
						</div>

						<div class="col-md-6 col-lg-3 mt-3">
							<div class="tile bg-light-danger p-0 shadow">
								<div class="row p-3">
									<div class="col-md-3">
										<i class="fa fa-times fa-2x text-white bg-strong-danger p-3 rounded-lg shadow"></i>
									</div>
									<div class="col-md-9 pt-1">
										<h5 class="text-dark">
											<small class="font-weight-bold pb-2" style="display: block;">CANCELLED ORDERS</small>
											<?php
												$todays_cancelled_orders = mysqli_query($conn, "SELECT IFNULL(COUNT(orderID), 0) FROM cancelled_orders WHERE cancelDate BETWEEN '$start_date_time' AND '". date("Y-m-d H:i") ."'") or die(mysqli_error($conn));
												$todays_cancelled_orders_rs = mysqli_fetch_array($todays_cancelled_orders);
												$yesterday_cancelled_orders = mysqli_query($conn, "SELECT IFNULL(COUNT(orderID), 0) FROM cancelled_orders WHERE cancelDate BETWEEN '$yesterday_start_date' AND '$yesterday_end_date'") or die(mysqli_error($conn));
												$yesterday_cancelled_orders_rs = mysqli_fetch_array($yesterday_cancelled_orders); 
											?>
											<span class="font-weight-normal" style="font-size: 0.95rem; display: block;"><?php echo $todays_cancelled_orders_rs[0]; ?></span>
											<span class="pull-right">
												<?php
													if ($todays_cancelled_orders_rs[0] > $yesterday_cancelled_orders_rs[0]) { ?>
														<span class="font-weight-bold text-danger" style="font-size: 0.80rem;"><i class="fa fa-arrow-up text-danger"></i> <?php echo abs((float)$todays_cancelled_orders_rs[0] - (float)$yesterday_cancelled_orders_rs[0]); ?></span>
														<span class="font-weight-normal text-primary" style="font-size: 0.80rem;"> since yesterday</span><?php
													} else if ($todays_cancelled_orders_rs[0] < $yesterday_cancelled_orders_rs[0]) { ?>
														<span class="font-weight-bold text-success" style="font-size: 0.80rem;"><i class="fa fa-arrow-down text-success"></i> <?php echo abs((float)$todays_cancelled_orders_rs[0] - (float)$yesterday_cancelled_orders_rs[0]); ?></span>
														<span class="font-weight-normal text-primary" style="font-size: 0.80rem;"> since yesterday</span><?php
													}
												?>
											</span>
										</h5>
									</div>
								</div>
							</div>
						</div>

						<div class="col-md-6 col-lg-3 mt-3">
							<div class="tile bg-light-info p-0 shadow">
								<div class="row p-3">
									<div class="col-md-3">
										<i class="fa fa-cutlery fa-2x text-white bg-strong-info p-3 rounded-lg shadow"></i>
									</div>
									<div class="col-md-9 pt-1">
										<h5 class="text-dark">
											<small class="font-weight-bold pb-2" style="display: block;">SOLD ITEMS</small>
											<?php
												$todays_sold_items = mysqli_query($conn, "SELECT IFNULL(COUNT(order_products_list.Quantity), 0) 'TotalSoldItems' FROM restaurant_orders JOIN order_products_list ON restaurant_orders.orderID = order_products_list.orderID WHERE restaurant_orders.orderStatus != '4' AND restaurant_orders.registerDate BETWEEN '$start_date_time' AND '". date("Y-m-d H:i") ."'") or die(mysqli_error($conn));
												$todays_sold_items_rs = mysqli_fetch_array($todays_sold_items);
												$yesterday_sold_items = mysqli_query($conn, "SELECT IFNULL(COUNT(order_products_list.Quantity), 0) 'TotalSoldItems' FROM restaurant_orders JOIN order_products_list ON restaurant_orders.orderID = order_products_list.orderID WHERE restaurant_orders.orderStatus != '4' AND restaurant_orders.registerDate BETWEEN '$yesterday_start_date' AND '$yesterday_end_date'") or die(mysqli_error($conn));
												$yesterday_sold_items_rs = mysqli_fetch_array($yesterday_sold_items); 
											?>
											<span class="font-weight-normal" style="font-size: 0.95rem; display: block;"><?php echo $todays_sold_items_rs[0]; ?></span>
											<span class="pull-right">
												<?php
													if ($todays_sold_items_rs[0] > $yesterday_sold_items_rs[0]) { ?>
														<span class="font-weight-bold text-success" style="font-size: 0.80rem;"><i class="fa fa-arrow-up text-success"></i> <?php echo abs((float)$todays_sold_items_rs[0] - (float)$yesterday_sold_items_rs[0]); ?></span>
														<span class="font-weight-normal text-primary" style="font-size: 0.80rem;"> since yesterday</span><?php
													} else if ($todays_sold_items_rs[0] < $yesterday_sold_items_rs[0]) { ?>
														<span class="font-weight-bold text-danger" style="font-size: 0.80rem;"><i class="fa fa-arrow-down text-danger"></i> <?php echo abs((float)$todays_sold_items_rs[0] - (float)$yesterday_sold_items_rs[0]); ?></span>
														<span class="font-weight-normal text-primary" style="font-size: 0.80rem;"> since yesterday</span><?php
													}
												?>
											</span>
										</h5>
									</div>
								</div>
							</div>
						</div>
						
						<div class="col-md-6 col-lg-3 mt-3" style="<?php if ($_SESSION['userTypeID'] == 'PS0001' || $_SESSION['userTypeID'] == 'PS0002')  { echo "display: block"; } else { echo "display: none"; }?>;">
							<div class="tile bg-light-success p-0 shadow">
								<div class="row p-3">
									<div class="col-md-3">
										<i class="fa fa-dollar fa-2x text-white bg-strong-success p-3 rounded-lg shadow"></i>
									</div>
									<div class="col-md-9 pt-1">
										<h5 class="text-dark">
											<small class="font-weight-bold pb-2" style="display: block;">TOTAL SALES</small>
											<?php
												$todays_total_sales = mysqli_query($conn, "SELECT IFNULL(SUM(orderSubtotal), 0) 'TotalSales' FROM restaurant_orders WHERE orderStatus != '4' AND registerDate BETWEEN '$start_date_time' AND '". date("Y-m-d H:i") ."'") or die(mysqli_error($conn));
												$todays_total_sales_rs = mysqli_fetch_array($todays_total_sales);
												$yesterday_total_sales = mysqli_query($conn, "SELECT IFNULL(SUM(orderSubtotal), 0) 'TotalSales' FROM restaurant_orders WHERE orderStatus != '4' AND registerDate BETWEEN '$yesterday_start_date' AND '$yesterday_end_date'") or die(mysqli_error($conn));
												$yesterday_total_sales_rs = mysqli_fetch_array($yesterday_total_sales); 
											?>
											<span class="font-weight-normal" style="font-size: 0.95rem; display: block;"><?php echo "$". number_format($todays_total_sales_rs[0], 2); ?></span>
											<span class="pull-right">
												<?php
													if ($todays_total_sales_rs[0] > $yesterday_total_sales_rs[0]) { ?>
														<span class="font-weight-bold text-success" style="font-size: 0.80rem;"><i class="fa fa-arrow-up text-success"></i> <?php echo "$". number_format(abs((float)$todays_total_sales_rs[0] - (float)$yesterday_total_sales_rs[0]), 2); ?></span>
														<span class="font-weight-normal text-primary" style="font-size: 0.80rem;"> since yesterday</span><?php
													} else if ($todays_total_sales_rs[0] < $yesterday_total_sales_rs[0]) { ?>
														<span class="font-weight-bold text-danger" style="font-size: 0.80rem;"><i class="fa fa-arrow-down text-danger"></i> <?php echo "$". number_format(abs((float)$todays_total_sales_rs[0] - (float)$yesterday_total_sales_rs[0]), 2); ?></span>
														<span class="font-weight-normal text-primary" style="font-size: 0.80rem;"> since yesterday</span><?php
													}
												?>
											</span>
										</h5>
									</div>
								</div>
							</div>
						</div>

						<div class="col-md-6 col-lg-3 mt-3">
							<div class="tile bg-light-warning p-0 shadow">
								<div class="row p-3">
									<div class="col-md-3">
										<i class="fa fa-money fa-2x text-white bg-strong-warning p-3 rounded-lg shadow"></i>
									</div>
									<div class="col-md-9 pt-1">
										<h5 class="text-dark">
											<small class="font-weight-bold pb-2" style="display: block;">TOTAL DISCOUNT</small>
											<?php
												$todays_total_discount = mysqli_query($conn, "SELECT IFNULL(SUM(orderDiscount), 0) 'TotalDiscount' FROM restaurant_orders WHERE orderStatus != '4' AND registerDate BETWEEN '$start_date_time' AND '". date("Y-m-d H:i") ."'") or die(mysqli_error($conn));
												$todays_total_discount_rs = mysqli_fetch_array($todays_total_discount);
												$yesterday_total_discount = mysqli_query($conn, "SELECT IFNULL(SUM(orderDiscount), 0) 'TotalDiscount' FROM restaurant_orders WHERE orderStatus != '4' AND registerDate BETWEEN '$yesterday_start_date' AND '$yesterday_end_date'") or die(mysqli_error($conn));
												$yesterday_total_discount_rs = mysqli_fetch_array($yesterday_total_discount); 
											?>
											<span class="font-weight-normal" style="font-size: 0.95rem; display: block;"><?php echo "$". number_format($todays_total_discount_rs[0], 2); ?></span>
											<span class="pull-right">
												<?php
													if ($todays_total_discount_rs[0] > $yesterday_total_discount_rs[0]) { ?>
														<span class="font-weight-bold text-danger" style="font-size: 0.80rem;"><i class="fa fa-arrow-up text-danger"></i> <?php echo "$". number_format(abs((float)$todays_total_discount_rs[0] - (float)$yesterday_total_discount_rs[0]), 2); ?></span>
														<span class="font-weight-normal text-primary" style="font-size: 0.80rem;"> since yesterday</span><?php
													} else if ($todays_total_discount_rs[0] < $yesterday_total_discount_rs[0]) { ?>
														<span class="font-weight-bold text-success" style="font-size: 0.80rem;"><i class="fa fa-arrow-down text-success"></i> <?php echo "$". number_format(abs((float)$todays_total_discount_rs[0] - (float)$yesterday_total_discount_rs[0]), 2); ?></span>
														<span class="font-weight-normal text-primary" style="font-size: 0.80rem;"> since yesterday</span><?php
													}
												?>
											</span>
										</h5>
									</div>
								</div>
							</div>
						</div>

						<div class="col-md-6 col-lg-3 mt-3" style="<?php if ($_SESSION['userTypeID'] == 'PS0001' || $_SESSION['userTypeID'] == 'PS0002')  { echo "display: block"; } else { echo "display: none"; }?>;">
							<div class="tile bg-light-success p-0 shadow">
								<div class="row p-3">
									<div class="col-md-3">
										<i class="fa fa-money fa-2x text-white bg-strong-success p-3 rounded-lg shadow"></i>
									</div>
									<div class="col-md-9 pt-1">
										<h5 class="text-dark">
											<small class="font-weight-bold pb-2" style="display: block;">TOTAL REVENUE</small>
											<?php
												$todays_total_revenue = mysqli_query($conn, "SELECT IFNULL(SUM(customer_payments.paidAmount), 0) 'TotalRevenue' FROM customer_payments WHERE registerDate BETWEEN '$start_date_time' AND '". date("Y-m-d H:i") ."'") or die(mysqli_error($conn));
												$todays_total_revenue_rs = mysqli_fetch_array($todays_total_revenue);
												$yesterday_total_revenue = mysqli_query($conn, "SELECT IFNULL(SUM(customer_payments.paidAmount), 0) 'TotalRevenue' FROM customer_payments WHERE registerDate BETWEEN '$yesterday_start_date' AND '$yesterday_end_date'") or die(mysqli_error($conn));
												$yesterday_total_revenue_rs = mysqli_fetch_array($yesterday_total_revenue); 
											?>
											<span class="font-weight-normal" style="font-size: 0.95rem; display: block;"><?php echo "$". number_format($todays_total_revenue_rs[0], 2); ?></span>
											<span class="pull-right">
												<?php
													if ($todays_total_revenue_rs[0] > $yesterday_total_revenue_rs[0]) { ?>
														<span class="font-weight-bold text-success" style="font-size: 0.80rem;"><i class="fa fa-arrow-up text-success"></i> <?php echo "$". number_format(abs((float)$todays_total_revenue_rs[0] - (float)$yesterday_total_revenue_rs[0]), 2); ?></span>
														<span class="font-weight-normal text-primary" style="font-size: 0.80rem;"> since yesterday</span><?php
													} else if ($todays_total_revenue_rs[0] < $yesterday_total_revenue_rs[0]) { ?>
														<span class="font-weight-bold text-danger" style="font-size: 0.80rem;"><i class="fa fa-arrow-down text-danger"></i> <?php echo "$". number_format(abs((float)$todays_total_revenue_rs[0] - (float)$yesterday_total_revenue_rs[0]), 2); ?></span>
														<span class="font-weight-normal text-primary" style="font-size: 0.80rem;"> since yesterday</span><?php
													}
												?>
											</span>
										</h5>
									</div>
								</div>
							</div>
						</div>

						<div class="col-md-6 col-lg-3 mt-3">
							<div class="tile bg-light-danger p-0 shadow">
								<div class="row p-3">
									<div class="col-md-3">
										<i class="fa fa-dollar fa-2x text-white bg-strong-danger p-3 rounded-lg shadow"></i>
									</div>
									<div class="col-md-9 pt-1">
										<h5 class="text-dark">
											<small class="font-weight-bold pb-2" style="display: block;">TOTAL DUE</small>
											<?php
												$todays_total_due = mysqli_query($conn, "SELECT IFNULL(SUM(restaurant_orders.totalAmount), 0) - IFNULL(SUM(customer_payments.paidAmount), 0) 'DueAmount' FROM restaurant_orders LEFT JOIN customer_payments ON restaurant_orders.orderID = customer_payments.orderID WHERE restaurant_orders.registerDate BETWEEN '$start_date_time' AND '". date("Y-m-d H:i") ."'") or die(mysqli_error($conn));
												$todays_total_due_rs = mysqli_fetch_array($todays_total_due);
												$yesterday_total_due = mysqli_query($conn, "SELECT IFNULL(SUM(restaurant_orders.totalAmount), 0) - IFNULL(SUM(customer_payments.paidAmount), 0) 'DueAmount' FROM restaurant_orders LEFT JOIN customer_payments ON restaurant_orders.orderID = customer_payments.orderID WHERE restaurant_orders.registerDate BETWEEN '$yesterday_start_date' AND '$yesterday_end_date'") or die(mysqli_error($conn));
												$yesterday_total_due_rs = mysqli_fetch_array($yesterday_total_due); 
											?>
											<span class="font-weight-normal" style="font-size: 0.95rem; display: block;"><?php echo "$". number_format($todays_total_due_rs[0], 2); ?></span>
											<span class="pull-right">
												<?php
													if ($todays_total_due_rs[0] > $yesterday_total_due_rs[0]) { ?>
														<span class="font-weight-bold text-danger" style="font-size: 0.80rem;"><i class="fa fa-arrow-up text-danger"></i> <?php echo "$". number_format(abs((float)$todays_total_due_rs[0] - (float)$yesterday_total_due_rs[0]), 2); ?></span>
														<span class="font-weight-normal text-primary" style="font-size: 0.80rem;"> since yesterday</span><?php
													} else if ($todays_total_due_rs[0] < $yesterday_total_due_rs[0]) { ?>
														<span class="font-weight-bold text-success" style="font-size: 0.80rem;"><i class="fa fa-arrow-down text-success"></i> <?php echo "$". number_format(abs((float)$todays_total_due_rs[0] - (float)$yesterday_total_due_rs[0]), 2); ?></span>
														<span class="font-weight-normal text-primary" style="font-size: 0.80rem;"> since yesterday</span><?php
													}
												?>
											</span>
										</h5>
									</div>
								</div>
							</div>
						</div>

						<div class="col-md-6 col-lg-3 mt-3">
							<div class="tile bg-light-danger p-0 shadow">
								<div class="row p-3">
									<div class="col-md-3">
										<i class="fa fa-dollar fa-2x text-white bg-strong-danger p-3 rounded-lg shadow"></i>
									</div>
									<div class="col-md-9 pt-1">
										<h5 class="text-dark">
											<small class="font-weight-bold pb-2" style="display: block;">TOTAL EXPENSES</small>
											<?php
												$todays_total_expenses = mysqli_query($conn, "SELECT IFNULL(SUM(expenseAmount), 0) 'TotalExpenses' FROM expenses WHERE approvedDate BETWEEN '$start_date_time' AND '". date("Y-m-d H:i") ."'") or die(mysqli_error($conn));
												$todays_total_expenses_rs = mysqli_fetch_array($todays_total_expenses);
												$yesterday_total_expenses = mysqli_query($conn, "SELECT IFNULL(SUM(expenseAmount), 0) 'TotalExpenses' FROM expenses WHERE approvedDate  BETWEEN '$yesterday_start_date' AND '$yesterday_end_date'") or die(mysqli_error($conn));
												$yesterday_total_expenses_rs = mysqli_fetch_array($yesterday_total_expenses); 
											?>
											<span class="font-weight-normal" style="font-size: 0.95rem; display: block;"><?php echo "$". number_format($todays_total_expenses_rs[0], 2); ?></span>
											<span class="pull-right">
												<?php
													if ($todays_total_expenses_rs[0] > $yesterday_total_expenses_rs[0]) { ?>
														<span class="font-weight-bold text-danger" style="font-size: 0.80rem;"><i class="fa fa-arrow-up text-danger"></i> <?php echo "$". number_format(abs((float)$todays_total_expenses_rs[0] - (float)$yesterday_total_expenses_rs[0]), 2); ?></span>
														<span class="font-weight-normal text-primary" style="font-size: 0.80rem;"> since yesterday</span><?php
													} else if ($todays_total_expenses_rs[0] < $yesterday_total_expenses_rs[0]) { ?>
														<span class="font-weight-bold text-success" style="font-size: 0.80rem;"><i class="fa fa-arrow-down text-success"></i> <?php echo "$". number_format(abs((float)$todays_total_expenses_rs[0] - (float)$yesterday_total_expenses_rs[0]), 2); ?></span>
														<span class="font-weight-normal text-primary" style="font-size: 0.80rem;"> since yesterday</span><?php
													}
												?>
											</span>
										</h5>
									</div>
								</div>
							</div>
						</div>


					</div>
				</div>
			</div>
			
		</div>
		
		<div class="row mt-5">
			<div class="col-md-12">
				<h2 class="text-primary">Delivery <span class="font-weight-normal">Analytics <sup class="font-weight-normal text-success" style="font-size: 1.19rem;"><?php echo $shown_today_date; ?></sup></span></h2>
			</div>
		</div>
		<div class="row mt-3">
			<div class="col-md-8">
				<div class="tile shadow">
				    <?php
				        $total_delivery_orders = 0;
        		        $getTotalDeliveryOrders = mysqli_query($conn, "SELECT COUNT(restaurant_orders.registeredBy) 'TotalOrders' FROM restaurant_orders JOIN system_users ON restaurant_orders.registeredBy = system_users.userID JOIN employees ON system_users.employeeID = employees.employeeID WHERE restaurant_orders.orderTypeID = 'OT0003' AND restaurant_orders.orderStatus != '4' AND restaurant_orders.registerDate BETWEEN '$start_date_time' AND '". date("Y-m-d H:i") ."'") or die(mysqli_error($conn));
        		        if (mysqli_num_rows($getTotalDeliveryOrders) > 0) {
        		            $delivery_orders_rs = mysqli_fetch_array($getTotalDeliveryOrders);
        		            $total_delivery_orders = $delivery_orders_rs[0];
        		        }
        		        $getDeliveryOrderersFirst = mysqli_query($conn, "SELECT employees.employeeID, system_users.Username, employees.employeePhoto, COUNT(restaurant_orders.orderID) 'TotalOrders'
        		        FROM restaurant_orders
        		        JOIN system_users ON restaurant_orders.registeredBy = system_users.userID
        		        JOIN employees ON system_users.employeeID = employees.employeeID
        		        WHERE restaurant_orders.orderTypeID = 'OT0003' AND restaurant_orders.orderStatus != '4' AND restaurant_orders.registerDate BETWEEN '$start_date_time' AND '". date("Y-m-d H:i") ."'
        		        GROUP BY restaurant_orders.registeredBy
        		        ORDER BY TotalOrders DESC");
        		        if ($getDeliveryOrderersFirst) {
        		            if (mysqli_num_rows($getDeliveryOrderersFirst) > 0) {
        		                
        		                // Declare array to get random value
                                $progress_bg_colors = ["bg-strong-primary", "bg-strong-success", "bg-strong-info", "bg-strong-warning"];
        
        		                while ($delivery_orderers_rs = mysqli_fetch_array($getDeliveryOrderersFirst)) {
        		                    $total_user_orders = $delivery_orderers_rs[3];
        		                    $user_percentage = ($total_user_orders / $total_delivery_orders) * 100;
        		                    $selected_color = $progress_bg_colors[rand(0,3)];
        		                   
        		                    ?><div class="row pt-2 align-items-center">
                						<div class="col-md-2 p-2 pl-3 text-left">
                						    <img class="img-fluid p-1 mr-2 rounded-circle shadow" src="<?php echo $delivery_orderers_rs[2]; ?>" width="47%" height="47%" />
                						    <span class="badge <?php echo $selected_color; ?> text-white mt-2 p-2"><?php echo substr($delivery_orderers_rs[1], 0, 5). ".."; ?></span>
                						</div>
                						<div class="col-md-9">
                							<div class="progress" style="height: 28px;">
                                                <div class="progress-bar <?php echo $selected_color; ?> pt-2" role="progressbar" style="width: <?php echo number_format($user_percentage, 2). "%"; ?>" aria-valuenow="<?php echo number_format($total_user_orders, 2); ?>" aria-valuemin="0" aria-valuemax="100"><h6><?php echo number_format($user_percentage, 2) ."%"; ?></h6></div>
                                            </div>
                						</div>
                						<div class="col-md-1 text-center">
                							<h6 class="bg-primary text-white rounded-lg p-1"><?php echo $total_user_orders; ?></h6>
                						</div>
                					</div><?php
        		                }
        		            } else {
        		                ?><div class="col-md-12 bg-white p-3 mt-3">
        		                    <h6 class="text-center text-danger font-weight-normal">Data Not Found</h6>
        		                </div><?php
        		            }
        		        } else {
        		            ?><div class="col-md-12 bg-white p-3 mt-3">
        	                    <h6 class="text-center text-danger font-weight-normal"><?php echo mysqli_error($conn); ?></h6>
        	                </div><?php
        	            }
                    ?>
				</div>
			</div>
			<div class="col-md-4">
				<div class="tile shadow">
				    <h4 class="text-primary font-weight-bold"><i class="fa fa-motorcycle"></i> Delivery <span class="font-weight-normal">Status <sup class="font-weight-normal text-success" style="font-size: 1.19rem;"><?php echo $shown_today_date; ?></sup></span></h3>
				    <canvas id="dailyDeliveryStatusChart" style="width:100%; height: 350px;"></canvas>
				    <?php
				        $statusLabels = [];
				        $getDeliveryInfo = mysqli_query($conn, "SELECT CASE WHEN orderStatus = 1 THEN 'In Kitchen' WHEN orderStatus = 2 THEN 'On the way' WHEN orderStatus = 3 then 'Delivered' END 'OrderStatus', COUNT(orderStatus) 'TotalOrders' FROM restaurant_orders WHERE orderTypeID = 'OT0003' AND orderStatus != '4' AND restaurant_orders.registerDate BETWEEN '$start_date_time' AND '". date("Y-m-d H:i") ."' GROUP BY orderStatus");
				        if ($getDeliveryInfo) {
				            if (mysqli_num_rows($getDeliveryInfo) > 0) {
				                while ($delivery_info_rs = mysqli_fetch_array($getDeliveryInfo)) {
				                    $statusLabels[] = [$delivery_info_rs[0], $delivery_info_rs[1], random_color()];
				                }
				            } else {
				                
				            }
				        } else {
				            
				        }
				    ?>
				    <script>
				        var delivery_status_data_json = '<?php echo json_encode($statusLabels); ?>';
				        var delivery_status_data = JSON.parse(delivery_status_data_json)
				        var status_names = delivery_status_data.map((status) => status[0])
				        var status_count = delivery_status_data.map((status) => status[1])
				        var status_color = delivery_status_data.map((status) => status[2])

                        new Chart("dailyDeliveryStatusChart", {
                          type: "pie",
                          data: {
                            labels: status_names,
                            datasets: [{
                              backgroundColor: status_color,
                              data: status_count
                            }]
                          }
                        });
                    </script>
				    
				</div>
			</div>
			
		</div>


		<div class="row mt-5">
			<div class="col-md-12">
				<h2 class="text-primary">Waiter <span class="font-weight-normal text-primary">Analytics</span></h2>
			</div>
		</div>
		<div class="row mt-2">
			<div class="col-md-12 p-0">
				<div class="btn-group btn-group-md col-md-12" role="group" aria-label="Basic example">
					<button type="button" class="btn btn-primary btnSelectDateWaiterAnalyticsDashboard" first-date-start="<?php echo $start_date_time; ?>" first-date-end="<?php echo date("Y-m-d H:i"); ?>" second-date-start="<?php echo $yesterday_start_date; ?>" second-date-end="<?php echo $yesterday_end_date; ?>" analytic-type="today" end-used-word=" since yesterday">Today</button>
					<button type="button" class="btn btn-primary btnSelectDateWaiterAnalyticsDashboard" first-date-start="<?php echo date('Y-m-d 06:00', strtotime('last Saturday')); ?>" first-date-end="<?php echo date("Y-m-d H:i"); ?>" second-date-start="<?php echo $last_week_start_day; ?>" second-date-end="<?php echo $yesterday_end_date; ?>" analytic-type="this-week" end-used-word=" since last week">This Week</button>
					<button type="button" class="btn btn-primary btnSelectDateWaiterAnalyticsDashboard" first-date-start="<?php echo date("Y-m-01 06:00"); ?>" first-date-end="<?php echo date("Y-m-d H:i"); ?>" second-date-start="<?php echo $last_month_start_day; ?>" second-date-end="<?php echo $last_month_end_day; ?>" analytic-type="this-month" end-used-word=" since last month">This Month</button>
					<button type="button" class="btn btn-primary btnSelectDateWaiterAnalyticsDashboard" first-date-start="<?php echo date('Y-01-01 06:00'); ?>" first-date-end="<?php echo date("Y-m-d H:i"); ?>" second-date-start="<?php echo $last_year_start_day; ?>" second-date-end="<?php echo $last_year_end_day; ?>" analytic-type="this-year" end-used-word=" since last year">This Year</button>
					<button type="button" class="btn btn-info">
					   <div class="row align-items-center">
        					<div class="col-md-2 font-weight-bold">
        						Custom
        					</div>
        					<div class="col-md-5">
        						<input class="form-control" type="date" name="txtFromDateCustomerWaiterAnalyticsDashboard" id="txtFromDateCustomerWaiterAnalyticsDashboard" value="<?php echo date("Y-m-d"); ?>" max="<?php echo date("Y-m-d"); ?>"/>
        					</div>
        					<div class="col-md-5">
        						<input class="form-control" type="date" name="txtToDateCustomerWaiterAnalyticsDashboard" id="txtToDateCustomerWaiterAnalyticsDashboard" value="<?php echo date("Y-m-d"); ?>" max="<?php echo date("Y-m-d"); ?>"/>
        					</div>
            			</div> 
				    </button>
				</div>
			</div>
			<div class="col-md-1"></div>
			
		</div>

		<div class="row mb-3 waiterAnalyticsDashboardAreaSection">
		    <?php
		        $getWaitersFirst = mysqli_query($conn, "SELECT employees.employeeID, system_users.Username, employees.employeePhoto, COUNT(restaurant_orders.orderID) 'TotalOrders'
		        FROM restaurant_orders
		        JOIN employees ON restaurant_orders.servedBy = employees.employeeID
		        JOIN system_users ON employees.employeeID = system_users.employeeID
		        WHERE (restaurant_orders.orderTypeID = 'OT0001' OR restaurant_orders.orderTypeID = 'OT0002') AND restaurant_orders.orderStatus != '4' AND restaurant_orders.registerDate BETWEEN '$start_date_time' AND '". date("Y-m-d H:i") ."'
		        GROUP BY servedBy
		        ORDER BY TotalOrders DESC");
		        if ($getWaitersFirst) {
		            if (mysqli_num_rows($getWaitersFirst) > 0) {
		                
		                // Declare array to get random value
                        $collout_colors = ["bd-callout-primary", "bd-callout-success", "bd-callout-info", "bd-callout-danger", "bd-callout-warning", "bd-callout-default"];
                        $icon_colors = ["bg-light-primary####bg-strong-primary####text-white", "bg-light-success####bg-strong-success####text-primary", "bg-light-info####bg-strong-info####text-primary", "bg-light-warning####bg-strong-warning####text-primary"];

		                while ($served_waiters_rs = mysqli_fetch_array($getWaitersFirst)) {
		                    $selected_collout_colors = $collout_colors[rand(0,5)];
		                    $selected_icon_colors = $icon_colors[rand(0,3)];
		                    $icon_color_info = explode("####", $selected_icon_colors);
		                    ?><div class="col-lg-3">
                				<div class="btn bg-white bd-callout <?php echo $selected_collout_colors; ?> bg-white p-4 shadow">
                					<div class="row mb-3">
                						<div class="col-md-3">
                						    <img class="img-fluid p-1 rounded-circle shadow" src="<?php echo $served_waiters_rs[2]; ?>" width="90%" height="90%" />
                						</div>
                						<div class="col-md-9">
                							<h5 class="text-left"><small class="font-weight-bold"><?php echo $served_waiters_rs[1]; ?></small></h5>
                						</div>
                					</div>
                					<div class="row <?php echo $icon_color_info[0]; ?> ml-0 mr-0 pl-0 pt-3 pb-1 rounded-lg shadow-sm">
                						<div class="col-md-4 pl-0 pb-1">
                						    <i class="fa fa-shopping-cart text-white <?php echo $icon_color_info[1]; ?> p-3 rounded-lg shadow-sm" style="font-size: 17px;"></i> 
                						</div>
                						<div class="col-md-8 pl-1">
                    						<h5 class="<?php echo $icon_color_info[2]; ?>">
                								<small class="font-weight-bold pb-1" style="display: block;">TOTAL ORDERS</small>
                								<?php
                									// Growth increase or decrease ratio formula$todays_total_orders_rs[0]. " - ".$yesterday_total_orders_rs[0] . " = ". (($todays_total_orders_rs[0]-$yesterday_total_orders_rs[0])/($yesterday_total_orders_rs[0]) * 100)
                									$waiter_yesterday_total_orders = mysqli_query($conn, "SELECT IFNULL(COUNT(orderID), 0) FROM restaurant_orders WHERE servedBy = '$served_waiters_rs[0]' AND orderStatus != '4' AND registerDate BETWEEN '$yesterday_start_date' AND '$yesterday_end_date'") or die(mysqli_error($conn));
                									$waiter_yesterday_total_orders_rs = mysqli_fetch_array($waiter_yesterday_total_orders); 
                									$waiter_todays_total_orders = mysqli_query($conn, "SELECT IFNULL(COUNT(orderID), 0) FROM restaurant_orders WHERE servedBy = '$served_waiters_rs[0]' AND orderStatus != '4' AND registerDate BETWEEN '$start_date_time' AND '". date("Y-m-d H:i") ."'") or die(mysqli_error($conn));
                									$waiter_todays_total_orders_rs = mysqli_fetch_array($waiter_todays_total_orders);
                								?>
                								<span class="font-weight-normal" style="font-size: 0.85rem; display: block;"><?php echo $waiter_todays_total_orders_rs[0]; ?></span>
                								<span>
                									<?php
                										if ($waiter_todays_total_orders_rs[0] > $waiter_yesterday_total_orders_rs[0]) { ?>
                											<span class="text-white bg-strong-success pt-1 pb-1 pl-2 pr-2 rounded-lg" style="font-size: 0.80rem;"><i class="fa fa-long-arrow-up text-white"></i><?php echo abs((float)$waiter_todays_total_orders_rs[0] - (float)$waiter_yesterday_total_orders_rs[0]); ?></span>
                											<span class="font-weight-normal <?php echo $icon_color_info[2]; ?>" style="font-size: 0.80rem;"> since yesterday</span><?php
                										} else if ($waiter_todays_total_orders_rs[0] < $waiter_yesterday_total_orders_rs[0]) { ?>
                											<span class="text-white bg-strong-danger pt-1 pb-1 pl-2 pr-2 rounded-lg" style="font-size: 0.80rem;"><i class="fa fa-long-arrow-down text-white"></i><?php echo abs((float)$waiter_todays_total_orders_rs[0] - (float)$waiter_yesterday_total_orders_rs[0]); ?></span>
                											<span class="font-weight-normal <?php echo $icon_color_info[2]; ?>" style="font-size: 0.80rem;"> since yesterday</span><?php
                										}
                									?>
                								</span>
                							</h5>
                						</div>
                					</div>
                				</div>
                			</div> <?php
		                }
		            } else {
		                ?><div class="col-md-12 bg-white p-3 mt-3">
		                    <h6 class="text-center text-danger font-weight-normal">Data Not Found</h6>
		                </div><?php
		            }
		        } else {
		            ?><div class="col-md-12 bg-white p-3 mt-3">
	                    <h6 class="text-center text-danger font-weight-normal"><?php echo mysqli_error($conn); ?></h6>
	                </div><?php
	            }
		    ?>
		</div>

		<div class="row mt-5">
			<div class="col-md-6 col-lg-3">
				<div class="tile bg-white p-0 shadow">
					<div class="row p-3">
						<div class="col-md-3">
							<i class="fa fa-home fa-3x text-white bg-strong-success p-3 rounded-lg shadow"></i>
						</div>
						<div class="col-md-9">
							<h5><small class="font-weight-bold">TOTAL EXPENSES</small></h5>
							<p class="text-primary" style="font-size: 0.95rem;">$20,400.00</p>
						</div>
					</div>
				</div>
			</div>
		</div>

		<div class="tile mt-4 shadow">
			<div class="row">
				<div class="col-md-6 col-lg-12">
					<div class="row">
						<div class="col-md-6 col-lg-3">
							<div class="tile bg-strong-info p-0">
								<div class="row p-3">
									<div class="col-md-3">
										<i class="fa fa-home fa-4x text-white rounded-lg"></i>
									</div>
									<div class="col-md-9 text-white pt-1">
										<h5><small class="font-weight-bold">TOTAL EXPENSES</small></h5>
										<span style="font-size: 0.95rem;">$20,400.00</span>
									</div>
								</div>
							</div>
						</div>

						<div class="col-md-6 col-lg-3">
							<div class="tile bg-strong-success p-0">
								<div class="row p-3">
									<div class="col-md-3">
										<i class="fa fa-home fa-4x text-white rounded-lg"></i>
									</div>
									<div class="col-md-9 text-white pt-1">
										<h5><small class="font-weight-bold">TOTAL EXPENSES</small></h5>
										<span style="font-size: 0.95rem;">$20,400.00</span>
									</div>
								</div>
							</div>
						</div>

						<div class="col-md-6 col-lg-3">
							<div class="tile bg-strong-warning p-0">
								<div class="row p-3">
									<div class="col-md-3">
										<i class="fa fa-home fa-4x text-white rounded-lg"></i>
									</div>
									<div class="col-md-9 text-white pt-1">
										<h5><small class="font-weight-bold">TOTAL EXPENSES</small></h5>
										<span style="font-size: 0.95rem;">$20,400.00</span>
									</div>
								</div>
							</div>
						</div>

						<div class="col-md-6 col-lg-3">
							<div class="tile bg-strong-danger p-0">
								<div class="row p-3">
									<div class="col-md-3">
										<i class="fa fa-home fa-4x text-white rounded-lg"></i>
									</div>
									<div class="col-md-9 text-white pt-1">
										<h5><small class="font-weight-bold">TOTAL EXPENSES</small></h5>
										<span style="font-size: 0.95rem;">$20,400.00</span>
									</div>
								</div>
							</div>
						</div>

					</div>
				</div>
			</div>
			
		</div>
		
		<div class="row mt-2">
			<div class="col-md-6 col-lg-8">
				<div class="tile shadow">

					<div class="row">
						<div class="col-md-6 col-lg-12">
							<h2>I am Ismail Mohamed Jamal, I am a Full Stack Developer</h2>
							<h3>Be strong this life, because life don't welcome the weak people</h3>
						</div>
					</div>
					<div class="row pt-4">
						<div class="col-md-6 col-lg-3">
							<div class="row">
								<div class="col-md-3">
									<button class="btn pt-2 pb-2 pl-2 pr-1 bg-strong-danger text-white shadow"><i class="fa fa-home" style="font-size: 1.53rem;"></i></button>
								</div>
								<div class="col-md-9 text-danger">
									<span class="font-weight-normal" style="font-size: 0.80rem; display: block;">Total Expenses</span>
									<h5 class="font-weight-bold">$345,000.00</h5>
								</div>
							</div>
						</div>
						<div class="col-md-6 col-lg-3">
							<div class="row">
								<div class="col-md-2">
									<i class="fa fa-home fa-2x p-2 bg-strong-info text-white rounded-lg"></i>
								</div>
								<div class="col-md-10 text-info pl-4">
									<span class="font-weight-normal" style="font-size: 0.80rem; display: block;">Total Expenses</span>
									<h5 class="font-weight-bold">$345,000.00</h5>
								</div>
							</div>
						</div>
						<div class="col-md-6 col-lg-3">
							<div class="row">
								<div class="col-md-2">
									<i class="fa fa-home fa-2x p-2 bg-strong-success text-white rounded-lg"></i>
								</div>
								<div class="col-md-10 text-success pl-4">
									<span class="font-weight-normal" style="font-size: 0.80rem; display: block;">Total Expenses</span>
									<h5 class="font-weight-bold">$345,000.00</h5>
								</div>
							</div>
						</div>
						<div class="col-md-6 col-lg-3">
							<div class="row">
								<div class="col-md-2">
									<i class="fa fa-home fa-2x p-2 bg-strong-warning text-white rounded-lg"></i>
								</div>
								<div class="col-md-10 text-warning pl-4">
									<span class="font-weight-normal" style="font-size: 0.80rem; display: block;">Total Expenses</span>
									<h5 class="font-weight-bold">$345,000.00</h5>
								</div>
							</div>
						</div>
					</div>

				</div>
			</div>

			<div class="col-md-6 col-lg-2">
				<div class="tile shadow">
					<div class="row">
						<div class="col-md-12">
							<i class="fa fa-home fa-3x p-2 bg-strong-info text-white rounded-circle shadow"></i>
						</div>
						<div class="col-md-12 text-success pt-3">
							<span class="font-weight-normal" style="font-size: 0.95rem; display: block;">Total Expenses</span>
							<h2 class="font-weight-bold">$345,000.00</h2>
						</div>
					</div>
				</div>
			</div>

			<div class="col-md-6 col-lg-2">
				<div class="tile shadow">
					<div class="row">
						<div class="col-md-12">
							<i class="fa fa-home fa-3x p-2 bg-strong-success text-white rounded-circle"></i>
						</div>
						<div class="col-md-12 text-primary pt-3">
							<span class="font-weight-normal" style="font-size: 0.95rem; display: block;">Total Expenses</span>
							<h2 class="font-weight-bold">$345,000.00</h2>
						</div>
					</div>
				</div>
			</div>
			
		</div>



	</main>
	
	<!-- Essential javascripts for application to work-->
	<?php include("library/footer.php");?>	    	
	<?php include("library/scripts.php"); ?>
	
  </body>
</html>