File manager - Edit - /var/www/order.cmtc.ac.th/admin/orders_free.php
Back
<?php session_start(); if(!isset($_SESSION['admin'])) { header('Location: index.php'); exit; } include('../config/db.php'); date_default_timezone_set('Asia/Bangkok'); // ========================== // ฟังก์ชันยืนยันและยกเลิก // ========================== if(isset($_GET['confirm'])){ $id = intval($_GET['confirm']); $chk = $conn->query("SELECT booking_no FROM orders WHERE id=$id")->fetch_assoc(); if(empty($chk['booking_no'])){ $booking_no = 'FREE' . date('YmdHis'); $conn->query("UPDATE orders SET booking_no='$booking_no', status='ยืนยันการชำระเงิน' WHERE id=$id"); echo "<script>alert('ยืนยันการชำระเงินแล้ว และออกเลขที่ใบจอง: $booking_no'); window.open('print_invoice.php?id=$id','_blank'); window.location='orders_free.php';</script>"; exit; } } if(isset($_GET['cancel'])){ $id = intval($_GET['cancel']); $conn->query("UPDATE orders SET status='ยกเลิกรายการ' WHERE id=$id"); } // ========================== // ฟังก์ชันเปลี่ยนสถานะ // ========================== if(isset($_GET['status']) && isset($_GET['id'])){ $sid = intval($_GET['id']); $status = mysqli_real_escape_string($conn, $_GET['status']); $conn->query("UPDATE orders SET status='$status' WHERE id=$sid"); } // ========================== // ตัวกรองข้อมูล // ========================== $today = date('Y-m-d'); $default_from = date('Y-m-d', strtotime('-6 days', strtotime($today))); $date_from = $_GET['date_from'] ?? $default_from; $date_to = $_GET['date_to'] ?? $today; $filter_receive = $_GET['receive'] ?? 'all'; $search = trim($_GET['search'] ?? ''); // เงื่อนไขเฉพาะ Free Order $where = "WHERE o.order_type='Free Order' AND DATE(o.created_at) BETWEEN ? AND ?"; $params = [$date_from, $date_to]; $types = 'ss'; if($filter_receive != 'all'){ $where .= " AND o.receive_method=?"; $params[] = ($filter_receive=='self' ? 'รับสินค้าด้วยตนเอง' : 'จัดส่งทางไปรษณีย์'); $types .= 's'; } if($search != ''){ $where .= " AND (o.booking_no LIKE ? OR o.fullname LIKE ? OR o.phone LIKE ?)"; $s = "%".$search."%"; $params[] = $s; $params[] = $s; $params[] = $s; $types .= 'sss'; } // ดึงข้อมูล $sql = " 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 $where GROUP BY o.id ORDER BY o.id DESC "; $stmt = $conn->prepare($sql); $stmt->bind_param($types, ...$params); $stmt->execute(); $res = $stmt->get_result(); ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <title>🟡 รายการจอง Free Order</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;500;600&display=swap" rel="stylesheet"> <style> body,*{font-family:'Kanit',sans-serif!important;} .table th,.table td{vertical-align:middle!important;} .dropdown-menu { position: absolute !important; z-index: 2000 !important; } .d-flex.gap-1 > * { flex-shrink: 0; } </style> </head> <body class="bg-light"> <?php include("menu.php"); ?> <div class="container py-4"> <div class="d-flex justify-content-between align-items-center mb-3"> <h3>🟡 รายการจอง Free Order</h3> <a href="orders.php" class="btn btn-outline-primary btn-sm">📦 กลับไปหน้า ปกติ</a> </div> <!-- ฟอร์มกรอง --> <div class="card mb-3 shadow-sm"> <div class="card-body"> <form class="row g-2 align-items-end"> <div class="col-md-2"> <label class="form-label">จากวันที่</label> <input type="date" name="date_from" value="<?=htmlspecialchars($date_from)?>" class="form-control"> </div> <div class="col-md-2"> <label class="form-label">ถึงวันที่</label> <input type="date" name="date_to" value="<?=htmlspecialchars($date_to)?>" class="form-control"> </div> <div class="col-md-2"> <label class="form-label">วิธีรับสินค้า</label> <select name="receive" class="form-select"> <option value="all" <?=($filter_receive=='all'?'selected':'')?>>ทั้งหมด</option> <option value="self" <?=($filter_receive=='self'?'selected':'')?>>รับสินค้าด้วยตนเอง</option> <option value="post" <?=($filter_receive=='post'?'selected':'')?>>จัดส่งทางไปรษณีย์</option> </select> </div> <div class="col-md-3"> <label class="form-label">ค้นหา (ชื่อ, เบอร์โทร, เลขที่ใบจอง)</label> <input type="text" name="search" value="<?=htmlspecialchars($search)?>" class="form-control"> </div> <div class="col-md-3 text-end"> <button class="btn btn-primary">🔍 แสดง</button> </div> </form> </div> </div> <!-- ปุ่มรายงาน --> <div class="d-flex justify-content-end gap-2 mb-3"> <a href="orders_free_print.php?date_from=<?=$date_from?>&date_to=<?=$date_to?>&receive=<?=$filter_receive?>&search=<?=urlencode($search)?>" target="_blank" class="btn btn-success">🖨 พิมพ์รายงาน</a> <a href="orders_free_export.php?date_from=<?=$date_from?>&date_to=<?=$date_to?>&receive=<?=$filter_receive?>&search=<?=urlencode($search)?>" class="btn btn-outline-success">📊 Export Excel</a> </div> <!-- ตาราง --> <div class="card shadow-sm"> <div class="card-header bg-warning fw-bold text-dark">รายการ Free Order (<?=htmlspecialchars($date_from)?> ถึง <?=htmlspecialchars($date_to)?>)</div> <div class="card-body p-0"> <div class="table-responsive"> <table class="table table-bordered text-center mb-0"> <thead class="table-light"> <tr> <th>เลขที่ใบจอง</th> <th>ชื่อผู้จอง</th> <th>เบอร์โทร</th> <th>รายการเหรียญ</th> <th>ยอดรวม</th> <th>สถานะ</th> <th>วิธีรับสินค้า</th> <th>วันที่จอง</th> <th>สลิป</th> <th>จัดการ</th> </tr> </thead> <tbody> <?php if($res->num_rows > 0): while($row=$res->fetch_assoc()): ?> <tr> <td><?= $row['booking_no'] ?: '-' ?></td> <td><?= htmlspecialchars($row['fullname']) ?></td> <td><?= htmlspecialchars($row['phone']) ?></td> <td><?= htmlspecialchars($row['items']) ?></td> <td><?= number_format($row['total'],2) ?></td> <td><span class="fw-bold text-warning"><?= htmlspecialchars($row['status']) ?></span></td> <td><?= htmlspecialchars($row['receive_method']) ?></td> <td><?= htmlspecialchars($row['created_at']) ?></td> <td> <?php if(!empty($row['slip'])): ?> <a href="../uploads/slip/<?=htmlspecialchars($row['slip'])?>" onclick="window.open(this.href, 'slipView', 'width=600,height=800'); return false;" class="btn btn-outline-info btn-sm">ดู</a> <?php else: ?><span class="text-muted">-</span><?php endif; ?> </td> <td> <?php if(empty($row['booking_no'])): ?> <div class="d-flex justify-content-center align-items-center gap-1"> <a href="?confirm=<?=$row['id']?>" class="btn btn-success btn-sm">✅ ยืนยัน</a> <a href="?cancel=<?=$row['id']?>" class="btn btn-outline-danger btn-sm" onclick="return confirm('ต้องการยกเลิกรายการนี้หรือไม่?')">❌ ยกเลิก</a> </div> <?php else: ?> <div class="d-flex justify-content-center align-items-center gap-1"> <div class="dropdown d-inline-block position-static"> <button class="btn btn-warning btn-sm dropdown-toggle" data-bs-toggle="dropdown">🔄 เปลี่ยนสถานะ</button> <ul class="dropdown-menu dropdown-menu-end shadow"> <?php if($row['receive_method']=='รับสินค้าด้วยตนเอง'): ?> <li><a class="dropdown-item" href="?id=<?=$row['id']?>&status=แพ็คเหรียญ">แพ็คเหรียญ</a></li> <li><a class="dropdown-item" href="?id=<?=$row['id']?>&status=รับเหรียญได้ที่วิทยาลัยฯ">รับเหรียญได้ที่วิทยาลัยฯ</a></li> <li><a class="dropdown-item" href="?id=<?=$row['id']?>&status=รับเหรียญเรียบร้อยแล้ว">รับเหรียญเรียบร้อยแล้ว</a></li> <?php else: ?> <li><a class="dropdown-item" href="?id=<?=$row['id']?>&status=แพ็คเหรียญ">แพ็คเหรียญ</a></li> <li><a class="dropdown-item" href="?id=<?=$row['id']?>&status=จัดส่งเรียบร้อยแล้ว">จัดส่ง</a></li> <?php endif; ?> </ul> </div> <a href="print_invoice.php?id=<?=$row['id']?>" target="_blank" class="btn btn-outline-primary btn-sm">🖨 พิมพ์ใบเสร็จ</a> </div> <?php endif; ?> </td> </tr> <?php endwhile; else: ?> <tr><td colspan="10" class="text-center text-muted py-4">ไม่พบข้อมูล Free Order</td></tr> <?php endif; ?> </tbody> </table> </div> </div> </div> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.41 |
proxy
|
phpinfo
|
Settings