feat: enhance Attendance model date formatting; add restricted roles check in EmployeeService; update RolePermissionSeeder with new payroll permissions

This commit is contained in:
Yoga Pangestu 2026-08-06 17:16:50 +07:00
parent 8df17601ea
commit ab217a8d79
3 changed files with 11 additions and 3 deletions

View File

@ -33,7 +33,7 @@ protected function casts(): array
protected function attendanceDate(): Attribute
{
return Attribute::make(
get: fn ($value) => $value?->translatedFormat('l, d F Y'),
get: fn ($value) => $value ? \Carbon\Carbon::parse($value)->translatedFormat('l, d F Y') : null,
);
}

View File

@ -10,12 +10,18 @@
class EmployeeService
{
private const ADMIN_ROLES = ['developer', 'owner', 'direktur', 'admin-toko'];
private const RESTRICTED_ROLES = ['admin-toko', 'direktur'];
public function canViewAll(): bool
{
return auth()->user()->hasAnyRole(self::ADMIN_ROLES);
}
public function shouldHideAdminBahanBaku(): bool
{
return auth()->user()->hasAnyRole(self::RESTRICTED_ROLES);
}
public function getAll(array $filters = []): Collection
{
return User::select(['id', 'email', 'username', 'is_active'])
@ -29,6 +35,7 @@ public function getAll(array $filters = []): Collection
$userRoles = auth()->user()->roles->pluck('name');
$q->whereHas('roles', fn ($rq) => $rq->whereIn('name', $userRoles));
})
->when($this->shouldHideAdminBahanBaku(), fn ($q) => $q->whereDoesntHave('roles', fn ($rq) => $rq->where('name', 'admin-bahan-baku')))
->when($filters['employment_status'] ?? null, fn ($q, $status) => $q->whereHas('employee', fn ($eq) => $eq->where('employment_status', $status)))
->when(isset($filters['is_active']) && $filters['is_active'] !== '', fn ($q) => $q->where('is_active', filter_var($filters['is_active'], FILTER_VALIDATE_BOOLEAN)))
->when($filters['gender'] ?? null, fn ($q, $gender) => $q->whereHas('userProfile', fn ($uq) => $uq->where('gender', $gender)))

View File

@ -60,7 +60,7 @@ public function run(): void
$developerOwnerPerms = array_values(array_filter(
$allPermissions,
fn ($p) => ! in_array($p, $excludedFromDeveloperOwner, true)
fn($p) => ! in_array($p, $excludedFromDeveloperOwner, true)
));
$rolePermissions = [
@ -156,6 +156,8 @@ public function run(): void
'payroll.view',
'payroll.adjust',
'payroll.pay',
'payroll.cancel',
'settings.view_system',
'settings.update_system',
@ -222,7 +224,6 @@ public function run(): void
'employee_advances.pay',
'payroll.view',
'payroll.adjust',
], true);
})),