Skip to content

Instantly share code, notes, and snippets.

@esmeromichael
Created March 9, 2017 07:51
Show Gist options
  • Save esmeromichael/fec865112bcb33e3fb642251c7fc46ee to your computer and use it in GitHub Desktop.
Save esmeromichael/fec865112bcb33e3fb642251c7fc46ee to your computer and use it in GitHub Desktop.
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=inventoryEvaluationReport.csv");
header("Pragma: no-cache");
header("Expires: 0");
$reports = DB::select("SELECT items.description as Description, SUM(inventoriable_qohs.qoh) as QOH,
(SELECT name FROM uoms WHERE items.uom_id = uoms.id) as UOM, items.item_cost as Itemcost
FROM inventoriable_qohs JOIN items ON inventoriable_qohs.item_id = items.id
WHERE items.inventory_types_id != '1' and items.status = 'Active'
GROUP BY inventoriable_qohs.item_id ORDER BY items.description
");
$columns = array('DESCRIPTION','QOH','Uom','ItemCost','Total');
$file = fopen('php://output', 'w');
fputcsv($file, $columns);
foreach($reports as $report) {
$total = $report->QOH * $report->Itemcost;
fputcsv($file, array($report->Description,$report->QOH,$report->UOM,$report->Itemcost,$total));
}
exit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment