« Back to History
va_pending_for_va.php
|
20260721_154033.php
Initial Bulk Import
Copy Code
<?php error_reporting(E_ALL); ini_set('display_errors', 1); require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('dashboard'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } // Date Filter Logic $from_date = $_GET['from_date'] ?? date('Y-m-01'); $to_date = $_GET['to_date'] ?? date('Y-m-d'); /* LOGIC UPDATE: - Shifted from gr.id to gr.gray_id (Manual Serial) - Linked cutting_entry and va_send_entry using gray_id */ $query = " SELECT gr.gray_id as lot_no, gr.gpno, gr.rec_date as gray_rec_date, MAX(ce.rec_date) as last_cutting_date, fqm.quality_name, SUM(ce.fresh_saree) as total_fresh_cut, COALESCE(v.sent_pcs, 0) as total_sent_pcs, (SUM(ce.fresh_saree) - COALESCE(v.sent_pcs, 0)) as pending_pcs FROM gray_receive gr /* Join using manual gray_id */ INNER JOIN cutting_entry ce ON gr.gray_id = ce.gray_id AND gr.company_id = ce.company_id LEFT JOIN ( SELECT grey_id, SUM(pcs) as sent_pcs FROM va_send_entry WHERE company_id = :cid1 GROUP BY grey_id ) v ON gr.gray_id = v.grey_id LEFT JOIN fabric_quality_master fqm ON gr.quality_id = fqm.id WHERE gr.company_id = :cid2 AND gr.rec_date >= :f AND gr.rec_date <= :t GROUP BY gr.gray_id HAVING pending_pcs > 0 ORDER BY gr.gray_id DESC "; try { $st = $pdo->prepare($query); $st->execute([ ':cid1' => $company_id, ':cid2' => $company_id, ':f' => $from_date, ':t' => $to_date ]); $report_data = $st->fetchAll(PDO::FETCH_ASSOC); } catch (Exception $e) { die("<div class='alert alert-danger'>SQL Error: " . h($e->getMessage()) . "</div>"); } require_once __DIR__ . '/partials/header.php'; ?> <div class="container-fluid py-4 px-4"> <div class="card mb-4 no-print bg-light border-0 shadow-sm"> <div class="card-body py-2"> <form method="get" class="row g-2 align-items-end justify-content-center"> <div class="col-md-2"> <label class="small fw-bold">From (Gray Rec Date)</label> <input type="date" name="from_date" value="<?= $from_date ?>" class="form-control form-control-sm"> </div> <div class="col-md-2"> <label class="small fw-bold">To (Gray Rec Date)</label> <input type="date" name="to_date" value="<?= $to_date ?>" class="form-control form-control-sm"> </div> <div class="col-md-1"> <button class="btn btn-primary btn-sm w-100 fw-bold shadow-sm">Apply</button> </div> <div class="col-md-1"> <button type="button" onclick="window.print()" class="btn btn-dark btn-sm w-100 shadow-sm">Print</button> </div> </form> </div> </div> <div class="text-center mb-4"> <h4 class="fw-bold mb-0 text-primary">VA Pending Report (Fresh Stock)</h4> <div class="text-muted small fw-bold mt-1"> Serial Wise Tracking | Gray Received: <?= date('d/m/Y', strtotime($from_date)) ?> to <?= date('d/m/Y', strtotime($to_date)) ?> </div> </div> <div class="card border-0 shadow-sm"> <div class="table-responsive"> <table class="table table-bordered align-middle mb-0"> <thead class="table-dark text-uppercase" style="font-size: 11px;"> <tr> <th class="text-center">Lot (Gray ID)</th> <th>GP No</th> <th>Gray Date</th> <th>Last Cutting</th> <th>Quality</th> <th class="text-center">Fresh Cut</th> <th class="text-center">Sent VA</th> <th class="text-center bg-danger text-white border-danger">Pending Pcs</th> </tr> </thead> <tbody style="font-size: 13px;"> <?php if(empty($report_data)): ?> <tr><td colspan="8" class="text-center py-5 text-muted">No pending fresh stock found for this range.</td></tr> <?php else: ?> <?php foreach($report_data as $row): ?> <tr> <td class="text-center fw-bold text-primary">#<?= h($row['lot_no']) ?></td> <td><?= h($row['gpno']) ?></td> <td class="text-muted small"><?= date('d-m-Y', strtotime($row['gray_rec_date'])) ?></td> <td class="fw-bold text-info small"><?= $row['last_cutting_date'] ? date('d-m-Y', strtotime($row['last_cutting_date'])) : '-' ?></td> <td><?= h($row['quality_name'] ?? 'N/A') ?></td> <td class="text-center fw-bold"><?= number_format($row['total_fresh_cut']) ?></td> <td class="text-center text-success fw-bold"><?= number_format($row['total_sent_pcs']) ?></td> <td class="text-center fw-bold text-danger" style="background: #fff5f5; font-size: 14px;"> <?= number_format($row['pending_pcs']) ?> </td> </tr> <?php endforeach; ?> <?php endif; ?> </tbody> </table> </div> </div> </div> <style> @media print { @page { size: A4 landscape; margin: 8mm; } .no-print { 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; } .text-primary { color: #000 !important; } } </style> <?php require_once __DIR__ . '/partials/footer.php'; ?>