u
This commit is contained in:
@@ -62,6 +62,14 @@ import { article as articleApi, supplier as supplierApi } from '../api';
|
||||
* @property {string|null} unmatchedSupplierName Parsed supplier name without a matching entity.
|
||||
*/
|
||||
|
||||
function parseNum(value) {
|
||||
if (value == null || value === '') return null;
|
||||
const cleaned = String(value).trim().replace('%', '').trim().replace(',', '.');
|
||||
if (cleaned === '') return null;
|
||||
const n = Number(cleaned);
|
||||
return Number.isFinite(n) ? n : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes a partial line into an editor line with a stable key.
|
||||
*
|
||||
@@ -69,14 +77,22 @@ import { article as articleApi, supplier as supplierApi } from '../api';
|
||||
* @returns {DeliveryLine} Normalized line.
|
||||
*/
|
||||
export function createEmptyLineitem(line = {}) {
|
||||
const netVal = line.netprice ?? line.net ?? null;
|
||||
const taxVal = line.taxrate ?? line.tax ?? null;
|
||||
const netRaw = line.netprice ?? line.net ?? line.eknetto ?? line.netPrice ?? null;
|
||||
const taxRaw = line.taxrate ?? line.tax ?? line.mwst ?? line.taxRate ?? null;
|
||||
const amountRaw = line.amount ?? line.count ?? line.qty ?? line.quantity ?? null;
|
||||
const puRaw = line.pu ?? line.vpe ?? null;
|
||||
|
||||
const netVal = netRaw != null ? (parseNum(netRaw) ?? netRaw) : null;
|
||||
const taxVal = taxRaw != null ? (parseNum(taxRaw) ?? taxRaw) : null;
|
||||
const amountVal = amountRaw != null ? (parseNum(amountRaw) ?? amountRaw) : null;
|
||||
const puVal = puRaw != null ? (parseNum(puRaw) ?? puRaw) : null;
|
||||
|
||||
return {
|
||||
key: line.key ?? `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
||||
name: line.name ?? null,
|
||||
sku: line.sku ?? null,
|
||||
amount: line.amount ?? null,
|
||||
pu: line.pu ?? null,
|
||||
name: line.name ?? line.articleName ?? line.title ?? null,
|
||||
sku: line.sku ?? line.liefArtNr ?? line.articleNumber ?? null,
|
||||
amount: amountVal,
|
||||
pu: puVal,
|
||||
unit: line.unit ?? null,
|
||||
netprice: netVal,
|
||||
net: netVal,
|
||||
@@ -657,6 +673,82 @@ export function createDeliveryEditorAutomat(options = {}) {
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Loads a delivery manifest (e.g. from draft_delivery_manifest tool) into the editor.
|
||||
* @param {Object} manifestData
|
||||
* @returns {void}
|
||||
*/
|
||||
loadDraftManifest(manifestData) {
|
||||
if (!manifestData || typeof manifestData !== 'object') return;
|
||||
const data = manifestData.manifest ?? manifestData;
|
||||
const basedata = data.basedata ?? data.baseData ?? data;
|
||||
const rawItems =
|
||||
data.items?.items ??
|
||||
data.items ??
|
||||
data.lines ??
|
||||
data.lineitems ??
|
||||
[];
|
||||
const itemsList = Array.isArray(rawItems) ? rawItems : [];
|
||||
|
||||
const partyId =
|
||||
basedata.lieferant_id ??
|
||||
basedata.lieferantId ??
|
||||
basedata.partyId ??
|
||||
basedata.deliveryEntity ??
|
||||
basedata.supplier_id ??
|
||||
basedata.supplierId ??
|
||||
null;
|
||||
const supplierName =
|
||||
basedata.lieferantName ??
|
||||
basedata.supplierName ??
|
||||
basedata.unmatchedSupplierName ??
|
||||
null;
|
||||
const extNum =
|
||||
basedata.manifestNr ??
|
||||
basedata.manifestNumber ??
|
||||
basedata.externalNumber ??
|
||||
basedata.external_number ??
|
||||
basedata.invoiceNumber ??
|
||||
basedata.invoice_number ??
|
||||
null;
|
||||
const date = basedata.date ?? null;
|
||||
const type = basedata.manifestType ?? basedata.type ?? 'rechnung';
|
||||
|
||||
let matchedPartyId = partyId != null && partyId !== '' ? partyId : null;
|
||||
if (!matchedPartyId && supplierName && automat.state.deliveryEntities?.length > 0) {
|
||||
const normName = String(supplierName).trim().toLowerCase();
|
||||
const found = automat.state.deliveryEntities.find(
|
||||
(e) =>
|
||||
(e.name && String(e.name).trim().toLowerCase() === normName) ||
|
||||
(e.company && String(e.company).trim().toLowerCase() === normName)
|
||||
);
|
||||
if (found?.id != null) {
|
||||
matchedPartyId = found.id;
|
||||
}
|
||||
}
|
||||
|
||||
const lines = itemsList.map((item, idx) =>
|
||||
createEmptyLineitem({
|
||||
...item,
|
||||
key: item.key ?? `manifest-${Date.now()}-${idx}-${Math.random().toString(36).slice(2, 6)}`,
|
||||
})
|
||||
);
|
||||
|
||||
automat.actions.setDelivery({
|
||||
id: null,
|
||||
deliveryId: null,
|
||||
date,
|
||||
partyId: matchedPartyId,
|
||||
deliveryEntity: matchedPartyId,
|
||||
unmatchedSupplierName: matchedPartyId != null ? null : supplierName,
|
||||
externalNumber: extNum,
|
||||
external_number: extNum,
|
||||
type,
|
||||
lines,
|
||||
lineitems: lines,
|
||||
});
|
||||
},
|
||||
|
||||
/** Serializes the delivery into a VFS draft manifest format. @returns {object} */
|
||||
getManifest() {
|
||||
const state = automat.state;
|
||||
@@ -724,6 +816,7 @@ export const {
|
||||
setId,
|
||||
setDeliveryEntities,
|
||||
setDelivery,
|
||||
loadDraftManifest,
|
||||
setDate,
|
||||
setDeliveryEntity,
|
||||
setPartyId,
|
||||
|
||||
Reference in New Issue
Block a user