From 1dabcdb0867e5fc5f80d72c135ac9b5e8b040283 Mon Sep 17 00:00:00 2001 From: Fiza Ali Date: Tue, 2 Feb 2021 18:57:04 +0800 Subject: [PATCH] API Mobile --- app/BankMaster.php | 29 ++++++++ app/Customer.php | 43 ++++++++++++ app/Http/Controllers/CustomerController.php | 78 ++++++++++++++++++++- routes/web.php | 3 + 4 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 app/BankMaster.php diff --git a/app/BankMaster.php b/app/BankMaster.php new file mode 100644 index 0000000..394d7c2 --- /dev/null +++ b/app/BankMaster.php @@ -0,0 +1,29 @@ +getKeyName(); + if(!is_array($keys)){ + return parent::setKeysForSaveQuery($query); + } + + foreach($keys as $keyName){ + $query->where($keyName, '=', $this->getKeyForSaveQuery($keyName)); + } + + return $query; + } + + /** + * Get the primary key value for a save query. + * + * @param mixed $keyName + * @return mixed + */ + protected function getKeyForSaveQuery($keyName = null) + { + if(is_null($keyName)){ + $keyName = $this->getKeyName(); + } + + if (isset($this->original[$keyName])) { + return $this->original[$keyName]; + } + + return $this->getAttribute($keyName); + } } \ No newline at end of file diff --git a/app/Http/Controllers/CustomerController.php b/app/Http/Controllers/CustomerController.php index 9a84468..44bda6d 100644 --- a/app/Http/Controllers/CustomerController.php +++ b/app/Http/Controllers/CustomerController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\BankMaster; use App\Customer; use App\Gadai; use App\Lelong; @@ -418,4 +419,79 @@ class CustomerController extends Controller return response('Deleted Successfully', 200); } -} \ No newline at end of file + + public function akaunBankMobile($nokp) + { + $array_cust = []; + $cawangan_all = Cawangan::on('mysql7')->get(); + + foreach($cawangan_all as $cawangan) + { + $customer = Customer::on($cawangan['mysql']) + ->where('kplama','=',$nokp) + ->orWhere('kpbaru','=',$nokp) + ->rightJoin('online_arrahn.bank', 'bank.id', '=', 'customer.kodbank') + ->first(); + + if(!empty($customer)) + { + $customer_detail['noakaun'] = $customer['noakaun']; + $customer_detail['namabank'] = $customer['name']; + $customer_detail['kodbank'] = $customer['id']; + + return response()->json($customer_detail); + } + else + { + return response()->json('Data Not Found'); + } + } + } + + public function bankListMobile() + { + $bank_array = []; + $cawangan_all = Cawangan::on('mysql7')->get(); + foreach($cawangan_all as $cawangan) + { + $bank = BankMaster::get(); + if(!empty($bank)) + { + //loop each array + foreach($bank as $banklist) + { + array_push($bank_array, array( + 'kodbank' => $banklist->id, + 'namabank' => $banklist->name, + )); + } + return response()->json($bank_array); + } + else + { + return response()->json('Data Not Found'); + } + } + } + + + public function insertAkaunBankMobile(Request $request) + { + $cawangan_all = Cawangan::on('mysql7')->get(); //return all 8 branches + foreach($cawangan_all as $index=>$cawangan) + { + $customer = Customer::on($cawangan['mysql']) //search Customer on dtabase cawangan (1-8) + ->where('kplama','=',$request->nokp) + ->orWhere('kpbaru','=',$request->nokp) + ->first(); + + if(!empty($customer)) + { + $customer->kodbank = $request->kodbank; + $customer->noakaun = $request->noakaun; + $customer->save(); + } + } + return response()->json($customer, 200); + } +} diff --git a/routes/web.php b/routes/web.php index fa8358d..8ec6d82 100644 --- a/routes/web.php +++ b/routes/web.php @@ -270,6 +270,9 @@ $router->group(['prefix'=>'mobile'], function () use ($router){ $router->get('harga_emas',['uses'=>'HargaEmasController@showAllHargaEmasMobile']); $router->get('gadai/norujukan/count/{nokp}',['uses'=>'CustomerController@countNorujukanMobile']); $router->get('gadai/norujukan/{nokp}',['uses'=>'CustomerController@listNorujukanMobile']); + $router->get('akaun-bank/{nokp}',['uses'=>'CustomerController@akaunBankMobile']); + $router->get('bank-listing/{nokp}',['uses'=>'CustomerController@bankListMobile']); + $router->post('insert/akaun-bank',['uses'=>'CustomerController@insertAkaunBankMobile']); //gadaian $router->get('gadai/{noic}',['uses'=>'GadaiController@showOneGadaiMobile']);