@happyvertical/smrt-commerce 0.66.1 → 0.67.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +213 -92
- package/dist/index.js.map +1 -1
- package/dist/invoice-revenue-sweep.d.ts +102 -0
- package/dist/invoice-revenue-sweep.d.ts.map +1 -0
- package/dist/manifest.json +1 -1
- package/dist/smrt-knowledge.json +3 -3
- package/package.json +14 -14
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post issued invoices into the tenant's settlement chart, and sweep up the
|
|
3
|
+
* ones that were never posted.
|
|
4
|
+
*
|
|
5
|
+
* `Invoice.recognizeRevenue` posts one balanced journal per frozen invoice
|
|
6
|
+
* snapshot and links it as `arJournalId`, so everything here is idempotent.
|
|
7
|
+
* {@link postInvoiceRevenueToSettlementChart} wires it to the chart from
|
|
8
|
+
* `ensureTenantSettlementAccounts`; {@link postPendingInvoiceRevenue} is the
|
|
9
|
+
* repair for invoices issued before posting existed or whose post failed.
|
|
10
|
+
*
|
|
11
|
+
* Both open their own money transaction: call them outside a model
|
|
12
|
+
* transaction, as `ensureTenantSettlementAccounts`.
|
|
13
|
+
*/
|
|
14
|
+
import type { DatabaseInterface } from '@happyvertical/smrt-core/migrations';
|
|
15
|
+
export interface PostInvoiceRevenueResult {
|
|
16
|
+
/** True when this call posted the journal. */
|
|
17
|
+
readonly posted: boolean;
|
|
18
|
+
/** The invoice's revenue journal, or null when it is not postable. */
|
|
19
|
+
readonly journalId: string | null;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Post one issued invoice's revenue journal (Dr receivables / Cr revenue / Cr
|
|
23
|
+
* tax) into the tenant's settlement chart for the invoice currency.
|
|
24
|
+
*
|
|
25
|
+
* Idempotent: an invoice that already links a journal returns it unchanged.
|
|
26
|
+
* Drafts, cancelled and written-off invoices are skipped. If a cancellation
|
|
27
|
+
* commits between the read and the post, the new journal is reversed so a
|
|
28
|
+
* cancelled invoice never keeps receivables.
|
|
29
|
+
*/
|
|
30
|
+
export declare function postInvoiceRevenueToSettlementChart(db: DatabaseInterface, tenantId: string, invoiceId: string): Promise<PostInvoiceRevenueResult>;
|
|
31
|
+
/**
|
|
32
|
+
* One page of unposted, issued invoice ids after `after`, ordered by id.
|
|
33
|
+
*
|
|
34
|
+
* Raw SQL, because an unposted invoice stores either NULL or '' in
|
|
35
|
+
* `ar_journal_id` and the collection filter cannot match both. Id columns are
|
|
36
|
+
* cast to text so the same statement runs on PostgreSQL (UUID columns) and
|
|
37
|
+
* SQLite (text).
|
|
38
|
+
*
|
|
39
|
+
* @internal exported for the PostgreSQL-dialect test.
|
|
40
|
+
*/
|
|
41
|
+
export declare function selectUnpostedInvoiceIds(db: DatabaseInterface, tenantId: string, after: string | null, limit: number): Promise<{
|
|
42
|
+
id: string;
|
|
43
|
+
}[]>;
|
|
44
|
+
/**
|
|
45
|
+
* One page of cancelled invoices that still carry a revenue journal but no
|
|
46
|
+
* reversal, after `after`, ordered by id. Same casts as
|
|
47
|
+
* {@link selectUnpostedInvoiceIds}.
|
|
48
|
+
*
|
|
49
|
+
* @internal exported for the PostgreSQL-dialect test.
|
|
50
|
+
*/
|
|
51
|
+
export declare function selectCancelledUnreversedInvoiceIds(db: DatabaseInterface, tenantId: string, after: string | null, limit: number): Promise<{
|
|
52
|
+
id: string;
|
|
53
|
+
}[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Reverse the revenue journal of a cancelled invoice that still carries one.
|
|
56
|
+
* Idempotent: the reversal is a deterministic journal, and an invoice that is
|
|
57
|
+
* not cancelled, has no journal, or is already reversed is left alone.
|
|
58
|
+
*/
|
|
59
|
+
export declare function reverseCancelledInvoiceRevenue(db: DatabaseInterface, tenantId: string, invoiceId: string): Promise<{
|
|
60
|
+
reversed: boolean;
|
|
61
|
+
}>;
|
|
62
|
+
export interface PostPendingInvoiceRevenueOptions {
|
|
63
|
+
/** Invoices per page (1-200, default 50). */
|
|
64
|
+
readonly limit?: number;
|
|
65
|
+
/** Pages per call (default 20). A larger backlog returns `nextCursor`. */
|
|
66
|
+
readonly maxPages?: number;
|
|
67
|
+
/** Resume from a previous call's `nextCursor`. */
|
|
68
|
+
readonly cursor?: string | null;
|
|
69
|
+
/** Called with the invoice id and error when one invoice fails. */
|
|
70
|
+
readonly onError?: (invoiceId: string, error: unknown) => void;
|
|
71
|
+
}
|
|
72
|
+
export interface PostPendingInvoiceRevenueResult {
|
|
73
|
+
/** Invoices posted by this call. */
|
|
74
|
+
readonly posted: number;
|
|
75
|
+
/** Cancelled invoices whose revenue journal this call reversed. */
|
|
76
|
+
readonly reversed: number;
|
|
77
|
+
/** Invoices whose post or reversal threw; the rest of the batch still ran. */
|
|
78
|
+
readonly failed: number;
|
|
79
|
+
/**
|
|
80
|
+
* Pass back as `options.cursor` to continue past this call's page budget, so
|
|
81
|
+
* invoices that fail every run cannot starve the ones after them. Null when
|
|
82
|
+
* the scan finished.
|
|
83
|
+
*/
|
|
84
|
+
readonly nextCursor: string | null;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Repair: bring the tenant's books in line with its invoices.
|
|
88
|
+
*
|
|
89
|
+
* Two phases, each filtered in the query before paging so settled invoices
|
|
90
|
+
* never consume the scan: (1) cancelled invoices that still carry a revenue
|
|
91
|
+
* journal get it reversed (a cancel that raced a post, or a reversal that
|
|
92
|
+
* failed); (2) issued, non-cancelled, non-written-off invoices with no journal
|
|
93
|
+
* get posted. A paid invoice whose payment settled before posting existed is
|
|
94
|
+
* balanced by its new journal. Safe to repeat and to run concurrently: posting
|
|
95
|
+
* and reversal are keyed on the invoice and its snapshot.
|
|
96
|
+
*
|
|
97
|
+
* One call scans up to `maxPages` pages. If it stops there, `nextCursor`
|
|
98
|
+
* resumes where it left off; an invoice that fails stays unposted but the
|
|
99
|
+
* cursor moves past it, so it cannot starve later ones.
|
|
100
|
+
*/
|
|
101
|
+
export declare function postPendingInvoiceRevenue(db: DatabaseInterface, tenantId: string, options?: PostPendingInvoiceRevenueOptions): Promise<PostPendingInvoiceRevenueResult>;
|
|
102
|
+
//# sourceMappingURL=invoice-revenue-sweep.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoice-revenue-sweep.d.ts","sourceRoot":"","sources":["../src/invoice-revenue-sweep.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAmB7E,MAAM,WAAW,wBAAwB;IACvC,8CAA8C;IAC9C,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,sEAAsE;IACtE,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;AAED;;;;;;;;GAQG;AACH,wBAAsB,mCAAmC,CACvD,EAAE,EAAE,iBAAiB,EACrB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,wBAAwB,CAAC,CAmCnC;AAED;;;;;;;;;GASG;AACH,wBAAsB,wBAAwB,CAC5C,EAAE,EAAE,iBAAiB,EACrB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,CAe3B;AAED;;;;;;GAMG;AACH,wBAAsB,mCAAmC,CACvD,EAAE,EAAE,iBAAiB,EACrB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,CAe3B;AAED;;;;GAIG;AACH,wBAAsB,8BAA8B,CAClD,EAAE,EAAE,iBAAiB,EACrB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC,CAgBhC;AAED,MAAM,WAAW,gCAAgC;IAC/C,6CAA6C;IAC7C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,0EAA0E;IAC1E,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,kDAAkD;IAClD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,mEAAmE;IACnE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CAChE;AAED,MAAM,WAAW,+BAA+B;IAC9C,oCAAoC;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,mEAAmE;IACnE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CACpC;AAcD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,yBAAyB,CAC7C,EAAE,EAAE,iBAAiB,EACrB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,gCAAqC,GAC7C,OAAO,CAAC,+BAA+B,CAAC,CA+C1C"}
|
package/dist/manifest.json
CHANGED
package/dist/smrt-knowledge.json
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
"sensitiveFieldsExcluded": true,
|
|
4
4
|
"generatedAt": "1970-01-01T00:00:00.000Z",
|
|
5
5
|
"packageName": "@happyvertical/smrt-commerce",
|
|
6
|
-
"packageVersion": "0.
|
|
6
|
+
"packageVersion": "0.67.0",
|
|
7
7
|
"sourceManifestPath": "dist/manifest.json",
|
|
8
8
|
"agentDocPath": "AGENTS.md",
|
|
9
9
|
"sourceHashes": {
|
|
10
|
-
"manifest": "
|
|
11
|
-
"packageJson": "
|
|
10
|
+
"manifest": "eac0725d5bac5fc5aafc090b146f232c85e7e1eba4334bde40425dc9648800ff",
|
|
11
|
+
"packageJson": "64c4460827ffe29e4873ac83561b3e940b900efcfc713b98a308b97f7f448627",
|
|
12
12
|
"agents": "4891a1eb6aa2be45b8374d9bacdcda357bab45e184d9d756596985381f6de442",
|
|
13
13
|
"moduleDoc:agents/customer-vendor-ui.md": "ee8cbe9b6c4334cb9d53c87258d20a6ec8abd042011135be75cb03d2198796cc",
|
|
14
14
|
"moduleDoc:README.md": "06668f73dad1198089b4eef19a9a6ab8421825615c581cf66c593da32754f359",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@happyvertical/smrt-commerce",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.67.0",
|
|
4
4
|
"smrtJsdoc": "strict",
|
|
5
5
|
"description": "Commerce models for the SMRT framework - contracts, fulfillments, payments",
|
|
6
6
|
"type": "module",
|
|
@@ -65,18 +65,18 @@
|
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@happyvertical/accounting": "^0.116.6",
|
|
67
67
|
"@happyvertical/payments": "^0.116.6",
|
|
68
|
-
"@happyvertical/smrt-agents": "0.
|
|
69
|
-
"@happyvertical/smrt-core": "0.
|
|
70
|
-
"@happyvertical/smrt-jobs": "0.
|
|
71
|
-
"@happyvertical/smrt-ledgers": "0.
|
|
72
|
-
"@happyvertical/smrt-products": "0.
|
|
73
|
-
"@happyvertical/smrt-profiles": "0.
|
|
74
|
-
"@happyvertical/smrt-reports": "0.
|
|
75
|
-
"@happyvertical/smrt-subscriptions": "0.
|
|
76
|
-
"@happyvertical/smrt-svelte": "0.
|
|
77
|
-
"@happyvertical/smrt-tenancy": "0.
|
|
78
|
-
"@happyvertical/smrt-types": "0.
|
|
79
|
-
"@happyvertical/smrt-ui": "0.
|
|
68
|
+
"@happyvertical/smrt-agents": "0.67.0",
|
|
69
|
+
"@happyvertical/smrt-core": "0.67.0",
|
|
70
|
+
"@happyvertical/smrt-jobs": "0.67.0",
|
|
71
|
+
"@happyvertical/smrt-ledgers": "0.67.0",
|
|
72
|
+
"@happyvertical/smrt-products": "0.67.0",
|
|
73
|
+
"@happyvertical/smrt-profiles": "0.67.0",
|
|
74
|
+
"@happyvertical/smrt-reports": "0.67.0",
|
|
75
|
+
"@happyvertical/smrt-subscriptions": "0.67.0",
|
|
76
|
+
"@happyvertical/smrt-svelte": "0.67.0",
|
|
77
|
+
"@happyvertical/smrt-tenancy": "0.67.0",
|
|
78
|
+
"@happyvertical/smrt-types": "0.67.0",
|
|
79
|
+
"@happyvertical/smrt-ui": "0.67.0",
|
|
80
80
|
"@happyvertical/sql": "^0.116.6"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
}
|
|
89
89
|
},
|
|
90
90
|
"devDependencies": {
|
|
91
|
-
"@happyvertical/smrt-vitest": "0.
|
|
91
|
+
"@happyvertical/smrt-vitest": "0.67.0",
|
|
92
92
|
"@sveltejs/package": "^2.5.8",
|
|
93
93
|
"@sveltejs/vite-plugin-svelte": "^7.3.0",
|
|
94
94
|
"@testing-library/jest-dom": "^7.0.1",
|