diff --git a/config/acl.yaml b/config/acl.yaml index 9de80027..64b53ad1 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -290,6 +290,8 @@ access_keys: label: Rejection Report - id: report.battery.conflict label: Battery Conflict Report + - id: report.popapp.comparison + label: Popapp Comparison Report - id: service label: Other Services diff --git a/config/routes/report.yaml b/config/routes/report.yaml index c8560798..40bba3f8 100644 --- a/config/routes/report.yaml +++ b/config/routes/report.yaml @@ -27,3 +27,13 @@ rep_battery_conflict_submit: path: /report/battery_conflict controller: App\Controller\ReportController::batteryConflictSubmit methods: [POST] + +rep_popapp_comp_form: + path: /report/popapp_comparison + controller: App\Controller\ReportController::popappComparisonForm + methods: [GET] + +rep_popapp_comp_submit: + path: /report/popapp_comparison + controller: App\Controller\ReportController::popappComparisonSubmit + methods: [POST] diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index b12c1a34..c92b071b 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -5,16 +5,22 @@ 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; +use Doctrine\DBAL\Connection; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\StreamedResponse; +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; @@ -399,4 +405,116 @@ class ReportController extends Controller return $resp; } + + /** + * @Menu(selected="outlet_list") + */ + public function popappComparisonForm() + { + $this->denyAccessUnlessGranted('report.popapp.comparison', null, 'No access.'); + $params['mode'] = 'form'; + + 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 + $data = $this->processPopappFile($file); + + // return response + //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) + { + // attempt to open file + try + { + $fh = fopen($csv_file, "r"); + } + catch (Exception $e) + { + throw new Exception('The file "' . $csv_file . '" could be read.'); + } + + // loop through the rows + $serial_numbers = []; + $row_num = 0; + while(($fields = fgetcsv($fh)) !== false) + { + if ($row_num <= 2) + { + $row_num++; + continue; + } + + // get the serial numbers + $serial_numbers[] = 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); + + $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) + { + // 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, + 'warr_activation_status' => $warranty->isActivated(), + ]; + + } + } + } + + return $results; + } } diff --git a/src/Ramcar/InvalidPlateNumber.php b/src/Ramcar/InvalidPlateNumber.php new file mode 100644 index 00000000..43f3a736 --- /dev/null +++ b/src/Ramcar/InvalidPlateNumber.php @@ -0,0 +1,20 @@ + +
| Customer ID | +Last Name | +First Name | +Plate Number | +Serial | +Warranty Create Date | +Activation Status | +Has Mobile App? | +
|---|---|---|---|---|---|---|---|
| {{ 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.warr_activation_status ? 'Active' : 'Inactive' }} | +{{ result.has_mobile ? 'Yes' : 'No' }} | +