forked from 92bondstreet/privateaser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
241 lines (226 loc) · 5.59 KB
/
index.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
'use strict';
//list of bats
//useful for ALL 5 steps
//could be an array of objects that you fetched from api or database
const bars = [{
'id': 'f944a3ff-591b-4d5b-9b67-c7e08cba9791',
'name': 'freemousse-bar',
'pricePerHour': 50,
'pricePerPerson': 20
}, {
'id': '165d65ec-5e3f-488e-b371-d56ee100aa58',
'name': 'solera',
'pricePerHour': 100,
'pricePerPerson': 40
}, {
'id': '6e06c9c0-4ab0-4d66-8325-c5fa60187cf8',
'name': 'la-poudriere',
'pricePerHour': 250,
'pricePerPerson': 80
}];
//list of current booking events
//useful for ALL steps
//the time is hour
//The `price` is updated from step 1 and 2
//The `commission` is updated from step 3
//The `options` is useful from step 4
const events = [{
'id': 'bba9500c-fd9e-453f-abf1-4cd8f52af377',
'booker': 'esilv-bde',
'barId': 'f944a3ff-591b-4d5b-9b67-c7e08cba9791',
'time': 4,
'persons': 8,
'options': {
'deductibleReduction': false
},
'price': 0,
'commission': {
'insurance': 0,
'treasury': 0,
'privateaser': 0
}
}, {
'id': '65203b0a-a864-4dea-81e2-e389515752a8',
'booker': 'societe-generale',
'barId': '165d65ec-5e3f-488e-b371-d56ee100aa58',
'time': 8,
'persons': 30,
'options': {
'deductibleReduction': true
},
'price': 0,
'commission': {
'insurance': 0,
'treasury': 0,
'privateaser': 0
}
}, {
'id': '94dab739-bd93-44c0-9be1-52dd07baa9f6',
'booker': 'otacos',
'barId': '6e06c9c0-4ab0-4d66-8325-c5fa60187cf8',
'time': 5,
'persons': 80,
'options': {
'deductibleReduction': true
},
'price': 0,
'commission': {
'insurance': 0,
'treasury': 0,
'privateaser': 0
}
}];
//list of actors for payment
//useful from step 5
const actors = [{
'eventId': 'bba9500c-fd9e-453f-abf1-4cd8f52af377',
'payment': [{
'who': 'booker',
'type': 'debit',
'amount': 0
}, {
'who': 'bar',
'type': 'credit',
'amount': 0
}, {
'who': 'insurance',
'type': 'credit',
'amount': 0
}, {
'who': 'treasury',
'type': 'credit',
'amount': 0
}, {
'who': 'privateaser',
'type': 'credit',
'amount': 0
}]
}, {
'eventId': '65203b0a-a864-4dea-81e2-e389515752a8',
'payment': [{
'who': 'booker',
'type': 'debit',
'amount': 0
}, {
'who': 'bar',
'type': 'credit',
'amount': 0
}, {
'who': 'insurance',
'type': 'credit',
'amount': 0
}, {
'who': 'treasury',
'type': 'credit',
'amount': 0
}, {
'who': 'privateaser',
'type': 'credit',
'amount': 0
}]
}, {
'eventId': '94dab739-bd93-44c0-9be1-52dd07baa9f6',
'payment': [{
'who': 'booker',
'type': 'debit',
'amount': 0
}, {
'who': 'bar',
'type': 'credit',
'amount': 0
}, {
'who': 'insurance',
'type': 'credit',
'amount': 0
}, {
'who': 'treasury',
'type': 'credit',
'amount': 0
}, {
'who': 'privateaser',
'type': 'credit',
'amount': 0
}]
}];
console.log(bars);
console.log(events);
console.log(actors);
function Step1_BookingPrice(){
events.forEach(event=>{
bars.forEach(bar => {
if (event.barId==bar.id) {
event.price = event.time*bar.pricePerHour + event.persons*bar.pricePerPerson;
}
});
});
}
console.log("Step 1 \n")
Step1_BookingPrice();
events.forEach(event=>{console.log("The price for the event is : "+event.price);});
function Step2_Discount(){
events.forEach(event=>{
if (event.persons>=10 && event.persons<20) {
event.price -=event.price*0.1;
}
if (event.persons>=20 && event.persons<60) {
event.price -=event.price*0.3;
}
if (event.persons>=60) {
event.price -=event.price*0.5;
}
});
}
console.log("Step 2 \n")
Step2_Discount();
events.forEach(event=>{console.log("The price for the event after discount is : "+event.price);});
function Step3_PayTheBar(){
events.forEach(event=>{
var commission=event.price*0.3;
event.commission.insurance=0.5*(commission);
event.commission.treasury=event.persons;
event.commission.privateaser=commission-(event.commission.insurance+event.commission.treasury);
})
}
console.log("Step 3 \n")
Step3_PayTheBar()
events.forEach(event=>{console.log(
"The amount due to the bar is : "+event.price*(0.7)+
"\n"+"The amount due to the insurance is : "+event.commission.insurance
+"\n"+"The amount due to the treasury is : "+event.commission.treasury
+"\n"+"The amount due to the privateaser is : "+event.commission.privateaser);
})
function Step4_TheDeductible(){
events.forEach(event=>{
event.options.deductibleReduction=true;
event.price+=event.persons;
})
}
console.log("Step 4 \n")
Step4_TheDeductible();
events.forEach(event=>{console.log("The price for the event after if the deductible is applied is : "+event.price);});
function Step5_PayTheActors(){
events.forEach(event=>{
actors.forEach(actor =>{
var commission=event.price*0.3;
if(actor.eventId==event.id){
actor.payment[1].amount=event.price-commission;
actor.payment[2].amount=0.5*(commission);
actor.payment[3].amount=event.persons;
if(event.options.deductibleReduction==true){
actor.payment[4].amount=200+commission-(actor.payment[2].amount+actor.payment[3].amount);
}
else{
actor.payment[4].amount=5000+commission-(actor.payment[2].amount+actor.payment[3].amount);
}
}
})
});
}
console.log("Step 5 \n")
Step5_PayTheActors()
actors.forEach(actor=>{console.log(
"The amount due to the bar is : "+actor.payment[1].amount+
"\n"+"The amount due to the insurance is : "+actor.payment[2].amount
+"\n"+"The amount due to the treasury is : "+actor.payment[3].amount
+"\n"+"The amount due to the privateaser is : "+actor.payment[4].amount);
})