diff --git a/app/Livewire/PurchaseOrdersTable.php b/app/Livewire/PurchaseOrdersTable.php index 1f042d9a5b..fc2a1517b2 100644 --- a/app/Livewire/PurchaseOrdersTable.php +++ b/app/Livewire/PurchaseOrdersTable.php @@ -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'); diff --git a/app/Livewire/QuotesTable.php b/app/Livewire/QuotesTable.php index 63b98ec18e..35c86fac55 100644 --- a/app/Livewire/QuotesTable.php +++ b/app/Livewire/QuotesTable.php @@ -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) diff --git a/app/Livewire/RecurringInvoiceCancellation.php b/app/Livewire/RecurringInvoiceCancellation.php index b01ee95349..a5a123edb2 100644 --- a/app/Livewire/RecurringInvoiceCancellation.php +++ b/app/Livewire/RecurringInvoiceCancellation.php @@ -18,16 +18,14 @@ use Livewire\Component; class RecurringInvoiceCancellation extends Component { - /** - * @var RecurringInvoice - */ - public $invoice; + + public $invoice_id; - public $company; + 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]); } } diff --git a/app/Livewire/RecurringInvoicesTable.php b/app/Livewire/RecurringInvoicesTable.php index 06ba0f841d..a8d0146c04 100644 --- a/app/Livewire/RecurringInvoicesTable.php +++ b/app/Livewire/RecurringInvoicesTable.php @@ -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') diff --git a/app/Livewire/RequiredClientInfo.php b/app/Livewire/RequiredClientInfo.php index 4640b9a9b7..b57c4cd42a 100644 --- a/app/Livewire/RequiredClientInfo.php +++ b/app/Livewire/RequiredClientInfo.php @@ -59,7 +59,6 @@ class RequiredClientInfo extends Component */ public $countries; - public $client_name; public $contact_first_name; public $contact_last_name; diff --git a/app/Livewire/SubscriptionPlanSwitch.php b/app/Livewire/SubscriptionPlanSwitch.php index 2ae807b57f..2909562bb4 100644 --- a/app/Livewire/SubscriptionPlanSwitch.php +++ b/app/Livewire/SubscriptionPlanSwitch.php @@ -12,40 +12,30 @@ 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, ]); diff --git a/app/Livewire/SubscriptionRecurringInvoicesTable.php b/app/Livewire/SubscriptionRecurringInvoicesTable.php index 5311901a81..e2fe5404b6 100644 --- a/app/Livewire/SubscriptionRecurringInvoicesTable.php +++ b/app/Livewire/SubscriptionRecurringInvoicesTable.php @@ -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) diff --git a/app/Livewire/SubscriptionsTable.php b/app/Livewire/SubscriptionsTable.php index e7397ff33f..0092d76617 100644 --- a/app/Livewire/SubscriptionsTable.php +++ b/app/Livewire/SubscriptionsTable.php @@ -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]) diff --git a/app/Livewire/TasksTable.php b/app/Livewire/TasksTable.php index 34954ef060..6d81661b07 100644 --- a/app/Livewire/TasksTable.php +++ b/app/Livewire/TasksTable.php @@ -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); diff --git a/resources/views/portal/ninja2020/components/livewire/subscription-plan-switch.blade.php b/resources/views/portal/ninja2020/components/livewire/subscription-plan-switch.blade.php index b67881b600..71b06c7383 100644 --- a/resources/views/portal/ninja2020/components/livewire/subscription-plan-switch.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/subscription-plan-switch.blade.php @@ -51,7 +51,7 @@