Skip to content

feat(reports): add owner-only daily sales Excel/CSV export - #809

Merged
khaira777 merged 4 commits into
mainfrom
feat/daily-sales-export
Sep 22, 2026
Merged

khaira777 merged 4 commits into
mainfrom
feat/daily-sales-export

Conversation

@khaira777

Copy link
Copy Markdown
Contributor

Related work

None (approved feature task from session: export daily sales as Excel/CSV).

Summary

Adds an owner-only daily sales export for one business day:

  • GET /api/reports/daily-sales/export?date=YYYY-MM-DD&format=xlsx|csv[&part=summary|items]
  • XLSX: single workbook with Summary + Items sheets (numeric money cells, no formulas).
  • CSV: two-file pair (summary / items), formula-neutralized via shared toCsvRow (main/lib/csv.ts), ASCII . decimals.
  • Backend accounting in buildDailySalesExportDataset; serializers only encode; frontend only blob-downloads (two day-mode buttons on the dashboard).
  • Reconciliation: sale day on bills.paid_at, refunds on refunds.created_at, net_collected = gross - refunds, Σ payment totals = net_collected, Σ net_item_sales = bills.subtotal.
  • Dependency: [email protected].
  • Contract docs: docs/daily-sales-export.md + API.md §Reports.

Scope

Out of scope: multi-day ranges, tips, PII, staff/Transactions/Addons sheets, alternate refund-day attribution, net_ex_tax.

Verification

Commands run:

  • npm run test:daily-sales-export → 34/34 passed
  • npm run test:script-coverage → OK (172 reachable)
  • npm run i18n:check → OK
  • npm run lint → 0 errors (5 pre-existing warnings)
  • npx tsc --noEmit -p tsconfig.json → OK
  • npm run build → OK
  • npm run build:frontend → OK
  • git diff --check → clean
  • Relative markdown link check → OK

Results: all green.

Compatibility & data safety

  • Database/data impact: None (read-only queries)
  • Migration: None
  • User-visible behavior: New owner-only export endpoint + dashboard export buttons (day mode)
  • Offline/network impact: None (local Express only)

Screenshots

N/A (backend + download buttons; no new visual surfaces beyond existing day-mode buttons).

Cross-cutting surfaces

Surface Status
UI affected — two export buttons in day mode; verified via build
API affected — new GET endpoint; covered by tests
Persistence not affected
Upgrade path not affected
CSV affected — shared toCsvRow; covered by formula-neutralization test
Web print not affected
Thermal print not affected
LAN / server app not affected
RTL not affected
Dark mode not affected
Timezone affected — tenant business date; covered by test
Permissions affected — owner-only; covered by 401/403 tests

Contributor checklist

  • This is a small isolated fix/doc update OR follows an approved issue/direction.
  • Unrelated cleanups, refactors, and dependency changes were kept out of this PR.
  • Tests were added or updated for any behavior changes.
  • Verification commands were run and documented above.
  • Customer data and upgrade safety were preserved (if touching database/storage).
  • Documentation or translations were updated where relevant.
  • I understand and can explain all submitted changes.

Add GET /api/reports/daily-sales/export for one tenant business day:
xlsx (Summary+Items workbook) and a two-file CSV pair. Accounting lives
in buildDailySalesExportDataset; serializers only encode; shared toCsvRow
provides CWE-1236 formula neutralization for CSV. Dashboard gains day-mode
export buttons; contract documented in docs/daily-sales-export.md and API.md.
@coderabbitai

coderabbitai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 6 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository: FreeOpenSourcePOS/FloCafe/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: e9f9f985-bfdc-47f1-ad59-3a567f468bd6

📥 Commits

Reviewing files that changed from the base of the PR and between 700eccb and 3d2b8cf.

⛔ Files ignored due to path filters (2)
  • package-lock.json is excluded by !**/package-lock.json, !package-lock.json
  • package.json is excluded by !package.json
📒 Files selected for processing (19)
  • docs/API.md
  • docs/README.md
  • docs/daily-sales-export.md
  • frontend/src/app/(dashboard)/dashboard/page.tsx
  • frontend/src/lib/i18n/messages/de.json
  • frontend/src/lib/i18n/messages/en.json
  • frontend/src/lib/i18n/messages/es.json
  • frontend/src/lib/i18n/messages/fa.json
  • frontend/src/lib/i18n/messages/fil.json
  • frontend/src/lib/i18n/messages/fr.json
  • frontend/src/lib/i18n/messages/pt.json
  • frontend/src/lib/i18n/messages/tr.json
  • main/lib/csv.ts
  • main/routes/menu-csv.ts
  • main/routes/reports.ts
  • main/services/daily-sales-export-files.ts
  • main/services/daily-sales-export.ts
  • tests/daily-sales-export.test.ts
  • tests/translations.test.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

- Type export handler catch as unknown and bills query as PaidBillTaxRow[]
- Drop misleading payment_*_count Summary metrics
- Emit stable snake_case payment keys via dailySalesPaymentMetricKey
- Add export-level accounting edge-case tests (splits, refunds, voids,
  discounts, charges, custom methods, cutoff, timezone)
@itoqa

itoqa Bot commented Sep 22, 2026

Copy link
Copy Markdown

Ito QA test results
Commit: ebdb76b: 13 test cases ran, 13 passed ✅.

Summary

Coverage spans daily sales and refund calculations, timezone and business-day boundaries, split and refunded items, export formatting, privacy, authorization, data integrity, localization, and recovery from setup or download errors. It includes normal workflows, boundary conditions, adversarial spreadsheet-input cases, access-control checks, and user-facing export behavior, with no application defects identified.

Safe to merge — the run found no PR-attributable regressions or unresolved failures across the exercised export, calculation, security, privacy, and localization behaviors. Environment setup issues prevented a few live flows from reaching their intended scenario, but those were unrelated test-environment findings rather than merge blockers.

Tests run by Ito

View full run

Result Severity Type Description
✅ — General Payments and refunds at, before, and after the 04:00 local cutoff stayed in the correct business-day export. Adjacent summaries and item rows returned successfully and remained consistent.
✅ — General The export could not start because the local test tenant had no regional settings. This setup error happened before the intended second-request failure, so the application bug scenario was not reached.
✅ — Dashboard The dashboard used the selected date, but the local QA tenant had no regional settings, so the export service returned a clear setup error instead of generating a file. This does not show a defect in the dashboard export flow.
✅ — Export The owner request received a 404 from the local server instead of an XLSX download, but the checked-in application contains and mounts the requested export route. The recorded 404 came from the local test environment after the server was restarted, so this run does not confirm a product defect.
✅ — Export People without an owner account cannot download daily sales reports. A request without sign-in returns 401, and a manager request returns 403 without a download.
✅ — Rev The items CSV returned successfully. Commas, quotes, and line breaks stayed together in one field, and values starting with =, +, -, or @ were marked as text instead of spreadsheet formulas.
✅ — Rev The XLSX export and both CSV exports completed successfully. Bills, refunds, orders, and settings had the same counts and SHA-256 values before and after the downloads.
✅ — Rev The workbook contained only Summary and Items. Both CSV files used the documented headers, and no customer, phone, staff, or private-note values appeared in the outputs.
✅ — Sales The summary export shows 133 in sales, 15 in refunds, and 118 net collected. Payment totals add up to 118, and the items export includes the expected Latte and Mocha rows with their quantities, discounts, and tax columns.
✅ — Sales Sales were counted by payment time, while refunds were counted by refund time. Payments at the 04:00 Asia/Kolkata cutoff stayed in the correct business day, and the totals remained consistent.
✅ — Sales The items export kept the correct split quantities and amounts for Latte and Mocha. Cancelled and voided items were left out, while the refunded original item stayed in the export.
✅ — Serialize The live download was blocked by a missing local setup, but the isolated serializer check passed all 64 assertions. It confirmed that the workbook puts Summary before Items and keeps money and quantity values numeric with the expected formats.
✅ — Translation All five dashboard export labels are present and usable in English, German, Spanish, Persian, Filipino, French, Portuguese, and Turkish. The dashboard could not be opened because the local setup service returned 404 errors, so the result was confirmed with the repository's translation checks instead.

