« Back to History
beam_quality_view.php
|
20260920_164915.php
Initial Domain Snapshot
Copy Code
<?php /* ========================================================= File: /erp/beam_quality_view.php Purpose: View-only page for Beam Quality (multi-yarn rows) Notes: Page-local; no edits, no schema changes. Mirrors beam_quality_edit layout ========================================================= */ error_reporting(E_ALL); ini_set('display_errors',1); /* ====== Auth/Bootstrap ====== */ require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('beam_quality_view'); $company_id = (int)$ctx['company_id']; $user_id = (int)$ctx['user']['id']; $u = $ctx['user']; $pdo = (isset($ctx['pdo']) && $ctx['pdo'] instanceof PDO) ? $ctx['pdo'] : null; if (!$pdo) { require __DIR__ . '/core/db.php'; } /* helpers */ function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } function canonical_stock($raw){ $raw = strtoupper(trim((string)$raw)); static $map = ['YARN'=>'Yarn','TFO'=>'TFO','TF0'=>'TFO','TFI'=>'TFO','TPM'=>'TPM','TP'=>'TPM','ZARI'=>'Zari']; return $map[$raw] ?? 'Yarn'; } function parse_denier_to_float($s): float { $s = trim((string)$s); if ($s === '') return 0.0; if (strpos($s, '/') !== false) { $left = trim(explode('/', $s, 2)[0]); if (preg_match('/\d+(\.\d+)?/', $left, $m)) return (float)$m[0]; } if (preg_match('/\d+(\.\d+)?/', $s, $m)) return (float)$m[0]; return 0.0; } function weight_100m_from_denier_and_tar($denier, $tar): float { // grams $d = max(0.0, (float)$denier); $t = max(0.0, (float)$tar); return ($d / 90.0) * $t; } /* ====== Load header + lines ====== */ $id = (int)($_GET['id'] ?? 0); if ($id <= 0){ http_response_code(400); exit('Missing id'); } $st = $pdo->prepare("SELECT * FROM beam_qualities WHERE id=:id AND company_id=:c"); $st->execute([':id'=>$id, ':c'=>$company_id]); $hdr = $st->fetch(PDO::FETCH_ASSOC); if(!$hdr){ http_response_code(404); exit('Not found or no permission'); } $st = $pdo->prepare("SELECT * FROM beam_quality_yarns WHERE beam_quality_id=:id ORDER BY seq_no,id"); $st->execute([':id'=>$id]); $lines = $st->fetchAll(PDO::FETCH_ASSOC); foreach($lines as &$ln){ $ln['stock_type'] = canonical_stock($ln['stock_type'] ?? 'Yarn'); } unset($ln); /* compute sums */ $hdr_tar_sum = 0.0; $weight_sum_g = 0.0; foreach($lines as $ln){ $v = isset($ln['total_tar']) ? (string)$ln['total_tar'] : ''; if ($v !== '' && is_numeric($v)) $hdr_tar_sum += (float)$v; $den = parse_denier_to_float($ln['denier'] ?? ''); $w = isset($ln['weight']) && is_numeric($ln['weight']) ? (float)$ln['weight'] : weight_100m_from_denier_and_tar($den, (float)($ln['total_tar'] ?? 0)); $weight_sum_g += $w; } /* ====== Render ====== */ ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>View Beam Quality • Mr. Manager</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> body{background:#f4f6f5} .table > :not(caption) > * > *{vertical-align:middle} </style> </head> <body> <?php $page_title = 'View Beam Quality'; $__header = __DIR__ . '/partials/header.php'; if (file_exists($__header)) { if (!isset($company) || !is_array($company)) { $company = ['id'=>$company_id, 'name'=>($u['company_name'] ?? '')]; } include $__header; } ?> <div class="container-fluid py-4"> <div class="d-flex flex-wrap gap-2 align-items-center justify-content-between mb-3"> <h5 class="mb-0">View Beam Quality</h5> <a class="btn btn-sm btn-outline-secondary" href="/erp/beam_quality_list.php">← Back to List</a> </div> <div class="card shadow-sm border-0 mb-3"> <div class="card-body"> <div class="row g-3"> <div class="col-md-6"> <label class="form-label text-muted small mb-1">Name</label> <div class="border rounded px-3 py-2 bg-light"><?= h($hdr['name']) ?></div> </div> <div class="col-md-6"> <label class="form-label text-muted small mb-1">Pattern</label> <div class="border rounded px-3 py-2 bg-light"><?= h($hdr['pattern'] ?? '') ?></div> </div> <div class="col-md-4"> <label class="form-label text-muted small mb-1">Tar (Auto Sum of Total Tar)</label> <div class="border rounded px-3 py-2 bg-light"><?= h(number_format((float)($hdr['tar'] ?? $hdr_tar_sum),3,'.','')) ?></div> </div> <div class="col-md-4"> <label class="form-label text-muted small mb-1">Warping Rate</label> <div class="border rounded px-3 py-2 bg-light"><?= h(number_format((float)($hdr['warping_rate'] ?? 0),3,'.','')) ?></div> </div> <div class="col-md-4"> <label class="form-label text-muted small mb-1">Total Weight (per 100 m)</label> <?php $wkg = $weight_sum_g/1000.0; ?> <div class="border rounded px-3 py-2 bg-light"><?= h(number_format($weight_sum_g,3,'.','').' g ('.number_format($wkg,3,'.','').' kg)') ?></div> </div> </div> </div> </div> <div class="card shadow-sm border-0"> <div class="card-header bg-white"> <h6 class="mb-0 fw-semibold">Yarns</h6> </div> <div class="card-body p-0"> <div class="table-responsive"> <table class="table table-hover mb-0"> <thead class="table-light"> <tr> <th>Seq</th><th>Stock Type</th><th>Yarn Type</th><th>Denier</th><th>Color</th> <th>Total Tar</th><th>TPM</th><th class="text-end">Weight (per 100 m)</th><th class="text-end">Wastage</th> </tr> </thead> <tbody> <?php if(empty($lines)): ?> <tr><td colspan="9" class="text-center text-muted py-4">No yarn rows.</td></tr> <?php else: ?> <?php $seq=1; foreach($lines as $ln): $den = parse_denier_to_float($ln['denier'] ?? ''); $tt = isset($ln['total_tar']) && is_numeric($ln['total_tar']) ? (float)$ln['total_tar'] : 0.0; $w = isset($ln['weight']) && is_numeric($ln['weight']) ? (float)$ln['weight'] : weight_100m_from_denier_and_tar($den, $tt); ?> <tr> <td class="text-muted"><?=h($seq++)?></td> <td><span class="badge text-bg-light border"><?=h($ln['stock_type'] ?? 'Yarn')?></span></td> <td><?=h($ln['yarn_type'] ?? '')?></td> <td class="small"><?=h($ln['denier'] ?? '')?></td> <td class="small"><?=h($ln['color'] ?? '')?></td> <td class="small"><?=h(number_format($tt,3,'.',''))?></td> <td class="small"><?=h(number_format((float)($ln['tpm'] ?? 0),3,'.',''))?></td> <td class="small text-end"><?=h(number_format($w,3,'.',''))?> g</td> <td class="small text-end"><?=h(number_format((float)($ln['wastage'] ?? 0),3,'.',''))?></td> </tr> <?php endforeach; ?> <?php endif; ?> </tbody> </table> </div> </div> <div class="card-footer bg-white"> <span class="small text-success">This is a view-only page. To modify this Beam Quality use the Edit action from the list.</span> </div> </div> </div> <?php $__footer = __DIR__ . '/partials/footer.php'; if (file_exists($__footer)) include $__footer; ?> </body> </html>