From 59a77c945ca0f87b188a5f2f0dd7d4ee630b0077 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 1 Mar 2021 11:09:43 +0000 Subject: [PATCH] Add command to get all customers for report. #539 --- .../GenerateCustomerSourceReportCommand.php | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/Command/GenerateCustomerSourceReportCommand.php diff --git a/src/Command/GenerateCustomerSourceReportCommand.php b/src/Command/GenerateCustomerSourceReportCommand.php new file mode 100644 index 00000000..5a178cd1 --- /dev/null +++ b/src/Command/GenerateCustomerSourceReportCommand.php @@ -0,0 +1,87 @@ +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; + } +}