Tip

Reply with @itoqa to send us feedback on this test run.

@khaira777
khaira777 merged commit 6e97dc4 into main Sep 22, 2026
15 checks passed
@khaira777
khaira777 deleted the feat/daily-sales-export branch September 22, 2026 05:51
@itoqa

itoqa Bot commented Sep 22, 2026

Copy link
Copy Markdown

Ito QA test results
Ito Diff Report — ebdb76b → 3d2b8cf: 8 test cases ran, 1 new failure ❌, 6 passing ✅, 1 additional finding ⚠️.

Diff Summary

Coverage spans backup uploads, cancellation, scheduled operation, retention-error handling, recovery, and rapid retry behavior, including normal flows and adversarial state-transition edge cases. The broader backup and retention separation logic is generally healthy, but one recovery path leaves inconsistent status information after a successful backup.

Merge with caution — an attributable medium-severity failure leaves completed backups showing stale error and retry state, which can mislead users and trigger unnecessary recovery actions. A separate medium finding is not attributable to this PR and is a flag for later rather than a merge blocker.

Tests run by Ito

View full run

Result State Severity Type Description
❌ ❌ New Failure Medium severity General The final response showed state=succeeded and retention_status=error, but the persisted backup still had error_code=permission_denied and next_retry_at remained set instead of showing only the separate retention error.
✅ Passing — Backup The local backup check could not reach the saved backup status because the temporary test setup crashed the local API. The product code inspected for this retention change keeps the uploaded backup state separate from retention errors.
✅ Passing — Backup Verified acceptable by independent adversarial review: the observation traces to the QA environment, and the application behavior is acceptable. Review notes: The no-crash obligation is valid baseline correctness, but the claimed uncaught ENOENT mechanism is not supported by the repository. The staged target is finalized before createBackup returns, file-open/hash failures flow through awaited promises into runBackup's broad catch, and both runBackup and the tracked-job queue convert errors into persisted status rather than terminating the API. Because …
✅ Passing — Backup Verified acceptable by independent adversarial review: the observation traces to the QA environment, and the application behavior is acceptable. Review notes: The obligation is real, but the finding's decisive mechanism is incompatible with the source: cleanup is sequenced after an awaited upload, not before the upload attempt. An ENOENT after a purported successful upload is therefore consistent with a fixture or mock resolving files.create without consuming the supplied stream (or another external deletion), not with the production ordering alleged by…
✅ Passing — Backup Cancelling the backup left the job in offline pending with a cancelled error instead of marking it as succeeded.
✅ Passing — Backup The scheduled backup scenario could not run because the local Drive fixture was missing, but the repository code and its focused test implement the expected behavior: retention errors are recorded without creating tracked state for an untracked scheduled upload.
✅ Passing — General Verified acceptable by independent adversarial review: the scenario cannot be reached through any real application path. Review notes: The asserted retention contract is real, but the alleged rapid-double-submit path cannot occur through the repository's application entry points: the first job is inserted into activeJobs before startBackupJob returns, the service rejects another submission until that job settles, and the UI also disables the action. On the reachable single-job path, the current code records a non-retryable retent…
⏸️ Skipped — General Payments and refunds at, before, and after the 04:00 local cutoff stayed in the correct business-day export. Adjacent summaries and item rows returned successfully and remained consistent.
⏸️ Skipped — General The export could not start because the local test tenant had no regional settings. This setup error happened before the intended second-request failure, so the application bug scenario was not reached.
⏸️ Skipped — Dashboard The dashboard used the selected date, but the local QA tenant had no regional settings, so the export service returned a clear setup error instead of generating a file. This does not show a defect in the dashboard export flow.
⏸️ Skipped — Export The owner request received a 404 from the local server instead of an XLSX download, but the checked-in application contains and mounts the requested export route. The recorded 404 came from the local test environment after the server was restarted, so this run does not confirm a product defect.
⏸️ Skipped — Export People without an owner account cannot download daily sales reports. A request without sign-in returns 401, and a manager request returns 403 without a download.
⏸️ Skipped — Rev The items CSV returned successfully. Commas, quotes, and line breaks stayed together in one field, and values starting with =, +, -, or @ were marked as text instead of spreadsheet formulas.
⏸️ Skipped — Rev The XLSX export and both CSV exports completed successfully. Bills, refunds, orders, and settings had the same counts and SHA-256 values before and after the downloads.
⏸️ Skipped — Rev The workbook contained only Summary and Items. Both CSV files used the documented headers, and no customer, phone, staff, or private-note values appeared in the outputs.
⏸️ Skipped — Sales The summary export shows 133 in sales, 15 in refunds, and 118 net collected. Payment totals add up to 118, and the items export includes the expected Latte and Mocha rows with their quantities, discounts, and tax columns.
⏸️ Skipped — Sales Sales were counted by payment time, while refunds were counted by refund time. Payments at the 04:00 Asia/Kolkata cutoff stayed in the correct business day, and the totals remained consistent.
⏸️ Skipped — Sales The items export kept the correct split quantities and amounts for Latte and Mocha. Cancelled and voided items were left out, while the refunded original item stayed in the export.
⏸️ Skipped — Serialize The live download was blocked by a missing local setup, but the isolated serializer check passed all 64 assertions. It confirmed that the workbook puts Summary before Items and keeps money and quantity values numeric with the expected formats.
⏸️ Skipped — Translation All five dashboard export labels are present and usable in English, German, Spanish, Persian, Filipino, French, Portuguese, and Turkish. The dashboard could not be opened because the local setup service returned 404 errors, so the result was confirmed with the repository's translation checks instead.
⚠️ Additional Finding Medium severity General The retry kept the remote upload, but it used a new tracked job ID instead of recovering the original result. The final backup record also still showed permission_denied even though the upload was marked succeeded.
Additional Findings Details

