Merge branch 'master' of gitlab.com:jankstudio/resq

This commit is contained in:
Ramon Gutierrez 2018-02-04 16:46:35 +08:00
commit 2b0f97a678
2 changed files with 53 additions and 1 deletions

View file

@ -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]

View file

@ -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;
@ -566,7 +568,7 @@ class APIController extends Controller
$wty_ex = $cv->getWarrantyExpiration()->format('Y-m-d');
$cv_list[] = [
'id' => $cv->getID(),
'cv_id' => $cv->getID(),
'mfg_id' => $cv->getVehicle()->getManufacturer()->getID(),
'make_id' => $cv->getVehicle()->getID(),
'name' => $cv->getName(),
@ -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();
}
}