Add invoie_id to client subs

This commit is contained in:
= 2021-03-20 14:39:30 +11:00
parent 6be79ad022
commit 2eb7de95ad
2 changed files with 45 additions and 3 deletions

View File

@ -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;

View File

@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddInvoiceIdToClientSubscriptionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('client_subscriptions', function (Blueprint $table) {
$table->unsignedInteger('invoice_id')->nullable();
$table->foreign('invoice_id')->references('id')->on('invoices')->onDelete('cascade')->onUpdate('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}