This commit is contained in:
seb
2026-09-26 07:34:37 +02:00
parent 607e6cc0ac
commit e491ecfa47
24 changed files with 2162 additions and 1716 deletions

View File

@@ -21,6 +21,10 @@ export default function create(provider) {
if (!date) {
throw new Error('Invalid delivery');
}
const createdAt = body.createdAt ? parseDate(body.createdAt) : new Date();
if (body.createdAt && !createdAt) {
throw new Error('Invalid delivery');
}
const externalNumber = body.externalNumber?.trim?.()
? body.externalNumber.trim()
: null;
@@ -46,6 +50,7 @@ export default function create(provider) {
entityId: supplierId,
externalNumber,
date,
createdAt,
});
const manifestId = created.rows[0]?.id ?? created.insertId;

View File

@@ -7,14 +7,24 @@ import { loadAttachments } from './attachments.js';
export const DELIVERY_TYPE = mssqlQueries.DELIVERY_TYPE;
export function shapeSummary(row) {
return {
const summary = {
id: row.id,
number: row.number,
type: DELIVERY_TYPE,
supplierId: row.supplierId ?? null,
externalNumber: row.externalNumber ?? null,
date: row.date,
createdAt: row.createdAt ?? row.created_at ?? null,
};
if (row.totalPositions !== undefined || row.completelyOnLedgerPositions !== undefined) {
summary.ledger = {
totalPositions: Number(row.totalPositions ?? 0),
completelyOnLedgerPositions: Number(row.completelyOnLedgerPositions ?? 0),
};
}
return summary;
}
export async function loadDelivery(provider, tx, companyId, id) {

View File

@@ -21,6 +21,7 @@ export default function update(provider) {
const hasNumber = Object.prototype.hasOwnProperty.call(patch, 'number');
const hasDate = Object.prototype.hasOwnProperty.call(patch, 'date');
const hasCreatedAt = Object.prototype.hasOwnProperty.call(patch, 'createdAt');
const hasSupplierId = Object.prototype.hasOwnProperty.call(
patch,
'supplierId',
@@ -29,7 +30,7 @@ export default function update(provider) {
const hasLines = Object.prototype.hasOwnProperty.call(patch, 'lines');
const hasFiles = Object.prototype.hasOwnProperty.call(patch, 'files');
if (!hasNumber && !hasDate && !hasSupplierId && !hasExternalNumber && !hasLines && !hasFiles) {
if (!hasNumber && !hasDate && !hasCreatedAt && !hasSupplierId && !hasExternalNumber && !hasLines && !hasFiles) {
throw new Error('Invalid delivery');
}
@@ -70,6 +71,14 @@ export default function update(provider) {
}
}
let createdAt = summary.createdAt ? parseDate(summary.createdAt) : null;
if (hasCreatedAt) {
createdAt = parseDate(patch.createdAt);
if (!createdAt) {
throw new Error('Invalid delivery');
}
}
let supplierId = summary.supplierId;
if (hasSupplierId) {
supplierId = await assertSupplier(
@@ -95,6 +104,7 @@ export default function update(provider) {
entityId: supplierId,
externalNumber,
date,
createdAt,
});
if (hasLines) {