-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcashcounter.html
More file actions
209 lines (201 loc) · 9.13 KB
/
Copy pathcashcounter.html
File metadata and controls
209 lines (201 loc) · 9.13 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
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
<!DOCTYPE html>
<head>
<Title>Cash Counter</Title>
<link rel="stylesheet" href="main.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<script src="math.js"></script>
<script>
bundles = {"d20":500,"d10":250,"d5":100,"d1":25,"c25":10,"c10":5,"c05":2,"c01":0.5}
window.addEventListener('beforeunload', function(e) {
e.preventDefault();
e.returnValue = '';
});
function fromQty(expression,denomination) {
if (denomination.substring(0,1) == "c") {
return math.evaluate(expression) * (denomination.substring(1) / 100)
} else {
return math.evaluate(expression) * denomination.substring(1)
}
}
function fromAmt(expression,denomination) {
return bundles[denomination] * expression
}
function getTotal(denomination) {
quantity = fromQty(document.getElementById(denomination + "_qty").value,denomination)
if (document.getElementById(denomination + "_amt").value != "") {
amount = fromAmt(document.getElementById(denomination + "_amt").value,denomination)
} else {
amount = 0
}
if (amount != "Error") {
total = isNaN(quantity) ? 0 : quantity
total = isNaN(amount) ? total : total + amount
document.getElementById(denomination + "_tot").innerText = "$" + math.round(total,2)
billsTotal()
coinsTotal()
finalTotal()
} else {
document.getElementById(denomination + "_tot").innerText = "Error"
}
}
function billsTotal() {
total = Number(document.getElementById("d100_tot").innerText.replace('$',''))
total += Number(document.getElementById("d50_tot").innerText.replace('$',''))
total += Number(document.getElementById("d20_tot").innerText.replace('$',''))
total += Number(document.getElementById("d10_tot").innerText.replace('$',''))
total += Number(document.getElementById("d5_tot").innerText.replace('$',''))
total += Number(document.getElementById("d2_tot").innerText.replace('$',''))
total += Number(document.getElementById("d1_tot").innerText.replace('$',''))
document.getElementById("bill_total").innerText = "$" + math.round(total,2)
}
function coinsTotal() {
total = Number(document.getElementById("c100_tot").innerText.replace('$',''))
total += Number(document.getElementById("c50_tot").innerText.replace('$',''))
total += Number(document.getElementById("c25_tot").innerText.replace('$',''))
total += Number(document.getElementById("c10_tot").innerText.replace('$',''))
total += Number(document.getElementById("c05_tot").innerText.replace('$',''))
total += Number(document.getElementById("c01_tot").innerText.replace('$',''))
document.getElementById("coin_total").innerText = "$" + math.round(total,2)
}
function finalTotal() {
total = Number(document.getElementById("bill_total").innerText.replace('$',''))
total += Number(document.getElementById("coin_total").innerText.replace('$',''))
document.getElementById("final_total").innerText = "$" + math.round(total,2)
}
function clearInputs() {
if (confirm("Do you want to clear all inputs?")) {
const elements = document.getElementsByTagName("input")
for (let i = 0; i < elements.length; i++) {
elements[i].value = ""
}
const labels = document.getElementsByClassName("flbl")
for (let i = 0; i < labels.length; i++) {
labels[i].innerText = "$0"
}
billsTotal()
coinsTotal()
finalTotal()
}
}
function changePageDC() {
window.location.href = "./index.html"
}
function changePageSC() {
window.location.href = "./safecounter.html"
}
</script>
<body>
<table id="mytable">
<tr>
<th>Bills</th>
<th>Quantity</th>
<th>Bundle</th>
<th>Totals</th>
</tr>
<tr>
<td>Hundreds</td>
<td><input id="d100_qty" type="text" inputmode="numeric" size=7 onChange="getTotal('d100')"></td>
<td><input id="d100_amt" type="text" inputmode="numeric" size=9 onChange="getTotal('d100')"></td>
<td><label id="d100_tot" class="flbl">$0</label></td>
</tr>
<tr>
<td>Fifties</td>
<td><input id="d50_qty" type="text" inputmode="numeric" size=7 onChange="getTotal('d50')"></td>
<td><input id="d50_amt" type="text" inputmode="numeric" size=9 onChange="getTotal('d50')"></td>
<td><label id="d50_tot" class="flbl">$0</label></td>
</tr>
<tr>
<td>Twenties</td>
<td><input id="d20_qty" type="text" inputmode="numeric" size=7 onChange="getTotal('d20')"></td>
<td><input id="d20_amt" type="text" inputmode="numeric" size=9 onChange="getTotal('d20')"></td>
<td><label id="d20_tot" class="flbl">$0</label></td>
</tr>
<tr>
<td>Tens</td>
<td><input id="d10_qty" type="text" inputmode="numeric" size=7 onChange="getTotal('d10')"></td>
<td><input id="d10_amt" type="text" inputmode="numeric" size=9 onChange="getTotal('d10')"></td>
<td><label id="d10_tot" class="flbl">$0</label></td>
</tr>
<tr>
<td>Fives</td>
<td><input id="d5_qty" type="text" inputmode="numeric" size=7 onChange="getTotal('d5')"></td>
<td><input id="d5_amt" type="text" inputmode="numeric" size=9 onChange="getTotal('d5')"></td>
<td><label id="d5_tot" class="flbl">$0</label></td>
</tr>
<tr>
<td>Twos</td>
<td><input id="d2_qty" type="text" inputmode="numeric" size=7 onChange="getTotal('d2')"></td>
<td><input id="d2_amt" type="text" inputmode="numeric" size=9 onChange="getTotal('d2')"></td>
<td><label id="d2_tot" class="flbl">$0</label></td>
</tr>
<tr>
<td>Ones</td>
<td><input id="d1_qty" type="text" inputmode="numeric" size=7 onChange="getTotal('d1')"></td>
<td><input id="d1_amt" type="text" inputmode="numeric" size=9 onChange="getTotal('d1')"></td>
<td><label id="d1_tot" class="flbl">$0</label></td>
</tr>
<tr>
<td></td>
<td></td>
<td>Total:</td>
<td class="difftable"><label id="bill_total">$0</label></td>
</tr>
<tr>
<th>Coins</th>
<th>Quantity</th>
<th>Rolls</th>
</tr>
<tr>
<td>Dollar Coin</td>
<td><input id="c100_qty" type="text" inputmode="numeric" size=7 onChange="getTotal('c100')"></td>
<td><input id="c100_amt" type="text" inputmode="numeric" size=9 onChange="getTotal('c100')"></td>
<td><label id="c100_tot" class="flbl">$0</label></td>
</tr>
<tr>
<td>Half Dollar</td>
<td><input id="c50_qty" type="text" inputmode="numeric" size=7 onChange="getTotal('c50')"></td>
<td><input id="c50_amt" type="text" inputmode="numeric" size=9 onChange="getTotal('c50')"></td>
<td><label id="c50_tot" class="flbl">$0</label></td>
</tr>
<tr>
<td>Quarters</td>
<td><input id="c25_qty" type="text" inputmode="numeric" size=7 onChange="getTotal('c25')"></td>
<td><input id="c25_amt" type="text" inputmode="numeric" size=9 onChange="getTotal('c25')"></td>
<td><label id="c25_tot" class="flbl">$0</label></td>
</tr>
<tr>
<td>Dimes</td>
<td><input id="c10_qty" type="text" inputmode="numeric" size=7 onChange="getTotal('c10')"></td>
<td><input id="c10_amt" type="text" inputmode="numeric" size=9 onChange="getTotal('c10')"></td>
<td><label id="c10_tot" class="flbl">$0</label></td>
</tr>
<tr>
<td>Nickels</td>
<td><input id="c05_qty" type="text" inputmode="numeric" size=7 onChange="getTotal('c05')"></td>
<td><input id="c05_amt" type="text" inputmode="numeric" size=9 onChange="getTotal('c05')"></td>
<td><label id="c05_tot" class="flbl">$0</label></td>
</tr>
<tr>
<td>Pennies</td>
<td><input id="c01_qty" type="text" inputmode="numeric" size=7 onChange="getTotal('c01')"></td>
<td><input id="c01_amt" type="text" inputmode="numeric" size=9 onChange="getTotal('c01')"></td>
<td><label id="c01_tot" class="flbl">$0</label></td>
</tr>
<tr>
<td></td>
<td></td>
<td>Total:</td>
<td class="difftable"><label id="coin_total">$0</label></td>
</tr>
<tr>
<td></td>
<td></td>
<td>Final Total:</td>
<td><b><label id="final_total">$0</label></b></td>
</tr>
</table>
<button onclick="clearInputs()">Clear Inputs</button>
<button onclick='changePageDC()'>Drawer Counter</button>
<button onclick='changePageSC()'>Safe Counter</button>
</body>