« Back to History
saree_quality_month_report.php
|
20260723_000646.php
Initial Domain Snapshot
Copy Code
<?php require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('saree_quality_month_report'); $company_id = (int)$ctx['company_id']; $pdo = $ctx['pdo']; if (!$pdo) require_once __DIR__ . '/core/db.php'; /* =============================== QUALITY MAP ================================ */ $QUALITY_MAP = [ 'Q001' => 'Balaton', 'Q002' => 'Butti', 'Q003' => 'Catonic', 'Q004' => 'GP', 'Q005' => 'Oarganza', 'Q006' => 'NP' ]; /* =============================== KHATA → SLAB MAP ================================ */ $SLAB_MAP = [ 'MST1' => '1-40', 'MST2A' => '41-76', 'MST2B' => '77-116', ]; /* =============================== AVAILABLE MONTHS ================================ */ $mStmt = $pdo->prepare(" SELECT DISTINCT month_label FROM saree_by_month WHERE company_id = ? ORDER BY month_date DESC "); $mStmt->execute([$company_id]); $MONTHS = $mStmt->fetchAll(PDO::FETCH_COLUMN); /* default = latest month */ $month_label = $_GET['month'] ?? ($MONTHS[0] ?? ''); if ($month_label === '') { die('No data available'); } /* =============================== FETCH DATA ================================ */ $stmt = $pdo->prepare(" SELECT quality, khata, SUM(total_saree) AS mtr FROM saree_by_month WHERE company_id = :cid AND month_label = :ml GROUP BY quality, khata "); $stmt->execute([ ':cid' => $company_id, ':ml' => $month_label, ]); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); /* =============================== BUILD MATRIX ================================ */ $report = []; $grand = []; foreach ($SLAB_MAP as $slab) { foreach ($QUALITY_MAP as $q) { $report[$slab][$q] = 0; } $report[$slab]['Total'] = 0; } foreach ($QUALITY_MAP as $q) { $grand[$q] = 0; } $grand['Total'] = 0; foreach ($rows as $r) { if (!isset($QUALITY_MAP[$r['quality']])) continue; if (!isset($SLAB_MAP[$r['khata']])) continue; $q = $QUALITY_MAP[$r['quality']]; $s = $SLAB_MAP[$r['khata']]; $m = (int)$r['mtr']; $report[$s][$q] += $m; $report[$s]['Total'] += $m; $grand[$q] += $m; $grand['Total'] += $m; } /* =============================== HELPERS ================================ */ function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } ?> <?php require_once __DIR__ . '/partials/header.php'; ?> <div class="wrap"> <div class="card"> <form method="get" style="margin-bottom:12px"> <label><b>Select Month:</b></label> <select name="month" onchange="this.form.submit()"> <?php foreach ($MONTHS as $m): ?> <option value="<?= h($m) ?>" <?= $m === $month_label ? 'selected' : '' ?>> <?= h($m) ?> </option> <?php endforeach; ?> </select> </form> <h2 style="text-align:center"><?= h($month_label) ?></h2> <table class="table table-bordered"> <thead> <tr> <th rowspan="2">Slab</th> <th colspan="<?= count($QUALITY_MAP) + 1 ?>" style="text-align:center"> Quality </th> </tr> <tr> <?php foreach ($QUALITY_MAP as $q): ?> <th><?= h($q) ?></th> <?php endforeach; ?> <th>Total</th> </tr> </thead> <tbody> <?php foreach ($report as $slab => $cols): ?> <tr> <th><?= h($slab) ?></th> <?php foreach ($QUALITY_MAP as $q): ?> <td><?= $cols[$q] ?: '' ?></td> <?php endforeach; ?> <th><?= $cols['Total'] ?></th> </tr> <?php endforeach; ?> </tbody> <tfoot> <tr> <th>Total</th> <?php foreach ($QUALITY_MAP as $q): ?> <th><?= $grand[$q] ?: '' ?></th> <?php endforeach; ?> <th><?= $grand['Total'] ?></th> </tr> </tfoot> </table> </div> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>