« Back to History
va_receive_summary.php
|
20260723_000646.php
Initial Domain Snapshot
Copy Code
<?php error_reporting(E_ALL); ini_set('display_errors', 1); require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('va_receive_summary'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; // Date Range Filter Logic (Default: Current Month) $first_day_of_month = date('Y-m-01'); $last_day_of_month = date('Y-m-t'); $from_date = $_GET['from_date'] ?? $first_day_of_month; $to_date = $_GET['to_date'] ?? $last_day_of_month; // SQL Logic: Grouped by Date and Quality $sql = " SELECT r.receive_date, IFNULL(qm.quality_name, 'Unknown Quality') as quality_title, SUM(r.total_pcs) as total_pcs FROM va_receive_entry r INNER JOIN va_send_entry s ON r.challan_no = s.challan_no AND r.company_id = s.company_id LEFT JOIN fabric_quality_master qm ON s.quality = qm.id AND s.company_id = qm.company_id WHERE r.company_id = :cid AND r.receive_date BETWEEN :from_date AND :to_date GROUP BY r.receive_date, qm.quality_name, s.quality ORDER BY r.receive_date DESC, quality_title ASC "; try { $stmt = $pdo->prepare($sql); $stmt->execute([ ':cid' => $company_id, ':from_date' => $from_date, ':to_date' => $to_date ]); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (Exception $e) { die("Query Error: " . $e->getMessage()); } // Data structural formatting for grouping by Date $grouped_data = []; foreach ($rows as $row) { $date = $row['receive_date']; $grouped_data[$date][] = $row; } require_once __DIR__ . '/partials/header.php'; ?> <div class="container-fluid mt-4 px-4"> <div class="card border-0 shadow-sm mb-4 no-print"> <div class="card-body bg-light rounded"> <form method="GET" class="row g-3 align-items-end"> <div class="col-md-3"> <label class="small fw-bold text-muted text-uppercase">From Date</label> <input type="date" name="from_date" class="form-control form-control-sm" value="<?= htmlspecialchars($from_date) ?>"> </div> <div class="col-md-3"> <label class="small fw-bold text-muted text-uppercase">To Date</label> <input type="date" name="to_date" class="form-control form-control-sm" value="<?= htmlspecialchars($to_date) ?>"> </div> <div class="col-md-3"> <button type="submit" class="btn btn-primary btn-sm px-4">Filter Report</button> <a href="va_receive_summary.php" class="btn btn-outline-secondary btn-sm px-3">Reset</a> </div> <div class="col-md-2 ms-auto text-end"> <button type="button" onclick="window.print()" class="btn btn-dark btn-sm px-4">Print Summary</button> </div> </form> </div> </div> <div class="card shadow-sm border-0"> <div class="card-header bg-white py-3"> <h5 class="text-primary fw-bold mb-0"> VA Receive Summary <span class="text-muted small">| Date Wise Quality Breakdown</span> </h5> </div> <div class="table-responsive"> <table class="table table-bordered align-middle mb-0"> <thead class="table-dark small text-uppercase"> <tr> <th style="width: 25%;">Receive Date</th> <th style="width: 50%;">Quality Name</th> <th class="text-center" style="width: 25%;">Total Pcs</th> </tr> </thead> <tbody class="small"> <?php $grand_total = 0; if (!empty($grouped_data)): foreach($grouped_data as $date => $records): $date_subtotal = 0; $row_count = count($records); foreach($records as $index => $r): $pcs = (int)$r['total_pcs']; $date_subtotal += $pcs; $grand_total += $pcs; ?> <tr> <?php if ($index === 0): ?> <td rowspan="<?= $row_count ?>" class="fw-bold text-dark align-top pt-3 bg-white"> <?= date('d-m-Y', strtotime($date)) ?> </td> <?php endif; ?> <td><?= htmlspecialchars($r['quality_title']) ?></td> <td class="text-center fw-semibold text-dark"><?= number_format($pcs) ?></td> </tr> <?php endforeach; ?> <tr class="table-secondary fw-bold"> <td colspan="2" class="text-end text-muted small text-uppercase">Total For <?= date('d-m-Y', strtotime($date)) ?>:</td> <td class="text-center text-dark"><?= number_format($date_subtotal) ?></td> </tr> <?php endforeach; ?> </tbody> <tfoot class="table-light fw-bold shadow-sm fs-6"> <tr> <td colspan="2" class="text-uppercase text-end">Grand Total:</td> <td class="text-center bg-dark text-white fw-bold"><?= number_format($grand_total) ?></td> </tr> <?php else: ?> <tr> <td colspan="3" class="text-center py-5 text-muted"> No receive records found for the selected date range. </td> </tr> <?php endif; ?> </tfoot> </table> </div> </div> </div> <style> @media print { .no-print, .navbar, .btn { display: none !important; } .card { border: none !important; box-shadow: none !important; } .table th { background-color: #212529 !important; color: #fff !important; -webkit-print-color-adjust: exact; } .table-secondary { background-color: #e2e3e5 !important; -webkit-print-color-adjust: exact; } .table-light { background-color: #f8f9fa !important; -webkit-print-color-adjust: exact; } } </style> <?php require_once __DIR__ . '/partials/footer.php'; ?>