Offene Chargen mit Zielmenge korrigieren

This commit is contained in:
gitea_admin committed 2026-09-08 09:18:31 +02:00
1 parent 584d941c03
commit 28fa29f294
3 files changed
+27 -2

No files matched your search

+1
View File
@@ -17,6 +17,7 @@
13. `db/migrations/0017_manufacturer_lot_traceability.sql` 13. `db/migrations/0017_manufacturer_lot_traceability.sql`
14. `db/migrations/0018_shopify_delta_sync_state.sql` 14. `db/migrations/0018_shopify_delta_sync_state.sql`
15. `db/migrations/0019_allow_multiple_open_stock_lots.sql` 15. `db/migrations/0019_allow_multiple_open_stock_lots.sql`
16. `db/migrations/0020_include_stock_adjustments_in_balance.sql`
## Beispielausfuehrung ## Beispielausfuehrung
@@ -0,0 +1,22 @@
BEGIN;
CREATE OR REPLACE VIEW v_stock_lot_balance AS
SELECT
sl.id AS stock_lot_id,
sl.product_id,
COALESCE(SUM(CASE WHEN sm.move_type = 'in' THEN sm.qty ELSE 0 END), 0) AS qty_in,
COALESCE(SUM(CASE WHEN sm.move_type = 'out' THEN sm.qty ELSE 0 END), 0) AS qty_out,
COALESCE(SUM(
CASE
WHEN sm.move_type = 'in' THEN sm.qty
WHEN sm.move_type = 'out' THEN -sm.qty
WHEN sm.move_type = 'adjustment' AND sm.to_location_id IS NOT NULL AND sm.from_location_id IS NULL THEN sm.qty
WHEN sm.move_type = 'adjustment' AND sm.from_location_id IS NOT NULL AND sm.to_location_id IS NULL THEN -sm.qty
ELSE 0
END
), 0) AS qty_net
FROM stock_lot sl
LEFT JOIN stock_move sm ON sm.lot_id = sl.id
GROUP BY sl.id, sl.product_id;
COMMIT;
+4 -2
View File
@@ -343,6 +343,8 @@ function update_stock_lot_traceability(
"SELECT COALESCE(SUM(CASE "SELECT COALESCE(SUM(CASE
WHEN move_type = 'in' THEN qty WHEN move_type = 'in' THEN qty
WHEN move_type = 'out' THEN -qty WHEN move_type = 'out' THEN -qty
WHEN move_type = 'adjustment' AND to_location_id IS NOT NULL AND from_location_id IS NULL THEN qty
WHEN move_type = 'adjustment' AND from_location_id IS NOT NULL AND to_location_id IS NULL THEN -qty
ELSE 0 ELSE 0
END), 0) END), 0)
FROM stock_move FROM stock_move
@@ -351,8 +353,8 @@ function update_stock_lot_traceability(
$balanceStmt->execute([':lot_id' => $lotId]); $balanceStmt->execute([':lot_id' => $lotId]);
$quantityDelta = $targetQty - (float) $balanceStmt->fetchColumn(); $quantityDelta = $targetQty - (float) $balanceStmt->fetchColumn();
$receiptQty = $quantityDelta > 0 ? $quantityDelta : 0.0; $receiptQty = $quantityDelta > 0 ? $quantityDelta : 0.0;
$outQty = $quantityDelta < 0 ? abs($quantityDelta) : 0.0; $outQty = 0.0;
$adjustmentQty = 0.0; $adjustmentQty = $quantityDelta < 0 ? $quantityDelta : 0.0;
} }
if (($adjustmentQty !== 0.0 || $outQty > 0) && (string) $before['status'] !== 'current' && $targetQty === null) { if (($adjustmentQty !== 0.0 || $outQty > 0) && (string) $before['status'] !== 'current' && $targetQty === null) {