80 lines
2.2 KiB
PHP
80 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Command;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use App\Service\JobOrderManager;
|
|
|
|
class SetJobOrderCustNewCommand extends Command
|
|
{
|
|
protected $em;
|
|
protected $jo_manager;
|
|
|
|
public function __construct(EntityManagerInterface $em, JobOrderManager $jo_manager)
|
|
{
|
|
$this->em = $em;
|
|
$this->jo_manager = $jo_manager;
|
|
|
|
parent::__construct();
|
|
}
|
|
|
|
protected function configure()
|
|
{
|
|
$this->setName('joborder:setcustomernew')
|
|
->setDescription('Set job order\'s customer new flag for existing job orders.')
|
|
->setHelp('Set job order\'s customer new flag for existing job orders');
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
$em = $this->em;
|
|
|
|
// pdo connection
|
|
$db = $em->getConnection();
|
|
|
|
// get all the ids for all job orders
|
|
$all_query_sql = 'SELECT id AS jo_id, customer_id AS cust_id FROM job_order ORDER BY id';
|
|
|
|
$all_query_stmt = $db->prepare($all_query_sql);
|
|
$all_query_stmt->execute();
|
|
|
|
$all_jo_results = $all_query_stmt->fetchAll();
|
|
|
|
$output->writeln('Processing job orders...');
|
|
|
|
foreach ($all_jo_results as $jo_row)
|
|
{
|
|
// for each jo id, get the customer id
|
|
$jo_id = $jo_row['jo_id'];
|
|
$cust_id = $jo_row['cust_id'];
|
|
|
|
// check how many JOs have that customer id
|
|
$jo_count = $this->jo_manager->getCustomerJobOrderCount($cust_id);
|
|
|
|
// if one or less, set flag_cust_new to true
|
|
if ($jo_count <= 1)
|
|
$this->updateCustNew($db, $jo_id);
|
|
}
|
|
|
|
$output->writeln('All done!');
|
|
|
|
return 0;
|
|
}
|
|
|
|
protected function updateCustNew($db, $jo_id)
|
|
{
|
|
$update_jo_sql = 'UPDATE job_order SET flag_cust_new = :flag_cust_new WHERE id = :jo_id';
|
|
|
|
$update_jo_stmt = $db->prepare($update_jo_sql);
|
|
$update_jo_stmt->execute([
|
|
'flag_cust_new' => true,
|
|
'jo_id' => $jo_id
|
|
]);
|
|
}
|
|
}
|