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

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
 <title></title>
<style type="text/css">
* {  box-sizing: border-box;}
body {  margin: 0;}
td {  padding:8px;border-bottom: 1px solid #ddd !important; font-size: xx-small; }

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

table { margin: auto; border-spacing: 1; width: 100%; float: left;  }

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

.table { margin-right: 3%; height: 80%; overflow-x: auto;scrollbar-width: thin; }

.top-top {float: left; font-size: x-small;color:#848482; width: 100%; padding: 10px; margin-bottom: 1%;}
.col-return-a {  float: left;  width: 30%;  padding: 15px;  }
.col-return-b {  float: left;  width: 70%;  padding: 15px; }

.col-return { background: white; padding: 15px; border-bottom: 3px solid #7CB9E8; float: left; width: 100%; }

.col-return a { float: right; color:#7CB9E8 ; }
.col-return p { padding: 10px; }

.img-return { float: left; width: 100%; height: 15em; }

.btn-exchange { background: none; border: 1px solid #7CB9E8; float: left; padding: 4px; font-size: xx-small; color: #7CB9E8;  border-radius: 5px; }
.btn-exchange:hover { background: #7CB9E8; border: 1px solid #7CB9E8; float: left; padding: 4px; font-size: xx-small; color: white;  border-radius: 5px; }
.btn-exchange:hover a { color: white; float: left; font-weight: bold; }

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

@media screen and (max-width:600px) {
  .col-return {  width: 100%;   }
  .col-return-a, .col-return-b{ width:100%;  float: left;} }

</style>
</head>
<body>


<div class="row">
  <div class="top-top">
<a href="index.php" style="color: black; text-decoration: none; font-weight: bold;"> Home </a>
<a href="index.php?link=101returned" style="color:#848482; text-decoration: none; font-weight: bold;">// Accept Returned Items</a>
<a>// Manage Returned Items</a>
</div>
  <div class="col-return-a">
    <nav class="col-return">
      <p>Total Returned Items  
<a> <?php $sql = "SELECT * FROM items_received ";     
$result = mysqli_query($conn,$sql); $rowcount=mysqli_num_rows($result);
  printf(" %d \n ",$rowcount);?></a>
      </p>
      <hr style="opacity: .1;">
      <p>Returned Today

<a> <?php $sql = "SELECT * FROM items_received where status = 1 AND  time >= CURDATE() AND YEAR(time) = YEAR(CURRENT_DATE) ";     
$result = mysqli_query($conn,$sql); $rowcount=mysqli_num_rows($result);
  printf(" %d \n ",$rowcount);?></a>
      </p>
      <hr style="opacity: .1;">

<img src="images/return.jpg" class="img-return">

    </nav>
  
  </div>
  
<div class="col-return-b">
<nav class="col-return">

<div class='table'>
<?php  require_once "inc/config.php";
 $sql = "SELECT * FROM items_received where status=0 order by time DESC";
   if($result = $mysqli->query($sql)){
   if($result->num_rows > 0){
   echo "<table >";
   echo "<thead>";
   echo "<tr class='t1'>";
   echo "<th>Customer Name</th>";
   echo "<th>items Received</th>";
  echo "<th>Item Size</th>";
   echo "<th>Quantity Received</th>";
    echo "<th>Unit price</th>";
    echo "<th>Total price</th>";
     echo "<th>Receipt No</th>";
  echo "<th>Received by</th>";
   echo "<th>Time Received</th>";
   echo "<th>In Exchange Of</th>";
     echo "</tr>";
   echo "</thead>";
   echo "<tbody>";
    while($row = $result->fetch_array()){
  echo "<tr>";
  echo "<td>" . $row['customer'] . "</td>";
  echo "<td>" . $row['item'] . "</td>";
  echo "<td>" . $row['size'] . "</td>";
  echo "<td>" . $row['quantity_1'] . "</td>";
  echo "<td>" . $row['price'] . "</td>";
   echo "<td>" . $row['totalprice'] . "</td>";
     echo "<td>" . $row['receipt_no'] . "</td>";
  echo "<td>" . $row['session'] . "</td>";

echo "<td  style=' color:orange; font-weight:bold; '  >" . date_format( new DateTime ($row['time'] ),"d M, Y H: m: s"). "</td>";

 echo "<td><button class='btn-exchange'><a href='exchange-returned-items?edit=". $row['id'] ."' title='Exchange returned goods' data-toggle='tooltip'>Exchange Item with</a></button>"."</td>";

// echo "<td>
//<form method ='post' action= 'index.php?link=returnaction.php'> 
// <input type='hidden' name='id' value=".$row['id']." />
// <button class='btn-exchange' type='submit' name='exchange'> Exchange with </button>
// </form>
// </td>";

 echo "</tr>";
         }
    echo "</tbody>";                            
    echo "</table>";
       $result->free();
            } else{ echo "<p class='no-results'><em>Opps! no records.</em></p>";}
  
   } else{ echo "ERROR: Could not able to execute $sql. " . $mysqli->error;}
   // Close connection
       $mysqli->close();?>
</nav>

</div>
 </div>
</div>

</body>
</html>
