Merge branch '197-report-to-track-battery-compatibility-conflict' into 'master'
Resolve "Report to track battery compatibility conflict" Closes #197 See merge request jankstudio/resq!231
This commit is contained in:
commit
62f97a00a4
5 changed files with 242 additions and 0 deletions
|
|
@ -248,3 +248,5 @@ access_keys:
|
|||
label: Menu
|
||||
- id: report.reject
|
||||
label: Rejection Report
|
||||
- id: report.battery.conflict
|
||||
label: Battery Conflict Report
|
||||
|
|
|
|||
|
|
@ -17,3 +17,13 @@ rep_reject_detail_submit:
|
|||
path: /report/rejection_detail
|
||||
controller: App\Controller\ReportController::rejectDetailSubmit
|
||||
methods: [POST]
|
||||
|
||||
rep_battery_conflict_form:
|
||||
path: /report/battery_conflict
|
||||
controller: App\Controller\ReportController::batteryConflictForm
|
||||
methods: [GET]
|
||||
|
||||
rep_battery_conflict_submit:
|
||||
path: /report/battery_conflict
|
||||
controller: App\Controller\ReportController::batteryConflictSubmit
|
||||
methods: [POST]
|
||||
|
|
|
|||
|
|
@ -5,8 +5,11 @@ namespace App\Controller;
|
|||
use App\Ramcar\BaseController;
|
||||
use App\Ramcar\JORejectionReason;
|
||||
use App\Ramcar\ServiceType;
|
||||
use App\Ramcar\JOStatus;
|
||||
|
||||
use App\Entity\JORejection;
|
||||
use App\Entity\Battery;
|
||||
use App\Entity\JobOrder;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
|
|
@ -260,4 +263,139 @@ class ReportController extends BaseController
|
|||
]);
|
||||
*/
|
||||
}
|
||||
|
||||
public function batteryConflictForm()
|
||||
{
|
||||
$this->denyAccessUnlessGranted('report.battery.conflict', null, 'No access.');
|
||||
|
||||
$params = $this->initParameters('outlet_list');
|
||||
|
||||
return $this->render('report/battery/batt_conflict_form.html.twig', $params);
|
||||
}
|
||||
|
||||
public function batteryConflictSubmit(Request $req)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('report.battery.conflict', null, 'No access.');
|
||||
|
||||
// get job order query builder
|
||||
$job_qb = $this->getDoctrine()
|
||||
->getRepository(JobOrder::class)
|
||||
->createQueryBuilder('jo');
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
// 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);
|
||||
|
||||
// build query for job order
|
||||
$jo_query = $job_qb->where('jo.date_create >= :start')
|
||||
->andWhere('jo.date_create <= :end')
|
||||
->andWhere('jo.status != :status')
|
||||
->setParameter('start', $date_start->format('Y-m-d') . ' 00:00:00')
|
||||
->setParameter('end', $date_end->format('Y-m-d') . ' 23:59:59')
|
||||
->setParameter('status', JOStatus::CANCELLED)
|
||||
->getQuery();
|
||||
|
||||
|
||||
// run queries
|
||||
$jos = $jo_query->getResult();
|
||||
|
||||
$batteries = $em->getRepository(Battery::class)->findAll();
|
||||
|
||||
// create compatibility matrix for battery and vehicle
|
||||
$comp_matrix = [];
|
||||
foreach ($batteries as $batt)
|
||||
{
|
||||
$vehicles = $batt->getVehicles();
|
||||
foreach ($vehicles as $vehicle)
|
||||
{
|
||||
$comp_matrix[$batt->getID()][$vehicle->getID()] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// go through the job orders to find the conflicts
|
||||
$results = [];
|
||||
foreach ($jos as $jo)
|
||||
{
|
||||
$invoice_items = $jo->getInvoice()->getItems();
|
||||
foreach ($invoice_items as $item)
|
||||
{
|
||||
// check if the item is a battery
|
||||
if ($item->getBattery() != null)
|
||||
{
|
||||
$batt_id = $item->getBattery()->getID();
|
||||
$vehicle_id = $jo->getCustomerVehicle()->getVehicle()->getID();
|
||||
if (isset($comp_matrix[$batt_id][$vehicle_id]) && $comp_matrix[$batt_id][$vehicle_id])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// get the compatible batteries for the customer vehicle
|
||||
$batteries = [];
|
||||
foreach($jo->getCustomerVehicle()->getVehicle()->getBatteries() as $comp_batt)
|
||||
{
|
||||
//$batteries[] = [
|
||||
// 'mfg_name' => $comp_batt->getManufacturer()->getName(),
|
||||
// 'model_name' => $comp_batt->getModel()->getName(),
|
||||
// 'size_name' => $comp_batt->getSize()->getName(),
|
||||
//];
|
||||
$batteries[] = $comp_batt->getManufacturer()->getName() . ' ' .
|
||||
$comp_batt->getModel()->getName() . ' ' .
|
||||
$comp_batt->getSize()->getName();
|
||||
}
|
||||
|
||||
$results[] = [
|
||||
'jo_id' => $jo->getID(),
|
||||
'jo_date_create' => $jo->getDateCreate()->format('m/d/Y H:i'),
|
||||
'cus_vehicle_manufacturer' => $jo->getCustomerVehicle()->getVehicle()->getManufacturer()->getName(),
|
||||
'cus_vehicle_make' => $jo->getCustomerVehicle()->getVehicle()->getMake(),
|
||||
'cus_vehicle_model' => $jo->getCustomerVehicle()->getModelYear(),
|
||||
'battery_model_ordered' => $item->getBattery()->getModel()->getName(),
|
||||
'battery_size_ordered' => $item->getBattery()->getSize()->getName(),
|
||||
'compatible_batt' => implode(', ', $batteries),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$resp = new StreamedResponse();
|
||||
$resp->setCallback(function() use ($results) {
|
||||
// csv output
|
||||
$csv_handle = fopen('php://output', 'w+');
|
||||
fputcsv($csv_handle, [
|
||||
'Order #',
|
||||
'Order Date and Time',
|
||||
'Manufacturer',
|
||||
'Make',
|
||||
'Year',
|
||||
'Battery Model',
|
||||
'Battery Size',
|
||||
'Compatible Batteries'
|
||||
]);
|
||||
foreach ($results as $row)
|
||||
{
|
||||
fputcsv($csv_handle, $row);
|
||||
}
|
||||
|
||||
fclose($csv_handle);
|
||||
});
|
||||
|
||||
$filename = 'battery_conflict_' . $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;
|
||||
|
||||
//return $this->json([
|
||||
// 'result' => $results,
|
||||
//]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,6 +128,16 @@
|
|||
</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="m-menu__item " data-redirect="true" aria-haspopup="true">
|
||||
<a href= "{{ url('rep_battery_conflict_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">
|
||||
Battery Conflict Report
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<!--
|
||||
|
|
|
|||
82
templates/report/battery/batt_conflict_form.html.twig
Normal file
82
templates/report/battery/batt_conflict_form.html.twig
Normal 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">Battery Conflict 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_battery_conflict_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 %}
|
||||
Loading…
Reference in a new issue