From dda39a9e7b5040c4ba1c27aadecf889eb2554a7d Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 27 May 2021 10:16:38 +0000 Subject: [PATCH] Fix issues found. #570 --- src/Controller/APIController.php | 6 +++--- src/Entity/Invoice.php | 18 ++++++++++++++++++ .../InvoiceGenerator/ResqInvoiceGenerator.php | 10 ++++++++-- .../JobOrderHandler/ResqJobOrderHandler.php | 2 +- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 409f36b8..6c275ead 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -1133,7 +1133,7 @@ class APIController extends Controller implements LoggedController foreach ($customer_tags as $customer_tag) { // TODO: not too comfy with this being hardcoded - if ($customer_tag->getID() == 'CAR_CLUB_PROMO') + if ($customer_tag->getID() == $invoice->getUsedCustomerTagId()) { // remove associated entity $customer->removeCustomerTag($customer_tag); @@ -1147,7 +1147,7 @@ class APIController extends Controller implements LoggedController $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, + $promo_logger->logPromoInfo($created_by, $cust_id, $cust_fname, $cust_lname, $jo_id, $invoice_id, $amount); } } @@ -2711,7 +2711,7 @@ class APIController extends Controller implements LoggedController foreach ($customer_tags as $customer_tag) { // TODO: not too comfy with this being hardcoded - if ($customer_tag->getID() == 'CAR_CLUB_PROMO') + if ($customer_tag->getID() == $invoice->getUsedCustomerTagId()) { // remove associated entity $customer->removeCustomerTag($customer_tag); diff --git a/src/Entity/Invoice.php b/src/Entity/Invoice.php index 305c7d84..3a01066d 100644 --- a/src/Entity/Invoice.php +++ b/src/Entity/Invoice.php @@ -102,6 +102,12 @@ class Invoice */ protected $promo; + // customer tag used by this invoice + /** + * @ORM\Column(type="string", length=80, nullable=true) + */ + protected $used_customer_tag_id; + public function __construct() { $this->date_create = new DateTime(); @@ -257,4 +263,16 @@ class Invoice { return $this->promo; } + + public function setUsedCustomerTagId($used_customer_tag_id) + { + $this->used_customer_tag_id = $used_customer_tag_id; + return $this; + } + + public function getUsedCustomerTagId() + { + return $this->used_customer_tag_id; + } + } diff --git a/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php b/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php index f1be78f1..47d8728e 100644 --- a/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php +++ b/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php @@ -486,17 +486,19 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface else { // assume fixed amount for this - $discount = $discount_value; + $discount_amount = $discount_value; $discounted_total = $total_amount - $discount; } - $total_discount_amount += $discounted_total; + $total_discount_amount += $discount_amount; $item = new InvoiceItem(); $item->setInvoice($invoice) ->setTitle($ct_info['invoice_display']) ->setQuantity(1) ->setPrice(-1 * $total_discount_amount); $invoice->addItem($item); + + $invoice->setUsedCustomerTagId($ct_info['id']); } $total['discount'] = $total_discount_amount; @@ -792,17 +794,21 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface { // TODO: can we keep the tag ids hardcoded? // check tag details + // get first tag found $cust_tag_type = $customer_tag->getTagDetails('type'); // TODO: might have to make this statement be more generic? if (($cust_tag_type != null) && ($cust_tag_type == 'one-time-discount')) { $cust_tag_info[] = [ + 'id' => $customer_tag->getID(), 'type' => $cust_tag_type, 'discount_type' => $customer_tag->getTagDetails('discount_type'), 'discount_amount' => $customer_tag->getTagDetails('discount_amount'), 'discount_value' => $customer_tag->getTagDetails('discount_value'), 'invoice_display' => $customer_tag->getTagDetails('invoice_display'), ]; + + break; } } } diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 804c0002..2ec57b40 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -494,7 +494,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface foreach ($customer_tags as $customer_tag) { // TODO: not too comfy with this being hardcoded - if ($customer_tag->getID() == 'CAR_CLUB_PROMO') + if ($customer_tag->getID() == $jo->getInvoice()->getUsedCustomerTagId()) { // remove associated entity $customer->removeCustomerTag($customer_tag);