Display customer and warranty information for serials from the uploaded CSV file. #248
This commit is contained in:
parent
10d9800bda
commit
99f0a9cf44
2 changed files with 113 additions and 17 deletions
|
|
@ -5,12 +5,14 @@ namespace App\Controller;
|
|||
use App\Ramcar\JORejectionReason;
|
||||
use App\Ramcar\ServiceType;
|
||||
use App\Ramcar\JOStatus;
|
||||
use App\Ramcar\InvalidPlateNumber;
|
||||
|
||||
use App\Entity\JORejection;
|
||||
use App\Entity\Battery;
|
||||
use App\Entity\JobOrder;
|
||||
use App\Entity\Warranty;
|
||||
use App\Entity\CustomerVehicle;
|
||||
use App\Entity\MobileSession;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
|
|
@ -410,22 +412,31 @@ class ReportController extends Controller
|
|||
public function popappComparisonForm()
|
||||
{
|
||||
$this->denyAccessUnlessGranted('report.popapp.comparison', null, 'No access.');
|
||||
$params['mode'] = 'form';
|
||||
|
||||
return $this->render('report/popapp/form.html.twig');
|
||||
return $this->render('report/popapp/form.html.twig', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Menu(selected="outlet_list")
|
||||
*/
|
||||
public function popappComparisonSubmit(Request $req)
|
||||
{
|
||||
// retrieve temporary info for file
|
||||
$file = $req->files->get('csv_file');
|
||||
|
||||
// process the csv file
|
||||
$this->processPopappFile($file);
|
||||
$data = $this->processPopappFile($file);
|
||||
|
||||
// return response
|
||||
return $this->json([
|
||||
'success' => true,
|
||||
]);
|
||||
//return $this->json([
|
||||
// 'success' => true,
|
||||
// 'data' => $data,
|
||||
//]);
|
||||
$params['mode'] = 'results';
|
||||
$params['data'] = $data;
|
||||
|
||||
return $this->render('report/popapp/form.html.twig', $params);
|
||||
}
|
||||
|
||||
protected function processPopappFile(UploadedFile $csv_file)
|
||||
|
|
@ -456,24 +467,53 @@ class ReportController extends Controller
|
|||
}
|
||||
|
||||
// get the warranty for serial
|
||||
$qb = $this->getDoctrine()
|
||||
$warr_qb = $this->getDoctrine()
|
||||
->getRepository(Warranty::class)
|
||||
->createQueryBuilder('q');
|
||||
$warranty_query = $qb->select('q')
|
||||
$warranty_query = $warr_qb->select('q')
|
||||
->where('q.serial IN(:serials)')
|
||||
->setParameter('serials', $serial_numbers, Connection::PARAM_STR_ARRAY);
|
||||
|
||||
$warr_results = $warranty_query->getQuery()->getResult();
|
||||
|
||||
// get the plate numbers
|
||||
$plate_numbers = [];
|
||||
$results = [];
|
||||
foreach ($warr_results as $warranty)
|
||||
{
|
||||
$plate_numbers[] = $warranty->getPlateNumber();
|
||||
// what if plate number is 0000 or NONE?
|
||||
//error_log($warranty->getPlateNumber());
|
||||
// validate the plate number
|
||||
$isValid = InvalidPlateNumber::isInvalid($warranty->getPlateNumber());
|
||||
if ($isValid)
|
||||
{
|
||||
// get customer vehicle using plate number
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$cust_vehicles = $em->getRepository(CustomerVehicle::class)->findBy(['plate_number' => $warranty->getPlateNumber()]);
|
||||
foreach ($cust_vehicles as $cv)
|
||||
{
|
||||
// get customer info
|
||||
// get mobile session of customer
|
||||
//error_log($cv->getCustomer()->getLastName() . ' ' . $cv->getCustomer()->getFirstName());
|
||||
$has_mobile = false;
|
||||
$mobile_session = $em->getRepository(MobileSession::class)->findBy(['customer' => $cv->getCustomer()->getID()]);
|
||||
foreach ($mobile_session as $mobile)
|
||||
{
|
||||
error_log($mobile->getID());
|
||||
$has_mobile = true;
|
||||
}
|
||||
$results[] = [
|
||||
'cust_id' => $cv->getCustomer()->getID(),
|
||||
'cust_lastname' => $cv->getCustomer()->getLastName(),
|
||||
'cust_firstname' => $cv->getCustomer()->getFirstName(),
|
||||
'plate_num' => $cv->getPlateNumber(),
|
||||
'serial' => $warranty->getSerial(),
|
||||
'warr_date_create' => $warranty->getDateCreate()->format("d M Y"),
|
||||
'has_mobile' => $has_mobile,
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// search in customer vehicle using the plate numbers
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@
|
|||
<div class="m-subheader">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="mr-auto">
|
||||
<h3 class="m-subheader__title">Popapp Comparison Report</h3>
|
||||
<h3 class="m-subheader__title">
|
||||
Popapp Comparison Report
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -46,10 +48,64 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% if mode == 'results' %}
|
||||
<!-- report details -->
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="m-portlet m-portlet--mobile">
|
||||
<div class="m-portlet__head">
|
||||
<div class="m-portlet__head-caption">
|
||||
<div class="m-portlet__head-title">
|
||||
<h3 class="m-portlet__head-text">
|
||||
Report Details
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-portlet__body">
|
||||
{% if data is empty %}
|
||||
<div class="m-alert m-alert--icon m-alert--icon-solid m-alert--outline alert alert-brand" role="alert">
|
||||
<div class="m-alert__icon">
|
||||
<i class="flaticon-exclamation-2"></i>
|
||||
<span></span>
|
||||
</div>
|
||||
<div class="m-alert__text">
|
||||
No records found.
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<table class="table table-striped m-table">
|
||||
<thead>
|
||||
<tr class="m-table__row--brand">
|
||||
<th>Customer ID</th>
|
||||
<th>Last Name</th>
|
||||
<th>First Name</th>
|
||||
<th>Plate Number</th>
|
||||
<th>Serial</th>
|
||||
<th>Warranty Create Date</th>
|
||||
<th>Has Mobile? </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for key, result in data %}
|
||||
<tr>
|
||||
<td>{{ result.cust_id|default("") }}</td>
|
||||
<td>{{ result.cust_lastname|default('') }}</td>
|
||||
<td>{{ result.cust_firstname|default('') }}</td>
|
||||
<td>{{ result.plate_num|default('') }}</td>
|
||||
<td>{{ result.serial|default('') }}</td>
|
||||
<td>{{ result.warr_date_create|default('') }}</td>
|
||||
<td>{{ result.has_mobile ? Yes : 'No' }} </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
|||
Loading…
Reference in a new issue