<?php

session_name('super_admin_session');

if (!is_dir(dirname(__DIR__) . '/session_data/super')) { mkdir(dirname(__DIR__) . '/session_data/super', 0700, true); } session_save_path(dirname(__DIR__) . '/session_data/super');

session_set_cookie_params(['path' => '/', 'httponly' => true, 'samesite' => 'Strict']);

session_start();

error_reporting(0);

include('includes/dbconnection.php');

require_once __DIR__ . '/includes/session_term_helper.php';
// Fetch current session and term (with gap/fallback support)
$stResult = resolveCurrentSessionTerm($con);
$currentSessionId   = $stResult['session_id'];
$currentSessionName = $stResult['session_name'];
$currentTermId      = $stResult['term_id'];
$currentTermName    = $stResult['term_name'];
if (strlen($_SESSION['sid'] == 0)) {

  header('location:logout.php');

}

if (isset($_GET['del'])) {

  mysqli_query($con, "delete from payment where id = '" . $_GET['id'] . "'");

  $_SESSION['delmsg'] = "student deleted !!";

}

?>

<!DOCTYPE html>

<html>

<?php @include("includes/head.php"); ?>



<body class="hold-transition sidebar-mini layout-fixed">

  <div class="wrapper">

    <!-- Navbar -->

    <?php @include("includes/header.php"); ?>

    <!-- /.navbar -->



    <!-- Main Sidebar Container -->

    <?php @include("includes/sidebar.php"); ?>



    <!-- Content Wrapper. Contains page content -->

    <div class="content-wrapper">

      <!-- Content Header (Page header) -->

                                <section class="content-header premium-header">

    <div class="container-fluid">

        <div class="header-glass-card">

            <div class="row align-items-center">

                <div class="col-md-8">

                    <div class="title-section">

                        <div class="icon-box bg-primary-gradient shadow-sm">

                            <i class="fas fa-wallet"></i>

                        </div>

                        <div>

                            <h1 class="premium-title text-primary">

                                Payment Management

                                <span class="premium-subtitle text-secondary">Payment Approved Today</span>

                            </h1>
                    <div class="mt-1">
                      <?php if ($currentSessionName): ?>
                        <span class="badge badge-primary mr-1">
                          <i class="fas fa-calendar-alt"></i>
                          <?= htmlspecialchars($currentSessionName) ?>
                        </span>
                      <?php endif; ?>
                      <?php if ($currentTermName): ?>
                        <span class="badge badge-success">
                          <i class="fas fa-bookmark"></i>
                          <?= htmlspecialchars($currentTermName) ?>
                        </span>
                      <?php else: ?>
                        <span class="badge badge-warning">
                          <i class="fas fa-exclamation-triangle"></i> No active term
                        </span>
                      <?php endif; ?>
                    </div>

                        </div>

                    </div>

                </div>

                <div class="col-md-4">

                    <nav aria-label="breadcrumb">

                        <ol class="breadcrumb premium-breadcrumb">

                            <li class="breadcrumb-item"><a href="dashboard.php" class="text-primary">Dashboard</a></li>

                            <li class="breadcrumb-item active" aria-current="page">Payment History</li>

                        </ol>

                    </nav>

                </div>

            </div>

        </div>

    </div>

</section> 



      <!-- Main content -->

      <section class="content">

        <div class="container-fluid">

          <div class="row">

            <div class="col-12">

              <div class="card card-primary">

                <div class="card-header">

                  <h5 class="card-title font-weight-bold"><i class="fas fa-history"></i> Recent Payment</h5>

                  <div class="card-tools">

                    <a href="approve.php"><button type="button" class="btn btn-sm btn-primary"><span style="color: #fff;"><i class="ion ion-person-add"></i> New Payment</span>

                      </button> </a>

                  </div>

                </div>

                <!-- /.card-header -->

                <div id="editData" class="modal fade">

                  <div class="modal-dialog modal-xl">

                    <div class="modal-content" id="receiptContent">

                      <div class="modal-header">

                        <h5 class="modal-title">Payment details</h5>



                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">

                          <span aria-hidden="true">&times;</span>

                        </button>

                      </div>

                      <div class="modal-body" id="info_update">

                      </div>

                      <div class="modal-footer ">

                        <button type="button" class="btn btn-success" onclick="printContent()"><i class="fa fa-download">Print</i></button>

                        <button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-times">Cancel</i></button>

                      </div>

                      <!-- /.modal-content -->

                    </div>

                    <!-- /.modal-dialog -->

                  </div>

                  <!-- /.modal -->

                </div>

                <!--   end modal -->



                <div id="editData2" class="modal fade">

                  <div class="modal-dialog ">

                    <div class="modal-content">

                      <div class="modal-header">

                        <h5 class="modal-title">Payment Details</h5>

                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">

                          <span aria-hidden="true">&times;</span>

                        </button>

                      </div>

                      <div class="modal-body" id="info_update2">

                      </div>

                      <div class="modal-footer ">

                        <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>

                      </div>

                      <!-- /.modal-content -->

                    </div>

                    <!-- /.modal-dialog -->

                  </div>

                  <!-- /.modal -->

                </div>

                <!--   end modal -->



                <div class="card-body mt-2 ">

                  <table id="example1" class="table table-bordered table-hover">

                    <thead>

                      <tr>

                        <th>#</th>



                        <th>Admission No.</th>

                        <th>Student Name.</th>

                        <th>Payment ID</th>

                        <th>Class </th>

                        <th>Payment For </th>

                        <th>Amount</th>

                        <th>Payment Date</th>



                        <th>Action</th>

                      </tr>

                    </thead>

                    <tbody>



                      <?php

                      $query = mysqli_query($con, "Select * from payment where DATE(payment_date) = CURDATE() ");

                      $cnt = 1;

                      while ($row = mysqli_fetch_array($query)) {

                      ?>

                        <tr>

                          <td><?php echo htmlentities($cnt); ?></td>

                          <td><?php echo htmlentities($row['studentno']); ?></td>

                          <td><?php echo htmlentities($row['studentName']); ?></td>

                          <td><?php echo htmlentities($row['pay_id']); ?></td>

                          <td><?php echo htmlentities($row['class']) . " " . htmlentities($row['section']); ?></td>

                          <td><?php echo htmlentities($row['pay_for']); ?></td>

                          <td><?php echo htmlentities($row['amount']); ?></td>

                          <td><?php echo date("M d,Y H:i A", strtotime($row['payment_date'])) ?></td>



                          <td>

                            <button class=" btn btn-primary btn-xs edit_data" id="<?php echo  $row['id']; ?>" title="click for edit"><i class="fa fa-eye"></i></button>

                            <a href="viewpaymenttoday.php?id=<?php echo $row['id'] ?>&del=delete" onClick="return confirm('Are you sure you want to delete?')" class=" btn btn-danger btn-xs "><i class="fa fa-trash"></i></a>



                          </td>

                        </tr>

                      <?php $cnt = $cnt + 1;

                      } ?>

                    </tbody>

                  </table>

                </div>

                <!-- /.card-body -->

              </div>

              <!-- /.card -->

            </div>

            <!-- /.col -->

          </div>

          <!-- /.row -->

        </div>

        <!-- /.container-fluid -->

      </section>

      <!-- /.content -->

    </div>

    <!-- /.content-wrapper -->

    <?php @include("includes/footer.php"); ?>

  </div>



  <!-- ./wrapper -->

  <?php @include("includes/foot.php"); ?>

  <script src="dist/js/jspdf.umd.min.js"></script>

  <script>

    function downloadPDF() {

      var receiptContent = document.getElementById('receiptContent').innerHTML;



      const {

        jsPDF

      } = window.jspdf;

      var doc = new jsPDF();



      doc.fromHTML(receiptContent, 15, 15 {

        'width': 170

      });

      doc.save('receipt.pdf');

    }

  </script>

  <script type="text/javascript">

    $(document).ready(function() {

      $(document).on('click', '.edit_data', function() {

        var edit_id = $(this).attr('id');

        $.ajax({

          url: "Receipt.php",

          type: "post",

          data: {

            edit_id: edit_id

          },

          success: function(data) {

            $("#info_update").html(data);

            $("#editData").data('ajax-src', 'Receipt.php').modal('show');
            $("#editData").find('form:not([action])').attr('data-ajax-action', 'Receipt.php');

            $("#editData").addClass('modal-md');

          }

        });

      });

    });



    function printContent() {

      var modalContent = document.querySelector('.modal-content').innerHTML;

      var originalContent = document.body.innerHTML;



      document.body.innerHTML = modalContent;

      window.print();



      document.body.innerHTML = originalContent;

      window.location.reload();

    }

  </script>

  <script>

    document.

  </script>

  <script type="text/javascript">

    $(document).ready(function() {

      $(document).on('click', '.edit_data2', function() {

        var edit_id2 = $(this).attr('id');

        $.ajax({

          url: "Receipt.php",

          type: "post",

          data: {

            edit_id2: edit_id2

          },

          success: function(data) {

            $("#info_update2").html(data);

            $("#editData2").data('ajax-src', 'Receipt.php').modal('show');
            $("#editData2").find('form:not([action])').attr('data-ajax-action', 'Receipt.php');

          }

        });

      });

    });

  </script>



</body>



</html>