File manager - Edit - /var/www/order.cmtc.ac.th/admin/orders_print.php
Back
<?php session_start(); if(!isset($_SESSION['admin'])) { header('Location: index.php'); exit; } include('../config/db.php'); date_default_timezone_set('Asia/Bangkok'); $date_from = $_GET['date_from'] ?? date('Y-m-d', strtotime('-6 days')); $date_to = $_GET['date_to'] ?? date('Y-m-d'); $filter_receive = $_GET['receive'] ?? 'all'; $search = trim($_GET['search'] ?? ''); // ✅ เงื่อนไขพื้นฐานเฉพาะ order_type = ปกติ $where = "WHERE o.order_type='ปกติ' 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>รายงานการจอง (ปกติ)</title> <link href="https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;600&display=swap" rel="stylesheet"> <style> body { font-family: 'Kanit', sans-serif; margin: 20px; } h2,h4 { text-align:center; margin:0; } table { width:100%; border-collapse:collapse; margin-top:20px; font-size:14px; } th,td { border:1px solid #999; padding:6px 8px; vertical-align:top; } th { background:#eee; } .text-center { text-align:center; } small { color:#666; } @media print { .noprint { display:none; } body { margin:0; } } </style> </head> <body> <h2>📋 รายงานการจอง (เฉพาะคำสั่งซื้อปกติ)</h2> <h4>วันที่ <?=htmlspecialchars($date_from)?> ถึง <?=htmlspecialchars($date_to)?></h4> <?php if($filter_receive=='self'): ?> <p class="text-center"><b>วิธีรับสินค้า:</b> รับสินค้าด้วยตนเอง</p> <?php elseif($filter_receive=='post'): ?> <p class="text-center"><b>วิธีรับสินค้า:</b> จัดส่งทางไปรษณีย์</p> <?php endif; ?> <?php if($search!=''): ?> <p class="text-center"><b>คำค้น:</b> "<?=htmlspecialchars($search)?>"</p> <?php endif; ?> <table> <thead> <tr> <th>ลำดับ</th> <th>เลขที่ใบจอง</th> <th>ชื่อผู้จอง</th> <th>เบอร์โทร</th> <th>รายการเหรียญ</th> <th>ยอดรวม</th> <th>สถานะ</th> <th>วิธีรับสินค้า</th> <th>วันที่จอง</th> </tr> </thead> <tbody> <?php $n=1; $sum_total=0; if($res->num_rows>0): while($row=$res->fetch_assoc()): $sum_total += $row['total']; ?> <tr> <td class="text-center"><?=$n++?></td> <td><?=$row['booking_no']?></td> <td><?=htmlspecialchars($row['fullname'])?></td> <td><?=htmlspecialchars($row['phone'])?></td> <td><?=htmlspecialchars($row['items'])?></td> <td class="text-center"><?=number_format($row['total'],2)?></td> <td class="text-center"><?=htmlspecialchars($row['status'])?></td> <td class="text-center"><?=htmlspecialchars($row['receive_method'])?></td> <td class="text-center"><?=htmlspecialchars($row['created_at'])?></td> </tr> <?php endwhile; else: ?> <tr><td colspan="9" class="text-center text-muted">ไม่พบข้อมูลการจอง</td></tr> <?php endif; ?> </tbody> <?php if($sum_total>0): ?> <tfoot> <tr> <th colspan="5" class="text-end">รวมยอดทั้งหมด</th> <th class="text-center"><?=number_format($sum_total,2)?></th> <th colspan="3"></th> </tr> </tfoot> <?php endif; ?> </table> <div class="noprint" style="text-align:center; margin-top:20px;"> <button onclick="window.print()">🖨 พิมพ์รายงาน</button> <button onclick="window.close()">❌ ปิดหน้าต่าง</button> </div> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.69 |
proxy
|
phpinfo
|
Settings