@happyvertical/smrt-commerce 0.56.2 → 0.57.1
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/AGENTS.md +24 -11
- package/README.md +137 -89
- package/agents/accounting-snapshot-mapper.md +3 -3
- package/agents/commercial-ui.md +2 -2
- package/agents/contract-money.md +9 -12
- package/agents/cost-billing.md +3 -6
- package/agents/customer-vendor-ui.md +1 -2
- package/agents/document-money.md +58 -31
- package/agents/invoice-calculations.md +31 -56
- package/agents/invoice-preparation.md +62 -73
- package/agents/invoice-quantity.md +9 -21
- package/agents/minor-unit-migration.md +4 -4
- package/agents/money-calculator.md +7 -8
- package/agents/money-model.md +18 -22
- package/agents/money-upgrade.md +92 -0
- package/agents/revenue-journal.md +2 -2
- package/agents/tax-codes.md +17 -14
- package/agents/tax-summary.md +8 -6
- package/dist/billing/period-close.d.ts.map +1 -1
- package/dist/billing/runtime.d.ts +5 -2
- package/dist/billing/runtime.d.ts.map +1 -1
- package/dist/chunks/{ContractLineItemCollection--BrGMtNz.js → ContractLineItemCollection-BZcrlrrY.js} +19 -24
- package/dist/chunks/ContractLineItemCollection-BZcrlrrY.js.map +1 -0
- package/dist/chunks/{CustomerCollection-CjGaZSpf.js → CustomerCollection-BIPH2ZUx.js} +2 -2
- package/dist/chunks/{CustomerCollection-CjGaZSpf.js.map → CustomerCollection-BIPH2ZUx.js.map} +1 -1
- package/dist/chunks/{DocumentTaxCollection-KOkaQT2M.js → DocumentTaxCollection-DDzlywMW.js} +14 -7
- package/dist/chunks/DocumentTaxCollection-DDzlywMW.js.map +1 -0
- package/dist/chunks/{InvoiceCollection-BUe_8FT1.js → InvoiceCollection-cinzAqt6.js} +50 -161
- package/dist/chunks/InvoiceCollection-cinzAqt6.js.map +1 -0
- package/dist/chunks/{TaxCodeCollection-DF2eaJed.js → TaxCodeCollection-DaBOPG9c.js} +11 -4
- package/dist/chunks/{TaxCodeCollection-DF2eaJed.js.map → TaxCodeCollection-DaBOPG9c.js.map} +1 -1
- package/dist/chunks/{TaxComponentCollection-3x24xSNh.js → TaxComponentCollection-C4zxnyVu.js} +3 -3
- package/dist/chunks/{TaxComponentCollection-3x24xSNh.js.map → TaxComponentCollection-C4zxnyVu.js.map} +1 -1
- package/dist/chunks/VendorCollection-D6ZcUYy8.js +100 -0
- package/dist/chunks/VendorCollection-D6ZcUYy8.js.map +1 -0
- package/dist/chunks/{allocation-integrity-Cq0g6CfO.js → allocation-integrity-WmWyXhtG.js} +6 -6
- package/dist/chunks/{allocation-integrity-Cq0g6CfO.js.map → allocation-integrity-WmWyXhtG.js.map} +1 -1
- package/dist/chunks/calculations-C9daQLsh.js +82 -0
- package/dist/chunks/calculations-C9daQLsh.js.map +1 -0
- package/dist/chunks/contract-money-EuToOghh.js +301 -0
- package/dist/chunks/contract-money-EuToOghh.js.map +1 -0
- package/dist/chunks/detect-CY9ufaFb.js +328 -0
- package/dist/chunks/detect-CY9ufaFb.js.map +1 -0
- package/dist/chunks/{document-money-oUDvdjOf.js → document-money-DV5t4vlK.js} +388 -62
- package/dist/chunks/document-money-DV5t4vlK.js.map +1 -0
- package/dist/chunks/{invoice-posting-CF3fE_Ec.js → invoice-posting-C2i5dOVZ.js} +20 -22
- package/dist/chunks/invoice-posting-C2i5dOVZ.js.map +1 -0
- package/dist/chunks/{revenue-journal-DY9fro8E.js → revenue-journal-LLA9Kh_i.js} +3 -14
- package/dist/chunks/revenue-journal-LLA9Kh_i.js.map +1 -0
- package/dist/chunks/tenant-money-barrier-6TlqUeVj.js +255 -0
- package/dist/chunks/tenant-money-barrier-6TlqUeVj.js.map +1 -0
- package/dist/chunks/types-Bbm0Xflc.js.map +1 -1
- package/dist/chunks/{units-CNcjH_eE.js → units-8ElbjVZK.js} +18 -3
- package/dist/chunks/units-8ElbjVZK.js.map +1 -0
- package/dist/collections/ContractCollection.d.ts.map +1 -1
- package/dist/collections/ContractLineItemCollection.d.ts.map +1 -1
- package/dist/collections/InvoiceCollection.d.ts.map +1 -1
- package/dist/collections/InvoiceLineItemCollection.d.ts +0 -30
- package/dist/collections/InvoiceLineItemCollection.d.ts.map +1 -1
- package/dist/collections/TaxCodeCollection.d.ts +5 -1
- package/dist/collections/TaxCodeCollection.d.ts.map +1 -1
- package/dist/collections/TaxSettingsCollection.d.ts +15 -8
- package/dist/collections/TaxSettingsCollection.d.ts.map +1 -1
- package/dist/collections/TaxSummaryReportCollection.d.ts +3 -3
- package/dist/collections/TaxSummaryReportCollection.d.ts.map +1 -1
- package/dist/collections/index.d.ts +0 -1
- package/dist/collections/index.d.ts.map +1 -1
- package/dist/commerce-money-tools.d.ts.map +1 -1
- package/dist/contract-money.d.ts +1 -13
- package/dist/contract-money.d.ts.map +1 -1
- package/dist/document-money-internal.d.ts +7 -3
- package/dist/document-money-internal.d.ts.map +1 -1
- package/dist/document-money.d.ts +1 -11
- package/dist/document-money.d.ts.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +667 -1650
- package/dist/index.js.map +1 -1
- package/dist/invoice-accounting-sync.d.ts.map +1 -1
- package/dist/invoice-mcp.d.ts +3 -3
- package/dist/invoice-mcp.d.ts.map +1 -1
- package/dist/invoice-posting.d.ts +11 -5
- package/dist/invoice-posting.d.ts.map +1 -1
- package/dist/invoice-record-screen.d.ts +1 -1
- package/dist/invoice-record-screen.d.ts.map +1 -1
- package/dist/invoices.d.ts +6 -1
- package/dist/invoices.d.ts.map +1 -1
- package/dist/invoices.js +2 -2
- package/dist/manifest.json +37 -765
- package/dist/migrations/invoiceEditorStorage.d.ts +2 -4
- package/dist/migrations/invoiceEditorStorage.d.ts.map +1 -1
- package/dist/models/Contract.d.ts.map +1 -1
- package/dist/models/ContractLineItem.d.ts +6 -22
- package/dist/models/ContractLineItem.d.ts.map +1 -1
- package/dist/models/Invoice.d.ts +18 -48
- package/dist/models/Invoice.d.ts.map +1 -1
- package/dist/models/InvoiceLineItem.d.ts +8 -37
- package/dist/models/InvoiceLineItem.d.ts.map +1 -1
- package/dist/models/TaxSettings.d.ts +0 -10
- package/dist/models/TaxSettings.d.ts.map +1 -1
- package/dist/models/index.d.ts +0 -1
- package/dist/models/index.d.ts.map +1 -1
- package/dist/playground.js +1 -1
- package/dist/playground.js.map +1 -1
- package/dist/recipes.d.ts +8 -11
- package/dist/recipes.d.ts.map +1 -1
- package/dist/revenue-journal.d.ts +0 -8
- package/dist/revenue-journal.d.ts.map +1 -1
- package/dist/smrt-knowledge.json +79 -661
- package/dist/svelte/components/InvoiceEditor.svelte +7 -148
- package/dist/svelte/components/InvoiceEditor.svelte.d.ts +4 -1
- package/dist/svelte/components/InvoiceEditor.svelte.d.ts.map +1 -1
- package/dist/svelte/components/InvoiceTotals.svelte +14 -118
- package/dist/svelte/components/InvoiceTotals.svelte.d.ts +4 -27
- package/dist/svelte/components/InvoiceTotals.svelte.d.ts.map +1 -1
- package/dist/svelte/components/MoneyInvoiceEditor.svelte +3 -23
- package/dist/svelte/components/MoneyInvoiceEditor.svelte.d.ts +3 -26
- package/dist/svelte/components/MoneyInvoiceEditor.svelte.d.ts.map +1 -1
- package/dist/svelte/index.d.ts +2 -3
- package/dist/svelte/index.d.ts.map +1 -1
- package/dist/svelte/index.js +1 -2
- package/dist/svelte/invoices/calculations.d.ts +3 -108
- package/dist/svelte/invoices/calculations.d.ts.map +1 -1
- package/dist/svelte/invoices/calculations.js +12 -309
- package/dist/svelte/invoices/messages.d.ts +1 -37
- package/dist/svelte/invoices/messages.d.ts.map +1 -1
- package/dist/svelte/invoices/messages.js +1 -37
- package/dist/svelte/invoices/money-editor.d.ts +1 -1
- package/dist/svelte/invoices/money-editor.d.ts.map +1 -1
- package/dist/svelte/invoices/types.d.ts +14 -114
- package/dist/svelte/invoices/types.d.ts.map +1 -1
- package/dist/svelte/playground/InvoicePreparationPreview.svelte +85 -94
- package/dist/svelte/playground/InvoicePreparationPreview.svelte.d.ts.map +1 -1
- package/dist/svelte/playground.js +1 -1
- package/dist/tax/index.d.ts +2 -1
- package/dist/tax/index.d.ts.map +1 -1
- package/dist/tax/standard-codes.d.ts +12 -0
- package/dist/tax/standard-codes.d.ts.map +1 -0
- package/dist/tax/tenant-bootstrap.d.ts +29 -0
- package/dist/tax/tenant-bootstrap.d.ts.map +1 -0
- package/dist/tenant-money-barrier.d.ts +12 -44
- package/dist/tenant-money-barrier.d.ts.map +1 -1
- package/dist/types/index.d.ts +10 -23
- package/dist/types/index.d.ts.map +1 -1
- package/dist/ui.js +1 -1
- package/dist/ui.js.map +1 -1
- package/dist/upgrade/detect.d.ts +129 -0
- package/dist/upgrade/detect.d.ts.map +1 -0
- package/dist/upgrade/money-v2.d.ts +81 -0
- package/dist/upgrade/money-v2.d.ts.map +1 -0
- package/package.json +14 -13
- package/agents/line-amount-migration.md +0 -50
- package/dist/chunks/ContractLineItemCollection--BrGMtNz.js.map +0 -1
- package/dist/chunks/DocumentTaxCollection-KOkaQT2M.js.map +0 -1
- package/dist/chunks/InvoiceCollection-BUe_8FT1.js.map +0 -1
- package/dist/chunks/InvoiceLineItemCollection-CPQGghyd.js +0 -468
- package/dist/chunks/InvoiceLineItemCollection-CPQGghyd.js.map +0 -1
- package/dist/chunks/TaxSettingsCollection-DYYF-In-.js +0 -319
- package/dist/chunks/TaxSettingsCollection-DYYF-In-.js.map +0 -1
- package/dist/chunks/calculations-DaHR17il.js +0 -333
- package/dist/chunks/calculations-DaHR17il.js.map +0 -1
- package/dist/chunks/document-money-oUDvdjOf.js.map +0 -1
- package/dist/chunks/invoice-posting-CF3fE_Ec.js.map +0 -1
- package/dist/chunks/revenue-journal-DY9fro8E.js.map +0 -1
- package/dist/chunks/tenant-money-barrier-y6EAa6vY.js +0 -135
- package/dist/chunks/tenant-money-barrier-y6EAa6vY.js.map +0 -1
- package/dist/chunks/units-CNcjH_eE.js.map +0 -1
- package/dist/collections/MoneyMigrationDocumentCollection.d.ts +0 -12
- package/dist/collections/MoneyMigrationDocumentCollection.d.ts.map +0 -1
- package/dist/migrations/commerceLineAmounts.d.ts +0 -84
- package/dist/migrations/commerceLineAmounts.d.ts.map +0 -1
- package/dist/models/MoneyMigrationDocument.d.ts +0 -28
- package/dist/models/MoneyMigrationDocument.d.ts.map +0 -1
- package/dist/svelte/components/InvoiceLineEditor.svelte +0 -92
- package/dist/svelte/components/InvoiceLineEditor.svelte.d.ts +0 -8
- package/dist/svelte/components/InvoiceLineEditor.svelte.d.ts.map +0 -1
- package/dist/svelte/invoices/fields.d.ts +0 -6
- package/dist/svelte/invoices/fields.d.ts.map +0 -1
- package/dist/svelte/invoices/fields.js +0 -22
- package/dist/tax/legacy.d.ts +0 -48
- package/dist/tax/legacy.d.ts.map +0 -1
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type { FormRetryStatus } from '@happyvertical/smrt-ui/form-retry';
|
|
2
|
-
import type { Snippet } from 'svelte';
|
|
3
1
|
import type { HTMLFormAttributes } from 'svelte/elements';
|
|
4
|
-
import type { InvoiceDraftCalculationOptions } from './calculations.js';
|
|
5
2
|
import type { MoneyEditorProps } from './money-editor.js';
|
|
6
3
|
export type { MoneyEditorDraft, MoneyEditorFieldNames, MoneyEditorLineDraft, MoneyEditorProps, MoneyEditorTaxCode, MoneyStoredDocument, MoneyStoredTax, } from './money-editor.js';
|
|
7
4
|
/** Authorized source projection supplied by the application, not fetched by UI. */
|
|
@@ -55,9 +52,6 @@ export interface InvoicePreparationHiddenField {
|
|
|
55
52
|
/** Value forwarded without normalization or rotation. */
|
|
56
53
|
value: string;
|
|
57
54
|
}
|
|
58
|
-
/** Invoice draft types shared with the Svelte-free exact calculator. */
|
|
59
|
-
export type { InvoiceDraftValues, InvoiceLineDraft } from './calculations.js';
|
|
60
|
-
import type { InvoiceDraftValues, InvoiceLineDraft } from './calculations.js';
|
|
61
55
|
/** Optional allocation fields, rendered without an enclosing form. */
|
|
62
56
|
export interface InvoiceAllocationFieldsProps {
|
|
63
57
|
/** Currency for allocation presentation. */
|
|
@@ -79,121 +73,27 @@ export interface InvoiceAllocationFieldsProps {
|
|
|
79
73
|
/** Stable label identity. */
|
|
80
74
|
id?: string;
|
|
81
75
|
}
|
|
82
|
-
/**
|
|
83
|
-
export interface
|
|
84
|
-
/**
|
|
85
|
-
key: string;
|
|
86
|
-
/** Description text. */
|
|
87
|
-
description: string;
|
|
88
|
-
/** Product/SKU reference text. */
|
|
89
|
-
sku: string;
|
|
90
|
-
/** Fractional quantity text. */
|
|
91
|
-
quantity: string;
|
|
92
|
-
/** Currency-unit price text. */
|
|
93
|
-
unitPrice: string;
|
|
94
|
-
/** Flat or percentage discount selection. */
|
|
95
|
-
discountType: string;
|
|
96
|
-
/** Currency-unit or percent discount text. */
|
|
97
|
-
discountValue: string;
|
|
98
|
-
/** Inherited or explicit tax selection. */
|
|
99
|
-
taxMode: string;
|
|
100
|
-
/** Explicit percentage tax text, including zero. */
|
|
101
|
-
taxRate: string;
|
|
102
|
-
}
|
|
103
|
-
/** Invoice header and submitter name adapters. */
|
|
104
|
-
export interface InvoiceFieldNames {
|
|
105
|
-
/** Customer reference. */
|
|
106
|
-
customerId: string;
|
|
107
|
-
/** Invoice date text. */
|
|
108
|
-
issuedOn: string;
|
|
109
|
-
/** Due date text. */
|
|
110
|
-
dueOn: string;
|
|
111
|
-
/** Currency code. */
|
|
112
|
-
currency: string;
|
|
113
|
-
/** Payment terms text. */
|
|
114
|
-
paymentTerms: string;
|
|
115
|
-
/** Default tax percentage text. */
|
|
116
|
-
taxRate: string;
|
|
117
|
-
/** Clicked submitter name. */
|
|
118
|
-
intent: string;
|
|
119
|
-
}
|
|
120
|
-
/** General invoice line fields; never renders a nested form. */
|
|
121
|
-
export interface InvoiceLineEditorProps extends InvoiceDraftCalculationOptions {
|
|
122
|
-
/** Lossless caller-owned line values. */
|
|
123
|
-
line: InvoiceLineDraft;
|
|
124
|
-
/** Current currency code for shared calculation. */
|
|
125
|
-
currency: string;
|
|
126
|
-
/** External default tax percentage; explicit line override remains distinct. */
|
|
127
|
-
inheritedTaxRate: string;
|
|
128
|
-
/** One-based display position. */
|
|
129
|
-
number?: number;
|
|
130
|
-
/** Stable control-label prefix. */
|
|
131
|
-
id?: string;
|
|
132
|
-
/** Native field-name adapters. */
|
|
133
|
-
fields?: Partial<InvoiceLineFieldNames>;
|
|
134
|
-
/** Caller errors keyed by canonical line field name. */
|
|
135
|
-
errors?: Partial<Record<keyof InvoiceLineFieldNames, string>>;
|
|
136
|
-
/** Presentation capability. */
|
|
137
|
-
canEdit?: boolean;
|
|
138
|
-
/** Disable structural actions while pending. */
|
|
139
|
-
pending?: boolean;
|
|
140
|
-
/** Native submitter name. */
|
|
141
|
-
intentField?: string;
|
|
142
|
-
/** Remove intent prefix, followed by caller line key. */
|
|
143
|
-
removePrefix?: string;
|
|
144
|
-
/** Optional notification with a new lossless draft; the supplied line is never mutated. */
|
|
145
|
-
onchange?: (line: InvoiceLineDraft) => void;
|
|
146
|
-
}
|
|
147
|
-
/** General native invoice editor with optional domain extensions. */
|
|
148
|
-
export interface InvoiceEditorProps extends InvoiceDraftCalculationOptions {
|
|
149
|
-
/** Caller native endpoint. */
|
|
76
|
+
/** The invoice editor: the v2 money surface is its only model. */
|
|
77
|
+
export interface InvoiceEditorProps {
|
|
78
|
+
/** Native form action owned by the caller's invoice route. */
|
|
150
79
|
action: string;
|
|
151
|
-
/** Native method
|
|
80
|
+
/** Native HTTP method retained for progressive enhancement. */
|
|
152
81
|
method?: 'post' | 'get';
|
|
153
|
-
/**
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
title?: string;
|
|
157
|
-
/** Retained editable strings; never reconstructed from model numbers. */
|
|
158
|
-
values?: InvoiceDraftValues;
|
|
159
|
-
/** Authorized customer projections; retained unknown references stay visible. */
|
|
160
|
-
customers?: readonly {
|
|
161
|
-
id: string;
|
|
162
|
-
label: string;
|
|
163
|
-
}[];
|
|
164
|
-
/** Caller field errors: header name or lineKey.fieldName. */
|
|
165
|
-
errors?: Record<string, string>;
|
|
166
|
-
/** Header and submitter field adapters. */
|
|
167
|
-
fields?: Partial<InvoiceFieldNames>;
|
|
168
|
-
/** Repeated line field adapters. */
|
|
169
|
-
lineFields?: Partial<InvoiceLineFieldNames>;
|
|
170
|
-
/** Presentation capability only; server reauthorizes all mutations. */
|
|
82
|
+
/** Typed v2 money draft, tax-code choices, and stored issued snapshot. */
|
|
83
|
+
money: MoneyEditorProps;
|
|
84
|
+
/** Presentation capability; the server remains the authority for writes. */
|
|
171
85
|
canEdit?: boolean;
|
|
172
|
-
/**
|
|
86
|
+
/** Caller transport state that disables edits and the save submitter. */
|
|
173
87
|
pending?: boolean;
|
|
174
|
-
/** Caller-owned
|
|
175
|
-
retryStatus?: FormRetryStatus;
|
|
176
|
-
/** Caller error or uncertain-outcome message. */
|
|
177
|
-
message?: string;
|
|
178
|
-
/** Server-authoritative review snapshot. */
|
|
179
|
-
review?: InvoicePreparationReview;
|
|
180
|
-
/** Exact caller tokens/context; repeated names preserved. */
|
|
88
|
+
/** Caller-owned request identity and route fields submitted unchanged. */
|
|
181
89
|
hiddenFields?: readonly InvoicePreparationHiddenField[];
|
|
182
|
-
/**
|
|
90
|
+
/** Native submitter field name expected by the caller, default intent. */
|
|
91
|
+
intentField?: string;
|
|
92
|
+
/** Submitter value that requests a draft save, default save. */
|
|
183
93
|
saveIntent?: string;
|
|
184
|
-
/**
|
|
185
|
-
addIntent?: string;
|
|
186
|
-
/** Remove-line intent prefix, default removeLine:. */
|
|
187
|
-
removePrefix?: string;
|
|
188
|
-
/** Caller-localized save label. */
|
|
94
|
+
/** Caller-visible label for the save submitter. */
|
|
189
95
|
saveLabel?: string;
|
|
190
|
-
/** Optional
|
|
191
|
-
cancelHref?: string;
|
|
192
|
-
/** Domain fields inside the single form; receives current draft for currency-aware extensions. */
|
|
193
|
-
children?: Snippet<[InvoiceDraftValues]>;
|
|
194
|
-
/** Optional enhancement; native submission remains the default. */
|
|
96
|
+
/** Optional native form enhancement; omitted submissions stay native. */
|
|
195
97
|
onsubmit?: HTMLFormAttributes['onsubmit'];
|
|
196
|
-
/** Explicit v2 money surface. Omit to retain the legacy invoice editor API. */
|
|
197
|
-
money?: MoneyEditorProps;
|
|
198
98
|
}
|
|
199
99
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/svelte/invoices/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/svelte/invoices/types.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,117 +1,108 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { Checkbox } from '@happyvertical/smrt-ui/forms';
|
|
3
|
-
import InvoiceAllocationFields from '../components/InvoiceAllocationFields.svelte';
|
|
4
3
|
import InvoiceEditor from '../components/InvoiceEditor.svelte';
|
|
5
|
-
import {
|
|
6
|
-
invoiceFieldNames,
|
|
7
|
-
invoiceLineFieldNames,
|
|
8
|
-
} from '../invoices/fields.js';
|
|
9
|
-
import type {
|
|
10
|
-
InvoiceAllocationDraft,
|
|
11
|
-
InvoiceDraftValues,
|
|
12
|
-
} from '../invoices/types.js';
|
|
4
|
+
import type { MoneyEditorProps } from '../invoices/types.js';
|
|
13
5
|
|
|
14
|
-
let
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
let canEdit = $state(true);
|
|
7
|
+
let frozen = $state(false);
|
|
8
|
+
const taxCodes: MoneyEditorProps['taxCodes'] = [
|
|
9
|
+
{
|
|
10
|
+
id: 'gst',
|
|
11
|
+
code: 'GST',
|
|
12
|
+
name: 'GST',
|
|
13
|
+
kind: 'taxable',
|
|
14
|
+
components: [{ taxComponentId: 'gst', percent: '5', compound: false }],
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: 'gst-pst',
|
|
18
|
+
code: 'GST+PST',
|
|
19
|
+
name: 'GST+PST',
|
|
20
|
+
componentNames: { gst: 'GST', pst: 'PST' },
|
|
21
|
+
kind: 'taxable',
|
|
22
|
+
components: [
|
|
23
|
+
{ taxComponentId: 'gst', percent: '5', compound: false },
|
|
24
|
+
{ taxComponentId: 'pst', percent: '7', compound: false },
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: 'exempt',
|
|
29
|
+
code: 'Exempt',
|
|
30
|
+
name: 'Exempt',
|
|
31
|
+
kind: 'exempt',
|
|
32
|
+
components: [],
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
const draft: MoneyEditorProps['draft'] = {
|
|
18
36
|
currency: 'CAD',
|
|
19
|
-
|
|
20
|
-
|
|
37
|
+
lineAmountType: 'exclusive',
|
|
38
|
+
roundingScope: 'line',
|
|
21
39
|
lines: [
|
|
22
40
|
{
|
|
23
|
-
|
|
41
|
+
id: 'consulting',
|
|
24
42
|
description: 'Consulting services',
|
|
25
|
-
sku: 'SERVICE',
|
|
26
43
|
quantity: '1.5',
|
|
27
44
|
unitPrice: '100.00',
|
|
28
45
|
discountType: 'percent',
|
|
29
46
|
discountValue: '10',
|
|
30
47
|
taxMode: 'inherit',
|
|
31
|
-
|
|
48
|
+
inheritedTaxCodeId: 'gst',
|
|
49
|
+
inheritedTaxCodeSource: 'product',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: 'stand',
|
|
53
|
+
description: 'Laptop stand',
|
|
54
|
+
quantity: '1',
|
|
55
|
+
unitPrice: '49.99',
|
|
56
|
+
discountType: 'none',
|
|
57
|
+
discountValue: '0',
|
|
58
|
+
taxMode: 'inherit',
|
|
59
|
+
inheritedTaxCodeId: 'gst-pst',
|
|
60
|
+
inheritedTaxCodeSource: 'app',
|
|
32
61
|
},
|
|
33
62
|
],
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
63
|
+
};
|
|
64
|
+
// The stored snapshot is what the server froze at issue; the editor never recomputes it.
|
|
65
|
+
const stored: MoneyEditorProps['stored'] = {
|
|
66
|
+
lineAmountType: 'exclusive',
|
|
67
|
+
roundingScope: 'line',
|
|
68
|
+
subtotalMinor: 18499,
|
|
69
|
+
discountTotalMinor: 1500,
|
|
70
|
+
taxMinor: 1275,
|
|
71
|
+
totalMinor: 19774,
|
|
72
|
+
taxes: [
|
|
73
|
+
{
|
|
74
|
+
id: 'gst',
|
|
75
|
+
taxComponentId: 'gst',
|
|
76
|
+
name: 'GST',
|
|
77
|
+
percent: '5',
|
|
78
|
+
taxableMinor: 18499,
|
|
79
|
+
taxMinor: 925,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
id: 'pst',
|
|
83
|
+
taxComponentId: 'pst',
|
|
84
|
+
name: 'PST',
|
|
85
|
+
percent: '7',
|
|
86
|
+
taxableMinor: 4999,
|
|
87
|
+
taxMinor: 350,
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
};
|
|
91
|
+
const money = $derived<MoneyEditorProps>(
|
|
92
|
+
frozen
|
|
93
|
+
? { mode: 'v2', draft, taxCodes, frozen: true, status: 'SENT', stored }
|
|
94
|
+
: { mode: 'v2', draft, taxCodes },
|
|
95
|
+
);
|
|
96
|
+
function submit(event: SubmitEvent) {
|
|
43
97
|
event.preventDefault();
|
|
44
|
-
const data = new FormData(event.currentTarget, event.submitter);
|
|
45
|
-
const text = (name: string) => String(data.get(name) ?? '');
|
|
46
|
-
values = {
|
|
47
|
-
...values,
|
|
48
|
-
...Object.fromEntries(
|
|
49
|
-
Object.entries(invoiceFieldNames)
|
|
50
|
-
.filter(([key]) => key !== 'intent')
|
|
51
|
-
.map(([key, name]) => [key, text(name)]),
|
|
52
|
-
),
|
|
53
|
-
lines: data
|
|
54
|
-
.getAll('lineKey')
|
|
55
|
-
.map(
|
|
56
|
-
(_, index) =>
|
|
57
|
-
Object.fromEntries(
|
|
58
|
-
Object.entries(invoiceLineFieldNames).map(([key, name]) => [
|
|
59
|
-
key,
|
|
60
|
-
String(data.getAll(name)[index] ?? ''),
|
|
61
|
-
]),
|
|
62
|
-
) as unknown as InvoiceDraftValues['lines'][number],
|
|
63
|
-
),
|
|
64
|
-
};
|
|
65
|
-
allocations = data.getAll('sourceId').map((sourceId, index) => ({
|
|
66
|
-
key: allocations[index]?.key ?? `allocation-${sequence++}`,
|
|
67
|
-
sourceId: String(sourceId),
|
|
68
|
-
amount: String(data.getAll('allocationAmount')[index] ?? ''),
|
|
69
|
-
remove: data.getAll('removeRow').includes(String(index)),
|
|
70
|
-
}));
|
|
71
|
-
const intent = text('intent');
|
|
72
|
-
if (intent === 'addLine')
|
|
73
|
-
values = {
|
|
74
|
-
...values,
|
|
75
|
-
lines: [
|
|
76
|
-
...values.lines,
|
|
77
|
-
{
|
|
78
|
-
key: `line-${sequence++}`,
|
|
79
|
-
description: '',
|
|
80
|
-
sku: '',
|
|
81
|
-
quantity: '1',
|
|
82
|
-
unitPrice: '',
|
|
83
|
-
discountType: 'flat',
|
|
84
|
-
discountValue: '0',
|
|
85
|
-
taxMode: 'inherit',
|
|
86
|
-
taxRate: '0',
|
|
87
|
-
},
|
|
88
|
-
],
|
|
89
|
-
};
|
|
90
|
-
else if (intent.startsWith('removeLine:'))
|
|
91
|
-
values = {
|
|
92
|
-
...values,
|
|
93
|
-
lines: values.lines.filter(
|
|
94
|
-
(line) => line.key !== intent.slice('removeLine:'.length),
|
|
95
|
-
),
|
|
96
|
-
};
|
|
97
|
-
else if (intent === 'addAllocation')
|
|
98
|
-
allocations = [
|
|
99
|
-
...allocations,
|
|
100
|
-
{ key: `allocation-${sequence++}`, sourceId: '', amount: '' },
|
|
101
|
-
];
|
|
102
|
-
else
|
|
103
|
-
message =
|
|
104
|
-
'Example server rejection: entries and request token retained. The server revalidates customer, prices and tax before saving.';
|
|
105
98
|
}
|
|
106
99
|
</script>
|
|
107
100
|
<div class="preview">
|
|
108
|
-
<Checkbox label="May read allocation sources" bind:checked={mayReadSources} />
|
|
109
101
|
<Checkbox label="May edit invoice" bind:checked={canEdit} />
|
|
110
|
-
<
|
|
111
|
-
|
|
112
|
-
<
|
|
113
|
-
|
|
114
|
-
</InvoiceEditor>
|
|
102
|
+
<Checkbox label="Issued (frozen snapshot)" bind:checked={frozen} />
|
|
103
|
+
{#key frozen}
|
|
104
|
+
<InvoiceEditor action="" {money} {canEdit} hiddenFields={[{ name: 'requestId', value: 'demo-request-retained' }]} onsubmit={submit} />
|
|
105
|
+
{/key}
|
|
115
106
|
</div>
|
|
116
107
|
<style>
|
|
117
108
|
@layer smrt.reset, smrt.structure, smrt.theme;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InvoicePreparationPreview.svelte.d.ts","sourceRoot":"","sources":["../../../src/svelte/playground/InvoicePreparationPreview.svelte.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"InvoicePreparationPreview.svelte.d.ts","sourceRoot":"","sources":["../../../src/svelte/playground/InvoicePreparationPreview.svelte.ts"],"names":[],"mappings":"AAqHA,QAAA,MAAM,yBAAyB,2DAAwC,CAAC;AACxE,KAAK,yBAAyB,GAAG,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAC9E,eAAe,yBAAyB,CAAC"}
|
|
@@ -275,7 +275,7 @@ export default {
|
|
|
275
275
|
{
|
|
276
276
|
id: 'invoice-preparation',
|
|
277
277
|
title: 'Invoice Preparation',
|
|
278
|
-
description: 'Edit invoice lines, prices
|
|
278
|
+
description: 'Edit invoice lines, prices and discounts with tax codes; issued invoices show their frozen stored totals.',
|
|
279
279
|
loadComponent: () => import('./playground/InvoicePreparationPreview.svelte'),
|
|
280
280
|
order: 7,
|
|
281
281
|
props: {},
|
package/dist/tax/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { applyCommerceCookbookSettings, applyCookbookTaxSettings, type CookbookTaxSettingsInput, cookbookTaxSettings, } from './cookbook.js';
|
|
2
2
|
export { applyTaxCodeExamplePack, COMMON_TAX_CODE_EXAMPLE_PACK, type TaxCodeExamplePack, } from './example-pack.js';
|
|
3
|
-
export { ensureTenantTaxCodes,
|
|
3
|
+
export { ensureTenantTaxCodes, STANDARD_TAX_CODES, } from './standard-codes.js';
|
|
4
|
+
export { type CommerceTenantBootstrap, type EnsureCommerceTenantOptions, ensureCommerceTenant, } from './tenant-bootstrap.js';
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/tax/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tax/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,wBAAwB,EACxB,KAAK,wBAAwB,EAC7B,mBAAmB,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,uBAAuB,EACvB,4BAA4B,EAC5B,KAAK,kBAAkB,GACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,oBAAoB,EACpB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tax/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,wBAAwB,EACxB,KAAK,wBAAwB,EAC7B,mBAAmB,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,uBAAuB,EACvB,4BAA4B,EAC5B,KAAK,kBAAkB,GACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,EAChC,oBAAoB,GACrB,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DatabaseInterface } from '@happyvertical/smrt-core/migrations';
|
|
2
|
+
import type { TaxCode } from '../models/TaxCode.js';
|
|
3
|
+
/** The non-taxable codes every tenant needs, by stable code. */
|
|
4
|
+
export declare const STANDARD_TAX_CODES: readonly [readonly ["exempt", "Exempt", "exempt"], readonly ["zero-rated", "Zero rated", "zero-rated"], readonly ["out-of-scope", "Out of scope", "out-of-scope"]];
|
|
5
|
+
/**
|
|
6
|
+
* Ensure the three non-taxable codes every tenant needs. Repeating the call is
|
|
7
|
+
* safe; callers must use a transaction-capable database so the check/create
|
|
8
|
+
* sequence is atomic with their surrounding work. An existing standard code
|
|
9
|
+
* whose kind or components were changed is refused, never adopted.
|
|
10
|
+
*/
|
|
11
|
+
export declare function ensureTenantTaxCodes(db: DatabaseInterface, tenantId: string): Promise<TaxCode[]>;
|
|
12
|
+
//# sourceMappingURL=standard-codes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standard-codes.d.ts","sourceRoot":"","sources":["../../src/tax/standard-codes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAG7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAGpD,gEAAgE;AAChE,eAAO,MAAM,kBAAkB,oKAIrB,CAAC;AAEX;;;;;GAKG;AACH,wBAAsB,oBAAoB,CACxC,EAAE,EAAE,iBAAiB,EACrB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,OAAO,EAAE,CAAC,CA0BpB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { DatabaseInterface } from '@happyvertical/smrt-core/migrations';
|
|
2
|
+
import type { Cookbook } from '@happyvertical/smrt-types';
|
|
3
|
+
export interface EnsureCommerceTenantOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The application's validated cookbook. Its commerce policy rows set the
|
|
6
|
+
* tenant's default tax code, `pricesIncludeTax` and `taxRounding` through
|
|
7
|
+
* {@link applyCommerceCookbookSettings}. Omit it to seed only the standard
|
|
8
|
+
* exempt, zero-rated and out-of-scope codes.
|
|
9
|
+
*/
|
|
10
|
+
readonly cookbook?: Pick<Cookbook, 'policies'>;
|
|
11
|
+
}
|
|
12
|
+
export interface CommerceTenantBootstrap {
|
|
13
|
+
readonly tenantId: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The one commerce call a host makes after it creates a tenant (#4009).
|
|
17
|
+
*
|
|
18
|
+
* Seeds the tenant's standard tax codes and its tax settings row, then applies
|
|
19
|
+
* the cookbook's commerce tax settings when one is given. Every step is
|
|
20
|
+
* idempotent, so a retry after a partial failure converges; re-running with a
|
|
21
|
+
* cookbook re-applies its defaults over the tenant's current default codes,
|
|
22
|
+
* amount type and rounding scope. A tenant holding money data from an earlier
|
|
23
|
+
* version is refused with `COMMERCE_DATA_NEEDS_UPGRADE`.
|
|
24
|
+
*
|
|
25
|
+
* Requires installed commerce schema and a database with transactions. The
|
|
26
|
+
* caller owns authority for `tenantId`; this function never derives it.
|
|
27
|
+
*/
|
|
28
|
+
export declare function ensureCommerceTenant(db: DatabaseInterface, tenantId: string, options?: EnsureCommerceTenantOptions): Promise<CommerceTenantBootstrap>;
|
|
29
|
+
//# sourceMappingURL=tenant-bootstrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-bootstrap.d.ts","sourceRoot":"","sources":["../../src/tax/tenant-bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAE7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAK1D,MAAM,WAAW,2BAA2B;IAC1C;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;CAChD;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,oBAAoB,CACxC,EAAE,EAAE,iBAAiB,EACrB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,uBAAuB,CAAC,CAclC"}
|
|
@@ -1,66 +1,34 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Tenant serialization point for commerce money runtime work. */
|
|
2
2
|
import type { DatabaseInterface } from '@happyvertical/smrt-core/migrations';
|
|
3
3
|
import type { TaxSettings } from './models/TaxSettings.js';
|
|
4
|
-
export type TenantMoneyRuntimeRequirement = 'legacy-or-v2' | 'v2';
|
|
5
|
-
export type TenantMoneyRuntimeBarrier = {
|
|
6
|
-
readonly moneyModel: 'legacy';
|
|
7
|
-
readonly settings: null;
|
|
8
|
-
readonly persistedBarrier: false;
|
|
9
|
-
} | {
|
|
10
|
-
readonly moneyModel: 'legacy';
|
|
11
|
-
readonly settings: TaxSettings;
|
|
12
|
-
readonly persistedBarrier: true;
|
|
13
|
-
} | {
|
|
14
|
-
readonly moneyModel: 'v2';
|
|
15
|
-
readonly settings: TaxSettings;
|
|
16
|
-
readonly persistedBarrier: true;
|
|
17
|
-
};
|
|
18
4
|
declare const tenantMoneyScopeBrand: unique symbol;
|
|
19
|
-
/** Transaction-affine proof that a tenant
|
|
5
|
+
/** Transaction-affine proof that a tenant's settings row is locked on `db`. */
|
|
20
6
|
export interface TenantMoneyRuntimeScope {
|
|
21
7
|
readonly db: DatabaseInterface;
|
|
22
8
|
readonly tenantId: string;
|
|
23
|
-
readonly
|
|
9
|
+
readonly settings: TaxSettings;
|
|
24
10
|
readonly phase: 'runtime';
|
|
25
11
|
readonly [tenantMoneyScopeBrand]: true;
|
|
26
12
|
}
|
|
27
|
-
declare const tenantMoneyMigrationScopeBrand: unique symbol;
|
|
28
|
-
/** Transaction-affine proof held only by the active migration owner. */
|
|
29
|
-
export interface TenantMoneyMigrationScope {
|
|
30
|
-
readonly db: DatabaseInterface;
|
|
31
|
-
readonly tenantId: string;
|
|
32
|
-
readonly migrationId: string;
|
|
33
|
-
readonly settings: TaxSettings;
|
|
34
|
-
readonly phase: 'migration';
|
|
35
|
-
readonly [tenantMoneyMigrationScopeBrand]: true;
|
|
36
|
-
}
|
|
37
13
|
/**
|
|
38
|
-
* Lock and re-read the tenant
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* modified. Once the table exists, a missing deterministic legacy row is
|
|
42
|
-
* materialized solely to provide the serialization point shared by migration.
|
|
14
|
+
* Lock and re-read the tenant's tax settings row before runtime money work,
|
|
15
|
+
* creating it once when missing. Old-format money data is refused first with
|
|
16
|
+
* `COMMERCE_DATA_NEEDS_UPGRADE`.
|
|
43
17
|
*/
|
|
44
|
-
export declare function lockTenantMoneyRuntime(tx: DatabaseInterface, tenantId: string
|
|
18
|
+
export declare function lockTenantMoneyRuntime(tx: DatabaseInterface, tenantId: string): Promise<TaxSettings>;
|
|
45
19
|
/**
|
|
46
|
-
* Run tenant money work under the
|
|
20
|
+
* Run tenant money work under the tenant settings lock on exactly one
|
|
21
|
+
* executor.
|
|
47
22
|
*
|
|
48
23
|
* Supplying an existing scope proves re-entry on the same executor. Calls made
|
|
49
24
|
* through the owning transaction wrapper also reuse its exact registered
|
|
50
25
|
* executor. No optional adapter-property heuristic can grant this capability.
|
|
51
26
|
*/
|
|
52
|
-
export declare function withTenantMoneyRuntime<T>(db: DatabaseInterface, tenantId: string,
|
|
27
|
+
export declare function withTenantMoneyRuntime<T>(db: DatabaseInterface, tenantId: string, operation: (scope: TenantMoneyRuntimeScope) => Promise<T>, existingScope?: TenantMoneyRuntimeScope): Promise<T>;
|
|
53
28
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* is `migrating`; possession cannot be inferred from adapter shape.
|
|
29
|
+
* @internal Guard a generated money-document collection read: a tenant whose
|
|
30
|
+
* data predates the current money model is refused before any row is read.
|
|
57
31
|
*/
|
|
58
|
-
export declare function withTenantMoneyMigration<T>(db: DatabaseInterface, tenantId: string, migrationId: string, operation: (scope: TenantMoneyMigrationScope) => Promise<T>, existingScope?: TenantMoneyMigrationScope): Promise<T>;
|
|
59
|
-
/** @internal Guard a generated collection read for runtime or migration. */
|
|
60
32
|
export declare function withTenantMoneyCollectionRead<T>(db: DatabaseInterface, tenantId: string, operation: (boundDb: DatabaseInterface) => Promise<T>): Promise<T>;
|
|
61
|
-
/** Lock a tenant at the legacy marker before the caller claims migration. */
|
|
62
|
-
export declare function lockTenantMoneyMigrationClaim(tx: DatabaseInterface, tenantId: string): Promise<TaxSettings>;
|
|
63
|
-
/** Lock and verify the exact owner of an active tenant migration. */
|
|
64
|
-
export declare function lockTenantMoneyMigrationOwner(tx: DatabaseInterface, tenantId: string, migrationId: string): Promise<TaxSettings>;
|
|
65
33
|
export {};
|
|
66
34
|
//# sourceMappingURL=tenant-money-barrier.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tenant-money-barrier.d.ts","sourceRoot":"","sources":["../src/tenant-money-barrier.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"tenant-money-barrier.d.ts","sourceRoot":"","sources":["../src/tenant-money-barrier.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAElE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAG7E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAI3D,OAAO,CAAC,MAAM,qBAAqB,EAAE,OAAO,MAAM,CAAC;AAEnD,+EAA+E;AAC/E,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,EAAE,EAAE,iBAAiB,CAAC;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,CAAC,qBAAqB,CAAC,EAAE,IAAI,CAAC;CACxC;AAgBD;;;;GAIG;AACH,wBAAsB,sBAAsB,CAC1C,EAAE,EAAE,iBAAiB,EACrB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,WAAW,CAAC,CAMtB;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAAC,CAAC,EAC5C,EAAE,EAAE,iBAAiB,EACrB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,OAAO,CAAC,CAAC,CAAC,EACzD,aAAa,CAAC,EAAE,uBAAuB,GACtC,OAAO,CAAC,CAAC,CAAC,CAkCZ;AAED;;;GAGG;AACH,wBAAsB,6BAA6B,CAAC,CAAC,EACnD,EAAE,EAAE,iBAAiB,EACrB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,OAAO,CAAC,CAAC,CAAC,GACpD,OAAO,CAAC,CAAC,CAAC,CAGZ"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* @packageDocumentation
|
|
4
4
|
*/
|
|
5
5
|
import type { SmrtObjectOptions } from '@happyvertical/smrt-core';
|
|
6
|
-
import type { InvoiceCalculationContext, InvoiceLineDraft } from '../svelte/invoices/calculations.js';
|
|
7
6
|
export declare enum CustomerStatus {
|
|
8
7
|
ACTIVE = "active",
|
|
9
8
|
INACTIVE = "inactive",
|
|
@@ -255,17 +254,20 @@ export interface RecordPaymentOptions {
|
|
|
255
254
|
export interface RecognizeRevenueOptions {
|
|
256
255
|
/** Account ID for accounts receivable (debit side) */
|
|
257
256
|
arAccountId: string;
|
|
258
|
-
/**
|
|
257
|
+
/** Revenue account for lines that do not name their own (credit side). */
|
|
259
258
|
revenueAccountId: string;
|
|
260
|
-
/**
|
|
259
|
+
/**
|
|
260
|
+
* Tax payable account for tax components without a liability account and
|
|
261
|
+
* for provider tax (credit side).
|
|
262
|
+
*/
|
|
261
263
|
taxAccountId?: string;
|
|
262
|
-
/**
|
|
263
|
-
bookCurrency
|
|
264
|
+
/** ISO 4217 ledger book currency; must equal the invoice currency. */
|
|
265
|
+
bookCurrency: string;
|
|
264
266
|
}
|
|
265
|
-
/** Options for atomically cancelling a posted
|
|
267
|
+
/** Options for atomically cancelling a posted invoice. */
|
|
266
268
|
export interface CancelRevenueOptions {
|
|
267
|
-
/**
|
|
268
|
-
bookCurrency
|
|
269
|
+
/** ISO 4217 ledger book currency; must equal the invoice currency. */
|
|
270
|
+
bookCurrency: string;
|
|
269
271
|
}
|
|
270
272
|
/**
|
|
271
273
|
* A single line item in the format expected by `@happyvertical/accounting`
|
|
@@ -386,8 +388,6 @@ export interface TaxSettingsOptions extends SmrtObjectOptions {
|
|
|
386
388
|
defaultLineAmountType?: 'exclusive' | 'inclusive' | 'none';
|
|
387
389
|
taxRoundingScope?: 'line' | 'document';
|
|
388
390
|
taxRegistrations?: TaxRegistrationOptions[];
|
|
389
|
-
moneyModel?: 'legacy' | 'migrating' | 'v2';
|
|
390
|
-
moneyMigrationId?: string;
|
|
391
391
|
}
|
|
392
392
|
/**
|
|
393
393
|
* Constructor options for {@link Contract} and its STI subtypes.
|
|
@@ -469,7 +469,6 @@ export interface ContractLineItemOptions extends SmrtObjectOptions {
|
|
|
469
469
|
taxComponents?: ContractTaxComponentSnapshot[];
|
|
470
470
|
taxComponentsJson?: string | null;
|
|
471
471
|
taxAmount?: number;
|
|
472
|
-
legacyAmount?: number | null;
|
|
473
472
|
moneySnapshotId?: string;
|
|
474
473
|
amount?: number;
|
|
475
474
|
productId?: string;
|
|
@@ -563,22 +562,11 @@ export interface InvoiceTaxComponentSnapshot {
|
|
|
563
562
|
percent: string;
|
|
564
563
|
taxMinor: number;
|
|
565
564
|
}
|
|
566
|
-
/** Retained editing modes, validated against resolved model fields before reuse. */
|
|
567
|
-
export interface InvoiceLineEditorState {
|
|
568
|
-
/** Lossless editor draft; never authoritative for ordinary model saves. */
|
|
569
|
-
draft: InvoiceLineDraft;
|
|
570
|
-
/** Context used to resolve that draft; caller authority must still match on reload. */
|
|
571
|
-
context: InvoiceCalculationContext;
|
|
572
|
-
}
|
|
573
565
|
/** Constructor options for {@link InvoiceLineItem}. */
|
|
574
566
|
export interface InvoiceLineItemOptions extends SmrtObjectOptions {
|
|
575
567
|
creditedLineId?: string | null;
|
|
576
568
|
creditCalculationBasis?: InvoiceCreditCalculationBasis | null;
|
|
577
569
|
creditCalculationBasisJson?: string;
|
|
578
|
-
/** Optional retained editor modes and their original calculation context. */
|
|
579
|
-
invoiceEditorState?: InvoiceLineEditorState | null;
|
|
580
|
-
/** Serialized editor state loaded from persistence; malformed JSON is ignored. */
|
|
581
|
-
invoiceEditorStateJson?: string;
|
|
582
570
|
tenantId?: string | null;
|
|
583
571
|
invoiceId?: string;
|
|
584
572
|
description?: string;
|
|
@@ -597,7 +585,6 @@ export interface InvoiceLineItemOptions extends SmrtObjectOptions {
|
|
|
597
585
|
taxComponents?: InvoiceTaxComponentSnapshot[];
|
|
598
586
|
taxComponentsJson?: string | null;
|
|
599
587
|
taxAmount?: number;
|
|
600
|
-
legacyAmount?: number | null;
|
|
601
588
|
moneySnapshotId?: string;
|
|
602
589
|
amount?: number;
|
|
603
590
|
sourceType?: string;
|