Merged in izzati-feat-pelanggan-baru (pull request #302)

pembetulan api untuk pelanggan baru
This commit is contained in:
izzati zulkifli
2025-05-15 06:55:00 +00:00
2 changed files with 22 additions and 21 deletions
@@ -9,6 +9,7 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use App\Services\Reports\GadaianService as ReportGadaianService; use App\Services\Reports\GadaianService as ReportGadaianService;
use App\Helper; use App\Helper;
use App\Services\Reports\RingkasanHarianService as ReportRingkasanHarianService;
class AnalisaController extends Controller class AnalisaController extends Controller
@@ -41,27 +42,21 @@ class AnalisaController extends Controller
]; ];
})->values()->toArray(); })->values()->toArray();
$summary_gadaian_data = array_map(function ($db_connection) use ($startDate, $endDate) { // Iterate through each branch and get data
$query = Gadai::on($db_connection) $response = array_map(function ($db_connection, $cawangan_detail) use ($request) {
->select( // Pass the required parameters to the service constructor
DB::raw('count(DISTINCT nokp) as total_pelanggan_baru'), $reportRingkasanHarianService = new ReportRingkasanHarianService($cawangan_detail['kodcaw'], $request);
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(); // Get the customer count from the service
}, $active_cawangan_db_connection); $bilangan_customer_baru = $reportRingkasanHarianService->getCustomerSummary(); // Call public method
$response = array_map(function ($cawangan_detail, $summary_gadaian_data) { // Return the response
return array_merge($cawangan_detail, $summary_gadaian_data[0]); return [
}, $active_cawangan_detail, $summary_gadaian_data); '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); return response()->json($response);
} }
@@ -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() private function getBayarRugiLelong()
{ {
$bayarRugiLelong = TuntutBaki::on($this->connectionCawangan) $bayarRugiLelong = TuntutBaki::on($this->connectionCawangan)