getCawanganReport(); } public function getSummaryLaporanPelangganBaru(Request $request) { $startDate = $request->startDate; $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(); $active_cawangan_db_connection = array_column($cawangan_available->toArray(), 'mysql'); $active_cawangan_detail = $cawangan_available->map(function ($c) { return [ 'kodcaw' => $c->kodcaw, 'details_caw' => $c->details_caw, ]; })->values()->toArray(); // Iterate through each branch and get data $response = array_map(function ($db_connection, $cawangan_detail) use ($request) { // Pass the required parameters to the service constructor $reportRingkasanHarianService = new ReportRingkasanHarianService($cawangan_detail['kodcaw'], $request); // Get the customer count from the service $bilangan_customer_baru = $reportRingkasanHarianService->getCustomerSummary(); // Call public method // Return the response return [ 'kodcaw' => $cawangan_detail['kodcaw'], 'details_caw' => $cawangan_detail['details_caw'], 'total_pelanggan_baru' => $bilangan_customer_baru, ]; }, $active_cawangan_db_connection, $active_cawangan_detail); return response()->json($response); } }