-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
483 lines (410 loc) · 22.2 KB
/
index.html
File metadata and controls
483 lines (410 loc) · 22.2 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SuperPOS Pro | Retail Management System</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/html5-qrcode" type="text/javascript"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&family=Inter:wght@300;400;600;800&display=swap" rel="stylesheet">
<style>
/* Enterprise Styling */
body { font-family: 'Inter', sans-serif; background-color: #0f172a; color: #e2e8f0; height: 100vh; overflow: hidden; }
.font-mono { font-family: 'JetBrains Mono', monospace; }
/* POS Layout */
.pos-grid { display: grid; grid-template-columns: 280px 1fr 400px; height: 100vh; }
/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #1e293b; }
::-webkit-scrollbar-thumb { background: #475569; border-radius: 3px; }
/* Animations */
.flash { animation: flash-anim 0.2s; }
@keyframes flash-anim { 0% { background-color: #22c55e; } 100% { background-color: transparent; } }
/* Receipt Print Layout */
@media print {
body { background: white; color: black; height: auto; overflow: visible; }
.no-print { display: none !important; }
#receipt-modal { position: static; background: white; width: 100%; border: none; box-shadow: none; display: block !important; }
.print-area { width: 80mm; margin: 0 auto; }
}
/* Mobile Responsive Fallback */
@media (max-width: 1024px) {
.pos-grid { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
.sidebar { display: none; }
.bill-panel { position: fixed; bottom: 0; left: 0; width: 100%; height: 60vh; transform: translateY(100%); transition: 0.3s; z-index: 50; }
.bill-panel.open { transform: translateY(0); }
}
</style>
</head>
<body>
<div class="pos-grid">
<aside class="sidebar bg-slate-900 border-r border-slate-800 flex flex-col no-print">
<div class="p-6 border-b border-slate-800 flex items-center gap-3">
<div class="w-10 h-10 bg-blue-600 rounded-lg flex items-center justify-center font-bold text-xl">S</div>
<div>
<h1 class="font-bold text-lg leading-none">SuperPOS</h1>
<span class="text-xs text-slate-500">v2.4 Enterprise</span>
</div>
</div>
<nav class="flex-1 p-4 space-y-2">
<button onclick="setView('pos')" id="nav-pos" class="w-full flex items-center gap-3 px-4 py-3 rounded-lg bg-blue-600 text-white font-medium transition">
<i class="fa-solid fa-cash-register"></i> Billing Terminal
</button>
<button onclick="setView('inventory')" id="nav-inventory" class="w-full flex items-center gap-3 px-4 py-3 rounded-lg hover:bg-slate-800 text-slate-400 font-medium transition">
<i class="fa-solid fa-boxes-stacked"></i> Inventory Manager
</button>
<button onclick="setView('transactions')" id="nav-transactions" class="w-full flex items-center gap-3 px-4 py-3 rounded-lg hover:bg-slate-800 text-slate-400 font-medium transition">
<i class="fa-solid fa-clock-rotate-left"></i> History
</button>
</nav>
<div class="p-4 bg-slate-800 mt-auto">
<div class="flex items-center justify-between mb-2">
<span class="text-xs text-slate-400 uppercase">Shift Status</span>
<span class="text-xs font-bold text-green-400">● Online</span>
</div>
<div class="text-sm font-bold">Operator: Adhi</div>
<div class="text-xs text-slate-500" id="clock">00:00:00</div>
</div>
</aside>
<main class="bg-slate-950 flex flex-col relative">
<header class="h-16 border-b border-slate-800 flex items-center justify-between px-6 bg-slate-900 no-print">
<div class="flex items-center gap-4">
<h2 class="font-bold text-slate-200" id="page-title">Billing Terminal</h2>
<span id="scanner-status" class="text-xs px-2 py-1 rounded bg-red-900/50 text-red-400 border border-red-800">Scanner Offline</span>
</div>
<div class="flex gap-3">
<button onclick="toggleScanner()" class="px-4 py-2 bg-slate-800 hover:bg-slate-700 rounded-lg text-sm border border-slate-700 transition">
<i class="fa-solid fa-camera"></i> Toggle Camera
</button>
<button onclick="resetCart()" class="px-4 py-2 bg-red-900/30 text-red-400 hover:bg-red-900/50 rounded-lg text-sm border border-red-900/50 transition">
<i class="fa-solid fa-ban"></i> Cancel Order
</button>
</div>
</header>
<div id="view-pos" class="flex-1 p-6 overflow-y-auto">
<div id="scanner-container" class="hidden mb-6 bg-black rounded-xl overflow-hidden border-2 border-slate-700 shadow-2xl relative h-64">
<div id="reader" class="w-full h-full"></div>
<div class="absolute inset-0 border-2 border-red-500/50 pointer-events-none m-12 rounded opacity-50"></div>
<div class="absolute bottom-2 left-0 w-full text-center text-xs text-white/70">Point at barcode</div>
</div>
<div class="bg-slate-900 p-6 rounded-xl border border-slate-800 shadow-lg">
<label class="text-xs font-bold text-slate-400 uppercase mb-2 block">Product Lookup</label>
<div class="flex gap-3">
<div class="relative flex-1">
<i class="fa-solid fa-barcode absolute left-4 top-4 text-slate-500"></i>
<input type="text" id="barcode-input" placeholder="Scan or type barcode (e.g. 123)"
class="w-full bg-slate-950 border border-slate-700 rounded-lg py-3 pl-12 pr-4 text-white font-mono focus:border-blue-500 focus:outline-none transition"
autofocus>
</div>
<button onclick="manualScan()" class="bg-blue-600 hover:bg-blue-500 text-white px-8 rounded-lg font-bold transition">ENTER</button>
</div>
<div class="mt-6">
<p class="text-xs text-slate-500 mb-3">QUICK ACCESS KEYS</p>
<div class="grid grid-cols-4 gap-3" id="quick-keys">
</div>
</div>
</div>
</div>
<div id="view-inventory" class="hidden flex-1 p-6">
<div class="bg-slate-900 rounded-xl border border-slate-800 overflow-hidden">
<div class="p-4 border-b border-slate-800 flex justify-between">
<h3 class="font-bold">Stock Database</h3>
<button onclick="openAddModal()" class="text-blue-400 text-sm hover:underline">+ Add New Item</button>
</div>
<table class="w-full text-left text-sm">
<thead class="bg-slate-950 text-slate-400">
<tr><th class="p-4">Barcode</th><th class="p-4">Name</th><th class="p-4 text-right">Price</th><th class="p-4 text-center">Action</th></tr>
</thead>
<tbody id="inventory-list" class="divide-y divide-slate-800"></tbody>
</table>
</div>
</div>
</main>
<aside class="bill-panel bg-slate-900 border-l border-slate-800 flex flex-col w-full h-full no-print">
<div class="p-4 border-b border-slate-800 bg-slate-900">
<h3 class="font-bold text-slate-300">Current Transaction</h3>
<p class="text-xs text-slate-500">INV-<span id="invoice-num">...</span></p>
</div>
<div class="flex-1 overflow-y-auto p-2 space-y-1" id="cart-list">
<div class="h-full flex flex-col items-center justify-center text-slate-600 opacity-50">
<i class="fa-solid fa-basket-shopping text-4xl mb-2"></i>
<p>Cart Empty</p>
</div>
</div>
<div class="p-6 bg-slate-950 border-t border-slate-800 shadow-[0_-10px_40px_rgba(0,0,0,0.3)]">
<div class="space-y-2 mb-4 text-sm">
<div class="flex justify-between text-slate-400"><span>Subtotal</span><span id="lbl-sub">0.00</span></div>
<div class="flex justify-between text-slate-400"><span>Tax (GST 18%)</span><span id="lbl-tax">0.00</span></div>
</div>
<div class="flex justify-between items-end mb-6">
<span class="text-xl font-bold text-white">TOTAL</span>
<span class="text-4xl font-mono font-bold text-green-400">₹<span id="lbl-total">0.00</span></span>
</div>
<button onclick="openPaymentModal()" class="w-full bg-green-600 hover:bg-green-500 text-white py-4 rounded-xl font-bold text-lg shadow-lg shadow-green-900/20 transition transform active:scale-95">
PROCEED TO PAY
</button>
</div>
</aside>
</div>
<div id="payment-modal" class="fixed inset-0 bg-black/80 z-50 hidden flex items-center justify-center backdrop-blur-sm p-4 no-print">
<div class="bg-slate-900 w-full max-w-md rounded-2xl border border-slate-700 shadow-2xl p-6">
<h3 class="text-xl font-bold text-white mb-6">Select Payment Method</h3>
<div class="grid grid-cols-3 gap-4 mb-6">
<button onclick="completePayment('CASH')" class="bg-slate-800 hover:bg-slate-700 p-4 rounded-xl border border-slate-700 flex flex-col items-center gap-2 transition">
<i class="fa-solid fa-money-bill-wave text-2xl text-green-400"></i>
<span class="text-xs font-bold">CASH</span>
</button>
<button onclick="completePayment('UPI')" class="bg-slate-800 hover:bg-slate-700 p-4 rounded-xl border border-slate-700 flex flex-col items-center gap-2 transition">
<i class="fa-solid fa-qrcode text-2xl text-blue-400"></i>
<span class="text-xs font-bold">UPI</span>
</button>
<button onclick="completePayment('CARD')" class="bg-slate-800 hover:bg-slate-700 p-4 rounded-xl border border-slate-700 flex flex-col items-center gap-2 transition">
<i class="fa-solid fa-credit-card text-2xl text-yellow-400"></i>
<span class="text-xs font-bold">CARD</span>
</button>
</div>
<button onclick="document.getElementById('payment-modal').classList.add('hidden')" class="w-full py-3 text-slate-400 hover:text-white">Cancel</button>
</div>
</div>
<div id="add-modal" class="fixed inset-0 bg-black/80 z-50 hidden flex items-center justify-center p-4 no-print">
<div class="bg-slate-900 w-full max-w-sm rounded-xl border border-slate-700 p-6">
<h3 class="font-bold text-white mb-4">Add Inventory</h3>
<input id="new-code" placeholder="Barcode" class="w-full bg-slate-950 border border-slate-700 rounded p-3 mb-3 text-white">
<input id="new-name" placeholder="Product Name" class="w-full bg-slate-950 border border-slate-700 rounded p-3 mb-3 text-white">
<input id="new-price" type="number" placeholder="Price" class="w-full bg-slate-950 border border-slate-700 rounded p-3 mb-4 text-white">
<button onclick="saveProduct()" class="w-full bg-blue-600 text-white py-3 rounded font-bold">Save Item</button>
<button onclick="document.getElementById('add-modal').classList.add('hidden')" class="w-full py-3 text-slate-500">Cancel</button>
</div>
</div>
<div id="receipt-modal" class="hidden print-area">
<div class="text-center font-mono text-black p-4">
<h1 class="text-2xl font-bold mb-1">SUPERMART RETAIL</h1>
<p class="text-sm">Store ID: #8842 • Bangalore</p>
<p class="text-sm mb-4">GSTIN: 29AAAAA0000A1Z5</p>
<div class="border-b-2 border-dashed border-black my-2"></div>
<div class="flex justify-between text-sm font-bold my-2">
<span>ITEM</span>
<span>AMT</span>
</div>
<div class="border-b-2 border-dashed border-black my-2"></div>
<div id="print-items" class="text-sm space-y-1 text-left"></div>
<div class="border-b-2 border-dashed border-black my-4"></div>
<div class="flex justify-between text-xl font-bold">
<span>TOTAL</span>
<span id="print-total">0.00</span>
</div>
<div class="mt-8 text-center text-sm">
<p>Payment Mode: <span id="print-mode">CASH</span></p>
<p class="mt-2">Thank you for shopping!</p>
</div>
</div>
</div>
<script>
// --- 1. DATA CORE ---
let db = JSON.parse(localStorage.getItem('superpos_db')) || {
'101': { name: 'Fresh Milk 500ml', price: 28 },
'102': { name: 'Whole Wheat Bread', price: 45 },
'103': { name: 'Farm Eggs (6pcs)', price: 55 },
'104': { name: 'Maggi Noodles', price: 14 },
'105': { name: 'Coca Cola 750ml', price: 40 },
'106': { name: 'Lays Chips', price: 20 }
};
let cart = [];
let scanner = null;
let currentInv = Math.floor(Math.random() * 900000) + 100000;
// --- 2. INITIALIZATION ---
window.onload = () => {
document.getElementById('invoice-num').innerText = currentInv;
renderQuickKeys();
renderInventory();
document.getElementById('barcode-input').focus();
// Clock
setInterval(() => {
document.getElementById('clock').innerText = new Date().toLocaleTimeString();
}, 1000);
};
// --- 3. SCANNER LOGIC (Robust) ---
function toggleScanner() {
const container = document.getElementById('scanner-container');
const status = document.getElementById('scanner-status');
if (container.classList.contains('hidden')) {
// Turning ON
container.classList.remove('hidden');
status.innerText = "Initializing...";
status.className = "text-xs px-2 py-1 rounded bg-yellow-900/50 text-yellow-400 border border-yellow-800";
scanner = new Html5Qrcode("reader");
scanner.start({ facingMode: "environment" }, { fps: 10, qrbox: 250 },
onScanSuccess,
(err) => {
console.log("Scan error (normal if no code in view)");
}
).then(() => {
status.innerText = "● Scanner Active";
status.className = "text-xs px-2 py-1 rounded bg-green-900/50 text-green-400 border border-green-800";
}).catch(err => {
status.innerText = "Camera Blocked";
status.className = "text-xs px-2 py-1 rounded bg-red-900/50 text-red-400 border border-red-800";
alert("Camera Error: Browser blocked access. Use 'localhost' or HTTPS.");
container.classList.add('hidden');
});
} else {
// Turning OFF
if (scanner) scanner.stop().then(() => scanner.clear());
container.classList.add('hidden');
status.innerText = "Scanner Offline";
status.className = "text-xs px-2 py-1 rounded bg-red-900/50 text-red-400 border border-red-800";
}
}
function onScanSuccess(code) {
// Play Beep
new Audio('https://www.soundjay.com/buttons/beep-01a.mp3').play();
// Add Item
processBarcode(code);
// Pause briefly to prevent double scan
if(scanner) scanner.pause();
setTimeout(() => scanner && scanner.resume(), 1000);
}
// --- 4. CORE BILLING LOGIC ---
function manualScan() {
const input = document.getElementById('barcode-input');
const code = input.value.trim();
if(code) processBarcode(code);
input.value = "";
input.focus();
}
function processBarcode(code) {
if (db[code]) {
addToCart(code);
} else {
// Auto-prompt to add new item
if(confirm(`Item ${code} not found. Add to database?`)) {
openAddModal(code);
}
}
}
function addToCart(code) {
const item = db[code];
const existing = cart.find(x => x.code === code);
if (existing) existing.qty++;
else cart.push({ code, ...item, qty: 1 });
renderCart();
}
function renderCart() {
const list = document.getElementById('cart-list');
if (cart.length === 0) {
list.innerHTML = `<div class="h-full flex flex-col items-center justify-center text-slate-600 opacity-50"><i class="fa-solid fa-basket-shopping text-4xl mb-2"></i><p>Cart Empty</p></div>`;
updateTotals(0);
return;
}
list.innerHTML = cart.map((item, i) => `
<div class="bg-slate-800 p-3 rounded flex justify-between items-center group">
<div>
<div class="text-white font-bold text-sm">${item.name}</div>
<div class="text-xs text-slate-400">₹${item.price} x ${item.qty}</div>
</div>
<div class="flex items-center gap-3">
<span class="font-mono font-bold text-white">₹${item.price * item.qty}</span>
<button onclick="remItem(${i})" class="text-red-500 opacity-0 group-hover:opacity-100 transition"><i class="fa-solid fa-trash"></i></button>
</div>
</div>
`).join('');
const total = cart.reduce((sum, x) => sum + (x.price * x.qty), 0);
updateTotals(total);
}
function updateTotals(subtotal) {
const tax = subtotal * 0.18;
const total = subtotal + tax;
document.getElementById('lbl-sub').innerText = subtotal.toFixed(2);
document.getElementById('lbl-tax').innerText = tax.toFixed(2);
document.getElementById('lbl-total').innerText = total.toFixed(2);
}
function remItem(i) {
cart.splice(i, 1);
renderCart();
}
// --- 5. PAYMENT & PRINT ---
function openPaymentModal() {
if (cart.length === 0) return alert("Cart is empty!");
document.getElementById('payment-modal').classList.remove('hidden');
}
function completePayment(mode) {
// Setup Receipt
document.getElementById('print-mode').innerText = mode;
document.getElementById('print-total').innerText = document.getElementById('lbl-total').innerText;
document.getElementById('print-items').innerHTML = cart.map(x =>
`<div class="flex justify-between mb-1"><span>${x.name} x${x.qty}</span><span>${(x.price*x.qty).toFixed(2)}</span></div>`
).join('');
// Close Modal & Print
document.getElementById('payment-modal').classList.add('hidden');
window.print();
// Reset
resetCart();
currentInv++;
document.getElementById('invoice-num').innerText = currentInv;
}
function resetCart() {
cart = [];
renderCart();
}
// --- 6. INVENTORY MANAGEMENT ---
function openAddModal(prefillCode = "") {
document.getElementById('add-modal').classList.remove('hidden');
document.getElementById('new-code').value = prefillCode;
document.getElementById('new-name').focus();
}
function saveProduct() {
const code = document.getElementById('new-code').value;
const name = document.getElementById('new-name').value;
const price = Number(document.getElementById('new-price').value);
if (code && name && price) {
db[code] = { name, price };
localStorage.setItem('superpos_db', JSON.stringify(db));
renderInventory();
renderQuickKeys();
document.getElementById('add-modal').classList.add('hidden');
// If we came from scanning, add to cart immediately
if (cart.length > 0 || confirm("Add new item to current bill?")) {
addToCart(code);
}
}
}
function renderInventory() {
const tbody = document.getElementById('inventory-list');
tbody.innerHTML = Object.entries(db).map(([code, item]) => `
<tr class="hover:bg-slate-800 border-b border-slate-800 text-slate-300">
<td class="p-4 font-mono">${code}</td>
<td class="p-4 font-bold text-white">${item.name}</td>
<td class="p-4 text-right">₹${item.price}</td>
<td class="p-4 text-center"><button onclick="deleteProduct('${code}')" class="text-red-500 hover:text-red-400"><i class="fa-solid fa-trash"></i></button></td>
</tr>
`).join('');
}
function renderQuickKeys() {
const div = document.getElementById('quick-keys');
div.innerHTML = Object.entries(db).slice(0, 8).map(([code, item]) => `
<button onclick="processBarcode('${code}')" class="bg-slate-800 hover:bg-blue-600 border border-slate-700 rounded p-2 text-left transition group">
<div class="text-xs text-slate-500 group-hover:text-blue-200">${code}</div>
<div class="font-bold text-white text-sm truncate">${item.name}</div>
</button>
`).join('');
}
function deleteProduct(code) {
if(confirm("Delete this item?")) {
delete db[code];
localStorage.setItem('superpos_db', JSON.stringify(db));
renderInventory();
renderQuickKeys();
}
}
// --- 7. NAVIGATION ---
function setView(viewId) {
['pos', 'inventory', 'transactions'].forEach(v => document.getElementById('view-'+v)?.classList.add('hidden'));
document.getElementById('view-'+viewId)?.classList.remove('hidden');
// Update Title
const titles = { 'pos': 'Billing Terminal', 'inventory': 'Stock Manager', 'transactions': 'Transaction History' };
document.getElementById('page-title').innerText = titles[viewId];
}
</script>
</body>
</html>