Historische Chargen im Produkt-Drawer anzeigen

This commit is contained in:
gitea_admin committed 2026-09-06 10:51:26 +02:00
1 parent ad5d23f6be
commit d747600e1c
2 files changed
+106 -4

No files matched your search

+54 -1
View File
@@ -76,6 +76,7 @@ function get_lager_product_overview(PDO $pdo): array
p.sku,
p.uom,
COALESCE(SUM(v.qty_net), 0) AS available_qty,
COALESCE(v.qty_in, 0) AS qty_in,
sl.lot_number,
sl.id AS lot_id,
sl.manufacturer_party_id,
@@ -108,13 +109,14 @@ function get_lager_product_overview(PDO $pdo): array
ORDER BY p.name ASC, p.id ASC"
);
return array_map(
$products = array_map(
static fn (array $row): array => [
'id' => (int) $row['id'],
'name' => (string) $row['name'],
'sku' => (string) $row['sku'],
'uom' => (string) $row['uom'],
'available_qty' => (float) $row['available_qty'],
'qty_in' => (float) $row['qty_in'],
'lot_id' => $row['lot_id'] === null ? null : (int) $row['lot_id'],
'lot_number' => $row['lot_number'],
'manufacturer_party_id' => $row['manufacturer_party_id'] === null ? null : (int) $row['manufacturer_party_id'],
@@ -129,6 +131,57 @@ function get_lager_product_overview(PDO $pdo): array
],
$stmt->fetchAll()
);
$historicalStmt = $pdo->query(
"SELECT
sl.product_id,
sl.id AS lot_id,
sl.lot_number,
sl.mfg_date,
sl.expiry_date,
sl.purchase_date,
sl.manufacturer_lot_number,
mp.name AS manufacturer_name,
COALESCE(v.qty_in, 0) AS qty_in,
COALESCE(v.qty_out, 0) AS qty_out,
COALESCE(v.qty_net, 0) AS qty_net,
MIN(sm.move_date) FILTER (WHERE sm.move_type = 'in') AS first_in_at,
MAX(sm.move_date) FILTER (WHERE sm.move_type = 'out') AS last_out_at
FROM stock_lot sl
LEFT JOIN party mp ON mp.id = sl.manufacturer_party_id
LEFT JOIN v_stock_lot_balance v ON v.stock_lot_id = sl.id
LEFT JOIN stock_move sm ON sm.lot_id = sl.id
WHERE sl.status = 'closed'
GROUP BY sl.product_id, sl.id, sl.lot_number, sl.mfg_date, sl.expiry_date,
sl.purchase_date, sl.manufacturer_lot_number, mp.name,
v.qty_in, v.qty_out, v.qty_net
ORDER BY sl.product_id, sl.id DESC"
);
$historicalLotsByProduct = [];
foreach ($historicalStmt->fetchAll() as $row) {
$historicalLotsByProduct[(int) $row['product_id']][] = [
'lot_id' => (int) $row['lot_id'],
'lot_number' => $row['lot_number'],
'mfg_date' => $row['mfg_date'],
'expiry_date' => $row['expiry_date'],
'purchase_date' => $row['purchase_date'],
'manufacturer_lot_number' => $row['manufacturer_lot_number'],
'manufacturer_name' => $row['manufacturer_name'],
'qty_in' => (float) $row['qty_in'],
'qty_out' => (float) $row['qty_out'],
'qty_net' => (float) $row['qty_net'],
'first_in_at' => $row['first_in_at'],
'last_out_at' => $row['last_out_at'],
];
}
foreach ($products as &$product) {
$product['historical_lots'] = $historicalLotsByProduct[$product['id']] ?? [];
}
unset($product);
return $products;
}
function update_stock_lot_traceability(