mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-13 22:54:25 +01:00
Refactor Livewire passing references
This commit is contained in:
parent
9e84f6c10f
commit
d4356af782
@ -35,7 +35,7 @@ class SubscriptionPlanSwitchController extends Controller
|
|||||||
->service()
|
->service()
|
||||||
->calculateUpgradePriceV2($recurring_invoice, $target);
|
->calculateUpgradePriceV2($recurring_invoice, $target);
|
||||||
|
|
||||||
nlog("upgrade amoutn = {$amount}");
|
nlog("payment amount = {$amount}");
|
||||||
/**
|
/**
|
||||||
* Null value here is a proxy for
|
* Null value here is a proxy for
|
||||||
* denying the user a change plan option
|
* denying the user a change plan option
|
||||||
@ -44,6 +44,9 @@ class SubscriptionPlanSwitchController extends Controller
|
|||||||
render('subscriptions.denied');
|
render('subscriptions.denied');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$amount = max(0,$amount);
|
||||||
|
|
||||||
return render('subscriptions.switch', [
|
return render('subscriptions.switch', [
|
||||||
'subscription' => $recurring_invoice->subscription,
|
'subscription' => $recurring_invoice->subscription,
|
||||||
'recurring_invoice' => $recurring_invoice,
|
'recurring_invoice' => $recurring_invoice,
|
||||||
|
@ -121,7 +121,7 @@ class BillingPortalPurchasev2 extends Component
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $request_data;
|
public $request_data = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instance of company.
|
* Instance of company.
|
||||||
@ -130,7 +130,13 @@ class BillingPortalPurchasev2 extends Component
|
|||||||
*/
|
*/
|
||||||
public $company;
|
public $company;
|
||||||
|
|
||||||
public $db;
|
|
||||||
|
/**
|
||||||
|
* Instance of company.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Campaign reference.
|
* Campaign reference.
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
namespace App\Http\Livewire;
|
namespace App\Http\Livewire;
|
||||||
|
|
||||||
use App\Libraries\MultiDB;
|
use App\Libraries\MultiDB;
|
||||||
|
use App\Models\Company;
|
||||||
use App\Models\Credit;
|
use App\Models\Credit;
|
||||||
use App\Utils\Traits\WithSorting;
|
use App\Utils\Traits\WithSorting;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
@ -23,26 +24,31 @@ class CreditsTable extends Component
|
|||||||
use WithPagination;
|
use WithPagination;
|
||||||
use WithSorting;
|
use WithSorting;
|
||||||
|
|
||||||
public $per_page = 10;
|
public int $per_page = 10;
|
||||||
|
|
||||||
public $company;
|
public Company $company;
|
||||||
|
|
||||||
|
public string $db;
|
||||||
|
|
||||||
|
public int $company_id;
|
||||||
|
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
MultiDB::setDb($this->company->db);
|
MultiDB::setDb($this->db);
|
||||||
|
|
||||||
|
$this->company = Company::find($this->company_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
$query = Credit::query()
|
$query = Credit::query()
|
||||||
->where('client_id', auth()->guard('contact')->user()->client_id)
|
|
||||||
->where('company_id', $this->company->id)
|
->where('company_id', $this->company->id)
|
||||||
|
->where('client_id', auth()->guard('contact')->user()->client_id)
|
||||||
->where('status_id', '<>', Credit::STATUS_DRAFT)
|
->where('status_id', '<>', Credit::STATUS_DRAFT)
|
||||||
->where('is_deleted', 0)
|
->where('is_deleted', 0)
|
||||||
->where(function ($query) {
|
->where(function ($query) {
|
||||||
$query->whereDate('due_date', '>=', now())
|
$query->whereDate('due_date', '>=', now())
|
||||||
->orWhereNull('due_date');
|
->orWhereNull('due_date');
|
||||||
//->orWhere('due_date', '=', '');
|
|
||||||
})
|
})
|
||||||
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')
|
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
|
@ -14,6 +14,7 @@ namespace App\Http\Livewire;
|
|||||||
|
|
||||||
use App\Libraries\MultiDB;
|
use App\Libraries\MultiDB;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
|
use App\Models\Company;
|
||||||
use App\Models\Credit;
|
use App\Models\Credit;
|
||||||
use App\Models\Document;
|
use App\Models\Document;
|
||||||
use App\Models\Expense;
|
use App\Models\Expense;
|
||||||
@ -31,21 +32,27 @@ class DocumentsTable extends Component
|
|||||||
{
|
{
|
||||||
use WithPagination, WithSorting;
|
use WithPagination, WithSorting;
|
||||||
|
|
||||||
public $client;
|
public Company $company;
|
||||||
|
|
||||||
public $per_page = 10;
|
public Client $client;
|
||||||
|
|
||||||
public $company;
|
public int $client_id;
|
||||||
|
|
||||||
|
public int $per_page = 10;
|
||||||
|
|
||||||
public string $tab = 'documents';
|
public string $tab = 'documents';
|
||||||
|
|
||||||
|
public string $db;
|
||||||
|
|
||||||
protected $query;
|
protected $query;
|
||||||
|
|
||||||
public function mount($client)
|
public function mount()
|
||||||
{
|
{
|
||||||
MultiDB::setDb($this->company->db);
|
MultiDB::setDb($this->db);
|
||||||
|
|
||||||
$this->client = $client;
|
$this->client = Client::with('company')->find($this->client_id);
|
||||||
|
|
||||||
|
$this->company = $this->client->company;
|
||||||
|
|
||||||
$this->query = $this->documents();
|
$this->query = $this->documents();
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,7 @@ class SubscriptionService
|
|||||||
//update the invoice and attach to the recurring invoice!!!!!
|
//update the invoice and attach to the recurring invoice!!!!!
|
||||||
$invoice = Invoice::find($payment_hash->fee_invoice_id);
|
$invoice = Invoice::find($payment_hash->fee_invoice_id);
|
||||||
$invoice->recurring_id = $recurring_invoice->id;
|
$invoice->recurring_id = $recurring_invoice->id;
|
||||||
|
$invoice->is_proforma = false;
|
||||||
$invoice->save();
|
$invoice->save();
|
||||||
|
|
||||||
//execute any webhooks
|
//execute any webhooks
|
||||||
@ -253,6 +254,7 @@ class SubscriptionService
|
|||||||
}
|
}
|
||||||
|
|
||||||
nlog("{$target->price} - {$refund} - {$outstanding_credit}");
|
nlog("{$target->price} - {$refund} - {$outstanding_credit}");
|
||||||
|
|
||||||
return $target->price - $refund - $outstanding_credit;
|
return $target->price - $refund - $outstanding_credit;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -346,7 +348,7 @@ class SubscriptionService
|
|||||||
|
|
||||||
$pro_rata_refund = round((($days_in_frequency - $days_of_subscription_used)/$days_in_frequency) * $invoice->amount ,2);
|
$pro_rata_refund = round((($days_in_frequency - $days_of_subscription_used)/$days_in_frequency) * $invoice->amount ,2);
|
||||||
|
|
||||||
return $pro_rata_refund;
|
return max(0, $pro_rata_refund);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -472,6 +474,7 @@ class SubscriptionService
|
|||||||
$pro_rata_charge_amount = 0;
|
$pro_rata_charge_amount = 0;
|
||||||
$pro_rata_refund_amount = 0;
|
$pro_rata_refund_amount = 0;
|
||||||
$is_credit = false;
|
$is_credit = false;
|
||||||
|
$credit = false;
|
||||||
|
|
||||||
/* Get last invoice */
|
/* Get last invoice */
|
||||||
$last_invoice = Invoice::where('subscription_id', $recurring_invoice->subscription_id)
|
$last_invoice = Invoice::where('subscription_id', $recurring_invoice->subscription_id)
|
||||||
@ -483,9 +486,8 @@ class SubscriptionService
|
|||||||
->orderBy('id', 'desc')
|
->orderBy('id', 'desc')
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
// $pro_rata_refund_amount = $this->calculateProRataRefund($last_invoice, $old_subscription);
|
if($this->calculateProRataRefundForSubscription($last_invoice) > 0)
|
||||||
|
$credit = $this->createCredit($last_invoice, $target_subscription, false);
|
||||||
$credit = $this->createCredit($last_invoice, $target_subscription, false);
|
|
||||||
|
|
||||||
$new_recurring_invoice = $this->createNewRecurringInvoice($recurring_invoice);
|
$new_recurring_invoice = $this->createNewRecurringInvoice($recurring_invoice);
|
||||||
|
|
||||||
@ -513,12 +515,7 @@ class SubscriptionService
|
|||||||
|
|
||||||
$response = $this->triggerWebhook($context);
|
$response = $this->triggerWebhook($context);
|
||||||
|
|
||||||
if($credit){
|
return '/client/recurring_invoices/'.$new_recurring_invoice->hashed_id;
|
||||||
return '/client/invoices/'.$invoice->hashed_id;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return '/client/invoices';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -783,9 +780,6 @@ class SubscriptionService
|
|||||||
$credit->discount = $last_invoice->discount;
|
$credit->discount = $last_invoice->discount;
|
||||||
$credit->is_amount_discount = $last_invoice->is_amount_discount;
|
$credit->is_amount_discount = $last_invoice->is_amount_discount;
|
||||||
|
|
||||||
// $line_items = $subscription_repo->generateLineItems($target, false, true);
|
|
||||||
|
|
||||||
// $credit->line_items = array_merge($line_items, $this->calculateProRataRefundItems($last_invoice, $last_invoice_is_credit));
|
|
||||||
$credit->line_items = $this->calculateProRataRefundItems($last_invoice, true);
|
$credit->line_items = $this->calculateProRataRefundItems($last_invoice, true);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
@ -816,6 +810,7 @@ class SubscriptionService
|
|||||||
$invoice->subscription_id = $target->id;
|
$invoice->subscription_id = $target->id;
|
||||||
|
|
||||||
$invoice->line_items = array_merge($subscription_repo->generateLineItems($target), $this->calculateProRataRefundItems($last_invoice));
|
$invoice->line_items = array_merge($subscription_repo->generateLineItems($target), $this->calculateProRataRefundItems($last_invoice));
|
||||||
|
$invoice->is_proforma = true;
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'client_id' => $client_id,
|
'client_id' => $client_id,
|
||||||
@ -848,6 +843,7 @@ class SubscriptionService
|
|||||||
$invoice->subscription_id = $target->id;
|
$invoice->subscription_id = $target->id;
|
||||||
|
|
||||||
$invoice->line_items = $subscription_repo->generateLineItems($target);
|
$invoice->line_items = $subscription_repo->generateLineItems($target);
|
||||||
|
$invoice->is_proforma = true;
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'client_id' => $client_id,
|
'client_id' => $client_id,
|
||||||
@ -914,6 +910,7 @@ 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->line_items = $subscription_repo->generateLineItems($this->subscription);
|
$invoice->line_items = $subscription_repo->generateLineItems($this->subscription);
|
||||||
$invoice->subscription_id = $this->subscription->id;
|
$invoice->subscription_id = $this->subscription->id;
|
||||||
|
$invoice->is_proforman = true;
|
||||||
|
|
||||||
if(strlen($data['coupon']) >=1 && ($data['coupon'] == $this->subscription->promo_code) && $this->subscription->promo_discount > 0)
|
if(strlen($data['coupon']) >=1 && ($data['coupon'] == $this->subscription->promo_code) && $this->subscription->promo_discount > 0)
|
||||||
{
|
{
|
||||||
@ -925,7 +922,6 @@ class SubscriptionService
|
|||||||
$invoice->is_amount_discount = $this->subscription->is_amount_discount;
|
$invoice->is_amount_discount = $this->subscription->is_amount_discount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return $invoice_repo->save($data, $invoice);
|
return $invoice_repo->save($data, $invoice);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1247,8 +1243,6 @@ class SubscriptionService
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return $this->handleRedirect('client/subscriptions');
|
return $this->handleRedirect('client/subscriptions');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,7 @@ return [
|
|||||||
'ninja_stripe_client_id' => env('NINJA_STRIPE_CLIENT_ID', null),
|
'ninja_stripe_client_id' => env('NINJA_STRIPE_CLIENT_ID', null),
|
||||||
'ninja_default_company_id' => env('NINJA_COMPANY_ID', null),
|
'ninja_default_company_id' => env('NINJA_COMPANY_ID', null),
|
||||||
'ninja_default_company_gateway_id' => env('NINJA_COMPANY_GATEWAY_ID', null),
|
'ninja_default_company_gateway_id' => env('NINJA_COMPANY_GATEWAY_ID', null),
|
||||||
'ninja_hosted_secret' => env('NINJA_HOSTED_SECRET', null),
|
'ninja_hosted_secret' => env('NINJA_HOSTED_SECRET', ''),
|
||||||
'ninja_hosted_header' =>env('NINJA_HEADER',''),
|
'ninja_hosted_header' =>env('NINJA_HEADER',''),
|
||||||
'internal_queue_enabled' => env('INTERNAL_QUEUE_ENABLED', true),
|
'internal_queue_enabled' => env('INTERNAL_QUEUE_ENABLED', true),
|
||||||
'ninja_apple_api_key' => env('APPLE_API_KEY', false),
|
'ninja_apple_api_key' => env('APPLE_API_KEY', false),
|
||||||
|
@ -13,6 +13,6 @@
|
|||||||
|
|
||||||
@section('body')
|
@section('body')
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
@livewire('credits-table', ['company' => $company])
|
@livewire('credits-table', ['company_id' => $company->id, 'db' => $company->db])
|
||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
@ -34,7 +34,6 @@
|
|||||||
@include('portal.ninja2020.components.entity-documents', ['entity' => $credit])
|
@include('portal.ninja2020.components.entity-documents', ['entity' => $credit])
|
||||||
|
|
||||||
@include('portal.ninja2020.components.pdf-viewer', ['entity' => $credit, 'invitation' => $invitation])
|
@include('portal.ninja2020.components.pdf-viewer', ['entity' => $credit, 'invitation' => $invitation])
|
||||||
|
|
||||||
|
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
@ -45,18 +44,5 @@
|
|||||||
|
|
||||||
var clipboard = new ClipboardJS('.btn');
|
var clipboard = new ClipboardJS('.btn');
|
||||||
|
|
||||||
// clipboard.on('success', function(e) {
|
|
||||||
// console.info('Action:', e.action);
|
|
||||||
// console.info('Text:', e.text);
|
|
||||||
// console.info('Trigger:', e.trigger);
|
|
||||||
|
|
||||||
// e.clearSelection();
|
|
||||||
// });
|
|
||||||
|
|
||||||
// clipboard.on('error', function(e) {
|
|
||||||
// console.error('Action:', e.action);
|
|
||||||
// console.error('Trigger:', e.trigger);
|
|
||||||
// });
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
@ -14,5 +14,5 @@
|
|||||||
@csrf
|
@csrf
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
@livewire('documents-table', ['client' => $client, 'company' => $company])
|
@livewire('documents-table', ['client_id' => $client->id, 'db' => $company->db])
|
||||||
@endsection
|
@endsection
|
||||||
|
Loading…
Reference in New Issue
Block a user