tambah laporan aging penebusan
This commit is contained in:
@@ -9,7 +9,7 @@ use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Exports\LaporanKeseluruhan\AgingAllExportExcel;
|
||||
use App\Exports\LaporanKeseluruhan\AgingTebusAllExportExcel;
|
||||
|
||||
class AgingController extends Controller
|
||||
{
|
||||
@@ -81,4 +81,77 @@ class AgingController extends Controller
|
||||
}
|
||||
return view('reports.aging.index', compact('aging', 'endDate'));
|
||||
}
|
||||
|
||||
public function agingtebus(Request $request)
|
||||
{
|
||||
$current = new Carbon();
|
||||
$request->hostname = config('api.url');
|
||||
// dd($request->hostname );
|
||||
$kod_cawangan = $request->kod_cawangan;
|
||||
$action = $request->input('action', 'search');
|
||||
// dd($action);
|
||||
|
||||
$getReportDate = function ($date_string) use ($current) {
|
||||
if ($date_string == null) {
|
||||
return $current->toDateString();
|
||||
}
|
||||
|
||||
return $date_string;
|
||||
};
|
||||
|
||||
$request->hostname = config('api.url');
|
||||
|
||||
$startDate = $getReportDate($request->startDate);
|
||||
|
||||
$endDate = $getReportDate($request->endDate);
|
||||
|
||||
$aging = Http::get($request->hostname . '/api/reports/agingtebus', [
|
||||
'startDate' => $startDate,
|
||||
'endDate' => $endDate,
|
||||
])->json();
|
||||
|
||||
$aging = $aging ?? [];
|
||||
|
||||
if ($action === 'excel') {
|
||||
$file_title = sprintf("LaporanAging(%s).xlsx", $kod_cawangan, $startDate, $endDate);
|
||||
return Excel::download(new AgingTebusAllExportExcel($aging,$startDate,$endDate), $file_title);
|
||||
}
|
||||
|
||||
return view('reports.agingtebus.index', compact('aging', 'startDate', 'endDate'));
|
||||
}
|
||||
public function showagingtebus(Request $request)
|
||||
{
|
||||
$current = Carbon::now();
|
||||
$action = $request->input('action', 'search');
|
||||
|
||||
$getReportDate = function ($date_string) use ($current) {
|
||||
return $date_string ? $date_string : $current->toDateString();
|
||||
};
|
||||
|
||||
$hostname = config('api.url');
|
||||
|
||||
$startDate = $getReportDate($request->startDate);
|
||||
$endDate = $getReportDate($request->endDate);
|
||||
|
||||
$response = Http::get("$hostname/api/reports/agingtebus", [
|
||||
'startDate' => $startDate,
|
||||
'endDate' => $endDate,
|
||||
]);
|
||||
|
||||
$aging = $response->json() ?? []; // Ensure it's an array
|
||||
|
||||
// Debugging: Check the response before using it
|
||||
if (empty($aging)) {
|
||||
return back()->with('error', 'Failed to fetch data from API.');
|
||||
}
|
||||
|
||||
if ($action === 'excel') {
|
||||
// Ensure $kod_cawangan is defined (Modify as per your data structure)
|
||||
$kod_cawangan = $request->input('kod_cawangan', 'DEFAULT');
|
||||
|
||||
$file_title = sprintf("LaporanAgingTebus(%s).xlsx", $kod_cawangan, $startDate, $endDate);
|
||||
return Excel::download(new AgingTebusAllExportExcel($aging, $startDate, $endDate), $file_title);
|
||||
}
|
||||
return view('reports.agingtebus.index', compact('aging', 'startDate', 'endDate'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user