-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculate.html
More file actions
98 lines (89 loc) · 3.35 KB
/
calculate.html
File metadata and controls
98 lines (89 loc) · 3.35 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bill Summary</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
.bill-container {
text-align: center;
max-width: 400px;
margin: auto;
padding: 20px;
border: 2px solid #000;
box-shadow: 0px 0px 10px rgba(0,0,0,0.1);
}
.restaurant-name {
text-align: center;
margin: 0;
font-size: 24px;
}
.bill-item, .total-line, .tip-line, .final-total-line {
display: flex;
justify-content: space-between;
margin: 10px 0;
}
.total-line, .final-total-line {
font-weight: bold;
}
.tip-input-container {
margin: 20px 0;
text-align: center;
}
#calculate-tip {
margin-top: 10px;
}
button{
color: white;
background-color: rgb(33, 33, 233);
margin: 20px 0;
text-align: center;
}
</style>
</head>
<body>
<div class="bill-container">
<h2 class="restaurant-name">Spatula Foods</h2>
<div id="order-summary"></div>
<div class="total-line"><span>Subtotal:</span><span id="subtotal">$0.00</span></div>
<div class="total-line"><span>HST (13%):</span><span id="tax">$0.00</span></div>
<div class="final-total-line"><span>Total:</span><span id="total-price">$0.00</span></div>
<div class="tip-input-container">
<input type="number" id="tip-percentage" placeholder="Tip %" />
<button id="calculate-tip">Add Tip</button>
</div>
<div class="final-total-line"><span>Total with Tip:</span><span id="total-with-tip">$0.00</span></div>
<button id="thankyou">Proceed To Pay</button>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const orderDetails = JSON.parse(localStorage.getItem('orderDetails'));
const orderSummary = document.getElementById('order-summary');
let subtotal = 0;
orderDetails.forEach(item => {
const itemElement = document.createElement('div');
itemElement.className = 'bill-item';
itemElement.innerHTML = `<span>${item.dish}</span><span>$${item.price.toFixed(2)}</span>`;
orderSummary.appendChild(itemElement);
subtotal += item.price;
});
const tax = subtotal * 0.13;
const total = subtotal + tax;
document.getElementById('subtotal').textContent = `$${subtotal.toFixed(2)}`;
document.getElementById('tax').textContent = `$${tax.toFixed(2)}`;
document.getElementById('total-price').textContent = `$${total.toFixed(2)}`;
document.getElementById('calculate-tip').addEventListener('click', () => {
const tipPercentage = document.getElementById('tip-percentage').value / 100;
const totalWithTip = total * (1 + tipPercentage);
document.getElementById('total-with-tip').textContent = `$${totalWithTip.toFixed(2)}`;
});
document.getElementById('thankyou').addEventListener('click', () => {
window.location.href = 'thankyoutpage.html'});
});
</script>
</body>
</html>