<?php
require_once('includes/load.php');

$mrpData = array(); // Initialize an array to store MRP data

// Retrieve data from the 'mrp' table
$mrpResult = $db->query("SELECT * FROM mrp");
while ($row = $db->fetch_assoc($mrpResult)) {
    $mrpData[] = $row;
}

// Generate CSV content
$csvContent = "Child BOM,Child Name,Level,Quantity,Quantity Order,Total Requirement,UoM,Total Requirement (KG)\n";
foreach ($mrpData as $data) {
    $csvContent .= "{$data['child_bom']},{$data['child_name']},{$data['level']},{$data['quantity']},{$data['quantity_order']},{$data['total_requirement']},{$data['uom']},{$data['total_requirement_kg']}\n";
}

// Set the response headers
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=mrp_export.csv");

// Output the CSV content
echo $csvContent;
exit();
?>
