Wednesday, December 31, 2014

Numerals to Txt as only in output ax 2012 Global class

// Numerals to Txt as only in output ax 2012 Global class

static TempStr numeralsToTxtOnly(real _num)
{
    int     numOfPennies = (decRound(frac(_num), 2) * 100) mod 100;
    real    test         = _num - frac(_num);

    int64   numOfTenths;
    str 20  ones[19], tenths[9], hundreds, thousands, millions, billions, trillions;

    int64   temp;
    str 200 returntxt;
    int64   testLoc;

    real modOperator(real a1, real a2)
    {
    int tmpi;
    real tmp1, tmp2;
    tmp1 = a1 / a2;
    tmpi = real2int(tmp1);
    tmp2 = tmpi;
    return (tmp1 - tmp2)*a2;
    }

    real checkPower(real  _test, int64 _power)
    {
        int64   numOfPower;

        if (_test >= _power)
        {
            testLoc = real2double(_test);
            numOfPower = testLoc div _power;
            if (numOfPower >= 100)
            {
                temp = numOfPower div 100;
                returntxt = returntxt + ' ' + ones[temp] + ' ' + hundreds;
                numOfPower = numOfPower mod 100;
            }
            if (numOfPower >= 20)
            {
                temp = numOfPower div 10;
                returntxt = returntxt + ' ' + tenths[temp];
                numOfPower = numOfPower mod 10;
            }
            if (numOfPower >= 1)
            {
                returntxt = returntxt + ' ' + ones[numOfPower];
                numOfPower = numOfPower mod 10;
            }
            switch(_power)
            {
                case 1000000000000 :
                    returntxt = returntxt + ' ' + trillions;
                    _test = modOperator(_test, 1000000000000.00);
                    break;
                case 1000000000 :
                    returntxt = returntxt + ' ' + billions;
                    _test = modOperator(_test, 1000000000);
                    break;
                case 1000000 :
                    returntxt = returntxt + ' ' + millions;
                    _test = modOperator(_test, 1000000);
                    break;
                case 1000 :
                    returntxt = returntxt + ' ' + thousands;
                    _test = modOperator(_test, 1000);
                    break;
                case 100 :
                    returntxt = returntxt + ' ' + hundreds;
                    _test = modOperator(_test, 100);
                    break;
            }
        }
        return _test;
    }

    #Define.text_1('One')
    #Define.text_2('Two')
    #Define.text_3('Three')
    #Define.text_4('Four')
    #Define.text_5('Five')
    #Define.text_6('Six')
    #Define.text_7('Seven')
    #Define.text_8('Eight')
    #Define.text_9('Nine')
    #Define.text_10('Ten')
    #Define.text_11('Eleven')
    #Define.text_12('Twelve')
    #Define.text_13('Thirteen')
    #Define.text_14('Fourteen')
    #Define.text_15('Fifteen')
    #Define.text_16('Sixteen')
    #Define.text_17('Seventeen')
    #Define.text_18('Eighteen')
    #Define.text_19('Nineteen')
    #Define.text_20('Twenty')
    #Define.text_30('Thirty')
    #Define.text_40('Forty')
    #Define.text_50('Fifty')
    #Define.text_60('Sixty')
    #Define.text_70('Seventy')
    #Define.text_80('Eighty')
    #Define.text_90('Ninety')
    #Define.text_100('Hundred')
    #Define.text_1000('Thousand')
    #Define.text_1000000('Million')
    #Define.text_1000000000('Billion')
    #Define.text_1000000000000('Trillion')
    #Define.text_and('and')

    ones[1] = #text_1;
    ones[2] = #text_2;
    ones[3] = #text_3;
    ones[4] = #text_4;
    ones[5] = #text_5;
    ones[6] = #text_6;
    ones[7] = #text_7;
    ones[8] = #text_8;
    ones[9] = #text_9;
    ones[10] = #text_10;
    ones[11] = #text_11;
    ones[12] = #text_12;
    ones[13] = #text_13;
    ones[14] = #text_14;
    ones[15] = #text_15;
    ones[16] = #text_16;
    ones[17] = #text_17;
    ones[18] = #text_18;
    ones[19] = #text_19;

    tenths[1] = 'Not used';
    tenths[2] = #text_20;
    tenths[3] = #text_30;
    tenths[4] = #text_40;
    tenths[5] = #text_50;
    tenths[6] = #text_60;
    tenths[7] = #text_70;
    tenths[8] = #text_80;
    tenths[9] = #text_90;

    hundreds    = #text_100;
    thousands   = #text_1000;
    millions    = #text_1000000;
    billions    = #text_1000000000;
    trillions   = #text_1000000000000;


    test = checkPower(test, 1000000000000);
    test = checkPower(test, 1000000000);
    test = checkPower(test, 1000000);
    test = checkPower(test, 1000);
    test = checkPower(test, 100);

    if (test >= 20)
    {
        testLoc = real2double(test);
        numOfTenths = testLoc div 10;
        returntxt = returntxt + ' ' + tenths[numofTenths];
        numOfTenths = numOfTenths mod 10;
        test = real2int(test) mod 10;
    }
    if (test >= 1)
    {
        numOfTenths = real2int(test);
        returntxt = returntxt + ' ' + ones[numOfTenths];
    }

    if (numOfPennies)
    {
       // returntxt = '***' + returntxt + ' ' + "@SYS5534" + ' ' + num2str(numOfPennies,0,0,0,0) + '/100';
        returntxt = returntxt + ' ' + "@SYS5534" + ' ' + num2str(numOfPennies,0,0,0,0) + '/100'+ ' Only';
        //returntxt = returntxt + ' ' + #text_and + ' ' + NumtoRupees::numtoRupees(numOfPennies,'SAR');
    }
    else
    {
        returntxt = returntxt + ' Only';// + #text_and + ' ' + '00/100';
        //returntxt = returntxt + ' Only';// + #text_and + ' ' + '00/100';
    }

    return returntxt;
}

No comments:

Post a Comment

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...