edit delay and penalty calculations
This commit is contained in:
@@ -71,7 +71,9 @@ class AttendanceController extends Controller
|
|||||||
}
|
}
|
||||||
if ($user && !empty($user->attendances)) {
|
if ($user && !empty($user->attendances)) {
|
||||||
foreach ($user->attendances as $att) {
|
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;
|
$att->date = $date != null ? $date->format('Y/m/d') : null;
|
||||||
if ($att->duration != null && $date != null && $now->getMonth() == $date->getMonth()) {
|
if ($att->duration != null && $date != null && $now->getMonth() == $date->getMonth()) {
|
||||||
[$h, $m, $sec] = explode(':', $att->duration);
|
[$h, $m, $sec] = explode(':', $att->duration);
|
||||||
|
|||||||
@@ -127,7 +127,12 @@ class LatePenaltyService
|
|||||||
|
|
||||||
public function jalaliMonthBounds(?Carbon $date = null): array
|
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();
|
$start = (new Jalalian($j->getYear(), $j->getMonth(), 1))->toCarbon()->startOfDay();
|
||||||
$endDay = $j->getMonth() <= 6 ? 31 : ($j->getMonth() <= 11 ? 30 : ($j->isLeapYear() ? 30 : 29));
|
$endDay = $j->getMonth() <= 6 ? 31 : ($j->getMonth() <= 11 ? 30 : ($j->isLeapYear() ? 30 : 29));
|
||||||
$end = (new Jalalian($j->getYear(), $j->getMonth(), $endDay))->toCarbon()->endOfDay();
|
$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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -146,10 +146,13 @@ if (!empty($user->tasks)) {
|
|||||||
// بررسی وجود داده
|
// بررسی وجود داده
|
||||||
$attendances = $user->attendances ?? collect();
|
$attendances = $user->attendances ?? collect();
|
||||||
|
|
||||||
// گروهبندی دادهها بر اساس نام ماه (مثلا: مهر، آبان)
|
// گروهبندی دادهها بر اساس نام ماه شمسی
|
||||||
$groupedData = $attendances->groupBy(function($item) {
|
$groupedData = $attendances
|
||||||
return \Morilog\Jalali\Jalalian::fromCarbon(\Carbon\Carbon::parse($item->entered_at))->format('%B');
|
->filter(fn ($item) => !empty($item->entered_at))
|
||||||
});
|
->groupBy(function ($item) {
|
||||||
|
$month = \App\Support\JalaliHelper::format($item->entered_at, '%B', '');
|
||||||
|
return $month !== '' ? $month : 'نامعتبر';
|
||||||
|
});
|
||||||
@endphp
|
@endphp
|
||||||
|
|
||||||
<div class="container inline-flex flex-col items-center justify-center">
|
<div class="container inline-flex flex-col items-center justify-center">
|
||||||
@@ -188,10 +191,10 @@ if (!empty($user->tasks)) {
|
|||||||
@php
|
@php
|
||||||
$monthLateMinutes = 0;
|
$monthLateMinutes = 0;
|
||||||
$monthDailyFine = 0;
|
$monthDailyFine = 0;
|
||||||
$monthKey = $records->first()?->entered_at
|
$monthKey = null;
|
||||||
? \Carbon\Carbon::parse($records->first()->entered_at)
|
$firstEntered = $records->first()?->entered_at;
|
||||||
: null;
|
if ($firstEntered && \App\Support\JalaliHelper::fromDateTime($firstEntered)) {
|
||||||
if ($monthKey) {
|
$monthKey = \Carbon\Carbon::parse($firstEntered);
|
||||||
[$mStart, $mEnd] = app(\App\Services\LatePenaltyService::class)->jalaliMonthBounds($monthKey);
|
[$mStart, $mEnd] = app(\App\Services\LatePenaltyService::class)->jalaliMonthBounds($monthKey);
|
||||||
$monthWeeklyFine = (int) \App\Models\LatePeriodFine::query()
|
$monthWeeklyFine = (int) \App\Models\LatePeriodFine::query()
|
||||||
->where('user_identity', $user->user_name)
|
->where('user_identity', $user->user_name)
|
||||||
@@ -220,9 +223,9 @@ if (!empty($user->tasks)) {
|
|||||||
|
|
||||||
{{-- تاریخ --}}
|
{{-- تاریخ --}}
|
||||||
<td style="border-right: 1px solid #ddd; padding: 4px; background-color: {{"#e6e6e6" }};">
|
<td style="border-right: 1px solid #ddd; padding: 4px; background-color: {{"#e6e6e6" }};">
|
||||||
{{ $item->entered_at ? \Morilog\Jalali\Jalalian::fromCarbon(\Carbon\Carbon::parse($item->entered_at))->format('m/d') : '-' }}
|
{{ \App\Support\JalaliHelper::format($item->entered_at, 'm/d') }}
|
||||||
<span class="text-xs text-gray-500 block">
|
<span class="text-xs text-gray-500 block">
|
||||||
{{ $item->entered_at ? \Morilog\Jalali\Jalalian::fromCarbon(\Carbon\Carbon::parse($item->entered_at))->format('%A') : '' }}
|
{{ \App\Support\JalaliHelper::format($item->entered_at, '%A', '') }}
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user