Resolve "Resq - sms message to customer upon JO completion" #1354

Merged
korina.cordero merged 5 commits from 464-resq-sms-message-to-customer-upon-jo-completion into 465-resq-august-13-release 2020-08-12 05:46:08 +00:00
2 changed files with 30 additions and 15 deletions

View file

@ -47,6 +47,7 @@ use App\Service\WarrantyHandler;
use App\Service\MQTTClient; use App\Service\MQTTClient;
use App\Service\APNSClient; use App\Service\APNSClient;
use App\Service\MapTools; use App\Service\MapTools;
use App\Service\RisingTideGateway;
use CrEOF\Spatial\PHP\Types\Geometry\Point; use CrEOF\Spatial\PHP\Types\Geometry\Point;
@ -67,13 +68,14 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
protected $rah; protected $rah;
protected $country_code; protected $country_code;
protected $wh; protected $wh;
protected $rt;
protected $template_hash; protected $template_hash;
public function __construct(Security $security, EntityManagerInterface $em, public function __construct(Security $security, EntityManagerInterface $em,
InvoiceGeneratorInterface $ic, ValidatorInterface $validator, InvoiceGeneratorInterface $ic, ValidatorInterface $validator,
TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah, TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah,
string $country_code, WarrantyHandler $wh) string $country_code, WarrantyHandler $wh, RisingTideGateway $rt)
{ {
$this->em = $em; $this->em = $em;
$this->ic = $ic; $this->ic = $ic;
@ -83,6 +85,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$this->rah = $rah; $this->rah = $rah;
$this->country_code = $country_code; $this->country_code = $country_code;
$this->wh = $wh; $this->wh = $wh;
$this->rt = $rt;
$this->loadTemplates(); $this->loadTemplates();
} }
@ -862,17 +865,6 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
else else
$reason = $req->request->get('no_wait_reason'); $reason = $req->request->get('no_wait_reason');
// check if trade in
$is_trade_in = $req->request->get('invoice_trade_in_type');
$no_trade_in_reason = '';
if (empty($is_trade_in))
{
$no_trade_in_reason = $req->request->get('no_trade_in_reason');
if (empty($no_trade_in_reason))
$error_array['no_trade_in_reason'] = 'No trade in reason required.';
}
if (empty($error_array)) { if (empty($error_array)) {
// coordinates // coordinates
$point = new Point($req->request->get('coord_lng'), $req->request->get('coord_lat')); $point = new Point($req->request->get('coord_lng'), $req->request->get('coord_lat'));
@ -890,8 +882,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
->setDeliveryAddress($req->request->get('delivery_address')) ->setDeliveryAddress($req->request->get('delivery_address'))
->setLandmark($req->request->get('landmark')) ->setLandmark($req->request->get('landmark'))
->setWillingToWait($req->request->get('flag_will_wait', false)) ->setWillingToWait($req->request->get('flag_will_wait', false))
->setReasonsNotWait($reason) ->setReasonsNotWait($reason);
->setNoTradeInReason($no_trade_in_reason);
// validate // validate
$errors = $this->validator->validate($obj); $errors = $this->validator->validate($obj);
@ -982,6 +973,11 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
else else
error_log('Invalid plate number for warranty. Plate number = ' . $obj->getCustomerVehicle()->getPlateNumber()); error_log('Invalid plate number for warranty. Plate number = ' . $obj->getCustomerVehicle()->getPlateNumber());
} }
// send SMS to customer
$phone_number = $obj->getCustomer()->getPhoneMobile();
if (!empty($phone_number))
$this->sendSMSToCustomer($phone_number);
} }
} }
@ -3161,4 +3157,11 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$em->flush(); $em->flush();
} }
public function sendSMSToCustomer($phone_number)
{
// TODO: put this in config file or somewhere
$message = "Your Resq job order has been completed.";
$this->rt->sendSMS($phone_number, 'MOTOLITE', $message);
}
} }

View file

@ -21,6 +21,7 @@ use App\Service\MQTTClient;
use App\Service\WarrantyHandler; use App\Service\WarrantyHandler;
use App\Service\JobOrderHandlerInterface; use App\Service\JobOrderHandlerInterface;
use App\Service\InvoiceGeneratorInterface; use App\Service\InvoiceGeneratorInterface;
use App\Service\RisingTideGateway;
use App\Entity\RiderSession; use App\Entity\RiderSession;
use App\Entity\Rider; use App\Entity\Rider;
@ -45,12 +46,13 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
protected $jo_handler; protected $jo_handler;
protected $ic; protected $ic;
protected $session; protected $session;
protected $rt;
public function __construct(EntityManagerInterface $em, RedisClientProvider $redis, public function __construct(EntityManagerInterface $em, RedisClientProvider $redis,
EncoderFactoryInterface $ef, RiderCache $rcache, EncoderFactoryInterface $ef, RiderCache $rcache,
string $country_code, MQTTClient $mclient, string $country_code, MQTTClient $mclient,
WarrantyHandler $wh, JobOrderHandlerInterface $jo_handler, WarrantyHandler $wh, JobOrderHandlerInterface $jo_handler,
InvoiceGeneratorInterface $ic) InvoiceGeneratorInterface $ic, RisingTideGateway $rt)
{ {
$this->em = $em; $this->em = $em;
$this->redis = $redis; $this->redis = $redis;
@ -61,6 +63,7 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
$this->wh = $wh; $this->wh = $wh;
$this->jo_handler = $jo_handler; $this->jo_handler = $jo_handler;
$this->ic = $ic; $this->ic = $ic;
$this->rt = $rt;
// one device = one session, since we have control over the devices // 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 // when a rider logs in, we just change the rider assigned to the device
@ -523,6 +526,15 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
// save to customer vehicle battery record // save to customer vehicle battery record
$this->jo_handler->updateVehicleBattery($jo); $this->jo_handler->updateVehicleBattery($jo);
// send SMS to customer
$phone_number = $jo->getCustomer()->getPhoneMobile();
if (!empty($phone_number))
{
// TODO: put this in config file or somewhere
$message = "Your Resq job order has been completed.";
$this->rt->sendSMS($phone_number, 'MOTOLITE', $message);
}
$this->em->flush(); $this->em->flush();
// create warranty // create warranty