Merge branch '476-resq-success-message-for-warranty-upload' into '480-resq-august-28-release'
Modified contents of the csv file when no invalid warranties are found. #476 See merge request jankstudio/resq!564
This commit is contained in:
commit
e6dd08d6d0
1 changed files with 46 additions and 31 deletions
|
|
@ -386,43 +386,58 @@ class WarrantyController extends Controller
|
|||
$inv_entries = $this->processWarrantyFile($file, $em, $wh);
|
||||
|
||||
$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';
|
||||
|
||||
$resp->setStatusCode(200);
|
||||
$resp->headers->set('Content-Type', 'text/csv; charset=utf-8');
|
||||
$resp->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
|
||||
$resp->setStatusCode(200);
|
||||
|
||||
return $resp;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue