-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
123 lines (90 loc) · 4.01 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
// prathomik variable-gulo
let dynamicSeatLeft = document.getElementById('dynamicSeatLeft');
let shobSeat = document.getElementsByClassName('seat');
let cartTableBody = document.getElementById('cartTableBody');
let tkPerSeat = parseFloat(document.getElementById('tkPerSeat').innerText);
let dynamicCartCount = document.getElementById('dynamicCartCount');
let dynamicTotalPrice = document.getElementById('dynamicTotalPrice');
let dynamicGrandTotalPrice = document.getElementById('dynamicGrandTotalPrice');
let couponErValue = document.getElementById('couponValue');
let couponDiv = document.getElementById('couponDiv');
let nirbachitoSeatCount = 0;
let totalPrice = 0;
let grandTotalPrice = 0;
// cart update-er table-e tbody append korar function
function updateCart(seatNumber) {
let notunRow = document.createElement('tr');
let seatCell = document.createElement('td');
seatCell.innerText = seatNumber;
let classCell = document.createElement('td');
classCell.innerText = 'Economy';
let priceCell = document.createElement('td');
priceCell.innerText = tkPerSeat.toFixed();
notunRow.appendChild(seatCell);
notunRow.appendChild(classCell);
notunRow.appendChild(priceCell);
cartTableBody.appendChild(notunRow);
}
// for loop diye seat nirbachon o daam update kora
for (let i = 0; i < shobSeat.length; i++) {
let seat = shobSeat[i];
seat.addEventListener('click', function () {
if (!seat.classList.contains("selected") && nirbachitoSeatCount < 4) {
seat.classList.add("selected");
seat.style.backgroundColor = "#27AE60";
nirbachitoSeatCount = nirbachitoSeatCount + 1;
updateCart(seat.innerText);
priceUpdates();
}
if (nirbachitoSeatCount >= 1) {
document.getElementById('nextSuccessBtn').disabled = false;
}
if (nirbachitoSeatCount == 4) {
document.getElementById('couponValue').disabled = false;
alert('Wow! The coupon box is open for you! 😊 But... Sorry, boss! CharTar beshi seat booking dewa jabe na. 🙁');
}
})
};
// coupon apply kore price update kora
applyCoupon.addEventListener('click', function () {
priceUpdates();
let couponAmount = 0;
couponAmount = grandTotalPrice - totalPrice;
let cpnAmountUpdate = document.getElementById('couponDiscount');
cpnAmountUpdate.innerHTML = `<div class="font-bold text-center flex justify-evenly"><p>Coupon Discount</p><p> BDT ${couponAmount} </p></div>`;
cpnAmountUpdate.appendChild(div);
//
});
// cart-er price-gulor function
function priceUpdates() {
dynamicCartCount.innerText = nirbachitoSeatCount;
dynamicSeatLeft.innerText = 40 - nirbachitoSeatCount;
totalPrice = tkPerSeat * nirbachitoSeatCount;
dynamicTotalPrice.innerText = totalPrice.toFixed();
grandTotalPrice = totalPrice;
// coupon jachai
if (couponErValue.value === 'NEW15') {
// grandTotalPrice *= 0.85;
grandTotalPrice = grandTotalPrice * 0.85;
couponDiv.style.display = 'none';
} else if (couponErValue.value === 'Couple 20') {
// grandTotalPrice *= 0.80;
grandTotalPrice = grandTotalPrice * 0.80;
couponDiv.style.display = 'none';
} else {
// alert('Invalid');
}
dynamicGrandTotalPrice.innerText = grandTotalPrice.toFixed();
}
// modal close korle page reload. inline-e use koray ekhane comment out kora holo
// function pageReload() {
// window.location.reload()
// }
// Next button-er shathe modal connect korar cheshta
document.getElementById('nextSuccessBtn').addEventListener('click', function () {
if (document.getElementById('name') === "" || document.getElementById('phone') === "" || document.getElementById('email') === "") {
alert('Required field alert! Form-er shobgulo field obosshoi puron korte hobe.');
return;
}
document.getElementById('myModal1').showModal();
});