Skip to content

Commit

Permalink
Merge pull request #430 from code4romania/425-ngo-admin-specialist-ca…
Browse files Browse the repository at this point in the history
…zuri-plan-de-interventie-implement-new-sectiontab-called-planuri-lunare

Monthly plan
  • Loading branch information
gheorghelupu17 authored Dec 20, 2024
2 parents 44c8f10 + dda014f commit 7b7062d
Show file tree
Hide file tree
Showing 23 changed files with 1,403 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
use App\Filament\Organizations\Resources\InterventionServiceResource\Pages\EditCounselingSheet;
use App\Filament\Organizations\Resources\InterventionServiceResource\Pages\EditInterventionService;
use App\Filament\Organizations\Resources\InterventionServiceResource\Pages\ViewInterventionService;
use App\Filament\Organizations\Resources\MonthlyPlanResource\Pages\CreateMonthlyPlan;
use App\Filament\Organizations\Resources\MonthlyPlanResource\Pages\EditMonthlyPlanDetails;
use App\Filament\Organizations\Resources\MonthlyPlanResource\Pages\EditMonthlyPlanServicesAndInterventions;
use App\Filament\Organizations\Resources\MonthlyPlanResource\Pages\ViewMonthlyPlan;
use App\Models\InterventionPlan;
use Filament\Resources\Resource;

Expand All @@ -24,6 +28,11 @@ public static function getPages(): array
'view_intervention_service' => ViewInterventionService::route('{parent}/service/{record}'),
'edit_intervention_service' => EditInterventionService::route('{parent}/service/{record}/edit'),
'edit_counseling_sheet' => EditCounselingSheet::route('{parent}/service/{record}/editCounselingSheet'),

'create_monthly_plan' => CreateMonthlyPlan::route('{parent}/createMonthlyPlan/{copyLastPlan?}'),
'view_monthly_plan' => ViewMonthlyPlan::route('{parent}/monthlyPlan{record}'),
'edit_monthly_plan_details' => EditMonthlyPlanDetails::route('{parent}/monthlyPlan{record}/editDetails'),
'edit_monthly_plan_services_and_interventions' => EditMonthlyPlanServicesAndInterventions::route('{parent}/monthlyPlan{record}/editServicesAndInterventions'),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Interventions extends MultiWidget
ServicesWidget::class,
BenefitsWidget::class,
ResultsWidget::class,
MonthlyPlanWidget::class,
];

public function shouldPersistMultiWidgetTabsInSession(): bool
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

declare(strict_types=1);

namespace App\Filament\Organizations\Resources\InterventionPlanResource\Widgets;

use App\Filament\Organizations\Resources\InterventionPlanResource;
use App\Models\InterventionPlan;
use App\Models\MonthlyPlan;
use Filament\Tables\Actions\Action;
use Filament\Tables\Actions\CreateAction;
use Filament\Tables\Actions\ViewAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Filament\Widgets\TableWidget as BaseWidget;

