From 9d4a0604fb7c2403386a2e12579f3a2ecb96051b Mon Sep 17 00:00:00 2001 From: BTMS2 Date: Mon, 21 Apr 2025 14:57:28 +0800 Subject: [PATCH] tambah laporan outstanding --- .../Reports/OutstandingController.php | 88 +++++++++++++++++++ routes/report.php | 2 + 2 files changed, 90 insertions(+) create mode 100644 app/Http/Controllers/Reports/OutstandingController.php diff --git a/app/Http/Controllers/Reports/OutstandingController.php b/app/Http/Controllers/Reports/OutstandingController.php new file mode 100644 index 0000000..88e8e33 --- /dev/null +++ b/app/Http/Controllers/Reports/OutstandingController.php @@ -0,0 +1,88 @@ +getCawanganReport(); + } + + public function getSummaryLaporanOutstanding(Request $request) + { + $endDate = $request->endDate; + + // Get active branch DBs from helper + $active_cawangan_db_connection = Helper::getActiveCawanganDbConnection(); + + // Fetch branch details with mysql info + $cawangan_available = Cawangan::select('kodcaw', 'details_caw', 'mysql') + ->whereIn('mysql', $active_cawangan_db_connection) + ->get(); + + // Get db connections + $active_cawangan_db_connection = array_column($cawangan_available->toArray(), 'mysql'); + + // Map branch info for response + $active_cawangan_detail = $cawangan_available->map(function ($c) { + return [ + 'kodcaw' => $c->kodcaw, + 'details_caw' => $c->details_caw, + ]; + })->values()->toArray(); + + // Query outstanding summary for each branch + $summary_Outstanding_data = array_map(function ($db_connection) use ($endDate) { + // SAG LAMA + $queryLama = Gadai::on($db_connection) + ->selectRaw('COUNT(norujukan) as total_gadaian, SUM(pinjaman) as sum_pinjaman') + ->where('tagbaru', 0) + ->where('sttebus', ''); + + // SAG BARU + $queryBaru = Gadai::on($db_connection) + ->selectRaw('COUNT(norujukan) as total_gadaian2, SUM(pinjaman) as sum_pinjaman2') + ->where('tagbaru', 1) + ->where('sttebus', ''); + + // SEMUA + $queryAll = Gadai::on($db_connection) + ->selectRaw('COUNT(norujukan) as total_gadaian_all, SUM(pinjaman) as sum_pinjaman_all') + ->where('sttebus', ''); + + if (!empty($endDate)) { + $queryLama->where('t_gadai', '<=', $endDate); + $queryBaru->where('t_gadai', '<=', $endDate); + $queryAll->where('t_gadai', '<=', $endDate); + } + + return array_merge( + $queryLama->first()->toArray(), + $queryBaru->first()->toArray(), + $queryAll->first()->toArray() + ); + }, $active_cawangan_db_connection); + + // Combine data with branch info + $response = array_map(function ($cawangan_detail, $outstanding_data) { + return array_merge($cawangan_detail, $outstanding_data); + }, $active_cawangan_detail, $summary_Outstanding_data); + + return response()->json($response); + } + + + +} diff --git a/routes/report.php b/routes/report.php index 1f9ab63..8f09b86 100644 --- a/routes/report.php +++ b/routes/report.php @@ -35,5 +35,7 @@ $router->group(['prefix' => 'api/reports'], function () use ($router) { $router->get('lelongan/{kod_cawangan}', ['uses' => 'LelonganController@getLaporanCawangan']); $router->get('aging', ['uses' => 'AgingController@getSummaryLaporanAging']); + + $router->get('outstanding', ['uses' => 'OutstandingController@getSummaryLaporanOutstanding']); }); });