Feature #10340
openTo implement auto apply priority based loyality rewards program (Stackable with other programs)
Added by Ajit A about 1 month ago. Updated about 1 month ago.
100%
Subtasks
Related issues
Updated by Ajit A about 1 month ago
- Subject changed from To implement auto apply priority based loyality rewards program to To implement auto apply priority based loyality rewards program (Stackable with other programs)
Updated by Ajit A about 1 month ago
Feature Update: Loyalty Program Priority, Stackability, & Redemption Logic
1. Database & Schema Enhancements
Loyalty Program Model (loyaltyProgramSchema.js): Enforced a default priority of 1 (minimum value of 1). Added a compound index ({ companyId: 1, status: 1, priority: 1, isDeleted: 1 }) to optimize program evaluation queries.
Sale Model (nursery.product.js): Added pointsEarnedOnSale and pointsRedeemedOnSale fields to accurately track points earned and redeemed directly on the sale document.
Company Model (Company-controller.js): Added support for a configurable maxStackablePrograms setting (default: 2) inside loyaltySettings to cap the maximum number of loyalty programs that can apply simultaneously to a transaction.
2. Core Loyalty Engine Refactoring (loyaltyEngine.js)
Priority ASC Sorting: Updated the engine to sort eligible loyalty programs by priority in ascending order (Priority 1 = Highest Priority), with deterministic fallback sorting.
Exclusivity & Mutual Stackability:
If the highest-priority program is marked as Stackable = false, the engine applies only that program and explicitly blocks all lower-priority programs.
If the highest-priority program is Stackable = true, the engine continues to evaluate subsequent programs. If it encounters a lower-priority program that is Stackable = false, it safely skips that specific program without breaking the chain for subsequent stackable programs.
Max Stackable Limit: Implemented enforcement of the maxStackablePrograms limit to protect against infinite point inflation.
3. POS Checkout, Returns, & Cancellation Enhancements (sale.service.js)
Synchronous Processing (cashSaleNew): Refactored POS checkout to process point earning, redemption, and wallet updates synchronously before finalizing the sale.
Gross Subtotal Calculation: Updated loyalty calculations to apply earnings against the gross subtotal (before loyalty discounts are applied) ensuring customers earn full points on their spend.
Returns (createSaleReturn): Added automated proportional reversal of earned loyalty points when an item is returned, including generating a REFUNDED ledger entry.
Cancellations (deleteSale): Added automated reversal of all earned points and full restoration of all redeemed points when an entire sale is cancelled.
4. E-Commerce & Product Quotation Integration
Quotations (productQuoteRoute.js): Integrated the unified processSaleLoyalty service into the completed quotation webhook flow.
E-Commerce Webhooks (ecomLoyalty.test.js verified): Ensured pending e-commerce checkout redemptions are fully cleared and finalized asynchronously upon successful Stripe payment webhooks, or synchronously for offline cash checkouts.
5. Frontend UI Clarification
Settings UI (LoyaltyRewardSettings.tsx): Updated the input label to explicitly read Priority (1 = Highest Priority) to eliminate user confusion during program configuration.
6. Testing & Quality Assurance
loyaltyEngine.test.js: All 12 scenarios passing (verifying Priority sorting, Exclusivity, Mutual Stackability, Max Limits, SKU Multipliers, and Tier Progressions).
posLoyalty.test.js: All 4 scenarios passing (verifying point earning, redemption, proportional return reversals, and full cancellation restorations).
ecomLoyalty.test.js: All 3 scenarios passing (verifying pending checkouts, Stripe webhook integration, and offline e-commerce payment tracking).
Updated by Ajit A about 1 month ago
- Status changed from In Progress to Resolved
- % Done changed from 0 to 100
Completed