mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
Subscriptions v2
This commit is contained in:
parent
32ff078a64
commit
a63d267deb
@ -195,6 +195,7 @@ class BillingPortalPurchasev2 extends Component
|
||||
public $login;
|
||||
public $float_amount_total;
|
||||
public $payment_started = false;
|
||||
public $valid_coupon = false;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
@ -308,10 +309,14 @@ class BillingPortalPurchasev2 extends Component
|
||||
public function handleCoupon()
|
||||
{
|
||||
|
||||
if($this->coupon == $this->subscription->promo_code)
|
||||
if($this->coupon == $this->subscription->promo_code) {
|
||||
$this->buildBundle();
|
||||
else
|
||||
$this->valid_coupon = true;
|
||||
}
|
||||
else{
|
||||
$this->discount = 0;
|
||||
$this->valid_coupon = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -332,6 +337,7 @@ class BillingPortalPurchasev2 extends Component
|
||||
$total = $p->price * $qty;
|
||||
|
||||
$this->bundle->push([
|
||||
'description' => $p->notes,
|
||||
'product_key' => $p->product_key,
|
||||
'unit_cost' => $p->price,
|
||||
'product' => nl2br(substr($p->notes, 0, 50)),
|
||||
@ -350,6 +356,7 @@ class BillingPortalPurchasev2 extends Component
|
||||
$total = $p->price * $qty;
|
||||
|
||||
$this->bundle->push([
|
||||
'description' => $p->notes,
|
||||
'product_key' => $p->product_key,
|
||||
'unit_cost' => $p->price,
|
||||
'product' => nl2br(substr($p->notes, 0, 50)),
|
||||
@ -379,6 +386,7 @@ class BillingPortalPurchasev2 extends Component
|
||||
|
||||
|
||||
$this->bundle->push([
|
||||
'description' => $p->notes,
|
||||
'product_key' => $p->product_key,
|
||||
'unit_cost' => $p->price,
|
||||
'product' => nl2br(substr($p->notes, 0, 50)),
|
||||
@ -404,6 +412,7 @@ class BillingPortalPurchasev2 extends Component
|
||||
return;
|
||||
|
||||
$this->bundle->push([
|
||||
'description' => $p->notes,
|
||||
'product_key' => $p->product_key,
|
||||
'unit_cost' => $p->price,
|
||||
'product' => nl2br(substr($p->notes, 0, 50)),
|
||||
@ -535,7 +544,7 @@ class BillingPortalPurchasev2 extends Component
|
||||
|
||||
$this->invoice = $this->subscription
|
||||
->service()
|
||||
->createInvoiceV2($this->bundle)
|
||||
->createInvoiceV2($this->bundle, $this->contact->client_id, $this->valid_coupon)
|
||||
->service()
|
||||
// ->markSent()
|
||||
->fillDefaults()
|
||||
|
@ -704,7 +704,7 @@ class SubscriptionService
|
||||
|
||||
}
|
||||
|
||||
public function createInvoiceV2($bundle)
|
||||
public function createInvoiceV2($bundle, $client_id, $valid_coupon = false)
|
||||
{
|
||||
|
||||
$invoice_repo = new InvoiceRepository();
|
||||
@ -712,17 +712,30 @@ class SubscriptionService
|
||||
|
||||
$invoice = InvoiceFactory::create($this->subscription->company_id, $this->subscription->user_id);
|
||||
$invoice->subscription_id = $this->subscription->id;
|
||||
$invoice->client_id = $client_id;
|
||||
|
||||
$line_items = $bundle->map(function ($item){
|
||||
|
||||
$line_item = new InvoiceItem;
|
||||
|
||||
$line_item->product_key = $item['product_key'];
|
||||
$line_item->quantity = $item['qty'];
|
||||
$line_item->cost = $item['unit_cost'];
|
||||
$line_item->notes = $item['description'];
|
||||
|
||||
return $line_item;
|
||||
|
||||
})->toArray();
|
||||
|
||||
nlog($line_items);
|
||||
|
||||
$invoice->line_items = $line_items;
|
||||
|
||||
if($valid_coupon){
|
||||
$invoice->discount = $this->subscription->promo_discount;
|
||||
$invoice->is_amount_discount = $this->subscription->is_amount_discount;
|
||||
}
|
||||
|
||||
return $invoice_repo->save([], $invoice);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user