@endora-commerce/mod-invoices 0.107.0 → 0.109.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.
- package/dist/admin/pages/InvoiceDetail.d.ts.map +1 -1
- package/dist/admin/pages/InvoiceDetail.js +3 -1
- package/dist/admin/pages/InvoiceDetail.js.map +1 -1
- package/dist/admin/templates/invoice-puck-config.d.ts.map +1 -1
- package/dist/admin/templates/invoice-puck-config.js +14 -2
- package/dist/admin/templates/invoice-puck-config.js.map +1 -1
- package/dist/backend/document/block-descriptions.d.ts.map +1 -1
- package/dist/backend/document/block-descriptions.js +2 -0
- package/dist/backend/document/block-descriptions.js.map +1 -1
- package/dist/backend/document/invoice-document-type.d.ts +6 -1
- package/dist/backend/document/invoice-document-type.d.ts.map +1 -1
- package/dist/backend/document/invoice-document-type.js +25 -1
- package/dist/backend/document/invoice-document-type.js.map +1 -1
- package/dist/backend/entities/invoice.entity.d.ts +13 -0
- package/dist/backend/entities/invoice.entity.d.ts.map +1 -1
- package/dist/backend/entities/invoice.entity.js +10 -0
- package/dist/backend/entities/invoice.entity.js.map +1 -1
- package/dist/backend/index.d.ts.map +1 -1
- package/dist/backend/index.js +53 -8
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/invoices-prose.d.ts +63 -0
- package/dist/backend/invoices-prose.d.ts.map +1 -0
- package/dist/backend/invoices-prose.js +78 -0
- package/dist/backend/invoices-prose.js.map +1 -0
- package/dist/backend/pdf-components/sample.d.ts.map +1 -1
- package/dist/backend/pdf-components/sample.js +1 -0
- package/dist/backend/pdf-components/sample.js.map +1 -1
- package/dist/backend/pdf-components/sections.d.ts +29 -7
- package/dist/backend/pdf-components/sections.d.ts.map +1 -1
- package/dist/backend/pdf-components/sections.js +78 -38
- package/dist/backend/pdf-components/sections.js.map +1 -1
- package/dist/backend/pdf-components/tree-mapper.d.ts +3 -0
- package/dist/backend/pdf-components/tree-mapper.d.ts.map +1 -1
- package/dist/backend/pdf-components/tree-mapper.js +5 -5
- package/dist/backend/pdf-components/tree-mapper.js.map +1 -1
- package/dist/backend/plugin.d.ts +15 -1
- package/dist/backend/plugin.d.ts.map +1 -1
- package/dist/backend/plugin.js +3 -2
- package/dist/backend/plugin.js.map +1 -1
- package/dist/backend/seeds/generic-invoice-template.d.ts.map +1 -1
- package/dist/backend/seeds/generic-invoice-template.js +5 -0
- package/dist/backend/seeds/generic-invoice-template.js.map +1 -1
- package/dist/backend/services/auto-issue-reactor.d.ts.map +1 -1
- package/dist/backend/services/auto-issue-reactor.js +11 -0
- package/dist/backend/services/auto-issue-reactor.js.map +1 -1
- package/dist/backend/services/corrective-invoice.d.ts +90 -0
- package/dist/backend/services/corrective-invoice.d.ts.map +1 -1
- package/dist/backend/services/corrective-invoice.js +275 -63
- package/dist/backend/services/corrective-invoice.js.map +1 -1
- package/dist/backend/services/cross-module-context.d.ts +7 -0
- package/dist/backend/services/cross-module-context.d.ts.map +1 -1
- package/dist/backend/services/cross-module-context.js +19 -0
- package/dist/backend/services/cross-module-context.js.map +1 -1
- package/dist/backend/services/invoice-email-dispatch.d.ts +7 -0
- package/dist/backend/services/invoice-email-dispatch.d.ts.map +1 -1
- package/dist/backend/services/invoice-email-dispatch.js +10 -3
- package/dist/backend/services/invoice-email-dispatch.js.map +1 -1
- package/dist/backend/services/invoice-line-builder.d.ts +63 -13
- package/dist/backend/services/invoice-line-builder.d.ts.map +1 -1
- package/dist/backend/services/invoice-line-builder.js +79 -28
- package/dist/backend/services/invoice-line-builder.js.map +1 -1
- package/dist/backend/services/invoice-paid.d.ts +56 -0
- package/dist/backend/services/invoice-paid.d.ts.map +1 -0
- package/dist/backend/services/invoice-paid.js +74 -0
- package/dist/backend/services/invoice-paid.js.map +1 -0
- package/dist/backend/services/invoice-service.d.ts +43 -2
- package/dist/backend/services/invoice-service.d.ts.map +1 -1
- package/dist/backend/services/invoice-service.js +115 -56
- package/dist/backend/services/invoice-service.js.map +1 -1
- package/dist/manifest.d.ts +3 -1
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js +34 -6
- package/dist/manifest.js.map +1 -1
- package/dist/migrations/20261024T145631_invoices_vat_summary.d.ts +18 -0
- package/dist/migrations/20261024T145631_invoices_vat_summary.d.ts.map +1 -0
- package/dist/migrations/20261024T145631_invoices_vat_summary.js +22 -0
- package/dist/migrations/20261024T145631_invoices_vat_summary.js.map +1 -0
- package/dist/migrations/index.d.ts +2 -1
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +3 -1
- package/dist/migrations/index.js.map +1 -1
- package/docs/invoices.md +45 -0
- package/i18n/en.json +38 -1
- package/i18n/pl.json +38 -1
- package/package.json +14 -14
|
@@ -2,6 +2,8 @@ import { z } from 'zod';
|
|
|
2
2
|
import { Invoice } from '../entities/invoice.entity.js';
|
|
3
3
|
import { rethrowIfModuleDisabled } from '@endora-commerce/platform/kernel';
|
|
4
4
|
import { SettingNotRegistered, SettingOutOfScopeForChannel, } from '@endora-commerce/platform/kernel';
|
|
5
|
+
import { ERROR_CODES } from '@endora-commerce/contracts';
|
|
6
|
+
import { HttpError } from '@endora-commerce/platform/http';
|
|
5
7
|
import { INVOICES_SETTING_CODES } from '../../manifest.js';
|
|
6
8
|
/** The message every non-delivery below is written under. */
|
|
7
9
|
const NOT_EMAILED = '[invoices] the auto-issued invoice was not e-mailed';
|
|
@@ -82,6 +84,15 @@ export function createAutoIssueReactor(deps) {
|
|
|
82
84
|
// not take the subscriber down. A switched-off module is not that — it
|
|
83
85
|
// is a presence answer about the whole operation and is re-thrown.
|
|
84
86
|
rethrowIfModuleDisabled(error);
|
|
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.
|
|
89
|
+
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', {
|
|
91
|
+
orderId: p.orderId,
|
|
92
|
+
reason: ERROR_CODES.INVOICE_ORDER_REFUNDED,
|
|
93
|
+
});
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
85
96
|
log('[invoices] the order was not auto-invoiced', {
|
|
86
97
|
orderId: p.orderId,
|
|
87
98
|
error: error instanceof Error ? error.message : error,
|
|
@@ -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;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;
|
|
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;AAC7E,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAI3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAgB3D,6DAA6D;AAC7D,MAAM,WAAW,GAAG,qDAAqD,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAA0B;IAG/D,MAAM,GAAG,GAAoB,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,OAAO,EAAE,OAAO,EAAQ,EAAE,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AM,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"}
|
|
@@ -3,6 +3,87 @@ 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
5
|
import type { CorrectiveInvoiceInput, CorrectiveInvoicePort, CorrectiveInvoiceResult } from '@endora-commerce/contracts';
|
|
6
|
+
/** One corrected line's amounts, as the `invoice_lines` columns store them. */
|
|
7
|
+
export interface CorrectionLineAmounts {
|
|
8
|
+
gross: string;
|
|
9
|
+
net: string;
|
|
10
|
+
unitNetPrice: string;
|
|
11
|
+
}
|
|
12
|
+
/** A correction asked to credit more than its lines add up to (review of PR #423). */
|
|
13
|
+
export declare class CorrectionTotalExceedsLinesError extends Error {
|
|
14
|
+
readonly total: string;
|
|
15
|
+
readonly linesTotal: string;
|
|
16
|
+
constructor(total: string, linesTotal: string);
|
|
17
|
+
}
|
|
18
|
+
/** A line already credited by an earlier correction of the same invoice, or a line of that invoice. */
|
|
19
|
+
export interface CreditedLine {
|
|
20
|
+
orderItemId: string;
|
|
21
|
+
rate: string;
|
|
22
|
+
net: string;
|
|
23
|
+
gross: string;
|
|
24
|
+
}
|
|
25
|
+
export interface CorrectionInput {
|
|
26
|
+
/** The gross the correction credits. Refused when above the sum of `lines`. */
|
|
27
|
+
total: string | number;
|
|
28
|
+
/** The corrected invoice's gross. */
|
|
29
|
+
originalGross: string;
|
|
30
|
+
/** What earlier corrections of the same invoice already credited, gross. */
|
|
31
|
+
creditedBefore?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Whether the corrected invoice was issued under the per-rate VAT method
|
|
34
|
+
* (it stored its summary); otherwise it was issued before 0.108.0 and is
|
|
35
|
+
* credited line by line, in proportion to what each line was invoiced.
|
|
36
|
+
*/
|
|
37
|
+
perRate: boolean;
|
|
38
|
+
/** The corrected invoice's lines — read for an invoice issued before the per-rate method. */
|
|
39
|
+
originalLines: readonly CreditedLine[];
|
|
40
|
+
/** The lines of earlier corrections of the same invoice. */
|
|
41
|
+
earlierLines: readonly CreditedLine[];
|
|
42
|
+
lines: ReadonlyArray<{
|
|
43
|
+
amount: string | number;
|
|
44
|
+
/** The part of the order-level discount `amount` carries: the goods are credited at `amount + discount`. */
|
|
45
|
+
discount?: string | number;
|
|
46
|
+
quantity: number;
|
|
47
|
+
rate: string | number;
|
|
48
|
+
orderItemId: string;
|
|
49
|
+
}>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 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).
|
|
55
|
+
*
|
|
56
|
+
* The credited amount is gross (a return credits what was paid, tax included),
|
|
57
|
+
* capped at what remains of the invoice after earlier corrections (FR-020),
|
|
58
|
+
* and shared out over the lines in order; a total above the lines' sum is
|
|
59
|
+
* refused ({@link CorrectionTotalExceedsLinesError}) rather than booked as a
|
|
60
|
+
* net with no VAT and no line.
|
|
61
|
+
*
|
|
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`).
|
|
71
|
+
*/
|
|
72
|
+
export declare function correctionAmounts(input: CorrectionInput): {
|
|
73
|
+
credited: string;
|
|
74
|
+
netTotal: string;
|
|
75
|
+
taxTotal: string;
|
|
76
|
+
lines: CorrectionLineAmounts[];
|
|
77
|
+
/** The correction's per-rate summary, as `invoices.vat_summary` stores it. */
|
|
78
|
+
vatSummary: Array<{
|
|
79
|
+
taxRate: string;
|
|
80
|
+
netTotal: string;
|
|
81
|
+
vatAmount: string;
|
|
82
|
+
grossTotal: string;
|
|
83
|
+
}>;
|
|
84
|
+
/** The order-level discount credited back, as a negative 0 % amount (`0.00` when none). */
|
|
85
|
+
discountCredit: string;
|
|
86
|
+
};
|
|
6
87
|
/**
|
|
7
88
|
* Invoices-side implementation of the returns module's `CorrectiveInvoicePort`
|
|
8
89
|
* (feature 046 / 047 US3). Creates an `invoices` row of kind `correction`:
|
|
@@ -20,6 +101,7 @@ import type { CorrectiveInvoiceInput, CorrectiveInvoicePort, CorrectiveInvoiceRe
|
|
|
20
101
|
* existed.
|
|
21
102
|
*/
|
|
22
103
|
export declare class CorrectiveInvoiceProvider implements CorrectiveInvoicePort {
|
|
104
|
+
#private;
|
|
23
105
|
private readonly emFactory;
|
|
24
106
|
private readonly numbers?;
|
|
25
107
|
private readonly audit?;
|
|
@@ -33,6 +115,14 @@ export declare class CorrectiveInvoiceProvider implements CorrectiveInvoicePort
|
|
|
33
115
|
* had switched `invoices` off took the backend down with it.
|
|
34
116
|
*/
|
|
35
117
|
constructor(emFactory: () => EntityManager, numbers?: (() => InvoiceNumberGenerator) | undefined, audit?: InvoiceAuditRecorder | undefined, events?: InvoiceDomainEventEmitter | undefined, ledgerRouting?: LedgerNumberingLookup | undefined);
|
|
118
|
+
/**
|
|
119
|
+
* Refuse, without writing anything, exactly what {@link createCorrection}
|
|
120
|
+
* would refuse for this input (issue #417, review of PR #423): a settlement
|
|
121
|
+
* asks before it moves any money, so a correction that cannot be made never
|
|
122
|
+
* follows a refund that was. An order with no invoice is not a refusal — its
|
|
123
|
+
* settlement records the refund without a document.
|
|
124
|
+
*/
|
|
125
|
+
validateCorrection(input: CorrectiveInvoiceInput): Promise<void>;
|
|
36
126
|
createCorrection(input: CorrectiveInvoiceInput): Promise<CorrectiveInvoiceResult>;
|
|
37
127
|
}
|
|
38
128
|
//# sourceMappingURL=corrective-invoice.d.ts.map
|
|
@@ -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;
|
|
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;gBAD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AA2F;IAC3F,cAAc,EAAE,MAAM,CAAC;CACxB,CA6GA;AAmCD;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,yBAA0B,YAAW,qBAAqB;;IASnE,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IACxB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC;IAZjC;;;;;;OAMG;gBAEgB,SAAS,EAAE,MAAM,aAAa,EAC9B,OAAO,CAAC,GAAE,MAAM,sBAAsB,aAAA,EACtC,KAAK,CAAC,EAAE,oBAAoB,YAAA,EAC5B,MAAM,CAAC,EAAE,yBAAyB,YAAA,EAClC,aAAa,CAAC,EAAE,qBAAqB,YAAA;IAGxD;;;;;;OAMG;IACG,kBAAkB,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAoHhE,gBAAgB,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,uBAAuB,CAAC;CA2JxF"}
|
|
@@ -1,13 +1,153 @@
|
|
|
1
1
|
import { randomUUID } from 'crypto';
|
|
2
|
-
import { ERROR_CODES } from '@endora-commerce/contracts';
|
|
2
|
+
import { ERROR_CODES, compareDecimals, allocateHalfUp, decimalDifference, decimalProduct, moneyDifference, moneySum, netForGrossAtRate, netFromGrossHalfUp, quotientHalfUp, roundHalfUp, } from '@endora-commerce/contracts';
|
|
3
3
|
import { HttpError } from '@endora-commerce/platform/http';
|
|
4
4
|
import { Invoice } from '../entities/invoice.entity.js';
|
|
5
5
|
import { InvoiceLine } from '../entities/invoice-line.entity.js';
|
|
6
6
|
import { shouldHoldForVendorNumber, } from './vendor-number-hold.js';
|
|
7
7
|
import { rethrowIfModuleDisabled } from '@endora-commerce/platform/kernel';
|
|
8
8
|
import { refuseDuplicateInvoiceNumber } from './duplicate-number-refusal.js';
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/** The smaller of two decimals. */
|
|
10
|
+
function minDecimal(a, b) {
|
|
11
|
+
return compareDecimals(a, b) <= 0 ? a : b;
|
|
12
|
+
}
|
|
13
|
+
/** A correction asked to credit more than its lines add up to (review of PR #423). */
|
|
14
|
+
export class CorrectionTotalExceedsLinesError extends Error {
|
|
15
|
+
total;
|
|
16
|
+
linesTotal;
|
|
17
|
+
constructor(total, linesTotal) {
|
|
18
|
+
super(`The correction total ${total} exceeds the sum of its lines, ${linesTotal}.`);
|
|
19
|
+
this.total = total;
|
|
20
|
+
this.linesTotal = linesTotal;
|
|
21
|
+
this.name = 'CorrectionTotalExceedsLinesError';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A correction's amounts, in exact decimal arithmetic, under the invoice's VAT
|
|
26
|
+
* method and **cumulatively** over the corrections of one invoice (issue #417,
|
|
27
|
+
* owner ruling of 2026-10-24, review of PR #423).
|
|
28
|
+
*
|
|
29
|
+
* The credited amount is gross (a return credits what was paid, tax included),
|
|
30
|
+
* capped at what remains of the invoice after earlier corrections (FR-020),
|
|
31
|
+
* and shared out over the lines in order; a total above the lines' sum is
|
|
32
|
+
* refused ({@link CorrectionTotalExceedsLinesError}) rather than booked as a
|
|
33
|
+
* net with no VAT and no line.
|
|
34
|
+
*
|
|
35
|
+
* What the invoice charged is split into groups: a VAT rate of an invoice
|
|
36
|
+
* issued per rate, a line of one issued before 0.108.0. For each group, the
|
|
37
|
+
* correction credits the net of everything credited so far, this correction
|
|
38
|
+
* included, minus the nets earlier corrections already credited — per rate the
|
|
39
|
+
* net `netForGrossAtRate` gives the cumulative gross (`N` with
|
|
40
|
+
* `N + round(N × rate) = gross`), per line the invoiced line net in proportion
|
|
41
|
+
* to the cumulative gross. The differences telescope: all corrections together
|
|
42
|
+
* credit exactly the invoiced net and VAT. A group's net is shared over the
|
|
43
|
+
* correction's lines in it in proportion to their gross (`allocateHalfUp`).
|
|
44
|
+
*/
|
|
45
|
+
export function correctionAmounts(input) {
|
|
46
|
+
const asked = input.lines.map((l) => (compareDecimals(l.amount, 0) < 0 ? '0.00' : roundHalfUp(l.amount)));
|
|
47
|
+
const linesTotal = moneySum(asked);
|
|
48
|
+
const total = roundHalfUp(input.total);
|
|
49
|
+
if (compareDecimals(total, linesTotal) > 0)
|
|
50
|
+
throw new CorrectionTotalExceedsLinesError(total, linesTotal);
|
|
51
|
+
const remainingOfInvoice = moneyDifference(input.originalGross, input.creditedBefore ?? '0');
|
|
52
|
+
const credited = compareDecimals(remainingOfInvoice, 0) <= 0 ? '0.00' : minDecimal(total, remainingOfInvoice);
|
|
53
|
+
const discounts = input.lines.map((l) => l.discount === undefined || compareDecimals(l.discount, 0) <= 0 ? '0.00' : roundHalfUp(l.discount));
|
|
54
|
+
// An order-level discount (issue #417, review of PR #423): the invoice charged
|
|
55
|
+
// the goods at their full value and the discount on a 0 % line of its own, so
|
|
56
|
+
// the goods are credited at `amount + discount` and the discount comes back as
|
|
57
|
+
// a negative 0 % amount — the correction totals the refund, and the goods'
|
|
58
|
+
// VAT is credited as it was charged. That holds only when the correction
|
|
59
|
+
// credits exactly what its lines add up to: a total below the lines (a short
|
|
60
|
+
// settlement, an empty one) or a credit capped below the total credits its
|
|
61
|
+
// amounts as goods, in line order, and no discount — crediting every line at
|
|
62
|
+
// `amount + discount` there would credit more VAT than the total carries
|
|
63
|
+
// (review of PR #423, B1).
|
|
64
|
+
const withDiscount = compareDecimals(credited, total) === 0 &&
|
|
65
|
+
compareDecimals(credited, linesTotal) === 0 &&
|
|
66
|
+
discounts.some((d) => compareDecimals(d, 0) > 0);
|
|
67
|
+
let remaining = credited;
|
|
68
|
+
const grosses = asked.map((a, i) => {
|
|
69
|
+
if (withDiscount)
|
|
70
|
+
return moneySum([a, discounts[i]]);
|
|
71
|
+
const gross = minDecimal(a, remaining);
|
|
72
|
+
remaining = roundHalfUp(decimalDifference(remaining, gross));
|
|
73
|
+
return gross;
|
|
74
|
+
});
|
|
75
|
+
const discountCredit = withDiscount ? moneyDifference('0', moneySum(discounts)) : '0.00';
|
|
76
|
+
const groupOf = (l) => input.perRate ? roundHalfUp(l.rate, 4) : l.orderItemId;
|
|
77
|
+
const byGroup = new Map();
|
|
78
|
+
input.lines.forEach((l, i) => {
|
|
79
|
+
const group = groupOf(l);
|
|
80
|
+
const indexes = byGroup.get(group);
|
|
81
|
+
if (indexes)
|
|
82
|
+
indexes.push(i);
|
|
83
|
+
else
|
|
84
|
+
byGroup.set(group, [i]);
|
|
85
|
+
});
|
|
86
|
+
const earlier = new Map();
|
|
87
|
+
for (const e of input.earlierLines) {
|
|
88
|
+
const group = groupOf(e);
|
|
89
|
+
const sums = earlier.get(group) ?? { net: [], gross: [] };
|
|
90
|
+
sums.net.push(e.net);
|
|
91
|
+
sums.gross.push(e.gross);
|
|
92
|
+
earlier.set(group, sums);
|
|
93
|
+
}
|
|
94
|
+
const nets = input.lines.map(() => '0.00');
|
|
95
|
+
for (const [group, indexes] of byGroup) {
|
|
96
|
+
const gross = moneySum(indexes.map((i) => grosses[i]));
|
|
97
|
+
const before = earlier.get(group) ?? { net: [], gross: [] };
|
|
98
|
+
const cumulativeGross = moneySum([...before.gross, gross]);
|
|
99
|
+
let cumulativeNet;
|
|
100
|
+
if (input.perRate) {
|
|
101
|
+
cumulativeNet = netForGrossAtRate(cumulativeGross, group, 'fraction').net;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
const original = input.originalLines.find((o) => o.orderItemId === group);
|
|
105
|
+
cumulativeNet =
|
|
106
|
+
original && compareDecimals(original.gross, 0) > 0
|
|
107
|
+
? quotientHalfUp(decimalProduct(original.net, cumulativeGross), original.gross)
|
|
108
|
+
: netFromGrossHalfUp(cumulativeGross, input.lines[indexes[0]].rate, 'fraction');
|
|
109
|
+
}
|
|
110
|
+
let net = moneyDifference(cumulativeNet, moneySum(before.net));
|
|
111
|
+
if (compareDecimals(net, 0) < 0)
|
|
112
|
+
net = '0.00';
|
|
113
|
+
if (compareDecimals(net, gross) > 0)
|
|
114
|
+
net = gross;
|
|
115
|
+
const shares = compareDecimals(gross, 0) === 0
|
|
116
|
+
? indexes.map(() => '0.00')
|
|
117
|
+
: allocateHalfUp(net, indexes.map((i) => quotientHalfUp(decimalProduct(net, grosses[i]), gross, 6)));
|
|
118
|
+
indexes.forEach((lineIndex, k) => {
|
|
119
|
+
nets[lineIndex] = shares[k];
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
const taxTotal = moneySum(grosses.map((g, i) => moneyDifference(g, nets[i])));
|
|
123
|
+
const rates = new Map();
|
|
124
|
+
const addToRate = (key, net, gross) => {
|
|
125
|
+
const sums = rates.get(key) ?? { net: [], gross: [] };
|
|
126
|
+
sums.net.push(net);
|
|
127
|
+
sums.gross.push(gross);
|
|
128
|
+
rates.set(key, sums);
|
|
129
|
+
};
|
|
130
|
+
input.lines.forEach((l, i) => addToRate(roundHalfUp(l.rate, 4), nets[i], grosses[i]));
|
|
131
|
+
if (compareDecimals(discountCredit, 0) !== 0)
|
|
132
|
+
addToRate('0.0000', discountCredit, discountCredit);
|
|
133
|
+
return {
|
|
134
|
+
credited,
|
|
135
|
+
netTotal: roundHalfUp(decimalDifference(credited, taxTotal)),
|
|
136
|
+
taxTotal,
|
|
137
|
+
lines: input.lines.map((l, i) => ({
|
|
138
|
+
gross: grosses[i],
|
|
139
|
+
net: nets[i],
|
|
140
|
+
unitNetPrice: quotientHalfUp(nets[i], l.quantity || 1, 4),
|
|
141
|
+
})),
|
|
142
|
+
vatSummary: [...rates.entries()]
|
|
143
|
+
.sort((a, b) => compareDecimals(a[0], b[0]))
|
|
144
|
+
.map(([taxRate, sums]) => {
|
|
145
|
+
const netTotal = moneySum(sums.net);
|
|
146
|
+
const grossTotal = moneySum(sums.gross);
|
|
147
|
+
return { taxRate, netTotal, vatAmount: moneyDifference(grossTotal, netTotal), grossTotal };
|
|
148
|
+
}),
|
|
149
|
+
discountCredit,
|
|
150
|
+
};
|
|
11
151
|
}
|
|
12
152
|
/**
|
|
13
153
|
* What a corrective line inherits from the line it corrects (product ruling
|
|
@@ -60,34 +200,34 @@ export class CorrectiveInvoiceProvider {
|
|
|
60
200
|
this.events = events;
|
|
61
201
|
this.ledgerRouting = ledgerRouting;
|
|
62
202
|
}
|
|
63
|
-
|
|
203
|
+
/**
|
|
204
|
+
* Refuse, without writing anything, exactly what {@link createCorrection}
|
|
205
|
+
* would refuse for this input (issue #417, review of PR #423): a settlement
|
|
206
|
+
* asks before it moves any money, so a correction that cannot be made never
|
|
207
|
+
* follows a refund that was. An order with no invoice is not a refusal — its
|
|
208
|
+
* settlement records the refund without a document.
|
|
209
|
+
*/
|
|
210
|
+
async validateCorrection(input) {
|
|
64
211
|
const em = this.emFactory();
|
|
65
|
-
// The same correction, asked for twice (D-91). A settlement attempts every
|
|
66
|
-
// external effect before it writes any state, so a refusal from a later
|
|
67
|
-
// step leaves a retryable case and the retry arrives here with the key of
|
|
68
|
-
// the correction this call already issued. Answering with that document is
|
|
69
|
-
// what keeps one return case to one credit note; the partial unique index
|
|
70
|
-
// on the column is what keeps two concurrent retries to one as well.
|
|
71
212
|
if (input.idempotencyKey) {
|
|
72
|
-
const already = await em.findOne(Invoice, {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
});
|
|
76
|
-
if (already) {
|
|
77
|
-
return {
|
|
78
|
-
issued: true,
|
|
79
|
-
invoiceId: already.id,
|
|
80
|
-
number: already.number,
|
|
81
|
-
status: already.status,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
213
|
+
const already = await em.findOne(Invoice, { correctionIdempotencyKey: input.idempotencyKey, kind: 'correction' });
|
|
214
|
+
if (already)
|
|
215
|
+
return;
|
|
84
216
|
}
|
|
217
|
+
await this.#prepare(em, input);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Everything a correction is computed from, and every refusal, before a
|
|
221
|
+
* number is drawn: the original invoice (or `null` when the order was never
|
|
222
|
+
* invoiced), its channel, the amounts and the line snapshots.
|
|
223
|
+
*/
|
|
224
|
+
async #prepare(em, input) {
|
|
85
225
|
const original = await em.findOne(Invoice, { orderId: input.orderId, kind: 'invoice' });
|
|
86
226
|
// No original, no correction (#135). The caller records the refund on the
|
|
87
227
|
// return case and the payment; only the VAT document is skipped, and the
|
|
88
228
|
// reason is stated so the caller reports it rather than reporting nothing.
|
|
89
229
|
if (!original)
|
|
90
|
-
return
|
|
230
|
+
return null;
|
|
91
231
|
// A correction is denominated in the corrected document's currency: the cap
|
|
92
232
|
// below compares the credited amount with the original gross, and two
|
|
93
233
|
// amounts in different currencies do not compare (#136.2). Nothing produces
|
|
@@ -105,11 +245,6 @@ export class CorrectiveInvoiceProvider {
|
|
|
105
245
|
// The correction belongs to the corrected document's channel — that is the
|
|
106
246
|
// numbering series it continues.
|
|
107
247
|
const salesChannelId = original.salesChannelId ?? null;
|
|
108
|
-
// Cap the credited total at the original invoice gross (never credit more
|
|
109
|
-
// than was invoiced).
|
|
110
|
-
const originalGross = Number(original.total);
|
|
111
|
-
const requested = round2(input.total);
|
|
112
|
-
const credited = Math.min(requested, originalGross);
|
|
113
248
|
// A correction mirrors the line it corrects. The link is `orderItemId`:
|
|
114
249
|
// issuance snapshots it on every product line of the original, and a return
|
|
115
250
|
// case item names the same order item.
|
|
@@ -117,37 +252,97 @@ export class CorrectiveInvoiceProvider {
|
|
|
117
252
|
const originalLines = await em.find(InvoiceLine, { invoiceId: original.id });
|
|
118
253
|
for (const l of originalLines) {
|
|
119
254
|
if (l.orderItemId)
|
|
120
|
-
mirrorByOrderItem.set(l.orderItemId, { rate:
|
|
255
|
+
mirrorByOrderItem.set(l.orderItemId, { rate: l.taxRate, unit: l.unit });
|
|
121
256
|
}
|
|
122
257
|
// Resolve every line before the transaction opens, so a line that cannot
|
|
123
258
|
// be mirrored refuses without having drawn a correction number.
|
|
124
|
-
|
|
125
|
-
//
|
|
126
|
-
//
|
|
127
|
-
//
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
name: l.productName,
|
|
139
|
-
quantity: qty,
|
|
140
|
-
rate: mirrored.rate,
|
|
141
|
-
unit: mirrored.unit,
|
|
142
|
-
net,
|
|
143
|
-
gross,
|
|
144
|
-
unitNetPrice: net / qty,
|
|
145
|
-
};
|
|
259
|
+
const mirrored = input.lines.map((l) => mirrorFor(original, mirrorByOrderItem, l.orderItemId));
|
|
260
|
+
// What earlier corrections of this invoice already credited: the cap and
|
|
261
|
+
// the cumulative rule both read it (review of PR #423).
|
|
262
|
+
// A cancelled correction credits nothing, so it is neither in the cap nor in
|
|
263
|
+
// the cumulative nets (review of PR #423).
|
|
264
|
+
const earlierCorrections = (await em.find(Invoice, { originalInvoiceId: original.id, kind: 'correction' })).filter((c) => c.status !== 'cancelled');
|
|
265
|
+
const earlierLines = earlierCorrections.length > 0
|
|
266
|
+
? await em.find(InvoiceLine, { invoiceId: { $in: earlierCorrections.map((c) => c.id) } })
|
|
267
|
+
: [];
|
|
268
|
+
const asCredited = (l) => ({
|
|
269
|
+
orderItemId: l.orderItemId ?? '',
|
|
270
|
+
rate: l.taxRate,
|
|
271
|
+
net: l.netValue,
|
|
272
|
+
gross: l.grossValue,
|
|
146
273
|
});
|
|
147
|
-
// The
|
|
148
|
-
//
|
|
149
|
-
const
|
|
150
|
-
|
|
274
|
+
// The invoice's own discount line: the discount credit mirrors its name and
|
|
275
|
+
// unit, and an invoice that itemized no discount credits none separately.
|
|
276
|
+
const discountLine = originalLines.find((l) => !l.orderItemId && compareDecimals(l.grossValue, 0) < 0);
|
|
277
|
+
let amounts;
|
|
278
|
+
try {
|
|
279
|
+
amounts = correctionAmounts({
|
|
280
|
+
total: input.total,
|
|
281
|
+
originalGross: original.total,
|
|
282
|
+
creditedBefore: moneySum(earlierCorrections.map((c) => c.total)),
|
|
283
|
+
// Issued under the per-rate method exactly when it stored its summary.
|
|
284
|
+
perRate: original.vatSummary != null,
|
|
285
|
+
// Goods lines only: a delivery, surcharge or discount line names no order
|
|
286
|
+
// item, and an earlier correction's discount credit is not goods.
|
|
287
|
+
originalLines: originalLines.filter((l) => l.orderItemId).map(asCredited),
|
|
288
|
+
earlierLines: earlierLines.filter((l) => l.orderItemId).map(asCredited),
|
|
289
|
+
lines: input.lines.map((l, index) => ({
|
|
290
|
+
amount: l.amount,
|
|
291
|
+
...(l.discount !== undefined && discountLine ? { discount: l.discount } : {}),
|
|
292
|
+
quantity: l.quantity,
|
|
293
|
+
rate: mirrored[index].rate,
|
|
294
|
+
orderItemId: l.orderItemId,
|
|
295
|
+
})),
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
catch (err) {
|
|
299
|
+
if (!(err instanceof CorrectionTotalExceedsLinesError))
|
|
300
|
+
throw err;
|
|
301
|
+
throw new HttpError(400, ERROR_CODES.VALIDATION_FAILED, err.message, {
|
|
302
|
+
code: 'correction_total_exceeds_lines',
|
|
303
|
+
total: err.total,
|
|
304
|
+
linesTotal: err.linesTotal,
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
const snapshots = input.lines.map((l, index) => ({
|
|
308
|
+
ordinal: index + 1,
|
|
309
|
+
orderItemId: l.orderItemId,
|
|
310
|
+
name: l.productName,
|
|
311
|
+
quantity: l.quantity || 1,
|
|
312
|
+
rate: roundHalfUp(mirrored[index].rate, 4),
|
|
313
|
+
unit: mirrored[index].unit,
|
|
314
|
+
...amounts.lines[index],
|
|
315
|
+
}));
|
|
316
|
+
return { original, salesChannelId, amounts, snapshots, discountLine };
|
|
317
|
+
}
|
|
318
|
+
async createCorrection(input) {
|
|
319
|
+
const em = this.emFactory();
|
|
320
|
+
// The same correction, asked for twice (D-91). A settlement attempts every
|
|
321
|
+
// external effect before it writes any state, so a refusal from a later
|
|
322
|
+
// step leaves a retryable case and the retry arrives here with the key of
|
|
323
|
+
// the correction this call already issued. Answering with that document is
|
|
324
|
+
// what keeps one return case to one credit note; the partial unique index
|
|
325
|
+
// on the column is what keeps two concurrent retries to one as well.
|
|
326
|
+
if (input.idempotencyKey) {
|
|
327
|
+
const already = await em.findOne(Invoice, {
|
|
328
|
+
correctionIdempotencyKey: input.idempotencyKey,
|
|
329
|
+
kind: 'correction',
|
|
330
|
+
});
|
|
331
|
+
if (already) {
|
|
332
|
+
return {
|
|
333
|
+
issued: true,
|
|
334
|
+
invoiceId: already.id,
|
|
335
|
+
number: already.number,
|
|
336
|
+
status: already.status,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
const plan = await this.#prepare(em, input);
|
|
341
|
+
// No original, no correction (#135).
|
|
342
|
+
if (!plan)
|
|
343
|
+
return { issued: false, reason: 'order_not_invoiced' };
|
|
344
|
+
const { original, salesChannelId, amounts, snapshots, discountLine } = plan;
|
|
345
|
+
const { credited: creditedTotal, netTotal, taxTotal } = amounts;
|
|
151
346
|
const issuedAt = new Date();
|
|
152
347
|
const holdForVendor = await shouldHoldForVendorNumber(this.ledgerRouting, salesChannelId);
|
|
153
348
|
// Captured out of the transaction: see the same note in `InvoiceService`.
|
|
@@ -176,9 +371,10 @@ export class CorrectiveInvoiceProvider {
|
|
|
176
371
|
// date and keeps its meaning — do not collapse the two back together.
|
|
177
372
|
saleDate: original.saleDate ?? issuedAt.toISOString().slice(0, 10),
|
|
178
373
|
currency: input.currency,
|
|
179
|
-
netTotal
|
|
180
|
-
taxTotal
|
|
181
|
-
total:
|
|
374
|
+
netTotal,
|
|
375
|
+
taxTotal,
|
|
376
|
+
total: creditedTotal,
|
|
377
|
+
vatSummary: amounts.vatSummary,
|
|
182
378
|
paidTotal: '0',
|
|
183
379
|
originalInvoiceId: original.id,
|
|
184
380
|
...(input.idempotencyKey ? { correctionIdempotencyKey: input.idempotencyKey } : {}),
|
|
@@ -198,13 +394,29 @@ export class CorrectiveInvoiceProvider {
|
|
|
198
394
|
// `opak.` is credited in `opak.` and not in `szt.` (#136.1).
|
|
199
395
|
unit: s.unit,
|
|
200
396
|
quantity: String(s.quantity),
|
|
201
|
-
unitNetPrice: s.unitNetPrice
|
|
202
|
-
taxRate: s.rate
|
|
203
|
-
netValue: s.net
|
|
204
|
-
grossValue: s.gross
|
|
397
|
+
unitNetPrice: s.unitNetPrice,
|
|
398
|
+
taxRate: s.rate,
|
|
399
|
+
netValue: s.net,
|
|
400
|
+
grossValue: s.gross,
|
|
205
401
|
orderItemId: s.orderItemId,
|
|
206
402
|
});
|
|
207
403
|
}
|
|
404
|
+
// The order-level discount the returned goods carried, credited back on
|
|
405
|
+
// a 0 % line of its own, as the invoice charged it (issue #417).
|
|
406
|
+
if (discountLine && compareDecimals(amounts.discountCredit, 0) !== 0) {
|
|
407
|
+
tx.create(InvoiceLine, {
|
|
408
|
+
invoiceId: inv.id,
|
|
409
|
+
ordinal: snapshots.length + 1,
|
|
410
|
+
name: discountLine.name,
|
|
411
|
+
unit: discountLine.unit,
|
|
412
|
+
quantity: '1',
|
|
413
|
+
unitNetPrice: roundHalfUp(amounts.discountCredit, 4),
|
|
414
|
+
taxRate: '0.0000',
|
|
415
|
+
netValue: amounts.discountCredit,
|
|
416
|
+
grossValue: amounts.discountCredit,
|
|
417
|
+
orderItemId: null,
|
|
418
|
+
});
|
|
419
|
+
}
|
|
208
420
|
await tx.flush();
|
|
209
421
|
return inv;
|
|
210
422
|
};
|
|
@@ -237,7 +449,7 @@ export class CorrectiveInvoiceProvider {
|
|
|
237
449
|
number: invoice.number,
|
|
238
450
|
orderId: input.orderId,
|
|
239
451
|
originalInvoiceId: original.id,
|
|
240
|
-
credited,
|
|
452
|
+
credited: Number(creditedTotal),
|
|
241
453
|
},
|
|
242
454
|
})
|
|
243
455
|
.catch(() => undefined);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"corrective-invoice.js","sourceRoot":"","sources":["../../../src/backend/services/corrective-invoice.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;IACjG,CAAC;CACF"}
|
|
1
|
+
{"version":3,"file":"corrective-invoice.js","sourceRoot":"","sources":["../../../src/backend/services/corrective-invoice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,OAAO,EACL,WAAW,EACX,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,QAAQ,EACR,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,WAAW,GACZ,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAGjE,OAAO,EACL,yBAAyB,GAE1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAU7E,mCAAmC;AACnC,SAAS,UAAU,CAAC,CAAS,EAAE,CAAS;IACtC,OAAO,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5C,CAAC;AASD,sFAAsF;AACtF,MAAM,OAAO,gCAAiC,SAAQ,KAAK;IAE9C;IACA;IAFX,YACW,KAAa,EACb,UAAkB;QAE3B,KAAK,CAAC,wBAAwB,KAAK,kCAAkC,UAAU,GAAG,CAAC,CAAC;QAH3E,UAAK,GAAL,KAAK,CAAQ;QACb,eAAU,GAAV,UAAU,CAAQ;QAG3B,IAAI,CAAC,IAAI,GAAG,kCAAkC,CAAC;IACjD,CAAC;CACF;AAqCD;;;;;;;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AAS;aAC1B,CAAC,CAAC;YACH,MAAM,GAAG,CAAC;QACZ,CAAC;QAED,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,CAAC,KAAK;iBACb,MAAM,CAAC;gBACN,MAAM,EAAE,mBAAmB;gBAC3B,UAAU,EAAE,SAAS;gBACrB,QAAQ,EAAE,OAAO,CAAC,EAAE;gBACpB,UAAU,EAAE;oBACV,MAAM,EAAE,OAAO,CAAC,MAAM;oBACtB,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,iBAAiB,EAAE,QAAQ,CAAC,EAAE;oBAC9B,QAAQ,EAAE,MAAM,CAAC,aAAa,CAAC;iBAChC;aACF,CAAC;iBACD,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC;QAED,8EAA8E;QAC9E,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,sBAAsB,EAAE;YACxC,OAAO,EAAE,UAAU,EAAE;YACrB,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACpC,SAAS,EAAE,OAAO,CAAC,EAAE;YACrB,iBAAiB,EAAE,QAAQ,CAAC,EAAE;YAC9B,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,cAAc;SACf,CAAC,CAAC;QAEH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;IACjG,CAAC;CACF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ChannelUrlFacts } from '@endora-commerce/contracts';
|
|
1
2
|
import type { EntityManager } from '@mikro-orm/postgresql';
|
|
2
3
|
import type { AssetReadPort, CustomerAccountReadPort, OrderRecord } from '@endora-commerce/contracts';
|
|
3
4
|
import type { LoadAssetImage } from '../pdf-components/embed-logo-images.js';
|
|
@@ -53,6 +54,12 @@ export declare function createRecipientEmailResolver(accounts: Pick<CustomerAcco
|
|
|
53
54
|
* the fallback both roots carried.
|
|
54
55
|
*/
|
|
55
56
|
export declare function createChannelLanguageResolver(emFactory: () => EntityManager): (salesChannelId: string | null) => Promise<string>;
|
|
57
|
+
/**
|
|
58
|
+
* Feature 167 (OR-14) — a channel's URL-language facts (its languages, default and
|
|
59
|
+
* *prefix the default language* setting), for links to storefront pages. The kernel
|
|
60
|
+
* `SalesChannel` row, read as the language resolver above reads it.
|
|
61
|
+
*/
|
|
62
|
+
export declare function createChannelUrlFactsResolver(emFactory: () => EntityManager): (salesChannelId: string | null) => Promise<ChannelUrlFacts | null>;
|
|
56
63
|
/**
|
|
57
64
|
* The operator's logo, as bytes pdfmake can inline.
|
|
58
65
|
*
|