@happyvertical/smrt-commerce 0.56.1 → 0.57.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.
Files changed (186) hide show
  1. package/AGENTS.md +24 -11
  2. package/README.md +159 -93
  3. package/agents/accounting-snapshot-mapper.md +3 -3
  4. package/agents/commercial-ui.md +2 -2
  5. package/agents/contract-money.md +9 -6
  6. package/agents/cost-billing.md +3 -6
  7. package/agents/customer-vendor-ui.md +6 -1
  8. package/agents/document-money.md +59 -31
  9. package/agents/invoice-calculations.md +31 -56
  10. package/agents/invoice-preparation.md +62 -73
  11. package/agents/invoice-quantity.md +9 -21
  12. package/agents/minor-unit-migration.md +4 -4
  13. package/agents/money-calculator.md +7 -8
  14. package/agents/money-model.md +18 -22
  15. package/agents/money-upgrade.md +92 -0
  16. package/agents/revenue-journal.md +2 -2
  17. package/agents/tax-codes.md +17 -14
  18. package/agents/tax-summary.md +12 -8
  19. package/dist/billing/period-close.d.ts.map +1 -1
  20. package/dist/billing/runtime.d.ts +5 -2
  21. package/dist/billing/runtime.d.ts.map +1 -1
  22. package/dist/chunks/{ContractLineItemCollection-DYjhj_pU.js → ContractLineItemCollection-BZcrlrrY.js} +22 -27
  23. package/dist/chunks/ContractLineItemCollection-BZcrlrrY.js.map +1 -0
  24. package/dist/chunks/{CustomerCollection-DQIujn4f.js → CustomerCollection-BIPH2ZUx.js} +3 -3
  25. package/dist/chunks/{CustomerCollection-DQIujn4f.js.map → CustomerCollection-BIPH2ZUx.js.map} +1 -1
  26. package/dist/chunks/{DocumentTaxCollection-BEpoqXAQ.js → DocumentTaxCollection-DDzlywMW.js} +41 -14
  27. package/dist/chunks/DocumentTaxCollection-DDzlywMW.js.map +1 -0
  28. package/dist/chunks/{InvoiceCollection-CKQflFjc.js → InvoiceCollection-cinzAqt6.js} +53 -164
  29. package/dist/chunks/InvoiceCollection-cinzAqt6.js.map +1 -0
  30. package/dist/chunks/{TaxCodeCollection-DOpzW4y8.js → TaxCodeCollection-DaBOPG9c.js} +11 -4
  31. package/dist/chunks/{TaxCodeCollection-DOpzW4y8.js.map → TaxCodeCollection-DaBOPG9c.js.map} +1 -1
  32. package/dist/chunks/{TaxComponentCollection-Cs2uXwEl.js → TaxComponentCollection-C4zxnyVu.js} +3 -3
  33. package/dist/chunks/{TaxComponentCollection-Cs2uXwEl.js.map → TaxComponentCollection-C4zxnyVu.js.map} +1 -1
  34. package/dist/chunks/VendorCollection-D6ZcUYy8.js +100 -0
  35. package/dist/chunks/VendorCollection-D6ZcUYy8.js.map +1 -0
  36. package/dist/chunks/{allocation-integrity-DI3G16BN.js → allocation-integrity-WmWyXhtG.js} +6 -6
  37. package/dist/chunks/{allocation-integrity-DI3G16BN.js.map → allocation-integrity-WmWyXhtG.js.map} +1 -1
  38. package/dist/chunks/calculations-C9daQLsh.js +82 -0
  39. package/dist/chunks/calculations-C9daQLsh.js.map +1 -0
  40. package/dist/chunks/contract-money-EuToOghh.js +301 -0
  41. package/dist/chunks/contract-money-EuToOghh.js.map +1 -0
  42. package/dist/chunks/detect-CY9ufaFb.js +328 -0
  43. package/dist/chunks/detect-CY9ufaFb.js.map +1 -0
  44. package/dist/chunks/{document-money-DNVhDJyC.js → document-money-DV5t4vlK.js} +389 -63
  45. package/dist/chunks/document-money-DV5t4vlK.js.map +1 -0
  46. package/dist/chunks/{invoice-posting-BwV8g7z0.js → invoice-posting-C2i5dOVZ.js} +21 -23
  47. package/dist/chunks/invoice-posting-C2i5dOVZ.js.map +1 -0
  48. package/dist/chunks/{revenue-journal-DY9fro8E.js → revenue-journal-LLA9Kh_i.js} +3 -14
  49. package/dist/chunks/revenue-journal-LLA9Kh_i.js.map +1 -0
  50. package/dist/chunks/tenant-money-barrier-6TlqUeVj.js +255 -0
  51. package/dist/chunks/tenant-money-barrier-6TlqUeVj.js.map +1 -0
  52. package/dist/chunks/{types-LDETvQ1C.js → types-Bbm0Xflc.js} +2 -1
  53. package/dist/chunks/types-Bbm0Xflc.js.map +1 -0
  54. package/dist/chunks/{units-CNcjH_eE.js → units-8ElbjVZK.js} +18 -3
  55. package/dist/chunks/units-8ElbjVZK.js.map +1 -0
  56. package/dist/collections/ContractCollection.d.ts.map +1 -1
  57. package/dist/collections/ContractLineItemCollection.d.ts.map +1 -1
  58. package/dist/collections/InvoiceCollection.d.ts.map +1 -1
  59. package/dist/collections/InvoiceLineItemCollection.d.ts +0 -30
  60. package/dist/collections/InvoiceLineItemCollection.d.ts.map +1 -1
  61. package/dist/collections/TaxCodeCollection.d.ts +5 -1
  62. package/dist/collections/TaxCodeCollection.d.ts.map +1 -1
  63. package/dist/collections/TaxSettingsCollection.d.ts +15 -8
  64. package/dist/collections/TaxSettingsCollection.d.ts.map +1 -1
  65. package/dist/collections/TaxSummaryReportCollection.d.ts +3 -3
  66. package/dist/collections/TaxSummaryReportCollection.d.ts.map +1 -1
  67. package/dist/collections/index.d.ts +0 -1
  68. package/dist/collections/index.d.ts.map +1 -1
  69. package/dist/commerce-money-tools.d.ts.map +1 -1
  70. package/dist/contract-money.d.ts +1 -13
  71. package/dist/contract-money.d.ts.map +1 -1
  72. package/dist/document-money-internal.d.ts +7 -3
  73. package/dist/document-money-internal.d.ts.map +1 -1
  74. package/dist/document-money.d.ts +1 -11
  75. package/dist/document-money.d.ts.map +1 -1
  76. package/dist/index.d.ts +6 -5
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/index.js +686 -1656
  79. package/dist/index.js.map +1 -1
  80. package/dist/invoice-accounting-sync.d.ts.map +1 -1
  81. package/dist/invoice-mcp.d.ts +3 -3
  82. package/dist/invoice-mcp.d.ts.map +1 -1
  83. package/dist/invoice-posting.d.ts +11 -5
  84. package/dist/invoice-posting.d.ts.map +1 -1
  85. package/dist/invoice-record-screen.d.ts +1 -1
  86. package/dist/invoice-record-screen.d.ts.map +1 -1
  87. package/dist/invoices.d.ts +6 -1
  88. package/dist/invoices.d.ts.map +1 -1
  89. package/dist/invoices.js +2 -2
  90. package/dist/manifest.json +1041 -863
  91. package/dist/migrations/invoiceEditorStorage.d.ts +2 -4
  92. package/dist/migrations/invoiceEditorStorage.d.ts.map +1 -1
  93. package/dist/migrations/partyLinks.d.ts.map +1 -1
  94. package/dist/models/Contract.d.ts +10 -4
  95. package/dist/models/Contract.d.ts.map +1 -1
  96. package/dist/models/ContractLineItem.d.ts +9 -17
  97. package/dist/models/ContractLineItem.d.ts.map +1 -1
  98. package/dist/models/DocumentTax.d.ts.map +1 -1
  99. package/dist/models/Invoice.d.ts +18 -48
  100. package/dist/models/Invoice.d.ts.map +1 -1
  101. package/dist/models/InvoiceLineItem.d.ts +13 -32
  102. package/dist/models/InvoiceLineItem.d.ts.map +1 -1
  103. package/dist/models/TaxSettings.d.ts +0 -10
  104. package/dist/models/TaxSettings.d.ts.map +1 -1
  105. package/dist/models/index.d.ts +1 -2
  106. package/dist/models/index.d.ts.map +1 -1
  107. package/dist/playground.js +1 -1
  108. package/dist/playground.js.map +1 -1
  109. package/dist/recipes.d.ts +8 -11
  110. package/dist/recipes.d.ts.map +1 -1
  111. package/dist/revenue-journal.d.ts +0 -8
  112. package/dist/revenue-journal.d.ts.map +1 -1
  113. package/dist/smrt-knowledge.json +2886 -6121
  114. package/dist/svelte/components/InvoiceEditor.svelte +7 -148
  115. package/dist/svelte/components/InvoiceEditor.svelte.d.ts +4 -1
  116. package/dist/svelte/components/InvoiceEditor.svelte.d.ts.map +1 -1
  117. package/dist/svelte/components/InvoiceTotals.svelte +14 -118
  118. package/dist/svelte/components/InvoiceTotals.svelte.d.ts +4 -27
  119. package/dist/svelte/components/InvoiceTotals.svelte.d.ts.map +1 -1
  120. package/dist/svelte/components/MoneyInvoiceEditor.svelte +3 -23
  121. package/dist/svelte/components/MoneyInvoiceEditor.svelte.d.ts +3 -26
  122. package/dist/svelte/components/MoneyInvoiceEditor.svelte.d.ts.map +1 -1
  123. package/dist/svelte/index.d.ts +2 -3
  124. package/dist/svelte/index.d.ts.map +1 -1
  125. package/dist/svelte/index.js +1 -2
  126. package/dist/svelte/invoices/calculations.d.ts +3 -108
  127. package/dist/svelte/invoices/calculations.d.ts.map +1 -1
  128. package/dist/svelte/invoices/calculations.js +12 -309
  129. package/dist/svelte/invoices/messages.d.ts +1 -37
  130. package/dist/svelte/invoices/messages.d.ts.map +1 -1
  131. package/dist/svelte/invoices/messages.js +1 -37
  132. package/dist/svelte/invoices/money-editor.d.ts +1 -1
  133. package/dist/svelte/invoices/money-editor.d.ts.map +1 -1
  134. package/dist/svelte/invoices/types.d.ts +14 -114
  135. package/dist/svelte/invoices/types.d.ts.map +1 -1
  136. package/dist/svelte/playground/InvoicePreparationPreview.svelte +85 -94
  137. package/dist/svelte/playground/InvoicePreparationPreview.svelte.d.ts.map +1 -1
  138. package/dist/svelte/playground.js +1 -1
  139. package/dist/tax/index.d.ts +2 -1
  140. package/dist/tax/index.d.ts.map +1 -1
  141. package/dist/tax/standard-codes.d.ts +12 -0
  142. package/dist/tax/standard-codes.d.ts.map +1 -0
  143. package/dist/tax/tenant-bootstrap.d.ts +29 -0
  144. package/dist/tax/tenant-bootstrap.d.ts.map +1 -0
  145. package/dist/tenant-money-barrier.d.ts +12 -44
  146. package/dist/tenant-money-barrier.d.ts.map +1 -1
  147. package/dist/types/index.d.ts +11 -23
  148. package/dist/types/index.d.ts.map +1 -1
  149. package/dist/ui.js +1 -1
  150. package/dist/ui.js.map +1 -1
  151. package/dist/upgrade/detect.d.ts +129 -0
  152. package/dist/upgrade/detect.d.ts.map +1 -0
  153. package/dist/upgrade/money-v2.d.ts +81 -0
  154. package/dist/upgrade/money-v2.d.ts.map +1 -0
  155. package/package.json +14 -13
  156. package/agents/line-amount-migration.md +0 -50
  157. package/dist/chunks/ContractLineItemCollection-DYjhj_pU.js.map +0 -1
  158. package/dist/chunks/DocumentTaxCollection-BEpoqXAQ.js.map +0 -1
  159. package/dist/chunks/InvoiceCollection-CKQflFjc.js.map +0 -1
  160. package/dist/chunks/InvoiceLineItemCollection-CHm9zdqh.js +0 -467
  161. package/dist/chunks/InvoiceLineItemCollection-CHm9zdqh.js.map +0 -1
  162. package/dist/chunks/TaxSettingsCollection-BBTZDH1S.js +0 -319
  163. package/dist/chunks/TaxSettingsCollection-BBTZDH1S.js.map +0 -1
  164. package/dist/chunks/calculations-DaHR17il.js +0 -333
  165. package/dist/chunks/calculations-DaHR17il.js.map +0 -1
  166. package/dist/chunks/document-money-DNVhDJyC.js.map +0 -1
  167. package/dist/chunks/invoice-posting-BwV8g7z0.js.map +0 -1
  168. package/dist/chunks/revenue-journal-DY9fro8E.js.map +0 -1
  169. package/dist/chunks/tenant-money-barrier-DjRXgMnX.js +0 -135
  170. package/dist/chunks/tenant-money-barrier-DjRXgMnX.js.map +0 -1
  171. package/dist/chunks/types-LDETvQ1C.js.map +0 -1
  172. package/dist/chunks/units-CNcjH_eE.js.map +0 -1
  173. package/dist/collections/MoneyMigrationDocumentCollection.d.ts +0 -12
  174. package/dist/collections/MoneyMigrationDocumentCollection.d.ts.map +0 -1
  175. package/dist/migrations/commerceLineAmounts.d.ts +0 -84
  176. package/dist/migrations/commerceLineAmounts.d.ts.map +0 -1
  177. package/dist/models/MoneyMigrationDocument.d.ts +0 -28
  178. package/dist/models/MoneyMigrationDocument.d.ts.map +0 -1
  179. package/dist/svelte/components/InvoiceLineEditor.svelte +0 -92
  180. package/dist/svelte/components/InvoiceLineEditor.svelte.d.ts +0 -8
  181. package/dist/svelte/components/InvoiceLineEditor.svelte.d.ts.map +0 -1
  182. package/dist/svelte/invoices/fields.d.ts +0 -6
  183. package/dist/svelte/invoices/fields.d.ts.map +0 -1
  184. package/dist/svelte/invoices/fields.js +0 -22
  185. package/dist/tax/legacy.d.ts +0 -48
  186. 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
