base commit
This commit is contained in:
11
app/Filament/Resources/Vacations/Pages/CreateVacation.php
Normal file
11
app/Filament/Resources/Vacations/Pages/CreateVacation.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Vacations\Pages;
|
||||
|
||||
use App\Filament\Resources\Vacations\VacationResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateVacation extends CreateRecord
|
||||
{
|
||||
protected static string $resource = VacationResource::class;
|
||||
}
|
||||
25
app/Filament/Resources/Vacations/Pages/EditVacation.php
Normal file
25
app/Filament/Resources/Vacations/Pages/EditVacation.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Vacations\Pages;
|
||||
|
||||
use App\Filament\Resources\Vacations\VacationResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\ForceDeleteAction;
|
||||
use Filament\Actions\RestoreAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditVacation extends EditRecord
|
||||
{
|
||||
protected static string $resource = VacationResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
ViewAction::make(),
|
||||
DeleteAction::make(),
|
||||
ForceDeleteAction::make(),
|
||||
RestoreAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
24
app/Filament/Resources/Vacations/Pages/ListVacations.php
Normal file
24
app/Filament/Resources/Vacations/Pages/ListVacations.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Vacations\Pages;
|
||||
|
||||
use App\Exports\VacationsExport;
|
||||
use App\Filament\Resources\Vacations\VacationResource;
|
||||
use App\Filament\Support\ExportExcelAction;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListVacations extends ListRecords
|
||||
{
|
||||
protected static string $resource = VacationResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
ExportExcelAction::make('export', VacationsExport::class, 'vacations.xlsx'),
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/Vacations/Pages/ViewVacation.php
Normal file
19
app/Filament/Resources/Vacations/Pages/ViewVacation.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Vacations\Pages;
|
||||
|
||||
use App\Filament\Resources\Vacations\VacationResource;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewVacation extends ViewRecord
|
||||
{
|
||||
protected static string $resource = VacationResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
EditAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
37
app/Filament/Resources/Vacations/Schemas/VacationForm.php
Normal file
37
app/Filament/Resources/Vacations/Schemas/VacationForm.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Vacations\Schemas;
|
||||
|
||||
use App\Enums\VacationType;
|
||||
use App\Filament\Support\HrForm;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class VacationForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
HrForm::employeeSelect(),
|
||||
Select::make('type')
|
||||
->options(VacationType::class)
|
||||
->required()
|
||||
->native(false),
|
||||
HrForm::leaveDatePicker('start_date', 'Start Date'),
|
||||
HrForm::leaveDatePicker('end_date', 'End Date'),
|
||||
DatePicker::make('return_date')
|
||||
->label('Return Date'),
|
||||
HrForm::leaveDaysDisplay(),
|
||||
Textarea::make('reason')
|
||||
->rows(3)
|
||||
->columnSpanFull(),
|
||||
HrForm::fileUpload('attachment_path')
|
||||
->label('Attachment')
|
||||
->acceptedFileTypes(['application/pdf', 'image/*'])
|
||||
->maxSize(10240),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Vacations\Schemas;
|
||||
|
||||
use App\Models\Vacation;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class VacationInfolist
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextEntry::make('employee.id')
|
||||
->label('Employee'),
|
||||
TextEntry::make('type')
|
||||
->badge(),
|
||||
TextEntry::make('start_date')
|
||||
->date(),
|
||||
TextEntry::make('end_date')
|
||||
->date(),
|
||||
TextEntry::make('return_date')
|
||||
->date()
|
||||
->placeholder('-'),
|
||||
TextEntry::make('days')
|
||||
->numeric(),
|
||||
TextEntry::make('status')
|
||||
->badge(),
|
||||
TextEntry::make('reason')
|
||||
->placeholder('-')
|
||||
->columnSpanFull(),
|
||||
TextEntry::make('attachment_path')
|
||||
->placeholder('-'),
|
||||
TextEntry::make('approved_by')
|
||||
->numeric()
|
||||
->placeholder('-'),
|
||||
TextEntry::make('approved_at')
|
||||
->dateTime()
|
||||
->placeholder('-'),
|
||||
TextEntry::make('created_at')
|
||||
->dateTime()
|
||||
->placeholder('-'),
|
||||
TextEntry::make('updated_at')
|
||||
->dateTime()
|
||||
->placeholder('-'),
|
||||
TextEntry::make('deleted_at')
|
||||
->dateTime()
|
||||
->visible(fn (Vacation $record): bool => $record->trashed()),
|
||||
]);
|
||||
}
|
||||
}
|
||||
134
app/Filament/Resources/Vacations/Tables/VacationsTable.php
Normal file
134
app/Filament/Resources/Vacations/Tables/VacationsTable.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Vacations\Tables;
|
||||
|
||||
use App\Enums\ApprovalStatus;
|
||||
use App\Enums\VacationType;
|
||||
use App\Models\Vacation;
|
||||
use App\Services\Vacation\VacationService;
|
||||
use Filament\Actions\Action;
|
||||
use App\Filament\Support\ExportExcelAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ForceDeleteBulkAction;
|
||||
use Filament\Actions\RestoreBulkAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Filters\TrashedFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class VacationsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('employee.full_name')
|
||||
->label('Employee')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('type')
|
||||
->badge()
|
||||
->color(fn (VacationType $state): string => $state->color())
|
||||
->formatStateUsing(fn (VacationType $state): string => $state->label())
|
||||
->searchable()
|
||||
->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())
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('approver.name')
|
||||
->label('Approved By')
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('approved_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('deleted_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('status')
|
||||
->options(ApprovalStatus::class),
|
||||
SelectFilter::make('type')
|
||||
->options(VacationType::class),
|
||||
Filter::make('date_range')
|
||||
->label('Date Range')
|
||||
->schema([
|
||||
DatePicker::make('start_from')
|
||||
->label('Start from'),
|
||||
DatePicker::make('start_until')
|
||||
->label('Start until'),
|
||||
])
|
||||
->query(function (Builder $query, array $data): Builder {
|
||||
return $query
|
||||
->when(
|
||||
$data['start_from'],
|
||||
fn (Builder $query, $date): Builder => $query->whereDate('start_date', '>=', $date),
|
||||
)
|
||||
->when(
|
||||
$data['start_until'],
|
||||
fn (Builder $query, $date): Builder => $query->whereDate('start_date', '<=', $date),
|
||||
);
|
||||
}),
|
||||
TrashedFilter::make(),
|
||||
])
|
||||
->recordActions([
|
||||
Action::make('approve')
|
||||
->label('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('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());
|
||||
}),
|
||||
ViewAction::make(),
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
ExportExcelAction::bulk('exportSelected', \App\Exports\VacationsExport::class, 'vacations.xlsx'),
|
||||
DeleteBulkAction::make(),
|
||||
ForceDeleteBulkAction::make(),
|
||||
RestoreBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
77
app/Filament/Resources/Vacations/VacationResource.php
Normal file
77
app/Filament/Resources/Vacations/VacationResource.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Vacations;
|
||||
|
||||
use App\Filament\Resources\Vacations\Pages\CreateVacation;
|
||||
use App\Filament\Resources\Vacations\Pages\EditVacation;
|
||||
use App\Filament\Resources\Vacations\Pages\ListVacations;
|
||||
use App\Filament\Resources\Vacations\Pages\ViewVacation;
|
||||
use App\Filament\Resources\Vacations\Schemas\VacationForm;
|
||||
use App\Filament\Resources\Vacations\Schemas\VacationInfolist;
|
||||
use App\Filament\Resources\Vacations\Tables\VacationsTable;
|
||||
use App\Models\Vacation;
|
||||
use BackedEnum;
|
||||
use UnitEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class VacationResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Vacation::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedSun;
|
||||
|
||||
protected static string | UnitEnum | null $navigationGroup = 'Leave Management';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'id';
|
||||
|
||||
protected static bool $isGloballySearchable = false;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return VacationForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function infolist(Schema $schema): Schema
|
||||
{
|
||||
return VacationInfolist::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return VacationsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListVacations::route('/'),
|
||||
'create' => CreateVacation::route('/create'),
|
||||
'view' => ViewVacation::route('/{record}'),
|
||||
'edit' => EditVacation::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getRecordRouteBindingEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getRecordRouteBindingEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user