:: **Zploit** v1.0 | Current Path: **/home/kreativepixelz/www/crm/quatation/**
:: Editing File: purchase_list.php
<?php error_reporting(E_ALL); ini_set('display_errors', '1'); include_once("session.php"); include("header.php"); include("db.php"); // --- PHP Filter Logic --- $filter_applied = false; $start_date = $_GET['start_date'] ?? ''; $end_date = $_GET['end_date'] ?? ''; $vendor_id_filter = $_GET['vendor_id'] ?? ''; // Basic sanitization $start_date_safe = mysqli_real_escape_string($conn, $start_date); $end_date_safe = mysqli_real_escape_string($conn, $end_date); $vendor_id_safe = mysqli_real_escape_string($conn, $vendor_id_filter); $where_conditions = []; if (!empty($start_date_safe) && !empty($end_date_safe)) { // Filter by PO Date (the 'po_date' column) $where_conditions[] = "p.po_date BETWEEN '$start_date_safe' AND '$end_date_safe'"; $filter_applied = true; } if (!empty($vendor_id_safe)) { // Filter by Vendor ID $where_conditions[] = "p.vendor_id = '$vendor_id_safe'"; $filter_applied = true; } $where_clause = ""; if (!empty($where_conditions)) { $where_clause = " WHERE " . implode(' AND ', $where_conditions); } // --- Fetch all vendors for the dropdown --- // Assuming your vendor table is named 'vendors' $vendors_query = "SELECT id, name FROM party ORDER BY name ASC"; $vendors_result = mysqli_query($conn, $vendors_query); // --- END PHP Filter Logic --- ?> <link href="assets/vendor/datatable/jquery.dataTables.min.css" rel="stylesheet" type="text/css"> <main> <div class="container-fluid"> <div class="row m-1"> <div class="col-9"> <h4 class="main-title">Purchase Report (Purchase Register)</h4> <ul class="app-line-breadcrumbs mb-3"> <li> <a class="f-s-14 f-w-500" href="dashboard.php"> <i class="ph-duotone ph-bank f-s-16"></i> Home </a> </li> <li class="active"> <a class="f-s-14 f-w-500" href="#">Purchase Report</a> </li> </ul> </div> <!--<div class="col-3"> <a href="add_po.php" class="btn btn-primary" style="float: right;">Add Purchase Order</a> </div> --> </div> <div class="row mb-3"> <div class="col-12"> <div class="card p-3"> <form method="GET" action="purchase_list.php" class="row g-3 align-items-end"> <div class="col-md-2"> <label class="form-label">Start Date</label> <input type="date" class="form-control" name="start_date" value="<?php echo htmlspecialchars($start_date); ?>"> </div> <div class="col-md-2"> <label class="form-label">End Date</label> <input type="date" class="form-control" name="end_date" value="<?php echo htmlspecialchars($end_date); ?>"> </div> <div class="col-md-3"> <label class="form-label">Party Name</label> <select class="form-control form-select" name="vendor_id"> <option value="">All Party</option> <?php if ($vendors_result && mysqli_num_rows($vendors_result) > 0) { while ($vendor_row = mysqli_fetch_assoc($vendors_result)) { $selected = ($vendor_row['id'] == $vendor_id_safe) ? 'selected' : ''; echo "<option value='{$vendor_row['id']}' {$selected}>" . htmlspecialchars($vendor_row['name']) . "</option>"; } } ?> </select> </div> <div class="col-md-3"> <button type="submit" class="btn btn-success">Filter</button> <?php if ($filter_applied): ?> <a href="purchase_list.php" class="btn btn-secondary">Clear Filter</a> <?php endif; ?> </div> </form> </div> </div> </div> <div class="row"> <div class="col-12"> <div class="card"> <div class="card-body p-0"> <div class="app-datatable-default overflow-auto"> <table class="display app-data-table default-data-table" id="purchase_table"> <thead> <tr> <th>PO No</th> <th>PO Date</th> <th>Vendor Name</th> <th>Billing Company</th> <th>Total Amount</th> <th>Status</th> <th>Actions</th> </tr> </thead> <tbody> <?php // ⚠️ Modified query to include the dynamic WHERE clause $sql = "SELECT p.id, p.po_no, p.po_date, p.grand_total, p.remark, p.purchase_receipt, p.po_status, v.name AS vendor_name, b.company_name AS billing_name FROM purchase AS p LEFT JOIN party AS v ON p.vendor_id = v.id LEFT JOIN billing AS b ON p.billing_id = b.id {$where_clause} ORDER BY p.po_date DESC, p.id DESC"; $result = mysqli_query($conn, $sql); $column_count = 7; // Total number of columns in the table if (mysqli_num_rows($result) > 0) { while ($row = mysqli_fetch_assoc($result)) { echo "<tr>"; echo "<td>".htmlspecialchars($row['po_no'])."</td>"; echo "<td>".date('d-m-Y', strtotime($row['po_date']))."</td>"; echo "<td>" . (!empty($row['vendor_name']) ? htmlspecialchars($row['vendor_name']) : '') . "</td>"; echo "<td>".htmlspecialchars($row['billing_name'])."</td>"; echo "<td>".number_format((float)$row['grand_total'],2)."</td>"; echo "<td>".htmlspecialchars($row['po_status'])."</td>"; echo "<td>"; // File link (if purchase receipt exists) if (!empty($row['purchase_receipt'])) { echo " <a target='_blank' href='".$row['purchase_receipt']."' class='btn btn-light-danger icon-btn b-r-4' title='View Receipt/File'> <i class='ti ti-file text-danger' aria-hidden='true'></i> </a> "; } echo " <a target='_blank' href='print_po1_invoice.php?id=".$row['id']."' class='btn btn-light-success icon-btn b-r-4' title='Print/View PO'> <i class='ti ti-printer text-success'></i> </a> <a href='edit_po.php?id=".$row['id']."' class='btn btn-light-primary icon-btn b-r-4' title='Edit PO'> <i class='ti ti-edit text-primary'></i> </a> <a href='delete_po.php?id=".$row['id']."' class='btn btn-light-danger icon-btn b-r-4' title='Delete PO' onclick=\"return confirm('Are you sure you want to delete this Purchase Order?');\"> <i class='ti ti-trash text-danger'></i> </a>"; echo "</td>"; echo "</tr>"; } } else { echo "<tr><td colspan='".$column_count."' class='text-center'>No Purchase Orders found</td></tr>"; } ?> </tbody> </table> </div> </div> </div> </div> </div> </div> </main> <?php include "footer.php"; ?> <script src="assets/vendor/datatable/jquery-3.5.1.js"></script> <script src="assets/vendor/datatable/jquery.dataTables.min.js"></script> <script src="assets/js/data_table.js"></script> <link rel="stylesheet" href="https://cdn.datatables.net/buttons/2.4.1/css/buttons.dataTables.min.css"> <script src="https://cdn.datatables.net/buttons/2.4.1/js/dataTables.buttons.min.js"></script> <script src="https://cdn.datatables.net/buttons/2.4.1/js/buttons.html5.min.js"></script> <script src="https://cdn.datatables.net/buttons/2.4.1/js/buttons.print.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js"></script> <script> // Initialize DataTable and (optionally) enable buttons (copy/csv/excel/pdf/print) $(document).ready(function() { var table = $('#purchase_table').DataTable({ dom: 'Bfrtip', buttons: [ 'copy', 'csv', 'excel', 'pdf', 'print' ], // Set initial order to PO Date descending for 'Purchase Register' view "order": [[ 1, "desc" ]], "paging": true, "searching": true, "info": true }); }); </script>