-
Notifications
You must be signed in to change notification settings - Fork 0
/
cockpit.js
98 lines (85 loc) · 2.38 KB
/
cockpit.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
Items = new Mongo.Collection("items");
Subscriptions = new Mongo.Collection("subscriptions");
client = "AMON CONSULTING MANAGMENT";
//client = "HARMONIOUS BREATHING";
AccountsTemplates.configure({
forbidClientAccountCreation: true,
});
T9n.setLanguage('fr');
Subscription = Astro.Class({
name: 'Subscription',
collection: Subscriptions,
fields: {
client: 'string',
started_at: 'date',
amount: 'number'
}
});
Item = Astro.Class({
name: 'Item',
collection: Items,
fields: {
client: 'string',
project: 'string',
started_at: 'date',
ended_at: 'date',
description: 'string'
},
methods: {
duration: function() {
return moment.duration(this.ended_at - this.started_at).asHours();
},
date: function() {
return moment(this.started_at).format("LL");
}
}
});
if (Meteor.isClient) {
Template.body.helpers({
items: function() {
return Items.find({client: client, started_at: {$gte: new Date('2016-03-01'), $lte: new Date('2016-03-29')}});
},
amount: function() {
return _.reduce(_.map(Subscriptions.find({client: client}).fetch(),
function(sub) {
//map
return sub.amount;
}),
function(amount, sum){
//reduce
return amount + sum;
}) - _.reduce(_.map(Items.find({client: client}).fetch(),
function(item) {
//map
return item.duration();
}),
function(amount, sum){
//reduce
return amount + sum;
});
},
sumForMonth: function() {
return _.reduce(_.map(Items.find({client: client, started_at: {$gte: new Date('2016-03-01'), $lte: new Date('2016-03-29')}}).fetch(),
function(item) {
//map
return item.duration();
}),
function(amount, sum){
//reduce
return amount + sum;
});
},
currentMonth: function() {
return "Mars";
}
});
Template.body.events({
'change select': function () {
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}