Add sending of SMS to hub if hub gets filtered out for no stock. #553
This commit is contained in:
parent
3a5d57e35c
commit
3c9070673f
3 changed files with 56 additions and 2 deletions
|
|
@ -23,7 +23,7 @@ class HubCriteria
|
||||||
$this->limit_distance = 500;
|
$this->limit_distance = 500;
|
||||||
$this->jo_type = '';
|
$this->jo_type = '';
|
||||||
$this->date_time = null;
|
$this->date_time = null;
|
||||||
$this->has_inventory = false;
|
$this->flag_inventory_check = true;
|
||||||
$this->items = [];
|
$this->items = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ namespace App\Service;
|
||||||
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
||||||
|
|
||||||
use App\Entity\Hub;
|
use App\Entity\Hub;
|
||||||
|
|
@ -11,6 +13,7 @@ use App\Entity\Hub;
|
||||||
use App\Service\HubDistributor;
|
use App\Service\HubDistributor;
|
||||||
use App\Service\InventoryManager;
|
use App\Service\InventoryManager;
|
||||||
use App\Service\HubFilterLogger;
|
use App\Service\HubFilterLogger;
|
||||||
|
use App\Service\RisingTideGateway;
|
||||||
|
|
||||||
use App\Ramcar\HubCriteria;
|
use App\Ramcar\HubCriteria;
|
||||||
use App\Ramcar\ServiceType;
|
use App\Ramcar\ServiceType;
|
||||||
|
|
@ -21,14 +24,19 @@ class HubSelector
|
||||||
protected $im;
|
protected $im;
|
||||||
protected $hub_distributor;
|
protected $hub_distributor;
|
||||||
protected $hub_filter_logger;
|
protected $hub_filter_logger;
|
||||||
|
protected $trans;
|
||||||
|
protected $rt;
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $em, InventoryManager $im,
|
public function __construct(EntityManagerInterface $em, InventoryManager $im,
|
||||||
HubDistributor $hub_distributor, HubFilterLogger $hub_filter_logger)
|
HubDistributor $hub_distributor, HubFilterLogger $hub_filter_logger,
|
||||||
|
TranslatorInterface $trans, RisingTideGateway $rt)
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
$this->im = $im;
|
$this->im = $im;
|
||||||
$this->hub_distributor = $hub_distributor;
|
$this->hub_distributor = $hub_distributor;
|
||||||
$this->hub_filter_logger = $hub_filter_logger;
|
$this->hub_filter_logger = $hub_filter_logger;
|
||||||
|
$this->trans = $trans;
|
||||||
|
$this->rt = $rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function find(HubCriteria $criteria)
|
public function find(HubCriteria $criteria)
|
||||||
|
|
@ -209,7 +217,19 @@ class HubSelector
|
||||||
'duration' => $hub_data['duration'],
|
'duration' => $hub_data['duration'],
|
||||||
];
|
];
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
// get the skus for the message
|
||||||
|
$sku_text = '';
|
||||||
|
foreach ($items as $key => $value)
|
||||||
|
{
|
||||||
|
$sku_text .= ' ' . $key;
|
||||||
|
}
|
||||||
|
// send SMS to hub
|
||||||
|
$message = str_replace('item_display', trim($sku_text), $this->trans->trans('no_inventory_message'));
|
||||||
|
error_log($message);
|
||||||
|
$this->sendSMSMessage($hub, $items);
|
||||||
$this->hub_filter_logger->logFilteredHub($hub, 'inventory');
|
$this->hub_filter_logger->logFilteredHub($hub, 'inventory');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ($jo_type == ServiceType::BATTERY_REPLACEMENT_WARRANTY)
|
if ($jo_type == ServiceType::BATTERY_REPLACEMENT_WARRANTY)
|
||||||
{
|
{
|
||||||
|
|
@ -223,7 +243,19 @@ class HubSelector
|
||||||
'duration' => $hub_data['duration'],
|
'duration' => $hub_data['duration'],
|
||||||
];
|
];
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
// get the skus for the message
|
||||||
|
$sku_text = '';
|
||||||
|
foreach ($items as $key => $value)
|
||||||
|
{
|
||||||
|
$sku_text .= ' ' . $key;
|
||||||
|
}
|
||||||
|
// send SMS to hub
|
||||||
|
$message = str_replace('item_display', trim($sku_text), $this->trans->trans('no_inventory_message'));
|
||||||
|
error_log($message);
|
||||||
|
$this->sendSMSMessage($hub, $items);
|
||||||
$this->hub_filter_logger->logFilteredHub($hub, 'inventory');
|
$this->hub_filter_logger->logFilteredHub($hub, 'inventory');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -231,6 +263,27 @@ class HubSelector
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function sendSMSMessage($hub, $items)
|
||||||
|
{
|
||||||
|
// compose message
|
||||||
|
// get the skus for the message
|
||||||
|
$sku_text = '';
|
||||||
|
foreach ($items as $key => $value)
|
||||||
|
{
|
||||||
|
$sku_text .= ' ' . $key;
|
||||||
|
}
|
||||||
|
$message = str_replace('item_display', trim($sku_text), $this->trans->trans('no_inventory_message'));
|
||||||
|
error_log($message);
|
||||||
|
|
||||||
|
// get hub notification number
|
||||||
|
$mobile_number = $hub->getNotifNumber();
|
||||||
|
|
||||||
|
// TODO: what if hub has no notif number?
|
||||||
|
// send SMS message
|
||||||
|
error_log('sending sms to - ' . $mobile_number);
|
||||||
|
$this->rt->sendSMS($mobile_number, 'MOTOLITE', $message);
|
||||||
|
}
|
||||||
|
|
||||||
protected function getClosestHubs(Point $point, $limit_distance)
|
protected function getClosestHubs(Point $point, $limit_distance)
|
||||||
{
|
{
|
||||||
// get closest hubs based on st_distance function from db
|
// get closest hubs based on st_distance function from db
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ add_cust_vehicle_battery_info: This vehicle is using a Motolite battery
|
||||||
jo_title_pdf: Motolite Res-Q Job Order
|
jo_title_pdf: Motolite Res-Q Job Order
|
||||||
country_code_prefix: '+63'
|
country_code_prefix: '+63'
|
||||||
delivery_instructions_label: Delivery Instructions
|
delivery_instructions_label: Delivery Instructions
|
||||||
|
no_inventory_message: No stock for [item_display]
|
||||||
|
|
||||||
# images
|
# images
|
||||||
image_logo_login: /assets/images/logo-resq.png
|
image_logo_login: /assets/images/logo-resq.png
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue