@endora-commerce/mod-invoices 0.109.0 → 0.110.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/dist/admin/templates/invoice-puck-config.d.ts.map +1 -1
  2. package/dist/admin/templates/invoice-puck-config.js +220 -135
  3. package/dist/admin/templates/invoice-puck-config.js.map +1 -1
  4. package/dist/backend/entities/invoice-line.entity.d.ts +18 -1
  5. package/dist/backend/entities/invoice-line.entity.d.ts.map +1 -1
  6. package/dist/backend/entities/invoice-line.entity.js +20 -0
  7. package/dist/backend/entities/invoice-line.entity.js.map +1 -1
  8. package/dist/backend/index.d.ts.map +1 -1
  9. package/dist/backend/index.js +19 -3
  10. package/dist/backend/index.js.map +1 -1
  11. package/dist/backend/invoices-prose.d.ts +2 -0
  12. package/dist/backend/invoices-prose.d.ts.map +1 -1
  13. package/dist/backend/invoices-prose.js +2 -0
  14. package/dist/backend/invoices-prose.js.map +1 -1
  15. package/dist/backend/pdf-components/embed-logo-images.d.ts.map +1 -1
  16. package/dist/backend/pdf-components/embed-logo-images.js +2 -15
  17. package/dist/backend/pdf-components/embed-logo-images.js.map +1 -1
  18. package/dist/backend/pdf-components/sections.d.ts.map +1 -1
  19. package/dist/backend/pdf-components/sections.js +3 -1
  20. package/dist/backend/pdf-components/sections.js.map +1 -1
  21. package/dist/backend/plugin.d.ts.map +1 -1
  22. package/dist/backend/plugin.js +2 -1
  23. package/dist/backend/plugin.js.map +1 -1
  24. package/dist/backend/routes.customer.d.ts +3 -3
  25. package/dist/backend/routes.customer.d.ts.map +1 -1
  26. package/dist/backend/routes.customer.js +17 -9
  27. package/dist/backend/routes.customer.js.map +1 -1
  28. package/dist/backend/seeds/generic-invoice-template.d.ts +13 -7
  29. package/dist/backend/seeds/generic-invoice-template.d.ts.map +1 -1
  30. package/dist/backend/seeds/generic-invoice-template.js +34 -22
  31. package/dist/backend/seeds/generic-invoice-template.js.map +1 -1
  32. package/dist/backend/services/auto-issue-reactor.d.ts.map +1 -1
  33. package/dist/backend/services/auto-issue-reactor.js +6 -2
  34. package/dist/backend/services/auto-issue-reactor.js.map +1 -1
  35. package/dist/backend/services/corrective-invoice.d.ts +167 -16
  36. package/dist/backend/services/corrective-invoice.d.ts.map +1 -1
  37. package/dist/backend/services/corrective-invoice.js +389 -52
  38. package/dist/backend/services/corrective-invoice.js.map +1 -1
  39. package/dist/backend/services/invoice-copy-host.service.d.ts.map +1 -1
  40. package/dist/backend/services/invoice-copy-host.service.js +3 -0
  41. package/dist/backend/services/invoice-copy-host.service.js.map +1 -1
  42. package/dist/backend/services/invoice-line-builder.d.ts +4 -0
  43. package/dist/backend/services/invoice-line-builder.d.ts.map +1 -1
  44. package/dist/backend/services/invoice-line-builder.js +1 -0
  45. package/dist/backend/services/invoice-line-builder.js.map +1 -1
  46. package/dist/backend/services/invoice-service.d.ts +27 -4
  47. package/dist/backend/services/invoice-service.d.ts.map +1 -1
  48. package/dist/backend/services/invoice-service.js +69 -12
  49. package/dist/backend/services/invoice-service.js.map +1 -1
  50. package/dist/backend/services/kept-quantities.d.ts +24 -0
  51. package/dist/backend/services/kept-quantities.d.ts.map +1 -0
  52. package/dist/backend/services/kept-quantities.js +32 -0
  53. package/dist/backend/services/kept-quantities.js.map +1 -0
  54. package/dist/backend/services/order-returns-lock.d.ts +19 -0
  55. package/dist/backend/services/order-returns-lock.d.ts.map +1 -0
  56. package/dist/backend/services/order-returns-lock.js +37 -0
  57. package/dist/backend/services/order-returns-lock.js.map +1 -0
  58. package/dist/manifest.d.ts +9 -3
  59. package/dist/manifest.d.ts.map +1 -1
  60. package/dist/migrations/20261108T073244_invoices_invoice_line_kind.d.ts +21 -0
  61. package/dist/migrations/20261108T073244_invoices_invoice_line_kind.d.ts.map +1 -0
  62. package/dist/migrations/20261108T073244_invoices_invoice_line_kind.js +28 -0
  63. package/dist/migrations/20261108T073244_invoices_invoice_line_kind.js.map +1 -0
  64. package/dist/migrations/index.d.ts +2 -1
  65. package/dist/migrations/index.d.ts.map +1 -1
  66. package/dist/migrations/index.js +3 -1
  67. package/dist/migrations/index.js.map +1 -1
  68. package/docs/invoices.md +89 -3
  69. package/i18n/en.json +5 -2
  70. package/i18n/pl.json +5 -2
  71. package/package.json +15 -15
