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/BeneficiaryFactory.php b/database/factories/BeneficiaryFactory.php index b295b937..02e6999d 100644 --- a/database/factories/BeneficiaryFactory.php +++ b/database/factories/BeneficiaryFactory.php @@ -24,9 +24,11 @@ use App\Models\Document; use App\Models\EvaluateDetails; use App\Models\FlowPresentation; +use App\Models\InterventionPlan; use App\Models\Meeting; use App\Models\Monitoring; use App\Models\MultidisciplinaryEvaluation; +use App\Models\Organization; use App\Models\RequestedServices; use App\Models\RiskFactors; use App\Models\Specialist; @@ -189,6 +191,17 @@ public function withEthnicity(): static ]); } + public function withInterventionPlan(Organization $organization): static + { + return $this->afterCreating(function (Beneficiary $beneficiary) use ($organization) { + InterventionPlan::factory() + ->for($beneficiary) + ->for($organization) + ->withService($organization) + ->create(); + }); + } + public function configure(): static { return $this diff --git a/database/factories/BeneficiaryInterventionFactory.php b/database/factories/BeneficiaryInterventionFactory.php index a46ab621..ba2d2d8a 100644 --- a/database/factories/BeneficiaryInterventionFactory.php +++ b/database/factories/BeneficiaryInterventionFactory.php @@ -18,8 +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' => $startDate->format('Y-m-d'), + 'end_date_interval' => $endDate->format('Y-m-d'), ]; } } diff --git a/database/factories/ChildrenFactory.php b/database/factories/ChildrenFactory.php index 4ec2bae3..0a8f6d0e 100644 --- a/database/factories/ChildrenFactory.php +++ b/database/factories/ChildrenFactory.php @@ -20,7 +20,7 @@ public function definition(): array { return [ 'name' => fake()->name(), - 'birthdate' => fake()->date(), + 'birthdate' => fake()->date('d-m-Y'), 'current_address' => fake()->boolean() ? fake()->address() : null, 'status' => fake()->boolean() ? fake()->words(asText: true) : null, ]; diff --git a/database/factories/InstitutionFactory.php b/database/factories/InstitutionFactory.php index e7a5f3c4..fe7140b7 100644 --- a/database/factories/InstitutionFactory.php +++ b/database/factories/InstitutionFactory.php @@ -64,9 +64,9 @@ public function withOrganization() ->for($institution) ->count(2) ->withUsers() + ->withServices() ->withBeneficiaries() ->withCommunityProfile() - ->withInterventions() ->create(); }); } diff --git a/database/factories/InterventionPlanFactory.php b/database/factories/InterventionPlanFactory.php index 3f4e8ada..bfb3cc2a 100644 --- a/database/factories/InterventionPlanFactory.php +++ b/database/factories/InterventionPlanFactory.php @@ -4,6 +4,10 @@ namespace Database\Factories; +use App\Models\InterventionPlan; +use App\Models\InterventionService; +use App\Models\Organization; +use App\Models\OrganizationService; use Illuminate\Database\Eloquent\Factories\Factory; /** @@ -19,7 +23,28 @@ class InterventionPlanFactory extends Factory public function definition(): array { return [ - // + 'admit_date_in_center' => $this->faker->date(), + 'plan_date' => $this->faker->date(), + 'last_revise_date' => $this->faker->date(), ]; } + + public function withService(Organization $organization): static + { + return $this->afterCreating(function (InterventionPlan $plan) use ($organization) { + InterventionService::factory() + ->for($plan) + ->state(fn () => [ + 'organization_service_id' => OrganizationService::query() + ->where('organization_id', $organization->id) + ->inRandomOrder() + ->first() + ->id, + 'specialist_id' => $plan->beneficiary->specialistsTeam->random()->id, + ]) + ->withBeneficiaryIntervention() + ->count(rand(1, 5)) + ->create(); + }); + } } diff --git a/database/factories/InterventionServiceFactory.php b/database/factories/InterventionServiceFactory.php index 28505341..df23de75 100644 --- a/database/factories/InterventionServiceFactory.php +++ b/database/factories/InterventionServiceFactory.php @@ -4,6 +4,8 @@ namespace Database\Factories; +use App\Models\BeneficiaryIntervention; +use App\Models\InterventionService; use Illuminate\Database\Eloquent\Factories\Factory; /** @@ -19,7 +21,32 @@ class InterventionServiceFactory extends Factory public function definition(): array { return [ - // + 'institution' => $this->faker->company(), + 'objections' => $this->faker->text(), ]; } + + public function withBeneficiaryIntervention(): self + { + return $this->afterCreating(function (InterventionService $interventionService) { + BeneficiaryIntervention::factory() + ->for($interventionService) + ->state( + fn () => [ + 'organization_service_intervention_id' => $interventionService->organizationServiceWithoutStatusCondition + ->interventions() + ->where('organization_id', $interventionService->organizationServiceWithoutStatusCondition->organization_id) + ->inRandomOrder() + ->first() + ->id, + 'specialist_id' => $interventionService->beneficiary + ->specialistsTeam + ->random() + ->id, + ] + ) + ->count(rand(1, 5)) + ->create(); + }); + } } diff --git a/database/factories/OrganizationFactory.php b/database/factories/OrganizationFactory.php index 3ebb340a..c180b21c 100644 --- a/database/factories/OrganizationFactory.php +++ b/database/factories/OrganizationFactory.php @@ -6,9 +6,11 @@ use App\Models\Beneficiary; use App\Models\CommunityProfile; -use App\Models\Intervention; use App\Models\Organization; +use App\Models\OrganizationService; +use App\Models\OrganizationServiceIntervention; use App\Models\Service; +use App\Models\ServiceIntervention; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Sequence; @@ -78,24 +80,37 @@ public function withBeneficiaries(int $count = 30): static ->withBeneficiaryDetails() ->withCitizenship() ->withEthnicity() + ->withInterventionPlan($organization) ->for($organization) ->create(); }); } - public function withInterventions(int $count = 5): static + public function withServices(int $count = 5): static { return $this->afterCreating(function (Organization $organization) use ($count) { Service::query() ->inRandomOrder() ->limit($count) + ->with('serviceInterventions') ->get() ->each( - fn (Service $service) => Intervention::factory() - ->count($count) - ->for($organization) - ->for($service) - ->create() + function (Service $service) use ($organization) { + $organizationService = OrganizationService::factory() + ->for($organization) + ->for($service) + ->create(); + + $service->serviceInterventions + ->filter(fn (ServiceIntervention $serviceIntervention) => $serviceIntervention->status) + ->each( + fn (ServiceIntervention $serviceIntervention) => OrganizationServiceIntervention::factory() + ->for($organizationService) + ->for($serviceIntervention) + ->for($organization) + ->create() + ); + } ); }); } diff --git a/database/factories/OrganizationServiceFactory.php b/database/factories/OrganizationServiceFactory.php index 21bb64e8..05866a62 100644 --- a/database/factories/OrganizationServiceFactory.php +++ b/database/factories/OrganizationServiceFactory.php @@ -19,7 +19,7 @@ class OrganizationServiceFactory extends Factory public function definition(): array { return [ - // + 'status' => fake()->boolean(), ]; } } diff --git a/database/factories/OrganizationServiceInterventionFactory.php b/database/factories/OrganizationServiceInterventionFactory.php index c06652bc..6030b4d8 100644 --- a/database/factories/OrganizationServiceInterventionFactory.php +++ b/database/factories/OrganizationServiceInterventionFactory.php @@ -19,7 +19,7 @@ class OrganizationServiceInterventionFactory extends Factory public function definition(): array { return [ - // + 'status' => fake()->boolean(), ]; } } 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', ], ];