Fix issues found. #570

This commit is contained in:
Korina Cordero 2021-05-27 10:16:38 +00:00
parent 989fdabc5b
commit dda39a9e7b
4 changed files with 30 additions and 6 deletions

View file

@ -1133,7 +1133,7 @@ class APIController extends Controller implements LoggedController
foreach ($customer_tags as $customer_tag) foreach ($customer_tags as $customer_tag)
{ {
// TODO: not too comfy with this being hardcoded // TODO: not too comfy with this being hardcoded
if ($customer_tag->getID() == 'CAR_CLUB_PROMO') if ($customer_tag->getID() == $invoice->getUsedCustomerTagId())
{ {
// remove associated entity // remove associated entity
$customer->removeCustomerTag($customer_tag); $customer->removeCustomerTag($customer_tag);
@ -1147,7 +1147,7 @@ class APIController extends Controller implements LoggedController
$invoice_id = $jo->getInvoice()->getID(); $invoice_id = $jo->getInvoice()->getID();
// TODO: check if we store total price of invoice or just the discounted amount // TODO: check if we store total price of invoice or just the discounted amount
$amount = $jo->getInvoice()->getTotalPrice(); $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); $invoice_id, $amount);
} }
} }
@ -2711,7 +2711,7 @@ class APIController extends Controller implements LoggedController
foreach ($customer_tags as $customer_tag) foreach ($customer_tags as $customer_tag)
{ {
// TODO: not too comfy with this being hardcoded // TODO: not too comfy with this being hardcoded
if ($customer_tag->getID() == 'CAR_CLUB_PROMO') if ($customer_tag->getID() == $invoice->getUsedCustomerTagId())
{ {
// remove associated entity // remove associated entity
$customer->removeCustomerTag($customer_tag); $customer->removeCustomerTag($customer_tag);

View file

@ -102,6 +102,12 @@ class Invoice
*/ */
protected $promo; protected $promo;
// customer tag used by this invoice
/**
* @ORM\Column(type="string", length=80, nullable=true)
*/
protected $used_customer_tag_id;
public function __construct() public function __construct()
{ {
$this->date_create = new DateTime(); $this->date_create = new DateTime();
@ -257,4 +263,16 @@ class Invoice
{ {
return $this->promo; 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;
}
} }

View file

@ -486,17 +486,19 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface
else else
{ {
// assume fixed amount for this // assume fixed amount for this
$discount = $discount_value; $discount_amount = $discount_value;
$discounted_total = $total_amount - $discount; $discounted_total = $total_amount - $discount;
} }
$total_discount_amount += $discounted_total; $total_discount_amount += $discount_amount;
$item = new InvoiceItem(); $item = new InvoiceItem();
$item->setInvoice($invoice) $item->setInvoice($invoice)
->setTitle($ct_info['invoice_display']) ->setTitle($ct_info['invoice_display'])
->setQuantity(1) ->setQuantity(1)
->setPrice(-1 * $total_discount_amount); ->setPrice(-1 * $total_discount_amount);
$invoice->addItem($item); $invoice->addItem($item);
$invoice->setUsedCustomerTagId($ct_info['id']);
} }
$total['discount'] = $total_discount_amount; $total['discount'] = $total_discount_amount;
@ -792,17 +794,21 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface
{ {
// TODO: can we keep the tag ids hardcoded? // TODO: can we keep the tag ids hardcoded?
// check tag details // check tag details
// get first tag found
$cust_tag_type = $customer_tag->getTagDetails('type'); $cust_tag_type = $customer_tag->getTagDetails('type');
// TODO: might have to make this statement be more generic? // TODO: might have to make this statement be more generic?
if (($cust_tag_type != null) && ($cust_tag_type == 'one-time-discount')) if (($cust_tag_type != null) && ($cust_tag_type == 'one-time-discount'))
{ {
$cust_tag_info[] = [ $cust_tag_info[] = [
'id' => $customer_tag->getID(),
'type' => $cust_tag_type, 'type' => $cust_tag_type,
'discount_type' => $customer_tag->getTagDetails('discount_type'), 'discount_type' => $customer_tag->getTagDetails('discount_type'),
'discount_amount' => $customer_tag->getTagDetails('discount_amount'), 'discount_amount' => $customer_tag->getTagDetails('discount_amount'),
'discount_value' => $customer_tag->getTagDetails('discount_value'), 'discount_value' => $customer_tag->getTagDetails('discount_value'),
'invoice_display' => $customer_tag->getTagDetails('invoice_display'), 'invoice_display' => $customer_tag->getTagDetails('invoice_display'),
]; ];
break;
} }
} }
} }

View file

@ -494,7 +494,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
foreach ($customer_tags as $customer_tag) foreach ($customer_tags as $customer_tag)
{ {
// TODO: not too comfy with this being hardcoded // 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 // remove associated entity
$customer->removeCustomerTag($customer_tag); $customer->removeCustomerTag($customer_tag);