Update document handling to support multiple files per entry
This update enhances the `DokumenJaminan` model to support multiple files for each document entry. It modifies both the backend logic to store multiple files and the frontend view to display and handle these files correctly. Additionally, it includes functionality to delete old document files if they are no longer associated with any detail document entry.
This commit is contained in:
@@ -167,8 +167,16 @@
|
||||
</div>
|
||||
|
||||
@if(isset($detail->dokumen_jaminan))
|
||||
<a href="{{ route('debitur.jaminan.download',['id'=>$debitur->id,'dokumen'=>$detail->id]) }}" class="badge badge-sm badge-outline mt-2">{{ basename($detail->dokumen_jaminan) }}
|
||||
<i class="ki-filled ki-cloud-download"></i></a>
|
||||
@php
|
||||
$dokumen_jaminan = is_array(json_decode($detail->dokumen_jaminan)) ? json_decode($detail->dokumen_jaminan) : [$detail->dokumen_jaminan];
|
||||
@endphp
|
||||
@foreach($dokumen_jaminan as $index => $dokumen)
|
||||
<a href="{{ route('debitur.jaminan.download', ['id' => $debitur->id, 'dokumen' => $detail->id, 'index' => $index]) }}"
|
||||
class="badge badge-sm badge-outline mt-2 mr-2">
|
||||
{{ basename($dokumen) }}
|
||||
<i class="ki-filled ki-cloud-download"></i>
|
||||
</a>
|
||||
@endforeach
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
@@ -527,6 +535,25 @@
|
||||
.catch(error => console.error('Error:', error));
|
||||
}
|
||||
|
||||
function renderExistingFiles(dokumenJaminan, debiturId, itemId) {
|
||||
if (typeof dokumenJaminan === 'string') {
|
||||
return `
|
||||
<a href="/debitur/${debiturId}/jaminan/download?dokumen=${itemId}" class="badge badge-sm badge-outline mt-2 mr-2">
|
||||
${dokumenJaminan.split('/').pop()}
|
||||
<i class="ki-filled ki-cloud-download"></i>
|
||||
</a>
|
||||
`;
|
||||
} else if (Array.isArray(dokumenJaminan)) {
|
||||
return dokumenJaminan.map(file => `
|
||||
<a href="/debitur/${debiturId}/jaminan/download?dokumen=${itemId}&file=${encodeURIComponent(file)}" class="badge badge-sm badge-outline mt-2 mr-2">
|
||||
${file.split('/').pop()}
|
||||
<i class="ki-filled ki-cloud-download"></i>
|
||||
</a>
|
||||
`).join('');
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function addFileInput(index) {
|
||||
const container = document.getElementById(`file-container-${index}`);
|
||||
const newInput = document.createElement('div');
|
||||
|
||||
Reference in New Issue
Block a user