Merge branch '252-add-columns-to-popapp-report' into 'master'

Resolve "Add columns to popapp report"

Closes #252

See merge request jankstudio/resq!297
This commit is contained in:
Kendrick Chan 2019-08-17 01:39:00 +00:00
commit f114554361

View file

@ -455,11 +455,18 @@ class ReportController extends Controller
// csv output // csv output
$csv_handle = fopen('php://output', 'w+'); $csv_handle = fopen('php://output', 'w+');
fputcsv($csv_handle, [ fputcsv($csv_handle, [
'Size/Model',
'SKU',
'Serial Number',
'Created Date',
'Branch Name',
'Branch Code',
'Customer ID', 'Customer ID',
'Last Name', 'Customer Last Name',
'First Name', 'Customer First Name',
'Warranty Last Name',
'Warranty First Name',
'Plate Number', 'Plate Number',
'Serial',
'Warranty Create Date', 'Warranty Create Date',
'Activation Status', 'Activation Status',
'Has Mobile App?', 'Has Mobile App?',
@ -495,67 +502,83 @@ class ReportController extends Controller
} }
// loop through the rows // loop through the rows
$serial_numbers = [];
$row_num = 0; $row_num = 0;
$results = [];
while(($fields = fgetcsv($fh)) !== false) while(($fields = fgetcsv($fh)) !== false)
{ {
$has_warranty = false;
if ($row_num <= 2) if ($row_num <= 2)
{ {
$row_num++; $row_num++;
continue; continue;
} }
// get the serial numbers // get the data
$serial_numbers[] = trim($fields[2]); $serial = trim($fields[2]);
}
// get the warranty for serial // get the warranty for serial
$warr_qb = $this->getDoctrine() $warr_qb = $this->getDoctrine()
->getRepository(Warranty::class) ->getRepository(Warranty::class)
->createQueryBuilder('q'); ->createQueryBuilder('q');
$warranty_query = $warr_qb->select('q') $warranty_query = $warr_qb->select('q')
->where('q.serial IN(:serials)') ->where('q.serial = :serial')
->setParameter('serials', $serial_numbers, Connection::PARAM_STR_ARRAY); ->setParameter('serial', $serial);
$warranty = $warranty_query->getQuery()->getOneOrNullResult();
$warr_results = $warranty_query->getQuery()->getResult(); if ($warranty != null)
// 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 $isValid = InvalidPlateNumber::isInvalid($warranty->getPlateNumber());
$em = $this->getDoctrine()->getManager(); if ($isValid)
$cust_vehicles = $em->getRepository(CustomerVehicle::class)->findBy(['plate_number' => $warranty->getPlateNumber()]);
foreach ($cust_vehicles as $cv)
{ {
// get customer info // get customer vehicle using plate number
// get mobile session of customer $em = $this->getDoctrine()->getManager();
//error_log($cv->getCustomer()->getLastName() . ' ' . $cv->getCustomer()->getFirstName()); $cust_vehicles = $em->getRepository(CustomerVehicle::class)->findBy(['plate_number' => $warranty->getPlateNumber()]);
$has_mobile = false; foreach ($cust_vehicles as $cv)
$mobile_session = $em->getRepository(MobileSession::class)->findBy(['customer' => $cv->getCustomer()->getID()]);
foreach ($mobile_session as $mobile)
{ {
error_log($mobile->getID()); // get customer info
$has_mobile = true; // get mobile session of customer
} //error_log($cv->getCustomer()->getLastName() . ' ' . $cv->getCustomer()->getFirstName());
$results[] = [ $has_mobile = false;
'cust_id' => $cv->getCustomer()->getID(), $mobile_session = $em->getRepository(MobileSession::class)->findBy(['customer' => $cv->getCustomer()->getID()]);
'cust_lastname' => $cv->getCustomer()->getLastName(), foreach ($mobile_session as $mobile)
'cust_firstname' => $cv->getCustomer()->getFirstName(), {
'plate_num' => $cv->getPlateNumber(), $has_mobile = true;
'serial' => $warranty->getSerial(), }
'warr_date_create' => $warranty->getDateCreate()->format("d M Y"), $has_warranty = true;
'warr_activation_status' => ($warranty->isActivated() ? 'Active' : 'Inactive'), $results[] = [
'has_mobile' => ($has_mobile ? 'Yes' : 'No'), 'model_size' => trim($fields[0]),
]; 'sku' => trim($fields[1]),
'serial' => $serial,
'created_date' => trim($fields[3]),
'branch_name' => trim($fields[4]),
'branch_code' => trim($fields[5]),
'cust_id' => $cv->getCustomer()->getID(),
'cust_lastname' => $cv->getCustomer()->getLastName(),
'cust_firstname' => $cv->getCustomer()->getFirstName(),
'warr_lastname' => $warranty->getLastName(),
'warr_firstname' => $warranty->getFirstName(),
'plate_num' => $cv->getPlateNumber(),
'warr_date_create' => $warranty->getDateCreate()->format("d M Y"),
'warr_activation_status' => ($warranty->isActivated() ? 'Active' : 'Inactive'),
'has_mobile' => ($has_mobile ? 'Yes' : 'No'),
];
}
} }
} }
if ($has_warranty == false)
{
$results[] = [
'model_size' => trim($fields[0]),
'sku' => trim($fields[1]),
'serial' => $serial,
'created_date' => trim($fields[3]),
'branch_name' => trim($fields[4]),
'branch_code' => trim($fields[5]),
];
}
$row_num++;
} }
return $results; return $results;