Create command to generate report. #267
This commit is contained in:
parent
2a81103773
commit
4a50729a41
3 changed files with 169 additions and 6 deletions
115
src/Command/GenerateMEHCustomerReportCommand.php
Normal file
115
src/Command/GenerateMEHCustomerReportCommand.php
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
|
||||
use Doctrine\ORM\Query\ResultSetMapping;
|
||||
|
||||
use App\Entity\JobOrder;
|
||||
use App\Entity\CustomerVehicle;
|
||||
use App\Entity\MobileSession;
|
||||
use App\Entity\Customer;
|
||||
|
||||
class GenerateMEHCustomerReportCommand extends Command
|
||||
{
|
||||
private $em;
|
||||
|
||||
public function __construct(ObjectManager $om)
|
||||
{
|
||||
$this->em = $om;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('customer:generateMEHReport')
|
||||
->setDescription('Generate MEH Customer Report.')
|
||||
->setHelp('Generate MEH Customer Report.');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$customer_outfile = fopen('/tmp/meh_customer_report.csv', 'w');
|
||||
|
||||
$data = $this->getMEHCustomerData($output);
|
||||
|
||||
foreach($data as $row)
|
||||
{
|
||||
$line = $row['last_name'] . ',' . $row['first_name'] . ',' .
|
||||
$row['cust_mobile_number'] . ',' . $row['landline_number'] . ',' .
|
||||
$row['office_number'] . ',' . $row['fax_number'] . ',' .
|
||||
$row['date_mobile'] . ',' . $row['mobile_number'];
|
||||
$output->writeln("Writing " . $line);
|
||||
fwrite($customer_outfile, $line . "\n");
|
||||
}
|
||||
|
||||
fclose($customer_outfile);
|
||||
|
||||
}
|
||||
|
||||
protected function getMEHCustomerData($output)
|
||||
{
|
||||
$em = $this->em;
|
||||
$results = [];
|
||||
|
||||
$output->writeln("about to query");
|
||||
$rsm = new ResultSetMapping();
|
||||
|
||||
$query = $em->createNativeQuery('SELECT c.id, c.last_name, c.first_name, c.phone_mobile, c.phone_landline,
|
||||
c.phone_office, c.phone_fax, 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 != \'mobile\'', $rsm);
|
||||
|
||||
$results = $query->getResult();
|
||||
|
||||
$output->writeln("about to iterate");
|
||||
|
||||
foreach($results as $row)
|
||||
{
|
||||
// check if the source of the job order is not 'mobile' (meaning JO originated from MEH)
|
||||
$output->writeln("checking job order source");
|
||||
//if ($row[0]->getSource() != 'mobile')
|
||||
//{
|
||||
// $mobile_date = '';
|
||||
// $mobile_number = '';
|
||||
|
||||
// $mobile_session = $em->getRepository(MobileSession::class)
|
||||
// ->findOneBy(['customer' => $row[1]->getID()], ['date_generated' => 'ASC']);
|
||||
// if ($mobile_session != null)
|
||||
// {
|
||||
// $output->writeln("mobile session not null");
|
||||
// $mobile_date = $mobile_session->getDateGenerated()->format("d M Y");
|
||||
// $mobile_number = $mobile_session->getPhoneNumber();
|
||||
// }
|
||||
|
||||
// $results[] = [
|
||||
// 'last_name' => $row[1]->getLastName(),
|
||||
// 'first_name' => $row[1]->getFirstName(),
|
||||
// 'cust_mobile_number' => $row[1]->getPhoneMobile(),
|
||||
// 'landline_number' => $row[1]->getPhoneLandline(),
|
||||
// 'office_number' => $row[1]->getPhoneOffice(),
|
||||
// 'fax_number' => $row[1]->getPhoneFax(),
|
||||
// 'date_mobile' => $mobile_date,
|
||||
// 'mobile_number' => $mobile_number,
|
||||
// ];
|
||||
//}
|
||||
|
||||
//$this->em->detach($cv[0]);
|
||||
//$this->em->detach($cv[1]);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -512,7 +512,7 @@ class ReportController extends Controller
|
|||
*/
|
||||
public function mehCustomerExportCSV(Request $req, EntityManagerInterface $em)
|
||||
{
|
||||
$data = getMEHCustomerData($em);
|
||||
$data = $this->getMEHCustomerData($em);
|
||||
|
||||
$resp = new StreamedResponse();
|
||||
$resp->setCallback(function() use ($data) {
|
||||
|
|
@ -682,21 +682,62 @@ class ReportController extends Controller
|
|||
$policy_mobile_id = $_ENV['POLICY_MOBILE'];
|
||||
|
||||
// get all the customers with mobile privacy policy id
|
||||
$customers = $em->getRepository(Customer::class)->findBy(['privpol_mobile_app' => $policy_mobile_id]):
|
||||
$customers = $em->getRepository(Customer::class)->findBy(['privpol_mobile_app' => $policy_mobile_id]);
|
||||
|
||||
foreach ($customers as $customer)
|
||||
{
|
||||
// get plate numbers
|
||||
$plate_numbers = $customer->getPlateNumberList();
|
||||
|
||||
// using plate number, get all customer vehicles with the plate number and the job orders with the plate number
|
||||
// using plate number, get all customer vehicles with the plate numbers
|
||||
//$cust_vehicles = $em->createQuery('SELECT cv from App\Entity\CustomerVehicle cv
|
||||
// WHERE cv.plate_number in (:plate_numbers)')
|
||||
// ->setParameter('plate_numbers', $plate_numbers)
|
||||
// ->getResult();
|
||||
foreach ($plate_numbers as $plate_number)
|
||||
{
|
||||
$cust_vehicles = $em->getRepository(CustomerVehicle::class)->findBy(['plate_number' => $plate_number]);
|
||||
|
||||
// get job orders of vehicles
|
||||
if ($cust_vehicles != null)
|
||||
{
|
||||
foreach($cust_vehicles as $cv)
|
||||
{
|
||||
// get the job orders for each cv
|
||||
$job_orders = $cv->getJobOrders();
|
||||
|
||||
// check if source is not null. If not null, add customer to results
|
||||
foreach($job_orders as $jo)
|
||||
{
|
||||
// check if the source of the job order is not 'mobile' (meaning JO originated from MEH)
|
||||
if ($jo->getSource() != 'mobile')
|
||||
{
|
||||
$mobile_date = '';
|
||||
$mobile_number = '';
|
||||
|
||||
$mobile_session = $em->getRepository(MobileSession::class)
|
||||
->findOneBy(['customer' => $customer->getID()], ['date_generated' => 'ASC']);
|
||||
if ($mobile_session != null)
|
||||
{
|
||||
$mobile_date = $mobile_session->getDateGenerated()->format("d M Y");
|
||||
$mobile_number = $mobile_session->getPhoneNumber();
|
||||
}
|
||||
|
||||
$results[] = [
|
||||
'last_name' => $customer->getLastName(),
|
||||
'first_name' => $customer->getFirstName(),
|
||||
'cust_mobile_number' => $customer->getPhoneMobile(),
|
||||
'landline_number' => $customer->getPhoneLandline(),
|
||||
'office_number' => $customer->getPhoneOffice(),
|
||||
'fax_number' => $customer->getPhoneFax(),
|
||||
'date_mobile' => $mobile_date,
|
||||
'mobile_number' => $mobile_number,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,6 +119,8 @@ class CustomerVehicle
|
|||
public function __construct()
|
||||
{
|
||||
$this->flag_active = true;
|
||||
|
||||
$this->job_orders = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getID()
|
||||
|
|
@ -256,6 +258,11 @@ class CustomerVehicle
|
|||
return $this->curr_battery;
|
||||
}
|
||||
|
||||
public function getJobOrders()
|
||||
{
|
||||
return $this->job_orders;
|
||||
}
|
||||
|
||||
public function setHasMotoliteBattery($flag_motolite_battery = true)
|
||||
{
|
||||
$this->flag_motolite_battery = $flag_motolite_battery;
|
||||
|
|
|
|||
Loading…
Reference in a new issue