843 lines
29 KiB
PHP
843 lines
29 KiB
PHP
<?php
|
|
|
|
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 App\Entity\Customer;
|
|
|
|
use Doctrine\ORM\Query;
|
|
use Doctrine\ORM\QueryBuilder;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Doctrine\DBAL\Connection;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
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;
|
|
|
|
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
|
use DateTime;
|
|
|
|
class ReportController extends Controller
|
|
{
|
|
const PREREGISTER_PREFIX = '9';
|
|
|
|
/**
|
|
* @Menu(selected="outlet_list")
|
|
*/
|
|
public function rejectSummaryForm()
|
|
{
|
|
$this->denyAccessUnlessGranted('report.reject', null, 'No access.');
|
|
|
|
return $this->render('report/rejection/summary_form.html.twig');
|
|
}
|
|
|
|
public function rejectSummarySubmit(Request $req)
|
|
{
|
|
$this->denyAccessUnlessGranted('report.reject', null, 'No access.');
|
|
|
|
// get query builder
|
|
$qb = $this->getDoctrine()
|
|
->getRepository(JORejection::class)
|
|
->createQueryBuilder('r');
|
|
|
|
// 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
|
|
$query = $qb->where('r.date_create >= :start')
|
|
->andWhere('r.date_create <= :end')
|
|
->setParameter('start', $date_start->format('Y-m-d') . ' 00:00:00')
|
|
->setParameter('end', $date_end->format('Y-m-d') . ' 23:59:59')
|
|
->getQuery();
|
|
|
|
|
|
// run query
|
|
$jors = $query->getResult();
|
|
|
|
// initialize counter
|
|
$counter = [];
|
|
|
|
// get results
|
|
$res = [];
|
|
foreach ($jors as $jor)
|
|
{
|
|
$jo = $jor->getJobOrder();
|
|
$hub = $jor->getHub();
|
|
$hub_id = $hub->getID();
|
|
$hub_name = $hub->getName() . ' - ' . $hub->getBranch();
|
|
|
|
$reason = $jor->getReason();
|
|
|
|
if (!isset($counter[$hub_id]))
|
|
$counter[$hub_id] = [
|
|
'reasons' => [],
|
|
'name' => $hub_name,
|
|
];
|
|
|
|
if (!isset($counter[$hub_id][$reason]))
|
|
{
|
|
$counter[$hub_id]['reasons'][$reason]['name'] = JORejectionReason::getName($reason);
|
|
$counter[$hub_id]['reasons'][$reason]['counter'] = 1;
|
|
}
|
|
else
|
|
{
|
|
$counter[$hub_id]['reasons'][$reason]['counter'] += 1;
|
|
}
|
|
|
|
$res[] = [
|
|
'jo_id' => $jo->getID(),
|
|
'jo_date_time' => $jo->getDateSchedule(),
|
|
'jor_date_create' => $jo->getDateCreate(),
|
|
'hub' => $hub->getName() . ' - ' . $hub->getBranch(),
|
|
'reason' => JORejectionReason::getName($jor->getReason()),
|
|
'contact' => $jor->getContactPerson(),
|
|
'remarks' => $jor->getRemarks(),
|
|
];
|
|
}
|
|
|
|
|
|
// response
|
|
$resp = new StreamedResponse();
|
|
$resp->setCallback(function() use ($counter) {
|
|
// csv output
|
|
$csv_handle = fopen('php://output', 'w+');
|
|
fputcsv($csv_handle, ['Enrollee', 'Reason', 'Count']);
|
|
foreach ($counter as $centry)
|
|
{
|
|
$first = true;
|
|
foreach ($centry['reasons'] as $creason)
|
|
{
|
|
// first line has hub name
|
|
if ($first)
|
|
{
|
|
fputcsv($csv_handle, [
|
|
$centry['name'],
|
|
$creason['name'],
|
|
$creason['counter'],
|
|
]);
|
|
$first = false;
|
|
}
|
|
else
|
|
{
|
|
fputcsv($csv_handle, [
|
|
'',
|
|
$creason['name'],
|
|
$creason['counter'],
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
|
|
fclose($csv_handle);
|
|
});
|
|
|
|
$filename = 'reject_' . $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' => $res,
|
|
'counter' => $counter,
|
|
]);
|
|
*/
|
|
}
|
|
|
|
/**
|
|
* @Menu(selected="outlet_list")
|
|
*/
|
|
public function rejectDetailForm()
|
|
{
|
|
$this->denyAccessUnlessGranted('report.reject', null, 'No access.');
|
|
|
|
return $this->render('report/rejection/detail_form.html.twig');
|
|
}
|
|
|
|
public function rejectDetailSubmit(Request $req)
|
|
{
|
|
$this->denyAccessUnlessGranted('report.reject', null, 'No access.');
|
|
|
|
// get query builder
|
|
$qb = $this->getDoctrine()
|
|
->getRepository(JORejection::class)
|
|
->createQueryBuilder('r');
|
|
|
|
// 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
|
|
$query = $qb->where('r.date_create >= :start')
|
|
->andWhere('r.date_create <= :end')
|
|
->setParameter('start', $date_start->format('Y-m-d') . ' 00:00:00')
|
|
->setParameter('end', $date_end->format('Y-m-d') . ' 23:59:59')
|
|
->getQuery();
|
|
|
|
|
|
// run query
|
|
$jors = $query->getResult();
|
|
|
|
// initialize counter
|
|
$counter = [];
|
|
|
|
// get results
|
|
$res = [];
|
|
foreach ($jors as $jor)
|
|
{
|
|
$jo = $jor->getJobOrder();
|
|
$hub = $jor->getHub();
|
|
$hub_id = $hub->getID();
|
|
$hub_name = $hub->getName() . ' - ' . $hub->getBranch();
|
|
|
|
/*
|
|
// check if created by app
|
|
$create_user = $jo->getCreatedBy();
|
|
if ($create_user == null)
|
|
$create_user_text = 'Application';
|
|
else
|
|
$create_user_text = $create_user->getFullName();
|
|
*/
|
|
|
|
$reason = $jor->getReason();
|
|
|
|
$res[] = [
|
|
$jo->getID(),
|
|
$jo->getDateSchedule()->format('m/d/Y H:i'),
|
|
$jor->getDateCreate()->format('m/d/Y H:i'),
|
|
$hub->getName() . ' - ' . $hub->getBranch(),
|
|
JORejectionReason::getName($jor->getReason()),
|
|
$jor->getContactPerson(),
|
|
$jor->getRemarks(),
|
|
$jor->getUser()->getFullName(),
|
|
ServiceType::getName($jo->getServiceType()),
|
|
];
|
|
}
|
|
|
|
|
|
// response
|
|
$resp = new StreamedResponse();
|
|
$resp->setCallback(function() use ($res) {
|
|
// csv output
|
|
$csv_handle = fopen('php://output', 'w+');
|
|
fputcsv($csv_handle, [
|
|
'Order #',
|
|
'Order Date and Time',
|
|
'Date and Time Rejected',
|
|
'Enrollee',
|
|
'Reason',
|
|
'Contact Person',
|
|
'Remarks',
|
|
'Dispatched By',
|
|
'Type of Service',
|
|
]);
|
|
foreach ($res as $row)
|
|
{
|
|
fputcsv($csv_handle, $row);
|
|
}
|
|
|
|
fclose($csv_handle);
|
|
});
|
|
|
|
$filename = 'reject_' . $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' => $res,
|
|
'counter' => $counter,
|
|
]);
|
|
*/
|
|
}
|
|
|
|
/**
|
|
* @Menu(selected="outlet_list")
|
|
*/
|
|
public function batteryConflictForm()
|
|
{
|
|
$this->denyAccessUnlessGranted('report.battery.conflict', null, 'No access.');
|
|
|
|
return $this->render('report/battery/batt_conflict_form.html.twig');
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
/**
|
|
* @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);
|
|
} */
|
|
|
|
/**
|
|
* @Menu(selected="outlet_list")
|
|
*/
|
|
public function popappExportCSV(Request $req, EntityManagerInterface $em)
|
|
{
|
|
// retrieve temporary info for file
|
|
$file = $req->files->get('csv_file');
|
|
|
|
// process the csv file
|
|
$data = $this->processPopappFile($file, $em);
|
|
|
|
$resp = new StreamedResponse();
|
|
$resp->setCallback(function() use ($data) {
|
|
// csv output
|
|
$csv_handle = fopen('php://output', 'w+');
|
|
fputcsv($csv_handle, [
|
|
'Size/Model',
|
|
'SKU',
|
|
'Serial Number',
|
|
'Created Date',
|
|
'Branch Name',
|
|
'Branch Code',
|
|
'Customer ID',
|
|
'Customer Last Name',
|
|
'Customer First Name',
|
|
'Customer Mobile Number',
|
|
'Warranty Last Name',
|
|
'Warranty First Name',
|
|
'Plate Number',
|
|
'Warranty Create Date',
|
|
'Activation Status',
|
|
'Warranty Class',
|
|
'Has Mobile App?',
|
|
'Date Mobile App Downloaded',
|
|
'Mobile Number Using Mobile App',
|
|
]);
|
|
foreach ($data as $row)
|
|
{
|
|
fputcsv($csv_handle, $row);
|
|
}
|
|
|
|
fclose($csv_handle);
|
|
});
|
|
|
|
$filename = 'popapp_comparison_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;
|
|
|
|
}
|
|
|
|
/**
|
|
* @Menu(selected="outlet_list")
|
|
*/
|
|
public function mehCustomerForm()
|
|
{
|
|
$this->denyAccessUnlessGranted('report.meh.customer', null, 'No access.');
|
|
$params['mode'] = 'form';
|
|
|
|
return $this->render('report/meh/form.html.twig', $params);
|
|
}
|
|
|
|
/**
|
|
* @Menu(selected="outlet_list")
|
|
*/
|
|
public function mehCustomerExportCSV(Request $req, EntityManagerInterface $em)
|
|
{
|
|
$data = $this->getMEHCustomerData($em);
|
|
|
|
$resp = new StreamedResponse();
|
|
$resp->setCallback(function() use ($data) {
|
|
// csv output
|
|
$csv_handle = fopen('php://output', 'w+');
|
|
fputcsv($csv_handle, [
|
|
'Last Name',
|
|
'First Name',
|
|
'Mobile Number',
|
|
'Landline Number',
|
|
'Office Number',
|
|
'Fax Number',
|
|
'Plate Number',
|
|
'Date Mobile App Downloaded',
|
|
'Mobile Number Using Mobile App',
|
|
]);
|
|
foreach ($data as $row)
|
|
{
|
|
fputcsv($csv_handle, $row);
|
|
}
|
|
|
|
fclose($csv_handle);
|
|
});
|
|
|
|
$filename = 'resq_meh_customer_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;
|
|
}
|
|
|
|
/**
|
|
* @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)
|
|
{
|
|
// 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
|
|
$row_num = 0;
|
|
$results = [];
|
|
|
|
while(($fields = fgetcsv($fh)) !== false)
|
|
{
|
|
//error_log($row_num . ' ' . trim($fields[2]));
|
|
if ($row_num < 1)
|
|
{
|
|
$row_num++;
|
|
continue;
|
|
}
|
|
|
|
// pre-populate the result array
|
|
$results[] = [
|
|
'model_size' => trim($fields[0]),
|
|
'sku' => trim($fields[1]),
|
|
'serial' => trim($fields[2]),
|
|
'created_date' => trim($fields[3]),
|
|
'branch_name' => trim($fields[4]),
|
|
'branch_code' => trim($fields[5]),
|
|
'cust_id' => '',
|
|
'cust_lastname' => '',
|
|
'cust_firstname' => '',
|
|
'cust_mobile_number' => '',
|
|
'warr_lastname' => '',
|
|
'warr_firstname' => '',
|
|
'plate_num' => '',
|
|
'warr_date_create' => '',
|
|
'warr_activation_status' => '',
|
|
'warr_class' => '',
|
|
'has_mobile' => '',
|
|
'date_mobile' => '',
|
|
'mobile_number' => '',
|
|
];
|
|
}
|
|
|
|
foreach($results as $key => $data)
|
|
{
|
|
//error_log($results[$key]['model_size']);
|
|
|
|
// get the serial
|
|
$serial = $results[$key]['serial'];
|
|
|
|
// if serial is empty, move to next element
|
|
if (!empty($serial))
|
|
{
|
|
// get the warranty for serial
|
|
$warranties = $em->getRepository(Warranty::class)->findBy(['serial' => $serial]);
|
|
|
|
if (!empty($warranties))
|
|
{
|
|
foreach ($warranties as $warranty)
|
|
{
|
|
//error_log('found warranty for serial ' . $serial);
|
|
$plate_number = $warranty->getPlateNumber();
|
|
$isValid = InvalidPlateNumber::isInvalid($plate_number);
|
|
if ($isValid)
|
|
{
|
|
// get customer vehicles using plate number
|
|
$customer_vehicles = $em->getRepository(CustomerVehicle::class)->findBy(['plate_number' => $plate_number]);
|
|
|
|
// check if customer vehicle is empty
|
|
if (count($customer_vehicles) != 0)
|
|
{
|
|
//error_log('found customer vehicle for plate number ' . $plate_number);
|
|
$has_mobile = false;
|
|
$mobile_date = '';
|
|
$mobile_number = '';
|
|
|
|
// get the first customer vehicle, store as best_cv until we find one with a mobile session
|
|
$best_cv = current($customer_vehicles);
|
|
|
|
foreach($customer_vehicles as $cv)
|
|
{
|
|
// get mobile session of customer
|
|
//error_log($cv->getCustomer()->getLastName() . ' ' . $cv->getCustomer()->getFirstName());
|
|
$cust_id = $cv->getCustomer()->getID();
|
|
$mobile_session = $em->getRepository(MobileSession::class)
|
|
->findOneBy(['customer' => $cust_id], ['date_generated' => 'ASC']);
|
|
if ($mobile_session != null)
|
|
{
|
|
// get mobile data
|
|
//error_log('found mobile session for customer id ' . $cv->getCustomer()->getID());
|
|
$has_mobile = true;
|
|
$mobile_date = $mobile_session->getDateGenerated()->format("d M Y");
|
|
$mobile_number = $mobile_session->getPhoneNumber();
|
|
|
|
// set best_cv to this customer vehicle with mobile session
|
|
$best_cv = $cv;
|
|
}
|
|
}
|
|
// set the customer data in results
|
|
$results[$key]['cust_id'] = $best_cv->getCustomer()->getID();
|
|
$results[$key]['cust_lastname'] = $best_cv->getCustomer()->getLastName();
|
|
$results[$key]['cust_firstname'] = $best_cv->getCustomer()->getFirstName();
|
|
$results[$key]['cust_mobile_number'] = $best_cv->getCustomer()->getPhoneMobile();
|
|
$results[$key]['plate_num'] = $best_cv->getPlateNumber();
|
|
$results[$key]['has_mobile'] = ($has_mobile ? 'Yes' : 'No');
|
|
$results[$key]['date_mobile'] = $mobile_date;
|
|
$results[$key]['mobile_number'] = $mobile_number;
|
|
}
|
|
}
|
|
// set the warranty data in results
|
|
$results[$key]['warr_lastname'] = $warranty->getLastName();
|
|
$results[$key]['warr_firstname'] = $warranty->getFirstName();
|
|
$results[$key]['warr_date_create'] = $warranty->getDateCreate()->format("d M Y");
|
|
$results[$key]['warr_activation_status'] = ($warranty->isActivated() ? 'Active' : 'Inactive');
|
|
$results[$key]['warr_class'] = $warranty->getWarrantyClass();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $results;
|
|
}
|
|
|
|
protected function getMEHCustomerData(EntityManagerInterface $em)
|
|
{
|
|
$results = [];
|
|
|
|
$conn = $em->getConnection();
|
|
$sql = 'SELECT c.id, c.last_name, c.first_name, c.phone_mobile, c.phone_landline,
|
|
c.phone_office, c.phone_fax,
|
|
cv.plate_number, jo.source
|
|
FROM job_order jo, customer_vehicle cv, customer c
|
|
WHERE c.id = cv.customer_id
|
|
AND jo.cvehicle_id = cv.id
|
|
AND c.policy_mobile_app_id IS NOT NULL
|
|
AND jo.source != :source';
|
|
|
|
$stmt = $conn->prepare($sql);
|
|
$stmt->execute(array('source' => 'mobile_app'));
|
|
|
|
$query_results = $stmt->fetchAll();
|
|
|
|
foreach($query_results as $row)
|
|
{
|
|
$mobile_date = '';
|
|
$mobile_number = '';
|
|
|
|
$mobile_session = $em->getRepository(MobileSession::class)
|
|
->findOneBy(['customer' => $row['id']], ['date_generated' => 'ASC']);
|
|
if ($mobile_session != null)
|
|
{
|
|
$mobile_date = $mobile_session->getDateGenerated()->format("d M Y");
|
|
$mobile_number = $mobile_session->getPhoneNumber();
|
|
}
|
|
|
|
$results[] = [
|
|
'last_name' => $row['last_name'],
|
|
'first_name' => $row['first_name'],
|
|
'cust_mobile_number' => $row['phone_mobile'],
|
|
'landline_number' => $row['phone_landline'],
|
|
'office_number' => $row['phone_office'],
|
|
'fax_number' => $row['phone_fax'],
|
|
'plate_number' => $row['plate_number'],
|
|
'date_mobile' => $mobile_date,
|
|
'mobile_number' => $mobile_number,
|
|
];
|
|
|
|
}
|
|
|
|
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));
|
|
}
|
|
}
|