Merge branch 'staging' of https://git.putrakuningan.com/daengdeni/lpj into tender

This commit is contained in:
2024-10-31 11:35:24 +07:00
13 changed files with 179 additions and 484 deletions

View File

@@ -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.');
}
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');