Refactor for livewire components
This commit is contained in:
parent
1e8a82fd29
commit
e01e0f92e4
|
|
@ -28,11 +28,11 @@ class PurchaseOrdersTable extends Component
|
|||
|
||||
public $status = [];
|
||||
|
||||
public $company;
|
||||
public $db;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
MultiDB::setDb($this->company->db);
|
||||
MultiDB::setDb($this->db);
|
||||
|
||||
$this->sort_asc = false;
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ class PurchaseOrdersTable extends Component
|
|||
|
||||
$query = PurchaseOrder::query()
|
||||
->with('vendor.contacts')
|
||||
->where('company_id', $this->company->id)
|
||||
->where('company_id', auth()->guard('vendor')->user()->company_id)
|
||||
->whereIn('status_id', [PurchaseOrder::STATUS_SENT, PurchaseOrder::STATUS_ACCEPTED])
|
||||
->where('is_deleted', false)
|
||||
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc');
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@ class QuotesTable extends Component
|
|||
|
||||
public array $status = [];
|
||||
|
||||
public Company $company;
|
||||
|
||||
public string $sort = 'status_id';
|
||||
|
||||
public bool $sort_asc = true;
|
||||
|
|
@ -39,8 +37,6 @@ class QuotesTable extends Component
|
|||
public function mount()
|
||||
{
|
||||
MultiDB::setDb($this->db);
|
||||
|
||||
$this->company = Company::find($this->company_id);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -82,7 +78,7 @@ class QuotesTable extends Component
|
|||
}
|
||||
|
||||
$query = $query
|
||||
->where('company_id', $this->company->id)
|
||||
->where('company_id', auth()->guard('contact')->user()->company_id)
|
||||
->where('client_id', auth()->guard('contact')->user()->client_id)
|
||||
->where('is_deleted', 0)
|
||||
->where('status_id', '<>', Quote::STATUS_DRAFT)
|
||||
|
|
|
|||
|
|
@ -18,16 +18,14 @@ use Livewire\Component;
|
|||
|
||||
class RecurringInvoiceCancellation extends Component
|
||||
{
|
||||
/**
|
||||
* @var RecurringInvoice
|
||||
*/
|
||||
public $invoice;
|
||||
|
||||
public $company;
|
||||
public $invoice_id;
|
||||
|
||||
public $db;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
MultiDB::setDb($this->company->db);
|
||||
MultiDB::setDb($this->db);
|
||||
}
|
||||
|
||||
public function render()
|
||||
|
|
@ -37,10 +35,15 @@ class RecurringInvoiceCancellation extends Component
|
|||
|
||||
public function processCancellation()
|
||||
{
|
||||
if ($this->invoice->subscription) {
|
||||
return $this->invoice->subscription->service()->handleCancellation($this->invoice);
|
||||
|
||||
MultiDB::setDb($this->db);
|
||||
|
||||
$ri = RecurringInvoice::withTrashed()->find($this->invoice_id);
|
||||
|
||||
if ($ri->subscription) {
|
||||
return $ri->subscription->service()->handleCancellation($ri);
|
||||
}
|
||||
|
||||
return redirect()->route('client.recurring_invoices.request_cancellation', ['recurring_invoice' => $this->invoice->hashed_id]);
|
||||
return redirect()->route('client.recurring_invoices.request_cancellation', ['recurring_invoice' => $ri->hashed_id]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,11 +25,13 @@ class RecurringInvoicesTable extends Component
|
|||
|
||||
public $per_page = 10;
|
||||
|
||||
public $company;
|
||||
public $company_id;
|
||||
|
||||
public $db;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
MultiDB::setDb($this->company->db);
|
||||
MultiDB::setDb($this->db);
|
||||
|
||||
$this->sort_asc = false;
|
||||
|
||||
|
|
@ -43,7 +45,7 @@ class RecurringInvoicesTable extends Component
|
|||
$query = $query
|
||||
// ->with('client')
|
||||
->where('client_id', auth()->guard('contact')->user()->client_id)
|
||||
->where('company_id', $this->company->id)
|
||||
->where('company_id', auth()->guard('contact')->user()->company_id)
|
||||
->whereIn('status_id', [RecurringInvoice::STATUS_ACTIVE])
|
||||
->orderBy('status_id', 'asc')
|
||||
->with('client')
|
||||
|
|
|
|||
|
|
@ -59,7 +59,6 @@ class RequiredClientInfo extends Component
|
|||
*/
|
||||
public $countries;
|
||||
|
||||
|
||||
public $client_name;
|
||||
public $contact_first_name;
|
||||
public $contact_last_name;
|
||||
|
|
|
|||
|
|
@ -12,39 +12,29 @@
|
|||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Subscription;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Component;
|
||||
use App\Libraries\MultiDB;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\Subscription;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\RecurringInvoice;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class SubscriptionPlanSwitch extends Component
|
||||
{
|
||||
/**
|
||||
* @var \App\Models\RecurringInvoice
|
||||
*/
|
||||
public $recurring_invoice;
|
||||
|
||||
/**
|
||||
* @var Subscription
|
||||
*/
|
||||
public $subscription;
|
||||
public $recurring_invoice_id;
|
||||
|
||||
public $subscription_id;
|
||||
|
||||
/**
|
||||
* @var ?float
|
||||
*/
|
||||
public $amount;
|
||||
|
||||
/**
|
||||
* @var Subscription
|
||||
*/
|
||||
public $target;
|
||||
public $target_id;
|
||||
|
||||
/**
|
||||
* @var ClientContact
|
||||
*/
|
||||
public ClientContact $contact;
|
||||
public $contact_id;
|
||||
|
||||
public $db;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
|
|
@ -74,8 +64,6 @@ class SubscriptionPlanSwitch extends Component
|
|||
*/
|
||||
public $hash;
|
||||
|
||||
public $company;
|
||||
|
||||
public ?string $first_name;
|
||||
|
||||
public ?string $last_name;
|
||||
|
|
@ -84,21 +72,45 @@ class SubscriptionPlanSwitch extends Component
|
|||
|
||||
public function mount()
|
||||
{
|
||||
MultiDB::setDb($this->company->db);
|
||||
MultiDB::setDb($this->db);
|
||||
|
||||
$this->total = $this->amount;
|
||||
|
||||
$this->methods = $this->contact->client->service()->getPaymentMethods($this->amount);
|
||||
$this->methods = $this->contact()->client->service()->getPaymentMethods($this->amount);
|
||||
|
||||
$this->hash = Str::uuid()->toString();
|
||||
|
||||
$this->state['show_rff'] = auth()->guard('contact')->user()->showRff();
|
||||
|
||||
$this->first_name = $this->contact->first_name;
|
||||
$this->first_name = $this->contact()->first_name;
|
||||
|
||||
$this->last_name = $this->contact->last_name;
|
||||
$this->last_name = $this->contact()->last_name;
|
||||
|
||||
$this->email = $this->contact->email;
|
||||
$this->email = $this->contact()->email;
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function recurring_invoice()
|
||||
{
|
||||
return RecurringInvoice::withTrashed()->find($this->recurring_invoice_id);
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function subscription()
|
||||
{
|
||||
return Subscription::withTrashed()->find($this->subscription_id);
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function target()
|
||||
{
|
||||
return Subscription::withTrashed()->find($this->target_id);
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function contact()
|
||||
{
|
||||
return ClientContact::withTrashed()->find($this->contact_id);
|
||||
}
|
||||
|
||||
public function handleRff()
|
||||
|
|
@ -109,7 +121,7 @@ class SubscriptionPlanSwitch extends Component
|
|||
'email' => ['required', 'email'],
|
||||
]);
|
||||
|
||||
$this->contact->update([
|
||||
$this->contact()->update([
|
||||
'first_name' => $this->first_name,
|
||||
'last_name' => $this->last_name,
|
||||
'email' => $this->email,
|
||||
|
|
@ -122,28 +134,28 @@ class SubscriptionPlanSwitch extends Component
|
|||
{
|
||||
$this->state['show_loading_bar'] = true;
|
||||
|
||||
$payment_required = $this->target->service()->changePlanPaymentCheck([
|
||||
'recurring_invoice' => $this->recurring_invoice,
|
||||
'subscription' => $this->subscription,
|
||||
'target' => $this->target,
|
||||
$payment_required = $this->target()->service()->changePlanPaymentCheck([
|
||||
'recurring_invoice' => $this->recurring_invoice(),
|
||||
'subscription' => $this->subscription(),
|
||||
'target' => $this->target(),
|
||||
'hash' => $this->hash,
|
||||
]);
|
||||
|
||||
if ($payment_required) {
|
||||
$this->state['invoice'] = $this->target->service()->createChangePlanInvoice([
|
||||
'recurring_invoice' => $this->recurring_invoice,
|
||||
'subscription' => $this->subscription,
|
||||
'target' => $this->target,
|
||||
$this->state['invoice'] = $this->target()->service()->createChangePlanInvoice([
|
||||
'recurring_invoice' => $this->recurring_invoice(),
|
||||
'subscription' => $this->subscription(),
|
||||
'target' => $this->target(),
|
||||
'hash' => $this->hash,
|
||||
]);
|
||||
|
||||
Cache::put(
|
||||
$this->hash,
|
||||
[
|
||||
'subscription_id' => $this->target->hashed_id,
|
||||
'target_id' => $this->target->hashed_id,
|
||||
'recurring_invoice' => $this->recurring_invoice->hashed_id,
|
||||
'client_id' => $this->recurring_invoice->client->hashed_id,
|
||||
'subscription_id' => $this->target()->hashed_id,
|
||||
'target_id' => $this->target()->hashed_id,
|
||||
'recurring_invoice' => $this->recurring_invoice()->hashed_id,
|
||||
'client_id' => $this->recurring_invoice()->client->hashed_id,
|
||||
'invoice_id' => $this->state['invoice']->hashed_id,
|
||||
'context' => 'change_plan',
|
||||
now()->addMinutes(60), ]
|
||||
|
|
@ -176,10 +188,10 @@ class SubscriptionPlanSwitch extends Component
|
|||
{
|
||||
$this->hide_button = true;
|
||||
|
||||
$response = $this->target->service()->createChangePlanCreditV2([
|
||||
'recurring_invoice' => $this->recurring_invoice,
|
||||
'subscription' => $this->subscription,
|
||||
'target' => $this->target,
|
||||
$response = $this->target()->service()->createChangePlanCreditV2([
|
||||
'recurring_invoice' => $this->recurring_invoice(),
|
||||
'subscription' => $this->subscription(),
|
||||
'target' => $this->target(),
|
||||
'hash' => $this->hash,
|
||||
]);
|
||||
|
||||
|
|
|
|||
|
|
@ -25,18 +25,20 @@ class SubscriptionRecurringInvoicesTable extends Component
|
|||
|
||||
public $per_page = 10;
|
||||
|
||||
public $company;
|
||||
public $company_id;
|
||||
|
||||
public $db;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
MultiDB::setDb($this->company->db);
|
||||
MultiDB::setDb($this->db);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$query = RecurringInvoice::query()
|
||||
->where('client_id', auth()->guard('contact')->user()->client->id)
|
||||
->where('company_id', $this->company->id)
|
||||
->where('company_id', $this->company_id)
|
||||
->whereNotNull('subscription_id')
|
||||
->where('is_deleted', false)
|
||||
->where('status_id', RecurringInvoice::STATUS_ACTIVE)
|
||||
|
|
|
|||
|
|
@ -25,18 +25,20 @@ class SubscriptionsTable extends Component
|
|||
|
||||
public $per_page = 10;
|
||||
|
||||
public $company;
|
||||
public $company_id;
|
||||
|
||||
public $db;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
MultiDB::setDb($this->company->db);
|
||||
MultiDB::setDb($this->db);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$query = RecurringInvoice::query()
|
||||
->where('client_id', auth()->guard('contact')->user()->client->id)
|
||||
->where('company_id', $this->company->id)
|
||||
->where('company_id', $this->company_id)
|
||||
->whereNotNull('subscription_id')
|
||||
->where('is_deleted', false)
|
||||
->whereIn('status_id', [RecurringInvoice::STATUS_ACTIVE, RecurringInvoice::STATUS_PAUSED])
|
||||
|
|
|
|||
|
|
@ -25,17 +25,19 @@ class TasksTable extends Component
|
|||
|
||||
public $per_page = 10;
|
||||
|
||||
public $company;
|
||||
public $company_id;
|
||||
|
||||
public $db;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
MultiDB::setDb($this->company->db);
|
||||
MultiDB::setDb($this->db);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$query = Task::query()
|
||||
->where('company_id', $this->company->id)
|
||||
->where('company_id', $this->company_id)
|
||||
->where('is_deleted', false)
|
||||
->where('client_id', auth()->guard('contact')->user()->client_id);
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@
|
|||
<div class="relative flex justify-center text-sm leading-5">
|
||||
<span class="font-bold tracking-wide bg-gray-100 px-6 py-0">{{ ctrans('texts.select_payment_method')}}</span>
|
||||
<h1 class="text-2xl font-bold tracking-wide bg-gray-100 px-6 py-0">
|
||||
{{ ctrans('texts.total') }}: {{ \App\Utils\Number::formatMoney($amount, $subscription->company) }}
|
||||
{{ ctrans('texts.total') }}: {{ \App\Utils\Number::formatMoney($amount, $this->subscription->company) }}
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -71,9 +71,9 @@
|
|||
<input type="hidden" name="action" value="payment">
|
||||
<input type="hidden" name="company_gateway_id" value="{{ $state['company_gateway_id'] }}"/>
|
||||
<input type="hidden" name="payment_method_id" value="{{ $state['payment_method_id'] }}"/>
|
||||
<input type="hidden" name="contact_first_name" value="{{ $contact->first_name }}">
|
||||
<input type="hidden" name="contact_last_name" value="{{ $contact->last_name }}">
|
||||
<input type="hidden" name="contact_email" value="{{ $contact->email }}">
|
||||
<input type="hidden" name="contact_first_name" value="{{ $this->contact()->first_name }}">
|
||||
<input type="hidden" name="contact_last_name" value="{{ $this->contact()->last_name }}">
|
||||
<input type="hidden" name="contact_email" value="{{ $this->contact()->email }}">
|
||||
</form>
|
||||
|
||||
<!-- Payment methods -->
|
||||
|
|
@ -107,7 +107,7 @@
|
|||
|
||||
<div class="relative flex justify-center text-sm leading-5">
|
||||
<h1 class="text-2xl font-bold tracking-wide bg-gray-100 px-6 py-0">
|
||||
{{ ctrans('texts.total') }}: {{ \App\Utils\Number::formatMoney($amount, $subscription->company) }}
|
||||
{{ ctrans('texts.total') }}: {{ \App\Utils\Number::formatMoney($amount, $this->subscription()->company) }}
|
||||
</h1>
|
||||
</div>
|
||||
<div class="relative flex justify-center text-sm leading-5 mt-10">
|
||||
|
|
|
|||
|
|
@ -20,6 +20,6 @@
|
|||
</form>
|
||||
</div>
|
||||
<div class="flex flex-col mt-4">
|
||||
@livewire('purchase-orders-table', ['company' => $company])
|
||||
@livewire('purchase-orders-table', ['company_id' => $company->id, 'db' => $company->db])
|
||||
</div>
|
||||
@endsection
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
</div>
|
||||
<div class="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse">
|
||||
<div class="flex w-full rounded-md shadow-sm sm:ml-3 sm:w-auto">
|
||||
@livewire('recurring-invoice-cancellation', ['invoice' => $invoice, 'company' => $company])
|
||||
@livewire('recurring-invoice-cancellation', ['invoice_id' => $invoice->id, 'db' => $company->db])
|
||||
</div>
|
||||
<div class="mt-3 flex w-full rounded-md shadow-sm sm:mt-0 sm:w-auto">
|
||||
<button @click="open = false" type="button" class="button button-secondary button-block">
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@
|
|||
|
||||
@section('body')
|
||||
<div class="flex flex-col">
|
||||
@livewire('recurring-invoices-table', ['company' => $company])
|
||||
@livewire('recurring-invoices-table', ['company_id' => $company->id, 'db' => $company->db])
|
||||
</div>
|
||||
@endsection
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@
|
|||
|
||||
@section('body')
|
||||
<div class="flex flex-col">
|
||||
@livewire('subscriptions-table', ['company' => $company])
|
||||
@livewire('subscriptions-table', ['db' => $company->db , 'company_id' => $company->id])
|
||||
</div>
|
||||
@endsection
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@
|
|||
</div>
|
||||
|
||||
<!-- Payment box -->
|
||||
@livewire('subscription-plan-switch', compact('recurring_invoice', 'subscription', 'target', 'contact', 'amount', 'company'))
|
||||
@livewire('subscription-plan-switch', ['db' => $company->db, 'recurring_invoice_id' => $recurring_invoice->id, 'subscription_id' => $subscription->id, 'target_id' => $target->id, 'contact_id' => $contact->id, 'amount' => $amount] )
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@
|
|||
|
||||
@section('body')
|
||||
<div class="flex flex-col">
|
||||
@livewire('tasks-table', ['company' => $company])
|
||||
@livewire('tasks-table', ['db' => $company->db, 'company_id' => $company->id])
|
||||
</div>
|
||||
@endsection
|
||||
|
|
|
|||
Loading…
Reference in New Issue