Add date_status_change for job order entity and refactor rider api job order data generation #424
This commit is contained in:
parent
ef7e362c7d
commit
0d89cab165
4 changed files with 97 additions and 91 deletions
|
|
@ -88,25 +88,10 @@ class CMBRAPIController extends Controller
|
||||||
|
|
||||||
public function getJobOrder(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
public function getJobOrder(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
||||||
{
|
{
|
||||||
$res = new NewAPIResult();
|
|
||||||
|
|
||||||
$data = $rapi_handler->getJobOrder($req);
|
$data = $rapi_handler->getJobOrder($req);
|
||||||
|
|
||||||
if (isset($data['error']))
|
$res = $this->generateResultFromHandler($data);
|
||||||
{
|
|
||||||
$message = $data['error'];
|
|
||||||
$title = $data['title'];
|
|
||||||
|
|
||||||
$res->setError(true)
|
|
||||||
->setErrorTitle($title)
|
|
||||||
->setErrorMessage($message);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$res->setData($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
// response
|
|
||||||
return $res->getReturnResponse();
|
return $res->getReturnResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -134,27 +119,6 @@ class CMBRAPIController extends Controller
|
||||||
return $res->getReturnResponse();
|
return $res->getReturnResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function generateResultFromHandler($data)
|
|
||||||
{
|
|
||||||
$res = new NewAPIResult();
|
|
||||||
|
|
||||||
if (isset($data['error']))
|
|
||||||
{
|
|
||||||
$message = $data['error'];
|
|
||||||
$title = $data['title'];
|
|
||||||
|
|
||||||
$res->setError(true)
|
|
||||||
->setErrorTitle($title)
|
|
||||||
->setErrorMessage($message);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$res->setData($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function cancelJobOrder(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
public function cancelJobOrder(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
||||||
{
|
{
|
||||||
$res = new NewAPIResult();
|
$res = new NewAPIResult();
|
||||||
|
|
@ -768,4 +732,25 @@ class CMBRAPIController extends Controller
|
||||||
return $res->getReturnResponse();
|
return $res->getReturnResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function generateResultFromHandler($data)
|
||||||
|
{
|
||||||
|
$res = new NewAPIResult();
|
||||||
|
|
||||||
|
if (isset($data['error']))
|
||||||
|
{
|
||||||
|
$message = $data['error'];
|
||||||
|
$title = $data['title'];
|
||||||
|
|
||||||
|
$res->setError(true)
|
||||||
|
->setErrorTitle($title)
|
||||||
|
->setErrorMessage($message);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$res->setData($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -340,6 +340,12 @@ class JobOrder
|
||||||
*/
|
*/
|
||||||
protected $jo_extra;
|
protected $jo_extra;
|
||||||
|
|
||||||
|
// date that the status last changed
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="datetime", nullable=true)
|
||||||
|
*/
|
||||||
|
protected $date_status_change;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->date_create = new DateTime();
|
$this->date_create = new DateTime();
|
||||||
|
|
@ -589,6 +595,7 @@ class JobOrder
|
||||||
{
|
{
|
||||||
// TODO: validate status
|
// TODO: validate status
|
||||||
$this->status = $status;
|
$this->status = $status;
|
||||||
|
$this->date_status_change = new DateTime();
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -602,6 +609,11 @@ class JobOrder
|
||||||
return JOStatus::getName($this->status);
|
return JOStatus::getName($this->status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDateStatusChange()
|
||||||
|
{
|
||||||
|
return $this->date_status_change;
|
||||||
|
}
|
||||||
|
|
||||||
public function setDeliveryInstructions($delivery_instructions)
|
public function setDeliveryInstructions($delivery_instructions)
|
||||||
{
|
{
|
||||||
$this->delivery_instructions = $delivery_instructions;
|
$this->delivery_instructions = $delivery_instructions;
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ class JOStatus extends NameValue
|
||||||
const PENDING = 'pending'; // JO has no hub assigned
|
const PENDING = 'pending'; // JO has no hub assigned
|
||||||
const RIDER_ASSIGN = 'rider_assign'; // JO has hub assigned but no rider assigned
|
const RIDER_ASSIGN = 'rider_assign'; // JO has hub assigned but no rider assigned
|
||||||
const ASSIGNED = 'assigned'; // JO has hub and rider assigned
|
const ASSIGNED = 'assigned'; // JO has hub and rider assigned
|
||||||
const IN_TRANSIT = 'in_transit'; // JO's rider is on his way
|
const IN_TRANSIT = 'in_transit'; // Rider is on his way
|
||||||
const IN_PROGRESS = 'in_progress'; // JO fulfillment in progress
|
const IN_PROGRESS = 'in_progress'; // Rider has arrived at customer's location and fulfillment is in progress
|
||||||
const PERFORMED = 'performed'; // Rider has finished performing JO task / service
|
const PERFORMED = 'performed'; // Rider has finished performing JO task / service
|
||||||
const PAID = 'paid'; // Rider has finished collecting payment for JO
|
const PAID = 'paid'; // Rider has finished collecting payment for JO
|
||||||
const CANCELLED = 'cancelled'; // JO is cancelled
|
const CANCELLED = 'cancelled'; // JO is cancelled
|
||||||
|
|
|
||||||
|
|
@ -605,18 +605,8 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getJobOrder(Request $req)
|
protected function formatJobOrderData($jo)
|
||||||
{
|
{
|
||||||
$required_params = [
|
|
||||||
'jo_id'
|
|
||||||
];
|
|
||||||
$data = $this->checkJO($req, $required_params, $jo);
|
|
||||||
if (isset($data['error']))
|
|
||||||
{
|
|
||||||
$data['title'] = 'Failed Get Job Order';
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
$coord = $jo->getCoordinates();
|
$coord = $jo->getCoordinates();
|
||||||
$cust = $jo->getCustomer();
|
$cust = $jo->getCustomer();
|
||||||
$cv = $jo->getCustomerVehicle();
|
$cv = $jo->getCustomerVehicle();
|
||||||
|
|
@ -664,47 +654,66 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
||||||
$trade_in_type = 'none';
|
$trade_in_type = 'none';
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'job_order' => [
|
'id' => $jo->getID(),
|
||||||
'id' => $jo->getID(),
|
'service_type' => $jo->getServiceType(),
|
||||||
'service_type' => $jo->getServiceType(),
|
'date_schedule' => $jo->getDateSchedule()->format('Ymd H:i:s'),
|
||||||
'date_schedule' => $jo->getDateSchedule()->format('Ymd H:i:s'),
|
'longitude' => $coord->getLongitude(),
|
||||||
'longitude' => $coord->getLongitude(),
|
'latitude' => $coord->getLatitude(),
|
||||||
'latitude' => $coord->getLatitude(),
|
'status' => $jo->getStatus(),
|
||||||
'status' => $jo->getStatus(),
|
'customer' => [
|
||||||
'customer' => [
|
'title' => $cust->getTitle(),
|
||||||
'title' => $cust->getTitle(),
|
'first_name' => $cust->getFirstName(),
|
||||||
'first_name' => $cust->getFirstName(),
|
'last_name' => $cust->getLastName(),
|
||||||
'last_name' => $cust->getLastName(),
|
'phone_mobile' => $this->country_code . $cust->getPhoneMobile(),
|
||||||
'phone_mobile' => $this->country_code . $cust->getPhoneMobile(),
|
'phone_landline' => $this->country_code . $cust->getPhoneLandline(),
|
||||||
'phone_landline' => $this->country_code . $cust->getPhoneLandline(),
|
],
|
||||||
],
|
'vehicle' => [
|
||||||
'vehicle' => [
|
'manufacturer' => $v->getManufacturer()->getName(),
|
||||||
'manufacturer' => $v->getManufacturer()->getName(),
|
'make' => $v->getMake(),
|
||||||
'make' => $v->getMake(),
|
'model' => $cv->getModelYear(),
|
||||||
'model' => $cv->getModelYear(),
|
'plate_number' => $cv->getPlateNumber(),
|
||||||
'plate_number' => $cv->getPlateNumber(),
|
'color' => $cv->getColor(),
|
||||||
'color' => $cv->getColor(),
|
],
|
||||||
],
|
'or_num' => $jo->getORNum(),
|
||||||
'or_num' => $jo->getORNum(),
|
'or_name' => $jo->getORName(),
|
||||||
'or_name' => $jo->getORName(),
|
'delivery_instructions' => $jo->getDeliveryInstructions(),
|
||||||
'delivery_instructions' => $jo->getDeliveryInstructions(),
|
'delivery_address' => $jo->getDeliveryAddress(),
|
||||||
'delivery_address' => $jo->getDeliveryAddress(),
|
'landmark' => $jo->getLandmark(),
|
||||||
'landmark' => $jo->getLandmark(),
|
'invoice' => [
|
||||||
'invoice' => [
|
'discount' => $inv->getDiscount(),
|
||||||
'discount' => $inv->getDiscount(),
|
'trade_in' => $inv->getTradeIn(),
|
||||||
'trade_in' => $inv->getTradeIn(),
|
'total_price' => $inv->getTotalPrice(),
|
||||||
'total_price' => $inv->getTotalPrice(),
|
'vat' => $inv->getVat(),
|
||||||
'vat' => $inv->getVat(),
|
'items' => $inv_items,
|
||||||
'items' => $inv_items,
|
],
|
||||||
],
|
'mode_of_payment' => $jo->getModeOfPayment(),
|
||||||
'mode_of_payment' => $jo->getModeOfPayment(),
|
'trade_in_type' => $trade_in_type,
|
||||||
'trade_in_type' => $trade_in_type,
|
'promo' => $promo_data,
|
||||||
'promo' => $promo_data,
|
// TODO: load the actual
|
||||||
// TODO: load the actual
|
'has_warranty_doc' => false,
|
||||||
'has_warranty_doc' => false,
|
'flag_coolant' => $jo->hasCoolant(),
|
||||||
'flag_coolant' => $jo->hasCoolant(),
|
'has_motolite' => $cv->hasMotoliteBattery(),
|
||||||
'has_motolite' => $cv->hasMotoliteBattery(),
|
];
|
||||||
]
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getJobOrder(Request $req)
|
||||||
|
{
|
||||||
|
$required_params = [
|
||||||
|
'jo_id'
|
||||||
|
];
|
||||||
|
$data = $this->checkJO($req, $required_params, $jo);
|
||||||
|
if (isset($data['error']))
|
||||||
|
{
|
||||||
|
$data['title'] = 'Failed Get Job Order';
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
$jo_data = $this->formatJobOrderData($jo);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'job_order' => $jo_data
|
||||||
];
|
];
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue