« Back to History
parcel_reports.php
|
20260721_154033.php
Initial Bulk Import
Copy Code
<?php /* ====================================================================== FILE: /erp/parcel_report.php MERGED MONOLITHIC VERSION (FINAL STABLE - 100% FIXED PRINT PREVIEW) ====================================================================== */ require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('parcel_reports'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; if (!function_exists('h')) { function h($s) { return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } } // 1. DATE HANDLERS $from = $_GET['from'] ?? date('Y-m-01'); $to = $_GET['to'] ?? date('Y-m-t'); $report_type = $_GET['report_type'] ?? 'send'; $db_from = (!empty($from)) ? date('Y-m-d', strtotime($from)) : date('Y-m-01'); $db_to = (!empty($to)) ? date('Y-m-d', strtotime($to)) : date('Y-m-t'); $isPrint = isset($_GET['print_view']) || isset($_GET['export']); // Common Table Classes for Screen Display $tableClass = "table table-sm table-bordered table-hover table-striped align-middle mb-0"; $theadClass = "table-light text-uppercase small text-center"; $joinCondition = " LEFT JOIN parcel_send_entry pse ON pse.company_id = psi.company_id AND psi.bill_no = pse.bill_no "; // If standard screen request, call layout template headers if (!$isPrint) { require_once __DIR__ . '/partials/header.php'; } else { // If explicit print engine click, compile self-contained pristine styling context echo '<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Print Report</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"> <style> body { background: #fff !important; color: #000 !important; font-family: sans-serif; padding: 20px; } table { width: 100% !important; border-collapse: collapse !important; margin-top: 15px; } th, td { border: 1px solid #333 !important; padding: 8px !important; font-size: 13px !important; color: #000 !important; text-align: left; } th { background-color: #f2f2f2 !important; font-weight: bold !important; text-transform: uppercase; text-align: center; } .print-header { margin-bottom: 20px; border-bottom: 2px solid #333; padding-bottom: 10px; } .text-center { text-align: center !important; } .fw-bold { font-weight: bold !important; } </style> </head> <body onload="window.print();">'; } ?> <style> @media print { html, body { background: #fff !important; color: #000 !important; height: auto !important; overflow: visible !important; } /* Neutralize bootstrap cascading layouts hidden parameters causing layout collapses */ .wrap, .container-fluid, .main-content, .card, .card-body, .table-responsive { display: block !important; overflow: visible !important; width: 100% !important; max-width: 100% !important; padding: 0 !important; margin: 0 !important; border: none !important; box-shadow: none !important; } /* Strictly clear UI interactive components */ .d-print-none, form, nav, header, footer, button, .btn, .navbar, .sidebar { display: none !important; } table { width: 100% !important; border-collapse: collapse !important; page-break-inside: auto !important; } tr { page-break-inside: avoid !important; page-break-after: auto !important; } th, td { border: 1px solid #000 !important; color: #000 !important; padding: 6px !important; font-size: 12px !important; background: transparent !important; } thead { display: table-header-group !important; } } </style> <div class="wrap"> <div class="print-header d-flex justify-content-between align-items-end mb-3 pb-2"> <div> <h2 class="fw-bold m-0 text-dark">Parcel Reports</h2> <span class="small text-muted fw-bold">Type: <?= strtoupper($report_type) ?> Report | Range: <?= h(date('d-M-Y', strtotime($db_from))) ?> to <?= h(date('d-M-Y', strtotime($db_to))) ?></span> </div> <div class="d-print-none"> <?php if(!$isPrint): ?> <a href="?from=<?=urlencode($from)?>&to=<?=urlencode($to)?>&report_type=<?=urlencode($report_type)?>&print_view=1" target="_blank" class="btn btn-dark fw-bold px-4"> Print Document </a> <?php endif; ?> </div> </div> <?php if(!$isPrint): ?> <div class="card shadow-sm border-0 mb-4 d-print-none"> <div class="card-body p-3"> <form method="get" class="row g-3 align-items-end"> <div class="col-md-2"> <label class="form-label small fw-bold">From</label> <input type="date" name="from" class="form-control" value="<?=h($from)?>"> </div> <div class="col-md-2"> <label class="form-label small fw-bold">To</label> <input type="date" name="to" class="form-control" value="<?=h($to)?>"> </div> <div class="col-md-4"> <label class="form-label small fw-bold">Report Type</label> <select name="report_type" class="form-select"> <option value="send" <?= $report_type==='send'?'selected':'' ?>>Send Report</option> <option value="bill" <?= $report_type==='bill'?'selected':'' ?>>Bill Detail</option> <option value="stock" <?= $report_type==='stock'?'selected':'' ?>>Bill Stock</option> <option value="delay" <?= $report_type==='delay'?'selected':'' ?>>Delay Report</option> <option value="daily" <?= $report_type==='daily'?'selected':'' ?>>Daily Summary</option> <option value="pending" <?= $report_type==='pending'?'selected':'' ?>>Pending Report</option> </select> </div> <div class="col-md-4"> <button type="submit" class="btn btn-primary px-4">Apply Filter</button> </div> </form> </div> </div> <?php endif; ?> <div class="card shadow-sm border-0"> <div class="card-body <?= $isPrint ? 'p-0' : 'p-4' ?>"> <div class="table-responsive" style="overflow: visible !important;"> <?php /* ================================================================ 1. SEND REPORT ================================================================ */ if ($report_type === 'send') { $st = $pdo->prepare(" SELECT pse.bill_no, pse.vehicle_no, pse.send_date, pse.remark, psi.transport, psi.station FROM parcel_send_entry pse LEFT JOIN parcel_stock_in psi ON psi.company_id = pse.company_id AND psi.bill_no = pse.bill_no WHERE pse.company_id = ? AND pse.send_date BETWEEN ? AND ? ORDER BY pse.send_date "); $st->execute([$company_id, $db_from, $db_to]); echo "<table class='{$tableClass}'> <thead class='{$theadClass}'><tr> <th>Bill No</th><th>Transport</th><th>Station</th><th>Vehicle</th><th>Send Date</th><th>Remark</th> </tr></thead><tbody>"; foreach ($st as $r) { echo "<tr> <td>".h($r['bill_no'])."</td> <td>".h($r['transport'])."</td> <td>".h($r['station'])."</td> <td>".h($r['vehicle_no'])."</td> <td>".h($r['send_date'])."</td> <td>".h($r['remark'])."</td> </tr>"; } echo "</tbody></table>"; } /* ================================================================ 2. BILL DETAIL ================================================================ */ elseif ($report_type === 'bill') { $st = $pdo->prepare(" SELECT bill_no, bill_date, party, transport, station FROM parcel_stock_in WHERE company_id = ? AND bill_date BETWEEN ? AND ? ORDER BY bill_date "); $st->execute([$company_id, $db_from, $db_to]); echo "<table class='{$tableClass}'> <thead class='{$theadClass}'><tr> <th>Bill No</th><th>Bill Date</th><th>Party</th><th>Transport</th><th>Station</th> </tr></thead><tbody>"; foreach ($st as $r) { echo "<tr> <td>".h($r['bill_no'])."</td> <td>".h($r['bill_date'])."</td> <td>".h($r['party'])."</td> <td>".h($r['transport'])."</td> <td>".h($r['station'])."</td> </tr>"; } echo "</tbody></table>"; } /* ================================================================ 3. STOCK (PENDING PHYSICAL) ================================================================ */ elseif ($report_type === 'stock') { $st = $pdo->prepare(" SELECT psi.bill_no, psi.bill_date, psi.party, psi.transport, psi.station FROM parcel_stock_in psi {$joinCondition} WHERE psi.company_id = ? AND pse.id IS NULL AND psi.cleared_unknown = 0 ORDER BY psi.bill_date "); $st->execute([$company_id]); echo "<table class='{$tableClass}'> <thead class='{$theadClass}'><tr> <th>Bill No</th><th>Date</th><th>Party</th><th>Transport</th><th>Station</th> </tr></thead><tbody>"; foreach ($st as $r) { echo "<tr> <td>".h($r['bill_no'])."</td> <td>".h($r['bill_date'])."</td> <td>".h($r['party'])."</td> <td>".h($r['transport'])."</td> <td>".h($r['station'])."</td> </tr>"; } echo "</tbody></table>"; } /* ================================================================ 4. DELAY REPORT ================================================================ */ elseif ($report_type === 'delay') { $st = $pdo->prepare(" SELECT psi.bill_no, psi.bill_date, psi.party, psi.transport, psi.station, DATEDIFF(CURDATE(), psi.bill_date) AS delay_days FROM parcel_stock_in psi {$joinCondition} WHERE psi.company_id = ? AND pse.id IS NULL AND psi.cleared_unknown = 0 ORDER BY delay_days DESC "); $st->execute([$company_id]); echo "<table class='{$tableClass}'> <thead class='{$theadClass}'><tr> <th>Bill No</th><th>Date</th><th>Party</th><th>Transport</th><th>Station</th><th>Delay</th> </tr></thead><tbody>"; foreach ($st as $r) { $d = (int)$r['delay_days']; $class = ($d > 2 && !$isPrint) ? "bg-danger text-white fw-bold text-center" : "text-center"; echo "<tr> <td>".h($r['bill_no'])."</td> <td>".h($r['bill_date'])."</td> <td>".h($r['party'])."</td> <td>".h($r['transport'])."</td> <td>".h($r['station'])."</td> <td class='{$class}'>{$d}</td> </tr>"; } echo "</tbody></table>"; } /* ================================================================ 5. DAILY SUMMARY ================================================================ */ elseif ($report_type === 'daily') { $st = $pdo->prepare(" SELECT psi.bill_date AS d, COUNT(*) AS total_bills, SUM(CASE WHEN pse.id IS NOT NULL THEN 1 ELSE 0 END) AS sent_bills FROM parcel_stock_in psi {$joinCondition} WHERE psi.company_id = ? AND psi.bill_date BETWEEN ? AND ? GROUP BY psi.bill_date ORDER BY psi.bill_date "); $st->execute([$company_id, $db_from, $db_to]); echo "<table class='{$tableClass}'> <thead class='{$theadClass}'><tr> <th>Date</th><th>Total Bills</th><th>Sent</th><th>Pending</th> </tr></thead><tbody>"; foreach ($st as $r) { $total = (int)$r['total_bills']; $sent = (int)$r['sent_bills']; $pending = $total - $sent; echo "<tr> <td>".h($r['d'])."</td> <td class='text-center'>{$total}</td> <td class='text-center'>{$sent}</td> <td class='text-center fw-bold'>{$pending}</td> </tr>"; } echo "</tbody></table>"; } /* ================================================================ 6. PENDING REPORT (WITH FULL DYNAMIC DATES) ================================================================ */ elseif ($report_type === 'pending') { $st = $pdo->prepare(" SELECT psi.id, psi.bill_no, psi.bill_date, psi.party, psi.transport, psi.station FROM parcel_stock_in psi {$joinCondition} WHERE psi.company_id = ? AND psi.bill_date BETWEEN ? AND ? AND pse.id IS NULL AND psi.cleared_unknown = 0 ORDER BY psi.bill_date "); $st->execute([$company_id, $db_from, $db_to]); echo "<table class='{$tableClass}'> <thead class='{$theadClass}'><tr> <th>Bill No</th><th>Date</th><th>Party</th><th>Transport</th><th>Station</th>"; if (!$isPrint) echo "<th class='d-print-none'>Action</th>"; echo "</tr></thead><tbody>"; foreach ($st as $r) { echo "<tr> <td>".h($r['bill_no'])."</td> <td>".h($r['bill_date'])."</td> <td>".h($r['party'])."</td> <td>".h($r['transport'])."</td> <td>".h($r['station'])."</td>"; if (!$isPrint) { echo "<td class='d-print-none'> <form method='post' action='parcel_clear.php'> <input type='hidden' name='id' value='".(int)$r['id']."'> <button type='submit' class='btn btn-sm btn-success'>Clear</button> </form> </td>"; } echo "</tr>"; } echo "</tbody></table>"; } ?> </div> </div> </div> </div> <?php if (!$isPrint) { require_once __DIR__ . '/partials/footer.php'; } else { echo '</body></html>'; } ?>