« Back to History
single_beam_report.php
|
20260722_120325.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('single_beam_report'); $company_id = (int)$ctx['company_id']; $pdo = $ctx['pdo']; function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } /* ========================================================= INPUT ========================================================= */ $beam_no = trim($_GET['beam_no'] ?? ''); if ($beam_no === '') { die('Beam number missing'); } /* ========================================================= COMPANY NAME ========================================================= */ $companyName = $pdo->prepare("SELECT name FROM companies WHERE id=?"); $companyName->execute([$company_id]); $company_name = $companyName->fetchColumn() ?: 'Company'; /* ========================================================= BEAM BOOK (METER SUMMARY) ========================================================= */ $beamBookStmt = $pdo->prepare(" SELECT total_meter, production FROM beam_book WHERE company_id=? AND beam_no=? "); $beamBookStmt->execute([$company_id, $beam_no]); $beamBook = $beamBookStmt->fetch(PDO::FETCH_ASSOC); if (!$beamBook) { die('Beam not found in beam_book'); } $total_meter = (float)$beamBook['total_meter']; $produced = (float)$beamBook['production']; $pending = max(0, $total_meter - $produced); $shortage = $pending; $percent = $total_meter > 0 ? round(($shortage / $total_meter) * 100, 2) : 0; /* ========================================================= LIFE CYCLE EVENTS (JSON) ========================================================= */ $lifeStmt = $pdo->prepare(" SELECT jt.action, jt.event_date, jt.machine_no, jt.slot, jt.warper_id, jt.employee_id, jt.meter FROM beam_life_cycle blc JOIN JSON_TABLE( blc.life_events, '$[*]' COLUMNS ( action VARCHAR(20) PATH '$.action', event_date DATE PATH '$.date', machine_no INT PATH '$.machine_no', slot VARCHAR(20) PATH '$.slot', warper_id INT PATH '$.warper_id', employee_id INT PATH '$.employee_id', meter DECIMAL(10,2) PATH '$.meter' ) ) jt WHERE blc.company_id = ? AND blc.beam_no = ? ORDER BY jt.event_date "); $lifeStmt->execute([$company_id, $beam_no]); $events = $lifeStmt->fetchAll(PDO::FETCH_ASSOC); /* ========================================================= MASTER DATA HELPERS ========================================================= */ function getName($pdo, $table, $id, $col='name'){ if (!$id) return ''; $q = $pdo->prepare("SELECT {$col} FROM {$table} WHERE id=?"); $q->execute([$id]); return $q->fetchColumn() ?: ''; } /* ========================================================= PAGE START ========================================================= */ $page_title = $company_name . ' : Single Beam Report'; require_once __DIR__ . '/partials/header.php'; ?> <div class="wrap"> <h2><?=h($company_name)?> : Single Beam Report</h2> <div class="card"> <table class="table table--bordered"> <tr><th>Beam No</th><td><?=h($beam_no)?></td></tr> <tr><th>Total Meter</th><td><?=number_format($total_meter,2)?></td></tr> <tr><th>Produced</th><td><?=number_format($produced,2)?></td></tr> <tr><th>Pending</th><td><?=number_format($pending,2)?></td></tr> <tr><th>Shortage</th><td><?=number_format($shortage,2)?></td></tr> <tr><th>Shortage %</th><td><?=number_format($percent,2)?>%</td></tr> </table> </div> <h3>Beam Life Timeline</h3> <table class="table table--bordered beam-book"> <thead> <tr> <th>Date</th> <th>Action</th> <th>Machine</th> <th>Slot</th> <th>Warper</th> <th>Employee</th> <th>Meter</th> </tr> </thead> <tbody> <?php foreach ($events as $e): ?> <tr> <td><?=h($e['event_date'])?></td> <td><?=ucfirst(h($e['action']))?></td> <td><?=h($e['machine_no'])?></td> <td><?=h($e['slot'])?></td> <td><?=h(getName($pdo,'warper_master',$e['warper_id'],'warper_name'))?></td> <td><?=h(getName($pdo,'company_employee_master',$e['employee_id'],'employee_name'))?></td> <td><?=number_format((float)$e['meter'],2)?></td> </tr> <?php endforeach; ?> </tbody> </table> <div class="toolbar no-print"> <button onclick="window.print()" class="btn">Print</button> </div> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>