diff --git a/app/Http/Controllers/Reports/GadaianController.php b/app/Http/Controllers/Reports/GadaianController.php index ac5fd80..149de0d 100644 --- a/app/Http/Controllers/Reports/GadaianController.php +++ b/app/Http/Controllers/Reports/GadaianController.php @@ -26,13 +26,24 @@ class GadaianController extends Controller $startDate = $request->startDate; $endDate = $request->endDate; + // Get active branch DBs from helper $active_cawangan_db_connection = Helper::getActiveCawanganDbConnection(); - - $active_cawangan_db_name = array_map(function ($db_connection) { - return config('database.connections' . '.' . $db_connection . '.' . 'database'); - }, $active_cawangan_db_connection); - - $active_cawangan_detail = Cawangan::select('kodcaw', 'details_caw')->whereIn('db_name', $active_cawangan_db_name)->get()->toArray(); + + // 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(); $summary_gadaian_data = array_map(function ($db_connection) use ($request) { $query = Gadai::on($db_connection); diff --git a/app/Http/Controllers/Reports/PenebusanController.php b/app/Http/Controllers/Reports/PenebusanController.php index 4a4447b..4a79cb0 100644 --- a/app/Http/Controllers/Reports/PenebusanController.php +++ b/app/Http/Controllers/Reports/PenebusanController.php @@ -21,16 +21,24 @@ class PenebusanController extends Controller public function getSummaryLaporanTebus(Request $request) { + // Get active branch DBs from helper $active_cawangan_db_connection = Helper::getActiveCawanganDbConnection(); - $arrahn_master_db_connection = Cawangan::all()->pluck('mysql')->toArray(); - - $active_cawangan_db_connection = array_intersect($active_cawangan_db_connection, $arrahn_master_db_connection); - - $active_cawangan_db_name = array_map(function ($db_connection) { - return config('database.connections' . '.' . $db_connection . '.' . 'database'); - }, $active_cawangan_db_connection); - - $active_cawangan_detail = Cawangan::select('kodcaw', 'details_caw')->whereIn('db_name', $active_cawangan_db_name)->get()->toArray(); + + // 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(); $summary_penebusan_data = array_map(function ($db_connection) use ($request) { $penebusan = Tebus::on($db_connection)