diff --git a/app/Models/Attendance.php b/app/Models/Attendance.php index e3fd4da..9803d95 100644 --- a/app/Models/Attendance.php +++ b/app/Models/Attendance.php @@ -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, ); } diff --git a/app/Services/Admin/HR/EmployeeService.php b/app/Services/Admin/HR/EmployeeService.php index d280a44..2da4190 100644 --- a/app/Services/Admin/HR/EmployeeService.php +++ b/app/Services/Admin/HR/EmployeeService.php @@ -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))) diff --git a/database/seeders/RolePermissionSeeder.php b/database/seeders/RolePermissionSeeder.php index 3a4a93a..29db0cf 100644 --- a/database/seeders/RolePermissionSeeder.php +++ b/database/seeders/RolePermissionSeeder.php @@ -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); })),