mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 16:34:36 -04:00
Add invoie_id to client subs
This commit is contained in:
parent
6be79ad022
commit
2eb7de95ad
@ -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;
|
||||
|
@ -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()
|
||||
{
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user