Magazzino - Imballaggi
Cerca per codice, nome, fornitore o lotto
getConnection(); $cat = $_GET['cat'] ?? 'all'; $allowedCats = ['all', 'PACKAGING_TYPE', 'BOX', 'PALLET', 'OTHER']; if (!in_array($cat, $allowedCats, true)) $cat = 'all'; $active = $_GET['active'] ?? '1'; if (!in_array($active, ['all', '0', '1'], true)) $active = '1'; $where = []; $params = []; if ($cat !== 'all') { $where[] = "pi.category = ?"; $params[] = $cat; } if ($active !== 'all') { $where[] = "pi.is_active = ?"; $params[] = (int)$active; } $whereSql = $where ? ("WHERE " . implode(" AND ", $where)) : ""; $sql = " SELECT psl.id AS stock_id, pi.id AS item_id, pi.category, pi.item_name, pi.item_code, pi.is_active, s.supplier_name, psl.lot_code, psl.expiry_date, psl.qty FROM packaging_stock_lots psl INNER JOIN packaging_items pi ON pi.id = psl.idpackaging_item INNER JOIN suppliers s ON s.idsupplier = psl.idsupplier $whereSql ORDER BY pi.category ASC, pi.item_name ASC, s.supplier_name ASC, psl.lot_code ASC, psl.id DESC "; $stmt = $pdo->prepare($sql); $stmt->execute($params); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); $today = date('Y-m-d'); function catLabel($c) { return match ($c) { 'PACKAGING_TYPE' => 'Tipo Confezione', 'BOX' => 'Scatola', 'PALLET' => 'Pallet', default => $c }; } ?>
"; } else { foreach ($rows as $r) { $expiry = $r['expiry_date'] ?? ''; $isExpired = ($expiry !== '' && $expiry < $today); $isActiveItem = ((int)$r['is_active'] === 1); $trClass = []; if ($isExpired) $trClass[] = 'expired'; if (!$isActiveItem) $trClass[] = 'inactive-item'; $trClassStr = $trClass ? " class='" . implode(' ', $trClass) . "'" : ""; $qtyVal = number_format((float)$r['qty'], 3, '.', ''); $expiryShow = $expiry ? htmlspecialchars($expiry) : '-'; $lotShow = htmlspecialchars($r['lot_code'] ?? ''); echo " "; } } ?>
ID Categoria Nome Codice Fornitore Lotto Scadenza Q.tà Salva
- Nessuna riga presente - - - - - - -
{$r['stock_id']} " . htmlspecialchars(catLabel($r['category'])) . " " . htmlspecialchars($r['item_name']) . " " . htmlspecialchars($r['item_code']) . " " . htmlspecialchars($r['supplier_name']) . " {$lotShow} {$expiryShow}
* Riga rossa = scaduta. * Riga opaca = item disattivo (ma stock ancora presente).