@spaceinvoices/js-sdk 8.1.0 → 8.2.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.
@@ -9,12 +9,24 @@ import type { Error, StatsQueryBatchRequest, StatsQueryBatchResponse, Validation
9
9
  /**
10
10
  * Execute one or more aggregation queries on entity data in a single request.
11
11
 
12
- Send an array of 1-25 queries. Each query runs independently and results are returned in the same order.
12
+ Send an array of 1-25 queries. Queries share one read-only database snapshot and results are returned in the same order.
13
13
 
14
- **Available tables**: invoices, estimates, credit_notes, advance_invoices, payments, customers, items
14
+ **Available tables**: invoices, estimates, credit_notes, advance_invoices, payments, customers, items, invoice_taxes, credit_note_taxes
15
15
 
16
16
  **Metric types**: count, sum, avg, min, max
17
17
 
18
+ **Filters and results**: filters accept a scalar, null, or an object containing only `not` with a scalar or null value. Unsupported operators, arrays, nested objects, duplicate result names, and the reserved alias `__proto__` return HTTP 400. Metric aliases must not collide with grouping fields. Text dimensions, including numeric-looking customer names and year strings, remain strings; numeric metrics are numbers.
19
+
20
+ **Financial reporting**:
21
+ - Invoice and credit-note queries can filter `financial_eligible: true` to exclude drafts, voided/deleted documents and cancellation credits whose original invoices are already excluded. Raw fields retain their existing meaning.
22
+ - Sum `financial_gross_converted` for gross invoice-date sales in the entity currency; subtract the equivalent eligible credit-note sum for net sales after credits. This is tax-inclusive sales, not service-period revenue recognition. Invoice `total_due_converted` reports invoice-only outstanding balances.
23
+ - Sum `collection_amount_converted` for direct invoice cash receipts or positive credit-note refund magnitudes, capped per document. Applied credits and advance allocations are excluded. Include `collection_conversion_missing` to detect unusable cash conversions as well as missing document conversion. Subtract refunds from invoice collections, and eligible credits from invoiced gross; bound collected cash to zero through net invoiced gross before calculating the rate. A nonpositive denominator has a zero rate.
24
+ - Payment charts use `active_invoice_cash_receipt: true` and `cash_amount_converted`. These are receipts on active invoices, excluding supplier payments, refunds and noncash allocations.
25
+ - On `invoice_taxes` and `credit_note_taxes`, use `financial_eligible: true` and `reverse_charge: false`, sum `tax_converted` by `rate`, then subtract eligible credit-note tax. This measures tax charged by document date, not cash tax collections or tax liability after expenses. `base_converted` provides the corresponding taxable base.
26
+ - Include a sum of `financial_conversion_missing` in every financial query. A positive result means the aggregate is incomplete and must be shown as unavailable, rather than treating omitted conversion values as zero. For limited rankings, check missing conversions across the whole eligible population in a separate query before presenting the ranking. Historical copied foreign amounts without conversion evidence are not treated as valid 1:1 conversions.
27
+ - Group invoice sales by `customer_key` and `customer_display_name` to keep linked customers stable across name changes; unlinked snapshots use a normalized-name fallback.
28
+ - Date filters are inclusive calendar dates. Invoice overdue fields use the entity timezone; callers should construct reporting periods in that same timezone.
29
+
18
30
  **Virtual fields for group_by**:
19
31
  - `month` - Extract month from date (YYYY-MM)
20
32
  - `year` - Extract year from date (YYYY)
@@ -9,12 +9,24 @@ import type { Error, StatsQueryBatchRequest, StatsQueryBatchResponse, Validation
9
9
  /**
10
10
  * Execute one or more aggregation queries on entity data in a single request.
11
11
 
12
- Send an array of 1-25 queries. Each query runs independently and results are returned in the same order.
12
+ Send an array of 1-25 queries. Queries share one read-only database snapshot and results are returned in the same order.
13
13
 
14
- **Available tables**: invoices, estimates, credit_notes, advance_invoices, payments, customers, items
14
+ **Available tables**: invoices, estimates, credit_notes, advance_invoices, payments, customers, items, invoice_taxes, credit_note_taxes
15
15
 
16
16
  **Metric types**: count, sum, avg, min, max
17
17
 
18
+ **Filters and results**: filters accept a scalar, null, or an object containing only `not` with a scalar or null value. Unsupported operators, arrays, nested objects, duplicate result names, and the reserved alias `__proto__` return HTTP 400. Metric aliases must not collide with grouping fields. Text dimensions, including numeric-looking customer names and year strings, remain strings; numeric metrics are numbers.
19
+
20
+ **Financial reporting**:
21
+ - Invoice and credit-note queries can filter `financial_eligible: true` to exclude drafts, voided/deleted documents and cancellation credits whose original invoices are already excluded. Raw fields retain their existing meaning.
22
+ - Sum `financial_gross_converted` for gross invoice-date sales in the entity currency; subtract the equivalent eligible credit-note sum for net sales after credits. This is tax-inclusive sales, not service-period revenue recognition. Invoice `total_due_converted` reports invoice-only outstanding balances.
23
+ - Sum `collection_amount_converted` for direct invoice cash receipts or positive credit-note refund magnitudes, capped per document. Applied credits and advance allocations are excluded. Include `collection_conversion_missing` to detect unusable cash conversions as well as missing document conversion. Subtract refunds from invoice collections, and eligible credits from invoiced gross; bound collected cash to zero through net invoiced gross before calculating the rate. A nonpositive denominator has a zero rate.
24
+ - Payment charts use `active_invoice_cash_receipt: true` and `cash_amount_converted`. These are receipts on active invoices, excluding supplier payments, refunds and noncash allocations.
25
+ - On `invoice_taxes` and `credit_note_taxes`, use `financial_eligible: true` and `reverse_charge: false`, sum `tax_converted` by `rate`, then subtract eligible credit-note tax. This measures tax charged by document date, not cash tax collections or tax liability after expenses. `base_converted` provides the corresponding taxable base.
26
+ - Include a sum of `financial_conversion_missing` in every financial query. A positive result means the aggregate is incomplete and must be shown as unavailable, rather than treating omitted conversion values as zero. For limited rankings, check missing conversions across the whole eligible population in a separate query before presenting the ranking. Historical copied foreign amounts without conversion evidence are not treated as valid 1:1 conversions.
27
+ - Group invoice sales by `customer_key` and `customer_display_name` to keep linked customers stable across name changes; unlinked snapshots use a normalized-name fallback.
28
+ - Date filters are inclusive calendar dates. Invoice overdue fields use the entity timezone; callers should construct reporting periods in that same timezone.
29
+
18
30
  **Virtual fields for group_by**:
19
31
  - `month` - Extract month from date (YYYY-MM)
20
32
  - `year` - Extract year from date (YYYY)
@@ -339,6 +339,8 @@ export declare const backfillExpenseRecognition: (expenseRecognitionBackfill: Ex
339
339
 
340
340
  Returns **202 Accepted** with the job, expense, and file identifiers. Recognition is asynchronous in live mode; poll `GET /expenses/recognitions/{id}` for status. Terminal success is `ready_for_review` or `needs_attention`; terminal failure is `failed`, with safe `error_code` and `error_message` fields.
341
341
 
342
+ Parsed document and line amounts are checked against the standard expense calculation before applying extraction. A disagreement keeps the draft unchanged and stores the extraction with `needs_attention` for review.
343
+
342
344
  Payment suggestions from OCR are advisory only and never mark the expense paid or create payments. Failed provider attempts record zero customer usage. Automatic provider attempts and a permitted customer retry share the same job; billable customer usage is recorded once only after a successful terminal result.
343
345
 
344
346
  `X-Request-Id` provides account/entity-scoped replay and fails closed with 409 Conflict when reused for different file content.
@@ -339,6 +339,8 @@ export declare const backfillExpenseRecognition: (expenseRecognitionBackfill: Ex
339
339
 
340
340
  Returns **202 Accepted** with the job, expense, and file identifiers. Recognition is asynchronous in live mode; poll `GET /expenses/recognitions/{id}` for status. Terminal success is `ready_for_review` or `needs_attention`; terminal failure is `failed`, with safe `error_code` and `error_message` fields.
341
341
 
342
+ Parsed document and line amounts are checked against the standard expense calculation before applying extraction. A disagreement keeps the draft unchanged and stores the extraction with `needs_attention` for review.
343
+
342
344
  Payment suggestions from OCR are advisory only and never mark the expense paid or create payments. Failed provider attempts record zero customer usage. Automatic provider attempts and a permitted customer retry share the same job; billable customer usage is recorded once only after a successful terminal result.
343
345
 
344
346
  `X-Request-Id` provides account/entity-scoped replay and fails closed with 409 Conflict when reused for different file content.
@@ -185,6 +185,10 @@ export type getRevenueByFinancialCategoryResponse404 = {
185
185
  data: Error;
186
186
  status: 404;
187
187
  };
188
+ export type getRevenueByFinancialCategoryResponse422 = {
189
+ data: Error;
190
+ status: 422;
191
+ };
188
192
  export type getRevenueByFinancialCategoryResponse500 = {
189
193
  data: Error;
190
194
  status: 500;
@@ -192,7 +196,7 @@ export type getRevenueByFinancialCategoryResponse500 = {
192
196
  export type getRevenueByFinancialCategoryResponseSuccess = (getRevenueByFinancialCategoryResponse200) & {
193
197
  headers: Headers;
194
198
  };
195
- export type getRevenueByFinancialCategoryResponseError = (getRevenueByFinancialCategoryResponse400 | getRevenueByFinancialCategoryResponse401 | getRevenueByFinancialCategoryResponse403 | getRevenueByFinancialCategoryResponse404 | getRevenueByFinancialCategoryResponse500) & {
199
+ export type getRevenueByFinancialCategoryResponseError = (getRevenueByFinancialCategoryResponse400 | getRevenueByFinancialCategoryResponse401 | getRevenueByFinancialCategoryResponse403 | getRevenueByFinancialCategoryResponse404 | getRevenueByFinancialCategoryResponse422 | getRevenueByFinancialCategoryResponse500) & {
196
200
  headers: Headers;
197
201
  };
198
202
  export type getRevenueByFinancialCategoryResponse = (getRevenueByFinancialCategoryResponseSuccess | getRevenueByFinancialCategoryResponseError);
@@ -185,6 +185,10 @@ export type getRevenueByFinancialCategoryResponse404 = {
185
185
  data: Error;
186
186
  status: 404;
187
187
  };
188
+ export type getRevenueByFinancialCategoryResponse422 = {
189
+ data: Error;
190
+ status: 422;
191
+ };
188
192
  export type getRevenueByFinancialCategoryResponse500 = {
189
193
  data: Error;
190
194
  status: 500;
@@ -192,7 +196,7 @@ export type getRevenueByFinancialCategoryResponse500 = {
192
196
  export type getRevenueByFinancialCategoryResponseSuccess = (getRevenueByFinancialCategoryResponse200) & {
193
197
  headers: Headers;
194
198
  };
195
- export type getRevenueByFinancialCategoryResponseError = (getRevenueByFinancialCategoryResponse400 | getRevenueByFinancialCategoryResponse401 | getRevenueByFinancialCategoryResponse403 | getRevenueByFinancialCategoryResponse404 | getRevenueByFinancialCategoryResponse500) & {
199
+ export type getRevenueByFinancialCategoryResponseError = (getRevenueByFinancialCategoryResponse400 | getRevenueByFinancialCategoryResponse401 | getRevenueByFinancialCategoryResponse403 | getRevenueByFinancialCategoryResponse404 | getRevenueByFinancialCategoryResponse422 | getRevenueByFinancialCategoryResponse500) & {
196
200
  headers: Headers;
197
201
  };
198
202
  export type getRevenueByFinancialCategoryResponse = (getRevenueByFinancialCategoryResponseSuccess | getRevenueByFinancialCategoryResponseError);
@@ -46,7 +46,7 @@ export type GetInvoicesParams = {
46
46
  - `endsWith` - String ends with
47
47
  - `between` - Value between two numbers/dates [min, max]
48
48
 
49
- **Allowed fields:** id, number, customer_id, date, customer, customer.name, customer.email, customer.address, customer.city, customer.country, total, total_with_tax, items.name, items.description, payments.type, payments.date, document_relations.relation_type, document_relations.target_type, metadata, created_at, updated_at, paid_in_full, voided_at, date_due, paid_in_full, total_due, total_paid, voided_at
49
+ **Allowed fields:** id, number, customer_id, date, customer, customer.name, customer.email, customer.address, customer.city, customer.country, total, total_with_tax, items.name, items.description, payments.type, payments.date, document_relations.relation_type, document_relations.target_type, metadata, created_at, updated_at, paid_in_full, voided_at, is_draft, date_due, paid_in_full, total_due, total_paid, voided_at
50
50
 
51
51
  **Examples:**
52
52
  - `{"total": {"gte": 1000}}` - Invoices over 1000
@@ -46,7 +46,7 @@ export type GetInvoicesParams = {
46
46
  - `endsWith` - String ends with
47
47
  - `between` - Value between two numbers/dates [min, max]
48
48
 
49
- **Allowed fields:** id, number, customer_id, date, customer, customer.name, customer.email, customer.address, customer.city, customer.country, total, total_with_tax, items.name, items.description, payments.type, payments.date, document_relations.relation_type, document_relations.target_type, metadata, created_at, updated_at, paid_in_full, voided_at, date_due, paid_in_full, total_due, total_paid, voided_at
49
+ **Allowed fields:** id, number, customer_id, date, customer, customer.name, customer.email, customer.address, customer.city, customer.country, total, total_with_tax, items.name, items.description, payments.type, payments.date, document_relations.relation_type, document_relations.target_type, metadata, created_at, updated_at, paid_in_full, voided_at, is_draft, date_due, paid_in_full, total_due, total_paid, voided_at
50
50
 
51
51
  **Examples:**
52
52
  - `{"total": {"gte": 1000}}` - Invoices over 1000
@@ -18,4 +18,5 @@ export declare const StatsQueryRequestTable: {
18
18
  readonly customers: "customers";
19
19
  readonly items: "items";
20
20
  readonly invoice_taxes: "invoice_taxes";
21
+ readonly credit_note_taxes: "credit_note_taxes";
21
22
  };
@@ -18,4 +18,5 @@ export declare const StatsQueryRequestTable: {
18
18
  readonly customers: "customers";
19
19
  readonly items: "items";
20
20
  readonly invoice_taxes: "invoice_taxes";
21
+ readonly credit_note_taxes: "credit_note_taxes";
21
22
  };
@@ -145,6 +145,10 @@ export type getRevenueRecognitionReportResponse404 = {
145
145
  data: Error;
146
146
  status: 404;
147
147
  };
148
+ export type getRevenueRecognitionReportResponse422 = {
149
+ data: Error;
150
+ status: 422;
151
+ };
148
152
  export type getRevenueRecognitionReportResponse500 = {
149
153
  data: Error;
150
154
  status: 500;
@@ -152,7 +156,7 @@ export type getRevenueRecognitionReportResponse500 = {
152
156
  export type getRevenueRecognitionReportResponseSuccess = (getRevenueRecognitionReportResponse200) & {
153
157
  headers: Headers;
154
158
  };
155
- export type getRevenueRecognitionReportResponseError = (getRevenueRecognitionReportResponse400 | getRevenueRecognitionReportResponse401 | getRevenueRecognitionReportResponse403 | getRevenueRecognitionReportResponse404 | getRevenueRecognitionReportResponse500) & {
159
+ export type getRevenueRecognitionReportResponseError = (getRevenueRecognitionReportResponse400 | getRevenueRecognitionReportResponse401 | getRevenueRecognitionReportResponse403 | getRevenueRecognitionReportResponse404 | getRevenueRecognitionReportResponse422 | getRevenueRecognitionReportResponse500) & {
156
160
  headers: Headers;
157
161
  };
158
162
  export type getRevenueRecognitionReportResponse = (getRevenueRecognitionReportResponseSuccess | getRevenueRecognitionReportResponseError);
@@ -181,6 +185,10 @@ export type getRevenueRecognitionDetailsResponse404 = {
181
185
  data: Error;
182
186
  status: 404;
183
187
  };
188
+ export type getRevenueRecognitionDetailsResponse422 = {
189
+ data: Error;
190
+ status: 422;
191
+ };
184
192
  export type getRevenueRecognitionDetailsResponse500 = {
185
193
  data: Error;
186
194
  status: 500;
@@ -188,7 +196,7 @@ export type getRevenueRecognitionDetailsResponse500 = {
188
196
  export type getRevenueRecognitionDetailsResponseSuccess = (getRevenueRecognitionDetailsResponse200) & {
189
197
  headers: Headers;
190
198
  };
191
- export type getRevenueRecognitionDetailsResponseError = (getRevenueRecognitionDetailsResponse400 | getRevenueRecognitionDetailsResponse401 | getRevenueRecognitionDetailsResponse403 | getRevenueRecognitionDetailsResponse404 | getRevenueRecognitionDetailsResponse500) & {
199
+ export type getRevenueRecognitionDetailsResponseError = (getRevenueRecognitionDetailsResponse400 | getRevenueRecognitionDetailsResponse401 | getRevenueRecognitionDetailsResponse403 | getRevenueRecognitionDetailsResponse404 | getRevenueRecognitionDetailsResponse422 | getRevenueRecognitionDetailsResponse500) & {
192
200
  headers: Headers;
193
201
  };
194
202
  export type getRevenueRecognitionDetailsResponse = (getRevenueRecognitionDetailsResponseSuccess | getRevenueRecognitionDetailsResponseError);
@@ -145,6 +145,10 @@ export type getRevenueRecognitionReportResponse404 = {
145
145
  data: Error;
146
146
  status: 404;
147
147
  };
148
+ export type getRevenueRecognitionReportResponse422 = {
149
+ data: Error;
150
+ status: 422;
151
+ };
148
152
  export type getRevenueRecognitionReportResponse500 = {
149
153
  data: Error;
150
154
  status: 500;
@@ -152,7 +156,7 @@ export type getRevenueRecognitionReportResponse500 = {
152
156
  export type getRevenueRecognitionReportResponseSuccess = (getRevenueRecognitionReportResponse200) & {
153
157
  headers: Headers;
154
158
  };
155
- export type getRevenueRecognitionReportResponseError = (getRevenueRecognitionReportResponse400 | getRevenueRecognitionReportResponse401 | getRevenueRecognitionReportResponse403 | getRevenueRecognitionReportResponse404 | getRevenueRecognitionReportResponse500) & {
159
+ export type getRevenueRecognitionReportResponseError = (getRevenueRecognitionReportResponse400 | getRevenueRecognitionReportResponse401 | getRevenueRecognitionReportResponse403 | getRevenueRecognitionReportResponse404 | getRevenueRecognitionReportResponse422 | getRevenueRecognitionReportResponse500) & {
156
160
  headers: Headers;
157
161
  };
158
162
  export type getRevenueRecognitionReportResponse = (getRevenueRecognitionReportResponseSuccess | getRevenueRecognitionReportResponseError);
@@ -181,6 +185,10 @@ export type getRevenueRecognitionDetailsResponse404 = {
181
185
  data: Error;
182
186
  status: 404;
183
187
  };
188
+ export type getRevenueRecognitionDetailsResponse422 = {
189
+ data: Error;
190
+ status: 422;
191
+ };
184
192
  export type getRevenueRecognitionDetailsResponse500 = {
185
193
  data: Error;
186
194
  status: 500;
@@ -188,7 +196,7 @@ export type getRevenueRecognitionDetailsResponse500 = {
188
196
  export type getRevenueRecognitionDetailsResponseSuccess = (getRevenueRecognitionDetailsResponse200) & {
189
197
  headers: Headers;
190
198
  };
191
- export type getRevenueRecognitionDetailsResponseError = (getRevenueRecognitionDetailsResponse400 | getRevenueRecognitionDetailsResponse401 | getRevenueRecognitionDetailsResponse403 | getRevenueRecognitionDetailsResponse404 | getRevenueRecognitionDetailsResponse500) & {
199
+ export type getRevenueRecognitionDetailsResponseError = (getRevenueRecognitionDetailsResponse400 | getRevenueRecognitionDetailsResponse401 | getRevenueRecognitionDetailsResponse403 | getRevenueRecognitionDetailsResponse404 | getRevenueRecognitionDetailsResponse422 | getRevenueRecognitionDetailsResponse500) & {
192
200
  headers: Headers;
193
201
  };
194
202
  export type getRevenueRecognitionDetailsResponse = (getRevenueRecognitionDetailsResponseSuccess | getRevenueRecognitionDetailsResponseError);
@@ -9,12 +9,24 @@ import * as zod from "zod";
9
9
  /**
10
10
  * Execute one or more aggregation queries on entity data in a single request.
11
11
 
12
- Send an array of 1-25 queries. Each query runs independently and results are returned in the same order.
12
+ Send an array of 1-25 queries. Queries share one read-only database snapshot and results are returned in the same order.
13
13
 
14
- **Available tables**: invoices, estimates, credit_notes, advance_invoices, payments, customers, items
14
+ **Available tables**: invoices, estimates, credit_notes, advance_invoices, payments, customers, items, invoice_taxes, credit_note_taxes
15
15
 
16
16
  **Metric types**: count, sum, avg, min, max
17
17
 
18
+ **Filters and results**: filters accept a scalar, null, or an object containing only `not` with a scalar or null value. Unsupported operators, arrays, nested objects, duplicate result names, and the reserved alias `__proto__` return HTTP 400. Metric aliases must not collide with grouping fields. Text dimensions, including numeric-looking customer names and year strings, remain strings; numeric metrics are numbers.
19
+
20
+ **Financial reporting**:
21
+ - Invoice and credit-note queries can filter `financial_eligible: true` to exclude drafts, voided/deleted documents and cancellation credits whose original invoices are already excluded. Raw fields retain their existing meaning.
22
+ - Sum `financial_gross_converted` for gross invoice-date sales in the entity currency; subtract the equivalent eligible credit-note sum for net sales after credits. This is tax-inclusive sales, not service-period revenue recognition. Invoice `total_due_converted` reports invoice-only outstanding balances.
23
+ - Sum `collection_amount_converted` for direct invoice cash receipts or positive credit-note refund magnitudes, capped per document. Applied credits and advance allocations are excluded. Include `collection_conversion_missing` to detect unusable cash conversions as well as missing document conversion. Subtract refunds from invoice collections, and eligible credits from invoiced gross; bound collected cash to zero through net invoiced gross before calculating the rate. A nonpositive denominator has a zero rate.
24
+ - Payment charts use `active_invoice_cash_receipt: true` and `cash_amount_converted`. These are receipts on active invoices, excluding supplier payments, refunds and noncash allocations.
25
+ - On `invoice_taxes` and `credit_note_taxes`, use `financial_eligible: true` and `reverse_charge: false`, sum `tax_converted` by `rate`, then subtract eligible credit-note tax. This measures tax charged by document date, not cash tax collections or tax liability after expenses. `base_converted` provides the corresponding taxable base.
26
+ - Include a sum of `financial_conversion_missing` in every financial query. A positive result means the aggregate is incomplete and must be shown as unavailable, rather than treating omitted conversion values as zero. For limited rankings, check missing conversions across the whole eligible population in a separate query before presenting the ranking. Historical copied foreign amounts without conversion evidence are not treated as valid 1:1 conversions.
27
+ - Group invoice sales by `customer_key` and `customer_display_name` to keep linked customers stable across name changes; unlinked snapshots use a normalized-name fallback.
28
+ - Date filters are inclusive calendar dates. Invoice overdue fields use the entity timezone; callers should construct reporting periods in that same timezone.
29
+
18
30
  **Virtual fields for group_by**:
19
31
  - `month` - Extract month from date (YYYY-MM)
20
32
  - `year` - Extract year from date (YYYY)
@@ -69,6 +81,7 @@ export declare const QueryEntityStatsBodyItem: zod.ZodObject<{
69
81
  customers: "customers";
70
82
  items: "items";
71
83
  invoice_taxes: "invoice_taxes";
84
+ credit_note_taxes: "credit_note_taxes";
72
85
  }>;
73
86
  date_from: zod.ZodOptional<zod.ZodString>;
74
87
  date_to: zod.ZodOptional<zod.ZodString>;
@@ -104,6 +117,7 @@ export declare const QueryEntityStatsBody: zod.ZodArray<zod.ZodObject<{
104
117
  customers: "customers";
105
118
  items: "items";
106
119
  invoice_taxes: "invoice_taxes";
120
+ credit_note_taxes: "credit_note_taxes";
107
121
  }>;
108
122
  date_from: zod.ZodOptional<zod.ZodString>;
109
123
  date_to: zod.ZodOptional<zod.ZodString>;
@@ -9,12 +9,24 @@ import * as zod from "zod";
9
9
  /**
10
10
  * Execute one or more aggregation queries on entity data in a single request.
11
11
 
12
- Send an array of 1-25 queries. Each query runs independently and results are returned in the same order.
12
+ Send an array of 1-25 queries. Queries share one read-only database snapshot and results are returned in the same order.
13
13
 
14
- **Available tables**: invoices, estimates, credit_notes, advance_invoices, payments, customers, items
14
+ **Available tables**: invoices, estimates, credit_notes, advance_invoices, payments, customers, items, invoice_taxes, credit_note_taxes
15
15
 
16
16
  **Metric types**: count, sum, avg, min, max
17
17
 
18
+ **Filters and results**: filters accept a scalar, null, or an object containing only `not` with a scalar or null value. Unsupported operators, arrays, nested objects, duplicate result names, and the reserved alias `__proto__` return HTTP 400. Metric aliases must not collide with grouping fields. Text dimensions, including numeric-looking customer names and year strings, remain strings; numeric metrics are numbers.
19
+
20
+ **Financial reporting**:
21
+ - Invoice and credit-note queries can filter `financial_eligible: true` to exclude drafts, voided/deleted documents and cancellation credits whose original invoices are already excluded. Raw fields retain their existing meaning.
22
+ - Sum `financial_gross_converted` for gross invoice-date sales in the entity currency; subtract the equivalent eligible credit-note sum for net sales after credits. This is tax-inclusive sales, not service-period revenue recognition. Invoice `total_due_converted` reports invoice-only outstanding balances.
23
+ - Sum `collection_amount_converted` for direct invoice cash receipts or positive credit-note refund magnitudes, capped per document. Applied credits and advance allocations are excluded. Include `collection_conversion_missing` to detect unusable cash conversions as well as missing document conversion. Subtract refunds from invoice collections, and eligible credits from invoiced gross; bound collected cash to zero through net invoiced gross before calculating the rate. A nonpositive denominator has a zero rate.
24
+ - Payment charts use `active_invoice_cash_receipt: true` and `cash_amount_converted`. These are receipts on active invoices, excluding supplier payments, refunds and noncash allocations.
25
+ - On `invoice_taxes` and `credit_note_taxes`, use `financial_eligible: true` and `reverse_charge: false`, sum `tax_converted` by `rate`, then subtract eligible credit-note tax. This measures tax charged by document date, not cash tax collections or tax liability after expenses. `base_converted` provides the corresponding taxable base.
26
+ - Include a sum of `financial_conversion_missing` in every financial query. A positive result means the aggregate is incomplete and must be shown as unavailable, rather than treating omitted conversion values as zero. For limited rankings, check missing conversions across the whole eligible population in a separate query before presenting the ranking. Historical copied foreign amounts without conversion evidence are not treated as valid 1:1 conversions.
27
+ - Group invoice sales by `customer_key` and `customer_display_name` to keep linked customers stable across name changes; unlinked snapshots use a normalized-name fallback.
28
+ - Date filters are inclusive calendar dates. Invoice overdue fields use the entity timezone; callers should construct reporting periods in that same timezone.
29
+
18
30
  **Virtual fields for group_by**:
19
31
  - `month` - Extract month from date (YYYY-MM)
20
32
  - `year` - Extract year from date (YYYY)
@@ -69,6 +81,7 @@ export declare const QueryEntityStatsBodyItem: zod.ZodObject<{
69
81
  customers: "customers";
70
82
  items: "items";
71
83
  invoice_taxes: "invoice_taxes";
84
+ credit_note_taxes: "credit_note_taxes";
72
85
  }>;
73
86
  date_from: zod.ZodOptional<zod.ZodString>;
74
87
  date_to: zod.ZodOptional<zod.ZodString>;
@@ -104,6 +117,7 @@ export declare const QueryEntityStatsBody: zod.ZodArray<zod.ZodObject<{
104
117
  customers: "customers";
105
118
  items: "items";
106
119
  invoice_taxes: "invoice_taxes";
120
+ credit_note_taxes: "credit_note_taxes";
107
121
  }>;
108
122
  date_from: zod.ZodOptional<zod.ZodString>;
109
123
  date_to: zod.ZodOptional<zod.ZodString>;
@@ -955,6 +955,8 @@ export declare const BackfillExpenseRecognitionResponse: zod.ZodObject<{
955
955
 
956
956
  Returns **202 Accepted** with the job, expense, and file identifiers. Recognition is asynchronous in live mode; poll `GET /expenses/recognitions/{id}` for status. Terminal success is `ready_for_review` or `needs_attention`; terminal failure is `failed`, with safe `error_code` and `error_message` fields.
957
957
 
958
+ Parsed document and line amounts are checked against the standard expense calculation before applying extraction. A disagreement keeps the draft unchanged and stores the extraction with `needs_attention` for review.
959
+
958
960
  Payment suggestions from OCR are advisory only and never mark the expense paid or create payments. Failed provider attempts record zero customer usage. Automatic provider attempts and a permitted customer retry share the same job; billable customer usage is recorded once only after a successful terminal result.
959
961
 
960
962
  `X-Request-Id` provides account/entity-scoped replay and fails closed with 409 Conflict when reused for different file content.
@@ -955,6 +955,8 @@ export declare const BackfillExpenseRecognitionResponse: zod.ZodObject<{
955
955
 
956
956
  Returns **202 Accepted** with the job, expense, and file identifiers. Recognition is asynchronous in live mode; poll `GET /expenses/recognitions/{id}` for status. Terminal success is `ready_for_review` or `needs_attention`; terminal failure is `failed`, with safe `error_code` and `error_message` fields.
957
957
 
958
+ Parsed document and line amounts are checked against the standard expense calculation before applying extraction. A disagreement keeps the draft unchanged and stores the extraction with `needs_attention` for review.
959
+
958
960
  Payment suggestions from OCR are advisory only and never mark the expense paid or create payments. Failed provider attempts record zero customer usage. Automatic provider attempts and a permitted customer retry share the same job; billable customer usage is recorded once only after a successful terminal result.
959
961
 
960
962
  `X-Request-Id` provides account/entity-scoped replay and fails closed with 409 Conflict when reused for different file content.