updated for previous issues about tuntutbaki duplicate and customer audit

This commit is contained in:
hafifierahman
2022-11-14 00:20:16 +08:00
parent 1baa436a74
commit b9f00bb2bf
5 changed files with 520 additions and 39 deletions
+61 -16
View File
@@ -359,24 +359,69 @@ class CustomerController extends Controller
}
public function customerUpdateKaunter($nokp,Request $request){
$poskod = Poskod::on('mysql7')->where('poskod','=',$request->poskod)->first();
$customer_update = Customer::on('mysql7')
DB::connection('mysql7')->beginTransaction();
try{
$poskod = Poskod::on('mysql7')->where('poskod','=',$request->poskod)->first();
$customer_info = DB::connection('mysql7')->table('customer')
->select('kodcaw','tarikhdaftar','nopelanggan','kpbaru','kplama','nama','t_lahir','jantina','alamat1','poskod','telefon','telefon2')
->where('kplama','=',$nokp)
->orWhere('kpbaru','=',$nokp)
->get()->toArray();
$old_data = json_encode($customer_info);
$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,
'alamat1' => $request->alamat,
'poskod' => $request->poskod,
'koddaerah' => $poskod['koddaerah'],
'kodnegeri' => $poskod['kodnegeri']
));
if($customer_update)
{
$customer_info_new = DB::connection('mysql7')->table('customer')
->select('kodcaw','tarikhdaftar','nopelanggan','kpbaru','kplama','nama','t_lahir','jantina','alamat1','poskod','telefon','telefon2')
->where('kplama','=',$nokp)
->orWhere('kpbaru','=',$nokp)
->update(array(
'telefon' => $request->telefon1,
'telefon2' => $request->telefon2,
'kodbank' => $request->kodbank,
'noakaun' => $request->noakaun,
'nota' => $request->nota,
'alamat1' => $request->alamat,
'poskod' => $request->poskod,
'koddaerah' => $poskod['koddaerah'],
'kodnegeri' => $poskod['kodnegeri']
));
return response()->json($customer_update, 200);
->get()->toArray();
$new_data = json_encode($customer_info_new);
$audit_customer = DB::connection('mysql7')
->table('audit_customer')
->insert([
'username' => $request->namateller,
'old_data' => $old_data,
'new_data' => $new_data,
'kodcaw' => $customer_info[0]->kodcaw,
'created_at' => Carbon::now()->toDateTimeString(),
'updated_at' => Carbon::now()->toDateTimeString(),
'customer_name' => $customer_info[0]->nama,
'customer_nokp' => $nokp,
]);
}
DB::connection('mysql7')->commit();
return response()->json($customer_update, 200);
}catch (\Exception $e) {
DB::connection('mysql7')->rollback();
return response()->json($e->getMessage(),400);
}
}
public function customerUpdateKhazanah($nokp,Request $request){