Merge branch '291-vehicle-battery-compatibility-report' into 'master'
Resolve "Vehicle Battery Compatibility Report" Closes #291 See merge request jankstudio/resq!335
This commit is contained in:
commit
0cbd100f27
5 changed files with 165 additions and 4 deletions
|
|
@ -298,6 +298,8 @@ access_keys:
|
|||
label: RESQ MEH Customer Report
|
||||
- id: report.warranty.class
|
||||
label: Warranty Class Report
|
||||
- id: report.vehicle.battery.compatibility
|
||||
label: Vehicle Battery Compatibility Report
|
||||
|
||||
- id: service
|
||||
label: Other Services
|
||||
|
|
|
|||
|
|
@ -57,3 +57,13 @@ rep_warranty_class_export_csv:
|
|||
path: /report/warranty_class_report
|
||||
controller: App\Controller\ReportController::warrantyClassExportCSV
|
||||
methods: [POST]
|
||||
|
||||
rep_vehicle_battery_compatibility_form:
|
||||
path: /report/vehicle_battery_compatibility_report
|
||||
controller: App\Controller\ReportController::vehicleBatteryCompatibilityForm
|
||||
methods: [GET]
|
||||
|
||||
rep_vehicle_battery_compatibility_export_csv:
|
||||
path: /report/vehicle_battery_compatibility_report
|
||||
controller: App\Controller\ReportController::vehicleBatteryCompatibilityExportCSV
|
||||
methods: [POST]
|
||||
|
|
|
|||
|
|
@ -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,55 @@ class ReportController extends Controller
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Menu(selected="outlet_list")
|
||||
*/
|
||||
public function vehicleBatteryCompatibilityForm()
|
||||
{
|
||||
$this->denyAccessUnlessGranted('report.vehicle.battery.compatibility', null, 'No access.');
|
||||
$params['mode'] = 'form';
|
||||
|
||||
return $this->render('report/vehicle-battery-compatibility/form.html.twig', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Menu(selected="outlet_list")
|
||||
*/
|
||||
public function vehicleBatteryCompatibilityExportCSV(Request $req, EntityManagerInterface $em)
|
||||
{
|
||||
$data = $this->getVehicleBatteryCompatibilityData($em);
|
||||
|
||||
$resp = new StreamedResponse();
|
||||
$resp->setCallback(function() use ($data) {
|
||||
// csv output
|
||||
$csv_handle = fopen('php://output', 'w+');
|
||||
fputcsv($csv_handle, [
|
||||
'Vehicle Manufacturer',
|
||||
'Vehicle Make',
|
||||
'Vehicle Model Year From',
|
||||
'Vehicle Model Year To',
|
||||
'Battery Manufacturer',
|
||||
'Battery Model',
|
||||
'Battery Size',
|
||||
]);
|
||||
foreach ($data as $row)
|
||||
{
|
||||
fputcsv($csv_handle, $row);
|
||||
}
|
||||
|
||||
fclose($csv_handle);
|
||||
});
|
||||
|
||||
$filename = 'vehicle_battery_compatibility_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 +963,46 @@ class ReportController extends Controller
|
|||
return $data;
|
||||
|
||||
}
|
||||
|
||||
protected function getVehicleBatteryCompatibilityData(EntityManagerInterface $em)
|
||||
{
|
||||
$results = [];
|
||||
|
||||
$conn = $em->getConnection();
|
||||
$sql = 'SELECT vm.name AS vm_name, v.make,
|
||||
v.model_year_from, v.model_year_to,
|
||||
bm.name AS bm_name, bmodel.name AS bmodel_name,
|
||||
bsize.name AS bsize_name
|
||||
FROM vehicle_manufacturer vm, vehicle v, battery_vehicle bv,
|
||||
battery b, battery_manufacturer bm, battery_model bmodel,
|
||||
battery_size bsize
|
||||
WHERE vm.id = v.manufacturer_id
|
||||
AND v.id = bv.vehicle_id
|
||||
AND bv.battery_id = b.id
|
||||
AND b.manufacturer_id = bm.id
|
||||
AND b.model_id = bmodel.id
|
||||
AND b.size_id = bsize.id
|
||||
ORDER BY vm.name, v.make';
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
$query_results = $stmt->fetchAll();
|
||||
|
||||
foreach($query_results as $row)
|
||||
{
|
||||
$results[] = [
|
||||
'vehicle_manufacturer' => $row['vm_name'],
|
||||
'vehicle_make' => $row['make'],
|
||||
'vehicle_model_year_from' => $row['model_year_from'],
|
||||
'vehicle_model_year_to' => $row['model_year_to'],
|
||||
'battery_manufacturer' => $row['bm_name'],
|
||||
'battery_model' => $row['bmodel_name'],
|
||||
'battery_size' => $row['bsize_name'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -173,6 +173,15 @@
|
|||
Warranty Class Report
|
||||
</span>
|
||||
</a>
|
||||
<a href="{{ url('rep_vehicle_battery_compatibility_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">
|
||||
Vehicle Battery Compatibility Report
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
|
|
|||
|
|
@ -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">
|
||||
Vehicle Battery Compatibility 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 Vehicle Battery Compatibility 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_vehicle_battery_compatibility_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