@happyvertical/smrt-commerce 0.30.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/AGENTS.md +44 -0
- package/CLAUDE.md +1 -0
- package/LICENSE +7 -0
- package/README.md +146 -0
- package/dist/__smrt-register__.d.ts +2 -0
- package/dist/__smrt-register__.d.ts.map +1 -0
- package/dist/collections/ContractCollection.d.ts +87 -0
- package/dist/collections/ContractCollection.d.ts.map +1 -0
- package/dist/collections/CustomerCollection.d.ts +58 -0
- package/dist/collections/CustomerCollection.d.ts.map +1 -0
- package/dist/collections/FulfillmentCollection.d.ts +75 -0
- package/dist/collections/FulfillmentCollection.d.ts.map +1 -0
- package/dist/collections/InvoiceCollection.d.ts +162 -0
- package/dist/collections/InvoiceCollection.d.ts.map +1 -0
- package/dist/collections/InvoiceLineItemCollection.d.ts +90 -0
- package/dist/collections/InvoiceLineItemCollection.d.ts.map +1 -0
- package/dist/collections/PaymentAllocationCollection.d.ts +86 -0
- package/dist/collections/PaymentAllocationCollection.d.ts.map +1 -0
- package/dist/collections/PaymentCollection.d.ts +96 -0
- package/dist/collections/PaymentCollection.d.ts.map +1 -0
- package/dist/collections/PaymentIntentCollection.d.ts +66 -0
- package/dist/collections/PaymentIntentCollection.d.ts.map +1 -0
- package/dist/collections/PayoutCollection.d.ts +47 -0
- package/dist/collections/PayoutCollection.d.ts.map +1 -0
- package/dist/collections/VendorCollection.d.ts +59 -0
- package/dist/collections/VendorCollection.d.ts.map +1 -0
- package/dist/collections/index.d.ts +15 -0
- package/dist/collections/index.d.ts.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5308 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.json +13852 -0
- package/dist/models/Contract.d.ts +425 -0
- package/dist/models/Contract.d.ts.map +1 -0
- package/dist/models/ContractLineItem.d.ts +92 -0
- package/dist/models/ContractLineItem.d.ts.map +1 -0
- package/dist/models/Customer.d.ts +98 -0
- package/dist/models/Customer.d.ts.map +1 -0
- package/dist/models/Fulfillment.d.ts +99 -0
- package/dist/models/Fulfillment.d.ts.map +1 -0
- package/dist/models/FulfillmentLineItem.d.ts +42 -0
- package/dist/models/FulfillmentLineItem.d.ts.map +1 -0
- package/dist/models/Invoice.d.ts +326 -0
- package/dist/models/Invoice.d.ts.map +1 -0
- package/dist/models/InvoiceLineItem.d.ts +120 -0
- package/dist/models/InvoiceLineItem.d.ts.map +1 -0
- package/dist/models/Payment.d.ts +269 -0
- package/dist/models/Payment.d.ts.map +1 -0
- package/dist/models/PaymentAllocation.d.ts +93 -0
- package/dist/models/PaymentAllocation.d.ts.map +1 -0
- package/dist/models/PaymentIntent.d.ts +341 -0
- package/dist/models/PaymentIntent.d.ts.map +1 -0
- package/dist/models/Payout.d.ts +200 -0
- package/dist/models/Payout.d.ts.map +1 -0
- package/dist/models/Vendor.d.ts +153 -0
- package/dist/models/Vendor.d.ts.map +1 -0
- package/dist/models/index.d.ts +17 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/playground.d.ts +2 -0
- package/dist/playground.d.ts.map +1 -0
- package/dist/playground.js +108 -0
- package/dist/playground.js.map +1 -0
- package/dist/smrt-knowledge.json +5494 -0
- package/dist/svelte/components/InvoiceActions.svelte +191 -0
- package/dist/svelte/components/InvoiceActions.svelte.d.ts +26 -0
- package/dist/svelte/components/InvoiceActions.svelte.d.ts.map +1 -0
- package/dist/svelte/components/InvoiceCard.svelte +233 -0
- package/dist/svelte/components/InvoiceCard.svelte.d.ts +16 -0
- package/dist/svelte/components/InvoiceCard.svelte.d.ts.map +1 -0
- package/dist/svelte/components/InvoiceHeader.svelte +258 -0
- package/dist/svelte/components/InvoiceHeader.svelte.d.ts +26 -0
- package/dist/svelte/components/InvoiceHeader.svelte.d.ts.map +1 -0
- package/dist/svelte/components/InvoiceLineItems.svelte +322 -0
- package/dist/svelte/components/InvoiceLineItems.svelte.d.ts +24 -0
- package/dist/svelte/components/InvoiceLineItems.svelte.d.ts.map +1 -0
- package/dist/svelte/components/InvoiceTotals.svelte +193 -0
- package/dist/svelte/components/InvoiceTotals.svelte.d.ts +27 -0
- package/dist/svelte/components/InvoiceTotals.svelte.d.ts.map +1 -0
- package/dist/svelte/components/UnbilledItems.svelte +355 -0
- package/dist/svelte/components/UnbilledItems.svelte.d.ts +18 -0
- package/dist/svelte/components/UnbilledItems.svelte.d.ts.map +1 -0
- package/dist/svelte/i18n.d.ts +19 -0
- package/dist/svelte/i18n.d.ts.map +1 -0
- package/dist/svelte/i18n.js +19 -0
- package/dist/svelte/index.d.ts +40 -0
- package/dist/svelte/index.d.ts.map +1 -0
- package/dist/svelte/index.js +43 -0
- package/dist/svelte/playground.d.ts +103 -0
- package/dist/svelte/playground.d.ts.map +1 -0
- package/dist/svelte/playground.js +103 -0
- package/dist/svelte/types.d.ts +47 -0
- package/dist/svelte/types.d.ts.map +1 -0
- package/dist/svelte/types.js +4 -0
- package/dist/types/index.d.ts +234 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/ui.d.ts +10 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +85 -0
- package/dist/ui.js.map +1 -0
- package/package.json +87 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# @happyvertical/smrt-commerce
|
|
2
|
+
|
|
3
|
+
E-commerce with Contract STI hierarchy, invoice lifecycle, payment tracking, payout remittance, and optional ledger integration.
|
|
4
|
+
|
|
5
|
+
## Models
|
|
6
|
+
|
|
7
|
+
- **Customer** / **Vendor**: linked to Profile via string ID (not FK). Customer has creditLimit, paymentTerms, customerType (DTC / WHOLESALE / RETAIL). Vendor has leadTimeDays, minimumOrder, and `payoutAddresses: Record<string, string>` — a flat map from payout-rail-qualified currency code (`USDC-base`, `BTC`, `USD-stripe`, ...) to destination string (EVM address, BTC address, Stripe Connect account id, IBAN). Use `getPayoutAddress(currency)` for a `Map.get`-style lookup; missing entries return `undefined` (caller decides skip-vs-error).
|
|
8
|
+
- **Contract** (STI base → Estimate, Order, Lease, Agreement, PurchaseOrder, WholesaleOrder, ProductionOrder, Cart, LicenseSale): 9 contract types sharing one table. Carries `channelId` (open-ended string — `dtc-web`, `wholesale-b2b`, `pos-store-N`, etc.) so the same model serves DTC checkout, B2B portals, and POS.
|
|
9
|
+
- **WholesaleOrder**: B2B order. Conventional pairing — customer has `customerType: 'wholesale'`, NET-30/60 terms, delivered via wholesale-portal channel.
|
|
10
|
+
- **ProductionOrder**: manufacturing equivalent of a PurchaseOrder — commission your factory to make finished goods. Consumes raw materials per BOM (`@happyvertical/smrt-manufacturing`) and produces SKU stock (`@happyvertical/smrt-inventory`).
|
|
11
|
+
- **Cart**: transient order-in-progress. Same shape as Order; the application promotes the row from `_meta_type: Cart` to `_meta_type: Order` at checkout instead of copying data between tables.
|
|
12
|
+
- **LicenseSale**: industry-neutral licensing primitive. Carries an *immutable* rights snapshot (`rightsMedium`, `rightsDistributionScope`, `rightsExclusivity`, `rightsDuration`, `rightsTerritory`, `rightsSublicensing`, `rightsDerivatives` — typed `Meta<T>` fields), licensee identity (`licenseeEmail`, optional `licenseeLegalEntity` / `licenseeJurisdiction`), and a signed-PDF reference (`pdfUrl`, `pdfHash`, optional `onChainHashRegistryRef`). Once saved at `ContractStatus.ACCEPTED`, the rights snapshot is frozen — mutating any of the seven rights fields and re-saving throws. The only legal transition out of ACCEPTED is `revoke()` (moves to CANCELLED without touching rights). Useful for stock media, music licensing, code-asset marketplaces, license keys, anywhere rights are sold for a fee.
|
|
13
|
+
- **ContractLineItem**: items on contracts.
|
|
14
|
+
- **Invoice**: status machine `DRAFT → SENT → VIEWED → PARTIAL → PAID` (also OVERDUE, CANCELLED, WRITTEN_OFF). `recognizeRevenue()` creates balanced AR journal entry (DR: Accounts Receivable, CR: Revenue, CR: Tax Payable).
|
|
15
|
+
- **InvoiceLineItem**: line items on invoices.
|
|
16
|
+
- **Payment** / **PaymentAllocation**: tracks payments against invoices. Status controlled by `Invoice.updatePaymentStatus()`, not Payment model. Carries optional backend-adapter fields for PaymentBackend-routed flows: `backendId` (rail adapter id — `base-usdc`, `btc`, `stripe`, distinct from `externalProvider` which names an accounting sync destination), `backendTxRef` (chain tx hash or gateway settlement id), `nativeAmount` / `nativeCurrency` (what actually arrived), `usdAtQuote` / `usdAtConfirmation` (drift accounting for volatile-currency rails). `Payment.usdDrift()` returns the confirmation - quote delta, or `0` when either side is unset.
|
|
17
|
+
- **PaymentIntent**: short-lived pre-payment commitment with multi-option semantics. Locks a USD price for a fixed window (default 15 minutes) and lists one or more `PaymentOption`s describing different rails (`backendId`, `currency`, `payTo`, `nativeAmount`, optional `chain` / `memo` / `x402Capable` / `expiresAt`). First option to receive payment wins; the others are implicitly retired. State machine `awaiting_payment → paid → (issued | retired)` plus `expired` and `cancelled`. Mutate via dedicated `markPaid` / `markIssued` / `expire` / `cancel` / `retire` helpers — direct status assignment bypasses the invariant checks. Idempotency via natural key `(tenant_id, offering_ref, licensee_email, idempotency_key)` and `PaymentIntentCollection.getOrCreateByIdempotencyKey()`.
|
|
18
|
+
- **Payout**: operator-to-supplier remittance. Distinct from Payment because direction, status machine, and chain semantics differ. Status machine `pending → sent → confirmed → failed` (failed is terminal but resettable via `resetFromFailed()` after fixing the underlying problem). References source `paymentId` (plain string) and destination `vendorId` (foreign key). Amount invariant `supplierNet === grossAmount - operatorFee` (1¢ rounding tolerance) enforced on save. `PayoutCollection.createFromPayment()` is the typical entry point; it pulls native amount / currency from the source Payment.
|
|
19
|
+
- **Fulfillment** / **FulfillmentLineItem**: shipment/delivery tracking.
|
|
20
|
+
|
|
21
|
+
## Ledger Integration
|
|
22
|
+
|
|
23
|
+
`@happyvertical/smrt-ledgers` is a regular dependency, loaded lazily via dynamic `import()` so the coupling stays runtime-only (no hard static import; the package graph stays a DAG — see #1582). Invoice stores `arJournalId` and `revenueJournalId` as string references. `recognizeRevenue()` creates a balanced AR journal entry; `getArJournal()` returns null when no journal has been recognized yet.
|
|
24
|
+
|
|
25
|
+
## Cross-Package References
|
|
26
|
+
|
|
27
|
+
- `customerId` → `@foreignKey('Customer')` (hard reference within package)
|
|
28
|
+
- `profileId` → plain string to smrt-profiles
|
|
29
|
+
- `arJournalId`, `revenueJournalId` → plain string to smrt-ledgers
|
|
30
|
+
- `skuId` (on `PaymentIntent`, `LicenseSale`) → plain string to smrt-products
|
|
31
|
+
- `paymentId` (on `PaymentIntent`, `Payout`, `LicenseSale`) → plain string to `Payment` (same package, but kept as plain string for cross-model consistency)
|
|
32
|
+
- `vendorId` on `Payout` → `@foreignKey(Vendor)` (hard reference within package)
|
|
33
|
+
|
|
34
|
+
## Gotchas
|
|
35
|
+
|
|
36
|
+
- **Optional tenancy**: all models `@TenantScoped({ mode: 'optional' })` + nullable tenantId
|
|
37
|
+
- **Currency in decimal fields**: price, taxAmount, totalAmount (not integer cents like affiliates)
|
|
38
|
+
- **Invoice controls payment status**: not the Payment model — use `Invoice.updatePaymentStatus()`
|
|
39
|
+
- **Tax rate is external**: no tax rate field on Invoice — rate must be calculated externally
|
|
40
|
+
- **Profile linking**: separate `ProfileCollection.create()` needed to fetch actual Profile object
|
|
41
|
+
- **PaymentIntent natural key**: `conflictColumns: ['tenant_id', 'offering_ref', 'licensee_email', 'idempotency_key']` — a retried `create` with the same tuple upserts the existing row. Use `getOrCreateByIdempotencyKey()` to branch on `{ intent, created }`. Empty natural-key inputs (e.g. blank `idempotencyKey`) disable dedup by design.
|
|
42
|
+
- **Payout state-machine guards**: `markSent` requires a non-empty `backendTxRef`; `markConfirmed` only valid from `SENT`; `markFailed` only valid from `PENDING` / `SENT` (a confirmed payout can't fail — that path is a refund). `resetFromFailed()` is the dedicated escape hatch from `FAILED` back to `PENDING` after an operator fixes the underlying problem; it clears `backendTxRef` so the next attempt picks up a fresh one.
|
|
43
|
+
- **LicenseSale immutability**: rights snapshot freezes on save-with-status-ACCEPTED. The captured snapshot lives in a module-scoped `WeakMap<LicenseSale, string>` so it doesn't interact with the schema or round-trip through `_meta_data`. Drafts (status != ACCEPTED) remain mutable. To "change" an issued license: `revoke()` it, then issue a new `LicenseSale` row.
|
|
44
|
+
- **Vendor.payoutAddresses normalization**: the constructor accepts either a `Record<string, string>` or a pre-serialized JSON string. `initialize()` re-normalizes after the framework's option-override pass; `save()` re-normalizes defensively against direct field assignment. Non-string values inside the input map are silently dropped to preserve the typed invariant downstream.
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@AGENTS.md
|
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright <2025> <Happy Vertical Corporation>
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# @happyvertical/smrt-commerce
|
|
2
|
+
|
|
3
|
+
Commerce models for the SMRT framework. Covers customers, vendors, contracts (5 STI types), invoices with ledger integration, payments, and fulfillment tracking.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @happyvertical/smrt-commerce
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import {
|
|
15
|
+
Customer, CustomerCollection,
|
|
16
|
+
Order, ContractCollection,
|
|
17
|
+
Invoice, InvoiceCollection,
|
|
18
|
+
Payment, PaymentCollection,
|
|
19
|
+
ContractStatus, InvoiceStatus, PaymentMethod
|
|
20
|
+
} from '@happyvertical/smrt-commerce';
|
|
21
|
+
|
|
22
|
+
// Create a customer linked to a profile
|
|
23
|
+
const customers = new CustomerCollection(db);
|
|
24
|
+
const customer = await customers.create({
|
|
25
|
+
profileId: 'profile-uuid',
|
|
26
|
+
creditLimit: 10000.00,
|
|
27
|
+
paymentTerms: 'Net 30',
|
|
28
|
+
});
|
|
29
|
+
await customer.save();
|
|
30
|
+
|
|
31
|
+
// Create an order (STI contract type)
|
|
32
|
+
const contracts = new ContractCollection(db);
|
|
33
|
+
const order = await contracts.create({
|
|
34
|
+
_meta_type: 'Order',
|
|
35
|
+
customerId: customer.id,
|
|
36
|
+
subtotal: 1000.00,
|
|
37
|
+
taxAmount: 50.00,
|
|
38
|
+
totalAmount: 1050.00,
|
|
39
|
+
currency: 'CAD',
|
|
40
|
+
});
|
|
41
|
+
await order.save();
|
|
42
|
+
|
|
43
|
+
// Create an invoice for the order
|
|
44
|
+
const invoices = new InvoiceCollection(db);
|
|
45
|
+
const invoiceNumber = await invoices.generateInvoiceNumber();
|
|
46
|
+
const invoice = await invoices.create({
|
|
47
|
+
customerId: customer.id,
|
|
48
|
+
contractId: order.id,
|
|
49
|
+
invoiceNumber,
|
|
50
|
+
subtotal: 1000.00,
|
|
51
|
+
taxAmount: 50.00,
|
|
52
|
+
totalAmount: 1050.00,
|
|
53
|
+
});
|
|
54
|
+
await invoice.save();
|
|
55
|
+
|
|
56
|
+
// Recognize revenue (creates balanced journal in smrt-ledgers)
|
|
57
|
+
await invoice.recognizeRevenue({
|
|
58
|
+
arAccountId: 'ar-account-id',
|
|
59
|
+
revenueAccountId: 'revenue-account-id',
|
|
60
|
+
taxAccountId: 'tax-account-id',
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Record a payment
|
|
64
|
+
const payments = new PaymentCollection(db);
|
|
65
|
+
const payment = await payments.create({
|
|
66
|
+
contractId: order.id,
|
|
67
|
+
customerId: customer.id,
|
|
68
|
+
amount: 1050.00,
|
|
69
|
+
method: PaymentMethod.CREDIT_CARD,
|
|
70
|
+
});
|
|
71
|
+
await payment.save();
|
|
72
|
+
|
|
73
|
+
// Record payment with ledger integration
|
|
74
|
+
await payment.recordPayment({
|
|
75
|
+
ledgerId: 'ledger-id',
|
|
76
|
+
receivablesAccountId: 'ar-account-id',
|
|
77
|
+
cashAccountId: 'bank-account-id',
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## API
|
|
82
|
+
|
|
83
|
+
### Models
|
|
84
|
+
|
|
85
|
+
| Export | Description |
|
|
86
|
+
|--------|------------|
|
|
87
|
+
| `Customer` | Customer record with creditLimit, paymentTerms, tax exemption, addresses |
|
|
88
|
+
| `Vendor` | Vendor/supplier with leadTimeDays, minimumOrderAmount, currency |
|
|
89
|
+
| `Contract` | STI base class for all commercial agreements |
|
|
90
|
+
| `Estimate` | Quote or proposal sent to a customer |
|
|
91
|
+
| `Order` | Customer purchase order |
|
|
92
|
+
| `Lease` | Rental or lease agreement |
|
|
93
|
+
| `Agreement` | Service or maintenance agreement |
|
|
94
|
+
| `PurchaseOrder` | Order sent to a vendor/supplier |
|
|
95
|
+
| `ContractLineItem` | Line item within a contract |
|
|
96
|
+
| `Invoice` | Billing document with status lifecycle and ledger integration |
|
|
97
|
+
| `InvoiceLineItem` | Individual invoice line item |
|
|
98
|
+
| `Payment` | Payment record with method, status, and optional ledger journal |
|
|
99
|
+
| `PaymentAllocation` | Payment-to-invoice allocation |
|
|
100
|
+
| `Fulfillment` | Shipment/delivery tracking with carrier and address |
|
|
101
|
+
| `FulfillmentLineItem` | Individual fulfillment line item |
|
|
102
|
+
|
|
103
|
+
### Collections
|
|
104
|
+
|
|
105
|
+
`CustomerCollection`, `VendorCollection`, `ContractCollection`, `InvoiceCollection`, `InvoiceLineItemCollection`, `PaymentCollection`, `PaymentAllocationCollection`, `FulfillmentCollection`
|
|
106
|
+
|
|
107
|
+
### Enums
|
|
108
|
+
|
|
109
|
+
| Export | Values |
|
|
110
|
+
|--------|--------|
|
|
111
|
+
| `ContractType` | `estimate`, `order`, `lease`, `agreement`, `purchase_order` |
|
|
112
|
+
| `ContractStatus` | `draft`, `sent`, `accepted`, `declined`, `completed`, `cancelled` |
|
|
113
|
+
| `CustomerStatus` | `active`, `inactive`, `suspended` |
|
|
114
|
+
| `VendorStatus` | `active`, `inactive`, `suspended` |
|
|
115
|
+
| `InvoiceStatus` | `draft`, `sent`, `viewed`, `partial`, `paid`, `overdue`, `cancelled`, `written_off` |
|
|
116
|
+
| `PaymentMethod` | `cash`, `check`, `credit_card`, `bank_transfer`, `crypto`, `other` |
|
|
117
|
+
| `PaymentStatus` | `pending`, `completed`, `failed`, `refunded`, `cancelled` |
|
|
118
|
+
| `FulfillmentStatus` | `pending`, `processing`, `shipped`, `delivered`, `cancelled` |
|
|
119
|
+
| `FulfillmentType` | `shipment`, `delivery`, `pickup`, `digital`, `service` |
|
|
120
|
+
|
|
121
|
+
### Types and Constants
|
|
122
|
+
|
|
123
|
+
| Export | Description |
|
|
124
|
+
|--------|------------|
|
|
125
|
+
| `Address` | Shared address interface (street1, street2, city, state, postalCode, country) |
|
|
126
|
+
| `RecognizeRevenueOptions` | Account IDs for invoice revenue recognition |
|
|
127
|
+
| `RecordPaymentOptions` | Ledger and account IDs for payment recording |
|
|
128
|
+
| `InvoiceNumberOptions` | Options for `generateInvoiceNumber()` (prefix, format) |
|
|
129
|
+
| `UNPAID_STATUSES` | Array of invoice statuses considered unpaid (sent, viewed, partial, overdue) |
|
|
130
|
+
| `COMMERCE_MODULE_META` | UI module metadata |
|
|
131
|
+
| `COMMERCE_UI_SLOTS` | UI slot definitions |
|
|
132
|
+
|
|
133
|
+
### Ledger Integration
|
|
134
|
+
|
|
135
|
+
Invoice and Payment integrate with `@happyvertical/smrt-ledgers` via dynamic import (optional dependency). Invoice stores `arJournalId` and `revenueJournalId` as plain string references to ledger journals. `recognizeRevenue()` creates a balanced AR entry (DR: Accounts Receivable, CR: Revenue, CR: Tax Payable). `recordPayment()` creates a balanced cash receipt entry (DR: Cash, CR: Accounts Receivable). Both methods return null or throw if the ledgers package is not installed.
|
|
136
|
+
|
|
137
|
+
### Cross-Package References
|
|
138
|
+
|
|
139
|
+
Customer and Vendor link to `@happyvertical/smrt-profiles` via plain `profileId` string. Invoice and Payment reference `@happyvertical/smrt-ledgers` journals via plain string IDs (`arJournalId`, `revenueJournalId`, `journalId`). All models use `@TenantScoped({ mode: 'optional' })` with nullable `tenantId`.
|
|
140
|
+
|
|
141
|
+
## Dependencies
|
|
142
|
+
|
|
143
|
+
- `@happyvertical/smrt-core` -- ORM and code generation
|
|
144
|
+
- `@happyvertical/smrt-tenancy` -- multi-tenant scoping
|
|
145
|
+
- `@happyvertical/smrt-types` -- shared type definitions
|
|
146
|
+
- Peer: `@happyvertical/smrt-ledgers`, `@happyvertical/smrt-profiles`, `@happyvertical/smrt-svelte`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"__smrt-register__.d.ts","sourceRoot":"","sources":["../src/__smrt-register__.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { SmrtCollection } from '@happyvertical/smrt-core';
|
|
2
|
+
import { Contract } from '../models/Contract.js';
|
|
3
|
+
import { ContractStatus, ContractType } from '../types/index.js';
|
|
4
|
+
export declare class ContractCollection extends SmrtCollection<Contract> {
|
|
5
|
+
static readonly _itemClass: typeof Contract;
|
|
6
|
+
/**
|
|
7
|
+
* Find contracts by customer
|
|
8
|
+
*
|
|
9
|
+
* @param customerId - Customer ID
|
|
10
|
+
* @returns Array of contracts
|
|
11
|
+
*/
|
|
12
|
+
findByCustomer(customerId: string): Promise<Contract[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Find contracts by vendor
|
|
15
|
+
*
|
|
16
|
+
* @param vendorId - Vendor ID
|
|
17
|
+
* @returns Array of contracts
|
|
18
|
+
*/
|
|
19
|
+
findByVendor(vendorId: string): Promise<Contract[]>;
|
|
20
|
+
/**
|
|
21
|
+
* Find contracts by type (STI)
|
|
22
|
+
*
|
|
23
|
+
* @param contractType - Contract type
|
|
24
|
+
* @returns Array of contracts
|
|
25
|
+
*/
|
|
26
|
+
findByType(contractType: ContractType): Promise<Contract[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Find contracts by status
|
|
29
|
+
*
|
|
30
|
+
* @param status - Contract status
|
|
31
|
+
* @returns Array of contracts
|
|
32
|
+
*/
|
|
33
|
+
findByStatus(status: ContractStatus): Promise<Contract[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Find all draft contracts
|
|
36
|
+
*
|
|
37
|
+
* @returns Array of draft contracts
|
|
38
|
+
*/
|
|
39
|
+
findDrafts(): Promise<Contract[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Find all accepted contracts
|
|
42
|
+
*
|
|
43
|
+
* @returns Array of accepted contracts
|
|
44
|
+
*/
|
|
45
|
+
findAccepted(): Promise<Contract[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Find overdue contracts
|
|
48
|
+
*
|
|
49
|
+
* @returns Array of overdue contracts
|
|
50
|
+
*/
|
|
51
|
+
findOverdue(): Promise<Contract[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Find expired estimates/quotes
|
|
54
|
+
*
|
|
55
|
+
* @returns Array of expired estimates
|
|
56
|
+
*/
|
|
57
|
+
findExpired(): Promise<Contract[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Find contracts in date range
|
|
60
|
+
*
|
|
61
|
+
* @param startDate - Start date
|
|
62
|
+
* @param endDate - End date
|
|
63
|
+
* @returns Array of contracts
|
|
64
|
+
*/
|
|
65
|
+
findByDateRange(startDate: Date, endDate: Date): Promise<Contract[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Find all contracts belonging to a specific tenant
|
|
68
|
+
*
|
|
69
|
+
* @param tenantId - Tenant ID
|
|
70
|
+
* @returns Array of contracts for the tenant
|
|
71
|
+
*/
|
|
72
|
+
findByTenant(tenantId: string): Promise<Contract[]>;
|
|
73
|
+
/**
|
|
74
|
+
* Find all global contracts (not associated with any tenant)
|
|
75
|
+
*
|
|
76
|
+
* @returns Array of global contracts
|
|
77
|
+
*/
|
|
78
|
+
findGlobal(): Promise<Contract[]>;
|
|
79
|
+
/**
|
|
80
|
+
* Find contracts for a tenant including global contracts
|
|
81
|
+
*
|
|
82
|
+
* @param tenantId - Tenant ID
|
|
83
|
+
* @returns Array of tenant-specific and global contracts
|
|
84
|
+
*/
|
|
85
|
+
findWithGlobals(tenantId: string): Promise<Contract[]>;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=ContractCollection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContractCollection.d.ts","sourceRoot":"","sources":["../../src/collections/ContractCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjE,qBAAa,kBAAmB,SAAQ,cAAc,CAAC,QAAQ,CAAC;IAC9D,MAAM,CAAC,QAAQ,CAAC,UAAU,kBAAY;IAEtC;;;;;OAKG;IACG,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAO7D;;;;;OAKG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAOzD;;;;;OAKG;IACG,UAAU,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAOjE;;;;;OAKG;IACG,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAO/D;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAIvC;;;;OAIG;IACG,YAAY,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAIzC;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAgBxC;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAkBxC;;;;;;OAMG;IACG,eAAe,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAc1E;;;;;OAKG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAIzD;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAIvC;;;;;OAKG;IACG,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;CAM7D"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { SmrtCollection } from '@happyvertical/smrt-core';
|
|
2
|
+
import { Customer } from '../models/Customer.js';
|
|
3
|
+
import { CustomerStatus } from '../types/index.js';
|
|
4
|
+
export declare class CustomerCollection extends SmrtCollection<Customer> {
|
|
5
|
+
static readonly _itemClass: typeof Customer;
|
|
6
|
+
/**
|
|
7
|
+
* Find customers by profile ID
|
|
8
|
+
*
|
|
9
|
+
* @param profileId - Profile ID from smrt-profiles
|
|
10
|
+
* @returns Array of customers linked to this profile
|
|
11
|
+
*/
|
|
12
|
+
findByProfile(profileId: string): Promise<Customer[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Find all active customers
|
|
15
|
+
*
|
|
16
|
+
* @returns Array of active customers
|
|
17
|
+
*/
|
|
18
|
+
findActive(): Promise<Customer[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Find customers by status
|
|
21
|
+
*
|
|
22
|
+
* @param status - Customer status
|
|
23
|
+
* @returns Array of customers
|
|
24
|
+
*/
|
|
25
|
+
findByStatus(status: CustomerStatus): Promise<Customer[]>;
|
|
26
|
+
/**
|
|
27
|
+
* Get or create a customer for a profile
|
|
28
|
+
*
|
|
29
|
+
* @param profileId - Profile ID
|
|
30
|
+
* @param defaults - Default values if creating
|
|
31
|
+
* @returns Customer
|
|
32
|
+
*/
|
|
33
|
+
getOrCreateForProfile(profileId: string, defaults?: Partial<{
|
|
34
|
+
creditLimit: number;
|
|
35
|
+
paymentTerms: string;
|
|
36
|
+
}>): Promise<Customer>;
|
|
37
|
+
/**
|
|
38
|
+
* Find all customers belonging to a specific tenant
|
|
39
|
+
*
|
|
40
|
+
* @param tenantId - Tenant ID
|
|
41
|
+
* @returns Array of customers for the tenant
|
|
42
|
+
*/
|
|
43
|
+
findByTenant(tenantId: string): Promise<Customer[]>;
|
|
44
|
+
/**
|
|
45
|
+
* Find all global customers (not associated with any tenant)
|
|
46
|
+
*
|
|
47
|
+
* @returns Array of global customers
|
|
48
|
+
*/
|
|
49
|
+
findGlobal(): Promise<Customer[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Find customers for a tenant including global customers
|
|
52
|
+
*
|
|
53
|
+
* @param tenantId - Tenant ID
|
|
54
|
+
* @returns Array of tenant-specific and global customers
|
|
55
|
+
*/
|
|
56
|
+
findWithGlobals(tenantId: string): Promise<Customer[]>;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=CustomerCollection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomerCollection.d.ts","sourceRoot":"","sources":["../../src/collections/CustomerCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,qBAAa,kBAAmB,SAAQ,cAAc,CAAC,QAAQ,CAAC;IAC9D,MAAM,CAAC,QAAQ,CAAC,UAAU,kBAAY;IAEtC;;;;;OAKG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAO3D;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAOvC;;;;;OAKG;IACG,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAO/D;;;;;;OAMG;IACG,qBAAqB,CACzB,SAAS,EAAE,MAAM,EACjB,QAAQ,GAAE,OAAO,CAAC;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;KACtB,CAAM,GACN,OAAO,CAAC,QAAQ,CAAC;IAoBpB;;;;;OAKG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAIzD;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAIvC;;;;;OAKG;IACG,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;CAM7D"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { SmrtCollection } from '@happyvertical/smrt-core';
|
|
2
|
+
import { Fulfillment } from '../models/Fulfillment.js';
|
|
3
|
+
import { FulfillmentStatus, FulfillmentType } from '../types/index.js';
|
|
4
|
+
export declare class FulfillmentCollection extends SmrtCollection<Fulfillment> {
|
|
5
|
+
static readonly _itemClass: typeof Fulfillment;
|
|
6
|
+
/**
|
|
7
|
+
* Find fulfillments by contract
|
|
8
|
+
*
|
|
9
|
+
* @param contractId - Contract ID
|
|
10
|
+
* @returns Array of fulfillments
|
|
11
|
+
*/
|
|
12
|
+
findByContract(contractId: string): Promise<Fulfillment[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Find fulfillments by status
|
|
15
|
+
*
|
|
16
|
+
* @param status - Fulfillment status
|
|
17
|
+
* @returns Array of fulfillments
|
|
18
|
+
*/
|
|
19
|
+
findByStatus(status: FulfillmentStatus): Promise<Fulfillment[]>;
|
|
20
|
+
/**
|
|
21
|
+
* Find fulfillments by type
|
|
22
|
+
*
|
|
23
|
+
* @param fulfillmentType - Fulfillment type
|
|
24
|
+
* @returns Array of fulfillments
|
|
25
|
+
*/
|
|
26
|
+
findByType(fulfillmentType: FulfillmentType): Promise<Fulfillment[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Find all pending fulfillments
|
|
29
|
+
*
|
|
30
|
+
* @returns Array of pending fulfillments
|
|
31
|
+
*/
|
|
32
|
+
findPending(): Promise<Fulfillment[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Find all in-transit shipments
|
|
35
|
+
*
|
|
36
|
+
* @returns Array of shipped fulfillments
|
|
37
|
+
*/
|
|
38
|
+
findInTransit(): Promise<Fulfillment[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Find by tracking number
|
|
41
|
+
*
|
|
42
|
+
* @param trackingNumber - Tracking number
|
|
43
|
+
* @returns Fulfillment or null
|
|
44
|
+
*/
|
|
45
|
+
findByTracking(trackingNumber: string): Promise<Fulfillment | null>;
|
|
46
|
+
/**
|
|
47
|
+
* Find fulfillments shipped in date range
|
|
48
|
+
*
|
|
49
|
+
* @param startDate - Start date
|
|
50
|
+
* @param endDate - End date
|
|
51
|
+
* @returns Array of fulfillments
|
|
52
|
+
*/
|
|
53
|
+
findShippedInRange(startDate: Date, endDate: Date): Promise<Fulfillment[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Find all fulfillments belonging to a specific tenant
|
|
56
|
+
*
|
|
57
|
+
* @param tenantId - Tenant ID
|
|
58
|
+
* @returns Array of fulfillments for the tenant
|
|
59
|
+
*/
|
|
60
|
+
findByTenant(tenantId: string): Promise<Fulfillment[]>;
|
|
61
|
+
/**
|
|
62
|
+
* Find all global fulfillments (not associated with any tenant)
|
|
63
|
+
*
|
|
64
|
+
* @returns Array of global fulfillments
|
|
65
|
+
*/
|
|
66
|
+
findGlobal(): Promise<Fulfillment[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Find fulfillments for a tenant including global fulfillments
|
|
69
|
+
*
|
|
70
|
+
* @param tenantId - Tenant ID
|
|
71
|
+
* @returns Array of tenant-specific and global fulfillments
|
|
72
|
+
*/
|
|
73
|
+
findWithGlobals(tenantId: string): Promise<Fulfillment[]>;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=FulfillmentCollection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FulfillmentCollection.d.ts","sourceRoot":"","sources":["../../src/collections/FulfillmentCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAE5E,qBAAa,qBAAsB,SAAQ,cAAc,CAAC,WAAW,CAAC;IACpE,MAAM,CAAC,QAAQ,CAAC,UAAU,qBAAe;IAEzC;;;;;OAKG;IACG,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAOhE;;;;;OAKG;IACG,YAAY,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAOrE;;;;;OAKG;IACG,UAAU,CAAC,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAO1E;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAI3C;;;;OAIG;IACG,aAAa,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAI7C;;;;;OAKG;IACG,cAAc,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAQzE;;;;;;OAMG;IACG,kBAAkB,CACtB,SAAS,EAAE,IAAI,EACf,OAAO,EAAE,IAAI,GACZ,OAAO,CAAC,WAAW,EAAE,CAAC;IAczB;;;;;OAKG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAI5D;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAI1C;;;;;OAKG;IACG,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;CAMhE"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { SmrtCollection } from '@happyvertical/smrt-core';
|
|
2
|
+
import { Invoice } from '../models/Invoice.js';
|
|
3
|
+
import { InvoiceStatus } from '../types/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Statuses that indicate an invoice has outstanding balance.
|
|
6
|
+
* Used for calculating outstanding amounts and finding unpaid invoices.
|
|
7
|
+
*/
|
|
8
|
+
export declare const UNPAID_STATUSES: readonly [InvoiceStatus.SENT, InvoiceStatus.VIEWED, InvoiceStatus.PARTIAL, InvoiceStatus.OVERDUE];
|
|
9
|
+
/**
|
|
10
|
+
* Options for generating invoice numbers
|
|
11
|
+
*/
|
|
12
|
+
export interface InvoiceNumberOptions {
|
|
13
|
+
/** Prefix for invoice numbers (default: 'INV') */
|
|
14
|
+
prefix?: string;
|
|
15
|
+
/** Format: 'prefix-year-seq' or 'prefix-seq' (default: 'prefix-year-seq') */
|
|
16
|
+
format?: 'prefix-year-seq' | 'prefix-seq';
|
|
17
|
+
}
|
|
18
|
+
export declare class InvoiceCollection extends SmrtCollection<Invoice> {
|
|
19
|
+
static readonly _itemClass: typeof Invoice;
|
|
20
|
+
/**
|
|
21
|
+
* Find invoices by customer
|
|
22
|
+
*
|
|
23
|
+
* @param customerId - Customer ID
|
|
24
|
+
* @returns Array of invoices
|
|
25
|
+
*/
|
|
26
|
+
findByCustomer(customerId: string): Promise<Invoice[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Find invoices by contract
|
|
29
|
+
*
|
|
30
|
+
* @param contractId - Contract ID
|
|
31
|
+
* @returns Array of invoices
|
|
32
|
+
*/
|
|
33
|
+
findByContract(contractId: string): Promise<Invoice[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Find invoices by status
|
|
36
|
+
*
|
|
37
|
+
* @param status - Invoice status
|
|
38
|
+
* @returns Array of invoices
|
|
39
|
+
*/
|
|
40
|
+
findByStatus(status: InvoiceStatus): Promise<Invoice[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Find all draft invoices
|
|
43
|
+
*
|
|
44
|
+
* @returns Array of draft invoices
|
|
45
|
+
*/
|
|
46
|
+
findDrafts(): Promise<Invoice[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Find all sent invoices
|
|
49
|
+
*
|
|
50
|
+
* @returns Array of sent invoices
|
|
51
|
+
*/
|
|
52
|
+
findSent(): Promise<Invoice[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Find all paid invoices
|
|
55
|
+
*
|
|
56
|
+
* @returns Array of paid invoices
|
|
57
|
+
*/
|
|
58
|
+
findPaid(): Promise<Invoice[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Find all partial invoices
|
|
61
|
+
*
|
|
62
|
+
* @returns Array of partially paid invoices
|
|
63
|
+
*/
|
|
64
|
+
findPartial(): Promise<Invoice[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Find overdue invoices (past due date, not paid).
|
|
67
|
+
*
|
|
68
|
+
* **Note**: This method finds invoices by date, but does not automatically
|
|
69
|
+
* update their status to OVERDUE. Use a background job or scheduled task
|
|
70
|
+
* to periodically update invoice statuses based on due dates.
|
|
71
|
+
*
|
|
72
|
+
* @returns Array of overdue invoices
|
|
73
|
+
*/
|
|
74
|
+
findOverdue(): Promise<Invoice[]>;
|
|
75
|
+
/**
|
|
76
|
+
* Find invoices in date range (by issue date)
|
|
77
|
+
*
|
|
78
|
+
* @param startDate - Start date
|
|
79
|
+
* @param endDate - End date
|
|
80
|
+
* @returns Array of invoices
|
|
81
|
+
*/
|
|
82
|
+
findByDateRange(startDate: Date, endDate: Date): Promise<Invoice[]>;
|
|
83
|
+
/**
|
|
84
|
+
* Find invoice by external ID (from accounting provider)
|
|
85
|
+
*
|
|
86
|
+
* @param externalId - External ID
|
|
87
|
+
* @returns Invoice or null
|
|
88
|
+
*/
|
|
89
|
+
findByExternalId(externalId: string): Promise<Invoice | null>;
|
|
90
|
+
/**
|
|
91
|
+
* Find invoices needing sync to external provider
|
|
92
|
+
* (no externalId or stale syncedAt)
|
|
93
|
+
*
|
|
94
|
+
* @returns Array of invoices needing sync
|
|
95
|
+
*/
|
|
96
|
+
findNeedingSync(): Promise<Invoice[]>;
|
|
97
|
+
/**
|
|
98
|
+
* Find invoice by invoice number
|
|
99
|
+
*
|
|
100
|
+
* @param invoiceNumber - Invoice number
|
|
101
|
+
* @returns Invoice or null
|
|
102
|
+
*/
|
|
103
|
+
findByNumber(invoiceNumber: string): Promise<Invoice | null>;
|
|
104
|
+
/**
|
|
105
|
+
* Count invoices for a given year
|
|
106
|
+
*
|
|
107
|
+
* @param year - Year to count
|
|
108
|
+
* @returns Number of invoices
|
|
109
|
+
*/
|
|
110
|
+
countForYear(year: number): Promise<number>;
|
|
111
|
+
/**
|
|
112
|
+
* Generate the next invoice number.
|
|
113
|
+
*
|
|
114
|
+
* **Warning**: This method has a potential race condition if multiple
|
|
115
|
+
* invoices are created concurrently. For high-concurrency environments,
|
|
116
|
+
* consider using a database sequence or atomic counter instead.
|
|
117
|
+
*
|
|
118
|
+
* @param options - Optional configuration for number format
|
|
119
|
+
* @returns Generated invoice number (e.g., 'INV-2025-0001')
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* // Default format: INV-2025-0001
|
|
124
|
+
* const num = await invoices.generateInvoiceNumber();
|
|
125
|
+
*
|
|
126
|
+
* // Custom prefix: BILL-2025-0001
|
|
127
|
+
* const num = await invoices.generateInvoiceNumber({ prefix: 'BILL' });
|
|
128
|
+
*
|
|
129
|
+
* // Simple sequential: INV-000001
|
|
130
|
+
* const num = await invoices.generateInvoiceNumber({ format: 'prefix-seq' });
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
generateInvoiceNumber(options?: InvoiceNumberOptions): Promise<string>;
|
|
134
|
+
/**
|
|
135
|
+
* Get total outstanding (unpaid) amount for a customer
|
|
136
|
+
*
|
|
137
|
+
* @param customerId - Customer ID
|
|
138
|
+
* @returns Total amount due
|
|
139
|
+
*/
|
|
140
|
+
getTotalOutstandingForCustomer(customerId: string): Promise<number>;
|
|
141
|
+
/**
|
|
142
|
+
* Find all invoices belonging to a specific tenant
|
|
143
|
+
*
|
|
144
|
+
* @param tenantId - Tenant ID
|
|
145
|
+
* @returns Array of invoices for the tenant
|
|
146
|
+
*/
|
|
147
|
+
findByTenant(tenantId: string): Promise<Invoice[]>;
|
|
148
|
+
/**
|
|
149
|
+
* Find all global invoices (not associated with any tenant)
|
|
150
|
+
*
|
|
151
|
+
* @returns Array of global invoices
|
|
152
|
+
*/
|
|
153
|
+
findGlobal(): Promise<Invoice[]>;
|
|
154
|
+
/**
|
|
155
|
+
* Find invoices for a tenant including global invoices
|
|
156
|
+
*
|
|
157
|
+
* @param tenantId - Tenant ID
|
|
158
|
+
* @returns Array of tenant-specific and global invoices
|
|
159
|
+
*/
|
|
160
|
+
findWithGlobals(tenantId: string): Promise<Invoice[]>;
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=InvoiceCollection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InvoiceCollection.d.ts","sourceRoot":"","sources":["../../src/collections/InvoiceCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;GAGG;AACH,eAAO,MAAM,eAAe,mGAKlB,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6EAA6E;IAC7E,MAAM,CAAC,EAAE,iBAAiB,GAAG,YAAY,CAAC;CAC3C;AAED,qBAAa,iBAAkB,SAAQ,cAAc,CAAC,OAAO,CAAC;IAC5D,MAAM,CAAC,QAAQ,CAAC,UAAU,iBAAW;IAErC;;;;;OAKG;IACG,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAO5D;;;;;OAKG;IACG,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAO5D;;;;;OAKG;IACG,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAO7D;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAItC;;;;OAIG;IACG,QAAQ,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAIpC;;;;OAIG;IACG,QAAQ,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAIpC;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAIvC;;;;;;;;OAQG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAgBvC;;;;;;OAMG;IACG,eAAe,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAUzE;;;;;OAKG;IACG,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAQnE;;;;;OAKG;IACG,eAAe,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAc3C;;;;;OAKG;IACG,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAQlE;;;;;OAKG;IACG,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAcjD;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,qBAAqB,CACzB,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,MAAM,CAAC;IAkBlB;;;;;OAKG;IACG,8BAA8B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAgBzE;;;;;OAKG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAIxD;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAItC;;;;;OAKG;IACG,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CAM5D"}
|