Skip to content

fix(loyalty): correct points scale and add billing history to ledger - #562

Merged
itsbkm merged 2 commits into
mainfrom
fix/loyalty-points-ledger-history
Aug 31, 2026
Merged

itsbkm merged 2 commits into
mainfrom
fix/loyalty-points-ledger-history

Conversation

@itsbkm

@itsbkm itsbkm commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Loyalty cashback points were scaled 100x too high: the code correctly computed floor(amount × rate / 100) in currency, then multiplied by a leftover LOYALTY_REDEMPTION_RATE = 100 constant meant for a paise-based scale that's no longer used. An 80% cashback rate on a ₹50 item earned 4000 points instead of 40.
  • Points are now 1:1 with currency. Wallet redemption (preparePaymentBatch) and debit recording were updated in the same change so spending points stays consistent with the new earn rate — leaving only the earn side fixed would have made redemption ~100x too stingy.
  • The customer Ledger modal (Customers page) now shows Billing History per bill (amount, points earned, points redeemed) plus summary totals for Total Spent, Points Earned, and Points Redeemed, alongside the existing points ledger.

Test plan

  • npm run lint — clean (pre-existing warnings only)
  • npm run build — backend compiles clean
  • npm run i18n:check — all 5 locales pass
  • tests/integration-loyalty.test.ts — 11/11 passed
  • tests/integration-loyalty-redemption.test.ts — 40/40 passed
  • tests/integration-loyalty-global-rate.test.ts — 24/24 passed
  • tests/integration-payments.test.ts — 33/33 passed
  • tests/issue-214-payment-integrity.test.ts — 83/83 passed
  • tests/payment-modal-currency-adapter.test.ts — passed
  • npm test — no new failures; the only failures (reports-insights.test.ts, busiest hour/day) are pre-existing on main, confirmed via git stash

🤖 Generated with Claude Code

Cashback points were multiplied by a leftover 100x redemption-rate
constant on top of the percent calculation, so an 80% cashback rate on
a ₹50 item earned 4000 points instead of 40. Points are now 1:1 with
currency; wallet redemption and debit recording were updated to match
so earning and redeeming stay consistent.

The customer ledger modal now also shows billing history per bill
(amount, points earned, points redeemed) plus totals for spend, points
earned, and points redeemed.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
… window

The busiest-hour/busiest-day fixtures were pinned to a fixed calendar
week (2026-06-01..07). Once "now" moved more than 90 days past that
week, GET /api/reports/insights?days=90 silently excluded them from
its trailing window, leaving only the unrelated "recent" rolling-window
fixtures to determine busiest hour/day and breaking the assertions.

