« Back to History
gray_receive_report.php
|
20260723_000646.php
Initial Domain Snapshot
Copy Code
<?php /* ====================================================================== FILE: /erp/gray_receive_report.php ====================================================================== */ require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('gray_receive_report'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; require_once __DIR__ . '/helpers/activity_helper.php'; if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'track_print') { $from_date = trim((string)($_POST['from'] ?? '')); $to_date = trim((string)($_POST['to'] ?? '')); $shortage_sort = trim((string)($_POST['shortage_sort'] ?? '')); $parts = []; if ($from_date !== '') { $parts[] = 'from '.$from_date; } if ($to_date !== '') { $parts[] = 'to '.$to_date; } if ($shortage_sort !== '') { $parts[] = 'sort='.$shortage_sort; } $remarks = ''; if (!empty($parts)) { $remarks = implode(', ', $parts); } if (function_exists('activity_print')) { activity_print('gray_receive_report', 'print', 0, $remarks); } elseif (function_exists('log_activity')) { log_activity([ 'activity_type' => 'print', 'module_name' => 'gray_receive_report', 'action_name' => 'print', 'activity_note' => $remarks, 'reference_id' => null, ]); } header('Content-Type: application/json'); echo json_encode(['ok' => true]); exit; } // Default dates for filter $from = $_GET['from'] ?? date('Y-m-d', strtotime('-30 days')); $to = $_GET['to'] ?? date('Y-m-d'); $shortage_sort = $_GET['shortage_sort'] ?? ''; $order_by = 'gr.rec_date DESC, gr.gray_id DESC'; if ($shortage_sort === 'high_to_low') { $order_by = '(gr.grey_mts - gr.finish_mts) DESC, gr.rec_date DESC, gr.gray_id DESC'; } elseif ($shortage_sort === 'low_to_high') { $order_by = '(gr.grey_mts - gr.finish_mts) ASC, gr.rec_date DESC, gr.gray_id DESC'; } require_once __DIR__ . '/partials/header.php'; /* ---------- FILTER ---------- */ $params = [':cid' => $company_id]; $where = "WHERE gr.company_id = :cid"; if ($from) { $where .= " AND gr.rec_date >= :from"; $params[':from'] = $from; } if ($to) { $where .= " AND gr.rec_date <= :to"; $params[':to'] = $to; } /* ---------- QUERY ---------- */ $sql = " SELECT gr.gray_id, gr.gpno, gr.rec_date, gr.grey_mts, gr.finish_mts AS init_mts, gr.taka, gr.quality_id, fq.quality_name, m.mill_name FROM gray_receive gr LEFT JOIN mill_master m ON m.id = gr.mill_id AND m.company_id = gr.company_id LEFT JOIN fabric_quality_master fq ON fq.id = gr.quality_id AND fq.company_id = gr.company_id $where ORDER BY $order_by "; $stmt = $pdo->prepare($sql); $stmt->execute($params); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); function h($s) { return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } ?> <style> /* UI FOR SCREEN */ .report-table th { font-size: 11px; background: #f8f9fa !important; color: #333 !important; padding: 8px 4px !important; text-align: center; vertical-align: middle; text-transform: uppercase; border: 1px solid #dee2e6 !important; } .report-table td { font-size: 12px; padding: 6px 4px !important; vertical-align: middle; } .badge-g { background: #f1f3f5; color: #0d6efd; padding: 2px 5px; border-radius: 3px; border: 1px solid #dee2e6; font-size: 10px; font-weight: bold; } .gp-text { font-weight: 700; color: #212529; display: block; line-height: 1.2; margin-top: 2px; } .mill-text { color: #868e96; font-size: 10px; } .status-check { color: #d63384; font-weight: bold; background: #fff0f6; border: 1px solid #ffdeeb; padding: 1px 6px; border-radius: 10px; font-size: 10px; } .status-ok { color: #099268; font-weight: bold; background: #ebfbee; border: 1px solid #d3f9d8; padding: 1px 6px; border-radius: 10px; font-size: 10px; } /* HARD PRINT FIX - FORCING A4 FIT & LOW INK */ @media print { @page { size: A4 portrait; margin: 5mm; } body { background: #fff !important; margin: 0; padding: 0; } .no-print { display: none !important; } .container-fluid { width: 100% !important; padding: 0 !important; margin: 0 !important; } .card { border: none !important; box-shadow: none !important; } .card-header { padding: 5px 0 !important; border-bottom: 1px solid #000 !important; } .report-table { width: 100% !important; table-layout: fixed !important; border-collapse: collapse !important; } /* Ink Saving Header (Light Grey instead of Black) */ .report-table thead th { background-color: #f2f2f2 !important; color: #000 !important; print-color-adjust: exact !important; -webkit-print-color-adjust: exact !important; border: 0.1pt solid #444 !important; font-size: 9px !important; padding: 4px 1px !important; } .report-table tbody td { border: 0.1pt solid #888 !important; font-size: 9px !important; padding: 3px 2px !important; word-wrap: break-word !important; } /* Strict Column Widths */ .col-date { width: 11% !important; } .col-info { width: 34% !important; } .col-gray { width: 13% !important; } .col-finish { width: 13% !important; } .col-short { width: 11% !important; } .col-pct { width: 9% !important; } .col-status { width: 9% !important; } .gp-text { font-size: 9px !important; } .mill-text { font-size: 8px !important; color: #333 !important; } .badge-g { border: none !important; color: #000 !important; font-size: 8px !important; padding: 0 !important; } .status-check, .status-ok { background: transparent !important; border: 0.1pt solid #999 !important; color: #000 !important; } } </style> <div class="container-fluid mt-3"> <div class="card shadow-sm border-0 mb-3 no-print"> <div class="card-body p-3"> <form id="report-filter-form" method="GET" class="row g-3 align-items-end"> <div class="col-md-3"> <label class="small fw-bold">From Date</label> <input type="date" name="from" class="form-control form-control-sm" value="<?= h($from) ?>"> </div> <div class="col-md-3"> <label class="small fw-bold">To Date</label> <input type="date" name="to" class="form-control form-control-sm" value="<?= h($to) ?>"> </div> <div class="col-md-3"> <label class="small fw-bold">Shortage Sort</label> <select name="shortage_sort" class="form-select form-select-sm"> <option value="" <?= $shortage_sort === '' ? 'selected' : '' ?>>Default</option> <option value="high_to_low" <?= $shortage_sort === 'high_to_low' ? 'selected' : '' ?>>Shortage High to Low</option> <option value="low_to_high" <?= $shortage_sort === 'low_to_high' ? 'selected' : '' ?>>Shortage Low to High</option> </select> </div> <div class="col-md-3"> <button type="submit" class="btn btn-sm btn-primary px-4 shadow-sm">Filter Data</button> <button type="button" onclick="trackPrintAndPrint()" class="btn btn-sm btn-dark ms-1 shadow-sm">Print Report</button> </div> </form> </div> </div> <div class="card shadow-sm border-0"> <div class="card-header bg-white py-2 d-flex justify-content-between align-items-center"> <h6 class="mb-0 fw-bold text-primary">Mill Receive report</h6> <span class="badge bg-light text-dark border no-print"><?= count($rows) ?> Lots Found</span> </div> <div class="card-body p-0"> <div class="table-responsive"> <table class="table table-bordered report-table mb-0"> <thead> <tr> <th class="col-date">Rec. Date</th> <th class="col-info">Gray ID / GP / Mill</th> <th class="col-quality">Quality</th> <th class="col-taka text-end">Taka</th> <th class="col-gray text-end">Gray Mtr</th> <th class="col-finish text-end">Finish Mtr</th> <th class="col-short text-end">Short Mts</th> <th class="col-pct">Short %</th> <th class="col-status">Status</th> </tr> </thead> <tbody> <?php foreach($rows as $r): $gray = (float)$r['grey_mts']; $init_mts = (float)$r['init_mts']; $short_mts = $gray - $init_mts; $init_pct = ($gray > 0) ? ($short_mts / $gray) * 100 : 0; if ($init_pct > 5) { $status = "CHECK"; $s_class = "status-check"; } else { $status = "OK"; $s_class = "status-ok"; } ?> <tr> <td class="text-center"><?= date('d-m-Y', strtotime($r['rec_date'])) ?></td> <td> <span class="badge-g">ID: <?= $r['gray_id'] ?></span> <span class="gp-text">GP: <?= h($r['gpno']) ?></span> <span class="mill-text"><?= h($r['mill_name']) ?></span> </td> <td><?= h($r['quality_name']) ?></td> <td class="text-end fw-bold"><?= number_format((float)$r['taka']) ?></td> <td class="text-end fw-bold"><?= number_format($gray, 2) ?></td> <td class="text-end"><?= number_format($init_mts, 2) ?></td> <td class="text-end text-muted"><?= number_format($short_mts, 2) ?></td> <td class="text-center fw-bold <?= ($init_pct > 5) ? 'text-danger' : '' ?>"> <?= number_format($init_pct, 2) ?>% </td> <td class="text-center"> <span class="<?= $s_class ?>"><?= $status ?></span> </td> </tr> <?php endforeach; ?> <?php if(empty($rows)): ?> <tr> <td colspan="9" class="text-center py-4 text-muted">No records found for the selected dates.</td> </tr> <?php endif; ?> </tbody> </table> </div> </div> </div> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>