diff --git a/src/Ramcar/HubCriteria.php b/src/Ramcar/HubCriteria.php index 2c91654f..e211e9dc 100644 --- a/src/Ramcar/HubCriteria.php +++ b/src/Ramcar/HubCriteria.php @@ -23,7 +23,7 @@ class HubCriteria $this->limit_distance = 500; $this->jo_type = ''; $this->date_time = null; - $this->has_inventory = false; + $this->flag_inventory_check = true; $this->items = []; } diff --git a/src/Service/HubSelector.php b/src/Service/HubSelector.php index ea55b160..d984ddff 100644 --- a/src/Service/HubSelector.php +++ b/src/Service/HubSelector.php @@ -4,6 +4,8 @@ namespace App\Service; use Doctrine\ORM\EntityManagerInterface; +use Symfony\Contracts\Translation\TranslatorInterface; + use CrEOF\Spatial\PHP\Types\Geometry\Point; use App\Entity\Hub; @@ -11,6 +13,7 @@ use App\Entity\Hub; use App\Service\HubDistributor; use App\Service\InventoryManager; use App\Service\HubFilterLogger; +use App\Service\RisingTideGateway; use App\Ramcar\HubCriteria; use App\Ramcar\ServiceType; @@ -21,14 +24,19 @@ class HubSelector protected $im; protected $hub_distributor; protected $hub_filter_logger; + protected $trans; + protected $rt; 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->im = $im; $this->hub_distributor = $hub_distributor; $this->hub_filter_logger = $hub_filter_logger; + $this->trans = $trans; + $this->rt = $rt; } public function find(HubCriteria $criteria) @@ -209,7 +217,19 @@ class HubSelector 'duration' => $hub_data['duration'], ]; 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'); + } } if ($jo_type == ServiceType::BATTERY_REPLACEMENT_WARRANTY) { @@ -223,7 +243,19 @@ class HubSelector 'duration' => $hub_data['duration'], ]; 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'); + } } } } @@ -231,6 +263,27 @@ class HubSelector 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) { // get closest hubs based on st_distance function from db diff --git a/translations/messages.en.yaml b/translations/messages.en.yaml index 70fe10ca..48265ab4 100644 --- a/translations/messages.en.yaml +++ b/translations/messages.en.yaml @@ -13,6 +13,7 @@ add_cust_vehicle_battery_info: This vehicle is using a Motolite battery jo_title_pdf: Motolite Res-Q Job Order country_code_prefix: '+63' delivery_instructions_label: Delivery Instructions +no_inventory_message: No stock for [item_display] # images image_logo_login: /assets/images/logo-resq.png