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 malaysia ' . $ringgitWords . ' and ' . $centsWords . ' cents only'); } 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; } }