This commit is contained in:
seb
2026-10-18 20:34:17 +02:00
parent ac9034685f
commit c211040cd3
3 changed files with 64 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
import numberAutomat from '../automats/numberAutomat';
import quoteAutomat from '../automats/quoteAutomat';
import orderAutomat from '../automats/orderAutomat';
import deliveryAutomat from '../automats/deliveryAutomat';
/**
* Formats a number pattern given prefix, padding width, and counter.
@@ -18,9 +19,9 @@ export function formatNumberPattern(prefix, padding, next) {
}
/**
* Returns the next document number for quote or order based on company sequences.
* Returns the next document number for quote, order, or delivery based on company sequences.
*
* @param {'quote'|'order'|string} kind
* @param {'quote'|'order'|'delivery'|string} kind
* @returns {string}
*/
export function getNextDocumentNumber(kind) {
@@ -42,7 +43,9 @@ export function getNextDocumentNumber(kind) {
let prefix = '';
let startNum = 1;
if (
if (kind === 'delivery') {
prefix = prefixStyle.startsWith('DEL-') ? 'DEL-' : (prefixStyle.startsWith('L-') ? 'L-' : 'LS-');
} else if (
prefixStyle.startsWith('ART-') ||
prefixStyle.startsWith('LS-') ||
prefixStyle.startsWith('KD-') ||
@@ -69,8 +72,8 @@ export function getNextDocumentNumber(kind) {
prefix = kind === 'quote' ? 'ANG-' : (kind === 'order' ? 'AUF-' : '');
}
// Check existing docs from quoteAutomat / orderAutomat to avoid collisions
const listAutomat = kind === 'quote' ? quoteAutomat : (kind === 'order' ? orderAutomat : null);
// Check existing docs from quoteAutomat / orderAutomat / deliveryAutomat to avoid collisions
const listAutomat = kind === 'quote' ? quoteAutomat : (kind === 'order' ? orderAutomat : (kind === 'delivery' ? deliveryAutomat : null));
const existingDocs = Array.isArray(listAutomat?.state?.items) ? listAutomat.state.items : [];
let maxFound = startNum - 1;
@@ -99,11 +102,11 @@ export function getNextDocumentNumber(kind) {
/**
* Asynchronously ensures required stores are loaded, then returns the next document number.
*
* @param {'quote'|'order'|string} kind
* @param {'quote'|'order'|'delivery'|string} kind
* @returns {Promise<string>}
*/
export async function ensureDocumentNumber(kind) {
const listAutomat = kind === 'quote' ? quoteAutomat : (kind === 'order' ? orderAutomat : null);
const listAutomat = kind === 'quote' ? quoteAutomat : (kind === 'order' ? orderAutomat : (kind === 'delivery' ? deliveryAutomat : null));
await Promise.all([
numberAutomat.actions.ensureLoaded().catch(() => {}),
listAutomat?.actions?.ensureLoaded ? listAutomat.actions.ensureLoaded().catch(() => {}) : Promise.resolve(),