- /** Editable line field names repeat in displayed order. */
83
- export interface InvoiceLineFieldNames {
84
- /** Stable line identity. */
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, default POST. */
80
+ /** Native HTTP method retained for progressive enhancement. */
152
81
  method?: 'post' | 'get';
153
- /** Stable form identity. */
154
- id?: string;
155
- /** Caller-localized title. */
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
- /** Disable submission while a request is pending. */
86
+ /** Caller transport state that disables edits and the save submitter. */
173
87
  pending?: boolean;
174
- /** Caller-owned retry-controller status. */
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
- /** Save intent, default save. */
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
- /** Add-line intent, default addLine. */
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 cancel navigation URL. */
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,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,KAAK,EAAE,8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AW,CAAC,EAAE,MAAM,CAAC;IACrB,gEAAgE;IAChE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mDAAmD;IACnD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yEAAyE;IACzE,QAAQ,CAAC,EAAE,kBAAkB,CAAC,UAAU,CAAC,CAAC;CAC3C"}
@@ -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 values = $state<InvoiceDraftValues>({
15
- customerId: 'customer',
16
- issuedOn: '2026-10-03',
17
- dueOn: '2026-11-03',
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
- paymentTerms: 'Net 30',
20
- taxRate: '5',
37
+ lineAmountType: 'exclusive',
38
+ roundingScope: 'line',
21
39
  lines: [
22
40
  {
23
- key: 'first',
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
- taxRate: '0',
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
- let allocations = $state<InvoiceAllocationDraft[]>([
36
- { key: 'allocation', sourceId: 'reviewed-expense', amount: '125.00' },
37
- ]);
38
- let mayReadSources = $state(true);
39
- let canEdit = $state(true);
40
- let message = $state('');
41
- let sequence = 1;
42
- function submit(event: SubmitEvent & { currentTarget: HTMLFormElement }) {
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
- <InvoiceEditor action="" {values} {canEdit} {message} customers={[{ id: 'customer', label: 'Example customer' }]} hiddenFields={[{ name: 'requestId', value: 'demo-request-retained' }]} onsubmit={submit}>
111
- {#snippet children(current)}
112
- <InvoiceAllocationFields currency={current.currency} {allocations} {canEdit} {mayReadSources} sources={[{ id: 'reviewed-expense', label: 'Reviewed supplier expense', availableMinor: 25000 }]} />
113
- {/snippet}
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":"AAgIA,QAAA,MAAM,yBAAyB,2DAAwC,CAAC;AACxE,KAAK,yBAAyB,GAAG,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAC9E,eAAe,yBAAyB,CAAC"}
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, discounts and tax, with optional source allocations and retained rejection recovery.',
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: {},
@@ -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, type LegacyTaxMapReport, type LegacyTaxRateRow, type MapLegacyTaxRatesOptions, mapLegacyTaxRates, mapLegacyTaxRatesInTransaction, } from './legacy.js';
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
@@ -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,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,iBAAiB,EACjB,8BAA8B,GAC/B,MAAM,aAAa,CAAC"}
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
- /** Shared tenant serialization barrier for commerce money runtime and migration. */
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 marker is locked on `db`. */
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 barrier: TenantMoneyRuntimeBarrier;
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 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.
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, requirement?: TenantMoneyRuntimeRequirement): Promise<TenantMoneyRuntimeBarrier>;
18
+ export declare function lockTenantMoneyRuntime(tx: DatabaseInterface, tenantId: string): Promise<TaxSettings>;
45
19
  /**
46
- * Run tenant money work under the shared marker lock on exactly one executor.
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, requirement: TenantMoneyRuntimeRequirement, operation: (scope: TenantMoneyRuntimeScope) => Promise<T>, existingScope?: TenantMoneyRuntimeScope): Promise<T>;
27
+ export declare function withTenantMoneyRuntime<T>(db: DatabaseInterface, tenantId: string, operation: (scope: TenantMoneyRuntimeScope) => Promise<T>, existingScope?: TenantMoneyRuntimeScope): Promise<T>;
53
28
  /**
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.
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,oFAAoF;AAEpF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAG7E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAG3D,MAAM,MAAM,6BAA6B,GAAG,cAAc,GAAG,IAAI,CAAC;AAElE,MAAM,MAAM,yBAAyB,GACjC;IACE,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC;IACxB,QAAQ,CAAC,gBAAgB,EAAE,KAAK,CAAC;CAClC,GACD;IACE,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,QAAQ,CAAC,gBAAgB,EAAE,IAAI,CAAC;CACjC,GACD;IACE,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,QAAQ,CAAC,gBAAgB,EAAE,IAAI,CAAC;CACjC,CAAC;AAEN,OAAO,CAAC,MAAM,qBAAqB,EAAE,OAAO,MAAM,CAAC;AAEnD,uEAAuE;AACvE,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,EAAE,EAAE,iBAAiB,CAAC;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,yBAAyB,CAAC;IAC5C,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,CAAC,qBAAqB,CAAC,EAAE,IAAI,CAAC;CACxC;AAED,OAAO,CAAC,MAAM,8BAA8B,EAAE,OAAO,MAAM,CAAC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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"}
@@ -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",
@@ -31,6 +30,7 @@ export declare enum ContractType {
31
30
  ORDER = "order",
32
31
  LEASE = "lease",
33
32
  AGREEMENT = "agreement",
33
+ SUPPLIER_QUOTE = "supplier_quote",
34
34
  PURCHASE_ORDER = "purchase_order",
35
35
  WHOLESALE_ORDER = "wholesale_order",
36
36
  PRODUCTION_ORDER = "production_order",
@@ -254,17 +254,20 @@ export interface RecordPaymentOptions {
254
254
  export interface RecognizeRevenueOptions {
255
255
  /** Account ID for accounts receivable (debit side) */
256
256
  arAccountId: string;
257
- /** Account ID for revenue (credit side) */
257
+ /** Revenue account for lines that do not name their own (credit side). */
258
258
  revenueAccountId: string;
259
- /** Account ID for tax payable (credit side, optional) */
259
+ /**
260
+ * Tax payable account for tax components without a liability account and
261
+ * for provider tax (credit side).
262
+ */
260
263
  taxAccountId?: string;
261
- /** Explicit ledger book currency. Required when the tenant uses money v2. */
262
- bookCurrency?: string;
264
+ /** ISO 4217 ledger book currency; must equal the invoice currency. */
265
+ bookCurrency: string;
263
266
  }
264
- /** Options for atomically cancelling a posted money-v2 invoice. */
267
+ /** Options for atomically cancelling a posted invoice. */
265
268
  export interface CancelRevenueOptions {
266
- /** Explicit ledger book currency; required for money-v2 cancellation. */
267
- bookCurrency?: string;
269
+ /** ISO 4217 ledger book currency; must equal the invoice currency. */
270
+ bookCurrency: string;
268
271
  }
269
272
  /**
270
273
  * A single line item in the format expected by `@happyvertical/accounting`
@@ -385,8 +388,6 @@ export interface TaxSettingsOptions extends SmrtObjectOptions {
385
388
  defaultLineAmountType?: 'exclusive' | 'inclusive' | 'none';
386
389
  taxRoundingScope?: 'line' | 'document';
387
390
  taxRegistrations?: TaxRegistrationOptions[];
388
- moneyModel?: 'legacy' | 'migrating' | 'v2';
389
- moneyMigrationId?: string;
390
391
  }
391
392
  /**
392
393
  * Constructor options for {@link Contract} and its STI subtypes.
@@ -468,7 +469,6 @@ export interface ContractLineItemOptions extends SmrtObjectOptions {
468
469
  taxComponents?: ContractTaxComponentSnapshot[];
469
470
  taxComponentsJson?: string | null;
470
471
  taxAmount?: number;
471
- legacyAmount?: number | null;
472
472
  moneySnapshotId?: string;
473
473
  amount?: number;
474
474
  productId?: string;
@@ -562,22 +562,11 @@ export interface InvoiceTaxComponentSnapshot {
562
562
  percent: string;
563
563
  taxMinor: number;
564
564
  }
565
- /** Retained editing modes, validated against resolved model fields before reuse. */
566
- export interface InvoiceLineEditorState {
567
- /** Lossless editor draft; never authoritative for ordinary model saves. */
568
- draft: InvoiceLineDraft;
569
- /** Context used to resolve that draft; caller authority must still match on reload. */
570
- context: InvoiceCalculationContext;
571
- }
572
565
  /** Constructor options for {@link InvoiceLineItem}. */
573
566
  export interface InvoiceLineItemOptions extends SmrtObjectOptions {
574
567
  creditedLineId?: string | null;
575
568
  creditCalculationBasis?: InvoiceCreditCalculationBasis | null;
576
569
  creditCalculationBasisJson?: string;
577
- /** Optional retained editor modes and their original calculation context. */
578
- invoiceEditorState?: InvoiceLineEditorState | null;
579
- /** Serialized editor state loaded from persistence; malformed JSON is ignored. */
580
- invoiceEditorStateJson?: string;
581
570
  tenantId?: string | null;
582
571
  invoiceId?: string;
583
572
  description?: string;
@@ -596,7 +585,6 @@ export interface InvoiceLineItemOptions extends SmrtObjectOptions {
596
585
  taxComponents?: InvoiceTaxComponentSnapshot[];
597
586
  taxComponentsJson?: string | null;
598
587
  taxAmount?: number;
599
- legacyAmount?: number | null;
600
588
  moneySnapshotId?: string;
601
589
  amount?: number;
602
590
  sourceType?: string;