generated from theradcoza/Laravel-Docker-Dev-Template
- Add shifts, shift_staff, and shift_attendance migrations - Add Shift, ShiftStaff, ShiftAttendance Eloquent models with auditing - Add ShiftService with business logic (create, start, complete, assign staff, mark attendance, reports, timesheets) - Add ShiftResource with list, create, edit, and attendance management pages - Add staff and attendance relation managers - Add standalone pages: ActiveShifts, StaffManagement, ShiftReports, Timesheets - Add dashboard widgets: ShiftOverview stats, TodaysShifts table - Add ShiftPolicy for role-based authorization - Add 10 shift permissions and manager role to RolePermissionSeeder - Update User model with shift relationships - Fix audits table migration with required columns for owen-it/laravel-auditing - Update DatabaseSeeder to create admin user and call RolePermissionSeeder - Switch docker-compose to MariaDB 10.11 for Docker Desktop compatibility
106 lines
3.8 KiB
PHP
106 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\ShiftResource\Pages;
|
|
|
|
use App\Filament\Resources\ShiftResource;
|
|
use App\Models\Shift;
|
|
use App\Models\ShiftAttendance;
|
|
use App\Services\ShiftService;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\Page;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Filament\Tables\Concerns\InteractsWithTable;
|
|
use Filament\Tables\Contracts\HasTable;
|
|
|
|
class ManageAttendance extends Page implements HasTable
|
|
{
|
|
use InteractsWithTable;
|
|
|
|
protected static string $resource = ShiftResource::class;
|
|
|
|
protected static string $view = 'filament.resources.shift-resource.pages.manage-attendance';
|
|
|
|
public Shift $record;
|
|
|
|
public function getTitle(): string
|
|
{
|
|
$title = $this->record->title ?? 'Shift';
|
|
|
|
return "Attendance — {$title} ({$this->record->shift_date->format('d M Y')})";
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->query(
|
|
ShiftAttendance::query()
|
|
->where('shift_id', $this->record->id)
|
|
->with(['user', 'marker'])
|
|
)
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('user.name')
|
|
->label('Staff Member')
|
|
->searchable(),
|
|
Tables\Columns\BadgeColumn::make('status')
|
|
->colors([
|
|
'gray' => 'not_marked',
|
|
'success' => 'present',
|
|
'danger' => 'absent',
|
|
])
|
|
->formatStateUsing(fn (string $state) => match ($state) {
|
|
'not_marked' => 'Not Marked',
|
|
'present' => 'Present',
|
|
'absent' => 'Absent',
|
|
default => $state,
|
|
}),
|
|
Tables\Columns\TextColumn::make('marker.name')
|
|
->label('Marked By')
|
|
->placeholder('—'),
|
|
Tables\Columns\TextColumn::make('marked_at')
|
|
->dateTime()
|
|
->placeholder('—'),
|
|
])
|
|
->actions([
|
|
Tables\Actions\Action::make('markPresent')
|
|
->label('Present')
|
|
->icon('heroicon-o-check')
|
|
->color('success')
|
|
->requiresConfirmation(false)
|
|
->action(function (ShiftAttendance $record) {
|
|
app(ShiftService::class)->markAttendance(
|
|
$this->record,
|
|
$record->user_id,
|
|
'present'
|
|
);
|
|
|
|
Notification::make()
|
|
->title("{$record->user->name} marked as present")
|
|
->success()
|
|
->send();
|
|
}),
|
|
Tables\Actions\Action::make('markAbsent')
|
|
->label('Absent')
|
|
->icon('heroicon-o-x-mark')
|
|
->color('danger')
|
|
->requiresConfirmation()
|
|
->action(function (ShiftAttendance $record) {
|
|
app(ShiftService::class)->markAttendance(
|
|
$this->record,
|
|
$record->user_id,
|
|
'absent'
|
|
);
|
|
|
|
Notification::make()
|
|
->title("{$record->user->name} marked as absent")
|
|
->warning()
|
|
->send();
|
|
}),
|
|
])
|
|
->bulkActions([])
|
|
->emptyStateHeading('No staff assigned')
|
|
->emptyStateDescription('Assign staff to this shift before managing attendance.');
|
|
}
|
|
}
|