u
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -142,11 +142,45 @@ export default function add(provider) {
|
||||
companyId,
|
||||
});
|
||||
|
||||
const upperType = String(transactionType).toUpperCase();
|
||||
const isDelivery =
|
||||
upperType === 'DELIVERY' ||
|
||||
upperType === 'GOODS_RECEIPT' ||
|
||||
(manifestArticle.manifestType === 'delivery' &&
|
||||
!upperType.includes('ADJUST') &&
|
||||
!upperType.includes('LOSS') &&
|
||||
!upperType.includes('WRITE_OFF'));
|
||||
|
||||
let historyText = transactionText;
|
||||
if (isDelivery) {
|
||||
const details = [];
|
||||
if (manifestArticle.supplierName) {
|
||||
details.push(`Lieferant: "${manifestArticle.supplierName}"`);
|
||||
}
|
||||
if (manifestArticle.net != null && Number.isFinite(Number(manifestArticle.net))) {
|
||||
const net = Number(manifestArticle.net);
|
||||
const rebate = Number(manifestArticle.rebate ?? 0);
|
||||
const taxrate = Number(manifestArticle.taxrate ?? 0);
|
||||
const netAfterRebate = net * (1 - rebate / 100);
|
||||
const brutto = netAfterRebate * (1 + taxrate / 100);
|
||||
const ekBrutto = (Math.round(brutto * 100) / 100).toFixed(2);
|
||||
details.push(`EK brutto: ${ekBrutto}`);
|
||||
}
|
||||
if (amount != null && Number.isFinite(Number(amount))) {
|
||||
details.push(`Menge: ${amount}`);
|
||||
}
|
||||
const suffix = details.length ? ` (${details.join(', ')})` : '';
|
||||
const base =
|
||||
transactionText?.trim() ||
|
||||
(manifestArticle.manifestNumber ? `Lieferung ${manifestArticle.manifestNumber}` : 'Lieferung');
|
||||
historyText = `${base}${suffix}`;
|
||||
}
|
||||
|
||||
for (const match of articleMatches.rows) {
|
||||
await runner.query(queries.INSERT_ARTICLE_HISTORY, {
|
||||
articleId: match.articleId,
|
||||
companyuserId,
|
||||
text: transactionText,
|
||||
text: historyText,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ export function shapeSummary(type, row) {
|
||||
entityId: row.entityId ?? null,
|
||||
externalNumber: row.externalNumber ?? null,
|
||||
date: row.date,
|
||||
createdAt: row.createdAt ?? row.created_at ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,10 @@ export default function create(provider) {
|
||||
if (!number || !date) {
|
||||
throw new Error('Invalid order');
|
||||
}
|
||||
const createdAt = body.createdAt ? parseDate(body.createdAt) : new Date();
|
||||
if (body.createdAt && !createdAt) {
|
||||
throw new Error('Invalid order');
|
||||
}
|
||||
const externalNumber = body.externalNumber?.trim?.()
|
||||
? body.externalNumber.trim()
|
||||
: null;
|
||||
@@ -66,6 +70,7 @@ export default function create(provider) {
|
||||
entityId,
|
||||
externalNumber,
|
||||
date,
|
||||
createdAt,
|
||||
});
|
||||
|
||||
const manifestId = created.rows[0]?.id ?? created.insertId;
|
||||
|
||||
@@ -52,11 +52,12 @@ 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 hasEntityId = Object.prototype.hasOwnProperty.call(patch, 'entityId');
|
||||
const hasExternalNumber = Object.prototype.hasOwnProperty.call(patch, 'externalNumber');
|
||||
const hasLines = Object.prototype.hasOwnProperty.call(patch, 'lines');
|
||||
|
||||
if (!hasNumber && !hasDate && !hasEntityId && !hasExternalNumber && !hasLines) {
|
||||
if (!hasNumber && !hasDate && !hasCreatedAt && !hasEntityId && !hasExternalNumber && !hasLines) {
|
||||
throw new Error('Invalid order');
|
||||
}
|
||||
|
||||
@@ -97,6 +98,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 order');
|
||||
}
|
||||
}
|
||||
|
||||
let entityId = summary.entityId;
|
||||
if (hasEntityId) {
|
||||
entityId = await assertCustomerEntity(
|
||||
@@ -121,6 +130,7 @@ export default function update(provider) {
|
||||
entityId,
|
||||
externalNumber,
|
||||
date,
|
||||
createdAt,
|
||||
});
|
||||
|
||||
if (hasLines) {
|
||||
|
||||
@@ -44,6 +44,10 @@ export default function create(provider) {
|
||||
if (!number || !date) {
|
||||
throw new Error('Invalid quote');
|
||||
}
|
||||
const createdAt = body.createdAt ? parseDate(body.createdAt) : new Date();
|
||||
if (body.createdAt && !createdAt) {
|
||||
throw new Error('Invalid quote');
|
||||
}
|
||||
const externalNumber = body.externalNumber?.trim?.()
|
||||
? body.externalNumber.trim()
|
||||
: null;
|
||||
@@ -66,6 +70,7 @@ export default function create(provider) {
|
||||
entityId,
|
||||
externalNumber,
|
||||
date,
|
||||
createdAt,
|
||||
});
|
||||
|
||||
const manifestId = created.rows[0]?.id ?? created.insertId;
|
||||
|
||||
@@ -52,11 +52,12 @@ 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 hasEntityId = Object.prototype.hasOwnProperty.call(patch, 'entityId');
|
||||
const hasExternalNumber = Object.prototype.hasOwnProperty.call(patch, 'externalNumber');
|
||||
const hasLines = Object.prototype.hasOwnProperty.call(patch, 'lines');
|
||||
|
||||
if (!hasNumber && !hasDate && !hasEntityId && !hasExternalNumber && !hasLines) {
|
||||
if (!hasNumber && !hasDate && !hasCreatedAt && !hasEntityId && !hasExternalNumber && !hasLines) {
|
||||
throw new Error('Invalid quote');
|
||||
}
|
||||
|
||||
@@ -97,6 +98,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 quote');
|
||||
}
|
||||
}
|
||||
|
||||
let entityId = summary.entityId;
|
||||
if (hasEntityId) {
|
||||
entityId = await assertCustomerEntity(
|
||||
@@ -121,6 +130,7 @@ export default function update(provider) {
|
||||
entityId,
|
||||
externalNumber,
|
||||
date,
|
||||
createdAt,
|
||||
});
|
||||
|
||||
if (hasLines) {
|
||||
|
||||
Reference in New Issue
Block a user