From bb32bf88329660571c59ac3ed9e5645c97782866 Mon Sep 17 00:00:00 2001 From: afiq Date: Mon, 9 Aug 2021 01:21:20 +0800 Subject: [PATCH 1/2] admin page customer --- app/Http/Controllers/CustomerController.php | 82 +++++++++++++++++++++ routes/web.php | 1 + 2 files changed, 83 insertions(+) diff --git a/app/Http/Controllers/CustomerController.php b/app/Http/Controllers/CustomerController.php index ab8f95a..3b677e6 100644 --- a/app/Http/Controllers/CustomerController.php +++ b/app/Http/Controllers/CustomerController.php @@ -428,6 +428,88 @@ class CustomerController extends Controller return response()->json($customer_update, 200); } + public function customerUpdateAdmin(Request $request){ + $poskod = Poskod::on('mysql7')->where('poskod','=',$request->poskod)->first(); + + if($request->ic_asal != $request->icno){ + + $existing_customer = Customer::on('mysql7') + ->where('kplama','=',$request->icno) + ->orWhere('kpbaru','=',$request->icno) + ->get(); + + if($existing_customer->isEmpty()){ + $cawangan_all = Cawangan::on('mysql7')->get(); + foreach($cawangan_all as $index=> $cawangan){ + $gadai = Gadai::on($cawangan['mysql'])->where('nokp',$request->ic_asal)->update([ + 'nokp'=>$request->icno + ]); + } + + $data_asal = $customer_update = Customer::on('mysql7') + ->where('kplama','=',$request->ic_asal) + ->orWhere('kpbaru','=',$request->ic_asal) + ->first(); + + if($data_asal['kpbaru'] != null){ + $customer_update = Customer::on('mysql7') + ->where('kplama','=',$request->ic_asal) + ->orWhere('kpbaru','=',$request->ic_asal) + ->update(array( + 'kpbaru' => $request->icno, + 'telefon' => $request->telefon1, + 'telefon2' => $request->telefon2, + 'kodbank' => $request->kodbank, + 'noakaun' => $request->noakaun, + 'nota' => $request->nota, + 'nama' => $request->nama, + 'alamat1' => $request->alamat, + 'poskod' => $request->poskod, + 'koddaerah' => $poskod['koddaerah'], + 'kodnegeri' => $poskod['kodnegeri'] + )); + }else{ + $customer_update = Customer::on('mysql7') + ->where('kplama','=',$request->ic_asal) + ->orWhere('kpbaru','=',$request->ic_asal) + ->update(array( + 'kplama' => $request->icno, + 'telefon' => $request->telefon1, + 'telefon2' => $request->telefon2, + 'kodbank' => $request->kodbank, + 'noakaun' => $request->noakaun, + 'nota' => $request->nota, + 'nama' => $request->nama, + 'alamat1' => $request->alamat, + 'poskod' => $request->poskod, + 'koddaerah' => $poskod['koddaerah'], + 'kodnegeri' => $poskod['kodnegeri'] + )); + } + }else{ + return response()->json('existing'); + } + }else if($request->ic_asal == $request->icno){ + $customer_update = Customer::on('mysql7') + ->where('kplama','=',$request->icno) + ->orWhere('kpbaru','=',$request->icno) + ->update(array( + 'telefon' => $request->telefon1, + 'telefon2' => $request->telefon2, + 'kodbank' => $request->kodbank, + 'noakaun' => $request->noakaun, + 'nota' => $request->nota, + 'nama' => $request->nama, + 'alamat1' => $request->alamat, + 'poskod' => $request->poskod, + 'koddaerah' => $poskod['koddaerah'], + 'kodnegeri' => $poskod['kodnegeri'] + )); + } + + return response()->json($customer_update, 200); + } + public function listNorujukanMobile($nokp){ $cawangan_all = Cawangan::on('mysql7')->get(); $array_norujukan = []; diff --git a/routes/web.php b/routes/web.php index 57ef895..39240ed 100644 --- a/routes/web.php +++ b/routes/web.php @@ -36,6 +36,7 @@ $router->group(['prefix'=>'api'], function () use ($router){ $router->put('customers/update/khazanah/{nokp}', ['uses' => 'CustomerController@customerUpdateKhazanah']); $router->get('customers/laporan/{kodcaw}/{tarikh}',['uses'=>'CustomerController@getLaporanCustomers']); $router->get('customers/latest/{kodcaw}',['uses'=>'CustomerController@getLatestCustomer']); + $router->put('customers/information/update/admin', ['uses' => 'CustomerController@customerUpdateAdmin']); //Gadai API $router->get('gadai',['uses'=>'GadaiController@showAllGadais']); From 3ae009b3c7064aad3b2a1c1db865514a28b068a9 Mon Sep 17 00:00:00 2001 From: afiq Date: Mon, 9 Aug 2021 12:10:19 +0800 Subject: [PATCH 2/2] fix customer admin --- app/Http/Controllers/CustomerController.php | 17 +++++++++++++++++ routes/web.php | 1 + 2 files changed, 18 insertions(+) diff --git a/app/Http/Controllers/CustomerController.php b/app/Http/Controllers/CustomerController.php index 3b677e6..3f28a59 100644 --- a/app/Http/Controllers/CustomerController.php +++ b/app/Http/Controllers/CustomerController.php @@ -63,6 +63,23 @@ class CustomerController extends Controller return response()->json($customer); } + public function showOneCustomerByICAdmin(Request $request){ + + // $cawangan_all = Cawangan::on('mysql7')->get(); + // $customer_all = []; + // foreach($cawangan_all as $index=>$cawangan){ + $customer = Customer::on('mysql7') + ->where('kplama','=',$request->ic) + ->orWhere('kpbaru','=',$request->ic) + ->first(); + // if($customer != null){ + // array_push($customer_all,$customer); + // } + // } + + return response()->json($customer); + } + public function showOneCustomerByICMobile($ic){ $cawangan_all = Cawangan::on('mysql7')->get(); diff --git a/routes/web.php b/routes/web.php index 39240ed..da3801b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -37,6 +37,7 @@ $router->group(['prefix'=>'api'], function () use ($router){ $router->get('customers/laporan/{kodcaw}/{tarikh}',['uses'=>'CustomerController@getLaporanCustomers']); $router->get('customers/latest/{kodcaw}',['uses'=>'CustomerController@getLatestCustomer']); $router->put('customers/information/update/admin', ['uses' => 'CustomerController@customerUpdateAdmin']); + $router->get('admin/customers/nokp/search',['uses'=>'CustomerController@showOneCustomerByICAdmin']); //Gadai API $router->get('gadai',['uses'=>'GadaiController@showAllGadais']);