@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
|
@@ -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
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
2
3
|
import { createColorField, definePageBuilderComponent } from '@endora-commerce/page-builder-core';
|
|
4
|
+
import { useBlockRenderEnvironment } from '@endora-commerce/page-builder-core/contributions';
|
|
3
5
|
import { createImageAssetField, createImageSourceField, createImageUrlField, } from '@endora-commerce/page-builder-admin';
|
|
4
6
|
import { fetchAssetDetail } from '@endora-commerce/admin-kit/components';
|
|
7
|
+
import { getBundles, resolve, useTranslationContext } from '@endora-commerce/admin-kit/i18n';
|
|
5
8
|
import { toAbsoluteAssetUrl } from '@endora-commerce/admin-kit/lib';
|
|
6
|
-
import { unitPriceFractionDigits } from '@endora-commerce/contracts';
|
|
9
|
+
import { supportedLanguageOf, unitPriceFractionDigits } from '@endora-commerce/contracts';
|
|
7
10
|
/**
|
|
8
11
|
* Dedicated Puck config for invoice PDF templates (feature 047, US6). Kept in
|
|
9
12
|
* the admin module (not the shared cms-components package) because invoice
|
|
@@ -77,9 +80,69 @@ const sampleInvoice = {
|
|
|
77
80
|
city: 'Chicago',
|
|
78
81
|
},
|
|
79
82
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Issue #888 — the canvas draws what the PDF prints: a label the template
|
|
85
|
+
* leaves empty (or blank) comes from this module's `pdf.*` keys **in the
|
|
86
|
+
* language of the tree being edited**, the fallback `sections.ts` takes with
|
|
87
|
+
* `str(props, key, labels[…])`; a label the operator typed is drawn as typed.
|
|
88
|
+
*
|
|
89
|
+
* The edited tree's language is the render environment the document-template
|
|
90
|
+
* editor provides around its canvas (`useBlockRenderEnvironment`). When it is
|
|
91
|
+
* the administrator's language the loaded bundle already holds it; otherwise
|
|
92
|
+
* that language's bundle is fetched once per session, and until it arrives the
|
|
93
|
+
* administrator's language stands in.
|
|
94
|
+
*/
|
|
95
|
+
const treeBundles = new Map();
|
|
96
|
+
function treeBundle(language) {
|
|
97
|
+
let pending = treeBundles.get(language);
|
|
98
|
+
if (!pending) {
|
|
99
|
+
pending = getBundles(language).then((response) => response.bundles);
|
|
100
|
+
// A failed read is not remembered, so the next canvas tries again.
|
|
101
|
+
pending.catch(() => treeBundles.delete(language));
|
|
102
|
+
treeBundles.set(language, pending);
|
|
103
|
+
}
|
|
104
|
+
return pending;
|
|
105
|
+
}
|
|
106
|
+
function useTreeLabels() {
|
|
107
|
+
const { language: treeLanguage } = useBlockRenderEnvironment();
|
|
108
|
+
const target = supportedLanguageOf(treeLanguage);
|
|
109
|
+
const { language: admin, bundle, fallbackBundle, t } = useTranslationContext();
|
|
110
|
+
const held = target === admin ? bundle : target === 'en' ? fallbackBundle : undefined;
|
|
111
|
+
const [fetched, setFetched] = useState(null);
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
if (held)
|
|
114
|
+
return undefined;
|
|
115
|
+
let live = true;
|
|
116
|
+
treeBundle(target).then((loaded) => {
|
|
117
|
+
if (live)
|
|
118
|
+
setFetched({ language: target, bundle: loaded });
|
|
119
|
+
}, () => undefined);
|
|
120
|
+
return () => {
|
|
121
|
+
live = false;
|
|
122
|
+
};
|
|
123
|
+
}, [held, target]);
|
|
124
|
+
const own = held ?? (fetched?.language === target ? fetched.bundle : undefined);
|
|
125
|
+
const english = admin === 'en' ? bundle : fallbackBundle;
|
|
126
|
+
return (key, params) => {
|
|
127
|
+
if (own) {
|
|
128
|
+
const result = resolve({
|
|
129
|
+
scope: 'invoices',
|
|
130
|
+
key,
|
|
131
|
+
language: target,
|
|
132
|
+
bundle: own,
|
|
133
|
+
...(english ? { fallbackBundle: english } : {}),
|
|
134
|
+
...(params ? { params } : {}),
|
|
135
|
+
});
|
|
136
|
+
if (result.outcome !== 'placeholder')
|
|
137
|
+
return result.value;
|
|
138
|
+
}
|
|
139
|
+
return t('invoices', key, params);
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/** The operator's label when it has text, as `sections.ts`'s `str` reads one; else `fallback`. */
|
|
143
|
+
function typed(value, fallback) {
|
|
144
|
+
return typeof value === 'string' && value.trim() ? value : fallback;
|
|
145
|
+
}
|
|
83
146
|
function money(n) {
|
|
84
147
|
return n.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
85
148
|
}
|
|
@@ -206,21 +269,23 @@ const InvoiceHeader = invoiceSection({
|
|
|
206
269
|
marginTop: 0,
|
|
207
270
|
marginBottom: 12,
|
|
208
271
|
},
|
|
209
|
-
render: (props) => {
|
|
210
|
-
const inv = sampleInvoice;
|
|
211
|
-
const align = asAlign(props.align, 'left');
|
|
212
|
-
const titleSize = asNum(props.titleSize, 14);
|
|
213
|
-
const titleBold = asBool(props.titleBold, true);
|
|
214
|
-
const titleColor = asColor(props.titleColor, '#0f172a');
|
|
215
|
-
return (_jsxs(Section, { marginTop: asNum(props.marginTop, 0), marginBottom: asNum(props.marginBottom, 12), children: [_jsxs("div", { style: {
|
|
216
|
-
fontSize: titleSize,
|
|
217
|
-
fontWeight: titleBold ? 700 : 400,
|
|
218
|
-
color: titleColor,
|
|
219
|
-
textAlign: align,
|
|
220
|
-
marginBottom: 6,
|
|
221
|
-
}, children: [TITLES[inv.kind], " No. ", inv.number] }), asBool(props.showIssuedAt, true) ? (_jsxs("div", { style: { textAlign: align }, children: [props.labelIssuedAt || 'Issue date', ": ", inv.issuedAt] })) : null, asBool(props.showSaleDate, true) ? (_jsxs("div", { style: { textAlign: align }, children: [props.labelSaleDate || 'Sale date', ": ", inv.saleDate] })) : null, asBool(props.showPaymentDue, true) ? (_jsxs("div", { style: { textAlign: align }, children: [props.labelPaymentDue || 'Payment due', ": ", inv.paymentDueDate] })) : null, asBool(props.showPaymentMethod, true) ? (_jsxs("div", { style: { textAlign: align }, children: [props.labelPaymentMethod || 'Payment method', ": ", inv.paymentMethod] })) : null] }));
|
|
222
|
-
},
|
|
272
|
+
render: (props) => _jsx(InvoiceHeaderCanvas, { ...props }),
|
|
223
273
|
});
|
|
274
|
+
function InvoiceHeaderCanvas(props) {
|
|
275
|
+
const label = useTreeLabels();
|
|
276
|
+
const inv = sampleInvoice;
|
|
277
|
+
const align = asAlign(props.align, 'left');
|
|
278
|
+
const titleSize = asNum(props.titleSize, 14);
|
|
279
|
+
const titleBold = asBool(props.titleBold, true);
|
|
280
|
+
const titleColor = asColor(props.titleColor, '#0f172a');
|
|
281
|
+
return (_jsxs(Section, { marginTop: asNum(props.marginTop, 0), marginBottom: asNum(props.marginBottom, 12), children: [_jsx("div", { style: {
|
|
282
|
+
fontSize: titleSize,
|
|
283
|
+
fontWeight: titleBold ? 700 : 400,
|
|
284
|
+
color: titleColor,
|
|
285
|
+
textAlign: align,
|
|
286
|
+
marginBottom: 6,
|
|
287
|
+
}, children: label('pdf.title.numbered', { title: label('pdf.title.invoice'), number: inv.number }) }), asBool(props.showIssuedAt, true) ? (_jsxs("div", { style: { textAlign: align }, children: [typed(props.labelIssuedAt, label('pdf.label.issuedAt')), ": ", inv.issuedAt] })) : null, asBool(props.showSaleDate, true) ? (_jsxs("div", { style: { textAlign: align }, children: [typed(props.labelSaleDate, label('pdf.label.saleDate')), ": ", inv.saleDate] })) : null, asBool(props.showPaymentDue, true) ? (_jsxs("div", { style: { textAlign: align }, children: [typed(props.labelPaymentDue, label('pdf.label.paymentDue')), ": ", inv.paymentDueDate] })) : null, asBool(props.showPaymentMethod, true) ? (_jsxs("div", { style: { textAlign: align }, children: [typed(props.labelPaymentMethod, label('pdf.label.paymentMethod')), ": ", inv.paymentMethod] })) : null] }));
|
|
288
|
+
}
|
|
224
289
|
const InvoiceParties = invoiceSection({
|
|
225
290
|
label: 'Seller & buyer',
|
|
226
291
|
fields: {
|
|
@@ -249,17 +314,19 @@ const InvoiceParties = invoiceSection({
|
|
|
249
314
|
marginTop: 0,
|
|
250
315
|
marginBottom: 16,
|
|
251
316
|
},
|
|
252
|
-
render: (props) => {
|
|
253
|
-
const { seller, buyer } = sampleInvoice;
|
|
254
|
-
const labelFs = asNum(props.labelFontSize, 10);
|
|
255
|
-
const bodyFs = asNum(props.bodyFontSize, 10);
|
|
256
|
-
const sellerPct = Math.min(70, Math.max(30, asNum(props.sellerWidthPercent, 50)));
|
|
257
|
-
const gap = asNum(props.columnGap, 16);
|
|
258
|
-
const labelStyle = { fontWeight: 700, fontSize: labelFs, marginBottom: 2 };
|
|
259
|
-
const bodyStyle = { fontSize: bodyFs };
|
|
260
|
-
return (_jsx(Section, { marginTop: asNum(props.marginTop, 0), marginBottom: asNum(props.marginBottom, 16), children: _jsxs("div", { style: { display: 'flex', gap }, children: [_jsxs("div", { style: { flex: `0 0 ${sellerPct}%` }, children: [_jsx("div", { style: labelStyle, children: props.sellerLabel || 'Seller' }), _jsx("div", { style: bodyStyle, children: seller.legalName }), _jsx("div", { style: bodyStyle, children: seller.addressLine1 }), seller.addressLine2 ? _jsx("div", { style: bodyStyle, children: seller.addressLine2 }) : null, _jsxs("div", { style: bodyStyle, children: [seller.postalCode, " ", seller.city] }), _jsxs("div", { style: bodyStyle, children: ["Tax ID: ", seller.taxId] }), asBool(props.showSellerBank, true) && seller.bankAccount ? (_jsxs("div", { style: bodyStyle, children: [seller.bankName, " ", seller.bankAccount] })) : null, asBool(props.showSellerSwift, true) && seller.swift ? (_jsxs("div", { style: bodyStyle, children: ["SWIFT: ", seller.swift] })) : null] }), _jsxs("div", { style: { flex: `1 1 ${100 - sellerPct}%` }, children: [_jsx("div", { style: labelStyle, children: props.buyerLabel || 'Buyer' }), _jsx("div", { style: bodyStyle, children: buyer.name }), _jsx("div", { style: bodyStyle, children: buyer.addressLine1 }), _jsxs("div", { style: bodyStyle, children: [buyer.postalCode, " ", buyer.city] }), asBool(props.showBuyerTaxId, true) && buyer.taxId ? (_jsxs("div", { style: bodyStyle, children: ["Tax ID: ", buyer.taxId] })) : null] })] }) }));
|
|
261
|
-
},
|
|
317
|
+
render: (props) => _jsx(InvoicePartiesCanvas, { ...props }),
|
|
262
318
|
});
|
|
319
|
+
function InvoicePartiesCanvas(props) {
|
|
320
|
+
const label = useTreeLabels();
|
|
321
|
+
const { seller, buyer } = sampleInvoice;
|
|
322
|
+
const labelFs = asNum(props.labelFontSize, 10);
|
|
323
|
+
const bodyFs = asNum(props.bodyFontSize, 10);
|
|
324
|
+
const sellerPct = Math.min(70, Math.max(30, asNum(props.sellerWidthPercent, 50)));
|
|
325
|
+
const gap = asNum(props.columnGap, 16);
|
|
326
|
+
const labelStyle = { fontWeight: 700, fontSize: labelFs, marginBottom: 2 };
|
|
327
|
+
const bodyStyle = { fontSize: bodyFs };
|
|
328
|
+
return (_jsx(Section, { marginTop: asNum(props.marginTop, 0), marginBottom: asNum(props.marginBottom, 16), children: _jsxs("div", { style: { display: 'flex', gap }, children: [_jsxs("div", { style: { flex: `0 0 ${sellerPct}%` }, children: [_jsx("div", { style: labelStyle, children: typed(props.sellerLabel, label('pdf.label.seller')) }), _jsx("div", { style: bodyStyle, children: seller.legalName }), _jsx("div", { style: bodyStyle, children: seller.addressLine1 }), seller.addressLine2 ? _jsx("div", { style: bodyStyle, children: seller.addressLine2 }) : null, _jsxs("div", { style: bodyStyle, children: [seller.postalCode, " ", seller.city] }), _jsxs("div", { style: bodyStyle, children: [label('pdf.label.taxId'), ": ", seller.taxId] }), asBool(props.showSellerBank, true) && seller.bankAccount ? (_jsxs("div", { style: bodyStyle, children: [seller.bankName, " ", seller.bankAccount] })) : null, asBool(props.showSellerSwift, true) && seller.swift ? (_jsxs("div", { style: bodyStyle, children: ["SWIFT: ", seller.swift] })) : null] }), _jsxs("div", { style: { flex: `1 1 ${100 - sellerPct}%` }, children: [_jsx("div", { style: labelStyle, children: typed(props.buyerLabel, label('pdf.label.buyer')) }), _jsx("div", { style: bodyStyle, children: buyer.name }), _jsx("div", { style: bodyStyle, children: buyer.addressLine1 }), _jsxs("div", { style: bodyStyle, children: [buyer.postalCode, " ", buyer.city] }), asBool(props.showBuyerTaxId, true) && buyer.taxId ? (_jsxs("div", { style: bodyStyle, children: [label('pdf.label.taxId'), ": ", buyer.taxId] })) : null] })] }) }));
|
|
329
|
+
}
|
|
263
330
|
const InvoiceLineItems = invoiceSection({
|
|
264
331
|
label: 'Line items table',
|
|
265
332
|
fields: {
|
|
@@ -294,68 +361,70 @@ const InvoiceLineItems = invoiceSection({
|
|
|
294
361
|
marginTop: 0,
|
|
295
362
|
marginBottom: 12,
|
|
296
363
|
},
|
|
297
|
-
render: (props) => {
|
|
298
|
-
const fontSize = asNum(props.fontSize, 8);
|
|
299
|
-
const headerBold = asBool(props.headerBold, true);
|
|
300
|
-
const headerBg = asColor(props.headerBackground);
|
|
301
|
-
const headerColor = asColor(props.headerColor);
|
|
302
|
-
const borderColor = asColor(props.borderColor, '#cbd5e1') ?? '#cbd5e1';
|
|
303
|
-
const zebra = asBool(props.zebra, false);
|
|
304
|
-
const showUnit = asBool(props.showUnit, true);
|
|
305
|
-
const showQty = asBool(props.showQty, true);
|
|
306
|
-
const showUnitNet = asBool(props.showUnitNet, true);
|
|
307
|
-
const showTaxRate = asBool(props.showTaxRate, true);
|
|
308
|
-
const showNet = asBool(props.showNet, true);
|
|
309
|
-
const showGross = asBool(props.showGross, true);
|
|
310
|
-
const cols = [
|
|
311
|
-
{ key: 'lp', label: '#' },
|
|
312
|
-
{ key: 'name', label: 'Description' },
|
|
313
|
-
];
|
|
314
|
-
if (showUnit)
|
|
315
|
-
cols.push({ key: 'unit', label: 'Unit' });
|
|
316
|
-
if (showQty)
|
|
317
|
-
cols.push({ key: 'qty', label: 'Qty', right: true });
|
|
318
|
-
if (showUnitNet)
|
|
319
|
-
cols.push({ key: 'unitNet', label: 'Unit net', right: true });
|
|
320
|
-
if (showTaxRate)
|
|
321
|
-
cols.push({ key: 'tax', label: 'Tax', right: true });
|
|
322
|
-
if (showNet)
|
|
323
|
-
cols.push({ key: 'net', label: 'Net', right: true });
|
|
324
|
-
if (showGross)
|
|
325
|
-
cols.push({ key: 'gross', label: 'Gross', right: true });
|
|
326
|
-
const head = {
|
|
327
|
-
...thStyle,
|
|
328
|
-
fontSize,
|
|
329
|
-
fontWeight: headerBold ? 600 : 400,
|
|
330
|
-
color: headerColor,
|
|
331
|
-
background: headerBg,
|
|
332
|
-
borderBottom: `1px solid ${borderColor}`,
|
|
333
|
-
borderRight: `1px solid ${borderColor}`,
|
|
334
|
-
};
|
|
335
|
-
const cell = (right, fill) => ({
|
|
336
|
-
...tdStyle,
|
|
337
|
-
fontSize,
|
|
338
|
-
textAlign: right ? 'right' : 'left',
|
|
339
|
-
background: fill,
|
|
340
|
-
borderBottom: `1px solid ${borderColor}`,
|
|
341
|
-
borderRight: `1px solid ${borderColor}`,
|
|
342
|
-
});
|
|
343
|
-
return (_jsx(Section, { marginTop: asNum(props.marginTop, 0), marginBottom: asNum(props.marginBottom, 12), children: _jsxs("table", { style: { width: '100%', borderCollapse: 'collapse', border: `1px solid ${borderColor}` }, children: [_jsx("thead", { children: _jsx("tr", { children: cols.map((c) => (_jsx("th", { style: { ...head, textAlign: c.right ? 'right' : 'left' }, children: c.label }, c.key))) }) }), _jsx("tbody", { children: sampleInvoice.lines.map((l, i) => {
|
|
344
|
-
const fill = zebra && i % 2 === 1 ? '#f8fafc' : undefined;
|
|
345
|
-
const values = {
|
|
346
|
-
lp: String(l.ordinal),
|
|
347
|
-
name: l.name,
|
|
348
|
-
unit: l.unit,
|
|
349
|
-
qty: String(l.quantity),
|
|
350
|
-
unitNet: unitMoney(l.unitNetPrice),
|
|
351
|
-
tax: pct(l.taxRate),
|
|
352
|
-
net: money(l.netValue),
|
|
353
|
-
gross: money(l.grossValue),
|
|
354
|
-
};
|
|
355
|
-
return (_jsx("tr", { children: cols.map((c) => (_jsx("td", { style: cell(c.right, fill), children: values[c.key] }, c.key))) }, l.ordinal));
|
|
356
|
-
}) })] }) }));
|
|
357
|
-
},
|
|
364
|
+
render: (props) => _jsx(InvoiceLineItemsCanvas, { ...props }),
|
|
358
365
|
});
|
|
366
|
+
function InvoiceLineItemsCanvas(props) {
|
|
367
|
+
const label = useTreeLabels();
|
|
368
|
+
const fontSize = asNum(props.fontSize, 8);
|
|
369
|
+
const headerBold = asBool(props.headerBold, true);
|
|
370
|
+
const headerBg = asColor(props.headerBackground);
|
|
371
|
+
const headerColor = asColor(props.headerColor);
|
|
372
|
+
const borderColor = asColor(props.borderColor, '#cbd5e1') ?? '#cbd5e1';
|
|
373
|
+
const zebra = asBool(props.zebra, false);
|
|
374
|
+
const showUnit = asBool(props.showUnit, true);
|
|
375
|
+
const showQty = asBool(props.showQty, true);
|
|
376
|
+
const showUnitNet = asBool(props.showUnitNet, true);
|
|
377
|
+
const showTaxRate = asBool(props.showTaxRate, true);
|
|
378
|
+
const showNet = asBool(props.showNet, true);
|
|
379
|
+
const showGross = asBool(props.showGross, true);
|
|
380
|
+
const cols = [
|
|
381
|
+
{ key: 'lp', label: label('pdf.column.ordinal') },
|
|
382
|
+
{ key: 'name', label: label('pdf.column.name') },
|
|
383
|
+
];
|
|
384
|
+
if (showUnit)
|
|
385
|
+
cols.push({ key: 'unit', label: label('pdf.column.unit') });
|
|
386
|
+
if (showQty)
|
|
387
|
+
cols.push({ key: 'qty', label: label('pdf.column.quantity'), right: true });
|
|
388
|
+
if (showUnitNet)
|
|
389
|
+
cols.push({ key: 'unitNet', label: label('pdf.column.unitNet'), right: true });
|
|
390
|
+
if (showTaxRate)
|
|
391
|
+
cols.push({ key: 'tax', label: label('pdf.column.taxRate'), right: true });
|
|
392
|
+
if (showNet)
|
|
393
|
+
cols.push({ key: 'net', label: label('pdf.column.net'), right: true });
|
|
394
|
+
if (showGross)
|
|
395
|
+
cols.push({ key: 'gross', label: label('pdf.column.gross'), right: true });
|
|
396
|
+
const head = {
|
|
397
|
+
...thStyle,
|
|
398
|
+
fontSize,
|
|
399
|
+
fontWeight: headerBold ? 600 : 400,
|
|
400
|
+
color: headerColor,
|
|
401
|
+
background: headerBg,
|
|
402
|
+
borderBottom: `1px solid ${borderColor}`,
|
|
403
|
+
borderRight: `1px solid ${borderColor}`,
|
|
404
|
+
};
|
|
405
|
+
const cell = (right, fill) => ({
|
|
406
|
+
...tdStyle,
|
|
407
|
+
fontSize,
|
|
408
|
+
textAlign: right ? 'right' : 'left',
|
|
409
|
+
background: fill,
|
|
410
|
+
borderBottom: `1px solid ${borderColor}`,
|
|
411
|
+
borderRight: `1px solid ${borderColor}`,
|
|
412
|
+
});
|
|
413
|
+
return (_jsx(Section, { marginTop: asNum(props.marginTop, 0), marginBottom: asNum(props.marginBottom, 12), children: _jsxs("table", { style: { width: '100%', borderCollapse: 'collapse', border: `1px solid ${borderColor}` }, children: [_jsx("thead", { children: _jsx("tr", { children: cols.map((c) => (_jsx("th", { style: { ...head, textAlign: c.right ? 'right' : 'left' }, children: c.label }, c.key))) }) }), _jsx("tbody", { children: sampleInvoice.lines.map((l, i) => {
|
|
414
|
+
const fill = zebra && i % 2 === 1 ? '#f8fafc' : undefined;
|
|
415
|
+
const values = {
|
|
416
|
+
lp: String(l.ordinal),
|
|
417
|
+
name: l.name,
|
|
418
|
+
unit: l.unit,
|
|
419
|
+
qty: String(l.quantity),
|
|
420
|
+
unitNet: unitMoney(l.unitNetPrice),
|
|
421
|
+
tax: pct(l.taxRate),
|
|
422
|
+
net: money(l.netValue),
|
|
423
|
+
gross: money(l.grossValue),
|
|
424
|
+
};
|
|
425
|
+
return (_jsx("tr", { children: cols.map((c) => (_jsx("td", { style: cell(c.right, fill), children: values[c.key] }, c.key))) }, l.ordinal));
|
|
426
|
+
}) })] }) }));
|
|
427
|
+
}
|
|
359
428
|
const InvoiceVatSummary = invoiceSection({
|
|
360
429
|
label: 'VAT summary',
|
|
361
430
|
fields: {
|
|
@@ -380,35 +449,42 @@ const InvoiceVatSummary = invoiceSection({
|
|
|
380
449
|
marginTop: 0,
|
|
381
450
|
marginBottom: 12,
|
|
382
451
|
},
|
|
383
|
-
render: (props) => {
|
|
384
|
-
const inv = sampleInvoice;
|
|
385
|
-
const fontSize = asNum(props.fontSize, 8);
|
|
386
|
-
const headerBold = asBool(props.headerBold, true);
|
|
387
|
-
const headerBg = asColor(props.headerBackground);
|
|
388
|
-
const headerColor = asColor(props.headerColor);
|
|
389
|
-
const borderColor = asColor(props.borderColor, '#cbd5e1') ?? '#cbd5e1';
|
|
390
|
-
const headers = ['Tax rate', 'Net', 'VAT', 'Gross'];
|
|
391
|
-
const head = (i) => ({
|
|
392
|
-
...thStyle,
|
|
393
|
-
fontSize,
|
|
394
|
-
fontWeight: headerBold ? 600 : 400,
|
|
395
|
-
color: headerColor,
|
|
396
|
-
background: headerBg,
|
|
397
|
-
textAlign: i === 0 ? 'left' : 'right',
|
|
398
|
-
borderBottom: `1px solid ${borderColor}`,
|
|
399
|
-
borderRight: `1px solid ${borderColor}`,
|
|
400
|
-
});
|
|
401
|
-
const cell = (right, bold) => ({
|
|
402
|
-
...tdStyle,
|
|
403
|
-
fontSize,
|
|
404
|
-
fontWeight: bold ? 700 : 400,
|
|
405
|
-
textAlign: right ? 'right' : 'left',
|
|
406
|
-
borderBottom: `1px solid ${borderColor}`,
|
|
407
|
-
borderRight: `1px solid ${borderColor}`,
|
|
408
|
-
});
|
|
409
|
-
return (_jsx(Section, { marginTop: asNum(props.marginTop, 0), marginBottom: asNum(props.marginBottom, 12), children: _jsxs("table", { style: { width: '100%', borderCollapse: 'collapse', border: `1px solid ${borderColor}` }, children: [_jsx("thead", { children: _jsx("tr", { children: headers.map((h, i) => (_jsx("th", { style: head(i), children: h }, h))) }) }), _jsxs("tbody", { children: [inv.vatSummary.map((v) => (_jsxs("tr", { children: [_jsx("td", { style: cell(), children: pct(v.taxRate) }), _jsx("td", { style: cell(true), children: money(v.netTotal) }), _jsx("td", { style: cell(true), children: money(v.vatAmount) }), _jsx("td", { style: cell(true), children: money(v.grossTotal) })] }, v.taxRate))), asBool(props.showTotalRow, true) ? (_jsxs("tr", { children: [_jsx("td", { style: cell(false, true), children: props.totalLabel || 'Total' }), _jsx("td", { style: cell(true, true), children: money(inv.netTotal) }), _jsx("td", { style: cell(true, true), children: money(inv.taxTotal) }), _jsx("td", { style: cell(true, true), children: money(inv.grossTotal) })] })) : null] })] }) }));
|
|
410
|
-
},
|
|
452
|
+
render: (props) => _jsx(InvoiceVatSummaryCanvas, { ...props }),
|
|
411
453
|
});
|
|
454
|
+
function InvoiceVatSummaryCanvas(props) {
|
|
455
|
+
const label = useTreeLabels();
|
|
456
|
+
const inv = sampleInvoice;
|
|
457
|
+
const fontSize = asNum(props.fontSize, 8);
|
|
458
|
+
const headerBold = asBool(props.headerBold, true);
|
|
459
|
+
const headerBg = asColor(props.headerBackground);
|
|
460
|
+
const headerColor = asColor(props.headerColor);
|
|
461
|
+
const borderColor = asColor(props.borderColor, '#cbd5e1') ?? '#cbd5e1';
|
|
462
|
+
const headers = [
|
|
463
|
+
label('pdf.vat.rate'),
|
|
464
|
+
label('pdf.column.net'),
|
|
465
|
+
label('pdf.vat.amount'),
|
|
466
|
+
label('pdf.column.gross'),
|
|
467
|
+
];
|
|
468
|
+
const head = (i) => ({
|
|
469
|
+
...thStyle,
|
|
470
|
+
fontSize,
|
|
471
|
+
fontWeight: headerBold ? 600 : 400,
|
|
472
|
+
color: headerColor,
|
|
473
|
+
background: headerBg,
|
|
474
|
+
textAlign: i === 0 ? 'left' : 'right',
|
|
475
|
+
borderBottom: `1px solid ${borderColor}`,
|
|
476
|
+
borderRight: `1px solid ${borderColor}`,
|
|
477
|
+
});
|
|
478
|
+
const cell = (right, bold) => ({
|
|
479
|
+
...tdStyle,
|
|
480
|
+
fontSize,
|
|
481
|
+
fontWeight: bold ? 700 : 400,
|
|
482
|
+
textAlign: right ? 'right' : 'left',
|
|
483
|
+
borderBottom: `1px solid ${borderColor}`,
|
|
484
|
+
borderRight: `1px solid ${borderColor}`,
|
|
485
|
+
});
|
|
486
|
+
return (_jsx(Section, { marginTop: asNum(props.marginTop, 0), marginBottom: asNum(props.marginBottom, 12), children: _jsxs("table", { style: { width: '100%', borderCollapse: 'collapse', border: `1px solid ${borderColor}` }, children: [_jsx("thead", { children: _jsx("tr", { children: headers.map((h, i) => (_jsx("th", { style: head(i), children: h }, h))) }) }), _jsxs("tbody", { children: [inv.vatSummary.map((v) => (_jsxs("tr", { children: [_jsx("td", { style: cell(), children: pct(v.taxRate) }), _jsx("td", { style: cell(true), children: money(v.netTotal) }), _jsx("td", { style: cell(true), children: money(v.vatAmount) }), _jsx("td", { style: cell(true), children: money(v.grossTotal) })] }, v.taxRate))), asBool(props.showTotalRow, true) ? (_jsxs("tr", { children: [_jsx("td", { style: cell(false, true), children: typed(props.totalLabel, label('pdf.label.total')) }), _jsx("td", { style: cell(true, true), children: money(inv.netTotal) }), _jsx("td", { style: cell(true, true), children: money(inv.taxTotal) }), _jsx("td", { style: cell(true, true), children: money(inv.grossTotal) })] })) : null] })] }) }));
|
|
487
|
+
}
|
|
412
488
|
const InvoiceTotals = invoiceSection({
|
|
413
489
|
label: 'Totals & amount in words',
|
|
414
490
|
fields: {
|
|
@@ -452,21 +528,23 @@ const InvoiceTotals = invoiceSection({
|
|
|
452
528
|
marginTop: 0,
|
|
453
529
|
marginBottom: 16,
|
|
454
530
|
},
|
|
455
|
-
render: (props) => {
|
|
456
|
-
const inv = sampleInvoice;
|
|
457
|
-
const align = asAlign(props.align, 'right');
|
|
458
|
-
const fontSize = asNum(props.fontSize, 10);
|
|
459
|
-
const color = asColor(props.color, '#0f172a');
|
|
460
|
-
const amountDueColor = asColor(props.amountDueColor) ?? color;
|
|
461
|
-
return (_jsx(Section, { marginTop: asNum(props.marginTop, 0), marginBottom: asNum(props.marginBottom, 16), children: _jsxs("div", { style: { textAlign: align, fontSize, color }, children: [asBool(props.showPaid, true) ? (_jsxs("div", { children: [props.labelPaid || 'Paid', ": ", money(inv.paidTotal), " ", inv.currency] })) : null, asBool(props.showAmountDue, true) ? (_jsxs("div", { style: {
|
|
462
|
-
fontWeight: asBool(props.amountDueBold, true) ? 700 : 400,
|
|
463
|
-
color: amountDueColor,
|
|
464
|
-
}, children: [props.labelAmountDue || 'Amount due', ": ", money(inv.amountDue), " ", inv.currency] })) : null, asBool(props.showOverpayment, true) && inv.overpayment > 0 ? (_jsxs("div", { children: [props.labelOverpayment || 'Overpayment', ": ", money(inv.overpayment), " ", inv.currency] })) : null, asBool(props.showGross, true) ? (_jsxs("div", { children: [props.labelGross || 'Total', ": ", money(inv.grossTotal), " ", inv.currency] })) : null, asBool(props.showAmountInWords, true) ? (_jsxs("div", { style: {
|
|
465
|
-
fontStyle: asBool(props.amountInWordsItalics, true) ? 'italic' : 'normal',
|
|
466
|
-
marginTop: 6,
|
|
467
|
-
}, children: [props.labelInWords || 'In words', ": ", inv.amountInWords, " ", inv.currency] })) : null] }) }));
|
|
468
|
-
},
|
|
531
|
+
render: (props) => _jsx(InvoiceTotalsCanvas, { ...props }),
|
|
469
532
|
});
|
|
533
|
+
function InvoiceTotalsCanvas(props) {
|
|
534
|
+
const label = useTreeLabels();
|
|
535
|
+
const inv = sampleInvoice;
|
|
536
|
+
const align = asAlign(props.align, 'right');
|
|
537
|
+
const fontSize = asNum(props.fontSize, 10);
|
|
538
|
+
const color = asColor(props.color, '#0f172a');
|
|
539
|
+
const amountDueColor = asColor(props.amountDueColor) ?? color;
|
|
540
|
+
return (_jsx(Section, { marginTop: asNum(props.marginTop, 0), marginBottom: asNum(props.marginBottom, 16), children: _jsxs("div", { style: { textAlign: align, fontSize, color }, children: [asBool(props.showPaid, true) ? (_jsxs("div", { children: [typed(props.labelPaid, label('pdf.label.paid')), ": ", money(inv.paidTotal), " ", inv.currency] })) : null, asBool(props.showAmountDue, true) ? (_jsxs("div", { style: {
|
|
541
|
+
fontWeight: asBool(props.amountDueBold, true) ? 700 : 400,
|
|
542
|
+
color: amountDueColor,
|
|
543
|
+
}, children: [typed(props.labelAmountDue, label('pdf.label.amountDue')), ": ", money(inv.amountDue), " ", inv.currency] })) : null, asBool(props.showOverpayment, true) && inv.overpayment > 0 ? (_jsxs("div", { children: [typed(props.labelOverpayment, label('pdf.label.overpayment')), ": ", money(inv.overpayment), " ", inv.currency] })) : null, asBool(props.showGross, true) ? (_jsxs("div", { children: [typed(props.labelGross, label('pdf.label.total')), ": ", money(inv.grossTotal), " ", inv.currency] })) : null, asBool(props.showAmountInWords, true) ? (_jsxs("div", { style: {
|
|
544
|
+
fontStyle: asBool(props.amountInWordsItalics, true) ? 'italic' : 'normal',
|
|
545
|
+
marginTop: 6,
|
|
546
|
+
}, children: [typed(props.labelInWords, label('pdf.label.inWords')), ": ", inv.amountInWords, " ", inv.currency] })) : null] }) }));
|
|
547
|
+
}
|
|
470
548
|
function renderTextBlock(props, defaults) {
|
|
471
549
|
const align = asAlign(props.align, 'left');
|
|
472
550
|
const fontSize = asNum(props.fontSize, defaults.fontSize);
|
|
@@ -679,13 +757,20 @@ const InvoiceFooter = invoiceSection({
|
|
|
679
757
|
marginTop: 0,
|
|
680
758
|
marginBottom: 8,
|
|
681
759
|
},
|
|
682
|
-
render: (props) =>
|
|
760
|
+
render: (props) => _jsx(InvoiceFooterCanvas, { ...props }),
|
|
761
|
+
});
|
|
762
|
+
function InvoiceFooterCanvas(props) {
|
|
763
|
+
// An empty footer prints the default one in the document's language, as an
|
|
764
|
+
// empty label does (issue #437).
|
|
765
|
+
const label = useTreeLabels();
|
|
766
|
+
const text = typed(props.text, label('pdf.footer.default'));
|
|
767
|
+
return renderTextBlock({ ...props, text }, {
|
|
683
768
|
fontSize: 9,
|
|
684
769
|
showTopDivider: true,
|
|
685
770
|
marginBottom: 8,
|
|
686
|
-
emptyHint:
|
|
687
|
-
})
|
|
688
|
-
}
|
|
771
|
+
emptyHint: text,
|
|
772
|
+
});
|
|
773
|
+
}
|
|
689
774
|
/* -------------------------------------------------------------------------- */
|
|
690
775
|
/* Config export */
|
|
691
776
|
/* -------------------------------------------------------------------------- */
|
|
@@ -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
|