edit delay and penalty calculations
This commit is contained in:
@@ -71,7 +71,9 @@ class AttendanceController extends Controller
|
||||
}
|
||||
if ($user && !empty($user->attendances)) {
|
||||
foreach ($user->attendances as $att) {
|
||||
$date = $att->entered_at != null ? Jalalian::fromCarbon(Carbon::parse($att->entered_at)) : null;
|
||||
$date = $att->entered_at != null
|
||||
? \App\Support\JalaliHelper::fromDateTime($att->entered_at)
|
||||
: null;
|
||||
$att->date = $date != null ? $date->format('Y/m/d') : null;
|
||||
if ($att->duration != null && $date != null && $now->getMonth() == $date->getMonth()) {
|
||||
[$h, $m, $sec] = explode(':', $att->duration);
|
||||
|
||||
@@ -127,7 +127,12 @@ class LatePenaltyService
|
||||
|
||||
public function jalaliMonthBounds(?Carbon $date = null): array
|
||||
{
|
||||
$j = Jalalian::fromCarbon($date ?? Carbon::now());
|
||||
$carbon = $date ?? Carbon::now();
|
||||
if ($carbon->year < 1000 || $carbon->year > 3000) {
|
||||
$carbon = Carbon::now();
|
||||
}
|
||||
|
||||
$j = Jalalian::fromCarbon($carbon);
|
||||
$start = (new Jalalian($j->getYear(), $j->getMonth(), 1))->toCarbon()->startOfDay();
|
||||
$endDay = $j->getMonth() <= 6 ? 31 : ($j->getMonth() <= 11 ? 30 : ($j->isLeapYear() ? 30 : 29));
|
||||
$end = (new Jalalian($j->getYear(), $j->getMonth(), $endDay))->toCarbon()->endOfDay();
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Morilog\Jalali\Jalalian;
|
||||
use Throwable;
|
||||
|
||||
class JalaliHelper
|
||||
{
|
||||
public static function fromDateTime($value): ?Jalalian
|
||||
{
|
||||
if ($value === null || $value === '' || $value === '0000-00-00' || str_starts_with((string) $value, '0000-00-00')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$carbon = $value instanceof Carbon ? $value : Carbon::parse($value);
|
||||
if ($carbon->year < 1000 || $carbon->year > 3000) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Jalalian::fromCarbon($carbon);
|
||||
} catch (Throwable $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static function format($value, string $format = 'Y/m/d', string $fallback = '-'): string
|
||||
{
|
||||
$jalali = self::fromDateTime($value);
|
||||
|
||||
return $jalali ? $jalali->format($format) : $fallback;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user