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:
@@ -146,7 +146,6 @@
|
||||
$debitur = Debiture::find($id);
|
||||
|
||||
$validate = $request->validated();
|
||||
|
||||
if ($validate) {
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
{
|
||||
$rules = [
|
||||
'debiture_id' => 'required|exists:debitures,id',
|
||||
'permohonan_id' => 'required|exists:permohonan,id',
|
||||
'pemilik_jaminan_id' => 'required',
|
||||
'jenis_jaminan_id' => 'required',
|
||||
'province_code' => 'nullable|exists:provinces,code',
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
@method('PUT')
|
||||
@endif
|
||||
@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">
|
||||
<label class="form-label max-w-56">
|
||||
Debitur
|
||||
@@ -427,13 +427,13 @@
|
||||
@push('scripts')
|
||||
{{--Pemilik Jaminan--}}
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const namaSertifikatDiv = document.getElementById("nama_sertifikat");
|
||||
|
||||
// Function to add delete event listeners to existing buttons
|
||||
function addDeleteListeners() {
|
||||
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();
|
||||
});
|
||||
});
|
||||
@@ -442,7 +442,7 @@
|
||||
// Add delete listeners to existing buttons
|
||||
addDeleteListeners();
|
||||
|
||||
document.getElementById("tambah_sertifikat").addEventListener("click", function () {
|
||||
document.getElementById("tambah_sertifikat").addEventListener("click", function() {
|
||||
const newDiv = document.createElement("div");
|
||||
newDiv.className = "flex items-baseline flex-wrap lg:flex-nowrap gap-2.5 mb-5";
|
||||
newDiv.innerHTML = `
|
||||
@@ -509,7 +509,7 @@
|
||||
${index + 1}. ${item.name}
|
||||
</label>
|
||||
<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 class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||
@@ -517,7 +517,7 @@
|
||||
Nomor
|
||||
</label>
|
||||
<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>
|
||||
|
||||
@@ -527,7 +527,7 @@
|
||||
</label>
|
||||
<div class="flex flex-wrap items-baseline w-full" id="file-container-${index}">
|
||||
<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 class="flex items-center gap-2 my-2 w-full">
|
||||
<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)}
|
||||
</div>
|
||||
</div>
|
||||
` : ''}
|
||||
` : ""}
|
||||
|
||||
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||
<label class="form-label max-w-56">
|
||||
Keterangan
|
||||
</label>
|
||||
<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>
|
||||
`;
|
||||
});
|
||||
})
|
||||
.catch(error => console.error('Error:', error));
|
||||
.catch(error => console.error("Error:", error));
|
||||
}
|
||||
|
||||
function addFileInput(index) {
|
||||
const container = document.getElementById(`file-container-${index}`);
|
||||
const newInput = document.createElement('div');
|
||||
newInput.className = 'flex items-center gap-2 mb-2 w-full';
|
||||
const newInput = document.createElement("div");
|
||||
newInput.className = "flex items-center gap-2 mb-2 w-full";
|
||||
newInput.innerHTML = `
|
||||
<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/*">
|
||||
@@ -575,60 +575,60 @@
|
||||
}
|
||||
|
||||
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) {
|
||||
if (typeof dokumenJaminan === 'string' && typeof dokumenNomor === 'string') {
|
||||
if (typeof dokumenJaminan === "string" && typeof dokumenNomor === "string") {
|
||||
return `
|
||||
<div class="flex w-full lg:w-[30%]">
|
||||
<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">
|
||||
${dokumenJaminan.split('/').pop()}
|
||||
${dokumenJaminan.split("/").pop()}
|
||||
<i class="ki-filled ki-cloud-download"></i>
|
||||
</a>
|
||||
</div>
|
||||
`;
|
||||
} else if (typeof dokumenJaminan === 'string' && dokumenNomor === null) {
|
||||
} else if (typeof dokumenJaminan === "string" && dokumenNomor === null) {
|
||||
return `
|
||||
<div class="flex w-full lg:w-[30%]">
|
||||
<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">
|
||||
${dokumenJaminan.split('/').pop()}
|
||||
${dokumenJaminan.split("/").pop()}
|
||||
<i class="ki-filled ki-cloud-download"></i>
|
||||
</a>
|
||||
</div>
|
||||
`;
|
||||
} else if (Array.isArray(dokumenJaminan) && Array.isArray(dokumenNomor)) {
|
||||
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">
|
||||
${file.split('/').pop()}
|
||||
${file.split("/").pop()}
|
||||
<i class="ki-filled ki-cloud-download"></i>
|
||||
</a></div>
|
||||
`).join('');
|
||||
} else if (Array.isArray(dokumenJaminan) && typeof dokumenNomor === 'string') {
|
||||
`).join("");
|
||||
} else if (Array.isArray(dokumenJaminan) && typeof dokumenNomor === "string") {
|
||||
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>
|
||||
<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>
|
||||
</a></div>
|
||||
`).join('');
|
||||
} else if (Array.isArray(dokumenJaminan) && dokumenNomor === 'null') {
|
||||
`).join("");
|
||||
} else if (Array.isArray(dokumenJaminan) && dokumenNomor === "null") {
|
||||
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>
|
||||
<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>
|
||||
</a></div>
|
||||
`).join('');
|
||||
`).join("");
|
||||
}
|
||||
return dokumenNomor;
|
||||
}
|
||||
|
||||
function getCustomFieldInput(type, fieldName, value) {
|
||||
value = value ? JSON.parse(value)[fieldName] || '' : '';
|
||||
value = value ? JSON.parse(value)[fieldName] || "" : "";
|
||||
switch (type) {
|
||||
case "text":
|
||||
return `<input class="input" type="text" name="custom_field[][${fieldName}]" value="${value}">`;
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
<i class="ki-outline ki-cloud-download"></i>
|
||||
</a>
|
||||
@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>
|
||||
</a>
|
||||
<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');
|
||||
}
|
||||
</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="flex flex-col gap-3">
|
||||
<div class="flex justify-center pt-5">
|
||||
@@ -147,6 +148,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
@include('lpj::component.pdfviewer')
|
||||
@@ -155,33 +157,33 @@
|
||||
<script type="text/javascript">
|
||||
function deleteData(data) {
|
||||
Swal.fire({
|
||||
title: 'Are you sure?',
|
||||
title: "Are you sure?",
|
||||
text: "You won't be able to revert this!",
|
||||
icon: 'warning',
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#3085d6',
|
||||
cancelButtonColor: '#d33',
|
||||
confirmButtonText: 'Yes, delete it!'
|
||||
confirmButtonColor: "#3085d6",
|
||||
cancelButtonColor: "#d33",
|
||||
confirmButtonText: "Yes, delete it!"
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
$.ajaxSetup({
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||
"X-CSRF-TOKEN": '{{ csrf_token() }}'
|
||||
}
|
||||
});
|
||||
|
||||
$.ajax(`debitur/{{$debitur->id}}}/jaminan/${data}`, {
|
||||
type: 'DELETE'
|
||||
type: "DELETE"
|
||||
}).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();
|
||||
});
|
||||
}).catch((error) => {
|
||||
console.error('Error:', error);
|
||||
Swal.fire('Error!', 'An error occurred while deleting the file.', 'error');
|
||||
console.error("Error:", error);
|
||||
Swal.fire("Error!", "An error occurred while deleting the file.", "error");
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
</script>
|
||||
@endpush
|
||||
|
||||
Reference in New Issue
Block a user