File manager - Edit - /var/www/order.cmtc.ac.th/admin/booking_logs.php
Back
<?php session_start(); include('../config/db.php'); if(!isset($_SESSION['admin'])) { header("Location: index.php"); exit; } // ✅ รับค่าการค้นหา $search_name = $_GET['search_name'] ?? ''; $search_phone = $_GET['search_phone'] ?? ''; $search_type = $_GET['search_type'] ?? ''; $date_start = $_GET['date_start'] ?? ''; $date_end = $_GET['date_end'] ?? ''; $where = []; if($search_name != '') $where[] = "l.customer_name LIKE '%" . mysqli_real_escape_string($conn, $search_name) . "%'"; if($search_phone != '') $where[] = "l.phone LIKE '%" . mysqli_real_escape_string($conn, $search_phone) . "%'"; if($search_type != '') $where[] = "o.order_type = '" . mysqli_real_escape_string($conn, $search_type) . "'"; if($date_start != '' && $date_end != '') $where[] = "DATE(l.created_at) BETWEEN '$date_start' AND '$date_end'"; elseif($date_start != '') $where[] = "DATE(l.created_at) >= '$date_start'"; elseif($date_end != '') $where[] = "DATE(l.created_at) <= '$date_end'"; $whereSQL = !empty($where) ? "WHERE " . implode(" AND ", $where) : ""; // ✅ ดึงข้อมูล log $logs = $conn->query(" SELECT l.*, p.name AS product_name, o.order_type, o.order_status FROM booking_logs l LEFT JOIN products p ON l.product_id = p.id LEFT JOIN orders o ON l.order_id = o.id $whereSQL ORDER BY l.id DESC "); // ✅ ดึงข้อมูลสรุปรายวัน $summary = $conn->query(" SELECT DATE(l.created_at) AS log_date, COUNT(*) AS total_orders, SUM(l.total) AS total_amount, SUM(CASE WHEN o.order_type='ปกติ' THEN 1 ELSE 0 END) AS normal_orders, SUM(CASE WHEN o.order_type='Pre Order' THEN 1 ELSE 0 END) AS preorder_orders FROM booking_logs l LEFT JOIN orders o ON l.order_id = o.id $whereSQL GROUP BY DATE(l.created_at) ORDER BY log_date ASC "); // ✅ เตรียมข้อมูลสำหรับ Chart.js $chart_labels = []; $chart_values = []; if($summary && $summary->num_rows > 0){ mysqli_data_seek($summary, 0); while($row = $summary->fetch_assoc()){ $chart_labels[] = date("d/m", strtotime($row['log_date'])); $chart_values[] = (float)$row['total_amount']; } mysqli_data_seek($summary, 0); } // ✅ สีของกราฟ (เขียว-เหลือง-แดง) $colors = array_map(function($v){ if ($v > 1000) return '#dc3545'; // แดง elseif ($v > 500) return '#ffc107'; // เหลือง else return '#28a745'; // เขียว }, $chart_values); ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <title>บันทึกการจองเหรียญ</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <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"> <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script> <style> body {font-family:'Kanit',sans-serif;background-color:#f8f9fa;} .card {border-radius:16px;box-shadow:0 3px 10px rgba(0,0,0,0.1);} .table th {background-color:#44000E;color:#fff;} footer {background:#44000E;color:#fff;text-align:center;padding:15px;margin-top:50px;} </style> </head> <body> <?php include("menu.php"); ?> <div class="container py-5"> <div class="d-flex justify-content-between align-items-center mb-4"> <h3 class="fw-bold text-primary">📋 บันทึกการจองเหรียญทั้งหมด</h3> <a href="statistics.php" class="btn btn-secondary">↩ กลับหน้าสถิติ</a> </div> <!-- ✅ ฟอร์มค้นหา --> <form method="get" class="card p-3 mb-4"> <div class="row g-2 align-items-end"> <div class="col-md-3"> <label class="form-label">ชื่อผู้จอง</label> <input type="text" name="search_name" class="form-control" value="<?=$search_name?>"> </div> <div class="col-md-2"> <label class="form-label">เบอร์โทร</label> <input type="text" name="search_phone" class="form-control" value="<?=$search_phone?>"> </div> <div class="col-md-2"> <label class="form-label">ประเภท</label> <select name="search_type" class="form-select"> <option value="">ทั้งหมด</option> <option value="ปกติ" <?=$search_type=='ปกติ'?'selected':''?>>ปกติ</option> <option value="Pre Order" <?=$search_type=='Pre Order'?'selected':''?>>Pre Order</option> </select> </div> <div class="col-md-2"> <label class="form-label">วันที่เริ่มต้น</label> <input type="date" name="date_start" class="form-control" value="<?=$date_start?>"> </div> <div class="col-md-2"> <label class="form-label">ถึงวันที่</label> <input type="date" name="date_end" class="form-control" value="<?=$date_end?>"> </div> <div class="col-md-1 d-grid"> <button type="submit" class="btn btn-primary">ค้นหา</button> </div> </div> <div class="mt-3 text-end"> <a href="export_booking_logs.php?<?=http_build_query($_GET)?>" class="btn btn-success">📤 ส่งออก Excel</a> </div> </form> <!-- ✅ กราฟยอดจองรายวัน --> <div class="card p-4 mb-4"> <h5 class="fw-bold text-center mb-3 text-dark">📊 กราฟยอดจองรายวัน (บาท)</h5> <canvas id="dailyChart" height="120"></canvas> </div> <!-- ✅ ตารางสรุปรายวัน --> <div class="card p-4 mb-4"> <h5 class="fw-bold text-center mb-3 text-dark">📆 สรุปรายวัน</h5> <div class="table-responsive"> <table class="table table-bordered text-center align-middle"> <thead class="table-light"> <tr> <th>วันที่</th> <th>จำนวนการจอง</th> <th>ยอดรวมทั้งหมด (บาท)</th> <th>ประเภทปกติ</th> <th>ประเภท Pre Order</th> </tr> </thead> <tbody> <?php if($summary && $summary->num_rows > 0): ?> <?php while($row = $summary->fetch_assoc()): ?> <tr> <td><?=date("d/m/Y", strtotime($row['log_date']))?></td> <td><?=$row['total_orders']?></td> <td><?=number_format($row['total_amount'],2)?></td> <td><span class="badge bg-success"><?=$row['normal_orders']?></span></td> <td><span class="badge bg-warning text-dark"><?=$row['preorder_orders']?></span></td> </tr> <?php endwhile; ?> <?php else: ?> <tr><td colspan="5" class="text-muted py-3">ไม่มีข้อมูลในช่วงวันที่ที่เลือก</td></tr> <?php endif; ?> </tbody> </table> </div> </div> <!-- ✅ ตาราง Log รายการจอง --> <div class="card p-4"> <h5 class="fw-bold text-center mb-3 text-dark">📋 รายการจองทั้งหมด</h5> <div class="table-responsive"> <table class="table table-bordered align-middle text-center"> <thead> <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($logs && $logs->num_rows > 0): $i=1; ?> <?php while($row = $logs->fetch_assoc()): ?> <tr> <td><?=$i++?></td> <td><?=$row['customer_name']?></td> <td><?=$row['phone']?></td> <td><?=$row['product_name']?></td> <td><?=$row['qty']?></td> <td><?=number_format($row['total'],2)?></td> <td><?=$row['receive_method']?></td> <td><?=$row['order_type']?></td> <td><?=$row['order_status']?></td> <td><?=date("d/m/Y H:i", strtotime($row['created_at']))?></td> </tr> <?php endwhile; ?> <?php else: ?> <tr><td colspan="10" class="text-muted py-4">ไม่มีรายการที่ตรงเงื่อนไข</td></tr> <?php endif; ?> </tbody> </table> </div> </div> </div> <footer> <small>© 2025 Developed by KruBig | Chiang Mai Technical College</small> </footer> <!-- ✅ สคริปต์แสดงกราฟ --> <script> const ctx = document.getElementById('dailyChart'); const chartData = { labels: <?=json_encode($chart_labels, JSON_UNESCAPED_UNICODE)?>, datasets: [{ label: 'ยอดรวมต่อวัน (บาท)', data: <?=json_encode($chart_values, JSON_UNESCAPED_UNICODE)?>, backgroundColor: <?=json_encode($colors, JSON_UNESCAPED_UNICODE)?>, borderWidth: 1, borderColor: '#fff' }] }; new Chart(ctx, { type: 'bar', data: chartData, options: { scales: { y: {beginAtZero: true, title:{display:true,text:'บาท'}}, x: {title:{display:true,text:'วันที่'}} }, plugins: {legend: {display: false}} } }); </script> <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.42 |
proxy
|
phpinfo
|
Settings