<?php
 namespace App\Utils\DigitsToLetters; abstract class KwnAbstract extends GeneralAbstract { protected $kwnLang = null; protected $minusWord = '-'; protected $andWord = ','; public function getText() { if (!$this->kwnLang) { throw new \Exception('You must set the kwnLang attribute.'); } $numToWordsObj = new \NumberToWords\NumberToWords(); $numTransformerObj = $numToWordsObj->getNumberTransformer($this->kwnLang); $valueComponents = $this->getNumberComponents(); $integerText = $numTransformerObj->toWords($valueComponents['integer']); $decimalsText = $valueComponents['decimals'] ? $numTransformerObj->toWords($valueComponents['decimals']) : ''; $signText = ($this->value<=0) ? $this->minusWord.$this->separator : ''; if (!$this->currencyName) { $text = $signText . $integerText; if ($valueComponents['decimals']) { $text .= $this->separator . '.' . $this->separator . $decimalsText; } } else { if ($valueComponents['decimals']) { if (!$this->currencySubdivision) { $text = $signText . $integerText . $this->separator . '.' . $this->separator . $decimalsText . $this->separator . $this->currencyName; } else { $text = $signText . $integerText . $this->separator . $this->currencyName . $this->separator . $this->andWord . $this->separator . $decimalsText . $this->separator . $this->currencySubdivision; } } else { $text = $signText . $integerText . $this->separator . $this->currencyName; } } return $text; } protected function getNumberComponents() { $intVal = (Int)$this->value; if ($this->currencyName) { $decimals = \App\Config\CurrencyDecimals::getCurrencyDecimals($this->currencyName); } else { $CFG = \Engine\Loader_Cfg::getInstance()->getGlobal(); $decimals = $CFG['localization']['maxDecimalsOnPrices']; } $floatVal = abs( round (($this->value - $intVal)*(10**$decimals)) ); return [ 'integer' => abs($intVal), 'decimals' => $floatVal, ]; } } 