« Back to History
va_sample_entry.php
|
20260721_154033.php
Initial Bulk Import
Copy Code
<?php require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('va_sample_entry'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; $u = $ctx['user']; require_once __DIR__ . '/partials/header.php'; // Handle form submit if ($_SERVER['REQUEST_METHOD'] === 'POST') { $entry_type = $_POST['entry_type'] ?? ''; $entry_date = $_POST['entry_date'] ?? date('Y-m-d'); $party_name = $_POST['party_name'] ?? ''; $item_name = $_POST['item_name'] ?? ''; $color = $_POST['color'] ?? ''; $quantity = $_POST['quantity'] ?? 0; $weight = $_POST['weight'] ?? 0; $remark = $_POST['remark'] ?? ''; if ($entry_type && $entry_date) { $stmt = $pdo->prepare(" INSERT INTO va_sample_entry (company_id, entry_type, entry_date, party_name, item_name, color, quantity, weight, remark) VALUES (:cid, :type, :date, :party, :item, :color, :qty, :wt, :remark) "); $stmt->execute([ ':cid' => $company_id, ':type' => $entry_type, ':date' => $entry_date, ':party' => $party_name, ':item' => $item_name, ':color' => $color, ':qty' => $quantity, ':wt' => $weight, ':remark' => $remark ]); echo '<div class="alert alert-success">Entry Saved</div>'; } else { echo '<div class="alert alert-danger">Required fields missing</div>'; } } // Fetch report $stmt = $pdo->prepare(" SELECT * FROM va_sample_entry WHERE company_id = :cid ORDER BY id DESC LIMIT 50 "); $stmt->execute([':cid' => $company_id]); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); ?> <div class="container mt-4"> <div class="card"> <div class="card-header d-flex justify-content-between"> <h5>VA Sample Entry</h5> <!-- Toggle Button --> <button type="button" id="toggleBtn" class="btn btn-warning"> Mode: SEND </button> </div> <div class="card-body"> <form method="POST" class="row g-3"> <input type="hidden" name="entry_type" id="entry_type" value="send"> <div class="col-md-3"> <label class="form-label">Date</label> <input type="date" name="entry_date" class="form-control" value="<?= date('Y-m-d') ?>" required> </div> <div class="col-md-3"> <label class="form-label">Party</label> <input type="text" name="party_name" class="form-control"> </div> <div class="col-md-3"> <label class="form-label">Item</label> <input type="text" name="item_name" class="form-control"> </div> <div class="col-md-3"> <label class="form-label">Color</label> <input type="text" name="color" class="form-control"> </div> <div class="col-md-3"> <label class="form-label">Quantity</label> <input type="number" step="0.001" name="quantity" class="form-control"> </div> <div class="col-md-3"> <label class="form-label">Weight</label> <input type="number" step="0.001" name="weight" class="form-control"> </div> <div class="col-md-6"> <label class="form-label">Remark</label> <input type="text" name="remark" class="form-control"> </div> <div class="col-12 text-end"> <button class="btn btn-primary">Save Entry</button> </div> </form> </div> </div> <!-- Report Section --> <div class="card mt-4"> <div class="card-header"> <h5>Recent Entries</h5> </div> <div class="card-body"> <table class="table table-bordered table-sm"> <thead> <tr> <th>Date</th> <th>Type</th> <th>Party</th> <th>Item</th> <th>Color</th> <th>Qty</th> <th>Weight</th> <th>Remark</th> </tr> </thead> <tbody> <?php foreach ($rows as $r): ?> <tr> <td><?= htmlspecialchars($r['entry_date']) ?></td> <td> <span class="badge <?= $r['entry_type']=='send' ? 'bg-danger' : 'bg-success' ?>"> <?= strtoupper($r['entry_type']) ?> </span> </td> <td><?= htmlspecialchars($r['party_name']) ?></td> <td><?= htmlspecialchars($r['item_name']) ?></td> <td><?= htmlspecialchars($r['color']) ?></td> <td><?= $r['quantity'] ?></td> <td><?= $r['weight'] ?></td> <td><?= htmlspecialchars($r['remark']) ?></td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> <script> let mode = 'send'; document.getElementById('toggleBtn').addEventListener('click', function() { mode = (mode === 'send') ? 'receive' : 'send'; document.getElementById('entry_type').value = mode; this.innerText = "Mode: " + mode.toUpperCase(); this.classList.toggle('btn-warning'); this.classList.toggle('btn-success'); }); </script> <?php require_once __DIR__ . '/partials/footer.php'; ?>