Your IP : 216.73.216.124


Current Path : /var/www/html/dyna-crm/components/
Upload File :
Current File : /var/www/html/dyna-crm/components/SharedFunction.php

<?php

namespace app\components;

use Yii;
use yii\base\Component;
use yii\base\InvalidConfigException;

class SharedFunction extends Component {

    public function convertMoneyToText($value) {
        $output = '';
        $arr = explode('.', $value);
        if (!empty($arr[0])) {
            $moneyNo = $arr[0];
            $moneyLen = strlen($moneyNo);
            if ($moneyLen < 3) {
                $output.= Yii::$app->formatter->asSpellout($moneyNo);
            } else {
                $moneyFront = substr_replace($moneyNo, '00', -2, 2);
                $moneyBack = substr($moneyNo, -2);
                $output.=Yii::$app->formatter->asSpellout($moneyFront);
                if ($moneyBack != '00')
                    $output.=' AND ' . Yii::$app->formatter->asSpellout($moneyBack);
            }
        }
        if (!empty($arr[1])) {
            $cents = str_pad($arr[1], 2, "0");
            if ($output != '')
                $output.= ' AND ';
            
            $output.= Yii::$app->formatter->asSpellout($cents) . ' CENTS';
        }
        if (!empty($output))
            $output = '<br>RINGGIT MALAYSIA ' . strtoupper($output . ' ONLY');
        return $output;
    }

}