Fix virtual shortage lot activation and warning

This commit is contained in:
gitea_admin committed 2026-09-08 16:55:37 +02:00
1 parent 17efaee53f
commit 8846a57b43
3 files changed
+129 -11

No files matched your search

+22 -2
View File
@@ -126,7 +126,12 @@ try {
$lotNumber === ''
);
sync_open_lot_activation_selection($pdo, $productId);
$preparedLot['next_active'] = is_open_lot_selected_for_activation($pdo, $lotId);
if (promote_open_lot_when_virtual_shortage_is_current($pdo, $productId, $lotId)) {
$preparedLot['status'] = 'current';
$preparedLot['next_active'] = false;
} else {
$preparedLot['next_active'] = is_open_lot_selected_for_activation($pdo, $lotId);
}
refresh_lager_stock_lot_forecast_for_product($pdo, $productId);
$forecast = get_lager_product_forecast($pdo, $productId);
json_response(200, ['ok' => true, 'productId' => $productId, 'lot' => $preparedLot, 'balance' => get_stock_lot_balance($pdo, $lotId), 'availableQty' => get_lager_product_available_qty($pdo, $productId), 'forecast' => $forecast]);
@@ -136,7 +141,8 @@ try {
$productId = (int) ($data['productId'] ?? 0);
$lotId = (int) ($data['lotId'] ?? 0);
select_open_lot_for_activation($pdo, $productId, $lotId);
json_response(200, ['ok' => true, 'productId' => $productId, 'selectedLotId' => $lotId]);
refresh_lager_stock_lot_forecast_for_product($pdo, $productId);
json_response(200, ['ok' => true, 'productId' => $productId, 'selectedLotId' => $lotId, 'forecast' => get_lager_product_forecast($pdo, $productId)]);
}
json_response(422, ['ok' => false, 'error' => 'Unsupported action']);
@@ -145,5 +151,19 @@ try {
} catch (InvalidArgumentException $error) {
json_response(422, ['ok' => false, 'error' => $error->getMessage()]);
} catch (Throwable $error) {
if (isset($pdo) && $pdo->inTransaction()) {
$pdo->rollBack();
}
try {
system_write_audit_log($pdo, 'lager_api', 'lager-charge.php', 'request_failed', $currentUser['username'] ?? $currentUser['email'] ?? 'unknown', [], [], [
'action' => $action ?? '',
'product_id' => $data['productId'] ?? null,
'lot_id' => $data['lotId'] ?? null,
'exception_class' => get_class($error),
'exception_message' => $error->getMessage(),
]);
} catch (Throwable) {
error_log('lager-charge API failure audit logging failed');
}
json_response(500, ['ok' => false, 'error' => 'Interner Serverfehler']);
}