Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions docs/architecture/regional-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,22 @@ Node-only dependencies.

## Consumers

`resolveRegionalSnapshot()` has 11 call sites in the backend, across 9 files:
Backend consumers of `resolveRegionalSnapshot()`:

| File | Use |
| --- | --- |
| `main/routes/auth.ts` | The local-tenant snapshot at login. |
| `main/server-app.ts` | The Server App tenant snapshot at `/api/server-app/info`, mapping the resolver's error to a 409 `regional_not_configured` response. |
| `main/routes/reports.ts` | Currency minor-unit factor for every monetary report. |
| `main/routes/reports.ts` | Currency minor-unit factor for every monetary report, and locale/currency formatting options for X and Z report HTML export. |
| `main/routes/cash-closures.ts` | Currency minor-unit factor for cash-closure arithmetic. |
| `main/services/cash-day-close-guards.ts` | Business timezone for cash-session business-date resolution. |
| `main/services/cash-close-export.ts` | Regional currency, locale, timezone, and formatting preferences when serializing X and Z report HTML without pre-resolved options. |
| `main/services/refund.ts` | Refund minor units and the business timezone used for the refund window. |
| `main/services/daily-sales-export.ts` | Currency minor-unit factor for the accounting export. |
| `main/services/daily-sales-export.ts` | Currency minor-unit factor for the accounting export, and regional locale and formatting preferences for `serializeDailySalesExportHtml`. |
| `main/services/expenses.ts` | Store currency and business timezone for expense business-date resolution. |
| `main/services/whatsapp.ts` | Store regional snapshot for WhatsApp message formatting. |
| `main/routes/menu-csv.ts` | Amount formatting and separators for menu and add-on CSV export. |
| `main/routes/printers.ts` | Regional snapshot for menu and delivery-slip print assembly. |
| `main/db.ts` | `requireTenantTimezone()` for order and bill numbering, and the target-currency snapshot taken inside the destructive currency reset. |
| `main/printers/thermal.ts` | Receipt currency symbol, fraction digits, and business timezone. |

