diff --git a/app/Http/Controllers/CallCenterController.php b/app/Http/Controllers/CallCenterController.php index 007e52d..fe63b24 100644 --- a/app/Http/Controllers/CallCenterController.php +++ b/app/Http/Controllers/CallCenterController.php @@ -337,6 +337,22 @@ class CallCenterController extends Controller } } + public function pelanggannew() + { + $search = false; + + $api_url = config('api.url'); + $auth_user = Auth::user(); + $idtype = 'nokp'; + $cawangan_info = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/cawangan/'. $auth_user['cawangan'])->json(); + $bank = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/bank')->json(); + if($auth_user->roles == 'admin'){ + return view('admin.customer_index',compact('search','cawangan_info','bank','api_url','idtype','auth_user')); + }else{ + return view('callcenter.indexnama',compact('search','cawangan_info','bank','api_url','idtype','auth_user')); + } + } + public function search(Request $request){ // dd($request->all()); $noic = $request->noic; @@ -365,6 +381,112 @@ class CallCenterController extends Controller } } + public function searchnama(Request $request) + { + $noic = $request->noic; + $kodcaw = $request->cawangan; + Session::put('noic', $noic); + Session::put('kodcaw', $kodcaw); + + $api_url = config('api.url'); + + $request->session()->forget('page_reload'); + $request->session()->forget('norujukan'); + + if (empty($noic)) { + return redirect()->route('arcc.pelanggannew')->with('failed', 'Maaf, Tiada Data Pelanggan...'); + } + + // ====================== + // 1️⃣ Kalau isi NOIC sahaja + // ====================== + if ($noic && !$kodcaw) { + $customersWithGadai = []; + + // Ambil semua cawangan + $cawanganList = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/api/cawangan') + ->json(); + + + if (is_array($cawanganList)) { + foreach ($cawanganList as $caw) { + $kod = $caw['kodcaw']; + + // Check customer di cawangan tu + $customer = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/api/customers/' . $noic, ['kodcaw' => $kod]) + ->json(); + + + if (!empty($customer)) { + // Check rekod gadai + $nokp = !empty($customer['kpbaru']) ? $customer['kpbaru'] : (!empty($customer['kplama']) ? $customer['kplama'] : $noic); + $gadaiData = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/arcc/rekodgadai', [ + 'nokp' => $nokp, + 'kodcaw' => $kod + ]) + ->json(); + // dump($gadaiData); + + if (!empty($gadaiData['data']) && $gadaiData['status'] === true) { + $customersWithGadai[] = [ + 'nama' => $customer['nama'] ?? '-', + 'kpbaru' => $customer['kpbaru'] ?? null, + 'kplama' => $customer['kplama'] ?? null, + 'customer' => $customer, + 'kodcaw' => $kod, + 'nama_cawangan' => $caw['details_caw'] ?? $kod, + // 'rekod_gadai' => $gadaiData + + ]; + } + } + } + } + // dd(true); + + // Kalau lebih 1 → pilih pelanggan + if (count($customersWithGadai) >= 1) { + Session::put('customer_list', $customersWithGadai); + return redirect()->route('arcc.pilihpelanggan'); + } + + return redirect()->route('arcc.pelanggannew')->with('failed', 'Maaf, Tiada Data Pelanggan...'); + } + + // ====================== + // 2️⃣ Kalau isi NOIC + Cawangan + // ====================== + if ($noic && $kodcaw) { + $customer_info = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/api/customers/' . $noic, ['kodcaw' => $kodcaw]) + ->json(); + + // Check sama ada $customer_info bukan null dan ada data penting seperti 'nama' (atau key lain) + if ($customer_info && !empty($customer_info['nama'])) { + Session::put('customer_info_arcc', $customer_info); + + $cawangan_info = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/api/cawangan/' . $kodcaw) + ->json(); + + return redirect()->route('arcc.customer_info_nama', [ + 'customer_info' => $customer_info, + 'cawangan_info' => $cawangan_info, + 'api_url' => $api_url + ]); + } + + // Jika tiada data pelanggan di cawangan tu + return redirect()->route('arcc.pelanggan')->with('failed', 'Maaf, Tiada Data Pelanggan di cawangan ini.'); + } + + + // Boleh tambah kes lain (Nama sahaja, Nama + Cawangan) kalau nak + } + public function info(Request $request){ $auth_user = Auth::user(); $api_url = config('api.url'); @@ -383,6 +505,52 @@ class CallCenterController extends Controller } + public function infonama(Request $request) + { + $auth_user = Auth::user(); + $api_url = Session::get('api_url_arcc', config('api.url')); + + $cawangan_info = Session::get('cawangan_info_arcc'); + $customer_info = Session::get('customer_info_arcc'); + + // Kalau data kosong, fallback panggil API + if (!$cawangan_info) { + $cawangan_info = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/api/cawangan/' . Session::get('kodcaw')) + ->json(); + } + if (!$customer_info) { + $customer_info = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/api/customers/' . Session::get('noic')) + ->json(); + + $customer_info = $response['data'] ?? []; + } + + $bakilelong = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/api/bakilelong/cawangan/' . Session::get('kodcaw') . '/' . Session::get('noic') . '/baki') + ->json(); + + $rugilelong = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/api/bakilelong/cawangan/' . Session::get('kodcaw') . '/' . Session::get('noic') . '/rugi') + ->json(); + + $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' + )); + } public function notisperingatankedua(Request $request){ $auth_user = Auth::user(); @@ -994,32 +1162,41 @@ class CallCenterController extends Controller public function pilihPelangganProceed(Request $request) -{ - $customerData = $request->input('customer'); - + { + $customerData = $request->input('customer'); + $kodcaw = $request->input('kodcaw'); - if ($customerData) { - $customer = json_decode(base64_decode($customerData), true); - $kodcaw = $customer['kodcaw']; - Session::put('customer_info_arcc', $customer); + if ($customerData) { + $customer = json_decode(base64_decode($customerData), true); + + // Merge data penuh supaya flat & senang guna di Blade + $customer_info = array_merge( + $customer['customer'] ?? $customer, // kalau ada sub-array 'customer', ambil dia + [ + 'kodcaw' => $customer['kodcaw'] ?? $kodcaw, + 'nama_cawangan' => $customer['nama_cawangan'] ?? '', + ] + ); - $api_url = config('api.url'); - $cawangan_info = Http::withOptions(['verify' => config('app.api_verify')]) - ->get($api_url . '/api/cawangan/' . $kodcaw)->json(); + // Simpan dalam session + Session::put('customer_info_arcc', $customer_info); + Session::put('kodcaw', $kodcaw); + Session::put('noic', $customer_info['kpbaru'] ?? $customer_info['kplama']); - return redirect()->route('arcc.customer_info', [ - 'customer_info' => $customer, - 'cawangan_info' => $cawangan_info, - 'api_url' => $api_url - ]); + $api_url = config('api.url'); + $cawangan_info = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/api/cawangan/' . $kodcaw)->json(); + + // Simpan juga dalam session + Session::put('cawangan_info_arcc', $cawangan_info); + Session::put('api_url_arcc', $api_url); + + return redirect()->route('arcc.customer_info'); + } + + return redirect()->route('arcc.pelanggan')->with('failed', 'Pelanggan tidak sah dipilih.'); } - return redirect()->route('arcc.pelanggan')->with('failed', 'Pelanggan tidak sah dipilih.'); -} - - - - public function ajaxSearchCustomer(Request $request) { $search = strtolower($request->query('search', '')); @@ -1031,4 +1208,170 @@ class CallCenterController extends Controller return view('callcenter.partials.customertable', ['customers' => $customers])->render(); } + public function cariannama(Request $request) + { + $nama = $request->nama; + $api_url = config('api.url'); + + if (empty($nama)) { + return redirect()->route('arcc.pelanggan')->with('failed', 'Maaf, Tiada Data Pelanggan...'); + } + + session(['last_search' => $request->all()]); + + // Clear session lama + $request->session()->forget(['page_reload', 'norujukan']); + + // 1. Call API carian nama + $customers = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/api/customers', ['nama' => $nama]) + ->json(); + + + if (!is_array($customers) || empty($customers)) { + return redirect()->route('arcc.pelanggannew')->with('failed', 'Tiada pelanggan dijumpai.'); + } + + // 2. Ambil senarai cawangan + $cawanganList = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/api/cawangan') + ->json(); + + if (!is_array($cawanganList) || empty($cawanganList)) { + return redirect()->route('arcc.pelanggan')->with('failed', 'Tiada senarai cawangan.'); + } + + // 3. Kumpul semua IC (kpbaru / kplama) dari senarai customer + $nokpList = collect($customers) + ->map(function ($customer) { + return $customer['kpbaru'] ?? $customer['kplama'] ?? null; + }) + ->filter() + ->unique() + ->values() + ->toArray(); + + + $customersWithGadai = collect(); + + foreach ($cawanganList as $caw) { + $kod = $caw['kodcaw']; + + $response = Http::withOptions(['verify' => config('app.api_verify')]) + ->post($api_url . '/arcc/rekodgadai-batch', [ + 'nokp_list' => $nokpList, + 'kodcaw' => $kod + ]); + + if ($response->failed()) { + continue; + } + + $data = $response->json(); + + if (!empty($data['data']) && is_array($data['data'])) { + foreach ($data['data'] as $rekod) { + $customer = collect($customers)->first(function ($c) use ($rekod) { + return ($c['kpbaru'] ?? $c['kplama']) === $rekod['nokp']; + }); + + if ($customer) { + $customersWithGadai->put( + $customer['kpbaru'] ?? $customer['kplama'], // guna IC as key + [ + 'nama' => $customer['nama'] ?? '-', + 'kpbaru' => $customer['kpbaru'] ?? null, + 'kplama' => $customer['kplama'] ?? null, + 'customer' => $customer, + 'kodcaw' => $kod, + 'nama_cawangan' => $caw['details_caw'] ?? $kod + ] + ); + } + } + } + } + + $customersWithGadai = $customersWithGadai + ->sortBy('nama') // sort ikut nama A→Z + ->values(); // reset key semula + + + // 5. Return ikut result + if ($customersWithGadai->count() > 1) { + Session::put('customer_list', $customersWithGadai); + return redirect()->route('arcc.pilihpelanggannama'); + } elseif ($customersWithGadai->count() === 1) { + $singleCustomer = $customersWithGadai->first(); + Session::put('customer_info_arcc', $singleCustomer['customer']); + + return redirect()->route('arcc.customer_info', [ + 'customer_info' => $singleCustomer['customer'], + 'cawangan_info' => [ + 'kodcaw' => $singleCustomer['kodcaw'], + 'nama_cawangan' => $singleCustomer['nama_cawangan'] + ], + 'api_url' => $api_url + ]); + } + + return redirect()->route('arcc.pelanggannew')->with('failed', 'Tiada pelanggan dengan rekod gadai.'); + } + + public function pilihPelanggannama() + { + 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.pilihpelanggannama', compact('cawangan_info')); + } + + public function pilihPelangganProceednama(Request $request) + { + $customerData = $request->input('customer'); + $kodcaw = $request->input('kodcaw'); + + if ($customerData) { + $customer = json_decode(base64_decode($customerData), true); + + // Merge data penuh supaya flat & senang guna di Blade + $customer_info = array_merge( + $customer['customer'] ?? $customer, // kalau ada sub-array 'customer', ambil dia + [ + 'kodcaw' => $customer['kodcaw'] ?? $kodcaw, + 'nama_cawangan' => $customer['nama_cawangan'] ?? '', + ] + ); + + // Simpan dalam session + Session::put('customer_info_arcc', $customer_info); + Session::put('kodcaw', $kodcaw); + Session::put('noic', $customer_info['kpbaru'] ?? $customer_info['kplama']); + + $api_url = config('api.url'); + $cawangan_info = Http::withOptions(['verify' => config('app.api_verify')]) + ->get($api_url . '/api/cawangan/' . $kodcaw)->json(); + + // Simpan juga dalam session + Session::put('cawangan_info_arcc', $cawangan_info); + Session::put('api_url_arcc', $api_url); + + return redirect()->route('arcc.customer_info'); + } + + return redirect()->route('arcc.pelanggan')->with('failed', 'Pelanggan tidak sah dipilih.'); + } } diff --git a/resources/views/callcenter/indexnama.blade.php b/resources/views/callcenter/indexnama.blade.php new file mode 100644 index 0000000..74ef53e --- /dev/null +++ b/resources/views/callcenter/indexnama.blade.php @@ -0,0 +1,943 @@ +@extends('layouts.app_callcenter') + +@section('content') + + +
{{ $message }}
+{{ $message }}
+| Nama | +No KP | + +Tindakan | +
|---|---|---|
| {{ $customer['nama'] }} | +@php + if($customer['kpbaru'] != null){ + $noic = $customer['kpbaru']; + }else{ + $noic = $customer['kplama']; + } + @endphp + {{ $noic }} | + ++ + | +