diff --git a/app/Enums/DashboardIntervalFilter.php b/app/Enums/DashboardIntervalFilter.php new file mode 100644 index 00000000..84e24c55 --- /dev/null +++ b/app/Enums/DashboardIntervalFilter.php @@ -0,0 +1,24 @@ +query( + fn () => BeneficiaryIntervention::query() + ->whereHas( + 'beneficiary', + ) + ->when( + ! auth()->user()->isNgoAdmin(), + fn (Builder $query) => $query->where( + fn (Builder $query) => $query + ->whereHas( + 'specialist', + fn (Builder $query) => $query->where('user_id', auth()->id()) + ) + ->orWhereHas( + 'beneficiary.managerTeam', + fn (Builder $query) => $query->where('user_id', auth()->id()) + ) + ) + ) + ->with([ + 'organizationServiceIntervention.serviceInterventionWithoutStatusCondition.service', + 'interventionService', + 'beneficiary', + 'specialist.user', + ]) + ) + ->heading(__('intervention_plan.headings.dashboard_intervention_table')) + ->searchPlaceholder(__('intervention_plan.placeholders.search_by_beneficiary_or_specialist')) + ->columns([ + TextColumn::make('organizationServiceIntervention.serviceInterventionWithoutStatusCondition.name') + ->label(__('intervention_plan.labels.intervention')), + + TextColumn::make('organizationServiceIntervention.serviceInterventionWithoutStatusCondition.service.name') + ->label(__('intervention_plan.labels.service')), + + TextColumn::make('interval') + ->label(__('intervention_plan.labels.interval')), + + TextColumn::make('beneficiary.full_name') + ->label(__('intervention_plan.labels.beneficiary')) + ->url( + fn ($record) => BeneficiaryResource::getUrl('view', [ + 'record' => $record->beneficiary, + ]) + ) + ->color('primary') + ->searchable(), + + TextColumn::make('specialist.user.full_name') + ->label(__('intervention_plan.labels.specialist')) + ->searchable(), + ]) + ->actions([ + Tables\Actions\ViewAction::make() + ->label(__('intervention_plan.actions.view_intervention')) + ->url( + fn (BeneficiaryIntervention $record) => InterventionServiceResource::getUrl('view_intervention', [ + 'parent' => $record->intervention_service_id, + 'record' => $record, + ]) + ), + ]) + ->recordUrl( + fn (BeneficiaryIntervention $record) => InterventionServiceResource::getUrl('view_intervention', [ + 'parent' => $record->intervention_service_id, + 'record' => $record, + ]) + ) + ->actionsColumnLabel(__('intervention_plan.labels.actions')) + ->filters([ + SelectFilter::make('selected_interval') + ->label(__('intervention_plan.labels.selected_interval')) + ->options(DashboardIntervalFilter::options()) + ->modifyQueryUsing(function (array $state, Builder $query) { + if (DashboardIntervalFilter::isValue($state['value'], DashboardIntervalFilter::ONE_WEEK)) { + return $query->where('start_date_interval', '<=', date('Y-m-d', strtotime('+1 week'))) + ->where('end_date_interval', '>=', date('Y-m-d')); + } + + if (DashboardIntervalFilter::isValue($state['value'], DashboardIntervalFilter::TOMORROW)) { + return $query->where('start_date_interval', '<=', date('Y-m-d', strtotime('+1 day'))) + ->where('end_date_interval', '>=', date('Y-m-d')); + } + + return $query->where('start_date_interval', '<=', date('Y-m-d')) + ->where('end_date_interval', '>=', date('Y-m-d')); + }), + ]) + ->paginationPageOptions([5, 10, 15]) + ->emptyStateHeading(__('intervention_plan.headings.dashboard_intervention_table_empty_state')) + ->emptyStateDescription('') + ->emptyStateIcon('heroicon-o-clipboard-document-check'); + } +} diff --git a/database/factories/BeneficiaryInterventionFactory.php b/database/factories/BeneficiaryInterventionFactory.php index 7cc7acf7..ba2d2d8a 100644 --- a/database/factories/BeneficiaryInterventionFactory.php +++ b/database/factories/BeneficiaryInterventionFactory.php @@ -18,14 +18,17 @@ class BeneficiaryInterventionFactory extends Factory */ public function definition(): array { + $startDate = fake()->dateTimeBetween('-2 weeks', '2 weeks'); + $endDate = fake()->dateTimeBetween($startDate, '+3 weeks'); + return [ 'objections' => fake()->text(), 'expected_results' => fake()->text(), 'procedure' => fake()->text(), 'indicators' => fake()->text(), 'achievement_degree' => fake()->text(), - 'start_date_interval' => fake()->date(), - 'end_date_interval' => fake()->date(), + 'start_date_interval' => $startDate->format('Y-m-d'), + 'end_date_interval' => $endDate->format('Y-m-d'), ]; } } diff --git a/database/factories/InterventionServiceFactory.php b/database/factories/InterventionServiceFactory.php index a712ef50..df23de75 100644 --- a/database/factories/InterventionServiceFactory.php +++ b/database/factories/InterventionServiceFactory.php @@ -29,15 +29,15 @@ public function definition(): array public function withBeneficiaryIntervention(): self { return $this->afterCreating(function (InterventionService $interventionService) { -// dd($interventionService->organizationService->interventions); -// $interventionService->load('organizationService', 'beneficiary'); BeneficiaryIntervention::factory() ->for($interventionService) ->state( fn () => [ 'organization_service_intervention_id' => $interventionService->organizationServiceWithoutStatusCondition - ->interventions - ->random() + ->interventions() + ->where('organization_id', $interventionService->organizationServiceWithoutStatusCondition->organization_id) + ->inRandomOrder() + ->first() ->id, 'specialist_id' => $interventionService->beneficiary ->specialistsTeam diff --git a/lang/ro/enum.php b/lang/ro/enum.php index 7dc18d08..3c2840ea 100644 --- a/lang/ro/enum.php +++ b/lang/ro/enum.php @@ -544,4 +544,10 @@ 'other' => 'Altă modalitate de plată', ], + + 'dashboard_interval_filter' => [ + 'today' => 'Astăzi', + 'tomorrow' => 'Mâine', + 'one_week' => '7 zile', + ], ]; diff --git a/lang/ro/intervention_plan.php b/lang/ro/intervention_plan.php index 2c58edd7..f5a7ef78 100644 --- a/lang/ro/intervention_plan.php +++ b/lang/ro/intervention_plan.php @@ -158,6 +158,9 @@ 'integration_and_participation_in_social_service_observations' => 'Alte observații legate de integrare și participare în serviciul social', 'count' => 'Nr', 'social_relationship' => 'Relația socială #:number', + 'beneficiary' => 'Beneficiar', + 'actions' => 'Acțiuni', + 'selected_interval' => 'Interval selectat', ], 'headings' => [ @@ -217,6 +220,8 @@ 'professional_experience' => 'Experiența profesională', 'children_details' => 'Date adiționale despre copii', 'integration_and_participation_in_social_service' => 'Integrare și participare în serviciul social', + 'dashboard_intervention_table' => 'Sumar intervenții', + '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.', ], 'actions' => [ @@ -262,5 +267,6 @@ 'peoples' => 'Introdu un număr', 'add_details' => 'Adaugă detalii', 'select_age' => 'Alege un an', + 'search_by_beneficiary_or_specialist' => 'Caută caz sau specialist', ], ];