$request->route()->getAction('prefix'), 'task' => taskLabel($request->route()->getActionMethod()), 'user_id' => session('uid'), 'ipaddress' => $request->getClientIp(), 'useragent' => $request->header('User-Agent'), 'note' => $note, 'created_at' => \Carbon\Carbon::now() ]; if (session('superuser') == false) $repository->create($data); } } if (!function_exists('trimId')) { /** * @param $val * @return array */ function trimId($val) { $string = explode('+', $val); return $string; } } if (!function_exists('dateTime')) { /** * make secure id * * @param string|null $val * * @return string */ function dateTime($date) { return date('d-m-Y H:i:s',strtotime(@$date)); } } if (!function_exists('encode_id')) { /** * make secure id * * @param string|null $val * * @return string */ function encode_id(?string $val = ''): string { $params = ['val' => $val]; return rtrim(base64_encode(serialize($params)), "="); } } if (!function_exists('decode_id')) { /** * @param string|null $val * ${STATIC} * * @return mixed|null * @author alex.gz * @created 02/12/2023 4:28 * */ function decode_id(?string $val = ''): mixed { $secure = unserialize(base64_decode($val)); return $secure ? $secure['val'] : null; } } if (!function_exists('permission')) { /** * @param $access * @param $key * @param string $method * @param bool $view * * @return mixed */ function permission($access, $key, string $method = 'menu', bool $view = false): mixed { if (@session('group_id') != 1) { if ($method == 'module') { if (is_array($access)) { $model = AccessMenu::where('module', 'LIKE', "{$key}%")->where('ms_group_id', session('group_id'))->first(); $query = count(array_intersect((array)$access, (array)$model->access)); } else { $query = AccessMenu::where($access, true)->where('module', 'LIKE', $key.'%')->where('ms_group_id', session('group_id'))->count(); if ($query > 0) { return true; } else { return abort('401'); } } } else { $query = AccessMenu::where($access, true)->where('ms_menu_id', $key)->where('ms_group_id', session('group_id'))->count(); } if ($query > 0) { return true; } else { return false; } } else { return true; } } } if (!function_exists('access')) { /** * @param $access * @param $key * * @return bool */ function access($access, $key) { if (session('group_alias') != 'administrator') { $query = AccessMenu::where($access, 1)->where('module', $key)->where('ms_group_id', session('group_id'))->count(); if ($query > 0) { return true; } else if (session('group_alias') == 'administrator') { return true; } else { return false; } } else { return true; } } } if (!function_exists('activeMenuClass')) { /** * Helper to grab the application version. * * @return mixed */ function activeMenuClass($route){ // dd(request()->route()->getName()); // if(request()->route()->getName() == $route){ // return true; // }else{ // return false; // } if (\Str::is($route, request()->route()->getName())) { return true; } else { return false; } } } if (!function_exists('renderMenu')) { /** * Loops through a folder and requires all PHP files * Searches sub-directories as well. * * @param $folder */ function renderMenu() { $parent = Menu::where('status',true)->where('menu_type','sidebar')->where('parent_id',0)->orderBy('ordering','ASC')->get(); $html = ''; foreach ($parent as $a => $p1) { // echo $p1->MsMenuId.'
'; $child2 = Menu::where('status',true)->where('menu_type','sidebar')->where('parent_id',$p1->MsMenuId)->orderBy('ordering','ASC')->get(); $access1 = permission('is_read', $p1->MsMenuId, 'menu', true); $ch1 = count($child2) > 0 ? 'has-arrow' : ''; $link1 = count($child2) > 0 ? '' : ''; $collapse1 = count($child2) > 0 ? 'href="javascript: void(0);"' : ''; $active = activeMenuClass($p1->module) ? 'mm-active' : ''; // dd($p1->route); if ($access1) { $active1 = activeMenuClass($p1->module) ? 'mm-active' : ''; $html .= '
  • '.@$p1->title.''; if (count($child2) > 0) { $html .= ''; $html .= ''; $html .= ''; } else { $html .= ''; } $html .= '
  • '; } } return $html; } } if (!function_exists('include_route_files')) { /** * Loops through a folder and requires all PHP files * Searches sub-directories as well. * * @param $folder */ function include_route_files($folder) { include_files_in_folder($folder); } } if (!function_exists('include_files_in_folder')) { /** * Loops through a folder and requires all PHP files * Searches sub-directories as well. * * @param $folder */ function include_files_in_folder($folder) { try { $rdi = new RecursiveDirectoryIterator($folder); $it = new RecursiveIteratorIterator($rdi); while ($it->valid()) { if (!$it->isDot() && $it->isFile() && $it->isReadable() && $it->current()->getExtension() === 'php') { require $it->key(); } $it->next(); } } catch (Exception $e) { echo $e->getMessage(); } } } //NEWW if (!function_exists('getMatriks')) { function getMatriks($ghgCode,$arCode) { $gwp = GWP::whereHas('ghg',function($queryGHG) use ($ghgCode){ $queryGHG->where('kode',$ghgCode); })->whereHas('ar',function($queryAR) use ($arCode){ $queryAR->where('kode',$arCode); })->first(); return @$gwp->value; } } if (!function_exists('getFormattedValue')) { function getFormattedValue($value, $decNum = 8, $hasTrail = false) { if ($value !== null && $value !== '' && is_numeric($value)) { // Convert to float and format with maximum decimal places $value = number_format((float) $value, $decNum, ',', '.'); // Remove trailing zeros and the decimal separator if there are no decimals left if ($hasTrail == false) { $value = rtrim(rtrim($value, '0'), ','); } } return $value; } } if (!function_exists('getOriginalValue')) { function getOriginalValue($value) { if ($value) { $value = str_replace('.', '', $value); // Remove periods $value = str_replace(',', '.', $value); // Replace commas with periods if (is_numeric($value)) { return (float) $value; } } return $value; } } if (!function_exists('formatActivityCode')) { function formatActivityCode($code) { if (strpos($code, '_') === false && strlen($code) <= 3) { return strtoupper($code); } else { $words = explode('_', $code); $formattedWords = array_map('ucwords', $words); return implode(' ', $formattedWords); } } } if (!function_exists('activityYearRange')) { function activityYearRange(int $inventoryYear, $isDesc = true, int $range = 15): array { if ($isDesc == true) { return range($inventoryYear - 1, $inventoryYear - $range); } else { return range($inventoryYear - $range, $inventoryYear - 1); } } } if (!function_exists('valueUnitKonversion')) { function valueUnitKonversion($kategori,$from,$to) { $value = UnitKonversi::where('kategori_id',$kategori) ->where('from_id',$from) ->where('to_id',$to) ->orderBy('UnitKonversiId','ASC') ->first(); return $value->value; } }