50 lines
1.8 KiB
PHP
50 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Reports;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
use App\Exports\LaporanKeseluruhan\BayaranOnlineExport;
|
|
|
|
class BayaranOnlineDetailController extends Controller
|
|
{
|
|
public function __invoke(Request $request)
|
|
{
|
|
$startDate = $request->filled('startDate') ?
|
|
Carbon::parse($request->startDate)->startOfDay() :
|
|
Carbon::now()->startOfDay();
|
|
|
|
$endDate = $request->filled('endDate') ?
|
|
Carbon::parse($request->endDate)->startOfDay() :
|
|
Carbon::now()->endOfDay();
|
|
|
|
$responseTransactions = Http::get(config('api.url') . '/api/reports/bayaran-online-detail', [
|
|
'startDate' => $startDate->toDateString(),
|
|
'endDate' => $endDate->toDateString(),
|
|
'status' => $request->status ?? 'PAID',
|
|
'kodcaw' => $request->kodcaw ?? '',
|
|
]);
|
|
|
|
|
|
if($responseTransactions->failed()){
|
|
throw new \Exception("Something wrong with the API", 1);
|
|
}
|
|
|
|
|
|
$data = $responseTransactions->json();
|
|
|
|
$title = 'laporan_bayaran_online';
|
|
$cawangan = $request->details_caw ?? 'Semua Cawangan';
|
|
$tarikh_carian = $startDate->toFormattedDateString() . ' hingga ' . $endDate->toFormattedDateString();
|
|
$tarikh_cetak = 'cetak pada ' . Carbon::now()->toDayDateTimeString();
|
|
|
|
$title = '--'.$title . '--' . $cawangan . '--' . $tarikh_carian . '--' . $tarikh_cetak . '--' . '.xlsx';
|
|
|
|
return Excel::download(new BayaranOnlineExport($data), $title);
|
|
}
|
|
|
|
}
|