« Back to History
backfill_beam_installation.php
|
20260722_120325.php
Initial Domain Snapshot
Copy Code
<?php /* ============================================================================= File: /erp/tools/backfill_beam_installation.php Title: Backfill Beam Installation Dates (earliest Pasaria/Pissing) Scope: Ops tool; Page-local; NO global/base edits. ============================================================================= */ header('X-Frame-Options: SAMEORIGIN'); error_reporting(E_ALL); ini_set('display_errors',1); require __DIR__.'/../modules/auth/auth.php'; require_login(['Owner','Admin','Manager']); // restrict appropriately $u = auth_user(); $company_id = (int)$u['company_id']; $pdo = $GLOBALS['pdo'] ?? null; if(!$pdo){ require __DIR__ . '/../core/db.php'; } require_once __DIR__.'/../modules/beam/_beam_installation_lib.php'; ensure_beam_installation_columns($pdo); function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } $do = isset($_POST['do']) && $_POST['do']=='1'; $changed=0; $scanned=0; if ($do) { $pdo->beginTransaction(); // Scan only NULL ones to be efficient $sql="SELECT beam_no FROM beam_entry WHERE company_id=? AND installation_date IS NULL"; $st=$pdo->prepare($sql); $st->execute([$company_id]); while($bn = $st->fetchColumn()){ $scanned++; if (recalc_installation_for_beam($pdo,$company_id,$bn)) $changed++; } $pdo->commit(); } ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Backfill Beam Installation Dates</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> body{font-family:system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;margin:0;background:#f6f8fa} .wrap{max-width:760px;margin:24px auto;padding:0 16px} h1{margin:0 0 10px;font-size:22px} .card{background:#fff;border:1px solid #d0d7de;border-radius:12px;padding:16px} .btn{padding:10px 14px;border:1px solid #d0d7de;border-radius:8px;background:#fff;cursor:pointer} .muted{color:#6a737d;font-size:12px} .ok{background:#e6fcf5;border:1px solid #c3fae8;color:#087f5b;padding:8px;border-radius:8px;margin-top:8px} </style> </head> <body> <?php if (is_file(__DIR__.'/../partials/header.php')) include __DIR__.'/../partials/header.php'; ?> <div class="wrap"> <h1>Backfill Beam Installation Dates</h1> <div class="card"> <form method="post"> <p class="muted">This sets <b>installation_date</b> and <b>installation_source</b> from the earliest Pasaria/Pissing entry per beam (Pasaria preferred on legacy conflicts).</p> <button class="btn" name="do" value="1" onclick="return confirm('Backfill now?')">Run Backfill</button> </form> <?php if($do): ?> <div class="ok">Scanned: <b><?= $scanned ?></b>, Updated: <b><?= $changed ?></b></div> <?php endif; ?> </div> </div> </body> </html>