...
Provision Calculation For Loan:
The By using the following query will results all loans which are over due either principal amount or interest or charges.we can get all active loan ids along with product id, number of days overdue, outstanding loan balance, due date
SELECT loan.id as loanid,
loan.product_id as productid,
GREATEST(datediff(CURDATE(),sch.duedate),0) as numberofdaysoverdue,
loan.total_outstanding_derived as outstandingbalance,
sch.duedate
FROM m_loan_repayment_schedule as sch
LEFT JOIN m_loan as loan
ON sch.loan_id = loan.id
WHERE loan.loan_status_id=300 and sch.principal_amount > 0 AND sch.completed_derived=false and sch.duedate < CURDATE() 0
GROUP BY sch.loan_id HAVING sch.duedate=min(sch.duedate)
The result of the above query will look like below (mock data).
loanid | productid | numberofdaysoverdue | outstandingbalance | duedate |
---|---|---|---|---|
11 | 9 | 859 | 5403.9600 | 2013-05-01 |
13 | 11 | 692 | 16300.0000 | 2013-10-15 |
27 | 21 | 1418 | 10654.0000 | 2011-10-20 |
32 | 26 | 6 | 6600.0000 | 2015-09-01 |
39 | 33 | 13 | 7584.7100 | 2015-08-25 |
48 | 4 | 0 | 11150.0000 | 2015-10-28 |
69 | 5 | 0 | 11310.0000 | 2015-10-28 |