Merge branch 'master' of gitlab.com:jankstudio/resq into 549-make-script-to-get-file-from-azure-storage
This commit is contained in:
commit
5a202526ba
33 changed files with 2043 additions and 442 deletions
|
|
@ -57,6 +57,7 @@ COUNTRY_CODE=+insert_country_code_here
|
|||
|
||||
# redis hash
|
||||
LATEST_ACTIVE_JO=latest_active_jo
|
||||
HUB_JO_KEY=hub_jo_count
|
||||
|
||||
# dashboard
|
||||
DASHBOARD_ENABLE=set_to_true_or_false
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
"symfony/flex": "^1.0",
|
||||
"symfony/framework-bundle": "^4.0",
|
||||
"symfony/maker-bundle": "^1.0",
|
||||
"symfony/monolog-bundle": "^3.7",
|
||||
"symfony/orm-pack": "^1.0",
|
||||
"symfony/process": "^4.0",
|
||||
"symfony/profiler-pack": "^1.0",
|
||||
|
|
|
|||
729
composer.lock
generated
729
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -14,4 +14,5 @@ return [
|
|||
Catalyst\APIBundle\CatalystAPIBundle::class => ['all' => true],
|
||||
Catalyst\AuthBundle\CatalystAuthBundle::class => ['all' => true],
|
||||
Catalyst\MenuBundle\CatalystMenuBundle::class => ['all' => true],
|
||||
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
|
||||
];
|
||||
|
|
|
|||
19
config/packages/dev/monolog.yaml
Normal file
19
config/packages/dev/monolog.yaml
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
monolog:
|
||||
handlers:
|
||||
main:
|
||||
type: stream
|
||||
path: "%kernel.logs_dir%/%kernel.environment%.log"
|
||||
level: debug
|
||||
channels: ["!event"]
|
||||
# uncomment to get logging in your browser
|
||||
# you may have to allow bigger header sizes in your Web server configuration
|
||||
#firephp:
|
||||
# type: firephp
|
||||
# level: info
|
||||
#chromephp:
|
||||
# type: chromephp
|
||||
# level: info
|
||||
console:
|
||||
type: console
|
||||
process_psr_3_messages: false
|
||||
channels: ["!event", "!doctrine", "!console"]
|
||||
8
config/packages/prod/deprecations.yaml
Normal file
8
config/packages/prod/deprecations.yaml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# As of Symfony 5.1, deprecations are logged in the dedicated "deprecation" channel when it exists
|
||||
#monolog:
|
||||
# channels: [deprecation]
|
||||
# handlers:
|
||||
# deprecation:
|
||||
# type: stream
|
||||
# channels: [deprecation]
|
||||
# path: php://stderr
|
||||
17
config/packages/prod/monolog.yaml
Normal file
17
config/packages/prod/monolog.yaml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
monolog:
|
||||
handlers:
|
||||
main:
|
||||
type: fingers_crossed
|
||||
action_level: error
|
||||
handler: nested
|
||||
excluded_http_codes: [404, 405]
|
||||
buffer_size: 50 # How many messages should be saved? Prevent memory leaks
|
||||
nested:
|
||||
type: stream
|
||||
path: php://stderr
|
||||
level: debug
|
||||
formatter: monolog.formatter.json
|
||||
console:
|
||||
type: console
|
||||
process_psr_3_messages: false
|
||||
channels: ["!event", "!doctrine"]
|
||||
12
config/packages/test/monolog.yaml
Normal file
12
config/packages/test/monolog.yaml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
monolog:
|
||||
handlers:
|
||||
main:
|
||||
type: fingers_crossed
|
||||
action_level: error
|
||||
handler: nested
|
||||
excluded_http_codes: [404, 405]
|
||||
channels: ["!event"]
|
||||
nested:
|
||||
type: stream
|
||||
path: "%kernel.logs_dir%/%kernel.environment%.log"
|
||||
level: debug
|
||||
|
|
@ -266,3 +266,21 @@ services:
|
|||
event: 'postPersist'
|
||||
entity: 'App\Entity\CustomerVehicle'
|
||||
|
||||
# hub service
|
||||
App\Service\HubSelector:
|
||||
arguments:
|
||||
$em: "@doctrine.orm.entity_manager"
|
||||
$im: "@App\\Service\\InventoryManager"
|
||||
$hub_distributor: "@App\\Service\\HubDistributor"
|
||||
$hub_filter_logger: "@App\\Service\\HubFilterLogger"
|
||||
|
||||
# hub distributor
|
||||
App\Service\HubDistributor:
|
||||
arguments:
|
||||
$redis: "@App\\Service\\RedisClientProvider"
|
||||
$hub_jo_key: "%env(HUB_JO_KEY)%"
|
||||
|
||||
# hub filter logger
|
||||
App\Service\HubFilterLogger:
|
||||
arguments:
|
||||
$em: "@doctrine.orm.entity_manager"
|
||||
|
|
|
|||
39
src/Command/ResetHubJoCountCommand.php
Normal file
39
src/Command/ResetHubJoCountCommand.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use App\Service\RedisClientProvider;
|
||||
|
||||
class ResetHubJoCountCommand extends Command
|
||||
{
|
||||
protected $redis;
|
||||
|
||||
public function __construct(RedisClientProvider $redis)
|
||||
{
|
||||
$this->redis = $redis->getRedisClient();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('hub:jo:reset')
|
||||
->setDescription('Reset hub\'s job order count')
|
||||
->setHelp('Reset hub\'s job order count');
|
||||
}
|
||||
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$key = 'hub_jo_count';
|
||||
|
||||
$this->redis->del($key);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -28,6 +28,8 @@ use App\Ramcar\TradeInType;
|
|||
use App\Ramcar\JOEventType;
|
||||
use App\Ramcar\AdvanceOrderSlot;
|
||||
use App\Ramcar\AutoAssignStatus;
|
||||
use App\Ramcar\HubCriteria;
|
||||
use App\Ramcar\WillingToWaitContent;
|
||||
|
||||
use App\Service\InvoiceGeneratorInterface;
|
||||
use App\Service\RisingTideGateway;
|
||||
|
|
@ -37,6 +39,9 @@ use App\Service\RiderTracker;
|
|||
use App\Service\MapTools;
|
||||
use App\Service\InventoryManager;
|
||||
use App\Service\RiderAssignmentHandlerInterface;
|
||||
use App\Service\HubSelector;
|
||||
use App\Service\HubDistributor;
|
||||
use App\Service\HubFilterLogger;
|
||||
|
||||
use App\Entity\MobileSession;
|
||||
use App\Entity\Customer;
|
||||
|
|
@ -844,7 +849,8 @@ class APIController extends Controller implements LoggedController
|
|||
|
||||
public function requestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
|
||||
MapTools $map_tools, InventoryManager $im, MQTTClient $mclient,
|
||||
RiderAssignmentHandlerInterface $rah)
|
||||
RiderAssignmentHandlerInterface $rah, HubSelector $hub_select,
|
||||
HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger)
|
||||
{
|
||||
// check required parameters and api key
|
||||
$required_params = [
|
||||
|
|
@ -917,6 +923,14 @@ class APIController extends Controller implements LoggedController
|
|||
}
|
||||
$jo->setServiceType($stype);
|
||||
|
||||
// check if willing to wait is true or not
|
||||
$will_wait = $req->request->get('willing_to_wait');
|
||||
// check for 'false' text
|
||||
if ($will_wait === false || $will_wait === 0 || $will_wait === '0' || $will_wait == 'false')
|
||||
$jo->setWillWait(WillingToWaitContent::NOT_WILLING_TO_WAIT);
|
||||
else
|
||||
$jo->setWillWait(WillingToWaitContent::WILLING_TO_WAIT);
|
||||
|
||||
// validate warranty
|
||||
$warr = $req->request->get('warranty');
|
||||
if (!WarrantyClass::validate($warr))
|
||||
|
|
@ -1009,49 +1023,73 @@ class APIController extends Controller implements LoggedController
|
|||
$invoice = $ic->generateInvoice($icrit);
|
||||
$jo->setInvoice($invoice);
|
||||
|
||||
// assign hub and rider
|
||||
if (($jo->getServiceType() == ServiceType::BATTERY_REPLACEMENT_NEW) ||
|
||||
($jo->getServicetype() == ServiceType::BATTERY_REPLACEMENT_WARRANTY))
|
||||
|
||||
// TODO: set this properly, since the other flags
|
||||
// are on default values
|
||||
$hub_criteria = new HubCriteria();
|
||||
$hub_criteria->setPoint($jo->getCoordinates())
|
||||
->setJoType($jo->getServiceType());
|
||||
|
||||
// add battery to items
|
||||
$sku = $batt->getSAPCode();
|
||||
if (!empty($sku))
|
||||
$hub_criteria->addItem($batt->getSAPCode(), 1);
|
||||
|
||||
// add payment method to criteria
|
||||
if (!empty($jo->getModeOfPayment()))
|
||||
$hub_criteria->setPaymentMethod($jo->getModeOfPayment());
|
||||
|
||||
// check if willing to wait is true or not
|
||||
if ($jo->getWillWait() == WillingToWaitContent::NOT_WILLING_TO_WAIT)
|
||||
{
|
||||
// get nearest hub
|
||||
// $nearest_hub = $this->findNearestHubWithInventory($jo, $batt, $em, $map_tools, $im);
|
||||
$nearest_hub = $this->findNearestHub($jo, $em, $map_tools);
|
||||
}
|
||||
else
|
||||
{
|
||||
$nearest_hub = $this->findNearestHub($jo, $em, $map_tools);
|
||||
$hub_criteria->setEmergency(true);
|
||||
}
|
||||
|
||||
if (!empty($nearest_hub))
|
||||
// find nearest hubs
|
||||
$nearest_hubs = $hub_select->find($hub_criteria);
|
||||
|
||||
if (!empty($nearest_hubs))
|
||||
{
|
||||
// go through the hub list, find the nearest hub
|
||||
// with an available rider
|
||||
//error_log('found nearest hub ' . $nearest_hub->getID());
|
||||
// assign rider
|
||||
$available_riders = $nearest_hub->getAvailableRiders();
|
||||
if (count($available_riders) > 0)
|
||||
foreach ($nearest_hubs as $nearest_hub)
|
||||
{
|
||||
$assigned_rider = null;
|
||||
if (count($available_riders) > 1)
|
||||
$available_riders = $nearest_hub['hub']->getAvailableRiders();
|
||||
if (count($available_riders) >= 1)
|
||||
{
|
||||
// TODO: the setting of riders into an array
|
||||
// will no longer be necessary when the contents
|
||||
// of randomizeRider changes
|
||||
$riders = [];
|
||||
foreach ($available_riders as $rider)
|
||||
$assigned_rider = null;
|
||||
if (count($available_riders) == 1)
|
||||
{
|
||||
$riders[] = $rider;
|
||||
$assigned_rider = $available_riders[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: the setting of riders into an array
|
||||
// will no longer be necessary when the contents
|
||||
// of randomizeRider changes
|
||||
$riders = [];
|
||||
foreach ($available_riders as $rider)
|
||||
{
|
||||
$riders[] = $rider;
|
||||
}
|
||||
|
||||
$assigned_rider = $this->randomizeRider($riders);
|
||||
}
|
||||
|
||||
$assigned_rider = $this->randomizeRider($riders);
|
||||
}
|
||||
else
|
||||
$assigned_rider = $available_riders[0];
|
||||
|
||||
//error_log('found rider ' . $assigned_rider->getID());
|
||||
$jo->setHub($nearest_hub);
|
||||
$jo->setRider($assigned_rider);
|
||||
$jo->setStatus(JOStatus::ASSIGNED);
|
||||
$jo->setHub($nearest_hub['hub']);
|
||||
$jo->setRider($assigned_rider);
|
||||
$jo->setStatus(JOStatus::ASSIGNED);
|
||||
$jo->setStatusAutoAssign(AutoAssignStatus::HUB_AND_RIDER_ASSIGNED);
|
||||
|
||||
$assigned_rider->setAvailable(false);
|
||||
$assigned_rider->setAvailable(false);
|
||||
|
||||
// update redis hub_jo_count for hub
|
||||
$hub_dist->incrementJoCountForHub($nearest_hub['hub']);
|
||||
|
||||
// break out of loop
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2330,7 +2368,8 @@ class APIController extends Controller implements LoggedController
|
|||
|
||||
public function newRequestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
|
||||
MapTools $map_tools, InventoryManager $im, MQTTClient $mclient,
|
||||
RiderAssignmentHandlerInterface $rah)
|
||||
RiderAssignmentHandlerInterface $rah, HubSelector $hub_select,
|
||||
HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger)
|
||||
{
|
||||
// check required parameters and api key
|
||||
$required_params = [
|
||||
|
|
@ -2419,6 +2458,14 @@ class APIController extends Controller implements LoggedController
|
|||
}
|
||||
$jo->setServiceType($stype);
|
||||
|
||||
// check if willing to wait is true or not
|
||||
$will_wait = $req->request->get('willing_to_wait');
|
||||
// check for 'false' text
|
||||
if ($will_wait === false || $will_wait === 0 || $will_wait === '0' || $will_wait == 'false')
|
||||
$jo->setWillWait(WillingToWaitContent::NOT_WILLING_TO_WAIT);
|
||||
else
|
||||
$jo->setWillWait(WillingToWaitContent::WILLING_TO_WAIT);
|
||||
|
||||
// validate warranty
|
||||
$warr = $req->request->get('warranty');
|
||||
if (!WarrantyClass::validate($warr))
|
||||
|
|
@ -2515,50 +2562,72 @@ class APIController extends Controller implements LoggedController
|
|||
// check if hub is null
|
||||
if ($hub == null)
|
||||
{
|
||||
// find nearest hub
|
||||
if (($jo->getServiceType() == ServiceType::BATTERY_REPLACEMENT_NEW) ||
|
||||
($jo->getServicetype() == ServiceType::BATTERY_REPLACEMENT_WARRANTY))
|
||||
// TODO: set this properly, since the other flags
|
||||
// are on default values
|
||||
$hub_criteria = new HubCriteria();
|
||||
$hub_criteria->setPoint($jo->getCoordinates())
|
||||
->setJoType($jo->getServiceType());
|
||||
|
||||
// add battery to items
|
||||
$sku = $batt->getSAPCode();
|
||||
if (!empty($sku))
|
||||
$hub_criteria->addItem($batt->getSAPCode(), 1);
|
||||
|
||||
// add payment method to criteria
|
||||
if (!empty($jo->getModeOfPayment()))
|
||||
$hub_criteria->setPaymentMethod($jo->getModeOfPayment());
|
||||
|
||||
// check if willing to wait is true or not
|
||||
if ($jo->getWillWait() == WillingToWaitContent::NOT_WILLING_TO_WAIT)
|
||||
{
|
||||
// get nearest hub
|
||||
// $nearest_hub = $this->findNearestHubWithInventory($jo, $batt, $em, $map_tools, $im);
|
||||
$nearest_hub = $this->findNearestHub($jo, $em, $map_tools);
|
||||
}
|
||||
else
|
||||
{
|
||||
$nearest_hub = $this->findNearestHub($jo, $em, $map_tools);
|
||||
$hub_criteria->setEmergency(true);
|
||||
}
|
||||
|
||||
if (!empty($nearest_hub))
|
||||
// find nearest hubs
|
||||
$nearest_hubs = $hub_select->find($hub_criteria);
|
||||
|
||||
if (!empty($nearest_hubs))
|
||||
{
|
||||
// go through the hub list, find the nearest hub
|
||||
// with an available rider
|
||||
//error_log('found nearest hub ' . $nearest_hub->getID());
|
||||
// assign rider
|
||||
$available_riders = $nearest_hub->getAvailableRiders();
|
||||
if (count($available_riders) > 0)
|
||||
foreach ($nearest_hubs as $nearest_hub)
|
||||
{
|
||||
$assigned_rider = null;
|
||||
if (count($available_riders) > 1)
|
||||
$available_riders = $nearest_hub['hub']->getAvailableRiders();
|
||||
if (count($available_riders) >= 1)
|
||||
{
|
||||
// TODO: the setting of riders into an array
|
||||
// will no longer be necessary when the contents
|
||||
// of randomizeRider changes
|
||||
$riders = [];
|
||||
foreach ($available_riders as $rider)
|
||||
$assigned_rider = null;
|
||||
if (count($available_riders) == 1)
|
||||
{
|
||||
$riders[] = $rider;
|
||||
$assigned_rider = $available_riders[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: the setting of riders into an array
|
||||
// will no longer be necessary when the contents
|
||||
// of randomizeRider changes
|
||||
$riders = [];
|
||||
foreach ($available_riders as $rider)
|
||||
{
|
||||
$riders[] = $rider;
|
||||
}
|
||||
|
||||
$assigned_rider = $this->randomizeRider($riders);
|
||||
}
|
||||
|
||||
$assigned_rider = $this->randomizeRider($riders);
|
||||
$jo->setHub($nearest_hub['hub']);
|
||||
$jo->setRider($assigned_rider);
|
||||
$jo->setStatus(JOStatus::ASSIGNED);
|
||||
$jo->setStatusAutoAssign(AutoAssignStatus::HUB_AND_RIDER_ASSIGNED);
|
||||
|
||||
$assigned_rider->setAvailable(false);
|
||||
|
||||
// update redis hub_jo_count for hub
|
||||
$hub_dist->incrementJoCountForHub($nearest_hub['hub']);
|
||||
|
||||
// break out of loop
|
||||
break;
|
||||
}
|
||||
else
|
||||
$assigned_rider = $available_riders[0];
|
||||
|
||||
//error_log('found rider ' . $assigned_rider->getID());
|
||||
$jo->setHub($nearest_hub);
|
||||
$jo->setRider($assigned_rider);
|
||||
$jo->setStatus(JOStatus::ASSIGNED);
|
||||
$jo->setStatusAutoAssign(AutoAssignStatus::HUB_AND_RIDER_ASSIGNED);
|
||||
|
||||
$assigned_rider->setAvailable(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2581,7 +2650,10 @@ class APIController extends Controller implements LoggedController
|
|||
$jo->setStatusAutoAssign(AutoAssignStatus::HUB_ASSIGNED);
|
||||
|
||||
if ($date_schedule != null)
|
||||
$jo->setDateSchedule($date_schedule);
|
||||
$jo->setDateSchedule($date_schedule);
|
||||
|
||||
// update redis hub_jo_count for hub
|
||||
$hub_dist->incrementJoCountForHub($hub);
|
||||
}
|
||||
|
||||
$em->persist($jo);
|
||||
|
|
@ -2905,7 +2977,11 @@ class APIController extends Controller implements LoggedController
|
|||
}
|
||||
|
||||
$sku = $warr_serial->getSKU();
|
||||
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
|
||||
// check if sku is null
|
||||
$batt = null;
|
||||
if ($sku != null)
|
||||
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
// TODO: put this in a config file
|
||||
$image_url = $req->getSchemeAndHttpHost() . '/battery/generic.png';
|
||||
if ($batt != null)
|
||||
|
|
@ -3009,14 +3085,14 @@ class APIController extends Controller implements LoggedController
|
|||
// $cust = $this->updateCustomerInfo($req, $em);
|
||||
|
||||
// update warranty
|
||||
$res = $this->updateWarranty($res, $em, $trans, $req, $serial, $inv_filename, $wcard_filename);
|
||||
$res = $this->updateWarranty($res, $em, $rt, $trans, $req, $serial, $inv_filename, $wcard_filename);
|
||||
|
||||
$em->flush();
|
||||
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
protected function updateWarranty($res, $em, $trans, $req, $serial, $inv_filename = null, $wcard_filename = null)
|
||||
protected function updateWarranty($res, $em, $rt, $trans, $req, $serial, $inv_filename = null, $wcard_filename = null)
|
||||
{
|
||||
// get serial
|
||||
$warr_serial = $em->getRepository(WarrantySerial::class)->find($serial);
|
||||
|
|
@ -3048,7 +3124,7 @@ class APIController extends Controller implements LoggedController
|
|||
if (!$is_customer_warranty)
|
||||
{
|
||||
$res->setError(true)
|
||||
->setErrorMessage('Warranty registred to a vehicle not in your list of vehicles.');
|
||||
->setErrorMessage('Warranty registered to a vehicle not in your list of vehicles.');
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
|
@ -3060,15 +3136,12 @@ class APIController extends Controller implements LoggedController
|
|||
$sms_msg = $trans->trans('warranty_register_confirm');
|
||||
}
|
||||
|
||||
// check if sku is null
|
||||
// get sap battery
|
||||
$sku = $warr_serial->getSKU();
|
||||
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
if ($sap_bty == null)
|
||||
{
|
||||
$res->setError(true)
|
||||
->setErrorMessage('Could not find battery entry for warranty.');
|
||||
return $res;
|
||||
}
|
||||
$sap_bty = null;
|
||||
if ($sku != null)
|
||||
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
|
||||
// default date purchase to today
|
||||
// NOTE: might need to change this later
|
||||
|
|
|
|||
|
|
@ -232,7 +232,11 @@ class CustomerWarrantyController extends APIController
|
|||
}
|
||||
|
||||
$sku = $warr_serial->getSKU();
|
||||
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
// check if sku is null
|
||||
$batt = null;
|
||||
if ($sku != null)
|
||||
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
|
||||
// TODO: put this in a config file
|
||||
$image_url = $req->getSchemeAndHttpHost() . '/battery/generic.png';
|
||||
if ($batt != null)
|
||||
|
|
@ -279,6 +283,8 @@ class CustomerWarrantyController extends APIController
|
|||
{
|
||||
error_log('HERE - register');
|
||||
// check required parameters
|
||||
// TODO: maybe add vmake_id? since warranty cannot be created with no vmake
|
||||
// TODO: maye also add mobile and email since customer creation won't let mobile and email be null
|
||||
$required_params = [
|
||||
'first_name',
|
||||
'last_name',
|
||||
|
|
@ -381,10 +387,16 @@ class CustomerWarrantyController extends APIController
|
|||
error_log('sap battery check');
|
||||
// get sap battery
|
||||
$sku = $warr_serial->getSKU();
|
||||
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
if ($sap_bty == null)
|
||||
$sap_bty = null;
|
||||
|
||||
// check if sku is null
|
||||
if ($sku != null)
|
||||
{
|
||||
return new APIResponse(false, 'Could not find battery entry for warranty.');
|
||||
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
//if ($sap_bty == null)
|
||||
//{
|
||||
// return new APIResponse(false, 'Could not find battery entry for warranty.');
|
||||
//}
|
||||
}
|
||||
|
||||
// vehicle fetch
|
||||
|
|
@ -403,15 +415,19 @@ class CustomerWarrantyController extends APIController
|
|||
// default date purchase to today
|
||||
// NOTE: might need to change this later
|
||||
$date_pur = new DateTime();
|
||||
$date_pur_cust = new DateTime();
|
||||
|
||||
// get date purchase specified by customer
|
||||
$date_pur_cust = DateTime::createFromFormat('Y-m-d', $req->request->get('date_purchase'));
|
||||
if (!$date_pur_cust)
|
||||
if (!empty($req->request->get('date_purchase')))
|
||||
{
|
||||
return new APIResponse(false, 'Invalid date format for date of purchase.');
|
||||
$date_pur_cust = DateTime::createFromFormat('Y-m-d', $req->request->get('date_purchase'));
|
||||
if (!$date_pur_cust)
|
||||
{
|
||||
return new APIResponse(false, 'Invalid date format for date of purchase.');
|
||||
}
|
||||
}
|
||||
|
||||
// chstomer check
|
||||
// customer check
|
||||
$priv_promo = $req->request->get('priv_promo', false);
|
||||
if ($cust == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -199,10 +199,16 @@ class WarrantyController extends APIController
|
|||
if (!$plate)
|
||||
return new APIResponse(false, 'Invalid plate number.');
|
||||
|
||||
// battery
|
||||
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
if ($batt == null)
|
||||
return new APIResponse(false, 'Invalid battery SKU.');
|
||||
// check if sku is blank
|
||||
if ((empty($sku)) || ($sku == null))
|
||||
$batt = null;
|
||||
else
|
||||
{
|
||||
// battery
|
||||
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
if ($batt == null)
|
||||
return new APIResponse(false, 'Invalid battery SKU.');
|
||||
}
|
||||
|
||||
/*
|
||||
// battery model
|
||||
|
|
@ -382,10 +388,16 @@ class WarrantyController extends APIController
|
|||
if (!$plate)
|
||||
return new APIResponse(false, 'Invalid plate number.');
|
||||
|
||||
// battery
|
||||
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
if ($batt == null)
|
||||
return new APIResponse(false, 'Invalid battery SKU.');
|
||||
// check if sku is blank
|
||||
if ((empty($sku)) || ($sku == null))
|
||||
$batt = null;
|
||||
else
|
||||
{
|
||||
// battery
|
||||
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
if ($batt == null)
|
||||
return new APIResponse(false, 'Invalid battery SKU.');
|
||||
}
|
||||
|
||||
$warr->setSerial($serial)
|
||||
->setWarrantyClass($warr_class)
|
||||
|
|
@ -634,6 +646,7 @@ class WarrantyController extends APIController
|
|||
$w_last_name = $warranty->getLastName();
|
||||
|
||||
$new_cust = new Customer();
|
||||
// TODO: add customer source
|
||||
$new_cust->setFirstName($w_first_name)
|
||||
->setLastName($w_last_name)
|
||||
->setPhoneMobile($w_mobile_num);
|
||||
|
|
|
|||
|
|
@ -17,8 +17,12 @@ use DateTime;
|
|||
|
||||
use Catalyst\MenuBundle\Annotation\Menu;
|
||||
|
||||
use App\Service\MapTools;
|
||||
use App\Service\RiderTracker;
|
||||
use App\Service\RisingTideGateway;
|
||||
use App\Service\HubSelector;
|
||||
|
||||
use App\Ramcar\HubCriteria;
|
||||
use App\Ramcar\ModeOfPayment;
|
||||
|
||||
class HubController extends Controller
|
||||
{
|
||||
|
|
@ -128,6 +132,7 @@ class HubController extends Controller
|
|||
$params = [];
|
||||
$params['obj'] = new Hub();
|
||||
$params['mode'] = 'create';
|
||||
$params['payment_methods'] = ModeOfPayment::getCollection();
|
||||
|
||||
// response
|
||||
return $this->render('hub/form.html.twig', $params);
|
||||
|
|
@ -154,7 +159,17 @@ class HubController extends Controller
|
|||
->setBranchCode($req->request->get('branch_code', ''))
|
||||
->setStatusOpen($req->request->get('status_open', false))
|
||||
->setRiderSlots($req->request->get('rider_slots', 0))
|
||||
->setHubViewFlag($req->request->get('flag_hub_view', false));
|
||||
->setHubViewFlag($req->request->get('flag_hub_view', false))
|
||||
->setNotifNumber($req->request->get('notif_number'))
|
||||
->clearPaymentMethods();
|
||||
|
||||
// set payment methods
|
||||
$payment_methods = $req->request->get('payment_methods');
|
||||
|
||||
if (!empty($payment_methods))
|
||||
{
|
||||
$obj->setPaymentMethods($payment_methods);
|
||||
}
|
||||
}
|
||||
|
||||
protected function setQueryFilters($datatable, QueryBuilder $query)
|
||||
|
|
@ -166,7 +181,7 @@ class HubController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
public function addSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator)
|
||||
public function addSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator, RisingTideGateway $rt)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('hub.add', null, 'No access.');
|
||||
|
||||
|
|
@ -176,14 +191,23 @@ class HubController extends Controller
|
|||
$em = $this->getDoctrine()->getManager();
|
||||
$obj = new Hub();
|
||||
|
||||
// initialize error list
|
||||
$error_array = [];
|
||||
|
||||
// validate the notification number
|
||||
$mobile = $req->request->get('notif_number');
|
||||
if (!empty($mobile))
|
||||
{
|
||||
$is_valid = $rt->validatePhoneNumber($mobile);
|
||||
if (!$is_valid)
|
||||
$error_array['notif_number'] = 'Invalid notification number';
|
||||
}
|
||||
|
||||
$this->setObject($obj, $req);
|
||||
|
||||
// validate
|
||||
$errors = $validator->validate($obj);
|
||||
|
||||
// initialize error list
|
||||
$error_array = [];
|
||||
|
||||
// add errors to list
|
||||
foreach ($errors as $error) {
|
||||
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||
|
|
@ -226,12 +250,13 @@ class HubController extends Controller
|
|||
$params = [];
|
||||
$params['obj'] = $obj;
|
||||
$params['mode'] = 'update';
|
||||
$params['payment_methods'] = ModeOfPayment::getCollection();
|
||||
|
||||
// response
|
||||
return $this->render('hub/form.html.twig', $params);
|
||||
}
|
||||
|
||||
public function updateSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator, $id)
|
||||
public function updateSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator, $id, RisingTideGateway $rt)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('hub.update', null, 'No access.');
|
||||
|
||||
|
|
@ -243,14 +268,23 @@ class HubController extends Controller
|
|||
if (empty($obj))
|
||||
throw $this->createNotFoundException('The item does not exist');
|
||||
|
||||
// initialize error list
|
||||
$error_array = [];
|
||||
|
||||
// validate the notification number
|
||||
$mobile = $req->request->get('notif_number');
|
||||
if (!empty($mobile))
|
||||
{
|
||||
$is_valid = $rt->validatePhoneNumber($mobile);
|
||||
if (!$is_valid)
|
||||
$error_array['notif_number'] = 'Invalid notification number';
|
||||
}
|
||||
|
||||
$this->setObject($obj, $req);
|
||||
|
||||
// validate
|
||||
$errors = $validator->validate($obj);
|
||||
|
||||
// initialize error list
|
||||
$error_array = [];
|
||||
|
||||
// add errors to list
|
||||
foreach ($errors as $error) {
|
||||
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||
|
|
@ -295,7 +329,7 @@ class HubController extends Controller
|
|||
$response->send();
|
||||
}
|
||||
|
||||
public function nearest(MapTools $map_tools, Request $req)
|
||||
public function nearest(HubSelector $hub_selector, Request $req)
|
||||
{
|
||||
// get lat / long
|
||||
$lat = $req->query->get('lat');
|
||||
|
|
@ -303,7 +337,12 @@ class HubController extends Controller
|
|||
|
||||
// get nearest hubs according to position
|
||||
$point = new Point($long, $lat);
|
||||
$result = $map_tools->getClosestHubs($point, 10, date("H:i:s"));
|
||||
|
||||
// set up hub criteria
|
||||
$hub_criteria = new HubCriteria();
|
||||
$hub_criteria->setPoint($point);
|
||||
$hub_selector->find($hub_criteria);
|
||||
//$result = $map_tools->getClosestHubs($point, 10, date("H:i:s"));
|
||||
|
||||
$hubs = [];
|
||||
foreach ($result as $hub_res)
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ use App\Service\MapTools;
|
|||
use App\Service\MQTTClient;
|
||||
use App\Service\APNSClient;
|
||||
use App\Service\InventoryManager;
|
||||
use App\Service\HubSelector;
|
||||
|
||||
use App\Service\RiderTracker;
|
||||
use App\Service\MotivConnector;
|
||||
|
|
@ -315,13 +316,13 @@ class JobOrderController extends Controller
|
|||
/**
|
||||
* @Menu(selected="jo_proc")
|
||||
*/
|
||||
public function processingForm(MapTools $map_tools, $id, JobOrderHandlerInterface $jo_handler, GISManagerInterface $gis, MotivConnector $motiv)
|
||||
public function processingForm(HubSelector $hub_selector, $id, JobOrderHandlerInterface $jo_handler, GISManagerInterface $gis, MotivConnector $motiv)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('jo_proc.list', null, 'No access.');
|
||||
|
||||
try
|
||||
{
|
||||
$params = $jo_handler->initializeProcessingForm($id, $map_tools, $motiv);
|
||||
$params = $jo_handler->initializeProcessingForm($id, $hub_selector, $motiv);
|
||||
}
|
||||
catch (AccessDeniedHttpException $e)
|
||||
{
|
||||
|
|
@ -504,14 +505,14 @@ class JobOrderController extends Controller
|
|||
/**
|
||||
* @Menu(selected="jo_open")
|
||||
*/
|
||||
public function openHubForm(MapTools $map_tools, $id, JobOrderHandlerInterface $jo_handler,
|
||||
public function openHubForm(HubSelector $hub_selector, $id, JobOrderHandlerInterface $jo_handler,
|
||||
GISManagerInterface $gis)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('jo_open.list', null, 'No access.');
|
||||
|
||||
try
|
||||
{
|
||||
$params = $jo_handler->initializeHubForm($id, $map_tools);
|
||||
$params = $jo_handler->initializeHubForm($id, $hub_selector);
|
||||
}
|
||||
catch (NotFoundHttpException $e)
|
||||
{
|
||||
|
|
@ -1204,6 +1205,7 @@ class JobOrderController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
// this is uncalled or does not display in admin panel
|
||||
/**
|
||||
* @Menu(selected="jo_autoassign")
|
||||
*/
|
||||
|
|
@ -1223,6 +1225,7 @@ class JobOrderController extends Controller
|
|||
return $this->render($template, $params);
|
||||
}
|
||||
|
||||
// this is uncalled or does not display in admin panel
|
||||
public function autoAssignSubmit(Request $req, JobOrderHandlerInterface $jo_handler,
|
||||
EntityManagerInterface $em, MapTools $map_tools,
|
||||
InventoryManager $im)
|
||||
|
|
|
|||
|
|
@ -181,31 +181,52 @@ class WarrantyController extends Controller
|
|||
}
|
||||
|
||||
// custom validation for battery model
|
||||
$model = $em->getRepository(BatteryModel::class)
|
||||
->find($req->request->get('battery_model'));
|
||||
// check if battery model is blank
|
||||
$bmodel = $req->request->get('battery_model');
|
||||
if (!empty($bmodel))
|
||||
{
|
||||
$model = $em->getRepository(BatteryModel::class)
|
||||
->find($req->request->get('battery_model'));
|
||||
|
||||
if (empty($model))
|
||||
$error_array['battery_model'] = 'Invalid model selected.';
|
||||
if (empty($model))
|
||||
$error_array['battery_model'] = 'Invalid model selected.';
|
||||
else
|
||||
$obj->setBatteryModel($model);
|
||||
}
|
||||
else
|
||||
$obj->setBatteryModel($model);
|
||||
$obj->setBatteryModel(NULL);
|
||||
|
||||
// custom validation for battery size
|
||||
$size = $em->getRepository(BatterySize::class)
|
||||
->find($req->request->get('battery_size'));
|
||||
// check if battery size is blank
|
||||
$bsize = $req->request->get('battery_size');
|
||||
if (!empty($bsize))
|
||||
{
|
||||
$size = $em->getRepository(BatterySize::class)
|
||||
->find($req->request->get('battery_size'));
|
||||
|
||||
if (empty($size))
|
||||
$error_array['battery_size'] = 'Invalid size selected.';
|
||||
if (empty($size))
|
||||
$error_array['battery_size'] = 'Invalid size selected.';
|
||||
else
|
||||
$obj->setBatterySize($size);
|
||||
}
|
||||
else
|
||||
$obj->setBatterySize($size);
|
||||
$obj->setBatterySize(NULL);
|
||||
|
||||
// custom validation for SAP battery
|
||||
$sap = $em->getRepository(SAPBattery::class)
|
||||
->find($req->request->get('sap_battery'));
|
||||
// check if sap battery is blank
|
||||
$sap_battery = $req->request->get('sap_battery');
|
||||
if (!empty($sap_battery))
|
||||
{
|
||||
$sap = $em->getRepository(SAPBattery::class)
|
||||
->find($req->request->get('sap_battery'));
|
||||
|
||||
if (empty($sap))
|
||||
$error_array['sap_battery'] = 'Invalid SAP battery selected.';
|
||||
if (empty($sap))
|
||||
$error_array['sap_battery'] = 'Invalid SAP battery selected.';
|
||||
else
|
||||
$obj->setSAPBattery($sap);
|
||||
}
|
||||
else
|
||||
$obj->setSAPBattery($sap);
|
||||
$obj->setSAPBattery(NULL);
|
||||
|
||||
// validate
|
||||
$errors = $validator->validate($obj);
|
||||
|
|
@ -303,31 +324,52 @@ class WarrantyController extends Controller
|
|||
}
|
||||
|
||||
// custom validation for battery model
|
||||
$model = $em->getRepository(BatteryModel::class)
|
||||
->find($req->request->get('battery_model'));
|
||||
// check if battery model is blank
|
||||
$bmodel = $req->request->get('battery_model');
|
||||
if (!empty($bmodel))
|
||||
{
|
||||
$model = $em->getRepository(BatteryModel::class)
|
||||
->find($req->request->get('battery_model'));
|
||||
|
||||
if (empty($model))
|
||||
$error_array['battery_model'] = 'Invalid model selected.';
|
||||
if (empty($model))
|
||||
$error_array['battery_model'] = 'Invalid model selected.';
|
||||
else
|
||||
$obj->setBatteryModel($model);
|
||||
}
|
||||
else
|
||||
$obj->setBatteryModel($model);
|
||||
$obj->setBatteryModel(null);
|
||||
|
||||
// custom validation for battery size
|
||||
$size = $em->getRepository(BatterySize::class)
|
||||
->find($req->request->get('battery_size'));
|
||||
// check if battery size is blank
|
||||
$bsize = $req->request->get('battery_size');
|
||||
if (!empty($bsize))
|
||||
{
|
||||
$size = $em->getRepository(BatterySize::class)
|
||||
->find($req->request->get('battery_size'));
|
||||
|
||||
if (empty($size))
|
||||
$error_array['battery_size'] = 'Invalid size selected.';
|
||||
if (empty($size))
|
||||
$error_array['battery_size'] = 'Invalid size selected.';
|
||||
else
|
||||
$obj->setBatterySize($size);
|
||||
}
|
||||
else
|
||||
$obj->setBatterySize($size);
|
||||
$obj->setBatterySize(null);
|
||||
|
||||
// custom validation for SAP battery
|
||||
$sap = $em->getRepository(SAPBattery::class)
|
||||
->find($req->request->get('sap_battery'));
|
||||
// check if sap battery is blank
|
||||
$sap_battery = $req->request->get('sap_battery');
|
||||
if (!empty($sap_battery))
|
||||
{
|
||||
$sap = $em->getRepository(SAPBattery::class)
|
||||
->find($req->request->get('sap_battery'));
|
||||
|
||||
if (empty($sap))
|
||||
$error_array['sap_battery'] = 'Invalid SAP battery selected.';
|
||||
if (empty($sap))
|
||||
$error_array['sap_battery'] = 'Invalid SAP battery selected.';
|
||||
else
|
||||
$obj->setSAPBattery($sap);
|
||||
}
|
||||
else
|
||||
$obj->setSAPBattery($sap);
|
||||
$obj->setSAPBattery(null);
|
||||
|
||||
// validate
|
||||
$errors = $validator->validate($obj);
|
||||
|
|
|
|||
|
|
@ -68,6 +68,18 @@ class Hub
|
|||
*/
|
||||
protected $flag_hub_view;
|
||||
|
||||
// notification number to send SMS to if hub doesn't have item
|
||||
/**
|
||||
* @ORM\Column(type="string", length=30)
|
||||
*/
|
||||
protected $notif_number;
|
||||
|
||||
// payment methods
|
||||
/**
|
||||
* @ORM\Column(type="array", nullable=true)
|
||||
*/
|
||||
protected $payment_methods;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->time_open = new DateTime();
|
||||
|
|
@ -76,6 +88,8 @@ class Hub
|
|||
$this->outlets = new ArrayCollection();
|
||||
$this->status_open = true;
|
||||
$this->flag_hub_view = false;
|
||||
$this->notif_number = '';
|
||||
$this->payment_methods = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getRiders()
|
||||
|
|
@ -185,5 +199,38 @@ class Hub
|
|||
return $this->flag_hub_view;
|
||||
}
|
||||
|
||||
public function setNotifNumber($notif_number)
|
||||
{
|
||||
$this->notif_number = $notif_number;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNotifNumber()
|
||||
{
|
||||
return $this->notif_number;
|
||||
}
|
||||
|
||||
public function getPaymentMethods()
|
||||
{
|
||||
return $this->payment_methods;
|
||||
}
|
||||
|
||||
public function setPaymentMethods(array $payment_methods)
|
||||
{
|
||||
$this->payment_methods = new ArrayCollection();
|
||||
|
||||
foreach ($payment_methods as $payment_method)
|
||||
{
|
||||
$this->payment_methods->add($payment_method);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function clearPaymentMethods()
|
||||
{
|
||||
$this->payment_methods = new ArrayCollection();
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
83
src/Entity/HubFilterLog.php
Normal file
83
src/Entity/HubFilterLog.php
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
use App\Entity\Hub;
|
||||
|
||||
use DateTime;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="hub_filter_log")
|
||||
*/
|
||||
class HubFilterLog
|
||||
{
|
||||
// unique id
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
// date created
|
||||
/**
|
||||
* @ORM\Column(type="datetime")
|
||||
*/
|
||||
protected $date_create;
|
||||
|
||||
// hub that was not included in results
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Hub", inversedBy="hub_filtered")
|
||||
* @ORM\JoinColumn(name="hub_filtered_id", referencedColumnName="id", nullable=true)
|
||||
*/
|
||||
protected $hub;
|
||||
|
||||
// filter that eliminated hub
|
||||
/**
|
||||
* @ORM\Column(type="string", length=80)
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
protected $filter_type_id;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->date_create = new DateTime();
|
||||
}
|
||||
|
||||
public function getID()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getDateCreate()
|
||||
{
|
||||
return $this->date_create;
|
||||
}
|
||||
|
||||
public function setHub(Hub $hub)
|
||||
{
|
||||
$this->hub = $hub;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHub()
|
||||
{
|
||||
return $this->hub;
|
||||
}
|
||||
|
||||
public function setFilterTypeId($filter_type_id)
|
||||
{
|
||||
$this->filter_type_id = $filter_type_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFilterTypeId()
|
||||
{
|
||||
return $this->filter_type_id;
|
||||
}
|
||||
}
|
||||
|
|
@ -73,14 +73,14 @@ class Warranty
|
|||
// battery model
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="BatteryModel", inversedBy="warranties")
|
||||
* @ORM\JoinColumn(name="bty_model_id", referencedColumnName="id")
|
||||
* @ORM\JoinColumn(name="bty_model_id", referencedColumnName="id", nullable=true)
|
||||
*/
|
||||
protected $bty_model;
|
||||
|
||||
// battery size
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="BatterySize", inversedBy="warranties")
|
||||
* @ORM\JoinColumn(name="bty_size_id", referencedColumnName="id")
|
||||
* @ORM\JoinColumn(name="bty_size_id", referencedColumnName="id", nullable=true)
|
||||
*/
|
||||
protected $bty_size;
|
||||
|
||||
|
|
@ -371,7 +371,7 @@ class Warranty
|
|||
return $this->mobile_number;
|
||||
}
|
||||
|
||||
public function setBatteryModel(BatteryModel $model)
|
||||
public function setBatteryModel(BatteryModel $model = null)
|
||||
{
|
||||
$this->bty_model = $model;
|
||||
return $this;
|
||||
|
|
@ -382,7 +382,7 @@ class Warranty
|
|||
return $this->bty_model;
|
||||
}
|
||||
|
||||
public function setBatterySize(BatterySize $size)
|
||||
public function setBatterySize(BatterySize $size = null)
|
||||
{
|
||||
$this->bty_size = $size;
|
||||
return $this;
|
||||
|
|
@ -393,7 +393,7 @@ class Warranty
|
|||
return $this->bty_size;
|
||||
}
|
||||
|
||||
public function setSAPBattery(SAPBattery $sap_bty)
|
||||
public function setSAPBattery(SAPBattery $sap_bty = null)
|
||||
{
|
||||
$this->sap_bty = $sap_bty;
|
||||
return $this;
|
||||
|
|
|
|||
140
src/Ramcar/HubCriteria.php
Normal file
140
src/Ramcar/HubCriteria.php
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
|
||||
namespace App\Ramcar;
|
||||
|
||||
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
||||
|
||||
use DateTime;
|
||||
|
||||
class HubCriteria
|
||||
{
|
||||
protected $point; // coordinates of source
|
||||
protected $limit_results; // number of results to return
|
||||
protected $limit_distance; // distance limit for search in km
|
||||
protected $flag_inventory_check; // flag if we need to check for inventory
|
||||
protected $jo_type; // jo service needed
|
||||
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 $payment_method; // payment method of JO
|
||||
protected $flag_emergency; // flag if emergency or not
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// TODO: default values might still change
|
||||
$this->limit_results = 10;
|
||||
$this->limit_distance = 500;
|
||||
$this->jo_type = '';
|
||||
$this->date_time = null;
|
||||
$this->flag_inventory_check = false;
|
||||
$this->items = [];
|
||||
$this->payment_method = '';
|
||||
$flag_emergency = false;
|
||||
}
|
||||
|
||||
public function setPoint(Point $point)
|
||||
{
|
||||
$this->point = $point;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPoint()
|
||||
{
|
||||
return $this->point;
|
||||
}
|
||||
|
||||
public function setLimitResults($limit_results)
|
||||
{
|
||||
$this->limit_results = $limit_results;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLimitResults()
|
||||
{
|
||||
return $this->limit_results;
|
||||
}
|
||||
|
||||
public function setLimitDistance($limit_distance)
|
||||
{
|
||||
$this->limit_distance = $limit_distance;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLimitDistance()
|
||||
{
|
||||
return $this->limit_distance;
|
||||
}
|
||||
|
||||
public function setInventoryCheck($flag_inventory_check = true)
|
||||
{
|
||||
$this->flag_inventory_check = $flag_inventory_check;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasInventoryCheck()
|
||||
{
|
||||
return $this->flag_inventory_check;
|
||||
}
|
||||
|
||||
public function setJoType($jo_type)
|
||||
{
|
||||
// TODO: validate the jo type
|
||||
$this->jo_type = $jo_type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getJoType()
|
||||
{
|
||||
return $this->jo_type;
|
||||
}
|
||||
|
||||
public function setDateTime(DateTime $date_time)
|
||||
{
|
||||
$this->date_time = $date_time;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDateTime()
|
||||
{
|
||||
return $this->date_time;
|
||||
}
|
||||
|
||||
public function addItem($sku, $quantity)
|
||||
{
|
||||
// at this point, sku is assumed to be a valid item
|
||||
$this->items[$sku] = $quantity;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getItems()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
public function setEmergency($flag_emergency = true)
|
||||
{
|
||||
$this->flag_emergency = $flag_emergency;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isEmergency()
|
||||
{
|
||||
return $this->flag_emergency;
|
||||
}
|
||||
}
|
||||
109
src/Service/HubDistributor.php
Normal file
109
src/Service/HubDistributor.php
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Service\RedisClientProvider;
|
||||
|
||||
use App\Entity\Hub;
|
||||
|
||||
class HubDistributor
|
||||
{
|
||||
protected $redis;
|
||||
protected $hub_jo_key;
|
||||
|
||||
public function __construct(RedisClientProvider $redis, $hub_jo_key)
|
||||
{
|
||||
$this->redis = $redis->getRedisClient();
|
||||
$this->hub_jo_key = $hub_jo_key;
|
||||
}
|
||||
|
||||
public function incrementJoCountForHub(Hub $hub)
|
||||
{
|
||||
$key = $hub->getID();
|
||||
|
||||
// get current count
|
||||
$jo_count = $this->redis->hget($this->hub_jo_key, $key);
|
||||
if ($jo_count == false)
|
||||
{
|
||||
// hub not in hash
|
||||
// add hub to hash
|
||||
// set to 1 since this is first jo for hub
|
||||
$this->redis->hset($this->hub_jo_key, $key, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// hub exist in hash
|
||||
// add to count
|
||||
$this->redis->hset($this->hub_jo_key, $key, $jo_count + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public function decrementJoCountForHub(Hub $hub)
|
||||
{
|
||||
$key = $hub->getID();
|
||||
|
||||
// get current count
|
||||
$jo_count = $this->redis->hget($this->hub_jo_key, $key);
|
||||
if ($jo_count)
|
||||
{
|
||||
// hub exist in hash
|
||||
// decrement count
|
||||
$this->redis->hset($this->hub_jo_key, $key, $jo_count - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public function arrangeHubs($hubs)
|
||||
{
|
||||
if (count($hubs) == 1)
|
||||
return $hubs;
|
||||
|
||||
$arranged_hubs = [];
|
||||
|
||||
foreach ($hubs as $hub_data)
|
||||
{
|
||||
$hub = $hub_data['hub'];
|
||||
|
||||
// need the id of hub
|
||||
$key = $hub->getID();
|
||||
|
||||
// get jo count of hub
|
||||
$hub_jo_count = $this->redis->hget($this->hub_jo_key, $key);
|
||||
|
||||
// check if hub is in hash. if not, hub has no jobs
|
||||
// but should still be added to results
|
||||
if ($hub_jo_count != null)
|
||||
{
|
||||
$arranged_hubs[] = [
|
||||
'hub' => $hub,
|
||||
'db_distance' => $hub_data['db_distance'],
|
||||
'distance' => $hub_data['distance'],
|
||||
'duration' => $hub_data['duration'],
|
||||
'jo_count' => $hub_jo_count,
|
||||
];
|
||||
}
|
||||
else
|
||||
{
|
||||
$arranged_hubs[] = [
|
||||
'hub' => $hub,
|
||||
'db_distance' => $hub_data['db_distance'],
|
||||
'distance' => $hub_data['distance'],
|
||||
'duration' => $hub_data['duration'],
|
||||
'jo_count' => 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
usort($arranged_hubs, function($a, $b) {
|
||||
if ($a['jo_count'] == $b['jo_count'])
|
||||
return 0;
|
||||
if ($a['jo_count'] < $b['jo_count'])
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
});
|
||||
|
||||
//error_log('arranged hubs ' . json_encode($arranged_hubs));
|
||||
|
||||
return $arranged_hubs;
|
||||
}
|
||||
}
|
||||
29
src/Service/HubFilterLogger.php
Normal file
29
src/Service/HubFilterLogger.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||