File manager - Edit - /var/www/order.cmtc.ac.th/admin/orders_summary_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'); $date_to = $_GET['date_to'] ?? date('Y-m-d'); // ✅ ดึงข้อมูลสรุปยอดรายวัน $sql = " SELECT DATE(o.created_at) AS order_date, SUM(CASE WHEN o.receive_method='รับสินค้าด้วยตนเอง' THEN o.total ELSE 0 END) AS self_total, SUM(CASE WHEN o.receive_method='จัดส่งทางไปรษณีย์' THEN o.total ELSE 0 END) AS post_total, SUM(o.total) AS total_all, SUM(CASE WHEN o.status LIKE '%Free Order%' THEN o.total ELSE 0 END) AS free_total FROM orders o WHERE DATE(o.created_at) BETWEEN ? AND ? GROUP BY DATE(o.created_at) ORDER BY DATE(o.created_at) DESC "; $stmt = $conn->prepare($sql); $stmt->bind_param('ss', $date_from, $date_to); $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:40px; } h2,h3 { text-align:center; margin:0; } table { width:100%; border-collapse:collapse; margin-top:20px; } th,td { border:1px solid #555; padding:6px 10px; font-size:14px; } th { background:#f0f0f0; } .text-right { text-align:right; } .text-center { text-align:center; } .logo { text-align:center; margin-bottom:10px; } .logo img { width:100px; } .watermark { position: fixed; bottom: 40%; left: 20%; font-size: 24px; color: rgba(200,200,200,0.3); transform: rotate(-30deg); pointer-events: none; } @media print {.no-print {display:none;}} </style> </head> <body> <div class="watermark">วิทยาลัยเทคนิคเชียงใหม่ การศึกษาเพื่ออาชีพและพัฒนาสังคม</div> <div class="logo"> <img src="../uploads/logo_cmtc.png" alt="โลโก้วิทยาลัยเทคนิคเชียงใหม่"> </div> <h2>รายงานสรุปยอดรายวัน (Order ปกติ + Free Order)</h2> <h3>ประจำวันที่ <?=htmlspecialchars($date_from)?> ถึง <?=htmlspecialchars($date_to)?></h3> <table> <thead> <tr> <th>วันที่</th> <th>รับสินค้าด้วยตนเอง (บาท)</th> <th>จัดส่งทางไปรษณีย์ (บาท)</th> <th>รวมยอดต่อวัน (บาท)</th> <th>ยอด Free Order (บาท)</th> </tr> </thead> <tbody> <?php $sum_self=0; $sum_post=0; $sum_all=0; $sum_free=0; if($res->num_rows > 0): while($r=$res->fetch_assoc()): $sum_self += $r['self_total']; $sum_post += $r['post_total']; $sum_all += $r['total_all']; $sum_free += $r['free_total']; ?> <tr> <td class="text-center"><?=htmlspecialchars($r['order_date'])?></td> <td class="text-right"><?=number_format($r['self_total'],2)?></td> <td class="text-right"><?=number_format($r['post_total'],2)?></td> <td class="text-right fw-bold"><?=number_format($r['total_all'],2)?></td> <td class="text-right text-warning fw-bold"><?=number_format($r['free_total'],2)?></td> </tr> <?php endwhile; else: ?> <tr><td colspan="5" class="text-center text-muted">ไม่พบข้อมูลในช่วงวันที่เลือก</td></tr> <?php endif; ?> </tbody> <tfoot> <tr> <th>รวมทั้งหมด</th> <th class="text-right"><?=number_format($sum_self,2)?></th> <th class="text-right"><?=number_format($sum_post,2)?></th> <th class="text-right"><?=number_format($sum_all,2)?></th> <th class="text-right text-warning"><?=number_format($sum_free,2)?></th> </tr> </tfoot> </table> <div class="text-center no-print" style="margin-top:20px;"> <button onclick="window.print()" style="padding:10px 20px; font-size:16px;">🖨 พิมพ์รายงาน</button> </div> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.42 |
proxy
|
phpinfo
|
Settings