fix(dokumen): perbaikan pengambilan detail dokumen jaminan

- Memperbaiki pengambilan data `details` pada `DokumenJaminanController`.
- Mengubah indeks pengambilan `custom_field` dari `$value` menjadi `$key`.
- Memperbaiki tampilan detail dokumen jaminan di view `jaminan.blade.php`.
- Menambahkan penanganan untuk menampilkan nomor dokumen dan detail yang sesuai.
This commit is contained in:
Daeng Deni Mardaeni
2025-03-05 16:25:43 +07:00
parent 3101cca619
commit 5932192d92
3 changed files with 145 additions and 97 deletions

View File

@@ -90,7 +90,7 @@
'jenis_legalitas_jaminan_id' => $value, 'jenis_legalitas_jaminan_id' => $value,
'name' => $request->name[$key], 'name' => $request->name[$key],
'keterangan' => $request->keterangan[$key], 'keterangan' => $request->keterangan[$key],
'details' => isset($request->custom_field[$value]) ? json_encode($request->custom_field[$value]) : '' 'details' => isset($request->custom_field[$key]) ? json_encode($request->custom_field[$key]) : ''
]; ];
$dokumenJaminan = []; $dokumenJaminan = [];

View File

@@ -282,7 +282,7 @@
<input class="input " type="text" id="name" name="name[]" value="{{ $detail->name ?? "" }}" placeholder="Nomor"> <input class="input " type="text" id="name" name="name[]" value="{{ $detail->name ?? "" }}" placeholder="Nomor">
</div> </div>
</div> </div>
<div id="document-container-${index}">
<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">
Dokumen Jaminan Dokumen Jaminan
@@ -321,11 +321,13 @@
@endif @endif
</div> </div>
</div> </div>
<div id="document-container"></div>
</div>
@if($detail->details) @if($detail->details)
@if($detail->jenisLegalitasJaminan->custom_fields) @if($detail->jenisLegalitasJaminan->custom_fields)
@foreach($detail->jenisLegalitasJaminan->custom_fields as $key) @foreach($detail->jenisLegalitasJaminan->custom_fields as $key)
<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 custom-field">
@php @php
$customField = getCustomField($key); $customField = getCustomField($key);
$fieldValue = json_decode($detail->details)->{$customField->name} ?? ''; $fieldValue = json_decode($detail->details)->{$customField->name} ?? '';
@@ -600,7 +602,7 @@
<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>
<div id="document-container-${index}">
<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">
Dokumen Jaminan Dokumen Jaminan
@@ -618,16 +620,19 @@
</div> </div>
${item.custom_fields && item.custom_fields.length > 0 ? item.custom_fields.map(field => ` ${item.custom_fields && item.custom_fields.length > 0 ? item.custom_fields.map(field => `
<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 mb-2 custom-field">
<label class="form-label max-w-56 capitalize"> <label class="form-label max-w-56 capitalize">
${field.label} ${field.label}
</label> </label>
<div class="flex flex-wrap items-baseline w-full"> <div class="flex flex-wrap items-baseline w-full">
${getCustomFieldInput(field.type, field.name, item.details, item.jenis_legalitas_jaminan_id)} ${getCustomFieldInput(index, field.type, field.name, item.details, item.jenis_legalitas_jaminan_id, 0)}
</div> </div>
</div> </div>
`).join('') : ""} `).join('') : ""}
<div id="document_container"></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
@@ -643,19 +648,51 @@
} }
function addFileInput(index) { function addFileInput(index) {
const container = document.getElementById(`file-container-${index}`); const documentContainer = document.getElementById(`document-container-${index}`);
const customFields = documentContainer.querySelectorAll('.custom-field');
const container = documentContainer.querySelector('#document_container');
// Get the current number of custom field sets
const currentFieldSets = container.querySelectorAll('.custom-field-set').length;
const newFieldIndex = currentFieldSets+1;
const newInput = document.createElement("div"); const newInput = document.createElement("div");
newInput.className = "flex items-center gap-2 mb-2 w-full"; newInput.className = "flex flex-col w-full gap-2 mb-4 custom-field-set";
let customFieldsHtml = '';
customFields.forEach(field => {
const label = field.querySelector('label').textContent;
const input = field.querySelector('input, textarea, select');
const fieldName = input.name.match(/\[([^\]]+)\]$/)[1];
customFieldsHtml += `
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
<label class="form-label max-w-56 capitalize">${label}</label>
<div class="flex flex-wrap items-baseline w-full">
${getCustomFieldInput(index, input.type, fieldName, null, null, newFieldIndex)}
</div>
</div>
`;
});
newInput.innerHTML = ` newInput.innerHTML = `
<div class="flex flex-wrap items-baseline w-full">
<div class="flex flex-col w-full gap-2">
&nbsp;
</div>
<div class="flex items-center gap-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">
<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/*">
<button type="button" class="flex-none btn btn-danger w-[100px] text-center" onclick="removeFileInput(this)">Remove</button> <button type="button" class="flex-none btn btn-danger w-[100px] text-center" onclick="removeFileInput(this)">Remove</button>
</div>
</div>
${customFieldsHtml}
`; `;
container.appendChild(newInput); container.appendChild(newInput);
} }
function removeFileInput(button) { function removeFileInput(button) {
button.closest(".flex.items-center.gap-2.mb-2").remove(); button.closest(".flex.flex-col.w-full.gap-2.mb-4").remove();
} }
function renderExistingFiles(dokumenJaminan, debiturId, itemId, dokumenNomor) { function renderExistingFiles(dokumenJaminan, debiturId, itemId, dokumenNomor) {
@@ -707,19 +744,19 @@
return dokumenNomor; return dokumenNomor;
} }
function getCustomFieldInput(type, fieldName, value, itemId) { function getCustomFieldInput(index, type, fieldName, value, itemId, fieldIndex = 0) {
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[${itemId}][${fieldName}]" value="${value}">`; return `<input class="input" type="text" name="custom_field[${index}][${fieldIndex}][${fieldName}]" value="${value}">`;
case "number": case "number":
return `<input class="input" type="number" step="0.01" name="custom_field[${itemId}][${fieldName}]" value="${value}">`; return `<input class="input" type="number" step="0.01" name="custom_field[${index}][${fieldIndex}][${fieldName}]" value="${value}">`;
case "date": case "date":
return `<input class="input" type="date" name="custom_field[${itemId}][${fieldName}]" value="${value}">`; return `<input class="input" type="date" name="custom_field[${index}][${fieldIndex}][${fieldName}]" value="${value}">`;
case "textarea": case "textarea":
return `<textarea class="textarea" rows="3" name="custom_field[${itemId}][${fieldName}]">${value}</textarea>`; return `<textarea class="textarea" rows="3" name="custom_field[${index}][${fieldIndex}][${fieldName}]">${value}</textarea>`;
default: default:
return `<input class="input" type="text" name="custom_field[${itemId}][${fieldName}]" value="${value}">`; return `<input class="input" type="text" name="custom_field[${index}][${fieldIndex}][${fieldName}]" value="${value}">`;
} }
} }

View File

@@ -78,15 +78,26 @@
@foreach($document->detail as $detail) @foreach($document->detail as $detail)
<div class="flex items-center justify-between flex-wrap my-2.5 gap-2"> <div class="flex items-center justify-between flex-wrap my-2.5 gap-2">
<span class="text-2xs text-gray-600 uppercase"> <span class="text-2xs text-gray-600 uppercase">
{{ $loop->index+1 }}. {{ $detail->jenisLegalitasJaminan->name }} <strong>{{ $loop->index+1 }}. {{ $detail->jenisLegalitasJaminan->name }}</strong>
</span> </span>
<div> <div>
&nbsp;
</div>
</div>
<div class="border-t border-gray-300 border-dashed"></div>
@if(isset($detail->dokumen_jaminan)) @if(isset($detail->dokumen_jaminan))
@php @php
$dokumen_jaminan = is_array(json_decode($detail->dokumen_jaminan)) ? json_decode($detail->dokumen_jaminan) : [$detail->dokumen_jaminan]; $dokumen_jaminan = is_array(json_decode($detail->dokumen_jaminan)) ? json_decode($detail->dokumen_jaminan) : [$detail->dokumen_jaminan];
$dokumen_nomor = is_array(json_decode($detail->dokumen_nomor)) ? json_decode($detail->dokumen_nomor) : ($detail->dokumen_nomor ? [$detail->dokumen_nomor] : []); $dokumen_nomor = is_array(json_decode($detail->dokumen_nomor)) ? json_decode($detail->dokumen_nomor) : ($detail->dokumen_nomor ? [$detail->dokumen_nomor] : []);
$count_jaminan = 0;
@endphp @endphp
@foreach($dokumen_jaminan as $index => $dokumen) @foreach($dokumen_jaminan as $index => $dokumen)
<div class="flex items-center justify-between flex-wrap my-2.5 gap-2">
<span class="text-2xs text-gray-600 uppercase pl-3">
{{ $loop->index+1 }}. Nomor : {{ $dokumen_nomor[$index] }}
</span>
<div>
@if(in_array(Auth::user()->roles[0]->name,['administrator','pemohon-eo'])) @if(in_array(Auth::user()->roles[0]->name,['administrator','pemohon-eo']))
<a href="{{ route('debitur.jaminan.download', ['id' => $debitur->id, 'dokumen' => $detail->id, 'index' => $index]) }}" <a href="{{ route('debitur.jaminan.download', ['id' => $debitur->id, 'dokumen' => $detail->id, 'index' => $index]) }}"
class="flex-none badge badge-sm badge-outline mt-2 mr-2"> class="flex-none badge badge-sm badge-outline mt-2 mr-2">
@@ -95,22 +106,19 @@
</a> </a>
@endif @endif
<span class="badge badge-sm badge-outline badge-warning mt-2" onclick="viewPDF('{{ Storage::url($dokumen_jaminan[$index]) }}')"><i class="ki-filled ki-eye mr-2"></i>Preview</span> <span class="badge badge-sm badge-outline badge-warning mt-2" onclick="viewPDF('{{ Storage::url($dokumen_jaminan[$index]) }}')"><i class="ki-filled ki-eye mr-2"></i>Preview</span>
<br>
@endforeach
@endif
</div> </div>
</div> </div>
<div class="border-t border-gray-300 border-dashed">
</div>
@if(isset($detail->details)) @if(isset($detail->details))
@if(json_decode($detail->details)) @if(json_decode($detail->details)[$index])
@foreach (json_decode($detail->details) as $key => $value) @foreach (json_decode($detail->details)[$index] as $key => $value)
<div class="flex items-start justify-between flex-wrap my-2.5 gap-2"> <div class="flex items-start justify-between flex-wrap my-2.5 gap-2">
<span class="text-2xs text-gray-600 uppercase pl-3"> <span class="text-2xs text-gray-600 uppercase pl-3">
{{ str_replace("_"," ",$key) ?? "" }} {{ str_replace("_"," ",$key) ?? "" }}
</span> </span>
<p class="text-2xs text-gray-600 text-right max-w-[250px]"> <p class="text-2xs text-gray-600 text-right max-w-[250px]">
{{ $value ?? "" }} {{ $value }}
</p> </p>
</div> </div>
<div class="border-t border-gray-300 border-dashed"> <div class="border-t border-gray-300 border-dashed">
@@ -118,6 +126,9 @@
@endforeach @endforeach
@endif @endif
@endif @endif
@endforeach
@endif
<div class="flex items-start justify-between flex-wrap my-2.5 gap-2"> <div class="flex items-start justify-between flex-wrap my-2.5 gap-2">
<span class="text-2xs text-gray-600 uppercase pl-3"> <span class="text-2xs text-gray-600 uppercase pl-3">