
PK 
<?php
include("../conn.php");
// Set headers for Excel download
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="orders_export.xls"');
header('Cache-Control: max-age=0');
// Build WHERE clause based on filters
$whr = 1;
if($_GET['date_filter']!="") {
switch ($_GET['date_filter']) {
case 'today':
$whr .= " and DATE(o.dt) = CURDATE() ";
break;
case 'yesterday':
$whr .= " and DATE(o.dt) = CURDATE() - INTERVAL 1 DAY ";
break;
case 'this_week':
$whr .= " and WEEK(o.dt) = WEEK(CURDATE()) AND YEAR(o.dt) = YEAR(CURDATE()) ";
break;
case 'last_week':
$whr .= " and WEEK(o.dt) = WEEK(CURDATE()) - 1 AND YEAR(o.dt) = YEAR(CURDATE()) ";
break;
case 'this_month':
$whr .= " and MONTH(o.dt) = MONTH(CURDATE()) AND YEAR(o.dt) = YEAR(CURDATE()) ";
break;
case 'last_month':
$whr .= " and MONTH(o.dt) = MONTH(CURDATE()) - 1 AND YEAR(o.dt) = YEAR(CURDATE()) ";
break;
}
} else if($_GET['frm']!="" && $_GET['to']!="") {
$whr .= " and o.dt >= '$_GET[frm] 00:00:00' and o.dt <= '$_GET[to] 23:59:59' ";
}
if($_GET['payment_method']!="") {
$whr .= " and payment_method='$_GET[payment_method]' ";
}
if($_GET['city']!="") {
$whr .= " and city LIKE '%$_GET[city]%' ";
}
if($_GET['sts']!="") {
$whr .= " and status='$_GET[sts]' ";
}
// Query to get filtered orders
$query = "SELECT o.order_id,
CONCAT(o.fname, ' ', o.lname) as customer_name,
o.mobile,
CONCAT(o.address, ' ', o.address1) as full_address,
o.city,
o.postcode,
o.total,
o.dt as order_date,
o.payment_method,
o.awbno,
o.status
FROM orders as o
WHERE $whr
ORDER BY o.dt DESC";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
// Create Excel Header
echo "Order ID\tCustomer Name\tMobile\tAddress\tCity\tPincode\tAmount\tOrder Date\tPayment Mode\tAWB No\tOrder Status\n";
// Output data rows
while($row = mysqli_fetch_array($result)) {
echo $row['order_id'] . "\t";
echo $row['customer_name'] . "\t";
echo $row['mobile'] . "\t";
echo str_replace("\n", " ", $row['full_address']) . "\t";
echo $row['city'] . "\t";
echo $row['postcode'] . "\t";
echo "Rs." . number_format($row['total'], 2) . "\t";
echo date("d M Y h:i:s a", strtotime($row['order_date'])) . "\t";
echo strtoupper($row['payment_method']) . "\t";
echo $row['awbno'] . "\t";
echo $row['status'] . "\n";
}
?>


PK 99