diff --git a/app/Http/Controllers/CustomerController.php b/app/Http/Controllers/CustomerController.php index ab8f95a..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(); @@ -428,6 +445,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 960123f..eccfa04 100644 --- a/routes/web.php +++ b/routes/web.php @@ -36,6 +36,8 @@ $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']); + $router->get('admin/customers/nokp/search',['uses'=>'CustomerController@showOneCustomerByICAdmin']); //Gadai API $router->get('gadai',['uses'=>'GadaiController@showAllGadais']);