role == 2){ // if($view == 'content.ref.index'){ // return view('errors.404'); // } // } $isAllow = false; $urlCheck = substr(\Request::getRequestUri(),1); if (!Auth::user()) { Auth::guard('admin')->logout(); return view('auth.login'); } $check = \DB::select("SELECT m.* from menu m join menu_privilege mp on mp.menu_uid = m.menu_uid where mp.group_id = ?",[Auth::user()->role]); foreach ($check as $key => $v) { if($v->url == '/'.$urlCheck){ $isAllow = true; } } if ($isAllow) { if (Req::ajax()) { return view('content.onlyContent')->nest('child', $view,$param); }else { return view('content.main')->nest('child', $view,$param); } }else{ return view('errors.404'); } } public function convertDate($date) { return date('Y-m-d',strtotime($date)); } public function cleanString($string) { // $string = str_replace(' ', '', $string); $string = str_replace('(', '', $string); $string = str_replace(')', '', $string); return preg_replace('/[^a-zA-Z0-9,()%@_ ]/', '', $string); } public function checkRoleAccessRef($type) { $isAllow = false; $check = \DB::select("SELECT m.* from menu m join menu_privilege mp on mp.menu_uid = m.menu_uid where mp.group_id = ?",[Auth::user()->role]); foreach ($check as $key => $v) { $typeUrl = substr($v->url, strpos($v->url, "=") + 1); if($typeUrl == $type){ $isAllow = true; } } return $isAllow; } public function checkRoleAccess($type) { $isAllow = false; $check = \DB::select("SELECT m.* from menu m join menu_privilege mp on mp.menu_uid = m.menu_uid where mp.group_id = ?",[Auth::user()->role]); foreach ($check as $key => $v) { $typeUrl = substr($v->url, strpos($v->url, "list/") + 5); if($typeUrl == $type){ $isAllow = true; } } return $isAllow; } public function decryptId($request) { try { if ($request->id) { $decId = Crypt::decryptString($request->id); $request->merge([ 'id' => $decId, ]); } if ($request->get_id) { $decId = Crypt::decryptString($request->get_id); $request->merge([ 'get_id' => $decId, ]); } if ($request->outlet_id) { $decId = Crypt::decryptString($request->outlet_id); $request->merge([ 'outlet_id' => $decId, ]); } if ($request->get_mid_tax) { $decId = Crypt::decryptString($request->get_mid_tax); $request->merge([ 'get_mid_tax' => $decId, ]); } return ['rc' => 0, 'data'=> $request]; } catch (DecryptException $e) { return ['rc' => 0, 'data'=> $request]; // return ['rc' => 999, 'data'=> 'Fak ╭∩╮(︶_︶)╭∩╮']; } } public function decryptIdOnly($id) { try { $decId = Crypt::decryptString($id); return $decId; } catch (DecryptException $e) { return ['rc' => 999, 'data'=> 'Fak ╭∩╮(︶_︶)╭∩╮']; } } public function hashPassword($password) { $iterations = 310000; $salt = openssl_random_pseudo_bytes(16); $hash_password = hash_pbkdf2('sha256', $password, $salt,$iterations,0, false); $salt = bin2hex($salt); return $salt.$hash_password; } public function hashPasswordCheck($passwordInput,$passwordUser) { $salt = substr($passwordUser,0,32); $saltHex = hex2bin($salt); $iterations = 310000; $hash_password = hash_pbkdf2('sha256', $passwordInput, $saltHex,$iterations,0, false); return $salt.$hash_password; } public function convertDateYear($date) { return date('Y',strtotime($date)); } public function convertDateMonth($date) { return date('m',strtotime($date)); } public function responseData($code, $message){ return ['code' => $code, 'message'=> $message]; } public function getNasabah($id) { return \DB::select("SELECT * FROM users where user_uid = ".$id); } public function getUserAdmin($id) { return \DB::select("SELECT * FROM users_admin where id = ".$id); } public function rupiah($nominal) { return "Rp ".number_format($nominal,0,",","."); } public function getNotifDesc($status) { $data = DB::selectOne("select notif from notif_format where id = ?",[$status]); return $data->notif; } public function clearSeparator($nominal) { if($nominal){ $nom = str_replace('.','',$nominal); $nom = str_replace(',','.',$nom); }else{ $nom = 0; } return $nom; // return str_replace('.','',$nominal); } public function numFormat($nominal) { return number_format($nominal,0,",","."); } public function sendNotif($cust_id,$text,$type) { $data = new NotifListModel(); $data->cust_id = $cust_id; $data->notif = $text; $data->type = $type; $data->save(); } public function sendMail($view,$data) { Mail::send($view, $data, function ($message) use ($data) { $message->from('official@huit.co.id', 'HUIT SPORTWEAR'); $message->to($data['sendto']); $message->subject($data['subject']); }); } public function auditTrail($event,$data) { $get = collect(\DB::select("SELECT max(id) as max_id FROM audits"))->first(); $d = new AuditTrailModel(); $d->id = $get->max_id+1; $d->user_id = Auth::user()->id; $d->event = Auth::user()->username."|".$event; $d->auditable_type = $data; $d->auditable_id = 0; $d->created_at = Date('Y-m-d H:i:s'); $d->save(); Log::info($event); } public function auditTrailValue($event,$data,$table,$newvalue,$oldvalue) { $get = collect(\DB::select("SELECT max(id) as max_id FROM audits"))->first(); $d = new AuditTrailModel(); $d->id = $get->max_id+1; $d->user_id = Auth::user()->id; $d->event = Auth::user()->username."|".$event; $d->auditable_type = $data; $d->auditable_id = 0; $d->created_at = Date('Y-m-d H:i:s'); $d->old_value = $oldvalue; $d->new_value = $newvalue; $d->table = $table; $d->save(); Log::info($event."|".$newvalue."|".$oldvalue); } public function auditTrailLog($event,$data,$table,$newvalue,$oldvalue) { $get = collect(\DB::select("SELECT max(id) as max_id FROM audits"))->first(); $d = new AuditTrailModel(); $d->id = $get->max_id+1; $d->event = $event; $d->auditable_type = $data; $d->auditable_id = 0; $d->created_at = Date('Y-m-d H:i:s'); $d->old_value = $oldvalue; $d->new_value = $newvalue; $d->table = $table; $d->save(); Log::info($event."|".$newvalue."|".$oldvalue); } public function DeleteWhere($table,$id,$condition) { DB::table($table)->where('votes', '>', 100)->delete(); } public function get_data(Request $request) { // LOCAL get if ($request->input('type') == 'local') { $response = json_encode($response); } // LOCAL POST WITH ID elseif ($request->input('type') == 'local_id') { $response = json_encode($response); } //API else{ $url = $request->input('url').$request->input('id'); $response = Http::withToken('eyJhbGciOiJIUzUxMiJ9.eyJhdXRob3JpdGllcyI6WyJST0xFX1dFQk1JTiJdLCJzdWIiOiJ3ZWJtaW4ifQ.IyFC9q18ehYtCUsOcLzHxnXbFog92DTCZxY2aR49NFElmIBFKBup2LC7Ld28m3mdDPYvI4UaUlsp1CbqwfMf0Q') ->get(env('API_BASE').$url)->json(); } return $response; } public function getPerencanaanByJobId($id) { $getPerencanaan = collect(\DB::select("SELECT map.* from master_audit_plan map join master_audit_job maj on maj.audit_plan_id = map.id where maj.id = ?",[$id]))->first(); return $getPerencanaan; } public function getPerencanaanByPlanId($id) { $getPerencanaan = collect(\DB::select("SELECT map.* from master_audit_plan map where map.id = ?",[$id]))->first(); return $getPerencanaan; } public function generateQR($data) { $toko_name = Str::of($data->toko_nm)->slug('_'); $fileName = $data->toko_id. '_' . $toko_name . '_qrcode' . '.png'; $qrCode = new QrCode(); $pathImgFile = public_path('qrcode') . "/" . $fileName; $d_json = [ 'toko_id' => Crypt::encryptString($data->toko_id), 'toko_nm' => $data->toko_nm, 'mid' => $data->mid ]; // $dataQR = json_encode($d_json); $enc_data = Crypt::encryptString($data->toko_id); // $dec_data = Crypt::decryptString($enc_data); $qrCode->setText($enc_data) ->setSize(600) ->setPadding(30) ->setErrorCorrection('high') ->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0)) ->setBackgroundColor(array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0)) // Path to your logo with transparency ->setLogo(public_path('/img/') . "bank_ntt.png") // Set the size of your logo, default is 48 ->setLogoSize(150) ->setImageType(QrCode::IMAGE_TYPE_PNG); $qrCode->save($pathImgFile); return $fileName; } // end function }