<?php 
  if (!isset($_SESSION['username'])) {
    $_SESSION['msg'] = "To access this page, Login is required";
    header('location: login.php');
  }  ?>

<!DOCTYPE>
<html lang="en">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

.body-b { width: 78%; margin: auto; }

.col-body-b {  float: left;  width: 100%; background: white;  padding: 0px; margin-top: 3%;  box-shadow: 0px 3px 2px 3px #EDEAE0; }
.col-body-b-a { float: left; width: 25%; background:  ; color: ;  padding: 15px; font-size: small;}
.col-body-b-a h5 { padding: 10px; }
.col-body-b-a a {float: right; color: #007AA5; font-weight: bold;}

.col-body-b-b { float: left; width: 75%; background: white; color: ;  padding: 15px;}

.time { color: ; font-size: x-small; font-weight: bold; }
.fa-calendar { margin-right: 3%; }

/* Clear floats after the col-body-bs */
.row:after {
  content: "";
  display: table;
  clear: both;
}

@media screen and (max-width:600px) {
  .col-body-b {  width: 100%;   } }

</style>
</head>
<body>


<div class="row">
<nav class="body-b"> 

  <div class="col-body-b">
    <nav class="col-body-b-a">
    <p style="font-weight: bold;" class="time"> <i class="fa fa-calendar"></i><?php $date = new DateTime(); echo $date->format('l, F jS, Y'); ?> </p>

    <h5>Total Sales
    <a> <?php $sql = "SELECT * FROM product_sales where time >= CURDATE() AND YEAR(time) = YEAR(CURRENT_DATE) ";     
$result = mysqli_query($conn,$sql); $rowcount=mysqli_num_rows($result);
  printf(" %d \n ",$rowcount);?></a>
   </h5>

 <?php  $sql = "select SUM(mpesa) as mpesa from earnings where time >= CURDATE() AND YEAR(time) = YEAR(CURRENT_DATE)";  

 $sql_1 = "select SUM(cash) as cash from earnings where time >= CURDATE() AND YEAR(time) = YEAR(CURRENT_DATE)"; 

 $result = $db->query($sql);   $result_1 = $db->query($sql_1);

 $row = $result->fetch_array();{  $sum_a = $row['mpesa'];}
 $row_1 = $result_1->fetch_array();{  $sum_b = $row_1['cash'];}
 
 $sum = $sum_a + $sum_b ;  ?> 


    <h5>Cash Income <a> <?php  echo $sum_b; ?> </a></h5>
 

    <h5>Mpesa Income <a> <?php echo $sum_a; ?> </a> </h5>


    <h5>Items on Loan <a>
        <?php $sql = "SELECT * FROM earnings where amount = balance";     
$result = mysqli_query($conn,$sql); $rowcount=mysqli_num_rows($result);
  printf(" %d \n ",$rowcount);?>
     </a>  </h5>

     </nav>
     <nav class="col-body-b-b">
  <?php include("daily-sales.php"); ?>
</nav>
  </div>

  </nav>
</div>

</body>
</html>
