UNPKG

client-ui

Version:

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

128 lines (115 loc) 4.63 kB
(function () { 'use strict'; angular.module(moduleName).controller('myDashboardController', myDashboardController); myDashboardController.$inject = ['loan', 'client', 'servicing', '$stateParams']; function myDashboardController(loanService, clientService, servicingService, $stateParams) { var self = this; self.loanIsWaiting = false; self.preClose = false; self.postClose = false; self.init = function () { clientService.getClient() .then(function (client) { self.client = client; return loanService.refreshCurrentLoanFromDB(); }, function (err) { throw err; }) .then(function (loan) { self.loan = loan; setMessages(); loanService.getLoanDisclosures() .then(function (disclosuresObj) { self.disclosures = disclosuresObj; }, function (err) { throw err; }); if (self.loan.statusCode < 800) { // handle preClose self.preClose = true; if (self.loan.selectedOffer) { return servicingService.amPaymentSchedule(); } else { return false; } } else if (self.loan.statusCode >= 800) { // handle postClose self.postClose = true; self.handleServicing(); } }, function (err) { throw err; }) .then(function (amSchedule) { self.amSchedule = amSchedule; }, function (err) { throw err; }); }; self.isBusinessHour = function () { var theirTime = new Date().getUTCHours(); return 14 <= theirTime && theirTime < 23; }; self.handleServicing = function () { self.totalPayments = 0; self.loan.servicing.transactions.forEach(function (transaction) { if(transaction.code === 124){ self.totalPayments += transaction.amount; } }); self.totalPayments = Math.round(self.totalPayments * 100)/100; self.paymentSchedule = self.loan.servicing.schedule; }; function setMessages() { self.messages = []; if ($stateParams.messages) { self.messages = $stateParams.messages.split("-"); } if (self.messages.indexOf('CALL_TO_PROCEED') >= 0) { self.loanIsWaiting = true; self.contactWarningClass = 'text-warning'; } if (self.client.hasPendingIdDocs || self.loan.hasPendingIncomeDocs) { self.loanIsWaiting = true; self.messages.push("DOCS_PENDING"); } } self.generateDownloadUrl = function (type, key, item) { var params = { type: type, id: key }; loanService.generateDownloadUrl(params) .then(function (res) { item.documentUrl = res.documentURL; }, function (err) { console.error("Failed to retrieve url"); }); }; self.generateChart = function () { var data = [ { value: self.totalPayments, color: "#0c4569", highlight: "#3d6a87", label: "Payments" }, { value: self.loan.servicing.balance, color: "#C3D3E3", highlight: "#dbe4ee", label: "Balance" } ]; var options = { nimationEasing: "easeInOutQuart", animationSteps: 35, responsive: true, tooltipTemplate: "<%if (label){%><%=label%>: <%}%>$<%= value %>" }; var ctx = document.getElementById("paymentInterestChart").getContext("2d"); new Chart(ctx).Doughnut(data, options); }; self.getNextStep = function () { return loanService.getNextStep(); }; } }());