Add price tiering for Resq 2 App and TAPI. #782
This commit is contained in:
parent
c136b0666b
commit
213171f4b7
6 changed files with 99 additions and 20 deletions
|
|
@ -50,6 +50,7 @@ use App\Service\HubFilterLogger;
|
|||
use App\Service\HubFilteringGeoChecker;
|
||||
use App\Service\HashGenerator;
|
||||
use App\Service\JobOrderManager;
|
||||
use App\Service\PriceTierManager;
|
||||
|
||||
use App\Entity\MobileSession;
|
||||
use App\Entity\Customer;
|
||||
|
|
@ -2911,6 +2912,10 @@ class APIController extends Controller implements LoggedController
|
|||
// old app doesn't have separate jumpstart
|
||||
$icrit->setSource(TransactionOrigin::CALL);
|
||||
|
||||
// set price tier
|
||||
$pt_id = $this->pt_manager->getPriceTier($jo->getCoordinates());
|
||||
$icrit->setPriceTier($pt_id);
|
||||
|
||||
// check promo
|
||||
$promo_id = $req->request->get('promo_id');
|
||||
if (!empty($promo_id))
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ use App\Service\JobOrderHandlerInterface;
|
|||
use App\Service\InvoiceGeneratorInterface;
|
||||
use App\Service\RisingTideGateway;
|
||||
use App\Service\RiderTracker;
|
||||
use App\Service\PriceTierManager;
|
||||
|
||||
use App\Ramcar\ServiceType;
|
||||
use App\Ramcar\TradeInType;
|
||||
|
|
@ -1099,7 +1100,7 @@ class RiderAppController extends ApiController
|
|||
return new APIResponse(true, 'Batteries found.', $data);
|
||||
}
|
||||
|
||||
public function changeService(Request $req, EntityManagerInterface $em, InvoiceGeneratorInterface $ic)
|
||||
public function changeService(Request $req, EntityManagerInterface $em, InvoiceGeneratorInterface $ic, PriceTierManager $pt_manager)
|
||||
{
|
||||
// $this->debugRequest($req);
|
||||
|
||||
|
|
@ -1203,6 +1204,10 @@ class RiderAppController extends ApiController
|
|||
$crit->setHasCoolant($jo->hasCoolant());
|
||||
$crit->setIsTaxable();
|
||||
|
||||
// set price tier
|
||||
$pt_id = $pt_manager->getPriceTier($jo->getCoordinates());
|
||||
$icrit->setPriceTier($pt_id);
|
||||
|
||||
if ($promo != null)
|
||||
$crit->addPromo($promo);
|
||||
|
||||
|
|
|
|||
|
|
@ -4,18 +4,22 @@ namespace App\Controller\CustomerAppAPI;
|
|||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Catalyst\ApiBundle\Component\Response as ApiResponse;
|
||||
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
||||
|
||||
use App\Service\InvoiceGeneratorInterface;
|
||||
use App\Service\PriceTierManager;
|
||||
use App\Ramcar\InvoiceCriteria;
|
||||
use App\Ramcar\TradeInType;
|
||||
use App\Ramcar\TransactionOrigin;
|
||||
use App\Entity\CustomerVehicle;
|
||||
use App\Entity\Promo;
|
||||
use App\Entity\Battery;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\CustomerMetadata;
|
||||
|
||||
class InvoiceController extends ApiController
|
||||
{
|
||||
public function getEstimate(Request $req, InvoiceGeneratorInterface $ic)
|
||||
public function getEstimate(Request $req, InvoiceGeneratorInterface $ic, PriceTierManager $pt_manager)
|
||||
{
|
||||
// $this->debugRequest($req);
|
||||
|
||||
|
|
@ -36,6 +40,9 @@ class InvoiceController extends ApiController
|
|||
return new ApiResponse(false, 'No customer information found.');
|
||||
}
|
||||
|
||||
// get customer location from customer_metadata using customer id
|
||||
$coordinates = $this->getCustomerMetadata($cust);
|
||||
|
||||
// make invoice criteria
|
||||
$icrit = new InvoiceCriteria();
|
||||
$icrit->setServiceType($req->request->get('service_type'));
|
||||
|
|
@ -113,6 +120,18 @@ class InvoiceController extends ApiController
|
|||
// set JO source
|
||||
$icrit->setSource(TransactionOrigin::MOBILE_APP);
|
||||
|
||||
// set price tier
|
||||
$pt_id = 0;
|
||||
if ($coordinates != null)
|
||||
{
|
||||
error_log('coordinates are not null');
|
||||
$pt_id = $pt_manager->getPriceTier($coordinates);
|
||||
}
|
||||
else
|
||||
error_log('null?');
|
||||
|
||||
$icrit->setPriceTier($pt_id);
|
||||
|
||||
// send to invoice generator
|
||||
$invoice = $ic->generateInvoice($icrit);
|
||||
|
||||
|
|
@ -148,4 +167,28 @@ class InvoiceController extends ApiController
|
|||
// response
|
||||
return new ApiResponse(true, '', $data);
|
||||
}
|
||||
|
||||
protected function getCustomerMetadata(Customer $cust)
|
||||
{
|
||||
$coordinates = null;
|
||||
|
||||
// check if customer already has existing metadata
|
||||
$c_meta = $this->em->getRepository(CustomerMetadata::class)->findOneBy(['customer' => $cust]);
|
||||
if ($c_meta != null)
|
||||
{
|
||||
$meta_data = $c_meta->getAllMetaInfo();
|
||||
foreach ($meta_data as $m_info)
|
||||
{
|
||||
if ((isset($m_info['longitude'])) && (isset($m_info['latitude'])))
|
||||
{
|
||||
$lng = $m_info['longitude'];
|
||||
$lat = $m_info['latitude'];
|
||||
|
||||
$coordinates = new Point($lng, $lat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $coordinates;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ use App\Service\HubDistributor;
|
|||
use App\Service\HubFilterLogger;
|
||||
use App\Service\HubFilteringGeoChecker;
|
||||
use App\Service\JobOrderManager;
|
||||
use App\Service\PriceTierManager;
|
||||
use App\Ramcar\ServiceType;
|
||||
use App\Ramcar\APIRiderStatus;
|
||||
use App\Ramcar\InvoiceCriteria;
|
||||
|
|
@ -484,7 +485,8 @@ class JobOrderController extends ApiController
|
|||
HubDistributor $hub_dist,
|
||||
HubFilterLogger $hub_filter_logger,
|
||||
HubFilteringGeoChecker $hub_geofence,
|
||||
JobOrderManager $jo_manager
|
||||
JobOrderManager $jo_manager,
|
||||
PriceTierManager $pt_manager
|
||||
) {
|
||||
// validate params
|
||||
$validity = $this->validateRequest($req, [
|
||||
|
|
@ -698,6 +700,10 @@ class JobOrderController extends ApiController
|
|||
// set JO source
|
||||
$icrit->setSource(TransactionOrigin::MOBILE_APP);
|
||||
|
||||
// set price tier
|
||||
$pt_id = $pt_manager->getPriceTier($jo->getCoordinates());
|
||||
$icrit->setPriceTier($pt_id);
|
||||
|
||||
// send to invoice generator
|
||||
$invoice = $ic->generateInvoice($icrit);
|
||||
$jo->setInvoice($invoice);
|
||||
|
|
@ -970,7 +976,8 @@ class JobOrderController extends ApiController
|
|||
HubDistributor $hub_dist,
|
||||
HubFilterLogger $hub_filter_logger,
|
||||
HubFilteringGeoChecker $hub_geofence,
|
||||
JobOrderManager $jo_manager
|
||||
JobOrderManager $jo_manager,
|
||||
PriceTierManager $pt_manager
|
||||
) {
|
||||
// validate params
|
||||
$validity = $this->validateRequest($req, [
|
||||
|
|
@ -1127,6 +1134,10 @@ class JobOrderController extends ApiController
|
|||
// set JO source
|
||||
$icrit->setSource(TransactionOrigin::MOBILE_APP);
|
||||
|
||||
// set price tier
|
||||
$pt_id = $pt_manager->getPriceTier($jo->getCoordinates());
|
||||
$icrit->setPriceTier($pt_id);
|
||||
|
||||
// send to invoice generator
|
||||
$invoice = $ic->generateInvoice($icrit);
|
||||
$jo->setInvoice($invoice);
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ use App\Service\RiderTracker;
|
|||
use App\Service\PromoLogger;
|
||||
use App\Service\MapTools;
|
||||
use App\Service\JobOrderManager;
|
||||
use App\Service\PriceTierManager;
|
||||
|
||||
use App\Entity\JobOrder;
|
||||
use App\Entity\CustomerVehicle;
|
||||
|
|
@ -79,7 +80,8 @@ class JobOrderController extends ApiController
|
|||
FCMSender $fcmclient,
|
||||
RiderAssignmentHandlerInterface $rah, PromoLogger $promo_logger,
|
||||
HubSelector $hub_select, HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger,
|
||||
HubFilteringGeoChecker $hub_geofence, EntityManagerInterface $em, JobOrderManager $jo_manager)
|
||||
HubFilteringGeoChecker $hub_geofence, EntityManagerInterface $em, JobOrderManager $jo_manager,
|
||||
PriceTierManager $pt_manager)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('tapi_jo.request', null, 'No access.');
|
||||
|
||||
|
|
@ -165,7 +167,17 @@ class JobOrderController extends ApiController
|
|||
// set JO source
|
||||
$icrit->setSource(TransactionOrigin::THIRD_PARTY);
|
||||
|
||||
$icrit->addEntry($data['batt'], $data['trade_in_type'], 1);
|
||||
// set price tier
|
||||
$pt_id = $pt_manager->getPriceTier($jo->getCoordinates());
|
||||
$icrit->setPriceTier($pt_id);
|
||||
|
||||
// add the actual battery item first
|
||||
$icrit->addEntry($data['batt'], null, 1);
|
||||
|
||||
// if we have a trade in, add it as well, assuming trade in battery == battery purchased
|
||||
if (!empty($data['trade_in_type'])) {
|
||||
$icrit->addEntry($data['batt'], $data['trade_in_type'], 1);
|
||||
}
|
||||
|
||||
// send to invoice generator
|
||||
$invoice = $ic->generateInvoice($icrit);
|
||||
|
|
|
|||
|
|
@ -55,21 +55,24 @@ class PriceTierManager
|
|||
{
|
||||
$price_tier_id = 0;
|
||||
|
||||
$long = $coordinates->getLongitude();
|
||||
$lat = $coordinates->getLatitude();
|
||||
|
||||
// get location's price tier, given a set of coordinates
|
||||
$query = $this->em->createQuery('SELECT s from App\Entity\SupportedArea s where st_contains(s.coverage_area, point(:long, :lat)) = true');
|
||||
$area = $query->setParameter('long', $long)
|
||||
->setParameter('lat', $lat)
|
||||
->setMaxResults(1)
|
||||
->getOneOrNullResult();
|
||||
|
||||
if ($area != null)
|
||||
if ($coordinates != null)
|
||||
{
|
||||
$price_tier = $area->getPriceTier();
|
||||
if ($price_tier != null)
|
||||
$price_tier_id = $price_tier->getID();
|
||||
$long = $coordinates->getLongitude();
|
||||
$lat = $coordinates->getLatitude();
|
||||
|
||||
// get location's price tier, given a set of coordinates
|
||||
$query = $this->em->createQuery('SELECT s from App\Entity\SupportedArea s where st_contains(s.coverage_area, point(:long, :lat)) = true');
|
||||
$area = $query->setParameter('long', $long)
|
||||
->setParameter('lat', $lat)
|
||||
->setMaxResults(1)
|
||||
->getOneOrNullResult();
|
||||
|
||||
if ($area != null)
|
||||
{
|
||||
$price_tier = $area->getPriceTier();
|
||||
if ($price_tier != null)
|
||||
$price_tier_id = $price_tier->getID();
|
||||
}
|
||||
}
|
||||
|
||||
return $price_tier_id;
|
||||
|
|
|
|||
Loading…
Reference in a new issue