Charge-Mengen beim Bearbeiten ersetzen

This commit is contained in:
gitea_admin committed 2026-09-08 09:16:18 +02:00
1 parent 3a56a24b00
commit 584d941c03
3 files changed
+33 -7

No files matched your search

+3 -1
View File
@@ -90,6 +90,7 @@ try {
$manufacturerPartyId = $data['manufacturerPartyId'] ?? null;
$manufacturerPartyId = $manufacturerPartyId === null || $manufacturerPartyId === '' ? null : (int) $manufacturerPartyId;
$receiptQty = isset($data['receiptQty']) && $data['receiptQty'] !== '' ? (float) $data['receiptQty'] : 0.0;
$targetQty = isset($data['targetQty']) && $data['targetQty'] !== '' ? (float) $data['targetQty'] : null;
$preparedLot = update_stock_lot_traceability(
$pdo,
$lotId,
@@ -102,7 +103,8 @@ try {
$receiptQty,
0.0,
0.0,
$lotNumber
$lotNumber,
$targetQty
);
json_response(200, ['ok' => true, 'lot' => $preparedLot, 'balance' => get_stock_lot_balance($pdo, $lotId)]);
}
+27 -3
View File
@@ -216,7 +216,7 @@ function get_lager_product_overview(PDO $pdo): array
'mfg_date' => $openLot['mfg_date'],
'expiry_date' => $openLot['expiry_date'],
'purchase_date' => $openLot['purchase_date'],
'qty_in' => (float) $openLot['qty_in'],
'qty_in' => (float) $openLot['qty_net'],
'qty_net' => (float) $openLot['qty_net'],
];
}
@@ -242,7 +242,8 @@ function update_stock_lot_traceability(
float $receiptQty = 0.0,
float $adjustmentQty = 0.0,
float $outQty = 0.0,
?string $lotNumber = null
?string $lotNumber = null,
?float $targetQty = null
): array {
if ($lotId <= 0) {
throw new InvalidArgumentException('Chargen-ID fehlt');
@@ -260,6 +261,9 @@ function update_stock_lot_traceability(
if (!is_finite($receiptQty) || !is_finite($adjustmentQty) || !is_finite($outQty)) {
throw new InvalidArgumentException('Ungueltige Bewegungsmenge');
}
if ($targetQty !== null && (!is_finite($targetQty) || $targetQty < 0)) {
throw new InvalidArgumentException('Ungueltige Chargenmenge');
}
if ($receiptQty < 0 || $outQty < 0) {
throw new InvalidArgumentException('Zugang und Abgang duerfen nicht negativ sein');
}
@@ -307,6 +311,9 @@ function update_stock_lot_traceability(
if ((string) $before['status'] === 'virtual_shortage') {
throw new InvalidArgumentException('Virtuelle Fehlbestandschargen koennen nicht gepflegt werden');
}
if ($targetQty !== null && (string) $before['status'] !== 'open') {
throw new InvalidArgumentException('Nur offene Chargen koennen mit einer Zielmenge bearbeitet werden');
}
if ($lotNumber !== null && (string) $before['status'] !== 'open') {
throw new InvalidArgumentException('Nur offene Chargen koennen neu angelegt werden');
}
@@ -331,7 +338,24 @@ function update_stock_lot_traceability(
if ($manufacturerPartyId !== null && $manufacturerLotNumber === null && (string) $before['status'] !== 'open') {
throw new InvalidArgumentException('Hersteller-Chargennummer fehlt');
}
if (($adjustmentQty !== 0.0 || $outQty > 0) && (string) $before['status'] !== 'current') {
if ($targetQty !== null) {
$balanceStmt = $pdo->prepare(
"SELECT COALESCE(SUM(CASE
WHEN move_type = 'in' THEN qty
WHEN move_type = 'out' THEN -qty
ELSE 0
END), 0)
FROM stock_move
WHERE lot_id = :lot_id"
);
$balanceStmt->execute([':lot_id' => $lotId]);
$quantityDelta = $targetQty - (float) $balanceStmt->fetchColumn();
$receiptQty = $quantityDelta > 0 ? $quantityDelta : 0.0;
$outQty = $quantityDelta < 0 ? abs($quantityDelta) : 0.0;
$adjustmentQty = 0.0;
}
if (($adjustmentQty !== 0.0 || $outQty > 0) && (string) $before['status'] !== 'current' && $targetQty === null) {
throw new InvalidArgumentException('Korrekturen und Abgaenge koennen nur auf der aktiven Charge gebucht werden');
}