<?php
$page_title = 'Export List Order';
require_once('includes/load.php');
page_require_level(2);

// Query SQL untuk mengambil data dari tabel list_order
$list_orders = find_all('list_order');

// Header untuk membuat file CSV
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="list_order.csv"');

$output = fopen('php://output', 'w');

// Header CSV
fputcsv($output, array('No Order', 'Model', 'Quantity', 'Description', 'Customer', 'Address', 'Order Date', 'Delivery Date'));

// Data CSV
foreach ($list_orders as $order) {
    fputcsv($output, array(
        $order['order_number'],
        $order['model'],
        $order['quantity'],
        $order['description'],
        $order['customer'],
        $order['address'],
        $order['order_date'],
        $order['delivery_date']
    ));
}

fclose($output);
exit();
?>
