@kreiseck/kasseneck-api 1.31.0 → 1.32.1

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 (124) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/cjs/client/aufrufe.d.ts +3 -3
  3. package/dist/cjs/client/aufrufe.js +8 -0
  4. package/dist/cjs/client/receipts.d.ts +11 -0
  5. package/dist/cjs/client/receipts.js +28 -2
  6. package/dist/cjs/index.d.ts +2 -2
  7. package/dist/cjs/index.js +8 -5
  8. package/dist/cjs/models/index.d.ts +1 -1
  9. package/dist/cjs/models/index.js +5 -2
  10. package/dist/cjs/models/receipt-errors.d.ts +1 -1
  11. package/dist/cjs/models/receipt-errors.js +9 -0
  12. package/dist/cjs/models/receipt-item.d.ts +44 -2
  13. package/dist/cjs/models/receipt-item.js +56 -1
  14. package/dist/cjs/models/receipt.d.ts +17 -0
  15. package/dist/cjs/models/receipt.js +9 -0
  16. package/dist/cjs/pos/artikel.d.ts +14 -0
  17. package/dist/cjs/pos/artikel.js +3 -0
  18. package/dist/cjs/pos/client.d.ts +1 -0
  19. package/dist/cjs/pos/client.js +3 -0
  20. package/dist/cjs/pos/errors.d.ts +1 -1
  21. package/dist/cjs/pos/errors.js +12 -0
  22. package/dist/cjs/pos/fremdgutschein-artikel.d.ts +3 -2
  23. package/dist/cjs/pos/fremdgutschein-artikel.js +4 -2
  24. package/dist/cjs/pos/index.d.ts +4 -2
  25. package/dist/cjs/pos/index.js +24 -4
  26. package/dist/cjs/pos/leergut.d.ts +60 -0
  27. package/dist/cjs/pos/leergut.js +82 -0
  28. package/dist/cjs/pos/pfand.d.ts +144 -0
  29. package/dist/cjs/pos/pfand.js +382 -0
  30. package/dist/cjs/pos/settings.d.ts +3 -7
  31. package/dist/cjs/pos/settings.js +7 -0
  32. package/dist/cjs/pos/texte.d.ts +72 -0
  33. package/dist/cjs/pos/texte.js +42 -1
  34. package/dist/cjs/receipt/discount.js +3 -0
  35. package/dist/cjs/receipt/due.d.ts +6 -0
  36. package/dist/cjs/receipt/due.js +16 -5
  37. package/dist/cjs/receipt/gutschein-plan.d.ts +7 -1
  38. package/dist/cjs/receipt/gutschein-plan.js +16 -2
  39. package/dist/cjs/receipt/layout.js +108 -2
  40. package/dist/cjs/register/pairing.d.ts +15 -1
  41. package/dist/cjs/register/pairing.js +14 -1
  42. package/dist/cjs/stored/vokabular.d.ts +1 -1
  43. package/dist/cjs/stored/vokabular.js +72 -4
  44. package/dist/cjs/version.d.ts +1 -1
  45. package/dist/cjs/version.js +1 -1
  46. package/dist/esm/client/aufrufe.d.ts +3 -3
  47. package/dist/esm/client/aufrufe.js +8 -0
  48. package/dist/esm/client/receipts.d.ts +11 -0
  49. package/dist/esm/client/receipts.js +29 -3
  50. package/dist/esm/index.d.ts +2 -2
  51. package/dist/esm/index.js +2 -2
  52. package/dist/esm/models/index.d.ts +1 -1
  53. package/dist/esm/models/index.js +1 -1
  54. package/dist/esm/models/receipt-errors.d.ts +1 -1
  55. package/dist/esm/models/receipt-errors.js +9 -0
  56. package/dist/esm/models/receipt-item.d.ts +44 -2
  57. package/dist/esm/models/receipt-item.js +54 -1
  58. package/dist/esm/models/receipt.d.ts +17 -0
  59. package/dist/esm/models/receipt.js +9 -0
  60. package/dist/esm/pos/artikel.d.ts +14 -0
  61. package/dist/esm/pos/artikel.js +3 -0
  62. package/dist/esm/pos/client.d.ts +1 -0
  63. package/dist/esm/pos/client.js +3 -0
  64. package/dist/esm/pos/errors.d.ts +1 -1
  65. package/dist/esm/pos/errors.js +12 -0
  66. package/dist/esm/pos/fremdgutschein-artikel.d.ts +3 -2
  67. package/dist/esm/pos/fremdgutschein-artikel.js +4 -2
  68. package/dist/esm/pos/index.d.ts +4 -2
  69. package/dist/esm/pos/index.js +4 -2
  70. package/dist/esm/pos/leergut.d.ts +60 -0
  71. package/dist/esm/pos/leergut.js +77 -0
  72. package/dist/esm/pos/pfand.d.ts +144 -0
  73. package/dist/esm/pos/pfand.js +371 -0
  74. package/dist/esm/pos/settings.d.ts +3 -7
  75. package/dist/esm/pos/settings.js +7 -0
  76. package/dist/esm/pos/texte.d.ts +72 -0
  77. package/dist/esm/pos/texte.js +40 -0
  78. package/dist/esm/receipt/discount.js +4 -1
  79. package/dist/esm/receipt/due.d.ts +6 -0
  80. package/dist/esm/receipt/due.js +17 -6
  81. package/dist/esm/receipt/gutschein-plan.d.ts +7 -1
  82. package/dist/esm/receipt/gutschein-plan.js +14 -2
  83. package/dist/esm/receipt/layout.js +109 -3
  84. package/dist/esm/register/pairing.d.ts +15 -1
  85. package/dist/esm/register/pairing.js +13 -1
  86. package/dist/esm/stored/vokabular.d.ts +1 -1
  87. package/dist/esm/stored/vokabular.js +72 -4
  88. package/dist/esm/version.d.ts +1 -1
  89. package/dist/esm/version.js +1 -1
  90. package/fixtures/deposit-cases.json +4758 -0
  91. package/fixtures/expected/deposit-return.grid32.txt +28 -0
  92. package/fixtures/expected/deposit-return.grid48.txt +28 -0
  93. package/fixtures/expected/deposit-return.lines.json +275 -0
  94. package/fixtures/expected/deposit-return.sheet32.json +194 -0
  95. package/fixtures/expected/deposit-return.sheet48.json +194 -0
  96. package/fixtures/expected/deposit.grid32.txt +34 -0
  97. package/fixtures/expected/deposit.grid48.txt +32 -0
  98. package/fixtures/expected/deposit.lines.json +316 -0
  99. package/fixtures/expected/deposit.sheet32.json +230 -0
  100. package/fixtures/expected/deposit.sheet48.json +218 -0
  101. package/fixtures/external-voucher-article-cases.json +20 -0
  102. package/fixtures/hobex-hps-codes.json +1 -1
  103. package/fixtures/invoice-api.schema.json +1 -1
  104. package/fixtures/invoice-texts.json +1 -1
  105. package/fixtures/manifest.json +16 -0
  106. package/fixtures/pos-texts.json +66 -1
  107. package/fixtures/receipts/deposit-return.json +63 -0
  108. package/fixtures/receipts/deposit.json +83 -0
  109. package/fixtures/return-code-cases.json +1338 -0
  110. package/fixtures/surface.json +45 -4
  111. package/fixtures/v3/antworten/belege.json +2 -2
  112. package/fixtures/v3/antworten/belegmail.json +2 -2
  113. package/fixtures/v3/antworten/berichte.json +2 -2
  114. package/fixtures/v3/antworten/kasse-belege.json +2 -2
  115. package/fixtures/v3/antworten/kasse.json +428 -13
  116. package/fixtures/v3/antworten/lager.json +1 -1
  117. package/fixtures/v3/antworten/rechnungen.json +2 -2
  118. package/fixtures/v3/antworten/storno.json +2 -2
  119. package/fixtures/v3/stored/belege.json +2 -2
  120. package/fixtures/v3/stored/kasse.json +42 -4
  121. package/fixtures/v3/stored/rechnungen.json +2 -2
  122. package/fixtures/v3/v3-vokabular.json +808 -27
  123. package/fixtures/v3/zahlbetrag-faelle.json +187 -3
  124. package/package.json +1 -1
