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


$expenseModel = new Expense($conn);
$allExpense =  $expenseModel->getAllExpenses();
$fromDate = '';
$toDate = '';


?>

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

<head>
  <title>Student | Add Student </title>
  <?php include("../templates/header.php"); ?>
</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 Payments</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>Expenses</th>
              <th>Amount</th>
              <th> Narration</th>
              <th>Issued Date</th>
              <?php
              if ($_SESSION['role'] == 'admin') {
              ?>
                <th> Actions</th>
              <?php
              }
              ?>
            </tr>
            </tr>
          </thead>
          <tbody>
            <?php
            $x = 0;
            foreach ($allExpense as $singleExpense) {   ?>
              <tr>
                <td> <?php echo ++$x; ?></td>
                <td><?= $singleExpense['expense'] ?></td>
                <td><?= $singleExpense['ammount'] ?></td>
                <td><?= $singleExpense['naration'] ?></td>
                <td><?= $singleExpense['issued_date'] ?></td>
                <?php
                if ($_SESSION['role'] == 'admin') {
                ?>
                  <td> <a href='edit_exp.php?id=<?= $singleExpense['id']  ?>' class="btn  btn-md"><i class="fa fa-pencil"></i></a>
                    <a href='delete_exp.php?id=<?= $singleExpense['id']  ?>' class="btn  btn-md"><i class="fa fa-trash"></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>