Add command to get all customers for report. #539
This commit is contained in:
parent
9f44148e1a
commit
59a77c945c
1 changed files with 87 additions and 0 deletions
87
src/Command/GenerateCustomerSourceReportCommand.php
Normal file
87
src/Command/GenerateCustomerSourceReportCommand.php
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\CustomerVehicle;
|
||||
use App\Entity\VehicleManufacturer;
|
||||
use App\Entity\Vehicle;
|
||||
|
||||
use DateTime;
|
||||
|
||||
class GenerateCustomerSourceReportCommand extends Command
|
||||
{
|
||||
protected $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('report:customer_source')
|
||||
->setDescription('Create customer source reports')
|
||||
->setHelp('Creates customer source reports.')
|
||||
->addArgument('year', InputArgument::REQUIRED, 'Year to process customer data')
|
||||
->addArgument('month', InputArgument::REQUIRED, 'Month to process customer data');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$em = $this->em;
|
||||
|
||||
// get year and month
|
||||
$year = $input->getArgument('year');
|
||||
$month = $input->getArgument('month');
|
||||
|
||||
$start_date = DateTime::createFromFormat('Y-m-d', $year . '-' . $month . '-01');
|
||||
$end_date = DateTime::createFromFormat('Y-m-d', $year . '-' . $month . '-01');
|
||||
$start_date->setTime(0, 0);
|
||||
$str_start_date = $start_date->format('Y-m-d H:i:s');
|
||||
|
||||
$end_date->modify('last day of this month');
|
||||
$end_date->setTime(23, 59);
|
||||
$str_end_date = $end_date->format('Y-m-d H:i:s');
|
||||
//error_log($start_date->format('Y-m-d H:i:s'));
|
||||
//error_log($str_end_date);
|
||||
|
||||
// get all customers
|
||||
$cust_query = $em->createQuery('select c from App\Entity\Customer c
|
||||
where c.date_create >= :start_date and c.date_create <= :end_date
|
||||
order by c.date_create asc');
|
||||
$cust_query->setParameter('start_date', $start_date)
|
||||
->setParameter('end_date', $end_date);
|
||||
|
||||
$customer_results = $cust_query->iterate();
|
||||
|
||||
$customers = [];
|
||||
foreach ($customer_results as $row)
|
||||
{
|
||||
$cust = $row[0];
|
||||
|
||||
//error_log($cust->getID());
|
||||
// get the ff fields: first name, last name, landline
|
||||
// mobile, fax, office, email address, vehicle brand,
|
||||
// vehicle model, plate number
|
||||
|
||||
// check if flag_confirmed == true and date_confirmed is not null
|
||||
// if so, source is Resq app
|
||||
// if not, source is OWR/CRM
|
||||
|
||||
$em->detach($row[0]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue