-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
654 lines (425 loc) · 12.5 KB
/
index.html
File metadata and controls
654 lines (425 loc) · 12.5 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
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ByteX POS</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
<style>
body{
font-family:'Inter',sans-serif;
background:radial-gradient(circle at top,#1a1a1a,#050505);
}
.glass{
background:rgba(255,255,255,0.05);
backdrop-filter:blur(20px);
border:1px solid rgba(255,255,255,0.08);
}
.btn{
transition:all .18s ease;
}
.btn:hover{
transform:translateY(-2px) scale(1.03);
}
.btn:active{
transform:scale(.96);
}
.fade{
animation:fade .2s ease;
}
@keyframes fade{
from{opacity:0;transform:translateY(6px)}
to{opacity:1;transform:translateY(0)}
}
</style>
</head>
<body class="text-zinc-200 p-6 min-h-screen">
<div class="max-w-6xl mx-auto">
<h1 class="text-3xl font-semibold mb-8 tracking-tight">
ByteX POS
</h1>
<div class="relative inline-block text-left mb-8 z-50" id="currencyDropdown">
<button onclick="toggleCurrencyDropdown()"
class="glass flex items-center gap-2 px-4 py-2 rounded-xl text-sm hover:bg-white/10 transition">
<span id="currencyLabel">Rupiah</span>
<svg id="currencyArrow"
class="w-4 h-4 transition-transform duration-200"
fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M19 9l-7 7-7-7"/>
</svg>
</button>
<div id="currencyMenu"
class="absolute left-0 mt-2 w-44 rounded-xl glass shadow-xl opacity-0 scale-95 pointer-events-none transition-all duration-200 z-50">
<button onclick="setCurrency('IDR','Rupiah',this)"
class="currencyItem flex justify-between w-full text-left px-4 py-2 hover:bg-white/10 rounded-t-xl">
<span>Rupiah</span>
<span class="check">✔</span>
</button>
<button onclick="setCurrency('MYR','MYR',this)"
class="currencyItem flex justify-between w-full text-left px-4 py-2 hover:bg-white/10">
<span>MYR</span>
<span class="check hidden">✔</span>
</button>
<button onclick="setCurrency('ROBUX','Robux',this)"
class="currencyItem flex justify-between w-full text-left px-4 py-2 hover:bg-white/10 rounded-b-xl">
<span>Robux</span>
<span class="check hidden">✔</span>
</button>
</div>
</div>
<div class="grid lg:grid-cols-2 gap-8">
<div class="glass rounded-2xl p-6 shadow-xl">
<input
id="search"
oninput="renderProducts()"
placeholder="Search product..."
class="w-full bg-black/40 px-4 py-2 rounded-xl mb-4"
/>
<div id="productList" class="space-y-2 mb-6"></div>
<h3 class="text-sm text-zinc-400 mb-2">
Custom Product
</h3>
<input id="customName" placeholder="Name"
class="w-full bg-black/40 rounded-xl px-3 py-2 mb-2"/>
<input id="customPrice" placeholder="Price (Rp)"
class="w-full bg-black/40 rounded-xl px-3 py-2 mb-3"/>
<button onclick="addCustom()"
class="btn bg-white text-black px-4 py-2 rounded-xl font-medium">
Add Product
</button>
</div>
<div class="glass rounded-2xl p-6 shadow-xl flex flex-col">
<h2 class="font-semibold mb-4">
Receipt
</h2>
<div id="cartItems" class="space-y-3 mb-4"></div>
<div class="mb-4 space-y-1">
<div class="flex justify-between text-sm">
<span>Subtotal</span>
<span id="subtotalText">Rp 0</span>
</div>
<div class="flex justify-between text-sm text-zinc-400">
<span>Discount</span>
<span id="discountText">Rp 0</span>
</div>
<div class="flex justify-between text-base font-semibold">
<span>Total</span>
<span id="totalText">Rp 0</span>
</div>
<div class="w-full bg-zinc-800 h-2 rounded-full overflow-hidden mt-2">
<div id="subtotalBar"
class="bg-white h-full w-0 transition-all duration-300"></div>
</div>
</div>
<div class="flex gap-2 mb-4">
<input id="discPercent" oninput="renderCart()" placeholder="%"
class="flex-1 bg-black/40 rounded-xl px-3 py-2"/>
<input id="discAmount" oninput="renderCart()" placeholder="Rp"
class="flex-1 bg-black/40 rounded-xl px-3 py-2"/>
</div>
<button onclick="generateBon()"
class="btn bg-white text-black px-4 py-2 rounded-xl mb-4">
Generate Receipt
</button>
<button id="openReceiptBtn"
onclick="openSuccess()"
class="btn bg-zinc-800 px-4 py-2 rounded-xl mb-4 hidden">
Show Payment Receipt
</button>
<div class="bg-black/40 rounded-xl p-4 text-sm mb-3">
<div class="font-medium mb-2">
Preview
</div>
<pre id="receiptPreview" class="whitespace-pre-wrap text-zinc-300"></pre>
</div>
<button onclick="copyBon()"
class="btn bg-zinc-800 px-4 py-2 rounded-xl">
Copy Receipt
</button>
</div>
</div>
</div>
<div id="successModal" class="fixed inset-0 bg-black/70 hidden items-center justify-center z-50">
<div class="text-center">
<div id="successReceipt" class="glass rounded-3xl p-8 w-[340px] text-center fade">
<div class="text-4xl mb-2">✓</div>
<h2 class="text-xl font-semibold mb-1">
Payment Successful
</h2>
<p class="text-sm text-zinc-400 mb-6">
Thank you for your purchase
</p>
<div class="bg-black/40 rounded-xl p-4 text-sm space-y-2 text-left">
<div class="flex justify-between">
<span class="text-zinc-400">Order ID</span>
<span id="successID"></span>
</div>
<div class="flex justify-between">
<span class="text-zinc-400">Time</span>
<span id="successTime"></span>
</div>
<div class="flex justify-between">
<span class="text-zinc-400">Items</span>
<span id="successItems"></span>
</div>
<div class="flex justify-between font-medium">
<span>Total Paid</span>
<span id="successTotal"></span>
</div>
</div>
</div>
<div id="renderButtons" class="flex gap-3 justify-center mt-4">
<button onclick="renderReceiptImage()"
class="btn bg-white text-black px-4 py-2 rounded-xl text-sm">
Render Image
</button>
<button onclick="closeSuccess()"
class="btn bg-zinc-800 px-4 py-2 rounded-xl text-sm">
Close
</button>
</div>
<div id="imageButtons" class="hidden flex gap-3 justify-center mt-4">
<button onclick="copyImage()"
class="btn bg-white text-black px-4 py-2 rounded-xl text-sm">
Copy Image
</button>
<button onclick="downloadImage()"
class="btn bg-zinc-800 px-4 py-2 rounded-xl text-sm">
Download PNG
</button>
</div>
</div>
</div>
<script>
let products=[]
let cart=[]
let currentCurrency="IDR"
let lastTotal=0
let renderedCanvas=null
let currentOrderID=""
const RP_PER_MYR=3333.33
const RP_PER_ROBUX=66.67
fetch("products.json")
.then(res=>res.json())
.then(data=>{
products=data
renderProducts()
})
function formatPrice(price){
if(currentCurrency==="IDR")
return "Rp "+price.toLocaleString()
if(currentCurrency==="MYR")
return (price/RP_PER_MYR).toFixed(2)+" MYR"
if(currentCurrency==="ROBUX")
return Math.floor(price/RP_PER_ROBUX)+" R$"
}
function toggleCurrencyDropdown(){
let menu=document.getElementById("currencyMenu")
let arrow=document.getElementById("currencyArrow")
menu.classList.toggle("opacity-0")
menu.classList.toggle("scale-95")
menu.classList.toggle("pointer-events-none")
arrow.classList.toggle("rotate-180")
}
document.addEventListener("click",function(e){
let dropdown=document.getElementById("currencyDropdown")
if(!dropdown.contains(e.target)){
let menu=document.getElementById("currencyMenu")
let arrow=document.getElementById("currencyArrow")
menu.classList.add("opacity-0","scale-95","pointer-events-none")
arrow.classList.remove("rotate-180")
}
})
function setCurrency(cur,label,el){
currentCurrency=cur
document.getElementById("currencyLabel").innerText=label
document.querySelectorAll(".check").forEach(c=>c.classList.add("hidden"))
el.querySelector(".check").classList.remove("hidden")
toggleCurrencyDropdown()
renderProducts()
renderCart()
}
function renderProducts(){
let keyword=document.getElementById("search").value.toLowerCase()
let html=""
products
.filter(p=>p.name.toLowerCase().includes(keyword))
.forEach(p=>{
html+=`
<button onclick="addItem('${p.name}',${p.price})"
class="btn w-full text-left bg-black/40 hover:bg-black/60 px-4 py-3 rounded-xl flex justify-between fade">
<span>${p.name}</span>
<span class="text-zinc-400">
${formatPrice(p.price)}
</span>
</button>
`
})
document.getElementById("productList").innerHTML=html
}
function addItem(name,price){
let found=cart.find(i=>i.name===name)
if(found) found.qty++
else cart.push({name,price,qty:1})
renderCart()
}
function changeQty(name,amount){
let item=cart.find(i=>i.name===name)
if(!item) return
item.qty+=amount
if(item.qty<=0)
cart=cart.filter(i=>i.name!==name)
renderCart()
}
function removeItem(name){
cart=cart.filter(i=>i.name!==name)
renderCart()
}
function addCustom(){
let name=document.getElementById("customName").value
let price=parseInt(document.getElementById("customPrice").value)
if(!name||!price) return
cart.push({name,price,qty:1})
renderCart()
}
function renderCart(){
let html=""
let subtotal=0
cart.forEach(i=>{
let total=i.price*i.qty
subtotal+=total
html+=`
<div class="flex justify-between items-center bg-black/40 px-4 py-3 rounded-xl fade">
<div>
<div class="font-medium">
${i.name}
</div>
<div class="text-sm text-zinc-400">
${formatPrice(total)}
</div>
</div>
<div class="flex items-center gap-2">
<button onclick="changeQty('${i.name}',-1)"
class="bg-zinc-800 px-2 rounded">-</button>
<span>${i.qty}</span>
<button onclick="changeQty('${i.name}',1)"
class="bg-zinc-800 px-2 rounded">+</button>
<button onclick="removeItem('${i.name}')"
class="bg-red-600 px-2 rounded">x</button>
</div>
</div>
`
})
document.getElementById("cartItems").innerHTML=html
updateTotals(subtotal)
}
function updateTotals(subtotal){
let discPercent=parseFloat(document.getElementById("discPercent").value)||0
let discAmount=parseFloat(document.getElementById("discAmount").value)||0
let discount=0
if(discPercent>0)
discount=subtotal*(discPercent/100)
if(discAmount>0)
discount=discAmount
let total=subtotal-discount
if(total<0) total=0
lastTotal=total
document.getElementById("subtotalText").innerText=formatPrice(subtotal)
document.getElementById("discountText").innerText="- "+formatPrice(Math.round(discount))
document.getElementById("totalText").innerText=formatPrice(Math.round(total))
let percent=Math.min(subtotal/200000*100,100)
document.getElementById("subtotalBar").style.width=percent+"%"
}
function generateID(){
return "BYTEX-"+Math.random().toString(36).substring(2,10).toUpperCase()
}
function generateBon(){
currentOrderID = generateID()
let id = currentOrderID
let subtotal=0
let text=""
cart.forEach(i=>{
let total=i.price*i.qty
subtotal+=total
text+=`• **${i.name}** × ${i.qty}
↳ ${formatPrice(total)}
`
})
let discPercent=parseFloat(document.getElementById("discPercent").value)||0
let discAmount=parseFloat(document.getElementById("discAmount").value)||0
let discount=0
if(discPercent>0)
discount=subtotal*(discPercent/100)
if(discAmount>0)
discount=discAmount
let total=subtotal-discount
if(total<0) total=0
let now=new Date()
let date=now.toLocaleDateString("id-ID")
let time=now.toLocaleTimeString("id-ID",{
hour:"2-digit",
minute:"2-digit",
second:"2-digit"
})
let bon=`# ByteX Studio
ID: **${id}**
${date} • ${time}
${text}
Subtotal: ${formatPrice(subtotal)}
Discount: -${formatPrice(Math.round(discount))}
TOTAL: ${formatPrice(Math.round(total))}
Bayar di https://tako.id/ByteX`
document.getElementById("receiptPreview").innerText=bon
document.getElementById("openReceiptBtn").classList.remove("hidden")
}
function copyBon(){
navigator.clipboard.writeText(
document.getElementById("receiptPreview").innerText
)
}
function openSuccess(){
let items=0
cart.forEach(i=>items+=i.qty)
let now=new Date()
document.getElementById("successID").innerText=currentOrderID
document.getElementById("successTime").innerText=
now.toLocaleTimeString("id-ID",{hour:"2-digit",minute:"2-digit",second:"2-digit"})
document.getElementById("successItems").innerText=items+" items"
document.getElementById("successTotal").innerText=formatPrice(lastTotal)
document.getElementById("successModal").classList.remove("hidden")
document.getElementById("successModal").classList.add("flex")
}
function closeSuccess(){
document.getElementById("successModal").classList.add("hidden")
}
function renderReceiptImage(){
let node=document.getElementById("successReceipt")
html2canvas(node,{
backgroundColor:null,
scale:3
}).then(canvas=>{
renderedCanvas=canvas
document.getElementById("imageButtons").classList.remove("hidden")
})
}
function downloadImage(){
if(!renderedCanvas) return
let link=document.createElement("a")
link.download="receipt.png"
link.href=renderedCanvas.toDataURL()
link.click()
}
async function copyImage(){
if(!renderedCanvas) return
renderedCanvas.toBlob(async blob=>{
await navigator.clipboard.write([
new ClipboardItem({ "image/png": blob })
])
})
}
</script>
</body>
</html>