@happyvertical/smrt-commerce 0.55.24 → 0.56.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 +11 -9
- package/README.md +114 -2
- package/agents/accounting-snapshot-mapper.md +111 -0
- package/agents/contract-money.md +18 -0
- package/agents/cost-billing.md +7 -2
- package/agents/document-money.md +126 -0
- package/agents/invoice-calculations.md +14 -2
- package/agents/line-amount-migration.md +50 -0
- package/agents/minor-unit-migration.md +20 -0
- package/agents/money-calculator.md +45 -0
- package/agents/money-model.md +113 -0
- package/agents/purchasing-ui.md +4 -3
- package/agents/quote-ui.md +3 -2
- package/agents/revenue-journal.md +23 -0
- package/agents/tax-codes.md +48 -0
- package/agents/tax-summary.md +126 -0
- package/dist/accounting-snapshot.d.ts +79 -0
- package/dist/accounting-snapshot.d.ts.map +1 -0
- package/dist/billing/runtime.d.ts +2 -0
- package/dist/billing/runtime.d.ts.map +1 -1
- package/dist/chunks/ContractLineItemCollection-DYjhj_pU.js +265 -0
- package/dist/chunks/ContractLineItemCollection-DYjhj_pU.js.map +1 -0
- package/dist/chunks/CustomerCollection-DQIujn4f.js +99 -0
- package/dist/chunks/CustomerCollection-DQIujn4f.js.map +1 -0
- package/dist/chunks/DocumentTaxCollection-BEpoqXAQ.js +1639 -0
- package/dist/chunks/DocumentTaxCollection-BEpoqXAQ.js.map +1 -0
- package/dist/chunks/InvoiceCollection-CKQflFjc.js +1047 -0
- package/dist/chunks/InvoiceCollection-CKQflFjc.js.map +1 -0
- package/dist/chunks/InvoiceLineItemCollection-CHm9zdqh.js +467 -0
- package/dist/chunks/InvoiceLineItemCollection-CHm9zdqh.js.map +1 -0
- package/dist/chunks/TaxCodeCollection-DOpzW4y8.js +149 -0
- package/dist/chunks/TaxCodeCollection-DOpzW4y8.js.map +1 -0
- package/dist/chunks/TaxComponentCollection-Cs2uXwEl.js +129 -0
- package/dist/chunks/TaxComponentCollection-Cs2uXwEl.js.map +1 -0
- package/dist/chunks/TaxSettingsCollection-BBTZDH1S.js +319 -0
- package/dist/chunks/TaxSettingsCollection-BBTZDH1S.js.map +1 -0
- package/dist/chunks/{money-DfrRxrel.js → allocation-integrity-DI3G16BN.js} +7 -12
- package/dist/chunks/allocation-integrity-DI3G16BN.js.map +1 -0
- package/dist/chunks/{calculations-Bz7RB3qK.js → calculations-DaHR17il.js} +134 -54
- package/dist/chunks/calculations-DaHR17il.js.map +1 -0
- package/dist/chunks/credit-allocation-yspz0Lab.js +121 -0
- package/dist/chunks/credit-allocation-yspz0Lab.js.map +1 -0
- package/dist/chunks/document-money-DNVhDJyC.js +860 -0
- package/dist/chunks/document-money-DNVhDJyC.js.map +1 -0
- package/dist/chunks/invoice-posting-BwV8g7z0.js +229 -0
- package/dist/chunks/invoice-posting-BwV8g7z0.js.map +1 -0
- package/dist/chunks/money-rational-CcW7gzG5.js +64 -0
- package/dist/chunks/money-rational-CcW7gzG5.js.map +1 -0
- package/dist/chunks/revenue-journal-DY9fro8E.js +140 -0
- package/dist/chunks/revenue-journal-DY9fro8E.js.map +1 -0
- package/dist/chunks/rolldown-runtime-D7D4PA-g.js +13 -0
- package/dist/chunks/tenant-money-barrier-DjRXgMnX.js +135 -0
- package/dist/chunks/tenant-money-barrier-DjRXgMnX.js.map +1 -0
- package/dist/chunks/{types-zVnIjSOk.js → types-LDETvQ1C.js} +3 -14
- package/dist/chunks/types-LDETvQ1C.js.map +1 -0
- package/dist/chunks/{units-BpZ0_Dpk.js → units-CNcjH_eE.js} +2 -2
- package/dist/chunks/{units-BpZ0_Dpk.js.map → units-CNcjH_eE.js.map} +1 -1
- package/dist/collections/ContractCollection.d.ts +37 -1
- package/dist/collections/ContractCollection.d.ts.map +1 -1
- package/dist/collections/ContractLineItemCollection.d.ts +26 -1
- package/dist/collections/ContractLineItemCollection.d.ts.map +1 -1
- package/dist/collections/DocumentTaxCollection.d.ts +75 -0
- package/dist/collections/DocumentTaxCollection.d.ts.map +1 -0
- package/dist/collections/InvoiceCollection.d.ts +26 -1
- package/dist/collections/InvoiceCollection.d.ts.map +1 -1
- package/dist/collections/InvoiceLineItemCollection.d.ts +26 -1
- package/dist/collections/InvoiceLineItemCollection.d.ts.map +1 -1
- package/dist/collections/MoneyMigrationDocumentCollection.d.ts +12 -0
- package/dist/collections/MoneyMigrationDocumentCollection.d.ts.map +1 -0
- package/dist/collections/PaymentAllocationCollection.d.ts +2 -0
- package/dist/collections/PaymentAllocationCollection.d.ts.map +1 -1
- package/dist/collections/PurchaseContractCollection.d.ts +8 -0
- package/dist/collections/PurchaseContractCollection.d.ts.map +1 -0
- package/dist/collections/SalesContractCollection.d.ts +8 -0
- package/dist/collections/SalesContractCollection.d.ts.map +1 -0
- package/dist/collections/TaxCodeCollection.d.ts +7 -0
- package/dist/collections/TaxCodeCollection.d.ts.map +1 -0
- package/dist/collections/TaxComponentCollection.d.ts +6 -0
- package/dist/collections/TaxComponentCollection.d.ts.map +1 -0
- package/dist/collections/TaxSettingsCollection.d.ts +16 -0
- package/dist/collections/TaxSettingsCollection.d.ts.map +1 -0
- package/dist/collections/TaxSummaryReportCollection.d.ts +151 -0
- package/dist/collections/TaxSummaryReportCollection.d.ts.map +1 -0
- package/dist/collections/index.d.ts +8 -0
- package/dist/collections/index.d.ts.map +1 -1
- package/dist/commerce-money-tools.d.ts +9 -0
- package/dist/commerce-money-tools.d.ts.map +1 -0
- package/dist/contract-money.d.ts +27 -0
- package/dist/contract-money.d.ts.map +1 -0
- package/dist/cost-billing.d.ts +0 -1
- package/dist/cost-billing.d.ts.map +1 -1
- package/dist/cost-billing.js +10 -15
- package/dist/cost-billing.js.map +1 -1
- package/dist/credit-allocation.d.ts +48 -0
- package/dist/credit-allocation.d.ts.map +1 -0
- package/dist/document-money-internal.d.ts +44 -0
- package/dist/document-money-internal.d.ts.map +1 -0
- package/dist/document-money.d.ts +85 -0
- package/dist/document-money.d.ts.map +1 -0
- package/dist/index.d.ts +16 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5563 -4243
- package/dist/index.js.map +1 -1
- package/dist/invoice-accounting-sync.d.ts +96 -0
- package/dist/invoice-accounting-sync.d.ts.map +1 -0
- package/dist/invoice-mcp.d.ts +16 -0
- package/dist/invoice-mcp.d.ts.map +1 -0
- package/dist/invoice-posting.d.ts +9 -0
- package/dist/invoice-posting.d.ts.map +1 -0
- package/dist/invoice-record-screen.d.ts +60 -0
- package/dist/invoice-record-screen.d.ts.map +1 -0
- package/dist/invoices.d.ts +2 -0
- package/dist/invoices.d.ts.map +1 -1
- package/dist/invoices.js +3 -2
- package/dist/manifest.json +11605 -4598
- package/dist/migrations/commerceLineAmounts.d.ts +84 -0
- package/dist/migrations/commerceLineAmounts.d.ts.map +1 -0
- package/dist/migrations/partyLinks.d.ts +39 -0
- package/dist/migrations/partyLinks.d.ts.map +1 -0
- package/dist/models/Contract.d.ts +61 -27
- package/dist/models/Contract.d.ts.map +1 -1
- package/dist/models/ContractLineItem.d.ts +30 -1
- package/dist/models/ContractLineItem.d.ts.map +1 -1
- package/dist/models/Customer.d.ts +7 -0
- package/dist/models/Customer.d.ts.map +1 -1
- package/dist/models/DocumentTax.d.ts +50 -0
- package/dist/models/DocumentTax.d.ts.map +1 -0
- package/dist/models/Invoice.d.ts +46 -2
- package/dist/models/Invoice.d.ts.map +1 -1
- package/dist/models/InvoiceLineItem.d.ts +33 -2
- package/dist/models/InvoiceLineItem.d.ts.map +1 -1
- package/dist/models/MoneyMigrationDocument.d.ts +28 -0
- package/dist/models/MoneyMigrationDocument.d.ts.map +1 -0
- package/dist/models/Payment.d.ts +5 -1
- package/dist/models/Payment.d.ts.map +1 -1
- package/dist/models/PaymentAllocation.d.ts.map +1 -1
- package/dist/models/TaxCode.d.ts +22 -0
- package/dist/models/TaxCode.d.ts.map +1 -0
- package/dist/models/TaxComponent.d.ts +21 -0
- package/dist/models/TaxComponent.d.ts.map +1 -0
- package/dist/models/TaxSettings.d.ts +33 -0
- package/dist/models/TaxSettings.d.ts.map +1 -0
- package/dist/models/TaxSummaryReport.d.ts +35 -0
- package/dist/models/TaxSummaryReport.d.ts.map +1 -0
- package/dist/models/Vendor.d.ts +9 -0
- package/dist/models/Vendor.d.ts.map +1 -1
- package/dist/models/index.d.ts +7 -1
- package/dist/models/index.d.ts.map +1 -1
- package/dist/money-rational.d.ts +15 -0
- package/dist/money-rational.d.ts.map +1 -0
- package/dist/money.d.ts +106 -25
- package/dist/money.d.ts.map +1 -1
- package/dist/money.js +274 -0
- package/dist/money.js.map +1 -0
- package/dist/recipes.d.ts +17 -47
- package/dist/recipes.d.ts.map +1 -1
- package/dist/revenue-journal.d.ts +61 -0
- package/dist/revenue-journal.d.ts.map +1 -0
- package/dist/smrt-knowledge.json +6558 -1316
- package/dist/svelte/components/InvoiceActions.svelte +12 -0
- package/dist/svelte/components/InvoiceActions.svelte.d.ts +5 -0
- package/dist/svelte/components/InvoiceActions.svelte.d.ts.map +1 -1
- package/dist/svelte/components/InvoiceEditor.svelte +15 -1
- package/dist/svelte/components/InvoiceEditor.svelte.d.ts.map +1 -1
- package/dist/svelte/components/InvoiceLineItems.svelte +3 -3
- package/dist/svelte/components/InvoiceRecordScreen.svelte +94 -0
- package/dist/svelte/components/InvoiceRecordScreen.svelte.d.ts +21 -0
- package/dist/svelte/components/InvoiceRecordScreen.svelte.d.ts.map +1 -0
- package/dist/svelte/components/InvoiceTotals.svelte +2 -2
- package/dist/svelte/components/MoneyInvoiceEditor.svelte +282 -0
- package/dist/svelte/components/MoneyInvoiceEditor.svelte.d.ts +31 -0
- package/dist/svelte/components/MoneyInvoiceEditor.svelte.d.ts.map +1 -0
- package/dist/svelte/components/PurchaseOrderEditor.svelte +53 -1
- package/dist/svelte/components/PurchaseOrderEditor.svelte.d.ts +5 -0
- package/dist/svelte/components/PurchaseOrderEditor.svelte.d.ts.map +1 -1
- package/dist/svelte/components/QuoteEditor.svelte +54 -1
- package/dist/svelte/components/QuoteEditor.svelte.d.ts +5 -0
- package/dist/svelte/components/QuoteEditor.svelte.d.ts.map +1 -1
- package/dist/svelte/i18n.d.ts +16 -0
- package/dist/svelte/i18n.d.ts.map +1 -1
- package/dist/svelte/i18n.js +16 -0
- package/dist/svelte/index.d.ts +7 -2
- package/dist/svelte/index.d.ts.map +1 -1
- package/dist/svelte/index.js +4 -1
- package/dist/svelte/invoices/calculations.d.ts +7 -2
- package/dist/svelte/invoices/calculations.d.ts.map +1 -1
- package/dist/svelte/invoices/calculations.js +141 -47
- package/dist/svelte/invoices/money-editor.d.ts +123 -0
- package/dist/svelte/invoices/money-editor.d.ts.map +1 -0
- package/dist/svelte/invoices/money-editor.js +101 -0
- package/dist/svelte/invoices/types.d.ts +5 -1
- package/dist/svelte/invoices/types.d.ts.map +1 -1
- package/dist/svelte/purchasing-i18n.d.ts +5 -0
- package/dist/svelte/purchasing-i18n.d.ts.map +1 -1
- package/dist/svelte/purchasing-i18n.js +5 -0
- package/dist/svelte/quote-i18n.d.ts +5 -0
- package/dist/svelte/quote-i18n.d.ts.map +1 -1
- package/dist/svelte/quote-i18n.js +5 -0
- package/dist/tax/cookbook.d.ts +22 -0
- package/dist/tax/cookbook.d.ts.map +1 -0
- package/dist/tax/example-pack.d.ts +25 -0
- package/dist/tax/example-pack.d.ts.map +1 -0
- package/dist/tax/identity.d.ts +5 -0
- package/dist/tax/identity.d.ts.map +1 -0
- package/dist/tax/index.d.ts +4 -0
- package/dist/tax/index.d.ts.map +1 -0
- package/dist/tax/legacy.d.ts +48 -0
- package/dist/tax/legacy.d.ts.map +1 -0
- package/dist/tax-summary-report-adapter.d.ts +37 -0
- package/dist/tax-summary-report-adapter.d.ts.map +1 -0
- package/dist/tax-summary.d.ts +129 -0
- package/dist/tax-summary.d.ts.map +1 -0
- package/dist/tenant-money-barrier.d.ts +66 -0
- package/dist/tenant-money-barrier.d.ts.map +1 -0
- package/dist/types/index.d.ts +145 -5
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +19 -11
- package/dist/chunks/calculations-Bz7RB3qK.js.map +0 -1
- package/dist/chunks/money-DfrRxrel.js.map +0 -1
- package/dist/chunks/types-zVnIjSOk.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/tax/identity.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,UAAU,GAAG,QAAQ,EAClD,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,CAAC,CAajB;AAED,gFAAgF;AAChF,wBAAsB,mBAAmB,CAAC,CAAC,EACzC,MAAM,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACxB,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,GACxC,OAAO,CAAC,CAAC,CAAC,CAeZ"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { applyCommerceCookbookSettings, applyCookbookTaxSettings, type CookbookTaxSettingsInput, cookbookTaxSettings, } from './cookbook.js';
|
|
2
|
+
export { applyTaxCodeExamplePack, COMMON_TAX_CODE_EXAMPLE_PACK, type TaxCodeExamplePack, } from './example-pack.js';
|
|
3
|
+
export { ensureTenantTaxCodes, type LegacyTaxMapReport, type LegacyTaxRateRow, type MapLegacyTaxRatesOptions, mapLegacyTaxRates, mapLegacyTaxRatesInTransaction, } from './legacy.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,iBAAiB,EACjB,8BAA8B,GAC/B,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { DatabaseInterface } from '@happyvertical/smrt-core/migrations';
|
|
2
|
+
import type { TaxCode } from '../models/TaxCode.js';
|
|
3
|
+
export interface LegacyTaxMapReport {
|
|
4
|
+
tenantId: string;
|
|
5
|
+
createdComponents: number;
|
|
6
|
+
createdCodes: number;
|
|
7
|
+
missingLiabilityAccountComponentIds: string[];
|
|
8
|
+
/** Every legacy source rate and the durable tax code selected for it. */
|
|
9
|
+
mappings: Array<{
|
|
10
|
+
sourceRate: string;
|
|
11
|
+
taxCodeId: string;
|
|
12
|
+
taxComponentId: string | null;
|
|
13
|
+
}>;
|
|
14
|
+
/** Invalid legacy rates are retained through `legacy-unreconciled`. */
|
|
15
|
+
unreconciledRates: string[];
|
|
16
|
+
}
|
|
17
|
+
export interface MapLegacyTaxRatesOptions {
|
|
18
|
+
/** Limit a resumable migration to one tenant. Omit only for a system admin run. */
|
|
19
|
+
tenantId?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface LegacyTaxRateRow {
|
|
22
|
+
tenantId?: string;
|
|
23
|
+
tenant_id?: string;
|
|
24
|
+
taxRate?: unknown;
|
|
25
|
+
tax_rate?: unknown;
|
|
26
|
+
customerTaxExempt?: unknown;
|
|
27
|
+
customer_tax_exempt?: unknown;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Ensure the three non-taxable codes every tenant needs. Repeating the call is
|
|
31
|
+
* safe; callers must use a transaction-capable database so the check/create
|
|
32
|
+
* sequence is atomic with their surrounding migration.
|
|
33
|
+
*/
|
|
34
|
+
export declare function ensureTenantTaxCodes(db: DatabaseInterface, tenantId: string): Promise<TaxCode[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Map old fractional line tax rates to rate components and one-component tax
|
|
37
|
+
* codes. A historical zero means no tax was applied, therefore it maps to
|
|
38
|
+
* out-of-scope unless the linked customer was explicitly exempt.
|
|
39
|
+
*/
|
|
40
|
+
export declare function mapLegacyTaxRates(db: DatabaseInterface, options?: MapLegacyTaxRatesOptions): Promise<LegacyTaxMapReport[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Executor-affine mapping entry point for a caller that already owns an open
|
|
43
|
+
* transaction. It never opens or commits a nested transaction. `tenantRows`
|
|
44
|
+
* are supplied by the wrapper after its source read so each tenant remains
|
|
45
|
+
* isolated and a failed mapping rolls back as one unit.
|
|
46
|
+
*/
|
|
47
|
+
export declare function mapLegacyTaxRatesInTransaction(tx: DatabaseInterface, tenantId: string, tenantRows: readonly LegacyTaxRateRow[]): Promise<LegacyTaxMapReport>;
|
|
48
|
+
//# sourceMappingURL=legacy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy.d.ts","sourceRoot":"","sources":["../../src/tax/legacy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAI7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAGpD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,mCAAmC,EAAE,MAAM,EAAE,CAAC;IAC9C,yEAAyE;IACzE,QAAQ,EAAE,KAAK,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;KAC/B,CAAC,CAAC;IACH,uEAAuE;IACvE,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,wBAAwB;IACvC,mFAAmF;IACnF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAgCD;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,EAAE,EAAE,iBAAiB,EACrB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,OAAO,EAAE,CAAC,CAsEpB;AAmCD;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,EAAE,EAAE,iBAAiB,EACrB,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAkB/B;AAED;;;;;GAKG;AACH,wBAAsB,8BAA8B,CAClD,EAAE,EAAE,iBAAiB,EACrB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,SAAS,gBAAgB,EAAE,GACtC,OAAO,CAAC,kBAAkB,CAAC,CAyF7B"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Existing report adapter/DataTable bridge for the commerce tax summary. */
|
|
2
|
+
import type { DatabaseInterface } from '@happyvertical/smrt-core/migrations';
|
|
3
|
+
import { type MaterializedReportDrilldownPresentation, type MaterializedReportHost, type MaterializedReportHostContext, type ReportAdapterDescriptor, type ReportAdapterOptions } from '@happyvertical/smrt-reports';
|
|
4
|
+
import { type TaxSummaryContributorDrilldown, type TaxSummaryContributorDrilldownOptions, type TaxSummaryExpenseSource, type TaxSummaryInvoiceDrilldownOptions, type TaxSummaryLedgerDrilldownSource } from './collections/TaxSummaryReportCollection.js';
|
|
5
|
+
import type { TaxSummaryComponentMapping } from './tax-summary.js';
|
|
6
|
+
export declare const TAX_SUMMARY_REPORT_ADAPTER: ReportAdapterOptions;
|
|
7
|
+
/** Tenant-bound owner dependencies used only while resolving a selected cell. */
|
|
8
|
+
export interface TaxSummaryMaterializedReportDrilldownSources {
|
|
9
|
+
expenseSource?: TaxSummaryExpenseSource;
|
|
10
|
+
ledgerSource?: TaxSummaryLedgerDrilldownSource;
|
|
11
|
+
expenseComponentMappings?: readonly TaxSummaryComponentMapping[];
|
|
12
|
+
}
|
|
13
|
+
export interface TaxSummaryMaterializedReportHostOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Resolve owner collections from the authenticated route context for each
|
|
16
|
+
* drilldown. A fixed source is intentionally unsupported so one tenant's
|
|
17
|
+
* collection cannot bleed into another request.
|
|
18
|
+
*/
|
|
19
|
+
drilldownSources?: (context: Readonly<MaterializedReportHostContext>) => TaxSummaryMaterializedReportDrilldownSources | Promise<TaxSummaryMaterializedReportDrilldownSources>;
|
|
20
|
+
}
|
|
21
|
+
/** Normalize commerce source facts before a generic report route serializes them. */
|
|
22
|
+
export declare function presentTaxSummaryDrilldown(drilldown: TaxSummaryContributorDrilldown): MaterializedReportDrilldownPresentation;
|
|
23
|
+
/** Create a fixed, server-only tax-summary host for an authenticated template route. */
|
|
24
|
+
export declare function createTaxSummaryMaterializedReportHost(database: DatabaseInterface | (() => Promise<DatabaseInterface>), options?: TaxSummaryMaterializedReportHostOptions): MaterializedReportHost<MaterializedReportDrilldownPresentation>;
|
|
25
|
+
/** Descriptor consumed by the registered report runtime and DataTable host. */
|
|
26
|
+
export declare function buildTaxSummaryReportAdapterDescriptor(): Promise<ReportAdapterDescriptor>;
|
|
27
|
+
/**
|
|
28
|
+
* Application drilldown bridge. Callers obtain tenantId from their authenticated
|
|
29
|
+
* principal and must not use a tenant value supplied by the report row.
|
|
30
|
+
*/
|
|
31
|
+
export declare function drilldownTaxSummaryInvoiceFacts(db: DatabaseInterface, options: TaxSummaryInvoiceDrilldownOptions): Promise<import("./index.js").DocumentTaxReportFact[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Application bridge for a specific report cell. Expense and ledger owners are
|
|
34
|
+
* injected by the host so commerce does not create a package dependency cycle.
|
|
35
|
+
*/
|
|
36
|
+
export declare function drilldownTaxSummaryContributors(db: DatabaseInterface, options: TaxSummaryContributorDrilldownOptions): Promise<TaxSummaryContributorDrilldown>;
|
|
37
|
+
//# sourceMappingURL=tax-summary-report-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tax-summary-report-adapter.d.ts","sourceRoot":"","sources":["../src/tax-summary-report-adapter.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAE7E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAIL,KAAK,uCAAuC,EAE5C,KAAK,sBAAsB,EAC3B,KAAK,6BAA6B,EAElC,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EAC1B,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,KAAK,8BAA8B,EACnC,KAAK,qCAAqC,EAC1C,KAAK,uBAAuB,EAC5B,KAAK,iCAAiC,EACtC,KAAK,+BAA+B,EAGrC,MAAM,6CAA6C,CAAC;AAErD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAEnE,eAAO,MAAM,0BAA0B,EAAE,oBAoBxC,CAAC;AAEF,iFAAiF;AACjF,MAAM,WAAW,4CAA4C;IAC3D,aAAa,CAAC,EAAE,uBAAuB,CAAC;IACxC,YAAY,CAAC,EAAE,+BAA+B,CAAC;IAC/C,wBAAwB,CAAC,EAAE,SAAS,0BAA0B,EAAE,CAAC;CAClE;AAED,MAAM,WAAW,uCAAuC;IACtD;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,CACjB,OAAO,EAAE,QAAQ,CAAC,6BAA6B,CAAC,KAE9C,4CAA4C,GAC5C,OAAO,CAAC,4CAA4C,CAAC,CAAC;CAC3D;AA+ED,qFAAqF;AACrF,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,8BAA8B,GACxC,uCAAuC,CAYzC;AAED,wFAAwF;AACxF,wBAAgB,sCAAsC,CACpD,QAAQ,EAAE,iBAAiB,GAAG,CAAC,MAAM,OAAO,CAAC,iBAAiB,CAAC,CAAC,EAChE,OAAO,GAAE,uCAA4C,GACpD,sBAAsB,CAAC,uCAAuC,CAAC,CAuEjE;AAED,+EAA+E;AAC/E,wBAAgB,sCAAsC,IAAI,OAAO,CAAC,uBAAuB,CAAC,CAKzF;AAED;;;GAGG;AACH,wBAAsB,+BAA+B,CACnD,EAAE,EAAE,iBAAiB,EACrB,OAAO,EAAE,iCAAiC,yDAI3C;AAED;;;GAGG;AACH,wBAAsB,+BAA+B,CACnD,EAAE,EAAE,iBAAiB,EACrB,OAAO,EAAE,qCAAqC,2CAI/C"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure stored-fact aggregation for the commerce tax summary report.
|
|
3
|
+
*
|
|
4
|
+
* Persistence owns source queries. This module deliberately accepts normalized
|
|
5
|
+
* snapshots so report arithmetic is testable without reaching into documents.
|
|
6
|
+
*/
|
|
7
|
+
export type TaxCodeKind = 'taxable' | 'zero-rated' | 'exempt' | 'out-of-scope';
|
|
8
|
+
export type TaxSummaryDirection = 'sales' | 'purchase';
|
|
9
|
+
export interface TaxSummaryStoredFact {
|
|
10
|
+
tenantId: string;
|
|
11
|
+
documentType: 'invoice' | 'credit_note' | 'contract';
|
|
12
|
+
documentId: string;
|
|
13
|
+
/** Invoice credits store positive facts and are negated here exactly once. */
|
|
14
|
+
documentKind: 'invoice' | 'credit_note' | 'contract';
|
|
15
|
+
issueDate: string;
|
|
16
|
+
status: string;
|
|
17
|
+
direction: TaxSummaryDirection;
|
|
18
|
+
currency: string;
|
|
19
|
+
/** Null means the stored snapshot cannot be assigned to a tax code. */
|
|
20
|
+
taxCodeId: string | null;
|
|
21
|
+
/** Null is an incomplete/unassigned stored snapshot, never out-of-scope. */
|
|
22
|
+
taxCodeKind: TaxCodeKind | null;
|
|
23
|
+
taxableMinor: number;
|
|
24
|
+
taxMinor: number;
|
|
25
|
+
recoverableMinor: number;
|
|
26
|
+
taxComponentId: string | null;
|
|
27
|
+
componentName: string | null;
|
|
28
|
+
liabilityAccountId: string | null;
|
|
29
|
+
commitmentId?: string | null;
|
|
30
|
+
commitmentLineId?: string | null;
|
|
31
|
+
}
|
|
32
|
+
export interface TaxSummaryExpenseFact {
|
|
33
|
+
tenantId: string;
|
|
34
|
+
expenseId: string;
|
|
35
|
+
incurredOn: string;
|
|
36
|
+
currency: string;
|
|
37
|
+
commitmentId: string | null;
|
|
38
|
+
commitmentLineId: string | null;
|
|
39
|
+
/** Null means a legacy fact whose supplier tax is unknown. */
|
|
40
|
+
financialBreakdown: {
|
|
41
|
+
taxes: ReadonlyArray<{
|
|
42
|
+
code: string;
|
|
43
|
+
amount: number;
|
|
44
|
+
recoverableAmount: number;
|
|
45
|
+
}>;
|
|
46
|
+
} | null;
|
|
47
|
+
}
|
|
48
|
+
export interface TaxSummaryComponentMapping {
|
|
49
|
+
tenantId: string;
|
|
50
|
+
expenseCode: string;
|
|
51
|
+
taxComponentId: string;
|
|
52
|
+
componentName: string;
|
|
53
|
+
liabilityAccountId: string | null;
|
|
54
|
+
}
|
|
55
|
+
export interface TaxSummaryLedgerMovement {
|
|
56
|
+
tenantId: string;
|
|
57
|
+
entryId: string;
|
|
58
|
+
accountId: string;
|
|
59
|
+
currency: string;
|
|
60
|
+
creditMinusDebit: number;
|
|
61
|
+
}
|
|
62
|
+
export interface TaxSummaryInput {
|
|
63
|
+
tenantId: string;
|
|
64
|
+
from: string;
|
|
65
|
+
to: string;
|
|
66
|
+
facts: ReadonlyArray<TaxSummaryStoredFact>;
|
|
67
|
+
expenses: ReadonlyArray<TaxSummaryExpenseFact>;
|
|
68
|
+
expenseComponentMappings: ReadonlyArray<TaxSummaryComponentMapping>;
|
|
69
|
+
ledgerMovements: ReadonlyArray<TaxSummaryLedgerMovement>;
|
|
70
|
+
}
|
|
71
|
+
export interface TaxSummaryComponentRow {
|
|
72
|
+
rowKind: 'component';
|
|
73
|
+
currency: string;
|
|
74
|
+
taxComponentId: string;
|
|
75
|
+
componentName: string;
|
|
76
|
+
liabilityAccountId: string | null;
|
|
77
|
+
/** Sum of stored component taxable bases; components intentionally overlap. */
|
|
78
|
+
taxableMinor: number;
|
|
79
|
+
collectedMinor: number;
|
|
80
|
+
purchaseRecoverableMinor: number;
|
|
81
|
+
expenseRecoverableMinor: number;
|
|
82
|
+
/** Null when unknown or ambiguous facts make an exact ITC unsafe. */
|
|
83
|
+
inputTaxCreditMinor: number | null;
|
|
84
|
+
/** Null when the corresponding ITC is incomplete. */
|
|
85
|
+
netTaxMinor: number | null;
|
|
86
|
+
documentCount: number;
|
|
87
|
+
/** Stable source classes used to reproduce a materialized drilldown. */
|
|
88
|
+
sourceScopes: readonly TaxSummarySourceScope[];
|
|
89
|
+
}
|
|
90
|
+
export interface TaxSummaryKindRow {
|
|
91
|
+
rowKind: 'kind';
|
|
92
|
+
currency: string;
|
|
93
|
+
direction: TaxSummaryDirection;
|
|
94
|
+
taxCodeKind: TaxCodeKind;
|
|
95
|
+
taxableMinor: number;
|
|
96
|
+
documentCount: number;
|
|
97
|
+
sourceScopes: readonly TaxSummarySourceScope[];
|
|
98
|
+
}
|
|
99
|
+
export interface TaxSummaryReconciliationRow {
|
|
100
|
+
rowKind: 'reconciliation';
|
|
101
|
+
currency: string;
|
|
102
|
+
taxComponentId: string;
|
|
103
|
+
liabilityAccountId: string | null;
|
|
104
|
+
collectedMinor: number;
|
|
105
|
+
ledgerMovementMinor: number | null;
|
|
106
|
+
differenceMinor: number | null;
|
|
107
|
+
status: 'reconciled' | 'difference' | 'unassigned' | 'ambiguous';
|
|
108
|
+
sourceScopes: readonly TaxSummarySourceScope[];
|
|
109
|
+
}
|
|
110
|
+
/** Source classes persisted for drilldown; amounts remain in the report rows. */
|
|
111
|
+
export type TaxSummarySourceScope = 'invoice' | 'purchase' | 'expense' | 'ledger';
|
|
112
|
+
export interface TaxSummaryWarning {
|
|
113
|
+
code: 'unknown-expense-tax' | 'unmapped-expense-component' | 'linked-purchase-expense' | 'unassigned-liability-account' | 'shared-liability-account' | 'unassigned-tax-code';
|
|
114
|
+
currency: string;
|
|
115
|
+
sourceId: string;
|
|
116
|
+
sourceType: 'document' | 'expense' | 'component' | 'account';
|
|
117
|
+
message: string;
|
|
118
|
+
}
|
|
119
|
+
export interface TaxSummaryResult {
|
|
120
|
+
componentRows: TaxSummaryComponentRow[];
|
|
121
|
+
kindRows: TaxSummaryKindRow[];
|
|
122
|
+
reconciliationRows: TaxSummaryReconciliationRow[];
|
|
123
|
+
warnings: TaxSummaryWarning[];
|
|
124
|
+
/** False means no row may be presented as an exact reconciled net tax total. */
|
|
125
|
+
complete: boolean;
|
|
126
|
+
}
|
|
127
|
+
/** Aggregate normalized stored facts without querying persistence. */
|
|
128
|
+
export declare function aggregateTaxSummary(input: TaxSummaryInput): TaxSummaryResult;
|
|
129
|
+
//# sourceMappingURL=tax-summary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tax-summary.d.ts","sourceRoot":"","sources":["../src/tax-summary.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,YAAY,GAAG,QAAQ,GAAG,cAAc,CAAC;AAC/E,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,UAAU,CAAC;AAEvD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,SAAS,GAAG,aAAa,GAAG,UAAU,CAAC;IACrD,UAAU,EAAE,MAAM,CAAC;IACnB,8EAA8E;IAC9E,YAAY,EAAE,SAAS,GAAG,aAAa,GAAG,UAAU,CAAC;IACrD,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,mBAAmB,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,SAAS,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AAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,cAAc,EAAE,MAAM,CAAC;IACvB,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,MAAM,EAAE,YAAY,GAAG,YAAY,GAAG,YAAY,GAAG,WAAW,CAAC;IACjE,YAAY,EAAE,SAAS,qBAAqB,EAAE,CAAC;CAChD;AAED,iFAAiF;AACjF,MAAM,MAAM,qBAAqB,GAC7B,SAAS,GACT,UAAU,GACV,SAAS,GACT,QAAQ,CAAC;AAEb,MAAM,WAAW,iBAAiB;IAChC,IAAI,EACA,qBAAqB,GACrB,4BAA4B,GAC5B,yBAAyB,GACzB,8BAA8B,GAC9B,0BAA0B,GAC1B,qBAAqB,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,UAAU,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAAC;IAC7D,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,sBAAsB,EAAE,CAAC;IACxC,QAAQ,EAAE,iBAAiB,EAAE,CAAC;IAC9B,kBAAkB,EAAE,2BAA2B,EAAE,CAAC;IAClD,QAAQ,EAAE,iBAAiB,EAAE,CAAC;IAC9B,gFAAgF;IAChF,QAAQ,EAAE,OAAO,CAAC;CACnB;AAwDD,sEAAsE;AACtE,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,eAAe,GAAG,gBAAgB,CA8V5E"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Shared tenant serialization barrier for commerce money runtime and migration. */
|
|
2
|
+
import type { DatabaseInterface } from '@happyvertical/smrt-core/migrations';
|
|
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
|
+
declare const tenantMoneyScopeBrand: unique symbol;
|
|
19
|
+
/** Transaction-affine proof that a tenant marker is locked on `db`. */
|
|
20
|
+
export interface TenantMoneyRuntimeScope {
|
|
21
|
+
readonly db: DatabaseInterface;
|
|
22
|
+
readonly tenantId: string;
|
|
23
|
+
readonly barrier: TenantMoneyRuntimeBarrier;
|
|
24
|
+
readonly phase: 'runtime';
|
|
25
|
+
readonly [tenantMoneyScopeBrand]: true;
|
|
26
|
+
}
|
|
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
|
+
/**
|
|
38
|
+
* Lock and re-read the tenant money marker before any runtime money work.
|
|
39
|
+
*
|
|
40
|
+
* Older schemas without TaxSettings stay byte-compatible legacy and are never
|
|
41
|
+
* modified. Once the table exists, a missing deterministic legacy row is
|
|
42
|
+
* materialized solely to provide the serialization point shared by migration.
|
|
43
|
+
*/
|
|
44
|
+
export declare function lockTenantMoneyRuntime(tx: DatabaseInterface, tenantId: string, requirement?: TenantMoneyRuntimeRequirement): Promise<TenantMoneyRuntimeBarrier>;
|
|
45
|
+
/**
|
|
46
|
+
* Run tenant money work under the shared marker lock on exactly one executor.
|
|
47
|
+
*
|
|
48
|
+
* Supplying an existing scope proves re-entry on the same executor. Calls made
|
|
49
|
+
* through the owning transaction wrapper also reuse its exact registered
|
|
50
|
+
* executor. No optional adapter-property heuristic can grant this capability.
|
|
51
|
+
*/
|
|
52
|
+
export declare function withTenantMoneyRuntime<T>(db: DatabaseInterface, tenantId: string, requirement: TenantMoneyRuntimeRequirement, operation: (scope: TenantMoneyRuntimeScope) => Promise<T>, existingScope?: TenantMoneyRuntimeScope): Promise<T>;
|
|
53
|
+
/**
|
|
54
|
+
* Run migration work under the exact owner marker and transaction executor.
|
|
55
|
+
* This is the only scope that lets guarded collections read while the marker
|
|
56
|
+
* is `migrating`; possession cannot be inferred from adapter shape.
|
|
57
|
+
*/
|
|
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
|
+
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
|
+
export {};
|
|
66
|
+
//# sourceMappingURL=tenant-money-barrier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-money-barrier.d.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f,OAAO,CAAC,WAAW,CAAC,CAyBtB;AAED,qEAAqE;AACrE,wBAAsB,6BAA6B,CACjD,EAAE,EAAE,iBAAiB,EACrB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,WAAW,CAAC,CAmBtB"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -82,6 +82,7 @@ export declare enum PaymentStatus {
|
|
|
82
82
|
REFUNDED = "refunded",
|
|
83
83
|
CANCELLED = "cancelled"
|
|
84
84
|
}
|
|
85
|
+
export type PaymentKind = 'payment' | 'refund';
|
|
85
86
|
/**
|
|
86
87
|
* Lifecycle status for a saved {@link PaymentInstrument} (card on file).
|
|
87
88
|
* `active` while chargeable, `expired` once the card lapses, `removed` when the
|
|
@@ -257,6 +258,13 @@ export interface RecognizeRevenueOptions {
|
|
|
257
258
|
revenueAccountId: string;
|
|
258
259
|
/** Account ID for tax payable (credit side, optional) */
|
|
259
260
|
taxAccountId?: string;
|
|
261
|
+
/** Explicit ledger book currency. Required when the tenant uses money v2. */
|
|
262
|
+
bookCurrency?: string;
|
|
263
|
+
}
|
|
264
|
+
/** Options for atomically cancelling a posted money-v2 invoice. */
|
|
265
|
+
export interface CancelRevenueOptions {
|
|
266
|
+
/** Explicit ledger book currency; required for money-v2 cancellation. */
|
|
267
|
+
bookCurrency?: string;
|
|
260
268
|
}
|
|
261
269
|
/**
|
|
262
270
|
* A single line item in the format expected by `@happyvertical/accounting`
|
|
@@ -295,6 +303,16 @@ export interface AccountingInvoiceInput {
|
|
|
295
303
|
currency: string;
|
|
296
304
|
reference?: string;
|
|
297
305
|
memo?: string;
|
|
306
|
+
idempotencyKey?: string;
|
|
307
|
+
quickbooksRequest?: {
|
|
308
|
+
readonly requestId: string;
|
|
309
|
+
readonly realmId: string;
|
|
310
|
+
readonly environment: 'sandbox' | 'production';
|
|
311
|
+
readonly payloadHash: string;
|
|
312
|
+
};
|
|
313
|
+
quickbooksMapping?: {
|
|
314
|
+
globalTaxCalculation: 'TaxExcluded' | 'NotApplicable';
|
|
315
|
+
};
|
|
298
316
|
}
|
|
299
317
|
/**
|
|
300
318
|
* Constructor options for {@link Customer}.
|
|
@@ -306,6 +324,7 @@ export interface CustomerOptions extends SmrtObjectOptions {
|
|
|
306
324
|
paymentTerms?: string;
|
|
307
325
|
taxExempt?: boolean;
|
|
308
326
|
taxId?: string;
|
|
327
|
+
defaultTaxCodeId?: string;
|
|
309
328
|
defaultShippingAddress?: Address;
|
|
310
329
|
defaultBillingAddress?: Address;
|
|
311
330
|
status?: CustomerStatus;
|
|
@@ -323,6 +342,8 @@ export interface VendorOptions extends SmrtObjectOptions {
|
|
|
323
342
|
minimumOrderAmount?: number;
|
|
324
343
|
paymentTerms?: string;
|
|
325
344
|
currency?: string;
|
|
345
|
+
taxId?: string;
|
|
346
|
+
defaultTaxCodeId?: string;
|
|
326
347
|
defaultContactEmail?: string;
|
|
327
348
|
defaultContactPhone?: string;
|
|
328
349
|
status?: VendorStatus;
|
|
@@ -330,6 +351,43 @@ export interface VendorOptions extends SmrtObjectOptions {
|
|
|
330
351
|
payoutAddresses?: Record<string, string> | string | null;
|
|
331
352
|
contacts?: PartyContact[] | string | null;
|
|
332
353
|
}
|
|
354
|
+
/** A component reference stored in a tax code's ordered component list. */
|
|
355
|
+
export interface TaxCodePart {
|
|
356
|
+
taxComponentId: string;
|
|
357
|
+
compound: boolean;
|
|
358
|
+
}
|
|
359
|
+
export interface TaxComponentOptions extends SmrtObjectOptions {
|
|
360
|
+
tenantId?: string | null;
|
|
361
|
+
name?: string;
|
|
362
|
+
percent?: string;
|
|
363
|
+
liabilityAccountId?: string;
|
|
364
|
+
recoverable?: boolean;
|
|
365
|
+
active?: boolean;
|
|
366
|
+
}
|
|
367
|
+
export interface TaxCodeOptions extends SmrtObjectOptions {
|
|
368
|
+
tenantId?: string | null;
|
|
369
|
+
code?: string;
|
|
370
|
+
name?: string;
|
|
371
|
+
kind?: 'taxable' | 'zero-rated' | 'exempt' | 'out-of-scope';
|
|
372
|
+
appliesTo?: 'sales' | 'purchases' | 'both';
|
|
373
|
+
components?: TaxCodePart[];
|
|
374
|
+
active?: boolean;
|
|
375
|
+
}
|
|
376
|
+
export interface TaxRegistrationOptions {
|
|
377
|
+
taxComponentId: string;
|
|
378
|
+
number: string;
|
|
379
|
+
label: string;
|
|
380
|
+
}
|
|
381
|
+
export interface TaxSettingsOptions extends SmrtObjectOptions {
|
|
382
|
+
tenantId?: string;
|
|
383
|
+
defaultSalesTaxCodeId?: string;
|
|
384
|
+
defaultPurchaseTaxCodeId?: string;
|
|
385
|
+
defaultLineAmountType?: 'exclusive' | 'inclusive' | 'none';
|
|
386
|
+
taxRoundingScope?: 'line' | 'document';
|
|
387
|
+
taxRegistrations?: TaxRegistrationOptions[];
|
|
388
|
+
moneyModel?: 'legacy' | 'migrating' | 'v2';
|
|
389
|
+
moneyMigrationId?: string;
|
|
390
|
+
}
|
|
333
391
|
/**
|
|
334
392
|
* Constructor options for {@link Contract} and its STI subtypes.
|
|
335
393
|
*/
|
|
@@ -337,9 +395,8 @@ export interface ContractOptions extends SmrtObjectOptions {
|
|
|
337
395
|
tenantId?: string | null;
|
|
338
396
|
contractType?: ContractType;
|
|
339
397
|
status?: ContractStatus;
|
|
340
|
-
customerId?: string | null;
|
|
341
|
-
vendorId?: string | null;
|
|
342
398
|
subtotal?: number;
|
|
399
|
+
discountTotal?: number;
|
|
343
400
|
taxAmount?: number;
|
|
344
401
|
totalAmount?: number;
|
|
345
402
|
currency?: string;
|
|
@@ -350,9 +407,21 @@ export interface ContractOptions extends SmrtObjectOptions {
|
|
|
350
407
|
notes?: string;
|
|
351
408
|
terms?: string;
|
|
352
409
|
channelId?: string;
|
|
410
|
+
lineAmountType?: 'exclusive' | 'inclusive' | 'none';
|
|
411
|
+
taxRoundingScope?: 'line' | 'document';
|
|
412
|
+
sellerTaxRegistrations?: TaxRegistrationOptions[];
|
|
413
|
+
sellerTaxRegistrationsJson?: string;
|
|
414
|
+
partyTaxId?: string;
|
|
415
|
+
moneySnapshotId?: string;
|
|
416
|
+
}
|
|
417
|
+
export interface SalesContractOptions extends ContractOptions {
|
|
418
|
+
customerId?: string | null;
|
|
419
|
+
}
|
|
420
|
+
export interface PurchaseContractOptions extends ContractOptions {
|
|
421
|
+
vendorId?: string | null;
|
|
353
422
|
}
|
|
354
423
|
/** Purchase-order header options stored in the existing STI metadata. */
|
|
355
|
-
export interface PurchaseOrderOptions extends
|
|
424
|
+
export interface PurchaseOrderOptions extends PurchaseContractOptions {
|
|
356
425
|
/** Expected delivery calendar date (YYYY-MM-DD); empty means unspecified. */
|
|
357
426
|
expectedDate?: string;
|
|
358
427
|
/** Delivery address/instructions snapshot. */
|
|
@@ -362,7 +431,7 @@ export interface PurchaseOrderOptions extends ContractOptions {
|
|
|
362
431
|
* Constructor options for {@link LicenseSale} (Contract STI subtype). Extends
|
|
363
432
|
* {@link ContractOptions} with the licensing-specific meta fields.
|
|
364
433
|
*/
|
|
365
|
-
export interface LicenseSaleOptions extends
|
|
434
|
+
export interface LicenseSaleOptions extends SalesContractOptions {
|
|
366
435
|
skuId?: string;
|
|
367
436
|
paymentId?: string;
|
|
368
437
|
licenseeEmail?: string;
|
|
@@ -389,7 +458,18 @@ export interface ContractLineItemOptions extends SmrtObjectOptions {
|
|
|
389
458
|
quantity?: number;
|
|
390
459
|
unitPrice?: number;
|
|
391
460
|
discount?: number;
|
|
461
|
+
discountType?: 'none' | 'percent' | 'amount';
|
|
462
|
+
discountRate?: string;
|
|
392
463
|
taxRate?: number;
|
|
464
|
+
taxMode?: 'inherit' | 'override';
|
|
465
|
+
taxCodeId?: string | null;
|
|
466
|
+
taxCodeCode?: string | null;
|
|
467
|
+
taxCodeName?: string | null;
|
|
468
|
+
taxComponents?: ContractTaxComponentSnapshot[];
|
|
469
|
+
taxComponentsJson?: string | null;
|
|
470
|
+
taxAmount?: number;
|
|
471
|
+
legacyAmount?: number | null;
|
|
472
|
+
moneySnapshotId?: string;
|
|
393
473
|
amount?: number;
|
|
394
474
|
productId?: string;
|
|
395
475
|
sku?: string;
|
|
@@ -398,16 +478,45 @@ export interface ContractLineItemOptions extends SmrtObjectOptions {
|
|
|
398
478
|
billingPeriod?: string;
|
|
399
479
|
sortOrder?: number;
|
|
400
480
|
}
|
|
481
|
+
/** Immutable component tax allocation for one Contract line. */
|
|
482
|
+
export interface ContractTaxComponentSnapshot {
|
|
483
|
+
taxComponentId: string;
|
|
484
|
+
name: string;
|
|
485
|
+
percent: string;
|
|
486
|
+
taxMinor: number;
|
|
487
|
+
}
|
|
401
488
|
/**
|
|
402
489
|
* How the provider collects an invoice (#3190): `charge_automatically`
|
|
403
490
|
* charges the payer's saved card; `send_invoice` asks the payer to pay. Empty
|
|
404
491
|
* for an invoice never pushed to a provider, or pushed before it was recorded.
|
|
405
492
|
*/
|
|
406
493
|
export type InvoiceCollectionMethod = '' | 'send_invoice' | 'charge_automatically';
|
|
494
|
+
export type InvoiceKind = 'invoice' | 'credit_note';
|
|
495
|
+
/** Frozen source pricing plus the one authoritative credit calculation basis. */
|
|
496
|
+
export type InvoiceCreditCalculationBasis = {
|
|
497
|
+
kind: 'quantity';
|
|
498
|
+
quantity: string;
|
|
499
|
+
sourceQuantity: string;
|
|
500
|
+
sourceUnitPrice: number;
|
|
501
|
+
sourceDiscountType: 'none' | 'percent' | 'amount';
|
|
502
|
+
sourceDiscountRate: string;
|
|
503
|
+
sourceDiscountMinor: number;
|
|
504
|
+
} | {
|
|
505
|
+
kind: 'net_amount';
|
|
506
|
+
netMinor: number;
|
|
507
|
+
sourceQuantity: string;
|
|
508
|
+
sourceUnitPrice: number;
|
|
509
|
+
sourceDiscountType: 'none' | 'percent' | 'amount';
|
|
510
|
+
sourceDiscountRate: string;
|
|
511
|
+
sourceDiscountMinor: number;
|
|
512
|
+
};
|
|
407
513
|
/**
|
|
408
514
|
* Constructor options for {@link Invoice}.
|
|
409
515
|
*/
|
|
410
516
|
export interface InvoiceOptions extends SmrtObjectOptions {
|
|
517
|
+
kind?: InvoiceKind;
|
|
518
|
+
creditedInvoiceId?: string | null;
|
|
519
|
+
creditedAmount?: number;
|
|
411
520
|
tenantId?: string | null;
|
|
412
521
|
customerId?: string;
|
|
413
522
|
contractId?: string;
|
|
@@ -424,6 +533,7 @@ export interface InvoiceOptions extends SmrtObjectOptions {
|
|
|
424
533
|
currency?: string;
|
|
425
534
|
status?: InvoiceStatus;
|
|
426
535
|
arJournalId?: string;
|
|
536
|
+
arReversalJournalId?: string | null;
|
|
427
537
|
revenueJournalId?: string;
|
|
428
538
|
externalId?: string;
|
|
429
539
|
customerExternalId?: string;
|
|
@@ -437,6 +547,20 @@ export interface InvoiceOptions extends SmrtObjectOptions {
|
|
|
437
547
|
notes?: string;
|
|
438
548
|
customerNotes?: string;
|
|
439
549
|
terms?: string;
|
|
550
|
+
lineAmountType?: 'exclusive' | 'inclusive' | 'none';
|
|
551
|
+
taxRoundingScope?: 'line' | 'document';
|
|
552
|
+
discountTotal?: number;
|
|
553
|
+
sellerTaxRegistrations?: TaxRegistrationOptions[];
|
|
554
|
+
sellerTaxRegistrationsJson?: string;
|
|
555
|
+
partyTaxId?: string;
|
|
556
|
+
moneySnapshotId?: string;
|
|
557
|
+
accountingSyncStateJson?: string;
|
|
558
|
+
}
|
|
559
|
+
export interface InvoiceTaxComponentSnapshot {
|
|
560
|
+
taxComponentId: string;
|
|
561
|
+
name: string;
|
|
562
|
+
percent: string;
|
|
563
|
+
taxMinor: number;
|
|
440
564
|
}
|
|
441
565
|
/** Retained editing modes, validated against resolved model fields before reuse. */
|
|
442
566
|
export interface InvoiceLineEditorState {
|
|
@@ -447,6 +571,9 @@ export interface InvoiceLineEditorState {
|
|
|
447
571
|
}
|
|
448
572
|
/** Constructor options for {@link InvoiceLineItem}. */
|
|
449
573
|
export interface InvoiceLineItemOptions extends SmrtObjectOptions {
|
|
574
|
+
creditedLineId?: string | null;
|
|
575
|
+
creditCalculationBasis?: InvoiceCreditCalculationBasis | null;
|
|
576
|
+
creditCalculationBasisJson?: string;
|
|
450
577
|
/** Optional retained editor modes and their original calculation context. */
|
|
451
578
|
invoiceEditorState?: InvoiceLineEditorState | null;
|
|
452
579
|
/** Serialized editor state loaded from persistence; malformed JSON is ignored. */
|
|
@@ -455,16 +582,28 @@ export interface InvoiceLineItemOptions extends SmrtObjectOptions {
|
|
|
455
582
|
invoiceId?: string;
|
|
456
583
|
description?: string;
|
|
457
584
|
sku?: string;
|
|
585
|
+
productId?: string | null;
|
|
458
586
|
quantity?: number;
|
|
459
587
|
unitPrice?: number;
|
|
460
588
|
discount?: number;
|
|
589
|
+
discountType?: 'none' | 'percent' | 'amount';
|
|
590
|
+
discountRate?: string;
|
|
461
591
|
taxRate?: number;
|
|
592
|
+
taxMode?: 'inherit' | 'override';
|
|
593
|
+
taxCodeId?: string | null;
|
|
594
|
+
taxCodeCode?: string | null;
|
|
595
|
+
taxCodeName?: string | null;
|
|
596
|
+
taxComponents?: InvoiceTaxComponentSnapshot[];
|
|
597
|
+
taxComponentsJson?: string | null;
|
|
598
|
+
taxAmount?: number;
|
|
599
|
+
legacyAmount?: number | null;
|
|
600
|
+
moneySnapshotId?: string;
|
|
462
601
|
amount?: number;
|
|
463
602
|
sourceType?: string;
|
|
464
603
|
sourceId?: string;
|
|
465
604
|
periodStart?: Date | null;
|
|
466
605
|
periodEnd?: Date | null;
|
|
467
|
-
revenueAccountId?: string;
|
|
606
|
+
revenueAccountId?: string | null;
|
|
468
607
|
sortOrder?: number;
|
|
469
608
|
}
|
|
470
609
|
/**
|
|
@@ -497,6 +636,7 @@ export interface FulfillmentLineItemOptions extends SmrtObjectOptions {
|
|
|
497
636
|
* Constructor options for {@link Payment}.
|
|
498
637
|
*/
|
|
499
638
|
export interface PaymentOptions extends SmrtObjectOptions {
|
|
639
|
+
kind?: PaymentKind;
|
|
500
640
|
tenantId?: string | null;
|
|
501
641
|
contractId?: string | null;
|
|
502
642
|
customerId?: string | null;
|