mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-21 13:34:00 +00:00
106 lines
4.1 KiB
PHP
106 lines
4.1 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;
|
|
use App\Http\Controllers\Controller;
|
|
use Carbon\Carbon;
|
|
|
|
class ExportArrivedParcelController extends Controller
|
|
{
|
|
/**
|
|
* ExportArrivedParcelController constructor.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth.check');
|
|
// $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)
|
|
{
|
|
|
|
$validated = $request->validate([
|
|
'startDate' => 'nullable|date_format:d-m-Y',
|
|
'endDate' => 'nullable|date_format:d-m-Y|after_or_equal:startDate',
|
|
]);
|
|
|
|
$startDate = null;
|
|
$endDate = null;
|
|
|
|
if (isset($validated['startDate']) && $validated['startDate']) {
|
|
$startDate = Carbon::createFromFormat('d-m-Y', $validated['startDate'])->startOfDay();
|
|
}
|
|
|
|
if (isset($validated['endDate']) && $validated['endDate']) {
|
|
$endDate = Carbon::createFromFormat('d-m-Y', $validated['endDate'])->endOfDay();
|
|
}
|
|
|
|
$exportsParcelsSummary = new ExportsParcel($startDate, $endDate);
|
|
$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;
|
|
}
|
|
}
|
|
}
|