@@ -79,6 +79,18 @@ export interface Receipt {
79
79
  registrationInfo?: RegistrationInfo;
80
80
  /** Nur an nacherfassten Belegen: der Handbeleg (siehe [ManualReceipt]). */
81
81
  manualReceipt?: ManualReceipt;
82
+ /** Pfand & Leergut: der Kunde trinkt/verzehrt vor Ort (gespeichert `vorOrt`); nur ein Wahrheitswert. */
83
+ onPremises?: boolean;
84
+ /**
85
+ * Gemeinsame Ruecknahmestelle fuer Leergut (gespeichert `pfandStelle`); der Server stempelt sie nur, wenn die
86
+ * Kasse `returns: 'shared'` hat und der Beleg Pfand traegt. Der Bon druckt daraus die Fusszeile.
87
+ */
88
+ sharedReturnPoint?: SharedReturnPoint;
89
+ }
90
+ /** Gemeinsame Ruecknahmestelle fuer Leergut (Name und Anschrift, wie der Server sie am Beleg stempelt). */
91
+ export interface SharedReturnPoint {
92
+ name: string;
93
+ address: string;
82
94
  }
83
95
  /** Registrierdaten von Signaturkarte und Kasse (Zeitstempel oder `null`, wenn unbekannt). */
84
96
  export interface RegistrationInfo {
@@ -131,6 +143,11 @@ export interface ReceiptPayloadRead extends Omit<ReceiptPayload, 'items' | 'vouc
131
143
  cashregisterRegisteredAt?: string | null;
132
144
  } | null;
133
145
  manualReceipt?: unknown;
146
+ onPremises?: boolean | null;
147
+ sharedReturnPoint?: {
148
+ name?: string | null;
149
+ address?: string | null;
150
+ } | null;
134
151
  }
135
152
  /**
136
153
  * Schreibt die Nutzlast in der **neuen** Form — sie **normalisiert, statt zu
@@ -89,8 +89,17 @@ export function fromReceiptPayload(payload) {
89
89
  ? { registrationInfo: readRegistrationInfo(payload.registrationInfo) }
90
90
  : {}),
91
91
  ...handbelegFeld(payload.manualReceipt),
92
+ ...(typeof payload.onPremises === 'boolean' ? { onPremises: payload.onPremises } : {}),
93
+ ...pfandStelleFeld(payload.sharedReturnPoint),
92
94
  };
93
95
  }
96
+ function pfandStelleFeld(roh) {
97
+ if (roh == null || typeof roh !== 'object')
98
+ return {};
99
+ const name = typeof roh.name === 'string' ? roh.name : '';
100
+ const address = typeof roh.address === 'string' ? roh.address : '';
101
+ return name !== '' || address !== '' ? { sharedReturnPoint: { name, address } } : {};
102
+ }
94
103
  function handbelegFeld(roh) {
95
104
  const manualReceipt = readManualReceipt(roh);
96
105
  return manualReceipt ? { manualReceipt } : {};
@@ -1,5 +1,6 @@
1
1
  import type { InternerTransport } from '../client/aufrufe.js';
2
2
  import { type PosReference } from './kachel-referenz.js';
3
+ import { type DepositEntry } from './pfand.js';
3
4
  import { type ArticleExternalVoucher } from './fremdgutschein-artikel.js';
4
5
  /**
5
6
  * Artikelgruppen (Kategorien der Kachel-Kasse) und Artikel in der Form, die
@@ -22,6 +23,11 @@ export interface ArticleGroup {
22
23
  * erst ueber [addOnsFor].
23
24
  */
24
25
  addOns?: string[] | null;
26
+ /**
27
+ * Pfand der Gruppe (Pfand & Leergut): gilt fuer Artikel ohne eigene Liste; null = keines.
28
+ * Optional wie `addOns`, der Leser setzt es immer.
29
+ */
30
+ deposits?: DepositEntry[] | null;
25
31
  }
