<?php
require 'config.php';
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-Disposition: attachment; filename=stock_report.xls");
header("Pragma: no-cache");
header("Expires: 0");

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

echo "<table border='1'>";
echo "<tr style='background:#bee5eb;'><th>المادة</th><th>عدد الشوالات</th><th>الوزن الكلي</th><th>تاريخ الإضافة</th></tr>";
foreach($stock as $s){
  echo "<tr>
    <td>{$s['name']}</td>
    <td>{$s['bags_count']}</td>
    <td>{$s['total_weight']}</td>
    <td>{$s['date_added']}</td>
  </tr>";
}
echo "</table>";
?>
