diff --git a/config/acl.yaml b/config/acl.yaml index c6100978..1546a0d9 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -296,6 +296,8 @@ access_keys: label: Popapp Comparison Report - id: report.meh.customer label: RESQ MEH Customer Report + - id: report.warranty.class + label: Warranty Class Report - id: service label: Other Services diff --git a/config/routes/report.yaml b/config/routes/report.yaml index 5d815490..f847cfe5 100644 --- a/config/routes/report.yaml +++ b/config/routes/report.yaml @@ -47,3 +47,13 @@ rep_resq_meh_export_csv: path: /report/meh_customer_export controller: App\Controller\ReportController::mehCustomerExportCSV methods: [POST] + +rep_warranty_class_form: + path: /report/warranty_class_report + controller: App\Controller\ReportController::warrantyClassForm + methods: [GET] + +rep_warranty_class_export_csv: + path: /report/warranty_class_report + controller: App\Controller\ReportController::warrantyClassExportCSV + methods: [POST] diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index 60db4d9d..0e8a06e7 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -36,6 +36,8 @@ use DateTime; class ReportController extends Controller { + const PREREGISTER_PREFIX = '9'; + /** * @Menu(selected="outlet_list") */ @@ -547,6 +549,70 @@ class ReportController extends Controller return $resp; } + /** + * @Menu(selected="outlet_list") + */ + public function warrantyClassForm() + { + $this->denyAccessUnlessGranted('report.warranty.class', null, 'No access.'); + $params['mode'] = 'form'; + + return $this->render('report/warranty-class/form.html.twig', $params); + } + + /** + * @Menu(selected="outlet_list") + */ + public function warrantyClassExportCSV(Request $req, EntityManagerInterface $em) + { + $data = $this->getWarrantyClassData($em); + + $resp = new StreamedResponse(); + $resp->setCallback(function() use ($data) { + // csv output + $csv_handle = fopen('php://output', 'w+'); + fputcsv($csv_handle, [ + 'Customer Last Name', + 'Customer First Name', + 'Vehicle Manufacturer', + 'Vehicle Make', + 'Model Year', + 'Vehicle Color', + 'Warranty Serial', + 'Warranty Class', + 'Plate Number', + 'Warranty Last Name', + 'Warranty First Name', + 'Warranty Mobile Number', + 'Warranty Battery Model', + 'Warranty Battery Size', + 'Warranty SAP Battery', + 'Warranty Status', + 'Warranty Created', + 'Warranty Purchased', + 'Warranty Expiry Date', + 'Warranty Claim Date', + 'Warranty Claimed From', + 'Is Warranty Activated?', + ]); + foreach ($data as $row) + { + fputcsv($csv_handle, $row); + } + + fclose($csv_handle); + }); + + $filename = 'warranty_class_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 @@ -723,6 +789,55 @@ class ReportController extends Controller } return $results; + } + protected function getWarrantyClassData(EntityManagerInterface $em) + { + $results = []; + + // query preregistered ustomers using search term '%9' + $cust_query = $em->createQuery('select c from App\Entity\Customer c where c.phone_mobile like :search_mobile') + ->setParameter('search_mobile', "%" . self::PREREGISTER_PREFIX); + $customers = $cust_query->iterate(); + + foreach($customers as $crow) + { + $cust = $crow[0]; + error_log('Processing customer ' . $cust->getID()); + + // get list of customer vehicles + $c_vehicles = $cust->getVehicles(); + + foreach($c_vehicles as $cv) + { + if (!empty($c_vehicles)) + { + // find warranty for plate number + $clean_cv_plate = $this->cleanPlateNumber($cv->getPlateNumber()); + + // $warranties = $em->getRepository(Warranty::class)->findBy(['plate_number' => $clean_cv_plate]); + // TODO: test this query to see if this is faster + $warr_query = $em->createQuery('select w from App\Entity\Warranty w where w.plate_number = :plate_num') + ->setParameter('plate_num', $clean_cv_plate); + $warranties = $warr_query->iterate(); + + foreach ($warranties as $wrow) + { + $warr = $wrow[0]; + error_log('Found warranty for plate number ' . $warr->getPlateNumber()); + } + } + + } + + } + + return $results; + } + + protected function cleanPlateNumber($plate) + { + // remove spaces and make upper case + return strtoupper(str_replace(' ', '', $plate)); } } diff --git a/templates/base.html.twig b/templates/base.html.twig index 3ef5e050..c6f1b9d5 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -165,6 +165,14 @@ RESQ MEH Customer Report + + + + + + diff --git a/templates/report/warranty-class/form.html.twig b/templates/report/warranty-class/form.html.twig new file mode 100644 index 00000000..a2313b1d --- /dev/null +++ b/templates/report/warranty-class/form.html.twig @@ -0,0 +1,50 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +