This commit is contained in:
seb
2026-10-08 22:44:51 +02:00
parent 22063e6944
commit ee93f71b27
11 changed files with 1047 additions and 67 deletions

View File

@@ -9,6 +9,7 @@ import customergroupAutomat from '../../automats/customergroupAutomat';
import deliveryAutomat from '../../automats/deliveryAutomat';
import quoteAutomat from '../../automats/quoteAutomat';
import orderAutomat from '../../automats/orderAutomat';
import { netFromGross } from '../../utils/price';
import {
GREEN_PANEL,
ORANGE_PANEL,
@@ -87,6 +88,7 @@ export function emptyLine() {
tax: '',
rebate: '',
net: '',
gross: '',
name: '',
pu: '',
unit: '',
@@ -98,6 +100,16 @@ export function emptyLine() {
export function lineFromApi(row) {
const netVal = row.netprice != null ? String(row.netprice) : row.net != null ? String(row.net) : '';
const taxVal = row.taxrate != null ? String(row.taxrate) : row.tax != null ? String(row.tax) : '';
const netNum = parseNum(netVal);
const taxNum = parseNum(taxVal);
let grossVal = '';
if (row.gross != null && row.gross !== '') {
grossVal = String(row.gross);
} else if (netNum != null) {
const rate = taxNum ?? 0;
const g = Math.round((netNum * (1 + rate / 100) + Number.EPSILON) * 100) / 100;
grossVal = String(g);
}
return {
id: row.id,
key: `line-${row.id ?? `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`}`,
@@ -106,6 +118,7 @@ export function lineFromApi(row) {
tax: taxVal,
rebate: row.rebate == null ? '' : String(row.rebate),
net: netVal,
gross: grossVal,
name: row.name ?? '',
pu: row.pu == null ? '' : String(row.pu),
unit: row.unit ?? '',
@@ -136,7 +149,7 @@ export function hasArticleLines(lines) {
const sku = String(l.sku ?? '').trim();
const name = String(l.name ?? '').trim();
const amount = String(l.amount ?? '').trim();
const net = String(l.net ?? l.netprice ?? '').trim();
const net = String(l.net ?? l.netprice ?? l.gross ?? '').trim();
return Boolean(sku || name || amount || net);
});
}
@@ -153,14 +166,19 @@ export function buildLines(lines, { requireAtLeastOne }) {
const rawAmount = getFirstVal(line.amount, line.count);
const amount = parseNum(rawAmount);
const rawNet = getFirstVal(line.net, line.netprice, line.netPrice, line.eknetto);
const net = parseNum(rawNet);
let net = parseNum(rawNet);
const rawTax = getFirstVal(line.tax, line.taxrate, line.taxRate, line.mwst);
const tax = parseNum(rawTax);
const rawGross = getFirstVal(line.gross);
const gross = parseNum(rawGross);
if (net == null && gross != null && tax != null) {
net = netFromGross(gross, tax);
}
const rebate = parseNum(getFirstVal(line.rebate));
const rawPu = getFirstVal(line.pu, line.vpe);
const pu = parseNum(rawPu);
const blank =
!sku && !name && amount == null && net == null && tax == null && rebate == null;
!sku && !name && amount == null && net == null && gross == null && tax == null && rebate == null;
if (blank) continue;
const missing = [];
@@ -479,11 +497,23 @@ export async function buildManifestBody(
}
export const LINE_COLUMNS = [
{ id: 'amount', label: 'Amount', width: 88, align: 'right', type: 'number' },
{ id: 'sku', label: 'SKU', width: 140, align: 'left', type: 'text' },
{ id: 'tax', label: 'Tax', width: 80, align: 'right', type: 'number' },
{ id: 'rebate', label: 'Rebate', width: 88, align: 'right', type: 'number' },
{ id: 'net', label: 'Net', width: 104, align: 'right', type: 'number' },
{ id: 'amount', label: 'Amount', width: 80, align: 'right', type: 'number' },
{ id: 'sku', label: 'SKU', width: 130, align: 'left', type: 'text' },
{ id: 'tax', label: 'Tax', width: 70, align: 'right', type: 'number' },
{ id: 'rebate', label: 'Rebate', width: 75, align: 'right', type: 'number' },
{ id: 'net', label: 'Net', width: 95, align: 'right', type: 'number' },
{ id: 'gross', label: 'Gross', width: 95, align: 'right', type: 'number' },
];
export const ORDER_LINE_COLUMNS = [
{ id: 'pos', label: 'Pos', width: 44, align: 'center' },
{ id: 'sku', label: 'SKU', width: 130, align: 'left', type: 'text' },
{ id: 'name', label: 'Name', width: 200, align: 'left', type: 'text' },
{ id: 'amount', label: 'Amount', width: 80, align: 'right', type: 'number' },
{ id: 'tax', label: 'Tax', width: 70, align: 'right', type: 'number' },
{ id: 'rebate', label: 'Rebate', width: 75, align: 'right', type: 'number' },
{ id: 'net', label: 'Net', width: 95, align: 'right', type: 'number' },
{ id: 'gross', label: 'Gross', width: 95, align: 'right', type: 'number' },
];
export const DELIVERY_LINE_COLUMNS = [
@@ -506,7 +536,8 @@ export const DELIVERY_LINE_COLUMNS = [
* @param {ManifestKind} kind Manifest kind.
* @returns {{get: Function, create: Function, update: Function, delete: Function}}
*/
export function apiFor(kind) {
export function apiFor(cfgOrKind) {
const kind = typeof cfgOrKind === 'string' ? cfgOrKind : cfgOrKind?.kind;
if (kind === 'delivery') return deliveryApi;
if (kind === 'quote') return quoteApi;
if (kind === 'order') return orderApi;
@@ -515,9 +546,10 @@ export function apiFor(kind) {
/**
* Load party options for Autocomplete / list name lookup.
* @param {ManifestKind} kind
* @param {ManifestKind|object} cfgOrKind
*/
export async function loadParties(kind) {
export async function loadParties(cfgOrKind) {
const kind = typeof cfgOrKind === 'string' ? cfgOrKind : cfgOrKind?.kind;
if (kind === 'delivery') {
if (supplierAutomat.state.status === 'ready') {
return sortSuppliers(supplierAutomat.state.suppliers);
@@ -532,16 +564,21 @@ export async function loadParties(kind) {
return filterCustomerEntities(entities, groups);
}
export function partyDisplayName(kind, party) {
export function partyDisplayName(cfgOrKind, party) {
if (!party) return '';
const kind = typeof cfgOrKind === 'string' ? cfgOrKind : cfgOrKind?.kind;
if (kind === 'delivery') return String(party.name ?? '');
return entityDisplayName(party);
}
/**
* @param {ManifestKind} kind
* @param {ManifestKind|object} cfgOrKind
*/
export function manifestConfig(kind) {
export function manifestConfig(cfgOrKind) {
if (cfgOrKind && typeof cfgOrKind === 'object' && cfgOrKind.kind && cfgOrKind.api) {
return cfgOrKind;
}
const kind = typeof cfgOrKind === 'string' ? cfgOrKind : cfgOrKind?.kind;
if (kind === 'delivery') {
return {
kind: 'delivery',
@@ -641,7 +678,7 @@ export function manifestConfig(kind) {
listAutomat: orderAutomat,
partiesByIdFromList: (parties) =>
Object.fromEntries(parties.map((row) => [row.id, row])),
columns: LINE_COLUMNS,
columns: ORDER_LINE_COLUMNS,
};
}
throw new Error(`Unknown manifest kind: ${kind}`);