diff --git a/config/acl.yaml b/config/acl.yaml index a9c20c0d..ecccd5f5 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -300,6 +300,8 @@ access_keys: label: Warranty Class Report - id: report.vehicle.battery.compatibility label: Vehicle Battery Compatibility Report + - id: report.warranty.details + label: Warranty Details Report - id: service label: Other Services diff --git a/config/routes/report.yaml b/config/routes/report.yaml index 05c6781d..85ad83ee 100644 --- a/config/routes/report.yaml +++ b/config/routes/report.yaml @@ -67,3 +67,13 @@ rep_vehicle_battery_compatibility_export_csv: path: /report/vehicle_battery_compatibility_report controller: App\Controller\ReportController::vehicleBatteryCompatibilityExportCSV methods: [POST] + +rep_warranty_details_form: + path: /report/warranty_details_report + controller: App\Controller\ReportController::warrantyDetailsForm + methods: [GET] + +rep_warranty_details_export_csv: + path: /report/warranty_details_report + controller: App\Controller\ReportController::warrantyDetailsExportCSV + methods: [POST] diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index fc2bcb3a..2f72b3fa 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -14,6 +14,8 @@ use App\Entity\Warranty; use App\Entity\CustomerVehicle; use App\Entity\MobileSession; use App\Entity\Customer; +use App\Entity\BatteryModel; +use App\Entity\BatterySize; use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; @@ -659,6 +661,66 @@ class ReportController extends Controller $resp->headers->set('Content-Type', 'text/csv; charset=utf-8'); $resp->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"'); + return $resp; + } + + /** + * @Menu(selected="outlet_list") + */ + public function warrantyDetailsForm() + { + $this->denyAccessUnlessGranted('report.warranty.details', null, 'No access.'); + $params['mode'] = 'form'; + + return $this->render('report/warranty-details/form.html.twig', $params); + } + + /** + * @Menu(selected="outlet_list") + */ + public function warrantyDetailsExportCSV(Request $resq, EntityManagerInterface $em) + { + $data = $this->getWarrantyDetailsData($em); + + $resp = new StreamedResponse(); + $resp->setCallback(function() use ($data) { + // csv output + $csv_handle = fopen('php://output', 'w+'); + fputcsv($csv_handle, [ + 'Warranty ID', + 'Serial', + 'Battery Model', + 'Battery Size', + 'Warranty Class', + 'Plate Number', + 'Status', + 'Date Created', + 'Date Purchased', + 'Expiry Date', + 'Date Claimed', + 'SAP Battery ID', + 'Claim ID', + 'Last Name', + 'First Name', + 'Mobile Number', + 'Privacy Policy Number', + 'Activated?', + + ]); + foreach ($data as $row) + { + fputcsv($csv_handle, $row); + } + + fclose($csv_handle); + }); + + $filename = 'warranty_details_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; } @@ -1005,7 +1067,99 @@ class ReportController extends Controller ]; } + return $results; + } + + protected function getWarrantyDetailsData(EntityManagerInterface $em) + { + $bm_hash = $this->loadBatteryModels($em); + $bs_hash = $this->loadBatterySizes($em); + + $results = []; + + $conn = $em->getConnection(); + $sql = 'SELECT w.id, w.serial, w.warranty_class, w.plate_number, + w.status, w.date_create, w.date_purchase, w.date_expire, + w.date_claim, w.sap_bty_id, w.claim_id, w.first_name, + w.last_name, w.mobile_number, w.flag_activated, + w.warranty_privacy_policy, w.bty_model_id, w.bty_size_id + FROM warranty w'; + + $stmt = $conn->prepare($sql); + $stmt->execute(); + + $query_results = $stmt->fetchAll(); + + foreach ($query_results as $row) + { + // get battery model and size names + $bmodel_name = ''; + $bm_id = $row['bty_model_id']; + if (!empty($bm_id)) + { + if (isset($bm_hash[$bm_id])) + $bmodel_name = $bm_hash[$bm_id]; + } + + $bsize_name = ''; + $bs_id = $row['bty_size_id']; + if (!empty($bs_id)) + { + if (isset($bs_hash[$bs_id])) + $bsize_name = $bs_hash[$bs_id]; + } + + $results[] = [ + 'id' => $row['id'], + 'serial' => $row['serial'], + 'battery_model' => $bmodel_name, + 'battery_size' => $bsize_name, + 'warranty_class' => $row['warranty_class'], + 'plate_number' => $row['plate_number'], + 'status' => $row['status'], + 'date_create' => $row['date_create'], + 'date_purchase' => $row['date_purchase'], + 'date_expire' => $row['date_expire'], + 'date_claim' => $row['date_claim'], + 'sap_bty_id' => $row['sap_bty_id'], + 'claim_id' => $row['claim_id'], + 'last_name' => $row['last_name'], + 'first_name' => $row['first_name'], + 'mobile_number' => $row['mobile_number'], + 'privacy_policy' => $row['warranty_privacy_policy'], + 'flag_activated' => (boolean) $row['flag_activated'], + ]; + } return $results; } + + protected function loadBatteryModels(EntityManagerInterface $em) + { + $bmodel_hash = []; + + $models = $em->getRepository(BatteryModel::class)->findAll(); + foreach ($models as $model) + { + $bmodel_id = $model->getID(); + $bmodel_hash[$bmodel_id] = $model->getName(); + } + + return $bmodel_hash; + } + + protected function loadBatterySizes(EntityManagerInterface $em) + { + $bsize_hash = []; + + $sizes = $em->getRepository(BatterySize::class)->findAll(); + foreach ($sizes as $size) + { + $bsize_id = $size->getID(); + $bsize_hash[$bsize_id] = $size->getName(); + } + + return $bsize_hash; + } + } diff --git a/templates/base.html.twig b/templates/base.html.twig index cf350525..251d8f55 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -181,7 +181,14 @@ Vehicle Battery Compatibility Report - + + + + + + Warranty Details Report + + diff --git a/templates/report/warranty-details/form.html.twig b/templates/report/warranty-details/form.html.twig new file mode 100644 index 00000000..c329785a --- /dev/null +++ b/templates/report/warranty-details/form.html.twig @@ -0,0 +1,50 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ Warranty Details Report +

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

+ Generate Warranty Details CSV File +

+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+{% endblock %} +