";
print_r($object);
echo "";
if ($die) die;
}
function label($text, $echo = true)
{
if ($echo) {
echo $text;
} else {
return $text;
}
}
function template($filepath)
{
$filepath = env("APP_URL") .'/' .env("CLIENT_PATH") . '/' . $filepath;
// $filepath=str_replace('\\','/',env("APP_URL")."/layout/".$filepath);
echo $filepath;
// return
}
if (!function_exists('N2')) {
function N2($N)
{
return number_format($N, 2, '.', ',');
}
}
if (!function_exists('slugify')) {
function slugify($text)
{
$text = preg_replace('/[^a-zA-Z0-9\-]/', '-', $text);
$text = preg_replace('/-+/', '-', $text);
$text = trim($text, '-');
$text = strtolower($text);
return $text;
}
}
function createButton($class = "", $type = "submit", $display = "Submit", $url = "")
{
if (!$url) :
?>
placeholder="" name="" class="form-control " value="" required>
where('status', '<>', -1)->orderBy($pk, 'asc')->pluck($name, $pk);
$customColumnName = !empty($customColumnName) ? $customColumnName : $pk; //if we pass column name other then primary key.
customCreateSelect($pk, $pk, $class, $display ?? $name, $systems, ($data) ? $data->$customColumnName : null);
}
function customCreateSelect($name, $id, $class = "form-control", $display = '', $values = array(), $defaultValue = '')
{
$disabled = (in_array("DISABLED", explode(" ", strtoupper($class)))) ? "Disabled" : false;
$required = (in_array("REQUIRED", explode(" ", strtoupper($class)))) ? "Required" : false;
?>
where('status', '<>', -1);
if ($defaultCondition) {
$query->whereRaw($defaultCondition);
}
$systems = $query->orderBy($fieldNameForValue, 'asc')->pluck($fieldNameToDisplay, $fieldNameForValue);
?>
" style="height: 5rem" />
" style="height: 40px;" class="img-fluid" />
where($referenceFieldName, $referenceValue);
$fieldData = $query->value($returnField);
return $fieldData;
}
function createErrorParagraph($name, $class = null)
{
echo "";
}
function createActivityLog($controllerName, $methodName, $activity)
{
$user_id = auth()->user()->id;
ActivityLog::create([
'user_id' => $user_id,
'controllerName' => $controllerName,
'methodName' => $methodName,
'actionUrl' => request()->fullUrl(),
'activity' => $activity,
]);
}
function getOperationNumber()
{
$startNumber = date('YmdHis') . rand(1000, 9999);
$isExists = OperationLog::where('operation_end_no', $startNumber)->first();
while ($isExists) {
$startNumber = date('YmdHis') . rand(1000, 9999);
$isExists = OperationLog::where('operation_end_no', $startNumber)->first();
}
return $startNumber;
}
function createOperationLog($startOperationNumber, $endOperationNumber, $modelName, $modelId, $operationName, $previousValues, $newValues)
{
$operationId = getOperationNumber();
$user_id = auth()->user()->id;
OperationLog::create([
'user_id' => $user_id,
'operation_start_no' => $startOperationNumber,
'operation_end_no' => $endOperationNumber,
'model_name' => $modelName,
'model_id' => $modelId,
'operation_name' => $operationName,
'previous_values' => $previousValues ? json_encode($previousValues) : null,
'new_values' => $newValues ? json_encode($newValues) : null,
]);
}
function createErrorLog($controllerName, $methodName, $errors)
{
$user_id = auth()->user()->id;
ErrorLog::create([
'user_id' => $user_id,
'controller_name' => $controllerName,
'method_name' => $methodName,
'errors' => $errors,
]);
}
function createDate($name, $display = "", $class = "datepicker", $default = "")
{
?>
display_order;
$nextDisplayOrder = $maxDisplayOrder + 1;
return $nextDisplayOrder;
}
if (!function_exists('myDate')) {
function myDate($originalDate)
{
return date("F d Y", strtotime($originalDate));
}
}
if (!function_exists('dbDate')) {
function dbDate($date)
{
return date("Y-m-d", strtotime($date));
}
}
if (!function_exists('myTime')) {
function myTime($originalDate)
{
return date("g:i A", strtotime($originalDate));
}
}
if (!function_exists('myDateTime')) {
function myDateTime($originalDate)
{
return date("F d Y g:i A", strtotime($originalDate));
}
}
if (!function_exists('myDaysDiff')) {
function myDaysDiff($fromDate, $toDate)
{
$fromDate = strtotime($fromDate);
$toDate = strtotime($toDate);
$datediff = $toDate - $fromDate;
return round($datediff / (60 * 60 * 24));
}
}
if (!function_exists('firstDayOfNepaliMonth')) {
function firstDayOfNepaliMonth($engDate = "")
{
$engDate = ($engDate != "") ? $engDate : date("Y-m-d");
$NepaliDate = NepaliDate($engDate);
$nD = explode("-", $NepaliDate);
$Day = '1';
$Month = $nD[1];
$Year = $nD[0];
$t = "select bs_date from tbl_nepengcalendar where bs_date='" . $Year . "-" . $Month . "-" . $Day . "'";
return DB::select($t)[0]->bs_date;
}
}
if (!function_exists('firstDayOfNepaliMonth1')) {
function firstDayOfNepaliMonth1($engDate = "")
{
$engDate = ($engDate != "") ? $engDate : date("Y-m-d");
$NepaliDate = NepaliDate($engDate);
$nD = explode("-", $NepaliDate);
$Day = '1';
$Month = ($nD[1] < 10) ? '0' . $nD[1] : $nD[1];
$Year = $nD[0];
$t = "select ad_date from tbl_nepengcalendar where bs_date='" . $Year . "-" . $Month . "-" . $Day . "'";
return DB::select($t)[0]->ad_date;
}
}
if (!function_exists('lastDayOfNepaliMonth')) {
function lastDayOfNepaliMonth($engDate = "")
{
$engDate = ($engDate != "") ? $engDate : date("Y-m-d");
$NepaliDate = NepaliDate1($engDate);
$nD = explode("-", $NepaliDate);
$Day = '1';
$Month = $nD[1];
$Year = $nD[0];
$t = "select ad_date from tbl_nepengcalendar where bs_date like '" . $Year . "-" . $Month . "-%' order by ad_date";
$dates = DB::select($t);
$date = end($dates);
return $date->ad_date;
}
}
if (!function_exists('EnglishDate')) {
function EnglishDate($NepaliYear, $NepaliMonth, $NepaliDay)
{
if ($NepaliMonth < 10) {
$NepaliMonth = "0" . $NepaliMonth;
}
$bs_date = $NepaliYear . "-" . $NepaliMonth . "-" . $NepaliDay;
$t = "select ad_date from tbl_nepengcalendar where bs_date='$bs_date'";
$q = DB::select($t);
return $q[0]->ad_date;
}
}
if (!function_exists('Today')) {
function Today()
{
return date("Y-m-d");
}
}
if (!function_exists('NepaliToEnglishDate')) {
function NepaliToEnglishDate($NepaliDate)
{
$NepaliDate = trim($NepaliDate);
if (trim($NepaliDate) == "") {
return date("Y-m-d");
}
$NepaliDate = explode("-", $NepaliDate);
$NepaliMonth = intval($NepaliDate[1]);
$NepaliYear = intval($NepaliDate[0]);
$NepaliDay = intval($NepaliDate[2]);
if ($NepaliMonth < 10) {
$NepaliMonth = "0" . $NepaliMonth;
}
$bs_date = $NepaliYear . "-" . $NepaliMonth . "-" . $NepaliDay;
$t = "select ad_date from tbl_nepengcalendar where bs_date='$bs_date'";
$q = DB::select($t);
return $q[0]->ad_date;
}
}
if (!function_exists('NepaliDate')) {
function NepaliDate($engDate = "")
{
$engDate = ($engDate != "") ? $engDate : date("Y-m-d");
if ($engDate != "0000-00-00") {
// return str_replace("-0", "-", DB::table('tbl_nepengcalendar')->where('ad_date', $engDate)->first()->bs_date);
$result = DB::table('tbl_nepengcalendar')->where('ad_date', $engDate)->first();
if ($result) {
$bsDate = $result->bs_date;
$convertedDate = convertNumbersToUnicode(str_replace("-", "-", $bsDate));
return $convertedDate;
} else {
// Handle the case when the query result is null
return null;
}
} else {
return "";
}
}
}
function convertNumbersToUnicode($number = "2080-10-13")
{
$unicodeDigits = [
'0' => '०',
'1' => '१',
'2' => '२',
'3' => '३',
'4' => '४',
'5' => '५',
'6' => '६',
'7' => '७',
'8' => '८',
'9' => '९',
];
$converted = '';
$digits = str_split((string)$number);
foreach ($digits as $digit) {
if (isset($unicodeDigits[$digit])) {
$converted .= $unicodeDigits[$digit];
} elseif ($digit === '-') {
$converted .= '-';
} else {
$converted .= $digit;
}
}
//dd($converted);
return $converted;
}
if (!function_exists('NepaliMonth')) {
function NepaliMonth($engDate = "")
{
$NepaliDate = NepaliDate($engDate);
$nD = explode("-", $NepaliDate);
$Month = $nD[1];
return intval($Month);
}
}
if (!function_exists('NepaliYear')) {
function NepaliYear($engDate = "")
{
$NepaliDate = NepaliDate($engDate);
$nD = explode("-", $NepaliDate);
$Year = $nD[0];
return intval($Year);
}
}
if (!function_exists('NepaliMonthNameByNumber')) {
function NepaliMonthNameByNumber($number)
{
$MonthNames = array(
"Baisakh", "Jestha", "Ashad", "Shrawan", "Bhadra", "Asoj",
"Kartik", "Mangsir", "Poush", "Magh", "Falgun", "Chaitra"
);
return $MonthNames[$number - 1];
}
}
if (!function_exists('NepaliMonthName')) {
function NepaliMonthName($engDate = "")
{
$Month = NepaliMonth($engDate);
$MonthNames = array(
"Baisakh", "Jestha", "Ashad", "Shrawan", "Bhadra", "Asoj",
"Kartik", "Mangsir", "Poush", "Magh", "Falgun", "Chaitra"
);
return $MonthNames[$Month - 1];
}
}
if (!function_exists('N2')) {
function N2($N)
{
return number_format($N, 2, '.', ',');
}
}
function collectScripts(callable $callback)
{
ob_start();
$callback();
$script = ob_get_clean();
if (!empty($script)) {
pushScriptToFooter($script);
}
}
function pushScriptToFooter($script)
{
if (!isset($GLOBALS['scripts'])) {
$GLOBALS['scripts'] = [];
}
$GLOBALS['scripts'][] = $script;
}
function processForShortcode($content)
{
return preg_replace_callback('/\[([\w_]+)([^]]*)\]/', function ($matches) {
$shortcodeName = $matches[1];
$shortcodeAttributes = [];
$mandatoryAttributes = ['alias', 'css', 'title'];
preg_match_all('/\s*(\w+)\s*=\s*(?:"([^"]*)"|\'([^\']*)\'|([^"\'][^\s]*))/', $matches[2], $attrMatches, PREG_SET_ORDER);
foreach ($attrMatches as $attrMatch) {
$attrName = $attrMatch[1];
$attrValue = $attrMatch[2] ?: ($attrMatch[3] ?: $attrMatch[4]); // Use non-empty capture group as the attribute value
$attrValue = trim($attrValue, "\"'"); // Remove both single and double quotes from the attribute value
$shortcodeAttributes[$attrName] = $attrValue;
}
// Fill in missing mandatory attributes with empty strings
foreach ($mandatoryAttributes as $attribute) {
if (!isset($shortcodeAttributes[$attribute])) {
$shortcodeAttributes[$attribute] = '';
}
}
return view("shortcodes." . $shortcodeName, $shortcodeAttributes);
}, $content);
}