-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #430 from code4romania/425-ngo-admin-specialist-ca…
…zuri-plan-de-interventie-implement-new-sectiontab-called-planuri-lunare Monthly plan
- Loading branch information
Showing
23 changed files
with
1,403 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
app/Filament/Organizations/Resources/InterventionPlanResource/Widgets/MonthlyPlanWidget.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
app/Filament/Organizations/Resources/MonthlyPlanResource.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
]; | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
app/Filament/Organizations/Resources/MonthlyPlanResource/Pages/CreateMonthlyPlan.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()), | ||
]; | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
app/Filament/Organizations/Resources/MonthlyPlanResource/Pages/EditMonthlyPlanDetails.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
]; | ||
} | ||
} |
Oops, something went wrong.