
<?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;}

.top-aa{ padding:15px; text-align: left; width: 100%; font-size: x-small; color: #848482; margin-bottom: 1%;}


td {  padding:7px;border-bottom: 1px solid #ddd !important; font-size: x-small; }

th {  padding:5px;border: 1px solid #ddd !important; background:#7CB9E8; color: white; opacity: .8;text-align: left;  font-size: x-small; border-spacing: 1;}
table { width: 100%; margin: auto; }

.table { overflow-x: auto; scrollbar-width: thin; width: 100%;}


.no-record{float: left; margin-left: 5%; color: red; font-size: small; font-style: italic;}


.column-cash-a {  float: left;  width: 40%;  padding: 15px;  }
.column-cash-b {  float: left;  width: 60%;  padding: 15px;  }

.cash-report-a a {float: right; color:#7CB9E8 ; font-weight: bold;}
.cash-report-a p { padding: 2px; }

.cash-report-a {  float: left;  width: 100%; padding: 15px;  background: white; border-bottom:  2px solid orange;}

.cash-report-b {  float: left;   width: 100%; padding: 2px;  background: white; border-bottom:  2px solid orange; margin-top:5%;}

.cash-report-c { display: none ; float: left;   width: 100%; padding: 2px;  background: white; border-bottom:  2px solid orange; margin-top: 5%;}


.pdf {color:  black; font-size: large; margin-right: 5%; margin-left: 5%;}

.report-report{ width:90%; margin: auto; }


.cash-report-b a{ text-align: left; text-decoration: none; color: #3B3C36; }
.cash-report-b a:hover{ text-align: left;  color:#96C8A2; font-weight: bold; }


.report{padding:0px; background: white; width: 100%; margin: auto; border: 1px solid white; float: left; padding: 1px; border-top: 0px solid #7CB9E8;}
.head-report{background:#FEFEFA; color:#3D2B1F; padding: 10px; font-weight: bold; box-shadow:  2px 2px #8C92AC;   }
.body-report {width: 100%; padding: 10px; float: left; }

.head-mpesa {width: 100%; float: left; background:#FEFEFA; color:#3D2B1F; font-weight: bold; padding: 10px; box-shadow:  2px 2px #8C92AC; }

.time {font-size:x-small; margin-right:5px; color:orange; text-align: right; float: right;}

.cal {font-size:small; margin-right:3%;  color:#7CB9E8 ;}


input[type=date]{  width: 70%;  padding:6px; border: 1px solid #ccc;  border-radius: 4px;    background: white; margin-top:10px; color:#96C8A2; margin-left: 15%; }

.btn-cash {background-color:orange;  font-weight: bold;  padding: 4px 6px;   border: none; 
 font-size: small;  margin-left:-9%; border-top-right-radius: 4px; border-bottom-right-radius: 4px; 
 opacity: .9; color: white;}

 .btn-cash:hover {background-color:orange;  padding: 5px 7px;}

.d {color: white;}

/* Clear floats after the column-cashs */
.row:after {
  content: "";
  display: table;
  clear: both;
}

@media screen and (max-width:600px) {
  #table{height: auto;}
   .column-cash-a, .column-cash-b {  width: 100%; padding: 0px;   }
  .column-cash-b {  width: 100%; margin-top: 5%;  padding: 0px;  }
  .report{width: 100%; height: auto; padding: 0px;}
  .report-report{width: 100%;}
  .body-report {width: 100%; padding: 10px; float: left;  overflow-x: auto; height: auto;}


   }

</style>
</head>
<body>


<div class="row">

<div class="top-aa">
<a href="index.php" style="color: black; text-decoration: none; font-weight: bold;">Home </a>
<a>// Income - Monthly report </a>
</div>

<div class="column-cash-a">

  <nav class="cash-report-a"> 
<p style="padding: 0px;"><i class="fa fa-calendar cal"> </i><a class="time"><?php $date = new DateTime(); echo $date->format('l, F jS, Y'); ?> </a></p>

<br>
<hr style="opacity: .1;">



 <p>Total Cash Collected 

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

 $sql_1 = "select SUM(cash) as cash from earnings where MONTH(time) >= MONTH(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 ;  echo $sum_b;?>  </a></p> 

<hr style="opacity: .1;">


<p>Total Mpesa Cash collected <a> <?php echo $sum_a; ?></a></p>

<hr style="opacity: .1;">


<p>Total Amount collected <a style="Color: orange;"> <?php echo $sum; ?></a></p>
 
</nav>

<nav class="cash-report-b"> <p> <i class="fa fa-file-pdf-o pdf"> </i>  <a  href="pdf/monthly-cash-report.php"> Download  Report </a> 
<a style="float: right; margin-right: 2%; color:orange; font-weight:bold; " > - <?php $t = date('F, Y'); echo $t; ?></a>

</p></nav>


<nav class="cash-report-c" > <p> <i class="fa fa-calendar pdf"> </i>  <a > Customize Download (Pick month to generate report) </a></p>

<form method="post" Action ="index.php?link=policy-search">
<input type="date" name="name" placeholder="Search Customer Records eg JOHN" required="autofocus">
<button class="btn-cash" name="search" > <i class="fa fa-download d"></i> </button>
</form>


</nav>


</div>






<div class="column-cash-b">

<nav class="report-report">
<nav class="report">
<nav class="head-report">Cash Collected 
</nav>

<nav class="body-report">
 

<?php    
    
include "inc/config.php";    
    
$sql = "SELECT * FROM earnings WHERE cash > 0 AND  time >= CURDATE() AND YEAR(time) = YEAR(CURRENT_DATE)  order by Id  DESC";   
$result = mysqli_query($conn,$sql);  

$sql_1 = "SELECT * FROM earnings WHERE mpesa > 0 AND  time >= CURDATE() AND YEAR(time) = YEAR(CURRENT_DATE)  order by Id  DESC";   
$result_1 = mysqli_query($conn,$sql_1);    

 
?> 
<nav class="table">
<table >
  <tr>

<?php   $rowcount=mysqli_num_rows($result);

if ($rowcount == 0) {
echo " <p class ='no-record'>opps ! No Cash  record for  today </p> ";

} else {   ?>
  <th>Customer</th>
  <th>Phone</th>
  <th>Amount</th>
  <th>Receipt - No</th>
  <th>Received By</th>
  <th>Time received</th>
</tr>  

<?php while($row = mysqli_fetch_object($result)){ ?>  

<tr> 
<td><?php echo $row->customer;?> </td>
<td><?php echo $row->phone;?></td>
<td><?php echo $row->amount;?></td>
<td><?php echo $row->receipt_no;?></td>
<td><?php echo $row->session;?></td>
<td style="Color:orange ; font-weight: bold;" ><?php echo date_format( new DateTime($row->time),"d,M, Y \t H:m:s");?></td>
        
 <?php } }?></tr>
        </table>
</nav>




<tr>  <p class="head-mpesa">Mpesa Collection</p>  </tr>

<nav class="table">
<table>
<?php   $rowcount_1=mysqli_num_rows($result_1);
if ($rowcount_1 == 0) {
echo " <p class ='no-record'>opps ! No  Mpesa  record for  today </p> ";  } 
else {   ?>
  
 <tr>
  <th>Customer</th>
  <th>Phone</th>
  <th>Amount</th>
  <th>Receipt - No</th>
  <th>Received By</th>
  <th>Time received</th>
</tr>  

<?php while($row = mysqli_fetch_object($result_1)){  ?>  

<tr> 
<td><?php echo $row->customer;?> </td>
<td><?php echo $row->phone;?></td>
<td><?php echo $row->amount;?></td>
<td><?php echo $row->receipt_no;?></td>
<td><?php echo $row->session;?></td>
<td style="Color:orange ; font-weight: bold;" ><?php echo date_format( new DateTime($row->time),"d,M, Y \t H:m:s");?></td>
        
<?php }}?></tr>

</table>
</nav>

</nav>


</nav>
</nav>

</div>
  

</div>
</body>
</html>
