UNPKG

client-ui

Version:

Testing implementation of nodeJs Backend, angular frontend, and hopefully in a way that this can be deployed to s3/cloudfront

82 lines (73 loc) 3.1 kB
(function () { 'use strict'; angular.module(moduleName).controller('makePaymentController', makePaymentController); makePaymentController.$inject = ['loan', 'servicing', '$filter']; function makePaymentController(loanService, servicing, $filter) { var self = this; self.init = function () { self.currentLoan = loanService.getCurrentLoan(); var now = new ExtendedDate(); var daysOffset = 2; self.validStartDate = now.getNextBusinessDay(daysOffset); now.addDays(15); var maxDate = now; self.userInput = { date: new Date() }; // GET PAYOFF INFO servicing.getPayoffAmount() .then(function (payoff) { self.payoff = payoff; }, function () { self.payoffError = "Failed to retrieve payoff amount"; }); // GET SERVICING ACCOUNT if (self.currentLoan.bank) { var servicingAccounts = $filter('filter')(self.currentLoan.bank.accounts, { servicing: true }); self.servicingAccount = servicingAccounts[0]; } // MOBILE DATE PICKER self.validDates = self.generateBusinessDays(self.validStartDate, maxDate.date); }; self.isDisabledDate = function (date) { var extendedDate = new ExtendedDate(date); return (extendedDate.isWeekend() || extendedDate.isFederalHoliday() || extendedDate.isPastDay(self.validStartDate)); }; self.makePayment = function () { self.working = true; self.submitted = self.userInput; servicing.makePayment(self.userInput) .then(function (res) { self.working = false; self.init(); self.successMessage = true; self.userInput = { amount: null, date: new Date() }; self.makePaymentForm.$setPristine(); }, function () { self.working = false; self.errorMessage = "Failed to make payment, currently you can only schedule one payment per day."; }); }; self.generateBusinessDays = function (fromDate, toDate) { var days = []; var extTo = new ExtendedDate(toDate); var currentDate = new ExtendedDate(fromDate); while (currentDate.date <= extTo.date) { if (currentDate.isWeekend() || currentDate.isFederalHoliday()) { //skip hollidays and weekends } else { days.push(new Date(currentDate.date)); } currentDate.addDays(1); } return days; }; } })();