pembetulan api untuk pelanggan baru

This commit is contained in:
BTMS2
2025-05-15 14:52:55 +08:00
parent 3aabdd6d4b
commit 78fbc4dba1
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'), // Get the customer count from the service
DB::raw('sum(pinjaman) as sum_pinjaman') $bilangan_customer_baru = $reportRingkasanHarianService->getCustomerSummary(); // Call public method
)
->whereIn('nokp', function ($sub) use ($startDate, $endDate) { // Return the response
$sub->select('nokp') return [
->from('gadai as g2') 'kodcaw' => $cawangan_detail['kodcaw'],
->groupBy('nokp') 'details_caw' => $cawangan_detail['details_caw'],
->havingRaw('MIN(t_gadai) BETWEEN ? AND ?', [$startDate, $endDate]); 'total_pelanggan_baru' => $bilangan_customer_baru,
}); ];
}, $active_cawangan_db_connection, $active_cawangan_detail);
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);
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)