diff --git a/config/routes/api.yaml b/config/routes/api.yaml index fe58d73d..459cd408 100644 --- a/config/routes/api.yaml +++ b/config/routes/api.yaml @@ -74,3 +74,8 @@ api_estimate: path: /api/estimate controller: App\Controller\APIController::getEstimate methods: [POST] + +api_ongoing: + path: /api/job_order/ongoing + controller: App\Controller\APIController::getOngoing + methods: [GET] diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 9bc09d7e..c13a7023 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -11,12 +11,14 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\JsonResponse; use App\Ramcar\APIResult; +use App\Ramcar\JOStatus; use App\Entity\MobileSession; use App\Entity\Customer; use App\Entity\VehicleManufacturer; use App\Entity\Vehicle; use App\Entity\CustomerVehicle; +use App\Entity\JobOrder; use DateTime; @@ -682,4 +684,49 @@ class APIController extends Controller return $res->getReturnResponse(); } + + public function getOngoing(Request $req) + { + $required_params = []; + $em = $this->getDoctrine()->getManager(); + $res = $this->checkParamsAndKey($req, $em, $required_params); + if ($res->isError()) + return $res->getReturnResponse(); + + // get customer + $cust = $this->session->getCustomer(); + if ($cust == null) + { + $res->setError(true) + ->setErrorMessage('No customer information found'); + return $res->getReturnResponse(); + } + + // check if we have an ongoing job order + $ongoing_jos = $em->getRepository(JobOrder::class)->findBy([ + 'customer' => $cust, + 'status' => [JOStatus::PENDING, JOStatus::RIDER_ASSIGN, JOStatus::ASSIGNED, JOStatus::IN_PROGRESS], + ]); + + // initialize data + $data = []; + + // no ongoing + if (count($ongoing_jos) <= 0) + { + $data = [ + 'has_ongoing' => false, + ]; + } + else + { + $data = [ + 'has_ongoing' => true, + ]; + } + + $res->setData($data); + + return $res->getReturnResponse(); + } }