From 498b61be48efa5087d5583d296fee1c0b8f456e7 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 15 Aug 2019 05:52:29 +0000 Subject: [PATCH 1/2] Add export to CSV button. Add method to controller that uploads a csv file and outputs a csv report of the results. #249 --- config/routes/report.yaml | 5 +++ src/Controller/ReportController.php | 48 ++++++++++++++++++++++++-- templates/report/popapp/form.html.twig | 5 +-- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/config/routes/report.yaml b/config/routes/report.yaml index 40bba3f8..795ae0c6 100644 --- a/config/routes/report.yaml +++ b/config/routes/report.yaml @@ -37,3 +37,8 @@ rep_popapp_comp_submit: path: /report/popapp_comparison controller: App\Controller\ReportController::popappComparisonSubmit methods: [POST] + +rep_popapp_export_csv: + path: /report/popapp_export + controller: App\Controller\ReportController::popappExportCSV + methods: [POST] diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index c92b071b..721e7e37 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -439,6 +439,49 @@ class ReportController extends Controller return $this->render('report/popapp/form.html.twig', $params); } + /** + * @Menu(selected="outlet_list") + */ + public function popappExportCSV(Request $req) + { + // retrieve temporary info for file + $file = $req->files->get('csv_file'); + + // process the csv file + $data = $this->processPopappFile($file); + + $resp = new StreamedResponse(); + $resp->setCallback(function() use ($data) { + // csv output + $csv_handle = fopen('php://output', 'w+'); + fputcsv($csv_handle, [ + 'Customer ID', + 'Last Name', + 'First Name', + 'Plate Number', + 'Serial', + 'Warranty Create Date', + 'Activation Status', + 'Has Mobile App?', + ]); + foreach ($data as $row) + { + fputcsv($csv_handle, $row); + } + + fclose($csv_handle); + }); + + $filename = 'popapp_comparison_report' . '.csv'; + + $resp->setStatusCode(200); + $resp->headers->set('Content-Type', 'text/csv; charset=utf-8'); + $resp->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"'); + + return $resp; + + } + protected function processPopappFile(UploadedFile $csv_file) { // attempt to open file @@ -507,8 +550,8 @@ class ReportController extends Controller 'plate_num' => $cv->getPlateNumber(), 'serial' => $warranty->getSerial(), 'warr_date_create' => $warranty->getDateCreate()->format("d M Y"), - 'has_mobile' => $has_mobile, - 'warr_activation_status' => $warranty->isActivated(), + 'warr_activation_status' => ($warranty->isActivated() ? 'Active' : 'Inactive'), + 'has_mobile' => ($has_mobile ? 'Yes' : 'No'), ]; } @@ -517,4 +560,5 @@ class ReportController extends Controller return $results; } + } diff --git a/templates/report/popapp/form.html.twig b/templates/report/popapp/form.html.twig index f48ada3d..12106ab4 100644 --- a/templates/report/popapp/form.html.twig +++ b/templates/report/popapp/form.html.twig @@ -39,6 +39,7 @@
+
@@ -96,8 +97,8 @@ {{ result.plate_num|default('') }} {{ result.serial|default('') }} {{ result.warr_date_create|default('') }} - {{ result.warr_activation_status ? 'Active' : 'Inactive' }} - {{ result.has_mobile ? 'Yes' : 'No' }} + {{ result.warr_activation_status }} + {{ result.has_mobile }} {% endfor %} From a36e9f810b31123797210453e8c5f037c0a51484 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 15 Aug 2019 06:15:53 +0000 Subject: [PATCH 2/2] Comment out the displaying of report details. #249 --- config/routes/report.yaml | 5 ----- src/Controller/ReportController.php | 4 ++-- templates/report/popapp/form.html.twig | 5 ++--- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/config/routes/report.yaml b/config/routes/report.yaml index 795ae0c6..274a1268 100644 --- a/config/routes/report.yaml +++ b/config/routes/report.yaml @@ -33,11 +33,6 @@ rep_popapp_comp_form: controller: App\Controller\ReportController::popappComparisonForm methods: [GET] -rep_popapp_comp_submit: - path: /report/popapp_comparison - controller: App\Controller\ReportController::popappComparisonSubmit - methods: [POST] - rep_popapp_export_csv: path: /report/popapp_export controller: App\Controller\ReportController::popappExportCSV diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index 721e7e37..0577595a 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -420,7 +420,7 @@ class ReportController extends Controller /** * @Menu(selected="outlet_list") */ - public function popappComparisonSubmit(Request $req) + /* public function popappComparisonSubmit(Request $req) { // retrieve temporary info for file $file = $req->files->get('csv_file'); @@ -437,7 +437,7 @@ class ReportController extends Controller $params['data'] = $data; return $this->render('report/popapp/form.html.twig', $params); - } + } */ /** * @Menu(selected="outlet_list") diff --git a/templates/report/popapp/form.html.twig b/templates/report/popapp/form.html.twig index 12106ab4..82384d08 100644 --- a/templates/report/popapp/form.html.twig +++ b/templates/report/popapp/form.html.twig @@ -29,7 +29,7 @@ -
+
@@ -38,8 +38,7 @@
- - +