« Back to History
kasab_entry_manage.php
|
20260721_154032.php
Initial Bulk Import
Copy Code
<?php require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('kasab_entry_manage'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; /* ---------- HELPERS ---------- */ function h($s) { return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } /* ---------- FETCH DATA ---------- */ $stmt = $pdo->prepare(" SELECT k.id, k.entry_date, k.roll_type, k.color, JSON_EXTRACT(k.rolls_json,'$.rolls') AS rolls, e.name AS contractor FROM kasab_entry k JOIN company_employee_master e ON e.id = k.employee_id WHERE k.company_id = :cid ORDER BY k.id DESC "); $stmt->execute([':cid' => $company_id]); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); ?> <?php require_once __DIR__ . '/partials/header.php'; ?> <div class="card"> <h2 class="text-center">Kasab Entries</h2> <table class="table"> <thead> <tr> <th>Date</th> <th>Roll Type</th> <th>Color</th> <th>Rolls</th> <th>Contractor</th> <th>Action</th> </tr> </thead> <tbody> <?php foreach ($rows as $r): ?> <tr> <td><?= h($r['entry_date']) ?></td> <td><?= h($r['roll_type']) ?></td> <td><?= h($r['color']) ?></td> <td><?= h($r['rolls']) ?></td> <td><?= h($r['contractor']) ?></td> <td> <button class="btn btn-sm btn-primary" onclick="openEdit(<?= (int)$r['id'] ?>)"> Edit </button> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> <div class="card" id="editBox" style="display:none"> <h3>Edit Weights</h3> <table class="table" id="editTable"> <thead> <tr> <th>Raw #</th> <th>Weight</th> <th>Avg / Roll</th> </tr> </thead> <tbody></tbody> </table> <button class="btn btn-success" onclick="saveEdit()">Update</button> </div> <script> let editId = 0; let editRolls = 0; let editWeights = []; function openEdit(id){ fetch('kasab_entry_get.php?id=' + id) .then(r => r.json()) .then(res => { editId = id; editRolls = res.rolls; editWeights = res.weights; const tbody = document.querySelector('#editTable tbody'); tbody.innerHTML = ''; editWeights.forEach((w,i)=>{ const avg = w / editRolls; tbody.innerHTML += ` <tr> <td>${i+1}</td> <td> <input type="number" step="0.01" value="${w}" onchange="editWeights[${i}] = parseFloat(this.value)"> </td> <td>${avg.toFixed(2)}</td> </tr> `; }); document.getElementById('editBox').style.display = 'block'; }); } function saveEdit(){ fetch('kasab_entry_update_batch.php', { method:'POST', headers:{'Content-Type':'application/json'}, body:JSON.stringify({ id: editId, weights: editWeights }) }) .then(r=>r.json()) .then(res=>{ if(res.success){ alert('Updated successfully'); location.reload(); } }); } </script> <?php require_once __DIR__ . '/partials/footer.php'; ?>