complete story 2.3 with qa test
This commit is contained in:
@@ -28,9 +28,14 @@ new class extends Component {
|
||||
{{ __('clients.back_to_companies') }}
|
||||
</flux:button>
|
||||
</div>
|
||||
<flux:button variant="primary" :href="route('admin.clients.company.edit', $client)" wire:navigate icon="pencil">
|
||||
{{ __('clients.edit_company') }}
|
||||
</flux:button>
|
||||
<div class="flex gap-2">
|
||||
<flux:button variant="ghost" class="border border-amber-500 text-amber-600 hover:bg-amber-50 dark:text-amber-400 dark:hover:bg-amber-900/20" x-data x-on:click="$flux.modal('convert-to-individual').show()" icon="user">
|
||||
{{ __('clients.convert_to_individual') }}
|
||||
</flux:button>
|
||||
<flux:button variant="primary" :href="route('admin.clients.company.edit', $client)" wire:navigate icon="pencil">
|
||||
{{ __('clients.edit_company') }}
|
||||
</flux:button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-6">
|
||||
@@ -176,4 +181,6 @@ new class extends Component {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<livewire:admin.clients.convert-to-individual-modal :client="$client" />
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\UserType;
|
||||
use App\Models\AdminLog;
|
||||
use App\Models\User;
|
||||
use App\Notifications\AccountTypeChangedNotification;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Livewire\Volt\Component;
|
||||
|
||||
new class extends Component {
|
||||
public User $client;
|
||||
|
||||
public string $company_name = '';
|
||||
public string $company_cert_number = '';
|
||||
public string $contact_person_name = '';
|
||||
public string $contact_person_id = '';
|
||||
|
||||
public bool $showConfirmation = false;
|
||||
|
||||
public function mount(User $client): void
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}; ?>
|
||||
|
||||
<div>
|
||||
<flux:modal name="convert-to-company" class="md:w-96">
|
||||
<div class="space-y-6">
|
||||
<div>
|
||||
<flux:heading size="lg">{{ __('clients.convert_to_company') }}</flux:heading>
|
||||
<flux:text class="mt-2 text-zinc-600 dark:text-zinc-400">
|
||||
{{ __('clients.convert_to_company_description') }}
|
||||
</flux:text>
|
||||
</div>
|
||||
|
||||
@if (!$showConfirmation)
|
||||
<form wire:submit="showConfirmationDialog" class="space-y-4">
|
||||
<flux:field>
|
||||
<flux:label>{{ __('clients.company_name') }}</flux:label>
|
||||
<flux:input wire:model="company_name" required />
|
||||
<flux:error name="company_name" />
|
||||
</flux:field>
|
||||
|
||||
<flux:field>
|
||||
<flux:label>{{ __('clients.registration_number') }}</flux:label>
|
||||
<flux:input wire:model="company_cert_number" required />
|
||||
<flux:error name="company_cert_number" />
|
||||
</flux:field>
|
||||
|
||||
<flux:field>
|
||||
<flux:label>{{ __('clients.contact_person_name') }}</flux:label>
|
||||
<flux:input wire:model="contact_person_name" required />
|
||||
<flux:error name="contact_person_name" />
|
||||
</flux:field>
|
||||
|
||||
<flux:field>
|
||||
<flux:label>{{ __('clients.contact_person_id') }}</flux:label>
|
||||
<flux:input wire:model="contact_person_id" required />
|
||||
<flux:error name="contact_person_id" />
|
||||
</flux:field>
|
||||
|
||||
<div class="flex gap-2 pt-4">
|
||||
<flux:button type="button" variant="ghost" x-on:click="$flux.modal('convert-to-company').close()">
|
||||
{{ __('clients.cancel') }}
|
||||
</flux:button>
|
||||
<flux:button type="submit" variant="primary">
|
||||
{{ __('clients.continue') }}
|
||||
</flux:button>
|
||||
</div>
|
||||
</form>
|
||||
@else
|
||||
<div class="space-y-4">
|
||||
<flux:callout variant="warning" icon="exclamation-triangle">
|
||||
<flux:callout.heading>{{ __('clients.confirm_conversion') }}</flux:callout.heading>
|
||||
<flux:callout.text>{{ __('clients.confirm_conversion_to_company_message') }}</flux:callout.text>
|
||||
</flux:callout>
|
||||
|
||||
<div class="rounded-lg border border-zinc-200 p-4 dark:border-zinc-700">
|
||||
<div class="space-y-2 text-sm">
|
||||
<div class="flex justify-between">
|
||||
<span class="text-zinc-500 dark:text-zinc-400">{{ __('clients.company_name') }}:</span>
|
||||
<span class="font-medium">{{ $company_name }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="text-zinc-500 dark:text-zinc-400">{{ __('clients.registration_number') }}:</span>
|
||||
<span class="font-medium">{{ $company_cert_number }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="text-zinc-500 dark:text-zinc-400">{{ __('clients.contact_person_name') }}:</span>
|
||||
<span class="font-medium">{{ $contact_person_name }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-2 pt-4">
|
||||
<flux:button type="button" variant="ghost" wire:click="cancelConfirmation">
|
||||
{{ __('clients.back') }}
|
||||
</flux:button>
|
||||
<flux:button type="button" variant="primary" wire:click="convertToCompany">
|
||||
{{ __('clients.confirm_convert') }}
|
||||
</flux:button>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</flux:modal>
|
||||
</div>
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\UserType;
|
||||
use App\Models\AdminLog;
|
||||
use App\Models\User;
|
||||
use App\Notifications\AccountTypeChangedNotification;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Livewire\Volt\Component;
|
||||
|
||||
new class extends Component {
|
||||
public User $client;
|
||||
|
||||
public string $full_name = '';
|
||||
public string $national_id = '';
|
||||
|
||||
public bool $showConfirmation = false;
|
||||
|
||||
public function mount(User $client): void
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}; ?>
|
||||
|
||||
<div>
|
||||
<flux:modal name="convert-to-individual" class="md:w-96">
|
||||
<div class="space-y-6">
|
||||
<div>
|
||||
<flux:heading size="lg">{{ __('clients.convert_to_individual') }}</flux:heading>
|
||||
<flux:text class="mt-2 text-zinc-600 dark:text-zinc-400">
|
||||
{{ __('clients.convert_to_individual_description') }}
|
||||
</flux:text>
|
||||
</div>
|
||||
|
||||
@if (!$showConfirmation)
|
||||
<form wire:submit="showConfirmationDialog" class="space-y-4">
|
||||
<flux:field>
|
||||
<flux:label>{{ __('clients.full_name') }}</flux:label>
|
||||
<flux:input wire:model="full_name" required />
|
||||
<flux:error name="full_name" />
|
||||
</flux:field>
|
||||
|
||||
<flux:field>
|
||||
<flux:label>{{ __('clients.national_id') }}</flux:label>
|
||||
<flux:input wire:model="national_id" required />
|
||||
<flux:error name="national_id" />
|
||||
</flux:field>
|
||||
|
||||
<flux:callout variant="info" icon="information-circle">
|
||||
<flux:callout.text>{{ __('clients.company_fields_will_be_cleared') }}</flux:callout.text>
|
||||
</flux:callout>
|
||||
|
||||
<div class="flex gap-2 pt-4">
|
||||
<flux:button type="button" variant="ghost" x-on:click="$flux.modal('convert-to-individual').close()">
|
||||
{{ __('clients.cancel') }}
|
||||
</flux:button>
|
||||
<flux:button type="submit" variant="primary">
|
||||
{{ __('clients.continue') }}
|
||||
</flux:button>
|
||||
</div>
|
||||
</form>
|
||||
@else
|
||||
<div class="space-y-4">
|
||||
<flux:callout variant="warning" icon="exclamation-triangle">
|
||||
<flux:callout.heading>{{ __('clients.confirm_conversion') }}</flux:callout.heading>
|
||||
<flux:callout.text>{{ __('clients.confirm_conversion_to_individual_message') }}</flux:callout.text>
|
||||
</flux:callout>
|
||||
|
||||
<div class="rounded-lg border border-zinc-200 p-4 dark:border-zinc-700">
|
||||
<div class="space-y-2 text-sm">
|
||||
<div class="flex justify-between">
|
||||
<span class="text-zinc-500 dark:text-zinc-400">{{ __('clients.full_name') }}:</span>
|
||||
<span class="font-medium">{{ $full_name }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="text-zinc-500 dark:text-zinc-400">{{ __('clients.national_id') }}:</span>
|
||||
<span class="font-medium">{{ $national_id }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-2 pt-4">
|
||||
<flux:button type="button" variant="ghost" wire:click="cancelConfirmation">
|
||||
{{ __('clients.back') }}
|
||||
</flux:button>
|
||||
<flux:button type="button" variant="primary" wire:click="convertToIndividual">
|
||||
{{ __('clients.confirm_convert') }}
|
||||
</flux:button>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</flux:modal>
|
||||
</div>
|
||||
@@ -28,9 +28,14 @@ new class extends Component {
|
||||
{{ __('clients.back_to_clients') }}
|
||||
</flux:button>
|
||||
</div>
|
||||
<flux:button variant="primary" :href="route('admin.clients.individual.edit', $client)" wire:navigate icon="pencil">
|
||||
{{ __('clients.edit_client') }}
|
||||
</flux:button>
|
||||
<div class="flex gap-2">
|
||||
<flux:button variant="ghost" class="border border-amber-500 text-amber-600 hover:bg-amber-50 dark:text-amber-400 dark:hover:bg-amber-900/20" x-data x-on:click="$flux.modal('convert-to-company').show()" icon="building-office">
|
||||
{{ __('clients.convert_to_company') }}
|
||||
</flux:button>
|
||||
<flux:button variant="primary" :href="route('admin.clients.individual.edit', $client)" wire:navigate icon="pencil">
|
||||
{{ __('clients.edit_client') }}
|
||||
</flux:button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-6">
|
||||
@@ -168,4 +173,6 @@ new class extends Component {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<livewire:admin.clients.convert-to-company-modal :client="$client" />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user