101 lines
3.5 KiB
PHP
101 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Services\PembiayaanService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class HomeController extends Controller
|
|
{
|
|
private $pembiayaanService;
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct(PembiayaanService $pembiayaanService)
|
|
{
|
|
$this->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();
|
|
$customerInfo = Http::withOptions(['verify' => config('app.api_verify')])
|
|
->get(config('api.url') . '/portal/customer/info', ['ic' => $authUser['icno']])
|
|
->json();
|
|
|
|
['gadai' => $customer_gadai, 'lelong' => $customer_lelong] = $customerInfo;
|
|
|
|
// 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'));
|
|
}
|
|
|
|
/**
|
|
* Show the application dashboard.
|
|
*
|
|
* @return \Illuminate\View\View
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
$pembiayaan = $this->pembiayaanService->getPembiayaan($request->filter);
|
|
|
|
$authUser = Auth::user();
|
|
$customer_pkb = Http::withOptions(['verify' => config('app.api_verify')])
|
|
->get(config('api.url') . '/portal/customer/info', ['ic' => $authUser['icno']])
|
|
->json();
|
|
|
|
$customer_koop = Http::withOptions(['verify' => config('app.api_verify')])
|
|
->get(config('api.url_koop') . '/portal/customer/info', ['ic' => $authUser['icno']])
|
|
->json();
|
|
|
|
// ['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'));
|
|
}
|
|
}
|