This commit is contained in:
seb
2026-10-16 23:53:09 +02:00
parent 82db75ac0f
commit b3a81efe46
8 changed files with 2099 additions and 443 deletions

View File

@@ -124,8 +124,8 @@ export async function fetchDeliveryLedgerSummary(deliveryId, { deliveryApi = def
});
const bookedAmount = deliveryEntries.reduce((sum, e) => sum + Number(e.amount || 0), 0);
const targetAmount = Number(line.amount || 0);
const remainingAmount = trackStock ? Math.max(0, targetAmount - bookedAmount) : 0;
const isBooked = trackStock ? (targetAmount > 0 ? bookedAmount >= targetAmount : bookedAmount > 0) : true;
const remainingAmount = Math.max(0, targetAmount - bookedAmount);
const isBooked = targetAmount > 0 ? bookedAmount >= targetAmount : bookedAmount > 0;
return {
...line,
@@ -134,21 +134,20 @@ export async function fetchDeliveryLedgerSummary(deliveryId, { deliveryApi = def
remainingAmount,
isBooked,
trackStock,
isBookable: trackStock,
isBookable: true,
ledgerEntries: deliveryEntries,
};
})
);
const stockLines = linesWithLedger.filter((l) => l.trackStock);
const totalPositions = stockLines.length;
const bookedPositions = stockLines.filter((l) => l.isBooked).length;
const totalQuantity = stockLines.reduce((sum, l) => sum + l.targetAmount, 0);
const bookedQuantity = stockLines.reduce((sum, l) => sum + l.bookedAmount, 0);
const hasTrackStock = stockLines.length > 0;
const totalPositions = linesWithLedger.length;
const bookedPositions = linesWithLedger.filter((l) => l.isBooked).length;
const totalQuantity = linesWithLedger.reduce((sum, l) => sum + l.targetAmount, 0);
const bookedQuantity = linesWithLedger.reduce((sum, l) => sum + l.bookedAmount, 0);
const hasTrackStock = linesWithLedger.some((l) => l.trackStock);
let status;
if (!hasTrackStock) {
if (totalPositions === 0) {
status = 'empty';
} else if (bookedPositions === totalPositions && bookedQuantity >= totalQuantity) {
status = 'booked';
@@ -176,8 +175,8 @@ export async function fetchDeliveryLedgerSummary(deliveryId, { deliveryApi = def
*
* @param {Object} params
* @param {Object} params.delivery - The delivery object (used for transaction memo and fallback)
* @param {Array<{ manifestarticleId?: number, id?: number, amount: number, sku?: string }>} params.linesToBook
* @param {number|string} params.warehouseId - Mandatory warehouse ID
* @param {Array<{ manifestarticleId?: number, id?: number, amount: number, sku?: string, trackStock?: boolean }>} params.linesToBook
* @param {number|string} [params.warehouseId] - Warehouse ID (mandatory only when at least one line tracks stock)
* @param {Object} [params.stockApi]
* @param {string} [params.transactionText]
* @returns {Promise<Array<Object>>}
@@ -189,15 +188,17 @@ export async function bookDeliveryLines({
stockApi = defaultStockApi,
transactionText,
}) {
const numericWarehouseId = Number(warehouseId);
if (!numericWarehouseId || numericWarehouseId <= 0) {
throw new Error('Bitte wählen Sie ein Lager aus.');
}
if (!Array.isArray(linesToBook) || linesToBook.length === 0) {
return [];
}
const numericWarehouseId = Number(warehouseId) || null;
const hasTrackedLines = linesToBook.some((l) => l.trackStock);
if (hasTrackedLines && (!numericWarehouseId || numericWarehouseId <= 0)) {
throw new Error('Bitte wählen Sie ein Lager aus.');
}
const memo = String(
transactionText != null && transactionText !== ''
? transactionText

View File

@@ -136,7 +136,9 @@ export function getMaxDocumentNumber(kind = 'quote') {
const prefixStyle = refSeq?.prefix ?? '';
let prefix = '';
if (
if (kind === 'delivery') {
prefix = prefixStyle.startsWith('DEL-') ? 'DEL-' : (prefixStyle.startsWith('L-') ? 'L-' : 'LS-');
} else if (
prefixStyle.startsWith('ART-') ||
prefixStyle.startsWith('LS-') ||
prefixStyle.startsWith('KD-') ||