@endora-commerce/mod-invoices 0.109.0 → 0.111.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/lib/invoice-list-path.d.ts +20 -0
- package/dist/admin/lib/invoice-list-path.js +36 -0
- package/dist/admin/pages/InvoicesList.js +46 -21
- package/dist/admin/templates/invoice-puck-config.js +220 -135
- package/dist/backend/admin-list-cursor.d.ts +20 -0
- package/dist/backend/admin-list-cursor.js +27 -0
- package/dist/backend/entities/invoice-line.entity.d.ts +18 -1
- package/dist/backend/entities/invoice-line.entity.js +20 -0
- package/dist/backend/index.js +19 -3
- package/dist/backend/invoices-prose.d.ts +2 -0
- package/dist/backend/invoices-prose.js +2 -0
- package/dist/backend/pdf-components/embed-logo-images.js +2 -15
- package/dist/backend/pdf-components/sections.js +3 -1
- package/dist/backend/plugin.js +2 -1
- package/dist/backend/routes.admin.js +55 -15
- package/dist/backend/routes.customer.d.ts +3 -3
- package/dist/backend/routes.customer.js +17 -9
- package/dist/backend/seeds/generic-invoice-template.d.ts +13 -7
- package/dist/backend/seeds/generic-invoice-template.js +34 -22
- package/dist/backend/services/auto-issue-reactor.js +6 -2
- package/dist/backend/services/corrective-invoice.d.ts +167 -16
- package/dist/backend/services/corrective-invoice.js +402 -58
- package/dist/backend/services/erp-sale-document-write-port.js +2 -2
- package/dist/backend/services/invoice-copy-host.service.js +3 -0
- package/dist/backend/services/invoice-line-builder.d.ts +4 -0
- package/dist/backend/services/invoice-line-builder.js +1 -0
- package/dist/backend/services/invoice-service.d.ts +27 -4
- package/dist/backend/services/invoice-service.js +75 -17
- package/dist/backend/services/kept-quantities.d.ts +24 -0
- package/dist/backend/services/kept-quantities.js +32 -0
- package/dist/backend/services/order-returns-lock.d.ts +19 -0
- package/dist/backend/services/order-returns-lock.js +37 -0
- package/dist/backend/services/seller-settings.js +1 -1
- package/dist/manifest.d.ts +15 -3
- package/dist/manifest.js +17 -2
- package/dist/migrations/20261108T073244_invoices_invoice_line_kind.d.ts +21 -0
- package/dist/migrations/20261108T073244_invoices_invoice_line_kind.js +28 -0
- package/dist/migrations/index.d.ts +2 -1
- package/dist/migrations/index.js +3 -1
- package/docs/invoices.md +143 -16
- package/i18n/en.json +13 -2
- package/i18n/pl.json +13 -2
- package/package.json +17 -16
- package/dist/admin/components/InvoiceSectionTabs.d.ts.map +0 -1
- package/dist/admin/components/InvoiceSectionTabs.js.map +0 -1
- package/dist/admin/document-blocks/InvoiceDivider.d.ts.map +0 -1
- package/dist/admin/document-blocks/InvoiceDivider.js.map +0 -1
- package/dist/admin/document-blocks/InvoiceFooter.d.ts.map +0 -1
- package/dist/admin/document-blocks/InvoiceFooter.js.map +0 -1
- package/dist/admin/document-blocks/InvoiceHeader.d.ts.map +0 -1
- package/dist/admin/document-blocks/InvoiceHeader.js.map +0 -1
- package/dist/admin/document-blocks/InvoiceLineItems.d.ts.map +0 -1
- package/dist/admin/document-blocks/InvoiceLineItems.js.map +0 -1
- package/dist/admin/document-blocks/InvoiceLogo.d.ts.map +0 -1
- package/dist/admin/document-blocks/InvoiceLogo.js.map +0 -1
- package/dist/admin/document-blocks/InvoiceNotes.d.ts.map +0 -1
- package/dist/admin/document-blocks/InvoiceNotes.js.map +0 -1
- package/dist/admin/document-blocks/InvoiceParties.d.ts.map +0 -1
- package/dist/admin/document-blocks/InvoiceParties.js.map +0 -1
- package/dist/admin/document-blocks/InvoiceSpacer.d.ts.map +0 -1
- package/dist/admin/document-blocks/InvoiceSpacer.js.map +0 -1
- package/dist/admin/document-blocks/InvoiceTotals.d.ts.map +0 -1
- package/dist/admin/document-blocks/InvoiceTotals.js.map +0 -1
- package/dist/admin/document-blocks/InvoiceVatSummary.d.ts.map +0 -1
- package/dist/admin/document-blocks/InvoiceVatSummary.js.map +0 -1
- package/dist/admin/index.d.ts.map +0 -1
- package/dist/admin/index.js.map +0 -1
- package/dist/admin/pages/InvoiceDetail.d.ts.map +0 -1
- package/dist/admin/pages/InvoiceDetail.js.map +0 -1
- package/dist/admin/pages/InvoiceTemplatesRedirect.d.ts.map +0 -1
- package/dist/admin/pages/InvoiceTemplatesRedirect.js.map +0 -1
- package/dist/admin/pages/InvoicesList.d.ts.map +0 -1
- package/dist/admin/pages/InvoicesList.js.map +0 -1
- package/dist/admin/templates/invoice-puck-config.d.ts.map +0 -1
- package/dist/admin/templates/invoice-puck-config.js.map +0 -1
- package/dist/backend/document/block-descriptions.d.ts.map +0 -1
- package/dist/backend/document/block-descriptions.js.map +0 -1
- package/dist/backend/document/document-templates-grant.d.ts.map +0 -1
- package/dist/backend/document/document-templates-grant.js.map +0 -1
- package/dist/backend/document/invoice-document-type.d.ts.map +0 -1
- package/dist/backend/document/invoice-document-type.js.map +0 -1
- package/dist/backend/document/render-invoice.d.ts.map +0 -1
- package/dist/backend/document/render-invoice.js.map +0 -1
- package/dist/backend/email-templates/invoice-issued.default.d.ts.map +0 -1
- package/dist/backend/email-templates/invoice-issued.default.js.map +0 -1
- package/dist/backend/entities/invoice-external-attachment.entity.d.ts.map +0 -1
- package/dist/backend/entities/invoice-external-attachment.entity.js.map +0 -1
- package/dist/backend/entities/invoice-line.entity.d.ts.map +0 -1
- package/dist/backend/entities/invoice-line.entity.js.map +0 -1
- package/dist/backend/entities/invoice-number-counter.entity.d.ts.map +0 -1
- package/dist/backend/entities/invoice-number-counter.entity.js.map +0 -1
- package/dist/backend/entities/invoice.entity.d.ts.map +0 -1
- package/dist/backend/entities/invoice.entity.js.map +0 -1
- package/dist/backend/index.d.ts.map +0 -1
- package/dist/backend/index.js.map +0 -1
- package/dist/backend/invoices-prose.d.ts.map +0 -1
- package/dist/backend/invoices-prose.js.map +0 -1
- package/dist/backend/pdf-components/embed-logo-images.d.ts.map +0 -1
- package/dist/backend/pdf-components/embed-logo-images.js.map +0 -1
- package/dist/backend/pdf-components/sample.d.ts.map +0 -1
- package/dist/backend/pdf-components/sample.js.map +0 -1
- package/dist/backend/pdf-components/sections.d.ts.map +0 -1
- package/dist/backend/pdf-components/sections.js.map +0 -1
- package/dist/backend/pdf-components/tree-mapper.d.ts.map +0 -1
- package/dist/backend/pdf-components/tree-mapper.js.map +0 -1
- package/dist/backend/plugin.d.ts.map +0 -1
- package/dist/backend/plugin.js.map +0 -1
- package/dist/backend/routes.admin.d.ts.map +0 -1
- package/dist/backend/routes.admin.js.map +0 -1
- package/dist/backend/routes.customer.d.ts.map +0 -1
- package/dist/backend/routes.customer.js.map +0 -1
- package/dist/backend/seeds/generic-invoice-template.d.ts.map +0 -1
- package/dist/backend/seeds/generic-invoice-template.js.map +0 -1
- package/dist/backend/services/amount-to-words.d.ts.map +0 -1
- package/dist/backend/services/amount-to-words.js.map +0 -1
- package/dist/backend/services/auto-issue-reactor.d.ts.map +0 -1
- package/dist/backend/services/auto-issue-reactor.js.map +0 -1
- package/dist/backend/services/corrective-invoice.d.ts.map +0 -1
- package/dist/backend/services/corrective-invoice.js.map +0 -1
- package/dist/backend/services/cross-module-context.d.ts.map +0 -1
- package/dist/backend/services/cross-module-context.js.map +0 -1
- package/dist/backend/services/duplicate-number-refusal.d.ts.map +0 -1
- package/dist/backend/services/duplicate-number-refusal.js.map +0 -1
- package/dist/backend/services/erp-sale-document-write-port.d.ts.map +0 -1
- package/dist/backend/services/erp-sale-document-write-port.js.map +0 -1
- package/dist/backend/services/invoice-attachment-fetch-registry.d.ts.map +0 -1
- package/dist/backend/services/invoice-attachment-fetch-registry.js.map +0 -1
- package/dist/backend/services/invoice-copy-host.service.d.ts.map +0 -1
- package/dist/backend/services/invoice-copy-host.service.js.map +0 -1
- package/dist/backend/services/invoice-email-dispatch.d.ts.map +0 -1
- package/dist/backend/services/invoice-email-dispatch.js.map +0 -1
- package/dist/backend/services/invoice-line-builder.d.ts.map +0 -1
- package/dist/backend/services/invoice-line-builder.js.map +0 -1
- package/dist/backend/services/invoice-number-collisions.d.ts.map +0 -1
- package/dist/backend/services/invoice-number-collisions.js.map +0 -1
- package/dist/backend/services/invoice-number-generator.d.ts.map +0 -1
- package/dist/backend/services/invoice-number-generator.js.map +0 -1
- package/dist/backend/services/invoice-paid.d.ts.map +0 -1
- package/dist/backend/services/invoice-paid.js.map +0 -1
- package/dist/backend/services/invoice-pdf-block-registry.d.ts.map +0 -1
- package/dist/backend/services/invoice-pdf-block-registry.js.map +0 -1
- package/dist/backend/services/invoice-pdf.d.ts.map +0 -1
- package/dist/backend/services/invoice-pdf.js.map +0 -1
- package/dist/backend/services/invoice-placement-apply-port.d.ts.map +0 -1
- package/dist/backend/services/invoice-placement-apply-port.js.map +0 -1
- package/dist/backend/services/invoice-read-port.d.ts.map +0 -1
- package/dist/backend/services/invoice-read-port.js.map +0 -1
- package/dist/backend/services/invoice-service.d.ts.map +0 -1
- package/dist/backend/services/invoice-service.js.map +0 -1
- package/dist/backend/services/numbering-configuration.d.ts.map +0 -1
- package/dist/backend/services/numbering-configuration.js.map +0 -1
- package/dist/backend/services/numbering-write-validator.d.ts.map +0 -1
- package/dist/backend/services/numbering-write-validator.js.map +0 -1
- package/dist/backend/services/seller-settings.d.ts.map +0 -1
- package/dist/backend/services/seller-settings.js.map +0 -1
- package/dist/backend/services/vendor-number-hold.d.ts.map +0 -1
- package/dist/backend/services/vendor-number-hold.js.map +0 -1
- package/dist/manifest.d.ts.map +0 -1
- package/dist/manifest.js.map +0 -1
- package/dist/migrations/20260629T125121_invoices_module.d.ts.map +0 -1
- package/dist/migrations/20260629T125121_invoices_module.js.map +0 -1
- package/dist/migrations/20260801T111000_invoices_generic_template_reseed.d.ts.map +0 -1
- package/dist/migrations/20260801T111000_invoices_generic_template_reseed.js.map +0 -1
- package/dist/migrations/20260817T201110_invoices_correction_idempotency_key.d.ts.map +0 -1
- package/dist/migrations/20260817T201110_invoices_correction_idempotency_key.js.map +0 -1
- package/dist/migrations/20260903T101756_invoices_namespace_block_names.d.ts.map +0 -1
- package/dist/migrations/20260903T101756_invoices_namespace_block_names.js.map +0 -1
- package/dist/migrations/20260914T133603_invoices_erp_imported_sale_documents.d.ts.map +0 -1
- package/dist/migrations/20260914T133603_invoices_erp_imported_sale_documents.js.map +0 -1
- package/dist/migrations/20260926T230239_invoices_import_identity.d.ts.map +0 -1
- package/dist/migrations/20260926T230239_invoices_import_identity.js.map +0 -1
- package/dist/migrations/20261017T075839_invoices_drop_invoice_templates.d.ts.map +0 -1
- package/dist/migrations/20261017T075839_invoices_drop_invoice_templates.js.map +0 -1
- package/dist/migrations/20261024T145631_invoices_vat_summary.d.ts.map +0 -1
- package/dist/migrations/20261024T145631_invoices_vat_summary.js.map +0 -1
- package/dist/migrations/index.d.ts.map +0 -1
- package/dist/migrations/index.js.map +0 -1
- package/dist/ports/index.d.ts.map +0 -1
- package/dist/ports/index.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ERROR_CODES, erpSaleDocumentUpsertInputSchema, } from '@endora-commerce/contracts';
|
|
2
2
|
import { HttpError } from '@endora-commerce/platform/http';
|
|
3
|
-
import {
|
|
3
|
+
import { orgInScope } from '@endora-commerce/platform/tenancy';
|
|
4
4
|
import { InvoiceExternalAttachment } from '../entities/invoice-external-attachment.entity.js';
|
|
5
5
|
import { Invoice } from '../entities/invoice.entity.js';
|
|
6
6
|
export class ErpSaleDocumentWritePortService {
|
|
@@ -29,7 +29,7 @@ export class ErpSaleDocumentWritePortService {
|
|
|
29
29
|
})));
|
|
30
30
|
}
|
|
31
31
|
const input = parsed.data;
|
|
32
|
-
if (!
|
|
32
|
+
if (!(await orgInScope(input.organizationId))) {
|
|
33
33
|
throw new HttpError(404, ERROR_CODES.NOT_FOUND, 'Organization not found.');
|
|
34
34
|
}
|
|
35
35
|
const em = this.emFactory();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Invoice } from '../entities/invoice.entity.js';
|
|
2
2
|
import { InvoiceLine as InvoiceLineEntity } from '../entities/invoice-line.entity.js';
|
|
3
|
+
import { isUuidShape } from '@endora-commerce/contracts';
|
|
3
4
|
const EMPTY_BUYER = {
|
|
4
5
|
name: '',
|
|
5
6
|
taxId: '',
|
|
@@ -18,6 +19,8 @@ export class InvoiceCopyHostService {
|
|
|
18
19
|
}
|
|
19
20
|
async getById(invoiceId) {
|
|
20
21
|
const em = this.emFactory();
|
|
22
|
+
if (!isUuidShape(invoiceId))
|
|
23
|
+
return null;
|
|
21
24
|
const invoice = await em.findOne(Invoice, { id: invoiceId });
|
|
22
25
|
if (!invoice)
|
|
23
26
|
return null;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type InvoiceLine, type VatSummaryRow } from '@endora-commerce/contracts';
|
|
2
|
+
import type { InvoiceLineKind } from '../entities/invoice-line.entity.js';
|
|
2
3
|
export interface RawOrderLine {
|
|
3
4
|
name: string;
|
|
4
5
|
unit: string;
|
|
@@ -10,6 +11,8 @@ export interface RawOrderLine {
|
|
|
10
11
|
/** Net line value (quantity × unitNetPrice) at two places. */
|
|
11
12
|
netValue: string | number;
|
|
12
13
|
orderItemId?: string | null;
|
|
14
|
+
/** Issue #904 — what the line is; carried to `invoice_lines.line_kind`. */
|
|
15
|
+
lineKind?: InvoiceLineKind | null;
|
|
13
16
|
}
|
|
14
17
|
/** The line's amounts as the `invoice_lines` columns store them. */
|
|
15
18
|
export interface StoredInvoiceLineAmounts {
|
|
@@ -20,6 +23,7 @@ export interface StoredInvoiceLineAmounts {
|
|
|
20
23
|
}
|
|
21
24
|
export type BuiltInvoiceLine = InvoiceLine & {
|
|
22
25
|
orderItemId?: string | null;
|
|
26
|
+
lineKind: InvoiceLineKind | null;
|
|
23
27
|
stored: StoredInvoiceLineAmounts;
|
|
24
28
|
};
|
|
25
29
|
export interface BuiltInvoiceTotals {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { EntityManager } from '@mikro-orm/postgresql';
|
|
2
|
-
import { type InvoiceDetail, type InvoiceKind, type OrderReadPort, type OrderReturnRefund, type SupportedLanguage } from '@endora-commerce/contracts';
|
|
2
|
+
import { type InvoiceDetail, type InvoiceKind, type OrderReadPort, type OrderRefundedCharges, type OrderReturnRefund, type OrderReturnedQuantity, 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 { OrderReturnsLock } from './order-returns-lock.js';
|
|
5
6
|
import { type InvoicesTranslate } from '../invoices-prose.js';
|
|
6
7
|
import { type LedgerNumberingLookup } from './vendor-number-hold.js';
|
|
7
8
|
export interface IssueInvoiceOptions {
|
|
@@ -22,11 +23,18 @@ export interface CapturedPaymentsLookup {
|
|
|
22
23
|
} | null>;
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
|
-
* What the order's settled return cases refunded
|
|
26
|
-
*
|
|
26
|
+
* What the order's settled return cases refunded (issue #428), and what of the
|
|
27
|
+
* order came back with them (issue #435) — empty lists when the `returns`
|
|
28
|
+
* module is absent and nothing can say.
|
|
27
29
|
*/
|
|
28
30
|
export interface ReturnRefundsLookup {
|
|
29
31
|
refundsFor(orderId: string): Promise<OrderReturnRefund[]>;
|
|
32
|
+
returnedQuantitiesFor(orderId: string): Promise<OrderReturnedQuantity[]>;
|
|
33
|
+
/**
|
|
34
|
+
* What those cases refunded of the order's delivery and surcharge (issue
|
|
35
|
+
* #876) — `0.00` each when `returns` is absent and nothing can say.
|
|
36
|
+
*/
|
|
37
|
+
refundedChargesFor(orderId: string): Promise<OrderRefundedCharges>;
|
|
30
38
|
}
|
|
31
39
|
/** Minimal audit-log seam (FR-035). */
|
|
32
40
|
export interface InvoiceAuditRecorder {
|
|
@@ -65,6 +73,7 @@ export interface InvoiceDomainEventEmitter {
|
|
|
65
73
|
* is worse than refusing to issue one.
|
|
66
74
|
*/
|
|
67
75
|
export declare class InvoiceService {
|
|
76
|
+
#private;
|
|
68
77
|
private readonly emFactory;
|
|
69
78
|
/** `orders`' read model. Not optional: an invoice is about an order. */
|
|
70
79
|
private readonly orders;
|
|
@@ -84,6 +93,13 @@ export declare class InvoiceService {
|
|
|
84
93
|
* N5), at issue. Without a translator, English.
|
|
85
94
|
*/
|
|
86
95
|
private readonly lineProse;
|
|
96
|
+
/**
|
|
97
|
+
* The order's returns lock (review of PR #865, F3): issuing holds it, so an
|
|
98
|
+
* invoice never reads a case a settlement has moved money for but not yet
|
|
99
|
+
* recorded. The composition always supplies it; without it (a unit test's
|
|
100
|
+
* fake entity manager) issuance takes no lock.
|
|
101
|
+
*/
|
|
102
|
+
private readonly returnsLock?;
|
|
87
103
|
constructor(emFactory: () => EntityManager,
|
|
88
104
|
/** `orders`' read model. Not optional: an invoice is about an order. */
|
|
89
105
|
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,
|
|
@@ -97,7 +113,14 @@ export declare class InvoiceService {
|
|
|
97
113
|
lineProse?: {
|
|
98
114
|
readonly translate?: InvoicesTranslate | undefined;
|
|
99
115
|
readonly language?: SupportedLanguage;
|
|
100
|
-
}
|
|
116
|
+
},
|
|
117
|
+
/**
|
|
118
|
+
* The order's returns lock (review of PR #865, F3): issuing holds it, so an
|
|
119
|
+
* invoice never reads a case a settlement has moved money for but not yet
|
|
120
|
+
* recorded. The composition always supplies it; without it (a unit test's
|
|
121
|
+
* fake entity manager) issuance takes no lock.
|
|
122
|
+
*/
|
|
123
|
+
returnsLock?: OrderReturnsLock | undefined);
|
|
101
124
|
/** Issue an invoice/proforma for an order. Idempotent per (order, kind). */
|
|
102
125
|
issue(orderId: string, kind: Exclude<InvoiceKind, 'correction' | 'wz'>, opts?: IssueInvoiceOptions): Promise<InvoiceDetail>;
|
|
103
126
|
/**
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { randomUUID } from 'crypto';
|
|
2
2
|
import { HttpError } from '@endora-commerce/platform/http';
|
|
3
|
-
import { ERROR_CODES, compareDecimals, lineAmountHalfUp, moneyDifference, roundHalfUp, supportedLanguageOf, } from '@endora-commerce/contracts';
|
|
3
|
+
import { ERROR_CODES, compareDecimals, lineAmountHalfUp, moneyDifference, roundHalfUp, supportedLanguageOf, isUuidShape, } from '@endora-commerce/contracts';
|
|
4
4
|
import { Invoice } from '../entities/invoice.entity.js';
|
|
5
5
|
import { InvoiceLine } from '../entities/invoice-line.entity.js';
|
|
6
|
-
import {
|
|
6
|
+
import { orgInScope } from '@endora-commerce/platform/tenancy';
|
|
7
7
|
import { rethrowIfModuleDisabled } from '@endora-commerce/platform/kernel';
|
|
8
8
|
import { refuseDuplicateInvoiceNumber } from './duplicate-number-refusal.js';
|
|
9
9
|
import { buildInvoiceLines, readModelVatSummary } from './invoice-line-builder.js';
|
|
10
10
|
import { invoicePaidPosition } from './invoice-paid.js';
|
|
11
|
+
import { keptDiscount, keptOrderLines } from './kept-quantities.js';
|
|
11
12
|
import { invoicesProseTable } from '../invoices-prose.js';
|
|
12
13
|
import { INVOICE_RENDER_LANGUAGE } from '../document/invoice-document-type.js';
|
|
13
14
|
import { shouldHoldForVendorNumber, } from './vendor-number-hold.js';
|
|
@@ -24,7 +25,6 @@ const INVOICE_LINE_NAME_KEYS = [
|
|
|
24
25
|
'lines.paymentSurcharge',
|
|
25
26
|
'lines.discount',
|
|
26
27
|
];
|
|
27
|
-
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
28
28
|
/**
|
|
29
29
|
* Core invoice issuance + read service (feature 047, US1). Issues invoices /
|
|
30
30
|
* proformas (and is reused by the corrective-invoice provider for credit
|
|
@@ -52,6 +52,7 @@ export class InvoiceService {
|
|
|
52
52
|
capturedPayments;
|
|
53
53
|
returnRefunds;
|
|
54
54
|
lineProse;
|
|
55
|
+
returnsLock;
|
|
55
56
|
constructor(emFactory,
|
|
56
57
|
/** `orders`' read model. Not optional: an invoice is about an order. */
|
|
57
58
|
orders, numbers, sellerSettings, audit, events, emailOnReady, ledgerRouting, capturedPayments, returnRefunds,
|
|
@@ -62,7 +63,14 @@ export class InvoiceService {
|
|
|
62
63
|
* written in the invoice's language, `INVOICE_RENDER_LANGUAGE` (owner answer
|
|
63
64
|
* N5), at issue. Without a translator, English.
|
|
64
65
|
*/
|
|
65
|
-
lineProse = {}
|
|
66
|
+
lineProse = {},
|
|
67
|
+
/**
|
|
68
|
+
* The order's returns lock (review of PR #865, F3): issuing holds it, so an
|
|
69
|
+
* invoice never reads a case a settlement has moved money for but not yet
|
|
70
|
+
* recorded. The composition always supplies it; without it (a unit test's
|
|
71
|
+
* fake entity manager) issuance takes no lock.
|
|
72
|
+
*/
|
|
73
|
+
returnsLock) {
|
|
66
74
|
this.emFactory = emFactory;
|
|
67
75
|
this.orders = orders;
|
|
68
76
|
this.numbers = numbers;
|
|
@@ -74,13 +82,19 @@ export class InvoiceService {
|
|
|
74
82
|
this.capturedPayments = capturedPayments;
|
|
75
83
|
this.returnRefunds = returnRefunds;
|
|
76
84
|
this.lineProse = lineProse;
|
|
85
|
+
this.returnsLock = returnsLock;
|
|
77
86
|
}
|
|
78
87
|
/** Issue an invoice/proforma for an order. Idempotent per (order, kind). */
|
|
79
88
|
async issue(orderId, kind, opts = {}) {
|
|
89
|
+
if (this.returnsLock)
|
|
90
|
+
return this.returnsLock.run(orderId, () => this.#issue(orderId, kind, opts));
|
|
91
|
+
return this.#issue(orderId, kind, opts);
|
|
92
|
+
}
|
|
93
|
+
async #issue(orderId, kind, opts) {
|
|
80
94
|
const em = this.emFactory();
|
|
81
95
|
const order = await this.orders.findById(orderId);
|
|
82
96
|
// Feature 050 — Invoice is transitively scoped through its Order's org.
|
|
83
|
-
if (!order || !
|
|
97
|
+
if (!order || !(await orgInScope(order.organizationId ?? ''))) {
|
|
84
98
|
throw new HttpError(404, ERROR_CODES.ORDER_NOT_FOUND, 'Order not found.');
|
|
85
99
|
}
|
|
86
100
|
const existing = await em.findOne(Invoice, { orderId, kind });
|
|
@@ -94,21 +108,36 @@ export class InvoiceService {
|
|
|
94
108
|
// (`unitPrice × quantity × (1 + taxRate)`), and reading it as the net taxed
|
|
95
109
|
// every VAT-payer line twice — the invoice's net was the order's gross.
|
|
96
110
|
const names = await invoicesProseTable(this.lineProse.translate, INVOICE_LINE_NAME_KEYS, this.lineProse.language ?? supportedLanguageOf(INVOICE_RENDER_LANGUAGE));
|
|
97
|
-
|
|
111
|
+
// Only what the buyer kept (issue #435, product-owner ruling of
|
|
112
|
+
// 2026-11-07): a return settled with a refund or a credit before the
|
|
113
|
+
// invoice exists has no invoice to correct (#135), so the invoice lists
|
|
114
|
+
// each line at its ordered quantity less what came back, and a line
|
|
115
|
+
// returned in full drops out. The delivery and surcharge lines below are
|
|
116
|
+
// the order's, less what a consumer's withdrawal refunded of them (issue
|
|
117
|
+
// #876); the discount line carries only the kept goods' share (ruling Q3).
|
|
118
|
+
const returned = (await this.returnRefunds?.returnedQuantitiesFor(orderId)) ?? [];
|
|
119
|
+
const raw = keptOrderLines(items, returned).map(({ item: it, quantity }) => ({
|
|
98
120
|
name: it.productSnapshot?.name ?? names['lines.item'],
|
|
99
121
|
unit: it.packagingUnitSnapshot?.name ?? names['lines.unit.piece'],
|
|
100
|
-
quantity
|
|
122
|
+
quantity,
|
|
101
123
|
unitNetPrice: it.unitPrice,
|
|
102
124
|
taxRate: it.taxRate,
|
|
103
|
-
netValue: lineAmountHalfUp(it.unitPrice,
|
|
125
|
+
netValue: lineAmountHalfUp(it.unitPrice, quantity),
|
|
104
126
|
orderItemId: it.id,
|
|
127
|
+
lineKind: 'goods',
|
|
105
128
|
}));
|
|
106
129
|
// Itemize the order's non-product amounts so the invoice total reconciles
|
|
107
130
|
// with the order total. The order model adds delivery + payment surcharge
|
|
108
131
|
// and subtracts the discount on the gross without extra VAT, so each is a
|
|
109
132
|
// 0%-VAT line (the discount is a negative line).
|
|
110
133
|
// The amounts are read as the decimals they are stored as (issue #417).
|
|
111
|
-
|
|
134
|
+
// Issue #876 — less what a settled return refunded of each: a consumer's
|
|
135
|
+
// withdrawal from the whole sale refunds the delivery and the surcharge, so
|
|
136
|
+
// the invoice charges only what is left, and a line that reaches 0 drops
|
|
137
|
+
// out. What is left is a delivery the operator reduced to the standard
|
|
138
|
+
// price (art. 13(2)), or one a business customer's return kept.
|
|
139
|
+
const refundedCharges = (await this.returnRefunds?.refundedChargesFor(orderId)) ?? { delivery: '0', surcharge: '0' };
|
|
140
|
+
const deliveryTotal = maxDecimal(moneyDifference(roundHalfUp(order.deliveryTotal ?? 0), refundedCharges.delivery), '0.00');
|
|
112
141
|
if (Number(deliveryTotal) > 0) {
|
|
113
142
|
raw.push({
|
|
114
143
|
name: names['lines.delivery'],
|
|
@@ -117,9 +146,10 @@ export class InvoiceService {
|
|
|
117
146
|
unitNetPrice: deliveryTotal,
|
|
118
147
|
taxRate: 0,
|
|
119
148
|
netValue: deliveryTotal,
|
|
149
|
+
lineKind: 'delivery',
|
|
120
150
|
});
|
|
121
151
|
}
|
|
122
|
-
const surcharge = roundHalfUp(order.paymentMethodSnapshot?.additionalPrice ?? 0);
|
|
152
|
+
const surcharge = maxDecimal(moneyDifference(roundHalfUp(order.paymentMethodSnapshot?.additionalPrice ?? 0), refundedCharges.surcharge), '0.00');
|
|
123
153
|
if (Number(surcharge) > 0) {
|
|
124
154
|
raw.push({
|
|
125
155
|
name: names['lines.paymentSurcharge'],
|
|
@@ -128,9 +158,17 @@ export class InvoiceService {
|
|
|
128
158
|
unitNetPrice: surcharge,
|
|
129
159
|
taxRate: 0,
|
|
130
160
|
netValue: surcharge,
|
|
161
|
+
lineKind: 'payment_surcharge',
|
|
131
162
|
});
|
|
132
163
|
}
|
|
133
|
-
|
|
164
|
+
// Whether anything is left to sell: a kept product line, the delivery or
|
|
165
|
+
// the payment surcharge. A discount line alone is not a sale (F4).
|
|
166
|
+
const keptSale = raw.length > 0;
|
|
167
|
+
// The discount the settled returns did not carry back (issue #435,
|
|
168
|
+
// product-owner ruling Q3 of 2026-11-07): their refunds already gave the
|
|
169
|
+
// buyer the rest, so the invoice of the kept goods, like what was paid,
|
|
170
|
+
// takes only this much off. Without a return it is the order's discount.
|
|
171
|
+
const discountTotal = keptDiscount(order.discountTotal ?? 0, returned);
|
|
134
172
|
if (Number(discountTotal) > 0) {
|
|
135
173
|
const negative = `-${discountTotal}`;
|
|
136
174
|
raw.push({
|
|
@@ -140,6 +178,7 @@ export class InvoiceService {
|
|
|
140
178
|
unitNetPrice: negative,
|
|
141
179
|
taxRate: 0,
|
|
142
180
|
netValue: negative,
|
|
181
|
+
lineKind: 'discount',
|
|
143
182
|
});
|
|
144
183
|
}
|
|
145
184
|
const built = buildInvoiceLines(raw);
|
|
@@ -164,8 +203,17 @@ export class InvoiceService {
|
|
|
164
203
|
// nothing kept, and the refunds cover the whole order — has no sale left to
|
|
165
204
|
// document, so it is not invoiced (owner ruling of 2026-10-24). One refunded
|
|
166
205
|
// in part is invoiced, with what was kept as paid.
|
|
167
|
-
|
|
168
|
-
|
|
206
|
+
//
|
|
207
|
+
// An order returned in full before it was invoiced — every product line
|
|
208
|
+
// back, and no delivery or surcharge kept — has no sale left either,
|
|
209
|
+
// whether or not the refund has been paid out yet: one waiting for a
|
|
210
|
+
// person, or for the gateway's webhook, refuses it the same way
|
|
211
|
+
// (product-owner ruling on F4, review of PR #865). Both are answered
|
|
212
|
+
// before a number is drawn; a proforma is refused for neither.
|
|
213
|
+
if (kind === 'invoice' && (position.refundedInFull || !keptSale)) {
|
|
214
|
+
throw new HttpError(422, ERROR_CODES.INVOICE_ORDER_REFUNDED, position.refundedInFull
|
|
215
|
+
? 'The order was refunded in full before it was invoiced, so there is no sale left to invoice.'
|
|
216
|
+
: 'The order was returned in full before it was invoiced, so there is no sale left to invoice.', { reason: position.refundedInFull ? 'refunded_in_full' : 'returned_in_full' });
|
|
169
217
|
}
|
|
170
218
|
const paidTotal = position.paid;
|
|
171
219
|
const buyer = {
|
|
@@ -220,6 +268,7 @@ export class InvoiceService {
|
|
|
220
268
|
netValue: l.stored.netValue,
|
|
221
269
|
grossValue: l.stored.grossValue,
|
|
222
270
|
orderItemId: l.orderItemId ?? null,
|
|
271
|
+
lineKind: l.lineKind,
|
|
223
272
|
});
|
|
224
273
|
}
|
|
225
274
|
await tx.flush();
|
|
@@ -229,7 +278,7 @@ export class InvoiceService {
|
|
|
229
278
|
if (this.audit) {
|
|
230
279
|
await this.audit
|
|
231
280
|
.record({
|
|
232
|
-
actorAdminUserId: opts.issuedBy &&
|
|
281
|
+
actorAdminUserId: opts.issuedBy && isUuidShape(opts.issuedBy) ? opts.issuedBy : null,
|
|
233
282
|
action: 'invoice.issued',
|
|
234
283
|
objectType: 'invoice',
|
|
235
284
|
objectId: invoice.id,
|
|
@@ -238,7 +287,8 @@ export class InvoiceService {
|
|
|
238
287
|
kind: invoice.kind,
|
|
239
288
|
orderId,
|
|
240
289
|
salesChannelId: order.salesChannelId,
|
|
241
|
-
|
|
290
|
+
// No amount (#470, D-288): the invoice is the Organization's, and the
|
|
291
|
+
// audit log is read without its reach. The total is on the invoice.
|
|
242
292
|
},
|
|
243
293
|
})
|
|
244
294
|
.catch(() => undefined);
|
|
@@ -286,6 +336,8 @@ export class InvoiceService {
|
|
|
286
336
|
*/
|
|
287
337
|
async recordKsefAssignment(invoiceId, assignment) {
|
|
288
338
|
const em = this.emFactory().fork();
|
|
339
|
+
if (!isUuidShape(invoiceId))
|
|
340
|
+
throw new HttpError(404, ERROR_CODES.NOT_FOUND, 'Invoice not found.');
|
|
289
341
|
const inv = await em.findOne(Invoice, { id: invoiceId });
|
|
290
342
|
if (!inv)
|
|
291
343
|
throw new HttpError(404, ERROR_CODES.NOT_FOUND, 'Invoice not found.');
|
|
@@ -307,6 +359,8 @@ export class InvoiceService {
|
|
|
307
359
|
*/
|
|
308
360
|
async applyVendorAssignedNumber(invoiceId, number) {
|
|
309
361
|
const em = this.emFactory().fork();
|
|
362
|
+
if (!isUuidShape(invoiceId))
|
|
363
|
+
throw new HttpError(404, ERROR_CODES.NOT_FOUND, 'Invoice not found.');
|
|
310
364
|
const inv = await em.findOne(Invoice, { id: invoiceId });
|
|
311
365
|
if (!inv)
|
|
312
366
|
throw new HttpError(404, ERROR_CODES.NOT_FOUND, 'Invoice not found.');
|
|
@@ -334,6 +388,8 @@ export class InvoiceService {
|
|
|
334
388
|
*/
|
|
335
389
|
async recordPaidFromLedger(invoiceId) {
|
|
336
390
|
const em = this.emFactory().fork();
|
|
391
|
+
if (!isUuidShape(invoiceId))
|
|
392
|
+
throw new HttpError(404, ERROR_CODES.NOT_FOUND, 'Invoice not found.');
|
|
337
393
|
const inv = await em.findOne(Invoice, { id: invoiceId });
|
|
338
394
|
if (!inv)
|
|
339
395
|
throw new HttpError(404, ERROR_CODES.NOT_FOUND, 'Invoice not found.');
|
|
@@ -347,16 +403,18 @@ export class InvoiceService {
|
|
|
347
403
|
/** Load an invoice as a render-ready detail (lines + derived VAT summary). */
|
|
348
404
|
async buildDetail(invoiceId) {
|
|
349
405
|
const em = this.emFactory();
|
|
406
|
+
if (!isUuidShape(invoiceId))
|
|
407
|
+
throw new HttpError(404, ERROR_CODES.NOT_FOUND, 'Invoice not found.');
|
|
350
408
|
const inv = await em.findOne(Invoice, { id: invoiceId });
|
|
351
409
|
if (!inv)
|
|
352
410
|
throw new HttpError(404, ERROR_CODES.NOT_FOUND, 'Invoice not found.');
|
|
353
411
|
const order = inv.orderId ? await this.orders.findById(inv.orderId) : null;
|
|
354
412
|
if (inv.origin === 'erp_import') {
|
|
355
|
-
if (!
|
|
413
|
+
if (!(await orgInScope(inv.organizationId ?? ''))) {
|
|
356
414
|
throw new HttpError(404, ERROR_CODES.NOT_FOUND, 'Invoice not found.');
|
|
357
415
|
}
|
|
358
416
|
}
|
|
359
|
-
else if (!order || !
|
|
417
|
+
else if (!order || !(await orgInScope(order.organizationId ?? ''))) {
|
|
360
418
|
throw new HttpError(404, ERROR_CODES.NOT_FOUND, 'Invoice not found.');
|
|
361
419
|
}
|
|
362
420
|
const lineRows = await em.find(InvoiceLine, { invoiceId }, { orderBy: { ordinal: 'asc' } });
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type OrderReturnedQuantity } from '@endora-commerce/contracts';
|
|
2
|
+
/**
|
|
3
|
+
* The order lines an invoice issued after a return lists, each with the
|
|
4
|
+
* quantity the buyer kept (issue #435, product-owner ruling of 2026-11-07):
|
|
5
|
+
* the ordered quantity less what settled returns took back, in the order's
|
|
6
|
+
* order. A line returned in full drops out. There is no invoice to correct
|
|
7
|
+
* before the first one is issued (#135), so the invoice itself documents the
|
|
8
|
+
* sale that is left.
|
|
9
|
+
*/
|
|
10
|
+
export declare function keptOrderLines<T extends {
|
|
11
|
+
id: string;
|
|
12
|
+
quantity: number;
|
|
13
|
+
}>(items: readonly T[], returned: readonly OrderReturnedQuantity[]): Array<{
|
|
14
|
+
item: T;
|
|
15
|
+
quantity: number;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* The order-level discount an invoice issued after a return lists (issue #435,
|
|
19
|
+
* product-owner ruling Q3 of 2026-11-07): the order's discount less what the
|
|
20
|
+
* settled returns carried back, as they recorded it — the kept goods' share —
|
|
21
|
+
* at two places, and never below zero. `'0.00'` means the line is left off.
|
|
22
|
+
*/
|
|
23
|
+
export declare function keptDiscount(orderDiscount: string | number, returned: readonly OrderReturnedQuantity[]): string;
|
|
24
|
+
//# sourceMappingURL=kept-quantities.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { compareDecimals, moneyDifference, moneySum, roundHalfUp } from '@endora-commerce/contracts';
|
|
2
|
+
/**
|
|
3
|
+
* The order lines an invoice issued after a return lists, each with the
|
|
4
|
+
* quantity the buyer kept (issue #435, product-owner ruling of 2026-11-07):
|
|
5
|
+
* the ordered quantity less what settled returns took back, in the order's
|
|
6
|
+
* order. A line returned in full drops out. There is no invoice to correct
|
|
7
|
+
* before the first one is issued (#135), so the invoice itself documents the
|
|
8
|
+
* sale that is left.
|
|
9
|
+
*/
|
|
10
|
+
export function keptOrderLines(items, returned) {
|
|
11
|
+
const back = new Map();
|
|
12
|
+
for (const r of returned)
|
|
13
|
+
back.set(r.orderItemId, (back.get(r.orderItemId) ?? 0) + r.quantity);
|
|
14
|
+
const kept = [];
|
|
15
|
+
for (const item of items) {
|
|
16
|
+
const quantity = item.quantity - (back.get(item.id) ?? 0);
|
|
17
|
+
if (quantity > 0)
|
|
18
|
+
kept.push({ item, quantity });
|
|
19
|
+
}
|
|
20
|
+
return kept;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The order-level discount an invoice issued after a return lists (issue #435,
|
|
24
|
+
* product-owner ruling Q3 of 2026-11-07): the order's discount less what the
|
|
25
|
+
* settled returns carried back, as they recorded it — the kept goods' share —
|
|
26
|
+
* at two places, and never below zero. `'0.00'` means the line is left off.
|
|
27
|
+
*/
|
|
28
|
+
export function keptDiscount(orderDiscount, returned) {
|
|
29
|
+
const kept = moneyDifference(roundHalfUp(orderDiscount), moneySum(['0', ...returned.map((r) => r.discount)]));
|
|
30
|
+
return compareDecimals(kept, 0) > 0 ? kept : '0.00';
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=kept-quantities.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { EntityManager } from '@mikro-orm/postgresql';
|
|
2
|
+
/** Runs `body` while holding the order's returns lock. */
|
|
3
|
+
export interface OrderReturnsLock {
|
|
4
|
+
run<T>(orderId: string, body: () => Promise<T>): Promise<T>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The order's returns lock, as `returns` takes it to create and to settle a
|
|
8
|
+
* case (`returnCaseOrderLockKey`, review of PR #865, F3), held on a connection
|
|
9
|
+
* of its own for the whole issuance — the reads of what came back and was
|
|
10
|
+
* refunded, and the invoice's own unit of work — the way the settlement holds
|
|
11
|
+
* it. A settlement records the resolution only after it has moved money and
|
|
12
|
+
* asked for a correction, which answers `not_due` while no invoice exists; an
|
|
13
|
+
* invoice issued in between would list every line and nothing would ever take
|
|
14
|
+
* the returned goods off. Issuing waits for it instead, and a settlement that
|
|
15
|
+
* starts afterwards waits for the invoice and corrects it. Waiting longer than
|
|
16
|
+
* {@link ISSUE_LOCK_TIMEOUT} is refused as retryable, with nothing issued.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createOrderReturnsLock(emFactory: () => EntityManager): OrderReturnsLock;
|
|
19
|
+
//# sourceMappingURL=order-returns-lock.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ERROR_CODES, returnCaseOrderLockKey } from '@endora-commerce/contracts';
|
|
2
|
+
import { HttpError } from '@endora-commerce/platform/http';
|
|
3
|
+
/** How long issuing waits for a settlement of the same order. */
|
|
4
|
+
const ISSUE_LOCK_TIMEOUT = '15s';
|
|
5
|
+
/** PostgreSQL's `lock_not_available`, raised when `lock_timeout` elapses. */
|
|
6
|
+
const LOCK_NOT_AVAILABLE = '55P03';
|
|
7
|
+
/**
|
|
8
|
+
* The order's returns lock, as `returns` takes it to create and to settle a
|
|
9
|
+
* case (`returnCaseOrderLockKey`, review of PR #865, F3), held on a connection
|
|
10
|
+
* of its own for the whole issuance — the reads of what came back and was
|
|
11
|
+
* refunded, and the invoice's own unit of work — the way the settlement holds
|
|
12
|
+
* it. A settlement records the resolution only after it has moved money and
|
|
13
|
+
* asked for a correction, which answers `not_due` while no invoice exists; an
|
|
14
|
+
* invoice issued in between would list every line and nothing would ever take
|
|
15
|
+
* the returned goods off. Issuing waits for it instead, and a settlement that
|
|
16
|
+
* starts afterwards waits for the invoice and corrects it. Waiting longer than
|
|
17
|
+
* {@link ISSUE_LOCK_TIMEOUT} is refused as retryable, with nothing issued.
|
|
18
|
+
*/
|
|
19
|
+
export function createOrderReturnsLock(emFactory) {
|
|
20
|
+
return {
|
|
21
|
+
run: (orderId, body) => emFactory()
|
|
22
|
+
.getKnex()
|
|
23
|
+
.transaction(async (lock) => {
|
|
24
|
+
await lock.raw(`set local lock_timeout = '${ISSUE_LOCK_TIMEOUT}'`);
|
|
25
|
+
try {
|
|
26
|
+
await lock.raw('select pg_advisory_xact_lock(hashtext(?))', [returnCaseOrderLockKey(orderId)]);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
if (err.code !== LOCK_NOT_AVAILABLE)
|
|
30
|
+
throw err;
|
|
31
|
+
throw new HttpError(409, ERROR_CODES.VERSION_CONFLICT, 'A return of this order is being settled. Try again in a moment.', { code: 'settlement_in_progress' });
|
|
32
|
+
}
|
|
33
|
+
return body();
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=order-returns-lock.js.map
|
|
@@ -30,7 +30,7 @@ export class SellerSettingsResolver {
|
|
|
30
30
|
}
|
|
31
31
|
const parsed = sellerCompanyDataSchema.safeParse({ ...raw, taxId: taxId || raw.taxId });
|
|
32
32
|
if (!parsed.success || !parsed.data.legalName || !parsed.data.taxId) {
|
|
33
|
-
throw new HttpError(422, ERROR_CODES.
|
|
33
|
+
throw new HttpError(422, ERROR_CODES.INVOICE_SELLER_DATA_MISSING, 'Seller VAT/NIP and company data must be configured before issuing invoices.', { setting: 'invoices.seller.company_data' });
|
|
34
34
|
}
|
|
35
35
|
return parsed.data;
|
|
36
36
|
}
|
package/dist/manifest.d.ts
CHANGED
|
@@ -111,6 +111,7 @@ export declare const manifest: {
|
|
|
111
111
|
weight: number;
|
|
112
112
|
descriptionKey?: string | undefined;
|
|
113
113
|
requiredPermission?: string | undefined;
|
|
114
|
+
entryApiRoute?: string | undefined;
|
|
114
115
|
keywordsKey?: string | undefined;
|
|
115
116
|
}[] | undefined;
|
|
116
117
|
permissions?: {
|
|
@@ -120,6 +121,12 @@ export declare const manifest: {
|
|
|
120
121
|
description?: string | undefined;
|
|
121
122
|
requires?: string[] | undefined;
|
|
122
123
|
}[] | undefined;
|
|
124
|
+
organizationPermissions?: {
|
|
125
|
+
code: string;
|
|
126
|
+
label: string;
|
|
127
|
+
description: string;
|
|
128
|
+
memberDefault: boolean;
|
|
129
|
+
}[] | undefined;
|
|
123
130
|
transactionalEmails?: {
|
|
124
131
|
code: string;
|
|
125
132
|
name: string;
|
|
@@ -146,9 +153,9 @@ export declare const manifest: {
|
|
|
146
153
|
name: string;
|
|
147
154
|
labelKey: string;
|
|
148
155
|
category: string;
|
|
149
|
-
contexts: ("invoice" | "
|
|
156
|
+
contexts: ("invoice" | "email" | "cms" | "newsletter" | "document")[];
|
|
150
157
|
fields: Record<string, {
|
|
151
|
-
type: "number" | "object" | "array" | "
|
|
158
|
+
type: "number" | "object" | "array" | "text" | "select" | "external" | "uuid" | "textarea" | "radio" | "richtext";
|
|
152
159
|
label?: string | undefined;
|
|
153
160
|
required?: boolean | undefined;
|
|
154
161
|
options?: {
|
|
@@ -170,7 +177,7 @@ export declare const manifest: {
|
|
|
170
177
|
blockCategories?: {
|
|
171
178
|
key: string;
|
|
172
179
|
titleKey: string;
|
|
173
|
-
contexts: ("invoice" | "
|
|
180
|
+
contexts: ("invoice" | "email" | "cms" | "newsletter" | "document")[];
|
|
174
181
|
weight?: number | undefined;
|
|
175
182
|
visible?: boolean | undefined;
|
|
176
183
|
}[] | undefined;
|
|
@@ -207,5 +214,10 @@ export declare const manifest: {
|
|
|
207
214
|
consumers: ("admin" | "backend" | "storefront")[];
|
|
208
215
|
addressOf: "admin" | "backend" | "storefront" | null;
|
|
209
216
|
}[] | undefined;
|
|
217
|
+
hookableActions?: {
|
|
218
|
+
action: string;
|
|
219
|
+
objectType: string;
|
|
220
|
+
phases: ("beforeCommit" | "afterCommit")[];
|
|
221
|
+
}[] | undefined;
|
|
210
222
|
};
|
|
211
223
|
//# sourceMappingURL=manifest.d.ts.map
|
package/dist/manifest.js
CHANGED
|
@@ -285,8 +285,9 @@ export const manifest = defineModuleManifest({
|
|
|
285
285
|
*
|
|
286
286
|
* The bundle holds a sentence for each of these keys and for no other, and
|
|
287
287
|
* `backend/test/unit/invoices/error-sentences.test.ts` enumerates the same
|
|
288
|
-
*
|
|
289
|
-
* authority, because a token nobody has written a
|
|
288
|
+
* sixteen keys by hand (eight before issue #633). Both agree with the raise
|
|
289
|
+
* sites; neither is the authority, because a token nobody has written a
|
|
290
|
+
* sentence for is still a token
|
|
290
291
|
* (`specs/090-module-owned-error-codes/migration-runbook.md` §5).
|
|
291
292
|
*/
|
|
292
293
|
errorCodes: [
|
|
@@ -300,6 +301,20 @@ export const manifest = defineModuleManifest({
|
|
|
300
301
|
// refuses to invoice an order refunded in full before it was invoiced. No
|
|
301
302
|
// `details`, so no token.
|
|
302
303
|
{ code: 'INVOICE_ORDER_REFUNDED' },
|
|
304
|
+
// Issue #633 (#86) — business refusals of issuance and correction that were
|
|
305
|
+
// `VALIDATION_FAILED` with an English sentence. `seller-settings.ts` raises
|
|
306
|
+
// the first; `corrective-invoice.ts` the four correction refusals, which
|
|
307
|
+
// reach an operator settling a return. The two `details.code` tokens the
|
|
308
|
+
// currency and lines-total refusals used to carry are gone: each code has
|
|
309
|
+
// one reason, except the two tokens declared below.
|
|
310
|
+
{ code: 'INVOICE_SELLER_DATA_MISSING' },
|
|
311
|
+
{ code: 'INVOICE_CORRECTION_CURRENCY_MISMATCH' },
|
|
312
|
+
{ code: 'INVOICE_CORRECTION_TOTAL_EXCEEDS_LINES', tokens: ['below_charges'] },
|
|
313
|
+
{ code: 'INVOICE_CORRECTION_EXCEEDS_RATE_REMAINING' },
|
|
314
|
+
{
|
|
315
|
+
code: 'INVOICE_CORRECTION_EXCEEDS_CHARGE_REMAINING',
|
|
316
|
+
tokens: ['delivery', 'payment_surcharge'],
|
|
317
|
+
},
|
|
303
318
|
],
|
|
304
319
|
actions: [
|
|
305
320
|
{
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Migration } from '@mikro-orm/migrations';
|
|
2
|
+
/**
|
|
3
|
+
* Issue #904, Phase A — `invoice_lines.line_kind`: what a line is, one of
|
|
4
|
+
* `goods`, `delivery`, `payment_surcharge`, `discount` or `price_reduction`.
|
|
5
|
+
*
|
|
6
|
+
* A charge line used to be told apart from the discount line by having no
|
|
7
|
+
* `order_item_id` and by its sign. Once delivery and the payment surcharge
|
|
8
|
+
* carry the goods' VAT, a charge line sits inside a goods rate's row, and the
|
|
9
|
+
* per-rate maths of a correction has to tell it from a goods line at the same
|
|
10
|
+
* rate: the kind has to be stated, not inferred.
|
|
11
|
+
*
|
|
12
|
+
* Written for every line of an invoice or a proforma issued from now on, the
|
|
13
|
+
* 0 % charge lines included. Nullable, no backfill: `null` is a line issued
|
|
14
|
+
* before (or a line no writer has named yet), read by the inference it always
|
|
15
|
+
* was — an issued document is never rewritten.
|
|
16
|
+
*/
|
|
17
|
+
export declare class Migration20261108T073244InvoicesInvoiceLineKind extends Migration {
|
|
18
|
+
up(): Promise<void>;
|
|
19
|
+
down(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=20261108T073244_invoices_invoice_line_kind.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Migration } from '@mikro-orm/migrations';
|
|
2
|
+
/**
|
|
3
|
+
* Issue #904, Phase A — `invoice_lines.line_kind`: what a line is, one of
|
|
4
|
+
* `goods`, `delivery`, `payment_surcharge`, `discount` or `price_reduction`.
|
|
5
|
+
*
|
|
6
|
+
* A charge line used to be told apart from the discount line by having no
|
|
7
|
+
* `order_item_id` and by its sign. Once delivery and the payment surcharge
|
|
8
|
+
* carry the goods' VAT, a charge line sits inside a goods rate's row, and the
|
|
9
|
+
* per-rate maths of a correction has to tell it from a goods line at the same
|
|
10
|
+
* rate: the kind has to be stated, not inferred.
|
|
11
|
+
*
|
|
12
|
+
* Written for every line of an invoice or a proforma issued from now on, the
|
|
13
|
+
* 0 % charge lines included. Nullable, no backfill: `null` is a line issued
|
|
14
|
+
* before (or a line no writer has named yet), read by the inference it always
|
|
15
|
+
* was — an issued document is never rewritten.
|
|
16
|
+
*/
|
|
17
|
+
export class Migration20261108T073244InvoicesInvoiceLineKind extends Migration {
|
|
18
|
+
async up() {
|
|
19
|
+
this.addSql('alter table "invoice_lines" add column if not exists "line_kind" varchar(24) null;');
|
|
20
|
+
this.addSql('alter table "invoice_lines" drop constraint if exists "invoice_lines_line_kind_check";');
|
|
21
|
+
this.addSql(`alter table "invoice_lines" add constraint "invoice_lines_line_kind_check" check ("line_kind" is null or "line_kind" in ('goods', 'delivery', 'payment_surcharge', 'discount', 'price_reduction'));`);
|
|
22
|
+
}
|
|
23
|
+
async down() {
|
|
24
|
+
this.addSql('alter table "invoice_lines" drop constraint if exists "invoice_lines_line_kind_check";');
|
|
25
|
+
this.addSql('alter table "invoice_lines" drop column if exists "line_kind";');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=20261108T073244_invoices_invoice_line_kind.js.map
|