This commit is contained in:
afiq
2021-10-03 03:19:52 +08:00
parent c7a93f3132
commit e5b6b4bb3c
11 changed files with 226 additions and 377 deletions
+53 -103
View File
@@ -17,66 +17,38 @@ use Carbon\Carbon;
class CustomerController extends Controller
{
public function showAllCustomers()
{
// $cawangan_all = Cawangan::on('mysql7')->get();
// $customer_all = [];
// foreach($cawangan_all as $index=>$cawangan){
$customer = Customer::on('mysql7')->get();
// if($customer != null){
// array_push($customer_all,$customer);
// }
// }
public function showAllCustomers(){
$customer = Customer::on('mysql7')->get();
return response()->json($customer);
}
public function getLatestCustomer($kodcaw){
// $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
$customer = Customer::on('mysql7')->orderBy('tarikhdaftar','desc')->orderBy('nosiri','desc')->first();
return response()->json($customer);
}
public function showAllCustomersByCawangan($kodcaw)
{
// $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
public function showAllCustomersByCawangan($kodcaw){
$customer = Customer::on('mysql7')->get();
return response()->json($customer);
}
public function showOneCustomerByIC($ic){
// $cawangan_all = Cawangan::on('mysql7')->get();
// $customer_all = [];
// foreach($cawangan_all as $index=>$cawangan){
$customer = Customer::on('mysql7')
->where('kplama','=',$ic)
->orWhere('kpbaru','=',$ic)
->first();
// if($customer != null){
// array_push($customer_all,$customer);
// }
// }
$customer = Customer::on('mysql7')
->where('kplama','=',$ic)
->orWhere('kpbaru','=',$ic)
->first();
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);
// }
// }
$customer = Customer::on('mysql7')
->where('kplama','=',$request->ic)
->orWhere('kpbaru','=',$request->ic)
->first();
return response()->json($customer);
}
@@ -315,8 +287,6 @@ class CustomerController extends Controller
public function getLaporanCustomers($kodcaw, $tarikh)
{
// $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
$gadai = Customer::on('mysql7')
->where([['tarikhdaftar','=',$tarikh],['kodcaw',$kodcaw]])
->orderBy('tarikhdaftar', 'desc')
@@ -364,28 +334,19 @@ class CustomerController extends Controller
}
public function customerUpdate($nokp,Request $request){
// $cawangan_all = Cawangan::on('mysql7')->get();
// foreach($cawangan_all as $index=>$cawangan){
// $customer = Customer::on($cawangan['mysql'])
// ->where('kplama','=',$nokp)
// ->orWhere('kpbaru','=',$nokp)
// ->first();
// if($customer != null){
$poskod = Poskod::on('mysql7')->where('poskod','=',$request->poskod)->first();
$customer_update = Customer::on('mysql7')
->where('kplama','=',$nokp)
->orWhere('kpbaru','=',$nokp)
->update(array(
'alamat1' => $request->alamat,
'alamat2' => '',
'poskod' => $request->poskod,
'koddaerah' => $poskod['koddaerah'],
'kodnegeri' => $poskod['kodnegeri'],
'telefon' => $request->telefon1,
'telefon2' => $request->telefon2
));
// }
// }
$poskod = Poskod::on('mysql7')->where('poskod','=',$request->poskod)->first();
$customer_update = Customer::on('mysql7')
->where('kplama','=',$nokp)
->orWhere('kpbaru','=',$nokp)
->update(array(
'alamat1' => $request->alamat,
'alamat2' => '',
'poskod' => $request->poskod,
'koddaerah' => $poskod['koddaerah'],
'kodnegeri' => $poskod['kodnegeri'],
'telefon' => $request->telefon1,
'telefon2' => $request->telefon2
));
return response()->json($customer_update, 200);
}
@@ -412,32 +373,24 @@ class CustomerController extends Controller
}
public function customerUpdateKhazanah($nokp,Request $request){
// $cawangan_all = Cawangan::on('mysql7')->get();
// foreach($cawangan_all as $index=>$cawangan){
// $customer = Customer::on($cawangan['mysql'])
// ->where('kplama','=',$nokp)
// ->orWhere('kpbaru','=',$nokp)
// ->first();
// if($customer != null){
$poskod = Poskod::on('mysql7')->where('poskod','=',$request->poskod)->first();
$poskod = Poskod::on('mysql7')->where('poskod','=',$request->poskod)->first();
$customer_update = Customer::on('mysql7')
->where('kplama','=',$nokp)
->orWhere('kpbaru','=',$nokp)
->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']
));
// }
// }
$customer_update = Customer::on('mysql7')
->where('kplama','=',$nokp)
->orWhere('kpbaru','=',$nokp)
->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);
}
@@ -654,21 +607,18 @@ class CustomerController extends Controller
public function insertAkaunBankMobile(Request $request)
{
// $cawangan_all = Cawangan::on('mysql7')->get();
// foreach($cawangan_all as $index=>$cawangan)
// {
$customer = Customer::on('mysql7')
->where('kplama','=',$request->nokp)
->orWhere('kpbaru','=',$request->nokp)
->first();
$customer = Customer::on('mysql7')
->where('kplama','=',$request->nokp)
->orWhere('kpbaru','=',$request->nokp)
->first();
if(!empty($customer))
{
$customer->kodbank = $request->kodbank;
$customer->noakaun = $request->noakaun;
$customer->save();
}
// }
if(!empty($customer))
{
$customer->kodbank = $request->kodbank;
$customer->noakaun = $request->noakaun;
$customer->save();
}
return response()->json($customer, 200);
}