From 498b61be48efa5087d5583d296fee1c0b8f456e7 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 15 Aug 2019 05:52:29 +0000 Subject: [PATCH 01/13] 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 02/13] 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 @@
- - +
From e634f2ee32c14e0123c4f4338fb24d9dae56eb30 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 15 Aug 2019 08:25:34 +0000 Subject: [PATCH 03/13] Add method to cancel warranty in WarrantyController. Add route and acl for cancel warranty. Add test command to test cancel warranty. #250 --- .../api-bundle/Command/TestAPICommand.php | 4 ++++ config/api_acl.yaml | 2 ++ config/routes/capi.yaml | 6 ++++++ src/Controller/CAPI/WarrantyController.php | 21 +++++++++++++++++++ 4 files changed, 33 insertions(+) diff --git a/catalyst/api-bundle/Command/TestAPICommand.php b/catalyst/api-bundle/Command/TestAPICommand.php index b7c12755..8d6680f2 100644 --- a/catalyst/api-bundle/Command/TestAPICommand.php +++ b/catalyst/api-bundle/Command/TestAPICommand.php @@ -73,6 +73,10 @@ class TestAPICommand extends Command ]; $api->post('/capi/warranties/' . $id . '/claim', $params); + // warranty cancel + $id = 86811; + $api->get('/capi/warranties/' . $id . '/cancel'); + // plate warranty $api->get('/capi/plates/' . $plate_num . '/warranties'); diff --git a/config/api_acl.yaml b/config/api_acl.yaml index 771d3d09..d1138fbc 100644 --- a/config/api_acl.yaml +++ b/config/api_acl.yaml @@ -12,6 +12,8 @@ access_keys: label: Register Battery - id: warranty.claim label: Claim + - id: warranty.cancel + label: Cancel - id: batterybrand label: Battery Brand Access acls: diff --git a/config/routes/capi.yaml b/config/routes/capi.yaml index a340041c..a8452122 100644 --- a/config/routes/capi.yaml +++ b/config/routes/capi.yaml @@ -84,6 +84,12 @@ capi_warranty_get_all: controller: App\Controller\CAPI\WarrantyController::getAll methods: [GET] +# cancel warranty +capi_warranty_cancel: + path: /capi/warranties/{id}/cancel + controller: App\Controller\CAPI\WarrantyController::cancel + methods: [GET] + # customer vehicle api diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index 081201ea..be80b25c 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -310,4 +310,25 @@ class WarrantyController extends APIController return new APIResponse(true, 'Warranties loaded.', $data); } + + public function cancel(Request $req, EntityManagerInterface $em, $id) + { + $this->denyAccessUnlessGranted('warranty.cancel', null, 'No access.'); + + // find warranty + $warr = $em->getRepository(Warranty::class)->find($id); + if ($warr == null) + { + return new APIResponse(false, 'No warranty found with that id.', null, 404); + } + + // set status to cancelled + $warr->setStatus(WarrantyStatus::CANCELLED); + + $em->persist($warr); + $em->flush(); + + return new APIResponse(true, 'Warranty cancelled successfully.'); + + } } From 2f8eab22368312c1a4f71f5967cc5ff47557909b Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 16 Aug 2019 01:53:24 +0000 Subject: [PATCH 04/13] Add checking for null on date_expire for warranty. #250 --- src/Controller/CAPI/WarrantyController.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index be80b25c..e5e367aa 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -60,7 +60,6 @@ class WarrantyController extends APIController 'status' => (string) $warr->getStatus(), 'date_create' => (string) $warr->getDateCreate()->format('YmdHis'), 'date_purchase' => (string) $warr->getDatePurchase()->format('Ymd'), - 'date_expire' => (string) $warr->getDateExpire()->format('Ymd'), 'flag_activated' => (boolean) $warr->isActivated(), ]; @@ -70,6 +69,12 @@ class WarrantyController extends APIController else $data['date_claim'] = (string) $warr->getDateClaim()->format('Ymd'); + $date_expire = $warr->getDateExpire(); + if ($date_expire == null) + $data['date_expire'] = null; + else + $data['date_expire'] = (string) $warr->getDateExpire()->format('Ymd'); + return $data; } @@ -322,6 +327,11 @@ class WarrantyController extends APIController return new APIResponse(false, 'No warranty found with that id.', null, 404); } + if ($warr->getStatus() == WarrantyStatus::CANCELLED) + { + return new APIResponse(false, 'Warranty already cancelled.'); + } + // set status to cancelled $warr->setStatus(WarrantyStatus::CANCELLED); From cf89311e1737d48a443d961ac6e1bcf88fc6d860 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 16 Aug 2019 03:01:25 +0000 Subject: [PATCH 05/13] Add delete method to WarrantyController. #250 --- .../api-bundle/Command/TestAPICommand.php | 4 ++++ config/api_acl.yaml | 2 ++ config/routes/capi.yaml | 6 ++++++ src/Controller/CAPI/WarrantyController.php | 19 ++++++++++++++++++- 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/catalyst/api-bundle/Command/TestAPICommand.php b/catalyst/api-bundle/Command/TestAPICommand.php index 8d6680f2..b70f3bdd 100644 --- a/catalyst/api-bundle/Command/TestAPICommand.php +++ b/catalyst/api-bundle/Command/TestAPICommand.php @@ -80,6 +80,10 @@ class TestAPICommand extends Command // plate warranty $api->get('/capi/plates/' . $plate_num . '/warranties'); + // warranty delete + $id = 86811; + $api->post('/capi/warranties/' . $id . '/delete'); + // battery $api->get('/capi/battery_brands'); $api->get('/capi/battery_sizes'); diff --git a/config/api_acl.yaml b/config/api_acl.yaml index d1138fbc..e7c24b9f 100644 --- a/config/api_acl.yaml +++ b/config/api_acl.yaml @@ -14,6 +14,8 @@ access_keys: label: Claim - id: warranty.cancel label: Cancel + - id: warranty.delete + label: Delete - id: batterybrand label: Battery Brand Access acls: diff --git a/config/routes/capi.yaml b/config/routes/capi.yaml index a8452122..c6dcb72d 100644 --- a/config/routes/capi.yaml +++ b/config/routes/capi.yaml @@ -90,6 +90,12 @@ capi_warranty_cancel: controller: App\Controller\CAPI\WarrantyController::cancel methods: [GET] +# delete warranty +capi_warranty_delete: + path: /capi/warranties/{id}/delete + controller: App\Controller\CAPI\WarrantyController::delete + methods: [POST] + # customer vehicle api diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index e5e367aa..9b4a5094 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -339,6 +339,23 @@ class WarrantyController extends APIController $em->flush(); return new APIResponse(true, 'Warranty cancelled successfully.'); - + } + + public function delete(EntityManagerInterface $em, $id) + { + $this->denyAccessUnlessGranted('warranty.delete', null, 'No access.'); + + // find warranty + $warr = $em->getRepository(Warranty::class)->find($id); + if ($warr == null) + { + return new APIResponse(false, 'No warranty found with that id.', null, 404); + } + + // delete the warranty + $em->remove($warr); + $em->flush(); + + return new APIResponse(true, 'Warranty deleted successfully.'); } } From f0841a0b739baa1000ad7605b3f3940c001f6a98 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 16 Aug 2019 06:45:15 +0000 Subject: [PATCH 06/13] Add the existing data from csv file to the report. #252 --- src/Controller/ReportController.php | 119 +++++++++++++++++----------- 1 file changed, 71 insertions(+), 48 deletions(-) diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index 0577595a..ee36a528 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -455,11 +455,18 @@ class ReportController extends Controller // csv output $csv_handle = fopen('php://output', 'w+'); fputcsv($csv_handle, [ + 'Size/Model', + 'SKU', + 'Serial Number', + 'Created Date', + 'Branch Name', + 'Branch Code', 'Customer ID', - 'Last Name', - 'First Name', + 'Customer Last Name', + 'Customer First Name', + 'Warranty Last Name', + 'Warranty First Name', 'Plate Number', - 'Serial', 'Warranty Create Date', 'Activation Status', 'Has Mobile App?', @@ -495,67 +502,83 @@ class ReportController extends Controller } // loop through the rows - $serial_numbers = []; $row_num = 0; + $results = []; while(($fields = fgetcsv($fh)) !== false) { + $has_warranty = false; if ($row_num <= 2) { $row_num++; continue; } - // get the serial numbers - $serial_numbers[] = trim($fields[2]); - } + // get the data + $serial = trim($fields[2]); - // get the warranty for serial - $warr_qb = $this->getDoctrine() - ->getRepository(Warranty::class) - ->createQueryBuilder('q'); - $warranty_query = $warr_qb->select('q') - ->where('q.serial IN(:serials)') - ->setParameter('serials', $serial_numbers, Connection::PARAM_STR_ARRAY); + // get the warranty for serial + $warr_qb = $this->getDoctrine() + ->getRepository(Warranty::class) + ->createQueryBuilder('q'); + $warranty_query = $warr_qb->select('q') + ->where('q.serial = :serial') + ->setParameter('serial', $serial); + $warranty = $warranty_query->getQuery()->getOneOrNullResult(); - $warr_results = $warranty_query->getQuery()->getResult(); - - // get the plate numbers - $results = []; - foreach ($warr_results as $warranty) - { - //error_log($warranty->getPlateNumber()); - // validate the plate number - $isValid = InvalidPlateNumber::isInvalid($warranty->getPlateNumber()); - if ($isValid) + if ($warranty != null) { - // 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) + $isValid = InvalidPlateNumber::isInvalid($warranty->getPlateNumber()); + if ($isValid) { - // 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) + // 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) { - 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"), - 'warr_activation_status' => ($warranty->isActivated() ? 'Active' : 'Inactive'), - 'has_mobile' => ($has_mobile ? 'Yes' : 'No'), - ]; - + // 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) + { + $has_mobile = true; + } + $has_warranty = true; + $results[] = [ + 'model_size' => trim($fields[0]), + 'sku' => trim($fields[1]), + 'serial' => $serial, + 'created_date' => trim($fields[3]), + 'branch_name' => trim($fields[4]), + 'branch_code' => trim($fields[5]), + 'cust_id' => $cv->getCustomer()->getID(), + 'cust_lastname' => $cv->getCustomer()->getLastName(), + 'cust_firstname' => $cv->getCustomer()->getFirstName(), + 'warr_lastname' => $warranty->getLastName(), + 'warr_firstname' => $warranty->getFirstName(), + 'plate_num' => $cv->getPlateNumber(), + 'warr_date_create' => $warranty->getDateCreate()->format("d M Y"), + 'warr_activation_status' => ($warranty->isActivated() ? 'Active' : 'Inactive'), + 'has_mobile' => ($has_mobile ? 'Yes' : 'No'), + ]; + } } } + + if ($has_warranty == false) + { + $results[] = [ + 'model_size' => trim($fields[0]), + 'sku' => trim($fields[1]), + 'serial' => $serial, + 'created_date' => trim($fields[3]), + 'branch_name' => trim($fields[4]), + 'branch_code' => trim($fields[5]), + ]; + } + + $row_num++; } return $results; From 24961b836fa4f1ff742f43515c8970cb4df6d0b3 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 16 Aug 2019 08:21:22 +0000 Subject: [PATCH 07/13] Remove owner's name from the Customer Battery Status Search. #253 --- src/Controller/WarrantySearchController.php | 2 -- templates/warranty-search/form.html.twig | 8 ++------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Controller/WarrantySearchController.php b/src/Controller/WarrantySearchController.php index f73d6267..17b3268f 100644 --- a/src/Controller/WarrantySearchController.php +++ b/src/Controller/WarrantySearchController.php @@ -34,7 +34,6 @@ class WarrantySearchController extends Controller $this->denyAccessUnlessGranted('warranty.search', null, 'No access.'); $serial = $req->query->get('battery_serial'); - $name = $req->query->get('owner_name'); $plate_num = $req->query->get('plate_num'); // find the warranty @@ -63,7 +62,6 @@ class WarrantySearchController extends Controller } $params['data'] = $res; $params['battery_serial'] = $serial; - $params['owner_name'] = $name; $params['plate_num'] = $plate_num; $params['mode'] = "results"; diff --git a/templates/warranty-search/form.html.twig b/templates/warranty-search/form.html.twig index e643d3a4..f0521cfb 100644 --- a/templates/warranty-search/form.html.twig +++ b/templates/warranty-search/form.html.twig @@ -35,19 +35,15 @@
-
+
-
- - -
From 832e88b61ce838e2733aab0ad6d1a1214592abff Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 19 Aug 2019 04:51:42 +0000 Subject: [PATCH 08/13] Add customer contact numbers from Customer and Mobile Session to the report. Add date when customer registered for the mobile application. #252 --- src/Controller/ReportController.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index ee36a528..37f6809a 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -464,12 +464,15 @@ class ReportController extends Controller 'Customer ID', 'Customer Last Name', 'Customer First Name', + 'Customer Mobile Number', 'Warranty Last Name', 'Warranty First Name', 'Plate Number', 'Warranty Create Date', 'Activation Status', 'Has Mobile App?', + 'Date Mobile App Downloaded', + 'Mobile Number Using Mobile App', ]); foreach ($data as $row) { @@ -539,10 +542,15 @@ class ReportController extends Controller // get mobile session of customer //error_log($cv->getCustomer()->getLastName() . ' ' . $cv->getCustomer()->getFirstName()); $has_mobile = false; + $mobile_date = ''; + $mobile_number = ''; $mobile_session = $em->getRepository(MobileSession::class)->findBy(['customer' => $cv->getCustomer()->getID()]); foreach ($mobile_session as $mobile) { + // get mobile data $has_mobile = true; + $mobile_date = $mobile->getDateGenerated()->format("d M Y"); + $mobile_number = $mobile->getPhoneNumber(); } $has_warranty = true; $results[] = [ @@ -555,13 +563,16 @@ class ReportController extends Controller 'cust_id' => $cv->getCustomer()->getID(), 'cust_lastname' => $cv->getCustomer()->getLastName(), 'cust_firstname' => $cv->getCustomer()->getFirstName(), + 'cust_mobile_number' => $cv->getCustomer()->getPhoneMobile(), 'warr_lastname' => $warranty->getLastName(), 'warr_firstname' => $warranty->getFirstName(), 'plate_num' => $cv->getPlateNumber(), 'warr_date_create' => $warranty->getDateCreate()->format("d M Y"), 'warr_activation_status' => ($warranty->isActivated() ? 'Active' : 'Inactive'), 'has_mobile' => ($has_mobile ? 'Yes' : 'No'), - ]; + 'date_mobile' => $mobile_date, + 'mobile_number' => $mobile_number, + ]; } } } From 33db797ca6bf3e59ca7df25e109df59367b85857 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 19 Aug 2019 05:17:06 +0000 Subject: [PATCH 09/13] Get the oldest mobile session of customer. #252 --- src/Controller/ReportController.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index 37f6809a..e6d4df0c 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -544,13 +544,14 @@ class ReportController extends Controller $has_mobile = false; $mobile_date = ''; $mobile_number = ''; - $mobile_session = $em->getRepository(MobileSession::class)->findBy(['customer' => $cv->getCustomer()->getID()]); - foreach ($mobile_session as $mobile) + $mobile_session = $em->getRepository(MobileSession::class) + ->findOneBy(['customer' => $cv->getCustomer()->getID()], ['date_generated' => 'ASC']); + if ($mobile_session != null) { // get mobile data $has_mobile = true; - $mobile_date = $mobile->getDateGenerated()->format("d M Y"); - $mobile_number = $mobile->getPhoneNumber(); + $mobile_date = $mobile_session->getDateGenerated()->format("d M Y"); + $mobile_number = $mobile_session->getPhoneNumber(); } $has_warranty = true; $results[] = [ From b4c8b837429314b5a1504a97f64cbdf0d15a4435 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 22 Aug 2019 06:47:33 +0000 Subject: [PATCH 10/13] Modify query for customer vehicle to get only one customer vehicle. #255 --- src/Controller/ReportController.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index e6d4df0c..4bbaf85b 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -510,7 +510,8 @@ class ReportController extends Controller while(($fields = fgetcsv($fh)) !== false) { $has_warranty = false; - if ($row_num <= 2) + //error_log($row_num . ' ' . trim($fields[2])); + if ($row_num < 1) { $row_num++; continue; @@ -535,8 +536,8 @@ class ReportController extends Controller { // 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) + $cv = $em->getRepository(CustomerVehicle::class)->findOneBy(['plate_number' => $warranty->getPlateNumber()]); + if ($cv != null) { // get customer info // get mobile session of customer From ce83ed689b52550144307d25b99d1e62ddef7bf8 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 22 Aug 2019 10:48:32 +0000 Subject: [PATCH 11/13] Redo the processing of the popapp csv file. #255 --- src/Controller/ReportController.php | 162 ++++++++++++++++------------ 1 file changed, 93 insertions(+), 69 deletions(-) diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index 4bbaf85b..b6a3ad6f 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -16,7 +16,9 @@ use App\Entity\MobileSession; use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\DBAL\Connection; +use Doctrine\Common\Collections\ArrayCollection; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\StreamedResponse; @@ -442,13 +444,13 @@ class ReportController extends Controller /** * @Menu(selected="outlet_list") */ - public function popappExportCSV(Request $req) + public function popappExportCSV(Request $req, EntityManagerInterface $em) { // retrieve temporary info for file $file = $req->files->get('csv_file'); // process the csv file - $data = $this->processPopappFile($file); + $data = $this->processPopappFile($file, $em); $resp = new StreamedResponse(); $resp->setCallback(function() use ($data) { @@ -492,7 +494,7 @@ class ReportController extends Controller } - protected function processPopappFile(UploadedFile $csv_file) + protected function processPopappFile(UploadedFile $csv_file, $em) { // attempt to open file try @@ -507,9 +509,10 @@ class ReportController extends Controller // loop through the rows $row_num = 0; $results = []; + + // TODO: first loop populate the result array while(($fields = fgetcsv($fh)) !== false) { - $has_warranty = false; //error_log($row_num . ' ' . trim($fields[2])); if ($row_num < 1) { @@ -517,81 +520,102 @@ class ReportController extends Controller continue; } - // get the data - $serial = trim($fields[2]); + // pre-populate the result array + $results[] = [ + 'model_size' => trim($fields[0]), + 'sku' => trim($fields[1]), + 'serial' => trim($fields[2]), + 'created_date' => trim($fields[3]), + 'branch_name' => trim($fields[4]), + 'branch_code' => trim($fields[5]), + 'cust_id' => '', + 'cust_lastname' => '', + 'cust_firstname' => '', + 'cust_mobile_number' => '', + 'warr_lastname' => '', + 'warr_firstname' => '', + 'plate_num' => '', + 'warr_date_create' => '', + 'warr_activation_status' => '', + 'has_mobile' => '', + 'date_mobile' => '', + 'mobile_number' => '', + ]; + } - // get the warranty for serial - $warr_qb = $this->getDoctrine() - ->getRepository(Warranty::class) - ->createQueryBuilder('q'); - $warranty_query = $warr_qb->select('q') + foreach($results as $key => $data) + { + //error_log($results[$key]['model_size']); + + // get the serial + $serial = $results[$key]['serial']; + + // if serial is empty, move to next element + if (!empty($serial)) + { + // get the warranty for serial + $warr_qb = $this->getDoctrine() + ->getRepository(Warranty::class) + ->createQueryBuilder('q'); + $warranty_query = $warr_qb->select('q') ->where('q.serial = :serial') ->setParameter('serial', $serial); - $warranty = $warranty_query->getQuery()->getOneOrNullResult(); + $warranty = $warranty_query->getQuery()->getOneOrNullResult(); - if ($warranty != null) - { - $isValid = InvalidPlateNumber::isInvalid($warranty->getPlateNumber()); - if ($isValid) + if ($warranty != null) { - // get customer vehicle using plate number - $em = $this->getDoctrine()->getManager(); - $cv = $em->getRepository(CustomerVehicle::class)->findOneBy(['plate_number' => $warranty->getPlateNumber()]); - if ($cv != null) + $isValid = InvalidPlateNumber::isInvalid($warranty->getPlateNumber()); + if ($isValid) { - // get customer info - // get mobile session of customer - //error_log($cv->getCustomer()->getLastName() . ' ' . $cv->getCustomer()->getFirstName()); - $has_mobile = false; - $mobile_date = ''; - $mobile_number = ''; - $mobile_session = $em->getRepository(MobileSession::class) - ->findOneBy(['customer' => $cv->getCustomer()->getID()], ['date_generated' => 'ASC']); - if ($mobile_session != null) + // get customer vehicles using plate number + $customer_vehicles = $em->getRepository(CustomerVehicle::class)->findBy(['plate_number' => $warranty->getPlateNumber()]); + + // check if customer vehicle is empty + if (count($customer_vehicles) != 0) { - // get mobile data - $has_mobile = true; - $mobile_date = $mobile_session->getDateGenerated()->format("d M Y"); - $mobile_number = $mobile_session->getPhoneNumber(); + $has_mobile = false; + $mobile_date = ''; + $mobile_number = ''; + + // get the first customer vehicle, store as best_cv until we find one with a mobile session + $best_cv = current($customer_vehicles); + + foreach($customer_vehicles as $cv) + { + // get mobile session of customer + //error_log($cv->getCustomer()->getLastName() . ' ' . $cv->getCustomer()->getFirstName()); + $mobile_session = $em->getRepository(MobileSession::class) + ->findOneBy(['customer' => $cv->getCustomer()->getID()], ['date_generated' => 'ASC']); + if ($mobile_session != null) + { + // get mobile data + $has_mobile = true; + $mobile_date = $mobile_session->getDateGenerated()->format("d M Y"); + $mobile_number = $mobile_session->getPhoneNumber(); + + // set best_cv to this customer vehicle with mobile session + $best_cv = $cv; + } + } + + // set the customer data in results + $results[$key]['cust_id'] = $best_cv->getCustomer()->getID(); + $results[$key]['cust_lastname'] = $best_cv->getCustomer()->getLastName(); + $results[$key]['cust_firstname'] = $best_cv->getCustomer()->getFirstName(); + $results[$key]['cust_mobile_number'] = $best_cv->getCustomer()->getPhoneMobile(); + $results[$key]['plate_num'] = $best_cv->getPlateNumber(); + $results[$key]['has_mobile'] = ($has_mobile ? 'Yes' : 'No'); + $results[$key]['date_mobile'] = $mobile_date; + $results[$key]['mobile_number'] = $mobile_number; } - $has_warranty = true; - $results[] = [ - 'model_size' => trim($fields[0]), - 'sku' => trim($fields[1]), - 'serial' => $serial, - 'created_date' => trim($fields[3]), - 'branch_name' => trim($fields[4]), - 'branch_code' => trim($fields[5]), - 'cust_id' => $cv->getCustomer()->getID(), - 'cust_lastname' => $cv->getCustomer()->getLastName(), - 'cust_firstname' => $cv->getCustomer()->getFirstName(), - 'cust_mobile_number' => $cv->getCustomer()->getPhoneMobile(), - 'warr_lastname' => $warranty->getLastName(), - 'warr_firstname' => $warranty->getFirstName(), - 'plate_num' => $cv->getPlateNumber(), - 'warr_date_create' => $warranty->getDateCreate()->format("d M Y"), - 'warr_activation_status' => ($warranty->isActivated() ? 'Active' : 'Inactive'), - 'has_mobile' => ($has_mobile ? 'Yes' : 'No'), - 'date_mobile' => $mobile_date, - 'mobile_number' => $mobile_number, - ]; - } + } + // set the warranty data in results + $results[$key]['warr_lastname'] = $warranty->getLastName(); + $results[$key]['warr_firstname'] = $warranty->getFirstName(); + $results[$key]['warr_date_create'] = $warranty->getDateCreate()->format("d M Y"); + $results[$key]['warr_activation_status'] = ($warranty->isActivated() ? 'Active' : 'Inactive'); } } - - if ($has_warranty == false) - { - $results[] = [ - 'model_size' => trim($fields[0]), - 'sku' => trim($fields[1]), - 'serial' => $serial, - 'created_date' => trim($fields[3]), - 'branch_name' => trim($fields[4]), - 'branch_code' => trim($fields[5]), - ]; - } - - $row_num++; } return $results; From 1425d82e998b563d9947edb271b0b1b6c1fdbc4c Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 22 Aug 2019 10:58:59 +0000 Subject: [PATCH 12/13] Remove TODO line. Add parameter type for the entitymanager. #255 --- src/Controller/ReportController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index b6a3ad6f..0c1ea33a 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -494,7 +494,7 @@ class ReportController extends Controller } - protected function processPopappFile(UploadedFile $csv_file, $em) + protected function processPopappFile(UploadedFile $csv_file, EntityManagerInterface $em) { // attempt to open file try @@ -510,7 +510,6 @@ class ReportController extends Controller $row_num = 0; $results = []; - // TODO: first loop populate the result array while(($fields = fgetcsv($fh)) !== false) { //error_log($row_num . ' ' . trim($fields[2])); From 1fdc574a9e9a9e21375eb9e114d6c99685ddab3d Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 27 Aug 2019 04:09:19 +0000 Subject: [PATCH 13/13] Remove the Please fill up two fields text from the warranty search template. #253 --- templates/warranty-search/form.html.twig | 5 ----- 1 file changed, 5 deletions(-) diff --git a/templates/warranty-search/form.html.twig b/templates/warranty-search/form.html.twig index f0521cfb..2e29b5de 100644 --- a/templates/warranty-search/form.html.twig +++ b/templates/warranty-search/form.html.twig @@ -35,11 +35,6 @@
-