Expand Down
22 changes: 12 additions & 10 deletions docs/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -858,8 +858,8 @@ day-boundary rules.
| `GET` | `/insights` | `ROLE_ACCESS.ownerManager` | query: `?days`, `?start_date`, `?end_date` | - |
| `GET` | `/x-report` | `ROLE_ACCESS.ownerManager` | query: `?date` | Live day report. Recomputed on every read. `openingFloatCents` is reported for context and is excluded from `expectedCashCents`, which includes cash sales, Pay In, Pay Out, Safe Drop, and cash refunds by `refunds.created_at`. The stored Z adds the opening float at close, so same-day X and Z expected values differ by exactly `opening_float_cents`. |
| `GET` | `/z-report` | `ROLE_ACCESS.ownerManager` | query: `?date` | The immutable close snapshot for one business date. `404` with `{ error: "Day not closed", alreadyClosed: false, businessDate }` when no close row exists. The `zReport` object carries integer-minor-unit `*_cents` fields, `payment_methods`, `staff_sales`, `tax_components`, and `cash_movements` arrays, plus `z_number`, `closed_by`, `closed_by_name`, `notes`, `created_at`, `business_date`, `period_start`, and `period_end`. `variance_cents` is `counted_cash_cents - expected_cash_cents` and may be negative. |
| `GET` | `/x-report/export` | `reports.view` (`ROLE_ACCESS.ownerManager` by default) | query: `?date`, `?format` (required: `csv` or `xlsx`) | Exports a live X-report snapshot for one business date. Returns `400` with `{ error: "format must be xlsx or csv" }` when `format` is missing or invalid. Sets `Content-Disposition` to `attachment; filename="x-report-<date>.<format>"`. |
| `GET` | `/z-report/export` | `reports.view` (`ROLE_ACCESS.ownerManager` by default) | query: `?date`, `?format` (required: `csv` or `xlsx`) | Exports the stored Z-report snapshot for a closed business date. Returns `400` with `{ error: "format must be xlsx or csv" }` when `format` is missing or invalid, and `404` with `{ error: "Day not closed" }` when the day has not been closed. Sets `Content-Disposition` to `attachment; filename="z-report-Z<z_number>-<date>.<format>"`. |
| `GET` | `/x-report/export` | `reports.view` (`ROLE_ACCESS.ownerManager` by default) | query: `?date`, `?format` (required: `csv`, `xlsx`, or `html`) | Exports a live X-report snapshot for one business date (or print-styled HTML for PDF/browser print when `format=html`). Returns `400` with `{ error: "format must be xlsx, csv, or html" }` when `format` is missing or invalid. Sets `Content-Disposition` to `attachment; filename="x-report-<date>.<format>"`. |
| `GET` | `/z-report/export` | `reports.view` (`ROLE_ACCESS.ownerManager` by default) | query: `?date`, `?format` (required: `csv`, `xlsx`, or `html`) | Exports the stored Z-report snapshot for a closed business date (or print-styled HTML for PDF/browser print when `format=html`). Returns `400` with `{ error: "format must be xlsx, csv, or html" }` when `format` is missing or invalid, and `404` with `{ error: "Day not closed" }` when the day has not been closed. Sets `Content-Disposition` to `attachment; filename="z-report-Z<z_number>-<date>.<format>"`. |
| `POST` | `/cash-closes/:id/whatsapp` | `reports.view` + `whatsapp.use` | path: `id`; body: `phone_e164`, `body` (non-empty, max 4096 chars) | Sends the submitted report body and returns `{ success: true, messageId }`; when WhatsApp is disconnected, returns `{ fallback: true, reason: "not_connected" }` so the client can open WhatsApp for sharing. Invalid input returns `400`; an unknown day close returns `404`. |
| `GET` | `/daily-sales/export` | `reports.daily-sales.export` (owner by default) | query: `?date`, `?from`, `?to`, `?format`, `?part` | See [GET `/api/reports/daily-sales/export`](#get-apireportsdaily-salesexport). |
| `GET` | `/customer-sales/export` | `reports.customer-sales.export` (owner by default) | query: `?start_date`, `?end_date`, `?format` | One row per item sold with customer details, for a business-date range of at most 366 days. `format` is `xlsx` or `csv`; invalid format, reversed range, or oversized range returns `400`. See [customer sales export](daily-sales-export.md#customer-sales-export). |
Expand All @@ -868,24 +868,26 @@ day-boundary rules.

Owner-only daily sales export for one tenant business date (`?date=YYYY-MM-DD`, defaults to the
current business date) or an inclusive business-date range (`?from=YYYY-MM-DD&to=YYYY-MM-DD`, up to
93 calendar days). Returns either a single XLSX workbook (`Summary`, `Daily`, `Taxes`, `Items`, and
`Payments` sheets) or one part of a five-file CSV set (`summary`, `daily`, `taxes`, `items`,
`payments`). Accounting and row grouping live entirely in `buildDailySalesExportDataset`; the
endpoint only validates, serializes, and sets headers. See [daily sales export](daily-sales-export.md)
for the full reconciliation contract, the summary metric field order, and the worksheet/CSV columns.
93 calendar days). Returns an XLSX workbook (`Summary`, `Daily`, `Taxes`, `Items`, and `Payments`
sheets), one part of a five-file CSV set (`summary`, `daily`, `taxes`, `items`, `payments`), or a
print-styled HTML document (`format=html`) used for desktop PDF export and browser print. Accounting
and row grouping live entirely in `buildDailySalesExportDataset`; the endpoint only validates,
serializes, and sets headers. See [daily sales export](daily-sales-export.md) for the full
reconciliation contract, the summary metric field order, and the worksheet/CSV columns.

| Param | Values | Notes |
| -------- | ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `date` | `YYYY-MM-DD` | Single tenant business date; defaults to the current business date when `from`/`to` are omitted. |
| `from` | `YYYY-MM-DD` | Inclusive start business date (must be paired with `to`, cannot be combined with `date`). |
| `to` | `YYYY-MM-DD` | Inclusive end business date (`from <= to`, at most 93 calendar days inclusive). |
| `format` | `xlsx` or `csv` | Required. Any other value returns `400`. |
| `part` | `summary`, `daily`, `taxes`, `items`, or `payments` | Required when `format=csv`; ignored for `xlsx`. Missing or invalid on CSV returns `400`. |
| `format` | `xlsx`, `csv`, or `html` | Required. Any other value returns `400`. |
| `part` | `summary`, `daily`, `taxes`, `items`, or `payments` | Required when `format=csv`; ignored for `xlsx` and `html`. Missing or invalid on CSV returns `400`. |

- `format=xlsx` returns `200` with `Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet` and `Content-Disposition: attachment; filename="daily-sales-YYYY-MM-DD.xlsx"` (or `daily-sales-YYYY-MM-DD_to_YYYY-MM-DD.xlsx` for multi-day ranges).
- `format=csv` returns `200` with `Content-Type: text/csv; charset=utf-8` and `Content-Disposition: attachment; filename="daily-sales-<slug>-<part>.csv"` for the requested `part` (`summary` has header `metric,value`; `daily`, `taxes`, `items`, and `payments` use the column headers and encoding rules in [daily sales export](daily-sales-export.md#file-formats)).
- `format=html` returns `200` with `Content-Type: text/html; charset=utf-8` and `Content-Disposition: attachment; filename="daily-sales-YYYY-MM-DD.html"` (or `daily-sales-YYYY-MM-DD_to_YYYY-MM-DD.html`); see [daily sales export](daily-sales-export.md#file-formats).

Errors: `400` for an invalid `format`, a CSV without `part`, mixed `date` and `from`/`to` arguments, an incomplete range, an invalid calendar date, `to < from`, or a range exceeding 93 days; `401` unauthenticated; `403` non-owner; `409` for a concurrent-write conflict; `500` otherwise.
Errors: `400` for an invalid `format`, a CSV without `part`, mixed `date` and `from`/`to` arguments, an incomplete range, an invalid calendar date, `to < from`, a range exceeding 93 days, or an `html` export exceeding the 15 MB PDF size limit; `401` unauthenticated; `403` non-owner; `409` for a concurrent-write conflict; `500` otherwise.

### Inline endpoints (registered outside a router)

Expand Down
Loading
Loading