Add report for hub filter. #594

This commit is contained in:
Korina Cordero 2021-06-30 09:11:00 +00:00
parent 2aece1fb10
commit 8a1ead57e0
5 changed files with 188 additions and 0 deletions

View file

@ -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

View file

@ -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]

View file

@ -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

View file

@ -249,6 +249,14 @@
Customer Source Report
</span>
</a>
<a href="{{ url('rep_hub_filter_form') }}" class="m-menu__link">
<i class="m-menu__link-bullet m-menu__link-bullet--dot">
<span></span>
</i>
<span class="m-menu__link-text">
Hub Filter Report
</span>
</a>
</li>
</ul>
</li>

View file

@ -0,0 +1,82 @@
{% extends 'base.html.twig' %}
{% block body %}
<!-- BEGIN: Subheader -->
<div class="m-subheader">
<div class="d-flex align-items-center">
<div class="mr-auto">
<h3 class="m-subheader__title">Hub Filter Report</h3>
</div>
</div>
</div>
<!-- END: Subheader -->
<div class="m-content">
<!--Begin::Section-->
<div class="row">
<div class="col-xl-6">
<div class="m-portlet m-portlet--mobile">
<div class="m-portlet__head">
<div class="m-portlet__head-caption">
<div class="m-portlet__head-title">
<span class="m-portlet__head-icon">
<i class="fa fa-calendar"></i>
</span>
<h3 class="m-portlet__head-text">
Select a date range
</h3>
</div>
</div>
</div>
<form id="row-form" autocomplete="off" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ url('rep_hub_filter_submit') }}">
<div class="m-portlet__body">
<div class="form-group m-form__group row">
<div class="input-daterange input-group" id="date-range">
<input role="presentation" type="text" class="form-control m-input" name="date_start" placeholder="Start date" />
<div class="input-group-append">
<span class="input-group-text"><i class="la la-ellipsis-h"></i></span>
</div>
<input role="presentation" type="text" class="form-control" name="date_end" placeholder="End date" />
</div>
</div>
</div>
<div class="m-portlet__foot m-portlet__foot--fit">
<div class="m-form__actions m-form__actions--solid m-form__actions--right">
<div class="row">
<div class="col-lg-12">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
$(function() {
$("#date-range").datepicker({
orientation: "bottom"
});
$("#row-form").submit(function(e) {
var form = $(this);
if (!$("[name='date_start']").val() || !$("[name='date_end']").val()) {
e.preventDefault();
swal({
title: 'Whoops!',
text: 'Please fill in both date fields.',
type: 'warning'
});
return false;
}
});
});
</script>
{% endblock %}