Add logging when one time discount has been availed. Add removal of promo from customer when one time discount has been availed. #558
This commit is contained in:
parent
f1c45af22e
commit
df05316612
5 changed files with 60 additions and 9 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue