« Back to History
beam_installation_list.php
|
20260921_175631.php
Initial Domain Snapshot
Copy Code
<?php /* ============================================================================= File: /erp/beam_installation_list.php Title: Beam Installation / Stock — Using installation_date + source Scope: Page-local; multi-company aware; 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(); $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'); } function gv($k,$d=null){ return isset($_GET[$k])?trim((string)$_GET[$k]):$d; } function pv($k,$d=null){ return isset($_POST[$k])?trim((string)$_POST[$k]):$d; } $STATUS = gv('status','any'); // any|stock|installed $SRC = gv('src','any'); // any|pissing|pasaria $Q = gv('q',''); $DF = gv('from',''); // installation_date from $DT = gv('to',''); // installation_date to $PP = max(10,min(200,(int)gv('pp',50))); $PAGE = max(1,(int)gv('page',1)); $OFF = ($PAGE-1)*$PP; $EXPORT = gv('export',''); // csv /* Optional: recalc selected */ if ($_SERVER['REQUEST_METHOD']==='POST' && ($_POST['act']??'')==='recalc' && !empty($_POST['b'])) { $bs = array_filter(array_map('trim',(array)$_POST['b'])); $pdo->beginTransaction(); foreach($bs as $bn){ recalc_installation_for_beam($pdo,$company_id,$bn); } $pdo->commit(); header("Location: ".$_SERVER['REQUEST_URI']); exit; } /* Chips */ $cnt_total = (int)$pdo->query("SELECT COUNT(*) FROM beam_entry WHERE company_id={$company_id}")->fetchColumn(); $cnt_stock = (int)$pdo->query("SELECT COUNT(*) FROM beam_entry WHERE company_id={$company_id} AND installation_date IS NULL")->fetchColumn(); $cnt_inst = $cnt_total - $cnt_stock; /* Base query */ $where="b.company_id=:cid"; $prms=[':cid'=>$company_id]; if($Q!==''){ $where.=" AND b.beam_no LIKE :q"; $prms[':q']="%$Q%"; } if($STATUS==='stock'){ $where.=" AND b.installation_date IS NULL"; } elseif($STATUS==='installed'){ $where.=" AND b.installation_date IS NOT NULL"; } if($SRC==='pissing'){ $where.=" AND b.installation_source='pissing'"; } elseif($SRC==='pasaria'){ $where.=" AND b.installation_source='pasaria'"; } if($DF!==''){ $where.=" AND b.installation_date >= :df"; $prms[':df']=$DF; } if($DT!==''){ $where.=" AND b.installation_date <= :dt"; $prms[':dt']=$DT; } $sqlBase = " SELECT b.id, b.entry_date AS beam_date, b.beam_no, b.taka, b.meter, b.tar, b.quality_id, q.name AS quality_name, q.pattern, q.jala_no, COALESCE(cem.name,e.name) AS warper_name, b.installation_date, b.installation_source, /* for display: latest event details */ (SELECT pe.machine_no FROM pasaria_entry pe WHERE pe.company_id=b.company_id AND (pe.primary_beam_no=b.beam_no OR pe.secondary_beam_no=b.beam_no) ORDER BY pe.id DESC LIMIT 1) AS pasaria_machine_no, (SELECT CASE WHEN pe.primary_beam_no=b.beam_no THEN 'Primary' WHEN pe.secondary_beam_no=b.beam_no THEN 'Secondary' END FROM pasaria_entry pe WHERE pe.company_id=b.company_id AND (pe.primary_beam_no=b.beam_no OR pe.secondary_beam_no=b.beam_no) ORDER BY pe.id DESC LIMIT 1) AS pasaria_side, (SELECT pe.employee_name FROM pasaria_entry pe WHERE pe.company_id=b.company_id AND (pe.primary_beam_no=b.beam_no OR pe.secondary_beam_no=b.beam_no) ORDER BY pe.id DESC LIMIT 1) AS pasaria_by, (SELECT pe.machine_no FROM pissing_entry pe WHERE pe.company_id=b.company_id AND pe.beam_no=b.beam_no ORDER BY pe.id DESC LIMIT 1) AS pissing_machine_no, (SELECT pe.pissing_type FROM pissing_entry pe WHERE pe.company_id=b.company_id AND pe.beam_no=b.beam_no ORDER BY pe.id DESC LIMIT 1) AS pissing_type, (SELECT pe.employee_name FROM pissing_entry pe WHERE pe.company_id=b.company_id AND pe.beam_no=b.beam_no ORDER BY pe.id DESC LIMIT 1) AS pissing_by FROM beam_entry b LEFT JOIN beam_qualities q ON q.id=b.quality_id AND q.company_id=b.company_id LEFT JOIN company_employee_master cem ON cem.id=b.employee_id AND cem.company_id=b.company_id LEFT JOIN employees e ON e.id=b.employee_id AND e.company_id=b.company_id WHERE $where"; /* Export CSV */ if ($EXPORT==='csv') { $sqlCSV = $sqlBase." ORDER BY (b.installation_date IS NULL) DESC, b.installation_date DESC, b.id DESC"; $st=$pdo->prepare($sqlCSV); $st->execute($prms); header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=beam_installation_list.csv'); $out=fopen('php://output','w'); fputcsv($out,['Beam No','Beam Date','Quality','Pattern','Jala','TAR','Meters','Taka','Warper','Installation Date','Source','Pasaria Machine','Side','Pasaria By','Pissing Machine','Pissing Type','Pissing By']); while($r=$st->fetch(PDO::FETCH_ASSOC)){ fputcsv($out,[ $r['beam_no'],$r['beam_date'],$r['quality_name'],$r['pattern'],$r['jala_no'], $r['tar'],$r['meter'],$r['taka'],$r['warper_name'],$r['installation_date'],$r['installation_source'], $r['pasaria_machine_no'],$r['pasaria_side'],$r['pasaria_by'], $r['pissing_machine_no'],$r['pissing_type'],$r['pissing_by'] ]); } fclose($out); exit; } /* Count + page */ $sqlCnt = "SELECT COUNT(*) FROM ( $sqlBase ) x"; $st=$pdo->prepare($sqlCnt); $st->execute($prms); $TOTAL=(int)$st->fetchColumn(); $sqlPage = $sqlBase." ORDER BY (b.installation_date IS NULL) DESC, b.installation_date DESC, b.id DESC LIMIT :lim OFFSET :off"; $st=$pdo->prepare($sqlPage); foreach($prms as $k=>$v){ $st->bindValue($k,$v); } $st->bindValue(':lim',$PP,PDO::PARAM_INT); $st->bindValue(':off',$OFF,PDO::PARAM_INT); $st->execute(); $rows=$st->fetchAll(PDO::FETCH_ASSOC); ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Beam Installation / Stock</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:1400px;margin:24px auto;padding:0 16px} h1{margin:0 0 10px;font-size:22px} .chips{display:flex;gap:8px;flex-wrap:wrap;margin:8px 0 16px} .chip{padding:6px 10px;border-radius:999px;font-size:12px;border:1px solid #d0d7de;background:#fff} .filters{display:flex;gap:8px;flex-wrap:wrap;margin:12px 0} input[type=text],input[type=date],select{padding:8px 10px;border:1px solid #d0d7de;border-radius:8px;background:#fff} .btn{padding:8px 12px;border:1px solid #d0d7de;border-radius:8px;background:#fff;cursor:pointer} table{width:100%;border-collapse:collapse;background:#fff;border:1px solid #d0d7de;border-radius:12px;overflow:hidden} th,td{padding:10px;border-bottom:1px solid #eaeef2;text-align:left;font-size:13px;vertical-align:top} tr:hover{background:#fafbfc} .muted{color:#6a737d} .s{font-weight:600;padding:2px 8px;border-radius:999px;font-size:12px;display:inline-block;border:1px solid #d0d7de;background:#fff} .s-stock{background:#e6fcf5;border-color:#c3fae8;color:#087f5b} .s-pissing{background:#e7f5ff;border-color:#d0ebff;color:#0b7285} .s-pasaria{background:#fff3cd;border-color:#ffe69c;color:#8a6d3b} </style> </head> <body> <?php if (is_file(__DIR__.'/partials/header.php')) include __DIR__.'/partials/header.php'; ?> <div class="wrap"> <h1>Beam Installation / Stock</h1> <div class="chips"> <div class="chip">Total: <b><?= $cnt_total ?></b></div> <div class="chip">In Stock: <b><?= $cnt_stock ?></b></div> <div class="chip">Installed: <b><?= $cnt_inst ?></b></div> </div> <form class="filters" method="get"> <input type="text" name="q" value="<?= h($Q) ?>" placeholder="Search Beam No…"> <select name="status"> <option value="any" <?= $STATUS==='any'?'selected':'' ?>>Status: Any</option> <option value="stock" <?= $STATUS==='stock'?'selected':'' ?>>In Stock</option> <option value="installed"<?= $STATUS==='installed'?'selected':'' ?>>Installed</option> </select> <select name="src"> <option value="any" <?= $SRC==='any'?'selected':'' ?>>Source: Any</option> <option value="pissing" <?= $SRC==='pissing'?'selected':'' ?>>Pissing</option> <option value="pasaria" <?= $SRC==='pasaria'?'selected':'' ?>>Pasaria</option> </select> <input type="date" name="from" value="<?= h($DF) ?>"> <input type="date" name="to" value="<?= h($DT) ?>"> <select name="pp"> <?php foreach([25,50,100,200] as $opt): ?> <option value="<?= $opt ?>" <?= $PP==$opt?'selected':'' ?>>Per page: <?= $opt ?></option> <?php endforeach; ?> </select> <button class="btn">Apply</button> <a class="btn" href="?<?= http_build_query(['q'=>$Q,'status'=>$STATUS,'src'=>$SRC,'from'=>$DF,'to'=>$DT,'pp'=>$PP,'export'=>'csv']) ?>">Export CSV</a> </form> <form method="post"> <input type="hidden" name="act" value="recalc"> <table> <thead> <tr> <th>#</th> <th><input type="checkbox" onclick="document.querySelectorAll('input[name=\'b[]\']').forEach(cb=>cb.checked=this.checked)"></th> <th>Beam No</th> <th>Beam Date</th> <th>Quality / Pattern / Jala</th> <th>TAR</th> <th>Meters</th> <th>Taka</th> <th>Warper</th> <th>Installation Date</th> <th>Source</th> <th>Pasaria → Machine / Side / By</th> <th>Pissing → Machine / Type / By</th> </tr> </thead> <tbody> <?php if(!$rows): ?> <tr><td colspan="13" class="muted">No records.</td></tr> <?php else: foreach($rows as $i=>$r): $badge = 's-stock'; if ($r['installation_source']==='pissing') $badge='s-pissing'; if ($r['installation_source']==='pasaria') $badge='s-pasaria'; ?> <tr> <td><?= $OFF+$i+1 ?></td> <td><input type="checkbox" name="b[]" value="<?= h($r['beam_no']) ?>"></td> <td><b><?= h($r['beam_no']) ?></b></td> <td><?= h($r['beam_date']) ?></td> <td> <?= h($r['quality_name'] ?: ('#'.$r['quality_id'])) ?> <?php if($r['pattern'] || $r['jala_no']): ?> <div class="muted"> <?php if($r['pattern']) echo 'Pattern: '.h($r['pattern']).' '; ?> <?php if($r['jala_no']) echo 'Jala: '.h($r['jala_no']); ?> </div> <?php endif; ?> </td> <td><?= h($r['tar']) ?></td> <td><?= h($r['meter']) ?></td> <td><?= h($r['taka']) ?></td> <td><?= h($r['warper_name']) ?></td> <td><?= h($r['installation_date'] ?: '') ?></td> <td><span class="s <?= $badge ?>"><?= h($r['installation_source'] ?: 'In Stock') ?></span></td> <td> <div><?= h($r['pasaria_machine_no'] ?: '-') ?></div> <div class="muted"><?= h($r['pasaria_side'] ?: '') ?> <?= h($r['pasaria_by'] ? ('/ '.$r['pasaria_by']) : '') ?></div> </td> <td> <div><?= h($r['pissing_machine_no'] ?: '-') ?></div> <div class="muted"><?= h($r['pissing_type'] ?: '') ?> <?= h($r['pissing_by'] ? ('/ '.$r['pissing_by']) : '') ?></div> </td> </tr> <?php endforeach; endif; ?> </tbody> </table> <div class="filters" style="justify-content:space-between"> <div class="muted">Showing <?= count($rows)?($OFF+1):0 ?>–<?= $OFF+count($rows) ?> of <?= $TOTAL ?></div> <div> <?php if($PAGE>1): ?> <a class="btn" href="?<?= http_build_query(['q'=>$Q,'status'=>$STATUS,'src'=>$SRC,'from'=>$DF,'to'=>$DT,'pp'=>$PP,'page'=>$PAGE-1]) ?>">Prev</a> <?php endif; ?> <?php if($OFF+$PP < $TOTAL): ?> <a class="btn" href="?<?= http_build_query(['q'=>$Q,'status'=>$STATUS,'src'=>$SRC,'from'=>$DF,'to'=>$DT,'pp'=>$PP,'page'=>$PAGE+1]) ?>">Next</a> <?php endif; ?> <button class="btn" type="submit" onclick="return confirm('Recalculate installation date for selected beams?')">Recalculate selected</button> </div> </div> </form> </div> </body> </html>