拖欠利息的数据库设计[已结束]

I'm developing a web application to manage loans. I have a table which stores the amortization schedule (how much does the person has to pay in a given date) and I also store payments in the same table (the actual payment of the person). However there are sometimes where the person doesn't pay on time, in this case there should be a charge (interest in arrears) for every day the person misses the payment. What do you think is the best way to calculate this interest in arrears?

I've thought on two approaches:

  1. Run a daily store procedure to calculate the interest for every payment that wasn't due.
  2. Calculate the interest in arrears until the payment is actually due, I mean, get the difference from two dates, debt and payment, calculate the interest and make the charge.

Anyone has another idea? I'm a newbie in term of finance. I hope to make myself understood

As the amount in arrears is calculated from other data, and is not a particularly difficult calculation, there is no reason to store it. Just calculate it when you need it. I'd think you would need it when a customer asks how much he owes, and maybe for some reports. So just calculate it when you produce the response to the customer query and/or when you produce the report.

I would recommend calculating the interest when the payment is due, for two reasons:

  • It's simpler to make the calculation when you need it than to change it daily even though it might not be useful; and
  • The more you change data, the more chances you'll change data wrongly or lose data.

I don't know your exact circumstances, but my vote is on calculating the interest when you actually need it.