Codebase update
- update jomweb/billplz package - refactor controllers, views with means of to simplify data fetch and manipuation
This commit is contained in:
@@ -1,19 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
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()
|
||||
public function __construct(PembiayaanService $pembiayaanService)
|
||||
{
|
||||
$this->middleware(['auth','verified']);
|
||||
$this->pembiayaanService = $pembiayaanService;
|
||||
$this->middleware(['auth', 'verified']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -21,67 +26,27 @@ class HomeController extends Controller
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
public function index(Request $request)
|
||||
{
|
||||
$auth_user = Auth::user();
|
||||
// $harga_emas = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') .'/api/harga_emas/')->json();
|
||||
$pembiayaan = $this->pembiayaanService->getPembiayaan($request->filter);
|
||||
|
||||
// $hargaemasterdahulu = array();
|
||||
$authUser = Auth::user();
|
||||
$customerInfo = Http::withOptions(['verify' => config('app.api_verify')])
|
||||
->get(config('api.url') . '/portal/customer/info', ['ic' => $authUser['icno']])
|
||||
->json();
|
||||
|
||||
// foreach($harga_emas as $index=>$harga)
|
||||
// {
|
||||
// $hargaemassandaran = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') .'/api/harga_emas/rekod/sandaran',['karat' => $harga['karat']])->json();
|
||||
['gadai' => $customer_gadai, 'lelong' => $customer_lelong] = $customerInfo;
|
||||
|
||||
// $percentnaik = (floatval($harga['harga']) - floatval($hargaemassandaran[1]['harga'])) / ($hargaemassandaran[1]['harga']) * 100;
|
||||
$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));
|
||||
|
||||
// array_push($hargaemasterdahulu,['karat' => $harga['karat'],'hargasemasa' => $harga['harga'], 'hargadahulu' => $hargaemassandaran[1]['harga'],'percent' => $percentnaik]);
|
||||
$sixMonths = sizeOf(array_filter($customer_gadai, fn($x) => $x['tempoh'] >= 6));
|
||||
|
||||
// }
|
||||
$bilanganLelong = sizeOf($customer_lelong);
|
||||
|
||||
$CustomerInfo = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') .'/portal/customer/info',['ic' => $auth_user['icno']]);
|
||||
//dd($CustomerInfo)
|
||||
$bilangan = sizeof($customer_gadai) + sizeOf($customer_lelong);
|
||||
|
||||
$total = 0.00;
|
||||
$sixmonths = 0;
|
||||
$bilangan = 0;
|
||||
foreach($CustomerInfo['gadai'] as $index=>$gadai)
|
||||
{
|
||||
$bilangan++;
|
||||
$total += $gadai['bakipjm'];
|
||||
|
||||
if($gadai['tempoh'] >= 6)
|
||||
{
|
||||
$sixmonths++;
|
||||
}
|
||||
}
|
||||
|
||||
$bilanganlelong = 0;
|
||||
foreach($CustomerInfo['lelong'] as $index1=>$lelong)
|
||||
{
|
||||
$bilangan++;
|
||||
$bilanganlelong += 1;
|
||||
}
|
||||
|
||||
// $arraysag = [];
|
||||
// $belum_tebus = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/customers/'. $auth_user['icno'] . '/gadai/' . 'belum_tebus')->json();
|
||||
|
||||
// if(is_array($belum_tebus))
|
||||
// {
|
||||
// if(sizeof($belum_tebus) > 0)
|
||||
// {
|
||||
// foreach($belum_tebus as $index=>$bt)
|
||||
// {
|
||||
// foreach($bt as $index1=>$bet)
|
||||
// {
|
||||
// array_push($arraysag,$bet);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// $belum_tebus = $arraysag;
|
||||
$api_url = config('api.url');
|
||||
|
||||
return view('includes.home',compact('api_url','bilangan','sixmonths','total','bilanganlelong'));
|
||||
return view('includes.home', compact('bilangan', 'sixMonths', 'total', 'bilanganLelong', 'pembiayaan'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user