Use this file to discover all available pages before exploring further.
The loyalty system lets tenants run a points-based rewards program for their customers. Each tenant configures one program with its earn and redemption ratios. Points are tracked in an append-only ledger for full auditability.
// app/Models/LoyaltyProgram.phpprotected $fillable = [ 'name', 'earn_ratio', // Spend this many currency units to earn 1 point 'redemption_ratio', // This many points = 1 currency unit 'expiry_days', // null = points never expire 'is_active',];
Invariant: One program per tenant (unique constraint on tenant_id).
// app/Models/LoyaltyProgram.php// Points earned for a given order totalpublic function calculatePoints(float|string $orderTotal): int{ if (!$this->is_active || $this->earn_ratio <= 0) return 0; return (int) floor((float) $orderTotal / $this->earn_ratio);}// Currency value of a given point balancepublic function calculateRedemptionValue(int $points): float{ if ($this->redemption_ratio <= 0) return 0.0; return round($points / $this->redemption_ratio, 2);}
Example: With earn_ratio = 10, a customer spending L.100 earns 10 points. With redemption_ratio = 100, those 10 points are worth L.0.10.
Earn: When an order is completed, the system calls LoyaltyProgram::calculatePoints($order->total) and inserts an earn ledger entry linked to the order.
Redeem: Customer selects a LoyaltyReward. The system inserts a redeem entry with a negative amount equal to $reward->points_cost.
Expire: A scheduled process queries expired scope and inserts expire entries to zero out lapsed points.
Adjust: Admins can insert adjustment entries directly to correct discrepancies.