Add call volume report. #294
This commit is contained in:
parent
e16e8a7c99
commit
3546268c88
2 changed files with 189 additions and 1 deletions
|
|
@ -27,7 +27,6 @@ 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;
|
||||
|
||||
|
|
@ -614,6 +613,57 @@ class ReportController extends Controller
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Menu(selected="outlet_list")
|
||||
*/
|
||||
public function callVolumeForm()
|
||||
{
|
||||
$this->denyAccessUnlessGranted('report.call.volume', null, 'No access.');
|
||||
$params['mode'] = 'form';
|
||||
|
||||
return $this->render('report/call-volume/form.html.twig', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Menu(selected="outlet_list")
|
||||
*/
|
||||
public function callVolumeExportCSV(Request $req, EntityManagerInterface $em)
|
||||
{
|
||||
$data = $this->getCallVolumeData($em);
|
||||
|
||||
$resp = new StreamedResponse();
|
||||
$resp->setCallback(function() use ($data) {
|
||||
// csv output
|
||||
$csv_handle = fopen('php://output', 'w+');
|
||||
fputcsv($csv_handle, [
|
||||
'Customer Last Name',
|
||||
'Customer First Name',
|
||||
'Vehicle Manufacturer',
|
||||
'Vehicle Make',
|
||||
'Model Year',
|
||||
'Plate Number',
|
||||
'Service Type',
|
||||
'Source',
|
||||
'Status',
|
||||
]);
|
||||
foreach ($data as $row)
|
||||
{
|
||||
fputcsv($csv_handle, $row);
|
||||
}
|
||||
|
||||
fclose($csv_handle);
|
||||
});
|
||||
|
||||
$filename = 'call_volume_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
|
||||
|
|
@ -915,4 +965,92 @@ class ReportController extends Controller
|
|||
return $data;
|
||||
|
||||
}
|
||||
|
||||
protected function getCallVolumeData(EntityManagerInterface $em)
|
||||
{
|
||||
$results = [];
|
||||
|
||||
// get job orders with source = 'call'
|
||||
//$jo_query = $em->createQuery('select jo from App\Entity\JobOrder jo where jo.source = :source_type')
|
||||
// ->setParameter('source_type', self::SOURCE_TYPE_CALL);
|
||||
//$jos = $jo_query->iterate();
|
||||
|
||||
$conn = $em->getConnection();
|
||||
$sql = 'SELECT c.last_name, c.first_name,
|
||||
jo.source, jo.service_type, jo.status,
|
||||
vmanu.name AS manufacturer_name, v.make,
|
||||
cv.model_year, cv.plate_number
|
||||
FROM job_order jo, customer c,
|
||||
customer_vehicle cv, vehicle v,
|
||||
vehicle_manufacturer vmanu
|
||||
WHERE c.id = cv.customer_id
|
||||
AND jo.cvehicle_id = cv.id
|
||||
AND cv.vehicle_id = v.id
|
||||
AND v.manufacturer_id = vmanu.id
|
||||
AND jo.source = :source';
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array('source' => 'call'));
|
||||
|
||||
$query_results = $stmt->fetchAll();
|
||||
|
||||
foreach($query_results as $row)
|
||||
{
|
||||
$results[] = [
|
||||
'cust_last_name' => $row['last_name'],
|
||||
'cust_first_name' => $row['first_name'],
|
||||
'cust_vehicle_manu' => $row['manufacturer_name'],
|
||||
'cust_vehicle_make' => $row['make'],
|
||||
'cust_vehicle_year' => $row['model_year'],
|
||||
'cust_plate_number' => $row['plate_number'],
|
||||
'service_type' => $row['service_type'],
|
||||
'source' => $row['source'],
|
||||
'status' => $row['status'],
|
||||
];
|
||||
/*
|
||||
$jo = $jorow[0];
|
||||
error_log('Processing job order ' . $jo->getID());
|
||||
|
||||
// get customer info
|
||||
$last_name = $jo->getCustomer()->getLastName();
|
||||
$first_name = $jo->getCustomer()->getFirstName();
|
||||
|
||||
// get customer vehicle info
|
||||
$cv_manufacturer = $jo->getCustomerVehicle()->getVehicle()->getManufacturer()->getName();
|
||||
$cv_make = $jo->getCustomerVehicle()->getVehicle()->getMake();
|
||||
$cv_model_year = $jo->getCustomerVehicle()->getModelYear();
|
||||
$cv_plate_number = $jo->getCustomerVehicle()->getPlateNumber();
|
||||
|
||||
// get job order info
|
||||
$service_type = $jo->getServiceType();
|
||||
$source = $jo->getSource();
|
||||
$status = $jo->getStatus();
|
||||
|
||||
// get hub name, if any
|
||||
$hub_name = '';
|
||||
$hub = $jo->getHub();
|
||||
if ($hub != null)
|
||||
{
|
||||
$hub_name = $jo->getHub()->getName();
|
||||
}
|
||||
|
||||
$results[] = [
|
||||
'cust_last_name' => $last_name,
|
||||
'cust_first_name' => $first_name,
|
||||
'cust_vehicle_manu' => $cv_manufacturer,
|
||||
'cust_vehicle_make' => $cv_make,
|
||||
'cust_vehicle_year' => $cv_model_year,
|
||||
'cust_plate_number' => $cv_plate_number,
|
||||
'service_type' => $service_type,
|
||||
'hub_name' => $hub_name,
|
||||
'source' => $source,
|
||||
'status' => $status,
|
||||
];
|
||||
|
||||
$em->clear();
|
||||
*/
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
50
templates/report/call-volume/form.html.twig
Normal file
50
templates/report/call-volume/form.html.twig
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
{% 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">
|
||||
Call Volume 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-upload"></i>
|
||||
</span>
|
||||
<h3 class="m-portlet__head-text">
|
||||
Generate Call Volume CSV File
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form id="upload_form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ url('rep_call_volume_export_csv') }}" enctype="multipart/form-data">
|
||||
<div class="m-portlet__body">
|
||||
<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">Export to CSV</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
Loading…
Reference in a new issue