feat: enhance Attendance model date formatting; add restricted roles check in EmployeeService; update RolePermissionSeeder with new payroll permissions
This commit is contained in:
parent
8df17601ea
commit
ab217a8d79
@ -33,7 +33,7 @@ protected function casts(): array
|
|||||||
protected function attendanceDate(): Attribute
|
protected function attendanceDate(): Attribute
|
||||||
{
|
{
|
||||||
return Attribute::make(
|
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,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,12 +10,18 @@
|
|||||||
class EmployeeService
|
class EmployeeService
|
||||||
{
|
{
|
||||||
private const ADMIN_ROLES = ['developer', 'owner', 'direktur', 'admin-toko'];
|
private const ADMIN_ROLES = ['developer', 'owner', 'direktur', 'admin-toko'];
|
||||||
|
private const RESTRICTED_ROLES = ['admin-toko', 'direktur'];
|
||||||
|
|
||||||
public function canViewAll(): bool
|
public function canViewAll(): bool
|
||||||
{
|
{
|
||||||
return auth()->user()->hasAnyRole(self::ADMIN_ROLES);
|
return auth()->user()->hasAnyRole(self::ADMIN_ROLES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function shouldHideAdminBahanBaku(): bool
|
||||||
|
{
|
||||||
|
return auth()->user()->hasAnyRole(self::RESTRICTED_ROLES);
|
||||||
|
}
|
||||||
|
|
||||||
public function getAll(array $filters = []): Collection
|
public function getAll(array $filters = []): Collection
|
||||||
{
|
{
|
||||||
return User::select(['id', 'email', 'username', 'is_active'])
|
return User::select(['id', 'email', 'username', 'is_active'])
|
||||||
@ -29,6 +35,7 @@ public function getAll(array $filters = []): Collection
|
|||||||
$userRoles = auth()->user()->roles->pluck('name');
|
$userRoles = auth()->user()->roles->pluck('name');
|
||||||
$q->whereHas('roles', fn ($rq) => $rq->whereIn('name', $userRoles));
|
$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($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(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)))
|
->when($filters['gender'] ?? null, fn ($q, $gender) => $q->whereHas('userProfile', fn ($uq) => $uq->where('gender', $gender)))
|
||||||
|
|||||||
@ -60,7 +60,7 @@ public function run(): void
|
|||||||
|
|
||||||
$developerOwnerPerms = array_values(array_filter(
|
$developerOwnerPerms = array_values(array_filter(
|
||||||
$allPermissions,
|
$allPermissions,
|
||||||
fn ($p) => ! in_array($p, $excludedFromDeveloperOwner, true)
|
fn($p) => ! in_array($p, $excludedFromDeveloperOwner, true)
|
||||||
));
|
));
|
||||||
|
|
||||||
$rolePermissions = [
|
$rolePermissions = [
|
||||||
@ -156,6 +156,8 @@ public function run(): void
|
|||||||
|
|
||||||
'payroll.view',
|
'payroll.view',
|
||||||
'payroll.adjust',
|
'payroll.adjust',
|
||||||
|
'payroll.pay',
|
||||||
|
'payroll.cancel',
|
||||||
|
|
||||||
'settings.view_system',
|
'settings.view_system',
|
||||||
'settings.update_system',
|
'settings.update_system',
|
||||||
@ -222,7 +224,6 @@ public function run(): void
|
|||||||
'employee_advances.pay',
|
'employee_advances.pay',
|
||||||
|
|
||||||
'payroll.view',
|
'payroll.view',
|
||||||
'payroll.adjust',
|
|
||||||
], true);
|
], true);
|
||||||
})),
|
})),
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user