« Back to History
beam_quality_list.php
|
20260721_154032.php
Initial Bulk Import
Copy Code
<?php /* ========================================================= File: /erp/beam_quality_list.php Purpose: List Beam Qualities (Add New + Edit + View) Scope: Module-only (no global/base changes) Auth: uses modules/auth/page_acl.php ========================================================= */ error_reporting(E_ALL); ini_set('display_errors',1); /* 1) Auth + ACL (brings $pdo) */ require __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('beam_quality_list'); // ACL slug $u = $ctx['user']; $company_id = (int)$ctx['company_id']; $pdo = $ctx['pdo'] ?? $pdo; $__header = __DIR__ . '/partials/header.php'; if (file_exists($__header)) { include_once $__header; } /* 2) Small helpers */ function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } /* 3) Filters, search, pagination */ $q = trim($_GET['q'] ?? ''); $page = max(1, (int)($_GET['page'] ?? 1)); $pp = min(50, max(10, (int)($_GET['pp'] ?? 20))); // per-page $offset = ($page-1)*$pp; $where = " WHERE company_id = :c "; $params = [':c'=>$company_id]; if ($q !== '') { $where .= " AND (name LIKE :q OR pattern LIKE :q) "; $params[':q'] = "%$q%"; } /* 4) Count total */ $sqlCnt = "SELECT COUNT(*) AS cnt FROM beam_qualities $where"; $stCnt = $pdo->prepare($sqlCnt); $stCnt->execute($params); $total = (int)$stCnt->fetchColumn(); $pages = max(1, (int)ceil($total / $pp)); /* 5) Fetch page rows + yarn stats */ $sql = " SELECT bq.id, bq.name, bq.pattern, bq.created_at, COALESCE(cnt.total_rows,0) AS yarn_rows, COALESCE(cnt.stock_types,'') AS stock_types FROM beam_qualities bq LEFT JOIN ( SELECT beam_quality_id, COUNT(*) AS total_rows, GROUP_CONCAT(DISTINCT stock_type ORDER BY stock_type SEPARATOR ', ') AS stock_types FROM beam_quality_yarns GROUP BY beam_quality_id ) cnt ON cnt.beam_quality_id = bq.id $where ORDER BY bq.id DESC LIMIT $pp OFFSET $offset "; $st = $pdo->prepare($sql); $st->execute($params); $rows = $st->fetchAll(PDO::FETCH_ASSOC); $saved = isset($_GET['saved']) && $_GET['saved']=='1'; $updated = isset($_GET['updated']) && $_GET['updated']=='1'; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Beam Quality List • Mister Manager</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> :root{ --primary:#34A853; --bg:#F5FFF7; --text:#202124; --muted:#5F6368; --card:#FFFFFF; --shadow:0 6px 18px rgba(0,0,0,.06); --radius:16px; --ok:#1e8e3e; --danger:#b00020; } body{margin:0; font-family:system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,Arial; background:var(--bg); color:var(--text);} .wrap{max-width:1150px; margin:20px auto; padding:16px;} .card{background:var(--card); border-radius:var(--radius); box-shadow:var(--shadow); padding:18px;} h1{margin:0 0 12px;} .toolbar{display:flex; gap:10px; align-items:center; justify-content:space-between; margin-bottom:12px} .pill{display:inline-block; padding:8px 12px; border-radius:999px; background:#e9f6ee; color:var(--ok); font-size:12px;} input, select{padding:10px; border:1px solid #e5e7eb; border-radius:10px; outline:none} input:focus{border-color:#c7ead1; box-shadow:0 0 0 3px rgba(52,168,83,.12)} table{width:100%; border-collapse:collapse; background:#fff; border-radius:12px; overflow:hidden} th, td{padding:12px; border-bottom:1px solid #eef2f7; text-align:left} th{font-size:12px; color:var(--muted); text-transform:uppercase; letter-spacing:.04em} .btn{padding:10px 14px; border-radius:12px; border:0; cursor:pointer; text-decoration:none; display:inline-block} .btn-primary{background:var(--primary); color:#fff} .btn-ghost{background:transparent; border:1px dashed #cdd9e3} .btn-small{padding:8px 10px; font-size:13px} .success{background:#e8f5e9; color:#1e8e3e; padding:10px 12px; border-radius:10px; margin-bottom:12px} .pagination{display:flex; gap:8px; align-items:center; justify-content:flex-end; margin-top:12px} .page-link{padding:6px 10px; border:1px solid #e5e7eb; border-radius:8px; text-decoration:none; color:var(--text)} .page-link.active{background:var(--primary); color:#fff; border-color:var(--primary)} </style> </head> <body> <div class="wrap"> <div class="card"> <h1>Beam Quality List</h1> <div class="toolbar"> <div class="pill">Company ID: <?= (int)$company_id ?></div> <div style="display:flex; gap:8px; align-items:center;"> <form method="get" style="display:flex; gap:8px; align-items:center;"> <input type="text" name="q" placeholder="Search name or pattern..." value="<?= h($q) ?>"> <select name="pp"> <?php foreach([10,20,30,50] as $opt){ ?> <option value="<?= $opt ?>" <?= $pp==$opt ? 'selected':'' ?>><?= $opt ?>/page</option> <?php } ?> </select> <button class="btn btn-ghost" type="submit">Filter</button> </form> <a class="btn btn-primary" href="/erp/beam_quality_add.php">+ Add New</a> </div> </div> <?php if($saved): ?> <div class="success">Beam Quality created successfully.</div> <?php endif; ?> <?php if($updated): ?> <div class="success">Beam Quality updated successfully.</div> <?php endif; ?> <table> <thead> <tr> <th>ID</th> <th>Name / Pattern</th> <th>Yarn Rows</th> <th>Stock Types</th> <th>Created</th> <th>Actions</th> </tr> </thead> <tbody> <?php if (!$rows): ?> <tr><td colspan="6" style="text-align:center; padding:24px;">No records.</td></tr> <?php else: foreach($rows as $r): ?> <tr> <td><?= (int)$r['id'] ?></td> <td> <div style="font-weight:600"><?= h($r['name']) ?></div> <div style="color:#5F6368; font-size:12px"><?= h($r['pattern'] ?? '') ?></div> </td> <td><?= (int)$r['yarn_rows'] ?></td> <td><?= h($r['stock_types']) ?></td> <td><?= h($r['created_at']) ?></td> <td> <a class="btn btn-small btn-ghost" href="/erp/beam_quality_view.php?id=<?= (int)$r['id'] ?>">View</a> <a class="btn btn-small btn-ghost" href="/erp/beam_quality_edit.php?id=<?= (int)$r['id'] ?>">Edit</a> </td> </tr> <?php endforeach; endif; ?> </tbody> </table> <?php if($pages>1): ?> <div class="pagination"> <?php for($p=1;$p<=$pages;$p++): $qs = $_GET; $qs['page']=$p; $url = '?'.http_build_query($qs); ?> <a class="page-link <?= $p==$page?'active':'' ?>" href="<?= h($url) ?>"><?= $p ?></a> <?php endfor; ?> </div> <?php endif; ?> </div> </div> </body> </html>