-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
186 lines (149 loc) · 6.34 KB
/
script.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
let valuePriceInput = document.getElementById('valuePriceInput');
valuePriceInput.addEventListener('input', calculateValuePrice);
valuePriceInput.addEventListener("keyup", closeSoftKeyboardWhenEnterPressed);
document.getElementById('seasonDaysSelection').addEventListener("change", calculateSeasonPrice);
document.getElementById('zoneSelection').addEventListener("change", calculateSeasonPrice);
document.getElementById('customerGroupSelection').addEventListener("change", calculateSeasonPrice);
function closeSoftKeyboardWhenEnterPressed(event) {
if (event.keyCode === 13) {
event.preventDefault();
document.activeElement.blur();
}
}
function calculateValuePrice() {
let price = 0;
let price1 = 0;
let price2 = 0;
let price3 = 0;
let price4 = 0;
let priceInputElement = document.querySelector('#valuePriceInput');
price = priceInputElement.value;
if (price >= 0.01) {
price1 = (parseFloat(price, 10));
price2 = (parseFloat(price, 10) + 1);
price3 = (parseFloat(price, 10) + 1);
price4 = (parseFloat(price, 10) + 1);
} else {
// alle 0.01
}
let priceElement1 = document.querySelector('#valueCost1');
priceElement1.textContent = price1.toLocaleString('fi-FI', { style: 'currency', currency: 'EUR' });
let priceElement2 = document.querySelector('#valueCost2');
priceElement2.textContent = price2.toLocaleString('fi-FI', { style: 'currency', currency: 'EUR' });
let priceElement3 = document.querySelector('#valueCost3');
priceElement3.textContent = price3.toLocaleString('fi-FI', { style: 'currency', currency: 'EUR' });
let priceElement4 = document.querySelector('#valueCost4');
priceElement4.textContent = price4.toLocaleString('fi-FI', { style: 'currency', currency: 'EUR' });
}
function calculateSeasonPrice() {
let price1 = 0;
let prices = [0, 0, 0];
let priceArray = [0.0, 0.0, 0.0, 0.0, 0.0];
let adult = [0.0, 0.0, 0.0, 0.0, 0.0];
let discount = [0.0, 0.0, 0.0, 0.0, 0.0];
let student = [0.0, 0.0, 0.0, 0.0, 0.0];
// AB = BC = D:
let adultAB = [47.1, 62.7, 125.4, 188.1, 627.3];
let discountAB = [23.6, 31.4, 62.8, 94.2, 314.0];
let studentAB = [25.9, 34.5, 69.0, 103.5, 344.7];
// ABC = BCD:
let adultABC = [74.8, 99.7, 199.4, 299.1, 997.3];
let discountABC = [37.5, 49.9, 99.8, 149.7, 498.7];
let studentABC = [41.1, 54.8, 109.6, 164.4, 548.0];
// CD:
let adultCD = [60.5, 80.6, 161.2, 241.8, 806.3];
let discountCD = [30.3, 40.3, 80.6, 120.9, 403.3];
let studentCD = [33.3, 44.3, 88.6, 132.9, 443.6];
// ABCD:
let adultABCD = [107.2, 142.7, 285.4, 428.1, 1427.3];
let discountABCD = [53.8, 71.4, 142.8, 214.2, 713.7];
let studentABCD = [59.0, 78.5, 157.0, 235.5, 785.6];
//let days = 0;
let selectedSeasonDays = "";
let selectedZone = "";
let selectedCustomerGroup = "";
let seasonDaysSelection = document.querySelector('#seasonDaysSelection');
selectedSeasonDays = seasonDaysSelection.value;
let zoneSelection = document.querySelector('#zoneSelection');
selectedZone = zoneSelection.value;
let customerGroupSelection = document.querySelector('#customerGroupSelection');
selectedCustomerGroup = customerGroupSelection.value;
// Hinnat valitun vyöhykkeen perusteella:
if (selectedZone == "ab" || selectedZone == "bc" || selectedZone == "d") {
adult = adultAB;
discount = discountAB;
student = studentAB;
} else if (selectedZone == "abc" || selectedZone == "bcd") {
adult = adultABC;
discount = discountABC;
student = studentABC;
} else if (selectedZone == "cd") {
adult = adultCD;
discount = discountCD;
student = studentCD;
} else if (selectedZone == "abcd") {
adult = adultABCD;
discount = discountABCD;
student = studentABCD;
}
let customerGroup = -1;
if (selectedCustomerGroup == "adult") {
priceArray = adult;
customerGroup = 0;
} else if (selectedCustomerGroup == "child" || selectedCustomerGroup == "pensioner" || selectedCustomerGroup == "physicallyChallenged") {
priceArray = discount;
customerGroup = 1;
} else if (selectedCustomerGroup == "student") {
priceArray = student;
customerGroup = 2;
}
if (selectedSeasonDays == "14") {
price1 = priceArray[0];
} else if (selectedSeasonDays == "30") {
price1 = priceArray[1];
} else if (selectedSeasonDays == "60") {
price1 = priceArray[2];
} else if (selectedSeasonDays == "90") {
price1 = priceArray[3];
} else if (selectedSeasonDays == "360") {
price1 = priceArray[4];
}
if (selectedSeasonDays != "empty"){
prices = calculateSeasonStorePrices(price1, customerGroup);
}
let priceElement1 = document.querySelector('#seasonCost1');
priceElement1.textContent = price1.toLocaleString('fi-FI', { style: 'currency', currency: 'EUR' });
let priceElement2 = document.querySelector('#seasonCost2');
priceElement2.textContent = prices[0].toLocaleString('fi-FI', { style: 'currency', currency: 'EUR' });
let priceElement3 = document.querySelector('#seasonCost3');
priceElement3.textContent = prices[1].toLocaleString('fi-FI', { style: 'currency', currency: 'EUR' });
let priceElement4 = document.querySelector('#seasonCost4');
priceElement4.textContent = prices[2].toLocaleString('fi-FI', { style: 'currency', currency: 'EUR' });
}
function calculateSeasonStorePrices(price, customerGroup) {
let rKioskiPrice = price * 0.035;
// R-kioski: percent 3,5%, max. 5 euros
if (rKioskiPrice > 5.00) {
rKioskiPrice = price + 5.00;
} else {
rKioskiPrice = price * 1.035;
}
// student or discount group: different price in K-ryhmä (1 euro)
if (customerGroup == 1 || customerGroup == 2) {
return [price + 1, price + 1, rKioskiPrice];
}
// adult: different price in K-ryhmä (2 euros)
return [price + 1, price + 2, rKioskiPrice];
}
$(document).ready(function () {
$('[data-toggle="popover"]').popover({ html: true });
$(".nav-tabs a").click(function () {
$(this).tab('show');
});
$("#linkToCalc1").click(function (event) {
$('.tab2').tab('show');
});
$("#linkToCalc2").click(function (event) {
$('.tab3').tab('show');
});
});