From 03360a2ae9f4a1c80b03692269acda124dd670bb Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 7 May 2021 07:48:22 +0000 Subject: [PATCH] Add logging when one time discount has been availed for mobile. Add removal of promo from customer when one time discount has been availed for mobile. #558 --- src/Controller/APIController.php | 70 ++++++++++++++++++- .../JobOrderHandler/ResqJobOrderHandler.php | 2 +- 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index f7004295..099f45a3 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -44,6 +44,7 @@ use App\Service\HubSelector; use App\Service\HubDistributor; use App\Service\HubFilterLogger; use App\Service\WarrantyAPILogger; +use App\Service\PromoLogger; use App\Entity\MobileSession; use App\Entity\Customer; @@ -852,7 +853,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, HubSelector $hub_select, - HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger) + HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger, + PromoLogger $promo_logger) { // check required parameters and api key $required_params = [ @@ -1160,6 +1162,37 @@ class APIController extends Controller implements LoggedController 'invoice' => $invoice_data ]; + // check service type + if ($jo->getServiceType() == ServiceType::BATTERY_REPLACEMENT_NEW) + { + $customer = $cv->getCustomer(); + $customer_tags = $customer->getCustomerTagObjects(); + if (!empty($customer_tags)) + { + foreach ($customer_tags as $customer_tag) + { + // TODO: not too comfy with this being hardcoded + if ($customer_tag->getID() == 'CAR_CLUB_PROMO') + { + // remove associated entity + $customer->removeCustomerTag($customer_tag); + + // log the availment of promo from customer + $created_by = $req->query->get('api_key');; + $cust_id = $jo->getCustomer()->getID(); + $cust_fname = $jo->getCustomer()->getFirstName(); + $cust_lname = $jo->getCustomer()->getLastName(); + $jo_id = $jo->getID(); + $invoice_id = $jo->getInvoice()->getID(); + // TODO: check if we store total price of invoice or just the discounted amount + $amount = $jo->getInvoice()->getTotalPrice(); + $this->promo_logger->logPromoInfo($created_by, $cust_id, $cust_fname, $cust_lname, $jo_id, + $invoice_id, $amount); + } + } + } + } + // set data $res->setData($data); @@ -2371,7 +2404,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, HubSelector $hub_select, - HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger) + HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger, + PromoLogger $promo_logger) { // check required parameters and api key $required_params = [ @@ -2740,6 +2774,38 @@ class APIController extends Controller implements LoggedController 'invoice' => $invoice_data ]; + // need to check for customer tag/promo + // check service type + if ($jo->getServiceType() == ServiceType::BATTERY_REPLACEMENT_NEW) + { + $customer = $cv->getCustomer(); + $customer_tags = $customer->getCustomerTagObjects(); + if (!empty($customer_tags)) + { + foreach ($customer_tags as $customer_tag) + { + // TODO: not too comfy with this being hardcoded + if ($customer_tag->getID() == 'CAR_CLUB_PROMO') + { + // remove associated entity + $customer->removeCustomerTag($customer_tag); + + // log the availment of promo from customer + $created_by = $req->query->get('api_key');; + $cust_id = $jo->getCustomer()->getID(); + $cust_fname = $jo->getCustomer()->getFirstName(); + $cust_lname = $jo->getCustomer()->getLastName(); + $jo_id = $jo->getID(); + $invoice_id = $jo->getInvoice()->getID(); + // TODO: check if we store total price of invoice or just the discounted amount + $amount = $jo->getInvoice()->getTotalPrice(); + $promo_logger->logPromoInfo($created_by, $cust_id, $cust_fname, $cust_lname, $jo_id, + $invoice_id, $amount); + } + } + } + } + // set data $res->setData($data); diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index ca6a747f..e0bf09a5 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -304,7 +304,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface { // new job order $jo = new JobOrder(); - $flag_new_jo = true; + $flag_new_jo = true; } // find customer