initData($request,$route); return $data; } public function index(Request $request) { $checkRole = $this->checkRoleAccessRef($request->get('type')); if ($checkRole == false) { return view('errors.404'); } //INIT $init = $this->getInit($request,$request->get('type')); $route = $init['route']; $param['title'] = $init['title']; $param['tableHead'] = $init['tableHead']; $param['head'] = $init['head']; $view = 'content.ref.index'; //END INIT $param['table'] = route('ref.data')."?type=".$route; $param['edit'] = route('ref.edit')."?type=".$route; $param['store'] = route('ref.store')."?type=".$route; $param['storeCustom'] = route('ref.storeCustom')."?type=".$route; $param['setActive'] = route('ref.setActive')."?type=".$route; $param['delete'] = route('ref.hapus')."?type=".$route; $param['import_xls'] = route('ref.import.xls')."?type=".$route; $param['vForm'] = 'content.ref.'.$route.'.form'; $param['vAction'] = 'content.ref.'.$route.'.action'; $param['init'] = $init; //REF $param['ref_role'] = \DB::select("SELECT * FROM groups_admin WHERE is_active = 't'"); return $this->bsGetView($view,$param); } public function data(Request $request) { $checkRole = $this->checkRoleAccessRef($request->get('type')); if ($checkRole == false) { return view('errors.404'); } $init = $this->getInit($request,$request->get('type')); $type = $request->get('type'); $data = $init['data_table']; $modelName = '\\App\Models\\'.$init['route'].'Model'; $model = new $modelName; $dt = $model->getDT($data,$init); $dt->addColumn('action', function ($data) use($init,$type) { // $param['id_key'] = $data->{$init['db_key']}; $param['id_key'] = Crypt::encryptString($data->{$init['db_key']}); $param['data'] = $data; $param['type'] = $type; //SET BUTTON return $this->getButtonAction($init['actButton'],$param); }); $dt->rawColumns(['logo','user_status_id','is_hotel','is_resto','is_mini_atm_active','tax_list','sn_list','is_sale_active','tsid','action','is_active','is_park_active','is_market_active','product_nominal']); return $dt->make(true); } public function store(Request $request) { $checkRole = $this->checkRoleAccessRef($request->get('type')); if ($checkRole == false) { return view('errors.404'); } DB::beginTransaction(); try{ //GET INIT $init = $this->getInit($request,$request->get('type')); $get_id = $request->input('get_id'); $setField = $init['set_field']; if ($get_id) { $get_id = $this->decryptIdOnly($get_id); } // SPECIAL CONDITION $check = $this->specialCondition($init['db'],$setField,$get_id); if ($check['rc'] == 99) { return response()->json([ 'rc' => 99, 'rm' => $check['rm'] ]); } //IF EDIT DATA if ($get_id) { if (isset($init['timestamps'])) { $setField['updated_at'] = date('Y-m-d H:i:s'); } $oldData = DB::table($init['db'])->where($init['db_key'], $get_id)->first(); DB::table($init['db'])->where($init['db_key'], $get_id)->update($setField); $event = "Edit Data ".$request->get('type'); $this->auditTrailValue($event,"Referensi",$init['db'],json_encode($setField),json_encode($oldData)); //IF ADD DATA }else { if (isset($init['timestamps'])) { $setField['created_at'] = date('Y-m-d H:i:s'); $setField['updated_at'] = date('Y-m-d H:i:s'); } $seq = DB::table($init['db'])->max($init['db_key']); $setField[$init['db_key']] = $seq+1; DB::table($init['db'])->insert($setField); $event = "Tambah Data ".$request->get('type'); $this->auditTrailValue($event,"Referensi",$init['db'],json_encode($setField),''); } DB::commit(); return response()->json([ 'rc' => 0, 'rm' => "sukses" ]); } catch (QueryException $e){ if($e->getCode() == '23505'){ $response = "Terjadi Duplikasi Data, Data Gagal Disimpan !"; }else{ $response = "Terjadi Kesalahan, Data Tidak Sesuai !"; } DB::rollback(); return response()->json([ 'rc' => 99, 'rm' => $response, // // 'msg' => $e->getMessage() ]); } } public function storeCustom(Request $request) { $checkRole = $this->checkRoleAccessRef($request->get('type')); if ($checkRole == false) { return view('errors.404'); } $decryt = $this->decryptId($request); if ($decryt['rc'] == 0) { $init = $this->getInit($decryt['data'],$request->get('type')); $modelName = '\\App\Models\\'.$init['route'].'Model'; $model = new $modelName; return $model->storeCustom($request->get('act'),$decryt['data']); } } public function edit(Request $request) { $checkRole = $this->checkRoleAccessRef($request->get('type')); if ($checkRole == false) { return view('errors.404'); } $decryt = $this->decryptId($request); if ($decryt['rc'] == 0) { $init = $this->getInit($decryt['data'],$request->get('type')); $getData = $init['get_data_edit']; if($request->get('type') == 'merchant'){ $getData['merchant']->get_id = Crypt::encryptString($getData['merchant']->mid); } else if($request->get('type') == 'toko'){ $getData['outlet']->outlet_id = Crypt::encryptString($getData['outlet']->outlet_id); } else{ $getData->{$init['db_key']} = Crypt::encryptString($getData->{$init['db_key']}); } return response()->json([ 'rc' => 0, 'data' => $getData ]); } } public function hapus(Request $request) { $checkRole = $this->checkRoleAccessRef($request->get('type')); if ($checkRole == false) { return view('errors.404'); } $decryt = $this->decryptId($request); if ($decryt['rc'] == 0) { $init = $this->getInit($decryt['data'],$request->get('type')); DB::table($init['db'])->where($init['db_key'], $decryt['data']->id)->delete(); $event = "Hapus Data ".$request->get('type'); $this->auditTrailValue($event,"Data",$init['db'],$decryt['data']->id,''); return response()->json([ 'rc' => 0, 'rm' => "Berhasil" ]); } } public function SetActive(Request $request) { //GET INIT $checkRole = $this->checkRoleAccessRef($request->get('type')); if ($checkRole == false) { return view('errors.404'); } $decryt = $this->decryptId($request); if ($decryt['rc'] == 0) { $init = $this->getInit($decryt['data'],$request->get('type')); $id = $request->input('id'); $isActive = $request->input('active'); if ($isActive == true) { DB::table($init['db'])->where($init['db_key'], $decryt['data']->id)->update([ 'is_active' => false, ]); $reqMessage = 'berhasil dinonaktifkan'; $event = $request->get('type')." ".$reqMessage; // $this->auditTrail($event,"Referensi"); $this->auditTrailValue($event,"Aktifasi",$init['db'],$decryt['data']->id,''); } else { if ($init['db'] == 'mst_wscreen') { DB::table('mst_wscreen')->update(['is_active' => false]); } DB::table($init['db'])->where($init['db_key'], $decryt['data']->id)->update([ 'is_active' => true, ]); $reqMessage = 'berhasil diaktifkan'; $event = $request->get('type')." ".$reqMessage; // $this->auditTrail($event,"Referensi"); $this->auditTrailValue($event,"Aktifasi",$init['db'],$decryt['data']->id,''); } return response()->json([ 'rc' => 0, 'rm' => $reqMessage ]); } } public function importXls(Request $request) { if($request->hasFile('xls_file')){ $import = new DeviceImport; Excel::import($import, $request->file('xls_file')); if ($import->validate) { return response()->json([ 'rc' => 99, 'rm' => 'Data Tidak Sesuai', 'msg'=> $import->validate ]); }else{ return response()->json([ 'rc' => 0, 'rm' => 'berhasil', 'msg' => 'berhasil' ]); } } } public function getButtonAction($typeButton,$param) { $editBtn =""; $detailBtn =""; $ActiveBtn = ""; $deleteBtn = ""; // DETAIL BUTTON if ( in_array("detail", $typeButton)) { $detailBtn = '