« Back to History
beam_book_finish.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_book_finish'); $company_id = (int)$ctx['company_id']; $pdo = $ctx['pdo']; function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } /* ========================================================= DATE FILTER (FINISH DATE) ========================================================= */ $from_date = $_GET['from_date'] ?? ''; $to_date = $_GET['to_date'] ?? ''; $use_date_filter = ($from_date && $to_date); /* ========================================================= COMPANY NAME ========================================================= */ $companyName = $pdo->prepare("SELECT name FROM companies WHERE id=?"); $companyName->execute([$company_id]); $company_name = $companyName->fetchColumn() ?: 'Company'; /* ========================================================= FINISHED BEAMS (FROM JSON life_events) ========================================================= */ $sql = " SELECT blc.beam_no, jt.machine_no, jt.slot, jt.finish_date FROM beam_life_cycle blc JOIN JSON_TABLE( blc.life_events, '$[*]' COLUMNS ( action VARCHAR(20) PATH '$.action', machine_no INT PATH '$.machine_no', slot VARCHAR(20) PATH '$.slot', finish_date DATE PATH '$.finish_date' ) ) jt WHERE blc.company_id = ? AND jt.action = 'finish' "; $params = [$company_id]; if ($use_date_filter) { $sql .= " AND jt.finish_date BETWEEN ? AND ?"; $params[] = $from_date; $params[] = $to_date; } $finishedStmt = $pdo->prepare($sql); $finishedStmt->execute($params); $finishedBeams = $finishedStmt->fetchAll(PDO::FETCH_ASSOC); /* ========================================================= BEAM BOOK DATA ========================================================= */ $beamBookStmt = $pdo->prepare(" SELECT total_meter, production FROM beam_book WHERE company_id=? AND beam_no=? "); /* ========================================================= PREPARE ROWS ========================================================= */ $rows = []; foreach ($finishedBeams as $f) { $beamBookStmt->execute([$company_id, $f['beam_no']]); $bb = $beamBookStmt->fetch(PDO::FETCH_ASSOC); if (!$bb) continue; $total = (float)$bb['total_meter']; $produced = (float)$bb['production']; $shortage = max(0, $total - $produced); $percent = $total > 0 ? round(($shortage / $total) * 100, 2) : 0; $rows[] = [ 'machine_no' => $f['machine_no'], 'slot' => ucfirst($f['slot']) . ' Beam', 'beam_no' => $f['beam_no'], 'finish_date'=> $f['finish_date'], 'total' => $total, 'produced' => $produced, 'shortage' => $shortage, 'percent' => $percent, ]; } /* ========================================================= PAGE START ========================================================= */ $page_title = $company_name . ' : Beam Shortage Report'; require_once __DIR__ . '/partials/header.php'; ?> <div class="wrap"> <h2><?=h($company_name)?> : Beam Shortage Report</h2> <!-- ================= DATE FILTER ================= --> <form method="get" class="toolbar no-print"> <label> From: <input type="date" name="from_date" value="<?=h($from_date)?>"> </label> <label> To: <input type="date" name="to_date" value="<?=h($to_date)?>"> </label> <button type="submit" class="btn">Filter</button> <a href="beam_book_finish.php" class="btn btn--light">Reset</a> <button onclick="window.print()" type="button" class="btn">Print</button> <a href="beam_book_finish_csv.php?from_date=<?=h($from_date)?>&to_date=<?=h($to_date)?>" class="btn"> Export CSV </a> <a href="beam_book_finish_pdf.php?from_date=<?=h($from_date)?>&to_date=<?=h($to_date)?>" class="btn"> Export PDF </a> </form> <table class="table table--bordered beam-book"> <thead> <tr> <th>Machine</th> <th>Beam</th> <th>Beam No</th> <th>Finish Date</th> <th>Total Meter</th> <th>Produced</th> <th>Shortage</th> <th>Shortage %</th> </tr> </thead> <tbody> <?php if (!$rows): ?> <tr> <td colspan="8" style="text-align:center;">No records found</td> </tr> <?php endif; ?> <?php foreach ($rows as $r): ?> <?php $rowClass = ''; if ($r['produced'] > $r['total']) { $rowClass = 'row-success'; // GREEN } elseif ($r['percent'] > 9) { $rowClass = 'row-danger'; // RED } elseif ($r['percent'] > 5) { $rowClass = 'row-warning'; // YELLOW } ?> <tr class="<?=h($rowClass)?>"> <td class="machine-cell"><?=h($r['machine_no'])?></td> <td><?=h($r['slot'])?></td> <td><?=h($r['beam_no'])?></td> <td><?=h($r['finish_date'])?></td> <td><?=number_format($r['total'],2)?></td> <td><?=number_format($r['produced'],2)?></td> <td><?=number_format($r['shortage'],2)?></td> <td><?=number_format($r['percent'],2)?>%</td> </tr> <?php endforeach; ?> </tbody> </table> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>