Guest User

Untitled

a guest
Feb 25th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. // models
  2. import Rate from '../models/rate.model';
  3. import Installment from '../models/installment.model';
  4.  
  5. /**
  6. * Method for creating installment
  7. *
  8. * @param {float} totalPayback Total amount to be paid back
  9. * @param {integer} rateId the rate Id for the loan requested
  10. * @param {string} loanId the loan Id
  11. * @return {Promise} installment created
  12. */
  13. const createInstalment = async (totalPayback, rateId, loanId) => {
  14. const { duration } = await Rate.findById(rateId);
  15.  
  16. const instalmentDate = (duration / 4);
  17. const chargeDate = new Date();
  18.  
  19. const instalmentAmount = parseFloat(totalPayback / 4);
  20.  
  21. const instalmentData = [
  22. {
  23. amount: instalmentAmount,
  24. dueDate: chargeDate.setDate(chargeDate.getDate() + instalmentDate),
  25. loanId
  26. },
  27. {
  28. amount: instalmentAmount,
  29. dueDate: chargeDate.setDate(chargeDate.getDate() + instalmentDate),
  30. loanId
  31. },
  32. {
  33. amount: instalmentAmount,
  34. dueDate: chargeDate.setDate(chargeDate.getDate() + instalmentDate),
  35. loanId
  36. },
  37. {
  38. amount: instalmentAmount,
  39. dueDate: chargeDate.setDate(chargeDate.getDate() + instalmentDate),
  40. loanId
  41. }
  42. ];
  43. };
  44.  
  45. export default createInstalment;
Add Comment
Please, Sign In to add comment