Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions app/Enums/DashboardIntervalFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace App\Enums;

use App\Concerns\Enums;
use Filament\Support\Contracts\HasLabel;

enum DashboardIntervalFilter: string implements HasLabel
{
use Enums\HasLabel;
use Enums\Comparable;
use Enums\Arrayable;

case TODAY = 'today';
case TOMORROW = 'tomorrow';
case ONE_WEEK = 'one_week';

protected function labelKeyPrefix(): ?string
{
return 'enum.dashboard_interval_filter';
}
}
118 changes: 118 additions & 0 deletions app/Filament/Organizations/Widgets/DashboardInterventionsWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

declare(strict_types=1);

namespace App\Filament\Organizations\Widgets;

use App\Enums\DashboardIntervalFilter;
use App\Filament\Organizations\Resources\BeneficiaryResource;
use App\Filament\Organizations\Resources\InterventionServiceResource;
use App\Models\BeneficiaryIntervention;
use App\Tables\Filters\SelectFilter;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Filament\Widgets\TableWidget as BaseWidget;
use Illuminate\Database\Eloquent\Builder;

class DashboardInterventionsWidget extends BaseWidget
{
protected int | string | array $columnSpan = 2;

public function table(Table $table): Table
{
return $table
->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');
}
}
13 changes: 13 additions & 0 deletions database/factories/BeneficiaryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion database/factories/BeneficiaryInterventionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
];
}
}
2 changes: 1 addition & 1 deletion database/factories/ChildrenFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
Expand Down
2 changes: 1 addition & 1 deletion database/factories/InstitutionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public function withOrganization()
->for($institution)
->count(2)
->withUsers()
->withServices()
->withBeneficiaries()
->withCommunityProfile()
->withInterventions()
->create();
});
}
Expand Down
27 changes: 26 additions & 1 deletion database/factories/InterventionPlanFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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();
});
}
}
29 changes: 28 additions & 1 deletion database/factories/InterventionServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Database\Factories;

use App\Models\BeneficiaryIntervention;
use App\Models\InterventionService;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
Expand All @@ -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();
});
}
}
29 changes: 22 additions & 7 deletions database/factories/OrganizationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
);
}
);
});
}
Expand Down
2 changes: 1 addition & 1 deletion database/factories/OrganizationServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class OrganizationServiceFactory extends Factory
public function definition(): array
{
return [
//
'status' => fake()->boolean(),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class OrganizationServiceInterventionFactory extends Factory
public function definition(): array
{
return [
//
'status' => fake()->boolean(),
];
}
}
6 changes: 6 additions & 0 deletions lang/ro/enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,4 +544,10 @@
'other' => 'Altă modalitate de plată',

],

'dashboard_interval_filter' => [
'today' => 'Astăzi',
'tomorrow' => 'Mâine',
'one_week' => '7 zile',
],
];
Loading