@kreiseck/kasseneck-api 1.25.1 → 1.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/models/receipt-errors.d.ts +1 -1
  3. package/dist/cjs/models/receipt-errors.js +2 -0
  4. package/dist/cjs/models/receipt-item.d.ts +10 -0
  5. package/dist/cjs/models/receipt-item.js +8 -0
  6. package/dist/cjs/pos/artikel.d.ts +39 -0
  7. package/dist/cjs/pos/artikel.js +23 -0
  8. package/dist/cjs/pos/index.d.ts +3 -1
  9. package/dist/cjs/pos/index.js +28 -2
  10. package/dist/cjs/pos/kachel-referenz.d.ts +55 -0
  11. package/dist/cjs/pos/kachel-referenz.js +107 -0
  12. package/dist/cjs/pos/texte.d.ts +35 -0
  13. package/dist/cjs/pos/texte.js +14 -0
  14. package/dist/cjs/pos/zusaetze.d.ts +70 -0
  15. package/dist/cjs/pos/zusaetze.js +159 -0
  16. package/dist/cjs/receipt/grid.js +16 -3
  17. package/dist/cjs/receipt/layout.js +16 -9
  18. package/dist/cjs/stored/draht.js +4 -0
  19. package/dist/cjs/stored/vokabular.d.ts +1 -1
  20. package/dist/cjs/stored/vokabular.js +25 -4
  21. package/dist/cjs/version.d.ts +1 -1
  22. package/dist/cjs/version.js +1 -1
  23. package/dist/esm/models/receipt-errors.d.ts +1 -1
  24. package/dist/esm/models/receipt-errors.js +2 -0
  25. package/dist/esm/models/receipt-item.d.ts +10 -0
  26. package/dist/esm/models/receipt-item.js +8 -0
  27. package/dist/esm/pos/artikel.d.ts +39 -0
  28. package/dist/esm/pos/artikel.js +20 -0
  29. package/dist/esm/pos/index.d.ts +3 -1
  30. package/dist/esm/pos/index.js +3 -1
  31. package/dist/esm/pos/kachel-referenz.d.ts +55 -0
  32. package/dist/esm/pos/kachel-referenz.js +98 -0
  33. package/dist/esm/pos/texte.d.ts +35 -0
  34. package/dist/esm/pos/texte.js +14 -0
  35. package/dist/esm/pos/zusaetze.d.ts +70 -0
  36. package/dist/esm/pos/zusaetze.js +148 -0
  37. package/dist/esm/receipt/grid.js +16 -3
  38. package/dist/esm/receipt/layout.js +16 -9
  39. package/dist/esm/stored/draht.js +4 -0
  40. package/dist/esm/stored/vokabular.d.ts +1 -1
  41. package/dist/esm/stored/vokabular.js +25 -4
  42. package/dist/esm/version.d.ts +1 -1
  43. package/dist/esm/version.js +1 -1
  44. package/fixtures/add-on-cases.json +103 -0
  45. package/fixtures/expected/add-ons.grid32.txt +31 -0
  46. package/fixtures/expected/add-ons.grid48.txt +27 -0
  47. package/fixtures/expected/add-ons.lines.json +270 -0
  48. package/fixtures/expected/add-ons.sheet32.json +212 -0
  49. package/fixtures/expected/add-ons.sheet48.json +188 -0
  50. package/fixtures/hobex-hps-codes.json +1 -1
  51. package/fixtures/invoice-api.schema.json +1 -1
  52. package/fixtures/invoice-texts.json +1 -1
  53. package/fixtures/manifest.json +8 -0
  54. package/fixtures/pos-texts.json +40 -1
  55. package/fixtures/receipts/add-ons.json +70 -0
  56. package/fixtures/reference-cases.json +238 -0
  57. package/fixtures/surface.json +14 -1
  58. package/fixtures/v3/antworten/belege.json +1 -1
  59. package/fixtures/v3/antworten/belegmail.json +1 -1
  60. package/fixtures/v3/antworten/berichte.json +1 -1
  61. package/fixtures/v3/antworten/kasse-belege.json +1 -1
  62. package/fixtures/v3/antworten/kasse.json +2 -2
  63. package/fixtures/v3/antworten/lager.json +1 -1
  64. package/fixtures/v3/antworten/rechnungen.json +1 -1
  65. package/fixtures/v3/antworten/storno.json +1 -1
  66. package/fixtures/v3/stored/belege.json +1 -1
  67. package/fixtures/v3/stored/kasse.json +2 -2
  68. package/fixtures/v3/stored/rechnungen.json +1 -1
  69. package/fixtures/v3/v3-vokabular.json +51 -12
  70. package/fixtures/v3/zahlbetrag-faelle.json +1 -1
  71. package/package.json +1 -1
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Kachel mit Betrag und Referenz: eine Kachel fragt beim Antippen den Betrag
3
+ * (`askPrice`) und/oder eine Referenz (Honorarnote, Auftragsnummer) ab.
4
+ * Dieselben Regeln rechnen das Backend (`kachel-referenz-core.js`) und das
5
+ * Dart-Paket; der Vertrag sind die Pruefaelle `fixtures/reference-cases.json`.
6
+ */
7
+ /** `optional` = darf leer bleiben, `required` = Pflicht. */
8
+ export const REFERENCE_MODES = ['optional', 'required'];
9
+ /** Hoechstlaenge der Eingabe an der Kasse. */
10
+ export const REFERENCE_INPUT_MAX = 40;
11
+ export const REFERENCE_LABEL_MAX = 30;
12
+ export const REFERENCE_HINT_MAX = 60;
13
+ export const REFERENCE_PATTERN_MAX = 200;
14
+ /** Vorlagen fuer das Musterfeld im Panel. */
15
+ export const REFERENCE_PATTERN_TEMPLATES = [
16
+ { key: 'digits', pattern: '\\d+' },
17
+ { key: 'year_number', pattern: '\\d{4}/\\d{1,6}' },
18
+ { key: 'letters_digits', pattern: '[A-Za-z]{1,4}-?\\d{1,8}' },
19
+ ];
20
+ // Steuer- und unsichtbare Formatzeichen.
21
+ // eslint-disable-next-line no-control-regex
22
+ const STEUERZEICHEN = /[\u0000-\u001f\u007f-\u009f\u200b-\u200f\u2028\u2029\u202a-\u202e\u2060-\u2064\ufeff]/g;
23
+ /**
24
+ * Eingabe an der Kasse: ohne Steuer- und Formatzeichen, Leerraum
25
+ * zusammengezogen und getrimmt. Bewusst ohne NFC, damit Web und Dart gleich
26
+ * rechnen (Dart kennt keine Unicode-Normalisierung).
27
+ */
28
+ export function cleanReferenceText(text) {
29
+ return text.replace(STEUERZEICHEN, '').replace(/\s+/g, ' ').trim();
30
+ }
31
+ // Konstrukte, die JS und Dart nicht garantiert gleich auswerten.
32
+ const GESPERRT = [/\(\?<[=!]/, /\(\?<[A-Za-z]/, /\\[1-9]/, /\\k</, /\(\?[a-zA-Z]/];
33
+ /** Ist das Muster erlaubt (kompilierbar, ohne gesperrte Konstrukte)? */
34
+ export function isValidReferencePattern(pattern) {
35
+ if (typeof pattern !== 'string' || pattern.length < 1 || pattern.length > REFERENCE_PATTERN_MAX)
36
+ return false;
37
+ if (GESPERRT.some((r) => r.test(pattern)))
38
+ return false;
39
+ try {
40
+ new RegExp(`^(?:${pattern})$`);
41
+ return true;
42
+ }
43
+ catch {
44
+ return false;
45
+ }
46
+ }
47
+ /** Reines Ziffernmuster -> die Kasse zeigt die Zifferntastatur. */
48
+ export function isDigitsOnlyPattern(pattern) {
49
+ if (typeof pattern !== 'string' || pattern === '' || !isValidReferencePattern(pattern))
50
+ return false;
51
+ const rest = pattern
52
+ .replace(/\\d/g, '')
53
+ .replace(/\[0-9\]/g, '')
54
+ .replace(/\{\d+(,\d*)?\}/g, '')
55
+ .replace(/\(\?:/g, '')
56
+ .replace(/[()|?*+^$]/g, '');
57
+ return rest === '';
58
+ }
59
+ /**
60
+ * Prueft die Eingabe an der Kasse. `empty` und `error` sperren das Uebernehmen,
61
+ * `warning` zeigt den Hinweis und laesst uebernehmen. Ein ungueltiges Muster
62
+ * (Altbestand, fremder Client) gilt wie keines.
63
+ */
64
+ export function checkReference(input, reference) {
65
+ const value = cleanReferenceText(input ?? '').slice(0, REFERENCE_INPUT_MAX);
66
+ if (!reference)
67
+ return { result: 'ok', value };
68
+ if (value === '')
69
+ return { result: reference.mode === 'required' ? 'empty' : 'ok', value };
70
+ if (reference.pattern && isValidReferencePattern(reference.pattern)) {
71
+ if (!new RegExp(`^(?:${reference.pattern})$`).test(value)) {
72
+ return { result: reference.patternStrict ? 'error' : 'warning', value };
73
+ }
74
+ }
75
+ return { result: 'ok', value };
76
+ }
77
+ /** Positionsname am Beleg: Artikelname + Leerzeichen + Referenz (leer = nur der Name). */
78
+ export function referenceLineName(articleName, value) {
79
+ return value ? `${articleName} ${value}` : articleName;
80
+ }
81
+ /** Liest `reference` vom Draht; alles Unbrauchbare -> null. */
82
+ export function fromReferencePayload(p) {
83
+ if (!p || typeof p !== 'object' || Array.isArray(p))
84
+ return null;
85
+ const r = p;
86
+ if (r.mode !== 'optional' && r.mode !== 'required')
87
+ return null;
88
+ if (typeof r.label !== 'string' || r.label === '')
89
+ return null;
90
+ const pattern = typeof r.pattern === 'string' && r.pattern !== '' ? r.pattern : null;
91
+ return {
92
+ mode: r.mode,
93
+ label: r.label,
94
+ hint: typeof r.hint === 'string' && r.hint !== '' ? r.hint : null,
95
+ pattern,
96
+ patternStrict: pattern !== null && r.patternStrict === true,
97
+ };
98
+ }
@@ -119,6 +119,16 @@ declare const MELDUNGEN_ROH: {
119
119
  readonly 'item.description_missing': {
120
120
  readonly text: "Bitte eine Bezeichnung eingeben – sie steht am Beleg.";
121
121
  };
122
+ readonly 'reference.missing': {
123
+ readonly text: "Bitte „{name}“ eingeben.";
124
+ readonly placeholders: readonly ["name"];
125
+ };
126
+ readonly 'reference.format_invalid': {
127
+ readonly text: "Das Format passt nicht.";
128
+ };
129
+ readonly 'reference.format_warning': {
130
+ readonly text: "Das Format passt nicht. Trotzdem übernehmen?";
131
+ };
122
132
  readonly 'discount.percent_invalid': {
123
133
  readonly text: "Bitte einen Prozentwert zwischen 0,1 und 100 eingeben.";
124
134
  };
@@ -2062,6 +2072,31 @@ declare const BESCHRIFTUNGEN_ROH: {
2062
2072
  readonly 'voucher.add': {
2063
2073
  readonly text: "Hinzufügen";
2064
2074
  };
2075
+ readonly 'tile_prompt.amount': {
2076
+ readonly text: "Betrag";
2077
+ };
2078
+ readonly 'tile_prompt.quantity': {
2079
+ readonly text: "Menge";
2080
+ };
2081
+ readonly 'tile_prompt.apply': {
2082
+ readonly text: "Übernehmen";
2083
+ };
2084
+ readonly 'tile_prompt.apply_anyway': {
2085
+ readonly text: "Trotzdem übernehmen";
2086
+ };
2087
+ readonly 'addons.title': {
2088
+ readonly text: "Zusätze zu {name}";
2089
+ readonly placeholders: readonly ["name"];
2090
+ };
2091
+ readonly 'addons.none': {
2092
+ readonly text: "Ohne Zusatz";
2093
+ };
2094
+ readonly 'addons.done': {
2095
+ readonly text: "Fertig";
2096
+ };
2097
+ readonly 'addons.open': {
2098
+ readonly text: "Zusätze";
2099
+ };
2065
2100
  readonly 'voucher.tab': {
2066
2101
  readonly text: "Gutscheine";
2067
2102
  };
@@ -69,6 +69,10 @@ const MELDUNGEN_ROH = {
69
69
  'articles.vat_rate_unknown': { text: '„{name}“ hat einen Steuersatz, den die Kasse nicht kennt.', placeholders: ['name'] },
70
70
  'item.amount_missing': { text: 'Bitte einen Betrag eingeben.' },
71
71
  'item.description_missing': { text: 'Bitte eine Bezeichnung eingeben – sie steht am Beleg.' },
72
+ // Kachel mit Betrag und Referenz (1.26.0): Eingabeblatt beim Antippen.
73
+ 'reference.missing': { text: 'Bitte „{name}“ eingeben.', placeholders: ['name'] },
74
+ 'reference.format_invalid': { text: 'Das Format passt nicht.' },
75
+ 'reference.format_warning': { text: 'Das Format passt nicht. Trotzdem übernehmen?' },
72
76
  'discount.percent_invalid': { text: 'Bitte einen Prozentwert zwischen 0,1 und 100 eingeben.' },
73
77
  // --- Kassieren -----------------------------------------------------------
74
78
  // Der Grund ueber dem Knopf, solange der Beleg nicht abgeschlossen werden kann.
@@ -1038,6 +1042,16 @@ const BESCHRIFTUNGEN_ROH = {
1038
1042
  'voucher.code_done': { text: 'Fertig' },
1039
1043
  'voucher.article': { text: 'Artikel' },
1040
1044
  'voucher.add': { text: 'Hinzufügen' },
1045
+ // Kachel mit Betrag und Referenz (1.26.0): Felder und Knoepfe des Eingabeblatts.
1046
+ 'tile_prompt.amount': { text: 'Betrag' },
1047
+ 'tile_prompt.quantity': { text: 'Menge' },
1048
+ 'tile_prompt.apply': { text: 'Übernehmen' },
1049
+ 'tile_prompt.apply_anyway': { text: 'Trotzdem übernehmen' },
1050
+ // Zusatz-Kacheln (1.27.0): Fenster nach dem Antippen einer Hauptleistung, Knopf an der Korbzeile.
1051
+ 'addons.title': { text: 'Zusätze zu {name}', placeholders: ['name'] },
1052
+ 'addons.none': { text: 'Ohne Zusatz' },
1053
+ 'addons.done': { text: 'Fertig' },
1054
+ 'addons.open': { text: 'Zusätze' },
1041
1055
  // Gutschein-Sorten als Kacheln im Reiter „Gutscheine“ (Stufe 4b, 1.17.0): Kachel je Sorte mit Betrag
1042
1056
  // oder „Betrag eingeben“, darunter klein die Art; dazu die feste Kachel „Leistungsgutschein“.
1043
1057
  'voucher.tab': { text: 'Gutscheine' },
@@ -0,0 +1,70 @@
1
+ import type { ArticleGroup, PosArticle } from './artikel.js';
2
+ /**
3
+ * Zusatz-Kacheln (1.27.0): Tippt man eine Hauptleistung an, oeffnet die Kasse
4
+ * ein Fenster mit ihren Zusaetzen. Die Liste steht an der Gruppe, je Artikel
5
+ * abweichend (`addOns`: null = wie die Gruppe, [] = keine, sonst eigene Liste).
6
+ * Jeder Zusatz wird eine eigene Belegposition mit `addOnOf` = Index der
7
+ * Hauptposition. Die Regeln rechnen Backend (`gemeinsam/zusatz-core.js`), npm
8
+ * und Dart gleich; der Vertrag sind die Pruefaelle `fixtures/add-on-cases.json`.
9
+ */
10
+ /** Hoechstens so viele Zusaetze je Liste (der Server weist mehr ab). */
11
+ export declare const ADD_ONS_MAX = 30;
12
+ /** Warum ein Artikel kein Zusatz sein kann (Panel zeigt den Grund an). */
13
+ export declare const ADD_ON_BLOCK_REASONS: readonly ["inactive", "own_list", "asks_price", "reference", "asks_quantity", "no_price", "service_voucher"];
14
+ export type AddOnBlockReason = typeof ADD_ON_BLOCK_REASONS[number];
15
+ type ZusatzArtikel = Pick<PosArticle, 'id' | 'active' | 'unitPriceCents'> & Partial<Pick<PosArticle, 'addOns' | 'askPrice' | 'reference' | 'askQuantity' | 'serviceVoucher'>>;
16
+ type ArtikelNachId<T> = ReadonlyMap<string, T> | Readonly<Record<string, T>>;
17
+ /**
18
+ * Taugt der Artikel als Zusatz? `null` = ja. Im Fenster wird ohne Abfrage
19
+ * gebucht: Betrag, Referenz oder Menge fragen geht nicht, ein Preis muss
20
+ * feststehen (0 erlaubt), ein Leistungsgutschein liefe am Gutschein-Weg vorbei,
21
+ * und ein Artikel mit eigener Liste oeffnete selbst ein Fenster (eine Ebene).
22
+ */
23
+ export declare function isSelectableAddOn(a: ZusatzArtikel): AddOnBlockReason | null;
24
+ /**
25
+ * Wirksame Zusatzliste eines Artikels: eigene Liste (auch leer) vor der der
26
+ * Gruppe; still heraus fallen der Artikel selbst, Unbekanntes, Dubletten und
27
+ * alles, was nicht als Zusatz taugt. Leer = kein Fenster.
28
+ */
29
+ export declare function addOnsFor<T extends ZusatzArtikel>(article: ZusatzArtikel, group: Pick<ArticleGroup, 'addOns'> | null | undefined, articleById: ArtikelNachId<T>): string[];
30
+ type MitVerweis = {
31
+ addOnOf?: number | null;
32
+ };
33
+ /**
34
+ * Halten die Verweise den Server-Regeln stand? Ganze Zahl, zeigt nach vorne
35
+ * auf eine Warenposition, die selbst kein Zusatz ist (sonst antwortet
36
+ * createReceipt mit `invalid_add_on_reference`).
37
+ */
38
+ export declare function addOnReferencesValid(items: readonly (MitVerweis & {
39
+ kind?: string | null;
40
+ })[]): boolean;
41
+ /** Indizes der Zusaetze einer Hauptposition (Storno: mit vormerken, abwaehlbar). */
42
+ export declare function addOnsOfItem(items: readonly MitVerweis[], index: number): number[];
43
+ /**
44
+ * Storno: Verweis je Storno-Position (in der Reihenfolge der stornierten
45
+ * Positionen, Menge > 0). Ein Zusatz behaelt ihn nur, wenn seine Hauptposition
46
+ * mit storniert wird, umgerechnet auf den neuen Index; sonst `null`.
47
+ */
48
+ export declare function addOnRemap(items: readonly MitVerweis[], quantities: readonly number[]): (number | null)[];
49
+ /** Ist Position `i` ein gueltiger Zusatz (Verweis nach vorne auf eine Hauptposition)? Paketintern (Layout). */
50
+ export declare function istGueltigerZusatz(items: readonly MitVerweis[], i: number): boolean;
51
+ /**
52
+ * Bon-Reihenfolge: jede Hauptposition, direkt gefolgt von ihren Zusaetzen
53
+ * (stabil). Positionen mit ungueltigem Verweis bleiben an ihrem Platz.
54
+ */
55
+ export declare function addOnDisplayOrder(items: readonly MitVerweis[]): number[];
56
+ /**
57
+ * Warenkorb -> Belegpositionen: Zeilen tragen die Zeilen-Id ihrer Hauptzeile
58
+ * (`addOnOf`). Sortiert jeden Zusatz hinter seine Hauptzeile (stabil) und
59
+ * rechnet den Verweis in den Index um. Fehlt die Hauptzeile (geloescht oder
60
+ * vorher herausgefiltert, etwa ein Gutschein-Verkauf), bleibt die Zeile ohne
61
+ * Verweis an ihrem Platz.
62
+ */
63
+ export declare function orderAddOnLines<T extends {
64
+ id: string;
65
+ addOnOf?: string | null;
66
+ }>(lines: readonly T[]): {
67
+ line: T;
68
+ addOnOf: number | null;
69
+ }[];
70
+ export {};
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Zusatz-Kacheln (1.27.0): Tippt man eine Hauptleistung an, oeffnet die Kasse
3
+ * ein Fenster mit ihren Zusaetzen. Die Liste steht an der Gruppe, je Artikel
4
+ * abweichend (`addOns`: null = wie die Gruppe, [] = keine, sonst eigene Liste).
5
+ * Jeder Zusatz wird eine eigene Belegposition mit `addOnOf` = Index der
6
+ * Hauptposition. Die Regeln rechnen Backend (`gemeinsam/zusatz-core.js`), npm
7
+ * und Dart gleich; der Vertrag sind die Pruefaelle `fixtures/add-on-cases.json`.
8
+ */
9
+ /** Hoechstens so viele Zusaetze je Liste (der Server weist mehr ab). */
10
+ export const ADD_ONS_MAX = 30;
11
+ /** Warum ein Artikel kein Zusatz sein kann (Panel zeigt den Grund an). */
12
+ export const ADD_ON_BLOCK_REASONS = ['inactive', 'own_list', 'asks_price', 'reference', 'asks_quantity', 'no_price', 'service_voucher'];
13
+ const eigeneListe = (a) => Array.isArray(a.addOns) && a.addOns.length > 0;
14
+ /**
15
+ * Taugt der Artikel als Zusatz? `null` = ja. Im Fenster wird ohne Abfrage
16
+ * gebucht: Betrag, Referenz oder Menge fragen geht nicht, ein Preis muss
17
+ * feststehen (0 erlaubt), ein Leistungsgutschein liefe am Gutschein-Weg vorbei,
18
+ * und ein Artikel mit eigener Liste oeffnete selbst ein Fenster (eine Ebene).
19
+ */
20
+ export function isSelectableAddOn(a) {
21
+ if (a.active === false)
22
+ return 'inactive';
23
+ if (eigeneListe(a))
24
+ return 'own_list';
25
+ if (a.askPrice === true)
26
+ return 'asks_price';
27
+ if (a.reference != null)
28
+ return 'reference';
29
+ if (a.askQuantity === true)
30
+ return 'asks_quantity';
31
+ if (typeof a.unitPriceCents !== 'number' || !Number.isInteger(a.unitPriceCents) || a.unitPriceCents < 0)
32
+ return 'no_price';
33
+ if (a.serviceVoucher === true)
34
+ return 'service_voucher';
35
+ return null;
36
+ }
37
+ function nachId(karte, id) {
38
+ if (karte instanceof Map)
39
+ return karte.get(id);
40
+ return Object.prototype.hasOwnProperty.call(karte, id) ? karte[id] : undefined;
41
+ }
42
+ /**
43
+ * Wirksame Zusatzliste eines Artikels: eigene Liste (auch leer) vor der der
44
+ * Gruppe; still heraus fallen der Artikel selbst, Unbekanntes, Dubletten und
45
+ * alles, was nicht als Zusatz taugt. Leer = kein Fenster.
46
+ */
47
+ export function addOnsFor(article, group, articleById) {
48
+ const liste = Array.isArray(article.addOns) ? article.addOns : (group && Array.isArray(group.addOns) ? group.addOns : []);
49
+ const raus = [];
50
+ for (const id of liste) {
51
+ if (typeof id !== 'string' || id === article.id || raus.includes(id))
52
+ continue;
53
+ const z = nachId(articleById, id);
54
+ if (!z || isSelectableAddOn(z) !== null)
55
+ continue;
56
+ raus.push(id);
57
+ }
58
+ return raus;
59
+ }
60
+ const hatVerweis = (it) => it != null && typeof it === 'object' && Object.prototype.hasOwnProperty.call(it, 'addOnOf') && it.addOnOf !== undefined;
61
+ // Positionsarten, die nie Zusatz oder Hauptposition sind (Trinkgeld, Rabatt, Gutschein).
62
+ const OHNE_ZUSATZ = new Set(['tip', 'discount', 'voucher', 'voucher_float']);
63
+ /**
64
+ * Halten die Verweise den Server-Regeln stand? Ganze Zahl, zeigt nach vorne
65
+ * auf eine Warenposition, die selbst kein Zusatz ist (sonst antwortet
66
+ * createReceipt mit `invalid_add_on_reference`).
67
+ */
68
+ export function addOnReferencesValid(items) {
69
+ return items.every((it, i) => {
70
+ if (!hatVerweis(it))
71
+ return true;
72
+ const z = it.addOnOf;
73
+ if (typeof z !== 'number' || !Number.isInteger(z) || z < 0 || z >= i)
74
+ return false;
75
+ const ziel = items[z];
76
+ if (OHNE_ZUSATZ.has(it.kind ?? '') || OHNE_ZUSATZ.has(ziel?.kind ?? ''))
77
+ return false;
78
+ return !hatVerweis(ziel);
79
+ });
80
+ }
81
+ /** Indizes der Zusaetze einer Hauptposition (Storno: mit vormerken, abwaehlbar). */
82
+ export function addOnsOfItem(items, index) {
83
+ const raus = [];
84
+ items.forEach((it, i) => { if (hatVerweis(it) && it.addOnOf === index)
85
+ raus.push(i); });
86
+ return raus;
87
+ }
88
+ /**
89
+ * Storno: Verweis je Storno-Position (in der Reihenfolge der stornierten
90
+ * Positionen, Menge > 0). Ein Zusatz behaelt ihn nur, wenn seine Hauptposition
91
+ * mit storniert wird, umgerechnet auf den neuen Index; sonst `null`.
92
+ */
93
+ export function addOnRemap(items, quantities) {
94
+ const neu = new Map();
95
+ const raus = [];
96
+ items.forEach((it, i) => {
97
+ if (!((quantities[i] ?? 0) > 0))
98
+ return;
99
+ neu.set(i, raus.length);
100
+ raus.push(hatVerweis(it) && neu.has(it.addOnOf) ? neu.get(it.addOnOf) : null);
101
+ });
102
+ return raus;
103
+ }
104
+ /** Ist Position `i` ein gueltiger Zusatz (Verweis nach vorne auf eine Hauptposition)? Paketintern (Layout). */
105
+ export function istGueltigerZusatz(items, i) {
106
+ const it = items[i];
107
+ return it != null && hatVerweis(it) && Number.isInteger(it.addOnOf)
108
+ && it.addOnOf >= 0 && it.addOnOf < i && !hatVerweis(items[it.addOnOf]);
109
+ }
110
+ /**
111
+ * Bon-Reihenfolge: jede Hauptposition, direkt gefolgt von ihren Zusaetzen
112
+ * (stabil). Positionen mit ungueltigem Verweis bleiben an ihrem Platz.
113
+ */
114
+ export function addOnDisplayOrder(items) {
115
+ const gueltig = (_it, i) => istGueltigerZusatz(items, i);
116
+ const raus = [];
117
+ items.forEach((it, i) => {
118
+ if (gueltig(it, i))
119
+ return;
120
+ raus.push(i);
121
+ items.forEach((z, j) => { if (j > i && gueltig(z, j) && z.addOnOf === i)
122
+ raus.push(j); });
123
+ });
124
+ return raus;
125
+ }
126
+ /**
127
+ * Warenkorb -> Belegpositionen: Zeilen tragen die Zeilen-Id ihrer Hauptzeile
128
+ * (`addOnOf`). Sortiert jeden Zusatz hinter seine Hauptzeile (stabil) und
129
+ * rechnet den Verweis in den Index um. Fehlt die Hauptzeile (geloescht oder
130
+ * vorher herausgefiltert, etwa ein Gutschein-Verkauf), bleibt die Zeile ohne
131
+ * Verweis an ihrem Platz.
132
+ */
133
+ export function orderAddOnLines(lines) {
134
+ const ids = new Set(lines.map((l) => l.id));
135
+ const istZusatz = (l) => typeof l.addOnOf === 'string' && l.addOnOf !== l.id && ids.has(l.addOnOf)
136
+ && !lines.some((h) => h.id === l.addOnOf && typeof h.addOnOf === 'string' && ids.has(h.addOnOf));
137
+ const raus = [];
138
+ for (const l of lines) {
139
+ if (istZusatz(l))
140
+ continue;
141
+ const index = raus.length;
142
+ raus.push({ line: l, addOnOf: null });
143
+ for (const z of lines)
144
+ if (istZusatz(z) && z.addOnOf === l.id)
145
+ raus.push({ line: z, addOnOf: index });
146
+ }
147
+ return raus;
148
+ }
@@ -99,7 +99,19 @@ export function renderReceiptGrid(layout, options = {}) {
99
99
  const breiten = gridColumnWidths(z.columns.map((c) => c.width), zeichen);
100
100
  // Inhalt jeder nicht-letzten Spalte um 1 Zeichen schmaler: garantierter Abstand.
101
101
  const inhalt = breiten.map((b, i) => (i < breiten.length - 1 ? Math.max(1, b - 1) : b));
102
- const teile = z.columns.map((c, i) => wrapText(c.text, inhalt[i]));
102
+ // Haengender Einzug wie bei Textzeilen: eine linksbuendige Spalte mit
103
+ // fuehrenden Leerzeichen bricht mit demselben Einzug um; ein Spiegelstrich
104
+ // „+ “ danach zaehlt mit (Zusatzzeile „ + 1 x …“: Fortsetzung unter der
105
+ // Menge). Ohne fuehrende Leerzeichen dieselben Zeichen wie bisher.
106
+ const einzugVon = (c, i) => {
107
+ const e = c.align === 'left' ? (/^ +(?:\+ )?/.exec(c.text)?.[0].length ?? 0) : 0;
108
+ return e > 0 && e < inhalt[i] && c.text.slice(e).trim() !== '' ? e : 0;
109
+ };
110
+ const einzuege = z.columns.map(einzugVon);
111
+ const umbrechen = (text, breite, e) => (e > 0
112
+ ? wrapText(text.slice(e), breite - e).map((t, k) => (k === 0 ? text.slice(0, e) : ' '.repeat(e)) + t)
113
+ : wrapText(text, breite));
114
+ const teile = z.columns.map((c, i) => umbrechen(c.text, inhalt[i], einzuege[i]));
103
115
  // Fliessregel: laeuft nach der ersten Zeile nur noch EINE Spalte weiter (die anderen sind
104
116
  // fertig), bekommt ihr Rest die volle Breite -- auf 58 mm sonst 18-Zeichen-Schnipsel.
105
117
  // Laufen mehrere weiter, bleibt das Raster (sonst verschoeben sich die Nachbarn).
@@ -118,8 +130,9 @@ export function renderReceiptGrid(layout, options = {}) {
118
130
  const i = weiterlaufend[0];
119
131
  // Rest aus dem Originaltext (nicht aus den schmal umbrochenen Stuecken), damit
120
132
  // Bindestrich-/Hartbrueche der schmalen Spalte nicht als Leerzeichen zurueckbleiben.
121
- const rest = restNach(z.columns[i].text, teile[i][0]);
122
- for (const t of wrapText(rest, zeichen))
133
+ const e = einzuege[i];
134
+ const rest = e > 0 ? restNach(z.columns[i].text.slice(e), teile[i][0].slice(e)) : restNach(z.columns[i].text, teile[i][0]);
135
+ for (const t of (e > 0 ? wrapText(rest, zeichen - e).map((x) => ' '.repeat(e) + x) : wrapText(rest, zeichen)))
123
136
  lines.push({ text: ausrichten(t, zeichen, z.columns[i].align), kind: 'columns', bold: z.bold === true });
124
137
  }
125
138
  break;
@@ -2,6 +2,7 @@ import { VatRate, VoucherAction, VoucherType } from '../enums/index.js';
2
2
  import { CANCELLATION_REASONS, isCancellationReason, receiptCompanyTaxInfo, receiptItemTotalCents, isDiscountItem, isTipItem, receiptSubSumCents, receiptSumCents, receiptValueVoucherSign, voucherIsValid, } from '../models/index.js';
3
3
  import { parseServerTimeStamp, toViennaWallClock } from '../vienna-time.js';
4
4
  import { KasseneckValidationError } from '../client/errors.js';
5
+ import { addOnDisplayOrder, istGueltigerZusatz } from '../pos/zusaetze.js';
5
6
  export const CURRENT_LAYOUT_RULESET = 2;
6
7
  /** Die Optionen von [buildReceiptLayout]; jede andere wird abgewiesen. */
7
8
  const LAYOUT_OPTIONEN = new Set(['paperSize', 'ruleset', 'testCashregister', 'testSignature', 'registrationInfo']);
@@ -818,8 +819,10 @@ function trinkgeldZeilen(name, teile) {
818
819
  * Aufteilung als Fussnote darunter (siehe trinkgeldZeilen).
819
820
  */
820
821
  const rabattZeilen = trinkgeldZeilen;
821
- /** Positionszeile: Menge, Bezeichnung, ab Menge 2 der Einzelpreis. */
822
- function positionsZeile(item, satz) {
822
+ /** Vorsatz einer Zusatzzeile (Zusatz-Kacheln, 1.27.0): eingerueckt unter der Hauptposition. */
823
+ const ZUSATZ_VORSATZ = ' + ';
824
+ /** Positionszeile: Menge, Bezeichnung, ab Menge 2 der Einzelpreis; ein Zusatz eingerueckt mit „+ “. */
825
+ function positionsZeile(item, satz, zusatz = false) {
823
826
  const menge = String(item.quantity);
824
827
  // Vorbild: Menge auf zwei Zeichen auffuellen, danach ' x ' — bei drei- und
825
828
  // mehrstelligen Mengen faellt das Leerzeichen dahinter weg.
@@ -829,7 +832,7 @@ function positionsZeile(item, satz) {
829
832
  return {
830
833
  kind: 'columns',
831
834
  columns: [
832
- { text: `${kopf}${item.name}${einzelpreis}`, width: 7, align: 'left' },
835
+ { text: `${zusatz ? ZUSATZ_VORSATZ : ''}${kopf}${item.name}${einzelpreis}`, width: 7, align: 'left' },
833
836
  { text: `${formatCents(receiptItemTotalCents(item))} ${satz.category}`, width: 5, align: 'right' },
834
837
  ],
835
838
  };
@@ -1153,22 +1156,26 @@ export function buildReceiptLayout(receipt, company, options = {}) {
1153
1156
  .reduce((summe, it) => summe + receiptItemTotalCents(it), 0);
1154
1157
  let zwischensummeGezeigt = false;
1155
1158
  const gutscheinZuordnung = gutscheinPositionen(receipt);
1159
+ // Zusatz-Kacheln: Zusaetze direkt unter ihrer Hauptposition (stabil); ohne
1160
+ // Verweise ist die Reihenfolge die des Belegs (byte-gleich).
1161
+ const reihe = addOnDisplayOrder(receipt.items);
1162
+ const an = (k) => receipt.items[reihe[k]];
1156
1163
  let i = 0;
1157
- while (i < receipt.items.length) {
1158
- const item = receipt.items[i];
1164
+ while (i < reihe.length) {
1165
+ const item = an(i);
1159
1166
  if (!isTipItem(item) && !isDiscountItem(item)) {
1160
1167
  const satz = steuersatz(item.vat);
1161
1168
  gruppeVon(satz).bruttoCents += receiptItemTotalCents(item);
1162
- const gutschein = gutscheinZuordnung.get(i);
1163
- lines.push(...(gutschein ? gutscheinPositionsZeilen(item, satz, gutschein) : [positionsZeile(item, satz)]));
1169
+ const gutschein = gutscheinZuordnung.get(reihe[i]);
1170
+ lines.push(...(gutschein ? gutscheinPositionsZeilen(item, satz, gutschein) : [positionsZeile(item, satz, istGueltigerZusatz(receipt.items, reihe[i]))]));
1164
1171
  i += 1;
1165
1172
  continue;
1166
1173
  }
1167
1174
  const artVon = (it) => (isTipItem(it) ? 'tip' : 'discount');
1168
1175
  const art = artVon(item);
1169
1176
  const gruppe = [];
1170
- while (i < receipt.items.length && artVon(receipt.items[i]) === art && !(!isTipItem(receipt.items[i]) && !isDiscountItem(receipt.items[i])) && receipt.items[i].name === item.name) {
1171
- gruppe.push(receipt.items[i]);
1177
+ while (i < reihe.length && artVon(an(i)) === art && !(!isTipItem(an(i)) && !isDiscountItem(an(i))) && an(i).name === item.name) {
1178
+ gruppe.push(an(i));
1172
1179
  i += 1;
1173
1180
  }
1174
1181
  const teile = [];
@@ -300,5 +300,9 @@ export function _storedArticleToWire(id, doc, functionName = 'fromStoredArticle'
300
300
  const kachel = regel(regel(schema.data.articles).unter.tile).unter;
301
301
  raus.tile = nurBekannte(raus.tile, new Set(Object.keys(kachel)));
302
302
  }
303
+ if (istObjekt(raus.reference)) {
304
+ const referenz = regel(regel(schema.data.articles).unter.reference).unter;
305
+ raus.reference = nurBekannte(raus.reference, new Set(Object.keys(referenz)), { mode: katalog('articles[].reference.mode') });
306
+ }
303
307
  return raus;
304
308
  }
@@ -1,5 +1,5 @@
1
1
  /** Fingerabdruck des Vertrags-Exports, aus dem diese Datei stammt (`_quelle.sha256`). */
2
- export declare const VOKABULAR_QUELLE = "44d12486b6108ca8c040230f317438b21c7761477fa1a9a7d6a65b28a5444e32";
2
+ export declare const VOKABULAR_QUELLE = "842340e1f94c14fab01ffe96277d76dff4482b97df2e355daa583ff49c2db634";
3
3
  /** Schema-Notation des Vertrags: Blatt 'aussen': 'innen', Objekt { __: 'innen', ... }, Liste [ { __: 'innen', ... } ]. */
4
4
  export type SchemaEintrag = string | SchemaObjekt | readonly [SchemaObjekt];
5
5
  export interface SchemaObjekt {
@@ -1,7 +1,7 @@
1
1
  // Erzeugt von scripts/stored-vokabular.mjs aus fixtures/v3/v3-vokabular.json.
2
2
  // Nicht von Hand aendern: test/stored.test.ts vergleicht mit dem Vertrag.
3
3
  /** Fingerabdruck des Vertrags-Exports, aus dem diese Datei stammt (`_quelle.sha256`). */
4
- export const VOKABULAR_QUELLE = "44d12486b6108ca8c040230f317438b21c7761477fa1a9a7d6a65b28a5444e32";
4
+ export const VOKABULAR_QUELLE = "842340e1f94c14fab01ffe96277d76dff4482b97df2e355daa583ff49c2db634";
5
5
  /** Schema je Endpunkt (aussen -> innen) und Wertverweise auf die Kataloge. */
6
6
  export const SCHEMAS = {
7
7
  "getReceipt": {
@@ -19,7 +19,8 @@ export const SCHEMAS = {
19
19
  {
20
20
  "__": "items",
21
21
  "receivedImmediately": "sofortErhalten",
22
- "keptByEmployee": "direkt"
22
+ "keptByEmployee": "direkt",
23
+ "addOnOf": "zusatzZu"
23
24
  }
24
25
  ],
25
26
  "manualReceipt": {
@@ -378,7 +379,17 @@ export const SCHEMAS = {
378
379
  "sort": "sort"
379
380
  },
380
381
  "stockLocationIds": "standorte",
381
- "minStockByLocation": "mindestJeStandort"
382
+ "minStockByLocation": "mindestJeStandort",
383
+ "askPrice": "preisFragen",
384
+ "reference": {
385
+ "__": "referenz",
386
+ "mode": "stufe",
387
+ "label": "bezeichnung",
388
+ "hint": "hinweis",
389
+ "pattern": "muster",
390
+ "patternStrict": "musterStreng"
391
+ },
392
+ "addOns": "zusaetze"
382
393
  }
383
394
  ]
384
395
  },
@@ -388,6 +399,9 @@ export const SCHEMAS = {
388
399
  },
389
400
  "articles[].e1aGroup": {
390
401
  "$catalog": "E1A_GRUPPE"
402
+ },
403
+ "articles[].reference.mode": {
404
+ "$catalog": "REFERENZ_STUFE"
391
405
  }
392
406
  }
393
407
  }
@@ -418,7 +432,10 @@ export const ARTIKEL_FELDER = [
418
432
  "groupId",
419
433
  "tile",
420
434
  "stockLocationIds",
421
- "minStockByLocation"
435
+ "minStockByLocation",
436
+ "askPrice",
437
+ "reference",
438
+ "addOns"
422
439
  ];
423
440
  /** Wertkataloge innen (deutsch) -> aussen (englisch). */
424
441
  export const KATALOGE = {
@@ -689,6 +706,10 @@ export const KATALOGE = {
689
706
  "stueck": "piece",
690
707
  "dezimal": "decimal"
691
708
  },
709
+ "REFERENZ_STUFE": {
710
+ "fragen": "optional",
711
+ "pflicht": "required"
712
+ },
692
713
  "STORNO_GRUND": {
693
714
  "fehleingabe": "input_error",
694
715
  "kunde_storniert": "customer_cancelled",
@@ -4,4 +4,4 @@
4
4
  * Client-Version, Nachtrag §6). Ein Test haelt sie gleich mit `package.json`;
5
5
  * beim Anheben der Version beide Stellen aendern.
6
6
  */
7
- export declare const PACKAGE_VERSION = "1.25.1";
7
+ export declare const PACKAGE_VERSION = "1.27.0";
@@ -4,4 +4,4 @@
4
4
  * Client-Version, Nachtrag §6). Ein Test haelt sie gleich mit `package.json`;
5
5
  * beim Anheben der Version beide Stellen aendern.
6
6
  */
7
- export const PACKAGE_VERSION = '1.25.1';
7
+ export const PACKAGE_VERSION = '1.27.0';