136 lines
5.3 KiB
PHP
Executable File
136 lines
5.3 KiB
PHP
Executable File
<?php
|
|
|
|
use Morilog\Jalali\Jalalian;
|
|
use Carbon\Carbon;
|
|
|
|
$monthlyTotals = [];
|
|
$currentJalaliYear = Jalalian::now()->getYear();
|
|
$monthLabels = [];
|
|
|
|
foreach ($data as $monthKey => $attendances) {
|
|
$tsec = 0;
|
|
|
|
foreach ($attendances as $attendance) {
|
|
if (!empty($attendance->duration)) {
|
|
[$h, $m, $s] = explode(':', $attendance->duration);
|
|
$tsec += (int)$h * 3600 + (int)$m * 60 + (int)$s;
|
|
}
|
|
}
|
|
|
|
$hours = floor($tsec / 3600);
|
|
$minutes = floor(($tsec % 3600) / 60);
|
|
|
|
$monthlyTotals[$monthKey] = sprintf('%02d:%02d', $hours, $minutes);
|
|
|
|
if (preg_match('/^(\d{4})-(\d{2})$/', (string) $monthKey, $m)) {
|
|
try {
|
|
$j = new Jalalian((int) $m[1], (int) $m[2], 1);
|
|
$name = $j->format('%B');
|
|
$monthLabels[$monthKey] = ((int) $m[1] === (int) $currentJalaliYear)
|
|
? $name
|
|
: $name . ' ' . $m[1];
|
|
} catch (\Throwable $e) {
|
|
$monthLabels[$monthKey] = $monthKey;
|
|
}
|
|
} else {
|
|
$monthLabels[$monthKey] = $monthKey;
|
|
}
|
|
}
|
|
|
|
$monthKeys = array_keys($data);
|
|
$recentMonthKeys = array_slice($monthKeys, 0, 3);
|
|
$olderMonthKeys = array_slice($monthKeys, 3);
|
|
|
|
?>
|
|
@extends('app')
|
|
|
|
@section('content')
|
|
<div class="ui-page">
|
|
@if(empty($data))
|
|
<div class="ui-empty">
|
|
<h1>اطلاعاتی موجود نمیباشد</h1>
|
|
</div>
|
|
@else
|
|
<div class="ui-month-tabs" style="margin-top: 5rem;">
|
|
@foreach($recentMonthKeys as $monthKey)
|
|
<button type="button" class="tablinks"
|
|
onclick="openCity(event, 'm-{{ $monthKey }}')">{{ $monthLabels[$monthKey] ?? $monthKey }}</button>
|
|
@endforeach
|
|
@if(!empty($olderMonthKeys))
|
|
<div class="ui-month-more">
|
|
<button type="button" class="tablinks ui-month-more-btn" onclick="toggleMonthMore(event)">⋯</button>
|
|
<div id="month-more-menu" class="ui-month-more-menu hidden">
|
|
@foreach($olderMonthKeys as $monthKey)
|
|
<button type="button" class="tablinks ui-month-more-item"
|
|
onclick="openCity(event, 'm-{{ $monthKey }}'); closeMonthMore();">
|
|
{{ $monthLabels[$monthKey] ?? $monthKey }}
|
|
</button>
|
|
@endforeach
|
|
</div>
|
|
</div>
|
|
@endif
|
|
</div>
|
|
|
|
@foreach($data as $monthKey => $records)
|
|
<div id="m-{{ $monthKey }}" class="tabcontent ui-attendance-card">
|
|
<table class="ui-attendance-table">
|
|
<thead>
|
|
<tr>
|
|
<th>تاریخ</th>
|
|
<th>روز</th>
|
|
<th>ورود</th>
|
|
<th>خروج</th>
|
|
<th>مدت</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach($records as $row)
|
|
<tr>
|
|
<td>{{ \App\Support\JalaliHelper::format($row->entered_at, 'Y/m/d') }}</td>
|
|
<td>{{ \App\Support\JalaliHelper::format($row->entered_at, '%A') }}</td>
|
|
<td>{{ Carbon::parse($row->entered_at)->format('H:i') ?? '-' }}</td>
|
|
<td>{{ $row->exited_at ? Carbon::parse($row->exited_at)->format('H:i') : '-' }}</td>
|
|
<td>{{ $row->exited_at ? Carbon::parse($row->duration)->format('H:i') : '-' }}</td>
|
|
</tr>
|
|
@endforeach
|
|
<tr>
|
|
<td colspan="5" class="table-summary">
|
|
مجموع کارکرد این ماه: {{ $monthlyTotals[$monthKey] }}
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
@endforeach
|
|
@endif
|
|
</div>
|
|
|
|
<script>
|
|
function openCity(evt, Month) {
|
|
document.querySelectorAll('.tabcontent').forEach(el => el.style.display = 'none');
|
|
document.querySelectorAll('.tablinks').forEach(el => el.classList.remove('active'));
|
|
|
|
const panel = document.getElementById(Month);
|
|
if (panel) panel.style.display = 'block';
|
|
if (evt && evt.currentTarget) evt.currentTarget.classList.add('active');
|
|
}
|
|
|
|
function toggleMonthMore(evt) {
|
|
if (evt) evt.stopPropagation();
|
|
const menu = document.getElementById('month-more-menu');
|
|
if (menu) menu.classList.toggle('hidden');
|
|
}
|
|
|
|
function closeMonthMore() {
|
|
const menu = document.getElementById('month-more-menu');
|
|
if (menu) menu.classList.add('hidden');
|
|
}
|
|
|
|
document.addEventListener('click', closeMonthMore);
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
const first = document.querySelector('.ui-month-tabs > .tablinks');
|
|
if (first) first.click();
|
|
});
|
|
</script>
|
|
@endsection
|