« Back to History
beam_sent_list.php
|
20260722_120325.php
Initial Domain Snapshot
Copy Code
<?php /* ========================================================================= File: /erp/beam_sent_list.php Purpose: List + Edit (popup) for beam_sent table Scope : company-scoped; no base/global changes ========================================================================= */ header('X-Frame-Options: SAMEORIGIN'); error_reporting(E_ALL); ini_set('display_errors', 1); require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('beam_sent_list'); $u = $ctx['user'] ?? null; $company_id = (int)($ctx['company_id'] ?? 0); $pdo = $ctx['pdo'] ?? null; require_once __DIR__ . '/helpers/activity_helper.php'; require_once __DIR__ . '/partials/header.php'; /* -------------------- Handle Update -------------------- */ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['edit_id'])) { $edit_id = (int)$_POST['edit_id']; $beam_no = trim($_POST['beam_no'] ?? ''); $meter = trim($_POST['meter'] ?? ''); $quality_id = trim($_POST['quality_id'] ?? ''); $sent_to = trim($_POST['sent_to'] ?? ''); $employee_id = trim($_POST['employee_id'] ?? ''); $sent_date = trim($_POST['sent_date'] ?? ''); $q = $pdo->prepare(" UPDATE beam_sent SET beam_no = :beam_no, meter = :meter, quality_id = :quality_id, sent_to = :sent_to, employee_id = :employee_id, sent_date = :sent_date WHERE id = :id AND company_id = :cid "); $q->execute([ ':beam_no' => $beam_no, ':meter' => $meter, ':quality_id' => $quality_id, ':sent_to' => $sent_to, ':employee_id' => $employee_id, ':sent_date' => $sent_date, ':id' => $edit_id, ':cid' => $company_id ]); activity_update('beam', 'beam_sent_list_update', $edit_id, 'Updated beam sent record'); echo "<script>alert('Updated successfully');window.location='beam_sent_list.php';</script>"; exit; } /* -------------------- Fetch All -------------------- */ $q = $pdo->prepare("SELECT * FROM beam_sent WHERE company_id = :cid ORDER BY id DESC"); $q->execute([':cid' => $company_id]); $rows = $q->fetchAll(PDO::FETCH_ASSOC); ?> <div class="card"> <div class="card-header"> <h2>Beam Sent List</h2> </div> <div class="card-body"> <table class="table table-striped table-bordered"> <thead> <tr> <th>ID</th> <th>Sent Date</th> <th>Beam No</th> <th>Meter</th> <th>Quality ID</th> <th>Sent To</th> <th>Employee ID</th> <th>Created By</th> <th>Created At</th> <th>Action</th> </tr> </thead> <tbody> <?php foreach ($rows as $r): ?> <tr> <td><?= htmlspecialchars($r['id']) ?></td> <td><?= htmlspecialchars($r['sent_date']) ?></td> <td><?= htmlspecialchars($r['beam_no']) ?></td> <td><?= htmlspecialchars($r['meter']) ?></td> <td><?= htmlspecialchars($r['quality_id']) ?></td> <td><?= htmlspecialchars($r['sent_to']) ?></td> <td><?= htmlspecialchars($r['employee_id']) ?></td> <td><?= htmlspecialchars($r['created_by']) ?></td> <td><?= htmlspecialchars($r['created_at']) ?></td> <td> <button class="btn btn-sm btn-primary editBtn" data-id="<?= $r['id'] ?>" data-date="<?= $r['sent_date'] ?>" data-beam="<?= $r['beam_no'] ?>" data-meter="<?= $r['meter'] ?>" data-quality="<?= $r['quality_id'] ?>" data-sentto="<?= $r['sent_to'] ?>" data-emp="<?= $r['employee_id'] ?>"> Edit </button> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> <!-- Popup Modal --> <div id="editModal" class="modal hidden"> <div class="modal-content card"> <div class="card-header"> <h3>Edit Beam Sent Entry</h3> </div> <div class="card-body"> <form method="POST" id="editForm"> <input type="hidden" name="edit_id" id="edit_id"> <div class="form-grid"> <label>Sent Date:</label> <input type="date" name="sent_date" id="sent_date" required> <label>Beam No:</label> <input type="text" name="beam_no" id="beam_no" required> <label>Meter:</label> <input type="number" name="meter" id="meter" required> <label>Quality ID:</label> <input type="text" name="quality_id" id="quality_id" required> <label>Sent To:</label> <input type="text" name="sent_to" id="sent_to" required> <label>Employee ID:</label> <input type="text" name="employee_id" id="employee_id" required> </div> <div class="mt-3"> <button type="submit" class="btn btn-success">Update</button> <button type="button" class="btn btn-secondary" id="closeModal">Cancel</button> </div> </form> </div> </div> </div> <script> document.querySelectorAll('.editBtn').forEach(btn => { btn.addEventListener('click', () => { document.getElementById('edit_id').value = btn.dataset.id; document.getElementById('sent_date').value = btn.dataset.date; document.getElementById('beam_no').value = btn.dataset.beam; document.getElementById('meter').value = btn.dataset.meter; document.getElementById('quality_id').value = btn.dataset.quality; document.getElementById('sent_to').value = btn.dataset.sentto; document.getElementById('employee_id').value = btn.dataset.emp; document.getElementById('editModal').classList.remove('hidden'); }); }); document.getElementById('closeModal').addEventListener('click', () => { document.getElementById('editModal').classList.add('hidden'); }); </script> <?php require_once __DIR__ . '/partials/footer.php'; ?>