@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cross-module-context.d.ts","sourceRoot":"","sources":["../../../src/backend/services/cross-module-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EACV,aAAa,EACb,uBAAuB,EACvB,WAAW,EACZ,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAE7E;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,IAAI,CAAC,uBAAuB,EAAE,UAAU,CAAC,GAClD,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAGhD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,aAAa,GAC7B,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,MAAM,CAAC,CAKpD;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,UAAU,GAAG,gBAAgB,CAAC,GACzD,cAAc,CAMhB"}
|
|
1
|
+
{"version":3,"file":"cross-module-context.d.ts","sourceRoot":"","sources":["../../../src/backend/services/cross-module-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EACV,aAAa,EACb,uBAAuB,EACvB,WAAW,EACZ,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAE7E;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,IAAI,CAAC,uBAAuB,EAAE,UAAU,CAAC,GAClD,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAGhD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,aAAa,GAC7B,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,MAAM,CAAC,CAKpD;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,aAAa,GAC7B,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAYpE;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,UAAU,GAAG,gBAAgB,CAAC,GACzD,cAAc,CAMhB"}
|
|
@@ -57,6 +57,25 @@ export function createChannelLanguageResolver(emFactory) {
|
|
|
57
57
|
? (await emFactory().findOne(SalesChannel, { id: salesChannelId }))?.defaultLanguage
|
|
58
58
|
: null) ?? 'en-US';
|
|
59
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Feature 167 (OR-14) — a channel's URL-language facts (its languages, default and
|
|
62
|
+
* *prefix the default language* setting), for links to storefront pages. The kernel
|
|
63
|
+
* `SalesChannel` row, read as the language resolver above reads it.
|
|
64
|
+
*/
|
|
65
|
+
export function createChannelUrlFactsResolver(emFactory) {
|
|
66
|
+
return async (salesChannelId) => {
|
|
67
|
+
if (!salesChannelId)
|
|
68
|
+
return null;
|
|
69
|
+
const channel = await emFactory().findOne(SalesChannel, { id: salesChannelId });
|
|
70
|
+
return channel
|
|
71
|
+
? {
|
|
72
|
+
languages: channel.languages,
|
|
73
|
+
defaultLanguage: channel.defaultLanguage,
|
|
74
|
+
prefixDefaultLanguage: channel.prefixDefaultLanguage,
|
|
75
|
+
}
|
|
76
|
+
: null;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
60
79
|
/**
|
|
61
80
|
* The operator's logo, as bytes pdfmake can inline.
|
|
62
81
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cross-module-context.js","sourceRoot":"","sources":["../../../src/backend/services/cross-module-context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cross-module-context.js","sourceRoot":"","sources":["../../../src/backend/services/cross-module-context.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAGhE;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,4BAA4B,CAC1C,QAAmD;IAEnD,OAAO,KAAK,EAAE,KAAK,EAAE,EAAE,CACrB,CAAC,MAAM,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC,EAAE,KAAK,IAAI,IAAI,CAAC;AAC9E,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,6BAA6B,CAC3C,SAA8B;IAE9B,OAAO,KAAK,EAAE,cAAc,EAAE,EAAE,CAC9B,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, OrderRecord, TransactionalEmailSender } from '@endora-commerce/contracts';
|
|
2
3
|
import type { InvoiceService } from './invoice-service.js';
|
|
3
4
|
import type { SettingsReader } from './seller-settings.js';
|
|
@@ -45,6 +46,12 @@ export interface InvoiceEmailDispatchDeps {
|
|
|
45
46
|
getSender: () => TransactionalEmailSender | undefined;
|
|
46
47
|
resolveRecipientEmail: (order: OrderRecord) => Promise<string | null>;
|
|
47
48
|
resolveLanguage: (salesChannelId: string | null) => Promise<string>;
|
|
49
|
+
/**
|
|
50
|
+
* Feature 167 (OR-14) — the channel's URL-language facts, so the e-mail links the
|
|
51
|
+
* storefront order page under the e-mail language's prefix. Absent, or no channel:
|
|
52
|
+
* the logical path.
|
|
53
|
+
*/
|
|
54
|
+
channelUrlFactsFor?: (salesChannelId: string | null) => Promise<ChannelUrlFacts | null>;
|
|
48
55
|
log?: InvoiceEmailLog;
|
|
49
56
|
}
|
|
50
57
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invoice-email-dispatch.d.ts","sourceRoot":"","sources":["../../../src/backend/services/invoice-email-dispatch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"invoice-email-dispatch.d.ts","sourceRoot":"","sources":["../../../src/backend/services/invoice-email-dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAEzF,OAAO,KAAK,EACV,kBAAkB,EAClB,yBAAyB,EACzB,aAAa,EACb,WAAW,EACX,wBAAwB,EACzB,MAAM,4BAA4B,CAAC;AAMpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D;;;;;;;;;;;;GAYG;AACH,YAAY,EAAE,yBAAyB,EAAE,CAAC;AAE1C,MAAM,MAAM,0BAA0B,GAClC;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,GACd;IAAE,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YASX,cAAc;IAS5B;;;;;OAKG;IACG,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC;CAQrE"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { storefrontPagePathFor } from '@endora-commerce/contracts';
|
|
1
2
|
import { z } from 'zod';
|
|
2
3
|
import { rethrowIfModuleDisabled } from '@endora-commerce/platform/kernel';
|
|
3
4
|
import { SettingNotRegistered, SettingOutOfScopeForChannel, } from '@endora-commerce/platform/kernel';
|
|
@@ -44,9 +45,15 @@ export class InvoiceEmailDispatcher {
|
|
|
44
45
|
const language = await this.deps.resolveLanguage(channelId);
|
|
45
46
|
const mode = opts.mode ?? (await this.resolveMode(channelId));
|
|
46
47
|
const baseUrl = await this.resolveBaseUrl(channelId);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
// Owner ruling OR-14 (feature 167) — the storefront order page, which lists
|
|
49
|
+
// the order's invoices with their PDF download, in the e-mail's language. The
|
|
50
|
+
// former `/orders/:id/invoices/:id/pdf` storefront address was served by nothing.
|
|
51
|
+
const orderPagePath = storefrontPagePathFor({
|
|
52
|
+
path: `/orders/${encodeURIComponent(detail.orderId)}`,
|
|
53
|
+
channel: this.deps.channelUrlFactsFor ? await this.deps.channelUrlFactsFor(channelId) : null,
|
|
54
|
+
requestedLanguage: language,
|
|
55
|
+
});
|
|
56
|
+
const downloadUrl = baseUrl ? `${baseUrl.replace(/\/$/, '')}${orderPagePath}` : '';
|
|
50
57
|
const variables = {
|
|
51
58
|
invoice: {
|
|
52
59
|
number: detail.number,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invoice-email-dispatch.js","sourceRoot":"","sources":["../../../src/backend/services/invoice-email-dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC3E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AO,QAAQ,CAAC;YAClE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,WAAW,CAAC,SAAwB;QAChD,OAAO,IAAI,CAAC,WAAW,CACrB,sBAAsB,CAAC,mBAAmB,EAC1C,SAAS,EACT,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,EAC9B,YAAY,CACb,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,cAAc,CAAC,SAAwB;QACnD,OAAO,IAAI,CAAC,WAAW,CACrB,sBAAsB,CAAC,mBAAmB,EAC1C,SAAS,EACT,CAAC,CAAC,MAAM,EAAE,EACV,EAAE,CACH,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,kBAAkB,CAAC,SAAwB;QAC/C,OAAO,IAAI,CAAC,WAAW,CACrB,sBAAsB,CAAC,mBAAmB,EAC1C,SAAS,EACT,CAAC,CAAC,OAAO,EAAE,EACX,KAAK,CACN,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,29 +1,79 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type InvoiceLine, type VatSummaryRow } from '@endora-commerce/contracts';
|
|
2
2
|
export interface RawOrderLine {
|
|
3
3
|
name: string;
|
|
4
4
|
unit: string;
|
|
5
5
|
quantity: number;
|
|
6
|
-
/** Net unit price. */
|
|
7
|
-
unitNetPrice: number;
|
|
8
|
-
/** Fractional VAT rate, e.g. 0.23
|
|
9
|
-
taxRate: number;
|
|
10
|
-
/** Net line value (quantity × unitNetPrice)
|
|
11
|
-
netValue: number;
|
|
6
|
+
/** Net unit price, as written (a decimal string, or a number read as its shortest decimal). */
|
|
7
|
+
unitNetPrice: string | number;
|
|
8
|
+
/** Fractional VAT rate, e.g. `0.23`. */
|
|
9
|
+
taxRate: string | number;
|
|
10
|
+
/** Net line value (quantity × unitNetPrice) at two places. */
|
|
11
|
+
netValue: string | number;
|
|
12
12
|
orderItemId?: string | null;
|
|
13
13
|
}
|
|
14
|
+
/** The line's amounts as the `invoice_lines` columns store them. */
|
|
15
|
+
export interface StoredInvoiceLineAmounts {
|
|
16
|
+
unitNetPrice: string;
|
|
17
|
+
taxRate: string;
|
|
18
|
+
netValue: string;
|
|
19
|
+
grossValue: string;
|
|
20
|
+
}
|
|
21
|
+
export type BuiltInvoiceLine = InvoiceLine & {
|
|
22
|
+
orderItemId?: string | null;
|
|
23
|
+
stored: StoredInvoiceLineAmounts;
|
|
24
|
+
};
|
|
14
25
|
export interface BuiltInvoiceTotals {
|
|
15
|
-
lines:
|
|
16
|
-
orderItemId?: string | null;
|
|
17
|
-
}>;
|
|
26
|
+
lines: BuiltInvoiceLine[];
|
|
18
27
|
vatSummary: VatSummaryRow[];
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
/** The summary as `invoices.vat_summary` stores it. */
|
|
29
|
+
storedVatSummary: StoredVatRow[];
|
|
30
|
+
/** Two-place decimal strings, as the `invoices` columns store them. */
|
|
31
|
+
netTotal: string;
|
|
32
|
+
taxTotal: string;
|
|
33
|
+
grossTotal: string;
|
|
34
|
+
}
|
|
35
|
+
/** One stored line's rate, net and gross, as two-place decimals. */
|
|
36
|
+
export interface VatSummaryInput {
|
|
37
|
+
taxRate: string | number;
|
|
38
|
+
netValue: string | number;
|
|
39
|
+
grossValue: string | number;
|
|
22
40
|
}
|
|
41
|
+
/** A per-rate summary row as `invoices.vat_summary` stores it: two-place decimal strings. */
|
|
42
|
+
export interface StoredVatRow {
|
|
43
|
+
taxRate: string;
|
|
44
|
+
netTotal: string;
|
|
45
|
+
vatAmount: string;
|
|
46
|
+
grossTotal: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The per-rate VAT summary a stored document is shown with — **decided by what
|
|
50
|
+
* was stored, never guessed** (review of PR #423). A document issued from
|
|
51
|
+
* 0.108.0 stored the summary it was issued with (`invoices.vat_summary`), and
|
|
52
|
+
* that is what it shows: its line grosses are each line's own rounding and need
|
|
53
|
+
* not add up to it. A document issued before (or imported) stored none, and its
|
|
54
|
+
* summary is derived from its stored lines exactly as it was then — per rate,
|
|
55
|
+
* the lines' grosses minus their nets.
|
|
56
|
+
*/
|
|
57
|
+
export declare function readModelVatSummary(lines: readonly VatSummaryInput[], stored: readonly StoredVatRow[] | null | undefined): VatSummaryRow[];
|
|
58
|
+
/** The stored form of a summary computed from rows. */
|
|
59
|
+
export declare function storedVatRows(rows: ReadonlyArray<{
|
|
60
|
+
rate: string;
|
|
61
|
+
net: string;
|
|
62
|
+
vat: string;
|
|
63
|
+
gross: string;
|
|
64
|
+
}>): StoredVatRow[];
|
|
23
65
|
/**
|
|
24
66
|
* Builds immutable invoice line snapshots + the per-rate VAT summary + totals
|
|
25
67
|
* from raw order lines. Pure + deterministic so it can be unit-tested in
|
|
26
68
|
* isolation (SC-003: net + VAT = gross per rate; Σ gross = grand total).
|
|
69
|
+
*
|
|
70
|
+
* **The VAT method is the platform's one** (`vatByRate`, owner ruling of
|
|
71
|
+
* 2026-10-24, issue #417; art. 106e ust. 1 pkt 13–14): per rate, VAT on the sum
|
|
72
|
+
* of the lines' nets, rounded half-up once; gross = net + VAT. A line's gross
|
|
73
|
+
* is informational and is the line's own rounding, `round(net × (1 + rate))`
|
|
74
|
+
* (owner ruling of 2026-10-24), so the line grosses may differ from the invoice
|
|
75
|
+
* gross by a cent. The net per line is what the law requires on the line; the
|
|
76
|
+
* gross per line is optional.
|
|
27
77
|
*/
|
|
28
78
|
export declare function buildInvoiceLines(raw: RawOrderLine[]): BuiltInvoiceTotals;
|
|
29
79
|
//# sourceMappingURL=invoice-line-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invoice-line-builder.d.ts","sourceRoot":"","sources":["../../../src/backend/services/invoice-line-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"invoice-line-builder.d.ts","sourceRoot":"","sources":["../../../src/backend/services/invoice-line-builder.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B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,SAAS,eAAe,EAAE,EACjC,MAAM,EAAE,SAAS,YAAY,EAAE,GAAG,IAAI,GAAG,SAAS,GACjD,aAAa,EAAE,CAOjB;AAED,uDAAuD;AACvD,wBAAgB,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,YAAY,EAAE,CAE5H;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,YAAY,EAAE,GAAG,kBAAkB,CAmCzE"}
|
|
@@ -1,46 +1,97 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { compareDecimals, decimalDifference, moneySum, roundHalfUp, vatByRate, } from '@endora-commerce/contracts';
|
|
2
|
+
/** A per-rate VAT summary in the contract's number shape — each figure a two-place decimal, read losslessly. */
|
|
3
|
+
function summaryRows(rows) {
|
|
4
|
+
return rows.map((r) => ({
|
|
5
|
+
taxRate: Number(r.rate),
|
|
6
|
+
netTotal: Number(r.net),
|
|
7
|
+
vatAmount: Number(r.vat),
|
|
8
|
+
grossTotal: Number(r.gross),
|
|
9
|
+
}));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The rule invoices were issued under before 0.108.0: per rate, the sum of the
|
|
13
|
+
* lines' own rounded grosses minus the sum of their nets. Kept only to show
|
|
14
|
+
* such a document — one with no stored summary — as it was issued.
|
|
15
|
+
*/
|
|
16
|
+
function legacyVatSummary(lines) {
|
|
17
|
+
const byRate = new Map();
|
|
18
|
+
for (const l of lines) {
|
|
19
|
+
const key = roundHalfUp(l.taxRate, 4);
|
|
20
|
+
const cur = byRate.get(key) ?? { net: [], gross: [] };
|
|
21
|
+
cur.net.push(l.netValue);
|
|
22
|
+
cur.gross.push(l.grossValue);
|
|
23
|
+
byRate.set(key, cur);
|
|
24
|
+
}
|
|
25
|
+
return summaryRows([...byRate.entries()]
|
|
26
|
+
.sort((a, b) => compareDecimals(a[0], b[0]))
|
|
27
|
+
.map(([rate, v]) => {
|
|
28
|
+
const net = moneySum(v.net);
|
|
29
|
+
const gross = moneySum(v.gross);
|
|
30
|
+
return { rate, net, vat: roundHalfUp(decimalDifference(gross, net)), gross };
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The per-rate VAT summary a stored document is shown with — **decided by what
|
|
35
|
+
* was stored, never guessed** (review of PR #423). A document issued from
|
|
36
|
+
* 0.108.0 stored the summary it was issued with (`invoices.vat_summary`), and
|
|
37
|
+
* that is what it shows: its line grosses are each line's own rounding and need
|
|
38
|
+
* not add up to it. A document issued before (or imported) stored none, and its
|
|
39
|
+
* summary is derived from its stored lines exactly as it was then — per rate,
|
|
40
|
+
* the lines' grosses minus their nets.
|
|
41
|
+
*/
|
|
42
|
+
export function readModelVatSummary(lines, stored) {
|
|
43
|
+
if (stored) {
|
|
44
|
+
return summaryRows(stored.map((r) => ({ rate: r.taxRate, net: r.netTotal, vat: r.vatAmount, gross: r.grossTotal })));
|
|
45
|
+
}
|
|
46
|
+
return legacyVatSummary(lines);
|
|
47
|
+
}
|
|
48
|
+
/** The stored form of a summary computed from rows. */
|
|
49
|
+
export function storedVatRows(rows) {
|
|
50
|
+
return rows.map((r) => ({ taxRate: r.rate, netTotal: r.net, vatAmount: r.vat, grossTotal: r.gross }));
|
|
4
51
|
}
|
|
5
52
|
/**
|
|
6
53
|
* Builds immutable invoice line snapshots + the per-rate VAT summary + totals
|
|
7
54
|
* from raw order lines. Pure + deterministic so it can be unit-tested in
|
|
8
55
|
* isolation (SC-003: net + VAT = gross per rate; Σ gross = grand total).
|
|
56
|
+
*
|
|
57
|
+
* **The VAT method is the platform's one** (`vatByRate`, owner ruling of
|
|
58
|
+
* 2026-10-24, issue #417; art. 106e ust. 1 pkt 13–14): per rate, VAT on the sum
|
|
59
|
+
* of the lines' nets, rounded half-up once; gross = net + VAT. A line's gross
|
|
60
|
+
* is informational and is the line's own rounding, `round(net × (1 + rate))`
|
|
61
|
+
* (owner ruling of 2026-10-24), so the line grosses may differ from the invoice
|
|
62
|
+
* gross by a cent. The net per line is what the law requires on the line; the
|
|
63
|
+
* gross per line is optional.
|
|
9
64
|
*/
|
|
10
65
|
export function buildInvoiceLines(raw) {
|
|
66
|
+
const nets = raw.map((r) => roundHalfUp(r.netValue));
|
|
67
|
+
const vat = vatByRate(raw.map((r, i) => ({ net: nets[i], rate: r.taxRate })), 'fraction');
|
|
11
68
|
const lines = raw.map((r, i) => {
|
|
12
|
-
const
|
|
13
|
-
|
|
69
|
+
const stored = {
|
|
70
|
+
unitNetPrice: roundHalfUp(r.unitNetPrice, 4),
|
|
71
|
+
taxRate: roundHalfUp(r.taxRate, 4),
|
|
72
|
+
netValue: nets[i],
|
|
73
|
+
grossValue: vat.lines[i].gross,
|
|
74
|
+
};
|
|
14
75
|
return {
|
|
15
76
|
ordinal: i + 1,
|
|
16
77
|
name: r.name,
|
|
17
78
|
unit: r.unit,
|
|
18
79
|
quantity: r.quantity,
|
|
19
|
-
unitNetPrice:
|
|
20
|
-
taxRate:
|
|
21
|
-
netValue,
|
|
22
|
-
grossValue,
|
|
80
|
+
unitNetPrice: Number(stored.unitNetPrice),
|
|
81
|
+
taxRate: Number(stored.taxRate),
|
|
82
|
+
netValue: Number(stored.netValue),
|
|
83
|
+
grossValue: Number(stored.grossValue),
|
|
23
84
|
orderItemId: r.orderItemId ?? null,
|
|
85
|
+
stored,
|
|
24
86
|
};
|
|
25
87
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
const vatSummary = [...byRate.entries()]
|
|
35
|
-
.sort((a, b) => a[0] - b[0])
|
|
36
|
-
.map(([taxRate, v]) => {
|
|
37
|
-
const netTotal = round2(v.net);
|
|
38
|
-
const grossTotal = round2(v.gross);
|
|
39
|
-
return { taxRate, netTotal, vatAmount: round2(grossTotal - netTotal), grossTotal };
|
|
40
|
-
});
|
|
41
|
-
const netTotal = round2(vatSummary.reduce((s, r) => s + r.netTotal, 0));
|
|
42
|
-
const taxTotal = round2(vatSummary.reduce((s, r) => s + r.vatAmount, 0));
|
|
43
|
-
const grossTotal = round2(vatSummary.reduce((s, r) => s + r.grossTotal, 0));
|
|
44
|
-
return { lines, vatSummary, netTotal, taxTotal, grossTotal };
|
|
88
|
+
return {
|
|
89
|
+
lines,
|
|
90
|
+
vatSummary: summaryRows(vat.rows),
|
|
91
|
+
storedVatSummary: storedVatRows(vat.rows),
|
|
92
|
+
netTotal: vat.net,
|
|
93
|
+
taxTotal: vat.vat,
|
|
94
|
+
grossTotal: vat.gross,
|
|
95
|
+
};
|
|
45
96
|
}
|
|
46
97
|
//# sourceMappingURL=invoice-line-builder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invoice-line-builder.js","sourceRoot":"","sources":["../../../src/backend/services/invoice-line-builder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"invoice-line-builder.js","sourceRoot":"","sources":["../../../src/backend/services/invoice-line-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,QAAQ,EACR,WAAW,EACX,SAAS,GAGV,MAAM,4BAA4B,CAAC;AA8CpC,gHAAgH;AAChH,SAAS,WAAW,CAAC,IAA8E;IACjG,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACtB,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC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|
2
|
+
/** What an invoice is told about the order's money when it is issued. */
|
|
3
|
+
export interface InvoicePaidInput {
|
|
4
|
+
/** The order's stored total (a two-place decimal). */
|
|
5
|
+
readonly orderTotal: string | number;
|
|
6
|
+
/** The order's payment status. */
|
|
7
|
+
readonly paymentStatus: string;
|
|
8
|
+
/** The kind of the order's payment method, as placement stamped it; `null` when unknown. */
|
|
9
|
+
readonly paymentKind: string | null;
|
|
10
|
+
/** What `payments` captured and refunded over the captured attempts; `null` when nothing was captured or `payments` is absent. */
|
|
11
|
+
readonly payments: {
|
|
12
|
+
readonly captured: string;
|
|
13
|
+
readonly refunded: string;
|
|
14
|
+
} | null;
|
|
15
|
+
/** The money-moving resolutions of the order's settled return cases; empty when `returns` is absent. */
|
|
16
|
+
readonly returnRefunds: readonly OrderReturnRefund[];
|
|
17
|
+
}
|
|
18
|
+
export interface InvoicePaidPosition {
|
|
19
|
+
/** What the buyer paid and kept paid: received less refunded, never below 0. */
|
|
20
|
+
readonly paid: string;
|
|
21
|
+
/** Everything refunded for the order, each refund once. */
|
|
22
|
+
readonly refunded: string;
|
|
23
|
+
/** Something was refunded, and the refunds return everything received and cover the whole order (owner ruling of 2026-10-24). */
|
|
24
|
+
readonly refundedInFull: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* What an invoice records as paid, and whether the order was refunded in full
|
|
28
|
+
* before it was invoiced — issue #417, extended by issue #428 to the refunds
|
|
29
|
+
* that never pass through `payments`
|
|
30
|
+
* (`specs/pricing/worked-examples.md` §10.17).
|
|
31
|
+
*
|
|
32
|
+
* **Received.** What `payments` captured, over the captured attempts; with
|
|
33
|
+
* nothing captured, the order's stored total when the order is recorded as paid
|
|
34
|
+
* (a transfer an operator confirmed) or as refunded (it was paid, then refunded);
|
|
35
|
+
* otherwise nothing — an order on credit terms is unpaid by arrangement.
|
|
36
|
+
*
|
|
37
|
+
* **Refunded, each refund once.**
|
|
38
|
+
* - What `payments` recorded as refunded from the captured attempts — a gateway
|
|
39
|
+
* refund, reflected by the gateway's webhook.
|
|
40
|
+
* - The issued refunds of the order's settled returns that `payments` never
|
|
41
|
+
* sees: every credit-limit top-up, and every money refund of an order whose
|
|
42
|
+
* method is not a gateway (the payments provider records those as issued and
|
|
43
|
+
* an operator makes the transfer). A gateway order's money refund is the
|
|
44
|
+
* gateway's, and `payments` already counts it. A refund still waiting for a
|
|
45
|
+
* person (`pending_manual`) has not happened and is not counted.
|
|
46
|
+
* - An order an operator marked refunded was refunded everything received —
|
|
47
|
+
* with nothing captured, its stored total; with a captured payment, what was
|
|
48
|
+
* captured (a refund settled by hand, e.g. after a refund anomaly). The mark
|
|
49
|
+
* is the larger of the refunds already recorded and what was received, never
|
|
50
|
+
* added to them, so nothing is counted twice.
|
|
51
|
+
*
|
|
52
|
+
* **Paid** is received less refunded, and never below 0: a credit-limit top-up
|
|
53
|
+
* for an order on credit terms reduces nothing that was paid.
|
|
54
|
+
*/
|
|
55
|
+
export declare function invoicePaidPosition(input: InvoicePaidInput): InvoicePaidPosition;
|
|
56
|
+
//# sourceMappingURL=invoice-paid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoice-paid.d.ts","sourceRoot":"","sources":["../../../src/backend/services/invoice-paid.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8C,KAAK,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAEhH,yEAAyE;AACzE,MAAM,WAAW,gBAAgB;IAC/B,sDAAsD;IACtD,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;IACrC,kCAAkC;IAClC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,4FAA4F;IAC5F,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,kIAAkI;IAClI,QAAQ,CAAC,QAAQ,EAAE;QAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACnF,wGAAwG;IACxG,QAAQ,CAAC,aAAa,EAAE,SAAS,iBAAiB,EAAE,CAAC;CACtD;AAED,MAAM,WAAW,mBAAmB;IAClC,gFAAgF;IAChF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,2DAA2D;IAC3D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,iIAAiI;IACjI,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,GAAG,mBAAmB,CA+ChF"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { compareDecimals, moneyDifference, moneySum } from '@endora-commerce/contracts';
|
|
2
|
+
/**
|
|
3
|
+
* What an invoice records as paid, and whether the order was refunded in full
|
|
4
|
+
* before it was invoiced — issue #417, extended by issue #428 to the refunds
|
|
5
|
+
* that never pass through `payments`
|
|
6
|
+
* (`specs/pricing/worked-examples.md` §10.17).
|
|
7
|
+
*
|
|
8
|
+
* **Received.** What `payments` captured, over the captured attempts; with
|
|
9
|
+
* nothing captured, the order's stored total when the order is recorded as paid
|
|
10
|
+
* (a transfer an operator confirmed) or as refunded (it was paid, then refunded);
|
|
11
|
+
* otherwise nothing — an order on credit terms is unpaid by arrangement.
|
|
12
|
+
*
|
|
13
|
+
* **Refunded, each refund once.**
|
|
14
|
+
* - What `payments` recorded as refunded from the captured attempts — a gateway
|
|
15
|
+
* refund, reflected by the gateway's webhook.
|
|
16
|
+
* - The issued refunds of the order's settled returns that `payments` never
|
|
17
|
+
* sees: every credit-limit top-up, and every money refund of an order whose
|
|
18
|
+
* method is not a gateway (the payments provider records those as issued and
|
|
19
|
+
* an operator makes the transfer). A gateway order's money refund is the
|
|
20
|
+
* gateway's, and `payments` already counts it. A refund still waiting for a
|
|
21
|
+
* person (`pending_manual`) has not happened and is not counted.
|
|
22
|
+
* - An order an operator marked refunded was refunded everything received —
|
|
23
|
+
* with nothing captured, its stored total; with a captured payment, what was
|
|
24
|
+
* captured (a refund settled by hand, e.g. after a refund anomaly). The mark
|
|
25
|
+
* is the larger of the refunds already recorded and what was received, never
|
|
26
|
+
* added to them, so nothing is counted twice.
|
|
27
|
+
*
|
|
28
|
+
* **Paid** is received less refunded, and never below 0: a credit-limit top-up
|
|
29
|
+
* for an order on credit terms reduces nothing that was paid.
|
|
30
|
+
*/
|
|
31
|
+
export function invoicePaidPosition(input) {
|
|
32
|
+
const outsidePayments = moneySum(input.returnRefunds
|
|
33
|
+
.filter((refund) => refund.settlementState === 'issued' &&
|
|
34
|
+
(refund.resolutionType === 'credit' || input.paymentKind !== 'gateway'))
|
|
35
|
+
.map((refund) => refund.amount));
|
|
36
|
+
let received;
|
|
37
|
+
let refunded;
|
|
38
|
+
if (input.payments) {
|
|
39
|
+
received = moneySum([input.payments.captured]);
|
|
40
|
+
refunded = moneySum([input.payments.refunded, outsidePayments]);
|
|
41
|
+
}
|
|
42
|
+
else if (input.paymentStatus === 'paid') {
|
|
43
|
+
received = moneySum([input.orderTotal]);
|
|
44
|
+
refunded = outsidePayments;
|
|
45
|
+
}
|
|
46
|
+
else if (input.paymentStatus === 'refunded') {
|
|
47
|
+
// Paid, then refunded: received its stored total (the mark below refunds it).
|
|
48
|
+
received = moneySum([input.orderTotal]);
|
|
49
|
+
refunded = outsidePayments;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
received = '0.00';
|
|
53
|
+
refunded = outsidePayments;
|
|
54
|
+
}
|
|
55
|
+
// An operator's mark that the order was refunded is a refund of everything
|
|
56
|
+
// received, whichever way it was made — by hand after a refund anomaly, or a
|
|
57
|
+
// transfer outside every module (owner ruling on PR #434). It is the larger of
|
|
58
|
+
// what is already recorded and what was received, never their sum, so a
|
|
59
|
+
// gateway refund already on the payment row is not counted twice.
|
|
60
|
+
if (input.paymentStatus === 'refunded' && compareDecimals(refunded, received) < 0)
|
|
61
|
+
refunded = received;
|
|
62
|
+
const kept = moneyDifference(received, refunded);
|
|
63
|
+
return {
|
|
64
|
+
paid: compareDecimals(kept, 0) > 0 ? kept : '0.00',
|
|
65
|
+
refunded,
|
|
66
|
+
// Something must actually have been refunded: a zero-total order (a 100 %
|
|
67
|
+
// coupon, free delivery) has received and refunded nothing, and it is a
|
|
68
|
+
// sale to document, not an order refunded in full (review of PR #434).
|
|
69
|
+
refundedInFull: compareDecimals(refunded, 0) > 0 &&
|
|
70
|
+
compareDecimals(refunded, received) >= 0 &&
|
|
71
|
+
compareDecimals(refunded, input.orderTotal) >= 0,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=invoice-paid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoice-paid.js","sourceRoot":"","sources":["../../../src/backend/services/invoice-paid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,QAAQ,EAA0B,MAAM,4BAA4B,CAAC;AAyBhH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAuB;IACzD,MAAM,eAAe,GAAG,QAAQ,CAC9B,KAAK,CAAC,aAAa;SAChB,MAAM,CACL,CAAC,MAAM,EAAE,EAAE,CACT,MAAM,CAAC,eAAe,KAAK,QAAQ;QACnC,CAAC,MAAM,CAAC,cAAc,KAAK,QAAQ,IAAI,KAAK,CAAC,WAAW,KAAK,SAAS,CAAC,CAC1E;SACA,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAClC,CAAC;IAEF,IAAI,QAAgB,CAAC;IACrB,IAAI,QAAgB,CAAC;IACrB,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QACnB,QAAQ,GAAG,QAAQ,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CA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J,CAAC"}
|
|
@@ -1,13 +1,33 @@
|
|
|
1
1
|
import type { EntityManager } from '@mikro-orm/postgresql';
|
|
2
|
-
import { type InvoiceDetail, type InvoiceKind, type OrderReadPort } from '@endora-commerce/contracts';
|
|
2
|
+
import { type InvoiceDetail, type InvoiceKind, type OrderReadPort, type OrderReturnRefund, type SupportedLanguage } from '@endora-commerce/contracts';
|
|
3
3
|
import type { InvoiceNumberGenerator } from './invoice-number-generator.js';
|
|
4
4
|
import type { SellerSettingsResolver } from './seller-settings.js';
|
|
5
|
+
import { type InvoicesTranslate } from '../invoices-prose.js';
|
|
5
6
|
import { type LedgerNumberingLookup } from './vendor-number-hold.js';
|
|
6
7
|
export interface IssueInvoiceOptions {
|
|
7
8
|
saleDate?: string;
|
|
8
9
|
paymentDueDate?: string;
|
|
9
10
|
issuedBy?: string;
|
|
10
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* What was captured for an order and what was refunded from it, each summed
|
|
14
|
+
* over the captured payment attempts as a two-place decimal — or `null` when no
|
|
15
|
+
* attempt was captured, or the `payments` module is absent and nothing can say
|
|
16
|
+
* (issue #417, review of PR #423).
|
|
17
|
+
*/
|
|
18
|
+
export interface CapturedPaymentsLookup {
|
|
19
|
+
capturedFor(orderId: string): Promise<{
|
|
20
|
+
captured: string;
|
|
21
|
+
refunded: string;
|
|
22
|
+
} | null>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* What the order's settled return cases refunded — an empty list when the
|
|
26
|
+
* `returns` module is absent and nothing can say (issue #428).
|
|
27
|
+
*/
|
|
28
|
+
export interface ReturnRefundsLookup {
|
|
29
|
+
refundsFor(orderId: string): Promise<OrderReturnRefund[]>;
|
|
30
|
+
}
|
|
11
31
|
/** Minimal audit-log seam (FR-035). */
|
|
12
32
|
export interface InvoiceAuditRecorder {
|
|
13
33
|
record(input: {
|
|
@@ -54,9 +74,30 @@ export declare class InvoiceService {
|
|
|
54
74
|
private readonly events?;
|
|
55
75
|
private readonly emailOnReady?;
|
|
56
76
|
private readonly ledgerRouting?;
|
|
77
|
+
private readonly capturedPayments?;
|
|
78
|
+
private readonly returnRefunds?;
|
|
79
|
+
/**
|
|
80
|
+
* The language the lines an invoice itemises beside the products are named
|
|
81
|
+
* in, and this module's bundle to name them from (issue #95). The name is
|
|
82
|
+
* stored with the line — an issued invoice does not change — so it is
|
|
83
|
+
* written in the invoice's language, `INVOICE_RENDER_LANGUAGE` (owner answer
|
|
84
|
+
* N5), at issue. Without a translator, English.
|
|
85
|
+
*/
|
|
86
|
+
private readonly lineProse;
|
|
57
87
|
constructor(emFactory: () => EntityManager,
|
|
58
88
|
/** `orders`' read model. Not optional: an invoice is about an order. */
|
|
59
|
-
orders: OrderReadPort, numbers: InvoiceNumberGenerator, sellerSettings: SellerSettingsResolver, audit?: InvoiceAuditRecorder | undefined, events?: InvoiceDomainEventEmitter | undefined, emailOnReady?: ((invoiceId: string) => Promise<void>) | undefined, ledgerRouting?: LedgerNumberingLookup | undefined
|
|
89
|
+
orders: OrderReadPort, numbers: InvoiceNumberGenerator, sellerSettings: SellerSettingsResolver, audit?: InvoiceAuditRecorder | undefined, events?: InvoiceDomainEventEmitter | undefined, emailOnReady?: ((invoiceId: string) => Promise<void>) | undefined, ledgerRouting?: LedgerNumberingLookup | undefined, capturedPayments?: CapturedPaymentsLookup | undefined, returnRefunds?: ReturnRefundsLookup | undefined,
|
|
90
|
+
/**
|
|
91
|
+
* The language the lines an invoice itemises beside the products are named
|
|
92
|
+
* in, and this module's bundle to name them from (issue #95). The name is
|
|
93
|
+
* stored with the line — an issued invoice does not change — so it is
|
|
94
|
+
* written in the invoice's language, `INVOICE_RENDER_LANGUAGE` (owner answer
|
|
95
|
+
* N5), at issue. Without a translator, English.
|
|
96
|
+
*/
|
|
97
|
+
lineProse?: {
|
|
98
|
+
readonly translate?: InvoicesTranslate | undefined;
|
|
99
|
+
readonly language?: SupportedLanguage;
|
|
100
|
+
});
|
|
60
101
|
/** Issue an invoice/proforma for an order. Idempotent per (order, kind). */
|
|
61
102
|
issue(orderId: string, kind: Exclude<InvoiceKind, 'correction' | 'wz'>, opts?: IssueInvoiceOptions): Promise<InvoiceDetail>;
|
|
62
103
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invoice-service.d.ts","sourceRoot":"","sources":["../../../src/backend/services/invoice-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,
|
|
1
|
+
{"version":3,"file":"invoice-service.d.ts","sourceRoot":"","sources":["../../../src/backend/services/invoice-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,EAOL,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACvB,MAAM,4BAA4B,CAAC;AAMpC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAGnE,OAAO,EAAsB,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAElF,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,yBAAyB,CAAC;AAOjC,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;CACtF;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,UAAU,CAAC,OAAO,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