Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // models
- import Rate from '../models/rate.model';
- import Installment from '../models/installment.model';
- /**
- * Method for creating installment
- *
- * @param {float} totalPayback Total amount to be paid back
- * @param {integer} rateId the rate Id for the loan requested
- * @param {string} loanId the loan Id
- * @return {Promise} installment created
- */
- const createInstalment = async (totalPayback, rateId, loanId) => {
- const { duration } = await Rate.findById(rateId);
- const instalmentDate = (duration / 4);
- const chargeDate = new Date();
- const instalmentAmount = parseFloat(totalPayback / 4);
- const instalmentData = [
- {
- amount: instalmentAmount,
- dueDate: chargeDate.setDate(chargeDate.getDate() + instalmentDate),
- loanId
- },
- {
- amount: instalmentAmount,
- dueDate: chargeDate.setDate(chargeDate.getDate() + instalmentDate),
- loanId
- },
- {
- amount: instalmentAmount,
- dueDate: chargeDate.setDate(chargeDate.getDate() + instalmentDate),
- loanId
- },
- {
- amount: instalmentAmount,
- dueDate: chargeDate.setDate(chargeDate.getDate() + instalmentDate),
- loanId
- }
- ];
- };
- export default createInstalment;
Add Comment
Please, Sign In to add comment