Perbaiki validasi, logika, dan tampilan terkait dokumen jaminan

- Menambahkan validasi untuk `permohonan_id` pada `DokumenJaminanRequest`.
- Memperbaiki logika penggabungan parameter query untuk rute tertentu.
- Merapikan formatting kode pada tampilan blade, termasuk elemen HTML dan JavaScript.
- Mengatasi beberapa bug minor terkait aksi dan tampilan dokumen jaminan.
This commit is contained in:
Daeng Deni Mardaeni
2024-12-27 09:36:07 +07:00
parent 407306e085
commit 66b8a9053b
4 changed files with 88 additions and 86 deletions

View File

@@ -146,7 +146,6 @@
$debitur = Debiture::find($id); $debitur = Debiture::find($id);
$validate = $request->validated(); $validate = $request->validated();
if ($validate) { if ($validate) {
try { try {
DB::beginTransaction(); DB::beginTransaction();

View File

@@ -14,6 +14,7 @@
{ {
$rules = [ $rules = [
'debiture_id' => 'required|exists:debitures,id', 'debiture_id' => 'required|exists:debitures,id',
'permohonan_id' => 'required|exists:permohonan,id',
'pemilik_jaminan_id' => 'required', 'pemilik_jaminan_id' => 'required',
'jenis_jaminan_id' => 'required', 'jenis_jaminan_id' => 'required',
'province_code' => 'nullable|exists:provinces,code', 'province_code' => 'nullable|exists:provinces,code',

View File

@@ -3,7 +3,7 @@
@method('PUT') @method('PUT')
@endif @endif
@csrf @csrf
<input type="hidden" name="permohonan_id" value="{{ $document->id ?? request()->get('permohonan_id') }}">
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5"> <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
<label class="form-label max-w-56"> <label class="form-label max-w-56">
Debitur Debitur
@@ -427,13 +427,13 @@
@push('scripts') @push('scripts')
{{--Pemilik Jaminan--}} {{--Pemilik Jaminan--}}
<script> <script>
document.addEventListener("DOMContentLoaded", function () { document.addEventListener("DOMContentLoaded", function() {
const namaSertifikatDiv = document.getElementById("nama_sertifikat"); const namaSertifikatDiv = document.getElementById("nama_sertifikat");
// Function to add delete event listeners to existing buttons // Function to add delete event listeners to existing buttons
function addDeleteListeners() { function addDeleteListeners() {
document.querySelectorAll(".delete-button").forEach(button => { document.querySelectorAll(".delete-button").forEach(button => {
button.addEventListener("click", function () { button.addEventListener("click", function() {
this.closest(".flex.items-baseline.flex-wrap.lg\\:flex-nowrap.gap-2\\.5.mb-5").remove(); this.closest(".flex.items-baseline.flex-wrap.lg\\:flex-nowrap.gap-2\\.5.mb-5").remove();
}); });
}); });
@@ -442,7 +442,7 @@
// Add delete listeners to existing buttons // Add delete listeners to existing buttons
addDeleteListeners(); addDeleteListeners();
document.getElementById("tambah_sertifikat").addEventListener("click", function () { document.getElementById("tambah_sertifikat").addEventListener("click", function() {
const newDiv = document.createElement("div"); const newDiv = document.createElement("div");
newDiv.className = "flex items-baseline flex-wrap lg:flex-nowrap gap-2.5 mb-5"; newDiv.className = "flex items-baseline flex-wrap lg:flex-nowrap gap-2.5 mb-5";
newDiv.innerHTML = ` newDiv.innerHTML = `
@@ -509,7 +509,7 @@
${index + 1}. ${item.name} ${index + 1}. ${item.name}
</label> </label>
<input type="hidden" name="jenis_legalitas_jaminan_id[]" value="${item.jenis_legalitas_jaminan_id}"> <input type="hidden" name="jenis_legalitas_jaminan_id[]" value="${item.jenis_legalitas_jaminan_id}">
${item.is_existing ? `<input type="hidden" name="detail_dokumen_jaminan_id[]" value="${item.id}">` : ''} ${item.is_existing ? `<input type="hidden" name="detail_dokumen_jaminan_id[]" value="${item.id}">` : ""}
</div> </div>
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5"> <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
@@ -517,7 +517,7 @@
Nomor Nomor
</label> </label>
<div class="flex flex-wrap items-baseline w-full"> <div class="flex flex-wrap items-baseline w-full">
<input class="input" type="text" name="name[]" value="${item.name || ''}" placeholder="Nomor"> <input class="input" type="text" name="name[]" value="${item.name || ""}" placeholder="Nomor">
</div> </div>
</div> </div>
@@ -527,7 +527,7 @@
</label> </label>
<div class="flex flex-wrap items-baseline w-full" id="file-container-${index}"> <div class="flex flex-wrap items-baseline w-full" id="file-container-${index}">
<div class="flex flex-col w-full gap-2"> <div class="flex flex-col w-full gap-2">
${item.dokumen_jaminan ? renderExistingFiles(item.dokumen_jaminan, debiturId, item.id, item.dokumen_nomor) : ''} ${item.dokumen_jaminan ? renderExistingFiles(item.dokumen_jaminan, debiturId, item.id, item.dokumen_nomor) : ""}
</div> </div>
<div class="flex items-center gap-2 my-2 w-full"> <div class="flex items-center gap-2 my-2 w-full">
<input class="flex-1 input" type="text" name="dokumen_nomor[${index}][]" placeholder="Nomor Dokumen"> <input class="flex-1 input" type="text" name="dokumen_nomor[${index}][]" placeholder="Nomor Dokumen">
@@ -546,26 +546,26 @@
${getCustomFieldInput(item.custom_field_type, item.custom_field, item.details)} ${getCustomFieldInput(item.custom_field_type, item.custom_field, item.details)}
</div> </div>
</div> </div>
` : ''} ` : ""}
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5"> <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
<label class="form-label max-w-56"> <label class="form-label max-w-56">
Keterangan Keterangan
</label> </label>
<div class="flex flex-wrap items-baseline w-full"> <div class="flex flex-wrap items-baseline w-full">
<textarea class="textarea" rows="3" name="keterangan[]">${item.keterangan || ''}</textarea> <textarea class="textarea" rows="3" name="keterangan[]">${item.keterangan || ""}</textarea>
</div> </div>
</div> </div>
`; `;
}); });
}) })
.catch(error => console.error('Error:', error)); .catch(error => console.error("Error:", error));
} }
function addFileInput(index) { function addFileInput(index) {
const container = document.getElementById(`file-container-${index}`); const container = document.getElementById(`file-container-${index}`);
const newInput = document.createElement('div'); const newInput = document.createElement("div");
newInput.className = 'flex items-center gap-2 mb-2 w-full'; newInput.className = "flex items-center gap-2 mb-2 w-full";
newInput.innerHTML = ` newInput.innerHTML = `
<input class="flex-1 input" type="text" name="dokumen_nomor[${index}][]" placeholder="Nomor Dokumen"> <input class="flex-1 input" type="text" name="dokumen_nomor[${index}][]" placeholder="Nomor Dokumen">
<input class="flex-1 file-input" type="file" name="dokumen_jaminan[${index}][]" accept=".pdf,image/*"> <input class="flex-1 file-input" type="file" name="dokumen_jaminan[${index}][]" accept=".pdf,image/*">
@@ -575,60 +575,60 @@
} }
function removeFileInput(button) { function removeFileInput(button) {
button.closest('.flex.items-center.gap-2.mb-2').remove(); button.closest(".flex.items-center.gap-2.mb-2").remove();
} }
function renderExistingFiles(dokumenJaminan, debiturId, itemId, dokumenNomor) { function renderExistingFiles(dokumenJaminan, debiturId, itemId, dokumenNomor) {
if (typeof dokumenJaminan === 'string' && typeof dokumenNomor === 'string') { if (typeof dokumenJaminan === "string" && typeof dokumenNomor === "string") {
return ` return `
<div class="flex w-full lg:w-[30%]"> <div class="flex w-full lg:w-[30%]">
<span class="flex-1 mt-2 text-info text-sm">Nomor Dokumen : ${dokumenNomor}</span> <span class="flex-1 mt-2 text-info text-sm">Nomor Dokumen : ${dokumenNomor}</span>
<a href="/debitur/${debiturId}/jaminan/download?dokumen=${itemId}" class="flex-none badge badge-sm badge-outline mt-2"> <a href="/debitur/${debiturId}/jaminan/download?dokumen=${itemId}" class="flex-none badge badge-sm badge-outline mt-2">
${dokumenJaminan.split('/').pop()} ${dokumenJaminan.split("/").pop()}
<i class="ki-filled ki-cloud-download"></i> <i class="ki-filled ki-cloud-download"></i>
</a> </a>
</div> </div>
`; `;
} else if (typeof dokumenJaminan === 'string' && dokumenNomor === null) { } else if (typeof dokumenJaminan === "string" && dokumenNomor === null) {
return ` return `
<div class="flex w-full lg:w-[30%]"> <div class="flex w-full lg:w-[30%]">
<span class="flex-1 mt-2 text-info text-sm">Nomor Dokumen : --</span> <span class="flex-1 mt-2 text-info text-sm">Nomor Dokumen : --</span>
<a href="/debitur/${debiturId}/jaminan/download?dokumen=${itemId}" class="flex-none badge badge-sm badge-outline mt-2"> <a href="/debitur/${debiturId}/jaminan/download?dokumen=${itemId}" class="flex-none badge badge-sm badge-outline mt-2">
${dokumenJaminan.split('/').pop()} ${dokumenJaminan.split("/").pop()}
<i class="ki-filled ki-cloud-download"></i> <i class="ki-filled ki-cloud-download"></i>
</a> </a>
</div> </div>
`; `;
} else if (Array.isArray(dokumenJaminan) && Array.isArray(dokumenNomor)) { } else if (Array.isArray(dokumenJaminan) && Array.isArray(dokumenNomor)) {
return dokumenJaminan.map((file, index) => `<div class="flex w-full lg:w-[30%]"> return dokumenJaminan.map((file, index) => `<div class="flex w-full lg:w-[30%]">
<span class="flex-1 mt-2 text-info text-sm">Nomor Dokumen : ${dokumenNomor[index] || 'N/A'}</span> <span class="flex-1 mt-2 text-info text-sm">Nomor Dokumen : ${dokumenNomor[index] || "N/A"}</span>
<a href="/debitur/${debiturId}/jaminan/download?dokumen=${itemId}&file=${file}" class="flex-none badge badge-sm badge-outline mt-2 mr-2"> <a href="/debitur/${debiturId}/jaminan/download?dokumen=${itemId}&file=${file}" class="flex-none badge badge-sm badge-outline mt-2 mr-2">
${file.split('/').pop()} ${file.split("/").pop()}
<i class="ki-filled ki-cloud-download"></i> <i class="ki-filled ki-cloud-download"></i>
</a></div> </a></div>
`).join(''); `).join("");
} else if (Array.isArray(dokumenJaminan) && typeof dokumenNomor === 'string') { } else if (Array.isArray(dokumenJaminan) && typeof dokumenNomor === "string") {
return dokumenJaminan.map((file, index) => `<div class="flex w-full lg:w-[30%]"> return dokumenJaminan.map((file, index) => `<div class="flex w-full lg:w-[30%]">
<span class="flex-1 mt-2 text-info text-sm">Nomor Dokumen : ${dokumenNomor} || 'N/A'}</span> <span class="flex-1 mt-2 text-info text-sm">Nomor Dokumen : ${dokumenNomor} || 'N/A'}</span>
<a href="/debitur/${debiturId}/jaminan/download?dokumen=${itemId}&file=${file}" class="flex-none badge badge-sm badge-outline mt-2 mr-2"> <a href="/debitur/${debiturId}/jaminan/download?dokumen=${itemId}&file=${file}" class="flex-none badge badge-sm badge-outline mt-2 mr-2">
${file.split('/').pop()} ${file.split("/").pop()}
<i class="ki-filled ki-cloud-download"></i> <i class="ki-filled ki-cloud-download"></i>
</a></div> </a></div>
`).join(''); `).join("");
} else if (Array.isArray(dokumenJaminan) && dokumenNomor === 'null') { } else if (Array.isArray(dokumenJaminan) && dokumenNomor === "null") {
return dokumenJaminan.map((file, index) => `<div class="flex w-full lg:w-[30%]"> return dokumenJaminan.map((file, index) => `<div class="flex w-full lg:w-[30%]">
<span class="flex-1 mt-2 text-info text-sm">Nomor Dokumen : ${dokumenNomor} || 'N/A'}</span> <span class="flex-1 mt-2 text-info text-sm">Nomor Dokumen : ${dokumenNomor} || 'N/A'}</span>
<a href="/debitur/${debiturId}/jaminan/download?dokumen=${itemId}&file=${file}" class="flex-none badge badge-sm badge-outline mt-2 mr-2"> <a href="/debitur/${debiturId}/jaminan/download?dokumen=${itemId}&file=${file}" class="flex-none badge badge-sm badge-outline mt-2 mr-2">
${file.split('/').pop()} ${file.split("/").pop()}
<i class="ki-filled ki-cloud-download"></i> <i class="ki-filled ki-cloud-download"></i>
</a></div> </a></div>
`).join(''); `).join("");
} }
return dokumenNomor; return dokumenNomor;
} }
function getCustomFieldInput(type, fieldName, value) { function getCustomFieldInput(type, fieldName, value) {
value = value ? JSON.parse(value)[fieldName] || '' : ''; value = value ? JSON.parse(value)[fieldName] || "" : "";
switch (type) { switch (type) {
case "text": case "text":
return `<input class="input" type="text" name="custom_field[][${fieldName}]" value="${value}">`; return `<input class="input" type="text" name="custom_field[][${fieldName}]" value="${value}">`;

View File

@@ -28,7 +28,7 @@
<i class="ki-outline ki-cloud-download"></i> <i class="ki-outline ki-cloud-download"></i>
</a> </a>
@endif @endif
<a href="{{ route('debitur.jaminan.edit',['id' => $debitur->id,'jaminan' => $document->id]) }}" class="btn btn-sm btn-icon btn-outline btn-info"> <a href="{{ route('debitur.jaminan.edit',array_merge(request()->query(),['id' => $debitur->id,'jaminan' => $document->id])) }}" class="btn btn-sm btn-icon btn-outline btn-info">
<i class="ki-outline ki-notepad-edit"></i> <i class="ki-outline ki-notepad-edit"></i>
</a> </a>
<a onclick="deleteData({{ $document->id }})" class="delete btn btn-sm btn-icon btn-outline btn-danger"> <a onclick="deleteData({{ $document->id }})" class="delete btn btn-sm btn-icon btn-outline btn-danger">
@@ -115,7 +115,8 @@
background-image: url('/assets/media/images/2600x1200/bg-4-dark.png'); background-image: url('/assets/media/images/2600x1200/bg-4-dark.png');
} }
</style> </style>
<a class="card border-2 border-dashed border-brand-clarity bg-center bg-[length:600px] bg-no-repeat add-new-bg" href="{{ route('debitur.jaminan.create',$debitur->id) }}"> @if(request()->get('permohonan_id'))
<a class="card border-2 border-dashed border-brand-clarity bg-center bg-[length:600px] bg-no-repeat add-new-bg" href="{{ route('debitur.jaminan.create',array_merge(request()->query(),['id'=>$debitur->id])) }}">
<div class="card-body grid items-center"> <div class="card-body grid items-center">
<div class="flex flex-col gap-3"> <div class="flex flex-col gap-3">
<div class="flex justify-center pt-5"> <div class="flex justify-center pt-5">
@@ -147,6 +148,7 @@
</div> </div>
</div> </div>
</a> </a>
@endif
</div> </div>
@include('lpj::component.pdfviewer') @include('lpj::component.pdfviewer')
@@ -155,33 +157,33 @@
<script type="text/javascript"> <script type="text/javascript">
function deleteData(data) { function deleteData(data) {
Swal.fire({ Swal.fire({
title: 'Are you sure?', title: "Are you sure?",
text: "You won't be able to revert this!", text: "You won't be able to revert this!",
icon: 'warning', icon: "warning",
showCancelButton: true, showCancelButton: true,
confirmButtonColor: '#3085d6', confirmButtonColor: "#3085d6",
cancelButtonColor: '#d33', cancelButtonColor: "#d33",
confirmButtonText: 'Yes, delete it!' confirmButtonText: "Yes, delete it!"
}).then((result) => { }).then((result) => {
if (result.isConfirmed) { if (result.isConfirmed) {
$.ajaxSetup({ $.ajaxSetup({
headers: { headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}' "X-CSRF-TOKEN": '{{ csrf_token() }}'
} }
}); });
$.ajax(`debitur/{{$debitur->id}}}/jaminan/${data}`, { $.ajax(`debitur/{{$debitur->id}}}/jaminan/${data}`, {
type: 'DELETE' type: "DELETE"
}).then((response) => { }).then((response) => {
swal.fire('Deleted!', 'Document Jaminan has been deleted.', 'success').then(() => { swal.fire("Deleted!", "Document Jaminan has been deleted.", "success").then(() => {
window.location.reload(); window.location.reload();
}); });
}).catch((error) => { }).catch((error) => {
console.error('Error:', error); console.error("Error:", error);
Swal.fire('Error!', 'An error occurred while deleting the file.', 'error'); Swal.fire("Error!", "An error occurred while deleting the file.", "error");
}); });
} }
}) });
} }
</script> </script>
@endpush @endpush