diff --git a/app/Http/Controllers/Exports/ExportAnalyticToExcelController.php b/app/Http/Controllers/Exports/ExportAnalyticToExcelController.php index 2a93a991..af90dbb5 100644 --- a/app/Http/Controllers/Exports/ExportAnalyticToExcelController.php +++ b/app/Http/Controllers/Exports/ExportAnalyticToExcelController.php @@ -9,6 +9,8 @@ use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Maatwebsite\Excel\Excel; +use Illuminate\Support\Facades\Storage; +use Carbon\Carbon; class ExportAnalyticToExcelController { @@ -24,14 +26,42 @@ class ExportAnalyticToExcelController } public function bookingData(ExportsAnalyticBookingTransactions $exportsAnalyticBookingTransactions, Request $request){ - $response = $exportsAnalyticBookingTransactions->download('bookingData.csv', Excel::CSV, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']); - ob_end_clean(); - return $response; + $exportFileName = 'bookingData.csv'; + $filesystemDriver = Storage::getDefaultDriver(); + if($filesystemDriver === 's3'){ + return response([ 'src' => $this->S3($exportFileName, $exportsAnalyticBookingTransactions) ]); + } + else{ + $response = $exportsAnalyticBookingTransactions->download($exportFileName, Excel::CSV, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']); + ob_end_clean(); + return $response; + } } public function billingData(ExportsAnalyticBillingTransactions $exportsAnalyticBillingTransactions, Request $request){ - $response = $exportsAnalyticBillingTransactions->download('billingData.csv', Excel::CSV, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']); - ob_end_clean(); - return $response; + $exportFileName = 'billingData.csv'; + $filesystemDriver = Storage::getDefaultDriver(); + if($filesystemDriver === 's3'){ + return response([ 'src' => $this->S3($exportFileName, $exportsAnalyticBillingTransactions) ]); + } + else{ + $response = $exportsAnalyticBillingTransactions->download($exportFileName, Excel::CSV, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']); + ob_end_clean(); + return $response; + } } -} \ No newline at end of file + + private function S3($exportFileName, $exportableObject){ + //Step 1: Upload to S3 + $filePathForS3 = 'temp/' . $exportFileName; + $exportableObject->store($filePathForS3, 's3'); + + //Step 2: Return temporary URL from S3 + $temporaryUrl = Storage::disk('s3')->temporaryUrl( + $filePathForS3, + Carbon::now()->addMinutes(10) + ); + + return $temporaryUrl; + } +} diff --git a/app/Http/Controllers/Exports/ExportCustomersWalletTransactionToExcelController.php b/app/Http/Controllers/Exports/ExportCustomersWalletTransactionToExcelController.php index c4457565..d19cf8e8 100644 --- a/app/Http/Controllers/Exports/ExportCustomersWalletTransactionToExcelController.php +++ b/app/Http/Controllers/Exports/ExportCustomersWalletTransactionToExcelController.php @@ -7,6 +7,8 @@ use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Maatwebsite\Excel\Excel; +use Illuminate\Support\Facades\Storage; +use Carbon\Carbon; class ExportCustomersWalletTransactionToExcelController { @@ -24,9 +26,29 @@ class ExportCustomersWalletTransactionToExcelController public function export(Request $request) { $exportsTransactions = new ExportsCustomersWalletTransactionHistory($request); - $filename = $request->route('marking') . '-wallet-' . ($request->route('is_precise') == 'true' ? 'precise-' : '') . 'transaction-history.xls'; - $response = $exportsTransactions->download($filename, Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']); - ob_end_clean(); - return $response; + $exportFileName = $request->route('marking') . '-wallet-' . ($request->route('is_precise') == 'true' ? 'precise-' : '') . 'transaction-history.xls'; + $filesystemDriver = Storage::getDefaultDriver(); + if($filesystemDriver === 's3'){ + return response([ 'src' => $this->S3($exportFileName, $exportsTransactions) ]); + } + else{ + $response = $exportsTransactions->download($exportFileName, Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']); + ob_end_clean(); + return $response; + } + } + + private function S3($exportFileName, $exportableObject){ + //Step 1: Upload to S3 + $filePathForS3 = 'temp/' . $exportFileName; + $exportableObject->store($filePathForS3, 's3'); + + //Step 2: Return temporary URL from S3 + $temporaryUrl = Storage::disk('s3')->temporaryUrl( + $filePathForS3, + Carbon::now()->addMinutes(10) + ); + + return $temporaryUrl; } } diff --git a/resources/assets/vue/components/accounting/elements/HistoryImportedInvoices.vue b/resources/assets/vue/components/accounting/elements/HistoryImportedInvoices.vue index d3d68cfb..d0dd1e93 100644 --- a/resources/assets/vue/components/accounting/elements/HistoryImportedInvoices.vue +++ b/resources/assets/vue/components/accounting/elements/HistoryImportedInvoices.vue @@ -3,7 +3,7 @@