Fixtures are now computed relative to "now" from a single shared Monday
anchor 3 weeks back, spaced apart from the "recent" fixtures so the two
sets can never land on the same calendar day, and can no longer drift
out of the query window.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@itsbkm
itsbkm merged commit 6a145fb into main Aug 31, 2026
14 checks passed
@itsbkm
itsbkm deleted the fix/loyalty-points-ledger-history branch August 31, 2026 12:41
carvalab added a commit that referenced this pull request Aug 31, 2026
…ion (#513)

- theme_mode setting (light|dark|system, default system) validated in both
  write paths (IPC set-setting + HTTP wildcard PUT); no migration, no seeding
- useThemeMode store + ThemeSync component: matchMedia resolution, .dark
  toggle, ownership-gated localStorage mirror, token-gated DB seed for
  follower windows (DB > param > mirror > OS, bounded retry with real delay
  + one-shot 60s re-check after transient failure), in-window user-choice
  guard, server-truth rollback with needsServerTruth hydration delivery,
  post-login re-hydration via flo:auth-changed, set-theme-effective push
- FOUC pre-paint guard (param > mirror > prefers-color-scheme) with vm-based
  precedence matrix test
- main-process wiring: direct getDatabase() initial isDark at window
  creation, sender-validated set-theme-effective handler (overlay +
  background color, main window only), effectiveTheme on get-status,
  ?theme= on the KDS window URL
- Appearance settings tab (ownerManager-gated, optimistic + rollback, 5 locales
  incl. French from #549)
- native Electron e2e: dark toggle, nativeTheme.themeSource system sync,
  relaunch persistence; theme-mode-settings + theme-fouc-script suites;
  KDS-hardening and renderer-API expectations aligned
- full dark-mode coverage: Settings page and panels, products, customers,
  tables, staff, addon-groups, POS modals, KDS components, dashboard,
  loyalty ledger modal — light mode pixel-stable
- docs amended (title-bar-phase1, platform matrix); reports-insights
  fixtures date-independent; allowScripts field for local install scripts

Review fixes (greptile): in-window user-choice guard; DB fetch before
mirror; bounded retry with no stale mirror write-back; server-truth
rollback; one-shot follower re-check after transient outage; hydration
delivers server truth when a failed save armed it.

Ponytail cleanup: shared fetchThemeMode helper (boot + recheck dedup),
stdlib asserts in theme-mode-settings, trimmed VM stubs, optional relaunch
on relaunched harness, dead refs/conditions/comments removed (-144 lines).

Rebase follow-ups (#537/#549/#546/#562): tokenize weighted-products/refund/
period-toggle/loyalty-ledger surfaces; fr.json theme-key parity; auth
dispatch guarded for non-browser envs (auth-ui-deterministic); themed
order-card selector in quick-customer-creation e2e; dashboard KPI values
kept dark on pastel tiles; test:refunds restored to the test chain;
comment hygiene (~200 lines of review-narration stripped); allowScripts
field for local npm install scripts.
carvalab added a commit that referenced this pull request Aug 31, 2026
…ion (#513)

- theme_mode setting (light|dark|system, default system) validated in both
  write paths (IPC set-setting + HTTP wildcard PUT); no migration, no seeding
- useThemeMode store + ThemeSync component: matchMedia resolution, .dark
  toggle, ownership-gated localStorage mirror, token-gated DB seed for
  follower windows (DB > param > mirror > OS, bounded retry with real delay
  + one-shot 60s re-check after transient failure), in-window user-choice
  guard, server-truth rollback with needsServerTruth hydration delivery,
  post-login re-hydration via flo:auth-changed, set-theme-effective push
- FOUC pre-paint guard (param > mirror > prefers-color-scheme) with vm-based
  precedence matrix test
- main-process wiring: direct getDatabase() initial isDark at window
  creation, sender-validated set-theme-effective handler (overlay +
  background color, main window only), effectiveTheme on get-status,
  ?theme= on the KDS window URL
- Appearance settings tab (ownerManager-gated, optimistic + rollback, 5 locales
  incl. French from #549)
- native Electron e2e: dark toggle, nativeTheme.themeSource system sync,
  relaunch persistence; theme-mode-settings + theme-fouc-script suites;
  KDS-hardening and renderer-API expectations aligned
- full dark-mode coverage: Settings page and panels, products, customers,
  tables, staff, addon-groups, POS modals, KDS components, dashboard,
  loyalty ledger modal — light mode pixel-stable
- docs amended (title-bar-phase1, platform matrix); allowScripts field for
  local npm install scripts

Review fixes (greptile): in-window user-choice guard; DB fetch before
mirror; bounded retry with no stale mirror write-back; server-truth
rollback; one-shot follower re-check after transient outage; hydration
delivers server truth when a failed save armed it.

Ponytail cleanup: shared fetchThemeMode helper (boot + recheck dedup),
stdlib asserts in theme-mode-settings, trimmed VM stubs, optional relaunch
on relaunched harness, dead refs/conditions/comments removed (-144 lines).

Rebase follow-ups (#537/#549/#546/#562): tokenize weighted-products/refund/
period-toggle/loyalty-ledger surfaces; fr.json theme-key parity; auth
dispatch guarded for non-browser envs (auth-ui-deterministic); themed
order-card selector in quick-customer-creation e2e; dashboard KPI values
kept dark on pastel tiles; reports-insights fixtures date-independent
(upstream #562 fix adopted); test:refunds restored to the test chain;
comment hygiene (~200 lines of review-narration stripped); allowScripts
field for local npm install scripts.
carvalab added a commit that referenced this pull request Aug 31, 2026
…ion (#513) (#563)

- theme_mode setting (light|dark|system, default system) validated in both
  write paths (IPC set-setting + HTTP wildcard PUT); no migration, no seeding
- useThemeMode store + ThemeSync component: matchMedia resolution, .dark
  toggle, ownership-gated localStorage mirror, token-gated DB seed for
  follower windows (DB > param > mirror > OS, bounded retry with real delay
  + one-shot 60s re-check after transient failure), in-window user-choice
  guard, server-truth rollback with needsServerTruth hydration delivery,
  post-login re-hydration via flo:auth-changed, set-theme-effective push
- FOUC pre-paint guard (param > mirror > prefers-color-scheme) with vm-based
  precedence matrix test
- main-process wiring: direct getDatabase() initial isDark at window
  creation, sender-validated set-theme-effective handler (overlay +
  background color, main window only), effectiveTheme on get-status,
  ?theme= on the KDS window URL
- Appearance settings tab (ownerManager-gated, optimistic + rollback, 5 locales
  incl. French from #549)
- native Electron e2e: dark toggle, nativeTheme.themeSource system sync,
  relaunch persistence; theme-mode-settings + theme-fouc-script suites;
  KDS-hardening and renderer-API expectations aligned
- full dark-mode coverage: Settings page and panels, products, customers,
  tables, staff, addon-groups, POS modals, KDS components, dashboard,
  loyalty ledger modal — light mode pixel-stable
- docs amended (title-bar-phase1, platform matrix); allowScripts field for
  local npm install scripts

Review fixes (greptile): in-window user-choice guard; DB fetch before
mirror; bounded retry with no stale mirror write-back; server-truth
rollback; one-shot follower re-check after transient outage; hydration
delivers server truth when a failed save armed it.

Ponytail cleanup: shared fetchThemeMode helper (boot + recheck dedup),
stdlib asserts in theme-mode-settings, trimmed VM stubs, optional relaunch
on relaunched harness, dead refs/conditions/comments removed (-144 lines).

Rebase follow-ups (#537/#549/#546/#562): tokenize weighted-products/refund/
period-toggle/loyalty-ledger surfaces; fr.json theme-key parity; auth
dispatch guarded for non-browser envs (auth-ui-deterministic); themed
order-card selector in quick-customer-creation e2e; dashboard KPI values
kept dark on pastel tiles; reports-insights fixtures date-independent
(upstream #562 fix adopted); test:refunds restored to the test chain;
comment hygiene (~200 lines of review-narration stripped); allowScripts
field for local npm install scripts.
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