diff --git a/config/services.yaml b/config/services.yaml index dea32a8b..0a176fd9 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -289,3 +289,8 @@ services: App\Service\WarrantyAPILogger: arguments: $em: "@doctrine.orm.entity_manager" + + # promo logger + App\Service\PromoLogger: + arguments: + $em: "@doctrine.orm.entity_manager" diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index d7c66525..2f593e00 100644 --- a/src/Entity/Customer.php +++ b/src/Entity/Customer.php @@ -643,4 +643,9 @@ class Customer return $this->customer_tags; } + public function removeCustomerTag(CustomerTag $customer_tag) + { + $this->customer_tags->removeElement($customer_tag); + $customer_tag->removeCustomer($this); + } } diff --git a/src/Entity/CustomerTag.php b/src/Entity/CustomerTag.php index 43942a76..28d41fd0 100644 --- a/src/Entity/CustomerTag.php +++ b/src/Entity/CustomerTag.php @@ -91,6 +91,11 @@ class CustomerTag return $this->customers; } + public function removeCustomer(Customer $customer) + { + $this->customers->removeElement($customer); + } + public function addTagDetails($id, $value) { $this->tag_details[$id] = $value; diff --git a/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php b/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php index 2c0b1abf..f4c752bb 100644 --- a/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php +++ b/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php @@ -789,18 +789,12 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface { foreach ($customer_tags as $customer_tag) { + // TODO: can we keep the tag ids hardcoded? // check tag details $cust_tag_type = $customer_tag->getTagDetails('type'); - error_log($cust_tag_type); + // TODO: might have to make this statement be more generic? if (($cust_tag_type != null) && ($cust_tag_type == 'one-time-discount')) { - // get the discount type and discount amount - $cust_tag_discount_amount = $customer_tag->getTagDetails('discount_amount'); - - $cust_tag_invoice_display = $customer_tag->getTagDetails('invoice_display'); - - error_log($cust_tag_invoice_display); - $cust_tag_info[] = [ 'type' => $cust_tag_type, 'discount_type' => $customer_tag->getTagDetails('discount_type'), diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 14660083..ca6a747f 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -54,6 +54,7 @@ use App\Service\MapTools; use App\Service\RisingTideGateway; use App\Service\HubSelector; use App\Service\HubDistributor; +use App\Service\PromoLogger; use CrEOF\Spatial\PHP\Types\Geometry\Point; @@ -76,6 +77,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface protected $wh; protected $rt; protected $hub_dist; + protected $promo_logger; protected $template_hash; @@ -83,7 +85,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface InvoiceGeneratorInterface $ic, ValidatorInterface $validator, TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah, string $country_code, WarrantyHandler $wh, RisingTideGateway $rt, - HubDistributor $hub_dist) + HubDistributor $hub_dist, PromoLogger $promo_logger) { $this->em = $em; $this->ic = $ic; @@ -95,6 +97,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $this->wh = $wh; $this->rt = $rt; $this->hub_dist = $hub_dist; + $this->promo_logger = $promo_logger; $this->loadTemplates(); } @@ -295,10 +298,13 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $em = $this->em; $jo = $em->getRepository(JobOrder::class)->find($id); + // flag for new job order for the customer tags + $flag_new_jo = false; if (empty($jo)) { // new job order $jo = new JobOrder(); + $flag_new_jo = true; } // find customer @@ -471,6 +477,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $em->persist($event); $em->flush(); + } } @@ -479,6 +486,41 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface if ($jo != null) { $data['job_order'] = $jo; + + // need to get the customer tags but only if new JO + if ($flag_new_jo) + { + // check service type + if ($jo->getServiceType() == ServiceType::BATTERY_REPLACEMENT_NEW) + { + $customer = $cust_vehicle->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 = $jo->getCreatedBy()->getUsername(); + $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); + } + } + } + } + } } return $data;