Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Calculate Point Rewards

Calculate both points_total and points_pending for all active users.

Calculation

  • points_total: the sum of all non-expired point transactions for a user, regardless of redemption status.
  • points_pending: the sum of points that have been earned but not yet confirmed (e.g., from bookings not yet completed).
points_total   = user.point_transactions.where(expired: false).sum(:points)
points_pending = user.point_transactions.where(confirmed: false, expired: false).sum(:points)

Do not base calculations on the redeemed status or expiry_date field directly. Use the expired boolean flag instead.