diff --git a/config/routes/report.yaml b/config/routes/report.yaml index 25d637c6..40bba3f8 100644 --- a/config/routes/report.yaml +++ b/config/routes/report.yaml @@ -31,4 +31,9 @@ rep_battery_conflict_submit: 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..0e66687e 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -9,12 +9,16 @@ use App\Ramcar\JOStatus; use App\Entity\JORejection; use App\Entity\Battery; use App\Entity\JobOrder; +use App\Entity\Warranty; +use App\Entity\CustomerVehicle; 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 +403,77 @@ class ReportController extends Controller return $resp; } + + /** + * @Menu(selected="outlet_list") + */ + public function popappComparisonForm() + { + $this->denyAccessUnlessGranted('report.popapp.comparison', null, 'No access.'); + + return $this->render('report/popapp/form.html.twig'); + } + + public function popappComparisonSubmit(Request $req) + { + // retrieve temporary info for file + $file = $req->files->get('csv_file'); + + // process the csv file + $this->processPopappFile($file); + + // return response + return $this->json([ + 'success' => true, + ]); + } + + 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 + $qb = $this->getDoctrine() + ->getRepository(Warranty::class) + ->createQueryBuilder('q'); + $warranty_query = $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 = []; + foreach ($warr_results as $warranty) + { + $plate_numbers[] = $warranty->getPlateNumber(); + // what if plate number is 0000 or NONE? + } + + // search in customer vehicle using the plate numbers + + } } diff --git a/templates/report/popapp/form.html.twig b/templates/report/popapp/form.html.twig new file mode 100644 index 00000000..bc176c63 --- /dev/null +++ b/templates/report/popapp/form.html.twig @@ -0,0 +1,55 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

Popapp Comparison Report

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

+ Upload Popapp CSV File +

+
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %}