Initial commit

This commit is contained in:
Senad Uka
2018-06-11 11:09:35 +02:00
commit ed7df7b11f
1954 changed files with 483354 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
(function () {
global.dashModule
.controller('financingController', ['$scope', '$http', '$', '$translate', 'utilsService', financingController])
.directive('financing', [financingDirective]);
function financingDirective() {
return {
restrict: 'E',
templateUrl: 'financing/html/financingTemplate'
};
}
function financingController($scope, $http, $, $translate, utilsService) {
$scope.getInterestRate = getInterestRate;
$scope.interestRate = 0;
$scope.saveInterestRate = saveInterestRate;
$scope.subModule = 'setInterestRate';
$scope.setSubModule = setSubModule;
$scope.isSubmoduleVisible = isSubmoduleVisible;
function setSubModule($event) {
$scope.subModule = $event.currentTarget.attributes.subModule.value;
}
function isSubmoduleVisible(subModule) {
return subModule === $scope.subModule;
}
function getInterestRate(){
$http({
method: 'POST',
url: 'financing/api/getInterestRate'
}).then(setInterestRate, utilsService.onHttpError);
}
function setInterestRate(response){
if(response.data && response.data.interestRate){
$scope.interestRate = response.data.interestRate;
}
}
function saveInterestRate(){
const params = $.param({
interestRate: $scope.interestRate
});
$http({
method: 'POST',
url: 'financing/api/saveInterestRate',
data: params
}).then(showUpdateDefaultMessage, utilsService.onHttpError);
}
function showUpdateDefaultMessage(response) {
if (typeof response.data.messages !== 'undefined') {
response.data.messages.forEach((messageObj) => {
let translatedMessage = $translate.instant('financing.messages.' + messageObj.message);
utilsService.displayMessage(messageObj.code, translatedMessage);
});
}
}
}
})();

View File

@@ -0,0 +1,33 @@
.module-layer {
position: relative;
margin-top: 1%;
background: rgba(255, 255, 255, 0.8);
margin-bottom: 3%;
min-height: 50rem;
}
#financing-module-layer {
.module-layer;
.edit-interest-rate {
width: 7rem;
padding: 0 0.6rem;
}
}
#set-customers-discount-module-container {
.customer-info-discount {
padding: 0.3% 0% 0.3% 1%;
}
.customer-info-discount:hover {
background: rgba(59, 185, 255, 0.1);
}
.customer-discount-message {
padding: 1% 0;
}
.edit-interest-rate-discount {
width: 70%;
}
}

View File

@@ -0,0 +1,56 @@
(function () {
global.dashModule.service('finanncingService', [finanncingService]);
function finanncingService() {
return {
calculateFinancing
};
/**
* Copy of Excel's PMT function.
* Credit: http://stackoverflow.com/questions/2094967/excel-pmt-function-in-js
*
* @param ratePerPeriod The interest rate for the loan.
* @param numberOfPayments The total number of payments for the loan in months.
* @param presentValue The present value, or the total amount that a series of future payments is worth now;
* Also known as the principal.
* @param futureValue The future value, or a cash balance you want to attain after the last payment is made.
* If fv is omitted, it is assumed to be 0 (zero), that is, the future value of a loan is 0.
* @param type Optional, defaults to 0. The number 0 (zero) or 1 and indicates when payments are due.
* 0 = At the end of period
* 1 = At the beginning of the period
* @returns {number}
*/
function calculateFinancing(ratePerPeriod, numberOfPayments, presentValue, futureValue = 0, type = 0) {
/*var q = 0;
var c = 0;
const monthlyRatePerPeriod = ratePerPeriod / 12;
if (monthlyRatePerPeriod !== 0.0) {
// Interest rate exists
q = Math.pow(1 + monthlyRatePerPeriod, numberOfPayments);
c = (monthlyRatePerPeriod * (futureValue + (q * presentValue))) / ((-1 + q) * (1 + monthlyRatePerPeriod * (type)));
return c.toFixed(2);
} else if (numberOfPayments !== 0.0) {
// No interest rate, but number of payments exists
return -(futureValue + presentValue) / numberOfPayments;
}
return 0;*/
const rates = {
24 : 4.282,
30 : 3.451,
36 : 2.896,
42 : 2.500,
48 : 2.223,
54 : 2.025,
60 : 1.834
};
const interest = rates[numberOfPayments] || 10;
return presentValue * (interest / 100);
}
}
})();

View File

@@ -0,0 +1,93 @@
(function () {
global.dashModule
.controller('setCustomersDiscountCtrl', ['$scope', '$http', '$', '$translate', 'utilsService', setCustomersDiscountController])
.directive('setCustomersDiscount', [setCustomersDiscountDirective]);
function setCustomersDiscountDirective() {
return {
restrict: 'E',
templateUrl: 'financing/html/setCustomersDiscountTemplate'
};
}
function setCustomersDiscountController($scope, $http, $, $translate, utilsService) {
$scope.getCustomersAndDiscount = getCustomersAndDiscount;
$scope.saveCustomersDiscount = saveCustomersDiscount;
$scope.getNewInterestRate = getNewInterestRate;
$scope.customers = {};
$scope.discounts = {};
$scope.interestRate = 0;
$scope.showMessage = false;
$scope.getMaxInterestRateValue = getMaxInterestRateValue;
$scope.searchText = '';
function getCustomersAndDiscount() {
$http({
method: 'POST',
url: 'financing/api/getCustomersAndDiscount'
}).then(setCustomersAndDiscount, utilsService.onHttpError);
}
function setCustomersAndDiscount(response) {
$scope.customers = response.data.customers ? response.data.customers : {};
$scope.interestRate = response.data.interestRate ? response.data.interestRate : 0;
$scope.customers.forEach(detail => {
$scope.discounts[detail.idCustomer] = parseFloat(detail.discount);
});
}
function getNewInterestRate(idCustomer) {
const newDiscount = $scope.discounts[idCustomer] || 0;
const newInterestRate = $scope.interestRate - newDiscount;
$scope.showMessage = newInterestRate <= 0 ||
newInterestRate > $scope.interestRate ||
$scope.discounts[idCustomer] === undefined ?
true : false;
return newInterestRate.toFixed(2);
}
function saveCustomersDiscount() {
const modifiedDiscounts = getOnlyModifiedDiscounts();
const params = $.param({
discounts: modifiedDiscounts
});
$http({
method: 'POST',
url: 'financing/api/saveCustomersDiscount',
data: params
}).then(showUpdateDefaultMessage, utilsService.onHttpError);
}
function getOnlyModifiedDiscounts() {
const filteredCustomers = $scope.customers.filter(info => {
$scope.discounts[info.idCustomer] = $scope.discounts[info.idCustomer] || 0;
return parseFloat(info.discount) !== $scope.discounts[info.idCustomer];
});
filteredCustomers.map(info => {
info.discount = $scope.discounts[info.idCustomer].toFixed(2);
});
return filteredCustomers;
}
function showUpdateDefaultMessage(response) {
if (typeof response.data.messages !== 'undefined') {
response.data.messages.forEach((messageObj) => {
const key = messageObj.key || '';
let translatedMessage = $translate.instant('financing.messages.' + messageObj.message);
translatedMessage = key !== '' ? translatedMessage + ': ' + key : translatedMessage;
utilsService.displayMessage(messageObj.code, translatedMessage);
});
}
}
function getMaxInterestRateValue() {
return ($scope.interestRate - 0.01).toFixed(2);
}
}
})();

View File

@@ -0,0 +1,52 @@
(function () {
global.dashModule
.controller('setInterestRateCtrl', ['$scope', '$http', '$', '$translate', 'utilsService', setInterestRateController])
.directive('setInterestRate', [setInterestRateDirective]);
function setInterestRateDirective() {
return {
restrict: 'E',
templateUrl: 'financing/html/setInterestRateTemplate'
};
}
function setInterestRateController($scope, $http, $, $translate, utilsService) {
$scope.getInterestRate = getInterestRate;
$scope.interestRate = 0;
$scope.saveInterestRate = saveInterestRate;
function getInterestRate(){
$http({
method: 'POST',
url: 'financing/api/getInterestRate'
}).then(setInterestRate, utilsService.onHttpError);
}
function setInterestRate(response){
if(response.data && response.data.interestRate){
$scope.interestRate = response.data.interestRate;
}
}
function saveInterestRate(){
const params = $.param({
interestRate: $scope.interestRate
});
$http({
method: 'POST',
url: 'financing/api/saveInterestRate',
data: params
}).then(showUpdateDefaultMessage, utilsService.onHttpError);
}
function showUpdateDefaultMessage(response) {
if (typeof response.data.messages !== 'undefined') {
response.data.messages.forEach((messageObj) => {
let translatedMessage = $translate.instant('financing.messages.' + messageObj.message);
utilsService.displayMessage(messageObj.code, translatedMessage);
});
}
}
}
})();