Modified contents of the csv file when no invalid warranties are found. #476
This commit is contained in:
parent
9fa7ee9684
commit
479ff96fdc
1 changed files with 46 additions and 31 deletions
|
|
@ -386,43 +386,58 @@ class WarrantyController extends Controller
|
||||||
$inv_entries = $this->processWarrantyFile($file, $em, $wh);
|
$inv_entries = $this->processWarrantyFile($file, $em, $wh);
|
||||||
|
|
||||||
$resp = new StreamedResponse();
|
$resp = new StreamedResponse();
|
||||||
$resp->setCallback(function() use($inv_entries) {
|
|
||||||
// csv output
|
|
||||||
$csv_handle = fopen('php://output', 'w+');
|
|
||||||
fputcsv($csv_handle, [
|
|
||||||
'Owner First Name',
|
|
||||||
'Owner Last Name',
|
|
||||||
'Owner Email',
|
|
||||||
'Owner Address',
|
|
||||||
'Owner Mobile',
|
|
||||||
'Owner Telephone',
|
|
||||||
'Vehicle Make',
|
|
||||||
'Vehicle Model',
|
|
||||||
'Vehicle Year',
|
|
||||||
'Vehicle Plate Number',
|
|
||||||
'Battery Serial Number',
|
|
||||||
'Battery Sales Invoice',
|
|
||||||
'Battery Date of Purchase',
|
|
||||||
'Distributor Name',
|
|
||||||
'Distributor Address',
|
|
||||||
'Application Type ID',
|
|
||||||
'Battery ID',
|
|
||||||
'Ownership Type',
|
|
||||||
'Reason Warranty Not Added',
|
|
||||||
]);
|
|
||||||
foreach ($inv_entries as $row)
|
|
||||||
{
|
|
||||||
fputcsv($csv_handle, $row);
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose($csv_handle);
|
if (count($inv_entries) > 0)
|
||||||
});
|
{
|
||||||
|
$resp->setCallback(function() use($inv_entries) {
|
||||||
|
// csv output
|
||||||
|
$csv_handle = fopen('php://output', 'w+');
|
||||||
|
fputcsv($csv_handle, [
|
||||||
|
'Owner First Name',
|
||||||
|
'Owner Last Name',
|
||||||
|
'Owner Email',
|
||||||
|
'Owner Address',
|
||||||
|
'Owner Mobile',
|
||||||
|
'Owner Telephone',
|
||||||
|
'Vehicle Make',
|
||||||
|
'Vehicle Model',
|
||||||
|
'Vehicle Year',
|
||||||
|
'Vehicle Plate Number',
|
||||||
|
'Battery Serial Number',
|
||||||
|
'Battery Sales Invoice',
|
||||||
|
'Battery Date of Purchase',
|
||||||
|
'Distributor Name',
|
||||||
|
'Distributor Address',
|
||||||
|
'Application Type ID',
|
||||||
|
'Battery ID',
|
||||||
|
'Ownership Type',
|
||||||
|
'Reason Warranty Not Added',
|
||||||
|
]);
|
||||||
|
foreach ($inv_entries as $row)
|
||||||
|
{
|
||||||
|
fputcsv($csv_handle, $row);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($csv_handle);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$resp->setCallback(function() {
|
||||||
|
// csv output
|
||||||
|
$csv_handle = fopen('php://output', 'w+');
|
||||||
|
fputcsv($csv_handle, ['No Invalid Warranties']);
|
||||||
|
|
||||||
|
fclose($csv_handle);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$filename = 'invalid_warranties' . '.csv';
|
$filename = 'invalid_warranties' . '.csv';
|
||||||
|
|
||||||
$resp->setStatusCode(200);
|
|
||||||
$resp->headers->set('Content-Type', 'text/csv; charset=utf-8');
|
$resp->headers->set('Content-Type', 'text/csv; charset=utf-8');
|
||||||
$resp->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
|
$resp->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
|
||||||
|
$resp->setStatusCode(200);
|
||||||
|
|
||||||
return $resp;
|
return $resp;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue