Fix formatting issue for csv output. #197

This commit is contained in:
Korina Cordero 2019-04-03 07:29:14 +00:00
parent 3af6d6b7e8
commit c80013bc02

View file

@ -324,6 +324,7 @@ class ReportController extends BaseController
$invoice_items = $jo->getInvoice()->getItems();
foreach ($invoice_items as $item)
{
// check if the item is a battery
if ($item->getBattery() != null)
{
$batt_id = $item->getBattery()->getID();
@ -338,42 +339,44 @@ class ReportController extends BaseController
$batteries = [];
foreach($jo->getCustomerVehicle()->getVehicle()->getBatteries() as $comp_batt)
{
$batteries[] = [
'id' => $comp_batt->getID(),
'mfg_name' => $comp_batt->getManufacturer()->getName(),
'model_name' => $comp_batt->getModel()->getName(),
'size_name' => $comp_batt->getSize()->getName(),
];
//$batteries[] = [
// 'mfg_name' => $comp_batt->getManufacturer()->getName(),
// 'model_name' => $comp_batt->getModel()->getName(),
// 'size_name' => $comp_batt->getSize()->getName(),
//];
$batteries[] = $comp_batt->getManufacturer()->getName() . ' ' .
$comp_batt->getModel()->getName() . ' ' .
$comp_batt->getSize()->getName();
}
$results[] = [
'jo_id' => $jo->getID(),
'jo_date_create' => $jo->getDateCreate(),
'jo_date_create' => $jo->getDateCreate()->format('m/d/Y H:i'),
'cus_vehicle_manufacturer' => $jo->getCustomerVehicle()->getVehicle()->getManufacturer()->getName(),
'cus_vehicle_make' => $jo->getCustomerVehicle()->getVehicle()->getMake(),
'cus_vehicle_model' => $jo->getCustomerVehicle()->getModelYear(),
'battery_model_ordered' => $item->getBattery()->getModel()->getName(),
'battery_size_ordered' => $item->getBattery()->getSize()->getName(),
'compatible_batt' => $batteries,
'compatible_batt' => implode(', ', $batteries),
];
}
}
}
}
/*
$resp = new StreamedResponse();
$resp->setCallback(function() use ($results) {
// csv output
$csv_handle = fopen('php://output', 'w+');
fputcsv($csv_handle, [
'Order #',
'Order Date and Time'
//'Manufacturer',
//'Make',
//'Year',
//'Battery Model',
//'Battery Size',
//'Compatible Batteries'
'Order Date and Time',
'Manufacturer',
'Make',
'Year',
'Battery Model',
'Battery Size',
'Compatible Batteries'
]);
foreach ($results as $row)
{
@ -390,10 +393,9 @@ class ReportController extends BaseController
$resp->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
return $resp;
*/
return $this->json([
'result' => $results,
]);
//return $this->json([
// 'result' => $results,
//]);
}
}