client = $client; $this->contact_person_name = $client->full_name; $this->contact_person_id = $client->national_id ?? ''; } public function showConfirmationDialog(): void { $this->validate([ 'company_name' => 'required|string|max:255', 'company_cert_number' => 'required|string|max:255|unique:users,company_cert_number', 'contact_person_name' => 'required|string|max:255', 'contact_person_id' => 'required|string|max:255', ]); $this->showConfirmation = true; } public function cancelConfirmation(): void { $this->showConfirmation = false; } public function convertToCompany(): void { $this->validate([ 'company_name' => 'required|string|max:255', 'company_cert_number' => 'required|string|max:255|unique:users,company_cert_number', 'contact_person_name' => 'required|string|max:255', 'contact_person_id' => 'required|string|max:255', ]); $oldValues = $this->client->only([ 'user_type', 'full_name', 'national_id', 'company_name', 'company_cert_number', 'contact_person_name', 'contact_person_id', ]); DB::transaction(function () use ($oldValues) { $this->client->update([ 'user_type' => UserType::Company, 'full_name' => $this->company_name, 'company_name' => $this->company_name, 'company_cert_number' => $this->company_cert_number, 'contact_person_name' => $this->contact_person_name, 'contact_person_id' => $this->contact_person_id, 'national_id' => null, ]); AdminLog::create([ 'admin_id' => auth()->id(), 'action' => 'convert_account', 'target_type' => 'user', 'target_id' => $this->client->id, 'old_values' => $oldValues, 'new_values' => $this->client->fresh()->only([ 'user_type', 'full_name', 'national_id', 'company_name', 'company_cert_number', 'contact_person_name', 'contact_person_id', ]), 'ip_address' => request()->ip(), 'created_at' => now(), ]); try { $this->client->notify(new AccountTypeChangedNotification(UserType::Company)); } catch (\Exception $e) { report($e); } }); session()->flash('success', __('clients.account_converted_to_company')); $this->redirect(route('admin.clients.company.show', $this->client), navigate: true); } }; ?>
{{ __('clients.convert_to_company') }} {{ __('clients.convert_to_company_description') }}
@if (!$showConfirmation)
{{ __('clients.company_name') }} {{ __('clients.registration_number') }} {{ __('clients.contact_person_name') }} {{ __('clients.contact_person_id') }}
{{ __('clients.cancel') }} {{ __('clients.continue') }}
@else
{{ __('clients.confirm_conversion') }} {{ __('clients.confirm_conversion_to_company_message') }}
{{ __('clients.company_name') }}: {{ $company_name }}
{{ __('clients.registration_number') }}: {{ $company_cert_number }}
{{ __('clients.contact_person_name') }}: {{ $contact_person_name }}
{{ __('clients.back') }} {{ __('clients.confirm_convert') }}
@endif