Imballaggi - Anagrafica & Stock
Elenco
getConnection(); $active = $_GET['active'] ?? '1'; if (!in_array($active, ['all', '0', '1'], true)) $active = '1'; $cat = $_GET['cat'] ?? 'all'; $allowedCats = ['all', 'PACKAGING_TYPE', 'BOX', 'PALLET', 'OTHER']; if (!in_array($cat, $allowedCats, true)) $cat = 'all'; $where = []; $params = []; if ($active !== 'all') { $where[] = "pi.is_active = ?"; $params[] = (int)$active; } if ($cat !== 'all') { $where[] = "pi.category = ?"; $params[] = $cat; } $whereSql = $where ? ("WHERE " . implode(" AND ", $where)) : ""; // Sum qty in subquery to avoid duplicates $sql = " SELECT pi.id, pi.category, pi.item_name, pi.item_code, pi.is_active, IFNULL(q.qty_totale, 0) AS qty_totale FROM packaging_items pi LEFT JOIN ( SELECT idpackaging_item, SUM(qty) AS qty_totale FROM packaging_stock_lots GROUP BY idpackaging_item ) q ON q.idpackaging_item = pi.id $whereSql ORDER BY pi.category ASC, pi.item_name ASC, pi.id DESC "; $stmt = $pdo->prepare($sql); $stmt->execute($params); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); function catLabel($c) { return match ($c) { 'PACKAGING_TYPE' => 'Tipo Confezione', 'BOX' => 'Scatola', 'PALLET' => 'Pallet', default => $c }; } ?>
"; } else { foreach ($rows as $r) { $isActive = ((int)$r['is_active'] === 1); $badge = $isActive ? "Attivo" : "Inattivo"; $toggleText = $isActive ? "Disattiva" : "Attiva"; $toggleClass = $isActive ? "btn-outline-warning" : "btn-outline-success"; $qtyTot = number_format((float)$r['qty_totale'], 3, ',', '.'); $trClass = $isActive ? "" : " class='inactive-item'"; echo " "; } } ?>
ID Categoria Nome Codice Q.tà Tot Stato Azioni
- Nessun elemento - - - - -
{$r['id']} " . htmlspecialchars(catLabel($r['category'])) . " " . htmlspecialchars($r['item_name']) . " " . htmlspecialchars($r['item_code']) . " {$qtyTot} {$badge}
Q.tà Tot = somma di tutti i lotti/fornitori collegati all’imballo.