0

I have created a custom invoice in that invoice total amountfield is there.Now it is coming in numbers.How to convert that into Words.

//write onto XL

$totalWeight = $weight * $qtyOrdered;
    $vat55 = $order->getTotalVatOne();
                        $totalAmount = $order->getTotalAmount();
                        $totalBasePrice = $order->getTotalBasePrice();
                        $poNumber = $order->getpoNumber();
    //echo "vat55" . strval($vat55);
    //print_r($vat55);
    $vat145 = $order->getTotalVatTwo();
    //echo "vat145". $vat145;
    $objPHPExcel->setActiveSheetIndex(0)
    ->setCellValue('A32', $index)
    ->setCellValue('B32', $productName)
    ->setCellValue('E32', round($weight) .' Kg x '.round($qtyOrdered))
    ->setCellValue('F32', 'Kg')
    ->setCellValue('H32', round($totalWeight))
    ->setCellValue('J32', $unitBasePrice)
    ->setCellValue('I53', 'Sub Total')
    ->setCellValue('I54', 'VAT 5.5%')
    ->setCellValue('K54', $vat55)
                        ->setCellValue('K53', $totalBasePrice)
                        ->setCellValue('K58', $totalAmount)
                        ->setCellValue('K32', $totalBasePrice)
                        ->setCellValue('D51', 'po:')
                        ->setCellValue('D52',$poNumber)
    ->setCellValue('I55', 'VAT 14.5%')
    ->setCellValue('K55', $vat145)
    ->setCellValue('I49','C.Ex.  12.50 %');
    $centralExcise = $order->getTotalCentralExcise();

1 Answer 1

0

Use this function as helper in magento, you should change the variable value to English because it still in bahasa ( Indonesia ). Good Luck !

    function terbilang($number) {

        $hyphen      = ' ';
        $conjunction = ' ';
        $separator   = ' ';
        $negative    = 'negative ';
        $decimal     = ' point ';
        $dictionary  = array(
            0                   => 'nol',
            1                   => 'satu',
            2                   => 'dua',
            3                   => 'tiga',
            4                   => 'empat',
            5                   => 'lima',
            6                   => 'enam',
            7                   => 'tujuh',
            8                   => 'delapan',
            9                   => 'sembilan',
            10                  => 'sepuluh',
            11                  => 'sebelas',
            12                  => 'dua belas',
            13                  => 'tiga belas',
            14                  => 'empat belas',
            15                  => 'lima belas',
            16                  => 'enam belas',
            17                  => 'tujuh belas',
            18                  => 'delapan belas',
            19                  => 'sembilan belas',
            20                  => 'dua puluh',
            30                  => 'tiga puluh',
            40                  => 'empat puluh',
            50                  => 'lima puluh',
            60                  => 'enam puluh',
            70                  => 'tujuh puluh',
            80                  => 'delapan puluh',
            90                  => 'sembilan puluh',
            100                 => 'ratus',
            1000                => 'ribu',
            1000000             => 'juta',
            1000000000          => 'miliar',
            1000000000000       => 'triliun'
            /*
            1000000000000000    => 'quadrillion',
            1000000000000000000 => 'quintillion'
            */
        );

        if (!is_numeric($number)) {
            return false;
        }

        if (($number >= 0 && (int) $number < 0) || (int) $number < 0 - PHP_INT_MAX) {
            // overflow
            trigger_error(
                'terbilang only accepts numbers between -' . PHP_INT_MAX . ' and ' . PHP_INT_MAX,
                E_USER_WARNING
            );
            return false;
        }

        if ($number < 0) {
            return $negative . terbilang(abs($number));
        }

        $string = $fraction = null;

        if (strpos($number, '.') !== false) {
            list($number, $fraction) = explode('.', $number);
        }

        switch (true) {
            case $number < 21:
                $string = $dictionary[$number];
                break;
            case $number < 100:
                $tens   = ((int) ($number / 10)) * 10;
                $units  = $number % 10;
                $string = $dictionary[$tens];
                if ($units) {
                    $string .= $hyphen . $dictionary[$units];
                }
                break;
            case $number < 1000:
                $hundreds  = $number / 100;
                $remainder = $number % 100;
                $string = $dictionary[$hundreds] . ' ' . $dictionary[100];
                if ($remainder) {
                    $string .= $conjunction . terbilang($remainder);
                }
                break;
            default:
                $baseUnit = pow(1000, floor(log($number, 1000)));
                $numBaseUnits = (int) ($number / $baseUnit);
                $remainder = $number % $baseUnit;
                $string = terbilang($numBaseUnits) . ' ' . $dictionary[$baseUnit];
                if ($remainder) {
                    $string .= $remainder < 100 ? $conjunction : $separator;
                    $string .= terbilang($remainder);
                }
                break;
        }

        if (null !== $fraction && is_numeric($fraction)) {
            $string .= $decimal;
            $words = array();
            foreach (str_split((string) $fraction) as $number) {
                $words[] = $dictionary[$number];
            }
            $string .= implode(' ', $words);
        }

        return $string;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.