132 lines
5.1 KiB
PHP
132 lines
5.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Resources\Employees\RelationManagers;
|
|
|
|
use App\Enums\ApprovalStatus;
|
|
use App\Enums\VacationType;
|
|
use App\Filament\Support\HrForm;
|
|
use App\Models\Vacation;
|
|
use App\Services\Vacation\VacationService;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\CreateAction;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Actions\DeleteBulkAction;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Actions\ForceDeleteBulkAction;
|
|
use Filament\Actions\RestoreBulkAction;
|
|
use Filament\Forms\Components\DatePicker;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Resources\RelationManagers\RelationManager;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
use Filament\Tables\Filters\TrashedFilter;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class VacationsRelationManager extends RelationManager
|
|
{
|
|
protected static string $relationship = 'vacations';
|
|
|
|
public static function getTitle(\Illuminate\Database\Eloquent\Model $ownerRecord, string $pageClass): string
|
|
{
|
|
return __("hr.relation_managers.vacations");
|
|
}
|
|
|
|
public function form(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->components([
|
|
Select::make('type')
|
|
->options(VacationType::class)
|
|
->required()
|
|
->native(false),
|
|
HrForm::leaveDatePicker('start_date', __(hr.fields.start_date)),
|
|
HrForm::leaveDatePicker('end_date', __(hr.fields.end_date)),
|
|
DatePicker::make('return_date')
|
|
->label(__('hr.fields.return_date')),
|
|
HrForm::leaveDaysDisplay(),
|
|
Textarea::make('reason')
|
|
->rows(3)
|
|
->columnSpanFull(),
|
|
HrForm::fileUpload('attachment_path')
|
|
->label(__('hr.fields.attachment'))
|
|
->acceptedFileTypes(['application/pdf', 'image/*'])
|
|
->maxSize(10240),
|
|
]);
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->recordTitleAttribute('start_date')
|
|
->columns([
|
|
TextColumn::make('type')
|
|
->badge()
|
|
->color(fn (VacationType $state): string => $state->color())
|
|
->formatStateUsing(fn (VacationType $state): string => $state->label())
|
|
->sortable(),
|
|
TextColumn::make('start_date')
|
|
->date()
|
|
->sortable(),
|
|
TextColumn::make('end_date')
|
|
->date()
|
|
->sortable(),
|
|
TextColumn::make('days')
|
|
->numeric()
|
|
->sortable(),
|
|
TextColumn::make('status')
|
|
->badge()
|
|
->color(fn (ApprovalStatus $state): string => $state->color())
|
|
->formatStateUsing(fn (ApprovalStatus $state): string => $state->label())
|
|
->sortable(),
|
|
TextColumn::make('approver.name')
|
|
->label(__('hr.fields.approved_by'))
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
])
|
|
->filters([
|
|
SelectFilter::make('status')
|
|
->options(ApprovalStatus::class),
|
|
SelectFilter::make('type')
|
|
->options(VacationType::class),
|
|
TrashedFilter::make(),
|
|
])
|
|
->headerActions([
|
|
CreateAction::make(),
|
|
])
|
|
->recordActions([
|
|
Action::make('approve')
|
|
->label(__('hr.actions.approve'))
|
|
->icon('heroicon-o-check-badge')
|
|
->color('success')
|
|
->requiresConfirmation()
|
|
->visible(fn (Vacation $record): bool => $record->status === ApprovalStatus::Pending)
|
|
->action(function (Vacation $record, VacationService $vacationService): void {
|
|
$vacationService->approve($record, Auth::user());
|
|
}),
|
|
Action::make('reject')
|
|
->label(__('hr.actions.reject'))
|
|
->icon('heroicon-o-x-mark')
|
|
->color('danger')
|
|
->requiresConfirmation()
|
|
->visible(fn (Vacation $record): bool => $record->status === ApprovalStatus::Pending)
|
|
->action(function (Vacation $record, VacationService $vacationService): void {
|
|
$vacationService->reject($record, Auth::user());
|
|
}),
|
|
EditAction::make(),
|
|
DeleteAction::make(),
|
|
])
|
|
->toolbarActions([
|
|
BulkActionGroup::make([
|
|
DeleteBulkAction::make(),
|
|
ForceDeleteBulkAction::make(),
|
|
RestoreBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
}
|