@@ -2,19 +2,31 @@
2
2
  * Seeded generic invoice template (feature 047, US6 / T027). A Puck content
3
3
  * envelope composed of the bounded invoice component set.
4
4
  *
5
- * Props on each node MUST mirror `defaultProps` in
6
- * `admin/.../invoice-puck-config.tsx` so the editor sidebar shows selected
7
- * radios/selects when a template is created from this seed (Puck does not
8
- * re-apply defaultProps onto already-persisted nodes).
5
+ * It is the *Invoice* document type's built-in layout
6
+ * (`document/invoice-document-type.ts`), and the content a template started
7
+ * from it copies. Every prop is spelled out so the editor sidebar shows
8
+ * selected radios/selects (Puck does not re-apply defaultProps onto
9
+ * already-persisted nodes). **Label props are empty** (issues #428, #437): an
10
+ * empty label is drawn in the document's language, and a literal here would
11
+ * be a template prop that wins over it.
9
12
  */
10
13
  export const GENERIC_INVOICE_TEMPLATE_CODE = 'generic';
11
14
  export const GENERIC_INVOICE_TEMPLATE_LANGUAGES = ['pl-PL', 'en-US'];
12
15
  /**
13
- * Bump when the seeded Puck tree shape changes so `ensureGenericSeed` (and the
14
- * matching data migration) refresh the system `generic` row on existing DBs.
16
+ * Bump when the seeded Puck tree changes. It is the envelope's
17
+ * `schema_version`; no stored row is rewritten on it since the seeded
18
+ * `generic` row went with `invoice_templates` (`specs/152-compare-pdf-template/`).
19
+ * Templates already stored are corrected by a migration of the module that
20
+ * owns them, as `document_templates` does for issue #437 (revision 3).
15
21
  */
16
- export const GENERIC_INVOICE_TEMPLATE_SEED_REVISION = 2;
17
- const DEFAULT_FOOTER_TEXT = 'Thank you for your business.\n{{var seller.legalName}} · Tax ID {{var seller.taxId}}';
22
+ export const GENERIC_INVOICE_TEMPLATE_SEED_REVISION = 3;
23
+ /**
24
+ * Empty on purpose (issue #437), like every label below: an empty footer text
25
+ * prints `pdf.footer.default` in the document's language. A literal here is a
26
+ * template prop, and a template prop wins over the translation — which is how
27
+ * a Polish invoice came to say "Thank you for your business."
28
+ */
29
+ const DEFAULT_FOOTER_TEXT = '';
18
30
  function genericTree() {
19
31
  return {
20
32
  root: { props: {} },
@@ -44,10 +56,13 @@ function genericTree() {
44
56
  showSaleDate: true,
45
57
  showPaymentDue: true,
46
58
  showPaymentMethod: true,
47
- labelIssuedAt: 'Issue date',
48
- labelSaleDate: 'Sale date',
49
- labelPaymentDue: 'Payment due',
50
- labelPaymentMethod: 'Payment method',
59
+ // Every label of the layout is empty (issue #437, after #428): the
60
+ // block prints it in the document's language unless a template
61
+ // sets its own.
62
+ labelIssuedAt: '',
63
+ labelSaleDate: '',
64
+ labelPaymentDue: '',
65
+ labelPaymentMethod: '',
51
66
  marginTop: 0,
52
67
  marginBottom: 12,
53
68
  },
@@ -60,8 +75,8 @@ function genericTree() {
60
75
  type: 'invoices.InvoiceParties',
61
76
  props: {
62
77
  id: 'inv-parties',
63
- sellerLabel: 'Seller',
64
- buyerLabel: 'Buyer',
78
+ sellerLabel: '',
79
+ buyerLabel: '',
65
80
  showSellerBank: true,
66
81
  showSellerSwift: true,
67
82
  showBuyerTaxId: true,
@@ -103,7 +118,7 @@ function genericTree() {
103
118
  headerColor: '',
104
119
  borderColor: '#cbd5e1',
105
120
  showTotalRow: true,
106
- totalLabel: 'Total',
121
+ totalLabel: '',
107
122
  marginTop: 0,
108
123
  marginBottom: 12,
109
124
  },
@@ -123,14 +138,11 @@ function genericTree() {
123
138
  showOverpayment: true,
124
139
  showGross: true,
125
140
  showAmountInWords: true,
126
- labelPaid: 'Paid',
127
- labelAmountDue: 'Amount due',
128
- // Empty on purpose (issue #428): the row is labelled in the language
129
- // the amounts are written in — Polish on a Polish invoice —
130
- // unless a template sets its own label.
141
+ labelPaid: '',
142
+ labelAmountDue: '',
131
143
  labelOverpayment: '',
132
- labelGross: 'Total',
133
- labelInWords: 'In words',
144
+ labelGross: '',
145
+ labelInWords: '',
134
146
  marginTop: 0,
135
147
  marginBottom: 16,
136
148
  },
@@ -1 +1 @@
1
- {"version":3,"file":"generic-invoice-template.js","sourceRoot":"","sources":["../../../src/backend/seeds/generic-invoice-template.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,SAAS,CAAC;AACvD,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAErE;;;GAGG;AACH,MAAM,CAAC,MAAM,sCAAsC,GAAG,CAAC,CAAC;AAExD,MAAM,mBAAmB,GACvB,sFAAsF,CAAC;AAEzF,SAAS,WAAW;IAClB,OAAO;QACL,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;QACnB,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,sBAAsB;gBAC5B,KAAK,EAAE;oBACL,EAAE,EAAE,UAAU;oBACd,WAAW,EAAE,KAAK;oBAClB,GAAG,EAAE,EAAE;oBACP,OAAO,EAAE,EAAE;oBACX,KAAK,EAAE,GAAG;oBACV,SAAS,EAAE,EAAE;oBACb,KAAK,EAAE,QAAQ;oBACf,YAAY,EAAE,EAAE;iBACjB;aACF;YACD;gBACE,IAAI,EAAE,wBAAwB;gBAC9B,KAAK,EAAE;oBACL,EAAE,EAAE,YAAY;oBAChB,SAAS,EAAE,EAAE;oBACb,UAAU,EAAE,SAAS;oBACrB,SAAS,EAAE,IAAI;oBACf,KAAK,EAAE,MAAM;oBACb,YAAY,EAAE,IAAI;oBAClB,YAAY,EAAE,IAAI;oBAClB,cAAc,EAAE,IAAI;oBACpB,iBAAiB,EAAE,IAAI;oBACvB,aAAa,EAAE,YAAY;oBAC3B,aAAa,EAAE,WAAW;oBAC1B,eAAe,EAAE,aAAa;oBAC9B,kBAAkB,EAAE,gBAAgB;oBACpC,SAAS,EAAE,CAAC;oBACZ,YAAY,EAAE,EAAE;iBACjB;aACF;YACD;gBACE,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IAC9C,cAAc,EAAE,sCAAsC;IACtD,SAAS,EAAE;QACT,OAAO,EAAE,WAAW,EAAE;QACtB,OAAO,EAAE,WAAW,EAAE;KACvB;CACyB,CAAC"}
1
+ {"version":3,"file":"generic-invoice-template.js","sourceRoot":"","sources":["../../../src/backend/seeds/generic-invoice-template.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,SAAS,CAAC;AACvD,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAErE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sCAAsC,GAAG,CAAC,CAAC;AAExD;;;;;GAKG;AACH,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B,SAAS,WAAW;IAClB,OAAO;QACL,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;QACnB,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,sBAAsB;gBAC5B,KAAK,EAAE;oBACL,EAAE,EAAE,UAAU;oBACd,WAAW,EAAE,KAAK;oBAClB,GAAG,EAAE,EAAE;oBACP,OAAO,EAAE,EAAE;oBACX,KAAK,EAAE,GAAG;oBACV,SAAS,EAAE,EAAE;oBACb,KAAK,EAAE,QAAQ;oBACf,YAAY,EAAE,EAAE;iBACjB;aACF;YACD;gBACE,IAAI,EAAE,wBAAwB;gBAC9B,KAAK,EAAE;oBACL,EAAE,EAAE,YAAY;oBAChB,SAAS,EAAE,EAAE;oBACb,UAAU,EAAE,SAAS;oBACrB,SAAS,EAAE,IAAI;oBACf,KAAK,EAAE,MAAM;oBACb,YAAY,EAAE,IAAI;oBAClB,YAAY,EAAE,IAAI;oBAClB,cAAc,EAAE,IAAI;oBACpB,iBAAiB,EAAE,IAAI;oBACvB,mEAAmE;oBACnE,+DAA+D;oBAC/D,gBAAgB;oBAChB,aAAa,EAAE,EAAE;oBACjB,aAAa,EAAE,EAAE;oBACjB,eAAe,EAAE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C;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,gCAAgC,GAAG;IAC9C,cAAc,EAAE,sCAAsC;IACtD,SAAS,EAAE;QACT,OAAO,EAAE,WAAW,EAAE;QACtB,OAAO,EAAE,WAAW,EAAE;KACvB;CACyB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"auto-issue-reactor.d.ts","sourceRoot":"","sources":["../../../src/backend/services/auto-issue-reactor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAU3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,aAAa,CAAC;IAC/B,cAAc,EAAE,cAAc,CAAC;IAC/B,eAAe,EAAE,cAAc,CAAC;IAChC,wEAAwE;IACxE,eAAe,CAAC,EAAE,sBAAsB,GAAG,SAAS,CAAC;IACrD;;;;OAIG;IACH,GAAG,CAAC,EAAE,eAAe,CAAC;CACvB;AAKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,oBAAoB,GAAG;IAClE,oBAAoB,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3D,CAyFA"}
1
+ {"version":3,"file":"auto-issue-reactor.d.ts","sourceRoot":"","sources":["../../../src/backend/services/auto-issue-reactor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAU3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,aAAa,CAAC;IAC/B,cAAc,EAAE,cAAc,CAAC;IAC/B,eAAe,EAAE,cAAc,CAAC;IAChC,wEAAwE;IACxE,eAAe,CAAC,EAAE,sBAAsB,GAAG,SAAS,CAAC;IACrD;;;;OAIG;IACH,GAAG,CAAC,EAAE,eAAe,CAAC;CACvB;AAKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,oBAAoB,GAAG;IAClE,oBAAoB,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3D,CA6FA"}
@@ -85,11 +85,15 @@ export function createAutoIssueReactor(deps) {
85
85
  // is a presence answer about the whole operation and is re-thrown.
86
86
  rethrowIfModuleDisabled(error);
87
87
  // An order refunded in full before it was invoiced is not invoiced at
88
- // all (owner ruling of 2026-10-24): skipped, and the log says why.
88
+ // all (owner ruling of 2026-10-24), nor is one returned in full
89
+ // (product-owner ruling on F4, review of PR #865): skipped, and the log
90
+ // says why, and which of the two.
89
91
  if (error instanceof HttpError && error.code === ERROR_CODES.INVOICE_ORDER_REFUNDED) {
90
- log('[invoices] the order was not auto-invoiced: its payments were refunded in full', {
92
+ const cause = error.details?.reason;
93
+ log('[invoices] the order was not auto-invoiced: it was refunded or returned in full', {
91
94
  orderId: p.orderId,
92
95
  reason: ERROR_CODES.INVOICE_ORDER_REFUNDED,
96
+ ...(typeof cause === 'string' ? { cause } : {}),
93
97
  });
94
98
  return;
95
99
  }
@@ -1 +1 @@
1
- {"version":3,"file":"auto-issue-reactor.js","sourceRoot":"","sources":["../../../src/backend/services/auto-issue-reactor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC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U,GAAG,IAAI,CAAC,eAAe,CAAC;YACxC,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,sEAAsE;gBACtE,0DAA0D;gBAC1D,GAAG,CAAC,WAAW,EAAE;oBACf,SAAS,EAAE,MAAM,CAAC,EAAE;oBACpB,OAAO,EAAE,CAAC,CAAC,OAAO;oBAClB,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,MAAM,EAAE,WAAW;iBACpB,CAAC,CAAC;gBACH,OAAO;YACT,CAAC;YACD,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS;gBAAE,OAAO;YACxC,IAAI,CAAC,CAAC,MAAM,UAAU,CAAC,kBAAkB,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;gBAAE,OAAO;YAE1E,uEAAuE;YACvE,mEAAmE;YACnE,2CAA2C;YAC3C,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACpD,IAAI,MAAM,CAAC,IAAI;gBAAE,OAAO;YACxB,GAAG,CAAC,WAAW,EAAE;gBACf,SAAS,EAAE,MAAM,CAAC,EAAE;gBACpB,OAAO,EAAE,CAAC,CAAC,OAAO;gBAClB,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,MAAM,EAAE,MAAM,CAAC,MAAM;aACtB,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"auto-issue-reactor.js","sourceRoot":"","sources":["../../../src/backend/services/auto-issue-reactor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EACL,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAsB,MAAM,4BAA4B,CAAC;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AC,eAAe,CAAC;YACxC,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,sEAAsE;gBACtE,0DAA0D;gBAC1D,GAAG,CAAC,WAAW,EAAE;oBACf,SAAS,EAAE,MAAM,CAAC,EAAE;oBACpB,OAAO,EAAE,CAAC,CAAC,OAAO;oBAClB,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,MAAM,EAAE,WAAW;iBACpB,CAAC,CAAC;gBACH,OAAO;YACT,CAAC;YACD,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS;gBAAE,OAAO;YACxC,IAAI,CAAC,CAAC,MAAM,UAAU,CAAC,kBAAkB,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;gBAAE,OAAO;YAE1E,uEAAuE;YACvE,mEAAmE;YACnE,2CAA2C;YAC3C,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACpD,IAAI,MAAM,CAAC,IAAI;gBAAE,OAAO;YACxB,GAAG,CAAC,WAAW,EAAE;gBACf,SAAS,EAAE,MAAM,CAAC,EAAE;gBACpB,OAAO,EAAE,CAAC,CAAC,OAAO;gBAClB,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,MAAM,EAAE,MAAM,CAAC,MAAM;aACtB,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -2,7 +2,8 @@ import type { EntityManager } from '@mikro-orm/postgresql';
2
2
  import type { InvoiceNumberGenerator } from './invoice-number-generator.js';
3
3
  import type { InvoiceAuditRecorder, InvoiceDomainEventEmitter } from './invoice-service.js';
4
4
  import { type LedgerNumberingLookup } from './vendor-number-hold.js';
5
- import type { CorrectiveInvoiceInput, CorrectiveInvoicePort, CorrectiveInvoiceResult } from '@endora-commerce/contracts';
5
+ import type { CorrectionLineBasis, CorrectiveInvoiceInput, CorrectiveInvoicePort, CorrectiveInvoiceResult, SupportedLanguage } from '@endora-commerce/contracts';
6
+ import { type InvoicesTranslate } from '../invoices-prose.js';
6
7
  /** One corrected line's amounts, as the `invoice_lines` columns store them. */
7
8
  export interface CorrectionLineAmounts {
8
9
  gross: string;
@@ -15,13 +16,83 @@ export declare class CorrectionTotalExceedsLinesError extends Error {
15
16
  readonly linesTotal: string;
16
17
  constructor(total: string, linesTotal: string);
17
18
  }
18
- /** A line already credited by an earlier correction of the same invoice, or a line of that invoice. */
19
+ /**
20
+ * A correction asked to credit more goods at one VAT rate than the invoice
21
+ * still charges at that rate (issue #885). Crediting it would take back more
22
+ * VAT than the rate charged.
23
+ */
24
+ export declare class CorrectionExceedsRateRemainingError extends Error {
25
+ readonly taxRate: string;
26
+ readonly remaining: string;
27
+ constructor(taxRate: string, remaining: string);
28
+ }
29
+ /**
30
+ * A correction asked to credit more of an order charge — the delivery or the
31
+ * payment surcharge — than the invoice still charges for it (issue #876).
32
+ */
33
+ export declare class CorrectionExceedsChargeRemainingError extends Error {
34
+ readonly kind: CorrectionChargeKind;
35
+ readonly remaining: string;
36
+ constructor(kind: CorrectionChargeKind, remaining: string);
37
+ }
38
+ /** The order charges a correction may credit (issue #876), named as `invoice_lines.line_kind` names their lines. */
39
+ export type CorrectionChargeKind = 'delivery' | 'payment_surcharge';
40
+ /** One order charge a correction credits (issue #876). */
41
+ export interface CorrectionCharge {
42
+ kind: CorrectionChargeKind;
43
+ /** The gross credited. */
44
+ amount: string | number;
45
+ /** The rate of the invoice line that charged it, as stored (`0.0000` today). */
46
+ rate: string | number;
47
+ /** What the invoice still charges for it: the line's gross less what earlier corrections credited of it. */
48
+ remaining: string;
49
+ }
50
+ /**
51
+ * On a correction, a goods line (one naming an order item) stored with
52
+ * quantity 0 is a price reduction (issue #885): its value changed, not its
53
+ * quantity. Corrections written before #885 never stored a goods line with
54
+ * quantity 0, so the rule holds for the whole history.
55
+ */
56
+ export declare function isPriceReductionLine(l: {
57
+ orderItemId?: string | null;
58
+ quantity: string | number;
59
+ }): boolean;
60
+ /** The units a correction line credits: none for a price reduction. */
61
+ export declare function creditedQuantity(l: {
62
+ orderItemId?: string | null;
63
+ quantity: string | number;
64
+ }): number;
65
+ /**
66
+ * The quantity a correction line is stored with: 0 for a price reduction, the
67
+ * returned quantity otherwise — and never 0 for returned goods, so a returned
68
+ * line is never read back as a price reduction.
69
+ */
70
+ export declare function storedCorrectionQuantity(basis: CorrectionLineBasis | undefined, quantity: number): number;
71
+ /** A line already credited by an earlier correction of the same invoice, or a goods line of that invoice. */
19
72
  export interface CreditedLine {
20
73
  orderItemId: string;
21
74
  rate: string;
22
75
  net: string;
23
76
  gross: string;
77
+ /** As stored. On an earlier correction, 0 is a price reduction ({@link isPriceReductionLine}). */
78
+ quantity: number;
79
+ unitNetPrice: string;
24
80
  }
81
+ /** One row of the corrected invoice's per-rate summary, as `invoices.vat_summary` stores it. */
82
+ export interface CorrectedSummaryRow {
83
+ taxRate: string;
84
+ netTotal: string;
85
+ vatAmount: string;
86
+ grossTotal: string;
87
+ }
88
+ /**
89
+ * How a rate's credited net was found (issue #873). Returned for tests and not
90
+ * persisted: `quantity` — the refund is the default one, and the invoice keeps
91
+ * `vatByRate` of the kept nets; `gross` — what the invoice keeps at the rate
92
+ * has a net under the rule; `gross_credit` — it has none, but the credit does;
93
+ * `gross_nearest` — neither does, so the nearest net is kept.
94
+ */
95
+ export type CorrectionPath = 'quantity' | 'gross' | 'gross_credit' | 'gross_nearest';
25
96
  export interface CorrectionInput {
26
97
  /** The gross the correction credits. Refused when above the sum of `lines`. */
27
98
  total: string | number;
@@ -35,9 +106,11 @@ export interface CorrectionInput {
35
106
  * credited line by line, in proportion to what each line was invoiced.
36
107
  */
37
108
  perRate: boolean;
38
- /** The corrected invoice's lines — read for an invoice issued before the per-rate method. */
109
+ /** The corrected invoice's goods lines, with the quantities and unit prices it invoiced. */
39
110
  originalLines: readonly CreditedLine[];
40
- /** The lines of earlier corrections of the same invoice. */
111
+ /** The corrected invoice's stored per-rate summary — read on an invoice issued per rate. */
112
+ originalSummary?: readonly CorrectedSummaryRow[] | null;
113
+ /** The goods lines of earlier, not cancelled, corrections of the same invoice. */
41
114
  earlierLines: readonly CreditedLine[];
42
115
  lines: ReadonlyArray<{
43
116
  amount: string | number;
@@ -46,12 +119,18 @@ export interface CorrectionInput {
46
119
  quantity: number;
47
120
  rate: string | number;
48
121
  orderItemId: string;
122
+ /** What the line documents (issue #885); `returned_goods` when absent. */
123
+ basis?: CorrectionLineBasis;
49
124
  }>;
125
+ /**
126
+ * Issue #876 — the order charges a consumer's withdrawal refunds, credited
127
+ * beside the goods: `total` includes them. Absent: goods only.
128
+ */
129
+ charges?: readonly CorrectionCharge[];
50
130
  }
51
131
  /**
52
132
  * A correction's amounts, in exact decimal arithmetic, under the invoice's VAT
53
- * method and **cumulatively** over the corrections of one invoice (issue #417,
54
- * owner ruling of 2026-10-24, review of PR #423).
133
+ * method (issue #417, owner ruling of 2026-10-24, review of PR #423).
55
134
  *
56
135
  * The credited amount is gross (a return credits what was paid, tax included),
57
136
  * capped at what remains of the invoice after earlier corrections (FR-020),
@@ -59,15 +138,36 @@ export interface CorrectionInput {
59
138
  * refused ({@link CorrectionTotalExceedsLinesError}) rather than booked as a
60
139
  * net with no VAT and no line.
61
140
  *
62
- * What the invoice charged is split into groups: a VAT rate of an invoice
63
- * issued per rate, a line of one issued before 0.108.0. For each group, the
64
- * correction credits the net of everything credited so far, this correction
65
- * included, minus the nets earlier corrections already credited — per rate the
66
- * net `netForGrossAtRate` gives the cumulative gross (`N` with
67
- * `N + round(N × rate) = gross`), per line the invoiced line net in proportion
68
- * to the cumulative gross. The differences telescope: all corrections together
69
- * credit exactly the invoiced net and VAT. A group's net is shared over the
70
- * correction's lines in it in proportion to their gross (`allocateHalfUp`).
141
+ * **An invoice issued per rate** (issue #873) is corrected on what it keeps,
142
+ * rate by rate. Before the correction the invoice keeps `Nb` net and `Vb` VAT
143
+ * at a rate, `Gb` gross: its summary row less what earlier corrections credited
144
+ * there. The correction credits `G` gross at the rate. Its goods lines leave
145
+ * each invoiced line with a kept quantity — the invoiced quantity less every
146
+ * credited quantity, where a price reduction (issue #885) credits none — and
147
+ * the kept net `K` is those quantities at the invoiced unit prices.
148
+ * - **Quantity path**: when `Gb − G` is `K + round(K × rate)`, the refund is the
149
+ * default one; the invoice keeps `K` net and `round(K × rate)` VAT, exactly
150
+ * what `vatByRate` charges on the kept nets, and the correction credits the
151
+ * rest.
152
+ * - **Gross path** otherwise — an operator-reduced amount, a price reduction, a
153
+ * capped credit, an order placed before 0.108.0: the invoice keeps `Gb − G`
154
+ * gross. When a net has that gross under the rule, the invoice keeps it;
155
+ * otherwise, when one has `G`, the correction credits it; otherwise the
156
+ * invoice keeps the nearest (owner ruling E1, 2026-11-07: the money is exact,
157
+ * and what is left may be a cent off the rule until the next correction).
158
+ *
159
+ * In every case the credited VAT is `G` less the credited net, which lies
160
+ * within `[0, G]` and never above `Nb`; a `G` above `Gb` is refused
161
+ * ({@link CorrectionExceedsRateRemainingError}). On the quantity path a rate's
162
+ * net is shared over its lines by what each line's kept net fell; otherwise in
163
+ * proportion to their gross.
164
+ *
165
+ * **An invoice issued before 0.108.0** is credited line by line, cumulatively:
166
+ * the invoiced line net in proportion to the cumulative gross, less the nets
167
+ * earlier corrections credited.
168
+ *
169
+ * An order-level discount the goods carried is credited back as a negative
170
+ * 0 % amount. A price-reduction line carries none.
71
171
  */
72
172
  export declare function correctionAmounts(input: CorrectionInput): {
73
173
  credited: string;
@@ -83,6 +183,38 @@ export declare function correctionAmounts(input: CorrectionInput): {
83
183
  }>;
84
184
  /** The order-level discount credited back, as a negative 0 % amount (`0.00` when none). */
85
185
  discountCredit: string;
186
+ /** Per rate of an invoice issued per rate, how its net was found. Not persisted. */
187
+ paths: Record<string, CorrectionPath>;
188
+ /** The order charges credited (issue #876), each at its line's rate. */
189
+ chargeLines: Array<{
190
+ kind: CorrectionChargeKind;
191
+ gross: string;
192
+ net: string;
193
+ rate: string;
194
+ }>;
195
+ };
196
+ /**
197
+ * The invoice's delivery and payment-surcharge lines (issue #876), by
198
+ * `line_kind`. A line issued before #904 has none. Issuance has written the
199
+ * delivery before the surcharge, each a positive 0 % line naming no order item,
200
+ * since it first itemised them (`ee860569e`, "itemize delivery, payment
201
+ * surcharge, and discount as lines"), so with two such lines the first is the
202
+ * delivery and the second the surcharge. Only 0 % lines are matched (ruling Q3
203
+ * on PR #965): a positive line at another rate is no charge issuance wrote, so
204
+ * a credit asked of it is refused `no_corrected_line`. With one, it is whichever charge the order had — the settlement
205
+ * names only a charge that was paid, so it never asks for both — and it answers
206
+ * for either. On those invoices both are 0 % lines, so the rate a credit
207
+ * mirrors is the same either way.
208
+ */
209
+ export declare function chargeLinesOf<T extends {
210
+ orderItemId?: string | null;
211
+ lineKind?: string | null;
212
+ grossValue: string;
213
+ taxRate: string;
214
+ ordinal: number;
215
+ }>(lines: readonly T[]): {
216
+ delivery?: T;
217
+ payment_surcharge?: T;
86
218
  };
87
219
  /**
88
220
  * Invoices-side implementation of the returns module's `CorrectiveInvoicePort`
@@ -107,6 +239,14 @@ export declare class CorrectiveInvoiceProvider implements CorrectiveInvoicePort
107
239
  private readonly audit?;
108
240
  private readonly events?;
109
241
  private readonly ledgerRouting?;
242
+ /**
243
+ * The language a price-reduction line is named in, and this module's
244
+ * bundle to name it from (issue #885), as `InvoiceService` names the lines
245
+ * it itemises: the name is stored with the line, so it is written in the
246
+ * document's language, `INVOICE_RENDER_LANGUAGE`. Without a translator,
247
+ * English.
248
+ */
249
+ private readonly lineProse;
110
250
  /**
111
251
  * `numbers` is an accessor for the same reason `emFactory` is: the generator
112
252
  * is a gated port, so resolving it is a question about `invoices`' effective
@@ -114,7 +254,18 @@ export declare class CorrectiveInvoiceProvider implements CorrectiveInvoicePort
114
254
  * resolved it while wiring this provider asked at boot, and an operator who
115
255
  * had switched `invoices` off took the backend down with it.
116
256
  */
117
- constructor(emFactory: () => EntityManager, numbers?: (() => InvoiceNumberGenerator) | undefined, audit?: InvoiceAuditRecorder | undefined, events?: InvoiceDomainEventEmitter | undefined, ledgerRouting?: LedgerNumberingLookup | undefined);
257
+ constructor(emFactory: () => EntityManager, numbers?: (() => InvoiceNumberGenerator) | undefined, audit?: InvoiceAuditRecorder | undefined, events?: InvoiceDomainEventEmitter | undefined, ledgerRouting?: LedgerNumberingLookup | undefined,
258
+ /**
259
+ * The language a price-reduction line is named in, and this module's
260
+ * bundle to name it from (issue #885), as `InvoiceService` names the lines
261
+ * it itemises: the name is stored with the line, so it is written in the
262
+ * document's language, `INVOICE_RENDER_LANGUAGE`. Without a translator,
263
+ * English.
264
+ */
265
+ lineProse?: {
266
+ readonly translate?: InvoicesTranslate | undefined;
267
+ readonly language?: SupportedLanguage;
268
+ });
118
269
  /**
119
270
  * Refuse, without writing anything, exactly what {@link createCorrection}
120
271
  * would refuse for this input (issue #417, review of PR #423): a settlement
@@ -1 +1 @@
1
- {"version":3,"file":"corrective-invoice.d.ts","sourceRoot":"","sources":["../../../src/backend/services/corrective-invoice.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAiB3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAC5F,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,yBAAyB,CAAC;AAMjC,OAAO,KAAK,EACV,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,4BAA4B,CAAC;AAOpC,+EAA+E;AAC/E,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,sFAAsF;AACtF,qBAAa,gCAAiC,SAAQ,KAAK;IAEvD,QAAQ,CAAC,KAAK,EAAE,MAAM;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM;gBADlB,KAAK,EAAE,MAAM,EACb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