Merge branch 'dillon/34.1-jenkins-vapor' into vapor/development

This commit is contained in:
Dillon Ngo
2024-04-26 15:53:37 +08:00
@@ -56,24 +56,6 @@ class BulkDownloadCustomerInvoicesLogic
$filesystemDriver = Storage::getDefaultDriver();
if($filesystemDriver == 's3'){
$zip = new ZipArchive();
$zipDataStr = '';
foreach ($invoicebookings as $booking) {
$invoiceFile = $booking->documents()
->where('document_type', DocumentType::INVOICE)
->whereNull('deleted_at')
->first()
->files()
->first();
$fileContent = Storage::disk('s3')
->get('documents/'.$invoiceFile->file->file_info->original->file);
$zipDataStr .= 'invoice-' . $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf';
$zipDataStr .= "\n"; // Add a separator
$zipDataStr .= $fileContent;
}
$zipDirectory = storage_path('app/bulk_invoice'); // Update this with the actual directory path
@@ -81,14 +63,19 @@ class BulkDownloadCustomerInvoicesLogic
mkdir($zipDirectory, 0755, true);
}
$zipFileName = "{$zipDirectory}/invoices_{$startDate}_to_{$endDate}_{$company->reference}.zip";
$zipFileName = "invoices_{$startDate}_to_{$endDate}_{$company->reference}.zip";
$zip_file = "{$zipDirectory}/{$zipFileName}";
if ($zip->open($zipFileName, ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
$zip->addFromString($zipFileName, $zipDataStr);
$zip = new ZipArchive();
if ($zip->open($zip_file, ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
foreach ($invoicebookings as $booking) {
$invoice_file = $booking->documents()->where('document_type', DocumentType::INVOICE)->whereNull('deleted_at')->first()->files()->first();
$zip->addFile(Storage::disk('documents')->path($invoice_file->file->file_info->original->file), 'invoice-' . $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf');
}
$zip->close();
$filePath = 'bulk_invoice/'.$zipFileName;
Storage::put($filePath, file_get_contents($zipFileName), 's3');
Storage::put($filePath, file_get_contents($zip_file), 's3');
return response(['src' => Storage::disk('s3')->get($$filePath) ]);