256 lines
13 KiB
PHP
Executable File
256 lines
13 KiB
PHP
Executable File
<?php
|
|
|
|
use App\Models\Attendance;
|
|
use App\Models\AttendanceBreak;
|
|
use Morilog\Jalali\Jalalian;
|
|
use Carbon\Carbon;
|
|
|
|
//dd($reqs);
|
|
$now = Jalalian::fromCarbon(Carbon::now());
|
|
foreach ($users as $user) {
|
|
$totaltime = 0;
|
|
$tsec = 0;
|
|
foreach ($user->attendances as $att) {
|
|
$date = $att->entered_at != null ? Jalalian::fromCarbon(Carbon::parse($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, $s] = explode(':', $att->duration);
|
|
$tsec += $h * 3600 + $m * 60 + $s;
|
|
}
|
|
}
|
|
$hours = floor($tsec / 3600);
|
|
$minutes = floor(($tsec % 3600) / 60);
|
|
$seconds = $tsec % 60;
|
|
|
|
$totalTime = sprintf('%02d:%02d', $hours, $minutes);
|
|
$user->totaltime = $totalTime;
|
|
|
|
}
|
|
//dd($users);
|
|
$now = now()->format('Y-m-d');
|
|
foreach ($users as $u) {
|
|
|
|
$us = $u->attendances()
|
|
->whereNull('exited_at')
|
|
->latest('entered_at')
|
|
->first();
|
|
// dump($us);
|
|
if ($us) {
|
|
$us->entered_at = Carbon::parse($us->entered_at)->format('Y-m-d');
|
|
if ($us->entered_at == $now)
|
|
$us = true;
|
|
else
|
|
$us = false;
|
|
$u->working = $us ? 1 : 0;
|
|
} else
|
|
$u->working = 0;
|
|
|
|
foreach ($u->attendances as $u_att) {
|
|
$break = AttendanceBreak::wherenull('break_end')->where('attendance_id', $u_att->id)->exists();
|
|
if ($break)
|
|
$u->working = 2;
|
|
}
|
|
|
|
}
|
|
//dd($users);
|
|
$users = $users->sortByDesc('working');
|
|
//$users = json_decode(json: $users);
|
|
// $users = collect($users);
|
|
$usersChunked = $users->chunk(3);
|
|
//dd($users);
|
|
?>
|
|
|
|
|
|
@extends('app')
|
|
@section('content')
|
|
<div class="container w-full flex flex-col items-center">
|
|
|
|
@if(!collect($reqs)->pluck('attendances')->flatten()->isEmpty())
|
|
<div class="mt-10 bg-white rounded-lg shadow-md max-w-[350px] flex flex-col items-center">
|
|
<p style="min-font-size: 30; text-align: center; margin-bottom: 10px">درخواست ها</p>
|
|
{{-- {{dd($reqs)}}--}}
|
|
|
|
@foreach ($reqs as $u)
|
|
@if(!empty($u['attendances']))
|
|
|
|
<button type="button"
|
|
class="w-[150px] p-3 font-bold text-white bg-blue-500 hover:bg-blue-700 rounded transition duration-150 text-center "
|
|
onclick="togglerequests('attendance-{{ $loop->index }}')"
|
|
style="margin: 10px 0; text-align: center; background-color: #00bcd4">
|
|
{{ $u['name'] }}
|
|
</button>
|
|
{{-- @else--}}
|
|
{{-- <p class="text-stone-400" style="text-align: center">درخواستی ثبت نشده</p>--}}
|
|
{{-- @break--}}
|
|
@endif
|
|
<div id="attendance-{{ $loop->index }}" class="hidden-content pt-4">
|
|
<table style="max-width: 350px; margin: auto; text-align: center" class="w-[350px] table-auto">
|
|
|
|
<thead>
|
|
<tr class="text-sm" style="background-color: #00a3ba; color: white; text-align: center;">
|
|
|
|
<th class="px-2 py-2 border w-1/6">درخواست</th>
|
|
<th class="px-2 py-2 border w-1/6">تاریخ</th>
|
|
<th class="px-2 py-2 border w-1/6">ورود</th>
|
|
<th class="px-2 py-2 border w-1/6">خروج</th>
|
|
@if($userType == 'admin')
|
|
<th class="px-2 py-2 border w-1/6">تعیین وضعیت</th>
|
|
@endif
|
|
</tr>
|
|
</thead>
|
|
|
|
<tbody>
|
|
{{-- {{dd($u['attendances'])}}--}}
|
|
@forelse($u['attendances'] as $rec)
|
|
<tr style="background-color: {{$rec->id=='new' ? 'lightblue' : 'white'}}">
|
|
{{--{{dd($rec)}}--}}
|
|
<td class="px-4 py-2 border">{{ match ($rec->function) {
|
|
'edit' => "تغییر ساعت",
|
|
'delete' => "حذف",
|
|
'new' => "جدید",
|
|
default => "نامشخص",
|
|
} }}</td>
|
|
<td class="px-4 py-2 border">{{ !empty($rec->date) ? Jalalian::fromCarbon(Carbon::parse($rec->date))->format('Y/m/d')
|
|
: Jalalian::fromCarbon(Carbon::parse($rec->oldenter))->format('Y/m/d')}}</td>
|
|
@php
|
|
$oldEnter = $rec->oldenter ? Carbon::parse($rec->oldenter)->format('H:i') : null;
|
|
$newEnter = $rec->newenter ? Carbon::parse($rec->newenter)->format('H:i') : null;
|
|
$oldExit = $rec->oldexit ? Carbon::parse($rec->oldexit)->format('H:i') : null;
|
|
$newExit = $rec->newexit ? Carbon::parse($rec->newexit)->format('H:i') : null;
|
|
@endphp
|
|
|
|
@if( $oldEnter == $newEnter || $newEnter == null)
|
|
<td class="px-4 py-2 border">{{ $oldEnter ?? '-' }}</td>
|
|
@else
|
|
<td class="px-4 py-2 border">{{ $oldEnter || $newEnter ? ($rec->id=='new' || $oldEnter==($newEnter ?? '') ? $oldEnter : $oldEnter.'👇🏻'.$newEnter) : '-' }}</td>
|
|
@endif
|
|
|
|
@if($oldExit == $newExit || $newExit == null)
|
|
<td class="px-4 py-2 border">{{$oldExit ? ($oldExit ?? $newExit) : '-'}}</td>
|
|
@else
|
|
<td class="px-4 py-2 border">{{ $oldExit || $newExit ? ($rec->id=='new' || $oldExit==($newExit ?? '') ? $oldExit : $oldExit.'👇🏻'.$newExit) : '-' }}</td>
|
|
@endif
|
|
|
|
@if($userType == 'admin')
|
|
<td class="px-4 py-2 border">
|
|
<form method="post" action="{{route('admin.update')}}">
|
|
@csrf
|
|
<input type="hidden" name="update" id="update" value="approve">
|
|
<input type="hidden" name="data" id="data"
|
|
value="{{json_encode($rec)}}">
|
|
<button class="bg-white rounded w-full"
|
|
style="background-color: #81ff65; margin-bottom: 5px">
|
|
تایید
|
|
</button>
|
|
</form>
|
|
<form method="post" action="{{route('admin.update')}}">
|
|
@csrf
|
|
<input type="hidden" name="update" id="update" value="reject">
|
|
<input type="hidden" name="data" id="data"
|
|
value="{{json_encode($rec)}}">
|
|
<button class="bg-white rounded w-full"
|
|
style="background-color: #ff6565">
|
|
رد
|
|
</button>
|
|
</form>
|
|
</td>
|
|
@endif
|
|
</tr>
|
|
@empty
|
|
<tr>
|
|
<td class="px-4 py-2 border text-center" colspan="6">هیچ رکوردی ثبت نشده</td>
|
|
</tr>
|
|
@endforelse
|
|
</tbody>
|
|
</table>
|
|
</div> {{-- پایان hidden-content --}}
|
|
@endforeach
|
|
{{-- @if(collect($reqs)->pluck('attendances')->flatten()->isEmpty())--}}
|
|
{{-- <p class="text-stone-400" style="text-align: center">درخواستی ثبت نشده</p>--}}
|
|
</div>
|
|
@endif
|
|
|
|
|
|
<div class="container" style="padding-top: 20px">
|
|
<div class="grid grid-cols-2 grid-rows-none ">
|
|
@foreach ($usersChunked as $chunk)
|
|
@foreach ($chunk as $u)
|
|
<div class="form m-3 justify-evenly rounded-lg shadow-md "
|
|
style="align-items: center; text-align: center; border: 2px solid
|
|
{{ $u->active_task ? '#00ff15' : ($u->working == 1 ? '#16c8ce' : ($u->working == 2 ? 'orange' : 'white' ))}}; padding: 10px; ">
|
|
@php
|
|
@endphp
|
|
<a href="/admin/{{ $u->user_name }}"
|
|
class=" rounded-xl"
|
|
style="text-decoration: none; color: inherit;">
|
|
<p style="font-weight: bold ; color:#333;">
|
|
{{ $u->name ?? $u->user_name }}
|
|
</p>
|
|
@if($u->active_task)
|
|
<p>وظیفه: {{ $u->active_task }}</p>
|
|
@endif
|
|
<p>
|
|
کارکرد ماه جاری:
|
|
{{ $u->totaltime }}
|
|
</p>
|
|
|
|
<p>
|
|
تعداد درخواست ها:
|
|
{{ $u->req_counts }}
|
|
</p>
|
|
|
|
</a>
|
|
@if($userType == 'admin')
|
|
|
|
<button type="button"
|
|
class="rounded-lg bg-cyan-500 hover:bg-cyan-600"
|
|
onclick="window.location.href='{{ url('attendance/profile').'?username='.$u->user_name }}'"
|
|
style=" border: none; color: white; padding: 5px 10px; text-align: center; text-decoration: none;
|
|
display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; ">
|
|
ویرایش
|
|
</button>
|
|
@endif
|
|
</div>
|
|
|
|
@endforeach
|
|
@endforeach
|
|
<a class="form m-3 justify-evenly rounded-lg shadow-md " href="{{route('admin.new')}}"
|
|
style="align-items: center; text-align: center; ">
|
|
<i class="fa-regular fa-plus "
|
|
style="font-size: 80px; width: 90%; height: 90%;"></i>
|
|
</a>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
{{-- {{dd($reqs)}}--}}
|
|
|
|
|
|
|
|
{{--MODAL--}}
|
|
|
|
@endsection
|
|
|
|
@section('script')
|
|
<script>
|
|
// این تابع اکنون یک DIV را باز و بسته میکند
|
|
function togglerequests(elementId) {
|
|
var contentDiv = document.getElementById(elementId);
|
|
|
|
// بررسی میکند اگر عنصر دارای کلاس 'hidden-content' هست، آن را حذف و نمایش دهد، وگرنه اضافه و پنهان کند.
|
|
if (contentDiv.classList.contains('hidden-content')) {
|
|
contentDiv.classList.remove('hidden-content');
|
|
// اگر از Tailwind استفاده میکنید، ممکن است بخواهید: contentDiv.classList.remove('hidden');
|
|
} else {
|
|
contentDiv.classList.add('hidden-content');
|
|
// contentDiv.classList.add('hidden');
|
|
}
|
|
}
|
|
</script>
|
|
<style>
|
|
/* نیاز به این کلاس برای پنهان کردن اولیه محتوا */
|
|
.hidden-content {
|
|
display: none;
|
|
}
|
|
</style>
|
|
@endsection
|