Merge branch '160-fulfillment-script' into 'master'
Resolve "Fulfillment script" Closes #160 See merge request jankstudio/resq!164
This commit is contained in:
commit
aa59a0b89a
2 changed files with 82 additions and 0 deletions
80
src/Command/FulfillOldJobOrderCommand.php
Normal file
80
src/Command/FulfillOldJobOrderCommand.php
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
<?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 FulfillOldJobOrderCommand extends Command
|
||||
{
|
||||
protected $em;
|
||||
|
||||
public function __construct(ObjectManager $om)
|
||||
{
|
||||
$this->em = $om;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('joborder:fulfill_old')
|
||||
->setDescription('Fulfill old 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();
|
||||
}
|
||||
}
|
||||
|
|
@ -1353,10 +1353,12 @@ class JobOrderController extends BaseController
|
|||
], 422);
|
||||
}
|
||||
|
||||
/*
|
||||
// set rider available
|
||||
$rider = $obj->getRider();
|
||||
if ($rider != null)
|
||||
$rider->setAvailable();
|
||||
*/
|
||||
|
||||
// the event
|
||||
$event = new JOEvent();
|
||||
|
|
|
|||
Loading…
Reference in a new issue