mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 20:43:56 +00:00
68 lines
2.4 KiB
PHP
68 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Exports;
|
|
|
|
|
|
use App\Classes\Modules\Exports\Services\ExportsAnalyticBookingTransactions;
|
|
use App\Classes\Modules\Exports\Services\ExportsAnalyticBillingTransactions;
|
|
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
|
|
{
|
|
|
|
/**
|
|
* ExportAnalyticToExcelController constructor.
|
|
* @param Request $request
|
|
*/
|
|
public function __construct(Request $request)
|
|
{
|
|
$token = Auth::fromUser(User::find(1));
|
|
$request->headers->set('Authorization', 'Bearer '.$token);
|
|
}
|
|
|
|
public function bookingData(ExportsAnalyticBookingTransactions $exportsAnalyticBookingTransactions, Request $request){
|
|
$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){
|
|
$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;
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|