diff --git a/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/CreateBeneficiary.php b/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/CreateBeneficiary.php index 91bb9104..87c7fd16 100644 --- a/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/CreateBeneficiary.php +++ b/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/CreateBeneficiary.php @@ -16,6 +16,7 @@ use Filament\Facades\Filament; use Filament\Forms\Components\Actions\Action; use Filament\Forms\Components\Checkbox; +use Filament\Forms\Components\CheckboxList; use Filament\Forms\Components\Grid; use Filament\Forms\Components\Group; use Filament\Forms\Components\Placeholder; @@ -324,15 +325,50 @@ protected function getSteps(): array ->columns() ->schema(EditFlowPresentation::flowSection()), ]), + Step::make('specialist') + ->label(__('beneficiary.wizard.specialist.label')) + ->schema([ + Section::make() + ->label(__('beneficiary.wizard.specialist.label')) + ->maxWidth('3xl') + ->schema([ + CheckboxList::make('roles') + ->label(__('beneficiary.section.specialists.labels.select_roles', ['user_name' => auth()->user()->full_name])) + ->options(function () { + $roles = auth()->user()->rolesInOrganization->pluck('name', 'id'); + $roles[-1] = __('beneficiary.section.specialists.labels.without_role'); + + return $roles; + }), + ]), + ]), ]; } public function afterCreate(): void { + /** @var Beneficiary $record */ $record = $this->getRecord(); if ($record->same_as_legal_residence) { $record->load(['legal_residence', 'effective_residence']); Beneficiary::copyLegalResidenceToEffectiveResidence($record); } + + $roles = $this->data['roles'] ?? []; + + if (! $roles) { + return; + } + + foreach ($roles as $role) { + if (! $role) { + continue; + } + $record->specialistsTeam()->create([ + 'role_id' => $role !== '-1' ? $role : null, + 'user_id' => auth()->id(), + 'specialistable_type' => 'beneficiary', + ]); + } } } diff --git a/app/Models/Beneficiary.php b/app/Models/Beneficiary.php index 802a18bc..2d8ac9cc 100644 --- a/app/Models/Beneficiary.php +++ b/app/Models/Beneficiary.php @@ -93,30 +93,6 @@ class Beneficiary extends Model 'status' => CaseStatus::class, ]; - protected static function booted() - { - static::created(function (Beneficiary $beneficiary) { - if (auth()->guest()) { - return; - } - - /** @var User $user */ - $user = auth()->user(); - $beneficiary->specialistsTeam()->create([ - 'user_id' => $user->id, - 'role_id' => $user->canBeCaseManager() - ? $user->rolesInOrganization - ->filter(fn ($role) => $role->case_manager) - ->first() - ?->id - : $user->rolesInOrganization - ->first() - ?->id, - 'specialistable_type' => $beneficiary->getMorphClass(), - ]); - }); - } - public function scopeWhereUserHasAccess(Builder $query): Builder { $user = auth()->user(); diff --git a/lang/ro/beneficiary.php b/lang/ro/beneficiary.php index da49ab80..2801f950 100644 --- a/lang/ro/beneficiary.php +++ b/lang/ro/beneficiary.php @@ -136,6 +136,9 @@ 'beneficiary_situation' => [ 'label' => 'Situația beneficiarului', ], + 'specialist' => [ + 'label' => 'Definește rol în echipa cazului ', + ], ], 'section' => [ @@ -322,6 +325,8 @@ 'status' => 'Status', 'roles' => 'Rol în echipa de caz', 'summarize' => '{1} +:count alt specialist|[2,19] +:count alți specialiști|[20,*] +:count de alți specialiști', + 'select_roles' => 'Selectează rolul (sau rolurile) specialistului :user_name în echipa cazului', + 'without_role' => 'Specialistul înregistrează cazul, dar nu are alt rol în echipa de caz', ], 'action' => [ 'delete' => 'Elimină din echipa de caz',