1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00

Subscriptions v2

This commit is contained in:
David Bomba 2022-12-12 16:00:39 +11:00
parent 32ff078a64
commit a63d267deb
2 changed files with 27 additions and 5 deletions

View File

@ -195,6 +195,7 @@ class BillingPortalPurchasev2 extends Component
public $login; public $login;
public $float_amount_total; public $float_amount_total;
public $payment_started = false; public $payment_started = false;
public $valid_coupon = false;
public function mount() public function mount()
{ {
@ -308,10 +309,14 @@ class BillingPortalPurchasev2 extends Component
public function handleCoupon() public function handleCoupon()
{ {
if($this->coupon == $this->subscription->promo_code) if($this->coupon == $this->subscription->promo_code) {
$this->buildBundle(); $this->buildBundle();
else $this->valid_coupon = true;
}
else{
$this->discount = 0; $this->discount = 0;
$this->valid_coupon = false;
}
} }
@ -332,6 +337,7 @@ class BillingPortalPurchasev2 extends Component
$total = $p->price * $qty; $total = $p->price * $qty;
$this->bundle->push([ $this->bundle->push([
'description' => $p->notes,
'product_key' => $p->product_key, 'product_key' => $p->product_key,
'unit_cost' => $p->price, 'unit_cost' => $p->price,
'product' => nl2br(substr($p->notes, 0, 50)), 'product' => nl2br(substr($p->notes, 0, 50)),
@ -350,6 +356,7 @@ class BillingPortalPurchasev2 extends Component
$total = $p->price * $qty; $total = $p->price * $qty;
$this->bundle->push([ $this->bundle->push([
'description' => $p->notes,
'product_key' => $p->product_key, 'product_key' => $p->product_key,
'unit_cost' => $p->price, 'unit_cost' => $p->price,
'product' => nl2br(substr($p->notes, 0, 50)), 'product' => nl2br(substr($p->notes, 0, 50)),
@ -379,6 +386,7 @@ class BillingPortalPurchasev2 extends Component
$this->bundle->push([ $this->bundle->push([
'description' => $p->notes,
'product_key' => $p->product_key, 'product_key' => $p->product_key,
'unit_cost' => $p->price, 'unit_cost' => $p->price,
'product' => nl2br(substr($p->notes, 0, 50)), 'product' => nl2br(substr($p->notes, 0, 50)),
@ -404,6 +412,7 @@ class BillingPortalPurchasev2 extends Component
return; return;
$this->bundle->push([ $this->bundle->push([
'description' => $p->notes,
'product_key' => $p->product_key, 'product_key' => $p->product_key,
'unit_cost' => $p->price, 'unit_cost' => $p->price,
'product' => nl2br(substr($p->notes, 0, 50)), 'product' => nl2br(substr($p->notes, 0, 50)),
@ -535,7 +544,7 @@ class BillingPortalPurchasev2 extends Component
$this->invoice = $this->subscription $this->invoice = $this->subscription
->service() ->service()
->createInvoiceV2($this->bundle) ->createInvoiceV2($this->bundle, $this->contact->client_id, $this->valid_coupon)
->service() ->service()
// ->markSent() // ->markSent()
->fillDefaults() ->fillDefaults()

View File

@ -704,7 +704,7 @@ class SubscriptionService
} }
public function createInvoiceV2($bundle) public function createInvoiceV2($bundle, $client_id, $valid_coupon = false)
{ {
$invoice_repo = new InvoiceRepository(); $invoice_repo = new InvoiceRepository();
@ -712,17 +712,30 @@ class SubscriptionService
$invoice = InvoiceFactory::create($this->subscription->company_id, $this->subscription->user_id); $invoice = InvoiceFactory::create($this->subscription->company_id, $this->subscription->user_id);
$invoice->subscription_id = $this->subscription->id; $invoice->subscription_id = $this->subscription->id;
$invoice->client_id = $client_id;
$line_items = $bundle->map(function ($item){ $line_items = $bundle->map(function ($item){
$line_item = new InvoiceItem; $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(); })->toArray();
nlog($line_items);
$invoice->line_items = $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);
} }