From 99f0a9cf449186c659def90f0b9160a9174fd916 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 9 Aug 2019 07:42:18 +0000 Subject: [PATCH] Display customer and warranty information for serials from the uploaded CSV file. #248 --- src/Controller/ReportController.php | 64 ++++++++++++++++++++----- templates/report/popapp/form.html.twig | 66 ++++++++++++++++++++++++-- 2 files changed, 113 insertions(+), 17 deletions(-) diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index 0e66687e..224019d2 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -5,12 +5,14 @@ namespace App\Controller; use App\Ramcar\JORejectionReason; use App\Ramcar\ServiceType; use App\Ramcar\JOStatus; +use App\Ramcar\InvalidPlateNumber; use App\Entity\JORejection; use App\Entity\Battery; use App\Entity\JobOrder; use App\Entity\Warranty; use App\Entity\CustomerVehicle; +use App\Entity\MobileSession; use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; @@ -410,22 +412,31 @@ class ReportController extends Controller public function popappComparisonForm() { $this->denyAccessUnlessGranted('report.popapp.comparison', null, 'No access.'); + $params['mode'] = 'form'; - return $this->render('report/popapp/form.html.twig'); + return $this->render('report/popapp/form.html.twig', $params); } + /** + * @Menu(selected="outlet_list") + */ public function popappComparisonSubmit(Request $req) { // retrieve temporary info for file $file = $req->files->get('csv_file'); // process the csv file - $this->processPopappFile($file); + $data = $this->processPopappFile($file); // return response - return $this->json([ - 'success' => true, - ]); + //return $this->json([ + // 'success' => true, + // 'data' => $data, + //]); + $params['mode'] = 'results'; + $params['data'] = $data; + + return $this->render('report/popapp/form.html.twig', $params); } protected function processPopappFile(UploadedFile $csv_file) @@ -456,24 +467,53 @@ class ReportController extends Controller } // get the warranty for serial - $qb = $this->getDoctrine() + $warr_qb = $this->getDoctrine() ->getRepository(Warranty::class) ->createQueryBuilder('q'); - $warranty_query = $qb->select('q') + $warranty_query = $warr_qb->select('q') ->where('q.serial IN(:serials)') ->setParameter('serials', $serial_numbers, Connection::PARAM_STR_ARRAY); $warr_results = $warranty_query->getQuery()->getResult(); // get the plate numbers - $plate_numbers = []; + $results = []; foreach ($warr_results as $warranty) { - $plate_numbers[] = $warranty->getPlateNumber(); - // what if plate number is 0000 or NONE? + //error_log($warranty->getPlateNumber()); + // validate the plate number + $isValid = InvalidPlateNumber::isInvalid($warranty->getPlateNumber()); + if ($isValid) + { + // get customer vehicle using plate number + $em = $this->getDoctrine()->getManager(); + $cust_vehicles = $em->getRepository(CustomerVehicle::class)->findBy(['plate_number' => $warranty->getPlateNumber()]); + foreach ($cust_vehicles as $cv) + { + // get customer info + // get mobile session of customer + //error_log($cv->getCustomer()->getLastName() . ' ' . $cv->getCustomer()->getFirstName()); + $has_mobile = false; + $mobile_session = $em->getRepository(MobileSession::class)->findBy(['customer' => $cv->getCustomer()->getID()]); + foreach ($mobile_session as $mobile) + { + error_log($mobile->getID()); + $has_mobile = true; + } + $results[] = [ + 'cust_id' => $cv->getCustomer()->getID(), + 'cust_lastname' => $cv->getCustomer()->getLastName(), + 'cust_firstname' => $cv->getCustomer()->getFirstName(), + 'plate_num' => $cv->getPlateNumber(), + 'serial' => $warranty->getSerial(), + 'warr_date_create' => $warranty->getDateCreate()->format("d M Y"), + 'has_mobile' => $has_mobile, + ]; + + } + } } - // search in customer vehicle using the plate numbers - + return $results; } } diff --git a/templates/report/popapp/form.html.twig b/templates/report/popapp/form.html.twig index bc176c63..1dad59a6 100644 --- a/templates/report/popapp/form.html.twig +++ b/templates/report/popapp/form.html.twig @@ -5,7 +5,9 @@
-

Popapp Comparison Report

+

+ Popapp Comparison Report +

@@ -46,10 +48,64 @@ + {% if mode == 'results' %} + +
+
+
+
+
+
+

+ Report Details +

+
+
+
+
+ {% if data is empty %} + + {% else %} + + + + + + + + + + + + + + {% for key, result in data %} + + + + + + + + + + {% endfor %} + +
Customer IDLast NameFirst NamePlate NumberSerialWarranty Create DateHas Mobile?
{{ result.cust_id|default("") }}{{ result.cust_lastname|default('') }}{{ result.cust_firstname|default('') }}{{ result.plate_num|default('') }}{{ result.serial|default('') }}{{ result.warr_date_create|default('') }}{{ result.has_mobile ? Yes : 'No' }}
+ {% endif %} +
+
+
+
+ {% endif %} {% endblock %} -{% block scripts %} - -{% endblock %}