File manager - Edit - /var/www/order.cmtc.ac.th/admin/report_paid_daily.php
Back
<?php // admin/report_paid_daily.php session_start(); if(!isset($_SESSION['admin'])) { header('Location: index.php'); exit; } include('../config/db.php'); // ตั้งค่าช่วงวันที่เริ่มต้น (ย้อนหลัง 7 วัน ถึง วันนี้) date_default_timezone_set('Asia/Bangkok'); $today = date('Y-m-d'); $default_from = date('Y-m-d', strtotime('-6 days', strtotime($today))); $date_from = isset($_GET['date_from']) && $_GET['date_from'] !== '' ? $_GET['date_from'] : $default_from; $date_to = isset($_GET['date_to']) && $_GET['date_to'] !== '' ? $_GET['date_to'] : $today; // ตรวจสอบรูปแบบวันที่ให้เป็น YYYY-mm-dd (กันพลาด) $valid = function($d){ return preg_match('/^\d{4}-\d{2}-\d{2}$/',$d); }; if(!$valid($date_from)) $date_from = $default_from; if(!$valid($date_to)) $date_to = $today; // ======================== // คิวรีสรุปรายวัน // ======================== $sql_summary = " SELECT DATE(o.created_at) AS order_date, COUNT(*) AS cnt_orders, SUM(o.total) AS sum_total FROM orders o WHERE DATE(o.created_at) BETWEEN ? AND ? AND (o.booking_no IS NOT NULL AND o.booking_no <> '' OR o.status LIKE 'ชำระเงินแล้ว%') GROUP BY DATE(o.created_at) ORDER BY DATE(o.created_at) DESC "; $stmt = $conn->prepare($sql_summary); $stmt->bind_param('ss', $date_from, $date_to); $stmt->execute(); $summary = $stmt->get_result(); // ======================== // คิวรีรายละเอียดรายวัน // ======================== $detail_date = isset($_GET['detail_date']) && $valid($_GET['detail_date']) ? $_GET['detail_date'] : ''; $detail_rows = null; if($detail_date){ $sql_detail = " SELECT o.id, o.booking_no, o.fullname, o.phone, o.receive_method, o.total, o.status, o.created_at, o.order_type FROM orders o WHERE DATE(o.created_at) = ? AND (o.booking_no IS NOT NULL AND o.booking_no <> '' OR o.status LIKE 'ชำระเงินแล้ว%') ORDER BY o.id DESC "; $stmt2 = $conn->prepare($sql_detail); $stmt2->bind_param('s', $detail_date); $stmt2->execute(); $detail_rows = $stmt2->get_result(); } ?> <!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="https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;500;600&display=swap" rel="stylesheet"> <style> body,*{font-family:'Kanit',sans-serif!important;} .card{border-radius:1rem;} .table thead th{white-space:nowrap;} .badge-free{background:#ffc107;color:#000;} .badge-normal{background:#28a745;} </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>📊 สรุปยอดการจองที่ชำระเงินแล้ว (รายวัน)</h3> </div> <!-- ฟอร์มเลือกช่วงวันที่ --> <div class="card shadow-sm mb-3"> <div class="card-body"> <form class="row g-2 align-items-end"> <div class="col-md-3"> <label class="form-label">จากวันที่</label> <input type="date" name="date_from" class="form-control" value="<?=htmlspecialchars($date_from)?>"> </div> <div class="col-md-3"> <label class="form-label">ถึงวันที่</label> <input type="date" name="date_to" class="form-control" value="<?=htmlspecialchars($date_to)?>"> </div> <div class="col-md-3"> <button class="btn btn-primary w-100">แสดงสรุป</button> </div> <div class="col-md-3"> <a class="btn btn-outline-secondary w-100" href="report_paid_daily.php">รีเซ็ตช่วงวันที่</a> </div> </form> </div> </div> <!-- ตารางสรุปรายวัน --> <div class="card shadow-sm mb-4"> <div class="card-header bg-dark text-white fw-bold"> สรุปรายวัน (ช่วง: <?=htmlspecialchars($date_from)?> ถึง <?=htmlspecialchars($date_to)?>) </div> <div class="card-body p-0"> <div class="table-responsive"> <table class="table table-bordered table-hover m-0 align-middle"> <thead class="table-light"> <tr> <th>วันที่</th> <th class="text-end">จำนวนใบจอง (ที่ชำระแล้ว)</th> <th class="text-end">ยอดรวม (บาท)</th> <th class="text-center">รายละเอียด</th> </tr> </thead> <tbody> <?php $grand_cnt = 0; $grand_sum = 0.0; if($summary->num_rows>0): while($r = $summary->fetch_assoc()): $grand_cnt += (int)$r['cnt_orders']; $grand_sum += (float)$r['sum_total']; ?> <tr> <td><?=htmlspecialchars($r['order_date'])?></td> <td class="text-end"><?=number_format((int)$r['cnt_orders'])?></td> <td class="text-end"><?=number_format((float)$r['sum_total'],2)?></td> <td class="text-center"> <a class="btn btn-sm btn-outline-primary" href="?date_from=<?=$date_from?>&date_to=<?=$date_to?>&detail_date=<?=$r['order_date']?>">ดูรายละเอียด</a> </td> </tr> <?php endwhile; else: ?> <tr><td colspan="4" class="text-center text-muted py-4">ไม่พบข้อมูลในช่วงวันที่ที่เลือก</td></tr> <?php endif; ?> </tbody> <tfoot class="table-secondary"> <tr class="fw-bold"> <td class="text-end">รวมช่วงนี้</td> <td class="text-end"><?=number_format($grand_cnt)?></td> <td class="text-end"><?=number_format($grand_sum,2)?></td> <td></td> </tr> </tfoot> </table> </div> </div> </div> <!-- รายละเอียดรายวัน --> <?php if($detail_date): ?> <div class="card shadow-sm"> <div class="card-header bg-primary text-white fw-bold"> รายละเอียดคำสั่งซื้อวันที่ <?=htmlspecialchars($detail_date)?> (ที่ชำระแล้ว) </div> <div class="card-body p-0"> <div class="table-responsive"> <table class="table table-bordered m-0 align-middle"> <thead class="table-light"> <tr> <th>เลขที่ใบจอง</th> <th>ชื่อผู้จอง</th> <th>เบอร์โทร</th> <th>ประเภทคำสั่งซื้อ</th> <th>วิธีรับสินค้า</th> <th class="text-end">ยอดรวม (บาท)</th> <th>สถานะ</th> <th>เวลาที่สร้าง</th> <th class="text-center">พิมพ์ใบเสร็จ</th> </tr> </thead> <tbody> <?php $sum_detail = 0.0; if($detail_rows && $detail_rows->num_rows>0): while($d = $detail_rows->fetch_assoc()): $sum_detail += (float)$d['total']; ?> <tr> <td><?=htmlspecialchars($d['booking_no'] ?: '-')?></td> <td><?=htmlspecialchars($d['fullname'])?></td> <td><?=htmlspecialchars($d['phone'])?></td> <td> <?php if($d['order_type']=='Pre Order'): ?> <span class="badge badge-free">Pre Order</span> <?php else: ?> <span class="badge badge-normal">ปกติ</span> <?php endif; ?> </td> <td><?=htmlspecialchars($d['receive_method'])?></td> <td class="text-end"><?=number_format((float)$d['total'],2)?></td> <td><span class="fw-bold text-success"><?=htmlspecialchars($d['status'])?></span></td> <td><?=htmlspecialchars($d['created_at'])?></td> <td class="text-center"> <?php if(!empty($d['booking_no'])): ?> <a href="print_invoice.php?id=<?=$d['id']?>" target="_blank" class="btn btn-sm btn-outline-primary">🖨 พิมพ์</a> <?php else: ?> <span class="text-muted">-</span> <?php endif; ?> </td> </tr> <?php endwhile; else: ?> <tr><td colspan="9" class="text-center text-muted py-4">ไม่พบรายการในวันดังกล่าว</td></tr> <?php endif; ?> </tbody> <tfoot class="table-secondary"> <tr class="fw-bold"> <td colspan="5" class="text-end">รวมทั้งวัน</td> <td class="text-end"><?=number_format($sum_detail,2)?></td> <td colspan="3"></td> </tr> </tfoot> </table> </div> </div> </div> <?php endif; ?> </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.7 |
proxy
|
phpinfo
|
Settings