« Back to History
saree_by_month_report.php
|
20260722_120325.php
Initial Domain Snapshot
Copy Code
<?php require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('saree_by_month_report'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } /* ================= INPUT ================= */ $from_month = $_GET['from'] ?? date('Y-m'); $to_month = $_GET['to'] ?? date('Y-m'); /* convert to date */ $from_date = $from_month . '-01'; $to_date = date('Y-m-t', strtotime($to_month . '-01')); /* ================= QUERY ================= */ $sql = " SELECT s.month_label, s.month_date, q.quality_name, SUM(s.total_saree) as total_saree FROM saree_by_month s LEFT JOIN qualities q ON q.code = s.quality AND q.company_id = s.company_id WHERE s.company_id = :cid AND s.month_date BETWEEN :from_dt AND :to_dt GROUP BY s.month_label, s.month_date, q.quality_name ORDER BY s.month_date ASC, q.quality_name ASC "; $st = $pdo->prepare($sql); $st->execute([ ':cid' => $company_id, ':from_dt' => $from_date, ':to_dt' => $to_date ]); $data = $st->fetchAll(PDO::FETCH_ASSOC); /* ================= GROUP BY MONTH ================= */ $months = []; foreach ($data as $row) { $month = $row['month_label']; if (!isset($months[$month])) { $months[$month] = []; } $months[$month][] = [ 'quality' => $row['quality_name'] ?? 'Unknown', 'total' => $row['total_saree'] ]; } require_once __DIR__ . '/partials/header.php'; ?> <div class="container py-4"> <!-- FILTER --> <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-4"> <label class="form-label fw-bold">From Month</label> <input type="month" name="from" class="form-control" value="<?=h($from_month)?>"> </div> <div class="col-md-4"> <label class="form-label fw-bold">To Month</label> <input type="month" name="to" class="form-control" value="<?=h($to_month)?>"> </div> <div class="col-md-4"> <button class="btn btn-primary w-100">Apply Filter</button> </div> </form> </div> </div> <!-- MONTH BOXES --> <div class="row g-4"> <?php if(empty($months)): ?> <div class="col-12"> <div class="alert alert-warning text-center"> No data found for selected range. </div> </div> <?php endif; ?> <?php foreach($months as $month_label => $list): ?> <div class="col-md-6 col-lg-4"> <div class="card shadow-sm h-100 border-0"> <div class="card-header bg-dark text-white fw-bold text-center"> <?= h($month_label) ?> </div> <div class="card-body"> <table class="table table-sm table-bordered mb-0"> <thead class="table-light"> <tr> <th>Quality</th> <th class="text-end">Total Saree</th> </tr> </thead> <tbody> <?php $month_total = 0; foreach($list as $row): $month_total += $row['total']; ?> <tr> <td><?= h($row['quality']) ?></td> <td class="text-end fw-bold"> <?= number_format($row['total'],0) ?> </td> </tr> <?php endforeach; ?> </tbody> <tfoot class="table-secondary"> <tr> <th>Total</th> <th class="text-end"> <?= number_format($month_total,0) ?> </th> </tr> </tfoot> </table> </div> </div> </div> <?php endforeach; ?> </div> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>