Skip to main content

Credit Statement Command — PR #2573 Review

An interactive walkthrough of PR #2573 — the new credit-statement:send command. It explains the legacy credit pool model, the current implementation, the bug in the credit math, and the correct fix — with worked numbers computed from the production database (10 March 2026 snapshot).

Context

This PR is part of issue #2562 — Refactor Credit Balance Email Notifications. The review is written for the engineers rebuilding the command.

Open the full review in a new tab →

What it covers

  • Context — the two credit wallets: the shared company pool, and per-outlet self-funded pools.
  • Current solution — the four files PR #2573 adds, and the computeBalance() method at the centre.
  • The bug — for HQ-funded outlets, the shared company pool is counted as if each outlet owned it. Reproduced with real data from FairPrice Hyper and NTUC Foodfare.
  • The fix — compute the company pool once, using the reservation method (getCreditsReservedByCompanyDeduction) that already exists.