From 78fbc4dba195cfa3534c99103a9ba9b354f37a8c Mon Sep 17 00:00:00 2001 From: BTMS2 Date: Thu, 15 May 2025 14:52:55 +0800 Subject: [PATCH] pembetulan api untuk pelanggan baru --- .../Controllers/Reports/AnalisaController.php | 37 ++++++++----------- .../Reports/RingkasanHarianService.php | 6 +++ 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/app/Http/Controllers/Reports/AnalisaController.php b/app/Http/Controllers/Reports/AnalisaController.php index ebf5b75..b1ddf36 100644 --- a/app/Http/Controllers/Reports/AnalisaController.php +++ b/app/Http/Controllers/Reports/AnalisaController.php @@ -9,6 +9,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use App\Services\Reports\GadaianService as ReportGadaianService; use App\Helper; +use App\Services\Reports\RingkasanHarianService as ReportRingkasanHarianService; class AnalisaController extends Controller @@ -41,27 +42,21 @@ class AnalisaController extends Controller ]; })->values()->toArray(); - $summary_gadaian_data = array_map(function ($db_connection) use ($startDate, $endDate) { - $query = Gadai::on($db_connection) - ->select( - DB::raw('count(DISTINCT nokp) as total_pelanggan_baru'), - DB::raw('sum(berat) as sum_berat'), - DB::raw('sum(nilaimarhun) as sum_nilai_marhun'), - DB::raw('sum(pinjaman) as sum_pinjaman') - ) - ->whereIn('nokp', function ($sub) use ($startDate, $endDate) { - $sub->select('nokp') - ->from('gadai as g2') - ->groupBy('nokp') - ->havingRaw('MIN(t_gadai) BETWEEN ? AND ?', [$startDate, $endDate]); - }); - - return $query->get()->toArray(); - }, $active_cawangan_db_connection); - - $response = array_map(function ($cawangan_detail, $summary_gadaian_data) { - return array_merge($cawangan_detail, $summary_gadaian_data[0]); - }, $active_cawangan_detail, $summary_gadaian_data); + // 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); } diff --git a/app/Services/Reports/RingkasanHarianService.php b/app/Services/Reports/RingkasanHarianService.php index b2331bf..4167b47 100644 --- a/app/Services/Reports/RingkasanHarianService.php +++ b/app/Services/Reports/RingkasanHarianService.php @@ -266,6 +266,12 @@ class RingkasanHarianService } + // Public method that calls the private method + public function getCustomerSummary() + { + return $this->getBilanganCustomerBaru(); // Access the private method here + } + private function getBayarRugiLelong() { $bayarRugiLelong = TuntutBaki::on($this->connectionCawangan)