180 lines
6.0 KiB
Markdown
180 lines
6.0 KiB
Markdown
# quote
|
|
|
|
This document is auto-generated from the JSDoc comments in `src/store` by running `npm run api-doc`.
|
|
|
|
## `quote.create`
|
|
|
|
*Source: `src/store/quote/create.js`*
|
|
|
|
Creates a new quote for the user's selected company with its lines.
|
|
|
|
**Parameters**
|
|
|
|
| Name | Type | Description |
|
|
| --- | --- | --- |
|
|
| `googleAuthId` | `number` | The id of the Google auth user. |
|
|
| `body` | `object` | The quote input. |
|
|
| `body.number` | `string` | The quote number. |
|
|
| `body.date` | `string` | The quote date. |
|
|
| `[body.entityId]` | `number` | The id of the customer entity. |
|
|
| `[body.externalNumber]` | `string` | An external (customer) reference number. |
|
|
| `[body.lines]` | `Array<{sku?: string, name?: string, pu?: number, amount: number, net: number, rebate?: number, taxrate: number, comment?: string|null}>` | The quote lines. |
|
|
| `[tx]` | `object` | Optional transaction to run within. |
|
|
|
|
**Returns**
|
|
|
|
`Promise<{id: number, number: string, type: string, entityId: number|null, externalNumber: string|null, date: string, lines: Array<{id: number, sku: string|null, name: string|null, pu: number, amount: number, net: number, rebate: number, taxrate: number, comment: string|null}>}>` — The created quote.
|
|
|
|
**Throws**
|
|
|
|
`Error` — If the quote is invalid.
|
|
|
|
**Example**
|
|
|
|
```js
|
|
const quote = await store.quote.create(42, { number: 'A-2026-001', date: '2026-09-01', entityId: 12, lines: [...] });
|
|
// => { id, number, type, entityId, externalNumber, date, lines: [...] }
|
|
```
|
|
|
|
## `quote.delete`
|
|
|
|
*Source: `src/store/quote/delete.js`*
|
|
|
|
Deletes a quote by its id within the user's selected company.
|
|
|
|
**Parameters**
|
|
|
|
| Name | Type | Description |
|
|
| --- | --- | --- |
|
|
| `googleAuthId` | `number` | The id of the Google auth user. |
|
|
| `id` | `number` | The id of the quote to delete. |
|
|
| `[tx]` | `object` | Optional transaction. |
|
|
|
|
**Returns**
|
|
|
|
`Promise<void>`
|
|
|
|
**Throws**
|
|
|
|
`Error` — If the quote is not found.
|
|
|
|
**Example**
|
|
|
|
```js
|
|
await store.quote.delete(42, 5);
|
|
```
|
|
|
|
## `quote.getById`
|
|
|
|
*Source: `src/store/quote/getById.js`*
|
|
|
|
Returns a single quote by its id within the user's selected company.
|
|
|
|
**Parameters**
|
|
|
|
| Name | Type | Description |
|
|
| --- | --- | --- |
|
|
| `googleAuthId` | `number` | The id of the Google auth user. |
|
|
| `id` | `number` | The id of the quote. |
|
|
| `[tx]` | `object` | Optional transaction. |
|
|
|
|
**Returns**
|
|
|
|
`Promise<{id: number, number: string, type: string, entityId: number|null, externalNumber: string|null, date: string, lines: Array<{id: number, sku: string|null, name: string|null, pu: number, amount: number, net: number, rebate: number, taxrate: number, comment: string|null}>}>` — The quote with its lines.
|
|
|
|
**Throws**
|
|
|
|
`Error` — If the quote is not found.
|
|
|
|
**Example**
|
|
|
|
```js
|
|
const quote = await store.quote.getById(42, 5);
|
|
// => { id, number, type, entityId, externalNumber, date, lines: [...] }
|
|
```
|
|
|
|
## `quote.list`
|
|
|
|
*Source: `src/store/quote/list.js`*
|
|
|
|
Lists the quotes of the user's selected company.
|
|
|
|
**Parameters**
|
|
|
|
| Name | Type | Description |
|
|
| --- | --- | --- |
|
|
| `googleAuthId` | `number` | The id of the Google auth user. |
|
|
| `[opts]` | `object` | Optional pagination and filter options. |
|
|
| `[opts.offset=0]` | `number` | Number of quotes to skip. |
|
|
| `[opts.limit=50]` | `number` | Number of quotes to return. |
|
|
| `[opts.search]` | `string` | Free-text search matching quote number, external number, or customer name. |
|
|
| `[opts.seekMonths]` | `number` | Negative integer for cutoff months ago (e.g. -1). |
|
|
| `[tx]` | `object` | Optional transaction. |
|
|
|
|
**Returns**
|
|
|
|
`Promise<{quotes: Array<{id: number, number: string, type: string, entityId: number|null, externalNumber: string|null, date: string, createdAt: string|null, lines: Array<{id: number, sku: string|null, name: string|null, pu: number, amount: number, net: number, rebate: number, taxrate: number, comment: string|null}>, positions?: number, grossTotal?: number, totalQuantity?: number, customerName?: string}>, total: number, unfilteredTotal: number, offset: number, limit: number}|Array<object>>` — The quotes.
|
|
|
|
**Example**
|
|
|
|
```js
|
|
const result = await store.quote.list(42, { offset: 0, limit: 50, search: 'A-1002' });
|
|
// => { quotes: [...], total: 10, unfilteredTotal: 42, offset: 0, limit: 50 }
|
|
|
|
const quotes = await store.quote.list(42);
|
|
// => [{ id, number, type, entityId, externalNumber, date, createdAt, lines: [...] }]
|
|
```
|
|
|
|
## `quote.rebuildSummaries`
|
|
|
|
*Source: `src/store/quote/rebuildSummaries.js`*
|
|
|
|
Rebuilds the `quotesummary` table for the user's selected company.
|
|
|
|
**Parameters**
|
|
|
|
| Name | Type | Description |
|
|
| --- | --- | --- |
|
|
| `provider` | `import('../../providers/provider.js').DatabaseProvider` | |
|
|
|
|
## `quote.syncSummary`
|
|
|
|
*Source: `src/store/quote/syncSummary.js`*
|
|
|
|
Centralized sync and rebuild logic for the materialized `quotesummary` table.
|
|
|
|
## `quote.update`
|
|
|
|
*Source: `src/store/quote/update.js`*
|
|
|
|
Updates a quote's header and/or lines.
|
|
|
|
**Parameters**
|
|
|
|
| Name | Type | Description |
|
|
| --- | --- | --- |
|
|
| `googleAuthId` | `number` | The id of the Google auth user. |
|
|
| `id` | `number` | The id of the quote to update. |
|
|
| `patch` | `object` | The update patch. |
|
|
| `[patch.number]` | `string` | The new quote number. |
|
|
| `[patch.date]` | `string` | The new quote date. |
|
|
| `[patch.entityId]` | `number` | The new customer entity id. |
|
|
| `[patch.externalNumber]` | `string` | The new external (customer) reference number. |
|
|
| `[patch.lines]` | `Array<{sku?: string, name?: string, pu?: number, amount: number, net: number, rebate?: number, taxrate: number, comment?: string|null}>` | The new quote lines. |
|
|
| `[tx]` | `object` | Optional transaction to run within. |
|
|
|
|
**Returns**
|
|
|
|
`Promise<{id: number, number: string, type: string, entityId: number|null, externalNumber: string|null, date: string, lines: Array<{id: number, sku: string|null, name: string|null, pu: number, amount: number, net: number, rebate: number, taxrate: number, comment: string|null}>}>` — The updated quote.
|
|
|
|
**Throws**
|
|
|
|
`Error` — If the quote is not found.
|
|
|
|
**Example**
|
|
|
|
```js
|
|
const quote = await store.quote.update(42, 5, { number: 'A-2026-002', lines: [...] });
|
|
// => { id, number, type, entityId, date, lines: [...] }
|
|
```
|