Charge-Mengen beim Bearbeiten ersetzen
This commit is contained in:
1 parent
3a56a24b00
commit
584d941c03
3 files changed
+33
-7
No files matched your search
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user