Add payment method filter. #554
This commit is contained in:
parent
0717df5fff
commit
63b989034d
4 changed files with 105 additions and 15 deletions
|
|
@ -1026,6 +1026,10 @@ class APIController extends Controller implements LoggedController
|
||||||
if (!empty($sku))
|
if (!empty($sku))
|
||||||
$hub_criteria->addItem($batt->getSAPCode(), 1);
|
$hub_criteria->addItem($batt->getSAPCode(), 1);
|
||||||
|
|
||||||
|
// add payment method to criteria
|
||||||
|
if (!empty($jo->getModeOfPayment()))
|
||||||
|
$hub_criteria->setPaymentMethod($jo->getModeOfPayment());
|
||||||
|
|
||||||
// find nearest hubs
|
// find nearest hubs
|
||||||
$nearest_hubs = $hub_select->find($hub_criteria);
|
$nearest_hubs = $hub_select->find($hub_criteria);
|
||||||
|
|
||||||
|
|
@ -2552,6 +2556,10 @@ class APIController extends Controller implements LoggedController
|
||||||
if (!empty($sku))
|
if (!empty($sku))
|
||||||
$hub_criteria->addItem($batt->getSAPCode(), 1);
|
$hub_criteria->addItem($batt->getSAPCode(), 1);
|
||||||
|
|
||||||
|
// add payment method to criteria
|
||||||
|
if (!empty($jo->getModeOfPayment()))
|
||||||
|
$hub_criteria->setPaymentMethod($jo->getModeOfPayment());
|
||||||
|
|
||||||
// find nearest hubs
|
// find nearest hubs
|
||||||
$nearest_hubs = $hub_select->find($hub_criteria);
|
$nearest_hubs = $hub_select->find($hub_criteria);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ class HubCriteria
|
||||||
protected $jo_type; // jo service needed
|
protected $jo_type; // jo service needed
|
||||||
protected $date_time; // date and time to check if hub is open or not
|
protected $date_time; // date and time to check if hub is open or not
|
||||||
protected $items; // array of items: items[sku] = quantity to check for
|
protected $items; // array of items: items[sku] = quantity to check for
|
||||||
|
protected $payment_method; // payment method of JO
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
|
@ -23,8 +24,9 @@ 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->flag_inventory_check = true;
|
$this->flag_inventory_check = false;
|
||||||
$this->items = [];
|
$this->items = [];
|
||||||
|
$this->payment_method = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPoint(Point $point)
|
public function setPoint(Point $point)
|
||||||
|
|
@ -105,4 +107,21 @@ class HubCriteria
|
||||||
{
|
{
|
||||||
return $this->items;
|
return $this->items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setItems($items)
|
||||||
|
{
|
||||||
|
$this->items = $items;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPaymentMethod($payment_method)
|
||||||
|
{
|
||||||
|
$this->payment_method = $payment_method;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPaymentMethod()
|
||||||
|
{
|
||||||
|
return $this->payment_method;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ class HubSelector
|
||||||
$flag_inventory_check = $criteria->hasInventoryCheck();
|
$flag_inventory_check = $criteria->hasInventoryCheck();
|
||||||
$items = $criteria->getItems();
|
$items = $criteria->getItems();
|
||||||
$date_time = $criteria->getDateTime();
|
$date_time = $criteria->getDateTime();
|
||||||
|
$payment_method = $criteria->getPaymentMethod();
|
||||||
|
|
||||||
$results = [];
|
$results = [];
|
||||||
|
|
||||||
|
|
@ -64,6 +65,12 @@ class HubSelector
|
||||||
$hubs_jo_type = $this->filterHubsByJoType($filtered_hubs, $jo_type);
|
$hubs_jo_type = $this->filterHubsByJoType($filtered_hubs, $jo_type);
|
||||||
$filtered_hubs = $hubs_jo_type;
|
$filtered_hubs = $hubs_jo_type;
|
||||||
|
|
||||||
|
// filter hubs by payment methods
|
||||||
|
$hubs_payment_method = $this->filterHubsByPaymentMethod($filtered_hubs, $payment_method);
|
||||||
|
$filtered_hubs = $hubs_payment_method;
|
||||||
|
|
||||||
|
// filter hubs by rider availability
|
||||||
|
|
||||||
// inventory filter
|
// inventory filter
|
||||||
$hubs_inventory = $this->filterHubsByInventory($filtered_hubs, $flag_inventory_check,
|
$hubs_inventory = $this->filterHubsByInventory($filtered_hubs, $flag_inventory_check,
|
||||||
$jo_type, $items);
|
$jo_type, $items);
|
||||||
|
|
@ -149,6 +156,47 @@ class HubSelector
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function filterHubsByPaymentMethod($hubs, $payment_method)
|
||||||
|
{
|
||||||
|
if (empty($hubs))
|
||||||
|
return $hubs;
|
||||||
|
if (empty($payment_method))
|
||||||
|
return $hubs;
|
||||||
|
|
||||||
|
$results = [];
|
||||||
|
foreach ($hubs as $hub_data)
|
||||||
|
{
|
||||||
|
$hub = $hub_data['hub'];
|
||||||
|
|
||||||
|
// name of payment method is what is saved
|
||||||
|
$payment_methods = $hub->getPaymentMethods();
|
||||||
|
if ($payment_methods != null)
|
||||||
|
{
|
||||||
|
$flag_found_pmethod = false;
|
||||||
|
foreach ($payment_methods as $pmethod)
|
||||||
|
{
|
||||||
|
if ($pmethod == $payment_method)
|
||||||
|
{
|
||||||
|
$results[] = [
|
||||||
|
'hub' => $hub,
|
||||||
|
'db_distance' => $hub_data['db_distance'],
|
||||||
|
'distance' => $hub_data['distance'],
|
||||||
|
'duration' => $hub_data['duration'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$flag_found_pmethod = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$flag_found_pmethod)
|
||||||
|
$this->hub_filter_logger->logFilteredHub($hub, 'no_payment_method');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$this->hub_filter_logger->logFilteredHub($hub, 'no_payment_method');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
protected function filterHubsByDateAndTime($hubs, $date_time)
|
protected function filterHubsByDateAndTime($hubs, $date_time)
|
||||||
{
|
{
|
||||||
if (empty($hubs))
|
if (empty($hubs))
|
||||||
|
|
|
||||||
|
|
@ -1898,11 +1898,39 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
// get rejection reasons
|
// get rejection reasons
|
||||||
$params['rejection_reasons'] = JORejectionReason::getCollection();
|
$params['rejection_reasons'] = JORejectionReason::getCollection();
|
||||||
|
|
||||||
|
// set hub criteria
|
||||||
|
$hub_criteria = new HubCriteria();
|
||||||
|
|
||||||
|
// get battery (if any)
|
||||||
|
$skus = [];
|
||||||
|
$items = [];
|
||||||
|
$invoice = $obj->getInvoice();
|
||||||
|
$inv_items = $invoice->getItems();
|
||||||
|
foreach ($inv_items as $inv_item)
|
||||||
|
{
|
||||||
|
$batt = $inv_item->getBattery();
|
||||||
|
if ($batt == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$skus[] = $batt->getSapCode();
|
||||||
|
$item_count = 1;
|
||||||
|
if (!empty($batt->getSapCode()))
|
||||||
|
{
|
||||||
|
$sap_code = $batt->getSapCode();
|
||||||
|
if (isset($items[$sap_code]))
|
||||||
|
$items[$sap_code] = $item_count + 1;
|
||||||
|
else
|
||||||
|
$items[$sap_code] = $item_count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// get closest hubs
|
// get closest hubs
|
||||||
// set hub criteria
|
// set hub criteria
|
||||||
$hub_criteria = new HubCriteria();
|
$hub_criteria = new HubCriteria();
|
||||||
$hub_criteria->setPoint($obj->getCoordinates())
|
$hub_criteria->setPoint($obj->getCoordinates())
|
||||||
->setLimitResults(50);
|
->setLimitResults(50)
|
||||||
|
->setPaymentMethod($obj->getModeOfPayment())
|
||||||
|
->setJoType($obj->getServiceType());
|
||||||
$hubs = $hub_selector->find($hub_criteria);
|
$hubs = $hub_selector->find($hub_criteria);
|
||||||
//$hubs = $map_tools->getClosestHubs($obj->getCoordinates(), 50, date("H:i:s"));
|
//$hubs = $map_tools->getClosestHubs($obj->getCoordinates(), 50, date("H:i:s"));
|
||||||
|
|
||||||
|
|
@ -1971,19 +1999,6 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
// get template to display
|
// get template to display
|
||||||
$params['template'] = $this->getTwigTemplate('jo_processing_form');
|
$params['template'] = $this->getTwigTemplate('jo_processing_form');
|
||||||
|
|
||||||
// get battery (if any)
|
|
||||||
$skus = [];
|
|
||||||
$invoice = $obj->getInvoice();
|
|
||||||
$inv_items = $invoice->getItems();
|
|
||||||
foreach ($inv_items as $inv_item)
|
|
||||||
{
|
|
||||||
$batt = $inv_item->getBattery();
|
|
||||||
if ($batt == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
$skus[] = $batt->getSapCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
// get inventory
|
// get inventory
|
||||||
$mres = $motiv->getInventory($branch_codes, $skus);
|
$mres = $motiv->getInventory($branch_codes, $skus);
|
||||||
foreach ($mres as $mres_item)
|
foreach ($mres as $mres_item)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue