« Back to History
packing_material_in_report.php
|
20260722_120325.php
Initial Domain Snapshot
Copy Code
<?php require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('packing_material_in_report'); $pdo = $ctx['pdo']; $company_id = $ctx['company_id']; $u = $ctx['user']; /* ========================= FILTER ========================= */ $from = $_GET['from'] ?? date('Y-m-01'); $to = $_GET['to'] ?? date('Y-m-d'); /* ========================= DETAIL DATA ========================= */ $stmt = $pdo->prepare(" SELECT i.*, m.material_type, m.quality FROM packing_material_in i LEFT JOIN packing_material_type m ON m.id = i.material_type_id AND m.company_id = i.company_id WHERE i.company_id = ? AND i.entry_date BETWEEN ? AND ? ORDER BY i.entry_date DESC, i.id DESC "); $stmt->execute([$company_id, $from, $to]); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); /* ========================= PARTY SUMMARY ========================= */ $party = $pdo->prepare(" SELECT party_name, SUM(in_kg) as total_kg, SUM(in_pcs) as total_pcs, SUM( CASE WHEN in_kg > 0 THEN in_kg * rate ELSE in_pcs * rate END ) as amount FROM packing_material_in WHERE company_id = ? AND entry_date BETWEEN ? AND ? GROUP BY party_name ORDER BY party_name "); $party->execute([$company_id, $from, $to]); $party_rows = $party->fetchAll(PDO::FETCH_ASSOC); /* ========================= MATERIAL SUMMARY ========================= */ $material = $pdo->prepare(" SELECT i.material_type_id, m.material_type, m.quality, i.size, SUM(i.in_kg) as total_kg, SUM(i.in_pcs) as total_pcs, SUM( CASE WHEN i.in_kg > 0 THEN i.in_kg * i.rate ELSE i.in_pcs * i.rate END ) as amount FROM packing_material_in i LEFT JOIN packing_material_type m ON m.id = i.material_type_id AND m.company_id = i.company_id WHERE i.company_id = ? AND i.entry_date BETWEEN ? AND ? GROUP BY i.material_type_id, m.material_type, m.quality, i.size ORDER BY m.material_type, m.quality, i.size "); $material->execute([$company_id, $from, $to]); $material_rows = $material->fetchAll(PDO::FETCH_ASSOC); require_once __DIR__ . '/partials/header.php'; ?> <div class="container mt-3"> <h4>📦 Packing Material IN Report</h4> <!-- FILTER --> <form class="row mb-3"> <div class="col-md-3"> <label>From</label> <input type="date" name="from" value="<?= $from ?>" class="form-control"> </div> <div class="col-md-3"> <label>To</label> <input type="date" name="to" value="<?= $to ?>" class="form-control"> </div> <div class="col-md-2 mt-4"> <button class="btn btn-primary">Filter</button> </div> </form> <!-- ================= DETAIL ================= --> <div class="card p-3 mb-4"> <h5>Detailed Entries</h5> <table class="table table-bordered table-sm"> <thead> <tr> <th>Date</th> <th>Party</th> <th>Invoice</th> <th>Material</th> <th>Size</th> <th>KG</th> <th>PCS</th> <th>Rate</th> <th>Amount</th> </tr> </thead> <tbody> <?php foreach ($rows as $r): $amount = ($r['in_kg'] > 0) ? $r['in_kg'] * $r['rate'] : $r['in_pcs'] * $r['rate']; ?> <tr> <td><?= $r['entry_date'] ?></td> <td><?= $r['party_name'] ?></td> <td><?= $r['invoice_no'] ?></td> <td><?= htmlspecialchars(($r['material_type'] ?? '') !== '' ? $r['material_type'] : ('Material #' . $r['material_type_id'])) ?></td> <td><?= $r['size'] ?></td> <td><?= $r['in_kg'] ?></td> <td><?= $r['in_pcs'] ?></td> <td><?= $r['rate'] ?></td> <td><?= number_format($amount,2) ?></td> </tr> <?php endforeach; ?> </tbody> </table> </div> <!-- ================= PARTY SUMMARY ================= --> <div class="card p-3 mb-4"> <h5>Party-wise Summary</h5> <table class="table table-bordered table-sm"> <thead> <tr> <th>Party</th> <th>Total KG</th> <th>Total PCS</th> <th>Total Amount</th> </tr> </thead> <tbody> <?php foreach ($party_rows as $r): ?> <tr> <td><?= $r['party_name'] ?></td> <td><?= $r['total_kg'] ?></td> <td><?= $r['total_pcs'] ?></td> <td><?= number_format($r['amount'],2) ?></td> </tr> <?php endforeach; ?> </tbody> </table> </div> <!-- ================= MATERIAL SUMMARY ================= --> <div class="card p-3"> <h5>Material-wise Summary</h5> <table class="table table-bordered table-sm"> <thead> <tr> <th>Material</th> <th>Size</th> <th>Total KG</th> <th>Total PCS</th> <th>Total Amount</th> </tr> </thead> <tbody> <?php foreach ($material_rows as $r): ?> <tr> <td><?= htmlspecialchars(($r['material_type'] ?? '') !== '' ? $r['material_type'] : ('Material #' . $r['material_type_id'])) ?></td> <td><?= $r['size'] ?></td> <td><?= $r['total_kg'] ?></td> <td><?= $r['total_pcs'] ?></td> <td><?= number_format($r['amount'],2) ?></td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>