I am developing a pre-pay system for a cafe or fastfood outlet. The premise is that a retailer will login to an admin page issue itself codes to supply to customers preloaded with credit purchased at the counter.
Currently I have the code system sorted the system will issue a 10 digit unique code and this is hashed and salted before storing in a database. Credit is assigned to the code.
Customers can buy multiple “codes” to build up credit should they want to.
The flow I have at purchase time is the user attempts to purchase an item. The balance of all coupons is calculated at purchase time. If there is sufficient credit the item is purchased the balance is deducted for what ever coupon has enough credit. If the item is $5.60 the coupon with the lowest credit is used and that coupon is now 0.00. The remainder is deducted from the next available coupon should it have insufficient funds. This will prevent anyone ever having dozens of coupons worth .25 or .50 due to purchases.
In the coupon table I have the following structure (some table data omitted)
+------------+----------------+----------------------+
| id | code | balance |
+------------+----------------+----------------------+
| 1 | abcde | 10.00 |
+------------+----------------+----------------------+
| 2 | fghij | 20.00 |
+------------+----------------+----------------------+
| 3 | klmno | 25.00 |
+------------+----------------+----------------------+
the transaction table is similar to..
+------------+----------------+----------------------+
| id | coupon | value |
+------------+----------------+----------------------+
| 1 | abcde | 2.59 |
+------------+----------------+----------------------+
| 2 | abcde | 4.50 |
+------------+----------------+----------------------+
| 3 | klmno | 25.00 |
+------------+----------------+----------------------+
My theory is the value of the coupon is never changed but the value of transactions is calculated and deducted at purchase time to give the remainder.
Does this seem like a practical approach to this?
If you feel this question does not belong here rather than down vote offer a better forum.
Sounds fine in theory, but since you have to keep records of all coupons and transactions anyway, it does not matter against which coupon a purchase is balanced – you need just the sums.
If the coupons are transferable between individuals, you would have to first scan all coupons available to an customer before deciding against which coupons you want to check his balance. Looks impractical to me.
If the coupons are not transferable, they are just receipts for the customer’s deposits on his own account and it does not make sense to single out one of them against which to check.