This commit is contained in:
seb
2026-10-27 00:28:06 +01:00
parent f52ab1be0c
commit 75691e6afc
21 changed files with 2458 additions and 60 deletions

View File

@@ -2,7 +2,8 @@ import numberAutomat from '../automats/numberAutomat';
import quoteAutomat from '../automats/quoteAutomat';
import orderAutomat from '../automats/orderAutomat';
import deliveryAutomat from '../automats/deliveryAutomat';
import { order as orderApi, quote as quoteApi, delivery as deliveryApi } from '../api';
import retoureAutomat from '../automats/retoureAutomat';
import { order as orderApi, quote as quoteApi, delivery as deliveryApi, retoure as retoureApi } from '../api';
/** Standard cross-platform monospace font stack for numbers from a number scheme. */
export const MONO_FONT_FAMILY =
@@ -61,7 +62,11 @@ export function getNextDocumentNumber(kind) {
pad = refSeq ? Math.max(0, Number(refSeq.padding) || 0) : 6;
const prefixStyle = refSeq?.prefix ?? '';
if (kind === 'delivery') {
if (kind === 'retoure') {
prefix = 'RET-';
pad = 5;
startNum = 1;
} else if (kind === 'delivery') {
prefix = prefixStyle.startsWith('DEL-') ? 'DEL-' : (prefixStyle.startsWith('L-') ? 'L-' : 'LS-');
} else if (
prefixStyle.startsWith('ART-') ||
@@ -91,8 +96,8 @@ export function getNextDocumentNumber(kind) {
}
}
// Check existing docs from quoteAutomat / orderAutomat / deliveryAutomat to avoid collisions
const listAutomat = kind === 'quote' ? quoteAutomat : (kind === 'order' ? orderAutomat : (kind === 'delivery' ? deliveryAutomat : null));
// Check existing docs from quoteAutomat / orderAutomat / deliveryAutomat / retoureAutomat to avoid collisions
const listAutomat = kind === 'quote' ? quoteAutomat : (kind === 'order' ? orderAutomat : (kind === 'delivery' ? deliveryAutomat : (kind === 'retoure' ? retoureAutomat : null)));
const existingDocs = Array.isArray(listAutomat?.state?.items) ? listAutomat.state.items : [];
let maxFound = Math.max(startNum - 1, maxKnownNumberByKind.get(kind) ?? 0);
@@ -128,7 +133,7 @@ export function getNextDocumentNumber(kind) {
* @returns {Promise<string>}
*/
export async function ensureDocumentNumber(kind) {
const listAutomat = kind === 'quote' ? quoteAutomat : (kind === 'order' ? orderAutomat : (kind === 'delivery' ? deliveryAutomat : null));
const listAutomat = kind === 'quote' ? quoteAutomat : (kind === 'order' ? orderAutomat : (kind === 'delivery' ? deliveryAutomat : (kind === 'retoure' ? retoureAutomat : null)));
await Promise.all([
numberAutomat.actions.ensureLoaded().catch(() => {}),
listAutomat?.actions?.ensureLoaded ? listAutomat.actions.ensureLoaded().catch(() => {}) : Promise.resolve(),
@@ -145,6 +150,9 @@ export async function ensureDocumentNumber(kind) {
} else if (kind === 'delivery') {
const res = await deliveryApi.list({ offset: 0, limit: 10 });
recentDocs = Array.isArray(res?.deliveries) ? res.deliveries : [];
} else if (kind === 'retoure') {
const res = await retoureApi.list({ offset: 0, limit: 10, pageSize: 10 });
recentDocs = Array.isArray(res?.retoures) ? res.retoures : (Array.isArray(res?.items) ? res.items : []);
}
if (recentDocs.length > 0) {
@@ -152,7 +160,7 @@ export async function ensureDocumentNumber(kind) {
const seq = numbers.find((r) => r.type === kind);
let prefix = seq?.prefix;
if (prefix == null) {
prefix = kind === 'quote' ? 'ANG-' : (kind === 'order' ? 'AUF-' : 'LS-');
prefix = kind === 'quote' ? 'ANG-' : (kind === 'order' ? 'AUF-' : (kind === 'retoure' ? 'RET-' : 'LS-'));
}
let maxFound = maxKnownNumberByKind.get(kind) ?? 0;
@@ -206,7 +214,9 @@ export function getMaxDocumentNumber(kind = 'quote') {
const prefixStyle = refSeq?.prefix ?? '';
let prefix = '';
if (kind === 'delivery') {
if (kind === 'retoure') {
return `RET-${'9'.repeat(5)}`;
} else if (kind === 'delivery') {
prefix = prefixStyle.startsWith('DEL-') ? 'DEL-' : (prefixStyle.startsWith('L-') ? 'L-' : 'LS-');
} else if (
prefixStyle.startsWith('ART-') ||