Skip to content

Commit

Permalink
Service status and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
alexPopaCode4 committed Dec 20, 2024
1 parent 5d86d10 commit dda014f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 51 deletions.
37 changes: 0 additions & 37 deletions app/Filament/Organizations/Resources/MonthlyPlanResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

use App\Filament\Organizations\Resources\MonthlyPlanResource\Pages;
use App\Models\MonthlyPlan;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;

class MonthlyPlanResource extends Resource
{
Expand All @@ -19,40 +16,6 @@ class MonthlyPlanResource extends Resource

public static string $parentResource = InterventionPlanResource::class;

public static function form(Form $form): Form
{
return $form
->schema([
//
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
//
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Forms\Components\Select;
use App\Forms\Components\TableRepeater;
use App\Models\Service;
use App\Models\ServiceIntervention;
use App\Services\Breadcrumb\InterventionPlanBreadcrumb;
use Filament\Facades\Filament;
use Filament\Forms\Components\Actions\Action;
Expand Down Expand Up @@ -92,7 +93,18 @@ public static function getSchema(): array
Select::make('service_id')
->label(__('intervention_plan.labels.service_type'))
->placeholder(__('intervention_plan.placeholders.select_service'))
->relationship('service', 'name')
->options(function (?int $state) {
$services = Service::query()
->active()
->get()
->pluck('name', 'id');

if ($state && ! isset($services[$state])) {
$services[$state] = Service::find($state)->name;
}

return $services;
})
->required()
->live(),

Expand Down Expand Up @@ -142,12 +154,22 @@ public static function getSchema(): array
->label(__('intervention_plan.headings.interventions'))
->placeholder(__('intervention_plan.placeholders.select_intervention'))
->options(
fn (Get $get) => $get('../../service_id') ?
Service::find((int) $get('../../service_id'))
->load('serviceInterventions')
->serviceInterventions
->pluck('name', 'id') :
[]
function (Get $get, ?int $state) {
if (! $get('../../service_id')) {
return [];
}

$interventions = Service::find((int) $get('../../service_id'))
->load('activeServiceInterventions')
->activeServiceInterventions
->pluck('name', 'id');

if ($state && ! isset($interventions[$state])) {
$interventions[$state] = ServiceIntervention::find($state)->name;
}

return $interventions;
}
),

TextInput::make('objections')
Expand Down
12 changes: 5 additions & 7 deletions app/Models/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\Relations\HasOne;

class Service extends Model
{
Expand All @@ -27,16 +25,16 @@ class Service extends Model
'counseling_sheet' => CounselingSheet::class,
];

// public function counselingSheet(): HasOne
// {
//
// }

public function serviceInterventions(): HasMany
{
return $this->hasMany(ServiceIntervention::class);
}

public function activeServiceInterventions(): HasMany
{
return $this->serviceInterventions()->active();
}

public function interventions(): HasMany
{
return $this->hasMany(Intervention::class);
Expand Down

0 comments on commit dda014f

Please sign in to comment.