From 2eb7de95adaa1e4a77326c2047bf7aa6ca33d1f4 Mon Sep 17 00:00:00 2001 From: = Date: Sat, 20 Mar 2021 14:39:30 +1100 Subject: [PATCH] Add invoie_id to client subs --- .../BillingSubscriptionService.php | 17 ++++++++-- ...voice_id_to_client_subscriptions_table.php | 31 +++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2021_03_20_033751_add_invoice_id_to_client_subscriptions_table.php diff --git a/app/Services/BillingSubscription/BillingSubscriptionService.php b/app/Services/BillingSubscription/BillingSubscriptionService.php index 1ce2b296b602..0043e028e5ae 100644 --- a/app/Services/BillingSubscription/BillingSubscriptionService.php +++ b/app/Services/BillingSubscription/BillingSubscriptionService.php @@ -102,7 +102,7 @@ class BillingSubscriptionService //do we have a promocode? enter this as a line item. - if(strlen($data['coupon']) >=1) + if(strlen($data['coupon']) >=1 && ($data['coupon'] == $this->billing_subscription->promo_code) && $this->billing_subscription->promo_discount > 0) $line_items[] = $this->createPromoLine($data); return $line_items; @@ -113,13 +113,24 @@ class BillingSubscriptionService $product = $this->billing_subscription->product; - $price = 0; + $discounted_amount = 0; + $discount = 0; + $amount = $data['quantity'] * $product->cost; + if ($this->billing_subscription->is_amount_discount == true) { + $discount = $this->billing_subscription->promo_discount; + } + else { + $discount = round($amount * ($this->billing_subscription->promo_discount / 100), 2); + } + + $discounted_amount = $amount - $discount; + $item = new InvoiceItem; $item->quantity = 1; $item->product_key = ctrans('texts.promo_code'); $item->notes = ctrans('texts.promo_code'); - $item->cost = $price; + $item->cost = $discounted_amount; $item->tax_rate1 = $product->tax_rate1 ?: 0; $item->tax_name1 = $product->tax_name1 ?: ''; $item->tax_rate2 = $product->tax_rate2 ?: 0; diff --git a/database/migrations/2021_03_20_033751_add_invoice_id_to_client_subscriptions_table.php b/database/migrations/2021_03_20_033751_add_invoice_id_to_client_subscriptions_table.php new file mode 100644 index 000000000000..18e1e7241a42 --- /dev/null +++ b/database/migrations/2021_03_20_033751_add_invoice_id_to_client_subscriptions_table.php @@ -0,0 +1,31 @@ +unsignedInteger('invoice_id')->nullable(); + + $table->foreign('invoice_id')->references('id')->on('invoices')->onDelete('cascade')->onUpdate('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + } +}