110 lines
4.7 KiB
Markdown
110 lines
4.7 KiB
Markdown
# ledger
|
|
|
|
This document is auto-generated from the JSDoc comments in `src/store` by running `npm run api-doc`.
|
|
|
|
## `ledger.add`
|
|
|
|
*Source: `src/store/ledger/add.js`*
|
|
|
|
Appends new append-only entry/entries to the ledger table according to manifest rules: - quote / order: no bookings possible (throws error) - delivery: acceptance entry (warehouse_id=null) + warehouse entry (if tracked) in one transaction - shipment: shipment entry (warehouse_id=null, negative amount) + warehouse entry (if tracked) in one transaction - adjustment: single warehouse inventory movement
|
|
|
|
**Parameters**
|
|
|
|
| Name | Type | Description |
|
|
| --- | --- | --- |
|
|
| `googleAuthId` | `number` | The id of the Google auth user. |
|
|
| `input` | `object` | Ledger entry payload. |
|
|
| `input.manifestarticle_id` | `number` | ID of the referenced manifest line (can also pass manifestarticleId). |
|
|
| `[input.warehouse_id]` | `number|null` | Optional warehouse ID (can also pass warehouseId). |
|
|
| `input.transaction_type` | `string` | Transaction type (can also pass transactionType). |
|
|
| `input.amount` | `number` | Movement amount. |
|
|
| `input.transaction_text` | `string` | Transaction memo/details (can also pass transactionText). |
|
|
| `[tx]` | `object` | Optional transaction to run within. |
|
|
|
|
**Returns**
|
|
|
|
`Promise<{id: number, manifestarticle_id: number, warehouse_id: number|null, transaction_type: string, amount: number, transaction_text: string, hash_version: number, prev_hash: string, created_at: string}>` — The primary ledger row.
|
|
|
|
## `ledger.listByManifestarticleId`
|
|
|
|
*Source: `src/store/ledger/listByManifestarticleId.js`*
|
|
|
|
Lists ledger entries for a specific manifest article line, optionally filtered by transaction type and/or warehouse.
|
|
|
|
**Parameters**
|
|
|
|
| Name | Type | Description |
|
|
| --- | --- | --- |
|
|
| `googleAuthId` | `number` | The id of the Google auth user. |
|
|
| `manifestarticleId` | `number` | The id of the manifest article line. |
|
|
| `[optionsOrType]` | `string|object` | Transaction type string or options object { transaction_type?: string, transactionType?: string, warehouse_id?: number, warehouseId?: number }. |
|
|
| `[tx]` | `object` | Optional transaction to run within. |
|
|
|
|
**Returns**
|
|
|
|
`Promise<Array<{id: number, manifestarticle_id: number, warehouse_id: number|null, sku: string|null, transaction_type: string, amount: number, transaction_text: string, hash_version: number, prev_hash: string, created_at: string}>>`
|
|
|
|
**Throws**
|
|
|
|
`Error` — If user not authorized, company not selected, or manifest article not found.
|
|
|
|
**Example**
|
|
|
|
```js
|
|
const entries = await store.ledger.listByManifestarticleId(googleAuthId, 42, 'DELIVERY');
|
|
// => [{ id, manifestarticle_id, warehouse_id, sku, transaction_type, amount, transaction_text, hash_version, prev_hash, created_at }]
|
|
```
|
|
|
|
## `ledger.listBySku`
|
|
|
|
*Source: `src/store/ledger/listBySku.js`*
|
|
|
|
Lists ledger entries for a given article SKU, optionally filtered by transaction type and/or warehouse.
|
|
|
|
**Parameters**
|
|
|
|
| Name | Type | Description |
|
|
| --- | --- | --- |
|
|
| `googleAuthId` | `number` | The id of the Google auth user. |
|
|
| `sku` | `string` | The article SKU. |
|
|
| `[optionsOrType]` | `string|object` | Transaction type string or options object { transaction_type?: string, transactionType?: string, warehouse_id?: number, warehouseId?: number }. |
|
|
| `[tx]` | `object` | Optional transaction to run within. |
|
|
|
|
**Returns**
|
|
|
|
`Promise<Array<{id: number, manifestarticle_id: number, warehouse_id: number|null, sku: string|null, transaction_type: string, amount: number, transaction_text: string, hash_version: number, prev_hash: string, created_at: string}>>`
|
|
|
|
**Throws**
|
|
|
|
`Error` — If user not authorized, company not selected, or SKU invalid.
|
|
|
|
**Example**
|
|
|
|
```js
|
|
const entries = await store.ledger.listBySku(googleAuthId, 'SKU-001', 'DELIVERY');
|
|
// => [{ id, manifestarticle_id, warehouse_id, sku, transaction_type, amount, transaction_text, hash_version, prev_hash, created_at }]
|
|
```
|
|
|
|
## `ledger.listHistory`
|
|
|
|
*Source: `src/store/ledger/listHistory.js`*
|
|
|
|
Lists ledger entries for the user's selected company across all articles, supporting pagination, date cutoff via seekMonths, and search.
|
|
|
|
**Parameters**
|
|
|
|
| Name | Type | Description |
|
|
| --- | --- | --- |
|
|
| `provider` | `import('../../providers/provider.js').Provider` | |
|
|
|
|
**Returns**
|
|
|
|
`(googleAuthId: number, opts?: {offset?: number, limit?: number, search?: string, seekMonths?: number}, tx?: object) => Promise<{ledger: Array<{id: number, date: string, sku: string|null, name: string|null, transaction_type: string, transaction_text: string, amount: number}>, total: number, unfilteredTotal: number, offset: number, limit: number}>`
|
|
|
|
**Example**
|
|
|
|
```js
|
|
const res = await store.ledger.listHistory(googleAuthId, { offset: 0, limit: 50, search: 'kjh', seekMonths: -1 });
|
|
// => { ledger: [...], total, unfilteredTotal, offset, limit }
|
|
```
|