mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
91 lines
2.4 KiB
PHP
91 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\General;
|
|
|
|
use Illuminate\Http\Resources\Json\ResourceCollection;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Str;
|
|
use NumberToWords\NumberToWords;
|
|
|
|
class Helper
|
|
{
|
|
|
|
/**
|
|
* @param string $methodName
|
|
* @return string
|
|
*/
|
|
static function getPropertyName(string $methodName){
|
|
return Str::snake(str_replace('get', '', $methodName));
|
|
}
|
|
|
|
/**
|
|
* @param string $className
|
|
* @return array
|
|
*/
|
|
static function getClassMethodsArray(string $className){
|
|
return array_slice(get_class_methods($className), 1);
|
|
}
|
|
|
|
/**
|
|
* @param $log
|
|
* @return array
|
|
*/
|
|
static function debugLogger($log){
|
|
if($log && isset($log['message'])){
|
|
$message = $log['message'];
|
|
$substring = 'No data were found';
|
|
if (isset($message)) {
|
|
if (strpos($message, $substring) !== false) {
|
|
// Log::info('Message exist');
|
|
} else {
|
|
Log::info($log['message']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param null|string $param
|
|
* @return array
|
|
*/
|
|
static function deserializeFilters($param): array {
|
|
if(gettype($param) == "array"){
|
|
$json = implode(',', $param);
|
|
}
|
|
else{
|
|
$json = $param;
|
|
}
|
|
return $json !== null ? collect(json_decode($json))->toArray() : [];
|
|
}
|
|
|
|
/**
|
|
* @param ResourceCollection $collection
|
|
* @return array
|
|
*/
|
|
static function collectionResponse(ResourceCollection $collection){
|
|
return json_decode($collection->response()->getContent(), true);
|
|
}
|
|
|
|
/**
|
|
* Convert a given number to words based on the specified locale.
|
|
*
|
|
* @param int|float $number
|
|
* @param string $locale The locale to use for conversion (default is 'en').
|
|
* @return string
|
|
*/
|
|
static function convert($number, $locale = 'en')
|
|
{
|
|
$numberToWords = new NumberToWords();
|
|
$numberTransformer = $numberToWords->getNumberTransformer($locale);
|
|
|
|
$number = number_format((float)$number, 2, '.', '');
|
|
[$ringgit, $cents] = explode('.', $number);
|
|
|
|
$ringgitWords = $numberTransformer->toWords((int)$ringgit);
|
|
$centsWords = $numberTransformer->toWords((int)$cents);
|
|
|
|
return strtoupper('ringgit ' . $ringgitWords . ' and ' . $centsWords . ' cents only');
|
|
}
|
|
|
|
}
|