From 2a811037736afef29a531ad9318e25a4b9125a49 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 16 Sep 2019 10:47:48 +0000 Subject: [PATCH] Add method and form for the report. #267 --- config/acl.yaml | 2 + config/routes/report.yaml | 10 ++++ src/Controller/ReportController.php | 79 +++++++++++++++++++++++++++++ templates/base.html.twig | 8 +++ templates/report/meh/form.html.twig | 50 ++++++++++++++++++ 5 files changed, 149 insertions(+) create mode 100644 templates/report/meh/form.html.twig diff --git a/config/acl.yaml b/config/acl.yaml index 64b53ad1..f48850f6 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -292,6 +292,8 @@ access_keys: label: Battery Conflict Report - id: report.popapp.comparison label: Popapp Comparison Report + - id: report.meh.customer + label: RESQ MEH Customer Report - id: service label: Other Services diff --git a/config/routes/report.yaml b/config/routes/report.yaml index 274a1268..5d815490 100644 --- a/config/routes/report.yaml +++ b/config/routes/report.yaml @@ -37,3 +37,13 @@ rep_popapp_export_csv: path: /report/popapp_export controller: App\Controller\ReportController::popappExportCSV methods: [POST] + +rep_resq_meh_form: + path: /report/meh_customer + controller: App\Controller\ReportController::mehCustomerForm + methods: [GET] + +rep_resq_meh_export_csv: + path: /report/meh_customer_export + controller: App\Controller\ReportController::mehCustomerExportCSV + methods: [POST] diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index 0c1ea33a..de2748bb 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -13,6 +13,7 @@ use App\Entity\JobOrder; use App\Entity\Warranty; use App\Entity\CustomerVehicle; use App\Entity\MobileSession; +use App\Entity\Customer; use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; @@ -26,6 +27,7 @@ use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Component\Dotenv\Dotenv; use Catalyst\MenuBundle\Annotation\Menu; @@ -494,6 +496,55 @@ class ReportController extends Controller } + /** + * @Menu(selected="outlet_list") + */ + public function mehCustomerForm() + { + $this->denyAccessUnlessGranted('report.meh.customer', null, 'No access.'); + $params['mode'] = 'form'; + + return $this->render('report/meh/form.html.twig', $params); + } + + /** + * @Menu(selected="outlet_list") + */ + public function mehCustomerExportCSV(Request $req, EntityManagerInterface $em) + { + $data = getMEHCustomerData($em); + + $resp = new StreamedResponse(); + $resp->setCallback(function() use ($data) { + // csv output + $csv_handle = fopen('php://output', 'w+'); + fputcsv($csv_handle, [ + 'Last Name', + 'First Name', + 'Mobile Number', + 'Landline Number', + 'Office Number', + 'Fax Number', + 'Date Mobile App Downloaded', + 'Mobile Number Using Mobile App', + ]); + foreach ($data as $row) + { + fputcsv($csv_handle, $row); + } + + fclose($csv_handle); + }); + + $filename = 'resq_meh_customer_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, EntityManagerInterface $em) { // attempt to open file @@ -620,4 +671,32 @@ class ReportController extends Controller return $results; } + protected function getMEHCustomerData(EntityManagerInterface $em) + { + $results = []; + + //get the policy id for the mobile privacy policy from env + $dotenv = new Dotenv(); + $dotenv->loadEnv(__DIR__.'/../../.env'); + + $policy_mobile_id = $_ENV['POLICY_MOBILE']; + + // get all the customers with mobile privacy policy id + $customers = $em->getRepository(Customer::class)->findBy(['privpol_mobile_app' => $policy_mobile_id]): + + foreach ($customers as $customer) + { + // get plate numbers + $plate_numbers = $customer->getPlateNumberList(); + + // using plate number, get all customer vehicles with the plate number and the job orders with the plate number + + // get job orders of vehicles + + // check if source is not null. If not null, add customer to results + } + + return $results; + } + } diff --git a/templates/base.html.twig b/templates/base.html.twig index 9052bb17..d1875e70 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -157,6 +157,14 @@ Popapp Comparison Report + + + + + + RESQ MEH Customer Report + + diff --git a/templates/report/meh/form.html.twig b/templates/report/meh/form.html.twig new file mode 100644 index 00000000..8cfd9570 --- /dev/null +++ b/templates/report/meh/form.html.twig @@ -0,0 +1,50 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ RESQ MEH Customer Report +

+
+
+
+ +
+ +
+
+
+
+
+
+ + + +

+ Generate Customer CSV File +

+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+{% endblock %} +