80 lines
2.1 KiB
PHP
80 lines
2.1 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\Entity\JobOrder;
|
|
use App\Entity\JOEvent;
|
|
use App\Entity\User;
|
|
|
|
use App\Ramcar\JOStatus;
|
|
use App\Ramcar\JOEventType;
|
|
|
|
use DateTime;
|
|
|
|
class FulfillOldJobOrderCommand extends Command
|
|
{
|
|
protected $em;
|
|
|
|
public function __construct(EntityManagerInterface $om)
|
|
{
|
|
$this->em = $om;
|
|
|
|
parent::__construct();
|
|
}
|
|
|
|
protected function configure()
|
|
{
|
|
$this->setName('joborder:fulfill_assigned')
|
|
->setDescription('Fulfill assigned job orders so riders can be available again.')
|
|
->setHelp('Mark old assigned job orders as fulfilled. Have to make it a script so it goes through the same process as the controller');
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
// get entity manager
|
|
$em = $this->em;
|
|
|
|
$date = new DateTime('2018-07-24');
|
|
$qb = $em->getRepository(JobOrder::class)
|
|
->createQueryBuilder('j');
|
|
|
|
// get all job orders that are assigned before scheduled date (inclusive)
|
|
$qb->select('j')
|
|
->where('j.status = :status')
|
|
->andWhere('j.date_schedule <= :date')
|
|
->setParameter('status', JOStatus::ASSIGNED)
|
|
->setParameter('date', $date);
|
|
|
|
$query = $qb->getQuery();
|
|
$res = $query->getResult();
|
|
|
|
|
|
// get user
|
|
$user = $em->getRepository(User::class)->find(1);
|
|
|
|
// fulfill each
|
|
foreach ($res as $jo)
|
|
{
|
|
echo 'fulfilling job order ' . $jo->getID() . "\n";
|
|
// fulfill
|
|
$jo->fulfill();
|
|
|
|
// add event
|
|
$event = new JOEvent();
|
|
$event->setDateHappen(new DateTime())
|
|
->setTypeID(JOEventType::FULFILL)
|
|
->setUser($user)
|
|
->setJobOrder($jo);
|
|
$em->persist($event);
|
|
}
|
|
|
|
$em->flush();
|
|
}
|
|
}
|