From dc0f63fb647ab464d877c860d22a6758984911ef Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Thu, 26 Jul 2018 21:25:56 +0800 Subject: [PATCH] Create new command for fulfilling pending job orders #160 --- src/Command/FulfillOldJobOrderCommand.php | 4 +- src/Command/FulfillPendingJobOrderCommand.php | 83 +++++++++++++++++++ 2 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 src/Command/FulfillPendingJobOrderCommand.php diff --git a/src/Command/FulfillOldJobOrderCommand.php b/src/Command/FulfillOldJobOrderCommand.php index 53259df5..a0cabd57 100644 --- a/src/Command/FulfillOldJobOrderCommand.php +++ b/src/Command/FulfillOldJobOrderCommand.php @@ -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'); } diff --git a/src/Command/FulfillPendingJobOrderCommand.php b/src/Command/FulfillPendingJobOrderCommand.php new file mode 100644 index 00000000..22180186 --- /dev/null +++ b/src/Command/FulfillPendingJobOrderCommand.php @@ -0,0 +1,83 @@ +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(); + } +}