<?php
include 'load.php';
if (isset($_SESSION['user_id'])) {
	$user_qury_02 = mysqli_query($conn, "SELECT * FROM tbl_user_branch WHERE user_id='" . $_SESSION['user_id'] . "'");
	$user_res = mysqli_fetch_array($user_qury_02);
	$user_branch = $user_res['branch_id'];
}
$branchid = $_SESSION['branch_id'];

$id2 = $user_res['branch_id'];
$query2 = $DB_con->prepare('SELECT branch_name FROM branch WHERE branch_id=' . $id2);
$query2->execute();
$result2 = $query2->fetch();
$branchName = ($result2['branch_name']) ? ' | ' . $result2['branch_name'] : '';

$sql = "SELECT DATE_FORMAT(create_at,'%Y-%m') AS sale_month, SUM(amount) AS total_amount
					FROM mobileorders
					WHERE create_at >= DATE_FORMAT(CURRENT_DATE,'%Y-01-01')
					GROUP BY DATE_FORMAT(create_at,'%Y-%m') ";

$result = $conn->query($sql);

$labels = [];
$data = [];
if ($result->num_rows > 0) {
	while ($row = $result->fetch_assoc()) {
		$labels[] = date('F Y', strtotime($row['sale_month'] . '-01'));
		$data[] = $row['total_amount'];
	}
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
	<style>
		.card {
			background-color: #fff;
			border-radius: 10px;
			border: none;
			position: relative;
			margin-bottom: 15px;
			box-shadow: 0 0.46875rem 2.1875rem rgba(90, 97, 105, 0.1), 0 0.9375rem 1.40625rem rgba(90, 97, 105, 0.1), 0 0.25rem 0.53125rem rgba(90, 97, 105, 0.12), 0 0.125rem 0.1875rem rgba(90, 97, 105, 0.1);
		}

		.l-bg-cherry {
			background: linear-gradient(to right, #493240, #f09) !important;
			color: #fff;
		}

		.l-bg-blue-dark {
			background: linear-gradient(to right, #373b44, #4286f4) !important;
			color: #fff;
		}

		.l-bg-green-dark {
			background: linear-gradient(to right, #0a504a, #38ef7d) !important;
			color: #fff;
		}

		.l-bg-orange-dark {
			background: linear-gradient(to right, #a86008, #ffba56) !important;
			color: #fff;
		}

		.l-bg-purple-dark {
			background: linear-gradient(to right, #4b0082, #9932cc) !important;
			color: #fff;
		}

		.l-bg-yellow-dark {
			background: linear-gradient(to right, #ffd700, #ff8c00) !important;
			color: #fff;
		}

		.l-bg-red-dark {
			background: linear-gradient(to right, #8b0000, #ff6347) !important;
			color: #fff;
		}

		.l-bg-cyan-dark {
			background: linear-gradient(to right, #008b8b, #00ced1) !important;
			color: #fff;
		}

		.l-bg-magenta-dark {
			background: linear-gradient(to right, #8b008b, #ff69b4) !important;
			color: #fff;
		}

		.l-bg-green-light {
			background-color: #d4edda;
			/* Light green color */
		}


		.card .card-statistic-3 .card-icon-large .fas,
		.card .card-statistic-3 .card-icon-large .far,
		.card .card-statistic-3 .card-icon-large .fab,
		.card .card-statistic-3 .card-icon-large .fal {
			font-size: 110px;
		}

		.card .card-statistic-3 .card-icon {
			padding: 2rem;
			text-align: center;
			line-height: 50px;
			margin-left: 15px;
			color: #000;
			position: absolute;
			right: -5px;
			top: 20px;
			opacity: 0.1;
		}

		.l-bg-cyan {
			background: linear-gradient(135deg, #289cf5, #84c0ec) !important;
			color: #fff;
		}

		.l-bg-green {
			background: linear-gradient(135deg, #23bdb8 0%, #43e794 100%) !important;
			color: #fff;
		}

		.l-bg-orange {
			background: linear-gradient(to right, #f9900e, #ffba56) !important;
			color: #fff;
		}

		.l-bg-cyan {
			background: linear-gradient(135deg, #289cf5, #84c0ec) !important;
			color: #fff;
		}

		.l-bg-pink {
			background: linear-gradient(135deg, #ff4e50, #ff8a65) !important;
			color: #fff;
		}

		.l-bg-blue {
			background: linear-gradient(135deg, #3498db, #9b59b6) !important;
			color: #fff;
		}

		.l-bg-purple {
			background: linear-gradient(135deg, #82589F, #A8CABA) !important;
			color: #fff;
		}

		.l-bg-yellow {
			background: linear-gradient(to right, #f9d423, #ff4e50) !important;
			color: #fff;
		}
	</style>
	<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'; ?>
	<script src="assets/js/popper.min.js" integrity="sha384-XThWIDJf7H0ql8C6iGvrZo9v3/PJq2gN73WTW9aKdFm+0lw1Wkk8jKVz07trZTdW" crossorigin="anonymous">
	</script>
	<script src="assets/js/bootstrap.min.js" integrity="sha384-Wm1vFJWFazXGMpBLQXeRRJIXwu4qnp68vmyeSogB8IZBfF2Pmr3UHzqLeW/Z+TZ8" crossorigin="anonymous">
	</script>
</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="row">
					<div class="col-lg-12  col-12 admin_title">
						<h2>Welcome to the POS Admin Panel <?= $branchName; ?></h2>
					</div>
					<!-- <div class="card bg-light"> -->
					<div class="row chart_details">
						<div class="col-lg-12 col-md-12 col-xl-12">
						<div class="row">
							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-cherry">
									<div class="card-statistic-3 p-4">
										<?php

										date_default_timezone_set("Asia/Colombo");
											
										$startmonth = date("Y-m-01");
										$endmonth = date("Y-m-30");
										$currentmonth = date('F', strtotime($startmonth));

										if ($branch_id == '1') {

										$stmt = $DB_con->prepare("SELECT SUM(mo.amount) as totalsales FROM mobileorders mo WHERE mo.create_at BETWEEN '$startmonth 00:00:00' AND '$endmonth 23:59:59'");

										} else {

										$stmt = $DB_con->prepare("SELECT SUM(mo.amount) as totalsales FROM mobileorders mo INNER JOIN invoice_other_details iod ON mo.order_id=iod.order_id WHERE iod.branch_id='$branch_id' AND mo.create_at BETWEEN '$startmonth 00:00:00' AND '$endmonth 23:59:59'");

										}
										
										$stmt->execute();

										if($stmt->rowCount() > 0)

										{

										while($row=$stmt->fetch(PDO::FETCH_ASSOC))

										{

										extract($row);

										$SumAmountView = $row['totalsales'];
										
										?>
										<div class="card-icon card-icon-large"><i class="fas fa-coins"></i> </div>
										<div class="mb-4">
											<h5 class="card-title mb-0">
											<h6>Total <?php echo $currentmonth; ?> Sales</h6>
											</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
												Rs.<?php echo number_format($SumAmountView, 2); ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-cyan" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
										<?php 
										} 
										} 
										?>
									</div>
								</div>
							</div>

							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-blue-dark">
									<div class="card-statistic-3 p-4">
									<?php
										
										date_default_timezone_set("Asia/Colombo");
										$today = date("Y-m-d");
										
										if ($branch_id == '1') {
											$stmt = $DB_con->prepare("SELECT SUM(mo.amount) as totalsales FROM mobileorders mo WHERE DATE(mo.create_at) = :today");
										} else {
											$stmt = $DB_con->prepare("SELECT SUM(mo.amount) as totalsales FROM mobileorders mo INNER JOIN invoice_other_details iod ON mo.order_id=iod.order_id WHERE iod.branch_id=:branch_id AND DATE(mo.create_at) = :today");
										}
										
										$stmt->bindParam(':today', $today);
										if ($branch_id != '1') {
											$stmt->bindParam(':branch_id', $branch_id);
										}
										
										
										$stmt->execute();

										if($stmt->rowCount() > 0)

										{

										while($row=$stmt->fetch(PDO::FETCH_ASSOC))

										{

										extract($row);
										
										$SumDailyAmountView = $row['totalsales'];

										?>
										<div class="card-icon card-icon-large"><i class="fas fa-shopping-cart"></i></div>
										<div class="mb-4">
										<h5 class="card-title mb-0">Total Daily Sales</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
													Rs.<?php echo number_format($SumDailyAmountView, 2); ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-green" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
										<?php 
										} 
										} 
										?>
									</div>
								</div>
							</div>

							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-cherry">
									<div class="card-statistic-3 p-4">
									<?php
										
										date_default_timezone_set("Asia/Colombo");
										$yesterday = date("Y-m-d", strtotime("-1 day"));
										
										if ($branch_id == '1') {

										$stmt = $DB_con->prepare("SELECT SUM(mo.amount) as totalsales FROM mobileorders mo WHERE DATE(mo.create_at) = '$yesterday'");

										} else {

										$stmt = $DB_con->prepare("SELECT SUM(mo.amount) as totalsales FROM mobileorders mo INNER JOIN invoice_other_details iod ON mo.order_id=iod.order_id WHERE iod.branch_id='$branch_id' AND DATE(mo.create_at) = '$yesterday'");

										}
										
										$stmt->execute();

										if($stmt->rowCount() > 0)

										{

										while($row=$stmt->fetch(PDO::FETCH_ASSOC))

										{

										extract($row);

										$SumYesterdayAmountView = $row['totalsales'];
	
										?>
											
										<div class="card-icon card-icon-large"><i class="fas fa-shopping-cart"></i></div>
										<div class="mb-4">
											<h5 class="card-title mb-0">Total Yesterday Sales</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
													Rs.<?php echo number_format($SumYesterdayAmountView, 2); ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-green" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
										<?php 
										} 
										} 
										?>
									</div>
								</div>
							</div>


							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-green-dark">
									<div class="card-statistic-3 p-4">
									<?php

											date_default_timezone_set("Asia/Colombo");
											$startmonth = date("Y-m-01");
											$endmonth = date("Y-m-30");
											$currentmonth = date('F', strtotime($startmonth));
											
											$profit=0;
											$marketprofit=0;

											$totalrowprofitamount=0;
											$totalrowmarketprofitamount=0;

											if ($branch_id == '1') {
												$stmt = $DB_con->prepare("SELECT mo.order_id as moorderid,mo.orid,mo.customer,mo.pay_option,mo.amount as moamount,mo.paid_amount,mo.due_amount,mtc.pro_discount,mtc.proid,mtc.discount_type,mo.discount,mo.all_discount,mo.discount_type,mo.status as mostatus,mo.create_at,SUM(mo.discount) as totaldiscount,SUM(mo.discount) as totaldiscount,SUM(mtc.pro_price * mtc.pro_qty) as totalbillptotal,SUM(mp.price * mtc.pro_qty) as totalproducttotal,SUM(mp.market_price * mtc.pro_qty) as totalproductmarkettotal FROM mobileorders mo INNER JOIN 
mobiletemporarycart mtc ON mo.order_id=mtc.orderid INNER JOIN
mobileproducts mp ON mtc.proid=mp.prid INNER JOIN
invoice_other_details iod ON mtc.orderid=iod.order_id
WHERE mo.create_at BETWEEN '$startmonth 00:00:00' AND '$endmonth 23:59:59' AND mtc.proid!='148' ORDER BY mo.create_at DESC");
											} else {
												$stmt = $DB_con->prepare("SELECT mo.order_id as moorderid,mo.orid,mo.customer,mo.pay_option,mo.amount as moamount,mo.paid_amount,mo.due_amount,mtc.pro_discount,mtc.proid,mtc.discount_type,mo.discount,mo.all_discount,mo.discount_type,mo.status as mostatus,mo.create_at,SUM(mo.discount) as totaldiscount,SUM(mtc.pro_price * mtc.pro_qty) as totalbillptotal,SUM(mp.price * mtc.pro_qty) as totalproducttotal,SUM(mp.market_price * mtc.pro_qty) as totalproductmarkettotal FROM mobileorders mo INNER JOIN 
mobiletemporarycart mtc ON mo.order_id=mtc.orderid INNER JOIN
mobileproducts mp ON mtc.proid=mp.prid INNER JOIN
invoice_other_details iod ON mtc.orderid=iod.order_id
WHERE iod.branch_id='$branch_id' AND mo.create_at BETWEEN '$startmonth 00:00:00' AND '$endmonth 23:59:59' AND mtc.proid!='148' ORDER BY mo.create_at DESC");
											}

										$stmt->execute();

										if($stmt->rowCount() > 0)

										{

										while($row=$stmt->fetch(PDO::FETCH_ASSOC))

										{

										extract($row);

										$profit=$row['totalbillptotal']-$row['totalproducttotal'];
										
										$marketprofit=$row['totalproductmarkettotal']-$row['totalproducttotal'];

										$totalrowprofitamount=$totalrowprofitamount+$profit-$row['totaldiscount'];
										
										$totalrowmarketprofitamount=$totalrowmarketprofitamount+$marketprofit-$row['totaldiscount'];

										$orders = mysqli_fetch_array(mysqli_query($conn, "SELECT SUM(amount) as amount FROM mobileorders"));
										$productcost = mysqli_fetch_array(mysqli_query($conn, "SELECT SUM(mobileproducts.price * mobiletemporarycart.pro_qty) as cost
														FROM mobiletemporarycart
														JOIN mobileproducts ON mobiletemporarycart.proid = mobileproducts.prid"));
										$totalprofi = $orders['amount'] - $productcost['cost'];
										//$profitnormal = number_format($totalprofi, 2);
										//var_dump($totalprofi);

										?>
										<div class="card-icon card-icon-large"><i class="fas fa-ticket-alt"></i></div>
										<div class="mb-4">
											<h5 class="card-title mb-0">Total Profit(Normal)</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
													Rs.<?php echo number_format($totalprofi, 2); ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-orange" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
										<?php 
										} 
										} 
										?>
									</div>
								</div>
							</div>

							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-cyan-dark">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-dollar-sign"></i></div>
										<div class="mb-4">
											<?php
											date_default_timezone_set("Asia/Colombo");
											$today = date("Y-m-d");

											$profit=0;
											$marketprofit=0;
											
											$totalrowprofitamount=0;
											$totalrowmarketprofitamount=0;

											if ($branch_id == '1') {
												$stmt = $DB_con->prepare("SELECT mo.order_id as moorderid,mo.orid,mo.customer,mo.pay_option,mo.amount as moamount,mo.paid_amount,mo.due_amount,mtc.pro_discount,mtc.proid,mtc.discount_type,mo.discount,mo.all_discount,mo.discount_type,mo.status as mostatus,mo.create_at,SUM(mo.discount) as totaldiscount,SUM(mtc.pro_price * mtc.pro_qty) as totalbillptotal,SUM(mp.price * mtc.pro_qty) as totalproducttotal,SUM(mp.market_price * mtc.pro_qty) as totalproductmarkettotal FROM mobileorders mo INNER JOIN 
mobiletemporarycart mtc ON mo.order_id=mtc.orderid INNER JOIN
mobileproducts mp ON mtc.proid=mp.prid INNER JOIN
invoice_other_details iod ON mtc.orderid=iod.order_id
WHERE DATE(mo.create_at) = '$today' AND mtc.proid!='148' ORDER BY mo.create_at DESC");
											} else {
												$stmt = $DB_con->prepare("SELECT mo.order_id as moorderid,mo.orid,mo.customer,mo.pay_option,mo.amount as moamount,mo.paid_amount,mo.due_amount,mtc.pro_discount,mtc.proid,mtc.discount_type,mo.discount,mo.all_discount,mo.discount_type,mo.status as mostatus,mo.create_at,SUM(mo.discount) as totaldiscount,SUM(mtc.pro_price * mtc.pro_qty) as totalbillptotal,SUM(mp.price * mtc.pro_qty) as totalproducttotal,SUM(mp.market_price * mtc.pro_qty) as totalproductmarkettotal FROM mobileorders mo INNER JOIN 
mobiletemporarycart mtc ON mo.order_id=mtc.orderid INNER JOIN
mobileproducts mp ON mtc.proid=mp.prid INNER JOIN
invoice_other_details iod ON mtc.orderid=iod.order_id
WHERE iod.branch_id='$branch_id' AND DATE(mo.create_at)='$today' AND mtc.proid!='148' ORDER BY mo.create_at DESC");
											}

										$stmt->execute();

										if($stmt->rowCount() > 0)

										{

										while($row=$stmt->fetch(PDO::FETCH_ASSOC))

										{

										extract($row);
										
										$profit=$row['totalbillptotal']-$row['totalproducttotal'];
										
										$marketprofit=$row['totalproductmarkettotal']-$row['totalproducttotal'];

										$totalrowprofitamount=$totalrowprofitamount+$profit-$row['totaldiscount'];
										
										$totalrowmarketprofitamount=$totalrowmarketprofitamount+$marketprofit-$row['totaldiscount'];
										

										

										$orders = mysqli_fetch_array(mysqli_query($conn, "SELECT SUM(amount) as amount FROM mobileorders WHERE DATE(create_at) ='$today'"));
										$productcost = mysqli_fetch_array(mysqli_query($conn, "SELECT SUM(mobileproducts.price * mobiletemporarycart.pro_qty) as cost
														FROM mobiletemporarycart
														JOIN mobileproducts ON mobiletemporarycart.proid = mobileproducts.prid WHERE DATE(mobiletemporarycart.added_date) ='$today'"));
										$totalprofi = $orders['amount'] - $productcost['cost'];



										?>
										<h5 class="card-title mb-0">Total Daily Profit(Normal)</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
												Rs.<?php echo number_format($totalprofi, 2); ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-cyan" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
										<?php 
										} 
										} 
										?>
									</div>
								</div>
							</div>
						
							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card  l-bg-orange-dark">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-dollar-sign"></i></div>
										<div class="mb-4">
											<?php
											date_default_timezone_set("Asia/Colombo");
											$today = date("Y-m-d");
											$yesterday = date("Y-m-d", strtotime("-1 day"));

											$profit=0;
											$marketprofit=0;
											
											$totalrowprofitamount=0;
											$totalrowmarketprofitamount=0;

											if ($branch_id == '1') {
												$stmt = $DB_con->prepare("SELECT mo.order_id as moorderid,mo.orid,mo.customer,mo.pay_option,mo.amount as moamount,mo.paid_amount,mo.due_amount,mtc.pro_discount,mtc.proid,mtc.discount_type,mo.discount,mo.all_discount,mo.discount_type,mo.status as mostatus,mo.create_at,SUM(mo.discount) as totaldiscount,SUM(mtc.pro_price * mtc.pro_qty) as totalbillptotal,SUM(mp.price * mtc.pro_qty) as totalproducttotal,SUM(mp.market_price * mtc.pro_qty) as totalproductmarkettotal FROM mobileorders mo INNER JOIN 
mobiletemporarycart mtc ON mo.order_id=mtc.orderid INNER JOIN
mobileproducts mp ON mtc.proid=mp.prid INNER JOIN
invoice_other_details iod ON mtc.orderid=iod.order_id
WHERE DATE(mo.create_at) = '$yesterday' AND mtc.proid!='148' ORDER BY mo.create_at DESC");
											} else {
												$stmt = $DB_con->prepare("SELECT mo.order_id as moorderid,mo.orid,mo.customer,mo.pay_option,mo.amount as moamount,mo.paid_amount,mo.due_amount,mtc.pro_discount,mtc.proid,mtc.discount_type,mo.discount,mo.all_discount,mo.discount_type,mo.status as mostatus,mo.create_at,SUM(mo.discount) as totaldiscount,SUM(mtc.pro_price * mtc.pro_qty) as totalbillptotal,SUM(mp.price * mtc.pro_qty) as totalproducttotal,SUM(mp.market_price * mtc.pro_qty) as totalproductmarkettotal FROM mobileorders mo INNER JOIN 
mobiletemporarycart mtc ON mo.order_id=mtc.orderid INNER JOIN
mobileproducts mp ON mtc.proid=mp.prid INNER JOIN
invoice_other_details iod ON mtc.orderid=iod.order_id
WHERE iod.branch_id='$branch_id' AND DATE(mo.create_at)='$yesterday' AND mtc.proid!='148' ORDER BY mo.create_at DESC");
											}

										$stmt->execute();

										if($stmt->rowCount() > 0)

										{

										while($row=$stmt->fetch(PDO::FETCH_ASSOC))

										{

										extract($row);
										
										$profit=$row['totalbillptotal']-$row['totalproducttotal'];
										
										$marketprofit=$row['totalproductmarkettotal']-$row['totalproducttotal'];

										$totalrowprofitamount=$totalrowprofitamount+$profit-$row['totaldiscount'];
										
										$totalrowmarketprofitamount=$totalrowmarketprofitamount+$marketprofit-$row['totaldiscount'];

										$orders = mysqli_fetch_array(mysqli_query($conn, "SELECT SUM(amount) as amount FROM mobileorders WHERE DATE(create_at) = CURDATE() - INTERVAL 1 DAY"));
										$productcost = mysqli_fetch_array(mysqli_query($conn, "SELECT SUM(mobileproducts.price * mobiletemporarycart.pro_qty) as cost
														FROM mobiletemporarycart
														JOIN mobileproducts ON mobiletemporarycart.proid = mobileproducts.prid WHERE DATE(mobiletemporarycart.added_date) = CURDATE() - INTERVAL 1 DAY"));
										$totalprofi = $orders['amount'] - $productcost['cost'];

										?>
											<h5 class="card-title mb-0">Total Yesterday Profit(Normal)</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
												Rs.<?php echo number_format($totalprofi, 2); ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-cyan" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
										<?php 
										} 
										} 
										?>
									</div>
								</div>
							</div>
							
							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-red-dark">
									<div class="card-statistic-3 p-4">
									<?php

											date_default_timezone_set("Asia/Colombo");
											$startmonth = date("Y-m-01");
											$endmonth = date("Y-m-30");
											$currentmonth = date('F', strtotime($startmonth));
											
											$profit=0;
											$marketprofit=0;

											$totalrowprofitamount=0;
											$totalrowmarketprofitamount=0;

											if ($branch_id == '1') {
												$stmt = $DB_con->prepare("SELECT mo.order_id as moorderid,mo.orid,mo.customer,mo.pay_option,mo.amount as moamount,mo.paid_amount,mo.due_amount,mtc.pro_discount,mtc.proid,mtc.discount_type,mo.discount,mo.all_discount,mo.discount_type,mo.status as mostatus,mo.create_at,SUM(mo.discount) as totaldiscount,SUM(mtc.pro_price * mtc.pro_qty) as totalbillptotal,SUM(mp.price * mtc.pro_qty) as totalproducttotal,SUM(mp.market_price * mtc.pro_qty) as totalproductmarkettotal FROM mobileorders mo INNER JOIN 
mobiletemporarycart mtc ON mo.order_id=mtc.orderid INNER JOIN
mobileproducts mp ON mtc.proid=mp.prid INNER JOIN
invoice_other_details iod ON mtc.orderid=iod.order_id
WHERE mo.create_at BETWEEN '$startmonth 00:00:00' AND '$endmonth 23:59:59' AND mtc.proid!='148' ORDER BY mo.create_at DESC");
											} else {
												$stmt = $DB_con->prepare("SELECT mo.order_id as moorderid,mo.orid,mo.customer,mo.pay_option,mo.amount as moamount,mo.paid_amount,mo.due_amount,mtc.pro_discount,mtc.proid,mtc.discount_type,mo.discount,mo.all_discount,mo.discount_type,mo.status as mostatus,mo.create_at,SUM(mo.discount) as totaldiscount,SUM(mtc.pro_price * mtc.pro_qty) as totalbillptotal,SUM(mp.price * mtc.pro_qty) as totalproducttotal,SUM(mp.market_price * mtc.pro_qty) as totalproductmarkettotal FROM mobileorders mo INNER JOIN 
mobiletemporarycart mtc ON mo.order_id=mtc.orderid INNER JOIN
mobileproducts mp ON mtc.proid=mp.prid INNER JOIN
invoice_other_details iod ON mtc.orderid=iod.order_id
WHERE iod.branch_id='$branch_id' AND mo.create_at BETWEEN '$startmonth 00:00:00' AND '$endmonth 23:59:59' AND mtc.proid!='148' ORDER BY mo.create_at DESC");
											}

										$stmt->execute();

										if($stmt->rowCount() > 0)

										{

										while($row=$stmt->fetch(PDO::FETCH_ASSOC))

										{

										extract($row);

										$profit=$row['totalbillptotal']-$row['totalproducttotal'];
										
										$marketprofit=$row['totalproductmarkettotal']-$row['totalproducttotal'];

										$totalrowprofitamount=$totalrowprofitamount+$profit-$row['totaldiscount'];
										
										$totalrowmarketprofitamount=$totalrowmarketprofitamount+$marketprofit-$row['totaldiscount'];

										/*$list = mysqli_query($conn, "SELECT * FROM mobiletemporarycart,mobileproducts,mobileorders WHERE mobiletemporarycart.proid=mobileproducts.prid AND mobiletemporarycart.orderid=mobileorders.order_id AND mobiletemporarycart.proid !='148'");
										$totalprofit = 0;
										if ($list->num_rows > 0) {
											while($row = $list->fetch_assoc()) {
												$cartprice = $row['pro_price'];
												$costprice = $row['price'];
												if($row['pro_discount']!=0){
													if($row['discount_type']==0){
														$cartprice = $cartprice - $row['pro_discount'];
													}else{
														$dis = ($cartprice / 100) * $row['pro_discount'];
														$cartprice = $cartprice - $dis;
													}
												}
												if($row['tax']!=0){
													if($row['tax_type']==0){
														$cartprice = $cartprice - $row['tax'];
													}else{
														$tax = ($cartprice / 100) * $row['tax'];
														$cartprice = $cartprice - $tax;
													}
												}

												$totalprofit = $totalprofit + ($cartprice - $costprice);

											}
										}
											*/



										?>
										<div class="card-icon card-icon-large"><i class="fas fa-ticket-alt"></i></div>
										<div class="mb-4">
											<h5 class="card-title mb-0">Total Profit(Market Price)</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
													Rs.<?php echo number_format($totalrowmarketprofitamount); ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-orange" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
										<?php 
										} 
										} 
										?>
									</div>
								</div>
							</div>

							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-cherry">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-dollar-sign"></i></div>
										<div class="mb-4">
											<?php
											date_default_timezone_set("Asia/Colombo");
											$today = date("Y-m-d");

											$profit=0;
											$marketprofit=0;
											
											$totalrowprofitamount=0;
											$totalrowmarketprofitamount=0;

											if ($branch_id == '1') {
												$stmt = $DB_con->prepare("SELECT mo.order_id as moorderid,mo.orid,mo.customer,mo.pay_option,mo.amount as moamount,mo.paid_amount,mo.due_amount,mtc.pro_discount,mtc.proid,mtc.discount_type,mo.discount,mo.all_discount,mo.discount_type,mo.status as mostatus,mo.create_at,SUM(mo.discount) as totaldiscount,SUM(mtc.pro_price * mtc.pro_qty) as totalbillptotal,SUM(mp.price * mtc.pro_qty) as totalproducttotal,SUM(mp.market_price * mtc.pro_qty) as totalproductmarkettotal FROM mobileorders mo INNER JOIN 
mobiletemporarycart mtc ON mo.order_id=mtc.orderid INNER JOIN
mobileproducts mp ON mtc.proid=mp.prid INNER JOIN
invoice_other_details iod ON mtc.orderid=iod.order_id
WHERE DATE(mo.create_at) = '$today' AND mtc.proid!='148' ORDER BY mo.create_at DESC");
											} else {
												$stmt = $DB_con->prepare("SELECT mo.order_id as moorderid,mo.orid,mo.customer,mo.pay_option,mo.amount as moamount,mo.paid_amount,mo.due_amount,mtc.pro_discount,mtc.proid,mtc.discount_type,mo.discount,mo.all_discount,mo.discount_type,mo.status as mostatus,mo.create_at,SUM(mo.discount) as totaldiscount,SUM(mtc.pro_price * mtc.pro_qty) as totalbillptotal,SUM(mp.price * mtc.pro_qty) as totalproducttotal,SUM(mp.market_price * mtc.pro_qty) as totalproductmarkettotal FROM mobileorders mo INNER JOIN 
mobiletemporarycart mtc ON mo.order_id=mtc.orderid INNER JOIN
mobileproducts mp ON mtc.proid=mp.prid INNER JOIN
invoice_other_details iod ON mtc.orderid=iod.order_id
WHERE iod.branch_id='$branch_id' AND DATE(mo.create_at)='$today' AND mtc.proid!='148'  AND mtc.proid!='148' ORDER BY mo.create_at DESC");
											}

										$stmt->execute();

										if($stmt->rowCount() > 0)

										{

										while($row=$stmt->fetch(PDO::FETCH_ASSOC))

										{

										extract($row);
										
										$profit=$row['totalbillptotal']-$row['totalproducttotal'];
										
										$marketprofit=$row['totalproductmarkettotal']-$row['totalproducttotal'];

										$totalrowprofitamount=$totalrowprofitamount+$profit-$row['totaldiscount'];
										
										$totalrowmarketprofitamount=$totalrowmarketprofitamount+$marketprofit-$row['totaldiscount'];

										?>
										<h5 class="card-title mb-0">Total Daily Profit(Market Price)</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
												Rs.<?php echo number_format($totalrowmarketprofitamount, 2); ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-cyan" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
										<?php 
										} 
										} 
										?>
									</div>
								</div>
							</div>
						
							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card  l-bg-purple-dark">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-dollar-sign"></i></div>
										<div class="mb-4">
											<?php
											/*date_default_timezone_set("Asia/Colombo");
											$today = date("Y-m-d");
											$yesterday = date("Y-m-d", strtotime("-1 day"));

											$profit=0;
											$marketprofit=0;
											
											$totalrowprofitamount=0;
											$totalrowmarketprofitamount=0;

											if ($branch_id == '1') {
												$stmt = $DB_con->prepare("SELECT mo.order_id as moorderid,mo.orid,mo.customer,mo.pay_option,mo.amount as moamount,mo.paid_amount,mo.due_amount,mtc.pro_discount,mtc.proid,mtc.discount_type,mo.discount,mo.all_discount,mo.discount_type,mo.status as mostatus,mo.create_at,SUM(mo.discount) as totaldiscount,SUM(mtc.pro_price * mtc.pro_qty) as totalbillptotal,SUM(mp.price * mtc.pro_qty) as totalproducttotal,SUM(mp.market_price * mtc.pro_qty) as totalproductmarkettotal FROM mobileorders mo INNER JOIN 
mobiletemporarycart mtc ON mo.order_id=mtc.orderid INNER JOIN
mobileproducts mp ON mtc.proid=mp.prid INNER JOIN
invoice_other_details iod ON mtc.orderid=iod.order_id
WHERE DATE(mo.create_at) = '$yesterday' AND mtc.proid!='148' ORDER BY mo.create_at DESC");
											} else {
												$stmt = $DB_con->prepare("SELECT mo.order_id as moorderid,mo.orid,mo.customer,mo.pay_option,mo.amount as moamount,mo.paid_amount,mo.due_amount,mtc.pro_discount,mtc.proid,mtc.discount_type,mo.discount,mo.all_discount,mo.discount_type,mo.status as mostatus,mo.create_at,SUM(mo.discount) as totaldiscount,bg-orange-darkbg-cherrySUM(mtc.pro_price * mtc.pro_qty) as totalbillptotal,SUM(mp.price * mtc.pro_qty) as totalproducttotal,SUM(mp.market_price * mtc.pro_qty) as totalproductmarkettotal FROM mobileorders mo INNER JOIN 
mobiletemporarycart mtc ON mo.order_id=mtc.orderid INNER JOIN
mobileproducts mp ON mtc.proid=mp.prid INNER JOIN
invoice_other_details iod ON mtc.orderid=iod.order_id
WHERE iod.branch_id='$branch_id' AND DATE(mo.create_at)='$yesterday' AND mtc.proid!='148' ORDER BY mo.create_at DESC");
											}

										$stmt->execute();

										if($stmt->rowCount() > 0)

										{

										while($row=$stmt->fetch(PDO::FETCH_ASSOC))

										{

										extract($row);
										
										$profit=$row['totalbillptotal']-$row['totalproducttotal'];
										
										$marketprofit=$row['totalproductmarkettotal']-$row['totalproducttotal'];

										$totalrowprofitamount=$totalrowprofitamount+$profit-$row['totaldiscount'];
										
										$totalrowmarketprofitamount=$totalrowmarketprofitamount+$marketprofit-$row['totaldiscount'];
										*/

										date_default_timezone_set("Asia/Colombo");
$today = date("Y-m-d");
$yesterday = date("Y-m-d", strtotime("-1 day"));

$profit = 0;
$marketprofit = 0;

$totalrowprofitamount = 0;
$totalrowmarketprofitamount = 0;

try {
    // Prepare SQL query based on branch ID
    if ($branch_id == '1') {
        $stmt = $DB_con->prepare("SELECT mo.order_id as moorderid, mo.orid, mo.customer, mo.pay_option, mo.amount as moamount, mo.paid_amount, mo.due_amount, 
                                  mtc.pro_discount, mtc.proid, mtc.discount_type, mo.discount, mo.all_discount, mo.discount_type, mo.status as mostatus, 
                                  mo.create_at, SUM(mo.discount) as totaldiscount, SUM(mtc.pro_price * mtc.pro_qty) as totalbillptotal, 
                                  SUM(mp.price * mtc.pro_qty) as totalproducttotal, SUM(mp.market_price * mtc.pro_qty) as totalproductmarkettotal 
                                  FROM mobileorders mo 
                                  INNER JOIN mobiletemporarycart mtc ON mo.order_id = mtc.orderid 
                                  INNER JOIN mobileproducts mp ON mtc.proid = mp.prid 
                                  INNER JOIN invoice_other_details iod ON mtc.orderid = iod.order_id 
                                  WHERE DATE(mo.create_at) = :yesterday AND mtc.proid != '148' 
                                  GROUP BY mo.order_id 
                                  ORDER BY mo.create_at DESC");
        $stmt->bindParam(':yesterday', $yesterday);
    } else {
        $stmt = $DB_con->prepare("SELECT mo.order_id as moorderid, mo.orid, mo.customer, mo.pay_option, mo.amount as moamount, mo.paid_amount, mo.due_amount, 
                                  mtc.pro_discount, mtc.proid, mtc.discount_type, mo.discount, mo.all_discount, mo.discount_type, mo.status as mostatus, 
                                  mo.create_at, SUM(mo.discount) as totaldiscount, SUM(mtc.pro_price * mtc.pro_qty) as totalbillptotal, 
                                  SUM(mp.price * mtc.pro_qty) as totalproducttotal, SUM(mp.market_price * mtc.pro_qty) as totalproductmarkettotal 
                                  FROM mobileorders mo 
                                  INNER JOIN mobiletemporarycart mtc ON mo.order_id = mtc.orderid 
                                  INNER JOIN mobileproducts mp ON mtc.proid = mp.prid 
                                  INNER JOIN invoice_other_details iod ON mtc.orderid = iod.order_id 
                                  WHERE iod.branch_id = :branch_id AND DATE(mo.create_at) = :yesterday AND mtc.proid != '148' 
                                  GROUP BY mo.order_id 
                                  ORDER BY mo.create_at DESC");
        $stmt->bindParam(':branch_id', $branch_id);
        $stmt->bindParam(':yesterday', $yesterday);
    }

    $stmt->execute();

    // Check if any rows returned
    if ($stmt->rowCount() > 0) {
        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
            extract($row);

            // Calculate profits
            $profit = $row['totalbillptotal'] - $row['totalproducttotal'];
            $marketprofit = $row['totalproductmarkettotal'] - $row['totalproducttotal'];

            // Update total row profits
            $totalrowprofitamount += $profit - $row['totaldiscount'];
            $totalrowmarketprofitamount += $marketprofit - $row['totaldiscount'];
        }
    }

} catch (PDOException $e) {
    echo "Error: " . $e->getMessage();
}




										?>
											<h5 class="card-title mb-0">Total Yesterday Profit(Market Price)</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
												Rs.<?php echo number_format($totalrowmarketprofitamount, 2); ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-cyan" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
										<?php 
										//} 
									//	} 
										?>
									</div>
								</div>
							</div>


							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-purple-dark">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-users"></i></div>
										<div class="mb-4">
											<?php

											$stmt = $DB_con->prepare('SELECT COUNT(*) AS customers_count FROM mobilecustomers where status="1"');
											$stmt->execute();
											$result = $stmt->fetch();
											$total_customers = $result['customers_count'];

											?>
											<h5 class="card-title mb-0">Customers</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
													<?php echo $total_customers ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-pink" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
									</div>
								</div>
							</div>

							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-magenta-dark ">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-users"></i></i></div>
										<div class="mb-4">
											<?php

											$stmt = $DB_con->prepare('SELECT COUNT(*) AS suppliers_count FROM mobilesuppliers where status="1"');
											$stmt->execute();
											$result = $stmt->fetch();
											$total_suppliers = $result['suppliers_count'];

											?>
											<h5 class="card-title mb-0">Suppliers</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
													<?php echo $total_suppliers ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-blue" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
									</div>
								</div>
							</div>

							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-red-dark">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-money-bill"></i></div>
										<div class="mb-4">
											<?php
											$stmt = $DB_con->prepare('SELECT COUNT(*) AS products_count FROM mobileproducts where status="1"');
											$stmt->execute();
											$result = $stmt->fetch();
											$total_products = $result['products_count'];

											?>
											<h5 class="card-title mb-0">Products</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
													<?php echo $total_products ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-blue" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
									</div>
								</div>
							</div>

							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-cyan-dark">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-credit-card"></i></i></i></div>
										<div class="mb-4">
											<?php

											$stmt = $DB_con->prepare('SELECT COUNT(*) AS products_count FROM mobileproducts where status="1"');
											$stmt->execute();
											$result = $stmt->fetch();
											$total_products = $result['products_count'];

											?>
											<h5 class="card-title mb-0">Purchase Invoice</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
												0
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-blue" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
									</div>
								</div>
							</div>

							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-blue-dark">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-money-bill"></i></div>
										<div class="mb-4">
											<?php
											$stmt = $DB_con->prepare('SELECT sum(amount) AS amount FROM mobileexpense');
											$stmt->execute();
											$result = $stmt->fetch();
											$amount = $result['amount'];

											?>
											<h5 class="card-title mb-0">All Expences</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
												Rs.<?php echo number_format((float) $amount, 2); ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-blue" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
									</div>
								</div>
							</div>

							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-green-dark">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-money-bill"></i></div>
										<div class="mb-4">
											<?php
											date_default_timezone_set("Asia/Colombo");
											$today = date("Y-m-d");
											//$stmt = $DB_con->prepare('SELECT sum(amount) AS amount,add_date FROM mobileexpense WHERE DATE(add_date)="$today"');
											//$stmt->execute();
											///$result = $stmt->fetch();
											//$amount = $result['amount'];

											$expen = "SELECT sum(amount) AS amount,add_date FROM mobileexpense WHERE DATE(add_date) = '$today'";
											$SDAresult = mysqli_query($conn, $expen);
											$amount = mysqli_fetch_assoc($SDAresult)['amount'];
											?>
											<h5 class="card-title mb-0">Daily Expences</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
												Rs.<?php echo number_format((float) $amount, 2); ?>
												</h2>
											</div>
										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-blue" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
									</div>
								</div>
							</div>

							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-orange-dark">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-money-bill"></i></div>
										<div class="mb-4">
										<?php
											$result = mysqli_fetch_array(mysqli_query($conn, "SELECT SUM(amount) as amount,pay_option FROM mobileorders WHERE pay_option='cash'"));
													

													 ?>
											<h5 class="card-title mb-0">Cash Payments Total</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
													Rs.<?php echo number_format((float) $result['amount'], 2); ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-blue" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
									</div>
								</div>
							</div>

							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-magenta-dark">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-money-bill"></i></div>
										<div class="mb-4">
										<?php
										$result = mysqli_fetch_array(mysqli_query($conn, "SELECT SUM(amount) as amount,pay_option FROM mobileorders WHERE pay_option='card'"));
													

													 ?>
											<h5 class="card-title mb-0">Card Payments Total</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
												Rs.<?php echo number_format((float) $result['amount'], 2); ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-blue" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
									</div>
								</div>
							</div>
							
							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-purple-dark">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-money-bill"></i></div>
										<div class="mb-4">
										<?php
										$result = mysqli_fetch_array(mysqli_query($conn, "SELECT SUM(amount) as amount,pay_option FROM mobileorders WHERE pay_option='banktransfer'"));
													

													 ?>
											<h5 class="card-title mb-0">Bank Transfer Total</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
												Rs.<?php echo number_format((float) $result['amount'], 2); ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-blue" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
									</div>
								</div>
							</div>

							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-red-dark">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-money-bill"></i></div>
										<div class="mb-4">
										<?php
										$result = mysqli_fetch_array(mysqli_query($conn, "SELECT SUM(amount) as amount,pay_option FROM mobileorders WHERE pay_option='cheques'"));
													

													 ?>
											<h5 class="card-title mb-0">Cheques Total</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
												Rs.<?php echo number_format((float) $result['amount'], 2); ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-blue" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
									</div>
								</div>
							</div>
							


							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-cyan-dark">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-money-bill"></i></div>
										<div class="mb-4">
										<?php
											date_default_timezone_set("Asia/Colombo");
											$today = date("Y-m-d");
											$result = mysqli_fetch_array(mysqli_query($conn, "SELECT SUM(amount) as amount,pay_option,create_at FROM mobileorders WHERE pay_option='cash' AND DATE(create_at) = '$today'"));
													

													 ?>
											<h5 class="card-title mb-0">Daily Cash Payments Total</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
													Rs.<?php echo number_format((float) $result['amount'], 2); ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-blue" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
									</div>
								</div>
							</div>

							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-blue-dark">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-money-bill"></i></div>
										<div class="mb-4">
										<?php
										$result = mysqli_fetch_array(mysqli_query($conn, "SELECT SUM(amount) as amount,pay_option,create_at FROM mobileorders WHERE pay_option='card'"));
													

													 ?>
											<h5 class="card-title mb-0">Daily Card Payments Total</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
												Rs.<?php echo number_format((float) $result['amount'], 2); ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-blue" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
									</div>
								</div>
							</div>
							
							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-cherry">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-money-bill"></i></div>
										<div class="mb-4">
										<?php
										$result = mysqli_fetch_array(mysqli_query($conn, "SELECT SUM(amount) as amount,pay_option,create_at FROM mobileorders WHERE pay_option='banktransfer' AND DATE(create_at) = '$today'"));
													

													 ?>
											<h5 class="card-title mb-0">Daily Bank Transfer Total</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
												Rs.<?php echo number_format((float) $result['amount'], 2); ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-blue" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
									</div>
								</div>
							</div>

							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-green-dark">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-money-bill"></i></div>
										<div class="mb-4">
										<?php
										$result = mysqli_fetch_array(mysqli_query($conn, "SELECT SUM(amount) as amount,pay_option,create_at FROM mobileorders WHERE pay_option='cheques' AND DATE(create_at) = '$today'"));
													

													 ?>
											<h5 class="card-title mb-0">Daily Cheques Total</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
												Rs.<?php echo number_format((float) $result['amount'], 2); ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-blue" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
									</div>
								</div>
							</div>

							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-purple-dark">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-credit-card"></i></i></i></div>
										<div class="mb-4">
											<?php
												 $tot = 0;
												 $result = mysqli_query($conn, "SELECT * FROM tbl_stock WHERE qty > '0' AND prid!='148'");		
												 if ($result->num_rows > 0) {
													 while($row = $result->fetch_assoc()) { 
														 ?>
														
															 <?php 
															 $prid =  $row['prid'];
															 $qry = mysqli_query($conn, "SELECT * FROM mobileproducts WHERE prid='$prid' AND prid!='148'");		
															 $rw = mysqli_fetch_array($qry); 
															 $tot = $tot + ($rw['price']*$row['qty']); ?>
		 
															
												   <?php }
												 }
											
											
											?>

											
											<h5 class="card-title mb-0">Daily Stock Valivation</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
													Rs.<?php echo $tot; ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-blue" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
									</div>
								</div>
							</div>
							
							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-red-dark">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-credit-card"></i></i></i></div>
										<div class="mb-4">
											<?php
											$date = date("Y-m-d");
											$stmt = $DB_con->prepare("SELECT * FROM mobile_drawer_balance WHERE drawer_balance_date = :date AND branch_id = :branch_id");
											$stmt->bindParam(':date', $date);
											$stmt->bindParam(':branch_id', $branchid);
											$stmt->execute();
											
											// Fetch the result
											$result = $stmt->fetch();
											$amount = $result['amount'];

											?>
											<h5 class="card-title mb-0">Daily Drawer Amount</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
													Rs.<?php echo $amount; ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-blue" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
									</div>
								</div>
							</div>

							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-orange-dark">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-credit-card"></i></i></i></div>
										<div class="mb-4">
											<?php
												$date = date("Y-m-d");
												$expeninfo = mysqli_fetch_array(mysqli_query($conn, "SELECT branch_id, add_date, SUM(amount) as sumamount FROM mobileexpense WHERE branch_id='$branchid' AND add_date='$date'"));

												$date = date("Y-m-d");
												$stmt = $DB_con->prepare("SELECT * FROM mobile_drawer_balance WHERE drawer_balance_date = :date AND branch_id = :branch_id");
												$stmt->bindParam(':date', $date);
												$stmt->bindParam(':branch_id', $branchid);
												$stmt->execute();

												// Fetch the result
												$result = $stmt->fetch();
												$amount = $result['amount'];

											?>
											<h5 class="card-title mb-0">Daily Drawer Out</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
													Rs.<?php echo $amount- $expeninfo['sumamount']; ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-blue" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
									</div>
								</div>
							</div>

							<div class="col-lg-4 col-sm-6 col-12">
								<div class="card l-bg-cyan-dark">
									<div class="card-statistic-3 p-4">
										<div class="card-icon card-icon-large"><i class="fas fa-credit-card"></i></i></i></div>
										<div class="mb-4">
											<?php
												$date = date("Y-m-d");
												$expeninfo = mysqli_fetch_array(mysqli_query($conn, "SELECT branch_id, create_at, SUM(paid_amount) as sumamount FROM mobileorders WHERE branch_id='$branchid' AND create_at='$date'"));

												$date = date("Y-m-d");
												$stmt = $DB_con->prepare("SELECT * FROM mobile_drawer_balance WHERE drawer_balance_date = :date AND branch_id = :branch_id");
												$stmt->bindParam(':date', $date);
												$stmt->bindParam(':branch_id', $branchid);
												$stmt->execute();

												// Fetch the result
												$result = $stmt->fetch();
												$amount = $result['amount'];

											?>
											<h5 class="card-title mb-0">Daily Drawer In</h5>
										</div>
										<div class="row align-items-center mb-2 d-flex">
											<div class="col-12">
												<h2 class="d-flex align-items-center mb-0">
													Rs.<?php echo $amount + $expeninfo['sumamount']; ?>
												</h2>
											</div>

										</div>
										<div class="progress mt-1 " data-height="8" style="height: 8px;">
											<div class="progress-bar l-bg-blue" role="progressbar" data-width="25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width: 25%;"></div>
										</div>
									</div>
								</div>
							</div>

					</div>
					</div>
				</div>
				<?php require_once 'footerjs.php'; ?>
			</div>
		</div>
		<div class="modal fade" id="shortcutModal" tabindex="-1" aria-labelledby="shortcutModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<h5 class="modal-title" id="shortcutModalLabel">Shortcut Keys</h5>
						<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
					</div>
					<div class="modal-body">
						<table class="table">
							<thead>
								<tr>
									<th>#</th>
									<th>Operations</th>
									<th>Keyboard Shortcut</th>
								</tr>
							</thead>
							<tbody>

								<tr>
									<td>1</td>
									<td>Hold</td>
									<td>shift+d</td>
								</tr>
								<tr>
									<td>2</td>
									<td>Unhold</td>
									<td>shift+u</td>
								</tr>
								<tr>
									<td>3</td>
									<td>Cancel</td>
									<td>shift+c</td>
								</tr>
								<tr>
									<td>4</td>
									<td>Edit Discount</td>
									<td>shift+i</td>
								</tr>
								<tr>
									<td>5</td>
									<td>Add Payment</td>
									<td>shift+r</td>
								</tr>
								<tr>
									<td>6</td>
									<td>Product Quantity</td>
									<td>f2</td>
								</tr>
								<tr>
									<td>7</td>
									<td>Add New Product</td>
									<td>f4</td>
								</tr>
								<tr>
									<td>8</td>
									<td>PayBill</td>
									<td>Tab</td>
								</tr>
								<tr>
									<td>9</td>
									<td>Go To Checkout</td>
									<td>Tab</td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>
			</div>
		</div>
		
		<script>
			const labels = <?php echo json_encode($labels); ?>;
			const data = <?php echo json_encode($data); ?>;

			const ctx = document.getElementById('myChart');

			new Chart(ctx, {
				type: 'line',
				data: {
					labels: labels,
					datasets: [{
						label: 'Sales',
						data: data,
						borderWidth: 1,
						backgroundColor: 'rgb(0, 128, 255)',
						borderColor: 'rgb(0, 51, 102)',
						hoverBackgroundColor: 'rgb(64, 191, 128)',
						hoverBorderColor: 'rgba(255, 99, 132, 1)'
					}]
				},
				options: {
					plugins: {
						legend: {
							labels: {
								font: {
									size: 15
								}
							}
						}
					},
					scales: {
						y: {
							beginAtZero: true
						}
					}
				}
			});
		</script>
	</div>
</body>

</html>