class MonthlyPlanWidget extends BaseWidget
{
public ?InterventionPlan $record = null;

public function table(Table $table): Table
{
return $table
->query(
fn () => $this->record->monthlyPlans()
->with(['caseManager', 'beneficiary'])
->withCount(['monthlyPlanServices', 'monthlyPlanInterventions'])
)
->heading(__('intervention_plan.headings.monthly_plans'))
->headerActions([
Action::make('create_modal')
->label(__('intervention_plan.actions.create_monthly_plan'))
->modalHeading(__('intervention_plan.headings.create_monthly_plan_modal'))
->modalDescription(__('intervention_plan.labels.create_monthly_plan_modal'))
->modalSubmitAction(
Action::make('crete_from_last')
->label(__('intervention_plan.actions.create_monthly_plan_from_last'))
->url(InterventionPlanResource::getUrl('create_monthly_plan', [
'parent' => $this->record,
'copyLastPlan' => 'copyLastPlan',
]))
)
->modalCancelAction(
Action::make('create_simple')
->label(__('intervention_plan.actions.create_monthly_plan_simple'))
->outlined()
->url(InterventionPlanResource::getUrl('create_monthly_plan', ['parent' => $this->record]))
)
->visible(fn () => $this->record->monthlyPlans->count()),

CreateAction::make()
->label(__('intervention_plan.actions.create_monthly_plan'))
->url(InterventionPlanResource::getUrl('create_monthly_plan', ['parent' => $this->record]))
->visible(fn () => ! $this->record->monthlyPlans->count()),
])
->columns([
TextColumn::make('interval')
->label(__('intervention_plan.headings.interval')),

TextColumn::make('caseManager.full_name')
->label(__('intervention_plan.headings.case_manager')),

TextColumn::make('monthly_plan_services_count')
->label(__('intervention_plan.headings.services_count')),

TextColumn::make('monthly_plan_interventions_count')
->label(__('intervention_plan.headings.interventions_count')),
])
->actions([
ViewAction::make()
->label(__('general.action.view_details'))
->url(fn (MonthlyPlan $record) => InterventionPlanResource::getUrl('view_monthly_plan', [
'parent' => $this->record,
'record' => $record,
])),
])
->recordUrl(
fn (MonthlyPlan $record) => InterventionPlanResource::getUrl('view_monthly_plan', [
'parent' => $this->record,
'record' => $record,
])
)
->emptyStateHeading(__('intervention_plan.headings.empty_state_monthly_plan_table'))
->emptyStateDescription(__('intervention_plan.labels.empty_state_monthly_plan_table'))
->emptyStateIcon('heroicon-o-document');
}

public function getDisplayName(): string
{
return __('intervention_plan.headings.monthly_plans');
}
}
27 changes: 27 additions & 0 deletions app/Filament/Organizations/Resources/MonthlyPlanResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace App\Filament\Organizations\Resources;

use App\Filament\Organizations\Resources\MonthlyPlanResource\Pages;
use App\Models\MonthlyPlan;
use Filament\Resources\Resource;

