First thing is this is a long question. So please first read it then give me your suggestion.
currently i am working on a banking projects for my degree. Where i am implementing a simple bank savings account. Where account holder can deposit and withdraw money.
The account starts with a opening balance. Then user can add or withdraw money. And also i have to calculate their interest (Flat 4% per year).
The following transaction is to be made
Date TNX Type Amount Interest Remaining LastTXDate 01/03/13 + Opening + 10000 0.00 10000.00 01/03/13 15/03/13 + Deposite + 5000 0.00 5000.00 15/03/13 09/04/13 + Deposite + 2500 0.00 2500.00 09/04/13 ============================================================================ 25/04/13 - Withdraw - 5000 17/05/13 - Withdraw - 6000 21/06/13 + Deposite + 10000
There are some rules
If a deposit made in between first 10 days of a month then interest will be calculated form the deposit date, Else interest will be calculated from 1 day of next month.
I store all deposit and withdraw TNX into a table called 'savings'.
Now my question is how can i calculate interest? Suggest me any logic. No code required.
Actually i have a logic but don't know if it it effective or not.
My logic is like follow
When a withdraw made, i first search last deposit record with remaining amount.
Then i calculate the Maturity days for that withdraw amount,
Then i calculate interest for that withdraw amount and save it to that
deposit record's interest field.
Am i right with this logic or i have to change it? Any suggestion will be helpful.