-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOffline_Order_Creator.html
More file actions
519 lines (372 loc) · 16.8 KB
/
Copy pathOffline_Order_Creator.html
File metadata and controls
519 lines (372 loc) · 16.8 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- IMPORTS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/CryptoStore/crypto-js/3.1.2/build/rollups/aes.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>KIDEY : Offline Order Creator</title>
<!-- CSS -->
<style>
* {
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
color: whitesmoke;
padding: 0%;
margin: 0%;
}
body {
background-color: black;
padding: 10px;
}
.wingy-parent {
padding: 5px;
font-size: 18px;
border-bottom: 1px solid grey;
position: fixed;
background-color: black;
left: 0%;
top: 0%;
width: 95%;
}
.input-classic {
padding: 10px;
margin: 5px;
background-color: #202020;
width: 190px;
outline: none;
border-radius: 5px;
border: none;
}
.big-button:hover {
background: #62c6ee;
}
.big-button:disabled {
background: #62c6ee74;
}
.big-button {
transition: 0.2s;
padding: 10px 15px;
margin: 5px;
font-size: 20px;
background: skyblue;
border-radius: 5px;
display: inline-block;
user-select: none;
color: black;
}
.category-head {
font-weight: 900;
font-size: 22px;
color: chartreuse;
text-align: center;
}
.product_list-product {
margin: 5px 0px;
padding: 3px;
background-color: #212121;
border-radius: 5px;
color: grey;
}
#product_list:hover {
background-color: #404040;
}
#product_list {
transition: 0.2s;
height: 250px;
overflow-y: auto;
background-color: #303030;
padding: 10px;
border-radius: 5px;
}
.productcounter-container {
display: flex;
user-select: none;
}
.productcounter-container span {
flex-grow: 1;
text-align: center;
font-weight: 900;
}
.add-product {
margin: 0px 2px;
padding: 0 3px;
background-color: #89cfeb80;
color: black;
transition: 0.2s;
border-radius: 5px;
}
.add-product:hover {
border-radius: 3px;
background-color: #89cfeb;
}
.non-zero-product span {
color: black;
}
.non-zero-product .add-product {
box-shadow: 1px 1px 3px black;
}
.non-zero-product {
margin: 5px 0px;
padding: 3px;
background-color: #6cfa49;
border-radius: 5px;
color: black;
}
.fnt-med {
font-size: 23px;
color: chartreuse;
}
</style>
</head>
<body>
<div class="wingy-parent" onclick="attemptConnectionToServer()">
<img id="server_connection_status" style="width: 20px;"
src="https://img.icons8.com/material-outlined/48/fa314a/no-network.png" />
<div style="float: right;">
<span id="server_connection_status_txt" style="color: gray; float: left;">Disconnected to Server!</span>
<img style="width: 20px; padding: 0px 0px 0px 5px;"
src="https://img.icons8.com/office/40/4a90e2/refresh--v2.png" />
</div>
</div>
<br><br>
<h2 style="padding: 10px; background-color: #202020;">Kidey Offline Tool</h2>
<br>
<div class="flex-object" id="addproduct_container" style="flex-grow: 1;">
<div id="addaproduct" class="fnt-med">Create Order Instance</div>
<div id="add-product-container">
<script>let orderJson = {}; let totalBill = 0; let discount = 0;</script>
<form id="order_form" action="" method="POST">
<div class="flex-row row-responsive">
<div class="flex-object">
<input class="input-classic" name="customer_name" type="text" placeholder="Customer Name"
autocomplete="off" required="">
<input class="input-classic" name="customer_phone_no" type="number" placeholder="Customer Phone"
autocomplete="off" required="">
<input class="input-classic" name="customer_address" value="" type="text" placeholder="Address"
autocomplete="off">
<br>Time Of Order:
<input class="input-classic" name="time_of_order" type="datetime-local"
placeholder="Time Of Order" autocomplete="off" required="">
<br>Time Of Delivery:
<input class="input-classic" name="time_of_delivery" type="datetime-local"
placeholder="Time Of Delivery" autocomplete="off" required=""><br>
<br>
<input class="input-classic" style="width: 100px; background-color: #101010;" name="total_bill"
type="number" placeholder="Total Bill" autocomplete="off" disabled="">-
<input class="input-classic" style="width: 100px;" onchange="addDiscount(Number(this.value));"
name="discount" type="number" placeholder="Discount" autocomplete="off">
<input class="input-classic" style="width: 90px; background-color: #101010;" name="payable_amt"
type="number" placeholder="Payable ₹" autocomplete="off" disabled="" required="">
</div>
<input type="hidden" name="order_json" value="">
<br>
<!-- PRODUCT LIST -->
<div class="flex-object" id="order_productlist">
<div class="fnt-med">Product List</div>
<div id="product_list">
<script>let products = {};</script>
</div>
</div>
<script>
function countProduct(product_id, operation) {
let count = Number(document.getElementById('product-counter-' + product_id).textContent);
if (operation == 'add') count++;
else { if (count != 0) count--; }
document.getElementById('product-counter-' + product_id).textContent = count;
// CHANGE CSS
if (count == 0) {
document.getElementById('product-' + product_id).classList.remove('non-zero-product');
} else document.getElementById('product-' + product_id).classList.add('non-zero-product');
if (count == 0) delete orderJson[product_id]; else orderJson[product_id] = count;
evaluateBill();
}
function evaluateBill() {
totalBill = 0;
for (let product in orderJson) {
let money = products[product] * orderJson[product];
totalBill += money;
// console.log(totalBill);
}
if (Object.keys(orderJson).length == 0) { totalBill = 0; document.getElementById('createbutton').disabled = true; }
else { document.getElementById('createbutton').disabled = false; }
// CHANGE HTML
document.getElementsByName('total_bill')[0].value = totalBill;
document.getElementsByName('payable_amt')[0].value = totalBill - discount;
document.getElementsByName('order_json')[0].value = JSON.stringify(orderJson);
}
function addDiscount(d) {
discount = d; evaluateBill();
}
</script>
</div>
<br><br>
<button onclick="rememberOrder()" class="big-button" id="createbutton" type="button"
style="font-size: 18px;">Stash</button>
<button onclick="pushOrders()" class="big-button" id="uploadbutton" disabled type="button"
style="font-size: 18px;">Upload Orders</button>
</form>
</div>
</div>
</body>
<!-- POST DOC SCRIPT -->
<script>
// <img src="https://img.icons8.com/ios/50/26e07f/connected.png"/>
let server_connection_status = document.getElementById('server_connection_status');
server_connection_status.src = 'https://img.icons8.com/material-outlined/48/fa314a/no-network.png';
let nativeServerIP = '';
function attemptConnectionToServer() {
connected = false;
document.getElementById('uploadbutton').disabled = true;
server_connection_status.src = 'https://report.lsac.org/Images/Loading.gif';
document.getElementById('server_connection_status_txt').textContent = "Trying to connect @ 'omega'";
document.getElementById('product_list').innerHTML = "Trying to Fetch from server 'omega'...";
fetch('http://192.168.0.106:8000/staff/respond_avail')
.then(response => response.json())
.then(data => {
console.log(data);
connected = data['RESPONSE'];
nativeServerIP = '192.168.0.106';
statusUpdateSERVER(connected, 'omega');
document.getElementById('uploadbutton').disabled = false;
}).catch(function (err) {
console.log(err.message, ": omega");
document.getElementById('server_connection_status_txt').textContent = "Trying to connect @ 'CHARUKRIT'";
document.getElementById('product_list').innerHTML = "Trying to Fetch from server 'CHARUKRIT'...";
// CHARUKRIT
fetch('http://192.168.0.112:8000/staff/respond_avail')
.then(response => response.json())
.then(data => {
console.log(data);
connected = data['RESPONSE'];
nativeServerIP = '192.168.0.112';
statusUpdateSERVER(connected, 'charukrit-pc');
document.getElementById('uploadbutton').disabled = false;
}).catch(function (err) {
console.log(err.message, ": CHARUKRIT");
document.getElementById('server_connection_status_txt').textContent = "Disconnected to Server!";
server_connection_status.src = 'https://img.icons8.com/material-outlined/48/fa314a/no-network.png';
// PASTE CACHED MENU
let cached_menu = JSON.parse(localStorage.getItem('cached_menu'));
pasteMenu(cached_menu);
});
});
}
function statusUpdateSERVER(connected, host) {
if (connected) {
server_connection_status.src = 'https://img.icons8.com/ios/50/26e07f/connected.png';
document.getElementById('server_connection_status_txt').textContent = "Connected! (HOST - " + host + ")";
// Fetch Required Data from server
fetchProducts();
}
}
function fetchProducts() {
fetch('http://' + nativeServerIP + ':8000/staff/fetchMenu')
.then(response => response.json())
.then(MENU => {
console.log(MENU);
// CACHE the MENU card
localStorage.setItem('cached_menu', JSON.stringify(MENU));
pasteMenu(MENU);
});
}
function pasteMenu(MENU) {
let menuHTML = ``;
document.getElementById('product_list').innerHTML = ``;
for (let category in MENU) {
menuHTML += `
<div class="category-head">
${category}
</div>
`;
for (let product in MENU[category]) {
menuHTML += `
<div id="product-${MENU[category][product]["ID"]}" class="product_list-product">
${product} <br>
<span style=" font-weight: 800;">₹${MENU[category][product]["PRICE"]}/-</span>
<div class="productcounter-container">
<span onclick="countProduct('${MENU[category][product]["ID"]}', 'add')" class="add-product">+</span>
<span id="product-counter-${MENU[category][product]["ID"]}" class="counter-product">0</span>
<span onclick="countProduct('${MENU[category][product]["ID"]}', 'substract')" class="add-product">-</span>
</div>
</div>
`;
products[MENU[category][product]["ID"]] = MENU[category][product]["PRICE"];
}
}
document.getElementById('product_list').innerHTML += menuHTML;
}
function rememberOrder() {
let timestamp = (new Date).getTime();
let ORDERS = localStorage.getItem('ORDERS_json');
if (ORDERS == null || ORDERS.trim().length == 0) { localStorage.setItem('ORDERS_json', "{}"); ORDERS = {}; console.log("Created ORDERS_json"); }
// console.log(ORDERS);
ORDERS = JSON.parse(ORDERS); // Make object out of it
let customer_name = document.getElementsByName('customer_name')[0].value;
let customer_phone_no = document.getElementsByName('customer_phone_no')[0].value;
let customer_address = document.getElementsByName('customer_address')[0].value;
let time_of_order = document.getElementsByName('time_of_order')[0].value;
let time_of_delivery = document.getElementsByName('time_of_delivery')[0].value;
let discount = document.getElementsByName('discount')[0].value;
// FRISK DATA
let form = document.getElementById('order_form');
for (var i = 0; i < form.elements.length; i++) {
if (form.elements[i].value === '' && form.elements[i].hasAttribute('required')) {
alert('There are some required fields!');
return false;
}
}
// SAVE DATA as str(json) in localstorage.getItem('ORDERS_json')
ORDERS[timestamp] = {
"customer_name": customer_name,
"customer_phone_no": customer_phone_no,
"customer_address": customer_address,
"time_of_order": time_of_order,
"time_of_delivery": time_of_delivery,
"orderJson": orderJson,
"discount": discount,
}
console.log(ORDERS);
// STASH the Data
localStorage.setItem('ORDERS_json', JSON.stringify(ORDERS));
// RESET HTML
for (let product_id in orderJson) {
document.getElementById('product-counter-' + product_id).textContent = 0;
document.getElementById('product-counter-' + product_id).parentElement.parentElement.classList.remove('non-zero-product');
}
form.reset();
orderJson = {};
}
function pushOrders() {
if (!connected) {
console.log("ERROR!");
return null;
}
let username = window.prompt('KIDEY Username');
let password = window.prompt('Password for ' + username + ': ');
let form = new FormData();
form.set('username', username);
form.set('password', password);
let ORDERS_json = localStorage.getItem('ORDERS_json');
form.set('ORDERS_json', ORDERS_json);
fetch('http://' + nativeServerIP + ':8000/staff/pushOrders__STATIC', {
method: 'POST',
body: form,
headers: {
'Accept': 'multipart/form-data, application/json, text/plain, */*',
},
})
.then(response => response.json())
.then(data => {
console.log(data);
if (data["ERROR"] == null){
localStorage.setItem('ORDERS_json', '{}');
}
});
}
// CONNECT TO SERVERS
let connected;
attemptConnectionToServer();
</script>
</html>