« Back to History
beam_to_yarn_edit.php
|
20260723_000646.php
Initial Domain Snapshot
Copy Code
<?php require_once __DIR__ . '/../modules/auth/page_acl.php'; $ctx = page_require_access('beam_to_yarn'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; $month = $_GET['month'] ?? ''; $location_id = (int)($_GET['location_id'] ?? 0); $machine_id = (int)($_GET['machine_id'] ?? 0); $stock_type = $_GET['stock_type'] ?? ''; if (!$month || !$location_id || !$stock_type) { die("Invalid parameters"); } // FETCH DATA $stmt = $pdo->prepare(" SELECT * FROM mesr_beam_to_yarn_stock WHERE company_id = :cid AND month = :m AND location_id = :l AND machine_id = :mac AND stock_type = :st "); $stmt->execute([ ':cid'=>$company_id, ':m'=>$month, ':l'=>$location_id, ':mac'=>$machine_id, ':st'=>$stock_type ]); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); // SAVE if ($_SERVER['REQUEST_METHOD'] === 'POST') { $month_post = $_POST['month'].'-01'; $pdo->beginTransaction(); try { // DELETE OLD GROUP $pdo->prepare(" DELETE FROM mesr_beam_to_yarn_stock WHERE company_id=? AND month=? AND location_id=? AND machine_id=? AND stock_type=? ")->execute([$company_id,$month_post,$location_id,$machine_id,$stock_type]); // INSERT NEW $ins = $pdo->prepare(" INSERT INTO mesr_beam_to_yarn_stock (company_id, month, location_id, machine_id, stock_type, denier, color, total_weight, remark, created_at) VALUES (?,?,?,?,?,?,?,?,?,NOW()) "); foreach ($_POST['denier'] as $i=>$d) { if(!$d) continue; $ins->execute([ $company_id, $month_post, $location_id, $machine_id, $stock_type, $d, $_POST['color'][$i], $_POST['total_weight'][$i], $_POST['remark'][$i] ]); } $pdo->commit(); require_once __DIR__ . '/../helpers/activity_helper.php'; log_activity([ 'activity_type' => 'entry', 'module_name' => 'beam_to_yarn_edit', 'action_name' => 'save', 'activity_note' => "Month: $month_post, Location: $location_id, Machine: $machine_id, Stock Type: $stock_type", 'reference_id' => null, ]); header("Location: mesr_beam_to_yarn.php?success=1"); exit; } catch(Exception $e){ $pdo->rollBack(); die($e->getMessage()); } } require_once __DIR__ . '/../partials/header.php'; ?> <div class="container mt-3"> <h4>Edit Beam → Yarn</h4> <form method="POST"> <input type="month" name="month" value="<?= substr($month,0,7) ?>" class="form-control mb-3"> <table class="table table-bordered" id="tbl"> <thead> <tr> <th>Denier</th> <th>Color</th> <th>Weight</th> <th>Remark</th> <th>X</th> </tr> </thead> <tbody> <?php foreach($rows as $r): ?> <tr> <td><input name="denier[]" value="<?= $r['denier'] ?>" class="form-control"></td> <td><input name="color[]" value="<?= $r['color'] ?>" class="form-control"></td> <td><input name="total_weight[]" value="<?= $r['total_weight'] ?>" class="form-control"></td> <td><input name="remark[]" value="<?= $r['remark'] ?>" class="form-control"></td> <td><button type="button" onclick="this.closest('tr').remove()">X</button></td> </tr> <?php endforeach; ?> </tbody> </table> <button type="button" onclick="addRow()" class="btn btn-success">+ Row</button> <button class="btn btn-primary">Update</button> </form> </div> <script> function addRow(){ let row = document.querySelector("#tbl tbody tr").cloneNode(true); row.querySelectorAll('input').forEach(i=>i.value=''); document.querySelector("#tbl tbody").appendChild(row); } </script> <?php require_once __DIR__ . '/../partials/footer.php'; ?>