Pre-requisite:
1. Creating Two Accounts
- Loyalty Points Account (type : Income)
- Other Payables Account (type : Other Current Liability)
2. Create a Discount Item:
Lists –> Accounting –>Items –> new –> Discount
Chose item name let say Loyalty Discount. In the rate field input ‘0’ and then save the item.
3. Create two script parameters
- Script parameter of level company for loyalty percentage
– It is the percentage at which you will be giving loyalty points)
- Script parameter of level company for validity months
– These are the months after which loyalty points expire)
Design of Loyalty Points System Has Three Major Flows:
1. Credits/Points Earning
This calculation would be done in your UserEvent Script After Submit event.
Steps:
1.1 Get the total of your transaction (Cash Sale/Sales Order)
– If you want’s to exclude tax then have value of field subtotal else use field total
1.2 Subtract the discount from the total to get Actual Amount
– Get the value of field discounttotal and subtract the total you fetched in step 1 from it to get the actual amount.
1.3 Calculate the loyalty points by multiplying loyalty percentage (fetch from script parameter of loyalty percentage) with actual amount
1.4 Save the credits information in a custom record for customer loyalty credits history having structure like:-
– Customer ID, Transaction ID, Credits Earned, Creation Date, Credits Expired? (include other fields as per your needs)
1.5 Pass the credits earned journal entry as
– Debit the points in Loyalty account
– Credit the points in Other Payables account
1.6 Put the credits earned journal entry ID on your transaction body field.
2. Credits/Points Redemption
This calculation would be done in your UserEvent Script Before Submit
Steps:
2.1 Check if the customer has the points available for redemption
– check in custom record you created in step 4 of points earning flow
2.2 If points are available
– Assign the discount item you created in pre-requisite 2 in discountitem field of your transaction
2.3 Set the points available for redemption in discountrate field of your transaction.
– Multiply the points with ‘-1’ since we need this value for subtraction
2.4 Mark the used credits
– Keep the ID of custom record of customer loyalty points utilized in this transaction in a hidden field on the record and in after submit event mark these points as used.
2.5 Pass the reverse journal entry
– Credit the points redeemed in Loyalty account
– Debit the points redeemed Other payables account
2.6 Put the credits earned journal entry NSID on your transaction body field.
3. Write a schedule script which runs daily to delete(make zero) out the expired credits