Changes to holidays and the overlap between this year and the previous year
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Attendance;
|
||||
use App\Models\Holiday;
|
||||
use App\Models\LatePeriodFine;
|
||||
use App\Models\LeaveRequest;
|
||||
use App\Models\User;
|
||||
@@ -18,6 +19,22 @@ class LatePenaltyService
|
||||
public const WEEKLY_ALLOWANCE_MINUTES = 15;
|
||||
public const FINE_PER_MINUTE = 2000;
|
||||
|
||||
/** جمعه و تعطیلات رسمی روز کاری نیستند؛ ورود در این روزها اضافهکاری است. */
|
||||
public function isWorkDay(Carbon $date): bool
|
||||
{
|
||||
if ($date->isFriday()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
return !Holiday::query()
|
||||
->whereDate('date', $date->toDateString())
|
||||
->exists();
|
||||
} catch (\Throwable $e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function calculateFromEnteredAt(?string $enteredAt, ?string $userIdentity = null): array
|
||||
{
|
||||
if (!$enteredAt) {
|
||||
@@ -31,6 +48,17 @@ class LatePenaltyService
|
||||
|
||||
// فقط تا دقیقه؛ ثانیه نادیده گرفته میشود
|
||||
$entered = Carbon::parse($enteredAt)->startOfMinute();
|
||||
|
||||
// جمعه / تعطیل → بدون تأخیر و جریمه
|
||||
if (!$this->isWorkDay($entered)) {
|
||||
return [
|
||||
'late_minutes' => 0,
|
||||
'grace_late_minutes' => 0,
|
||||
'daily_fine_minutes' => 0,
|
||||
'daily_fine_amount' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
$threshold = $entered->copy()->setTimeFromTimeString(self::WORK_START)->startOfMinute();
|
||||
|
||||
if ($userIdentity) {
|
||||
|
||||
Reference in New Issue
Block a user