« Back to History
packing_pouch_stock_report.php
|
20260721_154033.php
Initial Bulk Import
Copy Code
<?php error_reporting(E_ALL); ini_set('display_errors', 1); require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('packing_pouch'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; define('PER_BUNDLE_QTY', 200); // 🔹 Change if needed function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } /* ================= SIMPLE STOCK QUERY ================= */ $sql = " SELECT pouch_type, pouch_size, SUM(total_in) AS total_in_bundle, SUM(total_out) AS total_out_bundle, (SUM(total_in) - SUM(total_out)) AS current_bundle FROM ( SELECT pouch_type COLLATE utf8mb4_unicode_ci AS pouch_type, pouch_size COLLATE utf8mb4_unicode_ci AS pouch_size, SUM(quantity) AS total_in, 0 AS total_out FROM packing_pouch_in WHERE company_id = :cid GROUP BY pouch_type, pouch_size UNION ALL SELECT pouch_type COLLATE utf8mb4_unicode_ci AS pouch_type, pouch_size COLLATE utf8mb4_unicode_ci AS pouch_size, 0, SUM(quantity) FROM packing_pouch_out WHERE company_id = :cid GROUP BY pouch_type, pouch_size ) x GROUP BY pouch_type, pouch_size ORDER BY pouch_type, pouch_size "; $stmt = $pdo->prepare($sql); $stmt->execute(['cid' => $company_id]); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Packing Pouch Stock Report</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"> </head> <body class="p-4"> <div class="container-fluid"> <h4>📊 Packing Pouch Stock Report</h4> <table class="table table-bordered table-sm"> <thead> <tr> <th>Type</th> <th>Size</th> <th class="text-end">In (Bundle)</th> <th class="text-end">In (PCS)</th> <th class="text-end">Out (Bundle)</th> <th class="text-end">Out (PCS)</th> <th class="text-end">Stock (Bundle)</th> <th class="text-end">Stock (PCS)</th> </tr> </thead> <tbody> <?php foreach($rows as $r): $in_bundle = (int)$r['total_in_bundle']; $out_bundle = (int)$r['total_out_bundle']; $stock_bundle = (int)$r['current_bundle']; $in_pcs = $in_bundle * PER_BUNDLE_QTY; $out_pcs = $out_bundle * PER_BUNDLE_QTY; $stock_pcs = $stock_bundle * PER_BUNDLE_QTY; ?> <tr> <td><?= h($r['pouch_type']) ?></td> <td><?= h($r['pouch_size']) ?></td> <td class="text-end"><?= $in_bundle ?></td> <td class="text-end"><?= $in_pcs ?></td> <td class="text-end"><?= $out_bundle ?></td> <td class="text-end"><?= $out_pcs ?></td> <td class="text-end"><?= $stock_bundle ?></td> <td class="text-end"><?= $stock_pcs ?></td> </tr> <?php endforeach; ?> </tbody> </table> </div> </body> </html>