<?php
require_once __DIR__ . '/../config/db_remote.php';

header("Content-Type: text/csv");
header("Content-Disposition: attachment; filename=production_report.csv");

$out=fopen("php://output","w");
fputcsv($out,[
 'Serial','SKU','Crop','Variety','Packaging','Size','Grower',
 'CaseDate','Shipment','Pallet','Operator','Station','Note','ScanTime'
]);

$q=$mysqli->query("SELECT * FROM barcode_readings ORDER BY read_time DESC");
while($r=$q->fetch_assoc()){
    fputcsv($out,$r);
}
fclose($out);
exit;
