feat: redirect trip form to dashboard, distinguish cancellation sources, and add lightweight real-time polling
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Employee;
|
|||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Vehicle;
|
use App\Models\Vehicle;
|
||||||
use App\Models\VehicleActivity;
|
use App\Models\VehicleActivity;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
@@ -132,4 +133,72 @@ class DashboardController extends Controller
|
|||||||
return redirect()->route('employee.dashboard')
|
return redirect()->route('employee.dashboard')
|
||||||
->with('success', "Perjalanan {$activity->transaction_no} ({$activity->vehicle->code}) berhasil dibatalkan.");
|
->with('success', "Perjalanan {$activity->transaction_no} ({$activity->vehicle->code}) berhasil dibatalkan.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Endpoint micro-polling super ringan (JSON) untuk memantau status validasi tiket perjalanan driver.
|
||||||
|
* Menghemat bandwidth & CPU server dibanding me-refresh halaman penuh secara berulang.
|
||||||
|
*/
|
||||||
|
public function activeTripStatus(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$user = auth()->user();
|
||||||
|
if (!$user) {
|
||||||
|
return response()->json(['status' => 'unauthenticated'], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
$employee = $user->getOrCreateEmployee();
|
||||||
|
if (!$employee) {
|
||||||
|
return response()->json(['status' => 'no_employee', 'has_pending' => false]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$activityId = $request->query('activity_id');
|
||||||
|
|
||||||
|
$activity = null;
|
||||||
|
if ($activityId) {
|
||||||
|
$activity = VehicleActivity::with(['vehicle', 'gate', 'securityGuard'])
|
||||||
|
->where('driver_id', $employee->id)
|
||||||
|
->find($activityId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$activity) {
|
||||||
|
// Ambil tiket pending terbaru yang masih aktif
|
||||||
|
$activity = VehicleActivity::with(['vehicle', 'gate', 'securityGuard'])
|
||||||
|
->where('driver_id', $employee->id)
|
||||||
|
->where('validation_status', 'pending')
|
||||||
|
->latest('recorded_at')
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Jika masih null, ambil tiket paling akhir dari driver ini
|
||||||
|
if (!$activity) {
|
||||||
|
$activity = VehicleActivity::with(['vehicle', 'gate', 'securityGuard'])
|
||||||
|
->where('driver_id', $employee->id)
|
||||||
|
->latest('recorded_at')
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$activity) {
|
||||||
|
return response()->json([
|
||||||
|
'has_pending' => false,
|
||||||
|
'status' => 'none',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'id' => $activity->id,
|
||||||
|
'transaction_no' => $activity->transaction_no,
|
||||||
|
'vehicle_code' => $activity->vehicle?->code ?? '-',
|
||||||
|
'vehicle_name' => $activity->vehicle?->brand_type ?? '-',
|
||||||
|
'status' => $activity->validation_status,
|
||||||
|
'has_pending' => $activity->validation_status === 'pending',
|
||||||
|
'is_approved' => $activity->validation_status === 'approved',
|
||||||
|
'is_rejected' => $activity->validation_status === 'rejected',
|
||||||
|
'is_cancelled' => $activity->validation_status === 'cancelled',
|
||||||
|
'cancellation_source' => $activity->cancellation_source_label,
|
||||||
|
'gate_name' => $activity->gate?->name ?? 'Pos Gerbang',
|
||||||
|
'guard_name' => $activity->securityGuard?->name ?? 'Petugas Satpam',
|
||||||
|
'rejection_note' => $activity->rejection_note,
|
||||||
|
'recorded_at' => $activity->recorded_at ? $activity->recorded_at->format('H:i') . ' WIB' : null,
|
||||||
|
'validated_at' => $activity->validated_at ? $activity->validated_at->format('H:i') . ' WIB' : null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,9 +67,28 @@ class VerificationLogController extends Controller
|
|||||||
$query->where('direction', $request->input('direction'));
|
$query->where('direction', $request->input('direction'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter Status Verifikasi (approved, rejected, pending)
|
// Filter Status Verifikasi (approved, rejected, pending, cancelled, cancelled_system, cancelled_driver)
|
||||||
if ($request->filled('status')) {
|
if ($request->filled('status')) {
|
||||||
$query->where('validation_status', $request->input('status'));
|
$status = $request->input('status');
|
||||||
|
if ($status === 'cancelled_system') {
|
||||||
|
$query->where('validation_status', 'cancelled')
|
||||||
|
->where(function ($q) {
|
||||||
|
$q->where('rejection_note', 'like', '%sistem%')
|
||||||
|
->orWhere('rejection_note', 'like', '%timeout%')
|
||||||
|
->orWhere('rejection_note', 'like', '%melebihi batas%');
|
||||||
|
});
|
||||||
|
} elseif ($status === 'cancelled_driver') {
|
||||||
|
$query->where('validation_status', 'cancelled')
|
||||||
|
->where(function ($q) {
|
||||||
|
$q->where(function ($sub) {
|
||||||
|
$sub->where('rejection_note', 'not like', '%sistem%')
|
||||||
|
->where('rejection_note', 'not like', '%timeout%')
|
||||||
|
->where('rejection_note', 'not like', '%melebihi batas%');
|
||||||
|
})->orWhereNull('rejection_note');
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$query->where('validation_status', $status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter Kata Kunci Pencarian (No Transaksi, Petugas Satpam, Badge, Driver, NIK, Plat, Kode LV)
|
// Filter Kata Kunci Pencarian (No Transaksi, Petugas Satpam, Badge, Driver, NIK, Plat, Kode LV)
|
||||||
@@ -188,6 +207,7 @@ class VerificationLogController extends Controller
|
|||||||
$status = match($item->validation_status) {
|
$status = match($item->validation_status) {
|
||||||
'approved' => 'Disetujui',
|
'approved' => 'Disetujui',
|
||||||
'rejected' => 'Ditolak',
|
'rejected' => 'Ditolak',
|
||||||
|
'cancelled' => $item->cancellation_source_label,
|
||||||
default => 'Menunggu',
|
default => 'Menunggu',
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -285,6 +305,7 @@ class VerificationLogController extends Controller
|
|||||||
$status = match($item->validation_status) {
|
$status = match($item->validation_status) {
|
||||||
'approved' => 'Disetujui',
|
'approved' => 'Disetujui',
|
||||||
'rejected' => 'Ditolak' . ($item->rejection_note ? ' (' . $item->rejection_note . ')' : ''),
|
'rejected' => 'Ditolak' . ($item->rejection_note ? ' (' . $item->rejection_note . ')' : ''),
|
||||||
|
'cancelled' => $item->cancellation_source_label,
|
||||||
default => 'Menunggu',
|
default => 'Menunggu',
|
||||||
};
|
};
|
||||||
$odometer = number_format($item->current_km ?? 0, 0, ',', '.') . ' KM';
|
$odometer = number_format($item->current_km ?? 0, 0, ',', '.') . ' KM';
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ class VehicleActivityFormController extends Controller
|
|||||||
});
|
});
|
||||||
|
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('vehicle.activity.form', ['code' => $code])
|
->route('employee.dashboard')
|
||||||
->with('success', 'Aktivitas kendaraan berhasil dicatat! Silakan lapor ke petugas Satpam di pos gerbang untuk verifikasi fisik.');
|
->with('success', 'Form perjalanan berhasil dikirim! Silakan lapor ke petugas Satpam di pos gerbang untuk verifikasi fisik.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,9 +69,28 @@ class ActivityLogController extends Controller
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter Status Validasi (pending, approved, rejected)
|
// Filter Status Validasi (pending, approved, rejected, cancelled, cancelled_system, cancelled_driver)
|
||||||
if ($request->filled('status')) {
|
if ($request->filled('status')) {
|
||||||
$query->where('validation_status', $request->input('status'));
|
$status = $request->input('status');
|
||||||
|
if ($status === 'cancelled_system') {
|
||||||
|
$query->where('validation_status', 'cancelled')
|
||||||
|
->where(function (Builder $q) {
|
||||||
|
$q->where('rejection_note', 'like', '%sistem%')
|
||||||
|
->orWhere('rejection_note', 'like', '%timeout%')
|
||||||
|
->orWhere('rejection_note', 'like', '%melebihi batas%');
|
||||||
|
});
|
||||||
|
} elseif ($status === 'cancelled_driver') {
|
||||||
|
$query->where('validation_status', 'cancelled')
|
||||||
|
->where(function (Builder $q) {
|
||||||
|
$q->where(function (Builder $sub) {
|
||||||
|
$sub->where('rejection_note', 'not like', '%sistem%')
|
||||||
|
->where('rejection_note', 'not like', '%timeout%')
|
||||||
|
->where('rejection_note', 'not like', '%melebihi batas%');
|
||||||
|
})->orWhereNull('rejection_note');
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$query->where('validation_status', $status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
@@ -151,7 +170,12 @@ class ActivityLogController extends Controller
|
|||||||
$currKm = $act->current_km !== null ? number_format($act->current_km, 0, ',', '.') : '-';
|
$currKm = $act->current_km !== null ? number_format($act->current_km, 0, ',', '.') : '-';
|
||||||
$diffKm = $act->distance !== null ? number_format($act->distance, 0, ',', '.') : '-';
|
$diffKm = $act->distance !== null ? number_format($act->distance, 0, ',', '.') : '-';
|
||||||
$purpose = $act->purpose ?: '-';
|
$purpose = $act->purpose ?: '-';
|
||||||
$statusPg = $act->validation_status === 'approved' ? 'Disetujui' : ($act->validation_status === 'rejected' ? 'Ditolak' : ($act->validation_status === 'cancelled' ? 'Dibatalkan' : 'Menunggu PG'));
|
$statusPg = match($act->validation_status) {
|
||||||
|
'approved' => 'Disetujui',
|
||||||
|
'rejected' => 'Ditolak' . ($act->rejection_note ? ' (' . $act->rejection_note . ')' : ''),
|
||||||
|
'cancelled' => $act->cancellation_source_label,
|
||||||
|
default => 'Menunggu PG',
|
||||||
|
};
|
||||||
if ($act->is_corrected) {
|
if ($act->is_corrected) {
|
||||||
$statusPg .= ' (Terkoreksi)';
|
$statusPg .= ' (Terkoreksi)';
|
||||||
}
|
}
|
||||||
@@ -255,7 +279,12 @@ class ActivityLogController extends Controller
|
|||||||
$currKm = $act->current_km !== null ? number_format($act->current_km, 0, ',', '.') : '-';
|
$currKm = $act->current_km !== null ? number_format($act->current_km, 0, ',', '.') : '-';
|
||||||
$diffKm = $act->distance !== null ? number_format($act->distance, 0, ',', '.') . ' KM' : '-';
|
$diffKm = $act->distance !== null ? number_format($act->distance, 0, ',', '.') . ' KM' : '-';
|
||||||
$purpose = $act->purpose ?: '-';
|
$purpose = $act->purpose ?: '-';
|
||||||
$statusPg = $act->validation_status === 'approved' ? 'Disetujui' : ($act->validation_status === 'rejected' ? 'Ditolak' : ($act->validation_status === 'cancelled' ? 'Dibatalkan' : 'Menunggu PG'));
|
$statusPg = match($act->validation_status) {
|
||||||
|
'approved' => 'Disetujui',
|
||||||
|
'rejected' => 'Ditolak' . ($act->rejection_note ? ' (' . $act->rejection_note . ')' : ''),
|
||||||
|
'cancelled' => $act->cancellation_source_label,
|
||||||
|
default => 'Menunggu PG',
|
||||||
|
};
|
||||||
if ($act->is_corrected) {
|
if ($act->is_corrected) {
|
||||||
$statusPg .= ' (Terkoreksi)';
|
$statusPg .= ' (Terkoreksi)';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,6 +93,43 @@ class VehicleActivity extends Model
|
|||||||
return $this->validation_status === 'cancelled';
|
return $this->validation_status === 'cancelled';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cek apakah pembatalan dilakukan otomatis oleh sistem (timeout > 5 jam).
|
||||||
|
*/
|
||||||
|
public function isCancelledBySystem(): bool
|
||||||
|
{
|
||||||
|
if ($this->validation_status !== 'cancelled') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$note = strtolower((string) $this->rejection_note);
|
||||||
|
return str_contains($note, 'sistem') || str_contains($note, 'timeout') || str_contains($note, 'melebihi batas');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cek apakah pembatalan dilakukan mandiri oleh pengguna / driver.
|
||||||
|
*/
|
||||||
|
public function isCancelledByUser(): bool
|
||||||
|
{
|
||||||
|
return $this->validation_status === 'cancelled' && !$this->isCancelledBySystem();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Label sumber pembatalan yang deskriptif dan ramah pengguna.
|
||||||
|
*/
|
||||||
|
public function getCancellationSourceLabelAttribute(): string
|
||||||
|
{
|
||||||
|
if ($this->isCancelledBySystem()) {
|
||||||
|
return 'Batal Sistem (Timeout)';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->isCancelledByUser()) {
|
||||||
|
return 'Dibatalkan Pengemudi';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'Dibatalkan';
|
||||||
|
}
|
||||||
|
|
||||||
public function isRejected(): bool
|
public function isRejected(): bool
|
||||||
{
|
{
|
||||||
return $this->validation_status === 'rejected';
|
return $this->validation_status === 'rejected';
|
||||||
|
|||||||
@@ -59,7 +59,9 @@
|
|||||||
|
|
||||||
{{-- CARD PERJALANAN AKTIF (MENUNGGU PEMERIKSAAN SATPAM) --}}
|
{{-- CARD PERJALANAN AKTIF (MENUNGGU PEMERIKSAAN SATPAM) --}}
|
||||||
@if(isset($pendingActivity) && $pendingActivity)
|
@if(isset($pendingActivity) && $pendingActivity)
|
||||||
<div class="bg-gradient-to-br from-amber-500/10 via-amber-500/5 to-white border-2 border-amber-300/80 rounded-2xl p-5 sm:p-6 shadow-sm relative overflow-hidden">
|
<div id="pendingTripCard"
|
||||||
|
data-activity-id="{{ $pendingActivity->id }}"
|
||||||
|
class="bg-gradient-to-br from-amber-500/10 via-amber-500/5 to-white border-2 border-amber-300/80 rounded-2xl p-5 sm:p-6 shadow-sm relative overflow-hidden transition-all duration-300">
|
||||||
{{-- Dekorasi Latar Belakang --}}
|
{{-- Dekorasi Latar Belakang --}}
|
||||||
<div class="absolute -right-6 -bottom-6 text-amber-100/50 pointer-events-none text-9xl">
|
<div class="absolute -right-6 -bottom-6 text-amber-100/50 pointer-events-none text-9xl">
|
||||||
<i class="fa-solid fa-car-side"></i>
|
<i class="fa-solid fa-car-side"></i>
|
||||||
@@ -97,6 +99,11 @@
|
|||||||
<span class="w-2 h-2 rounded-full bg-amber-500 mr-1.5 -ml-3.5"></span>
|
<span class="w-2 h-2 rounded-full bg-amber-500 mr-1.5 -ml-3.5"></span>
|
||||||
Menunggu Pemeriksaan Satpam
|
Menunggu Pemeriksaan Satpam
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
<span class="inline-flex items-center px-2.5 py-1 rounded-full text-[10px] font-bold bg-emerald-50 text-emerald-800 border border-emerald-200 shadow-2xs" title="Sistem memantau persetujuan satpam secara otomatis tanpa refresh">
|
||||||
|
<span class="w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse mr-1.5"></span>
|
||||||
|
<span>Auto-Check Aktif</span>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -366,9 +373,23 @@
|
|||||||
<i class="fa-solid fa-circle-check mr-1 text-emerald-600"></i> Disetujui
|
<i class="fa-solid fa-circle-check mr-1 text-emerald-600"></i> Disetujui
|
||||||
</span>
|
</span>
|
||||||
@elseif($act->validation_status === 'cancelled')
|
@elseif($act->validation_status === 'cancelled')
|
||||||
<span class="inline-flex items-center px-2.5 py-1 rounded-lg text-[10px] font-bold bg-slate-100 text-slate-600 border border-slate-200" title="{{ $act->rejection_note }}">
|
@if($act->isCancelledBySystem())
|
||||||
<i class="fa-solid fa-ban mr-1 text-slate-400"></i> Dibatalkan
|
<div class="inline-flex flex-col items-center">
|
||||||
|
<span class="inline-flex items-center px-2 py-0.5 rounded-lg text-[10px] font-bold bg-amber-50 text-amber-800 border border-amber-200" title="{{ $act->rejection_note }}">
|
||||||
|
<i class="fa-solid fa-robot mr-1 text-amber-600"></i> Batal Sistem
|
||||||
</span>
|
</span>
|
||||||
|
<span class="text-[9px] text-amber-600 mt-0.5 font-medium">Timeout > 5 Jam</span>
|
||||||
|
</div>
|
||||||
|
@else
|
||||||
|
<div class="inline-flex flex-col items-center">
|
||||||
|
<span class="inline-flex items-center px-2 py-0.5 rounded-lg text-[10px] font-bold bg-slate-100 text-slate-700 border border-slate-200" title="{{ $act->rejection_note }}">
|
||||||
|
<i class="fa-solid fa-user-xmark mr-1 text-slate-500"></i> Batal Pengemudi
|
||||||
|
</span>
|
||||||
|
@if($act->rejection_note && $act->rejection_note !== 'Dibatalkan mandiri oleh pengemudi')
|
||||||
|
<span class="text-[9px] text-slate-500 mt-0.5 truncate max-w-[120px]" title="{{ $act->rejection_note }}">{{ $act->rejection_note }}</span>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
@elseif($act->validation_status === 'rejected')
|
@elseif($act->validation_status === 'rejected')
|
||||||
<span class="inline-flex items-center px-2.5 py-1 rounded-lg text-[10px] font-bold bg-rose-50 text-rose-700 border border-rose-200" title="Alasan: {{ $act->rejection_note }}">
|
<span class="inline-flex items-center px-2.5 py-1 rounded-lg text-[10px] font-bold bg-rose-50 text-rose-700 border border-rose-200" title="Alasan: {{ $act->rejection_note }}">
|
||||||
<i class="fa-solid fa-circle-xmark mr-1 text-rose-600"></i> Ditolak
|
<i class="fa-solid fa-circle-xmark mr-1 text-rose-600"></i> Ditolak
|
||||||
@@ -590,6 +611,54 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{-- MODAL 4: NOTIFIKASI HASIL VALIDASI POS GERBANG (POLLING REAL-TIME) --}}
|
||||||
|
<div id="validationNotificationModal"
|
||||||
|
class="hidden fixed inset-0 z-50 bg-slate-900/70 backdrop-blur-xs flex items-center justify-center p-4 overflow-y-auto"
|
||||||
|
aria-labelledby="validationNotificationTitle" role="dialog" aria-modal="true">
|
||||||
|
<div id="validationNotificationCard" class="relative z-10 bg-white rounded-2xl max-w-md w-full shadow-2xl border border-slate-200 overflow-hidden transform transition-all duration-300 scale-95">
|
||||||
|
<div id="validationNotificationBanner" class="p-6 text-center text-white bg-gradient-to-br from-emerald-600 to-[#1b5e20]">
|
||||||
|
<div id="validationNotificationIcon" class="w-16 h-16 mx-auto rounded-full bg-white/20 flex items-center justify-center text-3xl mb-3 shadow-inner">
|
||||||
|
<i class="fa-solid fa-circle-check text-emerald-100"></i>
|
||||||
|
</div>
|
||||||
|
<h3 id="validationNotificationTitle" class="text-lg font-black tracking-tight">Perjalanan Disetujui!</h3>
|
||||||
|
<p id="validationNotificationSubtitle" class="text-xs text-white/90 mt-1">Verifikasi di Pos Gerbang Berhasil</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="p-6 space-y-4">
|
||||||
|
<div class="bg-slate-50 rounded-xl p-4 border border-slate-200/80 text-xs space-y-2.5">
|
||||||
|
<div class="flex justify-between items-center pb-2 border-b border-slate-200/60">
|
||||||
|
<span class="text-slate-400 font-medium">No. Transaksi:</span>
|
||||||
|
<span id="validationTrxNo" class="font-mono font-bold text-slate-800">-</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-between items-center pb-2 border-b border-slate-200/60">
|
||||||
|
<span class="text-slate-400 font-medium">Unit Kendaraan:</span>
|
||||||
|
<span id="validationVehicle" class="font-bold text-slate-800">-</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-between items-center pb-2 border-b border-slate-200/60">
|
||||||
|
<span class="text-slate-400 font-medium">Pos Gerbang:</span>
|
||||||
|
<span id="validationGate" class="font-bold text-slate-800">-</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-between items-center">
|
||||||
|
<span class="text-slate-400 font-medium">Petugas Satpam:</span>
|
||||||
|
<span id="validationGuard" class="font-bold text-slate-800">-</span>
|
||||||
|
</div>
|
||||||
|
<div id="validationNoteRow" class="pt-2 border-t border-slate-200 hidden">
|
||||||
|
<span class="text-slate-400 font-medium block mb-1">Catatan Penolakan:</span>
|
||||||
|
<p id="validationNote" class="text-slate-700 italic bg-white p-2.5 rounded-lg border border-slate-200 text-[11px]">-</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="button"
|
||||||
|
id="validationDismissBtn"
|
||||||
|
onclick="handleValidationDismiss()"
|
||||||
|
class="w-full bg-[#1b5e20] hover:bg-[#144918] active:scale-[0.99] text-white font-bold py-3 px-4 rounded-xl text-xs sm:text-sm shadow-md transition flex items-center justify-center space-x-2 cursor-pointer">
|
||||||
|
<span>Lanjutkan ke Dashboard</span>
|
||||||
|
<i class="fa-solid fa-arrow-right text-xs"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
#qr-reader {
|
#qr-reader {
|
||||||
border: none !important;
|
border: none !important;
|
||||||
@@ -819,5 +888,126 @@
|
|||||||
setInterval(updateTripCountdown, 1000);
|
setInterval(updateTripCountdown, 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Real-Time Lightweight Polling untuk Memantau Status Validasi Pos Gerbang
|
||||||
|
const pendingTripCard = document.getElementById('pendingTripCard');
|
||||||
|
if (pendingTripCard) {
|
||||||
|
const activityId = pendingTripCard.getAttribute('data-activity-id');
|
||||||
|
let pollingTimer = null;
|
||||||
|
let isPollingInProgress = false;
|
||||||
|
|
||||||
|
async function pollTripStatus() {
|
||||||
|
// Jangan lakukan polling jika tab sedang di-minimize/background untuk hemat resource
|
||||||
|
if (document.hidden) return;
|
||||||
|
if (isPollingInProgress) return;
|
||||||
|
|
||||||
|
isPollingInProgress = true;
|
||||||
|
try {
|
||||||
|
const response = await fetch(`{{ route('employee.activity.status_polling') }}?activity_id=${activityId}`, {
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'X-Requested-With': 'XMLHttpRequest'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
isPollingInProgress = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
isPollingInProgress = false;
|
||||||
|
|
||||||
|
// Jika status sudah berubah dari pending, hentikan polling dan tampilkan notifikasi
|
||||||
|
if (data && data.status && data.status !== 'pending') {
|
||||||
|
if (pollingTimer) {
|
||||||
|
clearInterval(pollingTimer);
|
||||||
|
pollingTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
showValidationNotification(data);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
isPollingInProgress = false;
|
||||||
|
// Supresi error jaringan agar tidak mengganggu driver
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Jalankan polling ringan berkala setiap 4 detik
|
||||||
|
pollingTimer = setInterval(pollTripStatus, 4000);
|
||||||
|
|
||||||
|
// Jika user kembali ke tab browser, langsung cek status 1 kali
|
||||||
|
document.addEventListener('visibilitychange', () => {
|
||||||
|
if (!document.hidden && pollingTimer) {
|
||||||
|
pollTripStatus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function showValidationNotification(data) {
|
||||||
|
const modal = document.getElementById('validationNotificationModal');
|
||||||
|
const card = document.getElementById('validationNotificationCard');
|
||||||
|
const banner = document.getElementById('validationNotificationBanner');
|
||||||
|
const icon = document.getElementById('validationNotificationIcon');
|
||||||
|
const title = document.getElementById('validationNotificationTitle');
|
||||||
|
const subtitle = document.getElementById('validationNotificationSubtitle');
|
||||||
|
const trxNo = document.getElementById('validationTrxNo');
|
||||||
|
const vehicle = document.getElementById('validationVehicle');
|
||||||
|
const gate = document.getElementById('validationGate');
|
||||||
|
const guard = document.getElementById('validationGuard');
|
||||||
|
const noteRow = document.getElementById('validationNoteRow');
|
||||||
|
const note = document.getElementById('validationNote');
|
||||||
|
const dismissBtn = document.getElementById('validationDismissBtn');
|
||||||
|
|
||||||
|
if (!modal) return;
|
||||||
|
|
||||||
|
trxNo.textContent = data.transaction_no || '-';
|
||||||
|
vehicle.textContent = `${data.vehicle_code} (${data.vehicle_name})`;
|
||||||
|
gate.textContent = data.gate_name || 'Pos Gerbang';
|
||||||
|
guard.textContent = data.guard_name || 'Petugas Satpam';
|
||||||
|
|
||||||
|
if (data.is_approved) {
|
||||||
|
banner.className = 'p-6 text-center text-white bg-gradient-to-br from-emerald-600 to-[#1b5e20]';
|
||||||
|
icon.innerHTML = '<i class="fa-solid fa-circle-check text-emerald-100"></i>';
|
||||||
|
title.textContent = 'Perjalanan Disetujui!';
|
||||||
|
subtitle.textContent = `Pemeriksaan selesai oleh Satpam ${data.guard_name} pada ${data.validated_at || 'hari ini'}`;
|
||||||
|
dismissBtn.className = 'w-full bg-[#1b5e20] hover:bg-[#144918] text-white font-bold py-3 px-4 rounded-xl text-xs sm:text-sm shadow-md transition flex items-center justify-center space-x-2 cursor-pointer';
|
||||||
|
dismissBtn.innerHTML = '<span>Lanjutkan Perjalanan (OK)</span><i class="fa-solid fa-arrow-right text-xs"></i>';
|
||||||
|
noteRow.classList.add('hidden');
|
||||||
|
} else if (data.is_rejected) {
|
||||||
|
banner.className = 'p-6 text-center text-white bg-gradient-to-br from-rose-600 to-rose-800';
|
||||||
|
icon.innerHTML = '<i class="fa-solid fa-circle-xmark text-rose-100"></i>';
|
||||||
|
title.textContent = 'Perjalanan Ditolak';
|
||||||
|
subtitle.textContent = `Ditolak oleh Satpam ${data.guard_name} di ${data.gate_name}`;
|
||||||
|
dismissBtn.className = 'w-full bg-rose-700 hover:bg-rose-800 text-white font-bold py-3 px-4 rounded-xl text-xs sm:text-sm shadow-md transition flex items-center justify-center space-x-2 cursor-pointer';
|
||||||
|
dismissBtn.innerHTML = '<span>Tutup & Periksa Dashboard</span>';
|
||||||
|
if (data.rejection_note) {
|
||||||
|
note.textContent = data.rejection_note;
|
||||||
|
noteRow.classList.remove('hidden');
|
||||||
|
}
|
||||||
|
} else if (data.is_cancelled) {
|
||||||
|
banner.className = 'p-6 text-center text-white bg-gradient-to-br from-amber-600 to-amber-800';
|
||||||
|
icon.innerHTML = '<i class="fa-solid fa-ban text-amber-100"></i>';
|
||||||
|
title.textContent = data.cancellation_source || 'Perjalanan Dibatalkan';
|
||||||
|
subtitle.textContent = 'Status tiket perjalanan telah dibatalkan';
|
||||||
|
dismissBtn.className = 'w-full bg-slate-700 hover:bg-slate-800 text-white font-bold py-3 px-4 rounded-xl text-xs sm:text-sm shadow-md transition flex items-center justify-center space-x-2 cursor-pointer';
|
||||||
|
dismissBtn.innerHTML = '<span>Tutup</span>';
|
||||||
|
if (data.rejection_note) {
|
||||||
|
note.textContent = data.rejection_note;
|
||||||
|
noteRow.classList.remove('hidden');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
modal.classList.remove('hidden');
|
||||||
|
setTimeout(() => {
|
||||||
|
card.classList.remove('scale-95');
|
||||||
|
card.classList.add('scale-100');
|
||||||
|
}, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleValidationDismiss() {
|
||||||
|
// Refresh halus setelah driver klik agar state tabel tersinkron permanen
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
|||||||
@@ -193,6 +193,9 @@
|
|||||||
<option value="">Semua Status</option>
|
<option value="">Semua Status</option>
|
||||||
<option value="approved" {{ request('status') === 'approved' ? 'selected' : '' }}>Disetujui (Approved)</option>
|
<option value="approved" {{ request('status') === 'approved' ? 'selected' : '' }}>Disetujui (Approved)</option>
|
||||||
<option value="pending" {{ request('status') === 'pending' ? 'selected' : '' }}>Menunggu (Pending)</option>
|
<option value="pending" {{ request('status') === 'pending' ? 'selected' : '' }}>Menunggu (Pending)</option>
|
||||||
|
<option value="cancelled_system" {{ request('status') === 'cancelled_system' ? 'selected' : '' }}>Batal Sistem (Timeout)</option>
|
||||||
|
<option value="cancelled_driver" {{ request('status') === 'cancelled_driver' ? 'selected' : '' }}>Dibatalkan Pengemudi</option>
|
||||||
|
<option value="cancelled" {{ request('status') === 'cancelled' ? 'selected' : '' }}>Semua Dibatalkan</option>
|
||||||
<option value="rejected" {{ request('status') === 'rejected' ? 'selected' : '' }}>Ditolak (Rejected)</option>
|
<option value="rejected" {{ request('status') === 'rejected' ? 'selected' : '' }}>Ditolak (Rejected)</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@@ -394,10 +397,21 @@
|
|||||||
<span>Disetujui</span>
|
<span>Disetujui</span>
|
||||||
</span>
|
</span>
|
||||||
@elseif($item->validation_status === 'cancelled')
|
@elseif($item->validation_status === 'cancelled')
|
||||||
|
@if($item->isCancelledBySystem())
|
||||||
|
<div>
|
||||||
|
<span class="inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-[11px] font-bold bg-amber-100 text-amber-800" title="{{ $item->rejection_note }}">
|
||||||
|
<i class="fa-solid fa-robot text-[10px] text-amber-600"></i>
|
||||||
|
<span>Batal Sistem</span>
|
||||||
|
</span>
|
||||||
|
<p class="text-[10px] text-amber-700 max-w-xs truncate mx-auto mt-0.5">
|
||||||
|
Timeout > 5 Jam
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
@else
|
||||||
<div>
|
<div>
|
||||||
<span class="inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-[11px] font-bold bg-slate-100 text-slate-700" title="{{ $item->rejection_note }}">
|
<span class="inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-[11px] font-bold bg-slate-100 text-slate-700" title="{{ $item->rejection_note }}">
|
||||||
<i class="fa-solid fa-ban text-[10px] text-slate-400"></i>
|
<i class="fa-solid fa-user-xmark text-[10px] text-slate-500"></i>
|
||||||
<span>Dibatalkan</span>
|
<span>Batal Pengemudi</span>
|
||||||
</span>
|
</span>
|
||||||
@if($item->rejection_note)
|
@if($item->rejection_note)
|
||||||
<p class="text-[10px] text-slate-500 max-w-xs truncate mx-auto mt-0.5" title="{{ $item->rejection_note }}">
|
<p class="text-[10px] text-slate-500 max-w-xs truncate mx-auto mt-0.5" title="{{ $item->rejection_note }}">
|
||||||
@@ -405,6 +419,7 @@
|
|||||||
</p>
|
</p>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
@endif
|
||||||
@elseif($item->validation_status === 'rejected')
|
@elseif($item->validation_status === 'rejected')
|
||||||
<div>
|
<div>
|
||||||
<span class="inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-[11px] font-bold bg-rose-100 text-rose-800" title="{{ $item->rejection_note }}">
|
<span class="inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-[11px] font-bold bg-rose-100 text-rose-800" title="{{ $item->rejection_note }}">
|
||||||
|
|||||||
@@ -188,6 +188,10 @@
|
|||||||
<option value="">Semua Status</option>
|
<option value="">Semua Status</option>
|
||||||
<option value="approved" {{ request('status') === 'approved' ? 'selected' : '' }}>Disetujui</option>
|
<option value="approved" {{ request('status') === 'approved' ? 'selected' : '' }}>Disetujui</option>
|
||||||
<option value="pending" {{ request('status') === 'pending' ? 'selected' : '' }}>Menunggu PG</option>
|
<option value="pending" {{ request('status') === 'pending' ? 'selected' : '' }}>Menunggu PG</option>
|
||||||
|
<option value="cancelled_system" {{ request('status') === 'cancelled_system' ? 'selected' : '' }}>Batal Sistem (Timeout)</option>
|
||||||
|
<option value="cancelled_driver" {{ request('status') === 'cancelled_driver' ? 'selected' : '' }}>Dibatalkan Pengemudi</option>
|
||||||
|
<option value="cancelled" {{ request('status') === 'cancelled' ? 'selected' : '' }}>Semua Dibatalkan</option>
|
||||||
|
<option value="rejected" {{ request('status') === 'rejected' ? 'selected' : '' }}>Ditolak</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -311,9 +315,23 @@
|
|||||||
<i class="fa-solid fa-circle-check mr-1 text-emerald-600"></i> Disetujui
|
<i class="fa-solid fa-circle-check mr-1 text-emerald-600"></i> Disetujui
|
||||||
</span>
|
</span>
|
||||||
@elseif($act->validation_status === 'cancelled')
|
@elseif($act->validation_status === 'cancelled')
|
||||||
<span class="inline-flex items-center px-2.5 py-1 rounded-lg text-[10px] font-bold bg-slate-100 text-slate-600 border border-slate-200" title="{{ $act->rejection_note }}">
|
@if($act->isCancelledBySystem())
|
||||||
<i class="fa-solid fa-ban mr-1 text-slate-400"></i> Dibatalkan
|
<div class="inline-flex flex-col items-center">
|
||||||
|
<span class="inline-flex items-center px-2 py-0.5 rounded-lg text-[10px] font-bold bg-amber-50 text-amber-800 border border-amber-200" title="{{ $act->rejection_note }}">
|
||||||
|
<i class="fa-solid fa-robot mr-1 text-amber-600"></i> Batal Sistem
|
||||||
</span>
|
</span>
|
||||||
|
<span class="text-[9px] text-amber-600 mt-0.5 font-medium">Timeout > 5 Jam</span>
|
||||||
|
</div>
|
||||||
|
@else
|
||||||
|
<div class="inline-flex flex-col items-center">
|
||||||
|
<span class="inline-flex items-center px-2 py-0.5 rounded-lg text-[10px] font-bold bg-slate-100 text-slate-700 border border-slate-200" title="{{ $act->rejection_note }}">
|
||||||
|
<i class="fa-solid fa-user-xmark mr-1 text-slate-500"></i> Batal Pengemudi
|
||||||
|
</span>
|
||||||
|
@if($act->rejection_note && $act->rejection_note !== 'Dibatalkan mandiri oleh pengemudi')
|
||||||
|
<span class="text-[9px] text-slate-500 mt-0.5 truncate max-w-[120px]" title="{{ $act->rejection_note }}">{{ $act->rejection_note }}</span>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
@elseif($act->validation_status === 'rejected')
|
@elseif($act->validation_status === 'rejected')
|
||||||
<span class="inline-flex items-center px-2.5 py-1 rounded-lg text-[10px] font-bold bg-rose-50 text-rose-700 border border-rose-200" title="Alasan: {{ $act->rejection_note }}">
|
<span class="inline-flex items-center px-2.5 py-1 rounded-lg text-[10px] font-bold bg-rose-50 text-rose-700 border border-rose-200" title="Alasan: {{ $act->rejection_note }}">
|
||||||
<i class="fa-solid fa-circle-xmark mr-1 text-rose-600"></i> Ditolak
|
<i class="fa-solid fa-circle-xmark mr-1 text-rose-600"></i> Ditolak
|
||||||
|
|||||||
@@ -178,6 +178,7 @@ Route::middleware('auth')->group(function () {
|
|||||||
|
|
||||||
// 6. Modul Karyawan (Dashboard, P2H, Timesheet)
|
// 6. Modul Karyawan (Dashboard, P2H, Timesheet)
|
||||||
Route::get('/karyawan/dashboard', [\App\Http\Controllers\Employee\DashboardController::class, 'index'])->name('employee.dashboard');
|
Route::get('/karyawan/dashboard', [\App\Http\Controllers\Employee\DashboardController::class, 'index'])->name('employee.dashboard');
|
||||||
|
Route::get('/karyawan/aktivitas/status-polling', [\App\Http\Controllers\Employee\DashboardController::class, 'activeTripStatus'])->name('employee.activity.status_polling');
|
||||||
Route::post('/karyawan/aktivitas/{id}/update-km', [\App\Http\Controllers\Employee\DashboardController::class, 'updateKm'])->name('employee.activity.update_km');
|
Route::post('/karyawan/aktivitas/{id}/update-km', [\App\Http\Controllers\Employee\DashboardController::class, 'updateKm'])->name('employee.activity.update_km');
|
||||||
Route::post('/karyawan/aktivitas/{id}/cancel', [\App\Http\Controllers\Employee\DashboardController::class, 'cancelActivity'])->name('employee.activity.cancel');
|
Route::post('/karyawan/aktivitas/{id}/cancel', [\App\Http\Controllers\Employee\DashboardController::class, 'cancelActivity'])->name('employee.activity.cancel');
|
||||||
Route::get('/timesheet', [VehicleActivityFormController::class, 'index'])->name('timesheet.index')->middleware('permission:employee.timesheet|qma.vehicles.view');
|
Route::get('/timesheet', [VehicleActivityFormController::class, 'index'])->name('timesheet.index')->middleware('permission:employee.timesheet|qma.vehicles.view');
|
||||||
|
|||||||
@@ -0,0 +1,254 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Models\Employee;
|
||||||
|
use App\Models\Gate;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Models\Vehicle;
|
||||||
|
use App\Models\VehicleActivity;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Database\Seeders\RolePermissionSeeder;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class TripPollingAndCancellationDistinctionTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
protected User $driverUser;
|
||||||
|
protected Employee $driver;
|
||||||
|
protected Vehicle $vehicle;
|
||||||
|
protected Gate $gate;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->seed(RolePermissionSeeder::class);
|
||||||
|
|
||||||
|
$this->gate = Gate::create([
|
||||||
|
'code' => 'GATE-01',
|
||||||
|
'name' => 'Pos Gerbang Utama',
|
||||||
|
'location' => 'Main Gate Site',
|
||||||
|
'is_active' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->vehicle = Vehicle::create([
|
||||||
|
'category' => 'light_vehicle',
|
||||||
|
'code' => 'LV-TEST-01',
|
||||||
|
'brand_type' => 'Toyota Hilux 2.4G',
|
||||||
|
'license_plate' => 'BH 1234 XX',
|
||||||
|
'division' => 'Operasional',
|
||||||
|
'ownership' => 'PT KMH',
|
||||||
|
'status' => 'Operation',
|
||||||
|
'current_km' => 1000.0,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->driver = Employee::create([
|
||||||
|
'name' => 'Bambang Supriadi',
|
||||||
|
'nik' => 'DRV-999',
|
||||||
|
'position' => 'Driver',
|
||||||
|
'division' => 'Operasional',
|
||||||
|
'is_operator' => true,
|
||||||
|
'simper_expired_at' => Carbon::now()->addMonths(6),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->driverUser = User::factory()->create([
|
||||||
|
'username' => 'DRV-999',
|
||||||
|
'name' => 'Bambang Supriadi',
|
||||||
|
]);
|
||||||
|
$this->driver->update(['user_id' => $this->driverUser->id]);
|
||||||
|
$this->driverUser->assignRole('employee');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1. Pengisian formulir aktivitas kendaraan langsung me-redirect ke employee dashboard.
|
||||||
|
*/
|
||||||
|
public function test_submitting_vehicle_activity_redirects_to_employee_dashboard(): void
|
||||||
|
{
|
||||||
|
$direction = $this->vehicle->determineNextAllowedDirection();
|
||||||
|
if ($direction === 'ANY') {
|
||||||
|
$direction = 'out';
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = $this->actingAs($this->driverUser)->post("/gate-activity/{$this->vehicle->code}", [
|
||||||
|
'driver_id' => $this->driver->id,
|
||||||
|
'gate_id' => $this->gate->id,
|
||||||
|
'direction' => $direction,
|
||||||
|
'current_km' => 1025.0,
|
||||||
|
'purpose' => 'Mobilisasi dinas operasional site',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertRedirect(route('employee.dashboard'));
|
||||||
|
$response->assertSessionHas('success');
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('vehicle_activities', [
|
||||||
|
'vehicle_id' => $this->vehicle->id,
|
||||||
|
'driver_id' => $this->driver->id,
|
||||||
|
'validation_status' => 'pending',
|
||||||
|
'purpose' => 'Mobilisasi dinas operasional site',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2. Status pembatalan membedakan antara dibatalkan sistem (timeout) vs dibatalkan pengemudi.
|
||||||
|
*/
|
||||||
|
public function test_distinguishes_cancellation_source(): void
|
||||||
|
{
|
||||||
|
// A. Tiket dibatalkan sistem
|
||||||
|
$systemCancelled = VehicleActivity::create([
|
||||||
|
'transaction_no' => 'TRX-TEST-SYS01',
|
||||||
|
'vehicle_id' => $this->vehicle->id,
|
||||||
|
'driver_id' => $this->driver->id,
|
||||||
|
'gate_id' => $this->gate->id,
|
||||||
|
'direction' => 'out',
|
||||||
|
'previous_km' => 1000,
|
||||||
|
'current_km' => 1020,
|
||||||
|
'distance' => 20,
|
||||||
|
'purpose' => 'Test timeout',
|
||||||
|
'recorded_at' => Carbon::now()->subHours(6),
|
||||||
|
'validation_status' => 'cancelled',
|
||||||
|
'rejection_note' => 'Dibatalkan sistem: Melebihi batas waktu verifikasi (5 jam)',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertTrue($systemCancelled->isCancelled());
|
||||||
|
$this->assertTrue($systemCancelled->isCancelledBySystem());
|
||||||
|
$this->assertFalse($systemCancelled->isCancelledByUser());
|
||||||
|
$this->assertEquals('Batal Sistem (Timeout)', $systemCancelled->cancellation_source_label);
|
||||||
|
|
||||||
|
// B. Tiket dibatalkan mandiri oleh driver
|
||||||
|
$driverCancelled = VehicleActivity::create([
|
||||||
|
'transaction_no' => 'TRX-TEST-DRV01',
|
||||||
|
'vehicle_id' => $this->vehicle->id,
|
||||||
|
'driver_id' => $this->driver->id,
|
||||||
|
'gate_id' => $this->gate->id,
|
||||||
|
'direction' => 'out',
|
||||||
|
'previous_km' => 1000,
|
||||||
|
'current_km' => 1020,
|
||||||
|
'distance' => 20,
|
||||||
|
'purpose' => 'Test batal mandiri',
|
||||||
|
'recorded_at' => Carbon::now(),
|
||||||
|
'validation_status' => 'cancelled',
|
||||||
|
'rejection_note' => 'Salah input tujuan operasional',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertTrue($driverCancelled->isCancelled());
|
||||||
|
$this->assertFalse($driverCancelled->isCancelledBySystem());
|
||||||
|
$this->assertTrue($driverCancelled->isCancelledByUser());
|
||||||
|
$this->assertEquals('Dibatalkan Pengemudi', $driverCancelled->cancellation_source_label);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 3. Endpoint polling status tiket mengembalikan data JSON micro-response yang valid.
|
||||||
|
*/
|
||||||
|
public function test_active_trip_status_polling_endpoint(): void
|
||||||
|
{
|
||||||
|
$pendingActivity = VehicleActivity::create([
|
||||||
|
'transaction_no' => 'TRX-POLL-001',
|
||||||
|
'vehicle_id' => $this->vehicle->id,
|
||||||
|
'driver_id' => $this->driver->id,
|
||||||
|
'gate_id' => $this->gate->id,
|
||||||
|
'direction' => 'out',
|
||||||
|
'previous_km' => 1000,
|
||||||
|
'current_km' => 1030,
|
||||||
|
'distance' => 30,
|
||||||
|
'purpose' => 'Uji endpoint polling',
|
||||||
|
'recorded_at' => Carbon::now(),
|
||||||
|
'validation_status' => 'pending',
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Cek status saat masih pending
|
||||||
|
$response = $this->actingAs($this->driverUser)
|
||||||
|
->getJson(route('employee.activity.status_polling', ['activity_id' => $pendingActivity->id]));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
$response->assertJson([
|
||||||
|
'id' => $pendingActivity->id,
|
||||||
|
'transaction_no' => 'TRX-POLL-001',
|
||||||
|
'status' => 'pending',
|
||||||
|
'has_pending' => true,
|
||||||
|
'is_approved' => false,
|
||||||
|
'is_rejected' => false,
|
||||||
|
'is_cancelled' => false,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Ubah menjadi approved oleh PG
|
||||||
|
$pendingActivity->update([
|
||||||
|
'validation_status' => 'approved',
|
||||||
|
'validated_at' => Carbon::now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$responseApproved = $this->actingAs($this->driverUser)
|
||||||
|
->getJson(route('employee.activity.status_polling', ['activity_id' => $pendingActivity->id]));
|
||||||
|
|
||||||
|
$responseApproved->assertOk();
|
||||||
|
$responseApproved->assertJson([
|
||||||
|
'id' => $pendingActivity->id,
|
||||||
|
'status' => 'approved',
|
||||||
|
'has_pending' => false,
|
||||||
|
'is_approved' => true,
|
||||||
|
'is_rejected' => false,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 4. Filter log aktivitas dapat menyaring tiket dibatalkan sistem vs dibatalkan pengemudi.
|
||||||
|
*/
|
||||||
|
public function test_filter_logs_by_cancellation_sources(): void
|
||||||
|
{
|
||||||
|
$qmaUser = User::factory()->create();
|
||||||
|
$qmaUser->assignRole('qma_admin');
|
||||||
|
|
||||||
|
// Tiket Sistem
|
||||||
|
VehicleActivity::create([
|
||||||
|
'transaction_no' => 'TRX-FLT-SYS',
|
||||||
|
'vehicle_id' => $this->vehicle->id,
|
||||||
|
'driver_id' => $this->driver->id,
|
||||||
|
'gate_id' => $this->gate->id,
|
||||||
|
'direction' => 'out',
|
||||||
|
'previous_km' => 1000,
|
||||||
|
'current_km' => 1010,
|
||||||
|
'distance' => 10,
|
||||||
|
'purpose' => 'Aktivitas Timeout',
|
||||||
|
'recorded_at' => Carbon::now(),
|
||||||
|
'validation_status' => 'cancelled',
|
||||||
|
'rejection_note' => 'Dibatalkan sistem: Melebihi batas waktu verifikasi (5 jam)',
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Tiket Pengemudi
|
||||||
|
VehicleActivity::create([
|
||||||
|
'transaction_no' => 'TRX-FLT-DRV',
|
||||||
|
'vehicle_id' => $this->vehicle->id,
|
||||||
|
'driver_id' => $this->driver->id,
|
||||||
|
'gate_id' => $this->gate->id,
|
||||||
|
'direction' => 'out',
|
||||||
|
'previous_km' => 1010,
|
||||||
|
'current_km' => 1020,
|
||||||
|
'distance' => 10,
|
||||||
|
'purpose' => 'Aktivitas Batal Sopir',
|
||||||
|
'recorded_at' => Carbon::now(),
|
||||||
|
'validation_status' => 'cancelled',
|
||||||
|
'rejection_note' => 'Dibatalkan mandiri oleh pengemudi',
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Filter cancelled_system
|
||||||
|
$responseSys = $this->actingAs($qmaUser)->get(route('qma.activity.log', [
|
||||||
|
'status' => 'cancelled_system',
|
||||||
|
'start_date' => Carbon::today()->toDateString(),
|
||||||
|
'end_date' => Carbon::today()->toDateString(),
|
||||||
|
]));
|
||||||
|
$responseSys->assertOk();
|
||||||
|
$responseSys->assertSee('TRX-FLT-SYS');
|
||||||
|
$responseSys->assertDontSee('TRX-FLT-DRV');
|
||||||
|
|
||||||
|
// Filter cancelled_driver
|
||||||
|
$responseDrv = $this->actingAs($qmaUser)->get(route('qma.activity.log', [
|
||||||
|
'status' => 'cancelled_driver',
|
||||||
|
'start_date' => Carbon::today()->toDateString(),
|
||||||
|
'end_date' => Carbon::today()->toDateString(),
|
||||||
|
]));
|
||||||
|
$responseDrv->assertOk();
|
||||||
|
$responseDrv->assertSee('TRX-FLT-DRV');
|
||||||
|
$responseDrv->assertDontSee('TRX-FLT-SYS');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user