client = $client; $this->full_name = $client->contact_person_name ?? $client->company_name ?? ''; $this->national_id = $client->contact_person_id ?? ''; } public function showConfirmationDialog(): void { $this->validate([ 'full_name' => 'required|string|max:255', 'national_id' => 'required|string|max:255|unique:users,national_id', ]); $this->showConfirmation = true; } public function cancelConfirmation(): void { $this->showConfirmation = false; } public function convertToIndividual(): void { $this->validate([ 'full_name' => 'required|string|max:255', 'national_id' => 'required|string|max:255|unique:users,national_id', ]); $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::Individual, 'full_name' => $this->full_name, 'national_id' => $this->national_id, 'company_name' => null, 'company_cert_number' => null, 'contact_person_name' => null, 'contact_person_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::Individual)); } catch (\Exception $e) { report($e); } }); session()->flash('success', __('clients.account_converted_to_individual')); $this->redirect(route('admin.clients.individual.show', $this->client), navigate: true); } }; ?>
{{ __('clients.convert_to_individual') }} {{ __('clients.convert_to_individual_description') }}
@if (!$showConfirmation)
{{ __('clients.full_name') }} {{ __('clients.national_id') }} {{ __('clients.company_fields_will_be_cleared') }}
{{ __('clients.cancel') }} {{ __('clients.continue') }}
@else
{{ __('clients.confirm_conversion') }} {{ __('clients.confirm_conversion_to_individual_message') }}
{{ __('clients.full_name') }}: {{ $full_name }}
{{ __('clients.national_id') }}: {{ $national_id }}
{{ __('clients.back') }} {{ __('clients.confirm_convert') }}
@endif