<!DOCTYPE html>
<html lang="th">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Table Booking System</title>
<link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Thai:wght@200;300;400;500;600;700&display=swap" rel="stylesheet">
<!-- QR Code Library -->
<script src="https://cdn.jsdelivr.net/npm/qrious@4.0.2/dist/qrious.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'IBM Plex Sans Thai', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
min-height: 100vh;
color: #333;
overflow-x: hidden;
position: relative;
}
body::before {
content: '';
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background:
radial-gradient(circle at 20% 20%, rgba(120, 119, 198, 0.3) 0%, transparent 50%),
radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
radial-gradient(circle at 40% 40%, rgba(138, 43, 226, 0.2) 0%, transparent 50%);
pointer-events: none;
z-index: -1;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.header {
text-align: center;
margin-bottom: 40px;
animation: fadeInDown 0.8s ease-out;
}
.header h1 {
color: white;
font-size: 2.5rem;
font-weight: 700;
margin-bottom: 10px;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.header p {
color: rgba(255, 255, 255, 0.9);
font-size: 1.1rem;
font-weight: 300;
}
.main-content {
display: block;
animation: fadeInUp 0.8s ease-out;
}
.table-section {
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(20px);
border-radius: 24px;
box-shadow:
0 25px 50px rgba(0, 0, 0, 0.1),
0 0 0 1px rgba(255, 255, 255, 0.2);
padding: 40px;
margin-bottom: 30px;
border: 1px solid rgba(255, 255, 255, 0.2);
}
.section-title {
font-size: 1.8rem;
font-weight: 600;
margin-bottom: 20px;
color: #1e293b;
display: flex;
align-items: center;
gap: 10px;
}
.table-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 20px;
margin-bottom: 20px;
}
.table-card {
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.3);
border-radius: 20px;
padding: 25px;
cursor: pointer;
transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
position: relative;
overflow: hidden;
}
.table-card::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
transition: left 0.5s;
}
.table-card:hover::before {
left: 100%;
}
.table-card:hover {
transform: translateY(-8px) scale(1.02);
box-shadow:
0 25px 50px rgba(0, 0, 0, 0.2),
0 0 0 1px rgba(59, 130, 246, 0.3);
border-color: rgba(59, 130, 246, 0.5);
}
.table-card.available {
border-color: rgba(16, 185, 129, 0.5);
background: linear-gradient(135deg, rgba(240, 253, 244, 0.9) 0%, rgba(236, 253, 245, 0.9) 100%);
}
.table-card.available:hover {
border-color: rgba(16, 185, 129, 0.7);
box-shadow:
0 25px 50px rgba(16, 185, 129, 0.2),
0 0 0 1px rgba(16, 185, 129, 0.3);
}
.table-card.occupied {
background: linear-gradient(135deg, rgba(254, 226, 226, 0.9) 0%, rgba(252, 165, 165, 0.9) 100%);
border-color: rgba(248, 113, 113, 0.5);
color: #dc2626;
cursor: not-allowed;
}
.table-card.occupied:hover {
transform: none;
box-shadow: none;
}
.table-card.occupied::before {
display: none;
}
.table-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
}
.table-number {
font-size: 1.5rem;
font-weight: 700;
color: #1e293b;
}
.table-status {
padding: 4px 12px;
border-radius: 20px;
font-size: 0.8rem;
font-weight: 500;
text-transform: uppercase;
}
.table-status.available {
background: #10b981;
color: white;
}
.table-status.occupied {
background: #dc2626;
color: white;
}
.table-details {
margin-bottom: 15px;
}
.table-detail {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: #64748b;
}
.table-price {
font-size: 1.2rem;
font-weight: 600;
color: #3b82f6;
margin-bottom: 15px;
}
.book-btn {
width: 100%;
padding: 14px;
background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
color: white;
border: none;
border-radius: 16px;
font-size: 1rem;
font-weight: 500;
cursor: pointer;
transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
font-family: inherit;
position: relative;
overflow: hidden;
}
.book-btn::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
transition: left 0.5s;
}
.book-btn:hover::before {
left: 100%;
}
.book-btn:hover {
background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
transform: translateY(-2px);
box-shadow: 0 10px 25px rgba(59, 130, 246, 0.4);
}
.book-btn:disabled {
background: linear-gradient(135deg, #9ca3af 0%, #6b7280 100%);
cursor: not-allowed;
transform: none;
box-shadow: none;
}
.book-btn:disabled::before {
display: none;
}
/* Modal Styles */
.modal {
display: none;
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
animation: fadeIn 0.3s ease-out;
}
.modal-content {
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(20px);
margin: 5% auto;
padding: 0;
border-radius: 24px;
width: 90%;
max-width: 500px;
max-height: 90vh;
overflow-y: auto;
animation: slideIn 0.3s ease-out;
border: 1px solid rgba(255, 255, 255, 0.3);
box-shadow:
0 25px 50px rgba(0, 0, 0, 0.3),
0 0 0 1px rgba(255, 255, 255, 0.2);
}
.modal-header {
padding: 25px;
border-bottom: 1px solid #e2e8f0;
display: flex;
justify-content: space-between;
align-items: center;
}
.modal-title {
font-size: 1.5rem;
font-weight: 600;
color: #1e293b;
}
.close-btn {
background: none;
border: none;
font-size: 1.5rem;
cursor: pointer;
color: #64748b;
padding: 5px;
border-radius: 50%;
transition: background 0.3s ease;
}
.close-btn:hover {
background: #f1f5f9;
}
.modal-body {
padding: 25px;
}
.form-group {
margin-bottom: 20px;
}
.form-label {
display: block;
margin-bottom: 8px;
font-weight: 500;
color: #374151;
}
.form-input {
width: 100%;
padding: 16px 20px;
border: 2px solid rgba(229, 231, 235, 0.6);
border-radius: 16px;
font-size: 16px;
transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(10px);
font-family: inherit;
}
.form-input:focus {
outline: none;
border-color: #3b82f6;
box-shadow:
0 0 0 4px rgba(59, 130, 246, 0.1),
0 8px 25px rgba(59, 130, 246, 0.15);
transform: translateY(-2px);
background: rgba(255, 255, 255, 0.95);
}
.date-time-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 15px;
}
.booking-summary {
background: linear-gradient(135deg, rgba(248, 250, 252, 0.9) 0%, rgba(241, 245, 249, 0.9) 100%);
backdrop-filter: blur(10px);
border-radius: 20px;
padding: 25px;
margin-bottom: 20px;
border: 1px solid rgba(226, 232, 240, 0.6);
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
}
.summary-item {
display: flex;
justify-content: space-between;
margin-bottom: 12px;
padding: 8px 0;
border-bottom: 1px solid rgba(226, 232, 240, 0.3);
}
.summary-item:last-child {
border-bottom: none;
}
.summary-total {
border-top: 2px solid rgba(59, 130, 246, 0.2);
padding-top: 15px;
font-weight: 600;
font-size: 1.1rem;
color: #3b82f6;
background: linear-gradient(135deg, rgba(59, 130, 246, 0.1) 0%, rgba(29, 78, 216, 0.1) 100%);
border-radius: 12px;
padding: 15px;
margin-top: 10px;
}
.payment-section {
text-align: center;
padding: 30px;
background: linear-gradient(135deg, rgba(248, 250, 252, 0.8) 0%, rgba(241, 245, 249, 0.8) 100%);
border-radius: 20px;
margin-bottom: 20px;
border: 1px solid rgba(226, 232, 240, 0.5);
}
.qr-code {
width: 220px;
height: 220px;
margin: 20px auto;
background: white;
border-radius: 16px;
display: flex;
align-items: center;
justify-content: center;
border: 3px solid #e2e8f0;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
overflow: hidden;
}
.qr-code img {
width: 100%;
height: 100%;
object-fit: cover;
}
.qr-placeholder {
font-size: 3rem;
color: #94a3b8;
}
.payment-info {
color: #64748b;
margin-bottom: 20px;
}
.btn {
padding: 14px 28px;
border: none;
border-radius: 16px;
font-size: 16px;
font-weight: 500;
cursor: pointer;
transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
font-family: inherit;
display: inline-flex;
align-items: center;
gap: 8px;
position: relative;
overflow: hidden;
}
.btn::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
transition: left 0.5s;
}
.btn:hover::before {
left: 100%;
}
.btn-primary {
background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
color: white;
box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}
.btn-primary:hover {
background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
transform: translateY(-2px);
box-shadow: 0 8px 25px rgba(59, 130, 246, 0.4);
}
.btn-secondary {
background: linear-gradient(135deg, #64748b 0%, #475569 100%);
color: white;
box-shadow: 0 4px 15px rgba(100, 116, 139, 0.3);
}
.btn-secondary:hover {
background: linear-gradient(135deg, #475569 0%, #334155 100%);
transform: translateY(-2px);
box-shadow: 0 8px 25px rgba(100, 116, 139, 0.4);
}
.btn-success {
background: linear-gradient(135deg, #10b981 0%, #059669 100%);
color: white;
box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}
.btn-success:hover {
background: linear-gradient(135deg, #059669 0%, #047857 100%);
transform: translateY(-2px);
box-shadow: 0 8px 25px rgba(16, 185, 129, 0.4);
}
.btn-group {
display: flex;
gap: 15px;
justify-content: flex-end;
}
.success-message {
text-align: center;
padding: 50px 40px;
}
.success-icon {
font-size: 5rem;
color: #10b981;
margin-bottom: 25px;
animation: pulse 2s infinite;
}
.booking-id {
background: linear-gradient(135deg, #f0fdf4 0%, #bbf7d0 100%);
border: 2px solid #bbf7d0;
border-radius: 16px;
padding: 20px;
margin: 25px 0;
font-family: 'IBM Plex Sans Thai', monospace;
font-size: 1.2rem;
color: #166534;
font-weight: 600;
box-shadow: 0 8px 25px rgba(16, 185, 129, 0.15);
}
.floating-particles {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: -1;
}
.particle {
position: absolute;
background: rgba(255, 255, 255, 0.1);
border-radius: 50%;
animation: float 6s ease-in-out infinite;
}
@keyframes fadeInDown {
from {
opacity: 0;
transform: translateY(-30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateY(-50px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes float {
0%,
100% {
transform: translateY(0px);
}
50% {
transform: translateY(-20px);
}
}
@keyframes pulse {
0%,
100% {
transform: scale(1);
}
50% {
transform: scale(1.05);
}
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.material-symbols-outlined {
font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}
@media (max-width: 768px) {
.container {
padding: 10px;
}
.header h1 {
font-size: 2rem;
}
.table-grid {
grid-template-columns: 1fr;
}
.table-section {
padding: 20px;
}
.modal-content {
width: 95%;
margin: 10px auto;
}
.date-time-row {
grid-template-columns: 1fr;
}
.btn-group {
flex-direction: column;
}
.btn {
width: 100%;
justify-content: center;
}
.qr-code {
width: 180px;
height: 180px;
}
.header h1 {
font-size: 2.2rem;
}
.table-card {
padding: 20px;
}
.payment-section {
padding: 25px 20px;
}
.success-message {
padding: 40px 20px;
}
.success-icon {
font-size: 4rem;
}
.booking-id {
font-size: 1rem;
padding: 15px;
}
}
</style>
</head>
<body>
<div class="floating-particles" id="particles"></div>
<div class="container">
<div class="header">
<h1>Table Booking System</h1>
<p>เลือกโต๊ะที่ต้องการจองได้ทันที</p>
</div>
<div class="main-content">
<div class="table-section">
<h2 class="section-title">
<span class="material-symbols-outlined">table_restaurant</span>
เลือกโต๊ะ
</h2>
<div class="table-grid" id="tableGrid">
<!-- Tables will be generated by JavaScript -->
</div>
</div>
</div>
</div>
<!-- Booking Modal -->
<div id="bookingModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">จองโต๊ะ</h3>
<button class="close-btn" onclick="closeModal()">×</button>
</div>
<div class="modal-body">
<div id="bookingForm">
<div class="form-group">
<label class="form-label">ชื่อ-นามสกุล</label>
<input type="text" class="form-input" id="customerName" placeholder="กรอกชื่อ-นามสกุล">
</div>
<div class="form-group">
<label class="form-label">เบอร์โทรศัพท์</label>
<input type="tel" class="form-input" id="customerPhone" placeholder="กรอกเบอร์โทรศัพท์">
</div>
<div class="form-group">
<label class="form-label">จำนวนแขก</label>
<input type="number" class="form-input" id="guestCount" min="1" max="12" placeholder="จำนวนแขก">
</div>
<div class="date-time-row">
<div class="form-group">
<label class="form-label">วันที่</label>
<input type="date" class="form-input" id="bookingDate">
</div>
<div class="form-group">
<label class="form-label">เวลา</label>
<select class="form-input" id="bookingTime">
<option value="">เลือกเวลา</option>
<option value="11:00">11:00</option>
<option value="11:30">11:30</option>
<option value="12:00">12:00</option>
<option value="12:30">12:30</option>
<option value="13:00">13:00</option>
<option value="13:30">13:30</option>
<option value="14:00">14:00</option>
<option value="18:00">18:00</option>
<option value="18:30">18:30</option>
<option value="19:00">19:00</option>
<option value="19:30">19:30</option>
<option value="20:00">20:00</option>
<option value="20:30">20:30</option>
<option value="21:00">21:00</option>
</select>
</div>
</div>
<div class="btn-group">
<button class="btn btn-secondary" onclick="closeModal()">ยกเลิก</button>
<button class="btn btn-primary" onclick="proceedToPayment()">ดำเนินการต่อ</button>
</div>
</div>
<div id="paymentSection" style="display: none;">
<div class="booking-summary">
<h4>สรุปการจอง</h4>
<div id="bookingSummary"></div>
</div>
<div class="payment-section">
<h4>ชำระเงินผ่าน QR Code</h4>
<div class="qr-code" id="qrCodeContainer">
<div class="qr-placeholder">
<span class="material-symbols-outlined">qr_code</span>
</div>
</div>
<div class="payment-info">
<p><strong>สแกน QR Code เพื่อชำระเงิน</strong></p>
<p>หรือโอนเงินไปที่ <strong>เลขบัญชี: 123-456-7890</strong></p>
<p style="color: #059669; font-weight: 500; margin-top: 10px;">
ยอดที่ต้องชำระ: ฿<span id="totalAmount"></span>
</p>
</div>
</div>
<div class="btn-group">
<button class="btn btn-secondary" onclick="backToForm()">กลับไปแก้ไข</button>
<button class="btn btn-success" onclick="confirmPayment()">
<span class="material-symbols-outlined">check</span>
ยืนยันการชำระเงิน
</button>
</div>
</div>
<div id="successSection" style="display: none;">
<div class="success-message">
<div class="success-icon">
<span class="material-symbols-outlined">check_circle</span>
</div>
<h3>จองสำเร็จ!</h3>
<p>ข้อมูลการจองของคุณได้ถูกบันทึกเรียบร้อยแล้ว</p>
<div class="booking-id">
หมายเลขการจอง: <span id="bookingId"></span>
</div>
<button class="btn btn-primary" onclick="closeModal()">ปิด</button>
</div>
</div>
</div>
</div>
</div>
<script>
let selectedTable = null;
let bookingData = {};
const tables = [
{id: 1, capacity: 2, status: 'available', price: 100, location: 'หน้าต่าง'},
{id: 2, capacity: 4, status: 'available', price: 200, location: 'กลางร้าน'},
{id: 3, capacity: 4, status: 'occupied', price: 200, location: 'มุมเงียบ'},
{id: 4, capacity: 6, status: 'available', price: 300, location: 'VIP Zone'},
{id: 5, capacity: 2, status: 'available', price: 150, location: 'ระเบียง'},
{id: 6, capacity: 8, status: 'available', price: 400, location: 'ห้องส่วนตัว'},
{id: 7, capacity: 2, status: 'occupied', price: 120, location: 'บาร์เคาน์เตอร์'},
{id: 8, capacity: 4, status: 'available', price: 250, location: 'สวนหลังบ้าน'},
{id: 9, capacity: 6, status: 'available', price: 350, location: 'ชั้นบน'},
{id: 10, capacity: 10, status: 'available', price: 500, location: 'ห้องจัดเลี้ยง'},
{id: 11, capacity: 4, status: 'available', price: 200, location: 'ริมน้ำ'},
{id: 12, capacity: 2, status: 'available', price: 100, location: 'โซนคู่รัก'}
];
function generateTableGrid() {
const grid = document.getElementById('tableGrid');
grid.innerHTML = '';
tables.forEach(table => {
const tableCard = document.createElement('div');
tableCard.className = `table-card ${table.status}`;
tableCard.innerHTML = `
<div class="table-header">
<div class="table-number">โต๊ะ ${table.id}</div>
<div class="table-status ${table.status}">
${table.status === 'available' ? 'ว่าง' : 'ไม่ว่าง'}
</div>
</div>
<div class="table-details">
<div class="table-detail">
<span class="material-symbols-outlined">group</span>
<span>${table.capacity} ที่นั่ง</span>
</div>
<div class="table-detail">
<span class="material-symbols-outlined">location_on</span>
<span>${table.location}</span>
</div>
</div>
<div class="table-price">฿${table.price}</div>
<button class="book-btn" ${table.status === 'occupied' ? 'disabled' : ''}
onclick="openBookingModal(${table.id})">
<span class="material-symbols-outlined">
${table.status === 'available' ? 'event_available' : 'event_busy'}
</span>
${table.status === 'available' ? 'จองเลย' : 'ไม่ว่าง'}
</button>
`;
grid.appendChild(tableCard);
});
}
function openBookingModal(tableId) {
selectedTable = tables.find(t => t.id === tableId);
document.getElementById('bookingModal').style.display = 'block';
// Reset form
document.getElementById('bookingForm').style.display = 'block';
document.getElementById('paymentSection').style.display = 'none';
document.getElementById('successSection').style.display = 'none';
// Clear form data
document.getElementById('customerName').value = '';
document.getElementById('customerPhone').value = '';
document.getElementById('guestCount').value = '';
document.getElementById('bookingDate').value = '';
document.getElementById('bookingTime').value = '';
}
function closeModal() {
document.getElementById('bookingModal').style.display = 'none';
selectedTable = null;
bookingData = {};
}
function proceedToPayment() {
// Validate form
const name = document.getElementById('customerName').value;
const phone = document.getElementById('customerPhone').value;
const guests = document.getElementById('guestCount').value;
const date = document.getElementById('bookingDate').value;
const time = document.getElementById('bookingTime').value;
if (!name || !phone || !guests || !date || !time) {
alert('กรุณากรอกข้อมูลให้ครบถ้วน');
return;
}
// Store booking data
bookingData = {
customerName: name,
customerPhone: phone,
guestCount: parseInt(guests),
bookingDate: date,
bookingTime: time,
table: selectedTable
};
// Generate summary
generateSummary();
// Show payment section
document.getElementById('bookingForm').style.display = 'none';
document.getElementById('paymentSection').style.display = 'block';
}
function backToForm() {
document.getElementById('bookingForm').style.display = 'block';
document.getElementById('paymentSection').style.display = 'none';
}
function generateSummary() {
const summary = document.getElementById('bookingSummary');
summary.innerHTML = `
<div class="summary-item">
<span>ชื่อ-นามสกุล:</span>
<span>${bookingData.customerName}</span>
</div>
<div class="summary-item">
<span>เบอร์โทรศัพท์:</span>
<span>${bookingData.customerPhone}</span>
</div>
<div class="summary-item">
<span>จำนวนแขก:</span>
<span>${bookingData.guestCount} คน</span>
</div>
<div class="summary-item">
<span>วันที่:</span>
<span>${formatDate(bookingData.bookingDate)}</span>
</div>
<div class="summary-item">
<span>เวลา:</span>
<span>${bookingData.bookingTime}</span>
</div>
<div class="summary-item">
<span>โต๊ะ:</span>
<span>โต๊ะ ${selectedTable.id} (${selectedTable.capacity} ที่นั่ง)</span>
</div>
<div class="summary-item">
<span>ตำแหน่งโต๊ะ:</span>
<span>${selectedTable.location}</span>
</div>
<div class="summary-item summary-total">
<span>ยอดรวม:</span>
<span>฿${selectedTable.price}</span>
</div>
`;
// Generate QR Code
generateQRCode();
// Update total amount display
document.getElementById('totalAmount').textContent = selectedTable.price;
}
function generateQRCode() {
const paymentData = {
restaurant: 'Table Booking System',
table: `โต๊ะ ${selectedTable.id}`,
customer: bookingData.customerName,
phone: bookingData.customerPhone,
date: bookingData.bookingDate,
time: bookingData.bookingTime,
guests: bookingData.guestCount,
amount: selectedTable.price,
bookingId: 'BK' + Date.now().toString().slice(-8)
};
const qrText = `ชำระเงินการจองโต๊ะ
ร้าน: ${paymentData.restaurant}
${paymentData.table} (${selectedTable.capacity} ที่นั่ง)
ลูกค้า: ${paymentData.customer}
วันที่: ${formatDate(paymentData.date)}
เวลา: ${paymentData.time}
จำนวนแขก: ${paymentData.guests} คน
ยอดเงิน: ฿${paymentData.amount}
รหัสการจอง: ${paymentData.bookingId}
โอนเงินไปที่: 123-456-7890`;
const qrContainer = document.getElementById('qrCodeContainer');
// Try multiple QR code generation methods
try {
// Show loading state
qrContainer.innerHTML = `
<div style="padding: 40px; text-align: center;">
<div style="width: 40px; height: 40px; border: 4px solid #e2e8f0; border-top: 4px solid #3b82f6; border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 15px;"></div>
<p style="color: #64748b;">กำลังสร้าง QR Code...</p>
</div>
`;
// Method 1: QRServer API (primary)
const isMobile = window.innerWidth <= 768;
const qrSize = isMobile ? 180 : 200;
const qrServerURL = `https://api.qrserver.com/v1/create-qr-code/?size=${qrSize}x${qrSize}&data=${encodeURIComponent(qrText)}&format=png&ecc=M`;
// Test if image loads successfully
const testImg = new Image();
testImg.onload = function() {
qrContainer.innerHTML = `
<img src="${qrServerURL}"
alt="QR Code สำหรับชำระเงิน"
style="border-radius: 12px; max-width: 100%; height: auto;"
loading="lazy">
`;
};
testImg.onerror = function() {
console.warn('QRServer API failed, trying alternatives...');
generateQRCodeFallback(paymentData.bookingId);
};
testImg.src = qrServerURL;
} catch (error) {
console.error('Error generating QR code:', error);
generateQRCodeFallback(paymentData.bookingId);
}
}
// Alternative QR Code generation using different services
function tryAlternativeQRServices(qrText, bookingId) {
const qrContainer = document.getElementById('qrCodeContainer');
const isMobile = window.innerWidth <= 768;
const qrSize = isMobile ? 180 : 200;
const alternatives = [
// QuickChart QR (reliable and free)
`https://quickchart.io/qr?text=${encodeURIComponent(qrText)}&size=${qrSize}x${qrSize}&format=png&margin=1`,
// QR Code Generator API
`https://api.qrcode-generator.com/api/create?apikey=free&qrdata=${encodeURIComponent(qrText)}&size=${qrSize}x${qrSize}`,
// Alternative QRServer mirror
`https://qr-server.com/api/v1/create-qr-code/?size=${qrSize}x${qrSize}&data=${encodeURIComponent(qrText)}`,
];
let currentIndex = 0;
function tryNextService() {
if (currentIndex >= alternatives.length) {
console.warn('All QR services failed, using manual fallback');
generateManualQRFallback(bookingId);
return;
}
console.log(`Trying QR service ${currentIndex + 1}/${alternatives.length}`);
const img = new Image();
img.onload = function() {
console.log(`QR service ${currentIndex + 1} succeeded`);
img.style.borderRadius = '12px';
img.style.maxWidth = '100%';
img.style.height = 'auto';
qrContainer.innerHTML = '';
qrContainer.appendChild(img);
};
img.onerror = function() {
console.warn(`QR service ${currentIndex + 1} failed`);
currentIndex++;
tryNextService();
};
img.src = alternatives[currentIndex];
}
tryNextService();
}
function generateQRCodeFallback(bookingId) {
// First try alternative QR services
if (window.qrText) {
tryAlternativeQRServices(window.qrText, bookingId);
return;
}
// If qrious library is available, use it
if (typeof QRious !== 'undefined') {
try {
const qrContainer = document.getElementById('qrCodeContainer');
const canvas = document.createElement('canvas');
const qr = new QRious({
element: canvas,
value: window.qrText || `การจองโต๊ะ - รหัส: ${bookingId}`,
size: window.innerWidth <= 768 ? 180 : 200,
foreground: '#1e293b',
background: '#ffffff',
level: 'M'
});
canvas.style.borderRadius = '12px';
canvas.style.maxWidth = '100%';
canvas.style.height = 'auto';
qrContainer.innerHTML = '';
qrContainer.appendChild(canvas);
return;
} catch (error) {
console.error('QRious library failed:', error);
}
}
// Final fallback - manual payment info
generateManualQRFallback(bookingId);
}
function generateManualQRFallback(bookingId) {
const qrContainer = document.getElementById('qrCodeContainer');
qrContainer.innerHTML = `
<div style="padding: 25px; text-align: center; color: #64748b; background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%); border-radius: 12px;">
<span class="material-symbols-outlined" style="font-size: 4rem; margin-bottom: 15px; display: block; color: #3b82f6;">payment</span>
<h4 style="color: #1e293b; margin-bottom: 15px;">ข้อมูลการโอนเงิน</h4>
<div style="background: white; padding: 20px; border-radius: 8px; margin: 15px 0; box-shadow: 0 2px 10px rgba(0,0,0,0.1);">
<p style="font-weight: bold; color: #059669; font-size: 1.1rem; margin-bottom: 10px;">เลขบัญชี: 123-456-7890</p>
<p style="font-weight: bold; color: #dc2626; font-size: 1.2rem; margin-bottom: 10px;">จำนวน: ฿${selectedTable.price}</p>
<p style="font-weight: bold; color: #7c3aed;">รหัสอ้างอิง: ${bookingId}</p>
</div>
<p style="font-size: 0.9rem; color: #6b7280;">กรุณาใส่รหัสอ้างอิงในหมายเหตุการโอน</p>
</div>
`;
}
function confirmPayment() {
// Use the booking ID that was generated with QR code
const bookingId = window.currentBookingId || 'BK' + Date.now().toString().slice(-8);
document.getElementById('bookingId').textContent = bookingId;
// Update table status
selectedTable.status = 'occupied';
// Show success section with animation
document.getElementById('paymentSection').style.display = 'none';
document.getElementById('successSection').style.display = 'block';
// Refresh table grid
generateTableGrid();
// Add celebration effect
setTimeout(() => {
createCelebrationEffect();
}, 300);
}
function createCelebrationEffect() {
// Simple celebration animation
const successIcon = document.querySelector('.success-icon');
if (successIcon) {
successIcon.style.animation = 'pulse 0.6s ease-in-out 3';
}
}
function formatDate(dateString) {
const date = new Date(dateString);
return date.toLocaleDateString('th-TH', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
}
function createParticles() {
const container = document.getElementById('particles');
const particleCount = 25;
for (let i = 0; i < particleCount; i++) {
const particle = document.createElement('div');
particle.className = 'particle';
particle.style.left = Math.random() * 100 + '%';
particle.style.top = Math.random() * 100 + '%';
const size = Math.random() * 8 + 3;
particle.style.width = size + 'px';
particle.style.height = size + 'px';
particle.style.animationDelay = Math.random() * 6 + 's';
particle.style.animationDuration = (Math.random() * 4 + 4) + 's';
// Add different opacity for more depth
particle.style.opacity = Math.random() * 0.3 + 0.1;
container.appendChild(particle);
}
}
// Initialize
document.addEventListener('DOMContentLoaded', function() {
// Set minimum date to tomorrow
const today = new Date();
const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1);
document.getElementById('bookingDate').min = tomorrow.toISOString().split('T')[0];
// Generate table grid
generateTableGrid();
// Create particles
createParticles();
// Close modal when clicking outside
window.onclick = function(event) {
const modal = document.getElementById('bookingModal');
if (event.target === modal) {
closeModal();
}
};
});
</script>
</body>
</html>