Path : /var/www/html/thb_loan_system/app/ |
B-Con CMD Config cPanel C-Rdp D-Log Info Jump Mass Ransom Symlink vHost Zone-H |
Current File : /var/www/html/thb_loan_system/app/helpers.php |
<?php use App\Models\Borrower; use App\Models\Currency; use App\Models\Loan; use Carbon\Carbon; // Currency if (!function_exists('set_local_currency')) { function set_local_currency($currency) { session()->put('currency', $currency); } } if (!function_exists('get_default_currency')) { function get_default_currency() { $currency = session('currency', null); if (!$currency) { $currency = Currency::query() ->where('status', 1) ->where('default', 1) ->first(); } if (!$currency) { $currency = Currency::query() ->where('code', 'USD') ->first(); } set_local_currency($currency); return $currency; } } if (!function_exists('get_active_currencies')) { function get_active_currencies() { $currencies = collect(session('currencies', [])); if ($currencies->count() <= 0) { $currencies = Currency::query()->where('status', 1)->get(); session()->put('currencies', $currencies); } return $currencies; } } if (!function_exists('currency_converter')) { function currency_converter($amount, $decimals = 2) { return set_currency_symbol(round($amount, $decimals)); } } if (!function_exists('set_currency_symbol')) { function set_currency_symbol($amount, $decimals = 2) { $currency_position = get_currency_position(); $currency_symbol = get_currency_symbol(); if ($currency_position == 'left') { return $currency_symbol . ' ' . number_format($amount, $decimals); } return number_format($amount, $decimals) . ' ' . $currency_symbol; } } if (!function_exists('get_currency_position')) { function get_currency_position() { $position = session('currency_position', null); if (!$position) { $setting = \App\Models\Setting::where('setting_key', 'currency_position')->first(); $position = $setting->setting_value ?? 'left'; session()->put('currency_position', $position); } return $position; } } if (!function_exists('get_currency_symbol')) { function get_currency_symbol() { $symbol = session('currency_symbol', null); if (!$symbol) { $setting = \App\Models\Setting::where('setting_key', 'currency_symbol')->first(); $symbol = $setting->setting_value ?? '$'; session()->put('currency_symbol', $symbol); } return $symbol; } } // Loan if (!function_exists('get_loan_status_info')) { function get_loan_status_count() { return Loan::query()->toBase() ->selectRaw('count(*) as total') ->selectRaw("count(case when status = 'pending' then 1 end) as pending") ->selectRaw("count(case when status = 'approved' then 1 end) as approved") ->selectRaw("count(case when status = 'disbursed' then 1 end) as disbursed") ->selectRaw("count(case when status = 'rescheduled' then 1 end) as rescheduled") ->selectRaw("count(case when status = 'written_off' then 1 end) as written_off") ->selectRaw("count(case when status = 'declined' then 1 end) as declined") ->selectRaw("count(case when status = 'closed' then 1 end) as closed") ->selectRaw("count(case when status = 'disbursement' then 1 end) as disbursement") ->selectRaw("count(case when status = 'withdrawn' then 1 end) as withdrawn") ->where('branch_id', session('branch_id')) ->first(); } } if (!function_exists('get_borrowers_reports')) { function get_borrowers_reports($start_date = null, $end_date = null) { if (!empty($start_date) && !empty($end_date)) { $start_date = Carbon::parse($start_date)->startOfDay()->format('Y-m-d H:m:s'); $end_date = Carbon::parse($end_date)->endOfDay()->format('Y-m-d H:m:s'); } return Borrower::query() ->selectRaw("count('*') as total") ->selectRaw("count(case when blacklisted = '1' then 1 end) as blacklisted") ->selectRaw("count(case when created_at >= NOW() - INTERVAL 60 DAY = '1' then 1 end) as new_borrowers") ->selectRaw("count(case when (select count(*) from loans where loans.borrower_id = borrowers.id) > 0 then 1 end) as active_borrowers") ->selectRaw("count(case when (select count(*) from loans where loans.borrower_id = borrowers.id) <= 0 then 1 end) as dormant_borrowers") ->when(!empty($start_date) & !empty($end_date), function ($query) use ($start_date, $end_date) { return $query->whereBetween('created_at', [$start_date, $end_date]); }) ->first(); } } if (!function_exists('default_lang')) { function default_lang() { return session()->get('language') ?? app()->getLocale(); } } if (!function_exists('remove_invalid_character')) { function remove_invalid_character($str) { return str_ireplace(['\'', '"', ',', ';', '<', '>', '?'], ' ', $str); } } if (!function_exists('translate')) { function translate($key) { $local = default_lang(); app()->setLocale($local); $lang_path = base_path('resources/lang/' . $local . '/general.php'); $lang_array = include($lang_path); if (!is_array($lang_array)) { $lang_array = []; } $processed_key = ucfirst(str_replace('_', ' ', remove_invalid_character($key))); if (!array_key_exists($key, $lang_array)) { $lang_array[$key] = $processed_key; $str = "<?php return " . var_export($lang_array, true) . ";"; file_put_contents($lang_path, $str); $result = $processed_key; } else { $result = trans('general.' . $key); } return $result; } } if (!function_exists('default_paginate')) { function default_paginate() { return request('limit', 20); } } if (!function_exists('allowedPagination')) { function allowedPagination() { return [10,20,50,100,500,1000]; } }