Files
shipping-portal/app/Http/Controllers/Exports/ExportArrivedParcelController.php
T

87 lines
3.4 KiB
PHP

<?php
namespace App\Http\Controllers\Exports;
use App\Classes\Modules\Exports\Services\ExportsArrivedParcel;
use App\Classes\Modules\Exports\Services\ExportsParcel;
use App\Classes\Modules\Exports\Services\ExportsWarehousePackingList;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Maatwebsite\Excel\Excel;
use App\Classes\Modules\Exports\Services\ExportsAgingList;
use Illuminate\Support\Facades\Storage;
use App\Classes\General\AWSS3Helper;
class ExportArrivedParcelController
{
/**
* ExportArrivedParcelController constructor.
* @param Request $request
*/
public function __construct(Request $request)
{
$token = Auth::fromUser(User::find(1));
$request->headers->set('Authorization', 'Bearer '.$token);
}
public function export(Request $request) {
$startDate = $request->query('start_date');
$endDate = $request->query('end_date');
$exportsPendingArrangementDeliveryList = new ExportsArrivedParcel($startDate, $endDate);
$exportFileName = 'arrived-parcel.xlsx';
$filesystemDriver = Storage::getDefaultDriver();
if($filesystemDriver === 's3'){
return response([ 'src' => AWSS3Helper::S3Exportable($exportFileName, $exportsPendingArrangementDeliveryList) ]);
}
else{
$response = $exportsPendingArrangementDeliveryList->download($exportFileName, Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
ob_end_clean();
return $response;
}
}
public function summary(Request $request) {
$exportsParcelsSummary = new ExportsParcel();
$exportFileName = 'parcel-summary.xls';
$filesystemDriver = Storage::getDefaultDriver();
if($filesystemDriver === 's3'){
return response([ 'src' => AWSS3Helper::S3Exportable($exportFileName, $exportsParcelsSummary) ]);
}
else{
$response = $exportsParcelsSummary->download($exportFileName, Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
ob_end_clean();
return $response;
}
}
public function guangZhou2ToJohor(Request $request) {
$exportsWarehousePackingList = new ExportsWarehousePackingList();
$exportFileName = 'guangzhou2-to-johor-summary.xls';
$filesystemDriver = Storage::getDefaultDriver();
if($filesystemDriver === 's3'){
return response([ 'src' => AWSS3Helper::S3Exportable($exportFileName, $exportsWarehousePackingList) ]);
}
else{
$response = $exportsWarehousePackingList->download($exportFileName, Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
ob_end_clean();
return $response;
}
}
public function aging(Request $request) {
$data = new ExportsAgingList();
$exportFileName = 'aging_report.xls';
$filesystemDriver = Storage::getDefaultDriver();
if($filesystemDriver === 's3'){
return response([ 'src' => AWSS3Helper::S3Exportable($exportFileName, $data) ]);
}
else{
$response = $data->download($exportFileName, Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
ob_end_clean();
return $response;
}
}
}