diff --git a/app/Http/Controllers/CallCenterController.php b/app/Http/Controllers/CallCenterController.php index 9522b9d..2a1fa5c 100644 --- a/app/Http/Controllers/CallCenterController.php +++ b/app/Http/Controllers/CallCenterController.php @@ -338,50 +338,154 @@ class CallCenterController extends Controller } public function search(Request $request){ - // dd($request->all()); $noic = $request->noic; + $nama = $request->nama; $idtype = $request->customerIDType; $kodcaw = $request->cawangan; - Session::put('noic', $noic); - Session::put('kodcaw', $kodcaw); - - $api_url = config('api.url'); - $auth_user = Auth::user(); - $cawangan_info = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/cawangan/'. $kodcaw)->json(); - $bank = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/bank')->json(); - $customer_info = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/customers/'. $noic)->json(); - - $request->session()->forget('page_reload'); - $request->session()->forget('norujukan'); - - $search = true; - - if($customer_info){ - Session::put('customer_info_arcc',$customer_info); - return redirect()->route('arcc.customer_info', ['customer_info' => $customer_info,'cawangan_info'=>$cawangan_info,'api_url'=>$api_url]); - }else{ - return redirect()->route('arcc.pelanggan') - ->with('failed','Maaf,Tiada Data Pelanggan...'); + // Simpan ke session hanya jika ada input + if ($noic) { + Session::put('noic', $noic); } + if ($kodcaw) { + Session::put('kodcaw', $kodcaw); + } + + $api_url = config('api.url'); + $auth_user = Auth::user(); + + // Dapatkan maklumat cawangan jika kodcaw ada + $cawangan_info = null; + if ($kodcaw) { + $cawangan_info = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/api/cawangan/' . $kodcaw) + ->json(); + } + + // Dapatkan senarai bank (jika perlu) + $bank = Http::withOptions(['verify' => config('app.api_verify')])->get($api_url . '/api/bank')->json(); + + // Bersihkan session yang tidak perlu + $request->session()->forget('page_reload'); + $request->session()->forget('norujukan'); + + $customer_info = null; + + // Cari ikut IC jika diisi + if ($noic) { + $customer_info = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/api/customers/' . $noic) + ->json(); + } + + // Kalau nama diberi & IC tidak jumpa + elseif ($nama) { + $queryParams = ['nama' => $nama]; + if ($kodcaw) { + $queryParams['kodcaw'] = $kodcaw; + } + + $response = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/api/customers', $queryParams); + + if ($response->successful()) { + $customers = $response->json(); + + // Jika lebih dari satu pelanggan dijumpai + if (is_array($customers) && count($customers) > 1) { + Session::put('customer_list', $customers); + return redirect()->route('arcc.pilihpelanggan'); + } + + // Jika satu pelanggan dijumpai + $customer_info = $customers[0] ?? null; + } else { + logger('API carian nama gagal: ' . $response->body()); + } + } + + // Jika berjaya jumpa pelanggan + if ($customer_info) { + Session::put('customer_info_arcc', $customer_info); + + return redirect()->route('arcc.customer_info', [ + 'customer_info' => $customer_info, + 'cawangan_info' => $cawangan_info, + 'api_url' => $api_url + ]); + } + + // Gagal jumpa pelanggan + return redirect()->route('arcc.pelanggan') + ->with('failed', 'Maaf, Tiada Data Pelanggan...'); } - public function info(Request $request){ - $auth_user = Auth::user(); + + + public function info(Request $request) + { + $customer = $request->input('customer_info'); + + if (!$customer || !isset($customer['kodcaw'])) { + return redirect()->route('arcc.pelanggan')->with('failed', 'Maklumat pelanggan tidak lengkap.'); + } + + $kodcaw = $customer['kodcaw']; + $nokp = $customer['kpbaru'] ?? $customer['kplama'] ?? null; + + if (!$nokp) { + return redirect()->route('arcc.pelanggan')->with('failed', 'No KP pelanggan tidak dijumpai.'); + } + + Session::put('noic', $nokp); + $api_url = config('api.url'); - $cawangan_info = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/cawangan/'. Session::get('kodcaw'))->json(); - $customer_info = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/customers/'. Session::get('noic'))->json(); - $bakilelong = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/bakilelong/cawangan/' . Session::get('kodcaw') . '/' . Session::get('noic') . '/baki')->json(); - $rugilelong = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/bakilelong/cawangan/' . Session::get('kodcaw') . '/' . Session::get('noic') . '/rugi')->json(); + // Maklumat cawangan + $cawangan_info = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/api/cawangan/' . $kodcaw) + ->json(); - $negeri = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/negeri/')->json(); + if (!isset($cawangan_info['version'])) { + return redirect()->route('arcc.pelanggan')->with('failed', 'Maklumat cawangan tidak dijumpai.'); + } + + // Maklumat pelanggan + $customer_info = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/api/customers/' . $nokp) + ->json(); + + if (!$customer_info || isset($customer_info['error'])) { + return redirect()->route('arcc.pelanggan')->with('failed', 'Pelanggan tidak wujud dalam sistem.'); + } + + // Data lelong + $bakilelong = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/api/bakilelong/cawangan/' . $kodcaw . '/' . $nokp . '/baki') + ->json(); + + $rugilelong = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/api/bakilelong/cawangan/' . $kodcaw . '/' . $nokp . '/rugi') + ->json(); + + // Negeri + $negeri = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/api/negeri/') + ->json(); $request->session()->forget('page_reload'); $request->session()->forget('norujukan'); - return view('callcenter.' . $cawangan_info['version'] . '.info',compact('cawangan_info','api_url','customer_info','bakilelong','rugilelong','negeri')); + return view('callcenter.' . $cawangan_info['version'] . '.info', compact( + 'cawangan_info', + 'api_url', + 'customer_info', + 'bakilelong', + 'rugilelong', + 'negeri' + )); } + public function notisperingatankedua(Request $request){ $auth_user = Auth::user(); $api_url = config('api.url'); @@ -966,4 +1070,67 @@ class CallCenterController extends Controller $pertambahpinjaman = 0.80; return view('callcenter.' . $cawangan_info['version'] . '.index',compact('cawangan_info','api_url','gadai','marhun','nama','nilaihargasemasa','pertambahpinjaman')); } + + + public function pilihPelanggan() + { + if (!Session::has('customer_list')) { + return redirect()->route('arcc.pelanggan')->with('failed', 'Tiada pelanggan untuk dipilih.'); + } + + $kodcaw = Session::get('kodcaw'); // Ambil dari sesi + + $cawangan_info = null; + + // Kalau kodcaw ada, baru ambil cawangan_info + if ($kodcaw) { + $cawangan_info = Http::withOptions(['verify' => config('app.api_verify')]) + ->get(config('api.url') . '/api/cawangan/' . $kodcaw) + ->json(); + // dd($cawangan_info ); + } + + return view('callcenter.pilihpelanggan', compact('cawangan_info')); + } + + + + public function pilihPelangganProceed(Request $request) +{ + $customerData = $request->input('customer'); + + + if ($customerData) { + $customer = json_decode(base64_decode($customerData), true); + $kodcaw = $customer['kodcaw']; + Session::put('customer_info_arcc', $customer); + + $api_url = config('api.url'); + $cawangan_info = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/api/cawangan/' . $kodcaw)->json(); + + return redirect()->route('arcc.customer_info', [ + 'customer_info' => $customer, + 'cawangan_info' => $cawangan_info, + 'api_url' => $api_url + ]); + } + + return redirect()->route('arcc.pelanggan')->with('failed', 'Pelanggan tidak sah dipilih.'); +} + + + + + public function ajaxSearchCustomer(Request $request) + { + $search = strtolower($request->query('search', '')); + $customers = collect(session('customer_list', [])) + ->filter(function ($customer) use ($search) { + return strpos(strtolower($customer['nama']), $search) !== false || + strpos(strtolower($customer['nokp']), $search) !== false; + }); + + return view('callcenter.partials.customertable', ['customers' => $customers])->render(); + } } diff --git a/resources/views/callcenter/index.blade.php b/resources/views/callcenter/index.blade.php index 12212cc..90c6ecb 100644 --- a/resources/views/callcenter/index.blade.php +++ b/resources/views/callcenter/index.blade.php @@ -22,15 +22,16 @@
Pilih Cawangan Dan Masukkan nombor kad pengenalan
-
+
-
+ +
@php $cawangan_all = Http::withOptions(['verify' => config('app.api_verify')])->get($api_url . '/arcc/cawangan')->json(); @endphp - @foreach($cawangan_all as $cawangan) @@ -38,20 +39,28 @@
+ + - +
- + +
+
-
- -
-
+ +
+ +
+ +
+
@@ -832,25 +841,27 @@ function verifynokp(){ var id_type = $('#customerIDType').val(); var nokp = $('#noic').val(); - if(id_type=='nokp'){ - if($.isNumeric(nokp) == false){ - Swal.fire({ - icon: 'error', - title: 'Amaran!', - text: 'Sila Masukkan Nombor Sahaja Pada No KP Pelanggan' - }); - event.preventDefault(); - return false; - } - if(nokp.length != 12){ - Swal.fire({ - icon: 'error', - title: 'Amaran!', - text: 'Sila Periksa No KP Pelanggan' - }); - event.preventDefault(); - return false; - } + if(id_type === 'nokp'){ + if(!$.isNumeric(nokp)){ + Swal.fire({ + icon: 'error', + title: 'Amaran!', + text: 'Sila Masukkan Nombor Sahaja Pada No KP Pelanggan' + }); + event.preventDefault(); + return false; + } + + if(nokp.length != 12){ + Swal.fire({ + icon: 'error', + title: 'Amaran!', + text: 'Sila Periksa No KP Pelanggan' + }); + event.preventDefault(); + return false; + } + } }else if(id_type=='passport'){ // if(nokp.length < 5){ // Swal.fire({ diff --git a/resources/views/callcenter/partials/customertable.blade.php b/resources/views/callcenter/partials/customertable.blade.php new file mode 100644 index 0000000..b7e9e5b --- /dev/null +++ b/resources/views/callcenter/partials/customertable.blade.php @@ -0,0 +1,32 @@ +@if(count($customers) > 0) + + + + + + + + + + + @foreach($customers as $customer) + + + + + + + @endforeach + +
NamaNo KPKod CawanganTindakan
{{ $customer['nama'] }}{{ $customer['kpbaru'] ?? $customer['kplama'] ?? '-' }}{{ $customer['kodcaw'] }} + + @csrf + + + + + +
+@else +
Tiada pelanggan dijumpai.
+@endif diff --git a/resources/views/callcenter/pilihpelanggan.blade.php b/resources/views/callcenter/pilihpelanggan.blade.php new file mode 100644 index 0000000..08993f4 --- /dev/null +++ b/resources/views/callcenter/pilihpelanggan.blade.php @@ -0,0 +1,39 @@ +@extends('layouts.app_callcenter') + +@section('content') +
+

Senarai Pelanggan Dijumpai

+ @if(session('customer_list') && count(session('customer_list')) > 0) + + + + + + + + + + + @foreach(session('customer_list') as $customer) + + + + + + + @endforeach + +
NamaNo KPKod CawanganTindakan
{{ $customer['nama'] }}{{ $customer['kpbaru'] ?? $customer['kplama'] ?? '-' }}{{ $customer['kodcaw'] }} +
+ @csrf + + +
+
+ @else +
Tiada pelanggan dijumpai.
+ @endif + + Kembali +
+@endsection diff --git a/routes/web.php b/routes/web.php index 26a8f5e..d6cffb1 100644 --- a/routes/web.php +++ b/routes/web.php @@ -437,6 +437,9 @@ Route::get('/kemaskininotisperingatankedua/{notisid}',['as'=>'arcc.kemaskininoti Route::get('/kemaskininotisperingatanbycaw/{kodcaw}/{notisid}',['as'=>'arcc.kemaskininotisperingatanbycaw','uses'=>'CallCenterController@kemaskininotisperingatanbycaw'])->middleware('auth','callcenter'); Route::get('/kemaskininotisperingatankeduabycaw/{kodcaw}/{notisid}',['as'=>'arcc.kemaskininotisperingatankeduabycaw','uses'=>'CallCenterController@kemaskininotisperingatankeduabycaw'])->middleware('auth','callcenter'); Route::get('/arcc/tanyaupah/{norujukan}',['as'=>'tanyaupah','uses' => 'CallCenterController@tanyaupah'])->middleware('auth','callcenter'); +Route::get('/pilihpelanggan',['as'=>'arcc.pilihpelanggan','uses' => 'CallCenterController@pilihPelanggan'])->middleware('auth','callcenter'); +Route::post('/pilihpelanggan/proceed', ['as'=>'arcc.pilihpelanggan.proceed','uses' => 'CallCenterController@pilihPelangganProceed'])->middleware('auth','callcenter'); +Route::get('/ajax/search-customer',['as'=>'arcc.ajaxSearchCustomer','uses' => 'CallCenterController@ajaxSearchCustomer'])->middleware('auth','callcenter'); //taraf pc atau ppc Route::get('/cawangan/notisperingatan',['as'=>'laporan.notisperingatan','uses'=>'KhazanahController@notisperingatan'])->middleware('auth','khazanah');