@endora-commerce/mod-invoices 0.110.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/backend/admin-list-cursor.d.ts +20 -0
- package/dist/backend/admin-list-cursor.js +27 -0
- package/dist/backend/routes.admin.js +55 -15
- package/dist/backend/services/corrective-invoice.js +20 -13
- package/dist/backend/services/erp-sale-document-write-port.js +2 -2
- package/dist/backend/services/invoice-service.js +6 -5
- package/dist/backend/services/seller-settings.js +1 -1
- package/dist/manifest.d.ts +7 -1
- package/dist/manifest.js +17 -2
- package/docs/invoices.md +58 -17
- package/i18n/en.json +9 -1
- package/i18n/pl.json +9 -1
- package/package.json +15 -14
- 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/kept-quantities.d.ts.map +0 -1
- package/dist/backend/services/kept-quantities.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/order-returns-lock.d.ts.map +0 -1
- package/dist/backend/services/order-returns-lock.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/20261108T073244_invoices_invoice_line_kind.d.ts.map +0 -1
- package/dist/migrations/20261108T073244_invoices_invoice_line_kind.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
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { InvoiceKind, InvoiceStatus } from '@endora-commerce/contracts';
|
|
2
|
+
/** The admin invoice list's filter bar, as the inputs hold it. */
|
|
3
|
+
export interface InvoiceListFilters {
|
|
4
|
+
status: '' | InvoiceStatus;
|
|
5
|
+
kind: '' | InvoiceKind;
|
|
6
|
+
orderNumber: string;
|
|
7
|
+
/** `YYYY-MM-DD` from a date input, or `''`. */
|
|
8
|
+
issuedFrom: string;
|
|
9
|
+
issuedTo: string;
|
|
10
|
+
totalMin: string;
|
|
11
|
+
totalMax: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const NO_INVOICE_FILTERS: InvoiceListFilters;
|
|
14
|
+
/**
|
|
15
|
+
* The `GET /api/v1/admin/invoices` path for one page of the list. `cursor` is
|
|
16
|
+
* the opaque `pagination.cursor` the previous page answered (issue #1120); the
|
|
17
|
+
* first page passes none.
|
|
18
|
+
*/
|
|
19
|
+
export declare function invoiceListPath(filters: InvoiceListFilters, cursor?: string | null): string;
|
|
20
|
+
//# sourceMappingURL=invoice-list-path.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export const NO_INVOICE_FILTERS = {
|
|
2
|
+
status: '',
|
|
3
|
+
kind: '',
|
|
4
|
+
orderNumber: '',
|
|
5
|
+
issuedFrom: '',
|
|
6
|
+
issuedTo: '',
|
|
7
|
+
totalMin: '',
|
|
8
|
+
totalMax: '',
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The `GET /api/v1/admin/invoices` path for one page of the list. `cursor` is
|
|
12
|
+
* the opaque `pagination.cursor` the previous page answered (issue #1120); the
|
|
13
|
+
* first page passes none.
|
|
14
|
+
*/
|
|
15
|
+
export function invoiceListPath(filters, cursor) {
|
|
16
|
+
const params = new URLSearchParams();
|
|
17
|
+
if (filters.status)
|
|
18
|
+
params.set('filter[status]', filters.status);
|
|
19
|
+
if (filters.kind)
|
|
20
|
+
params.set('filter[kind]', filters.kind);
|
|
21
|
+
if (filters.orderNumber.trim())
|
|
22
|
+
params.set('filter[orderNumber]', filters.orderNumber.trim());
|
|
23
|
+
if (filters.issuedFrom)
|
|
24
|
+
params.set('filter[issuedFrom]', `${filters.issuedFrom}T00:00:00.000Z`);
|
|
25
|
+
if (filters.issuedTo)
|
|
26
|
+
params.set('filter[issuedTo]', `${filters.issuedTo}T23:59:59.999Z`);
|
|
27
|
+
if (filters.totalMin.trim())
|
|
28
|
+
params.set('filter[totalMin]', filters.totalMin.trim());
|
|
29
|
+
if (filters.totalMax.trim())
|
|
30
|
+
params.set('filter[totalMax]', filters.totalMax.trim());
|
|
31
|
+
if (cursor)
|
|
32
|
+
params.set('cursor', cursor);
|
|
33
|
+
const query = params.toString();
|
|
34
|
+
return '/api/v1/admin/invoices' + (query ? `?${query}` : '');
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=invoice-list-path.js.map
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { Link } from 'react-router-dom';
|
|
4
4
|
import { FileDown, Mail } from 'lucide-react';
|
|
5
5
|
import { apiBaseUrl, apiClient, ApiError, formatDateTime, formatMoney, sendInvoiceEmailMessage } from '@endora-commerce/admin-kit/lib';
|
|
6
6
|
import { Alert, AlertDescription, Badge, Button, Card, CardContent, Input, Label, PageHeader, Select, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@endora-commerce/admin-kit/ui';
|
|
7
7
|
import { InvoiceSectionTabs } from '../components/InvoiceSectionTabs.js';
|
|
8
8
|
import { useTranslation } from '@endora-commerce/admin-kit/i18n';
|
|
9
|
+
import { invoiceKindSchema, } from '@endora-commerce/contracts';
|
|
10
|
+
import { invoiceListPath } from '../lib/invoice-list-path.js';
|
|
9
11
|
const STATUSES = ['pending', 'ready', 'cancelled'];
|
|
10
|
-
|
|
12
|
+
/** Every kind the list can answer, an ERP `wz` included (issue #1120). */
|
|
13
|
+
const KINDS = invoiceKindSchema.options;
|
|
11
14
|
const STATUS_VARIANT = {
|
|
12
15
|
pending: 'warning',
|
|
13
16
|
ready: 'success',
|
|
@@ -17,6 +20,12 @@ export function InvoicesList() {
|
|
|
17
20
|
const t = useTranslation('core');
|
|
18
21
|
const [rows, setRows] = useState([]);
|
|
19
22
|
const [loading, setLoading] = useState(true);
|
|
23
|
+
// Issue #1120 — the cursor the last page answered; `null` once the list is complete.
|
|
24
|
+
const [nextCursor, setNextCursor] = useState(null);
|
|
25
|
+
const [loadingMore, setLoadingMore] = useState(false);
|
|
26
|
+
// Bumped by every first-page load, so a "load more" answering after the
|
|
27
|
+
// filters changed does not append rows of the old filter.
|
|
28
|
+
const generation = useRef(0);
|
|
20
29
|
const [error, setError] = useState(null);
|
|
21
30
|
const [notice, setNotice] = useState(null);
|
|
22
31
|
const [status, setStatus] = useState('');
|
|
@@ -42,36 +51,50 @@ export function InvoicesList() {
|
|
|
42
51
|
setTotalMin('');
|
|
43
52
|
setTotalMax('');
|
|
44
53
|
}, []);
|
|
54
|
+
const filters = { status, kind, orderNumber, issuedFrom, issuedTo, totalMin, totalMax };
|
|
45
55
|
const refresh = useCallback(async () => {
|
|
56
|
+
const current = ++generation.current;
|
|
46
57
|
setLoading(true);
|
|
47
58
|
setError(null);
|
|
48
59
|
try {
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
if (kind)
|
|
53
|
-
params.set('filter[kind]', kind);
|
|
54
|
-
if (orderNumber.trim())
|
|
55
|
-
params.set('filter[orderNumber]', orderNumber.trim());
|
|
56
|
-
if (issuedFrom)
|
|
57
|
-
params.set('filter[issuedFrom]', `${issuedFrom}T00:00:00.000Z`);
|
|
58
|
-
if (issuedTo)
|
|
59
|
-
params.set('filter[issuedTo]', `${issuedTo}T23:59:59.999Z`);
|
|
60
|
-
if (totalMin.trim())
|
|
61
|
-
params.set('filter[totalMin]', totalMin.trim());
|
|
62
|
-
if (totalMax.trim())
|
|
63
|
-
params.set('filter[totalMax]', totalMax.trim());
|
|
64
|
-
const path = '/api/v1/admin/invoices' + (params.toString() ? `?${params.toString()}` : '');
|
|
65
|
-
const res = await apiClient.get(path);
|
|
60
|
+
const res = await apiClient.get(invoiceListPath({ status, kind, orderNumber, issuedFrom, issuedTo, totalMin, totalMax }));
|
|
61
|
+
if (current !== generation.current)
|
|
62
|
+
return;
|
|
66
63
|
setRows(res.data);
|
|
64
|
+
setNextCursor(res.pagination.cursor);
|
|
67
65
|
}
|
|
68
66
|
catch (err) {
|
|
67
|
+
if (current !== generation.current)
|
|
68
|
+
return;
|
|
69
69
|
setError(err instanceof ApiError ? err.envelope.error.message : 'Failed to load.');
|
|
70
70
|
}
|
|
71
71
|
finally {
|
|
72
|
-
|
|
72
|
+
if (current === generation.current)
|
|
73
|
+
setLoading(false);
|
|
73
74
|
}
|
|
74
75
|
}, [status, kind, orderNumber, issuedFrom, issuedTo, totalMin, totalMax]);
|
|
76
|
+
const loadMore = async () => {
|
|
77
|
+
if (!nextCursor || loadingMore)
|
|
78
|
+
return;
|
|
79
|
+
const current = generation.current;
|
|
80
|
+
setLoadingMore(true);
|
|
81
|
+
setError(null);
|
|
82
|
+
try {
|
|
83
|
+
const res = await apiClient.get(invoiceListPath(filters, nextCursor));
|
|
84
|
+
if (current !== generation.current)
|
|
85
|
+
return;
|
|
86
|
+
setRows((previous) => [...previous, ...res.data]);
|
|
87
|
+
setNextCursor(res.pagination.cursor);
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
if (current !== generation.current)
|
|
91
|
+
return;
|
|
92
|
+
setError(err instanceof ApiError ? err.envelope.error.message : 'Failed to load.');
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
setLoadingMore(false);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
75
98
|
// Debounced so typing in the order-number / total inputs doesn't refetch
|
|
76
99
|
// on every keystroke.
|
|
77
100
|
useEffect(() => {
|
|
@@ -105,7 +128,9 @@ export function InvoicesList() {
|
|
|
105
128
|
setError(err instanceof ApiError ? err.envelope.error.message : 'Failed to send.');
|
|
106
129
|
}
|
|
107
130
|
}, [t]);
|
|
108
|
-
return (_jsxs(_Fragment, { children: [_jsx(PageHeader, { title: t('invoices.title'), description: t('invoices.description') }), _jsx(InvoiceSectionTabs, {}), error ? (_jsx(Alert, { variant: "destructive", className: "mb-4", children: _jsx(AlertDescription, { children: error }) })) : null, notice ? (_jsx(Alert, { className: "mb-4", children: _jsx(AlertDescription, { children: notice }) })) : null, _jsx(Card, { className: "mb-4", children: _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "grid gap-4 md:grid-cols-3 lg:grid-cols-4", children: [_jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "iorder", children: t('invoices.fields.orderNumber') }), _jsx(Input, { id: "iorder", value: orderNumber, onChange: (e) => setOrderNumber(e.target.value), placeholder: t('invoices.filters.orderNumberPlaceholder') })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "ikind", children: t('invoices.fields.kind') }), _jsxs(Select, { id: "ikind", value: kind, onChange: (e) => setKind(e.target.value), children: [_jsx("option", { value: "", children: t('invoices.kind.all') }), KINDS.map((k) => (_jsx("option", { value: k, children: t(`invoices.kind.${k}`) }, k)))] })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "istatus", children: t('invoices.fields.status') }), _jsxs(Select, { id: "istatus", value: status, onChange: (e) => setStatus(e.target.value), children: [_jsx("option", { value: "", children: t('invoices.status.all') }), STATUSES.map((s) => (_jsx("option", { value: s, children: t(`invoices.status.${s}`) }, s)))] })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "ifrom", children: t('invoices.fields.issuedFrom') }), _jsx(Input, { id: "ifrom", type: "date", value: issuedFrom, onChange: (e) => setIssuedFrom(e.target.value) })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "ito", children: t('invoices.fields.issuedTo') }), _jsx(Input, { id: "ito", type: "date", value: issuedTo, onChange: (e) => setIssuedTo(e.target.value) })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "itmin", children: t('invoices.fields.totalMin') }), _jsx(Input, { id: "itmin", type: "number", step: "0.01", min: "0", value: totalMin, onChange: (e) => setTotalMin(e.target.value) })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "itmax", children: t('invoices.fields.totalMax') }), _jsx(Input, { id: "itmax", type: "number", step: "0.01", min: "0", value: totalMax, onChange: (e) => setTotalMax(e.target.value) })] }), _jsx("div", { className: "flex items-end", children: _jsx(Button, { type: "button", variant: "outline", disabled: !hasFilters, onClick: clearFilters, children: t('invoices.filters.clear') }) })] }) }) }), _jsx(Card, { children:
|
|
131
|
+
return (_jsxs(_Fragment, { children: [_jsx(PageHeader, { title: t('invoices.title'), description: t('invoices.description') }), _jsx(InvoiceSectionTabs, {}), error ? (_jsx(Alert, { variant: "destructive", className: "mb-4", children: _jsx(AlertDescription, { children: error }) })) : null, notice ? (_jsx(Alert, { className: "mb-4", children: _jsx(AlertDescription, { children: notice }) })) : null, _jsx(Card, { className: "mb-4", children: _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "grid gap-4 md:grid-cols-3 lg:grid-cols-4", children: [_jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "iorder", children: t('invoices.fields.orderNumber') }), _jsx(Input, { id: "iorder", value: orderNumber, onChange: (e) => setOrderNumber(e.target.value), placeholder: t('invoices.filters.orderNumberPlaceholder') })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "ikind", children: t('invoices.fields.kind') }), _jsxs(Select, { id: "ikind", value: kind, onChange: (e) => setKind(e.target.value), children: [_jsx("option", { value: "", children: t('invoices.kind.all') }), KINDS.map((k) => (_jsx("option", { value: k, children: t(`invoices.kind.${k}`) }, k)))] })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "istatus", children: t('invoices.fields.status') }), _jsxs(Select, { id: "istatus", value: status, onChange: (e) => setStatus(e.target.value), children: [_jsx("option", { value: "", children: t('invoices.status.all') }), STATUSES.map((s) => (_jsx("option", { value: s, children: t(`invoices.status.${s}`) }, s)))] })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "ifrom", children: t('invoices.fields.issuedFrom') }), _jsx(Input, { id: "ifrom", type: "date", value: issuedFrom, onChange: (e) => setIssuedFrom(e.target.value) })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "ito", children: t('invoices.fields.issuedTo') }), _jsx(Input, { id: "ito", type: "date", value: issuedTo, onChange: (e) => setIssuedTo(e.target.value) })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "itmin", children: t('invoices.fields.totalMin') }), _jsx(Input, { id: "itmin", type: "number", step: "0.01", min: "0", value: totalMin, onChange: (e) => setTotalMin(e.target.value) })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "itmax", children: t('invoices.fields.totalMax') }), _jsx(Input, { id: "itmax", type: "number", step: "0.01", min: "0", value: totalMax, onChange: (e) => setTotalMax(e.target.value) })] }), _jsx("div", { className: "flex items-end", children: _jsx(Button, { type: "button", variant: "outline", disabled: !hasFilters, onClick: clearFilters, children: t('invoices.filters.clear') }) })] }) }) }), _jsx(Card, { children: _jsxs(CardContent, { className: "pt-6", children: [loading ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('common.state.loading') })) : rows.length === 0 ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('invoices.empty') })) : (_jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: t('invoices.columns.number') }), _jsx(TableHead, { children: t('invoices.columns.kind') }), _jsx(TableHead, { children: t('invoices.columns.issued') }), _jsx(TableHead, { children: t('invoices.columns.order') }), _jsx(TableHead, { children: t('invoices.columns.total') }), _jsx(TableHead, { children: t('invoices.columns.status') }), _jsx(TableHead, {})] }) }), _jsx(TableBody, { children: rows.map((i) => (_jsxs(TableRow, { children: [_jsx(TableCell, { className: "font-medium", children: _jsx(Link, { to: `/invoices/${i.id}`, className: "underline underline-offset-2", children: i.number }) }), _jsx(TableCell, { children: t(`invoices.kind.${i.kind}`) }), _jsx(TableCell, { children: formatDateTime(i.issuedAt) }), _jsx(TableCell, { children: i.orderId === null ? (
|
|
132
|
+
// An ERP-imported sale document may have no order.
|
|
133
|
+
_jsx("span", { className: "text-muted-foreground", children: "\u2014" })) : (_jsx(Link, { to: `/orders/${i.orderId}`, className: "font-mono text-xs underline underline-offset-2", children: i.orderBusinessId ?? i.orderId.slice(0, 8) })) }), _jsx(TableCell, { className: "tabular-nums", children: formatMoney(i.total, i.currency) }), _jsx(TableCell, { children: _jsx(Badge, { variant: STATUS_VARIANT[i.status], children: t(`invoices.status.${i.status}`) }) }), _jsx(TableCell, { children: _jsxs("div", { className: "flex items-center gap-2", children: [i.pdfReady ? (_jsx(Button, { asChild: true, variant: "outline", size: "sm", children: _jsxs("a", { href: `${baseUrl}/api/v1/admin/invoices/${i.id}/pdf`, target: "_blank", rel: "noreferrer", children: [_jsx(FileDown, {}), "PDF"] }) })) : (_jsx("span", { className: "text-xs text-muted-foreground", children: t('invoices.pdfNotReady') })), _jsx(Button, { variant: "ghost", size: "sm", onClick: () => void resendEmail(i.id), title: t('invoices.resendEmail'), children: _jsx(Mail, {}) })] }) })] }, i.id))) })] })), !loading && nextCursor ? (_jsx("div", { className: "mt-4 flex justify-center", children: _jsx(Button, { type: "button", variant: "outline", disabled: loadingMore, "aria-busy": loadingMore, onClick: () => void loadMore(), children: t('invoices.loadMore') }) })) : null] }) })] }));
|
|
109
134
|
}
|
|
110
135
|
/**
|
|
111
136
|
* The registry loads a route component through a dynamic-import factory and
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cursor of `GET /api/v1/admin/invoices` (issue #1120): the sort key of the
|
|
3
|
+
* last row a page answered, `(issuedAt desc, id desc)`. The id breaks a tie on
|
|
4
|
+
* `issuedAt`, without which two invoices issued in the same millisecond would
|
|
5
|
+
* be skipped or repeated across a page boundary.
|
|
6
|
+
*
|
|
7
|
+
* The encoding is the platform's (`encodeCursor` / `decodeCursor`), so the
|
|
8
|
+
* value is opaque base64url like every other list cursor; a client passes it
|
|
9
|
+
* back as `?cursor=` and reads nothing out of it.
|
|
10
|
+
*/
|
|
11
|
+
export interface InvoiceListPosition {
|
|
12
|
+
readonly issuedAt: Date;
|
|
13
|
+
readonly id: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function encodeInvoiceListCursor(position: InvoiceListPosition): string;
|
|
16
|
+
/** The position a cursor names; a value this route did not issue is a 400. */
|
|
17
|
+
export declare function decodeInvoiceListCursor(raw: string): InvoiceListPosition;
|
|
18
|
+
/** The rows strictly after `position` in `(issuedAt desc, id desc)` order. */
|
|
19
|
+
export declare function afterPosition(position: InvoiceListPosition): Record<string, unknown>;
|
|
20
|
+
//# sourceMappingURL=admin-list-cursor.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ERROR_CODES, isUuidShape } from '@endora-commerce/contracts';
|
|
2
|
+
import { HttpError, decodeCursor, encodeCursor } from '@endora-commerce/platform/http';
|
|
3
|
+
const SEPARATOR = '|';
|
|
4
|
+
export function encodeInvoiceListCursor(position) {
|
|
5
|
+
return encodeCursor(`${position.issuedAt.toISOString()}${SEPARATOR}${position.id}`);
|
|
6
|
+
}
|
|
7
|
+
/** The position a cursor names; a value this route did not issue is a 400. */
|
|
8
|
+
export function decodeInvoiceListCursor(raw) {
|
|
9
|
+
const key = decodeCursor(raw);
|
|
10
|
+
const at = key?.indexOf(SEPARATOR) ?? -1;
|
|
11
|
+
if (key !== undefined && at > 0) {
|
|
12
|
+
const issuedAt = new Date(key.slice(0, at));
|
|
13
|
+
const id = key.slice(at + 1);
|
|
14
|
+
if (!Number.isNaN(issuedAt.getTime()) && isUuidShape(id))
|
|
15
|
+
return { issuedAt, id };
|
|
16
|
+
}
|
|
17
|
+
throw new HttpError(400, ERROR_CODES.VALIDATION_FAILED, 'The cursor is not one this API issued.', [
|
|
18
|
+
{ path: 'cursor', issue: 'Expected a cursor from a previous page' },
|
|
19
|
+
]);
|
|
20
|
+
}
|
|
21
|
+
/** The rows strictly after `position` in `(issuedAt desc, id desc)` order. */
|
|
22
|
+
export function afterPosition(position) {
|
|
23
|
+
return {
|
|
24
|
+
$or: [{ issuedAt: { $lt: position.issuedAt } }, { issuedAt: position.issuedAt, id: { $lt: position.id } }],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=admin-list-cursor.js.map
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { issueInvoiceRequestSchema, sendInvoiceEmailRequestSchema, } from '@endora-commerce/contracts';
|
|
2
2
|
import { Invoice } from './entities/invoice.entity.js';
|
|
3
|
-
import {
|
|
3
|
+
import { orgInScope } from '@endora-commerce/platform/tenancy';
|
|
4
4
|
import { renderInvoicePdf } from './document/render-invoice.js';
|
|
5
|
+
import { afterPosition, decodeInvoiceListCursor, encodeInvoiceListCursor, } from './admin-list-cursor.js';
|
|
5
6
|
export async function registerInvoicesAdminRoutes(app, deps) {
|
|
6
7
|
const { emFactory, orderReadPort, requireAdmin, invoiceService, documents } = deps;
|
|
7
8
|
// List ------------------------------------------------------------------
|
|
8
9
|
app.get('/api/v1/admin/invoices', { preHandler: requireAdmin('invoices:read') }, async (request) => {
|
|
9
10
|
const q = (request.query ?? {});
|
|
11
|
+
// The page size asked for — what `pagination.limit` answers, an empty
|
|
12
|
+
// page included (`paginationSchema`: 1–200; issue #599).
|
|
13
|
+
const limit = Math.min(Math.max(Number.parseInt(q['limit'] ?? '50', 10) || 50, 1), 200);
|
|
14
|
+
// Issue #1120 — decoded before any read, so a forged cursor is a 400 and
|
|
15
|
+
// not an empty page.
|
|
16
|
+
const after = q['cursor'] ? decodeInvoiceListCursor(q['cursor']) : null;
|
|
10
17
|
const where = {};
|
|
11
18
|
if (q['filter[status]'])
|
|
12
19
|
where['status'] = q['filter[status]'];
|
|
@@ -44,31 +51,63 @@ export async function registerInvoicesAdminRoutes(app, deps) {
|
|
|
44
51
|
if (orderNumber) {
|
|
45
52
|
const matchingOrderIds = await orderReadPort.findIdsByBusinessIdLike(orderNumber, 500);
|
|
46
53
|
if (matchingOrderIds.length === 0) {
|
|
47
|
-
return { data: [], pagination: { cursor: null, hasMore: false, limit
|
|
54
|
+
return { data: [], pagination: { cursor: null, hasMore: false, limit } };
|
|
48
55
|
}
|
|
49
56
|
where['orderId'] = { $in: matchingOrderIds };
|
|
50
57
|
}
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
// Issue #1120 — a page is `limit` rows the caller may see, newest first,
|
|
59
|
+
// and `hasMore` says whether one more exists. The tenant scope below is
|
|
60
|
+
// applied after the read (an invoice is scoped through its order's
|
|
61
|
+
// organisation, which `orders` owns), so the read walks forward in
|
|
62
|
+
// batches until it holds one visible row beyond the page or runs out: an
|
|
63
|
+
// out-of-scope row never shortens a page, never ends the walk early, and
|
|
64
|
+
// never becomes the cursor, which is always the last row answered.
|
|
65
|
+
const batch = limit + 1;
|
|
66
|
+
const visible = [];
|
|
67
|
+
const businessIdByOrder = new Map();
|
|
68
|
+
let position = after;
|
|
69
|
+
for (;;) {
|
|
70
|
+
const rows = await em.find(Invoice, position ? { $and: [where, afterPosition(position)] } : where, { orderBy: { issuedAt: 'desc', id: 'desc' }, limit: batch });
|
|
71
|
+
visible.push(...(await scoped(rows, businessIdByOrder)));
|
|
72
|
+
const last = rows[rows.length - 1];
|
|
73
|
+
if (visible.length > limit || rows.length < batch || !last)
|
|
74
|
+
break;
|
|
75
|
+
position = { issuedAt: last.issuedAt, id: last.id };
|
|
76
|
+
}
|
|
77
|
+
const page = visible.slice(0, limit);
|
|
78
|
+
const hasMore = visible.length > limit;
|
|
79
|
+
const end = page[page.length - 1];
|
|
80
|
+
return {
|
|
81
|
+
data: page.map((i) => serialize(i, i.orderId ? (businessIdByOrder.get(i.orderId) ?? null) : null)),
|
|
82
|
+
pagination: {
|
|
83
|
+
cursor: hasMore && end ? encodeInvoiceListCursor({ issuedAt: end.issuedAt, id: end.id }) : null,
|
|
84
|
+
hasMore,
|
|
85
|
+
limit,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
/**
|
|
90
|
+
* The rows of `rows` in the ambient tenant scope, in order. Records each
|
|
91
|
+
* order's business id into `businessIdByOrder` for the serializer.
|
|
92
|
+
*/
|
|
93
|
+
async function scoped(rows, businessIdByOrder) {
|
|
53
94
|
const orderIds = [
|
|
54
95
|
...new Set(rows.map((r) => r.orderId).filter((id) => id != null)),
|
|
55
96
|
];
|
|
56
97
|
// Feature 075, Phase C — the order number and the owning organisation are
|
|
57
98
|
// `orders`' fields, read over its port rather than out of its table.
|
|
58
|
-
const orders = await orderReadPort.findByIds(orderIds);
|
|
59
|
-
const
|
|
99
|
+
const orders = orderIds.length > 0 ? await orderReadPort.findByIds(orderIds) : [];
|
|
100
|
+
for (const o of orders)
|
|
101
|
+
businessIdByOrder.set(o.id, o.businessId);
|
|
60
102
|
const orgByOrder = new Map(orders.map((o) => [o.id, o.organizationId]));
|
|
61
103
|
// Feature 050 — Invoice is transitively scoped via its Order's org; hide
|
|
62
104
|
// invoices whose order is out of the ambient tenant scope. ERP-imported
|
|
63
105
|
// rows without an order scope directly on `organizationId` (feature 119).
|
|
64
|
-
const
|
|
65
|
-
?
|
|
66
|
-
:
|
|
67
|
-
return
|
|
68
|
-
|
|
69
|
-
pagination: { cursor: null, hasMore: false, limit: scoped.length },
|
|
70
|
-
};
|
|
71
|
-
});
|
|
106
|
+
const inScope = await Promise.all(rows.map((i) => i.origin === 'erp_import'
|
|
107
|
+
? orgInScope(i.organizationId ?? '')
|
|
108
|
+
: orgInScope(orgByOrder.get(i.orderId ?? '') ?? '')));
|
|
109
|
+
return rows.filter((_, index) => inScope[index]);
|
|
110
|
+
}
|
|
72
111
|
// Detail ----------------------------------------------------------------
|
|
73
112
|
app.get('/api/v1/admin/invoices/:id', { preHandler: requireAdmin('invoices:read') }, async (request) => {
|
|
74
113
|
return { data: await invoiceService.buildDetail(request.params.id) };
|
|
@@ -157,7 +196,8 @@ async function sendOnIssue(deps, invoiceId, salesChannelId, invoiceStatus) {
|
|
|
157
196
|
function serialize(i, orderBusinessId) {
|
|
158
197
|
return {
|
|
159
198
|
id: i.id,
|
|
160
|
-
|
|
199
|
+
// An ERP-imported sale document may have no order: `null`, never an absent key (issue #599).
|
|
200
|
+
orderId: i.orderId ?? null,
|
|
161
201
|
orderBusinessId,
|
|
162
202
|
salesChannelId: i.salesChannelId ?? null,
|
|
163
203
|
kind: i.kind,
|
|
@@ -465,10 +465,9 @@ export class CorrectiveInvoiceProvider {
|
|
|
465
465
|
// currency — so refusing costs nothing and closes the seam. Conversion is
|
|
466
466
|
// deliberately not attempted here.
|
|
467
467
|
if (input.currency !== original.currency) {
|
|
468
|
-
throw new HttpError(422, ERROR_CODES.
|
|
469
|
-
code: 'correction_currency_mismatch',
|
|
468
|
+
throw new HttpError(422, ERROR_CODES.INVOICE_CORRECTION_CURRENCY_MISMATCH, `A correction must be issued in the corrected invoice's currency (${original.currency}), not ${input.currency}.`, {
|
|
470
469
|
requestedCurrency: input.currency,
|
|
471
|
-
|
|
470
|
+
invoiceCurrency: original.currency,
|
|
472
471
|
originalInvoiceId: original.id,
|
|
473
472
|
});
|
|
474
473
|
}
|
|
@@ -565,28 +564,37 @@ export class CorrectiveInvoiceProvider {
|
|
|
565
564
|
});
|
|
566
565
|
}
|
|
567
566
|
catch (err) {
|
|
567
|
+
// Issue #633 — each refusal has its own code; the amounts are the
|
|
568
|
+
// two-decimal strings the sentences interpolate, with the currency they
|
|
569
|
+
// are in (the invoice's, which the check above made the request's too).
|
|
568
570
|
if (err instanceof CorrectionExceedsChargeRemainingError) {
|
|
569
|
-
throw new HttpError(422, ERROR_CODES.
|
|
570
|
-
|
|
571
|
+
throw new HttpError(422, ERROR_CODES.INVOICE_CORRECTION_EXCEEDS_CHARGE_REMAINING, err.message, {
|
|
572
|
+
// The token picks the sentence that names the charge.
|
|
573
|
+
code: err.kind,
|
|
571
574
|
chargeKind: err.kind,
|
|
572
575
|
remaining: err.remaining,
|
|
576
|
+
currency: original.currency,
|
|
573
577
|
});
|
|
574
578
|
}
|
|
575
579
|
if (err instanceof CorrectionExceedsRateRemainingError) {
|
|
576
|
-
throw new HttpError(422, ERROR_CODES.
|
|
577
|
-
code: 'correction_exceeds_rate_remaining',
|
|
580
|
+
throw new HttpError(422, ERROR_CODES.INVOICE_CORRECTION_EXCEEDS_RATE_REMAINING, err.message, {
|
|
578
581
|
taxRate: err.taxRate,
|
|
579
582
|
remaining: err.remaining,
|
|
580
583
|
// For the operator's sentence: 23, not 0.2300.
|
|
581
584
|
vatRatePercent: String(Number(decimalProduct(err.taxRate, 100))),
|
|
585
|
+
currency: original.currency,
|
|
582
586
|
});
|
|
583
587
|
}
|
|
584
588
|
if (!(err instanceof CorrectionTotalExceedsLinesError))
|
|
585
589
|
throw err;
|
|
586
|
-
throw new HttpError(400, ERROR_CODES.
|
|
587
|
-
|
|
590
|
+
throw new HttpError(400, ERROR_CODES.INVOICE_CORRECTION_TOTAL_EXCEEDS_LINES, err.message, {
|
|
591
|
+
// `correctionAmounts` raises this error twice: for a total above what
|
|
592
|
+
// the lines and charges credit, and for a total below the charges
|
|
593
|
+
// alone, where `linesTotal` is the charges. Only the second is "less".
|
|
594
|
+
...(compareDecimals(err.total, err.linesTotal) < 0 ? { code: 'below_charges' } : {}),
|
|
588
595
|
total: err.total,
|
|
589
596
|
linesTotal: err.linesTotal,
|
|
597
|
+
currency: original.currency,
|
|
590
598
|
});
|
|
591
599
|
}
|
|
592
600
|
// One at a time, as `invoicesProseTable` reads the bundle.
|
|
@@ -782,11 +790,10 @@ export class CorrectiveInvoiceProvider {
|
|
|
782
790
|
number: invoice.number,
|
|
783
791
|
orderId: input.orderId,
|
|
784
792
|
originalInvoiceId: original.id,
|
|
785
|
-
|
|
793
|
+
// Counts and kinds, never amounts (#470, D-288): what was credited is
|
|
794
|
+
// on the corrective invoice itself.
|
|
786
795
|
priceReductionLines: input.lines.filter((l) => l.basis === 'price_reduction').length,
|
|
787
|
-
...(chargeSnapshots.length > 0
|
|
788
|
-
? { charges: Object.fromEntries(chargeSnapshots.map((c) => [c.kind, Number(c.gross)])) }
|
|
789
|
-
: {}),
|
|
796
|
+
...(chargeSnapshots.length > 0 ? { chargeKinds: [...new Set(chargeSnapshots.map((c) => c.kind))].sort() } : {}),
|
|
790
797
|
},
|
|
791
798
|
})
|
|
792
799
|
.catch(() => undefined);
|
|
@@ -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();
|
|
@@ -3,7 +3,7 @@ import { HttpError } from '@endora-commerce/platform/http';
|
|
|
3
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';
|
|
@@ -94,7 +94,7 @@ export class InvoiceService {
|
|
|
94
94
|
const em = this.emFactory();
|
|
95
95
|
const order = await this.orders.findById(orderId);
|
|
96
96
|
// Feature 050 — Invoice is transitively scoped through its Order's org.
|
|
97
|
-
if (!order || !
|
|
97
|
+
if (!order || !(await orgInScope(order.organizationId ?? ''))) {
|
|
98
98
|
throw new HttpError(404, ERROR_CODES.ORDER_NOT_FOUND, 'Order not found.');
|
|
99
99
|
}
|
|
100
100
|
const existing = await em.findOne(Invoice, { orderId, kind });
|
|
@@ -287,7 +287,8 @@ export class InvoiceService {
|
|
|
287
287
|
kind: invoice.kind,
|
|
288
288
|
orderId,
|
|
289
289
|
salesChannelId: order.salesChannelId,
|
|
290
|
-
|
|
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.
|
|
291
292
|
},
|
|
292
293
|
})
|
|
293
294
|
.catch(() => undefined);
|
|
@@ -409,11 +410,11 @@ export class InvoiceService {
|
|
|
409
410
|
throw new HttpError(404, ERROR_CODES.NOT_FOUND, 'Invoice not found.');
|
|
410
411
|
const order = inv.orderId ? await this.orders.findById(inv.orderId) : null;
|
|
411
412
|
if (inv.origin === 'erp_import') {
|
|
412
|
-
if (!
|
|
413
|
+
if (!(await orgInScope(inv.organizationId ?? ''))) {
|
|
413
414
|
throw new HttpError(404, ERROR_CODES.NOT_FOUND, 'Invoice not found.');
|
|
414
415
|
}
|
|
415
416
|
}
|
|
416
|
-
else if (!order || !
|
|
417
|
+
else if (!order || !(await orgInScope(order.organizationId ?? ''))) {
|
|
417
418
|
throw new HttpError(404, ERROR_CODES.NOT_FOUND, 'Invoice not found.');
|
|
418
419
|
}
|
|
419
420
|
const lineRows = await em.find(InvoiceLine, { invoiceId }, { orderBy: { ordinal: 'asc' } });
|
|
@@ -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?: {
|
|
@@ -154,7 +155,7 @@ export declare const manifest: {
|
|
|
154
155
|
category: string;
|
|
155
156
|
contexts: ("invoice" | "email" | "cms" | "newsletter" | "document")[];
|
|
156
157
|
fields: Record<string, {
|
|
157
|
-
type: "number" | "object" | "array" | "text" | "
|
|
158
|
+
type: "number" | "object" | "array" | "text" | "select" | "external" | "uuid" | "textarea" | "radio" | "richtext";
|
|
158
159
|
label?: string | undefined;
|
|
159
160
|
required?: boolean | undefined;
|
|
160
161
|
options?: {
|
|
@@ -213,5 +214,10 @@ export declare const manifest: {
|
|
|
213
214
|
consumers: ("admin" | "backend" | "storefront")[];
|
|
214
215
|
addressOf: "admin" | "backend" | "storefront" | null;
|
|
215
216
|
}[] | undefined;
|
|
217
|
+
hookableActions?: {
|
|
218
|
+
action: string;
|
|
219
|
+
objectType: string;
|
|
220
|
+
phases: ("beforeCommit" | "afterCommit")[];
|
|
221
|
+
}[] | undefined;
|
|
216
222
|
};
|
|
217
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
|
{
|