File manager - Edit - /var/www/order.cmtc.ac.th/admin/orders_1.php
Back
<?php session_start(); if(!isset($_SESSION['admin'])) { header('Location: index.php'); exit; } include('../config/db.php'); $admin_password = "1234"; // ใช้ค่ายืนยันเริ่มต้น // ✅ ยืนยันคำสั่งซื้อ (ตัดสต็อก) // ✅ ยืนยันคำสั่งซื้อ (ตัดสต็อก + ออกเลขที่ใบจอง + แสดง Pop-up) if(isset($_GET['confirm'])) { $id = intval($_GET['confirm']); // ✅ สร้างเลขที่ใบจอง $prefix = "BK" . date("Ymd"); $latest = $conn->query("SELECT booking_no FROM orders WHERE booking_no LIKE '{$prefix}%' ORDER BY booking_no DESC LIMIT 1"); if($latest && $latest->num_rows > 0) { $last = $latest->fetch_assoc()['booking_no']; $num = intval(substr($last, -3)) + 1; } else { $num = 1; } $booking_no = $prefix . str_pad($num, 3, "0", STR_PAD_LEFT); // ✅ ตัดสต็อกสินค้า $items = $conn->query("SELECT product_id, qty FROM order_items WHERE order_id=$id"); while($it = $items->fetch_assoc()) { $conn->query("UPDATE products SET stock = stock - {$it['qty']} WHERE id = {$it['product_id']} AND stock >= {$it['qty']}"); } // ✅ อัปเดตสถานะและเลขที่ใบจอง $conn->query("UPDATE orders SET status='ชำระเงินแล้ว', booking_no='$booking_no' WHERE id=$id"); // ✅ แสดง Modal แจ้งผลสำเร็จ echo " <html> <head> <meta charset='UTF-8'> <link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'> <script src='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js'></script> </head> <body class='bg-light d-flex justify-content-center align-items-center' style='height:100vh;'> <div class='modal fade show d-block' tabindex='-1' style='background-color:rgba(0,0,0,0.5);'> <div class='modal-dialog'> <div class='modal-content text-center'> <div class='modal-header bg-success text-white'> <h5 class='modal-title'>✅ ยืนยันคำสั่งซื้อสำเร็จ</h5> </div> <div class='modal-body'> <p class='mb-0 fs-5'>ออกเลขที่ใบจอง:</p> <h3 class='text-primary mt-2 mb-3'>$booking_no</h3> <p>สถานะ: <b class='text-success'>ชำระเงินแล้ว</b></p> </div> <div class='modal-footer justify-content-center'> <button class='btn btn-success' onclick='window.location=\"orders.php\";'>ตกลง</button> </div> </div> </div> </div> </body> </html> "; exit; } // ✅ ยกเลิก (คืนสินค้า + รหัสผ่าน) if(isset($_POST['cancel_id'])) { $oid = intval($_POST['cancel_id']); $pw = trim($_POST['password']); if($pw === $admin_password) { $items = $conn->query("SELECT product_id, qty FROM order_items WHERE order_id=$oid"); while($it = $items->fetch_assoc()) { $conn->query("UPDATE products SET stock = stock + {$it['qty']} WHERE id = {$it['product_id']}"); } $conn->query("UPDATE orders SET status='ยกเลิกแล้ว' WHERE id=$oid"); $msg = "✅ ยกเลิกคำสั่งซื้อเรียบร้อย"; } else { $msg = "❌ รหัสผ่านไม่ถูกต้อง!"; } } // ✅ เปลี่ยนสถานะทั่วไป if(isset($_GET['id']) && isset($_GET['status'])) { $id = intval($_GET['id']); $st = $_GET['status']; $conn->query("UPDATE orders SET status='$st' WHERE id=$id"); header("Location: orders.php?updated=1"); exit; } // ✅ ดึงรายการคำสั่งซื้อทั้งหมด $res = $conn->query(" SELECT o.*, GROUP_CONCAT(CONCAT(p.name,' x',i.qty) SEPARATOR ', ') AS items FROM orders o JOIN order_items i ON o.id=i.order_id JOIN products p ON i.product_id=p.id GROUP BY o.id ORDER BY o.id DESC "); ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <title>จัดการคำสั่งจอง</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="../assets/css/style.css" rel="stylesheet"> <style> .password-box { display:none; margin-top:5px; } </style> </head> <body class="bg-light"> <?php include("menu.php"); ?> <div class="container py-4"> <h3 class="mb-3">📜 จัดการคำสั่งจอง</h3> <?php if(isset($msg)): ?><div class="alert alert-info"><?= $msg ?></div><?php endif; ?> <table class="table table-bordered bg-white shadow-sm align-middle"> <thead class="table-dark"> <tr> <th>เลขที่ใบจอง</th> <th>ชื่อผู้จอง</th> <th>รายการพระ</th> <th>ยอดรวม</th> <th>สถานะ</th> <th>สลิป</th> <th>จัดการ</th> <th>ใบเสร็จ</th> </tr> </thead> <?php while($r=$res->fetch_assoc()): ?> <tr> <td><?=$r['booking_no']?></td> <td><?=$r['fullname']?></td> <td><?=$r['items']?></td> <td><?=number_format($r['total'],2)?></td> <td><b><?=$r['status']?></b></td> <td> <?php if(!empty($r['slip'])): ?> <a href="#" class="view-slip text-decoration-none" data-img="../uploads/slip/<?=$r['slip']?>" data-id="<?=$r['id']?>" data-name="<?=htmlspecialchars($r['fullname'])?>" data-total="<?=number_format($r['total'],2)?>" data-status="<?=htmlspecialchars($r['status'])?>"> ดู </a> <?php else: ?> <span class="text-muted">-</span> <?php endif; ?> </td> <td> <?php if($r['status']=='รอตรวจสอบ' || $r['status']=='ยืนยันแล้ว'): ?> <a href="?confirm=<?=$r['id']?>" class="btn btn-success btn-sm">✔ ยืนยัน</a> <?php elseif($r['status']=='ชำระเงินแล้ว'): ?> <div class="dropdown d-inline mb-1"> <button class="btn btn-secondary btn-sm dropdown-toggle" data-bs-toggle="dropdown">เปลี่ยนสถานะ</button> <ul class="dropdown-menu"> <li><a class="dropdown-item" href="?id=<?=$r['id']?>&status=รับ order แล้ว">รับ order แล้ว</a></li> <li><a class="dropdown-item" href="?id=<?=$r['id']?>&status=มารับเหรียญได้ที่วิทยาลัยฯ">มารับเหรียญได้ที่วิทยาลัยฯ</a></li> <li><a class="dropdown-item" href="?id=<?=$r['id']?>&status=กำลังจัดส่ง">กำลังจัดส่ง</a></li> <li><a class="dropdown-item" href="?id=<?=$r['id']?>&status=รับเหรียญเรียบร้อยแล้ว">รับเหรียญเรียบร้อยแล้ว</a></li> <li><a class="dropdown-item" href="?id=<?=$r['id']?>&status=จัดส่งเรียบร้อยแล้ว">จัดส่งเรียบร้อยแล้ว</a></li> </ul> </div> <button class="btn btn-danger btn-sm" onclick="toggleCancel(<?=$r['id']?>)">❌ ยกเลิก</button> <div id="cancelBox<?=$r['id']?>" class="password-box"> <form method="post"> <input type="hidden" name="cancel_id" value="<?=$r['id']?>"> <input type="password" name="password" class="form-control form-control-sm mt-1" placeholder="รหัสผ่าน"> <button type="submit" class="btn btn-warning btn-sm mt-1">ยืนยัน</button> </form> </div> <?php elseif($r['status']=='ยกเลิกแล้ว'): ?> <span class="text-muted">คำสั่งนี้ถูกยกเลิก</span> <?php else: ?> <span class="text-secondary">-</span> <?php endif; ?> </td> <td><a href="print_invoice.php?id=<?=$r['id']?>" target="_blank" class="btn btn-outline-primary btn-sm">🖨 พิมพ์</a></td> </tr> <?php endwhile; ?> </table> </div> <script> function toggleCancel(id){ const box=document.getElementById('cancelBox'+id); box.style.display = (box.style.display=='block'?'none':'block'); } </script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <!-- ✅ Overlay แสดงสลิปและข้อมูล --> <div id="slipOverlay" class="slip-overlay"> <span class="close-btn">×</span> <div class="slip-content-box"> <img id="slipImage" class="slip-content" src="" alt="สลิปการโอนเงิน"> <div class="slip-info mt-3"> <p class="mb-1"><b>👤 ผู้จอง:</b> <span id="slipName"></span></p> <p class="mb-3"><b>💰 ยอดรวม:</b> <span id="slipTotal"></span> บาท</p> <div class="d-flex justify-content-center gap-3 mt-3"> <a id="downloadSlip" href="#" download class="btn btn-outline-light">⬇️ ดาวน์โหลดสลิป</a> <button id="confirmOrder" class="btn btn-success">✅ ยืนยันการชำระเงิน</button> </div> </div> </div> </div> <style> .slip-overlay { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.85); text-align: center; padding-top: 60px; } .slip-content-box { display: inline-block; background: rgba(255,255,255,0.1); padding: 20px 30px; border-radius: 10px; max-width: 95%; } .slip-content { max-width: 400px; max-height: 65vh; border-radius: 8px; box-shadow: 0 0 15px rgba(255,255,255,0.3); } .slip-info { color: #fff; font-size: 1rem; margin-top: 15px; } .close-btn { position: fixed; top: 20px; right: 40px; color: white; font-size: 40px; font-weight: bold; cursor: pointer; transition: 0.3s; } .close-btn:hover { color: #ff5555; } </style> <script> // ✅ เปิด Overlay document.querySelectorAll('.view-slip').forEach(link => { link.addEventListener('click', function(e) { e.preventDefault(); const imgSrc = this.getAttribute('data-img'); const name = this.getAttribute('data-name'); const total = this.getAttribute('data-total'); const id = this.getAttribute('data-id'); const status = this.getAttribute('data-status'); document.getElementById('slipImage').src = imgSrc; document.getElementById('slipName').innerText = name; document.getElementById('slipTotal').innerText = total; document.getElementById('downloadSlip').href = imgSrc; document.getElementById('confirmOrder').setAttribute('data-id', id); // ถ้าสถานะถูกยืนยันแล้ว → ปิดปุ่ม const confirmBtn = document.getElementById('confirmOrder'); if (status.includes('ชำระเงินแล้ว') || status.includes('ยืนยันแล้ว') || status.includes('รับ')) { confirmBtn.disabled = true; confirmBtn.classList.remove('btn-success'); confirmBtn.classList.add('btn-secondary'); confirmBtn.innerText = '✔️ ยืนยันแล้ว'; } else { confirmBtn.disabled = false; confirmBtn.classList.remove('btn-secondary'); confirmBtn.classList.add('btn-success'); confirmBtn.innerText = '✅ ยืนยันการชำระเงิน'; } document.getElementById('slipOverlay').style.display = 'block'; }); }); // ✅ ปิด Overlay document.querySelector('.close-btn').addEventListener('click', () => { document.getElementById('slipOverlay').style.display = 'none'; }); document.getElementById('slipOverlay').addEventListener('click', (e) => { if (e.target === e.currentTarget) e.currentTarget.style.display = 'none'; }); // ✅ ปุ่มยืนยันการชำระเงิน document.getElementById('confirmOrder').addEventListener('click', function() { const id = this.getAttribute('data-id'); if (!id || this.disabled) return; if (confirm('ยืนยันการชำระเงินใบจองนี้หรือไม่?')) { this.disabled = true; this.innerText = '⏳ กำลังยืนยัน...'; window.location.href = 'orders.php?confirm=' + id; } }); </script> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.41 |
proxy
|
phpinfo
|
Settings