Skip to content

Commit

Permalink
Merge branch 'main' into 420-implement-back-feature
Browse files Browse the repository at this point in the history
  • Loading branch information
alexPopaCode4 authored Dec 20, 2024
2 parents 3e95da2 + 7b7062d commit 180ded0
Show file tree
Hide file tree
Showing 26 changed files with 1,413 additions and 13 deletions.
3 changes: 2 additions & 1 deletion app/Enums/CaseStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ enum CaseStatus: string implements HasLabel, HasColor

case ACTIVE = 'active';
case MONITORED = 'monitored';
case INACTIVE = 'inactive';
case CLOSED = 'closed';
case ARCHIVED = 'archived';

Expand All @@ -30,7 +31,7 @@ public function getColor(): string|array|null
return match ($this) {
self::ACTIVE => Color::Green,
self::MONITORED => Color::Yellow,
self::CLOSED => Color::Gray,
self::CLOSED, self::INACTIVE => Color::Gray,
self::ARCHIVED => Color::Purple,
default => Color::Red,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Enums\CaseStatus;
use App\Enums\Ternary;
use App\Filament\Organizations\Resources\BeneficiaryResource;
use App\Filament\Organizations\Resources\BeneficiaryResource\Actions\ChangeStatus;
use App\Filament\Organizations\Resources\BeneficiaryResource\Actions\ViewDetailsAction;
use App\Filament\Organizations\Resources\BeneficiaryResource\Widgets\CaseTeamListWidget;
use App\Filament\Organizations\Resources\BeneficiaryResource\Widgets\CloseFileWidget;
Expand Down Expand Up @@ -87,10 +88,11 @@ protected function getHeaderActions(): array
ActionGroup::make([])
->dropdown(false)
->actions([
BeneficiaryResource\Actions\ChangeStatus::make('active'),
BeneficiaryResource\Actions\ChangeStatus::make('monitored'),
BeneficiaryResource\Actions\ChangeStatus::make('closed'),
BeneficiaryResource\Actions\ChangeStatus::make('archived'),
ChangeStatus::make('active'),
ChangeStatus::make('monitored'),
ChangeStatus::make('inactive'),
ChangeStatus::make('closed'),
ChangeStatus::make('archived'),
]),

ActionGroup::make([])
Expand Down
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()),
];
}
}
Loading

0 comments on commit 180ded0

Please sign in to comment.