26
32
  export interface ArticleGroupPayload {
27
33
  id?: string | null;
@@ -31,6 +37,7 @@ export interface ArticleGroupPayload {
31
37
  sort?: number | null;
32
38
  vatRate?: number | null;
33
39
  addOns?: unknown;
40
+ deposits?: unknown;
34
41
  }
35
42
  /** Zusatzliste am Draht: nur eine Liste von Texten zaehlt, sonst null. Paketintern. */
36
43
  export declare function addOnListe(wert: unknown): string[] | null;
@@ -132,6 +139,12 @@ export interface PosArticle {
132
139
  * unbekannter Wert wird null.
133
140
  */
134
141
  externalVoucher?: ArticleExternalVoucher | null;
142
+ /**
143
+ * Pfand des Artikels (Pfand & Leergut): `null` = keine eigene Angabe (die Gruppe gilt), `[]` = ausdruecklich
144
+ * ohne Pfand, sonst die Eintraege. Der Server setzt die Pfandzeilen am Beleg daraus (`autoDeposits`). Optional wie
145
+ * `addOns`, der Leser setzt es immer.
146
+ */
147
+ deposits?: DepositEntry[] | null;
135
148
  }
136
149
  /**
137
150
  * Kann die Kachel gebucht werden? Mit festem Preis immer, ohne Preis nur mit
@@ -173,6 +186,7 @@ export interface PosArticlePayload {
173
186
  reference?: unknown;
174
187
  addOns?: unknown;
175
188
  externalVoucher?: unknown;
189
+ deposits?: unknown;
176
190
  }
177
191
  export declare function fromPosArticlePayload(p: PosArticlePayload): PosArticle;
178
192
  /**
@@ -1,5 +1,6 @@
1
1
  import { KasseneckValidationError } from '../client/errors.js';
2
2
  import { fromReferencePayload } from './kachel-referenz.js';
3
+ import { depositEntriesFromWire } from './pfand.js';
3
4
  import { isArticleExternalVoucher } from './fremdgutschein-artikel.js';
4
5
  /** Zusatzliste am Draht: nur eine Liste von Texten zaehlt, sonst null. Paketintern. */
5
6
  export function addOnListe(wert) {
@@ -14,6 +15,7 @@ export function fromArticleGroupPayload(p) {
14
15
  sort: typeof p.sort === 'number' ? p.sort : 0,
15
16
  vatRate: typeof p.vatRate === 'number' ? p.vatRate : null,
16
17
  addOns: addOnListe(p.addOns),
18
+ deposits: depositEntriesFromWire(p.deposits),
17
19
  };
18
20
  }
19
21
  /**
@@ -94,6 +96,7 @@ export function fromPosArticlePayload(p) {
94
96
  reference: fromReferencePayload(p.reference),
95
97
  addOns: addOnListe(p.addOns),
96
98
  externalVoucher: isArticleExternalVoucher(p.externalVoucher) ? p.externalVoucher : null,
99
+ deposits: depositEntriesFromWire(p.deposits),
97
100
  };
98
101
  }
99
102
  /**
@@ -9,6 +9,7 @@ export declare function posSettingsFromWire(data: {
9
9
  business?: unknown;
10
10
  device?: unknown;
11
11
  vouchers?: unknown;
12
+ deposit?: unknown;
12
13
  } | null | undefined): PosSettings;
13
14
  /** Betriebsweite Einstellungen schreiben (Recht `layout`); liefert den gemischten Stand. */
14
15
  export declare function setMyPosSettings(transport: InternerTransport, business: Partial<PosBusinessSettings>): Promise<PosBusinessSettings>;
@@ -1,5 +1,6 @@
1
1
  import { KasseneckValidationError } from '../client/errors.js';
2
2
  import { posVoucherSettingsFromWire } from './gutschein.js';
3
+ import { posDepositSettingsFromWire } from './pfand.js';
3
4
  import { checkDiscountPresets, INVALID_DISCOUNT_PRESET } from './rabatt-vorlagen.js';
4
5
  import { POS_BUSINESS_DEFAULTS, POS_DEVICE_DEFAULTS, POS_BUSINESS_VALUES, POS_DEVICE_VALUES, POS_SHORTCUT_ACTIONS, POS_DEVICE_OPTIONAL_FIELDS, POS_BUSINESS_OPTIONAL_FIELDS, POS_BUSINESS_OPTIONAL_CHOICES, POS_BUSINESS_OPTIONAL_LISTS, POS_DEVICE_OPTIONAL_CHOICES, mergePosSettings, posShortcutConflict, _istAltwert0x, _optionalerWert, } from './settings.js';
5
6
  /*
@@ -31,10 +32,12 @@ export async function getPosSettings(transport, options = {}) {
31
32
  }
32
33
  /** `{business, device, vouchers}` einer Antwort, gemischt mit den Standardwerten. */
33
34
  export function posSettingsFromWire(data) {
35
+ const deposit = posDepositSettingsFromWire(data?.deposit);
34
36
  return {
35
37
  vouchers: posVoucherSettingsFromWire(data?.vouchers),
36
38
  business: mergePosSettings(POS_BUSINESS_DEFAULTS, objekt(data?.business)),
37
39
  device: mergePosSettings(POS_DEVICE_DEFAULTS, objekt(data?.device)),
40
+ ...(deposit ? { deposit } : {}),
38
41
  };
39
42
  }
40
43
  /** Betriebsweite Einstellungen schreiben (Recht `layout`); liefert den gemischten Stand. */
@@ -21,7 +21,7 @@ import { KasseneckApiError } from '../client/errors.js';
21
21
  * ueber `KasseneckApiError.code` lesbar; die Kasse braucht dafuer einen
22
22
  * Rueckfallzweig.
23
23
  */
24
- export declare const POS_ERROR_CODES: readonly ["account_not_found", "action_confirmation_required", "admin_required", "after_count_not_permitted", "api_not_approved", "app_check_invalid", "app_check_missing", "article_not_found", "article_not_in_scope", "article_not_tracked", "cash_movement_exceeds_balance", "cashregister_not_assigned", "cashregister_not_found", "cashregister_token_invalid", "cashregister_token_missing", "comment_required", "count_already_voided", "count_not_found", "device_not_found", "dialect_mismatch", "drawer_inactive", "drawer_not_found", "idempotency_conflict", "idempotency_key_required", "internal_translation_error", "invalid_amount", "invalid_cursor", "invalid_denominations", "invalid_discount_preset", "invalid_movement_type", "invalid_quantity", "invalid_serial", "live_not_enabled", "location_inactive", "location_not_found", "logo_invalid", "logo_invalid_type", "logo_too_large", "method_not_allowed", "mfa_required", "module_inactive", "not_found", "not_permitted", "note_required", "password_change_required", "print_job_not_found", "print_layout_failed", "printer_not_found", "recount_exhausted", "register_user_no_business", "register_user_not_allowed", "register_user_not_found", "response_translation_failed", "second_factor_required", "serial_already_counted", "serial_not_allowed", "serial_required", "server_error", "session_expired", "session_other_cashregister", "shift_already_open", "shift_closed", "shift_mode_off", "shift_not_open", "stocktake_closed", "stocktake_closing", "stocktake_not_found", "stocktake_not_open", "tip_payout_exceeds_claim", "too_many_counts", "transfer_same_drawer", "unauthorized", "user_disabled", "user_verification_failed", "validation", "route_missing"];
24
+ export declare const POS_ERROR_CODES: readonly ["account_not_found", "action_confirmation_required", "admin_required", "after_count_not_permitted", "api_not_approved", "app_check_invalid", "app_check_missing", "article_not_found", "article_not_in_scope", "article_not_tracked", "cash_movement_exceeds_balance", "cashregister_not_assigned", "cashregister_not_found", "cashregister_token_invalid", "cashregister_token_missing", "comment_required", "count_already_voided", "count_not_found", "deposit_follows_item", "deposit_not_enabled", "deposit_return_not_offered", "deposit_set_by_server", "deposit_type_in_use", "deposit_type_not_found", "deposit_type_not_issued", "device_not_found", "dialect_mismatch", "drawer_inactive", "drawer_not_found", "filler_role_required", "idempotency_conflict", "idempotency_key_required", "internal_translation_error", "invalid_amount", "invalid_cursor", "invalid_denominations", "invalid_deposit", "invalid_deposit_quantity", "invalid_discount_preset", "invalid_item_kind", "invalid_movement_type", "invalid_quantity", "invalid_serial", "live_not_enabled", "location_inactive", "location_not_found", "logo_invalid", "logo_invalid_type", "logo_too_large", "method_not_allowed", "mfa_required", "module_inactive", "not_found", "not_permitted", "note_required", "password_change_required", "print_job_not_found", "print_layout_failed", "printer_not_found", "recount_exhausted", "register_user_no_business", "register_user_not_allowed", "register_user_not_found", "response_translation_failed", "second_factor_required", "serial_already_counted", "serial_not_allowed", "serial_required", "server_error", "session_expired", "session_other_cashregister", "shift_already_open", "shift_closed", "shift_mode_off", "shift_not_open", "stocktake_closed", "stocktake_closing", "stocktake_not_found", "stocktake_not_open", "tip_payout_exceeds_claim", "too_many_counts", "too_many_deposit_types", "transfer_same_drawer", "unauthorized", "user_disabled", "user_verification_failed", "validation", "route_missing"];
25
25
  export type PosErrorCode = typeof POS_ERROR_CODES[number];
26
26
  export declare function isPosErrorCode(value: unknown): value is PosErrorCode;
27
27
  /** Der Code eines geworfenen Fehlers, wenn er in [POS_ERROR_CODES] steht; sonst `undefined`. */
@@ -40,17 +40,28 @@ export const POS_ERROR_CODES = Object.freeze([
40
40
  'comment_required',
41
41
  'count_already_voided',
42
42
  'count_not_found',
43
+ 'deposit_follows_item',
44
+ 'deposit_not_enabled',
45
+ 'deposit_return_not_offered',
46
+ 'deposit_set_by_server',
47
+ 'deposit_type_in_use',
48
+ 'deposit_type_not_found',
49
+ 'deposit_type_not_issued',
43
50
  'device_not_found',
44
51
  'dialect_mismatch',
45
52
  'drawer_inactive',
46
53
  'drawer_not_found',
54
+ 'filler_role_required',
47
55
  'idempotency_conflict',
48
56
  'idempotency_key_required',
49
57
  'internal_translation_error',
50
58
  'invalid_amount',
51
59
  'invalid_cursor',
52
60
  'invalid_denominations',
61
+ 'invalid_deposit',
62
+ 'invalid_deposit_quantity',
53
63
  'invalid_discount_preset',
64
+ 'invalid_item_kind',
54
65
  'invalid_movement_type',
55
66
  'invalid_quantity',
56
67
  'invalid_serial',
@@ -92,6 +103,7 @@ export const POS_ERROR_CODES = Object.freeze([
92
103
  'stocktake_not_open',
93
104
  'tip_payout_exceeds_claim',
94
105
  'too_many_counts',
106
+ 'too_many_deposit_types',
95
107
  'transfer_same_drawer',
96
108
  'unauthorized',
97
109
  'user_disabled',
@@ -17,7 +17,7 @@ export declare const ARTICLE_EXTERNAL_VOUCHER_TYPES: readonly ArticleExternalVou
17
17
  /** Fehlercode beim Speichern eines Artikels, intern und unter `/v3` gleich. */
18
18
  export declare const ARTICLE_EXTERNAL_VOUCHER_INVALID = "article_external_voucher_invalid";
19
19
  /** Welche Regel verletzt ist (Antwortfeld `data.grund`), in der Reihenfolge, in der der Server prueft. */
20
- export declare const EXTERNAL_VOUCHER_ARTICLE_REASONS: readonly ["invalid_type", "service_voucher", "add_ons", "stock_tracked", "reference", "asks_quantity", "rate_required", "invalid_rate", "price_required"];
20
+ export declare const EXTERNAL_VOUCHER_ARTICLE_REASONS: readonly ["invalid_type", "service_voucher", "add_ons", "stock_tracked", "reference", "asks_quantity", "deposit", "rate_required", "invalid_rate", "price_required"];
21
21
  export type ExternalVoucherArticleReason = typeof EXTERNAL_VOUCHER_ARTICLE_REASONS[number];
22
22
  /**
23
23
  * Ein Artikel im Editor (`/v3`-Form), soweit die Regeln ihn lesen. Bewusst
@@ -30,6 +30,7 @@ export interface ExternalVoucherArticleInput {
30
30
  askPrice?: boolean | null;
31
31
  serviceVoucher?: boolean | null;
32
32
  addOns?: readonly unknown[] | null;
33
+ deposits?: readonly unknown[] | null;
33
34
  stockTracked?: boolean | null;
34
35
  reference?: unknown;
35
36
  askQuantity?: boolean | null;
@@ -49,7 +50,7 @@ export declare function checkExternalVoucherValue(value: unknown): ExternalVouch
49
50
  * `pruefeArtikel`: `null` = passt. Ohne `externalVoucher` gilt keine Regel.
50
51
  * Einzweck verlangt einen Satz der Kasse (0 = befreit verkauft), Mehrzweck ignoriert ihn;
51
52
  * nie zusammen mit Leistungsgutschein, eigener Zusatzliste, Lagerbestand,
52
- * Referenz oder Mengenabfrage (die Kasse fragt die Nummer selbst und bucht
53
+ * Referenz, Mengenabfrage oder Pfand (die Kasse fragt die Nummer selbst und bucht
53
54
  * genau einen); ohne `askPrice` braucht er einen Preis ab 1 Cent.
54
55
  */
55
56
  export declare function checkExternalVoucherArticle(a: ExternalVoucherArticleInput): ExternalVoucherArticleReason | null;
@@ -3,7 +3,7 @@ export const ARTICLE_EXTERNAL_VOUCHER_TYPES = Object.freeze(['multi_purpose', 's
3
3
  export const ARTICLE_EXTERNAL_VOUCHER_INVALID = 'article_external_voucher_invalid';
4
4
  /** Welche Regel verletzt ist (Antwortfeld `data.grund`), in der Reihenfolge, in der der Server prueft. */
5
5
  export const EXTERNAL_VOUCHER_ARTICLE_REASONS = Object.freeze([
6
- 'invalid_type', 'service_voucher', 'add_ons', 'stock_tracked', 'reference', 'asks_quantity', 'rate_required', 'invalid_rate', 'price_required',
6
+ 'invalid_type', 'service_voucher', 'add_ons', 'stock_tracked', 'reference', 'asks_quantity', 'deposit', 'rate_required', 'invalid_rate', 'price_required',
7
7
  ]);
8
8
  /**
9
9
  * Saetze, mit denen ein Einzweckgutschein verkauft werden kann (Prozent wie
@@ -24,7 +24,7 @@ export function checkExternalVoucherValue(value) {
24
24
  * `pruefeArtikel`: `null` = passt. Ohne `externalVoucher` gilt keine Regel.
25
25
  * Einzweck verlangt einen Satz der Kasse (0 = befreit verkauft), Mehrzweck ignoriert ihn;
26
26
  * nie zusammen mit Leistungsgutschein, eigener Zusatzliste, Lagerbestand,
27
- * Referenz oder Mengenabfrage (die Kasse fragt die Nummer selbst und bucht
27
+ * Referenz, Mengenabfrage oder Pfand (die Kasse fragt die Nummer selbst und bucht
28
28
  * genau einen); ohne `askPrice` braucht er einen Preis ab 1 Cent.
29
29
  */
30
30
  export function checkExternalVoucherArticle(a) {
@@ -42,6 +42,8 @@ export function checkExternalVoucherArticle(a) {
42
42
  return 'reference';
43
43
  if (a.askQuantity === true)
44
44
  return 'asks_quantity';
45
+ if (Array.isArray(a.deposits) && a.deposits.length > 0)
46
+ return 'deposit';
45
47
  if (a.externalVoucher === 'single_purpose' && !(typeof a.vatRate === 'number' && Number.isFinite(a.vatRate)))
46
48
  return 'rate_required';
47
49
  if (a.externalVoucher === 'single_purpose' && !ARTICLE_EXTERNAL_VOUCHER_VAT_RATES.includes(a.vatRate))
@@ -10,18 +10,20 @@ export { type PosTheme, type PosFontSize, type PosWatermark, type PosQuantity, t
10
10
  export { type ArticleGroup, type ArticleGroupPayload, fromArticleGroupPayload, type PosArticle, type PosArticlePayload, fromPosArticlePayload, listMyArticleGroups, listMyArticles, QUANTITY_RULES, type QuantityRule, type QuantityDefaults, quantityRuleForUnit, quantityDefaults, allowedQuantity, isBookableArticle, tilePrompts, } from './artikel.js';
11
11
  export { REFERENCE_MODES, type ReferenceMode, type PosReference, REFERENCE_INPUT_MAX, REFERENCE_LABEL_MAX, REFERENCE_HINT_MAX, REFERENCE_PATTERN_MAX, REFERENCE_PATTERN_TEMPLATES, cleanReferenceText, isValidReferencePattern, isDigitsOnlyPattern, type ReferenceCheckResult, checkReference, referenceLineName, fromReferencePayload, } from './kachel-referenz.js';
12
12
  export { ADD_ONS_MAX, ADD_ON_BLOCK_REASONS, type AddOnBlockReason, isSelectableAddOn, addOnsFor, addOnReferencesValid, addOnsOfItem, addOnRemap, addOnDisplayOrder, orderAddOnLines, } from './zusaetze.js';
13
+ export { DEPOSIT_KINDS, type DepositKind, DEPOSIT_TYPES, type DepositContainerType, DEPOSIT_RETURN_MODES, type DepositReturnMode, DEPOSIT_ON_PREMISES_DEFAULTS, type DepositOnPremisesDefault, type DepositAmount, type DepositType, type DepositSettings, type DepositEntry, type DepositSharedReturnPoint, type CashRegisterDeposit, posDepositSettingsFromWire, depositEntriesFromWire, cashRegisterDepositFromWire, depositsFor, depositAmountOn, viennaDay, withDepositLines, depositReturnLine, type DepositPreviewItem, type DepositPreviewLine, type DepositPreviewInput, type DepositPreviewArticle, type DepositPreviewResult, type DepositPreviewErrorCode, } from './pfand.js';
13
14
  export { ARTICLE_EXTERNAL_VOUCHER_TYPES, type ArticleExternalVoucher, ARTICLE_EXTERNAL_VOUCHER_INVALID, ARTICLE_EXTERNAL_VOUCHER_VAT_RATES, EXTERNAL_VOUCHER_ARTICLE_REASONS, type ExternalVoucherArticleReason, type ExternalVoucherArticleInput, isArticleExternalVoucher, checkExternalVoucherValue, checkExternalVoucherArticle, type ExternalVoucherTileBlock, externalVoucherTileBlock, } from './fremdgutschein-artikel.js';
14
15
  export { ownVoucherCodeShape, OWN_VOUCHER_CODE_SHAPES, type OwnVoucherCodeShape } from '../models/voucher.js';
15
16
  export { getPosSettings, setMyPosSettings, setMyRegisterDeviceSettings, setMyPosLogo, posSettingsFromWire, type SetMyPosLogoOptions, } from './client.js';
16
17
  export { POS_ERROR_CODES, type PosErrorCode, isPosErrorCode, posErrorCode, isPosError, type PosFieldError, posFieldErrors, } from './errors.js';
17
18
  export { distributeDiscount } from '../receipt/discount.js';
18
- export { cancelScopeOf, receiptsScopeOf, stockViewOf, voucherPermsOf, type VoucherPerms, type RegisterScope, type RegisterUserPerms } from '../register/pairing.js';
19
+ export { cancelScopeOf, receiptsScopeOf, stockViewOf, voucherPermsOf, depositReturnOf, type VoucherPerms, type RegisterScope, type RegisterUserPerms } from '../register/pairing.js';
19
20
  export { type NetworkPrinter, type PrintJob, type PrintJobStatus, PRINT_JOB_STATUSES, type PrintJobSource, PRINT_JOB_SOURCES, isPrintJobFinished, type CreatePrintJobOptions, listMyPrinters, createPrintJob, getPrintJob, } from './drucker.js';
20
21
  export { listMyTipRecipients } from './trinkgeld.js';
21
22
  export { posDiscountPresets, discountPresetChipText, discountChipsFromPresets, checkDiscountPresets, discountBlockLines, INVALID_DISCOUNT_PRESET, DISCOUNT_PRESETS_MAX, DISCOUNT_PRESET_NAME_MAX, DISCOUNT_PRESET_PERCENT_BP, DISCOUNT_PRESET_AMOUNT_CENTS, DISCOUNT_PRESET_MESSAGES, type DiscountPresetReason, type DiscountPresetError, type DiscountPresetsCheck, type DiscountBlockLine, type DiscountTotal, } from './rabatt-vorlagen.js';
22
23
  export { depFolderName } from './dep.js';
23
24
  export { type RegisterInspectionInfo, type RegisterInspectionSignature, type InspectionSignatureStatus, type InspectionInfoRow, type InspectionInfoRowKey, type InspectionInfoSection, type InspectionInfoLinesOptions, getRegisterInspectionInfo, inspectionInfoRows, inspectionInfoLines, } from './kasseninfo.js';
24
25
  export { type ConnectStateReport, reportConnectState } from './connect-bestand.js';
26
+ export { type ReturnCode, type ReturnCodeEntry, type ReturnCodeMatch, type ReturnCodeArticle, type ReturnCodeGroup, type ReturnCodeInput, learnReturnCode, listReturnCodes, matchReturnCode, } from './leergut.js';
25
27
  export { STOCK_LOCATION_TYPES, type StockLocationType, type StockLocation, type StockLocationAddress, type StockLevel, type StockValue, type StockList, type ListMyStockOptions, type SetMyCashregisterStockLocationOptions, type CashregisterStockLocation, listMyStockLocations, listMyStock, setMyCashregisterStockLocation, } from './lager.js';
26
28
  export { type ListMyStocktakesOptions, type ListMyStocktakeItemsOptions, type ListMyStocktakeCountsOptions, type RecordMyStocktakeCountOptions, type VoidMyStocktakeCountOptions, listMyStocktakes, listMyStocktakeItems, listMyStocktakeCounts, recordMyStocktakeCount, voidMyStocktakeCount, parseQuantityMilli, } from './inventur.js';
27
29
  export type { Stocktake, StocktakeItem, StocktakeCount, StocktakeCountResult, StocktakeItemPage, StocktakeCountPage, StocktakeActor, StocktakeProgress, StocktakeReview, StocktakeRecount, StocktakeScope, } from '../inventory/typen.js';
@@ -32,5 +34,5 @@ export { EUR_DENOMINATIONS, MOVEMENT_TYPES, MANUAL_MOVEMENT_TYPES, CASH_LOCATION
32
34
  export { type ShiftReceiptLayoutOptions, shiftReceiptLayout, cashMovementLayout } from '../receipt/shift-sheet.js';
33
35
  export { RECEIPT_OUTPUT_KINDS, RECEIPT_OUTPUT_RESULTS, type ReceiptOutputKind, type ReceiptOutputResult } from '../models/receipt-output.js';
34
36
  export { RETURN_DISPOSITIONS, isReturnDisposition, type ReturnDisposition } from '../models/cancellation.js';
35
- export { MESSAGES, ERROR_RULES, ERROR_CODE_RULES, ERROR_OUTCOME_RULES, CALLS_WITH_EFFECT, findErrorRule, messageOutcome, messageText, messageAppliesTo, RECEIPT_EMAIL_ERROR_MESSAGES, receiptEmailErrorMessage, CANCELLATION_PAYMENT_ERROR_MESSAGES, cancellationPaymentErrorMessage, CANCELLATION_VOUCHER_ERROR_MESSAGES, cancellationErrorMessage, VOUCHER_ERROR_MESSAGES, voucherErrorMessage, EXTERNAL_VOUCHER_TILE_MESSAGES, EXTERNAL_VOUCHER_ARTICLE_MESSAGES, externalVoucherArticleErrorMessage, EXTERNAL_VOUCHERS_LABELS, EXTERNAL_VOUCHER_KIND_LABELS, TIP_KEPT_MODE_LABELS, LABELS, labelText, RETURN_DISPOSITION_LABELS, receiptOutputLabel, type TextEntry, type MessageKey, type ErrorKind, type ErrorRule, type ErrorRuleDetail, type Surface, type ReceiptEmailMessageCode, type CancellationPaymentMessageCode, type LabelKey, } from './texte.js';
37
+ export { MESSAGES, ERROR_RULES, ERROR_CODE_RULES, ERROR_OUTCOME_RULES, CALLS_WITH_EFFECT, findErrorRule, messageOutcome, messageText, messageAppliesTo, RECEIPT_EMAIL_ERROR_MESSAGES, receiptEmailErrorMessage, CANCELLATION_PAYMENT_ERROR_MESSAGES, cancellationPaymentErrorMessage, CANCELLATION_VOUCHER_ERROR_MESSAGES, cancellationErrorMessage, VOUCHER_ERROR_MESSAGES, voucherErrorMessage, DEPOSIT_ERROR_MESSAGES, depositErrorMessage, EXTERNAL_VOUCHER_TILE_MESSAGES, EXTERNAL_VOUCHER_ARTICLE_MESSAGES, externalVoucherArticleErrorMessage, EXTERNAL_VOUCHERS_LABELS, EXTERNAL_VOUCHER_KIND_LABELS, TIP_KEPT_MODE_LABELS, LABELS, labelText, RETURN_DISPOSITION_LABELS, receiptOutputLabel, type TextEntry, type MessageKey, type ErrorKind, type ErrorRule, type ErrorRuleDetail, type Surface, type ReceiptEmailMessageCode, type CancellationPaymentMessageCode, type LabelKey, } from './texte.js';
36
38
  export { roundUpSuggestions } from './aufrunden.js';
@@ -12,6 +12,7 @@ THEME, FONT_SIZE, WATERMARK, QUANTITY, TIP_MODE, TIP_KINDS, TIP_START, TIP_KEPT_
12
12
  export { fromArticleGroupPayload, fromPosArticlePayload, listMyArticleGroups, listMyArticles, QUANTITY_RULES, quantityRuleForUnit, quantityDefaults, allowedQuantity, isBookableArticle, tilePrompts, } from './artikel.js';
13
13
  export { REFERENCE_MODES, REFERENCE_INPUT_MAX, REFERENCE_LABEL_MAX, REFERENCE_HINT_MAX, REFERENCE_PATTERN_MAX, REFERENCE_PATTERN_TEMPLATES, cleanReferenceText, isValidReferencePattern, isDigitsOnlyPattern, checkReference, referenceLineName, fromReferencePayload, } from './kachel-referenz.js';
14
14
  export { ADD_ONS_MAX, ADD_ON_BLOCK_REASONS, isSelectableAddOn, addOnsFor, addOnReferencesValid, addOnsOfItem, addOnRemap, addOnDisplayOrder, orderAddOnLines, } from './zusaetze.js';
15
+ export { DEPOSIT_KINDS, DEPOSIT_TYPES, DEPOSIT_RETURN_MODES, DEPOSIT_ON_PREMISES_DEFAULTS, posDepositSettingsFromWire, depositEntriesFromWire, cashRegisterDepositFromWire, depositsFor, depositAmountOn, viennaDay, withDepositLines, depositReturnLine, } from './pfand.js';
15
16
  export { ARTICLE_EXTERNAL_VOUCHER_TYPES, ARTICLE_EXTERNAL_VOUCHER_INVALID, ARTICLE_EXTERNAL_VOUCHER_VAT_RATES, EXTERNAL_VOUCHER_ARTICLE_REASONS, isArticleExternalVoucher, checkExternalVoucherValue, checkExternalVoucherArticle, externalVoucherTileBlock, } from './fremdgutschein-artikel.js';
16
17
  // Form-Erkennung eigener Codes im Gutschein-Feld (Nachfrage statt Abweisung); dieselbe Funktion wie an der Wurzel.
17
18
  export { ownVoucherCodeShape, OWN_VOUCHER_CODE_SHAPES } from '../models/voucher.js';
@@ -20,7 +21,7 @@ export { POS_ERROR_CODES, isPosErrorCode, posErrorCode, isPosError, posFieldErro
20
21
  export { distributeDiscount } from '../receipt/discount.js';
21
22
  // Reichweiten der Kassen-Rechte (Migration wie im Backend) -- bewusst NICHT im
22
23
  // Register-Unterpfad: dessen Exportnamen sind 1:1 Function-Namen (Rewrites).
23
- export { cancelScopeOf, receiptsScopeOf, stockViewOf, voucherPermsOf } from '../register/pairing.js';
24
+ export { cancelScopeOf, receiptsScopeOf, stockViewOf, voucherPermsOf, depositReturnOf } from '../register/pairing.js';
24
25
  export { PRINT_JOB_STATUSES, PRINT_JOB_SOURCES, isPrintJobFinished, listMyPrinters, createPrintJob, getPrintJob, } from './drucker.js';
25
26
  export { listMyTipRecipients } from './trinkgeld.js';
26
27
  export { posDiscountPresets, discountPresetChipText, discountChipsFromPresets, checkDiscountPresets, discountBlockLines, INVALID_DISCOUNT_PRESET, DISCOUNT_PRESETS_MAX, DISCOUNT_PRESET_NAME_MAX, DISCOUNT_PRESET_PERCENT_BP, DISCOUNT_PRESET_AMOUNT_CENTS, DISCOUNT_PRESET_MESSAGES, } from './rabatt-vorlagen.js';
@@ -30,6 +31,7 @@ export { depFolderName } from './dep.js';
30
31
  export { getRegisterInspectionInfo, inspectionInfoRows, inspectionInfoLines, } from './kasseninfo.js';
31
32
  // Connect-Bestand: die Kasse meldet Version und System von Kasseneck Connect.
32
33
  export { reportConnectState } from './connect-bestand.js';
34
+ export { learnReturnCode, listReturnCodes, matchReturnCode, } from './leergut.js';
33
35
  export { STOCK_LOCATION_TYPES, listMyStockLocations, listMyStock, setMyCashregisterStockLocation, } from './lager.js';
34
36
  export { listMyStocktakes, listMyStocktakeItems, listMyStocktakeCounts, recordMyStocktakeCount, voidMyStocktakeCount, parseQuantityMilli, } from './inventur.js';
35
37
  // Gutschein pruefen und Etikett nachdrucken an der Kasse; Gutschein-Sorten (Stufe 4b, 1.17.0).
@@ -43,5 +45,5 @@ export { RECEIPT_OUTPUT_KINDS, RECEIPT_OUTPUT_RESULTS } from '../models/receipt-
43
45
  // Rueckgabe-Wahl beim Storno (Kassen-Dialog); dieselbe Liste wie an der Wurzel.
44
46
  export { RETURN_DISPOSITIONS, isReturnDisposition } from '../models/cancellation.js';
45
47
  // Was die Kasse selbst sagt: ein Katalog fuer Browser-Kasse und App.
46
- export { MESSAGES, ERROR_RULES, ERROR_CODE_RULES, ERROR_OUTCOME_RULES, CALLS_WITH_EFFECT, findErrorRule, messageOutcome, messageText, messageAppliesTo, RECEIPT_EMAIL_ERROR_MESSAGES, receiptEmailErrorMessage, CANCELLATION_PAYMENT_ERROR_MESSAGES, cancellationPaymentErrorMessage, CANCELLATION_VOUCHER_ERROR_MESSAGES, cancellationErrorMessage, VOUCHER_ERROR_MESSAGES, voucherErrorMessage, EXTERNAL_VOUCHER_TILE_MESSAGES, EXTERNAL_VOUCHER_ARTICLE_MESSAGES, externalVoucherArticleErrorMessage, EXTERNAL_VOUCHERS_LABELS, EXTERNAL_VOUCHER_KIND_LABELS, TIP_KEPT_MODE_LABELS, LABELS, labelText, RETURN_DISPOSITION_LABELS, receiptOutputLabel, } from './texte.js';
48
+ export { MESSAGES, ERROR_RULES, ERROR_CODE_RULES, ERROR_OUTCOME_RULES, CALLS_WITH_EFFECT, findErrorRule, messageOutcome, messageText, messageAppliesTo, RECEIPT_EMAIL_ERROR_MESSAGES, receiptEmailErrorMessage, CANCELLATION_PAYMENT_ERROR_MESSAGES, cancellationPaymentErrorMessage, CANCELLATION_VOUCHER_ERROR_MESSAGES, cancellationErrorMessage, VOUCHER_ERROR_MESSAGES, voucherErrorMessage, DEPOSIT_ERROR_MESSAGES, depositErrorMessage, EXTERNAL_VOUCHER_TILE_MESSAGES, EXTERNAL_VOUCHER_ARTICLE_MESSAGES, externalVoucherArticleErrorMessage, EXTERNAL_VOUCHERS_LABELS, EXTERNAL_VOUCHER_KIND_LABELS, TIP_KEPT_MODE_LABELS, LABELS, labelText, RETURN_DISPOSITION_LABELS, receiptOutputLabel, } from './texte.js';
47
49
  export { roundUpSuggestions } from './aufrunden.js';
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Leergut-Codes an der Kasse (Pfand & Leergut): ein Code, den die Kasse im Leergut-Blatt noch nicht kennt,
3
+ * wird einer Pfandart zugeordnet und gelernt (`learnReturnCode`); `listReturnCodes` liest die gelernten Codes.
4
+ * `matchReturnCode` ist die Regel, mit der ein Scan im Leergut-Blatt einer Pfandart zugeordnet wird – Web-Kasse
5
+ * und Kassen-App (ueber den Dart-Zwilling) benutzen genau diese Regel.
6
+ */
7
+ import type { InternerTransport } from '../client/aufrufe.js';
8
+ import { type DepositEntry, type DepositType } from './pfand.js';
9
+ /** Ein gelernter Leergut-Code: die GTIN und die Pfandart, der sie zugeordnet ist. */
10
+ export interface ReturnCode {
11
+ gtin: string;
12
+ depositTypeId: string;
13
+ }
14
+ /** Eine Zeile der Zuordnung: Pfandart und Stueckzahl, die ein Scan ins Leergut-Blatt bringt. */
15
+ export interface ReturnCodeEntry {
16
+ depositTypeId: string;
17
+ quantity: number;
18
+ }
19
+ /** Ergebnis von `matchReturnCode`: die Eintraege oder `unknown` (Code ist keiner Pfandart zuzuordnen). */
20
+ export type ReturnCodeMatch = {
21
+ entries: ReturnCodeEntry[];
22
+ } | {
23
+ unknown: true;
24
+ };
25
+ /**
26
+ * Lernt einen Leergut-Code (`learnMyLeergutCode`, nur Kassenweg, Recht `depositReturn`): `gtin` muss eine gueltige
27
+ * GTIN sein, `depositTypeId` eine aktive Pfandart. Die Form wird vor dem Senden geprueft; was der Server nicht
28
+ * annimmt, lehnt er mit `invalid_deposit` oder `deposit_type_not_found` ab.
29
+ */
30
+ export declare function learnReturnCode(transport: InternerTransport, code: ReturnCode): Promise<ReturnCode>;
31
+ /** Liest die gelernten Leergut-Codes (`listMyLeergutCodes`, nur Kassenweg): nur aktive Pfandarten, nach GTIN sortiert. */
32
+ export declare function listReturnCodes(transport: InternerTransport): Promise<ReturnCode[]>;
33
+ /** Was `matchReturnCode` von einem Artikel braucht (Teil von `PosArticle`). */
34
+ export interface ReturnCodeArticle {
35
+ groupId?: string | null;
36
+ ean?: string | null;
37
+ number?: string | null;
38
+ internalCode?: string | null;
39
+ deposits?: DepositEntry[] | null;
40
+ externalVoucher?: unknown;
41
+ }
42
+ /** Was `matchReturnCode` von einer Gruppe braucht (Teil von `ArticleGroup`). */
43
+ export interface ReturnCodeGroup {
44
+ id: string;
45
+ deposits?: DepositEntry[] | null;
46
+ }
47
+ export interface ReturnCodeInput {
48
+ articles: ReadonlyArray<ReturnCodeArticle>;
49
+ groups: ReadonlyArray<ReturnCodeGroup>;
50
+ learned: ReadonlyArray<ReturnCode>;
51
+ depositTypes: ReadonlyArray<Pick<DepositType, 'id' | 'active'>>;
52
+ }
53
+ /**
54
+ * Ordnet einen Scan im Leergut-Blatt einer Pfandart zu. Reihenfolge: (1) gelernter Code -> 1 Stueck; (2) `gtin` eines
55
+ * Pfandeintrags an Artikel oder Gruppe -> 1 Stueck dieser Pfandart; (3) Artikel-EAN, -Nummer oder -Code mit wirksamer
56
+ * Pfandliste -> jeder Eintrag mit seiner `quantity` (Kiste: 1 Kiste + 20 Flaschen); sonst `unknown`. Es zaehlen nur
57
+ * aktive Pfandarten: ein Treffer auf eine stillgelegte oder unbekannte Pfandart ist `unknown` (die Suche endet am
58
+ * ersten Treffer, sie faellt nicht auf die naechste Stufe zurueck). Der Code wird getrimmt, ein leerer ist `unknown`.
59
+ */
60
+ export declare function matchReturnCode(code: string, input: ReturnCodeInput): ReturnCodeMatch;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Leergut-Codes an der Kasse (Pfand & Leergut): ein Code, den die Kasse im Leergut-Blatt noch nicht kennt,
3
+ * wird einer Pfandart zugeordnet und gelernt (`learnReturnCode`); `listReturnCodes` liest die gelernten Codes.
4
+ * `matchReturnCode` ist die Regel, mit der ein Scan im Leergut-Blatt einer Pfandart zugeordnet wird – Web-Kasse
5
+ * und Kassen-App (ueber den Dart-Zwilling) benutzen genau diese Regel.
6
+ */
7
+ import { Gtin } from '@kreiseck/validator';
8
+ import { KasseneckValidationError } from '../client/errors.js';
9
+ import { depositsFor } from './pfand.js';
10
+ const istObjekt = (w) => w !== null && typeof w === 'object' && !Array.isArray(w);
11
+ function leergutCode(wert) {
12
+ if (!istObjekt(wert) || typeof wert['gtin'] !== 'string' || typeof wert['depositTypeId'] !== 'string')
13
+ return null;
14
+ return { gtin: wert['gtin'], depositTypeId: wert['depositTypeId'] };
15
+ }
16
+ /**
17
+ * Lernt einen Leergut-Code (`learnMyLeergutCode`, nur Kassenweg, Recht `depositReturn`): `gtin` muss eine gueltige
18
+ * GTIN sein, `depositTypeId` eine aktive Pfandart. Die Form wird vor dem Senden geprueft; was der Server nicht
19
+ * annimmt, lehnt er mit `invalid_deposit` oder `deposit_type_not_found` ab.
20
+ */
21
+ export async function learnReturnCode(transport, code) {
22
+ const name = 'learnMyLeergutCode';
23
+ const anfrage = (grund) => new KasseneckValidationError(name, grund, 'request');
24
+ if (!istObjekt(code))
25
+ throw anfrage('Anfrage muss ein Objekt sein');
26
+ const fremd = Object.keys(code).find((k) => k !== 'gtin' && k !== 'depositTypeId');
27
+ if (fremd != null)
28
+ throw anfrage(`unbekanntes Feld "${fremd}"`);
29
+ if (typeof code.gtin !== 'string' || !Gtin.isValid(code.gtin))
30
+ throw anfrage('gtin ist keine gueltige GTIN');
31
+ if (typeof code.depositTypeId !== 'string' || code.depositTypeId === '')
32
+ throw anfrage('depositTypeId fehlt');
33
+ const antwort = await transport(name, { gtin: code.gtin, depositTypeId: code.depositTypeId });
34
+ return leergutCode(antwort) ?? { gtin: code.gtin, depositTypeId: code.depositTypeId };
35
+ }
36
+ /** Liest die gelernten Leergut-Codes (`listMyLeergutCodes`, nur Kassenweg): nur aktive Pfandarten, nach GTIN sortiert. */
37
+ export async function listReturnCodes(transport) {
38
+ const antwort = await transport('listMyLeergutCodes', {});
39
+ const liste = istObjekt(antwort) && Array.isArray(antwort['codes']) ? antwort['codes'] : [];
40
+ return liste.map(leergutCode).filter((c) => c != null);
41
+ }
42
+ /**
43
+ * Ordnet einen Scan im Leergut-Blatt einer Pfandart zu. Reihenfolge: (1) gelernter Code -> 1 Stueck; (2) `gtin` eines
44
+ * Pfandeintrags an Artikel oder Gruppe -> 1 Stueck dieser Pfandart; (3) Artikel-EAN, -Nummer oder -Code mit wirksamer
45
+ * Pfandliste -> jeder Eintrag mit seiner `quantity` (Kiste: 1 Kiste + 20 Flaschen); sonst `unknown`. Es zaehlen nur
46
+ * aktive Pfandarten: ein Treffer auf eine stillgelegte oder unbekannte Pfandart ist `unknown` (die Suche endet am
47
+ * ersten Treffer, sie faellt nicht auf die naechste Stufe zurueck). Der Code wird getrimmt, ein leerer ist `unknown`.
48
+ */
49
+ export function matchReturnCode(code, input) {
50
+ const unbekannt = { unknown: true };
51
+ const gesucht = typeof code === 'string' ? code.trim() : '';
52
+ if (gesucht === '')
53
+ return unbekannt;
54
+ const aktiv = new Set(input.depositTypes.filter((t) => t.active).map((t) => t.id));
55
+ const eins = (depositTypeId) => (aktiv.has(depositTypeId) ? { entries: [{ depositTypeId, quantity: 1 }] } : unbekannt);
56
+ const gelernt = input.learned.find((l) => l.gtin === gesucht);
57
+ if (gelernt != null)
58
+ return eins(gelernt.depositTypeId);
59
+ const gruppeVon = (a) => input.groups.find((g) => g.id === a.groupId) ?? null;
60
+ for (const a of input.articles) {
61
+ const hit = (depositsFor(a, gruppeVon(a))).find((d) => d.gtin === gesucht);
62
+ if (hit != null)
63
+ return eins(hit.depositTypeId);
64
+ }
65
+ for (const g of input.groups) {
66
+ const hit = (g.deposits ?? []).find((d) => d.gtin === gesucht);
67
+ if (hit != null)
68
+ return eins(hit.depositTypeId);
69
+ }
70
+ const artikel = input.articles.find((a) => a.ean === gesucht || a.number === gesucht || a.internalCode === gesucht);
71
+ if (artikel == null)
72
+ return unbekannt;
73
+ const liste = depositsFor(artikel, gruppeVon(artikel));
74
+ if (liste.length === 0 || !liste.every((d) => aktiv.has(d.depositTypeId)))
75
+ return unbekannt;
76
+ return { entries: liste.map((d) => ({ depositTypeId: d.depositTypeId, quantity: d.quantity })) };
77
+ }
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Pfand & Leergut an der Kasse: Pfandarten und Einstellungen aus
3
+ * `getKasseSettings` (Block `deposit`), Pfandliste am Artikel und an der
4
+ * Gruppe (`deposits`) und die Pfand-Angaben des Kassenobjekts aus
5
+ * `listRegisterUsersForDevice`. Alles nur Lesen und Schreiben der Formen; die
6
+ * Rechnung (Betrag, Staffel nach Tag) kommt in einem eigenen Modul.
7
+ */
8
+ import type { ReceiptItem } from '../models/receipt-item.js';
9
+ /** Art einer Pfandart: Einweg oder Mehrweg. */
10
+ export declare const DEPOSIT_KINDS: readonly ["single_use", "reusable"];
11
+ export type DepositKind = typeof DEPOSIT_KINDS[number];
12
+ /** Gebindetyp einer Pfandart (frei, nur zur Anzeige). */
13
+ export declare const DEPOSIT_TYPES: readonly ["bottle", "crate", "keg", "cup", "glass", "other"];
14
+ export type DepositContainerType = typeof DEPOSIT_TYPES[number];
15
+ /** Wer nimmt Leergut an der Kasse zurueck: diese Kasse, eine gemeinsame Stelle oder niemand. */
16
+ export declare const DEPOSIT_RETURN_MODES: readonly ["here", "shared", "none"];
17
+ export type DepositReturnMode = typeof DEPOSIT_RETURN_MODES[number];
18
+ /** Vorbelegung, ob Getraenke vor Ort getrunken oder mitgenommen werden. */
19
+ export declare const DEPOSIT_ON_PREMISES_DEFAULTS: readonly ["on_premises", "takeaway", "ask"];
20
+ export type DepositOnPremisesDefault = typeof DEPOSIT_ON_PREMISES_DEFAULTS[number];
21
+ /** Ein Pfandbetrag ab einem Tag (`from`, Wiener Tag `YYYY-MM-DD`), in Cent je Stueck. */
22
+ export interface DepositAmount {
23
+ from: string;
24
+ cents: number;
25
+ }
26
+ /** Eine Pfandart des Betriebs. */
27
+ export interface DepositType {
28
+ id: string;
29
+ kind: DepositKind;
30
+ name: string;
31
+ type: DepositContainerType | null;
32
+ /** Betraege nach Gueltigkeit, wie vom Server geliefert (aufsteigend nach `from`). */
33
+ amounts: DepositAmount[];
34
+ /** Steuersatz in Prozent, mit dem Mehrweg-Leergut zurueckgenommen wird (Rueckgabesatz), oder null (noch nie ausgegeben). */
35
+ returnRate: number | null;
36
+ /** Die Pfandart steht an mindestens einem Artikel oder Beleg. */
37
+ used: boolean;
38
+ active: boolean;
39
+ }
40
+ /** Block `deposit` aus `getKasseSettings`; fehlt bei ausgeschaltetem Pfand. */
41
+ export interface DepositSettings {
42
+ singleUse: boolean;
43
+ reusable: boolean;
44
+ depositTypes: DepositType[];
45
+ }
46
+ /** Eine Pfandangabe an Artikel oder Gruppe (`deposits[]`). */
47
+ export interface DepositEntry {
48
+ depositTypeId: string;
49
+ quantity: number;
50
+ gtin?: string;
51
+ ownFilling?: boolean;
52
+ }
53
+ /** Gemeinsame Rueckgabestelle (Kassen-Pfandangaben). */
54
+ export interface DepositSharedReturnPoint {
55
+ name: string;
56
+ address: string;
57
+ }
58
+ /** Pfand-Angaben des Kassenobjekts aus `listRegisterUsersForDevice`; fehlt bei ausgeschaltetem Pfand. */
59
+ export interface CashRegisterDeposit {
60
+ returns: DepositReturnMode;
61
+ onPremisesDefault: DepositOnPremisesDefault;
62
+ usualQuantity: number;
63
+ sharedReturnPoint: DepositSharedReturnPoint | null;
64
+ }
65
+ /**
66
+ * Den Block `deposit` einer Antwort lesen. Kein Objekt (Pfand aus, alter
67
+ * Server) -> `undefined`: das Feld fehlt dann am Modell, es wird nichts erfunden.
68
+ * Eine Pfandart in unbekannter Form faellt weg.
69
+ */
70
+ export declare function posDepositSettingsFromWire(value: unknown): DepositSettings | undefined;
71
+ /** Die Pfandliste eines Artikels oder einer Gruppe; keine Liste -> `null`, unlesbare Eintraege fallen weg. */
72
+ export declare function depositEntriesFromWire(value: unknown): DepositEntry[] | null;
73
+ /** Die Pfand-Angaben eines Kassenobjekts; fehlt der Block oder ist er unbrauchbar -> `undefined`. */
74
+ export declare function cashRegisterDepositFromWire(value: unknown): CashRegisterDeposit | undefined;
75
+ /** Pfandangaben, wirksam fuer einen Artikel: Artikel vor Gruppe, `[]` = kein Pfand, `null`/fehlend = wie die Gruppe. */
76
+ export declare function depositsFor(article: {
77
+ deposits?: DepositEntry[] | null;
78
+ externalVoucher?: unknown;
79
+ } | null | undefined, group: {
80
+ deposits?: DepositEntry[] | null;
81
+ } | null | undefined): DepositEntry[];
82
+ /** Pfandbetrag in Cent am Wiener Tag `day` (`YYYY-MM-DD`): letzter Eintrag mit `from <= day`, sonst `null`. */
83
+ export declare function depositAmountOn(type: Pick<DepositType, 'amounts'>, day: string): number | null;
84
+ /** Wiener Kalendertag `YYYY-MM-DD` zum Zeitpunkt `nowMs` (nie der UTC-Tag). */
85
+ export declare function viennaDay(nowMs: number): string;
86
+ /** Eine Position des Korbs in der Leitungsform (`amount`/`quantity`, `vat`/`vatRate`, `addOnOf` ...). */
87
+ export type DepositPreviewItem = object | null;
88
+ /** Eine Pfand- oder Leergutzeile in der Leitungsform, wie der Server sie baut. */
89
+ export type DepositPreviewLine = Record<string, unknown>;
90
+ /** Fehlercodes der Vorschau (die /v3-Codes von `createReceipt`). */
91
+ export type DepositPreviewErrorCode = 'invalid_deposit' | 'deposit_set_by_server' | 'deposit_type_not_found' | 'invalid_deposit_quantity' | 'deposit_return_not_offered' | 'deposit_type_not_issued' | 'not_permitted';
92
+ /** Eingabe der Vorschau (ohne die Positionen): was der Server aus Konto, Kasse und Beleg wuesste. */
93
+ export interface DepositPreviewInput {
94
+ /** Pfand zu Artikeln selbst ableiten (`autoDeposits`). */
95
+ auto: boolean;
96
+ articles: ReadonlyMap<string, DepositPreviewArticle> | Readonly<Record<string, DepositPreviewArticle>>;
97
+ groups: ReadonlyMap<string, {
98
+ deposits?: DepositEntry[] | null;
99
+ }> | Readonly<Record<string, {
100
+ deposits?: DepositEntry[] | null;
101
+ }>>;
102
+ depositTypes: ReadonlyMap<string, DepositType> | Readonly<Record<string, DepositType>>;
103
+ /** Wiener Tag des Belegs. */
104
+ day: string;
105
+ /** Vor Ort getrunken: Einweg entfaellt. */
106
+ onPremises: boolean;
107
+ /** Pfand-Angaben der Kasse (nur `returns` zaehlt); ohne Angabe nimmt die Kasse kein Leergut zurueck. */
108
+ cashRegister?: Pick<CashRegisterDeposit, 'returns'> | null;
109
+ smallBusiness: boolean;
110
+ /** Der Benutzer darf Leergut zuruecknehmen (`depositReturnOf`). */
111
+ mayReturn: boolean;
112
+ }
113
+ /** Artikel, soweit die Vorschau ihn liest. */
114
+ export interface DepositPreviewArticle {
115
+ id?: string;
116
+ groupId?: string | null;
117
+ deposits?: DepositEntry[] | null;
118
+ externalVoucher?: unknown;
119
+ }
120
+ export type DepositPreviewResult<T> = {
121
+ ok: true;
122
+ items: T[];
123
+ } | {
124
+ ok: false;
125
+ code: DepositPreviewErrorCode;
126
+ };
127
+ /**
128
+ * Pfand- und Leergutzeilen eines Belegs wie der Server: leitet Pfand zu Artikeln ab (`auto`), prueft ausdrueckliche
129
+ * `deposit`-Zeilen und `deposit_return`-Zeilen und rechnet `addOnOf` und `depositFor` auf die neuen Positionen um.
130
+ * Ohne Pfand-/Leergutzeile und ohne Ableitung kommen die Positionen unveraendert zurueck. Die Fehlercodes sind die
131
+ * von `createReceipt`.
132
+ */
133
+ export declare function withDepositLines<T extends DepositPreviewItem>(items: readonly T[], input: DepositPreviewInput): DepositPreviewResult<T | DepositPreviewLine>;
134
+ /**
135
+ * Die Leergutzeile zu `quantity` Stueck einer Pfandart, wie `withDepositLines` sie fuer eine
136
+ * `deposit_return`-Eingabe baut (fuer die Korb-Vorschau). Wirft, wenn sich keine Zeile ergibt
137
+ * (unbekannte Pfandart, Menge ausserhalb 1 bis 1000, Mehrweg ohne Rueckgabesatz, ungueltige Codes);
138
+ * ob die Kasse Leergut annimmt, prueft der Aufrufer.
139
+ */
140
+ export declare function depositReturnLine(type: DepositType, quantity: number, options: {
141
+ day: string;
142
+ smallBusiness: boolean;
143
+ codes?: Record<string, number>;
144
+ }): ReceiptItem;