Skip to content

feat(reports): dispatch cash close via whatsapp - #940

Merged
khaira777 merged 6 commits into
mainfrom
codex/whatsapp-cash-close
Oct 1, 2026
Merged

khaira777 merged 6 commits into
mainfrom
codex/whatsapp-cash-close

Conversation

@khaira777

@khaira777 khaira777 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add localized X/Z cash close summaries and a phone confirmation modal, with background WhatsApp dispatch and a prefilled wa.me fallback.
  • Protect the dispatch route with reports.view and whatsapp.use, and add the z_report message kind with a data-preserving migration.
  • Cover formatting, locale/currency, variance cases, dispatch fallback, permissions, schema, and test-script wiring.

Related to #830 (WhatsApp report sharing only; the epic remains open).

Verification

  • npm run i18n:check — passed
  • npm run lint — passed with existing warnings and no errors
  • npm run build — passed
  • npm run build:frontend — passed
  • npm run test:cash-closures — passed (320/320 plus WhatsApp tests)
  • npm run test:whatsapp-schema — passed
  • npm run test:upgrade-path — passed
  • npm run test:script-coverage — passed

Summary by CodeRabbit

  • New Features

    • Send X and Z cash-close reports through WhatsApp, or open WhatsApp to share manually when direct sending isn’t available.
    • Review and edit the recipient’s phone number before sending. Z reports include cash variance details and notes.
    • Cash-close WhatsApp sharing and report labels are available in multiple languages.
    • Z-report messages appear in WhatsApp message history for users with report access.
  • Bug Fixes

    • Editing the recipient number while settings load now preserves the entered number.

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (3)
docs/README.md — configured
docs/reference/roles-and-permissions.md — configured
AGENTS.md — configured

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Advanced

Run ID: f3ddc95a-cc44-464a-8dd5-fb7400691b27

📥 Commits

Reviewing files that changed from the base of the PR and between fe4e5f0 and b09a409.

📒 Files selected for processing (4)
  • docs/reference/api.md
  • main/routes/whatsapp.ts
  • main/services/whatsapp.ts
  • tests/reports-whatsapp.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.


Walkthrough

Adds WhatsApp sharing for X- and Z-cash-close reports. The change adds report formatting and delivery, recipient validation, Z-report message support, dashboard controls, localized text, and tests.

Changes

Cash-close WhatsApp sharing

