Add warranty class report to yaml files, templates and ReportController. #283
This commit is contained in:
parent
50cb1d8617
commit
743bbf9c61
5 changed files with 185 additions and 0 deletions
|
|
@ -296,6 +296,8 @@ access_keys:
|
||||||
label: Popapp Comparison Report
|
label: Popapp Comparison Report
|
||||||
- id: report.meh.customer
|
- id: report.meh.customer
|
||||||
label: RESQ MEH Customer Report
|
label: RESQ MEH Customer Report
|
||||||
|
- id: report.warranty.class
|
||||||
|
label: Warranty Class Report
|
||||||
|
|
||||||
- id: service
|
- id: service
|
||||||
label: Other Services
|
label: Other Services
|
||||||
|
|
|
||||||
|
|
@ -47,3 +47,13 @@ rep_resq_meh_export_csv:
|
||||||
path: /report/meh_customer_export
|
path: /report/meh_customer_export
|
||||||
controller: App\Controller\ReportController::mehCustomerExportCSV
|
controller: App\Controller\ReportController::mehCustomerExportCSV
|
||||||
methods: [POST]
|
methods: [POST]
|
||||||
|
|
||||||
|
rep_warranty_class_form:
|
||||||
|
path: /report/warranty_class_report
|
||||||
|
controller: App\Controller\ReportController::warrantyClassForm
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
rep_warranty_class_export_csv:
|
||||||
|
path: /report/warranty_class_report
|
||||||
|
controller: App\Controller\ReportController::warrantyClassExportCSV
|
||||||
|
methods: [POST]
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,8 @@ use DateTime;
|
||||||
|
|
||||||
class ReportController extends Controller
|
class ReportController extends Controller
|
||||||
{
|
{
|
||||||
|
const PREREGISTER_PREFIX = '9';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Menu(selected="outlet_list")
|
* @Menu(selected="outlet_list")
|
||||||
*/
|
*/
|
||||||
|
|
@ -547,6 +549,70 @@ class ReportController extends Controller
|
||||||
return $resp;
|
return $resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Menu(selected="outlet_list")
|
||||||
|
*/
|
||||||
|
public function warrantyClassForm()
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('report.warranty.class', null, 'No access.');
|
||||||
|
$params['mode'] = 'form';
|
||||||
|
|
||||||
|
return $this->render('report/warranty-class/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Menu(selected="outlet_list")
|
||||||
|
*/
|
||||||
|
public function warrantyClassExportCSV(Request $req, EntityManagerInterface $em)
|
||||||
|
{
|
||||||
|
$data = $this->getWarrantyClassData($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',
|
||||||
|
'Vehicle Color',
|
||||||
|
'Warranty Serial',
|
||||||
|
'Warranty Class',
|
||||||
|
'Plate Number',
|
||||||
|
'Warranty Last Name',
|
||||||
|
'Warranty First Name',
|
||||||
|
'Warranty Mobile Number',
|
||||||
|
'Warranty Battery Model',
|
||||||
|
'Warranty Battery Size',
|
||||||
|
'Warranty SAP Battery',
|
||||||
|
'Warranty Status',
|
||||||
|
'Warranty Created',
|
||||||
|
'Warranty Purchased',
|
||||||
|
'Warranty Expiry Date',
|
||||||
|
'Warranty Claim Date',
|
||||||
|
'Warranty Claimed From',
|
||||||
|
'Is Warranty Activated?',
|
||||||
|
]);
|
||||||
|
foreach ($data as $row)
|
||||||
|
{
|
||||||
|
fputcsv($csv_handle, $row);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($csv_handle);
|
||||||
|
});
|
||||||
|
|
||||||
|
$filename = 'warranty_class_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)
|
protected function processPopappFile(UploadedFile $csv_file, EntityManagerInterface $em)
|
||||||
{
|
{
|
||||||
// attempt to open file
|
// attempt to open file
|
||||||
|
|
@ -723,6 +789,55 @@ class ReportController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getWarrantyClassData(EntityManagerInterface $em)
|
||||||
|
{
|
||||||
|
$results = [];
|
||||||
|
|
||||||
|
// query preregistered ustomers using search term '%9'
|
||||||
|
$cust_query = $em->createQuery('select c from App\Entity\Customer c where c.phone_mobile like :search_mobile')
|
||||||
|
->setParameter('search_mobile', "%" . self::PREREGISTER_PREFIX);
|
||||||
|
$customers = $cust_query->iterate();
|
||||||
|
|
||||||
|
foreach($customers as $crow)
|
||||||
|
{
|
||||||
|
$cust = $crow[0];
|
||||||
|
error_log('Processing customer ' . $cust->getID());
|
||||||
|
|
||||||
|
// get list of customer vehicles
|
||||||
|
$c_vehicles = $cust->getVehicles();
|
||||||
|
|
||||||
|
foreach($c_vehicles as $cv)
|
||||||
|
{
|
||||||
|
if (!empty($c_vehicles))
|
||||||
|
{
|
||||||
|
// find warranty for plate number
|
||||||
|
$clean_cv_plate = $this->cleanPlateNumber($cv->getPlateNumber());
|
||||||
|
|
||||||
|
// $warranties = $em->getRepository(Warranty::class)->findBy(['plate_number' => $clean_cv_plate]);
|
||||||
|
// TODO: test this query to see if this is faster
|
||||||
|
$warr_query = $em->createQuery('select w from App\Entity\Warranty w where w.plate_number = :plate_num')
|
||||||
|
->setParameter('plate_num', $clean_cv_plate);
|
||||||
|
$warranties = $warr_query->iterate();
|
||||||
|
|
||||||
|
foreach ($warranties as $wrow)
|
||||||
|
{
|
||||||
|
$warr = $wrow[0];
|
||||||
|
error_log('Found warranty for plate number ' . $warr->getPlateNumber());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function cleanPlateNumber($plate)
|
||||||
|
{
|
||||||
|
// remove spaces and make upper case
|
||||||
|
return strtoupper(str_replace(' ', '', $plate));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -165,6 +165,14 @@
|
||||||
RESQ MEH Customer Report
|
RESQ MEH Customer Report
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
|
<a href="{{ url('rep_warranty_class_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">
|
||||||
|
Warranty Class Report
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
||||||
50
templates/report/warranty-class/form.html.twig
Normal file
50
templates/report/warranty-class/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">
|
||||||
|
Warranty Class 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 Warranty Class 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_warranty_class_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