-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.js
55 lines (46 loc) · 1.13 KB
/
global.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
class Global {
static getRanks(payments, customers) {
var result = [];
for (var i = 0; i < customers.length; i++) {
var customerTotalPayments = 0;
var customer = customers[i];
for (var j = 0; j < payments.length; j++) {
if (payments[j].customer == customer.pk) customerTotalPayments += payments[j].amount * 100;
}
result.push({
id: customer.pk,
surname: customer.nickname,
spent: parseFloat(((customerTotalPayments - parseInt(customer.balance * 100)) / 100).toFixed(2)),
year: customer.year,
status: customer.status.name,
});
}
result.sort(function (a, b) {
return b.spent - a.spent;
});
return result;
}
static formatDate(date) {
var mm = date.getMonth() + 1; // getMonth() is zero-based
var dd = date.getDate();
var hh = date.getHours();
var MM = date.getMinutes();
var date =
"" +
(dd > 9 ? "" : "0") +
dd +
"/" +
(mm > 9 ? "" : "0") +
mm +
"/" +
date.getFullYear() +
" à " +
(hh > 9 ? "" : "0") +
hh +
"h" +
(MM > 9 ? "" : "0") +
MM;
return date;
}
}
module.exports = Global;