Add country code to constructor of RiderAPIHandler service. #311

This commit is contained in:
Korina Cordero 2020-01-31 06:04:18 +00:00
parent 3e5ea688bc
commit 35ccaa73c3
2 changed files with 133 additions and 2 deletions

View file

@ -197,7 +197,13 @@ services:
App\Service\RiderAssignmentHandlerInterface: "@App\\Service\\RiderAssignmentHandler\\CMBRiderAssignmentHandler"
# rider API service
App\Service\RiderAPIHandler\CMBRiderAPIHandler: ~
App\Service\RiderAPIHandler\CMBRiderAPIHandler:
arguments:
$country_code: "%env(COUNTRY_CODE)%"
#App\Service\RiderAPIHandler\ResqRiderAPIHandler:
# arguments:
# $country_code: "%env(COUNTRY_CODE)%"
# rider API interface
App\Service\RiderAPIHandlerInterface: "@App\\Service\\RiderAPIHandler\\CMBRiderAPIHandler"

View file

@ -23,15 +23,18 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
protected $redis;
protected $ef;
protected $rcache;
protected $country_code;
protected $session;
public function __construct(EntityManagerInterface $em, RedisClientProvider $redis,
EncoderFactoryInterface $ef, RiderCache $rcache)
EncoderFactoryInterface $ef, RiderCache $rcache,
string $country_code)
{
$this->em = $em;
$this->redis = $redis;
$this->ef = $ef;
$this->rcache = $rcache;
$this->country_code = $country_code;
// one device = one session, since we have control over the devices
// when a rider logs in, we just change the rider assigned to the device
@ -214,6 +217,128 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
return $data;
}
public function getJobOrder(Request $req)
{
// get the job order of the rider assigned to this session
$required_params = [];
$data = $this->checkParamsAndKey($req, $required_params);
if (isset($data['error']))
return $data;
// are we logged in?
if (!$this->session->hasRider())
{
$data = [
'error' => 'No logged in rider.'
];
return $data;
}
$rider = $this->session->getRider();
// do we have a job order?
$jo = $rider->getActiveJobOrder();
if ($jo == null)
{
$data = [
'job_order' => null
];
}
else
{
$coord = $jo->getCoordinates();
$cust = $jo->getCustomer();
$cv = $jo->getCustomerVehicle();
$v = $cv->getVehicle();
$inv = $jo->getInvoice();
$promo = $inv->getPromo();
// invoice items
$inv_items = [];
foreach ($inv->getItems() as $item)
{
$item_batt = $item->getBattery();
if ($item_batt == null)
$batt_id = null;
else
$batt_id = $item_batt->getID();
$inv_items[] = [
'id' => $item->getID(),
'title' => $item->getTitle(),
'qty' => $item->getQuantity(),
'price' => $item->getPrice(),
'batt_id' => $batt_id,
];
}
// promo
if ($promo != null)
{
$promo_data = [
'id' => $promo->getID(),
'name' => $promo->getName(),
'code' => $promo->getCode(),
'discount_rate' => $promo->getDiscountRate(),
'discount_apply' => $promo->getDiscountApply(),
];
}
else
{
$promo_data = null;
}
$trade_in_type = $jo->getTradeInType();
if (empty($trade_in_type))
$trade_in_type = 'none';
$data = [
'job_order' => [
'id' => $jo->getID(),
'service_type' => $jo->getServiceType(),
'date_schedule' => $jo->getDateSchedule()->format('Ymd H:i:s'),
'longitude' => $coord->getLongitude(),
'latitude' => $coord->getLatitude(),
'status' => $jo->getStatus(),
'customer' => [
'title' => $cust->getTitle(),
'first_name' => $cust->getFirstName(),
'last_name' => $cust->getLastName(),
'phone_mobile' => $this->country_code . $cust->getPhoneMobile(),
],
'vehicle' => [
'manufacturer' => $v->getManufacturer()->getName(),
'make' => $v->getMake(),
'model' => $cv->getModelYear(),
'plate_number' => $cv->getPlateNumber(),
'color' => $cv->getColor(),
],
'or_num' => $jo->getORNum(),
'or_name' => $jo->getORName(),
'delivery_instructions' => $jo->getDeliveryInstructions(),
'delivery_address' => $jo->getDeliveryAddress(),
'landmark' => $jo->getLandmark(),
'invoice' => [
'discount' => $inv->getDiscount(),
'trade_in' => $inv->getTradeIn(),
'total_price' => $inv->getTotalPrice(),
'vat' => $inv->getVat(),
'items' => $inv_items,
],
'mode_of_payment' => $jo->getModeOfPayment(),
'trade_in_type' => $trade_in_type,
'promo' => $promo_data,
// TODO: load the actual
'has_warranty_doc' => false,
'flag_coolant' => $jo->hasCoolant(),
'has_motolite' => $cv->hasMotoliteBattery(),
]
];
}
return $data;
}
protected function checkMissingParameters(Request $req, $params = [])
{
$missing = [];