diff --git a/config/acl.yaml b/config/acl.yaml index 64b53ad1..f48850f6 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -292,6 +292,8 @@ access_keys: label: Battery Conflict Report - id: report.popapp.comparison label: Popapp Comparison Report + - id: report.meh.customer + label: RESQ MEH Customer Report - id: service label: Other Services diff --git a/config/routes/report.yaml b/config/routes/report.yaml index 274a1268..5d815490 100644 --- a/config/routes/report.yaml +++ b/config/routes/report.yaml @@ -37,3 +37,13 @@ rep_popapp_export_csv: path: /report/popapp_export controller: App\Controller\ReportController::popappExportCSV methods: [POST] + +rep_resq_meh_form: + path: /report/meh_customer + controller: App\Controller\ReportController::mehCustomerForm + methods: [GET] + +rep_resq_meh_export_csv: + path: /report/meh_customer_export + controller: App\Controller\ReportController::mehCustomerExportCSV + methods: [POST] diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index 0c1ea33a..72606601 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -13,6 +13,7 @@ use App\Entity\JobOrder; use App\Entity\Warranty; use App\Entity\CustomerVehicle; use App\Entity\MobileSession; +use App\Entity\Customer; use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; @@ -26,6 +27,7 @@ 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; +use Symfony\Component\Dotenv\Dotenv; use Catalyst\MenuBundle\Annotation\Menu; @@ -494,6 +496,55 @@ class ReportController extends Controller } + /** + * @Menu(selected="outlet_list") + */ + public function mehCustomerForm() + { + $this->denyAccessUnlessGranted('report.meh.customer', null, 'No access.'); + $params['mode'] = 'form'; + + return $this->render('report/meh/form.html.twig', $params); + } + + /** + * @Menu(selected="outlet_list") + */ + public function mehCustomerExportCSV(Request $req, EntityManagerInterface $em) + { + $data = $this->getMEHCustomerData($em); + + $resp = new StreamedResponse(); + $resp->setCallback(function() use ($data) { + // csv output + $csv_handle = fopen('php://output', 'w+'); + fputcsv($csv_handle, [ + 'Last Name', + 'First Name', + 'Mobile Number', + 'Landline Number', + 'Office Number', + 'Fax Number', + 'Date Mobile App Downloaded', + 'Mobile Number Using Mobile App', + ]); + foreach ($data as $row) + { + fputcsv($csv_handle, $row); + } + + fclose($csv_handle); + }); + + $filename = 'resq_meh_customer_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 @@ -620,4 +671,51 @@ class ReportController extends Controller return $results; } + protected function getMEHCustomerData(EntityManagerInterface $em) + { + $results = []; + + $conn = $em->getConnection(); + $sql = 'SELECT c.id, c.last_name, c.first_name, c.phone_mobile, c.phone_landline, + c.phone_office, c.phone_fax, jo.source FROM job_order jo, + customer_vehicle cv, customer c + WHERE c.id = cv.customer_id + AND jo.cvehicle_id = cv.id + AND c.policy_mobile_app_id IS NOT NULL + AND jo.source != :source'; + + $stmt = $conn->prepare($sql); + $stmt->execute(array('source' => 'mobile_app')); + + $query_results = $stmt->fetchAll(); + + foreach($query_results as $row) + { + $mobile_date = ''; + $mobile_number = ''; + + $mobile_session = $em->getRepository(MobileSession::class) + ->findOneBy(['customer' => $row['id']], ['date_generated' => 'ASC']); + if ($mobile_session != null) + { + $mobile_date = $mobile_session->getDateGenerated()->format("d M Y"); + $mobile_number = $mobile_session->getPhoneNumber(); + } + + $results[] = [ + 'last_name' => $row['last_name'], + 'first_name' => $row['first_name'], + 'cust_mobile_number' => $row['phone_mobile'], + 'landline_number' => $row['phone_landline'], + 'office_number' => $row['phone_office'], + 'fax_number' => $row['phone_fax'], + 'date_mobile' => $mobile_date, + 'mobile_number' => $mobile_number, + ]; + + } + + return $results; + + } } diff --git a/src/Entity/CustomerVehicle.php b/src/Entity/CustomerVehicle.php index 3af617ef..d73906fa 100644 --- a/src/Entity/CustomerVehicle.php +++ b/src/Entity/CustomerVehicle.php @@ -119,6 +119,8 @@ class CustomerVehicle public function __construct() { $this->flag_active = true; + + $this->job_orders = new ArrayCollection(); } public function getID() @@ -256,6 +258,11 @@ class CustomerVehicle return $this->curr_battery; } + public function getJobOrders() + { + return $this->job_orders; + } + public function setHasMotoliteBattery($flag_motolite_battery = true) { $this->flag_motolite_battery = $flag_motolite_battery; diff --git a/templates/base.html.twig b/templates/base.html.twig index 9052bb17..d1875e70 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -157,6 +157,14 @@ Popapp Comparison Report + + + + + + diff --git a/templates/report/meh/form.html.twig b/templates/report/meh/form.html.twig new file mode 100644 index 00000000..8cfd9570 --- /dev/null +++ b/templates/report/meh/form.html.twig @@ -0,0 +1,50 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +