55 lines
1.7 KiB
PHP
55 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Employee;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Attendance;
|
|
use Illuminate\Http\Request;
|
|
use Carbon\Carbon;
|
|
use Inertia\Inertia;
|
|
|
|
class EmployeeDashboardController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$employee = $request->user()->employee;
|
|
if (!$employee) {
|
|
return Inertia::render('employee/index', [
|
|
'stats' => null,
|
|
]);
|
|
}
|
|
|
|
$currentMonth = Carbon::now()->month;
|
|
$currentYear = Carbon::now()->year;
|
|
|
|
$attendances = Attendance::where('employee_id', $employee->id)
|
|
->whereMonth('date', $currentMonth)
|
|
->whereYear('date', $currentYear)
|
|
->get();
|
|
|
|
$presentCount = $attendances->where('status', 'present')->count();
|
|
$leaveCount = $attendances->where('status', 'leave')->count();
|
|
$dispensationCount = $attendances->where('status', 'dispensation')->count();
|
|
|
|
// Batas telat 08:00
|
|
$onTimeCount = $attendances->where('status', 'present')->filter(function ($att) {
|
|
return $att->check_in && $att->check_in <= '08:00:00';
|
|
})->count();
|
|
|
|
$lateCount = $attendances->where('status', 'present')->filter(function ($att) {
|
|
return $att->check_in && $att->check_in > '08:00:00';
|
|
})->count();
|
|
|
|
return Inertia::render('employee/index', [
|
|
'stats' => [
|
|
'present' => $presentCount,
|
|
'leave' => $leaveCount,
|
|
'dispensation' => $dispensationCount,
|
|
'on_time' => $onTimeCount,
|
|
'late' => $lateCount,
|
|
],
|
|
'employee' => $employee,
|
|
]);
|
|
}
|
|
}
|