Add Bulk Download Pada Dokumen Jaminan
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
use Modules\Lpj\Models\JenisJaminan;
|
||||
use Modules\Lpj\Models\JenisLegalitasJaminan;
|
||||
use Modules\Lpj\Models\PemilikJaminan;
|
||||
use ZipArchive;
|
||||
|
||||
class DokumenJaminanController extends Controller
|
||||
{
|
||||
@@ -274,6 +275,45 @@
|
||||
}
|
||||
}
|
||||
|
||||
public function bulkDownload()
|
||||
{
|
||||
$dokumenIds = request()->get('jaminan'); // Expecting an array of dokumen_jaminan_id
|
||||
$documents = DetailDokumenJaminan::where('dokumen_jaminan_id', $dokumenIds)->get();
|
||||
if ($documents->isEmpty()) {
|
||||
return redirect()->back()->with('error', 'No documents found for the provided IDs.');
|
||||
}
|
||||
|
||||
$zip = new ZipArchive;
|
||||
$zipFileName = 'documents_jaminan_' . $dokumenIds . '.zip';
|
||||
$zipFilePath = storage_path('app/public/' . $zipFileName);
|
||||
|
||||
if ($zip->open($zipFilePath, ZipArchive::CREATE) === true) {
|
||||
foreach ($documents as $document) {
|
||||
$filePath = storage_path('app/public/' . $document->dokumen_jaminan);
|
||||
if (file_exists($filePath)) {
|
||||
$zip->addFile($filePath, basename($filePath));
|
||||
} else {
|
||||
// Log or display an error message for missing files
|
||||
return redirect()->back()->with('error', 'File not found: ' . $filePath);
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
|
||||
if (!file_exists($zipFilePath)) {
|
||||
return redirect()->back()->with('error', 'Failed to create ZIP file.');
|
||||
}
|
||||
} else {
|
||||
return redirect()->back()->with('error', 'Failed to create ZIP file.');
|
||||
}
|
||||
sleep(10);
|
||||
return response()->download($zipFilePath, $zipFileName, [
|
||||
'Content-Type' => 'application/zip',
|
||||
'Content-Disposition' => 'attachment; filename="' . $zipFileName . '"',
|
||||
'Content-Length' => filesize($zipFilePath),
|
||||
])->deleteFileAfterSend(false);
|
||||
}
|
||||
|
||||
|
||||
public function download()
|
||||
{
|
||||
$dokumen = request()->get('dokumen');
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
'branch_id' => 'required|exists:branches,id',
|
||||
'tujuan_penilaian_id' => 'required|exists:tujuan_penilaian,id',
|
||||
'debiture_id' => 'required|exists:debitures,id',
|
||||
'status' => 'required|string|default:order',
|
||||
'status' => 'required|string',
|
||||
'jenis_fasilitas_kredit_id' => 'required|exists:jenis_fasilitas_kredit,id',
|
||||
'nilai_plafond_id' => 'required|exists:nilai_plafond,id',
|
||||
'status_bayar' => 'required|string',
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
</div>
|
||||
<div class="menu inline-flex" data-menu="true">
|
||||
<div class="flex flex-nowrap justify-center gap-1.5">
|
||||
<a href="{{ route('debitur.jaminan.bulk.download',['id' => $debitur->id,'jaminan' => $document->id]) }}" class="btn btn-sm btn-icon btn-outline btn-success">
|
||||
<i class="ki-outline ki-cloud-download"></i>
|
||||
</a>
|
||||
<a href="{{ route('debitur.jaminan.edit',['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>
|
||||
|
||||
@@ -298,6 +298,7 @@ Route::middleware(['auth'])->group(function () {
|
||||
|
||||
Route::name('jaminan.')->prefix('{id}/jaminan')->group(function () {
|
||||
Route::get('download', [DokumenJaminanController::class, 'download'])->name('download');
|
||||
Route::get('bulk-download', [DokumenJaminanController::class, 'bulkDownload'])->name('bulk.download');
|
||||
Route::get('/', [DokumenJaminanController::class, 'index'])->name('index');
|
||||
Route::get('create', [DokumenJaminanController::class, 'create'])->name('create');
|
||||
Route::get('{jaminan}/edit', [DokumenJaminanController::class, 'edit'])->name('edit');
|
||||
|
||||
Reference in New Issue
Block a user