Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
feat: added interestDue and amountDue to loanTransactionSchema.
Browse files Browse the repository at this point in the history
  • Loading branch information
riki-11 committed Nov 23, 2023
1 parent 00e79ec commit 06e14f0
Show file tree
Hide file tree
Showing 4 changed files with 1,425 additions and 1,403 deletions.
10 changes: 10 additions & 0 deletions src/models/loanTransactionSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ const LoanTransactionSchema = new Schema({
type: Decimal128,
required: true
},
amountDue: {
type: Decimal128,
required: false,
default: 0
},
balance: {
type: Decimal128,
required: true
Expand All @@ -35,6 +40,11 @@ const LoanTransactionSchema = new Schema({
type: Decimal128,
required: true
},
interestDue: {
type: Decimal128,
required: false,
default: 0
},
finesPaid: {
type: Decimal128,
required: true
Expand Down
12 changes: 9 additions & 3 deletions src/routes/loan-ledgers.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,16 @@ router.put('/', (req, res, next) => {
$push: { ledger: transactionInfo }
}

// Update balance
if (loan.balance) {

// Update balance depending on whether transaction is readjustment or not
if (loan.balance && req.body.readjusment === false) {
query.$set = {
// Should we include amountDue here?
balance: loan.balance + req.body.interestDue - req.body.amountPaid - req.body.interestPaid - req.body.finesPaid
}
} else {
query.$set = {
balance: loan.balance - req.body.amountPaid
balance: req.body.balance
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/routes/loans.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ router.put('/user/:username', async (req, res, next) => {
dueDate: null,
coborrower: req.body.coborrower,
originalLoanAmount: req.body.amount,
balance: req.body.amount,
ledger: [],
status: req.body.status,
classification: req.body.classification
Expand Down Expand Up @@ -264,8 +265,10 @@ router.post('/:loanID/review', async (req, res, next) => {
transactionDate: Date.now(),
submissionDate: Date.now(),
amountPaid: deductions,
amountDue: 0,
balance: deductions.neg().add(existingLoan.balance).toString(),
interestPaid: 0,
interestDue: 0,
finesPaid: 0,
officerInCharge: req.body.oic
}
Expand Down
Loading

0 comments on commit 06e14f0

Please sign in to comment.