diff --git a/src/Controller/WarrantyController.php b/src/Controller/WarrantyController.php index 3e45576d..b25fd14d 100644 --- a/src/Controller/WarrantyController.php +++ b/src/Controller/WarrantyController.php @@ -454,60 +454,46 @@ class WarrantyController extends Controller $file = $req->files->get('csv_file'); // process the csv file. Call the WarrantyBulkUploader service - $inv_entries = $warr_uploader->warrantyUpload($file); + $entries = $warr_uploader->warrantyUpload($file); $resp = new StreamedResponse(); - if (count($inv_entries) > 0) - { - $resp->setCallback(function() use($inv_entries) { - // csv output - $csv_handle = fopen('php://output', 'w+'); - fputcsv($csv_handle, [ - 'Encoded By', - 'Date of Encoded', - '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', - 'Status', - 'Reason Warranty Not Added', - ]); - foreach ($inv_entries as $row) - { - fputcsv($csv_handle, $row); - } + $resp->setCallback(function() use($entries) { + // csv output + $csv_handle = fopen('php://output', 'w+'); + fputcsv($csv_handle, [ + 'Encoded By', + 'Date of Encoded', + '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', + 'Status', + 'Reason Warranty Not Added', + ]); + foreach ($entries as $row) + { + fputcsv($csv_handle, $row); + } - fclose($csv_handle); - }); + 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 = 'upload_warranty_results' . '.csv'; $resp->headers->set('Content-Type', 'text/csv; charset=utf-8'); $resp->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');