Server IP : 162.214.80.37 / Your IP : 216.73.216.83 Web Server : Apache System : Linux sh013.webhostingservices.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64 User : imyrqtmy ( 2189) PHP Version : 8.2.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home2/imyrqtmy/public_html/dts/vendor/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
<?php session_start(); if (!isset($_SESSION['id'])) { header("Location: login.php"); exit(); } include("inc/config.php"); // Get selected filters from GET request $start_date = isset($_GET['start_datetime']) ? $_GET['start_datetime'] : ""; $end_date = isset($_GET['end_datetime']) ? $_GET['end_datetime'] : ""; $status = isset($_GET['status']) ? $_GET['status'] : ""; // Base Query $query = "SELECT * FROM invoices WHERE 1"; // Apply Date Filters if (!empty($start_date) && !empty($end_date)) { $query .= " AND invoice_date BETWEEN '$start_date' AND '$end_date'"; } // Apply Status Filter if (!empty($status)) { $query .= " AND status = '$status'"; } // Fetch filtered invoice data $query_run = mysqli_query($conn, $query); // Calculate Grand Total $total_query = "SELECT prices FROM invoices WHERE 1"; if (!empty($start_date) && !empty($end_date)) { $total_query .= " AND invoice_date BETWEEN '$start_date' AND '$end_date'"; } if (!empty($status)) { $total_query .= " AND status = '$status'"; } $total_result = mysqli_query($conn, $total_query); $grand_total = 0; while ($row = mysqli_fetch_assoc($total_result)) { $prices = json_decode($row['prices'], true); if (is_array($prices)) { $grand_total += array_sum($prices); } elseif (is_numeric($row['prices'])) { $grand_total += $row['prices']; } } // Calculate Pending Amount $pending_query = "SELECT prices FROM invoices WHERE status = 'Pending'"; if (!empty($start_date) && !empty($end_date)) { $pending_query .= " AND invoice_date BETWEEN '$start_date' AND '$end_date'"; } $pending_result = mysqli_query($conn, $pending_query); $pending_total = 0; while ($row = mysqli_fetch_assoc($pending_result)) { $prices = json_decode($row['prices'], true); if (is_array($prices)) { $pending_total += array_sum($prices); } elseif (is_numeric($row['prices'])) { $pending_total += $row['prices']; } } // Calculate Complete Amount $complete_query = "SELECT prices FROM invoices WHERE status = 'Complete'"; if (!empty($start_date) && !empty($end_date)) { $complete_query .= " AND invoice_date BETWEEN '$start_date' AND '$end_date'"; } $complete_result = mysqli_query($conn, $complete_query); $complete_total = 0; while ($row = mysqli_fetch_assoc($complete_result)) { $prices = json_decode($row['prices'], true); if (is_array($prices)) { $complete_total += array_sum($prices); } elseif (is_numeric($row['prices'])) { $complete_total += $row['prices']; } } ?> <!DOCTYPE html> <html lang="en"> <?php require "inc/head.php"; ?> <body> <?php require "inc/header.php"; ?> <div class="wrapper"> <?php require "inc/sidebar.php"; ?> <div id="content"> <div class="row"> <div class="col-12 col-sm-12"> <div class="row mb-4"> <div class="col-12 col-md-12"> <div class="card redial-border-light redial-shadow mb-4"> <div class="card-body"> <h6 class="header-title pl-3 redial-relative">Data Table</h6> <!-- Date & Status Filter Form --> <form method="GET" action=""> <div class="row mb-3"> <div class="col-md-3"> <label for="start_datetime">Start Date:</label> <input type="date" name="start_datetime" id="start_datetime" class="form-control" value="<?php echo htmlspecialchars($start_date); ?>"> </div> <div class="col-md-3"> <label for="end_datetime">End Date:</label> <input type="date" name="end_datetime" id="end_datetime" class="form-control" value="<?php echo htmlspecialchars($end_date); ?>"> </div> <div class="col-md-3"> <label for="status">Status:</label> <select name="status" id="status" class="form-control"> <option value="">All</option> <option value="Pending" <?php echo ($status == 'Pending') ? 'selected' : ''; ?>>Pending</option> <option value="Complete" <?php echo ($status == 'Complete') ? 'selected' : ''; ?>>Complete</option> </select> </div> <div class="col-md-3"> <button type="submit" class="btn btn-primary mt-4">Filter</button> </div> </div> </form> <table id="example" class="table table-bordered" cellspacing="0" width="100%"> <thead> <tr> <th>#</th> <th>Invoice No</th> <th>Product</th> <th>Invoice Date</th> <th>Due Date</th> <th>Price</th> <th>Status</th> <th>Action</th> </tr> </thead> <tbody> <?php if (mysqli_num_rows($query_run) > 0) { foreach ($query_run as $row) { ?> <tr> <td><?php echo $row['id']; ?></td> <td><?php echo $row['invoice_number']; ?> </td> <td> <?php $products = json_decode($row['product_names'], true); if ($products === null || !is_array($products)) { if (!empty($row['product_names'])) { echo htmlspecialchars($row['product_names']); } else { echo "-"; } } else { echo implode("<br>", $products); } ?> </td> <td><?php echo $row['invoice_date']; ?></td> <td><?php echo $row['due_date']; ?></td> <td> <?php $prices = json_decode($row['prices'], true); if (!empty($prices)) { if (!is_array($prices)) { $prices = [$prices]; } echo "$" . implode("<br>$", $prices); } else { echo "-"; } ?> </td> <td><?php echo $row['status']; ?></td> <td> <div class='btn-group mb-2'> <a href="pdf.php?invoice_number=<?php echo $row['invoice_number']; ?>" class="btn btn-success"> <i class="fa fa-file-pdf-o" aria-hidden="true"></i> </a> <?php if ($row['status'] != 'Complete') { ?> <form action="update_status.php" method="POST" style="display:inline;"> <input type="hidden" name="invoice_id" value="<?php echo $row['id']; ?>"> <button type="submit" name="complete_status" class="btn btn-info"> <i class="fa fa-check"></i> </button> </form> <?php } ?> </div> </td> </tr> <?php } } else { echo "<tr><td colspan='8' class='text-center'>No records found.</td></tr>"; } ?> </tbody> </table> <!-- <h5 class="mt-3 text-right">Grand Total: <span class="text-success">₹<?php echo number_format($grand_total, 2); ?></span></h5> --> <?php if ($status == "Pending") { ?> <h5 class="mt-2 text-right">Pending Total: <span class="text-danger">₹<?php echo number_format($pending_total, 2); ?></span></h5> <?php } elseif ($status == "Complete") { ?> <h5 class="mt-2 text-right">Complete Total: <span class="text-primary">₹<?php echo number_format($complete_total, 2); ?></span></h5> <?php } ?> <!-- <h4 class="mt-3 text-right">Grand Total: <span class="text-success">₹<?php echo number_format($grand_total, 2); ?></span></h4> <h5 class="mt-2 text-right">Pending Total: <span class="text-danger">₹<?php echo number_format($pending_total, 2); ?></span></h5> <h5 class="mt-2 text-right">Complete Total: <span class="text-primary">₹<?php echo number_format($complete_total, 2); ?></span></h5> --> </div> </div> </div> </div> </div> </div> </div> </div> <!-- jQuery --> <script src="dist/js/plugins.min.js"></script> <script src="dist/js/common.js"></script> </body> </html>