diff --git a/app/Filament/Organizations/Resources/InterventionPlanResource/Widgets/MonthlyPlanWidget.php b/app/Filament/Organizations/Resources/InterventionPlanResource/Widgets/MonthlyPlanWidget.php index 0482c372..64d13b8a 100644 --- a/app/Filament/Organizations/Resources/InterventionPlanResource/Widgets/MonthlyPlanWidget.php +++ b/app/Filament/Organizations/Resources/InterventionPlanResource/Widgets/MonthlyPlanWidget.php @@ -23,7 +23,7 @@ public function table(Table $table): Table return $table ->query( fn () => $this->record->monthlyPlans() - ->with('caseManager') + ->with(['caseManager', 'beneficiary']) ->withCount(['monthlyPlanServices', 'monthlyPlanInterventions']) ) ->heading(__('intervention_plan.headings.monthly_plans')) diff --git a/app/Filament/Organizations/Resources/MonthlyPlanResource/Pages/ViewMonthlyPlan.php b/app/Filament/Organizations/Resources/MonthlyPlanResource/Pages/ViewMonthlyPlan.php index f30b1dec..7f0759e0 100644 --- a/app/Filament/Organizations/Resources/MonthlyPlanResource/Pages/ViewMonthlyPlan.php +++ b/app/Filament/Organizations/Resources/MonthlyPlanResource/Pages/ViewMonthlyPlan.php @@ -5,6 +5,7 @@ namespace App\Filament\Organizations\Resources\MonthlyPlanResource\Pages; use App\Concerns\HasParentResource; +use App\Filament\Organizations\Resources\BeneficiaryResource; use App\Filament\Organizations\Resources\InterventionPlanResource; use App\Filament\Organizations\Resources\MonthlyPlanResource; use App\Infolists\Components\SectionHeader; @@ -12,6 +13,7 @@ use App\Models\Specialist; use App\Services\Breadcrumb\InterventionPlanBreadcrumb; use Carbon\Carbon; +use Filament\Actions\DeleteAction; use Filament\Infolists\Components\Actions\Action; use Filament\Infolists\Components\RepeatableEntry; use Filament\Infolists\Components\Section; @@ -39,6 +41,24 @@ public function getTitle(): string|Htmlable return __('intervention_plan.headings.monthly_plan'); } + public function getHeaderActions(): array + { + return [ + DeleteAction::make() + ->label(__('intervention_plan.actions.delete_monthly_plan')) + ->icon('heroicon-o-trash') + ->modalHeading(__('intervention_plan.headings.delete_monthly_plan_modal')) + ->modalSubmitActionLabel(__('intervention_plan.actions.delete_monthly_plan')) + ->successRedirectUrl( + BeneficiaryResource::getUrl('view_intervention_plan', [ + 'parent' => $this->parent->beneficiary, + 'record' => $this->parent, + ]) + ) + ->outlined(), + ]; + } + public function infolist(Infolist $infolist): Infolist { $this->getRecord() diff --git a/app/Policies/MonthlyPlanPolicy.php b/app/Policies/MonthlyPlanPolicy.php new file mode 100644 index 00000000..b5b27490 --- /dev/null +++ b/app/Policies/MonthlyPlanPolicy.php @@ -0,0 +1,67 @@ +hasAccessToBeneficiary($monthlyPlan->beneficiary); + } + + /** + * Determine whether the user can create models. + */ + public function create(User $user): bool + { + return true; + } + + /** + * Determine whether the user can update the model. + */ + public function update(User $user, MonthlyPlan $monthlyPlan): bool + { + return $user->hasAccessToBeneficiary($monthlyPlan->beneficiary); + } + + /** + * Determine whether the user can delete the model. + */ + public function delete(User $user, MonthlyPlan $monthlyPlan): bool + { + return $user->hasAccessToBeneficiary($monthlyPlan->beneficiary); + } + + /** + * Determine whether the user can restore the model. + */ + public function restore(User $user, MonthlyPlan $monthlyPlan): bool + { + return true; + } + + /** + * Determine whether the user can permanently delete the model. + */ + public function forceDelete(User $user, MonthlyPlan $monthlyPlan): bool + { + return true; + } +} diff --git a/lang/ro/intervention_plan.php b/lang/ro/intervention_plan.php index 7b0ba074..434a8f88 100644 --- a/lang/ro/intervention_plan.php +++ b/lang/ro/intervention_plan.php @@ -248,6 +248,7 @@ 'dashboard_intervention_table_empty_state' => 'Odată deschis primul caz și creat primul plan de intervenție pentru acesta, o listă a intervențiilor va fi afișată în acest tabel.', 'edit_monthly_plan_title' => 'Editează plan lunar', 'edit_monthly_plan_services_and_interventions_title' => 'Editează servicii si intervenții', + 'delete_monthly_plan_modal' => 'Șterge plan lunar', ], 'actions' => [ @@ -275,6 +276,7 @@ 'create_monthly_plan' => 'Crează un plan', 'create_monthly_plan_from_last' => 'Pornește de la un duplicat', 'create_monthly_plan_simple' => 'Începe cu un plan necompletată', + 'delete_monthly_plan' => 'Șterge planul lunar', ], 'placeholders' => [