Improve loan dashboard interactions

This commit is contained in:
Rafael Foster
2026-05-01 08:09:12 -03:00
parent 977bee8a3a
commit 79f55cbfbc
18 changed files with 425 additions and 24 deletions
+11
View File
@@ -889,6 +889,17 @@ router.put('/:id', (req, res) => {
if (linkedPayment && amount !== undefined && Number(amount) <= 0) {
return res.status(400).json({ error: 'Loan repayment entries must remain income.', code: 400 });
}
if (linkedPayment && amount !== undefined) {
const loan = db.get().prepare('SELECT total_amount FROM budget_loans WHERE id = ?').get(linkedPayment.loan_id);
const otherPaid = db.get().prepare(`
SELECT COALESCE(SUM(amount), 0) AS total
FROM budget_loan_payments
WHERE loan_id = ? AND id != ?
`).get(linkedPayment.loan_id, linkedPayment.id).total;
if (Number(amount) - (Number(loan?.total_amount || 0) - Number(otherPaid || 0)) > 0.005) {
return res.status(400).json({ error: 'Amount cannot be greater than the remaining loan amount.', code: 400 });
}
}
const nextCategory = category ?? entry.category;
const subcategory = requestedSubcategory !== undefined || category !== undefined
? validateSubcategory(nextCategory, requestedSubcategory ?? entry.subcategory)