-
Notifications
You must be signed in to change notification settings - Fork 0
/
salaryController.js
165 lines (135 loc) · 4.56 KB
/
salaryController.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
'use strict';
var lodash = angular.module('lodash', []);
lodash.factory('_', function() {
return window._;
})
var app = angular.module('calculator', ['pascalprecht.translate', 'ngCookies', 'lodash']);
app.config(function($translateProvider) {
$translateProvider
.translations('en-US', {
TITLE: 'Calculate net pay from gross pay',
DESCRIPTION1: 'Easily calculate a net salary from a gross value.',
DESCRIPTION2: 'Tax rates may vary depending on your job, salary, location or age.',
COUNTRY: 'country',
SALARY: 'Pay by',
GROSS: 'Gross',
NET: 'Net',
HOURLY: 'hour',
MONTHLY: 'month',
ANNUALLY: 'year',
PARAMETERS: 'Parameters',
HOURS_PER_WEEK: 'hours per week',
MONTHS_PER_YEAR: 'months per year',
TAX_RATE: 'tax rate',
EXPLANATIONS: 'Show explanations',
VALUES_ROUNDED: 'Values above are rounded to the nearest integer.'
})
.translations('fr-FR', {
TITLE: 'Calcul du salaire brut en net',
DESCRIPTION1: 'Calculez facilement un salaire net à partir d\'un montant brut.',
DESCRIPTION2: 'Les charges salariales varient en fonction du status, du salaire, de la localisation ou de l\'âge.',
COUNTRY: 'pays',
SALARY: 'Salaire',
GROSS: 'Brut',
NET: 'Net',
HOURLY: 'horaire',
MONTHLY: 'mensuel',
ANNUALLY: 'annuel',
PARAMETERS: 'Paramètres',
HOURS_PER_WEEK: 'heures par semaine',
MONTHS_PER_YEAR: 'mois par ans',
TAX_RATE: 'charges salariales',
EXPLANATIONS: 'Explications',
VALUES_ROUNDED: 'Les valeurs ci-dessous sont arrondies à l\'entier le plus proche.'
});
$translateProvider.preferredLanguage('en-US');
});
app.controller('salaryController', salaryController);
function roundAll(obj) {
obj.hg = Math.round(obj.hg);
obj.hn = Math.round(obj.hn);
obj.mg = Math.round(obj.mg);
obj.mn = Math.round(obj.mn);
obj.ag = Math.round(obj.ag);
obj.an = Math.round(obj.an);
}
function evalGross(obj) {
obj.hg = obj.hn/obj.k;
obj.mg = obj.mn/obj.k;
obj.ag = obj.an/obj.k;
}
function evalNet(obj) {
obj.hn = obj.hg*obj.k;
obj.mn = obj.mg*obj.k;
obj.an = obj.ag*obj.k;
}
function getWM(NBmonths) {
return 52/NBmonths;
}
function getGNFactor(rate) {
return 1-rate/100;
}
function salaryController($translate, $cookies, $scope, _) {
$scope.favCountry = $cookies.favCountry;
// Default values
$scope.mg = 2500; // Gross Monthly Salary
$scope.hw = 35; // Number of hours worked by week
$scope.tr = 23; // Percentage Tax Rate
$scope.my = 12; // Number of months payed
$scope.countries = [
{ label: 'USA', value: 'en-US'},
{ label: 'France', value: 'fr-FR'}
];
var defCountry = _.find($scope.countries, {value: $cookies.favCountry});
$scope.country = defCountry ? defCountry : $scope.countries[0];
$translate.use($scope.country.value);
$scope.withExplain = false;
// Computed values
$scope.wm = getWM($scope.my); // Average number of weeks/month
$scope.k = getGNFactor($scope.tr); // Gross to Net factor
$scope.mn = $scope.mg*$scope.k; // Net Monthly Salary
$scope.ag = $scope.mg*$scope.my; // Gross Annual Salary
$scope.an = $scope.ag*$scope.k; // Net Annual Salary
$scope.hg = $scope.mg/$scope.wm/$scope.hw; // Gross Hourly Salary
$scope.hn = $scope.hg*$scope.k; // Gross Houryly Salary
roundAll($scope);
$scope.grossToNet = function(type) {
if (type === 'all') {
$scope.wm = getWM($scope.my);
$scope.k = getGNFactor($scope.tr);
}
if (type === 'hour') {
$scope.mg = $scope.hg*$scope.hw*$scope.wm;
$scope.ag = $scope.mg*$scope.my;
} else if (type === 'month') {
$scope.hg = $scope.mg/$scope.wm/$scope.hw;
$scope.ag = $scope.mg*$scope.my;
} else {
$scope.mg = $scope.ag/$scope.my;
$scope.hg = $scope.mg/$scope.wm/$scope.hw;
}
evalNet($scope);
roundAll($scope);
};
$scope.netToGross = function(type) {
if (type === 'hour') {
$scope.mn = $scope.hn*$scope.hw*$scope.wm;
$scope.an = $scope.mn*$scope.my;
} else if (type === 'month') {
$scope.hn = $scope.mn/$scope.wm/$scope.hw;
$scope.an = $scope.mn*$scope.my;
} else {
$scope.mn = $scope.an/$scope.my;
$scope.hn = $scope.mn/$scope.wm/$scope.hw;
}
evalGross($scope);
roundAll($scope);
};
$scope.toggleExplain = function() {
$scope.withExplain = !$scope.withExplain;
};
$scope.setLang = function() {
$cookies.favCountry = $scope.country.value;
$translate.use($scope.country.value);
};
}