64 lines
1.9 KiB
PHP
64 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Models\Location;
|
|
use App\Models\Order;
|
|
use Carbon\Carbon;
|
|
|
|
class ReportKurirController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
|
|
$month = $request->month ?? now()->month;
|
|
$year = $request->year ?? now()->year;
|
|
$userId = auth()->id();
|
|
|
|
// Ambil presensi (lokasi pertama per hari)
|
|
$presences = Location::select('user_id', Location::raw('DATE(created_at) as date'), Location::raw('MIN(created_at) as check_in_time'))
|
|
->where('user_id', $userId)
|
|
->whereMonth('created_at', $month)
|
|
->whereYear('created_at', $year)
|
|
->groupBy('user_id', 'date')
|
|
->get();
|
|
|
|
// Hitung presensi yang ontime
|
|
$ontimePresensi = $presences->filter(function ($presence) {
|
|
return Carbon::parse($presence->check_in_time)->format('H:i') < '07:30';
|
|
})->count();
|
|
|
|
// Hitung hari on target (≥5 order per hari)
|
|
$onTargetDays = Order::selectRaw('DATE(created_at) as date')
|
|
->where('kurir_id', $userId)
|
|
->whereMonth('created_at', $month)
|
|
->whereYear('created_at', $year)
|
|
->groupBy('date')
|
|
->havingRaw('COUNT(*) >= 5')
|
|
->get()
|
|
->count();
|
|
|
|
$totalNilai = $ontimePresensi + $onTargetDays;
|
|
|
|
// Predikat berdasarkan total nilai
|
|
if ($totalNilai >= 20 && $totalNilai <= 30) {
|
|
$predikat = 'Baik Sekali';
|
|
} elseif ($totalNilai >= 15 && $totalNilai < 20) {
|
|
$predikat = 'Baik';
|
|
} elseif ($totalNilai >= 5) {
|
|
$predikat = 'Perfect';
|
|
} else {
|
|
$predikat = '-';
|
|
}
|
|
|
|
return view('kurir.report', compact(
|
|
'month', 'year',
|
|
'ontimePresensi',
|
|
'onTargetDays',
|
|
'predikat'
|
|
));
|
|
}
|
|
|
|
}
|