Editing Employee Attendance and Check-ins

This commit is contained in:
2026-10-07 17:51:03 +03:30
parent 694f41968a
commit ce2ce49ffb
7 changed files with 134 additions and 6 deletions
+30 -2
View File
@@ -19,6 +19,34 @@ class LatePenaltyService
public const WEEKLY_ALLOWANCE_MINUTES = 15;
public const FINE_PER_MINUTE = 2000;
/** @var array<string, string> */
private array $workStartCache = [];
/** ساعت شروع کار کاربر (H:i)؛ اگر ادمین تعیین نکرده باشد ۰۸:۳۰ */
public function workStartFor(?string $userIdentity): string
{
if (!$userIdentity) {
return self::WORK_START;
}
if (!array_key_exists($userIdentity, $this->workStartCache)) {
$value = null;
try {
$value = User::where('user_name', $userIdentity)->value('work_start_time');
} catch (\Throwable $e) {
}
$this->workStartCache[$userIdentity] = $value ? substr((string) $value, 0, 5) : self::WORK_START;
}
return $this->workStartCache[$userIdentity];
}
public function forgetWorkStart(string $userIdentity): void
{
unset($this->workStartCache[$userIdentity]);
}
/** جمعه و تعطیلات رسمی روز کاری نیستند؛ ورود در این روزها اضافه‌کاری است. */
public function isWorkDay(Carbon $date): bool
{
@@ -59,7 +87,7 @@ class LatePenaltyService
];
}
$threshold = $entered->copy()->setTimeFromTimeString(self::WORK_START)->startOfMinute();
$threshold = $entered->copy()->setTimeFromTimeString($this->workStartFor($userIdentity))->startOfMinute();
if ($userIdentity) {
$leaveThreshold = $this->approvedLeaveWorkThreshold($userIdentity, $entered);
@@ -104,7 +132,7 @@ class LatePenaltyService
public function approvedLeaveWorkThreshold(string $userIdentity, Carbon $entered): Carbon|false|null
{
$day = $entered->toDateString();
$workStart = $entered->copy()->setTimeFromTimeString(self::WORK_START)->startOfMinute();
$workStart = $entered->copy()->setTimeFromTimeString($this->workStartFor($userIdentity))->startOfMinute();
$leaves = LeaveRequest::query()
->where('user_identity', $userIdentity)