Ollama
|
66b6c99384
|
Extract reward logic to Reward_lib library and add unit tests
- Create app/Libraries/Reward_lib.php with reward point business logic:
- calculatePointsEarned(): calculate rewards from purchase amount
- adjustRewardPoints(): deduct/restore/adjust customer points
- handleCustomerChange(): handle points when customer changes on sale
- adjustRewardDelta(): adjust delta for same customer payment changes
- hasSufficientPoints(): validate customer has enough points
- getPointsBalance(): get customer points balance
- calculateRewardPaymentAmount(): sum reward payments from array
- Add tests/Libraries/Reward_libTest.php with 20+ test cases covering:
- Points calculation edge cases
- Customer change scenarios
- Deletion/restore operations
- Sufficient points validation
- Payment amount calculation
- Update tests/phpunit.xml to include Libraries testsuite
This extraction centralizes reward logic for better testability and
follows the existing library pattern (Tax_lib, Sale_lib, etc.).
|
2026-03-17 15:00:57 +00:00 |
|