Add the existing data from csv file to the report. #252
This commit is contained in:
parent
4d0c0345fb
commit
f0841a0b73
1 changed files with 71 additions and 48 deletions
|
|
@ -455,11 +455,18 @@ class ReportController extends Controller
|
|||
// csv output
|
||||
$csv_handle = fopen('php://output', 'w+');
|
||||
fputcsv($csv_handle, [
|
||||
'Size/Model',
|
||||
'SKU',
|
||||
'Serial Number',
|
||||
'Created Date',
|
||||
'Branch Name',
|
||||
'Branch Code',
|
||||
'Customer ID',
|
||||
'Last Name',
|
||||
'First Name',
|
||||
'Customer Last Name',
|
||||
'Customer First Name',
|
||||
'Warranty Last Name',
|
||||
'Warranty First Name',
|
||||
'Plate Number',
|
||||
'Serial',
|
||||
'Warranty Create Date',
|
||||
'Activation Status',
|
||||
'Has Mobile App?',
|
||||
|
|
@ -495,67 +502,83 @@ class ReportController extends Controller
|
|||
}
|
||||
|
||||
// loop through the rows
|
||||
$serial_numbers = [];
|
||||
$row_num = 0;
|
||||
$results = [];
|
||||
while(($fields = fgetcsv($fh)) !== false)
|
||||
{
|
||||
$has_warranty = false;
|
||||
if ($row_num <= 2)
|
||||
{
|
||||
$row_num++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// get the serial numbers
|
||||
$serial_numbers[] = trim($fields[2]);
|
||||
}
|
||||
// get the data
|
||||
$serial = 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);
|
||||
// get the warranty for serial
|
||||
$warr_qb = $this->getDoctrine()
|
||||
->getRepository(Warranty::class)
|
||||
->createQueryBuilder('q');
|
||||
$warranty_query = $warr_qb->select('q')
|
||||
->where('q.serial = :serial')
|
||||
->setParameter('serial', $serial);
|
||||
$warranty = $warranty_query->getQuery()->getOneOrNullResult();
|
||||
|
||||
$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)
|
||||
if ($warranty != null)
|
||||
{
|
||||
// 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)
|
||||
$isValid = InvalidPlateNumber::isInvalid($warranty->getPlateNumber());
|
||||
if ($isValid)
|
||||
{
|
||||
// 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)
|
||||
// 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)
|
||||
{
|
||||
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"),
|
||||
'warr_activation_status' => ($warranty->isActivated() ? 'Active' : 'Inactive'),
|
||||
'has_mobile' => ($has_mobile ? 'Yes' : 'No'),
|
||||
];
|
||||
|
||||
// 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)
|
||||
{
|
||||
$has_mobile = true;
|
||||
}
|
||||
$has_warranty = true;
|
||||
$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]),
|
||||
'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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue