added baki lelong and rugi lelong

This commit is contained in:
hafifierahman
2025-08-31 21:56:32 +08:00
parent 4c4dbe18c6
commit 2a8f3a1655
3 changed files with 77 additions and 3 deletions
+33 -3
View File
@@ -38,6 +38,8 @@ class HomeController extends Controller
->get(config('api.url_koop') . '/portal/customer/info', ['ic' => $authUser['icno']])
->json();
$customerLelong = $this->getCustomerInfoLelong($authUser['icno']);
// ['gadai' => $customer_gadai, 'lelong' => $customer_lelong] = $customerInfo;
$customer_gadai = array_merge(
$customer_pkb['gadai'] ?? [],
@@ -48,7 +50,7 @@ class HomeController extends Controller
$customer_pkb['lelong'] ?? [],
$customer_koop['lelong'] ?? []
);
// only get lelong that is harga jualan that is not null or 0
$customer_lelong = array_filter($customer_lelong, fn($x) => $x['hargajualan'] != null && $x['hargajualan'] != 0);
@@ -62,7 +64,7 @@ class HomeController extends Controller
$bilangan = sizeof($customer_gadai) + sizeOf($customer_lelong);
return view('includes.buffer', compact('bilangan', 'sixMonths', 'total', 'bilanganLelong', 'homeUrl'));
return view('includes.buffer', compact('bilangan', 'sixMonths', 'total', 'bilanganLelong', 'homeUrl','customerLelong'));
}
/**
@@ -83,6 +85,7 @@ class HomeController extends Controller
->get(config('api.url_koop') . '/portal/customer/info', ['ic' => $authUser['icno']])
->json();
$customerLelong = $this->getCustomerInfoLelong($authUser['icno']);
// ['gadai' => $customer_gadai, 'lelong' => $customer_lelong] = $customerInfo;
$customer_gadai = array_merge(
@@ -108,6 +111,33 @@ class HomeController extends Controller
$bilangan = sizeof($customer_gadai) + sizeOf($customer_lelong);
return view('includes.home', compact('bilangan', 'sixMonths', 'total', 'bilanganLelong', 'pembiayaan'));
return view('includes.home', compact('bilangan', 'sixMonths', 'total', 'bilanganLelong', 'pembiayaan','customerLelong'));
}
private function getCustomerInfoLelong($icno){
$customerLelong = Http::withOptions(['verify' => config('app.api_verify')])
->get(config('api.url') . '/portal/customer/info/lelong', ['ic' => $icno])
->json();
$customerLelongKoop = Http::withOptions(['verify' => config('app.api_verify')])
->get(config('api.url_koop') . '/portal/customer/info/lelong', ['ic' => $icno])
->json();
// Extract data with null safety
$bakiLelong = isset($customerLelong['success']) && $customerLelong['success']
? ($customerLelong['data']['bakilelong'] ?? 0) : 0;
$rugiLelong = isset($customerLelong['success']) && $customerLelong['success']
? ($customerLelong['data']['rugilelong'] ?? 0) : 0;
$bakiKoop = isset($customerLelongKoop['success']) && $customerLelongKoop['success']
? ($customerLelongKoop['data']['bakilelong'] ?? 0) : 0;
$rugiKoop = isset($customerLelongKoop['success']) && $customerLelongKoop['success']
? ($customerLelongKoop['data']['rugilelong'] ?? 0) : 0;
// Calculate totals
$totalBakiLelong = $bakiLelong + $bakiKoop;
$totalRugiLelong = $rugiLelong + $rugiKoop;
return ['rugilelong' => $totalRugiLelong, 'bakilelong' => $totalBakiLelong];
}
}