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,
'name' => $request->name[$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 = [];

View File

@@ -282,50 +282,52 @@
<input class="input " type="text" id="name" name="name[]" value="{{ $detail->name ?? "" }}" placeholder="Nomor">
</div>
</div>
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
<label class="form-label max-w-56">
Dokumen Jaminan
</label>
<div class="flex flex-wrap items-baseline w-full">
<div class="flex flex-col w-full gap-2" id="file-container-{{$n}}">
<div class="flex items-center gap-2">
<input class="flex-1 input" type="text" name="dokumen_nomor[{{ $n }}][]" placeholder="Nomor Dokumen">
<input class="flex-1 file-input" type="file" name="dokumen_jaminan[{{ $n }}][]" accept=".pdf,image/*">
<button type="button" class="flex-none btn btn-primary w-[100px] text-center" onclick="addFileInput({{ $n }})">Add More</button>
</div>
<div id="additional-files-{{ $n }}"></div>
</div>
@if(isset($detail->dokumen_jaminan))
@if(isset($detail->dokumen_jaminan))
@php
$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] : []);
@endphp
<div class="flex flex-col w-full gap-2">
@foreach($dokumen_jaminan as $index => $dokumen)
<div class="flex w-full lg:w-[30%]">
@if(!empty($dokumen_nomor))
<span class="flex-1 mt-2 text-info text-sm">Nomor Dokumen : {{ $dokumen_nomor[$index] }}</span>
@endif
<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">
{{ basename($dokumen) }}
<i class="ki-filled ki-cloud-download"></i>
</a>
</div>
@endforeach
<div id="document-container-${index}">
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
<label class="form-label max-w-56">
Dokumen Jaminan
</label>
<div class="flex flex-wrap items-baseline w-full">
<div class="flex flex-col w-full gap-2" id="file-container-{{$n}}">
<div class="flex items-center gap-2">
<input class="flex-1 input" type="text" name="dokumen_nomor[{{ $n }}][]" placeholder="Nomor Dokumen">
<input class="flex-1 file-input" type="file" name="dokumen_jaminan[{{ $n }}][]" accept=".pdf,image/*">
<button type="button" class="flex-none btn btn-primary w-[100px] text-center" onclick="addFileInput({{ $n }})">Add More</button>
</div>
<div id="additional-files-{{ $n }}"></div>
</div>
@if(isset($detail->dokumen_jaminan))
@if(isset($detail->dokumen_jaminan))
@php
$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] : []);
@endphp
<div class="flex flex-col w-full gap-2">
@foreach($dokumen_jaminan as $index => $dokumen)
<div class="flex w-full lg:w-[30%]">
@if(!empty($dokumen_nomor))
<span class="flex-1 mt-2 text-info text-sm">Nomor Dokumen : {{ $dokumen_nomor[$index] }}</span>
@endif
<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">
{{ basename($dokumen) }}
<i class="ki-filled ki-cloud-download"></i>
</a>
</div>
@endforeach
</div>
@endif
@endif
@endif
</div>
</div>
<div id="document-container"></div>
</div>
@if($detail->details)
@if($detail->jenisLegalitasJaminan->custom_fields)
@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
$customField = getCustomField($key);
$fieldValue = json_decode($detail->details)->{$customField->name} ?? '';
@@ -600,33 +602,36 @@
<input class="input" type="text" name="name[]" value="${item.name || ""}" placeholder="Nomor">
</div>
</div>
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
<label class="form-label max-w-56">
Dokumen Jaminan
</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) : ""}
</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">
<input class="flex-1 file-input" type="file" name="dokumen_jaminan[${index}][]" accept=".pdf,image/*">
<button type="button" class="flex-none btn btn-primary w-[100px] text-center" onclick="addFileInput(${index})">Add File</button>
<div id="document-container-${index}">
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
<label class="form-label max-w-56">
Dokumen Jaminan
</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) : ""}
</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">
<input class="flex-1 file-input" type="file" name="dokumen_jaminan[${index}][]" accept=".pdf,image/*">
<button type="button" class="flex-none btn btn-primary w-[100px] text-center" onclick="addFileInput(${index})">Add File</button>
</div>
</div>
</div>
</div>
${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">
<label class="form-label max-w-56 capitalize">
${field.label}
</label>
<div class="flex flex-wrap items-baseline w-full">
${getCustomFieldInput(field.type, field.name, item.details, item.jenis_legalitas_jaminan_id)}
${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 mb-2 custom-field">
<label class="form-label max-w-56 capitalize">
${field.label}
</label>
<div class="flex flex-wrap items-baseline w-full">
${getCustomFieldInput(index, field.type, field.name, item.details, item.jenis_legalitas_jaminan_id, 0)}
</div>
</div>
`).join('') : ""}
<div id="document_container"></div>
</div>
`).join('') : ""}
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
<label class="form-label max-w-56">
@@ -643,19 +648,51 @@
}
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");
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 = `
<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 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>
`;
</div>
</div>
${customFieldsHtml}
`;
container.appendChild(newInput);
}
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) {
@@ -707,19 +744,19 @@
return dokumenNomor;
}
function getCustomFieldInput(type, fieldName, value, itemId) {
function getCustomFieldInput(index, type, fieldName, value, itemId, fieldIndex = 0) {
value = value ? JSON.parse(value)[fieldName] || "" : "";
switch (type) {
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":
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":
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":
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:
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)
<div class="flex items-center justify-between flex-wrap my-2.5 gap-2">
<span class="text-2xs text-gray-600 uppercase">
{{ $loop->index+1 }}. {{ $detail->jenisLegalitasJaminan->name }}
<strong>{{ $loop->index+1 }}. {{ $detail->jenisLegalitasJaminan->name }}</strong>
</span>
<div>
@if(isset($detail->dokumen_jaminan))
@php
$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] : []);
@endphp
@foreach($dokumen_jaminan as $index => $dokumen)
&nbsp;
</div>
</div>
<div class="border-t border-gray-300 border-dashed"></div>
@if(isset($detail->dokumen_jaminan))
@php
$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] : []);
$count_jaminan = 0;
@endphp
@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']))
<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">
@@ -95,30 +106,30 @@
</a>
@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>
<br>
@endforeach
</div>
</div>
@if(isset($detail->details))
@if(json_decode($detail->details)[$index])
@foreach (json_decode($detail->details)[$index] as $key => $value)
<div class="flex items-start justify-between flex-wrap my-2.5 gap-2">
<span class="text-2xs text-gray-600 uppercase pl-3">
{{ str_replace("_"," ",$key) ?? "" }}
</span>
<p class="text-2xs text-gray-600 text-right max-w-[250px]">
{{ $value }}
</p>
</div>
<div class="border-t border-gray-300 border-dashed">
</div>
@endforeach
@endif
@endif
</div>
</div>
<div class="border-t border-gray-300 border-dashed">
</div>
@if(isset($detail->details))
@if(json_decode($detail->details))
@foreach (json_decode($detail->details) as $key => $value)
<div class="flex items-start justify-between flex-wrap my-2.5 gap-2">
<span class="text-2xs text-gray-600 uppercase pl-3">
{{ str_replace("_"," ",$key) ?? "" }}
</span>
<p class="text-2xs text-gray-600 text-right max-w-[250px]">
{{ $value ?? "" }}
</p>
</div>
<div class="border-t border-gray-300 border-dashed">
</div>
@endforeach
@endif
@endforeach
@endif
<div class="flex items-start justify-between flex-wrap my-2.5 gap-2">
<span class="text-2xs text-gray-600 uppercase pl-3">
keterangan