Files
Credit-Zombies/app/Helper/helper.php
2026-06-24 18:29:01 +06:00

898 lines
25 KiB
PHP

<?php
if(!function_exists('uploadFile')){
function uploadFile($file_path,$file_name,$content){
app('ManageFile')->uploadFile($file_path,$file_name,$content);
}
}
if(!function_exists('getFile')){
function getFile($file_path){
return app('ManageFile')->getFile($file_path);
}
}
if(!function_exists('uploadHTML')){
function uploadHTML($file_path,$file_name,$content){
return app('ManageFile')->uploadHTML($file_path,$file_name,$content);
}
}
if(!function_exists('deleteFile')){
function deleteFile($file_path){
return app('ManageFile')->deleteFile($file_path);
}
}
if(!function_exists('getPublicFile')){
function getPublicFile($file_path){
$file_path = config('constant.MAIN_DIR').DIRECTORY_SEPARATOR.$file_path;
return \Illuminate\Support\Facades\Storage::disk('public')->exists($file_path) ? asset(Illuminate\Support\Facades\Storage::url($file_path)):"";
}
}
if(!function_exists('getSupportFile')){
function getSupportFile($file_path){
return asset('storage/resources/support_ticket/'.$file_path);
}
}
if(!function_exists('appLog')){
function appLog($data){
app('ManageLogging')->createLog($data);
}
}
if(!function_exists('generateOrderId')) {
function generateOrderId(): string
{
return time() . rand(10000, 99999);
}
}
if(!function_exists('generateUniqueId')) {
function generateUniqueId(): string
{
return time() . rand(10000, 99999);
}
}
if(!function_exists('getClientIpAddress')) {
function getClientIpAddress(): string
{
$ipaddress = '';
if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if (isset($_SERVER['HTTP_X_FORWARDED']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if (isset($_SERVER['HTTP_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if (isset($_SERVER['HTTP_FORWARDED']))
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if (isset($_SERVER['REMOTE_ADDR']))
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
if (strlen($ipaddress) > 45) {
$ipaddress = substr($ipaddress, 0, 45);
}
return $ipaddress;
}
}
if(!function_exists('setUserId')) {
function setUserId($id){
setContainerValue('user_id',$id);
}
}
if(!function_exists('setSecurityKey')) {
function setSecurityKey($value){
setContainerValue('security_key',$value);
}
}
if(!function_exists('getSecurityKey')) {
function getSecurityKey(){
if(auth()->check()){
return customEncrypt(auth()->id());
}
return getContainerValue('security_key');
}
}
if(!function_exists('setContainerValue')) {
function setContainerValue($key,$value){
\App\Services\CustomContainer::setContainer($key, $value);
}
}
if(!function_exists('getContainerValue')) {
function getContainerValue($key){
return \App\Services\CustomContainer::getContainer($key);
}
}
if(!function_exists('getUserId')) {
function getUserId(){
return \App\Services\CustomContainer::getContainer('user_id');
}
}
if(!function_exists('getAvailableWave')) {
function getAvailableWave(){
return session('available_wave');
}
}
if(!function_exists('setAvailableWave')) {
function setAvailableWave($wave){
return session('available_wave',$wave);
}
}
if(!function_exists('customEncrypt')) {
function customEncrypt($string){
return (new \App\Services\OpenSSLCryptoClass())->encrypt_decrypt('encrypt',$string);
}
}
if(!function_exists('customDecrypt')) {
function customDecrypt($string){
return (new \App\Services\OpenSSLCryptoClass())->encrypt_decrypt('decrypt',$string);
}
}
if(!function_exists('getCurrentDate')) {
function getCurrentDate($format = 'Y-m-d')
{
$dt = \Carbon\Carbon::now();
return $dt->format($format);
}
}
if(!function_exists('getCurrentDateTime')) {
function getCurrentDateTime($format = 'Y-m-d H:i:s')
{
$dt = \Carbon\Carbon::now();
return $dt->format($format);
}
}
if(!function_exists('getStringToDate')) {
function getStringToDate($stringDate,$format = 'Y-m-d')
{
$date=strtotime($stringDate);
return date($format, $date);
}
}
if(!function_exists('getStringToDateTime')) {
function getStringToDateTime($stringDate,$format = 'Y-m-d H:i:s')
{
$date=strtotime($stringDate);
return date($format, $date);
}
}
if(!function_exists('setSession')) {
function setSession($key,$value)
{
return session()->put($key,$value);
}
}
if(!function_exists('getSession')) {
function getSession($key)
{
return session()->get($key);
}
}
if(!function_exists('getDateDifference')) {
// compare with current date time
function getDateDifference($date,$type = 'day')
{
if($type == 'day'){
return \Carbon\Carbon::now()->diffInDays($date);
}else if($type == 'min'){
return \Carbon\Carbon::now()->diffInMinutes($date);
}else if($type == 'year'){
return \Carbon\Carbon::now()->diffInYears($date);
}
}
}
if(!function_exists('getDateAfterSpicificDay')) {
// compare with current date time
function getDateAfterSpicificDay($date,$interval,$format = 'Y-m-d H:i:s')
{
$interval_data = $interval.' days';
return date($format,strtotime($interval_data, strtotime($date)));
}
}
if(!function_exists('unSetSession')) {
function unSetSession($key)
{
return session()->forget($key);
}
}
if(!function_exists('getWaveList')) {
function getWaveList($key)
{
return session()->forget($key);
}
}
if(!function_exists('isEmployee')) {
function isEmployee()
{
return auth()->user()->user_type == 2;
}
}
if(!function_exists('isAdmin')) {
function isAdmin()
{
return auth()->user()->user_type == 1;
}
}
if(!function_exists('isSupport')) {
function isSupport()
{
return auth()->user()->email == "cz_support@gmail.com";
}
}
if(!function_exists('isClient')) {
function isClient()
{
return auth()->user()->user_type == 0;
}
}
if(!function_exists('setCache')) {
function setCache($key,$value)
{
return cache()->put($key,$value);
}
}
if(!function_exists('getCache')) {
function getCache($key)
{
return cache()->get($key) ?? null;
}
}
if(!function_exists('unsetCache')) {
function unsetCache($key)
{
return cache()->forget($key);
}
}
if(!function_exists('getSection')) {
function getSection()
{
return config('constant.SECTION_NAME')??[];
}
}
if(!function_exists('getSectionById')) {
function getSectionById($id)
{
return config('constant.SECTION_NAME')[$id] ?? null;
}
}
if(!function_exists('getSectionIdByKey')) {
function getSectionIdByKey($key)
{
return config('constant.SECTION_IDS.'.$key) ?? null;
}
}
if(!function_exists('setCookies')) {
function setCookies($key,$value)
{
setcookie(
$key,
$value,
time() + (10 * 365 * 24 * 60 * 60)
);
return $value;
}
}
if(!function_exists('getCookie')) {
function getCookie($key)
{
$c_key = $key;
// return \Cookie::get($key);
// return request()->cookie($key);
return $_COOKIE[$c_key];
}
}
if(!function_exists('unsetCookie')) {
function unsetCookie($key)
{
return Cookie::forget($key);
}
}
if(!function_exists('cookieExitOrNot')) {
function cookieExitOrNot($key)
{
return Cookie::has($key);
}
}
if(!function_exists('isClientSubscription')) {
function isClientSubscription()
{
return auth()->user()->subscription_status == config('constant.SUBSCRIPTION_STATUS.SUBSCRIBED');
}
}
if(!function_exists('decisionFromClientWave')) {
function decisionFromClientWave()
{
$current_wave = auth()->user()->wave;
$day_interval = config('constant.PACKAGE_INTERVAL_DAY');
$decisionWaves = [];
for($i = 1 ; $i<= $current_wave; $i++) {
$day_start = ($day_interval * ($i - 1));
$start = 1;
$end = $day_interval;
if ($i > 1) {
$start = $day_start + ($i - 1);
$end = $start + $day_interval;
}
$wave_text = "I want to use a Wave $i attack for this content box's items ( Day $start - $end )";
$wave_value = "w$i";
$decisionWaves[$i]['key'] = $wave_value;
$decisionWaves[$i]['text'] = $wave_text;
}
return $decisionWaves;
// return ['wave_text'=>$wave_text,'wave_value'=>$wave_value];
}
}
if(!function_exists('creditCardNumberMasking')) {
function creditCardNumberMasking($number, $maskingCharacter = '*')
{
return str_repeat($maskingCharacter, strlen($number) - 4) . substr($number, -4);
}
}
if(!function_exists('sizeFilter')){
function sizeFilter( $size )
{
$sizes = ['KB', 'MB', 'GB'];
$count=0;
if ($size >= 1024) {
while ($size >= 1024) {
$size = round($size / 1024);
$count++;
}
}
return $size .$sizes[$count];
}
}
if(!function_exists('getPaymentStatus')){
function getPaymentStatus( $status)
{
$result = '<span class="text-danger"> failed </span>';
if (!empty($status)) {
$result = '<span class="text-success"> success </span>';
}
return $result;
}
}
if(!function_exists('getAccountStatus')){
function getAccountStatus($subscription_status, $status)
{
$result = '<span class="text-danger"> Inactive </span>';
if ($status == config('constant.ACCOUNT_STATUS.Active')) {
$result = '<span class="text-success"> Active </span>';
if($subscription_status == config('constant.SUBSCRIPTION_STATUS.CANCEL_ACCOUNT')){
$result = '<span class="text-danger"> Canceled </span>';
}
}
return $result;
}
}
if(!function_exists('getNextImportDate')) {
function getNextImportDate()
{
$date = getCurrentDate('m/d/Y');
if(Auth::user()->last_import_date!=null) {
$date = getDateAfterSpicificDay(Auth::user()->last_import_date, config('constant.PACKAGE_INTERVAL_DAY'), 'm/d/Y');
}
return $date;
}
}
if(!function_exists('isPermitted')) {
function isPermitted()
{
$result = false;
$current_route_name = request()->route()->getName();
$get_route_list = getSession('permissions_route_list');
if(in_array($current_route_name,$get_route_list)){
$result = true;
}
return $result;
}
}
if(!function_exists('isShowContent')) {
function isShowContent($route_name)
{
$result = false;
$get_route_list = getSession('permissions_route_list');
if(isEmployee()) {
if (in_array($route_name, $get_route_list)) {
$result = true;
}
}else{
$result = true;
}
return $result;
}
}
if(!function_exists('addDays')) {
function addDays($day,$date,$format = 'Y-m-d H:i:s'){
return \Carbon\Carbon::parse($date)->addDays($day)->format($format);
}
}
if(!function_exists('clientWaves')) {
function clientWaves($current_wave=null)
{
$waves = [];
if(empty($current_wave)) {
$current_wave = auth()->user()->wave;
}
for($i=1 ; $i<= $current_wave ; $i++)
{
$waves[$i]['key'] = $i;
$waves[$i]['text'] = 'Wave '. $i;
}
return $waves;
}
}
if(!function_exists('imageFileRotate')){
function imageFileRotate($imageFile){
$image = file_get_contents($imageFile);
$exif = [];
try {
$exif = exif_read_data($imageFile);
if(!empty($exif['Orientation']) && matchExifOrientation($exif['Orientation']) ) {
$format = $exif['MimeType'];
$rotated = '';
$temp = '';
$photo = $imageFile;
if( $format == 'image/jpeg' || $format == 'image/jpg') {
$temp = imagecreatefromjpeg($photo);
} elseif( $format == 'image/png' ) {
$temp = imagecreatefrompng($photo);
} elseif( $format == 'image/gif' ) {
$temp = imagecreatefromgif($photo);
}
switch($exif['Orientation']) {
case 8:
$rotated = imagerotate($temp,90,0);
break;
case 3:
$rotated = imagerotate($temp,180,0);
break;
case 6:
$rotated = imagerotate($temp,-90,0);
break;
}
$extension = $photo->getClientOriginalExtension();
$flieNametoStore = time() . "___" . explode('.', $photo->getClientOriginalName())[0] . '.' . $extension;
ob_start();
imagejpeg($rotated);
$image = ob_get_contents();
ob_clean();
}
}catch (Exception $ex){
}
return $image;
}
}
if(!function_exists('matchExifOrientation')) {
function matchExifOrientation($orientation)
{
return match ($orientation){
3,6,8 => true,
default => false
};
}
}
if(!function_exists('getCreditReportPersonalInfo')) {
function getCreditReportPersonalInfo($data,$key)
{
$result = '';
if($key == 'NAME') {
$result = $data['Name']['first'] . ' ' . $data['Name']['middle'] . ' ' . $data['Name']['last'] . ' ';
}
elseif($key == 'ALSO_KNOWN_AS') {
$result = $data['Name']['first'] . ' ' . $data['Name']['middle'] . ' ' . $data['Name']['last'] . ' ';
}
elseif($key == 'CREDIT_REPORT_DATE') {
$result = getStringToDateTime($data['Source']['InquiryDate'],'m/d/Y') ;
}
elseif($key == 'DATE_OF_BIRTH') {
$result = $data['BirthDate']['year'] . ' ';
}
elseif($key == 'CURRENT_ADDRESS' || $key == 'PREVIOUS_ADDRESS') {
if($data['Source']['Bureau']['symbol'] == 'TUC'){
$result = $data['CreditAddress']['houseNumber'].' '.$data['CreditAddress']['streetName'].' ';
}else{
$result = $data['CreditAddress']['unparsedStreet'].' ' ;
}
$result =$result.$data['CreditAddress']['city'] . ', ' . $data['CreditAddress']['stateCode'].' ' . $data['CreditAddress']['postalCode'] . ' ';
if (isset($data['dateUpdated'])) {
$result = $result. "Date Updated: " . getStringToDateTime($data['dateUpdated'],'m/Y') ;
}
} elseif($key == 'EMPLOYER') {
$result = $data['name'] . ' ';
if (isset($data['dateUpdated'])) {
$result .= "Date Updated: " . getStringToDateTime($data['dateUpdated'],'m/Y');
}
}
return $result;
}
}
if(!function_exists('getCreditReportValuesExistOrNot')) {
function getCreditReportValuesExistOrNot($data,$key)
{
return (empty($data['data']['TransUnion']) && empty($data['data']['Experian']) && empty($data['data']['Equifax']) && $key != 'ALSO_KNOWN_AS');
}
}
if(!function_exists('getCreditReportAccountHistoryInfo')) {
function getCreditReportAccountHistoryInfo($data,$key)
{
$result = '';
if($key == 'ACCOUNT') {
$result = isset($data['accountNumber'])? accountNumberMasking($data['accountNumber']):'--';
}
elseif($key == 'HIGH_BALANCE') {
$result = isset($data['highBalance'])? amountFormatter($data['highBalance']) : '--';
}
elseif($key == 'LAST_VERIFIED') {
$result = isset($data['dateVerified'])? getStringToDateTime($data['dateVerified'],'m/d/Y') :'--';
}
elseif($key == 'DATE_OF_LAST_ACTIVITY') {
$result = isset($data['dateAccountStatus'])? getStringToDateTime($data['dateAccountStatus'],'m/d/Y') :'--';
}
elseif($key == 'DATE_REPORTED') {
$result = isset($data['dateReported'])? getStringToDateTime($data['dateReported'],'m/d/Y') :'--';
}
elseif($key == 'DATE_OPENED') {
$result = isset($data['dateOpened'])? getStringToDateTime($data['dateOpened'],'m/d/Y') :'--';
}
elseif($key == 'BALANCE_OWED') {
$result = isset($data['currentBalance'])?amountFormatter($data['currentBalance']) : '--';
}
elseif($key == 'CLOSED_DATE') {
$result = isset($data['dateClosed'])? getStringToDateTime($data['dateClosed'],'m/d/Y') :'--';
}
elseif($key == 'ACCOUNT_RATING') {
$result = $data['AccountCondition']['description']??'--';
}
elseif($key == 'ACCOUNT_DESCRIPTION') {
$result = $data['AccountDesignator']['description']??'--';
}
elseif($key == 'DISPUTE_STATUS') {
$result = $data['DisputeFlag']['description']??'--';
}
elseif($key == 'CREDITOR_TYPE') {
$result = $data['IndustryCode']['description']??'--';
}
elseif($key == 'ACCOUNT_STATUS') {
$result = $data['OpenClosed']['description']??'--';
}
elseif($key == 'PAYMENT_STATUS') {
$result = $data['PayStatus']['description']??'--';
}
elseif($key == 'CREDITOR_REMARKS') {
$remark_data = '--';
if(!empty($data['Remark'])) {
$remark_data = '';
if(isset($data['Remark']['RemarkCode'])){
$data['Remark'] = [ $data['Remark'] ];
}
foreach ($data['Remark'] as $remark) {
$remark_data = $remark_data . $remark['RemarkCode']['description'] .'<br>';
}
}
echo $remark_data;
}elseif($key == 'ORIGINAL_CREDITOR') {
$result = $data['CollectionTrade']['originalCreditor']??'--';
}
elseif($key == 'PAYMENT_AMOUNT') {
$result = isset($data['GrantedTrade']['monthlyPayment'])?amountFormatter($data['GrantedTrade']['monthlyPayment']):'--';
}
elseif($key == 'LAST_PAYMENT') {
$result = isset($data['GrantedTrade']['dateLastPayment'])? getStringToDateTime($data['GrantedTrade']['dateLastPayment'],'m/d/Y') :'--';
}
elseif($key == 'TERM_LENGTH') {
$result = !empty($data['GrantedTrade']['termMonths'])? $data['GrantedTrade']['termMonths'].' Month(s)' :'--';
}
elseif($key == 'PAST_DUE_AMOUNT') {
$result = isset($data['GrantedTrade']['amountPastDue'])?amountFormatter($data['GrantedTrade']['amountPastDue']):'--';
}
elseif($key == 'ACCOUNT_TYPE') {
$result = !empty($data['GrantedTrade']['AccountType']['description'])? $data['GrantedTrade']['AccountType']['description'] :'--';
}
elseif($key == 'PAYMENT_FREQUENCY') {
$result = !empty($data['GrantedTrade']['PaymentFrequency']['description'])? $data['GrantedTrade']['PaymentFrequency']['description'] : '--';
}
elseif($key == 'CREDIT_LIMIT') {
$result = isset($data['GrantedTrade']['CreditLimit'])? amountFormatter($data['GrantedTrade']['CreditLimit']) :'--';
}
return $result;
}
}
if(!function_exists('accountNumberMasking')) {
function accountNumberMasking($number, $maskingCharacter = '*')
{
return substr($number, 0, -4).str_repeat($maskingCharacter,4) ;
}
}
if(!function_exists('amountFormatter')) {
function amountFormatter($number,$currency='$')
{
$number = (float)$number;
return $currency.rtrim(rtrim(number_format($number, 2, '.', ','),'0'),'.');
}
}
if(!function_exists('getMonthlyPayStatus')) {
function getMonthlyPayStatus($monthlyPayStatus)
{
$status = '';
$url_first = 'https://www.smartcredit.com/resources/images/shared/tui/creditreport/tradeline-';
$url_last = '.gif';
$url_middle = '';
$pay_status = $monthlyPayStatus['status'];
if($pay_status == 'C'){
$status = 'OK';
$url_middle = 'ok';
}elseif ($pay_status == 'U'){
$status = 'unknown';
$url_middle = 'unknown';
}elseif ($pay_status == '5' || $pay_status == '4' || $pay_status == '3' || $pay_status == '2' || $pay_status == '1'){
$month = 30;
$status = ($pay_status*$month) .' days late';
$url_middle = ($pay_status*$month);
}elseif ($pay_status == '9' ){
$status = 'Collection Chargeoff';
$url_middle = 'co';
}
return ['status'=>$status,'url'=>$url_first.$url_middle.$url_last];
}
}
if(!function_exists('getPayStatusHistory')) {
function getPayStatusHistory($monthlyPayStatus)
{
$month = '';
$month = getStringToDateTime($monthlyPayStatus['date'],'M');
$months = (getStringToDateTime($monthlyPayStatus['date'],'m') == '01');
$year = getStringToDateTime($monthlyPayStatus['date'],'y');
$year_split = str_split($year);
$url_first = 'https://www.smartcredit.com/resources/images/shared/tui/creditreport/monthsandyears/';
$url_last = '-gray.gif';
$url1 = $url_first.$year_split[0].$url_last;
$url2 = $url_first.$year_split[1].$url_last;
$url3 = $url_first.strtolower($month).$url_last;
return ['isViewed'=>$months,'month'=>$month,'year_split_0'=>$year_split[0],'year_split_1'=>$year_split[1],'url1'=>$url1,'url2'=>$url2,'url3'=>$url3];
}
}
if(!function_exists('isRowVisibleInCreditReportHtml')) {
function isRowVisibleInCreditReportHtml($keys,$sub_account_history_data)
{
return (($keys == 'ORIGINAL_CREDITOR' && $sub_account_history_data['accountTypeSymbol']!='Y')||(($keys == 'PAYMENT_AMOUNT' || $keys == 'TERM_LENGTH' || $keys == 'PAYMENT_FREQUENCY' || $keys == 'CREDIT_LIMIT') && $sub_account_history_data['accountTypeSymbol']=='Y'));
}
}
if(!function_exists('getConsumerStatement')) {
function getConsumerStatement($data)
{
$result = 'NONE REPORTED';
if(!empty($data)){
$result = '';
foreach($data as $equifax){
$result = $result.$equifax['statement'] ;
}
}
return $result;
}
}
if(!function_exists('getModelDataMasking')) {
function getModelDataMasking($inputData)
{
if (!empty($inputData['password'])) {
$inputData['password'] = "*********";
}
if (!empty($inputData['full_ssn'])) {
$inputData['full_ssn'] = "*********";
}
if (!empty($inputData['security_key'])) {
$inputData['security_key'] = "*********";
}
if (!empty($inputData['card_number'])) {
$inputData['card_number'] = creditCardNumberMasking($inputData['card_number']);
}
if(!empty($inputData['ssn']))
{
$inputData['ssn']="****";
}
if(!empty($inputData['html_content']))
{
$inputData['html_content']="*********************************";
}
return $inputData;
}
}
if(!function_exists('getEnableImportReset')) {
function getEnableImportReset($data)
{
$result = false;
// if ($data['status'] == 1 && $data['subscription_status'] == 1 && $data['is_import'] == 0){
// $result = true;
// }
if ($data['status'] == 1 && $data['subscription_status'] == 1){
$result = true;
}
return $result;
}
}
if(!function_exists('getSupportIsAdmin')) {
function getSupportIsAdmin($obj)
{
return (($obj->user_type == config('constant.USER_TYPE.ADMIN') && auth()->user()->user_type == config('constant.USER_TYPE.EMPLOYEE'))||
(auth()->user()->user_type == config('constant.USER_TYPE.ADMIN') && $obj->user_type == config('constant.USER_TYPE.EMPLOYEE'))||
(auth()->user()->user_type == config('constant.USER_TYPE.ADMIN') && $obj->user_type == config('constant.USER_TYPE.ADMIN')));
}
}
if(!function_exists('removeAnySpaces')) {
function removeAnySpaces($data,$replaceBy)
{
return preg_replace('/\s+/', $replaceBy, trim($data));
}
}
if(!function_exists('getUserImagesAndDoc')) {
function getUserImagesAndDoc($id)
{
$uploadMediaObj = app(\App\Models\Uploadmedia::class);
$upload_medias = $uploadMediaObj->getProfilePicByUserId($id);
$user_image = '';
$profile_image = '';
if($upload_medias->isNotEmpty()) {
$profile_image = $upload_medias->where('image_type_id',9)->pluck('image_path')->first();
$user_image = config('constant.UPLOAD_MEDIA_PATH') . DIRECTORY_SEPARATOR . $id . DIRECTORY_SEPARATOR . $profile_image;
}
setSession('user_image',$user_image);
setSession('profile_image',$profile_image);
}
}
if(!function_exists('isClientFirstTimeLogin')) {
function isClientFirstTimeLogin()
{
return getSession('is_first_time_login');
}
}