« Back to History
packing_pouch_out_entry.php
|
20260723_000646.php
Initial Domain Snapshot
Copy Code
<?php error_reporting(E_ALL); ini_set('display_errors', 1); // Auth & Context require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('packing_pouch'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; $user_id = isset($ctx['user_id']) ? (int)$ctx['user_id'] : (isset($u['id']) ? (int)$u['id'] : 0); function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } /* ================= SAVE / UPDATE LOGIC ================= */ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'save') { try { $pdo->beginTransaction(); $id = !empty($_POST['id']) ? (int)$_POST['id'] : null; // Delete-then-Insert pattern if ($id) { $del = $pdo->prepare("DELETE FROM packing_pouch_out WHERE id = ? AND company_id = ?"); $del->execute([$id, $company_id]); } $sql = "INSERT INTO packing_pouch_out (id, company_id, entry_date, pouch_type, pouch_size, quantity, remarks, created_by, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, NOW())"; $stmt = $pdo->prepare($sql); $stmt->execute([ $id, $company_id, $_POST['entry_date'], $_POST['pouch_type'], $_POST['pouch_size'], $_POST['quantity'], $_POST['remarks'] ?? '', $user_id ]); $pdo->commit(); header("Location: packing_pouch_out_entry.php?msg=Success"); exit; } catch (Exception $e) { if ($pdo->inTransaction()) $pdo->rollBack(); die("Error: " . $e->getMessage()); } } /* ================= FETCH MASTER DATA ================= */ $stmt_master = $pdo->prepare(" SELECT DISTINCT pouch_type, pouch_size FROM pouch_data WHERE company_id = ? AND is_active = 1 "); $stmt_master->execute([$company_id]); $masters = $stmt_master->fetchAll(PDO::FETCH_ASSOC); $unique_types = array_unique(array_column($masters, 'pouch_type')); /* ================= FETCH RECENT ENTRIES ================= */ $stmt_entries = $pdo->prepare(" SELECT * FROM packing_pouch_out WHERE company_id = ? ORDER BY entry_date DESC, id DESC LIMIT 15 "); $stmt_entries->execute([$company_id]); $entries = $stmt_entries->fetchAll(PDO::FETCH_ASSOC); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Packing Pouch OUT</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"> <style> body { background: #f4f6f9; font-size: 0.9rem; } .form-card { background: white; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,0.08); padding: 25px; border: none; } .table-card { background: white; border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); border: none; } .form-label { font-weight: 600; color: #555; } </style> </head> <body class="p-4"> <div class="container-fluid"> <div class="d-flex justify-content-between align-items-center mb-4"> <h4 class="fw-bold mb-0">📤 Packing Pouch Stock OUT</h4> <div class="text-muted small">Company ID: <strong><?= $company_id ?></strong></div> </div> <div class="form-card mb-4"> <form method="POST"> <input type="hidden" name="action" value="save"> <input type="hidden" name="id" id="row_id"> <div class="row g-3"> <div class="col-md-2"> <label class="form-label">Entry Date</label> <input type="date" name="entry_date" id="entry_date" class="form-control" value="<?= date('Y-m-d') ?>" required> </div> <div class="col-md-3"> <label class="form-label">Pouch Type</label> <select name="pouch_type" id="pouch_type" class="form-select" onchange="filterSizes()" required> <option value="">-- Select Type --</option> <?php foreach($unique_types as $type): ?> <option value="<?= h($type) ?>"><?= h($type) ?></option> <?php endforeach; ?> </select> </div> <div class="col-md-3"> <label class="form-label">Pouch Size</label> <select name="pouch_size" id="pouch_size" class="form-select" required> <option value="">-- Select Size --</option> <?php foreach($masters as $m): ?> <option value="<?= h($m['pouch_size']) ?>" class="size-opt d-none" data-type="<?= h($m['pouch_type']) ?>"> <?= h($m['pouch_size']) ?> </option> <?php endforeach; ?> </select> </div> <div class="col-md-2"> <label class="form-label">Quantity</label> <input type="number" name="quantity" id="quantity" class="form-control" min="1" required> </div> <div class="col-md-2 d-flex align-items-end"> <button type="submit" class="btn btn-danger w-100 fw-bold"> Save OUT </button> </div> <div class="col-md-12"> <label class="form-label">Remarks</label> <input type="text" name="remarks" id="remarks" class="form-control" placeholder="Optional details..."> </div> </div> </form> </div> <div class="table-card"> <div class="p-3 border-bottom bg-light rounded-top"> <h6 class="mb-0 fw-bold">Recent OUT Entries</h6> </div> <div class="table-responsive"> <table class="table table-hover align-middle mb-0"> <thead class="table-light small text-uppercase text-muted"> <tr> <th class="ps-4">Date</th> <th>Pouch Type</th> <th>Size</th> <th>Quantity</th> <th>Remarks</th> <th class="text-center">Action</th> </tr> </thead> <tbody> <?php if(empty($entries)): ?> <tr> <td colspan="6" class="text-center p-4 text-muted"> No entries found. </td> </tr> <?php endif; ?> <?php foreach($entries as $row): ?> <tr> <td class="ps-4 font-monospace"><?= h($row['entry_date']) ?></td> <td> <span class="badge bg-danger-subtle text-danger border border-danger-subtle px-3"> <?= h($row['pouch_type']) ?> </span> </td> <td><?= h($row['pouch_size']) ?></td> <td class="fw-bold"><?= number_format($row['quantity']) ?></td> <td class="text-muted small"><?= h($row['remarks']) ?></td> <td class="text-center"> <button class="btn btn-sm btn-outline-dark" onclick='editEntry(<?= json_encode($row) ?>)'> Edit </button> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> <script> function filterSizes() { const selectedType = document.getElementById('pouch_type').value; const options = document.querySelectorAll('.size-opt'); const sizeSelect = document.getElementById('pouch_size'); sizeSelect.value = ""; options.forEach(opt => { if (opt.getAttribute('data-type') === selectedType) { opt.classList.remove('d-none'); } else { opt.classList.add('d-none'); } }); } function editEntry(data) { document.getElementById('row_id').value = data.id; document.getElementById('entry_date').value = data.entry_date; document.getElementById('pouch_type').value = data.pouch_type; filterSizes(); document.getElementById('pouch_size').value = data.pouch_size; document.getElementById('quantity').value = data.quantity; document.getElementById('remarks').value = data.remarks; window.scrollTo({ top: 0, behavior: 'smooth' }); } </script> </body> </html>