« Back to History
beam_life_cycle_add.php
|
20260921_175631.php
Initial Domain Snapshot
Copy Code
<?php error_reporting(E_ALL); ini_set('display_errors', 1); require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('beam_register'); $pdo = $ctx['pdo']; $company_id = (int)($ctx['company_id'] ?? 0); require_once __DIR__ . '/helpers/beam_life_helpers.php'; require_once __DIR__ . '/helpers/activity_helper.php'; function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } /* ---------- TEST QUERY: Sabse Basic ---------- */ $machines = []; try { // Agar company_id ka issue hai toh filter hata kar dekho $st = $pdo->prepare("SELECT id, code FROM machines WHERE company_id = ? ORDER BY id ASC"); $st->execute([$company_id]); $machines = $st->fetchAll(PDO::FETCH_ASSOC); } catch (Exception $e) { $error = "SQL Error: " . $e->getMessage(); } $success = false; $msg = ""; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $beam_no = trim($_POST['beam_no'] ?? ''); $m_id = (int)($_POST['machine_id'] ?? 0); $slot = $_POST['slot'] ?? 'primary'; $action = $_POST['action'] ?? 'running'; $event_date = $_POST['event_date'] ?? date('Y-m-d'); if ($beam_no && $m_id) { try { // Machine code nikaalna $m_st = $pdo->prepare("SELECT code FROM machines WHERE id = ?"); $m_st->execute([$m_id]); $m_code = (string)$m_st->fetchColumn(); // Regex for number (L-01 -> 1) preg_match('/(\d+)$/', $m_code, $match); $m_no = isset($match[1]) ? ltrim($match[1], '0') : '0'; // Insert/Update $pdo->prepare("INSERT INTO beam_life_cycle (company_id, beam_no, life_events) VALUES (?, ?, JSON_ARRAY()) ON DUPLICATE KEY UPDATE beam_no=beam_no")->execute([$company_id, $beam_no]); $pdo->prepare("UPDATE beam_life_cycle SET life_events = JSON_ARRAY_APPEND(IFNULL(life_events, JSON_ARRAY()), '$', JSON_OBJECT('machine_no', ?, 'machine_id', ?, 'slot', ?, 'action', ?, 'load_date', ?)) WHERE company_id = ? AND beam_no = ?") ->execute([$m_no, $m_no, $slot, $action, $event_date, $company_id, $beam_no]); // Rebuild derived tables (updates company_beam_stock.load_type) $evStmt = $pdo->prepare("SELECT life_events FROM beam_life_cycle WHERE company_id = ? AND beam_no = ?"); $evStmt->execute([$company_id, (int)$beam_no]); $updatedEvents = json_decode($evStmt->fetchColumn() ?: '[]', true); rebuild_machine_beam_status($pdo, $company_id, (int)$beam_no, $updatedEvents); activity_update('beam', 'beam_life_cycle_add', (int)$beam_no, 'Updated beam life cycle'); $success = true; } catch (Exception $e) { $msg = $e->getMessage(); } } } require_once __DIR__ . '/partials/header.php'; ?> <div class="container py-4"> <div class="card border-danger shadow mx-auto" style="max-width: 500px;"> <div class="card-header bg-danger text-white text-center"> <h5 class="mb-0">FORCE FIX BEAM DATA</h5> </div> <div class="card-body"> <?php if($success): ?> <div class="alert alert-success">Added! Beam: <?=h($beam_no)?></div> <?php endif; ?> <?php if(isset($error)): ?> <div class="alert alert-warning small"><?=h($error)?></div> <?php endif; ?> <form method="post"> <div class="mb-3"> <label class="form-label fw-bold">BEAM NO</label> <input name="beam_no" class="form-control border-dark" required> </div> <div class="mb-3"> <label class="form-label fw-bold">MACHINE</label> <select name="machine_id" class="form-select border-primary" required> <option value="">-- Select --</option> <?php foreach ($machines as $m): ?> <option value="<?= $m['id'] ?>"><?= h($m['code']) ?></option> <?php endforeach; ?> </select> <?php if(empty($machines)): ?> <small class="text-danger">No machines found! Check DB.</small> <?php endif; ?> </div> <div class="row"> <div class="col-6 mb-3"> <label class="form-label fw-bold">SLOT</label> <select name="slot" class="form-select"> <option value="primary">Primary</option> <option value="secondary">Secondary</option> </select> </div> <div class="col-6 mb-3"> <label class="form-label fw-bold">ACTION</label> <select name="action" class="form-select"> <option value="running">Running</option> <option value="cut">Cut</option> <option value="finish">Finish</option> </select> </div> </div> <div class="mb-3"> <label class="form-label fw-bold">DATE</label> <input type="date" name="event_date" class="form-control" value="<?=date('Y-m-d')?>"> </div> <button type="submit" class="btn btn-danger w-100 fw-bold">FORCE SAVE</button> </form> </div> </div> </div> <footer style="height:28px; line-height:28px; background:#000; color:#fff; text-align:center; position:fixed; bottom:0; width:100%; font-size:10px;"> SYSTEM RECOVERY MODE </footer> <?php require_once __DIR__ . '/partials/footer.php'; ?>