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


.table-loans th {  padding:6px;border: 1px solid #ddd !important; background:none; color: #7CB9E8; opacity: .8;text-align: left;  font-size: x-small;
 border-spacing: 1;}  

.table-loans td {  padding:8px;border-bottom: 1px solid #ddd !important; font-size: xx-small; }

.table-loans table { margin: auto; border-spacing: 1; width:100%;    background: white; border-collapse: collapse;}

.table-loans {  overflow-x: auto; scrollbar-width: thin; height: 120px; padding: 2px; }

.col-alerts {  float: left;  width:100%;   background: white;  box-shadow: 0px 2px 3px 2px  #E3DAC9; }
.col-alerts-b {  float: left;  width:100%;   background: white;  box-shadow: 0px 2px 3px 2px  #E3DAC9; margin-top: 5%;}
.alerts-head { float: left; width: 100%; padding: 5px; background:#F5F5DC;  font-weight: bolder; color:#848482; text-align: left; border-bottom: 1px solid red;}

.loans-head span { background: skyblue; padding: 8px; color: white; border-radius: 50%; }

.loans-head { float: left; width: 100%; padding: 5px; background:#F5F5DC;   font-weight: bolder; color:#848482; text-align: left; border-bottom: 1px solid #848482; color: #007AA5;}

.alerts-body { float: left; width: 100%; padding: 5px;   overflow-x: auto; scrollbar-width: thin;}

.alerts-bottom { float: left; text-align: right; padding: 5px; width: 100%; font-size: x-small; font-weight: bold; color: #007AA5; }

.alerts-bottom a{ margin-right: 4%; text-decoration: none;color: #007AA5;}


.btn-add {background: white; border:  1px solid #7CB9E8; padding: 4px 8px;  color:#7CB9E8; font-size: x-small; }



.product-image { float: left; width: 50%; height: 1em; }

.stock-out{ background: red; padding:5px; color: white; float: left; }

.low-stock { background:orange; color: white; padding: 6px; float: left; }

.no-record { font-size: small; text-align: center; padding: 30px;  color: red;}

.fa-shopping-basket { float: right; margin-right: 5%; }

.fa-bell-o { float: right; margin-right: 5%; color: red; }

.r { float: right; margin-right: 5%; color: skyblue; }

.alerts-head p { margin-left: 3%; }

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

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

</style>
</head>
<body>


<div class="row">
  <div class="col-alerts">
    <nav class="alerts-head"> <p>OUT OF STOCK PRODUCTS <a style="font-weight:bold; margin-left: 2%; color: red;"> 

 <?php $sql = "SELECT * FROM products where quantity <= 20";     
$result = mysqli_query($conn,$sql); $rowcount=mysqli_num_rows($result);
  printf(" %d \n ",$rowcount);?>

     </a> <i class="fa fa-bell-o"></i> </p></nav>
 <nav class="alerts-body">




<?php    
    
include "inc/config.php";    
    
$sql = "SELECT * FROM products where quantity <= 10";   
$result = mysqli_query($conn,$sql);   

   if($result->num_rows > 0){
?> 

 <table>    
<tr> 

  <th>Product Name</th>
  <th>Product Size</th>
  <th>Items</th>
  <th>Status</th>
</tr>  


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

<td><?php echo $row->name;?></td>
<td><?php echo $row->size;?></td>
<td><?php echo $row->quantity;?></td>

<td>
<?php  $a = $row->quantity;  

if ($a == 0) { echo "<a class='stock-out'>Stock out </a>  ";}

else{ echo " <a class='low-stock'> Low </a> ";}

?>
  
</td>


<?php } ?>

<?php } else{ echo "<a class='no-record'> <i class ='fa fa-thumbs-o-up'></i> Your stock is sufficient </a>" ; } ?>

</tr>
</table>     
</nav>
 
 <nav class="alerts-bottom">
<p> <a href="index.php?link=002products">  <i class="fa fa-eye"></i> Manage Stock </a></p> </nav>

  </div>


 
  <div class="col-alerts-b" >
    <nav class="loans-head"> <p>Items On Loan<a style="font-weight:bold; margin-right: 2%; float: right; color: #007AA5;"> 
<span>
 <?php $sql = "SELECT * FROM earnings where amount = balance";     
$result = mysqli_query($conn,$sql); $rowcount=mysqli_num_rows($result);
  printf(" %d \n ",$rowcount);?>
  </span>

     </a> <i class="fa fa--o r"></i> </p></nav>
 <nav class="alerts-body">
<nav class="table-loans">
<?php  $sql = "SELECT * FROM earnings where amount = balance";    $result = mysqli_query($conn,$sql);   
   if($result->num_rows > 0){   ?> 
 <table>    
<tr> 
  <th>Customer</th>
  <th>Amount</th>
  
  <th>When released</th>
</tr>  
  <?php while($row = mysqli_fetch_object($result)){  ?>  
 <tr> 

<td><?php echo $row->customer;?></td>
<td>Ksh-<?php echo $row->amount;?>/=</td>


<td style="color:#848482; font-weight: bold;" ><?php echo date_format( new DateTime($row->time),"d,M, Y \t H:m:s");?></td>


<?php } ?>

<?php } else{ echo "<a class='no-record'> No records for loaned items </a>" ; } ?>


</tr>
</table>  
</nav>
 <nav class="alerts-bottom">
<p> <a href="index.php?link=001loan">  <i class="fa fa-eye-o"></i> Manage loan items  </a></p> </nav>
</nav>
</div>

  
</div>

</body>
</html>
