So I'm stuck. I am working on an expiring credit system. Like credit cards, but not entirely accurate. By the way, I'm sorry about the book, but I needed to add enough details to help get the whole picture.
I need a system in which the user accumulates loans to perform actions. But they can also spend these loans on activities. Loans expire in 30 days if they are not used. I seem to be stuck with how to accurately calculate this in a batch that will work every night. Any ideas in any language would be greatly appreciated, as I seem to be stuck on one minor detail that I cannot get around. The following is sample data:
7/1: +5 - user registration
7/2: +5 - the user interacts with the system
7/2: -3 - user shopping activity
7/3: +5 - the user interacts with the system
So, at the moment the user received 15 credits and spent 3. Leaving him a total of 12 credits. (At least I got basic math: P)
I must add that we are currently playing with the idea of creating two fields: the last processed, then processed. Thus, these values at this time suggested that this is a new sign:
Last processed date: 7/1
Next process date: 8/1
So now 8/1 appears. The party starts and looks at all loans that are older than 30 days. Which at this moment is 5.
Here he begins to become fuzzy.
Then the system should look at all the loans that have been spent in the last 30 days to find out if they are using any loans. Because they should expire only if they have not been used. Thus, there are 3. Therefore, I then subtract 2 credits to the user, because this is the difference in credits earned over 30 days and what was spent. So, I will finish the game and set the dates accordingly the next day. Now, believing that they have not spent anymore, I start calculating for loans earned over 30 years, which is 5, and the remaining loans - again 3. But I obviously do not want to consider 3 loans that I counted yesterday. What is a good approach to not include these 3 loans again for consideration.
This is where I am stuck.
We are thinking of recording a debit entry for expired loans so that we can track them, but with difficulty seeing how I can use it in this calculation.
If you read this far, thanks. Even if you make some effort in return, I will at least give you a vote for the effort.
EDIT:
Ok @Greg mentioned something that I forgot to contact. The idea is to put a flag on the considered loans. A valid point, but not one that may work due to the following scenario:
Let's say that on a certain day the user spends 10 credits. But the expired loans that the package considers only accumulate up to 5. Well, he must still have 5 more loans so that they do not expire, because he spent more than one term. Thus, the flag will not work, because we would have missed these 5 additional credits. Hope this makes sense?