<?php
require_once '../auth/auth.php';
require_once '../models/db_connection.php';
require_once '../models/deposit_model.php';


$depositModel = new CashDeposit($conn);
$allDeposits =  $depositModel->getAllDeposits();
$fromDate = '';
$toDate = '';


if (isset($_POST['filter'])) {


  $fromDate = $_POST['from'];
  $toDate = $_POST['to'];
  $studentPayments =  $fee->getAllPaymentsDate($fromDate, $toDate);
}

?>

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

<head>
  <title>Student | Add Student </title>
  <?php include("../templates/header.php"); ?>
  <script type='text/javascript'>
    function ConfirmDelete() {
      if (confirm("Are you sure you want to delete this deposit?"))
        return true;
      else
        return false;
    }
  </script>
</head>

<body>
  <?php
  if (isset($_GET["message"])) {
    $message = $_GET["message"];
    echo "<script>alert('" . $message . "')</script>";
  }
  ?>
  <div class="container-scroller">
    <!-- partial:partials/_navbar.html -->
    <?php include("../templates/nav.php"); ?>
    <!-- partial -->
    <div class="container-fluid page-body-wrapper">
      <!-- partial:partials/_sidebar.html -->
      <?php include("../templates/sidenav.php"); ?>
      <!-- partial -->
      <div class="main-panel">
        <div class="content-wrapper">

          <form action="view_payments.php" method="POST">
            <div class="col-lg-12 grid-margin stretch-card">

              <div class="card">
                <div class="card-body">
                  <h4 class="card-title">View Deposits</h4>
                  <div class="row">
                    <div class="col-4">
                      <p class="card-description">
                        Students Table <code></code>
                      </p>
                    </div>
                    <div class="col-8">

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

      <div class="table-responsive pt-3">
        <table class="table table-bordered display" id="example" style="width:100%">
          <thead>



            <tr>
              <th> SNO </th>
              <th>Ammount</th>
              <th> Narration</th>
              <th>Deposited Date</th>
              <th>Deposited By</th>
              <?php
              if ($_SESSION['role'] == 'admin') {
              ?>
                <th> Actions</th>
              <?php } ?>
            </tr>
            </tr>
          </thead>
          <tbody>
            <?php
            $x = 0;
            foreach ($allDeposits as $singleDeposit) {
              
              ?>
              <tr>
                <td> <?php echo ++$x; ?></td>
                <td><?= $singleDeposit['ammount'] ?></td>
                <td><?= $singleDeposit['narration'] ?></td>
                <td><?= $singleDeposit['deposit_date'] ?></td>
                <td><?= $singleDeposit['username'] ?></td>
                <?php
                if ($_SESSION['role'] == 'admin') {
                ?>
                  <td> <a href='delete_deposit.php?id=<?= $singleDeposit['cash_id']  ?>' class="btn btn-dark btn-md" onclick="return ConfirmDelete()"><i class="fa fa-trash"></i></a>
                  <a href='edit_deposit.php?id=<?= $singleDeposit['cash_id']  ?>' class="btn btn-dark btn-md"><i class="fa fa-pencil"></i></a></td>

              <?php 
            }
              } ?>
          </tbody>
        </table>
      </div>
    </div>
  </div>
  </div>
  </div>
  <!-- content-wrapper ends -->
  <!-- partial:partials/_footer.html -->
  <?php include("../templates/footer.php"); ?>

  <!-- partial -->
  </div>
  <!-- main-panel ends -->
  </div>
  <!-- page-body-wrapper ends -->
  </div>
  <?php include("../templates/inc_scripts.php"); ?>
  <script>
    new DataTable('#example');
  </script>
</body>

</html>