107 lines
4.6 KiB
PHP
Executable File
107 lines
4.6 KiB
PHP
Executable File
<?php
|
|
|
|
use Morilog\Jalali\Jalalian;
|
|
use Carbon\Carbon;
|
|
|
|
//dd($data);
|
|
$monthlyTotals = [];
|
|
|
|
foreach ($data as $month => $attendances) {
|
|
$tsec = 0;
|
|
|
|
foreach ($attendances as $attendance) {
|
|
// اگر duration موجود باشه استفاده میکنیم
|
|
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);
|
|
$seconds = $tsec % 60;
|
|
|
|
// ذخیره در آرایه جدید با کل زمان ماه
|
|
$monthlyTotals[$month] = sprintf('%02d:%02d', $hours, $minutes);
|
|
}
|
|
|
|
|
|
//dd($monthlyTotals);
|
|
|
|
?>
|
|
@extends('app')
|
|
@section('content')
|
|
|
|
<div class="container inline-flex flex-col items-center justify-center ">
|
|
@if(empty($data))
|
|
<div class="mt-80 text-gray-500 text-xl font-bold italic">
|
|
<h1>اطلاعاتی موجود نمیباشد</h1>
|
|
</div>
|
|
@else
|
|
<div class="tab rounded-t-2xl max-w-[350px] mx-auto flex"
|
|
style="margin-top: 80px; max-width: 350px">
|
|
@foreach(array_keys($data) as $month)
|
|
<button class="tablinks active rounded-t-2xl cursor-pointer" onclick="openCity(event, '{{$month}}')">{{$month}}</button>
|
|
@endforeach
|
|
</div>
|
|
|
|
@foreach($data as $month => $records)
|
|
<div id="{{$month}}" class="tabcontent w-[350px] bg-white rounded-b-xl rounded-tl-2xl cursor-default leading-7" style="">
|
|
|
|
<table class="" style="width:100%; border-collapse: collapse;text-align: center">
|
|
<thead>
|
|
<tr class="" style="border-bottom: 1px solid #ddd;">
|
|
<th style="border-right: 1px solid #ddd;">تاریخ</th>
|
|
<th style="border-right: 1px solid #ddd;">روز</th>
|
|
<th style="border-right: 1px solid #ddd;">ورود</th>
|
|
<th style="border-right: 1px solid #ddd;">خروج</th>
|
|
<th style="border-right: 1px solid #ddd;">مدت</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody >
|
|
@foreach($records as $row)
|
|
<tr class="hover:bg-cyan-500" style="border-bottom: 1px solid #ddd;">
|
|
<td style="border-right: 1px solid #ddd;">{{ Jalalian::fromCarbon(\Carbon\Carbon::parse($row->entered_at))->format('m/d') ?? '-' }}</td>
|
|
<td style="border-right: 1px solid #ddd;">{{ Jalalian::fromCarbon(\Carbon\Carbon::parse($row->entered_at))->format('%A') ?? '-' }}</td>
|
|
<td style="border-right: 1px solid #ddd;">{{ \Carbon\Carbon::parse($row->entered_at)->format('H:i') ?? '-' }}</td>
|
|
<td style="border-right: 1px solid #ddd;">{{ $row->exited_at ? \Carbon\Carbon::parse($row->exited_at)->format('H:i') : '-' }}</td>
|
|
<td style="border-right: 1px solid #ddd;">{{ $row->exited_at ? \Carbon\Carbon::parse($row->duration)->format('H:i') : '-' }}</td>
|
|
</tr>
|
|
@endforeach
|
|
<tr>
|
|
<td colspan="5" class="hover:bg-cyan-500 rounded-b-xl" style="border-top: 1px solid #ddd; text-align: center; ">
|
|
مجموع کارکرد این ماه: {{$monthlyTotals[$month]}}
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
@endforeach
|
|
@endif
|
|
</div>
|
|
<script>
|
|
function openCity(evt, Month) {
|
|
var i, tabcontent, tablinks;
|
|
tabcontent = document.getElementsByClassName("tabcontent");
|
|
for (i = 0; i < tabcontent.length; i++) {
|
|
tabcontent[i].style.display = "none";
|
|
}
|
|
tablinks = document.getElementsByClassName("tablinks");
|
|
for (i = 0; i < tablinks.length; i++) {
|
|
tablinks[i].className = tablinks[i].className.replace(" active", "");
|
|
}
|
|
document.getElementById(Month).style.display = "block";
|
|
evt.currentTarget.className += " active";
|
|
}
|
|
|
|
// باز کردن اولین تب به صورت پیشفرض
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
let firstTab = document.querySelector(".tablinks"); // اولین دکمه
|
|
if (firstTab) {
|
|
firstTab.click(); // همون اول کلیک مجازی بخوره
|
|
}
|
|
});
|
|
</script>
|
|
|
|
@endsection
|