Merge branch '248-generate-popapp-report' into 'master'
Resolve "Generate popapp report" Closes #248 See merge request jankstudio/resq!293
This commit is contained in:
commit
74e1e329a7
6 changed files with 283 additions and 0 deletions
|
|
@ -290,6 +290,8 @@ access_keys:
|
||||||
label: Rejection Report
|
label: Rejection Report
|
||||||
- id: report.battery.conflict
|
- id: report.battery.conflict
|
||||||
label: Battery Conflict Report
|
label: Battery Conflict Report
|
||||||
|
- id: report.popapp.comparison
|
||||||
|
label: Popapp Comparison Report
|
||||||
|
|
||||||
- id: service
|
- id: service
|
||||||
label: Other Services
|
label: Other Services
|
||||||
|
|
|
||||||
|
|
@ -27,3 +27,13 @@ rep_battery_conflict_submit:
|
||||||
path: /report/battery_conflict
|
path: /report/battery_conflict
|
||||||
controller: App\Controller\ReportController::batteryConflictSubmit
|
controller: App\Controller\ReportController::batteryConflictSubmit
|
||||||
methods: [POST]
|
methods: [POST]
|
||||||
|
|
||||||
|
rep_popapp_comp_form:
|
||||||
|
path: /report/popapp_comparison
|
||||||
|
controller: App\Controller\ReportController::popappComparisonForm
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
rep_popapp_comp_submit:
|
||||||
|
path: /report/popapp_comparison
|
||||||
|
controller: App\Controller\ReportController::popappComparisonSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,22 @@ namespace App\Controller;
|
||||||
use App\Ramcar\JORejectionReason;
|
use App\Ramcar\JORejectionReason;
|
||||||
use App\Ramcar\ServiceType;
|
use App\Ramcar\ServiceType;
|
||||||
use App\Ramcar\JOStatus;
|
use App\Ramcar\JOStatus;
|
||||||
|
use App\Ramcar\InvalidPlateNumber;
|
||||||
|
|
||||||
use App\Entity\JORejection;
|
use App\Entity\JORejection;
|
||||||
use App\Entity\Battery;
|
use App\Entity\Battery;
|
||||||
use App\Entity\JobOrder;
|
use App\Entity\JobOrder;
|
||||||
|
use App\Entity\Warranty;
|
||||||
|
use App\Entity\CustomerVehicle;
|
||||||
|
use App\Entity\MobileSession;
|
||||||
|
|
||||||
use Doctrine\ORM\Query;
|
use Doctrine\ORM\Query;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
use Doctrine\DBAL\Connection;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||||
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
|
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
|
||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
|
|
@ -399,4 +405,116 @@ class ReportController extends Controller
|
||||||
|
|
||||||
return $resp;
|
return $resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Menu(selected="outlet_list")
|
||||||
|
*/
|
||||||
|
public function popappComparisonForm()
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('report.popapp.comparison', null, 'No access.');
|
||||||
|
$params['mode'] = 'form';
|
||||||
|
|
||||||
|
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
|
||||||
|
$data = $this->processPopappFile($file);
|
||||||
|
|
||||||
|
// return response
|
||||||
|
//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)
|
||||||
|
{
|
||||||
|
// attempt to open file
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$fh = fopen($csv_file, "r");
|
||||||
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
throw new Exception('The file "' . $csv_file . '" could be read.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// loop through the rows
|
||||||
|
$serial_numbers = [];
|
||||||
|
$row_num = 0;
|
||||||
|
while(($fields = fgetcsv($fh)) !== false)
|
||||||
|
{
|
||||||
|
if ($row_num <= 2)
|
||||||
|
{
|
||||||
|
$row_num++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the serial numbers
|
||||||
|
$serial_numbers[] = trim($fields[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the warranty for serial
|
||||||
|
$warr_qb = $this->getDoctrine()
|
||||||
|
->getRepository(Warranty::class)
|
||||||
|
->createQueryBuilder('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
|
||||||
|
$results = [];
|
||||||
|
foreach ($warr_results as $warranty)
|
||||||
|
{
|
||||||
|
//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,
|
||||||
|
'warr_activation_status' => $warranty->isActivated(),
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
20
src/Ramcar/InvalidPlateNumber.php
Normal file
20
src/Ramcar/InvalidPlateNumber.php
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Ramcar;
|
||||||
|
|
||||||
|
class InvalidPlateNumber
|
||||||
|
{
|
||||||
|
static public function isInvalid($plate_number)
|
||||||
|
{
|
||||||
|
$number = strtoupper($plate_number);
|
||||||
|
switch($number)
|
||||||
|
{
|
||||||
|
case 'NONE':
|
||||||
|
case '000000':
|
||||||
|
case '0000':
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -140,6 +140,26 @@
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="m-menu__item">
|
||||||
|
<h3 class="m-menu__heading m-menu__toggle">
|
||||||
|
<span class="m-menu__link-text">
|
||||||
|
Other Reports
|
||||||
|
</span>
|
||||||
|
<i class="m-menu__ver-arrow la la-angle-right"></i>
|
||||||
|
</h3>
|
||||||
|
<ul class="m-menu__inner">
|
||||||
|
<li class="m-menu__item " data-redirect="true" aria-haspopup="true">
|
||||||
|
<a href="{{ url('rep_popapp_comp_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">
|
||||||
|
Popapp Comparison Report
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
<!--
|
<!--
|
||||||
<li class="m-menu__item">
|
<li class="m-menu__item">
|
||||||
<h3 class="m-menu__heading m-menu__toggle">
|
<h3 class="m-menu__heading m-menu__toggle">
|
||||||
|
|
|
||||||
113
templates/report/popapp/form.html.twig
Normal file
113
templates/report/popapp/form.html.twig
Normal file
|
|
@ -0,0 +1,113 @@
|
||||||
|
{% 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">
|
||||||
|
Popapp Comparison 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">
|
||||||
|
Upload Popapp 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_popapp_comp_submit') }}" enctype="multipart/form-data">
|
||||||
|
<div class="m-portlet__body">
|
||||||
|
<div class="form-group m-form__group row">
|
||||||
|
<input type="file" id="csv_file" name="csv_file" >
|
||||||
|
</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>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</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>Activation Status</th>
|
||||||
|
<th>Has Mobile App? </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.warr_activation_status ? 'Active' : 'Inactive' }}</td>
|
||||||
|
<td>{{ result.has_mobile ? 'Yes' : 'No' }} </td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
Loading…
Reference in a new issue