Add cancelJobOrder. #617
This commit is contained in:
parent
1554f173a8
commit
5ea4ac013b
1 changed files with 49 additions and 1 deletions
|
|
@ -38,6 +38,7 @@ use App\Ramcar\InvoiceStatus;
|
||||||
use App\Ramcar\ModeOfPayment;
|
use App\Ramcar\ModeOfPayment;
|
||||||
use App\Ramcar\InvoiceCriteria;
|
use App\Ramcar\InvoiceCriteria;
|
||||||
use App\Ramcar\WarrantySource;
|
use App\Ramcar\WarrantySource;
|
||||||
|
use App\Ramcar\DeliveryStatus;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
|
||||||
|
|
@ -430,8 +431,55 @@ class RiderController extends APIController
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cancelJobOrder(Request $req, EntityManagerInterface $em)
|
public function cancelJobOrder(Request $req, EntityManagerInterface $em, MQTTClient $mclient)
|
||||||
{
|
{
|
||||||
|
$required_params = ['jo_id'];
|
||||||
|
|
||||||
|
// get capi user to link to rider api user
|
||||||
|
$capi_user_id = $this->getUser()->getID();
|
||||||
|
|
||||||
|
// check if capi user already has a rider api user
|
||||||
|
$rapi_session = $em->getRepository(RiderAPISession::class)->findOneBy(['capi_user_id' => $capi_user_id]);
|
||||||
|
|
||||||
|
// are we logged in?
|
||||||
|
if (!$rapi_session->hasRider())
|
||||||
|
return new APIResponse(false, 'No logged in rider.');
|
||||||
|
|
||||||
|
$rider = $rapi_session->getRider();
|
||||||
|
|
||||||
|
$msg = $this->checkJO($req, $required_params, $jo, $rider);
|
||||||
|
if (!empty($msg))
|
||||||
|
return new APIResponse(false, $msg);
|
||||||
|
|
||||||
|
// requeue it, instead of cancelling it
|
||||||
|
$jo->requeue();
|
||||||
|
|
||||||
|
// set delivery status to requeued
|
||||||
|
$jo->setDeliveryStatus(DeliveryStatus::REQUEUE);
|
||||||
|
|
||||||
|
// set rider's current job order to null
|
||||||
|
$rider->setCurrentJobOrder();
|
||||||
|
|
||||||
|
// add event log
|
||||||
|
$event = new JOEvent();
|
||||||
|
$event->setDateHappen(new DateTime())
|
||||||
|
->setTypeID(JOEventType::REQUEUE)
|
||||||
|
->setJobOrder($jo)
|
||||||
|
->setRider($rider);
|
||||||
|
$em->persist($event);
|
||||||
|
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// send mqtt event
|
||||||
|
// send outlet assign since order should go back to hub and await reassignment to another rider
|
||||||
|
$payload = [
|
||||||
|
'event' => 'outlet_assign',
|
||||||
|
'jo_id' => $jo->getID(),
|
||||||
|
];
|
||||||
|
$mclient->sendEvent($jo, $payload);
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
return new APIResponse(true, 'Job order requeued.', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function arrive(Request $req, EntityManagerInterface $em)
|
public function arrive(Request $req, EntityManagerInterface $em)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue