Skip to content

Commit cc645c7

Browse files
feat: add service and intervention management to monthly plans
1 parent 66cc0d1 commit cc645c7

File tree

12 files changed

+735
-118
lines changed

12 files changed

+735
-118
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use App\Filament\Organizations\Resources\Cases\Pages\InterventionPlan\CreateCaseInterventionPlan;
3030
use App\Filament\Organizations\Resources\Cases\Pages\InterventionPlan\CreateCaseMonthlyPlan;
3131
use App\Filament\Organizations\Resources\Cases\Pages\InterventionPlan\EditCaseMonthlyPlanDetails;
32+
use App\Filament\Organizations\Resources\Cases\Pages\InterventionPlan\EditCaseMonthlyPlanServicesAndInterventions;
3233
use App\Filament\Organizations\Resources\Cases\Pages\InterventionPlan\ViewCaseBeneficiaryIntervention;
3334
use App\Filament\Organizations\Resources\Cases\Pages\InterventionPlan\ViewCaseInterventionPlan;
3435
use App\Filament\Organizations\Resources\Cases\Pages\InterventionPlan\ViewCaseInterventionService;
@@ -183,6 +184,7 @@ public static function getPages(): array
183184
'create_monthly_plan' => CreateCaseMonthlyPlan::route('/{case}/intervention-plan/monthly-plans/create'),
184185
'view_monthly_plan' => ViewCaseMonthlyPlan::route('/{record}/intervention-plan/monthly-plans/{monthlyPlan}'),
185186
'edit_monthly_plan_details' => EditCaseMonthlyPlanDetails::route('/{record}/intervention-plan/monthly-plans/{monthlyPlan}/edit-details'),
187+
'edit_monthly_plan_services' => EditCaseMonthlyPlanServicesAndInterventions::route('/{record}/intervention-plan/monthly-plans/{monthlyPlan}/edit-services'),
186188
];
187189
}
188190

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ protected function fillForm(): void
8989
$beneficiary = $this->getBeneficiary();
9090
$this->callHook('beforeFill');
9191
$this->form->fill([
92-
'start_date' => Carbon::now()->startOfMonth()->format('Y-m-d'),
93-
'end_date' => Carbon::now()->endOfMonth()->format('Y-m-d'),
92+
'start_date' => Carbon::today()->format('Y-m-d'),
93+
'end_date' => Carbon::today()->addMonth()->format('Y-m-d'),
9494
'case_manager_user_id' => $beneficiary?->managerTeam?->first()?->user_id ?? auth()->id(),
95+
'specialists' => $beneficiary?->specialistsTeam()->pluck('id')->values()->all() ?? [],
9596
]);
9697
$this->callHook('afterFill');
9798
}
@@ -144,11 +145,12 @@ public function form(Schema $schema): Schema
144145
->label(__('intervention_plan.labels.monthly_plan_end_date'))
145146
->required(),
146147
Select::make('case_manager_user_id')
147-
->label(__('intervention_plan.headings.case_manager'))
148+
->label(__('intervention_plan.labels.case_manager'))
148149
->options(User::getTenantOrganizationUsers()->all())
150+
->required()
149151
->placeholder(__('intervention_plan.placeholders.specialist')),
150152
Select::make('specialists')
151-
->label(__('intervention_plan.labels.specialists'))
153+
->label(__('intervention_plan.labels.case_team'))
152154
->multiple()
153155
->options(fn (): Collection => $this->getBeneficiary()?->specialistsTeam()->with('user', 'roleForDisplay')->get()->pluck('name_role', 'id') ?? collect())
154156
->placeholder(__('intervention_plan.placeholders.specialists')),
@@ -172,11 +174,14 @@ protected function mutateFormDataBeforeCreate(array $data): array
172174

173175
protected function getRedirectUrl(): string
174176
{
175-
$beneficiary = $this->getBeneficiary();
177+
$record = $this->getRecord();
178+
$beneficiary = $this->getBeneficiary()
179+
?? $record->beneficiary
180+
?? $record->interventionPlan?->beneficiary;
176181

177182
return CaseResource::getUrl('view_monthly_plan', [
178-
'record' => $beneficiary ?? $this->getRecord()->interventionPlan?->beneficiary,
179-
'monthlyPlan' => $this->getRecord(),
183+
'record' => $beneficiary,
184+
'monthlyPlan' => $record,
180185
]);
181186
}
182187

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

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,28 @@ public function mount(int|string $record): void
5555

5656
protected function authorizeAccess(): void
5757
{
58-
abort_unless(CaseResource::canEdit($this->beneficiary ?? $this->getRecord()), 403);
58+
abort_unless(CaseResource::canEdit($this->resolveCaseBeneficiary()), 403);
59+
}
60+
61+
protected function resolveCaseBeneficiary(): Beneficiary
62+
{
63+
if ($this->beneficiary instanceof Beneficiary) {
64+
return $this->beneficiary;
65+
}
66+
67+
$monthlyPlan = $this->getRecord();
68+
if (! $monthlyPlan instanceof MonthlyPlan) {
69+
abort(404);
70+
}
71+
72+
$monthlyPlan->loadMissing(['beneficiary', 'interventionPlan.beneficiary']);
73+
74+
$beneficiary = $monthlyPlan->beneficiary ?? $monthlyPlan->interventionPlan?->beneficiary;
75+
if (! $beneficiary instanceof Beneficiary) {
76+
abort(404);
77+
}
78+
79+
return $beneficiary;
5980
}
6081

6182
public function getTitle(): string|Htmlable
@@ -65,11 +86,11 @@ public function getTitle(): string|Htmlable
6586

6687
public function getBreadcrumbs(): array
6788
{
68-
$record = $this->beneficiary ?? $this->getRecord();
89+
$record = $this->resolveCaseBeneficiary();
6990

7091
return [
7192
CaseResource::getUrl('index') => __('case.view.breadcrumb_all'),
72-
CaseResource::getUrl('view', ['record' => $record]) => $record instanceof Beneficiary ? $record->getBreadcrumb() : '',
93+
CaseResource::getUrl('view', ['record' => $record]) => $record->getBreadcrumb(),
7394
CaseResource::getUrl('view_intervention_plan', ['record' => $record]) => __('intervention_plan.headings.view_page'),
7495
CaseResource::getUrl('view_monthly_plan', ['record' => $record, 'monthlyPlan' => $this->getRecord()]) => __('intervention_plan.headings.monthly_plan'),
7596
'' => __('intervention_plan.headings.edit_monthly_plan_title'),
@@ -81,7 +102,7 @@ protected function getHeaderActions(): array
81102
return [
82103
BackAction::make()
83104
->url(CaseResource::getUrl('view_monthly_plan', [
84-
'record' => $this->beneficiary,
105+
'record' => $this->resolveCaseBeneficiary(),
85106
'monthlyPlan' => $this->getRecord(),
86107
'tab' => '-'.str(\Illuminate\Support\Str::slug(__('intervention_plan.headings.monthly_plan_details')))->append('-tab')->toString(),
87108
])),
@@ -91,7 +112,7 @@ protected function getHeaderActions(): array
91112
protected function getRedirectUrl(): ?string
92113
{
93114
return CaseResource::getUrl('view_monthly_plan', [
94-
'record' => $this->beneficiary,
115+
'record' => $this->resolveCaseBeneficiary(),
95116
'monthlyPlan' => $this->getRecord(),
96117
'tab' => '-'.str(\Illuminate\Support\Str::slug(__('intervention_plan.headings.monthly_plan_details')))->append('-tab')->toString(),
97118
]);
@@ -143,13 +164,13 @@ public function form(Schema $schema): Schema
143164
->label(__('intervention_plan.labels.monthly_plan_end_date'))
144165
->required(),
145166
Select::make('case_manager_user_id')
146-
->label(__('intervention_plan.headings.case_manager'))
167+
->label(__('intervention_plan.labels.case_manager'))
147168
->options(User::getTenantOrganizationUsers()->all())
148169
->placeholder(__('intervention_plan.placeholders.specialist')),
149170
Select::make('specialists')
150-
->label(__('intervention_plan.labels.specialists'))
171+
->label(__('intervention_plan.labels.case_team'))
151172
->multiple()
152-
->options(fn (): Collection => $this->beneficiary?->specialistsTeam()->with('user', 'roleForDisplay')->get()->pluck('name_role', 'id') ?? collect())
173+
->options(fn (): Collection => $this->resolveCaseBeneficiary()->specialistsTeam()->with('user', 'roleForDisplay')->get()->pluck('name_role', 'id'))
153174
->placeholder(__('intervention_plan.placeholders.specialists')),
154175
]),
155176
]);

0 commit comments

Comments
 (0)