Generate JO ID before hub selection on user app API, add additional params to HubCriteria for JORejection and SMS #800
This commit is contained in:
parent
aae4aaa390
commit
6dfaeee799
4 changed files with 133 additions and 49 deletions
|
|
@ -488,6 +488,8 @@ class JobOrderController extends ApiController
|
||||||
JobOrderManager $jo_manager,
|
JobOrderManager $jo_manager,
|
||||||
PriceTierManager $pt_manager
|
PriceTierManager $pt_manager
|
||||||
) {
|
) {
|
||||||
|
//error_log("CREATING JOB ORDER WITH PARAMS " . print_r($req->request->all(), true));
|
||||||
|
|
||||||
// validate params
|
// validate params
|
||||||
$validity = $this->validateRequest($req, [
|
$validity = $this->validateRequest($req, [
|
||||||
'service_type',
|
'service_type',
|
||||||
|
|
@ -575,6 +577,8 @@ class JobOrderController extends ApiController
|
||||||
$flag_advance_order = true;
|
$flag_advance_order = true;
|
||||||
// $flag_advance_order = $advance_order ? true : false;
|
// $flag_advance_order = $advance_order ? true : false;
|
||||||
|
|
||||||
|
//error_log("RUNNING QUERY NEXT");
|
||||||
|
|
||||||
$jo = new JobOrder();
|
$jo = new JobOrder();
|
||||||
$jo->setSource(TransactionOrigin::MOBILE_APP)
|
$jo->setSource(TransactionOrigin::MOBILE_APP)
|
||||||
->setStatus(JOStatus::PENDING)
|
->setStatus(JOStatus::PENDING)
|
||||||
|
|
@ -643,6 +647,8 @@ class JobOrderController extends ApiController
|
||||||
$icrit->addPromo($promo);
|
$icrit->addPromo($promo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//error_log("CONTINUING QUERY BUILDING");
|
||||||
|
|
||||||
// check customer vehicle
|
// check customer vehicle
|
||||||
$cv = $this->em->getRepository(CustomerVehicle::class)->find($req->request->get('cv_id'));
|
$cv = $this->em->getRepository(CustomerVehicle::class)->find($req->request->get('cv_id'));
|
||||||
if ($cv == null) {
|
if ($cv == null) {
|
||||||
|
|
@ -708,6 +714,13 @@ class JobOrderController extends ApiController
|
||||||
$invoice = $ic->generateInvoice($icrit);
|
$invoice = $ic->generateInvoice($icrit);
|
||||||
$jo->setInvoice($invoice);
|
$jo->setInvoice($invoice);
|
||||||
|
|
||||||
|
//error_log("GENERATED INVOICE");
|
||||||
|
|
||||||
|
// save here first so we have a JO ID which is required for the hub selector
|
||||||
|
$this->em->persist($invoice);
|
||||||
|
$this->em->persist($jo);
|
||||||
|
$this->em->flush();
|
||||||
|
|
||||||
// assign hub and rider
|
// assign hub and rider
|
||||||
// check if hub is null
|
// check if hub is null
|
||||||
if ($hub == null) {
|
if ($hub == null) {
|
||||||
|
|
@ -715,6 +728,13 @@ class JobOrderController extends ApiController
|
||||||
$hub_criteria = new HubCriteria();
|
$hub_criteria = new HubCriteria();
|
||||||
$hub_criteria->setPoint($jo->getCoordinates());
|
$hub_criteria->setPoint($jo->getCoordinates());
|
||||||
|
|
||||||
|
// set job order info
|
||||||
|
$hub_criteria->setJobOrderId($jo->getID())
|
||||||
|
->setJoType($jo->getServiceType())
|
||||||
|
->setCustomerClass($cust->getCustomerClassification())
|
||||||
|
->setOrderDate($jo->getDateCreate())
|
||||||
|
->setServiceType($jo->getServiceType());
|
||||||
|
|
||||||
// get distance limit for mobile from env
|
// get distance limit for mobile from env
|
||||||
// get value of hub_filter_enable from env
|
// get value of hub_filter_enable from env
|
||||||
$limit_distance = $_ENV['CUST_DISTANCE_LIMIT'];
|
$limit_distance = $_ENV['CUST_DISTANCE_LIMIT'];
|
||||||
|
|
@ -845,8 +865,10 @@ class JobOrderController extends ApiController
|
||||||
$hub_dist->incrementJoCountForHub($hub);
|
$hub_dist->incrementJoCountForHub($hub);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//error_log("DONE SELECTING HUB");
|
||||||
|
|
||||||
|
// save additional hub related changes
|
||||||
$this->em->persist($jo);
|
$this->em->persist($jo);
|
||||||
$this->em->persist($invoice);
|
|
||||||
|
|
||||||
// add event log for JO
|
// add event log for JO
|
||||||
$event = new JOEvent();
|
$event = new JOEvent();
|
||||||
|
|
@ -957,6 +979,8 @@ class JobOrderController extends ApiController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//error_log("DONE CREATING JOB ORDER " . $jo->getID());
|
||||||
|
|
||||||
// response
|
// response
|
||||||
return new ApiResponse(true, '', [
|
return new ApiResponse(true, '', [
|
||||||
'jo_id' => $jo->getID(),
|
'jo_id' => $jo->getID(),
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,9 @@ class HubCriteria
|
||||||
protected $flag_round_robin; // flag if we use round robin or not
|
protected $flag_round_robin; // flag if we use round robin or not
|
||||||
protected $jo_id; // JO id. This is null if called from mobile API
|
protected $jo_id; // JO id. This is null if called from mobile API
|
||||||
protected $customer_id; // customer id
|
protected $customer_id; // customer id
|
||||||
|
protected $customer_class; // customer class
|
||||||
|
protected $order_date; // date JO was created
|
||||||
|
protected $service_type; // service type of JO
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
|
@ -33,10 +36,13 @@ class HubCriteria
|
||||||
$this->flag_riders_check = false;
|
$this->flag_riders_check = false;
|
||||||
$this->items = [];
|
$this->items = [];
|
||||||
$this->payment_method = '';
|
$this->payment_method = '';
|
||||||
$flag_emergency = false;
|
$this->flag_emergency = false;
|
||||||
$flag_round_robin = false;
|
$this->flag_round_robin = false;
|
||||||
$jo_id = null;
|
$this->jo_id = null;
|
||||||
$customer_id = null;
|
$this->customer_id = null;
|
||||||
|
$this->customer_class = null;
|
||||||
|
$this->order_date = new DateTime();
|
||||||
|
$this->service_type = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPoint(Point $point)
|
public function setPoint(Point $point)
|
||||||
|
|
@ -184,5 +190,37 @@ class HubCriteria
|
||||||
return $this->customer_id;
|
return $this->customer_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setCustomerClass($customer_class)
|
||||||
|
{
|
||||||
|
$this->customer_class = $customer_class;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCustomerClass()
|
||||||
|
{
|
||||||
|
return $this->customer_class;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setOrderDate($order_date)
|
||||||
|
{
|
||||||
|
$this->order_date = $order_date;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOrderDate()
|
||||||
|
{
|
||||||
|
return $this->order_date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setServiceType($service_type)
|
||||||
|
{
|
||||||
|
$this->service_type = $service_type;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getServiceType()
|
||||||
|
{
|
||||||
|
return $this->service_type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,13 +60,14 @@ class HubSelector
|
||||||
$flag_round_robin = $criteria->isRoundRobin();
|
$flag_round_robin = $criteria->isRoundRobin();
|
||||||
$jo_id = $criteria->getJobOrderId();
|
$jo_id = $criteria->getJobOrderId();
|
||||||
$customer_id = $criteria->getCustomerId();
|
$customer_id = $criteria->getCustomerId();
|
||||||
|
$customer_class = $criteria->getCustomerClass();
|
||||||
|
|
||||||
|
// needed for JORejection records and SMS notifs
|
||||||
|
$order_date = $criteria->getOrderDate();
|
||||||
|
$service_type = $criteria->getServiceType();
|
||||||
|
|
||||||
$results = [];
|
$results = [];
|
||||||
|
|
||||||
// get the job order object and customer class
|
|
||||||
$jo = $this->em->getRepository(JobOrder::class)->find($jo_id);
|
|
||||||
$customer_class = $jo->getCustomer()->getCustomerClassification();
|
|
||||||
|
|
||||||
// error_log('payment methods ' . $payment_method);
|
// error_log('payment methods ' . $payment_method);
|
||||||
// error_log('distance limit ' . $limit_distance);
|
// error_log('distance limit ' . $limit_distance);
|
||||||
// error_log('emergency flag ' . $flag_emergency);
|
// error_log('emergency flag ' . $flag_emergency);
|
||||||
|
|
@ -104,13 +105,13 @@ class HubSelector
|
||||||
}
|
}
|
||||||
|
|
||||||
// only enable rider and inventory checks if not VIP
|
// only enable rider and inventory checks if not VIP
|
||||||
if ($customer_class !== CustomerClassification::VIP) {
|
if (!empty($customer_class) && $customer_class !== CustomerClassification::VIP) {
|
||||||
// available riders filter
|
// available riders filter
|
||||||
$hubs_riders = $this->filterHubsByRiderAvailability($filtered_hubs, $flag_riders_check, $jo_type, $jo, $customer_id);
|
$hubs_riders = $this->filterHubsByRiderAvailability($filtered_hubs, $flag_riders_check, $jo_id, $customer_id, $order_date, $service_type);
|
||||||
$filtered_hubs = $hubs_riders;
|
$filtered_hubs = $hubs_riders;
|
||||||
|
|
||||||
// inventory filter
|
// inventory filter
|
||||||
$hubs_inventory = $this->filterHubsByInventory($filtered_hubs, $flag_inventory_check, $jo_type, $items, $jo, $customer_id);
|
$hubs_inventory = $this->filterHubsByInventory($filtered_hubs, $flag_inventory_check, $jo_type, $items, $jo_id, $customer_id, $order_date, $service_type);
|
||||||
$filtered_hubs = $hubs_inventory;
|
$filtered_hubs = $hubs_inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -284,10 +285,8 @@ class HubSelector
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function filterHubsByInventory($hubs, $flag_inventory_check, $jo_type, $items, $jo, $customer_id)
|
protected function filterHubsByInventory($hubs, $flag_inventory_check, $jo_type, $items, $jo_id, $customer_id, $order_date, $service_type)
|
||||||
{
|
{
|
||||||
$jo_id = $jo->getID();
|
|
||||||
|
|
||||||
// check if this is enabled
|
// check if this is enabled
|
||||||
if (!$flag_inventory_check) {
|
if (!$flag_inventory_check) {
|
||||||
error_log("INVENTORY CHECK " . $jo_id . ": DISABLED");
|
error_log("INVENTORY CHECK " . $jo_id . ": DISABLED");
|
||||||
|
|
@ -367,21 +366,26 @@ class HubSelector
|
||||||
|
|
||||||
// check if we are filtering this hub
|
// check if we are filtering this hub
|
||||||
if (isset($hubs_to_filter[$branch_code])) {
|
if (isset($hubs_to_filter[$branch_code])) {
|
||||||
// create rejection report entry
|
// if we have a JO, create rejection record and notify
|
||||||
$robj = $this->createRejectionEntry(
|
if (!empty($jo_id)) {
|
||||||
$jo,
|
// create rejection report entry
|
||||||
$hub_obj,
|
$robj = $this->createRejectionEntry(
|
||||||
"SKU(s): " . $battery_string
|
$jo_id,
|
||||||
);
|
$hub_obj,
|
||||||
|
"SKU(s): " . $battery_string
|
||||||
|
);
|
||||||
|
|
||||||
// build SMS message
|
// build SMS message
|
||||||
$this->sendSMSMessage(
|
$this->sendSMSMessage(
|
||||||
$hub_obj,
|
$hub_obj,
|
||||||
$jo,
|
$jo_id,
|
||||||
$robj,
|
$order_date,
|
||||||
JORejectionReason::getName(JORejectionReason::NO_STOCK_SALES),
|
$service_type,
|
||||||
"Requested SKU(s) - " . $battery_string
|
$robj,
|
||||||
);
|
JORejectionReason::getName(JORejectionReason::NO_STOCK_SALES),
|
||||||
|
"Requested SKU(s) - " . $battery_string
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// log this filter
|
// log this filter
|
||||||
$this->hub_filter_logger->logFilteredHub($hub_obj, 'no_inventory', $jo_id, $customer_id);
|
$this->hub_filter_logger->logFilteredHub($hub_obj, 'no_inventory', $jo_id, $customer_id);
|
||||||
|
|
@ -470,7 +474,7 @@ class HubSelector
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function filterHubsByRiderAvailability($hubs, $flag_riders_check, $jo_type, $jo, $customer_id)
|
protected function filterHubsByRiderAvailability($hubs, $flag_riders_check, $jo_id, $customer_id, $order_date, $service_type)
|
||||||
{
|
{
|
||||||
// check if this is enabled
|
// check if this is enabled
|
||||||
if (!$flag_riders_check) {
|
if (!$flag_riders_check) {
|
||||||
|
|
@ -482,7 +486,6 @@ class HubSelector
|
||||||
return $hubs;
|
return $hubs;
|
||||||
}
|
}
|
||||||
|
|
||||||
$jo_id = $jo->getID();
|
|
||||||
$results = [];
|
$results = [];
|
||||||
|
|
||||||
foreach ($hubs as $hub_data) {
|
foreach ($hubs as $hub_data) {
|
||||||
|
|
@ -490,17 +493,22 @@ class HubSelector
|
||||||
|
|
||||||
// check we have available riders
|
// check we have available riders
|
||||||
if ($hub_obj->getAvailableRiders() === 0) {
|
if ($hub_obj->getAvailableRiders() === 0) {
|
||||||
// create rejection report entry
|
// if we have a JO, create rejection record and notify
|
||||||
$robj = $this->createRejectionEntry($jo, $hub_obj);
|
if (!empty($jo_id)) {
|
||||||
|
// create rejection report entry
|
||||||
// build SMS message
|
$robj = $this->createRejectionEntry($jo_id, $hub_obj);
|
||||||
$this->sendSMSMessage(
|
|
||||||
$hub_obj,
|
|
||||||
$jo,
|
|
||||||
$robj,
|
|
||||||
JORejectionReason::getName(JORejectionReason::NO_RIDER_AVAILABLE),
|
|
||||||
);
|
|
||||||
|
|
||||||
|
// build SMS message
|
||||||
|
$this->sendSMSMessage(
|
||||||
|
$hub_obj,
|
||||||
|
$jo_id,
|
||||||
|
$order_date,
|
||||||
|
$service_type,
|
||||||
|
$robj,
|
||||||
|
JORejectionReason::getName(JORejectionReason::NO_RIDER_AVAILABLE),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// log this filter
|
// log this filter
|
||||||
$this->hub_filter_logger->logFilteredHub($hub_obj, 'no_available_rider', $jo_id, $customer_id);
|
$this->hub_filter_logger->logFilteredHub($hub_obj, 'no_available_rider', $jo_id, $customer_id);
|
||||||
|
|
||||||
|
|
@ -616,8 +624,10 @@ class HubSelector
|
||||||
return round(($miles * 1.609344), 1);
|
return round(($miles * 1.609344), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createRejectionEntry($jo, $hub, $remarks = ""): JORejection
|
protected function createRejectionEntry($jo_id, $hub, $remarks = ""): JORejection
|
||||||
{
|
{
|
||||||
|
$jo = $this->em->getRepository(JobOrder::class)->find($jo_id);
|
||||||
|
|
||||||
$robj = new JORejection();
|
$robj = new JORejection();
|
||||||
$robj->setDateCreate(new DateTime())
|
$robj->setDateCreate(new DateTime())
|
||||||
->setHub($hub)
|
->setHub($hub)
|
||||||
|
|
@ -631,15 +641,15 @@ class HubSelector
|
||||||
return $robj;
|
return $robj;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function sendSMSMessage($hub, $jo, $rejection, $reason = "", $remarks = ""): void
|
protected function sendSMSMessage($hub, $jo_id, $order_date, $service_type, $rejection, $reason = "", $remarks = ""): void
|
||||||
{
|
{
|
||||||
$message = 'Job Order #: ' . $jo->getID() . "\n" .
|
$message = 'Job Order #: ' . $jo_id . "\n" .
|
||||||
'Order Date and Time: ' . $jo->getDateCreate()->format('d M Y g:i A') . "\n" .
|
'Order Date and Time: ' . $order_date->format('d M Y g:i A') . "\n" .
|
||||||
'Date and Time Rejected: ' . $rejection->getDateCreate()->format('d M Y g:i A') . "\n" .
|
'Date and Time Rejected: ' . $rejection->getDateCreate()->format('d M Y g:i A') . "\n" .
|
||||||
'Enrollee Name: ' . implode(" - ", [$hub->getName(), $hub->getBranch()]) . "\n" .
|
'Enrollee Name: ' . implode(" - ", [$hub->getName(), $hub->getBranch()]) . "\n" .
|
||||||
'Reason of Rejection: ' . $reason . "\n" .
|
'Reason of Rejection: ' . $reason . "\n" .
|
||||||
'Remarks: ' . $remarks . "\n" .
|
'Remarks: ' . $remarks . "\n" .
|
||||||
'Type of Service: ' . ServiceType::getName($jo->getServiceType());
|
'Type of Service: ' . ServiceType::getName($service_type);
|
||||||
|
|
||||||
error_log("SENDING SMS MESsAGE:\r\n" . $message);
|
error_log("SENDING SMS MESsAGE:\r\n" . $message);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2552,7 +2552,13 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
->setLimitResults(50);
|
->setLimitResults(50);
|
||||||
|
|
||||||
// NOTE: set JO type regardless, for now
|
// NOTE: set JO type regardless, for now
|
||||||
$hub_criteria->setJoType($obj->getServiceType());
|
$hub_criteria->setJoType($obj->getServiceType())
|
||||||
|
->setOrderDate($obj->getDateCreate())
|
||||||
|
->setServiceType($obj->getServiceType());
|
||||||
|
|
||||||
|
// set customer class
|
||||||
|
$cust = $obj->getCustomer();
|
||||||
|
$hub_criteria->setCustomerClass($cust->getCustomerClass());
|
||||||
|
|
||||||
// check if hub filter is enabled. If not, use default values
|
// check if hub filter is enabled. If not, use default values
|
||||||
// for the rest of the HubCriteria fields
|
// for the rest of the HubCriteria fields
|
||||||
|
|
@ -2900,7 +2906,13 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
->setLimitResults(50);
|
->setLimitResults(50);
|
||||||
|
|
||||||
// NOTE: set JO type regardless, for now
|
// NOTE: set JO type regardless, for now
|
||||||
$hub_criteria->setJoType($obj->getServiceType());
|
$hub_criteria->setJoType($obj->getServiceType())
|
||||||
|
->setOrderDate($obj->getDateCreate())
|
||||||
|
->setServiceType($obj->getServiceType());
|
||||||
|
|
||||||
|
// set customer class
|
||||||
|
$cust = $obj->getCustomer();
|
||||||
|
$hub_criteria->setCustomerClass($cust->getCustomerClass());
|
||||||
|
|
||||||
if ($this->hub_geofence->isCovered($long, $lat))
|
if ($this->hub_geofence->isCovered($long, $lat))
|
||||||
{
|
{
|
||||||
|
|
@ -2926,7 +2938,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
|
|
||||||
// get JO and customer id for logging purposes
|
// get JO and customer id for logging purposes
|
||||||
$jo_id = $obj->getID();
|
$jo_id = $obj->getID();
|
||||||
$customer_id = $obj->getCustomer()->getID();
|
$customer_id = $cust->getID();
|
||||||
|
|
||||||
$hub_criteria->setJobOrderId($jo_id)
|
$hub_criteria->setJobOrderId($jo_id)
|
||||||
->setCustomerId($customer_id);
|
->setCustomerId($customer_id);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue