Skip to content

Commit

Permalink
Dashboard intervention widget
Browse files Browse the repository at this point in the history
  • Loading branch information
alexPopaCode4 committed Dec 13, 2024
1 parent a178f60 commit 4f8a92b
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 6 deletions.
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');
}
}
7 changes: 5 additions & 2 deletions database/factories/BeneficiaryInterventionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
];
}
}
8 changes: 4 additions & 4 deletions database/factories/InterventionServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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',
],
];
6 changes: 6 additions & 0 deletions lang/ro/intervention_plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down Expand Up @@ -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' => [
Expand Down Expand Up @@ -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',
],
];

0 comments on commit 4f8a92b

Please sign in to comment.