-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpizza.html
223 lines (204 loc) · 6.92 KB
/
pizza.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!-- Ensure proper scaling on mobile devices -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pizza Driver Pay Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 500px;
margin: 40px auto;
padding: 0 20px;
}
h1 {
text-align: center;
}
label {
display: block;
margin: 15px 0 5px;
}
select, input {
width: 100%;
padding: 8px;
box-sizing: border-box;
font-size: 16px;
}
button {
margin-top: 20px;
padding: 10px;
width: 100%;
font-size: 16px;
}
.result {
margin-top: 25px;
font-size: 20px;
font-weight: bold;
text-align: center;
}
/* Remove spinner arrows in number inputs for Chrome, Safari, Edge, Opera */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
/* Remove spinner arrows in Firefox */
input[type=number] {
-moz-appearance: textfield;
}
</style>
</head>
<body>
<h1>Driver Pay Calculator</h1>
<!-- Dropdown for start time -->
<label for="startTime">Start Time:</label>
<select id="startTime"></select>
<!-- Dropdown for end time (populated dynamically based on start time) -->
<label for="endTime">End Time:</label>
<select id="endTime"></select>
<!-- Input for number of deliveries -->
<label for="deliveries">Number of Deliveries:</label>
<input
type="number"
id="deliveries"
min="0"
step="1"
placeholder="Enter number"
inputmode="numeric"
pattern="[0-9]*">
<!-- Input for Leixlip bonus -->
<label for="leixlip">Leixlip:</label>
<input
type="number"
id="leixlip"
min="0"
step="1"
placeholder="Enter number"
inputmode="numeric"
pattern="[0-9]*">
<!-- Input for Celbridge bonus -->
<label for="celbridge">Celbridge:</label>
<input
type="number"
id="celbridge"
min="0"
step="1"
placeholder="Enter number"
inputmode="numeric"
pattern="[0-9]*">
<!-- Input for Driver Cash on Hand -->
<label for="driverCash">Driver Cash on Hand:</label>
<input
type="number"
id="driverCash"
min="0"
step="0.01"
placeholder="Enter number"
inputmode="decimal"
pattern="[0-9]*">
<!-- Button to trigger calculation -->
<button onclick="calculatePay()">Calculate Pay</button>
<!-- Display the result -->
<div id="result" class="result"></div>
<script>
// Define the shop's operating hours using numeric values for calculation:
// 1:00 PM = 13, 2:00 PM = 14, …, 11:00 PM = 23, 12:00 AM = 24, 1:00 AM = 25, 2:00 AM = 26.
const times = [
{ text: "1:00 PM", value: 13 },
{ text: "2:00 PM", value: 14 },
{ text: "3:00 PM", value: 15 },
{ text: "4:00 PM", value: 16 },
{ text: "5:00 PM", value: 17 },
{ text: "6:00 PM", value: 18 },
{ text: "7:00 PM", value: 19 },
{ text: "8:00 PM", value: 20 },
{ text: "9:00 PM", value: 21 },
{ text: "10:00 PM", value: 22 },
{ text: "11:00 PM", value: 23 },
{ text: "12:00 AM", value: 24 },
{ text: "1:00 AM", value: 25 },
{ text: "2:00 AM", value: 26 }
];
// Populate the startTime dropdown.
function populateStartTime() {
const startSelect = document.getElementById("startTime");
times.forEach(time => {
const option = document.createElement("option");
option.value = time.value;
option.textContent = time.text;
startSelect.appendChild(option);
});
}
populateStartTime();
// Function to update the endTime dropdown based on the selected start time.
function updateEndTimeOptions() {
const startTimeValue = parseInt(document.getElementById("startTime").value, 10);
const endSelect = document.getElementById("endTime");
// Clear any existing options.
endSelect.innerHTML = "";
// Add only times that are strictly after the selected start time.
times.forEach(time => {
if (time.value > startTimeValue) {
const option = document.createElement("option");
option.value = time.value;
option.textContent = time.text;
endSelect.appendChild(option);
}
});
}
// Update endTime options whenever the startTime selection changes.
document.getElementById("startTime").addEventListener("change", updateEndTimeOptions);
// Initialize the endTime dropdown based on the default start time.
updateEndTimeOptions();
// Function to calculate the driver's pay and determine the cash difference.
function calculatePay() {
const startTime = parseInt(document.getElementById("startTime").value, 10);
const endTime = parseInt(document.getElementById("endTime").value, 10);
const deliveries = parseInt(document.getElementById("deliveries").value, 10) || 0;
const leixlip = parseInt(document.getElementById("leixlip").value, 10) || 0;
const celbridge = parseInt(document.getElementById("celbridge").value, 10) || 0;
const driverCash = parseFloat(document.getElementById("driverCash").value) || 0;
// Validate that all inputs are valid whole numbers.
if (isNaN(deliveries) || deliveries < 0 ||
isNaN(leixlip) || leixlip < 0 ||
isNaN(celbridge) || celbridge < 0 ||
isNaN(driverCash) || driverCash < 0) {
alert("Please ensure all values are valid whole numbers.");
return;
}
// Calculate the number of hours worked.
let hoursWorked = endTime - startTime;
if (hoursWorked < 0) {
// Adjust if the shift spans midnight.
hoursWorked += 24;
}
// Define rates.
const hourlyRate = 6;
const deliveryRate = 2.8;
const leixlipBonusRate = 1; // €1 per unit.
const celbridgeBonusRate = 2; // €2 per unit.
// Compute total earnings.
const totalPay = (hoursWorked * hourlyRate) +
(deliveries * deliveryRate) +
(leixlip * leixlipBonusRate) +
(celbridge * celbridgeBonusRate);
// Determine cash difference:
// - If totalPay > driverCash, the shop owes the driver the difference.
// - If driverCash > totalPay, the driver must return the excess to the shop.
const difference = totalPay - driverCash;
let cashMessage = "";
if (difference > 0) {
cashMessage = "Shop owes driver: €" + difference.toFixed(2);
} else if (difference < 0) {
cashMessage = "Driver must return: €" + Math.abs(difference).toFixed(2);
} else {
cashMessage = "Cash is balanced.";
}
// Display the total earnings and the cash difference.
document.getElementById("result").innerHTML =
"Total Pay: €" + totalPay.toFixed(2) + "<br>" + cashMessage;
}
</script>
</body>
</html>