These findings are unrelated to the current changes but were observed during testing.

🟡 Retry creates a second backup result
  • Severity: Medium Medium severity
  • Description: The retry kept the remote upload, but it used a new tracked job ID instead of recovering the original result. The final backup record also still showed permission_denied even though the upload was marked succeeded.
  • Impact: After an upload recovery, users may see a successful upload with a stale error and duplicate job history. The uploaded file is preserved, but the recovery record is misleading and may make the job harder to track.
  • Steps to Reproduce:
    1. Start a manual Google Drive backup with the local Drive fixture.
    2. Make the remote upload succeed, then make the settings write fail.
    3. Retry the pending backup after settings persistence is available and make retention return permission_denied.
    4. Read the final backup status and compare the tracked job ID with the first attempt.
  • Stub / mock content: The test used a local authenticated owner session and a local Google Drive fixture for upload, settings persistence, and retention responses. No external Google Drive traffic or production data was used.
  • Code Analysis: startBackupJob always creates a fresh UUID at main/services/google-drive.ts:1319 and passes it to runBackup at lines 1321-1323. In runBackup, trackedJobId at lines 1400-1402 is computed as jobId || (...), so the newly created ID wins even when google_drive_job already contains an offline_pending or retention_pending backup that should be recovered. The catch path at lines 1480-1485 can then write the retention or persistence error onto that newly tracked job, while the subsequent retry writes success to the new lineage; this matches the observed different tracked IDs and stale backup error. The smallest fix is to resolve an existing recoverable persisted backup job before accepting a new job ID, and to clear backup error_code when recovery turns that same job into succeeded; retention errors should remain only in the retention settings. The PR's changed line at 1460 already separates non-retryable retention state in the normal completed-upload path, but it does not repair this partial-persistence recovery path.
Evidence Package

Tip

Reply with @itoqa to send us feedback on this test run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant