diff --git a/config/acl.yaml b/config/acl.yaml index b9b42afb..fb623290 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -344,6 +344,8 @@ access_keys: label: Advance Order Job Order Report - id: report.customer.source label: Customer Source Report + - id: report.hub.filter + label: Hub Filter Report - id: service label: Other Services diff --git a/config/routes/report.yaml b/config/routes/report.yaml index 02f12f41..bb9096b9 100644 --- a/config/routes/report.yaml +++ b/config/routes/report.yaml @@ -137,3 +137,13 @@ rep_customer_source_submit: path: /report/customer_source_report controller: App\Controller\ReportController::customerSourceSubmit methods: [POST] + +rep_hub_filter_form: + path: /report/hub_filter_report + controller: App\Controller\ReportController::hubFilterForm + methods: [GET] + +rep_hub_filter_submit: + path: /report/hub_filter_report + controller: App\Controller\ReportController::hubFilterSubmit + methods: [POST] diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index f259619a..14f60f3f 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -20,6 +20,7 @@ use App\Entity\Customer; use App\Entity\BatteryModel; use App\Entity\BatterySize; use App\Entity\SMSMessage; +use App\Entity\HubFilterLog; use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; @@ -1123,6 +1124,56 @@ class ReportController extends Controller return $resp; } + /** + * @Menu(selected="outlet_list") + */ + public function hubFilterForm() + { + $this->denyAccessUnlessGranted('report.hub.filter', null, 'No access.'); + + return $this->render('report/hub-filter/form.html.twig'); + } + + public function hubFilterSubmit(Request $req, EntityManagerInterface $em) + { + // get dates + $raw_date_start = $req->request->get('date_start'); + $raw_date_end = $req->request->get('date_end'); + + $date_start = DateTime::createFromFormat('m/d/Y', $raw_date_start); + $date_end = DateTime::createFromFormat('m/d/Y', $raw_date_end); + + $data = $this->getHubFilterData($req, $em, $raw_date_start, $raw_date_end); + + $resp = new StreamedResponse(); + $resp->setCallback(function() use ($data) { + // csv output + $csv_handle = fopen('php://output', 'w+'); + fputcsv($csv_handle, [ + 'Filtered Hub ID', + 'Hub Name', + 'Date Created', + 'Reason', + ]); + + foreach ($data as $row) + { + fputcsv($csv_handle, $row); + } + + fclose($csv_handle); + }); + + $filename = 'hub_filter_' . $date_start->format('Ymd') . '_' . $date_end->format('Ymd') . '.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 @@ -2261,6 +2312,41 @@ class ReportController extends Controller return $result; } + protected function getHubFilterData($req, $em, $raw_date_start, $raw_date_end) + { + $date_start = DateTime::createFromFormat('m/d/Y', $raw_date_start); + $date_end = DateTime::createFromFormat('m/d/Y', $raw_date_end); + + // change to this format: Y-m-d H:i:s + $new_date_start = $date_start->format('Y-m-d H:i:s'); + $new_date_end = $date_end->format('Y-m-d H:i:s'); + + // pdo connection. Table gets big very fast. + $db = $em->getConnection(); + + // get hub filter logs + $sql = 'SELECT hf.hub_filtered_id, h.name, hf.date_create, hf.filter_type_id FROM hub_filter_log hf, hub h WHERE hf.hub_filtered_id=h.id AND hf.date_create >= :date_start AND hf.date_create <= :date_end'; + $stmt = $db->prepare($sql); + $stmt->execute([ + 'date_start' => $new_date_start, + 'date_end' => $new_date_end, + ]); + + $result = []; + // go through rows + while ($row = $stmt->fetch(PDO::FETCH_NUM)) + { + $result[] = [ + $row[0], // filtered hub id + $row[1], // hub name + $row[2], // date create + $row[3], // reason + ]; + } + + return $result; + } + protected function getRESQCustomerIDs(EntityManagerInterface $em) { // pdo connection diff --git a/templates/base.html.twig b/templates/base.html.twig index 3316aa32..ab5dfb77 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -249,6 +249,14 @@ Customer Source Report + + + + + + diff --git a/templates/report/hub-filter/form.html.twig b/templates/report/hub-filter/form.html.twig new file mode 100644 index 00000000..c41e9712 --- /dev/null +++ b/templates/report/hub-filter/form.html.twig @@ -0,0 +1,82 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +