D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
siliguritoys.com
/
slgadmintoys
/
Filename :
purchase_report.php
back
Copy
<?php include 'config.php'; // Handle Excel Export if(isset($_GET['export'])) { header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename="purchase_report_'.date('Ymd').'.xls"'); // Build query (same as main page) $query = "SELECT o.*, c.customer_name, c.customer_email, c.customer_phone FROM orders o JOIN slgtoys_customer c ON o.customer_id = c.customer_id"; if (!empty($_GET['from_date']) && !empty($_GET['to_date'])) { $query .= " WHERE o.created_at BETWEEN '".$_GET['from_date']." 00:00:00' AND '".$_GET['to_date']." 23:59:59'"; } $query .= " ORDER BY o.created_at DESC"; $result = mysqli_query($conn, $query); // Start Excel output echo "<table border='1'>"; echo "<tr> <th>Order ID</th> <th>Customer</th> <th>Email</th> <th>Phone</th> <th>Amount</th> <th>Payment Method</th> <th>Payment ID</th> <th>Date</th> <th>Status</th> </tr>"; while($row = mysqli_fetch_assoc($result)) { $status = $row['status'] ?? 'pending'; echo "<tr> <td>".$row['id']."</td> <td>".$row['customer_name']."</td> <td>".$row['customer_email']."</td> <td>".$row['customer_phone']."</td> <td>₹".number_format($row['grand_total'], 2)."</td> <td>".ucfirst($row['payment_method'])."</td> <td>".($row['razorpay_payment_id'] ?: 'N/A')."</td> <td>".date("d M Y, h:i A", strtotime($row['created_at']))."</td> <td>".ucfirst($status)."</td> </tr>"; } echo "</table>"; exit(); } ?> <!DOCTYPE html> <html lang="en" data-theme="light"> <head> <?php include 'style.php'; ?> </head> <body> <?php include 'sidebar.php'; ?> <main class="dashboard-main"> <?php include 'header.php'; ?> <div class="dashboard-main-body"> <div class="d-flex flex-wrap align-items-center justify-content-between gap-3 mb-24"> <h6 class="fw-semibold mb-0">Purchase Report</h6> <ul class="d-flex align-items-center gap-2"> <li class="fw-medium"> <a href="index.html" class="d-flex align-items-center gap-1 hover-text-primary"> <iconify-icon icon="solar:home-smile-angle-outline" class="icon text-lg"></iconify-icon> Dashboard </a> </li> <li>-</li> <li class="fw-medium">Purchase Report</li> </ul> </div> <div class="row gy-4"> <div class="col-lg-12"> <div class="card"> <div class="card-header"> <h5 class="card-title mb-0">Complete Purchase History</h5> <div class="d-flex gap-2"> <form method="get" class="d-flex gap-2"> <input type="date" name="from_date" class="form-control" value="<?= $_GET['from_date'] ?? '' ?>"> <input type="date" name="to_date" class="form-control" value="<?= $_GET['to_date'] ?? '' ?>"> <button type="submit" class="btn btn-primary">Filter</button> <a href="?export=1&from_date=<?= $_GET['from_date'] ?? '' ?>&to_date=<?= $_GET['to_date'] ?? '' ?>" class="btn btn-success">Export to Excel</a> </form> </div> </div> <div class="card-body"> <div class="table-responsive"> <table class="table bordered-table mb-0"> <thead> <tr> <th>Order ID</th> <th>Customer</th> <th>Email</th> <th>Phone</th> <th>Amount</th> <th>Payment Method</th> <th>Payment ID</th> <th>Date</th> <th>Status</th> </tr> </thead> <tbody> <?php // Build query with filters $query = "SELECT o.*, c.customer_name, c.customer_email, c.customer_phone FROM orders o JOIN slgtoys_customer c ON o.customer_id = c.customer_id"; // Add date filters if provided if (!empty($_GET['from_date']) && !empty($_GET['to_date'])) { $query .= " WHERE o.created_at BETWEEN '".$_GET['from_date']." 00:00:00' AND '".$_GET['to_date']." 23:59:59'"; } $query .= " ORDER BY o.created_at DESC"; $result = mysqli_query($conn, $query); if (mysqli_num_rows($result) > 0) { while ($row = mysqli_fetch_assoc($result)) { $status = $row['status'] ?? 'pending'; ?> <tr> <td><?= $row['id']; ?></td> <td><?= $row['customer_name']; ?></td> <td><?= $row['customer_email']; ?></td> <td><?= $row['customer_phone']; ?></td> <td>₹<?= number_format($row['grand_total'], 2); ?></td> <td><?= ucfirst($row['payment_method']); ?></td> <td><?= $row['razorpay_payment_id'] ?: 'N/A'; ?></td> <td><?= date("d M Y, h:i A", strtotime($row['created_at'])); ?></td> <td> <span class="badge <?= $status == 'approved' ? 'bg-success' : ($status == 'rejected' ? 'bg-danger' : 'bg-warning') ?>"> <?= ucfirst($status); ?> </span> </td> </tr> <?php } } else { echo "<tr><td colspan='9' class='text-center'>No orders found</td></tr>"; } ?> </tbody> </table> </div> </div> </div> </div> </div> </div> <?php include 'Footer.php'; ?> </main> </body> </html>