base commit
This commit is contained in:
120
app/Filament/Resources/Employees/EmployeeResource.php
Normal file
120
app/Filament/Resources/Employees/EmployeeResource.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Employees;
|
||||
|
||||
use App\Filament\Resources\Employees\Pages\CreateEmployee;
|
||||
use App\Filament\Resources\Employees\Pages\EditEmployee;
|
||||
use App\Filament\Resources\Employees\Pages\ListEmployees;
|
||||
use App\Filament\Resources\Employees\Pages\ViewEmployee;
|
||||
use App\Filament\Resources\Employees\RelationManagers\BonusesRelationManager;
|
||||
use App\Filament\Resources\Employees\RelationManagers\DisciplinaryReportsRelationManager;
|
||||
use App\Filament\Resources\Employees\RelationManagers\DocumentsRelationManager;
|
||||
use App\Filament\Resources\Employees\RelationManagers\ExplanationsRelationManager;
|
||||
use App\Filament\Resources\Employees\RelationManagers\GiftsRelationManager;
|
||||
use App\Filament\Resources\Employees\RelationManagers\SickLeavesRelationManager;
|
||||
use App\Filament\Resources\Employees\RelationManagers\UnpaidLeavesRelationManager;
|
||||
use App\Filament\Resources\Employees\RelationManagers\VacationsRelationManager;
|
||||
use App\Filament\Resources\Employees\Schemas\EmployeeForm;
|
||||
use App\Filament\Resources\Employees\Schemas\EmployeeInfolist;
|
||||
use App\Filament\Resources\Employees\Tables\EmployeesTable;
|
||||
use App\Models\Employee;
|
||||
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\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class EmployeeResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Employee::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedUsers;
|
||||
|
||||
protected static string | UnitEnum | null $navigationGroup = 'Employees';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'full_name';
|
||||
|
||||
protected static bool $isGloballySearchable = true;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return EmployeeForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function infolist(Schema $schema): Schema
|
||||
{
|
||||
return EmployeeInfolist::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return EmployeesTable::configure($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public static function getGloballySearchableAttributes(): array
|
||||
{
|
||||
return [
|
||||
'employee_number',
|
||||
'full_name',
|
||||
'phone',
|
||||
'department.name',
|
||||
'position.name',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function getGlobalSearchResultDetails(Model $record): array
|
||||
{
|
||||
/** @var Employee $record */
|
||||
return [
|
||||
'Employee #' => $record->employee_number,
|
||||
'Department' => $record->department?->name ?? '—',
|
||||
'Position' => $record->position?->name ?? '—',
|
||||
];
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
VacationsRelationManager::class,
|
||||
SickLeavesRelationManager::class,
|
||||
UnpaidLeavesRelationManager::class,
|
||||
DisciplinaryReportsRelationManager::class,
|
||||
ExplanationsRelationManager::class,
|
||||
BonusesRelationManager::class,
|
||||
GiftsRelationManager::class,
|
||||
DocumentsRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListEmployees::route('/'),
|
||||
'create' => CreateEmployee::route('/create'),
|
||||
'view' => ViewEmployee::route('/{record}'),
|
||||
'edit' => EditEmployee::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getRecordRouteBindingEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getRecordRouteBindingEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
11
app/Filament/Resources/Employees/Pages/CreateEmployee.php
Normal file
11
app/Filament/Resources/Employees/Pages/CreateEmployee.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Employees\Pages;
|
||||
|
||||
use App\Filament\Resources\Employees\EmployeeResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateEmployee extends CreateRecord
|
||||
{
|
||||
protected static string $resource = EmployeeResource::class;
|
||||
}
|
||||
25
app/Filament/Resources/Employees/Pages/EditEmployee.php
Normal file
25
app/Filament/Resources/Employees/Pages/EditEmployee.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Employees\Pages;
|
||||
|
||||
use App\Filament\Resources\Employees\EmployeeResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\ForceDeleteAction;
|
||||
use Filament\Actions\RestoreAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditEmployee extends EditRecord
|
||||
{
|
||||
protected static string $resource = EmployeeResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
ViewAction::make(),
|
||||
DeleteAction::make(),
|
||||
ForceDeleteAction::make(),
|
||||
RestoreAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
26
app/Filament/Resources/Employees/Pages/ListEmployees.php
Normal file
26
app/Filament/Resources/Employees/Pages/ListEmployees.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Employees\Pages;
|
||||
|
||||
use App\Exports\EmployeesExport;
|
||||
use App\Filament\Resources\Employees\EmployeeResource;
|
||||
use App\Filament\Support\ExportExcelAction;
|
||||
use App\Filament\Support\ExportPdfAction;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListEmployees extends ListRecords
|
||||
{
|
||||
protected static string $resource = EmployeeResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
ExportExcelAction::make('export', EmployeesExport::class, 'employees.xlsx'),
|
||||
ExportPdfAction::employeeList(),
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
47
app/Filament/Resources/Employees/Pages/ViewEmployee.php
Normal file
47
app/Filament/Resources/Employees/Pages/ViewEmployee.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Employees\Pages;
|
||||
|
||||
use App\Filament\Resources\Employees\EmployeeResource;
|
||||
use App\Filament\Resources\Employees\Widgets\EmployeeStatsWidget;
|
||||
use App\Filament\Support\ExportPdfAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewEmployee extends ViewRecord
|
||||
{
|
||||
protected static string $resource = EmployeeResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
ExportPdfAction::employeeProfile(),
|
||||
ExportPdfAction::employeeLeaveSummary(),
|
||||
EditAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string>
|
||||
*/
|
||||
protected function getHeaderWidgets(): array
|
||||
{
|
||||
return [
|
||||
EmployeeStatsWidget::class,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int | array<string, ?int>
|
||||
*/
|
||||
public function getHeaderWidgetsColumns(): int | array
|
||||
{
|
||||
return [
|
||||
'default' => 1,
|
||||
'sm' => 2,
|
||||
'xl' => 4,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Employees\RelationManagers;
|
||||
|
||||
use App\Enums\BonusType;
|
||||
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\TextInput;
|
||||
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;
|
||||
|
||||
class BonusesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'bonuses';
|
||||
|
||||
protected static ?string $title = 'Bonuses';
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
DatePicker::make('bonus_date')
|
||||
->required()
|
||||
->default(now()),
|
||||
Select::make('bonus_type')
|
||||
->options(BonusType::class)
|
||||
->required()
|
||||
->native(false),
|
||||
TextInput::make('amount')
|
||||
->required()
|
||||
->numeric()
|
||||
->prefix('TMT')
|
||||
->minValue(0)
|
||||
->step(0.01),
|
||||
Textarea::make('reason')
|
||||
->rows(3)
|
||||
->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('bonus_date')
|
||||
->columns([
|
||||
TextColumn::make('bonus_date')
|
||||
->date()
|
||||
->sortable(),
|
||||
TextColumn::make('bonus_type')
|
||||
->label('Type')
|
||||
->badge()
|
||||
->color(fn (BonusType $state): string => $state->color())
|
||||
->formatStateUsing(fn (BonusType $state): string => $state->label())
|
||||
->sortable(),
|
||||
TextColumn::make('amount')
|
||||
->money('TMT')
|
||||
->sortable(),
|
||||
TextColumn::make('reason')
|
||||
->limit(40)
|
||||
->toggleable(),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('bonus_type')
|
||||
->label('Type')
|
||||
->options(BonusType::class),
|
||||
TrashedFilter::make(),
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
ForceDeleteBulkAction::make(),
|
||||
RestoreBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Employees\RelationManagers;
|
||||
|
||||
use App\Enums\DisciplinarySeverity;
|
||||
use App\Filament\Support\HrForm;
|
||||
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\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Filters\TrashedFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class DisciplinaryReportsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'disciplinaryReports';
|
||||
|
||||
protected static ?string $title = 'Disciplinary Reports';
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
DatePicker::make('report_date')
|
||||
->required()
|
||||
->default(now()),
|
||||
TextInput::make('title')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Textarea::make('description')
|
||||
->required()
|
||||
->rows(4)
|
||||
->columnSpanFull(),
|
||||
Select::make('severity')
|
||||
->options(DisciplinarySeverity::class)
|
||||
->required()
|
||||
->native(false),
|
||||
HrForm::fileUpload('attachment_path')
|
||||
->label('Attachment')
|
||||
->acceptedFileTypes(['application/pdf', 'image/*'])
|
||||
->maxSize(10240),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('title')
|
||||
->columns([
|
||||
TextColumn::make('report_date')
|
||||
->date()
|
||||
->sortable(),
|
||||
TextColumn::make('title')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('severity')
|
||||
->badge()
|
||||
->color(fn (DisciplinarySeverity $state): string => $state->color())
|
||||
->formatStateUsing(fn (DisciplinarySeverity $state): string => $state->label())
|
||||
->sortable(),
|
||||
IconColumn::make('attachment_path')
|
||||
->label('Attachment')
|
||||
->boolean()
|
||||
->trueIcon('heroicon-o-paper-clip')
|
||||
->falseIcon('heroicon-o-minus'),
|
||||
TextColumn::make('creator.name')
|
||||
->label('Created By')
|
||||
->toggleable(),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('severity')
|
||||
->options(DisciplinarySeverity::class),
|
||||
TrashedFilter::make(),
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
ForceDeleteBulkAction::make(),
|
||||
RestoreBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Employees\RelationManagers;
|
||||
|
||||
use App\Enums\DocumentType;
|
||||
use App\Filament\Support\HrForm;
|
||||
use App\Models\EmployeeDocument;
|
||||
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\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
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\Storage;
|
||||
|
||||
class DocumentsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'documents';
|
||||
|
||||
protected static ?string $title = 'Employee Documents';
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Select::make('document_type')
|
||||
->options(DocumentType::class)
|
||||
->required()
|
||||
->native(false),
|
||||
TextInput::make('title')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
HrForm::fileUpload('file_path')
|
||||
->label('Document')
|
||||
->required()
|
||||
->acceptedFileTypes(['application/pdf', 'image/*', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'])
|
||||
->maxSize(15360),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('title')
|
||||
->columns([
|
||||
TextColumn::make('document_type')
|
||||
->label('Type')
|
||||
->badge()
|
||||
->color(fn (DocumentType $state): string => $state->color())
|
||||
->formatStateUsing(fn (DocumentType $state): string => $state->label())
|
||||
->sortable(),
|
||||
TextColumn::make('title')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('uploaded_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('document_type')
|
||||
->label('Type')
|
||||
->options(DocumentType::class),
|
||||
TrashedFilter::make(),
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make(),
|
||||
])
|
||||
->recordActions([
|
||||
Action::make('download')
|
||||
->label('Download')
|
||||
->icon('heroicon-o-arrow-down-tray')
|
||||
->visible(fn (EmployeeDocument $record): bool => filled($record->file_path))
|
||||
->action(function (EmployeeDocument $record) {
|
||||
$disk = Storage::disk(config('hr.file_uploads.disk'));
|
||||
|
||||
return response()->download(
|
||||
$disk->path($record->file_path),
|
||||
basename($record->file_path),
|
||||
);
|
||||
}),
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
ForceDeleteBulkAction::make(),
|
||||
RestoreBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Employees\RelationManagers;
|
||||
|
||||
use App\Filament\Support\HrForm;
|
||||
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\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\TrashedFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class ExplanationsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'explanations';
|
||||
|
||||
protected static ?string $title = 'Explanations';
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
DatePicker::make('explanation_date')
|
||||
->required()
|
||||
->default(now()),
|
||||
TextInput::make('reason')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Textarea::make('description')
|
||||
->required()
|
||||
->rows(4)
|
||||
->columnSpanFull(),
|
||||
HrForm::fileUpload('attachment_path')
|
||||
->label('Attachment')
|
||||
->acceptedFileTypes(['application/pdf', 'image/*'])
|
||||
->maxSize(10240),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('reason')
|
||||
->columns([
|
||||
TextColumn::make('explanation_date')
|
||||
->date()
|
||||
->sortable(),
|
||||
TextColumn::make('reason')
|
||||
->searchable()
|
||||
->limit(40),
|
||||
TextColumn::make('description')
|
||||
->limit(50)
|
||||
->toggleable(),
|
||||
IconColumn::make('attachment_path')
|
||||
->label('Attachment')
|
||||
->boolean()
|
||||
->trueIcon('heroicon-o-paper-clip')
|
||||
->falseIcon('heroicon-o-minus'),
|
||||
])
|
||||
->filters([
|
||||
TrashedFilter::make(),
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
ForceDeleteBulkAction::make(),
|
||||
RestoreBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Employees\RelationManagers;
|
||||
|
||||
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\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\TrashedFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class GiftsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'gifts';
|
||||
|
||||
protected static ?string $title = 'Gifts';
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
DatePicker::make('gift_date')
|
||||
->required()
|
||||
->default(now()),
|
||||
TextInput::make('gift_name')
|
||||
->label('Gift Name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
TextInput::make('value')
|
||||
->required()
|
||||
->numeric()
|
||||
->prefix('TMT')
|
||||
->minValue(0)
|
||||
->step(0.01)
|
||||
->default(0),
|
||||
Textarea::make('reason')
|
||||
->rows(3)
|
||||
->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('gift_name')
|
||||
->columns([
|
||||
TextColumn::make('gift_date')
|
||||
->date()
|
||||
->sortable(),
|
||||
TextColumn::make('gift_name')
|
||||
->label('Gift')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('value')
|
||||
->money('TMT')
|
||||
->sortable(),
|
||||
TextColumn::make('reason')
|
||||
->limit(40)
|
||||
->toggleable(),
|
||||
])
|
||||
->filters([
|
||||
TrashedFilter::make(),
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
ForceDeleteBulkAction::make(),
|
||||
RestoreBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Employees\RelationManagers;
|
||||
|
||||
use App\Filament\Support\HrForm;
|
||||
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\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\TrashedFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class SickLeavesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'sickLeaves';
|
||||
|
||||
protected static ?string $title = 'Sick Leaves';
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
HrForm::leaveDatePicker('start_date', 'Start Date'),
|
||||
HrForm::leaveDatePicker('end_date', 'End Date'),
|
||||
HrForm::leaveDaysDisplay(),
|
||||
TextInput::make('medical_institution')
|
||||
->maxLength(255),
|
||||
Textarea::make('reason')
|
||||
->rows(3)
|
||||
->columnSpanFull(),
|
||||
HrForm::fileUpload('document_path')
|
||||
->label('Medical Document')
|
||||
->acceptedFileTypes(['application/pdf', 'image/*'])
|
||||
->maxSize(10240),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('start_date')
|
||||
->columns([
|
||||
TextColumn::make('start_date')
|
||||
->date()
|
||||
->sortable(),
|
||||
TextColumn::make('end_date')
|
||||
->date()
|
||||
->sortable(),
|
||||
TextColumn::make('days')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
TextColumn::make('medical_institution')
|
||||
->searchable()
|
||||
->toggleable(),
|
||||
IconColumn::make('document_path')
|
||||
->label('Document')
|
||||
->boolean()
|
||||
->trueIcon('heroicon-o-document-check')
|
||||
->falseIcon('heroicon-o-document'),
|
||||
])
|
||||
->filters([
|
||||
TrashedFilter::make(),
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
ForceDeleteBulkAction::make(),
|
||||
RestoreBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Employees\RelationManagers;
|
||||
|
||||
use App\Enums\ApprovalStatus;
|
||||
use App\Filament\Support\HrForm;
|
||||
use App\Models\UnpaidLeave;
|
||||
use App\Services\Leave\UnpaidLeaveService;
|
||||
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\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 UnpaidLeavesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'unpaidLeaves';
|
||||
|
||||
protected static ?string $title = 'Unpaid Leaves';
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
HrForm::leaveDatePicker('start_date', 'Start Date'),
|
||||
HrForm::leaveDatePicker('end_date', 'End Date'),
|
||||
HrForm::leaveDaysDisplay(),
|
||||
Textarea::make('reason')
|
||||
->rows(3)
|
||||
->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('start_date')
|
||||
->columns([
|
||||
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('Approved By')
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('status')
|
||||
->options(ApprovalStatus::class),
|
||||
TrashedFilter::make(),
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make(),
|
||||
])
|
||||
->recordActions([
|
||||
Action::make('approve')
|
||||
->label('Approve')
|
||||
->icon('heroicon-o-check-badge')
|
||||
->color('success')
|
||||
->requiresConfirmation()
|
||||
->visible(fn (UnpaidLeave $record): bool => $record->status === ApprovalStatus::Pending)
|
||||
->action(function (UnpaidLeave $record, UnpaidLeaveService $unpaidLeaveService): void {
|
||||
$unpaidLeaveService->approve($record, Auth::user());
|
||||
}),
|
||||
Action::make('reject')
|
||||
->label('Reject')
|
||||
->icon('heroicon-o-x-mark')
|
||||
->color('danger')
|
||||
->requiresConfirmation()
|
||||
->visible(fn (UnpaidLeave $record): bool => $record->status === ApprovalStatus::Pending)
|
||||
->action(function (UnpaidLeave $record, UnpaidLeaveService $unpaidLeaveService): void {
|
||||
$unpaidLeaveService->reject($record, Auth::user());
|
||||
}),
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
ForceDeleteBulkAction::make(),
|
||||
RestoreBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?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';
|
||||
|
||||
protected static ?string $title = 'Vacations';
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
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),
|
||||
]);
|
||||
}
|
||||
|
||||
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('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('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());
|
||||
}),
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
ForceDeleteBulkAction::make(),
|
||||
RestoreBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
90
app/Filament/Resources/Employees/Schemas/EmployeeForm.php
Normal file
90
app/Filament/Resources/Employees/Schemas/EmployeeForm.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Employees\Schemas;
|
||||
|
||||
use App\Enums\EmploymentStatus;
|
||||
use App\Enums\Gender;
|
||||
use App\Filament\Support\HrForm;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Schemas\Components\Tabs;
|
||||
use Filament\Schemas\Components\Tabs\Tab;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class EmployeeForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Tabs::make('Employee')
|
||||
->tabs([
|
||||
Tab::make('Personal')
|
||||
->schema([
|
||||
HrForm::fileUpload('profile_photo_path')
|
||||
->label('Photo')
|
||||
->image()
|
||||
->avatar()
|
||||
->imageEditor(),
|
||||
TextInput::make('employee_number')
|
||||
->required()
|
||||
->maxLength(50)
|
||||
->unique(ignoreRecord: true),
|
||||
TextInput::make('full_name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
TextInput::make('national_id')
|
||||
->label('National ID')
|
||||
->maxLength(50),
|
||||
Select::make('gender')
|
||||
->options(Gender::class)
|
||||
->required()
|
||||
->native(false),
|
||||
DatePicker::make('birth_date')
|
||||
->required(),
|
||||
TextInput::make('phone')
|
||||
->tel()
|
||||
->default(config('hr.default_phone'))
|
||||
->required(),
|
||||
Textarea::make('address')
|
||||
->rows(3)
|
||||
->columnSpanFull(),
|
||||
])
|
||||
->columns(2),
|
||||
Tab::make('Employment')
|
||||
->schema([
|
||||
Select::make('department_id')
|
||||
->relationship('department', 'name')
|
||||
->searchable()
|
||||
->preload()
|
||||
->required(),
|
||||
Select::make('position_id')
|
||||
->relationship('position', 'name')
|
||||
->searchable()
|
||||
->preload()
|
||||
->required(),
|
||||
Select::make('shift_id')
|
||||
->relationship('shift', 'name')
|
||||
->searchable()
|
||||
->preload()
|
||||
->required(),
|
||||
Select::make('employment_status')
|
||||
->options(EmploymentStatus::class)
|
||||
->default(EmploymentStatus::Active)
|
||||
->required()
|
||||
->native(false),
|
||||
DatePicker::make('hire_date')
|
||||
->required(),
|
||||
DatePicker::make('termination_date'),
|
||||
Textarea::make('notes')
|
||||
->rows(4)
|
||||
->columnSpanFull(),
|
||||
])
|
||||
->columns(2),
|
||||
])
|
||||
->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
204
app/Filament/Resources/Employees/Schemas/EmployeeInfolist.php
Normal file
204
app/Filament/Resources/Employees/Schemas/EmployeeInfolist.php
Normal file
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Employees\Schemas;
|
||||
|
||||
use App\Enums\EmploymentStatus;
|
||||
use App\Enums\Gender;
|
||||
use App\Models\Employee;
|
||||
use App\Models\Vacation;
|
||||
use App\Services\Employee\EmployeeStatisticsService;
|
||||
use Filament\Infolists\Components\ImageEntry;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Tabs;
|
||||
use Filament\Schemas\Components\Tabs\Tab;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class EmployeeInfolist
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Tabs::make('Employee Details')
|
||||
->tabs([
|
||||
Tab::make('Overview')
|
||||
->schema([
|
||||
Section::make('Profile')
|
||||
->schema([
|
||||
ImageEntry::make('profile_photo_path')
|
||||
->label('Photo')
|
||||
->disk(config('hr.file_uploads.disk'))
|
||||
->visibility('private')
|
||||
->circular()
|
||||
->height(120)
|
||||
->placeholder('—')
|
||||
->columnSpanFull(),
|
||||
TextEntry::make('employee_number')
|
||||
->label('Employee #'),
|
||||
TextEntry::make('full_name'),
|
||||
TextEntry::make('national_id')
|
||||
->label('National ID')
|
||||
->placeholder('—'),
|
||||
TextEntry::make('gender')
|
||||
->badge()
|
||||
->color(fn (Gender $state): string => $state->color())
|
||||
->formatStateUsing(fn (Gender $state): string => $state->label()),
|
||||
TextEntry::make('birth_date')
|
||||
->date(),
|
||||
TextEntry::make('phone'),
|
||||
TextEntry::make('address')
|
||||
->placeholder('—')
|
||||
->columnSpanFull(),
|
||||
])
|
||||
->columns(2),
|
||||
Section::make('Organization')
|
||||
->schema([
|
||||
TextEntry::make('department.name')
|
||||
->label('Department')
|
||||
->badge()
|
||||
->color('info'),
|
||||
TextEntry::make('position.name')
|
||||
->label('Position')
|
||||
->badge()
|
||||
->color('primary'),
|
||||
TextEntry::make('shift.name')
|
||||
->label('Shift')
|
||||
->badge()
|
||||
->color('gray'),
|
||||
TextEntry::make('employment_status')
|
||||
->badge()
|
||||
->color(fn (EmploymentStatus $state): string => $state->color())
|
||||
->formatStateUsing(fn (EmploymentStatus $state): string => $state->label())
|
||||
->icon(fn (EmploymentStatus $state): string => $state->icon()),
|
||||
])
|
||||
->columns(2),
|
||||
Section::make('Employment Timeline')
|
||||
->schema([
|
||||
TextEntry::make('hire_date')
|
||||
->label('Hire Date')
|
||||
->date()
|
||||
->icon('heroicon-o-calendar'),
|
||||
TextEntry::make('termination_date')
|
||||
->label('Termination Date')
|
||||
->date()
|
||||
->placeholder('—')
|
||||
->icon('heroicon-o-calendar-days'),
|
||||
TextEntry::make('tenure')
|
||||
->label('Tenure')
|
||||
->state(fn (Employee $record): string => $record->hire_date
|
||||
? $record->hire_date->diffForHumans(now(), true)
|
||||
: '—'),
|
||||
TextEntry::make('notes')
|
||||
->placeholder('—')
|
||||
->columnSpanFull(),
|
||||
])
|
||||
->columns(2),
|
||||
]),
|
||||
Tab::make('Statistics')
|
||||
->schema([
|
||||
Section::make('Leave & Attendance')
|
||||
->schema([
|
||||
TextEntry::make('stats_vacation_taken')
|
||||
->label('Vacation Taken (days)')
|
||||
->state(fn (Employee $record): int => app(EmployeeStatisticsService::class)->summary($record)->vacationTaken)
|
||||
->numeric()
|
||||
->icon('heroicon-o-sun'),
|
||||
TextEntry::make('stats_vacation_remaining')
|
||||
->label('Vacation Remaining (days)')
|
||||
->state(fn (Employee $record): int => app(EmployeeStatisticsService::class)->summary($record)->vacationRemaining)
|
||||
->numeric()
|
||||
->color('success')
|
||||
->icon('heroicon-o-calendar'),
|
||||
TextEntry::make('stats_sick_leave_count')
|
||||
->label('Sick Leave Records')
|
||||
->state(fn (Employee $record): int => app(EmployeeStatisticsService::class)->summary($record)->sickLeaveCount)
|
||||
->numeric()
|
||||
->icon('heroicon-o-heart'),
|
||||
])
|
||||
->columns(3),
|
||||
Section::make('HR Records')
|
||||
->schema([
|
||||
TextEntry::make('stats_reports_count')
|
||||
->label('Disciplinary Reports')
|
||||
->state(fn (Employee $record): int => app(EmployeeStatisticsService::class)->summary($record)->reportsCount)
|
||||
->numeric()
|
||||
->icon('heroicon-o-exclamation-triangle'),
|
||||
TextEntry::make('stats_bonuses_total')
|
||||
->label('Total Bonuses')
|
||||
->state(fn (Employee $record): float => app(EmployeeStatisticsService::class)->summary($record)->bonusesTotal)
|
||||
->money('TMT')
|
||||
->icon('heroicon-o-banknotes'),
|
||||
TextEntry::make('stats_gifts_count')
|
||||
->label('Gifts Received')
|
||||
->state(fn (Employee $record): int => app(EmployeeStatisticsService::class)->summary($record)->giftsCount)
|
||||
->numeric()
|
||||
->icon('heroicon-o-gift'),
|
||||
])
|
||||
->columns(3),
|
||||
]),
|
||||
Tab::make('Leave Summary')
|
||||
->schema([
|
||||
Section::make('Annual Leave Balance')
|
||||
->schema([
|
||||
TextEntry::make('leave_balance_taken')
|
||||
->label('Days Taken')
|
||||
->state(fn (Employee $record): int => app(EmployeeStatisticsService::class)->summary($record)->vacationTaken)
|
||||
->suffix(' days'),
|
||||
TextEntry::make('leave_balance_remaining')
|
||||
->label('Days Remaining')
|
||||
->state(fn (Employee $record): int => app(EmployeeStatisticsService::class)->summary($record)->vacationRemaining)
|
||||
->suffix(' days')
|
||||
->color('success'),
|
||||
TextEntry::make('leave_balance_total')
|
||||
->label('Annual Allowance')
|
||||
->state(fn (): int => (int) config('hr.annual_leave_days'))
|
||||
->suffix(' days'),
|
||||
])
|
||||
->columns(3),
|
||||
Section::make('Upcoming Approved Leave')
|
||||
->schema([
|
||||
TextEntry::make('upcoming_leave')
|
||||
->label('Scheduled Vacations')
|
||||
->state(function (Employee $record): string {
|
||||
$upcoming = app(EmployeeStatisticsService::class)
|
||||
->summary($record)
|
||||
->upcomingLeave;
|
||||
|
||||
if ($upcoming->isEmpty()) {
|
||||
return 'No upcoming approved leave';
|
||||
}
|
||||
|
||||
return $upcoming
|
||||
->map(fn (Vacation $vacation): string => sprintf(
|
||||
'%s: %s – %s (%d days)',
|
||||
$vacation->type->label(),
|
||||
$vacation->start_date->format('M j, Y'),
|
||||
$vacation->end_date->format('M j, Y'),
|
||||
$vacation->days,
|
||||
))
|
||||
->implode("\n");
|
||||
})
|
||||
->listWithLineBreaks()
|
||||
->columnSpanFull(),
|
||||
]),
|
||||
Section::make('Other Leave Types')
|
||||
->schema([
|
||||
TextEntry::make('unpaid_leaves_count')
|
||||
->label('Unpaid Leave Records')
|
||||
->state(fn (Employee $record): int => $record->unpaidLeaves()->count())
|
||||
->numeric(),
|
||||
TextEntry::make('explanations_count')
|
||||
->label('Explanations')
|
||||
->state(fn (Employee $record): int => $record->explanations()->count())
|
||||
->numeric(),
|
||||
])
|
||||
->columns(2),
|
||||
]),
|
||||
])
|
||||
->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
146
app/Filament/Resources/Employees/Tables/EmployeesTable.php
Normal file
146
app/Filament/Resources/Employees/Tables/EmployeesTable.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Employees\Tables;
|
||||
|
||||
use App\Enums\EmploymentStatus;
|
||||
use App\Enums\Gender;
|
||||
use App\Models\Department;
|
||||
use App\Models\Employee;
|
||||
use App\Filament\Support\ExportExcelAction;
|
||||
use Filament\Actions\BulkAction;
|
||||
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\Select;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Filters\TrashedFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class EmployeesTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('employee_number')
|
||||
->label('Number')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('full_name')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('national_id')
|
||||
->label('National ID')
|
||||
->searchable()
|
||||
->toggleable(),
|
||||
TextColumn::make('gender')
|
||||
->badge()
|
||||
->color(fn (Gender $state): string => $state->color())
|
||||
->formatStateUsing(fn (Gender $state): string => $state->label())
|
||||
->searchable(),
|
||||
TextColumn::make('phone')
|
||||
->searchable()
|
||||
->toggleable(),
|
||||
TextColumn::make('department.name')
|
||||
->label('Department')
|
||||
->badge()
|
||||
->color('info')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('position.name')
|
||||
->label('Position')
|
||||
->badge()
|
||||
->color('primary')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('shift.name')
|
||||
->label('Shift')
|
||||
->badge()
|
||||
->color('gray')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('employment_status')
|
||||
->label('Status')
|
||||
->badge()
|
||||
->color(fn (EmploymentStatus $state): string => $state->color())
|
||||
->formatStateUsing(fn (EmploymentStatus $state): string => $state->label())
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('hire_date')
|
||||
->date()
|
||||
->sortable(),
|
||||
TextColumn::make('termination_date')
|
||||
->date()
|
||||
->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('department_id')
|
||||
->label('Department')
|
||||
->relationship('department', 'name')
|
||||
->searchable()
|
||||
->preload(),
|
||||
SelectFilter::make('position_id')
|
||||
->label('Position')
|
||||
->relationship('position', 'name')
|
||||
->searchable()
|
||||
->preload(),
|
||||
SelectFilter::make('shift_id')
|
||||
->label('Shift')
|
||||
->relationship('shift', 'name')
|
||||
->searchable()
|
||||
->preload(),
|
||||
SelectFilter::make('employment_status')
|
||||
->label('Employment Status')
|
||||
->options(EmploymentStatus::class),
|
||||
TrashedFilter::make(),
|
||||
])
|
||||
->recordActions([
|
||||
ViewAction::make(),
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
ExportExcelAction::bulk('exportSelected', \App\Exports\EmployeesExport::class, 'employees.xlsx'),
|
||||
BulkAction::make('changeDepartment')
|
||||
->label('Change Department')
|
||||
->icon('heroicon-o-building-office-2')
|
||||
->schema([
|
||||
Select::make('department_id')
|
||||
->label('Department')
|
||||
->options(fn (): array => Department::query()->orderBy('name')->pluck('name', 'id')->all())
|
||||
->searchable()
|
||||
->required(),
|
||||
])
|
||||
->action(function (Collection $records, array $data): void {
|
||||
$records->each(
|
||||
fn (Employee $employee) => $employee->update([
|
||||
'department_id' => $data['department_id'],
|
||||
]),
|
||||
);
|
||||
})
|
||||
->deselectRecordsAfterCompletion(),
|
||||
DeleteBulkAction::make(),
|
||||
ForceDeleteBulkAction::make(),
|
||||
RestoreBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Employees\Widgets;
|
||||
|
||||
use App\Models\Employee;
|
||||
use App\Services\Employee\EmployeeStatisticsService;
|
||||
use Filament\Widgets\StatsOverviewWidget;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
|
||||
class EmployeeStatsWidget extends StatsOverviewWidget
|
||||
{
|
||||
public ?Employee $record = null;
|
||||
|
||||
protected function getStats(): array
|
||||
{
|
||||
if (! $this->record instanceof Employee) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$summary = app(EmployeeStatisticsService::class)->summary($this->record);
|
||||
|
||||
return [
|
||||
Stat::make('Vacation Taken', (string) $summary->vacationTaken)
|
||||
->description("{$summary->vacationRemaining} days remaining")
|
||||
->descriptionIcon('heroicon-o-calendar')
|
||||
->color('primary')
|
||||
->icon('heroicon-o-sun'),
|
||||
Stat::make('Sick Leaves', (string) $summary->sickLeaveCount)
|
||||
->description('Total records')
|
||||
->descriptionIcon('heroicon-o-heart')
|
||||
->color('warning')
|
||||
->icon('heroicon-o-heart'),
|
||||
Stat::make('Disciplinary Reports', (string) $summary->reportsCount)
|
||||
->description('On file')
|
||||
->descriptionIcon('heroicon-o-exclamation-triangle')
|
||||
->color('danger')
|
||||
->icon('heroicon-o-exclamation-triangle'),
|
||||
Stat::make('Total Bonuses', number_format($summary->bonusesTotal, 2).' TMT')
|
||||
->description("{$summary->giftsCount} gifts received")
|
||||
->descriptionIcon('heroicon-o-gift')
|
||||
->color('success')
|
||||
->icon('heroicon-o-banknotes'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user