mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-24 15:04:32 +00:00
128 lines
3.0 KiB
PHP
128 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\General;
|
|
|
|
use Illuminate\Http\Resources\Json\ResourceCollection;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
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
|
|
*/
|
|
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 ResourceCollection $collection
|
|
* @return array
|
|
*/
|
|
static function collectionResponse(ResourceCollection $collection){
|
|
return json_decode($collection->response()->getContent(), true);
|
|
}
|
|
|
|
/**
|
|
* @param null|string $json
|
|
* @return array
|
|
*/
|
|
static function deserializeFilters(?string $json): array {
|
|
return $json !== null ? collect(json_decode($json))->toArray() : [];
|
|
}
|
|
|
|
public static function getLHDNStateCodeByName($name)
|
|
{
|
|
$path = resource_path('data/lhdn/StateCodes.json');
|
|
|
|
if (!file_exists($path)) {
|
|
return null;
|
|
}
|
|
|
|
$json = file_get_contents($path);
|
|
$data = json_decode($json, true);
|
|
|
|
if (!is_array($data)) {
|
|
return null;
|
|
}
|
|
|
|
$name = strtolower(trim($name));
|
|
|
|
// Step 1: Try exact match
|
|
foreach ($data as $item) {
|
|
if (
|
|
isset($item['State']) &&
|
|
strtolower(trim($item['State'])) === $name
|
|
) {
|
|
return $item['Code'] ?? null;
|
|
}
|
|
}
|
|
|
|
// Step 2: Try partial match
|
|
foreach ($data as $item) {
|
|
if (
|
|
isset($item['State']) &&
|
|
str_contains(strtolower($item['State']), $name)
|
|
) {
|
|
return $item['Code'] ?? null;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public static function getLHDNMsicDescriptionByCode($code)
|
|
{
|
|
$path = resource_path('data/lhdn/MSICSubCategoryCodes.json');
|
|
|
|
if (!file_exists($path)) {
|
|
return null;
|
|
}
|
|
|
|
$json = file_get_contents($path);
|
|
$data = json_decode($json, true);
|
|
|
|
if (!is_array($data)) {
|
|
return null;
|
|
}
|
|
|
|
foreach ($data as $item) {
|
|
if (
|
|
isset($item['Code']) &&
|
|
$item['Code'] === $code
|
|
) {
|
|
return $item['Description'] ?? null;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|