Created
March 9, 2017 07:51
-
-
Save esmeromichael/fec865112bcb33e3fb642251c7fc46ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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