zenityx commited on
Commit
9dc695b
·
verified ·
1 Parent(s): 7acb72e

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +79 -18
index.html CHANGED
@@ -1,19 +1,80 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
1
+ <!DOCTYPE html>
2
+ <html lang="th">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <title>รายการออเดอร์ (ครัว)</title>
7
+ <link rel="stylesheet" href="style.css">
8
+ <style>
9
+ body { background: #eef7fa; }
10
+ .kitchen-table { width:100%; border-collapse: collapse; margin-top: 1em; }
11
+ .kitchen-table th, .kitchen-table td { border: 1px solid #b3d2e5; padding: 6px 8px; text-align: left; }
12
+ .kitchen-table th { background: #cee6fa; }
13
+ .refresh-btn { background: #2177c2; color: #fff; border: none; border-radius: 8px; padding: 6px 18px; margin-bottom: 12px; cursor:pointer; }
14
+ .k-row { font-size: 1.15em; }
15
+ @media (max-width: 520px) {
16
+ .kitchen-table td, .kitchen-table th { padding: 3px 4px; font-size: 0.97em; }
17
+ }
18
+ </style>
19
+ </head>
20
+ <body>
21
+ <div class="container">
22
+ <h2 style="text-align:center;">ออเดอร์เข้าครัว</h2>
23
+ <button class="refresh-btn" onclick="fetchKitchenOrders()">รีเฟรชรายการ</button>
24
+ <div id="kitchen-orders"></div>
25
+ </div>
26
+ <script>
27
+ const scriptURL = "https://api.sheetbest.com/sheets/67a68e64-dca9-4eea-99b7-0431c5786cf6";
28
+ function getLatestUnpaidOrders(data) {
29
+ // ใช้ key โต๊ะ+เมนู (กรณีแต่ละโต๊ะสั่งเมนูซ้ำ)
30
+ const latest = {};
31
+ data.forEach((row, idx) => {
32
+ const key = `${row.table}__${row.menu}`;
33
+ latest[key] = { ...row, idx };
34
+ });
35
+ return Object.values(latest).filter(r => (r.status ?? "unpaid") === "unpaid");
36
+ }
37
+ async function fetchKitchenOrders() {
38
+ document.querySelector('.refresh-btn').disabled = true;
39
+ document.querySelector('.refresh-btn').textContent = 'กำลังโหลด...';
40
+ const res = await fetch(scriptURL);
41
+ const data = await res.json();
42
+ const orders = getLatestUnpaidOrders(data);
43
+ // รวมจำนวนต่อเมนู+โต๊ะ
44
+ const summary = {};
45
+ orders.forEach(item => {
46
+ const key = `${item.table}__${item.menu}`;
47
+ if (!summary[key]) summary[key] = { menu: item.menu, table: item.table, qty: 0, note: "", time: item.timestamp || "" };
48
+ summary[key].qty += Number(item.qty || 1);
49
+ if (item.note && item.note.trim() && summary[key].note.trim() === "") summary[key].note = item.note;
50
+ if (item.timestamp) summary[key].time = item.timestamp;
51
+ });
52
+
53
+ let html = `<table class="kitchen-table">
54
+ <tr>
55
+ <th>โต๊ะ</th>
56
+ <th>เมนู</th>
57
+ <th>จำนวน</th>
58
+ <th>หมายเหตุ</th>
59
+ <th>เวลา</th>
60
+ </tr>`;
61
+ Object.values(summary).forEach(row => {
62
+ html += `<tr class="k-row">
63
+ <td>${row.table}</td>
64
+ <td>${row.menu}</td>
65
+ <td style="text-align:center;font-weight:bold">${row.qty}</td>
66
+ <td>${row.note||""}</td>
67
+ <td style="font-size:0.9em;color:#237;">${(row.time||'').replace('T','<br>')}</td>
68
+ </tr>`;
69
+ });
70
+ html += `</table>`;
71
+ if (Object.keys(summary).length === 0) html = "<div style='color:#aaa;text-align:center'>ยังไม่มีออเดอร์ใหม่</div>";
72
+ document.getElementById('kitchen-orders').innerHTML = html;
73
+ document.querySelector('.refresh-btn').disabled = false;
74
+ document.querySelector('.refresh-btn').textContent = 'รีเฟรชรายการ';
75
+ }
76
+ // ดึงข้อมูลรอบแรก
77
+ fetchKitchenOrders();
78
+ </script>
79
+ </body>
80
  </html>