File manager - Edit - /var/www/order.cmtc.ac.th/admin/orders_product_summary.php
Back
<?php session_start(); if(!isset($_SESSION['admin'])) { header('Location: index.php'); exit; } include('../config/db.php'); date_default_timezone_set('Asia/Bangkok'); $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; // =============================== // ðđ āļāļķāļāļāđāļāļĄāļđāļĨāđāļĒāļāļāļēāļĄāļāļĢāļ°āđāļ āļ order_type // =============================== $sql = " SELECT o.order_type, p.name AS product_name, SUM(i.qty) AS total_qty, SUM(i.qty * i.price) AS total_amount, SUM(CASE WHEN i.receive_method='āļĢāļąāļāđāļŦāļĢāļĩāļĒāļāļāđāļ§āļĒāļāļāđāļāļ' THEN i.qty ELSE 0 END) AS qty_self, SUM(CASE WHEN i.receive_method='āļāļąāļāļŠāđāļāļāļēāļāđāļāļĢāļĐāļāļĩāļĒāđ' THEN i.qty ELSE 0 END) AS qty_post FROM order_items i JOIN orders o ON i.order_id = o.id JOIN products p ON i.product_id = p.id WHERE DATE(o.created_at) BETWEEN ? AND ? AND i.confirm_status = 'āļĒāļ·āļāļĒāļąāļ' AND (o.order_type = 'āļāļāļāļī' OR o.order_type = 'Pre Order') GROUP BY p.id, o.order_type ORDER BY o.order_type ASC, p.name ASC "; $stmt = $conn->prepare($sql); $stmt->bind_param('ss', $date_from, $date_to); $stmt->execute(); $res = $stmt->get_result(); // āđāļĒāļāļāđāļāļĄāļđāļĨāđāļāđāļ 2 āļāļĨāļļāđāļĄ $data_normal = []; $data_free = []; while($r = $res->fetch_assoc()) { if($r['order_type'] == 'Pre Order') { $data_free[] = $r; } else { $data_normal[] = $r; } } ?> <!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;} .table th,.table td{vertical-align:middle!important;} .section-title { background: linear-gradient(90deg, #333, #666); color: #fff; padding: 10px 15px; border-radius: 6px; margin-top: 20px; } .badge-normal{background:#28a745;color:#fff;font-size:0.8rem;padding:3px 8px;border-radius:10px;} .badge-free{background:#ffc107;color:#000;font-size:0.8rem;padding:3px 8px;border-radius:10px;} .summary-total { background: #f7f7f7; border-radius: 8px; padding: 15px; margin-top: 25px; font-size: 1.05rem; box-shadow: 0 0 5px rgba(0,0,0,0.1); } </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 mb-3 shadow-sm"> <div class="card-body"> <form class="row g-2 align-items-end"> <div class="col-md-4"> <label class="form-label">āļāļēāļāļ§āļąāļāļāļĩāđ</label> <input type="date" name="date_from" value="<?=htmlspecialchars($date_from)?>" class="form-control"> </div> <div class="col-md-4"> <label class="form-label">āļāļķāļāļ§āļąāļāļāļĩāđ</label> <input type="date" name="date_to" value="<?=htmlspecialchars($date_to)?>" class="form-control"> </div> <div class="col-md-2"> <button class="btn btn-primary w-100">āđāļŠāļāļ</button> </div> <div class="col-md-2 text-end"> <a href="orders_product_summary_export.php?date_from=<?=$date_from?>&date_to=<?=$date_to?>" class="btn btn-outline-success w-100">ð Export Excel</a> </div> </form> </div> </div> <!-- ðđ āļāļēāļĢāļēāļāļāļģāļŠāļąāđāļāļāļ·āđāļāļāļāļāļī --> <div class="section-title">ðĐ āļŠāļĢāļļāļāļĒāļāļāļāļģāļŠāļąāđāļāļāļ·āđāļ <span class="badge-normal">āļāļāļāļī</span></div> <div class="card shadow-sm mb-4"> <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> </tr> </thead> <tbody> <?php $i=1; $sum_qty=0; $sum_amt=0; $sum_self=0; $sum_post=0; if(count($data_normal)>0): foreach($data_normal as $r): $sum_qty += $r['total_qty']; $sum_amt += $r['total_amount']; $sum_self += $r['qty_self']; $sum_post += $r['qty_post']; ?> <tr> <td><?=$i++?></td> <td><?=htmlspecialchars($r['product_name'])?></td> <td><?=number_format($r['total_qty'])?></td> <td><?=number_format($r['qty_self'])?></td> <td><?=number_format($r['qty_post'])?></td> <td><?=number_format($r['total_amount'],2)?></td> </tr> <?php endforeach; else: ?> <tr><td colspan="6" class="text-center text-muted py-4">āđāļĄāđāļĄāļĩāļāđāļāļĄāļđāļĨāļāļģāļŠāļąāđāļāļāļ·āđāļāļāļāļāļī</td></tr> <?php endif; ?> </tbody> <tfoot class="table-secondary fw-bold"> <tr> <td colspan="2">āļĢāļ§āļĄāļāļąāđāļāļŦāļĄāļ (āļāļāļāļī)</td> <td><?=number_format($sum_qty)?></td> <td><?=number_format($sum_self)?></td> <td><?=number_format($sum_post)?></td> <td><?=number_format($sum_amt,2)?></td> </tr> </tfoot> </table> </div> </div> </div> <!-- ðļ āļāļēāļĢāļēāļ Free Order --> <div class="section-title">ðĻ āļŠāļĢāļļāļāļĒāļāļāļāļģāļŠāļąāđāļāļāļ·āđāļ <span class="badge-free">Pre Order</span></div> <div class="card shadow-sm"> <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> </tr> </thead> <tbody> <?php $j=1; $sum_free_qty=0; $sum_free_amt=0; $sum_free_self=0; $sum_free_post=0; if(count($data_free)>0): foreach($data_free as $r): $sum_free_qty += $r['total_qty']; $sum_free_amt += $r['total_amount']; $sum_free_self += $r['qty_self']; $sum_free_post += $r['qty_post']; ?> <tr> <td><?=$j++?></td> <td><?=htmlspecialchars($r['product_name'])?></td> <td><?=number_format($r['total_qty'])?></td> <td><?=number_format($r['qty_self'])?></td> <td><?=number_format($r['qty_post'])?></td> <td><?=number_format($r['total_amount'],2)?></td> </tr> <?php endforeach; else: ?> <tr><td colspan="6" class="text-center text-muted py-4">āđāļĄāđāļĄāļĩāļāđāļāļĄāļđāļĨāļāļģāļŠāļąāđāļāļāļ·āđāļ Pre Order</td></tr> <?php endif; ?> </tbody> <tfoot class="table-secondary fw-bold"> <tr> <td colspan="2">āļĢāļ§āļĄāļāļąāđāļāļŦāļĄāļ (Pre Order)</td> <td><?=number_format($sum_free_qty)?></td> <td><?=number_format($sum_free_self)?></td> <td><?=number_format($sum_free_post)?></td> <td><?=number_format($sum_free_amt,2)?></td> </tr> </tfoot> </table> </div> </div> </div> <!-- â āļĢāļ§āļĄāļāļąāđāļāļŦāļĄāļāļāļąāđāļāļŠāļāļāļāļĢāļ°āđāļ āļ --> <div class="summary-total mt-4"> <h5 class="fw-bold mb-2">ð āļĢāļ§āļĄāļĒāļāļāļāļąāđāļāļŦāļĄāļ (āļāļāļāļī + Pre Order)</h5> <p class="mb-0"> âĒ āļĒāļāļāļĢāļ§āļĄāļāļģāļāļ§āļāđāļŦāļĢāļĩāļĒāļāļāļąāđāļāļŦāļĄāļ: <b><?=number_format($sum_qty + $sum_free_qty)?></b> āļāļīāđāļ<br> âĒ āļĢāļąāļāđāļŦāļĢāļĩāļĒāļāļāđāļ§āļĒāļāļāđāļāļ: <b><?=number_format($sum_self + $sum_free_self)?></b> āļāļīāđāļ<br> âĒ āļāļąāļāļŠāđāļāļāļēāļāđāļāļĢāļĐāļāļĩāļĒāđ: <b><?=number_format($sum_post + $sum_free_post)?></b> āļāļīāđāļ<br> âĒ āļĒāļāļāļĢāļ§āļĄāļāļąāđāļāļŦāļĄāļ: <b><?=number_format($sum_amt + $sum_free_amt, 2)?></b> āļāļēāļ </p> </div> <div class="text-end mt-4"> <a href="orders_product_summary_print.php?date_from=<?=$date_from?>&date_to=<?=$date_to?>" target="_blank" class="btn btn-success">ðĻ āļāļīāļĄāļāđāļĢāļēāļĒāļāļēāļ</a> </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.7 |
proxy
|
phpinfo
|
Settings