Offene Chargen im Drawer vollbreit und im Lagerbestand beruecksichtigen

This commit is contained in:
gitea_admin committed 2026-09-08 10:14:11 +02:00
1 parent 668ebbc64a
commit 9382647a87
3 files changed
+37 -10

No files matched your search

+3 -3
View File
@@ -66,12 +66,12 @@ try {
}
if ($action === 'delete_open_lot') {
delete_open_stock_lot(
$productId = delete_open_stock_lot(
$pdo,
(int) ($data['lotId'] ?? 0),
(string) ($currentUser['username'] ?? $currentUser['email'] ?? 'unknown')
);
json_response(200, ['ok' => true]);
json_response(200, ['ok' => true, 'productId' => $productId, 'availableQty' => get_lager_product_available_qty($pdo, $productId)]);
}
if ($action === 'prepare_lot') {
@@ -116,7 +116,7 @@ try {
$targetQty,
$lotId > 0 && $lotNumber === ''
);
json_response(200, ['ok' => true, 'lot' => $preparedLot, 'balance' => get_stock_lot_balance($pdo, $lotId)]);
json_response(200, ['ok' => true, 'lot' => $preparedLot, 'balance' => get_stock_lot_balance($pdo, $lotId), 'availableQty' => get_lager_product_available_qty($pdo, $productId)]);
}
json_response(422, ['ok' => false, 'error' => 'Unsupported action']);
+26 -3
View File
@@ -75,7 +75,14 @@ function get_lager_product_overview(PDO $pdo): array
p.name,
p.sku,
p.uom,
COALESCE(SUM(v.qty_net), 0) AS available_qty,
COALESCE(SUM(v.qty_net), 0) + COALESCE((
SELECT SUM(open_v.qty_net)
FROM stock_lot open_sl
INNER JOIN v_stock_lot_balance open_v ON open_v.stock_lot_id = open_sl.id
WHERE open_sl.product_id = p.id
AND open_sl.status = 'open'
), 0) AS available_qty,
COALESCE(v.qty_net, 0) AS current_qty,
COALESCE(v.qty_in, 0) AS qty_in,
sl.lot_number,
sl.id AS lot_id,
@@ -113,7 +120,7 @@ function get_lager_product_overview(PDO $pdo): array
WHERE p.status = 'active'
GROUP BY p.id, p.name, p.sku, p.uom, sl.id, sl.lot_number, sl.manufacturer_party_id,
sl.manufacturer_lot_number, mp.name, sl.mfg_date, sl.expiry_date, sl.purchase_date,
sl.sellout_date, sl.sellout_forecast_status, v.qty_in
sl.sellout_date, sl.sellout_forecast_status, v.qty_net, v.qty_in
ORDER BY p.name ASC, p.id ASC"
);
@@ -124,6 +131,7 @@ function get_lager_product_overview(PDO $pdo): array
'sku' => (string) $row['sku'],
'uom' => (string) $row['uom'],
'available_qty' => (float) $row['available_qty'],
'current_qty' => (float) $row['current_qty'],
'qty_in' => (float) $row['qty_in'],
'lot_id' => $row['lot_id'] === null ? null : (int) $row['lot_id'],
'lot_number' => $row['lot_number'],
@@ -230,6 +238,19 @@ function get_lager_product_overview(PDO $pdo): array
return $products;
}
function get_lager_product_available_qty(PDO $pdo, int $productId): float
{
$stmt = $pdo->prepare(
"SELECT COALESCE(SUM(v.qty_net), 0)
FROM stock_lot sl
INNER JOIN v_stock_lot_balance v ON v.stock_lot_id = sl.id
WHERE sl.product_id = :product_id
AND sl.status IN ('current', 'open')"
);
$stmt->execute([':product_id' => $productId]);
return (float) $stmt->fetchColumn();
}
function update_stock_lot_traceability(
PDO $pdo,
int $lotId,
@@ -809,7 +830,7 @@ function get_or_create_open_lot(PDO $pdo, int $productId): int
return (int) $newLotId;
}
function delete_open_stock_lot(PDO $pdo, int $lotId, string $changedBy): void
function delete_open_stock_lot(PDO $pdo, int $lotId, string $changedBy): int
{
if ($lotId <= 0 || trim($changedBy) === '') {
throw new InvalidArgumentException('Offene Charge und Bediener sind erforderlich');
@@ -850,9 +871,11 @@ function delete_open_stock_lot(PDO $pdo, int $lotId, string $changedBy): void
throw new RuntimeException('Offene Charge konnte nicht geloescht werden');
}
$productId = (int) $lot['product_id'];
if ($startedTransaction) {
$pdo->commit();
}
return $productId;
} catch (Throwable $error) {
if ($startedTransaction && $pdo->inTransaction()) {
$pdo->rollBack();