We have a web-app for tracking periodic payments for a loan, currently we are managing it in a mysql database like this:
loan_payments table with the following columns
[ id, customerId, installmentNo, installmentAmount, penalty, previousOutstanding, totalReceivable, amountReceived ]
receipts table with the following columns
[ id, loan_payments.id (FK), paymentAmount, otherPaymentDetails]
The code flow is as follows:
loan_payments table for that customer. Assuming there are fixed 10 installments for all customers, 10 rows will be created
installmentNo = 1 ), the penalty and previousOutstanding will be set to 0.amountReceived is incremented by that amount in the current installment ( installmentNo = 1) and an entry is done in the payments table. *At any give time there is only ONE current installment*installmentNo = 2) , the previous installment's [ totalReceivable - amountReceived ] is inserted into the next installment's ( installmentNo = 2) previousOutstanding. All previous payments/installments are frozen. And intimation is sent to customers indicating, installmentAmount, penalty and previousOutstanding to be paid.installmentNo = 2) and its amountReceived will be incremented whenever a new payment is received.Currently we do not provide update/delete of any payments that does not belong to the current installment.
Everything was working fine, until the client asked for a feature to update/delete previous payments. Following are the problems we will face, if we allow update/delete of previous payments
Suppose current installment no is 5, If user updates payment with installment no 2, all the calculation of previousOutstanding and penalty will be wrong. This doesnt make sense since, intimations were already sent to customers.
There are lot of reports currently using the previousOutstanding and the penalty columns.
Our queries:
previousOutstanding and penalty in the database? Or should it be calculated in the code?An accounting database should be easy to audit, which means it is much better to make it append-only and not edit any old rows. If some columns contain precalculated aggregates, denormalise by dropping them, and put them in a view so your reports still work. The mailings you sent using snapshots of aggregate values should be stored in another append-only table, and since you define these to be snapshots they won't become inaccurate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With