Skip to content

Commit e36f226

Browse files
wip
1 parent 2c84329 commit e36f226

File tree

9 files changed

+355
-40
lines changed

9 files changed

+355
-40
lines changed

app/Filament/Organizations/Resources/Cases/CaseResource.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use App\Filament\Organizations\Resources\Cases\Pages\InitialEvaluation\CreateCaseInitialEvaluation;
2020
use App\Filament\Organizations\Resources\Cases\Pages\InterventionPlan\CreateCaseInterventionPlan;
2121
use App\Filament\Organizations\Resources\Cases\Pages\InterventionPlan\CreateCaseMonthlyPlan;
22+
use App\Filament\Organizations\Resources\Cases\Pages\InterventionPlan\EditCaseMonthlyPlanDetails;
2223
use App\Filament\Organizations\Resources\Cases\Pages\InterventionPlan\ViewCaseInterventionPlan;
2324
use App\Filament\Organizations\Resources\Cases\Pages\InterventionPlan\ViewCaseInterventionService;
2425
use App\Filament\Organizations\Resources\Cases\Pages\InterventionPlan\ViewCaseMonthlyPlan;
@@ -159,6 +160,7 @@ public static function getPages(): array
159160
'view_intervention_service' => ViewCaseInterventionService::route('/{record}/intervention-plan/services/{interventionService}'),
160161
'create_monthly_plan' => CreateCaseMonthlyPlan::route('/{case}/intervention-plan/monthly-plans/create'),
161162
'view_monthly_plan' => ViewCaseMonthlyPlan::route('/{record}/intervention-plan/monthly-plans/{monthlyPlan}'),
163+
'edit_monthly_plan_details' => EditCaseMonthlyPlanDetails::route('/{record}/intervention-plan/monthly-plans/{monthlyPlan}/edit-details'),
162164
];
163165
}
164166

