pembiayaanService = $pembiayaanService; $this->middleware(['auth', 'verified']); } /** * Show the application buffer page. * * @return \Illuminate\View\View */ public function buffer(Request $request) { $homeUrl = route('home'); $authUser = Auth::user(); [$customer_pkb, $customer_koop] = CustomerInfoService::get($authUser['icno']); $customerLelong = $this->getCustomerInfoLelong($authUser['icno']); // ['gadai' => $customer_gadai, 'lelong' => $customer_lelong] = $customerInfo; $customer_gadai = array_merge( $customer_pkb['gadai'] ?? [], $customer_koop['gadai'] ?? [] ); $customer_lelong = array_merge( $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); $formatMoney = fn($x) => number_format($x, 2); $getTotal = fn($x) => array_reduce($x, fn($accumulator, $current_item) => $accumulator + $current_item['bakipjm'], 0); $total = $formatMoney($getTotal($customer_gadai)); $sixMonths = sizeOf(array_filter($customer_gadai, fn($x) => $x['tempoh'] >= 6)); $bilanganLelong = sizeOf($customer_lelong); $bilangan = sizeof($customer_gadai) + sizeOf($customer_lelong); return view('includes.buffer', compact('bilangan', 'sixMonths', 'total', 'bilanganLelong', 'homeUrl','customerLelong')); } /** * Show the application dashboard. * * @return \Illuminate\View\View */ public function index(Request $request) { $pembiayaan = $this->pembiayaanService->getPembiayaan($request->filter); $authUser = Auth::user(); [$customer_pkb, $customer_koop] = CustomerInfoService::get($authUser['icno']); $customerLelong = $this->getCustomerInfoLelong($authUser['icno']); // ['gadai' => $customer_gadai, 'lelong' => $customer_lelong] = $customerInfo; $customer_gadai = array_merge( $customer_pkb['gadai'] ?? [], $customer_koop['gadai'] ?? [] ); $customer_lelong = array_merge( $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); $formatMoney = fn($x) => number_format($x, 2); $getTotal = fn($x) => array_reduce($x, fn($accumulator, $current_item) => $accumulator + $current_item['bakipjm'], 0); $total = $formatMoney($getTotal($customer_gadai)); $sixMonths = sizeOf(array_filter($customer_gadai, fn($x) => $x['tempoh'] >= 6)); $bilanganLelong = sizeOf($customer_lelong); $bilangan = sizeof($customer_gadai) + sizeOf($customer_lelong); return view('includes.home', compact('bilangan', 'sixMonths', 'total', 'bilanganLelong', 'pembiayaan','customerLelong')); } private function getCustomerInfoLelong($icno){ [$customerLelong, $customerLelongKoop] = CustomerInfoService::get($icno, '/portal/customer/info/lelong'); // 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]; } }