Files
admin-erahn/app/Http/Controllers/Reports/BayaranOnlineController.php
T
2025-06-14 15:23:41 +08:00

49 lines
1.9 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;
class BayaranOnlineController 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()->startOfDay();
$responseTransactionSortedByTotalCawanganPayment = Http::get(config('api.url') . '/api/reports/bayaran-online', [
'startDate' => $startDate->toDateString(),
'endDate' => $endDate->toDateString(),
'orderBy' => 'totalCawanganPayment',
]);
$responseTransactionSortedByTotalReferenceNo = Http::get(config('api.url') . '/api/reports/bayaran-online', [
'startDate' => $startDate->toDateString(),
'endDate' => $endDate->toDateString(),
'orderBy' => 'totalReferenceNo',
]);
if($responseTransactionSortedByTotalCawanganPayment->failed() OR $responseTransactionSortedByTotalReferenceNo->failed()){
throw new \Exception("Something wrong with the API", 1);
}
$data = [
'sortedByTotalCawanganPayment' => $responseTransactionSortedByTotalCawanganPayment->json(),
'sortedByTotalReferenceNo' => $responseTransactionSortedByTotalReferenceNo->json(),
];
return view('reports.bayaran-online.index', compact('data', 'startDate', 'endDate'));
}
}