Merge branch '160-fulfillment-script' into 'master'
Resolve "Fulfillment script" Closes #160 See merge request jankstudio/resq!165
This commit is contained in:
commit
8e5a7ebc49
2 changed files with 85 additions and 2 deletions
|
|
@ -31,8 +31,8 @@ class FulfillOldJobOrderCommand extends Command
|
|||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('joborder:fulfill_old')
|
||||
->setDescription('Fulfill old job orders so riders can be available again.')
|
||||
$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');
|
||||
}
|
||||
|
||||
|
|
|
|||
83
src/Command/FulfillPendingJobOrderCommand.php
Normal file
83
src/Command/FulfillPendingJobOrderCommand.php
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
<?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\Common\Persistence\ObjectManager;
|
||||
|
||||
use App\Entity\JobOrder;
|
||||
use App\Entity\JOEvent;
|
||||
use App\Entity\User;
|
||||
|
||||
use App\Ramcar\JOStatus;
|
||||
use App\Ramcar\JOEventType;
|
||||
|
||||
use DateTime;
|
||||
|
||||
class FulfillPendingJobOrderCommand extends Command
|
||||
{
|
||||
protected $em;
|
||||
|
||||
public function __construct(ObjectManager $om)
|
||||
{
|
||||
$this->em = $om;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('joborder:fulfill_pending')
|
||||
->setDescription('Fulfill pending job orders so hubs/outlets can be available again.')
|
||||
->setHelp('Mark old pending job orders as fulfilled. Allocate placeholder rider and fulfill the job order. 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::RIDER_ASSIGN)
|
||||
->setParameter('date', $date);
|
||||
|
||||
$query = $qb->getQuery();
|
||||
$res = $query->getResult();
|
||||
|
||||
|
||||
// get user
|
||||
$user = $em->getRepository(User::class)->find(1);
|
||||
|
||||
// TODO: get placeholder rider
|
||||
|
||||
// fulfill each
|
||||
foreach ($res as $jo)
|
||||
{
|
||||
echo 'fulfilling job order ' . $jo->getID() . "\n";
|
||||
// TODO: assign placeholder rider
|
||||
// fulfill
|
||||
$jo->fulfill();
|
||||
|
||||
// add event
|
||||
$event = new JOEvent();
|
||||
$event->setDateHappen(new DateTime())
|
||||
->setTypeID(JOEventType::FULFILL)
|
||||
->setUser($user)
|
||||
->setJobOrder($jo);
|
||||
$em->persist($event);
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue