mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 14:04:35 -04:00
Subscriptions
This commit is contained in:
parent
803818b53c
commit
f2342e640a
@ -244,6 +244,7 @@ class CreateSingleAccount extends Command
|
|||||||
$sub->group_id = $gs->id;
|
$sub->group_id = $gs->id;
|
||||||
$sub->recurring_product_ids = "{$p1->hashed_id}";
|
$sub->recurring_product_ids = "{$p1->hashed_id}";
|
||||||
$sub->webhook_configuration = $webhook_config;
|
$sub->webhook_configuration = $webhook_config;
|
||||||
|
$sub->allow_plan_changes = true;
|
||||||
$sub->save();
|
$sub->save();
|
||||||
|
|
||||||
$sub = SubscriptionFactory::create($company->id, $user->id);
|
$sub = SubscriptionFactory::create($company->id, $user->id);
|
||||||
@ -251,6 +252,7 @@ class CreateSingleAccount extends Command
|
|||||||
$sub->group_id = $gs->id;
|
$sub->group_id = $gs->id;
|
||||||
$sub->recurring_product_ids = "{$p2->hashed_id}";
|
$sub->recurring_product_ids = "{$p2->hashed_id}";
|
||||||
$sub->webhook_configuration = $webhook_config;
|
$sub->webhook_configuration = $webhook_config;
|
||||||
|
$sub->allow_plan_changes = true;
|
||||||
$sub->save();
|
$sub->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,15 +30,20 @@ class SubscriptionPlanSwitchController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index(ShowPlanSwitchRequest $request, RecurringInvoice $recurring_invoice, Subscription $target)
|
public function index(ShowPlanSwitchRequest $request, RecurringInvoice $recurring_invoice, Subscription $target)
|
||||||
{
|
{
|
||||||
//calculate whether a payment is required or whether we pass through a credit for this.
|
|
||||||
|
|
||||||
$amount = $recurring_invoice->subscription->service()->calculateUpgradePrice($recurring_invoice, $target);
|
$amount = $recurring_invoice->subscription
|
||||||
|
->service()
|
||||||
|
->calculateUpgradePrice($recurring_invoice, $target);
|
||||||
|
|
||||||
nlog($amount);
|
/**
|
||||||
|
*
|
||||||
|
* Null value here is a proxy for
|
||||||
|
* denying the user a change plan option
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if(is_null($amount))
|
||||||
|
render('subscriptions.denied');
|
||||||
|
|
||||||
//if($amount == null)
|
|
||||||
//please show account upgrade unavailable
|
|
||||||
//@ben
|
|
||||||
|
|
||||||
return render('subscriptions.switch', [
|
return render('subscriptions.switch', [
|
||||||
'subscription' => $recurring_invoice->subscription,
|
'subscription' => $recurring_invoice->subscription,
|
||||||
|
@ -72,8 +72,6 @@ class SubscriptionPlanSwitch extends Component
|
|||||||
|
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
// $this->total = $this->subscription->service()->getPriceBetweenSubscriptions($this->subscription, $this->target);
|
|
||||||
|
|
||||||
$this->total = $this->amount;
|
$this->total = $this->amount;
|
||||||
|
|
||||||
$this->methods = $this->contact->client->service()->getPaymentMethods(100);
|
$this->methods = $this->contact->client->service()->getPaymentMethods(100);
|
||||||
@ -86,6 +84,7 @@ class SubscriptionPlanSwitch extends Component
|
|||||||
$this->state['show_loading_bar'] = true;
|
$this->state['show_loading_bar'] = true;
|
||||||
|
|
||||||
$this->state['invoice'] = $this->subscription->service()->createChangePlanInvoice([
|
$this->state['invoice'] = $this->subscription->service()->createChangePlanInvoice([
|
||||||
|
'recurring_invoice' => $this->recurring_invoice,
|
||||||
'subscription' => $this->subscription,
|
'subscription' => $this->subscription,
|
||||||
'target' => $this->target,
|
'target' => $this->target,
|
||||||
]);
|
]);
|
||||||
|
@ -184,7 +184,7 @@ class RecurringInvoice extends BaseModel
|
|||||||
|
|
||||||
public function invoices()
|
public function invoices()
|
||||||
{
|
{
|
||||||
return $this->hasMany(Invoice::class, 'id', 'recurring_id')->withTrashed();
|
return $this->hasMany(Invoice::class, 'recurring_id', 'id')->withTrashed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function invitations()
|
public function invitations()
|
||||||
|
@ -190,7 +190,7 @@ class SubscriptionService
|
|||||||
$current_amount = $recurring_invoice->amount;
|
$current_amount = $recurring_invoice->amount;
|
||||||
$currency_frequency = $recurring_invoice->frequency_id;
|
$currency_frequency = $recurring_invoice->frequency_id;
|
||||||
|
|
||||||
$outstanding = $recurring_invoice->invoices
|
$outstanding = $recurring_invoice->invoices()
|
||||||
->where('is_deleted', 0)
|
->where('is_deleted', 0)
|
||||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||||
->where('balance', '>', 0);
|
->where('balance', '>', 0);
|
||||||
@ -238,11 +238,25 @@ class SubscriptionService
|
|||||||
//Data array structure
|
//Data array structure
|
||||||
/**
|
/**
|
||||||
* [
|
* [
|
||||||
|
* 'recurring_invoice' => RecurringInvoice::class,
|
||||||
* 'subscription' => Subscription::class,
|
* 'subscription' => Subscription::class,
|
||||||
* 'target' => Subscription::class
|
* 'target' => Subscription::class
|
||||||
* ]
|
* ]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
$outstanding_invoice = $recurring_invoice->invoices()
|
||||||
|
->where('is_deleted', 0)
|
||||||
|
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||||
|
->where('balance', '>', 0)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
|
||||||
|
// we calculate the pro rata refund for this invoice.
|
||||||
|
if($outstanding_invoice)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//logic
|
//logic
|
||||||
|
|
||||||
// Is the user paid up to date? ie are there any outstanding invoices for this subscription
|
// Is the user paid up to date? ie are there any outstanding invoices for this subscription
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
@extends('portal.ninja2020.layout.app')
|
||||||
|
@section('meta_title', ctrans('texts.subscriptions'))
|
||||||
|
|
||||||
|
@section('body')
|
||||||
|
<div class="container mx-auto">
|
||||||
|
<!-- Top section showing details between plans -->
|
||||||
|
<div class="grid grid-cols-12 gap-8">
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="col-span-12 md:col-start-2 md:col-span-4 bg-white rounded px-4 py-5 shadow hover:shadow-lg">
|
||||||
|
<span class="text-sm uppercase text-gray-900">{{ ctrans('texts.current') }}</span>
|
||||||
|
<p class="mt-4">{{ $subscription->name }}</p>
|
||||||
|
<div class="flex justify-end mt-2">
|
||||||
|
<p> Cannot upgrade / downgrade as you have one of more invoices outstanding</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Payment box -->
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@push('footer')
|
||||||
|
@endpush
|
Loading…
x
Reference in New Issue
Block a user