Layer / File(s) Summary
Z-report message support
main/db.ts, main/routes/reports.ts, main/routes/whatsapp.ts, main/services/whatsapp.ts, frontend/src/app/(dashboard)/whatsapp/page.tsx, tests/whatsapp-schema.test.ts, tests/reports-whatsapp.test.ts, docs/reference/api.md
The database and WhatsApp message types accept z_report. An authenticated route validates and sends Z-report messages. Message history filters Z reports by report-view permission, with the filter applied before pagination.
Report formatting and delivery
frontend/src/lib/whatsapp-share.ts, frontend/src/hooks/useCashClose.ts, tests/reports-whatsapp.test.ts, package.json
The hook builds X- and Z-report payloads. The sharing helper formats report content and sends through the API or WhatsApp link fallback. Tests cover formatting, API responses, permissions, and fallbacks. The cash-close test script includes the new test file.
Recipient dialog and localized controls
frontend/src/components/dashboard/CashCloseModal.tsx, frontend/src/components/dashboard/SendWhatsAppReportModal.tsx, frontend/e2e/cash-close-whatsapp-recipient.spec.ts, frontend/src/lib/i18n/messages/*.json
The cash-close modal offers WhatsApp actions and renders a recipient dialog that validates the phone number and handles saved settings. Locale files add report, variance, and message-kind labels. The end-to-end test checks that a delayed settings response does not replace an edited recipient.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~30 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant CashCloseModal
  participant SendWhatsAppReportModal
  participant useCashClose
  participant shareCashCloseViaWhatsApp
  participant ReportsRoute
  participant WhatsAppService
  CashCloseModal->>SendWhatsAppReportModal: Open recipient dialog
  SendWhatsAppReportModal->>useCashClose: Submit validated phone number
  useCashClose->>shareCashCloseViaWhatsApp: Send Z-report payload
  shareCashCloseViaWhatsApp->>ReportsRoute: POST report body and phone
  ReportsRoute->>WhatsAppService: Send z_report message
  WhatsAppService-->>ReportsRoute: Return send result
Loading

Merge Risk: ⚪ Minimal · up to b09a4

The change adds WhatsApp sharing of cash-close reports and restricts Z-report history to users with report-view permission. No merge-blocking risk was found in the reviewed context.

Security Architecture Review

Security architecture risk: 🔵 Low · up to b09a4

Report dispatch requires both report-view and WhatsApp permissions, and report history is filtered on the server. No unauthorized report-disclosure path was established. External sharing adds a bounded disclosure surface, while report provenance and recovery after interrupted delivery remain limited or unverified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — Shared content includes financial totals and drawer reconciliation; Z reports also include the closer's name, variance, and notes. Connected sends persist this content in whatsapp_messages and deliver it to the selected phone. Fallback places the same content in an external wa.me URL without using the application's dispatch-history path.

Security Findings and Attack Paths

  • inferred — The generic WhatsApp send route can accept the newly permitted z_report label under whatsapp.use alone. However, it consumes caller-supplied text rather than retrieving cash-close data, and arbitrary text delivery already existed at the base revision. This establishes a report-label provenance limitation, not a demonstrated new report-disclosure or messaging-authority escalation.

Trust Boundaries and Controls

  • observed — Authentication precedes route permission enforcement. Connected report dispatch requires both permissions, while existing report retrieval remains report-view gated. The recipient modal validates the number and avoids overwriting an edited recipient with a late settings response. Fallback constructs a fixed HTTPS wa.me destination with a digits-only phone path and encoded message text.

Resilience and Maintainability Implications

  • inferred — An interruption after external acceptance but before external-ID persistence can leave delivery uncertain. This condition predates the PR and was not shown to weaken report authorization. The new client does not automatically fall back on generic send failures or permission errors, limiting unintended second-path delivery.

Hardening Proposals

  • proposed — If shared reports must serve as authoritative audit records, bind messages to a cash-close ID and authoritative snapshot, and reserve report labels for an authorized producer. Treat this as an additional provenance guarantee, not remediation of a demonstrated disclosure finding.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description includes a useful summary, related issue context, and detailed verification results. It omits the required Scope, Compatibility & data safety, Screenshots, Cross-cutting surfaces, Deve… Add the missing template sections. Document out-of-scope items, database migration and user-visible impacts, network behavior, applicable cross-cutting surfaces and permission effects, documentation status, screenshots or an explicit not-ap…
Docstring Coverage ⚠️ Warning Docstring coverage is 27.78% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 12 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: dispatching cash-close reports through WhatsApp.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description includes a useful summary, related issue context, and detailed verification results. It omits the required Scope, Compatibility & data safety, Screenshots, Cross-cutting surfaces, Developer documentation, and Contributor checklist sections.

Resolution

Add the missing template sections. Document out-of-scope items, database migration and user-visible impacts, network behavior, applicable cross-cutting surfaces and permission effects, documentation status, screenshots or an explicit not-applicable statement, and the contributor checklist selections.

Full details: Docstring Coverage

Explanation

Docstring coverage is 27.78% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 12 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

@khaira777

khaira777 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Cash-close WhatsApp report sharing includes the localized Opening Float in X and Z. X Expected Cash adds the separately reported float to the API movement expectation, matching the cash-close UI; Z Expected Cash remains unchanged because its snapshot already includes float. Over-limit reports use the manual WhatsApp share path with the full message.

The PR head is synced with merged #939 via normal merge commit fe4e5f0240a6b7c9c6718e6694c906025c76b361 (parents: prior #940 head 7f50a78a52f436fd364b21d92ba9a8e2ae05b19d and main ae3edc1f9d1da925893d98ad3f58105aa9a212dc). The merge had no conflicts and added only #939 source/spec and locales. PR #940 remains Related to #830; the epic remains open.

Commit b09a4094c254c06d05f81f6bf77d2a8cc0d88de3 filters stored z_report message rows from /api/whatsapp/messages unless the authenticated caller has configurable reports.view. Filtering occurs in SQL before pagination, and ordinary WhatsApp history remains available. Regression coverage includes cashier denial, manager/owner access, a cashier explicitly granted reports.view, report-like manual text, explicit kind queries, and pagination. The API docs now include the cash-close WhatsApp route and history permission behavior.

Local checks passed on b09a409: lint and lint budget, backend build, docs check, focused cash-close/WhatsApp/authorization suites, and full npm test (isolated TMPDIR; exit 0). Frontend source was unchanged; the synced-head frontend build and 110/110 browser suite had already passed.

All CI checks are green on exact head b09a4094c254c06d05f81f6bf77d2a8cc0d88de3, including both core shards, browser and native Electron E2E, docs, CodeQL, and Required Checks Gate. Greptile reviewed this exact SHA and reported no outstanding finding. CodeRabbit completed run f3ddc95a-cc44-464a-8dd5-fb7400691b27 on fe4e5f02..b09a4094 and reported no actionable comments; it notes advisory PR-description-template and touched-function-docstring coverage warnings. All three existing inline review threads are resolved. PR #940 is open, unmerged, and clean against base ae3edc1f9d1da925893d98ad3f58105aa9a212dc.

@khaira777

Copy link
Copy Markdown
Contributor Author

@greptile review

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Adds WhatsApp delivery for daily cash close reports.

The PR appears safe to merge; no outstanding finding or new actionable issue remains.

Summary

This PR adds localized X/Z cash-close sharing through WhatsApp, with a recipient confirmation modal, direct Z-report dispatch, and a manual-share fallback. It also adds the Z-report message kind, an upgrade migration, permission-filtered message history, and regression coverage.

Diagram
sequenceDiagram
  participant Staff
  participant UI as Cash-close UI
  participant API as Reports API
  participant WA as WhatsApp
  Staff->>UI: Confirm recipient
  UI->>API: Dispatch Z report
  API->>WA: Send message
  alt Connected
    API-->>UI: Message ID
  else Disconnected or manual share
    UI->>WA: Open prefilled share link
  end
Loading

Reviews (5) · Last reviewed commit: "fix(whatsapp): restrict report history a..."

Comment thread main/routes/reports.ts Resolved
Comment thread main/routes/reports.ts Resolved
Comment thread frontend/src/lib/whatsapp-share.ts Resolved
@khaira777

Copy link
Copy Markdown
Contributor Author

@greptile review

@khaira777

Copy link
Copy Markdown
Contributor Author

@greptile review

@khaira777

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@khaira777

Copy link
Copy Markdown
Contributor Author

@greptile review

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@khaira777

Copy link
Copy Markdown
Contributor Author

@greptile review

@khaira777

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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