feat(p2h): add soft delete feature for p2h heavy equipment records with confirmation modal and trash support
This commit is contained in:
@@ -767,4 +767,20 @@ class P2hInspectionController extends Controller
|
|||||||
|
|
||||||
return back()->with('success', "Inspeksi P2H [{$record->transaction_no}] untuk unit {$record->vehicle->code} DITOLAK. Status unit diubah ke Breakdown.");
|
return back()->with('success', "Inspeksi P2H [{$record->transaction_no}] untuk unit {$record->vehicle->code} DITOLAK. Status unit diubah ke Breakdown.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hapus pemeriksaan P2H Heavy Equipment (Soft Delete).
|
||||||
|
* Data yang dihapus akan dipindahkan ke Tong Sampah dan dapat dipulihkan sewaktu-waktu.
|
||||||
|
*/
|
||||||
|
public function destroy(int $id): RedirectResponse
|
||||||
|
{
|
||||||
|
$record = P2hRecord::findOrFail($id);
|
||||||
|
$trxNo = $record->transaction_no;
|
||||||
|
|
||||||
|
// Cascade soft delete record items
|
||||||
|
$record->items()->delete();
|
||||||
|
$record->delete();
|
||||||
|
|
||||||
|
return redirect()->route('qma.p2h.index')->with('success', "Data pemeriksaan P2H [{$trxNo}] berhasil dihapus dan dipindahkan ke Tong Sampah.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -205,6 +205,12 @@
|
|||||||
<a href="{{ route('qma.p2h.export_single_excel', $rec->id) }}" class="w-7 h-7 rounded-xl bg-emerald-50 hover:bg-emerald-100 text-emerald-700 flex items-center justify-center transition border border-emerald-200 shadow-2xs" title="Download Lembar P2H (Excel)">
|
<a href="{{ route('qma.p2h.export_single_excel', $rec->id) }}" class="w-7 h-7 rounded-xl bg-emerald-50 hover:bg-emerald-100 text-emerald-700 flex items-center justify-center transition border border-emerald-200 shadow-2xs" title="Download Lembar P2H (Excel)">
|
||||||
<i class="fa-solid fa-file-excel text-xs"></i>
|
<i class="fa-solid fa-file-excel text-xs"></i>
|
||||||
</a>
|
</a>
|
||||||
|
<button type="button"
|
||||||
|
onclick="openDeleteP2hModal({{ $rec->id }}, '{{ $rec->transaction_no }}', '{{ $rec->vehicle->code ?? '' }}')"
|
||||||
|
class="w-7 h-7 rounded-xl bg-rose-50 hover:bg-rose-100 text-rose-600 flex items-center justify-center transition border border-rose-200 shadow-2xs cursor-pointer"
|
||||||
|
title="Hapus Pemeriksaan P2H">
|
||||||
|
<i class="fa-regular fa-trash-can text-xs"></i>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -312,12 +318,64 @@ function closeGuideModal() {
|
|||||||
document.addEventListener('keydown', function(e) {
|
document.addEventListener('keydown', function(e) {
|
||||||
if (e.key === 'Escape') {
|
if (e.key === 'Escape') {
|
||||||
closeGuideModal();
|
closeGuideModal();
|
||||||
|
closeDeleteP2hModal();
|
||||||
const exportMenu = document.getElementById('exportMenuP2h');
|
const exportMenu = document.getElementById('exportMenuP2h');
|
||||||
if (exportMenu) exportMenu.style.display = 'none';
|
if (exportMenu) exportMenu.style.display = 'none';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function openDeleteP2hModal(id, trxNo, unitCode) {
|
||||||
|
document.getElementById('deleteP2hForm').action = `/qma/p2h-records/${id}`;
|
||||||
|
document.getElementById('deleteP2hTxNo').textContent = trxNo;
|
||||||
|
document.getElementById('deleteP2hUnitCode').textContent = unitCode || '-';
|
||||||
|
const modal = document.getElementById('deleteP2hModal');
|
||||||
|
if (modal) {
|
||||||
|
modal.classList.remove('hidden');
|
||||||
|
modal.style.display = 'block';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeDeleteP2hModal() {
|
||||||
|
const modal = document.getElementById('deleteP2hModal');
|
||||||
|
if (modal) {
|
||||||
|
modal.classList.add('hidden');
|
||||||
|
modal.style.display = 'none';
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!-- ========================================================================= -->
|
||||||
|
<!-- MODAL POPUP: HAPUS PEMERIKSAAN P2H -->
|
||||||
|
<!-- ========================================================================= -->
|
||||||
|
<div id="deleteP2hModal" class="hidden fixed inset-0 z-50 overflow-y-auto" style="display: none;">
|
||||||
|
<div class="fixed inset-0 bg-slate-900/60 backdrop-blur-xs transition-opacity" onclick="closeDeleteP2hModal()"></div>
|
||||||
|
|
||||||
|
<div class="flex min-h-full items-center justify-center p-4">
|
||||||
|
<div class="relative w-full max-w-md bg-white rounded-2xl shadow-xl border border-slate-100 p-6 text-center transform transition-all">
|
||||||
|
<div class="w-12 h-12 rounded-full bg-rose-50 text-rose-600 flex items-center justify-center mx-auto mb-4 border border-rose-100">
|
||||||
|
<i class="fa-solid fa-triangle-exclamation text-xl"></i>
|
||||||
|
</div>
|
||||||
|
<h3 class="text-sm font-bold text-slate-900 mb-1">Hapus Data Pemeriksaan P2H?</h3>
|
||||||
|
<p class="text-xs text-slate-500 mb-4 leading-relaxed">
|
||||||
|
Apakah Anda yakin ingin menghapus inspeksi P2H <span id="deleteP2hTxNo" class="font-mono font-bold text-rose-600">-</span> untuk unit <span id="deleteP2hUnitCode" class="font-bold text-slate-800">-</span>? Data akan dipindahkan ke <strong>Tong Sampah</strong> dan dapat dipulihkan sewaktu-waktu.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<form id="deleteP2hForm" method="POST" action="">
|
||||||
|
@csrf
|
||||||
|
@method('DELETE')
|
||||||
|
<div class="flex items-center justify-center space-x-3">
|
||||||
|
<button type="button" onclick="closeDeleteP2hModal()" class="bg-slate-100 hover:bg-slate-200 text-slate-700 px-4 py-2 rounded-xl text-xs font-semibold transition cursor-pointer">
|
||||||
|
Batal
|
||||||
|
</button>
|
||||||
|
<button type="submit" class="bg-rose-600 hover:bg-rose-700 text-white px-5 py-2 rounded-xl text-xs font-bold transition shadow-xs cursor-pointer">
|
||||||
|
Ya, Hapus
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- ========================================================================= -->
|
<!-- ========================================================================= -->
|
||||||
<!-- MODAL POPUP: PANDUAN HALAMAN (LOG P2H HEAVY EQUIPMENT) -->
|
<!-- MODAL POPUP: PANDUAN HALAMAN (LOG P2H HEAVY EQUIPMENT) -->
|
||||||
<!-- ========================================================================= -->
|
<!-- ========================================================================= -->
|
||||||
|
|||||||
@@ -25,6 +25,15 @@
|
|||||||
<span>Ekspor Excel (.xlsx)</span>
|
<span>Ekspor Excel (.xlsx)</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
<!-- Tombol Hapus P2H -->
|
||||||
|
<button type="button"
|
||||||
|
onclick="openDeleteP2hModal({{ $record->id }}, '{{ $record->transaction_no }}', '{{ $record->vehicle->code ?? '' }}')"
|
||||||
|
class="inline-flex items-center space-x-1.5 text-xs font-bold text-rose-700 bg-rose-50 hover:bg-rose-100 border border-rose-200 px-3 py-1.5 rounded-xl transition shadow-xs cursor-pointer"
|
||||||
|
title="Hapus Pemeriksaan P2H">
|
||||||
|
<i class="fa-regular fa-trash-can text-[13px] text-rose-600"></i>
|
||||||
|
<span>Hapus P2H</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
<!-- Badge Status Validasi -->
|
<!-- Badge Status Validasi -->
|
||||||
<div>
|
<div>
|
||||||
@if($record->isPending())
|
@if($record->isPending())
|
||||||
@@ -230,6 +239,63 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- MODAL POPUP: HAPUS PEMERIKSAAN P2H -->
|
||||||
|
<div id="deleteP2hModal" class="hidden fixed inset-0 z-50 overflow-y-auto" style="display: none;">
|
||||||
|
<div class="fixed inset-0 bg-slate-900/60 backdrop-blur-xs transition-opacity" onclick="closeDeleteP2hModal()"></div>
|
||||||
|
|
||||||
|
<div class="flex min-h-full items-center justify-center p-4">
|
||||||
|
<div class="relative w-full max-w-md bg-white rounded-2xl shadow-xl border border-slate-100 p-6 text-center transform transition-all">
|
||||||
|
<div class="w-12 h-12 rounded-full bg-rose-50 text-rose-600 flex items-center justify-center mx-auto mb-4 border border-rose-100">
|
||||||
|
<i class="fa-solid fa-triangle-exclamation text-xl"></i>
|
||||||
|
</div>
|
||||||
|
<h3 class="text-sm font-bold text-slate-900 mb-1">Hapus Data Pemeriksaan P2H?</h3>
|
||||||
|
<p class="text-xs text-slate-500 mb-4 leading-relaxed">
|
||||||
|
Apakah Anda yakin ingin menghapus inspeksi P2H <span id="deleteP2hTxNo" class="font-mono font-bold text-rose-600">-</span> untuk unit <span id="deleteP2hUnitCode" class="font-bold text-slate-800">-</span>? Data akan dipindahkan ke <strong>Tong Sampah</strong> dan dapat dipulihkan sewaktu-waktu.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<form id="deleteP2hForm" method="POST" action="">
|
||||||
|
@csrf
|
||||||
|
@method('DELETE')
|
||||||
|
<div class="flex items-center justify-center space-x-3">
|
||||||
|
<button type="button" onclick="closeDeleteP2hModal()" class="bg-slate-100 hover:bg-slate-200 text-slate-700 px-4 py-2 rounded-xl text-xs font-semibold transition cursor-pointer">
|
||||||
|
Batal
|
||||||
|
</button>
|
||||||
|
<button type="submit" class="bg-rose-600 hover:bg-rose-700 text-white px-5 py-2 rounded-xl text-xs font-bold transition shadow-xs cursor-pointer">
|
||||||
|
Ya, Hapus
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function openDeleteP2hModal(id, trxNo, unitCode) {
|
||||||
|
document.getElementById('deleteP2hForm').action = `/qma/p2h-records/${id}`;
|
||||||
|
document.getElementById('deleteP2hTxNo').textContent = trxNo;
|
||||||
|
document.getElementById('deleteP2hUnitCode').textContent = unitCode || '-';
|
||||||
|
const modal = document.getElementById('deleteP2hModal');
|
||||||
|
if (modal) {
|
||||||
|
modal.classList.remove('hidden');
|
||||||
|
modal.style.display = 'block';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeDeleteP2hModal() {
|
||||||
|
const modal = document.getElementById('deleteP2hModal');
|
||||||
|
if (modal) {
|
||||||
|
modal.classList.add('hidden');
|
||||||
|
modal.style.display = 'none';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('keydown', function(e) {
|
||||||
|
if (e.key === 'Escape') {
|
||||||
|
closeDeleteP2hModal();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@media print {
|
@media print {
|
||||||
.no-print, header, nav, aside, #mobileDrawer, #topNavbar, .sidebar-container {
|
.no-print, header, nav, aside, #mobileDrawer, #topNavbar, .sidebar-container {
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ Route::middleware('auth')->group(function () {
|
|||||||
Route::get('/p2h-records/{id}/export-excel', [P2hInspectionController::class, 'exportSingleExcel'])->name('p2h.export_single_excel')->middleware('permission:qma.p2h.view|qma.vehicles.view');
|
Route::get('/p2h-records/{id}/export-excel', [P2hInspectionController::class, 'exportSingleExcel'])->name('p2h.export_single_excel')->middleware('permission:qma.p2h.view|qma.vehicles.view');
|
||||||
Route::post('/p2h-records/{id}/approve', [P2hInspectionController::class, 'approve'])->name('p2h.approve')->middleware('permission:qma.p2h.approve|qma.vehicles.edit');
|
Route::post('/p2h-records/{id}/approve', [P2hInspectionController::class, 'approve'])->name('p2h.approve')->middleware('permission:qma.p2h.approve|qma.vehicles.edit');
|
||||||
Route::post('/p2h-records/{id}/reject', [P2hInspectionController::class, 'reject'])->name('p2h.reject')->middleware('permission:qma.p2h.approve|qma.vehicles.edit');
|
Route::post('/p2h-records/{id}/reject', [P2hInspectionController::class, 'reject'])->name('p2h.reject')->middleware('permission:qma.p2h.approve|qma.vehicles.edit');
|
||||||
|
Route::delete('/p2h-records/{id}', [P2hInspectionController::class, 'destroy'])->name('p2h.destroy')->middleware('permission:qma.vehicles.delete|qma.p2h.approve|qma.vehicles.edit');
|
||||||
|
|
||||||
// Master 28 Template Checksheet P2H & Kelola Pertanyaan
|
// Master 28 Template Checksheet P2H & Kelola Pertanyaan
|
||||||
Route::get('/p2h-templates', [P2hTemplateController::class, 'index'])->name('p2h.templates')->middleware('permission:qma.p2h.templates|qma.vehicles.view');
|
Route::get('/p2h-templates', [P2hTemplateController::class, 'index'])->name('p2h.templates')->middleware('permission:qma.p2h.templates|qma.vehicles.view');
|
||||||
|
|||||||
@@ -734,6 +734,45 @@ class P2hInspectionTest extends TestCase
|
|||||||
$this->assertCount(4, $itemsAfterDelete);
|
$this->assertCount(4, $itemsAfterDelete);
|
||||||
$this->assertEquals([1, 2, 3, 4], $itemsAfterDelete->pluck('sequence')->all());
|
$this->assertEquals([1, 2, 3, 4], $itemsAfterDelete->pluck('sequence')->all());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Admin QMA dapat menghapus data riwayat pemeriksaan P2H (Soft Delete ke Tong Sampah).
|
||||||
|
*/
|
||||||
|
public function test_qma_admin_can_soft_delete_p2h_record(): void
|
||||||
|
{
|
||||||
|
$record = P2hRecord::create([
|
||||||
|
'transaction_no' => 'P2H-TEST-DEL-001',
|
||||||
|
'vehicle_id' => $this->supportVehicle->id,
|
||||||
|
'employee_id' => $this->operatorEmp->id,
|
||||||
|
'template_id' => $this->template->id,
|
||||||
|
'shift' => 'Shift Siang',
|
||||||
|
'start_hm' => 1500.0,
|
||||||
|
'summary_condition' => 'normal',
|
||||||
|
'validation_status' => 'pending',
|
||||||
|
'inspected_at' => Carbon::now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$item = \App\Models\P2hRecordItem::create([
|
||||||
|
'p2h_record_id' => $record->id,
|
||||||
|
'section' => 'Bagian A',
|
||||||
|
'title' => 'Cek Oli Mesin',
|
||||||
|
'question_type' => 'choice',
|
||||||
|
'condition_status' => 'baik',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($this->qmaAdmin)
|
||||||
|
->delete(route('qma.p2h.destroy', $record->id));
|
||||||
|
|
||||||
|
$response->assertRedirect(route('qma.p2h.index'));
|
||||||
|
$response->assertSessionHas('success');
|
||||||
|
|
||||||
|
$this->assertSoftDeleted('p2h_records', ['id' => $record->id]);
|
||||||
|
$this->assertSoftDeleted('p2h_record_items', ['id' => $item->id]);
|
||||||
|
|
||||||
|
// Pastikan muncul di TrashService
|
||||||
|
$trashItems = app(\App\Services\TrashService::class)->getTrashedItems('p2h_records');
|
||||||
|
$this->assertTrue(collect($trashItems->items())->contains('id', $record->id));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user