class MonthlyPlanResource extends Resource
{
protected static ?string $model = MonthlyPlan::class;

protected static bool $shouldRegisterNavigation = false;

public static string $parentResource = InterventionPlanResource::class;

public static function getPages(): array
{
return [
'index' => Pages\ListMonthlyPlans::route('/'),
'create' => Pages\CreateMonthlyPlan::route('/create'),
'edit' => Pages\EditMonthlyPlanDetails::route('/{record}/edit'),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php

declare(strict_types=1);

namespace App\Filament\Organizations\Resources\MonthlyPlanResource\Pages;

use App\Concerns\HasParentResource;
use App\Concerns\PreventMultipleSubmit;
use App\Concerns\PreventSubmitFormOnEnter;
use App\Filament\Organizations\Resources\InterventionPlanResource;
use App\Filament\Organizations\Resources\MonthlyPlanResource;
use App\Services\Breadcrumb\InterventionPlanBreadcrumb;
use Filament\Facades\Filament;
use Filament\Forms\Components\Wizard\Step;
use Filament\Forms\Get;
use Filament\Forms\Set;
use Filament\Resources\Pages\CreateRecord;
use Filament\Resources\Pages\CreateRecord\Concerns\HasWizard;
use Illuminate\Contracts\Support\Htmlable;

class CreateMonthlyPlan extends CreateRecord
{
use HasWizard;
use HasParentResource;
use PreventMultipleSubmit;
use PreventSubmitFormOnEnter;

protected static string $resource = MonthlyPlanResource::class;

protected array | null $services = null;

public function getBreadcrumbs(): array
{
return InterventionPlanBreadcrumb::make($this->parent)
->getCreateMonthlyPlan($this->getRecord());
}

public function getTitle(): string|Htmlable
{
return __('intervention_plan.headings.create_monthly_plan');
}

protected function getRedirectUrl(): string
{
return InterventionPlanResource::getUrl('view_monthly_plan', [
'parent' => $this->parent,
'record' => $this->getRecord(),
]);
}

protected function afterFill(): void
{
$copyLastPlan = (bool) request('copyLastPlan');

if (! $copyLastPlan) {
$this->services = [
[
'start_date' => now(),
'end_date' => now()->addMonth(),
'institution' => Filament::getTenant()->name,
],
];

$this->form->fill([
'start_date' => now(),
'end_date' => now()->addMonth(),
'case_manager_user_id' => $this->parent
->beneficiary
->managerTeam
->first()
?->user_id,
'specialists' => $this->parent
->beneficiary
->specialistsTeam
->pluck('id'),
'intervention_plan_id' => $this->parent->id,
]);

return;
}

$lastPlan = $this->parent
->monthlyPlans()
->with(['monthlyPlanServices.monthlyPlanInterventions'])
->orderByDesc('id')
->first();
$this->services = $lastPlan?->monthlyPlanServices
->toArray();

$this->form->fill($lastPlan
?->toArray());
}

public function getSteps(): array
{
return [
Step::make('details')
->label(__('intervention_plan.headings.monthly_plan_details'))
->schema(EditMonthlyPlanDetails::getSchema($this->parent->beneficiary)),

Step::make('services_and_interventions')
->label(__('intervention_plan.headings.services_and_interventions'))
->afterStateHydrated(function (Set $set, Get $get) {
if (! $this->services) {
return;
}

$set('monthlyPlanServices', $this->services);
foreach ($get('monthlyPlanServices') as $key => $service) {
$interventionPath = \sprintf('monthlyPlanServices.%s.monthlyPlanInterventions', $key);
$interventions = $this->services[$key]['monthly_plan_interventions'] ?? [[]];

$set($interventionPath, $interventions);
}
})
->schema(EditMonthlyPlanServicesAndInterventions::getSchema()),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

declare(strict_types=1);

namespace App\Filament\Organizations\Resources\MonthlyPlanResource\Pages;

use App\Concerns\HasParentResource;
use App\Filament\Organizations\Resources\InterventionPlanResource;
use App\Filament\Organizations\Resources\MonthlyPlanResource;
use App\Forms\Components\DatePicker;
use App\Forms\Components\Select;
use App\Models\Beneficiary;
use App\Services\Breadcrumb\InterventionPlanBreadcrumb;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Support\Str;

class EditMonthlyPlanDetails extends EditRecord
{
use HasParentResource;

protected static string $resource = MonthlyPlanResource::class;

public function getBreadcrumbs(): array
{
return InterventionPlanBreadcrumb::make($this->parent)
->getViewMonthlyPlan($this->getRecord());
}

public function getTitle(): string
{
return __('intervention_plan.headings.edit_monthly_plan_title');
}

protected function getRedirectUrl(): ?string
{
return InterventionPlanResource::getUrl('view_monthly_plan', [
'parent' => $this->parent,
'record' => $this->getRecord(),
'tab' => \sprintf('-%s-tab', $this->getTabSlug()),
]);
}

protected function getTabSlug(): string
{
return Str::slug(__('intervention_plan.headings.monthly_plan_details'));
}

public function form(Form $form): Form
{
return $form->schema(self::getSchema($this->parent->beneficiary));
}

public static function getSchema(?Beneficiary $beneficiary = null): array
{
return [
Section::make()
->maxWidth('3xl')
->columns()
->schema([
DatePicker::make('start_date')
->label(__('intervention_plan.labels.monthly_plan_start_date'))
->displayFormat('d-m-Y')
->required(),

DatePicker::make('end_date')
->label(__('intervention_plan.labels.monthly_plan_end_date'))
->displayFormat('d-m-Y')
->required(),

Select::make('case_manager_user_id')
->label(__('intervention_plan.labels.case_manager'))
->placeholder(__('intervention_plan.placeholders.specialist'))
->options(
fn () => $beneficiary
->specialistsMembers
->pluck('full_name', 'id')
)
->required(),

Select::make('specialists')
->label(__('intervention_plan.labels.specialists'))
->placeholder(__('intervention_plan.placeholders.specialists'))
->multiple()
->options(
fn () => $beneficiary
->specialistsTeam
->pluck('name_role', 'id')
)
->required(),
]),

Hidden::make('intervention_plan_id'),
];
}
}
Loading

0 comments on commit 7b7062d

Please sign in to comment.