<?php
require 'config.php';
include 'navbar.php'; ?>

header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-Disposition: attachment; filename=sales_report.xls");
header("Pragma: no-cache");
header("Expires: 0");

$sales = $pdo->query("SELECT s.*, p.name FROM sales s JOIN products p ON p.id=s.product_id ORDER BY s.id DESC")->fetchAll();

echo "<table border='1'>";
echo "<tr style='background:#ffeeba;'><th>المادة</th><th>الشوالات</th><th>الوزن</th><th>السعر</th><th>ملاحظات</th><th>تاريخ</th></tr>";
foreach($sales as $s){
  echo "<tr>
    <td>{$s['name']}</td>
    <td>{$s['bags_sold']}</td>
    <td>{$s['weight_sold']}</td>
    <td>{$s['price']}</td>
    <td>{$s['note']}</td>
    <td>{$s['sale_date']}</td>
  </tr>";
}
echo "</table>";
?>
