This commit is contained in:
seb
2026-10-15 02:33:24 +02:00
parent 360660b850
commit 77f6a0815f
2 changed files with 253 additions and 80 deletions

View File

@@ -110,3 +110,55 @@ export async function ensureDocumentNumber(kind) {
]);
return getNextDocumentNumber(kind);
}
/**
* Returns the maximum document number pattern for quote or order based on company sequences.
* E.g. with prefix 'ANG-' and padding 6 -> 'ANG-999999'.
*
* @param {'quote'|'order'|string} [kind='quote']
* @returns {string}
*/
export function getMaxDocumentNumber(kind = 'quote') {
const numbers = numberAutomat.state.items ?? [];
const seq = numbers.find((r) => r.type === kind);
if (seq) {
const pad = Math.max(1, Number(seq.padding) || 6);
const prefix = seq.prefix ?? '';
return `${prefix}${'9'.repeat(pad)}`;
}
const skuSeq = numbers.find((r) => r.type === 'sku');
const deliverySeq = numbers.find((r) => r.type === 'delivery');
const entitySeq = numbers.find((r) => r.type === 'entity');
const refSeq = skuSeq || deliverySeq || entitySeq;
const pad = refSeq ? Math.max(1, Number(refSeq.padding) || 6) : 6;
const prefixStyle = refSeq?.prefix ?? '';
let prefix = '';
if (
prefixStyle.startsWith('ART-') ||
prefixStyle.startsWith('LS-') ||
prefixStyle.startsWith('KD-') ||
prefixStyle.endsWith('-')
) {
prefix = kind === 'quote' ? 'ANG-' : (kind === 'order' ? 'AUF-' : '');
} else if (
prefixStyle.startsWith('SKU-') ||
prefixStyle.startsWith('DEL-') ||
prefixStyle.startsWith('C-')
) {
prefix = kind === 'quote' ? 'Q-' : (kind === 'order' ? 'ORD-' : '');
} else if (
prefixStyle.startsWith('A-') ||
prefixStyle.startsWith('L-') ||
prefixStyle.startsWith('K-')
) {
prefix = kind === 'quote' ? 'AG-' : (kind === 'order' ? 'AU-' : '');
} else {
prefix = kind === 'quote' ? 'ANG-' : (kind === 'order' ? 'AUF-' : '');
}
return `${prefix}${'9'.repeat(pad)}`;
}