27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'app/controllers/dscf/credit/loan_accruals_controller.rb', line 27
def statistics
loan = Loan.find(params[:loan_id])
stats = {
loan_id: loan.id,
principal_amount: loan.principal_amount,
remaining_amount: loan.remaining_amount,
total_facilitation_fee: loan.total_facilitation_fee,
total_interest: loan.total_interest,
total_penalty: loan.total_penalty,
total_vat: loan.total_vat,
total_outstanding: loan.total_outstanding,
accrual_breakdown: {
facilitation_fee: {
pending: loan.loan_accruals.where(accrual_type: "facilitation_fee", status: "pending").sum(:amount),
paid: loan.loan_accruals.where(accrual_type: "facilitation_fee", status: "paid").sum(:amount)
},
tax: {
pending: loan.loan_accruals.where(accrual_type: "tax", status: "pending").sum(:amount),
paid: loan.loan_accruals.where(accrual_type: "tax", status: "paid").sum(:amount)
},
interest: {
pending: loan.loan_accruals.where(accrual_type: "interest", status: "pending").sum(:amount),
paid: loan.loan_accruals.where(accrual_type: "interest", status: "paid").sum(:amount)
},
penalty: {
pending: loan.loan_accruals.where(accrual_type: "penalty", status: "pending").sum(:amount),
paid: loan.loan_accruals.where(accrual_type: "penalty", status: "paid").sum(:amount)
}
},
accrual_count: {
total: loan.loan_accruals.count,
pending: loan.loan_accruals.where(status: "pending").count,
paid: loan.loan_accruals.where(status: "paid").count,
cancelled: loan.loan_accruals.where(status: "cancelled").count
}
}
render_success(
"Loan accrual statistics retrieved successfully",
data: stats
)
end
|