« Back to History
monthly_folding_summary.php
|
20260723_000646.php
Initial Domain Snapshot
Copy Code
<?php require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('folding_entry_report'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; function e($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } $today = date('Y-m-d'); $from = $_GET['from'] ?? date('Y-m-01'); $to = $_GET['to'] ?? $today; if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $from)) $from = date('Y-m-01'); if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $to)) $to = $today; /* |-------------------------------------------------------------------------- | MONTH + QUALITY WISE AGGREGATION |-------------------------------------------------------------------------- */ $sql = " SELECT DATE_FORMAT(fe.entry_date, '%Y-%m') AS ym, DATE_FORMAT(fe.entry_date, '%M %Y') AS month_label, q.quality_name, SUM(fe.total_meter) AS total_meter, SUM(fe.total_saree) AS total_saree, SUM(fe.total_weight) AS total_weight FROM folding_entry fe LEFT JOIN qualities q ON q.id = fe.quality_id AND q.company_id = fe.company_id WHERE fe.company_id = :cid AND fe.entry_date BETWEEN :f AND :t GROUP BY ym, fe.quality_id ORDER BY ym, q.quality_name "; $stmt = $pdo->prepare($sql); $stmt->execute([ ':cid' => $company_id, ':f' => $from, ':t' => $to ]); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); require_once __DIR__ . '/partials/header.php'; ?> <div class="container-fluid py-4"> <div class="card shadow-sm mb-4"> <div class="card-body"> <form method="get" class="row g-3 align-items-end"> <div class="col-md-3"> <label class="form-label fw-semibold">From Date</label> <input type="date" name="from" value="<?= e($from) ?>" class="form-control"> </div> <div class="col-md-3"> <label class="form-label fw-semibold">To Date</label> <input type="date" name="to" value="<?= e($to) ?>" class="form-control"> </div> <div class="col-md-3"> <button class="btn btn-primary w-100"> Show Report </button> </div> </form> </div> </div> <div class="text-center mb-3"> <h4 class="fw-bold">Monthly Quality-wise Folding Summary</h4> <div class="text-muted"> <?= e($from) ?> — <?= e($to) ?> </div> </div> <div class="card shadow-sm"> <div class="card-body p-0"> <div class="table-responsive"> <table class="table table-bordered table-striped align-middle mb-0 text-nowrap"> <thead class="table-dark text-center"> <tr> <th>#</th> <th>Month</th> <th>Quality</th> <th class="text-end">Total Meter</th> <th class="text-end">Total Saree</th> <th class="text-end">Total Weight</th> <th class="text-end">Final Cut</th> </tr> </thead> <tbody> <?php if(empty($rows)): ?> <tr> <td colspan="7" class="text-center py-4"> No data found for selected range. </td> </tr> <?php else: ?> <?php $i = 1; foreach($rows as $r): $meter = (float)$r['total_meter']; $saree = (float)$r['total_saree']; $weight = (float)$r['total_weight']; $cut = ($saree > 0) ? ($meter / $saree) : 0; ?> <tr> <td><?= $i++ ?></td> <td><?= e($r['month_label']) ?></td> <td><?= e($r['quality_name'] ?? 'Unknown') ?></td> <td class="text-end"><?= number_format($meter,2) ?></td> <td class="text-end"><?= number_format($saree,0) ?></td> <td class="text-end"><?= number_format($weight,2) ?></td> <td class="text-end fw-bold"> <?= $saree > 0 ? number_format($cut,3) : '-' ?> </td> </tr> <?php endforeach; ?> <?php endif; ?> </tbody> </table> </div> </div> </div> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>