app/Filament/Organizations/Resources/Cases/Pages/DetailedEvaluation/ViewCaseDetailedEvaluation.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,6 @@ protected function getIdentitateCopiiSchema(): array
192192
->link(),
193193
]),
194194
Section::make(__('beneficiary.wizard.children.label'))
195-
->headerActions([
196-
EditAction::make('edit')
197-
->url(fn (Beneficiary $record): string => CaseResource::getUrl('edit_children', ['record' => $record])),
198-
])
199195
->schema([
200196
Grid::make(2)
201197
->schema([
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Filament\Organizations\Resources\Cases\Pages\InterventionPlan;
6+
7+
use App\Actions\BackAction;
8+
use App\Concerns\PreventSubmitFormOnEnter;
9+
use App\Filament\Organizations\Resources\Cases\CaseResource;
10+
use App\Forms\Components\DatePicker;
11+
use App\Models\Beneficiary;
12+
use App\Models\MonthlyPlan;
13+
use App\Models\User;
14+
use Filament\Forms\Components\Select;
15+
use Filament\Notifications\Notification;
16+
use Filament\Resources\Pages\EditRecord;
17+
use Filament\Schemas\Components\Section;
18+
use Filament\Schemas\Schema;
19+
use Illuminate\Contracts\Support\Htmlable;
20+
use Illuminate\Support\Collection;
21+
22+
class EditCaseMonthlyPlanDetails extends EditRecord
23+
{
24+
use PreventSubmitFormOnEnter;
25+
26+
protected static string $resource = CaseResource::class;
27+
28+
protected ?Beneficiary $beneficiary = null;
29+
30+
public function mount(int|string $record): void
31+
{
32+
$this->beneficiary = CaseResource::resolveRecordRouteBinding($record);
33+
if (! $this->beneficiary instanceof Beneficiary) {
34+
abort(404);
35+
}
36+
37+
$plan = $this->beneficiary->interventionPlan;
38+
if (! $plan) {
39+
$this->redirect(CaseResource::getUrl('view_intervention_plan', ['record' => $this->beneficiary]));
40+
41+
return;
42+
}
43+
44+
$monthlyPlanId = request()->route('monthlyPlan');
45+
$monthlyPlanModel = MonthlyPlan::query()
46+
->where('intervention_plan_id', $plan->id)
47+
->where('id', $monthlyPlanId)
48+
->firstOrFail();
49+
50+
$this->record = $monthlyPlanModel;
51+
$this->authorizeAccess();
52+
$this->fillForm();
53+
$this->previousUrl = url()->previous();
54+
}
55+
56+
protected function authorizeAccess(): void
57+
{
58+
abort_unless(CaseResource::canEdit($this->beneficiary ?? $this->getRecord()), 403);
59+
}
60+
61+
public function getTitle(): string|Htmlable
62+
{
63+
return __('intervention_plan.headings.edit_monthly_plan_title');
64+
}
65+
66+
public function getBreadcrumbs(): array
67+
{
68+
$record = $this->beneficiary ?? $this->getRecord();
69+
70+
return [
71+
CaseResource::getUrl('index') => __('case.view.breadcrumb_all'),
72+
CaseResource::getUrl('view', ['record' => $record]) => $record instanceof Beneficiary ? $record->getBreadcrumb() : '',
73+
CaseResource::getUrl('view_intervention_plan', ['record' => $record]) => __('intervention_plan.headings.view_page'),
74+
CaseResource::getUrl('view_monthly_plan', ['record' => $record, 'monthlyPlan' => $this->getRecord()]) => __('intervention_plan.headings.monthly_plan'),
75+
'' => __('intervention_plan.headings.edit_monthly_plan_title'),
76+
];
77+
}
78+
79+
protected function getHeaderActions(): array
80+
{
81+
return [
82+
BackAction::make()
83+
->url(CaseResource::getUrl('view_monthly_plan', [
84+
'record' => $this->beneficiary,
85+
'monthlyPlan' => $this->getRecord(),
86+
'tab' => '-'.str(\Illuminate\Support\Str::slug(__('intervention_plan.headings.monthly_plan_details')))->append('-tab')->toString(),
87+
])),
88+
];
89+
}
90+
91+
protected function getRedirectUrl(): ?string
92+
{
93+
return CaseResource::getUrl('view_monthly_plan', [
94+
'record' => $this->beneficiary,
95+
'monthlyPlan' => $this->getRecord(),
96+
'tab' => '-'.str(\Illuminate\Support\Str::slug(__('intervention_plan.headings.monthly_plan_details')))->append('-tab')->toString(),
97+
]);
98+
}
99+
100+
/**
101+
* @return class-string<\Illuminate\Database\Eloquent\Model>
102+
*/
103+
public function getModel(): string
104+
{
105+
return MonthlyPlan::class;
106+
}
107+
108+
/**
109+
* @param array<string, mixed> $data
110+
* @return array<string, mixed>
111+
*/
112+
protected function mutateFormDataBeforeFill(array $data): array
113+
{
114+
$data['specialists'] = $data['specialists'] ?? [];
115+
if ($data['specialists'] instanceof \Illuminate\Support\Collection) {
116+
$data['specialists'] = $data['specialists']->values()->all();
117+
}
118+
119+
return $data;
120+
}
121+
122+
/**
123+
* @param array<string, mixed> $data
124+
* @return array<string, mixed>
125+
*/
126+
protected function mutateFormDataBeforeSave(array $data): array
127+
{
128+
$data['specialists'] = $data['specialists'] ?? [];
129+
130+
return $data;
131+
}
132+
133+
public function form(Schema $schema): Schema
134+
{
135+
return $schema->components([
136+
Section::make(__('intervention_plan.headings.monthly_plan_details'))
137+
->maxWidth('3xl')
138+
->schema([
139+
DatePicker::make('start_date')
140+
->label(__('intervention_plan.labels.monthly_plan_start_date'))
141+
->required(),
142+
DatePicker::make('end_date')
143+
->label(__('intervention_plan.labels.monthly_plan_end_date'))
144+
->required(),
145+
Select::make('case_manager_user_id')
146+
->label(__('intervention_plan.headings.case_manager'))
147+
->options(User::getTenantOrganizationUsers()->all())
148+
->placeholder(__('intervention_plan.placeholders.specialist')),
149+
Select::make('specialists')
150+
->label(__('intervention_plan.labels.specialists'))
151+
->multiple()
152+
->options(fn (): Collection => $this->beneficiary?->specialistsTeam()->with('user', 'roleForDisplay')->get()->pluck('name_role', 'id') ?? collect())
153+
->placeholder(__('intervention_plan.placeholders.specialists')),
154+
]),
155+
]);
156+
}
157+
158+
protected function getSavedNotification(): ?Notification
159+
{
160+
return Notification::make()
161+
->success()
162+
->title(__('filament-actions::edit.single.notifications.saved.title'));
163+
}
164+
}

app/Filament/Organizations/Resources/Cases/Pages/InterventionPlan/ViewCaseMonthlyPlan.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use App\Actions\BackAction;
88
use App\Filament\Organizations\Resources\Cases\CaseResource;
9+
use App\Infolists\Components\Actions\EditAction;
910
use App\Infolists\Components\SectionHeader;
1011
use App\Models\Beneficiary;
1112
use App\Models\MonthlyPlan;
@@ -115,7 +116,16 @@ public function infolist(Schema $schema): Schema
115116
->columns(2)
116117
->schema([
117118
SectionHeader::make('monthly_plan_details')
118-
->state(__('intervention_plan.headings.monthly_plan_details')),
119+
->state(__('intervention_plan.headings.monthly_plan_details'))
120+
->action(
121+
EditAction::make()
122+
->url(
123+
CaseResource::getUrl('edit_monthly_plan_details', [
124+
'record' => $this->getRecord(),
125+
'monthlyPlan' => $this->monthlyPlan,
126+
])
127+
)
128+
),
119129

120130
TextEntry::make('beneficiary.full_name')
121131
->label(__('intervention_plan.labels.full_name')),

app/Filament/Organizations/Resources/Cases/Pages/InterventionPlan/Widgets/InterventionPlanResultsWidget.php

Lines changed: 69 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use App\Models\InterventionPlanResult;
1010
use App\Models\Result;
1111
use App\Models\User;
12+
use Filament\Actions\DeleteAction;
13+
use Filament\Actions\EditAction;
1214
use Filament\Forms\Components\Checkbox;
1315
use Filament\Forms\Components\RichEditor;
1416
use Filament\Forms\Components\Select;
@@ -63,44 +65,80 @@ public function table(Table $table): Table
6365

6466
return $data;
6567
})
66-
->schema([
67-
Grid::make()
68-
->columns(3)
69-
->schema([
70-
Select::make('result_id')
71-
->label(__('intervention_plan.labels.result'))
72-
->options(Result::query()->active()->pluck('name', 'id')->all())
73-
->required(),
74-
Select::make('user_id')
75-
->label(__('intervention_plan.labels.specialist'))
76-
->options(User::getTenantOrganizationUsers()->all()),
77-
DatePicker::make('started_at')
78-
->label(__('intervention_plan.labels.started_at'))
79-
->required(),
80-
DatePicker::make('ended_at')
81-
->label(__('intervention_plan.labels.ended_at'))
82-
->disabled(fn (Get $get): bool => (bool) $get('retried')),
83-
Checkbox::make('retried')
84-
->label(__('intervention_plan.labels.retried'))
85-
->live(),
86-
Checkbox::make('lost_from_monitoring')
87-
->label(__('intervention_plan.labels.lost_from_monitoring'))
88-
->disabled(fn (Get $get): bool => (bool) $get('retried')),
89-
DatePicker::make('retried_at')
90-
->label(__('intervention_plan.labels.retried_at'))
91-
->visible(fn (Get $get): bool => (bool) $get('retried')),
92-
]),
93-
RichEditor::make('observations')
94-
->label(__('intervention_plan.labels.result_observations'))
95-
->placeholder(__('intervention_plan.placeholders.result_observations')),
96-
])
68+
->schema($this->getResultFormSchema())
9769
->createAnother(false),
9870
])
71+
->recordActionsColumnLabel(__('intervention_plan.labels.actions'))
72+
->recordActions([
73+
EditAction::make()
74+
->label(__('intervention_plan.actions.edit_result'))
75+
->modalHeading(__('intervention_plan.headings.edit_result'))
76+
->fillForm(fn (InterventionPlanResult $record): array => [
77+
'result_id' => $record->result_id,
78+
'user_id' => $record->user_id,
79+
'started_at' => $record->started_at,
80+
'ended_at' => $record->ended_at,
81+
'retried' => $record->retried ?? false,
82+
'retried_at' => $record->retried_at,
83+
'lost_from_monitoring' => $record->lost_from_monitoring ?? false,
84+
'observations' => $record->observations,
85+
])
86+
->schema($this->getResultFormSchema())
87+
->action(function (array $data, InterventionPlanResult $record): void {
88+
$record->update($data);
89+
})
90+
->extraModalFooterActions([
91+
DeleteAction::make()
92+
->label(__('intervention_plan.actions.delete_result'))
93+
->modalHeading(__('intervention_plan.headings.delete_result_modal'))
94+
->modalDescription(fn (InterventionPlanResult $record): string => $record->result?->name ?? '')
95+
->modalSubmitActionLabel(__('intervention_plan.actions.delete_result'))
96+
->cancelParentActions(),
97+
]),
98+
])
9999
->emptyStateHeading(__('intervention_plan.headings.empty_state_result_table'))
100100
->emptyStateDescription(__('intervention_plan.labels.empty_state_result_table'))
101101
->emptyStateIcon('heroicon-o-document');
102102
}
103103

104+
/**
105+
* @return array<int, \Filament\Forms\Components\Component>
106+
*/
107+
private function getResultFormSchema(): array
108+
{
109+
return [
110+
Grid::make()
111+
->columns(3)
112+
->schema([
113+
Select::make('result_id')
114+
->label(__('intervention_plan.labels.result'))
115+
->options(Result::query()->active()->pluck('name', 'id')->all())
116+
->required(),
117+
Select::make('user_id')
118+
->label(__('intervention_plan.labels.specialist'))
119+
->options(User::getTenantOrganizationUsers()->all()),
120+
DatePicker::make('started_at')
121+
->label(__('intervention_plan.labels.started_at'))
122+
->required(),
123+
DatePicker::make('ended_at')
124+
->label(__('intervention_plan.labels.ended_at'))
125+
->disabled(fn (Get $get): bool => (bool) $get('retried')),
126+
Checkbox::make('retried')
127+
->label(__('intervention_plan.labels.retried'))
128+
->live(),
129+
Checkbox::make('lost_from_monitoring')
130+
->label(__('intervention_plan.labels.lost_from_monitoring'))
131+
->disabled(fn (Get $get): bool => (bool) $get('retried')),
132+
DatePicker::make('retried_at')
133+
->label(__('intervention_plan.labels.retried_at'))
134+
->visible(fn (Get $get): bool => (bool) $get('retried')),
135+
]),
136+
RichEditor::make('observations')
137+
->label(__('intervention_plan.labels.result_observations'))
138+
->placeholder(__('intervention_plan.placeholders.result_observations')),
139+
];
140+
}
141+
104142
public static function canView(): bool
105143
{
106144
return true;

app/Filament/Organizations/Resources/Cases/Resources/Monitoring/Pages/CreateMonitoring.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,16 @@ protected function fillForm(): void
127127
'name' => $c->name,
128128
'status' => $c->status,
129129
'age' => $c->age,
130-
'birthdate' => $c->birthdate?->format('d.m.Y'),
130+
'birthdate' => $c->birthdate?->format('Y-m-d'),
131131
'aggressor_relationship' => $c->aggressor_relationship?->value,
132132
'maintenance_sources' => $c->maintenance_sources?->value,
133133
'location' => $c->location,
134134
'observations' => $c->observations,
135135
])
136136
->all();
137137
} else {
138+
$beneficiary->loadMissing('children');
139+
138140
$data['specialistsTeam'] = $beneficiary->specialistsTeam
139141
->filter(fn (Specialist $s): bool => (bool) $s->role_id)
140142
->map(fn (Specialist $s): array => [
@@ -150,7 +152,7 @@ protected function fillForm(): void
150152
'name' => $c->name ?? '',
151153
'status' => $c->status ?? '',
152154
'age' => $c->age !== null ? (string) $c->age : '',
153-
'birthdate' => $c->birthdate?->format('d.m.Y'),
155+
'birthdate' => $c->birthdate?->format('Y-m-d'),
154156
'aggressor_relationship' => null,
155157
'maintenance_sources' => null,
156158
'location' => $c->current_address ?? '',
@@ -293,7 +295,8 @@ protected function getChildrenStepSchema(): array
293295
->maxLength(2)
294296
->mask('99'),
295297
DatePicker::make('birthdate')
296-
->label(__('monitoring.labels.birthdate')),
298+
->label(__('monitoring.labels.birthdate'))
299+
->format('Y-m-d'),
297300
Select::make('aggressor_relationship')
298301
->label(__('monitoring.labels.aggressor_relationship'))
299302
->placeholder(__('monitoring.placeholders.select_an_answer'))
@@ -441,7 +444,7 @@ protected function afterCreate(): void
441444
$birthdateRaw = trim((string) ($item['birthdate'] ?? ''));
442445
if ($birthdateRaw !== '' && $birthdateRaw !== '-') {
443446
try {
444-
$child['birthdate'] = Carbon::createFromFormat('d.m.Y', $birthdateRaw)->format('Y-m-d');
447+
$child['birthdate'] = Carbon::parse($birthdateRaw)->format('Y-m-d');
445448
} catch (\Throwable) {
446449
$child['birthdate'] = null;
447450
}

0 commit comments

Comments
 (0)