adding audit customer

This commit is contained in:
hafifierahman
2022-07-26 22:14:01 +08:00
parent b0f4eafb99
commit 1abdfe524a
5 changed files with 200 additions and 22 deletions
+68 -18
View File
@@ -10,10 +10,13 @@ use App\Lelong;
use App\Cawangan;
use App\Poskod;
use App\Blacklist;
use App\AuditCustomer;
use Illuminate\Http\Request;
use Carbon\Carbon;
use DB;
class CustomerController extends Controller
{
@@ -373,26 +376,73 @@ class CustomerController extends Controller
}
public function customerUpdateKhazanah($nokp,Request $request){
$poskod = Poskod::on('mysql7')->where('poskod','=',$request->poskod)->first();
DB::connection('mysql7')->beginTransaction();
$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']
));
try{
$poskod = DB::connection('mysql7')->table('poskod')->where('poskod','=',$request->poskod)->first();
$customer_info = DB::connection('mysql7')->table('customer')
->select('kodcaw','tarikhdaftar','nopelanggan','kpbaru','kplama','nama','t_lahir','jantina','alamat1','poskod')
->where('kplama','=',$nokp)
->orWhere('kpbaru','=',$nokp)
->get()->toArray();
$old_data = json_encode($customer_info);
$customer_update = DB::connection('mysql7')
->table('customer')
->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
));
if($customer_update)
{
$customer_info_new = DB::connection('mysql7')->table('customer')
->select('kodcaw','tarikhdaftar','nopelanggan','kpbaru','kplama','nama','t_lahir','jantina','alamat1','poskod')
->where('kplama','=',$nokp)
->orWhere('kpbaru','=',$nokp)
->get()->toArray();
$new_data = json_encode($customer_info_new);
$audit_customer = DB::connection('mysql7')
->table('audit_customer')
->insert([
'username' => $request->namakhazanah,
'old_data' => $old_data,
'new_data' => $new_data,
'kodcaw' => $request->kodcaw,
'created_at' => Carbon::now()->toDateTimeString(),
'updated_at' => Carbon::now()->toDateTimeString(),
'customer_name' => $request->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);
}
return response()->json($customer_update, 200);
}
public function customerUpdateAdmin(Request $request){