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

Commit

Permalink
feat: deposit ledger calculations.
Browse files Browse the repository at this point in the history
  • Loading branch information
riki-11 committed Nov 24, 2023
1 parent 49f9caa commit 5a8f20e
Show file tree
Hide file tree
Showing 9 changed files with 354 additions and 351 deletions.
670 changes: 335 additions & 335 deletions .yarn/releases/yarn-4.0.2.cjs → .yarn/releases/yarn-4.0.1.cjs
100644 → 100755

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ enableGlobalCache: false

nodeLinker: pnp

yarnPath: .yarn/releases/yarn-4.0.2.cjs
yarnPath: .yarn/releases/yarn-4.0.1.cjs
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
"nodemon": "^3.0.1",
"prettier": "^3.1.0"
},
"packageManager": "[email protected].2"
"packageManager": "[email protected].1"
}
3 changes: 3 additions & 0 deletions src/models/deposit.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const DepositSchema = new Schema({
type: Decimal128,
required: true
},
runningAmount: {
type: Decimal128
},
ledger: [DepositTransactionSchema],
status: {
type: String,
Expand Down
6 changes: 3 additions & 3 deletions src/models/depositTransactionSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ const DepositTransactionSchema = new Schema({
type: Date,
required: true
},
depositType: {
transactionType: {
type: String,
required: true,
validate: {
validator: (val) => {
return ['deposit', 'withdrawal'].includes(val)
return ['deposit', 'withdrawal', 'Deposit', 'Withdrawal'].includes(val)
},
message: 'Deposit Type must be either "deposit" or "withdrawal"'
message: 'Transaction Type must be either "Deposit" or "Withdrawal"'
}
},
amount: {
Expand Down
4 changes: 4 additions & 0 deletions src/models/loanTransactionSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ const LoanTransactionSchema = new Schema({
required: false,
default: 0
},
finesDue: {
type: Decimal128,
required: true
},
finesPaid: {
type: Decimal128,
required: true
Expand Down
5 changes: 4 additions & 1 deletion src/routes/deposit-ledgers.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ router.put('/', async (req, res, next) => {
// Add transaction to ledger
await Deposit.updateOne(
{ deleted: false, depositID },
{ $push: { ledger: transactionInfo } }
{
$push: { ledger: transactionInfo },
$set: { runningAmount: req.body.balance }
}
)

// Return transaction
Expand Down
1 change: 1 addition & 0 deletions src/routes/deposits.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ router.put('/user/:username', async (req, res, next) => {
category: req.body.category,
interestRate: req.body.interestRate,
originalDepositAmount: req.body.originalDepositAmount,
runningAmount: req.body.originalDepositAmount,
ledger: [],
status: req.body.status || 'pending'
})
Expand Down
12 changes: 2 additions & 10 deletions src/routes/loan-ledgers.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,9 @@ router.put('/', (req, res, next) => {
$push: { ledger: transactionInfo }
}


// 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: req.body.balance
}
if (loan.balance) {
query.$set = { balance: req.body.balance }
}

try {
Expand Down

0 comments on commit 5a8f20e

Please sign in to comment.