« Back to History
mesr_jari_machine_entry.php
|
20260721_154033.php
Initial Bulk Import
Copy Code
<?php ini_set('display_errors', 1); error_reporting(E_ALL); require_once __DIR__ . '/../modules/auth/page_acl.php'; $ctx = page_require_access('mesr_stock_entry', []); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; $is_post = ($_SERVER['REQUEST_METHOD'] === 'POST'); /* ================= DEFAULT SAFE VALUES ================= */ $entry_date = $_POST['entry_date'] ?? date('Y-m-d'); $machine_id = (int)($_POST['machine_id'] ?? 0); $total_raws = (int)($_POST['total_raws'] ?? 0); $sections = $_POST['sections'] ?? []; /* ================= HEADER ================= */ require_once __DIR__ . '/../partials/header.php'; /* ====================================================== STEP 1: CONFIG FORM (GET OR INVALID POST) ====================================================== */ if ( !$is_post || !$machine_id || !$total_raws || !is_array($sections) || count($sections) !== 4 ): ?> <div class="card"> <h3>Jari Machine – Configuration</h3> <form method="post"> <div class="form-grid"> <label>Date</label> <input type="date" name="entry_date" value="<?= htmlspecialchars($entry_date) ?>" required> <label>Machine ID</label> <input type="number" name="machine_id" required> <label>Total Raws</label> <input type="number" name="total_raws" min="1" required> <hr> <?php for ($i = 1; $i <= 4; $i++): ?> <h4>Section <?= $i ?></h4> <input type="hidden" name="sections[<?= $i ?>][section_no]" value="<?= $i ?>"> <label>Material</label> <select name="sections[<?= $i ?>][material]" required> <option value="">Select</option> <option value="Kasab">Kasab</option> <option value="Metallic">Metallic</option> </select> <label>Denier</label> <input type="text" name="sections[<?= $i ?>][denier]" required> <label>Color</label> <input type="text" name="sections[<?= $i ?>][color]" placeholder="Gold / Silver"> <?php endfor; ?> <button class="btn btn-primary">Start Entry</button> </div> </form> </div> <?php require_once __DIR__ . '/../partials/footer.php'; exit; endif; /* ====================================================== STEP 2: ACTUAL ENTRY PAGE (VALID POST) ====================================================== */ ?> <div class="card"> <h3>Jari Entry – Machine <?= htmlspecialchars($machine_id) ?></h3> <p><strong>Date:</strong> <?= htmlspecialchars($entry_date) ?></p> <p><strong>Total Raws:</strong> <?= $total_raws ?></p> </div> <div class="card"> <h3>Raw <span id="rawCounter">1</span> / <?= $total_raws ?></h3> <form id="entryForm"> <input type="hidden" name="machine_id" value="<?= $machine_id ?>"> <input type="hidden" name="entry_date" value="<?= $entry_date ?>"> <input type="hidden" name="raw_no" id="raw_no" value="1"> <table class="table erp-table"> <thead> <tr> <th>Section</th> <th>Material</th> <th>Denier</th> <th>Color</th> <th>Weight (kg)</th> </tr> </thead> <tbody> <?php foreach ($sections as $i => $sec): ?> <tr> <td><?= $sec['section_no'] ?></td> <td><?= htmlspecialchars($sec['material']) ?></td> <td><?= htmlspecialchars($sec['denier']) ?></td> <td><?= htmlspecialchars($sec['color'] ?? '') ?></td> <td> <input type="number" step="0.001" required class="wgt" name="weights[<?= $i ?>]"> </td> </tr> <input type="hidden" name="sections[<?= $i ?>][section_no]" value="<?= $sec['section_no'] ?>"> <input type="hidden" name="sections[<?= $i ?>][material]" value="<?= $sec['material'] ?>"> <input type="hidden" name="sections[<?= $i ?>][denier]" value="<?= $sec['denier'] ?>"> <input type="hidden" name="sections[<?= $i ?>][color]" value="<?= $sec['color'] ?? '' ?>"> <?php endforeach; ?> </tbody> </table> <button type="submit" class="btn btn-success">Save Raw</button> </form> </div> <script> let currentRaw = 1; const totalRaws = <?= $total_raws ?>; document.querySelectorAll('.wgt').forEach((el, i, arr) => { el.addEventListener('keydown', e => { if (e.key === 'Enter') { e.preventDefault(); arr[i + 1]?.focus(); } }); }); document.getElementById('entryForm').onsubmit = async e => { e.preventDefault(); const fd = new FormData(e.target); const res = await fetch('mesr_jari_machine_save.php', { method:'POST', body:fd }); const out = await res.text(); if (!out.includes('OK')) { alert(out); return; } currentRaw++; if (currentRaw > totalRaws) { alert('All raws saved'); location.reload(); return; } document.getElementById('rawCounter').innerText = currentRaw; document.getElementById('raw_no').value = currentRaw; document.querySelectorAll('.wgt').forEach(i => i.value = ''); document.querySelector('.wgt').focus(); }; </script> <?php require_once __DIR__ . '/../partials/footer.php'; ?>