feat: add 5-hour trip expiration timer and rbac activity deletion permissions
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\VehicleActivity;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class ExpirePendingActivitiesCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'activities:expire-pending {--hours=5 : Batas maksimal jam menunggu verifikasi}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Batalkan otomatis tiket perjalanan pending yang melebihi batas waktu verifikasi (default 5 jam)';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$hours = (int) $this->option('hours');
|
||||
if ($hours <= 0) {
|
||||
$hours = VehicleActivity::PENDING_TIMEOUT_HOURS;
|
||||
}
|
||||
|
||||
$this->info("Memeriksa tiket perjalanan pending yang berusia lebih dari {$hours} jam...");
|
||||
|
||||
$affected = VehicleActivity::expireOverduePendingActivities($hours);
|
||||
|
||||
$this->info("Selesai: Sebanyak {$affected} tiket perjalanan berhasil dibatalkan otomatis.");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,9 @@ class DashboardController extends Controller
|
||||
$myRecentActivities = collect();
|
||||
|
||||
if ($employee) {
|
||||
// Otomatis batalkan perjalanan pending yang sudah melewati batas waktu 5 jam
|
||||
VehicleActivity::expireOverduePendingActivities();
|
||||
|
||||
$pendingActivity = VehicleActivity::with(['vehicle', 'gate'])
|
||||
->where('driver_id', $employee->id)
|
||||
->where('validation_status', 'pending')
|
||||
|
||||
@@ -46,6 +46,9 @@ class GateInspectionController extends Controller
|
||||
$needsGateSelection = true;
|
||||
}
|
||||
|
||||
// Otomatis bersihkan antrean pending yang sudah lewat batas 5 jam
|
||||
VehicleActivity::expireOverduePendingActivities();
|
||||
|
||||
$pendingActivities = collect();
|
||||
if ($gate) {
|
||||
$pendingActivities = VehicleActivity::where('gate_id', $gate->id)
|
||||
@@ -112,6 +115,9 @@ class GateInspectionController extends Controller
|
||||
?: ($user ? $user->gate_id : null);
|
||||
$gate = $gateId ? Gate::find($gateId) : Gate::first();
|
||||
|
||||
// Otomatis bersihkan antrean pending yang sudah lewat batas 5 jam
|
||||
VehicleActivity::expireOverduePendingActivities();
|
||||
|
||||
$pendingActivities = collect();
|
||||
if ($gate) {
|
||||
$pendingActivities = VehicleActivity::where('gate_id', $gate->id)
|
||||
|
||||
@@ -3,13 +3,16 @@
|
||||
namespace App\Http\Controllers\Pg;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\AdminActivityLog;
|
||||
use App\Models\Gate;
|
||||
use App\Models\SecurityGuard;
|
||||
use App\Models\VehicleActivity;
|
||||
use App\Services\PgTablePdfExporter;
|
||||
use App\Services\SimpleXlsxExporter;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\View\View;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
@@ -20,6 +23,9 @@ class VerificationLogController extends Controller
|
||||
*/
|
||||
protected function getVerificationLogsQuery(Request $request)
|
||||
{
|
||||
// Otomatis batalkan antrean pending yang melewati batas 5 jam
|
||||
VehicleActivity::expireOverduePendingActivities();
|
||||
|
||||
$query = VehicleActivity::with(['vehicle', 'driver', 'gate', 'securityGuard'])
|
||||
->orderByRaw('COALESCE(validated_at, recorded_at) DESC');
|
||||
|
||||
@@ -314,4 +320,60 @@ class VerificationLogController extends Controller
|
||||
'Content-Disposition' => 'inline; filename="' . $fileName . '"',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hapus riwayat log verifikasi gerbang oleh Admin yang berwenang.
|
||||
*/
|
||||
public function destroy(int $id): RedirectResponse
|
||||
{
|
||||
$activity = VehicleActivity::with(['vehicle', 'driver', 'gate', 'securityGuard'])->findOrFail($id);
|
||||
|
||||
$vehicleCode = $activity->vehicle?->code ?? '-';
|
||||
$trxNo = $activity->transaction_no;
|
||||
$driverName = $activity->driver?->name ?? 'Pengemudi';
|
||||
$gateName = $activity->gate?->name ?? 'Gerbang';
|
||||
|
||||
DB::transaction(function () use ($activity, $vehicleCode, $trxNo, $driverName, $gateName) {
|
||||
// Jika aktivitas yang dihapus adalah aktivitas approved terakhir, kembalikan posisi & km master jika perlu
|
||||
if ($activity->validation_status === 'approved' && $activity->vehicle) {
|
||||
$prevApproved = VehicleActivity::where('vehicle_id', $activity->vehicle_id)
|
||||
->where('id', '!=', $activity->id)
|
||||
->where('validation_status', 'approved')
|
||||
->latest('recorded_at')
|
||||
->first();
|
||||
|
||||
if ($prevApproved) {
|
||||
$activity->vehicle->update([
|
||||
'current_km' => $prevApproved->current_km,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Catat log audit ke AdminActivityLog
|
||||
AdminActivityLog::record(
|
||||
actionType: 'delete',
|
||||
module: 'Keamanan & Pos Satpam (PG)',
|
||||
description: "Menghapus riwayat verifikasi perlintasan gerbang {$trxNo} pada unit {$vehicleCode} di pos {$gateName} (Driver: {$driverName}).",
|
||||
targetType: 'VehicleActivity',
|
||||
targetId: $activity->id,
|
||||
targetName: "{$vehicleCode} ({$trxNo})",
|
||||
oldValues: [
|
||||
'transaction_no' => $trxNo,
|
||||
'current_km' => (float)$activity->current_km,
|
||||
'direction' => $activity->direction,
|
||||
'gate' => $gateName,
|
||||
'validation_status' => $activity->validation_status,
|
||||
],
|
||||
newValues: null
|
||||
);
|
||||
|
||||
// Hapus relasi riwayat lokasi (jika ada)
|
||||
$activity->locationHistories()->delete();
|
||||
|
||||
// Hapus aktivitas
|
||||
$activity->delete();
|
||||
});
|
||||
|
||||
return back()->with('success', "Riwayat log verifikasi gerbang {$trxNo} ({$vehicleCode}) berhasil dihapus.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +66,9 @@ class VehicleActivityFormController extends Controller
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
// Bersihkan data aktivitas pending yang telah kedaluwarsa (> 5 jam)
|
||||
VehicleActivity::expireOverduePendingActivities();
|
||||
|
||||
// Tentukan arah yang diperbolehkan berdasarkan riwayat terakhir
|
||||
$allowedDirection = $vehicle->determineNextAllowedDirection();
|
||||
|
||||
|
||||
@@ -23,6 +23,9 @@ class ActivityLogController extends Controller
|
||||
*/
|
||||
private function getFilteredActivityQuery(Request $request): Builder
|
||||
{
|
||||
// Otomatis update status perjalanan pending yang kedaluwarsa (> 5 jam)
|
||||
VehicleActivity::expireOverduePendingActivities();
|
||||
|
||||
$query = VehicleActivity::with(['vehicle', 'driver', 'gate', 'securityGuard'])
|
||||
->latest('recorded_at');
|
||||
|
||||
@@ -741,4 +744,59 @@ class ActivityLogController extends Controller
|
||||
|
||||
return back()->with('success', "Odometer transaksi {$activity->transaction_no} ({$activity->vehicle->code}) berhasil dikoreksi menjadi " . number_format($newCurrentKm, 0, ',', '.') . " KM.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Hapus catatan aktivitas perjalanan kendaraan (Timesheet LV) dari sistem.
|
||||
*/
|
||||
public function destroy(int $id): RedirectResponse
|
||||
{
|
||||
$activity = VehicleActivity::with(['vehicle', 'driver'])->findOrFail($id);
|
||||
|
||||
$vehicleCode = $activity->vehicle?->code ?? '-';
|
||||
$trxNo = $activity->transaction_no;
|
||||
$driverName = $activity->driver?->name ?? 'Pengemudi';
|
||||
|
||||
DB::transaction(function () use ($activity, $vehicleCode, $trxNo, $driverName) {
|
||||
// Jika aktivitas yang dihapus adalah aktivitas approved terakhir, sinkronkan master km ke aktivitas sebelumnya
|
||||
if ($activity->validation_status === 'approved' && $activity->vehicle) {
|
||||
$prevApproved = VehicleActivity::where('vehicle_id', $activity->vehicle_id)
|
||||
->where('id', '!=', $activity->id)
|
||||
->where('validation_status', 'approved')
|
||||
->latest('recorded_at')
|
||||
->first();
|
||||
|
||||
if ($prevApproved) {
|
||||
$activity->vehicle->update([
|
||||
'current_km' => $prevApproved->current_km,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Catat log audit ke AdminActivityLog
|
||||
AdminActivityLog::record(
|
||||
actionType: 'delete',
|
||||
module: 'Operasional Kendaraan (QMA)',
|
||||
description: "Menghapus catatan perjalanan {$trxNo} pada unit {$vehicleCode} (Driver: {$driverName}).",
|
||||
targetType: 'VehicleActivity',
|
||||
targetId: $activity->id,
|
||||
targetName: "{$vehicleCode} ({$trxNo})",
|
||||
oldValues: [
|
||||
'transaction_no' => $trxNo,
|
||||
'current_km' => (float)$activity->current_km,
|
||||
'distance' => (float)$activity->distance,
|
||||
'direction' => $activity->direction,
|
||||
'validation_status' => $activity->validation_status,
|
||||
],
|
||||
newValues: null
|
||||
);
|
||||
|
||||
// Hapus relasi riwayat lokasi (jika ada)
|
||||
$activity->locationHistories()->delete();
|
||||
|
||||
// Hapus aktivitas
|
||||
$activity->delete();
|
||||
});
|
||||
|
||||
return back()->with('success', "Catatan perjalanan {$trxNo} ({$vehicleCode}) berhasil dihapus dari sistem.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -12,6 +13,8 @@ class VehicleActivity extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public const PENDING_TIMEOUT_HOURS = 5;
|
||||
|
||||
protected $fillable = [
|
||||
'transaction_no',
|
||||
'vehicle_id',
|
||||
@@ -95,6 +98,54 @@ class VehicleActivity extends Model
|
||||
return $this->validation_status === 'rejected';
|
||||
}
|
||||
|
||||
/**
|
||||
* Cek apakah tiket perjalanan pending sudah melebihi batas waktu 5 jam.
|
||||
*/
|
||||
public function isOverdue(int $hours = self::PENDING_TIMEOUT_HOURS): bool
|
||||
{
|
||||
if ($this->validation_status !== 'pending' || !$this->recorded_at) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->recorded_at->copy()->addHours($hours)->isPast();
|
||||
}
|
||||
|
||||
/**
|
||||
* Waktu tepat tiket kedaluwarsa (recorded_at + 5 jam).
|
||||
*/
|
||||
public function getExpiresAtAttribute(): ?Carbon
|
||||
{
|
||||
return $this->recorded_at ? $this->recorded_at->copy()->addHours(self::PENDING_TIMEOUT_HOURS) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hitung sisa detik sebelum tiket kedaluwarsa.
|
||||
*/
|
||||
public function getRemainingSecondsAttribute(): int
|
||||
{
|
||||
if ($this->validation_status !== 'pending' || !$this->recorded_at) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$expireTime = $this->expires_at;
|
||||
return max(0, (int) Carbon::now()->diffInSeconds($expireTime, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Batalkan otomatis seluruh tiket pending yang sudah melebihi batas waktu (default 5 jam).
|
||||
*/
|
||||
public static function expireOverduePendingActivities(int $hours = self::PENDING_TIMEOUT_HOURS): int
|
||||
{
|
||||
$cutoff = Carbon::now()->subHours($hours);
|
||||
|
||||
return static::where('validation_status', 'pending')
|
||||
->where('recorded_at', '<=', $cutoff)
|
||||
->update([
|
||||
'validation_status' => 'cancelled',
|
||||
'rejection_note' => "Dibatalkan sistem: Melebihi batas waktu verifikasi ({$hours} jam)",
|
||||
]);
|
||||
}
|
||||
|
||||
public function scopePending(Builder $query): Builder
|
||||
{
|
||||
return $query->where('validation_status', 'pending');
|
||||
|
||||
@@ -100,6 +100,10 @@ return [
|
||||
'label' => 'Koreksi Odometer & Kelola Timesheet Support',
|
||||
'description' => 'Mengoreksi angka kilometer perjalanan LV serta menambah, mengubah, dan menghapus Timesheet Unit Support.',
|
||||
],
|
||||
'qma.logs.delete' => [
|
||||
'label' => 'Menghapus Catatan Perjalanan (Timesheet LV)',
|
||||
'description' => 'Menghapus riwayat data perjalanan mobilisasi kendaraan operasional dari sistem.',
|
||||
],
|
||||
'qma.summary.view' => [
|
||||
'label' => 'Melihat Rekapitulasi & Laporan Armada',
|
||||
'description' => 'Melihat total kilometer, jumlah perjalanan, dan ringkasan penggunaan armada per periode.',
|
||||
@@ -146,6 +150,10 @@ return [
|
||||
'label' => 'Melihat Riwayat Keluar-Masuk Gerbang',
|
||||
'description' => 'Melihat catatan kendaraan yang diperiksa, disetujui, atau ditolak oleh satpam di pos gerbang.',
|
||||
],
|
||||
'pg.logs.delete' => [
|
||||
'label' => 'Menghapus Riwayat Verifikasi Gerbang',
|
||||
'description' => 'Menghapus catatan log verifikasi perlintasan kendaraan pos gerbang dari sistem.',
|
||||
],
|
||||
],
|
||||
],
|
||||
'gate' => [
|
||||
|
||||
@@ -83,7 +83,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="self-start sm:self-center">
|
||||
<div class="self-start sm:self-center flex flex-wrap items-center gap-2">
|
||||
<!-- Timer Countdown Sisa Waktu 5 Jam -->
|
||||
<div id="pendingTripCountdownContainer"
|
||||
data-expires-at="{{ $pendingActivity->expires_at?->toISOString() }}"
|
||||
class="inline-flex items-center px-3 py-1 rounded-full text-xs font-mono font-bold bg-white text-rose-700 border border-rose-300 shadow-2xs">
|
||||
<i class="fa-solid fa-stopwatch mr-1.5 text-rose-600 animate-pulse"></i>
|
||||
<span>Sisa: <strong id="tripCountdownTimerText">--:--:--</strong></span>
|
||||
</div>
|
||||
|
||||
<span class="inline-flex items-center px-3 py-1 rounded-full text-xs font-bold bg-amber-100 text-amber-900 border border-amber-300">
|
||||
<span class="w-2 h-2 rounded-full bg-amber-500 animate-ping mr-1.5"></span>
|
||||
<span class="w-2 h-2 rounded-full bg-amber-500 mr-1.5 -ml-3.5"></span>
|
||||
@@ -776,5 +784,40 @@
|
||||
errorMsg.textContent = (err && err.message) ? err.message : 'Kamera tidak dapat diakses. Pastikan peramban browser diberikan izin akses kamera (Camera Permission).';
|
||||
}
|
||||
}
|
||||
|
||||
// Countdown Timer Tiket Pending (Batas Waktu 5 Jam)
|
||||
const countdownContainer = document.getElementById('pendingTripCountdownContainer');
|
||||
if (countdownContainer) {
|
||||
const expiresAtRaw = countdownContainer.getAttribute('data-expires-at');
|
||||
const timerTextEl = document.getElementById('tripCountdownTimerText');
|
||||
if (expiresAtRaw && timerTextEl) {
|
||||
const expireTime = new Date(expiresAtRaw).getTime();
|
||||
|
||||
function updateTripCountdown() {
|
||||
const now = new Date().getTime();
|
||||
const distance = expireTime - now;
|
||||
|
||||
if (distance <= 0) {
|
||||
timerTextEl.textContent = 'Kedaluwarsa';
|
||||
countdownContainer.classList.remove('text-rose-700', 'border-rose-300');
|
||||
countdownContainer.classList.add('text-slate-600', 'bg-slate-100', 'border-slate-300');
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 2500);
|
||||
return;
|
||||
}
|
||||
|
||||
const hours = Math.floor(distance / (1000 * 60 * 60));
|
||||
const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
|
||||
const seconds = Math.floor((distance % (1000 * 60)) / 1000);
|
||||
|
||||
const pad = (n) => String(n).padStart(2, '0');
|
||||
timerTextEl.textContent = `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
|
||||
}
|
||||
|
||||
updateTripCountdown();
|
||||
setInterval(updateTripCountdown, 1000);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endsection
|
||||
|
||||
@@ -241,6 +241,9 @@
|
||||
<th class="py-3.5 px-4 text-center">ARAH</th>
|
||||
<th class="py-3.5 px-4 text-right">ODOMETER</th>
|
||||
<th class="py-3.5 px-4 text-center">STATUS & CATATAN</th>
|
||||
@can('pg.logs.delete')
|
||||
<th class="py-3.5 px-4 text-center whitespace-nowrap">AKSI</th>
|
||||
@endcan
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="verificationLogTableBody" class="divide-y divide-slate-100 font-medium text-slate-700">
|
||||
@@ -390,6 +393,18 @@
|
||||
<i class="fa-solid fa-check text-[10px]"></i>
|
||||
<span>Disetujui</span>
|
||||
</span>
|
||||
@elseif($item->validation_status === 'cancelled')
|
||||
<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 }}">
|
||||
<i class="fa-solid fa-ban text-[10px] text-slate-400"></i>
|
||||
<span>Dibatalkan</span>
|
||||
</span>
|
||||
@if($item->rejection_note)
|
||||
<p class="text-[10px] text-slate-500 max-w-xs truncate mx-auto mt-0.5" title="{{ $item->rejection_note }}">
|
||||
{{ $item->rejection_note }}
|
||||
</p>
|
||||
@endif
|
||||
</div>
|
||||
@elseif($item->validation_status === 'rejected')
|
||||
<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 }}">
|
||||
@@ -409,10 +424,23 @@
|
||||
</span>
|
||||
@endif
|
||||
</td>
|
||||
|
||||
<!-- Aksi Hapus Log (RBAC Protected) -->
|
||||
@can('pg.logs.delete')
|
||||
<td class="py-3 px-4 text-center whitespace-nowrap">
|
||||
<button type="button"
|
||||
onclick="confirmDeleteVerificationLog({{ $item->id }}, '{{ $item->transaction_no }}', '{{ $item->vehicle?->code ?? '-' }}')"
|
||||
class="inline-flex items-center space-x-1 px-2.5 py-1.5 rounded-lg text-xs font-bold bg-rose-50 text-rose-700 border border-rose-200 hover:bg-rose-100 hover:border-rose-300 transition cursor-pointer shadow-2xs"
|
||||
title="Hapus Catatan Log Ini">
|
||||
<i class="fa-regular fa-trash-can text-rose-600 text-[11px]"></i>
|
||||
<span>Hapus</span>
|
||||
</button>
|
||||
</td>
|
||||
@endcan
|
||||
</tr>
|
||||
@empty
|
||||
<tr id="serverVerificationEmptyRow">
|
||||
<td colspan="10" class="py-12 text-center text-slate-400">
|
||||
<td colspan="{{ auth()->user()->can('pg.logs.delete') ? 11 : 10 }}" class="py-12 text-center text-slate-400">
|
||||
<div class="flex flex-col items-center justify-center space-y-2">
|
||||
<div class="w-12 h-12 rounded-full bg-slate-100 flex items-center justify-center text-slate-400 text-lg">
|
||||
<i class="fa-solid fa-clipboard-question"></i>
|
||||
@@ -696,7 +724,59 @@
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Escape') {
|
||||
closeGuideModal();
|
||||
closeDeleteVerificationLogModal();
|
||||
}
|
||||
});
|
||||
|
||||
// Modal Konfirmasi Hapus Log Verifikasi Gerbang
|
||||
function confirmDeleteVerificationLog(id, trxNo, vehicleCode) {
|
||||
const textEl = document.getElementById('deleteLogTrxText');
|
||||
const codeEl = document.getElementById('deleteLogCodeText');
|
||||
const form = document.getElementById('deleteVerificationLogForm');
|
||||
if (textEl) textEl.textContent = trxNo;
|
||||
if (codeEl) codeEl.textContent = vehicleCode;
|
||||
if (form) form.action = "{{ url('/pg/verification-logs') }}/" + id;
|
||||
|
||||
const modal = document.getElementById('deleteVerificationLogModal');
|
||||
if (modal) modal.style.display = 'flex';
|
||||
}
|
||||
|
||||
function closeDeleteVerificationLogModal() {
|
||||
const modal = document.getElementById('deleteVerificationLogModal');
|
||||
if (modal) modal.style.display = 'none';
|
||||
}
|
||||
</script>
|
||||
|
||||
@can('pg.logs.delete')
|
||||
<!-- Modal Konfirmasi Hapus Log Verifikasi Gerbang PG -->
|
||||
<div id="deleteVerificationLogModal" style="display: none;" class="fixed inset-0 z-50 flex items-center justify-center p-4 bg-slate-900/60 backdrop-blur-xs">
|
||||
<div class="bg-white rounded-2xl max-w-md w-full shadow-2xl border border-slate-100 overflow-hidden transform transition-all">
|
||||
<div class="p-6 text-center">
|
||||
<div class="w-14 h-14 rounded-2xl bg-rose-50 text-rose-600 flex items-center justify-center mx-auto mb-4 border border-rose-100 text-2xl">
|
||||
<i class="fa-solid fa-triangle-exclamation"></i>
|
||||
</div>
|
||||
<h3 class="text-lg font-bold text-slate-900">Konfirmasi Hapus Log Gerbang</h3>
|
||||
<p class="text-xs text-slate-500 mt-1.5">
|
||||
Apakah Anda yakin ingin menghapus data perlintasan <strong id="deleteLogTrxText" class="text-slate-800 font-mono"></strong> pada kendaraan <strong id="deleteLogCodeText" class="text-emerald-700 font-mono"></strong>?
|
||||
</p>
|
||||
<p class="text-[11px] text-amber-700 bg-amber-50 p-2.5 rounded-xl border border-amber-200 mt-3 text-left">
|
||||
<i class="fa-solid fa-circle-info mr-1 text-amber-600"></i>
|
||||
Tindakan ini permanen dan akan dicatat ke dalam riwayat audit log sistem.
|
||||
</p>
|
||||
</div>
|
||||
<form id="deleteVerificationLogForm" method="POST" action="">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<div class="bg-slate-50 px-6 py-4 flex items-center justify-end space-x-2 border-t border-slate-100">
|
||||
<button type="button" onclick="closeDeleteVerificationLogModal()" class="px-4 py-2 rounded-xl text-xs font-bold text-slate-600 hover:bg-slate-200 transition cursor-pointer">
|
||||
Batal
|
||||
</button>
|
||||
<button type="submit" class="px-4 py-2 rounded-xl text-xs font-bold text-white bg-rose-600 hover:bg-rose-700 transition cursor-pointer shadow-sm">
|
||||
<i class="fa-regular fa-trash-can mr-1.5"></i> Ya, Hapus Log
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@endcan
|
||||
@endsection
|
||||
|
||||
@@ -211,9 +211,9 @@
|
||||
<th class="py-3.5 px-4 text-right whitespace-nowrap">KM Berjalan</th>
|
||||
<th class="py-3.5 px-4 whitespace-nowrap">Aktivitas</th>
|
||||
<th class="py-3.5 px-4 text-center whitespace-nowrap">Status PG</th>
|
||||
@can('qma.logs.edit_odometer')
|
||||
@if(auth()->user()->can('qma.logs.edit_odometer') || auth()->user()->can('qma.logs.delete'))
|
||||
<th class="py-3.5 px-4 text-center whitespace-nowrap">Aksi</th>
|
||||
@endcan
|
||||
@endif
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="activityLogTableBody" class="divide-y divide-slate-100 text-slate-700 bg-white">
|
||||
@@ -325,9 +325,11 @@
|
||||
@endif
|
||||
</td>
|
||||
|
||||
<!-- Aksi Koreksi Odometer (RBAC Protected) -->
|
||||
@can('qma.logs.edit_odometer')
|
||||
<!-- Aksi (Koreksi Odometer & Hapus - RBAC Protected) -->
|
||||
@if(auth()->user()->can('qma.logs.edit_odometer') || auth()->user()->can('qma.logs.delete'))
|
||||
<td class="py-3.5 px-4 text-center whitespace-nowrap">
|
||||
<div class="inline-flex items-center gap-1.5">
|
||||
@can('qma.logs.edit_odometer')
|
||||
<button type="button"
|
||||
onclick="openQmaOdometerModal({{ json_encode([
|
||||
'id' => $act->id,
|
||||
@@ -347,12 +349,24 @@
|
||||
<i class="fa-solid fa-screwdriver-wrench text-amber-600 text-[11px]"></i>
|
||||
<span>Koreksi</span>
|
||||
</button>
|
||||
</td>
|
||||
@endcan
|
||||
|
||||
@can('qma.logs.delete')
|
||||
<button type="button"
|
||||
onclick="confirmDeleteActivity({{ $act->id }}, '{{ $act->transaction_no }}', '{{ $act->vehicle?->code ?? '-' }}')"
|
||||
class="inline-flex items-center space-x-1 px-2.5 py-1.5 rounded-lg text-xs font-bold bg-rose-50 text-rose-700 border border-rose-200 hover:bg-rose-100 hover:border-rose-300 transition cursor-pointer shadow-2xs"
|
||||
title="Hapus Catatan Perjalanan Ini">
|
||||
<i class="fa-regular fa-trash-can text-rose-600 text-[11px]"></i>
|
||||
<span>Hapus</span>
|
||||
</button>
|
||||
@endcan
|
||||
</div>
|
||||
</td>
|
||||
@endif
|
||||
</tr>
|
||||
@empty
|
||||
<tr id="serverActivityEmptyRow">
|
||||
<td colspan="{{ auth()->user()->can('qma.logs.edit_odometer') ? 12 : 11 }}" class="py-12 px-4 text-center">
|
||||
<td colspan="{{ (auth()->user()->can('qma.logs.edit_odometer') || auth()->user()->can('qma.logs.delete')) ? 12 : 11 }}" class="py-12 px-4 text-center">
|
||||
<div class="flex flex-col items-center justify-center space-y-3">
|
||||
<div class="w-14 h-14 rounded-full bg-slate-100 flex items-center justify-center text-slate-400 text-2xl">
|
||||
<i class="fa-solid fa-magnifying-glass"></i>
|
||||
@@ -794,4 +808,51 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
}
|
||||
</script>
|
||||
@endcan
|
||||
|
||||
@can('qma.logs.delete')
|
||||
<!-- Modal Konfirmasi Hapus Catatan Perjalanan QMA -->
|
||||
<div id="deleteActivityModal" style="display: none;" class="fixed inset-0 z-50 flex items-center justify-center p-4 bg-slate-900/60 backdrop-blur-xs">
|
||||
<div class="bg-white rounded-2xl max-w-md w-full shadow-2xl border border-slate-100 overflow-hidden transform transition-all">
|
||||
<div class="p-6 text-center">
|
||||
<div class="w-14 h-14 rounded-2xl bg-rose-50 text-rose-600 flex items-center justify-center mx-auto mb-4 border border-rose-100 text-2xl">
|
||||
<i class="fa-solid fa-triangle-exclamation"></i>
|
||||
</div>
|
||||
<h3 class="text-lg font-bold text-slate-900">Konfirmasi Hapus Perjalanan</h3>
|
||||
<p class="text-xs text-slate-500 mt-1.5">
|
||||
Apakah Anda yakin ingin menghapus data perjalanan <strong id="deleteTrxNoText" class="text-slate-800 font-mono"></strong> pada unit <strong id="deleteVehicleCodeText" class="text-emerald-700 font-mono"></strong>?
|
||||
</p>
|
||||
<p class="text-[11px] text-amber-700 bg-amber-50 p-2.5 rounded-xl border border-amber-200 mt-3 text-left">
|
||||
<i class="fa-solid fa-circle-info mr-1 text-amber-600"></i>
|
||||
Tindakan ini permanen dan akan dicatat ke dalam riwayat audit log sistem.
|
||||
</p>
|
||||
</div>
|
||||
<form id="deleteActivityForm" method="POST" action="">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<div class="bg-slate-50 px-6 py-4 flex items-center justify-end space-x-2 border-t border-slate-100">
|
||||
<button type="button" onclick="closeDeleteActivityModal()" class="px-4 py-2 rounded-xl text-xs font-bold text-slate-600 hover:bg-slate-200 transition cursor-pointer">
|
||||
Batal
|
||||
</button>
|
||||
<button type="submit" class="px-4 py-2 rounded-xl text-xs font-bold text-white bg-rose-600 hover:bg-rose-700 transition cursor-pointer shadow-sm">
|
||||
<i class="fa-regular fa-trash-can mr-1.5"></i> Ya, Hapus Catatan
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function confirmDeleteActivity(id, trxNo, vehicleCode) {
|
||||
document.getElementById('deleteTrxNoText').textContent = trxNo;
|
||||
document.getElementById('deleteVehicleCodeText').textContent = vehicleCode;
|
||||
const form = document.getElementById('deleteActivityForm');
|
||||
form.action = "{{ url('/qma/activity-log') }}/" + id;
|
||||
document.getElementById('deleteActivityModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
function closeDeleteActivityModal() {
|
||||
document.getElementById('deleteActivityModal').style.display = 'none';
|
||||
}
|
||||
</script>
|
||||
@endcan
|
||||
@endsection
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
<?php
|
||||
|
||||
use App\Console\Commands\ExpirePendingActivitiesCommand;
|
||||
use Illuminate\Foundation\Inspiring;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Schedule;
|
||||
|
||||
Artisan::command('inspire', function () {
|
||||
$this->comment(Inspiring::quote());
|
||||
})->purpose('Display an inspiring quote');
|
||||
|
||||
// Jadwalkan pembatalan otomatis tiket perjalanan pending yang melewati 5 jam
|
||||
Schedule::command(ExpirePendingActivitiesCommand::class)->hourly();
|
||||
|
||||
|
||||
@@ -89,6 +89,7 @@ Route::middleware('auth')->group(function () {
|
||||
Route::get('/activity-log', [ActivityLogController::class, 'index'])->name('activity.log')->middleware('permission:qma.logs.view');
|
||||
Route::get('/activity-log/support-timesheet', [SupportTimesheetController::class, 'index'])->name('activity.support_timesheet')->middleware('permission:qma.logs.view');
|
||||
Route::post('/activity-log/{id}/correct-odometer', [ActivityLogController::class, 'correctOdometer'])->name('activity.correct_odometer')->middleware('permission:qma.logs.edit_odometer');
|
||||
Route::delete('/activity-log/{id}', [ActivityLogController::class, 'destroy'])->name('activity.destroy')->middleware('permission:qma.logs.delete');
|
||||
Route::get('/activity-log/export-excel', [ActivityLogController::class, 'exportExcel'])->name('activity.export_excel')->middleware('permission:qma.logs.view');
|
||||
Route::get('/activity-log/export-pdf', [ActivityLogController::class, 'exportPdf'])->name('activity.export_pdf')->middleware('permission:qma.logs.view');
|
||||
Route::get('/activity-summary', [ActivityLogController::class, 'summary'])->name('activity.summary')->middleware('permission:qma.summary.view');
|
||||
@@ -156,6 +157,7 @@ Route::middleware('auth')->group(function () {
|
||||
Route::post('/guards/{id}/toggle', [SecurityGuardController::class, 'toggleStatus'])->name('guards.toggle')->middleware('permission:pg.guards.toggle');
|
||||
Route::delete('/guards/{id}', [SecurityGuardController::class, 'destroy'])->name('guards.destroy')->middleware('permission:pg.guards.delete');
|
||||
Route::get('/verification-logs', [VerificationLogController::class, 'index'])->name('logs.index')->middleware('permission:pg.logs.view');
|
||||
Route::delete('/verification-logs/{id}', [VerificationLogController::class, 'destroy'])->name('logs.destroy')->middleware('permission:pg.logs.delete');
|
||||
Route::get('/verification-logs/export-excel', [VerificationLogController::class, 'exportExcel'])->name('logs.export_excel')->middleware('permission:pg.logs.view');
|
||||
Route::get('/verification-logs/export-pdf', [VerificationLogController::class, 'exportPdf'])->name('logs.export_pdf')->middleware('permission:pg.logs.view');
|
||||
|
||||
|
||||
@@ -0,0 +1,301 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\AdminActivityLog;
|
||||
use App\Models\Employee;
|
||||
use App\Models\Gate;
|
||||
use App\Models\SecurityGuard;
|
||||
use App\Models\User;
|
||||
use App\Models\Vehicle;
|
||||
use App\Models\VehicleActivity;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ActivityExpirationAndDeletionTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected User $superAdmin;
|
||||
protected User $qmaUser;
|
||||
protected User $pgUser;
|
||||
protected User $driverUser;
|
||||
protected Employee $driver;
|
||||
protected Vehicle $vehicle;
|
||||
protected Gate $gate;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->seedSampleData();
|
||||
|
||||
$this->superAdmin = User::where('username', 'superadmin')->first();
|
||||
|
||||
// Siapkan master kendaraan & gerbang
|
||||
$this->gate = Gate::first();
|
||||
$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,
|
||||
]);
|
||||
|
||||
// Siapkan driver
|
||||
$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',
|
||||
'role' => 'employee',
|
||||
]);
|
||||
$this->driver->update(['user_id' => $this->driverUser->id]);
|
||||
$this->driverUser->assignRole('employee');
|
||||
|
||||
// Siapkan user QMA (tanpa permission delete)
|
||||
$this->qmaUser = User::factory()->create(['role' => 'qma_admin']);
|
||||
$this->qmaUser->assignRole('qma_admin');
|
||||
|
||||
// Siapkan user PG (tanpa permission delete)
|
||||
$this->pgUser = User::factory()->create(['role' => 'pg_admin']);
|
||||
$this->pgUser->assignRole('pg_admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. Tiket perjalanan pending yang sudah berusia > 5 jam otomatis dibatalkan sistem.
|
||||
*/
|
||||
public function test_pending_activity_older_than_5_hours_is_automatically_cancelled(): void
|
||||
{
|
||||
// Buat tiket perjalanan 6 jam yang lalu
|
||||
$overdueActivity = VehicleActivity::create([
|
||||
'transaction_no' => 'TRX-EXP-01',
|
||||
'vehicle_id' => $this->vehicle->id,
|
||||
'driver_id' => $this->driver->id,
|
||||
'gate_id' => $this->gate->id,
|
||||
'direction' => 'out',
|
||||
'previous_km' => 1000.0,
|
||||
'current_km' => 1050.0,
|
||||
'distance' => 50.0,
|
||||
'purpose' => 'Mobilisasi Site',
|
||||
'recorded_at' => Carbon::now()->subHours(6),
|
||||
'validation_status' => 'pending',
|
||||
]);
|
||||
|
||||
// Buat tiket perjalanan 2 jam yang lalu (masih valid)
|
||||
$validActivity = VehicleActivity::create([
|
||||
'transaction_no' => 'TRX-VAL-02',
|
||||
'vehicle_id' => $this->vehicle->id,
|
||||
'driver_id' => $this->driver->id,
|
||||
'gate_id' => $this->gate->id,
|
||||
'direction' => 'in',
|
||||
'previous_km' => 1050.0,
|
||||
'current_km' => 1100.0,
|
||||
'distance' => 50.0,
|
||||
'purpose' => 'Kembali ke Site',
|
||||
'recorded_at' => Carbon::now()->subHours(2),
|
||||
'validation_status' => 'pending',
|
||||
]);
|
||||
|
||||
// Jalankan fungsi auto expire
|
||||
$affected = VehicleActivity::expireOverduePendingActivities(5);
|
||||
|
||||
$this->assertEquals(1, $affected);
|
||||
|
||||
$overdueActivity->refresh();
|
||||
$this->assertEquals('cancelled', $overdueActivity->validation_status);
|
||||
$this->assertStringContainsString('Dibatalkan sistem: Melebihi batas waktu verifikasi (5 jam)', $overdueActivity->rejection_note);
|
||||
|
||||
$validActivity->refresh();
|
||||
$this->assertEquals('pending', $validActivity->validation_status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 2. Perintah artisan activities:expire-pending bekerja membatalkan tiket kedaluwarsa.
|
||||
*/
|
||||
public function test_artisan_command_expires_pending_activities(): void
|
||||
{
|
||||
VehicleActivity::create([
|
||||
'transaction_no' => 'TRX-CMD-01',
|
||||
'vehicle_id' => $this->vehicle->id,
|
||||
'driver_id' => $this->driver->id,
|
||||
'gate_id' => $this->gate->id,
|
||||
'direction' => 'out',
|
||||
'previous_km' => 1000.0,
|
||||
'current_km' => 1050.0,
|
||||
'distance' => 50.0,
|
||||
'purpose' => 'Uji Command',
|
||||
'recorded_at' => Carbon::now()->subHours(7),
|
||||
'validation_status' => 'pending',
|
||||
]);
|
||||
|
||||
$this->artisan('activities:expire-pending')
|
||||
->expectsOutputToContain('Selesai: Sebanyak 1 tiket perjalanan berhasil dibatalkan otomatis.')
|
||||
->assertSuccessful();
|
||||
|
||||
$activity = VehicleActivity::where('transaction_no', 'TRX-CMD-01')->first();
|
||||
$this->assertEquals('cancelled', $activity->validation_status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 3. Driver dashboard otomatis membatalkan tiket > 5 jam saat diakses dan kartu pending hilang.
|
||||
*/
|
||||
public function test_driver_dashboard_auto_cancels_overdue_ticket_and_clears_pending_card(): void
|
||||
{
|
||||
VehicleActivity::create([
|
||||
'transaction_no' => 'TRX-DRV-01',
|
||||
'vehicle_id' => $this->vehicle->id,
|
||||
'driver_id' => $this->driver->id,
|
||||
'gate_id' => $this->gate->id,
|
||||
'direction' => 'out',
|
||||
'previous_km' => 1000.0,
|
||||
'current_km' => 1050.0,
|
||||
'distance' => 50.0,
|
||||
'purpose' => 'Perjalanan Terlewat',
|
||||
'recorded_at' => Carbon::now()->subHours(5)->subMinutes(10),
|
||||
'validation_status' => 'pending',
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($this->driverUser)->get(route('employee.dashboard'));
|
||||
$response->assertOk();
|
||||
|
||||
// Card pending tidak boleh muncul karena tiket sudah kedaluwarsa
|
||||
$response->assertDontSee('Perjalanan Aktif');
|
||||
|
||||
$activity = VehicleActivity::where('transaction_no', 'TRX-DRV-01')->first();
|
||||
$this->assertEquals('cancelled', $activity->validation_status);
|
||||
$this->assertStringContainsString('Dibatalkan sistem: Melebihi batas waktu verifikasi (5 jam)', $activity->rejection_note);
|
||||
}
|
||||
|
||||
/**
|
||||
* 4. User tanpa permission qma.logs.delete tidak dapat menghapus aktivitas QMA (403).
|
||||
*/
|
||||
public function test_unauthorized_user_cannot_delete_qma_activity(): void
|
||||
{
|
||||
$activity = VehicleActivity::create([
|
||||
'transaction_no' => 'TRX-DEL-01',
|
||||
'vehicle_id' => $this->vehicle->id,
|
||||
'driver_id' => $this->driver->id,
|
||||
'gate_id' => $this->gate->id,
|
||||
'direction' => 'out',
|
||||
'previous_km' => 1000.0,
|
||||
'current_km' => 1050.0,
|
||||
'distance' => 50.0,
|
||||
'purpose' => 'Testing Hapus',
|
||||
'recorded_at' => Carbon::now(),
|
||||
'validation_status' => 'pending',
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($this->qmaUser)->delete(route('qma.activity.destroy', $activity->id));
|
||||
$response->assertForbidden();
|
||||
|
||||
$this->assertDatabaseHas('vehicle_activities', ['id' => $activity->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 5. User dengan permission qma.logs.delete atau Super Admin dapat menghapus aktivitas QMA.
|
||||
*/
|
||||
public function test_authorized_user_and_superadmin_can_delete_qma_activity(): void
|
||||
{
|
||||
$activity = VehicleActivity::create([
|
||||
'transaction_no' => 'TRX-DEL-02',
|
||||
'vehicle_id' => $this->vehicle->id,
|
||||
'driver_id' => $this->driver->id,
|
||||
'gate_id' => $this->gate->id,
|
||||
'direction' => 'out',
|
||||
'previous_km' => 1000.0,
|
||||
'current_km' => 1050.0,
|
||||
'distance' => 50.0,
|
||||
'purpose' => 'Testing Hapus QMA Berhasil',
|
||||
'recorded_at' => Carbon::now(),
|
||||
'validation_status' => 'pending',
|
||||
]);
|
||||
|
||||
// Berikan izin qma.logs.delete ke qmaUser
|
||||
$this->qmaUser->givePermissionTo('qma.logs.delete');
|
||||
|
||||
$response = $this->actingAs($this->qmaUser)->delete(route('qma.activity.destroy', $activity->id));
|
||||
$response->assertRedirect();
|
||||
$response->assertSessionHas('success');
|
||||
|
||||
$this->assertDatabaseMissing('vehicle_activities', ['id' => $activity->id]);
|
||||
|
||||
// Verifikasi audit log tercatat
|
||||
$this->assertDatabaseHas('admin_activity_logs', [
|
||||
'action_type' => 'delete',
|
||||
'module' => 'Operasional Kendaraan (QMA)',
|
||||
'target_name' => "{$this->vehicle->code} (TRX-DEL-02)",
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 6. User tanpa permission pg.logs.delete tidak dapat menghapus log verifikasi PG (403).
|
||||
*/
|
||||
public function test_unauthorized_user_cannot_delete_pg_verification_log(): void
|
||||
{
|
||||
$activity = VehicleActivity::create([
|
||||
'transaction_no' => 'TRX-PG-DEL-01',
|
||||
'vehicle_id' => $this->vehicle->id,
|
||||
'driver_id' => $this->driver->id,
|
||||
'gate_id' => $this->gate->id,
|
||||
'direction' => 'out',
|
||||
'previous_km' => 1000.0,
|
||||
'current_km' => 1050.0,
|
||||
'distance' => 50.0,
|
||||
'purpose' => 'Testing Hapus PG',
|
||||
'recorded_at' => Carbon::now(),
|
||||
'validation_status' => 'approved',
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($this->pgUser)->delete(route('pg.logs.destroy', $activity->id));
|
||||
$response->assertForbidden();
|
||||
|
||||
$this->assertDatabaseHas('vehicle_activities', ['id' => $activity->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 7. User dengan permission pg.logs.delete atau Super Admin dapat menghapus log verifikasi PG.
|
||||
*/
|
||||
public function test_authorized_user_and_superadmin_can_delete_pg_verification_log(): void
|
||||
{
|
||||
$activity = VehicleActivity::create([
|
||||
'transaction_no' => 'TRX-PG-DEL-02',
|
||||
'vehicle_id' => $this->vehicle->id,
|
||||
'driver_id' => $this->driver->id,
|
||||
'gate_id' => $this->gate->id,
|
||||
'direction' => 'out',
|
||||
'previous_km' => 1000.0,
|
||||
'current_km' => 1050.0,
|
||||
'distance' => 50.0,
|
||||
'purpose' => 'Testing Hapus PG Berhasil',
|
||||
'recorded_at' => Carbon::now(),
|
||||
'validation_status' => 'approved',
|
||||
]);
|
||||
|
||||
// Berikan izin pg.logs.delete ke pgUser
|
||||
$this->pgUser->givePermissionTo('pg.logs.delete');
|
||||
|
||||
$response = $this->actingAs($this->pgUser)->delete(route('pg.logs.destroy', $activity->id));
|
||||
$response->assertRedirect();
|
||||
$response->assertSessionHas('success');
|
||||
|
||||
$this->assertDatabaseMissing('vehicle_activities', ['id' => $activity->id]);
|
||||
|
||||
// Verifikasi audit log tercatat
|
||||
$this->assertDatabaseHas('admin_activity_logs', [
|
||||
'action_type' => 'delete',
|
||||
'module' => 'Keamanan & Pos Satpam (PG)',
|
||||
'target_name' => "{$this->vehicle->code} (TRX-PG-DEL-02)",
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user