Friday, November 25, 2011

How to create a New Web Form in Axapta

How to create a new Web Form in Axapta
Step 1:
To create a new web form you need to add the data source in the Data source node of the web form.
(i.e. either use can use the existing table or create a new table in the AOT and use it in the web form data source)
Go to AOT à Web à Web Forms

Create a new form as shown in the above screen shot and name it as per the naming convention.
Step 2:
 Now add the data Source in the data source node of the form(if created new Table add the created table or if using the existing standard ax table add it).
In the Design node of the form, as per required add the Web group or web grid and the fields from the data source as required.


Step 3:
Once the Form is designed add the “Display Web Content” in the below path
AOT à Web à Web Content à Display, as shown in the below screen


Step 4:
Now Go to the EP site and create a web-part page as shown below…




Step 5:
Give the name for the Web part and then click create…

A web-part page with “EPExample.aspx” page will be created.
Then click on the Add Web part page as shown in the screen, a new window with control will be opened. From that window choose the “Web form Web part”.


Step 6:
After adding the” Web form Web part”, go to Modify shared web part ,over there attach the Web Content Display item to the created web part page and click OK as shown in the below screen

Step 7:
Again go back to
AOT à Web à Web Menu Items à URLs
Over there create a new URL and go to properties of that URL and the URL which we created for the Web form web part page in the EP as shown in the screen shot


Step 8:
Once finished with the URL, then right click on the created URL and click the Import Page, so it creates the page definition for it in the following path
AOT à Web à Web Files à Page Definitions àExample

Friday, September 2, 2011

How to pass real value to excel through the Code

Hi...

I just came across that while generating a report data into excel through code, required to pass the real values in the report.
Here is an example which illustrates how to pass the real value into excel by ussing the "Arrays"....

static void realValinArrays(Args _args)
{
    //Declaration of Array type -- real...
    Array             arr = new Array(Types::Real);
    CommaIO      commaIO;
    str                  fileName;
    container        con;
    int                  i;
    ;
   
    fileName    = WinAPI::getTempPath() + "Example" + ".csv";
    commaIO = new CommaIO(fileName,"w");
   
    arr.value(1,19.23); //Inserting the real value 19.23 in array postion 1
    arr.value(2,20.0);  //Inserting the real value 20.0 in array postion 2
   
    for( i = 1; i <= 2; i++)
    {
        con = [arr.value(i)];
        commaIO.write(con);
    }
   
    WinAPI::shellExecute(fileName);
}

Thursday, September 1, 2011

How to move Security Settings from one environment to other environment.

By using the Standard AX functionality of Export/Import function...
Let say that testing -- TestServer and production --- ProdServer.

Now log onto TestServer
1. Go to Administration ---> Setup ---> Security ---> User group permissions
2. Select the User group and Domain which you want to export as shown in the screen shot.

3. Click on the Export button and give the file name and location and Click OK
4. Once it is exported use the file to import into the ProdServer.

Now Log into ProdServer.
1. Go to Administration ---> Setup ---> Security ---> User group permissions
2. Select the User group and Domain for which you want to import the security settings and click the Import button as shown in below.

3. Attach the exported file and click OK, the setting gets imported into the ProdServer.

Sunday, August 28, 2011

Sequence of methods in the FORM level in AX

Hi...

This gives the information of method calls in the form level while
1. Opening the Form.
2. Creating/Updating/Deleting the record in the Form.
3. Closing the Form.
Sequence of Methods calls while opening the Form
Form --- init ()
Form --- Datasource --- init ()
Form --- run ()
Form --- Datasource --- execute Query ()
Form --- Datasource --- active ()

Sequence of Methods calls while closing the Form
Form --- canClose ()
Form --- close ()

Sequence of Methods calls while creating the record in the Form
Form --- Datasource --- create ()
Form --- Datasource --- initValue ()
Table --- initValue ()
Form --- Datasource --- active ()

Sequence of Method calls while saving the record in the Form
Form --- Datasource --- ValidateWrite ()
Table --- ValidateWrite ()
Form --- Datasource --- write ()
Table --- insert ()

Sequence of Method calls while deleting the record in the Form
Form --- Datasource --- validatedelete ()
Table --- validatedelete ()
Table --- delete ()
Form --- Datasource --- active ()

Sequence of Methods calls while modifying the fields in the Form
Table --- validateField ()
Table --- modifiedField ()

 

Saturday, August 27, 2011

Microsoft Dynamics AX 2012 E - Learning

Hi...

Some important usefull stuff for AX 2012 in the link...
https://dynamics.microsoftelearning.com/

Exporting the Data from AX to CSV file

Hi....
Here is an example of exporting the AX data to a CSV file ...

static void ExportDataToCSV(Args _args)
{
    Query                             q;
    QueryBuildDataSource    qbds;
    QueryBuildRange            qbr;
    QueryRun                       qr;
    CommaIO                       commaIO;
    FileName                        fileName;
    InventTable                     inventTable;
    ;
   
    fileName       = WINAPI::getTempPath() + "ItemDetails" + ".csv";
    commaIO      = new CommaIO(fileName,'W');
   
    q                  = new Query();
    qbds             = q.addDataSource(tablenum(InventTable));
    qbr               = qbds.addRange(fieldnum(InventTable,ItemId));
   
    qr                = new QueryRun(q);
   
    commaIO.write("ItemId","Item Name","Item Type","Item GroupId","Dimension GroupId","Model GroupId");
    while( qr.next() )
    {
        inventTable = qr.get(tablenum(InventTable));
       
        commaIO.write(inventTable.ItemId,inventTable.ItemName,enum2str(inventTable.ItemType),inventTable.ItemGroupId,
                      inventTable.DimGroupId,inventTable.ModelGroupId);
    }
   
    WINAPI::shellExecute(fileName);
}

Saturday, August 20, 2011

Creating The Number Sequence For The Existing Module

To create a numbersequence for the Existing module.

Suppose in my HRM Module for the Employee Table I have to create the NumberSequence (EmplTable).

I need to follow these steps to create the NumberSequence.

1.Go to the Classes -> NumberseqReference_HRM (Class) -> LoadMethod

2.In the load method you have to override the code , need to added the code to which field we are planning to add the code that it can be copied from the exisitng code and modfiy the EDT which we want to add ( Here My EDT is EmplId)

Let us Assume (Existing Code )
numRef.DataTypeId = typeId2ExtendedTypeId(typeid(HRMApplicationId));

For The Empl Id We have to add the code means

numRef.DataTypeId = typeId2ExtendedTypeId(typeid(EmplId));


3.After completing the above procedure, we have to go to AOT -> Tables ->HRM Parameters -> Need to Override the code in the method

Ex: The Overrided code is


static client server NumberSequenceReference numRefEmplId()
{
return NumberSeqReference::findReference(typeId2ExtendedTypeId(typeid(EmplId)));
}


4.After the above step go to the Empl Form -> Form Level Methods u have to write the number sequence formhandler method have to create the code.


Class declaration Code
IN the class declaration we have to write the code

NumberSeqFormHandler numberSeqFormHandler;

Numberseqformhandler Code
In the Numberseqformhandler write the below code


NumberSeqFormHandler numberSeqFormHandler()
{
if (!numberSeqFormHandler)
{
numberSeqFormHandler = NumberSeqFormHandler::newForm(HRMParameters::numRefEmplId().NumberSequence,element, EmplTable_ds, fieldnum(EmplTable, EmplId));
}
return numberSeqFormHandler;
}


5.Then we have to Override the DataSource Methods ( Create, Write ,Delete).



Write Method Code is

element.numberSeqFormHandler().formMethodDataSourceWrite(); ---- After Super

Create Method is

element.numberSeqFormHandler().formMethodDataSourceCreatePre(); - Before Super
super();
element.numberSeqFormHandler().formMethodDataSourceCreate(); --- > After Super


Delete Method Code Is

element.numberSeqFormHandler().formMethodDataSourceDelete();---- After Super

6.After completing all the above steps.

7.Go -> HRM Module -> Setup -> Parameters -> Numbersequence

8.We have to add the reference for the EMP ID.

Saturday, August 13, 2011

Date functions in AX 2009

Hi....

These are some of the functions,from where we can get the day or month or year from the date...
Here is the below example....

static void date_Functions(Args _args)
{
    Transdate    d;
    ;
   
    d = today();
   
    info(strfmt("Date - %1",d));
   
    //Gets the month for the given date...
    info(strfmt("Month - %1",mthofYr(d)));
   
    //Gets the month name from the given date...
    info(strfmt("Month Name - %1",mthname(mthofYr(d))));
   
    //Gets the day for the given date...
    info(strfmt("Day - %1",dayOfMth(d)));
   
    //Gets the day name from the given date...
    info(strfmt("Day Name - %1",dayname(dayOfMth(d))));
   
    //Gets the year for the given date...
    info(strfmt("Year - %1",year(d)));
   
    //Gets the current weekday number from the date...
    info(strfmt("Weekday number - %1",dayOfwk(d)));
   
    //Gets the day of the year from the given date...
    info(strfmt("Day of year - %1",dayOfyr(d)));
   
    //Gets the week of the year from the given date...
    info(strfmt("Week of the year - %1",wkofyr(d)));
}

Sunday, August 7, 2011

How to setup alerts for multiple users in Ax

In standard AX there is functionality for setup alerts only for the single user..
I came across in one the blogs, the functionality is customized to mutiple users in AX.
I just wanted to share this link to all...
Check out over here for,How to setup the alerts for mutiple users....


Wednesday, August 3, 2011

How to develop a new “Parameters form” in case of New Module developed in AX.

How to develop a new “Parameters form” in case of New Module developed in AX.
We go through it by considering an example of creating the new module as Payroll.
So now we will create the Payroll Parameters setup form for the payroll module.
Initially create a Parameters table for the Module, the naming convention should be the Module name followed by Parameter as in this case it is PayrollParameters table….and need to have the fields accordingly what is required in the Parameters table.
Set the following properties for the parameter table as…

Create a parameter form by considering the PayrollParameters and NumberSequenceReference as data sources. And set the following properties for the data source in the form level as

First thing is that there shouldn’t be any provision to create the record in the parameters form. The record in the Parameters should be by default and it can be updated as per the functionality required
So when creating the new company in the Axapta, the parameters form should have the default values.
To have the default values in the parameters we need to have the following code in the  table  level of find() of PayrollParameters tables .
static PayrollParameters find(boolean _forupdate = false)
{
    PayrollParameters  parameter;

    if (_forupdate)
    parameter.selectForUpdate(_forupdate);

    select firstonly parameter
        index Key
        where parameter.Key == 0;

    if (!parameter && !parameter.isTmp())
    {
        Company::createParameter(parameter);
        NumberSeqReference::construct(PayrollParameters::numberSeqModule()).load();
    }

    return parameter;
}


Tuesday, August 2, 2011

Displaying the PageNum/Total Pages in the report header

Displaying the PageNum/Total Pages in the report header...

For example: If a report contains a 10 pages then in the pager header it should be displaed as
Page 1 of 10,Page 2 of 10.....Page 10 of 10

Write these 2 methods in the report header
//Method to get the page number for every page in the report....
display int page()
{
    return element.page();
}
//Method to get the total pages in the report for every page...
display int pages()
{
    return element.pagesTotal();
}
Arrange these controls according in the design to display in the report..

Saturday, July 30, 2011

How to disable the “Setup” option for the Forms in the Axapta in security keys for the users

How to disable the “Setup” option for the Forms in the Axapta in security keys for the users….
Go to
Administration --- > Setup --- > User Groups --- > Create a new user Group and add the User to the newly created used group as shown in the screen shot



Click on the Button “Permissions”, now in the User Group permissions Form go to Permissions Tab, there able to see the tree structure of all the modules
Here to go
Administration --- > Miscellaneous --- > select the Form Personalization --- > and give No Access as shown in the below screen shot.


Now attach this User group to User in the Administration --- > Users Form for which users want to disable the setup option in the forms…

Monday, July 25, 2011

How to Configure the Batch jobs…

Batch jobs are required to perform the particular/defined set of action in the system in the regular intervals of time defined accordingly…
In AX there were the existing batch jobs, we can use them accordingly to your use….
Let say for example,
In the Employee master, employee status needs to change accordingly…
i.e. if employee is going on leave one week after, but the leave is entered on the current date, so employee status need to be changed on the day of the leave.
Once the employee is back from the leave, it is should be retained back to original status accordingly..
So in this case of scenario’s we can have a batch job which run basis on the interval defined and changes the status accordingly…
To write a batch job...
Create a new class and it should extend from “RunBaseBatch” from the standard AX.
Class EmployeeStatusChange extends RunBaseBatch
{
}

And having the logic as per accordingly…
After creating the class, create the action menu item for the Class.
Setup;
In Administration --- setup --- open the Server Configuration form


Is Batch Server check box needs to be checked – this indicates the batch job need to be executed on which AOS instance.

In Administration --- setup --- open the Batch Group form


Here create a new Batch Group and in the Batch servers tab selected the server on which this job needs to be scheduled.

Now open the Action menu item created for the class,then

Here attach the batch job created in the above step , mark the Batch processing checkbox and click the Recurrence button there need to be defined when the job needs to be started, and what interval need to processed..
In the alerts button, email alerts can be defined.

Once the Batch job is scheduled it is being queued in the Batch Jobs list..In Basic – Inquiries – Batch Job, here the scheduled batch can be found.

Sunday, July 17, 2011

How to create ‘New Number Sequence’ if added new module in AX.

How to create ‘New Number Sequence’ if added new module in AX.
I have created a new Module “Payroll”
Setp1:
Need to create a new element in the baseenum “NumberSeqModule” as “Payroll” .The name should be baseenum should be the Module name.
Step2:
The field which need to be generated as number sequence it should be as extended data type.So create a extended data type and use this in the table.
Step3:
Create a new class as per module name as follows “NumberSeqRefernce_Payroll”
Add the following methods
Class NumberSeqRefernce_Payroll extends NumberSeqReference
{
}

public static client server NumberSeqModule numberSeqModule()
{
    return NumberSeqModule::Payroll;
}

protected void loadModule()
{
    NumberSequenceReference numRef;
    ;

    numRef.dataTypeId                     = typeId2ExtendedTypeId(typeid(EmpId));
    numRef.configurationKeyId       = configurationKeyNum(payroll);
    numRef.referenceHelp                = literalStr("Unique Key for Employee identification.The key is used when creating the Employee");
    numRef.wizardContinuous         = true;
    numRef.wizardManual                 = NoYes::No;
    numRef.wizardAllowChangeDown    = NoYes::No;
    numRef.wizardAllowChangeUp      = NoYes::No;
    numRef.wizardHighest            = 999999;
    numRef.sortField                = 1;

    this.create(numRef);
}


Step4:
To get the new module number sequence in the Basic > Setup > Number sequences > Number sequences, add the following code in the “NumberSeqReference” class methods

In Construct () method add the following line of code…
case (NumberSeqRefernce_Payroll::numberSeqModule()) : return new NumberSeqrefernce_Payroll(_module);

 In the moduleList() method….
moduleList += NumberSeqrefernce_Payroll::numberSeqModule();

Step5:
Go to Basic > Setup > Number sequences > Number sequences there click the Wizard button in the form & click the Next button.
 On the next screen, the number sequence for the Module “Payroll” will be shown,go further and finish the wizard.
After finishing the wizard select newly created number sequence in Number sequences form and go to General Tab and check the continuous check box

Step6:
Design the form and add the following code in the form
In Form
In Class declaration declare the
NumberSeqFormHandler numberSeqFormHandler;

Added the following method
NumberSeqFormHandler numberSeqFormHandler()
{
    if (!numberSeqFormHandler)
    {
        numberSeqFormHandler = NumberSeqFormHandler::newForm(EmployeeTable::numRefEmpId().NumberSequence,element, EmployeeTable_ds, fieldnum(EmployeeTable, EmpId));
    }
    return numberSeqFormHandler;
}

In the form DataSource Level added following methods

public void create(boolean _append = false)
{
    element.numberSeqFormHandler().formMethodDataSourceCreatePre();

    super(_append);

    element.numberSeqFormHandler().formMethodDataSourceCreate();
}
public void delete()
{
    element.numberSeqFormHandler().formMethodDataSourceDelete();

    super();
}
public void write()
{
    super();
    element.numberSeqFormHandler().formMethodDataSourceWrite();
}

Monday, July 11, 2011

Adding table methods in the form lookup method.....

Adding the table level methods in the form lookup as the table fields...

public void lookup(FormControl _formControl, str _filterStr)
{
    SysTableLookup              sysTableLookup;
    Query                              query;
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange             queryBuildRange;
    ;
    sysTableLookup  = SysTableLookup::newParameters(tablenum(EmplTable), _formControl);
    sysTableLookup.addLookupfield(fieldnum(EmplTable, EmplId));
    sysTableLookup.addLookupfield(fieldnum(EmplTable, legacyEmplId));
    // adding the EmplTable method name() int he lookup methos as follows....    sysTableLookup.addLookupMethod(identifierstr(name));
    query                              =  new Query();
    queryBuildDataSource    =  query.addDataSource(tablenum(EmplTable));
  
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}

Saturday, July 9, 2011

Import Data into AX from excel file

static void DataImportToAXFromExcel(Args _args)
{
    SysExcelApplication xlsApplication;
    SysExcelWorkBooks   xlsWorkBookCollection;
    SysExcelWorkBook    xlsWorkBook;
    SysExcelWorksheets  xlsWorkSheetCollection;
    SysExcelWorksheet   xlsWorkSheet;
    SysExcelRange       xlsRange;
    SysExcelCells       Cells;
    SysExcelCell        RCell;
    CommaIO             inFile;

    int                 nRow,i;

    DialogField         dialogPath;
    Dialog              dialog;
    Filename            filename;

    CustTable           custTable;
    CustAccount         custAccount;
    CustGroupId         custGroupId;
    CurrencyCode        currencyCode;
    ;

    dialog = new Dialog("Import");
    dialogPath = dialog.addField(typeid(Filenameopen), "File Name");
    dialog.run();

    if (dialog.run())
    {
        filename = (dialogPath.value());
    }

    inFile = new CommaIO (filename, 'R');

    if (!inFile || infile.status() != IO_Status::Ok )
    {
        throw error (strfmt("@SYS19312",filename));
    }

    try
    {
        xlsApplication          = SysExcelApplication::construct();
        xlsWorkBookCollection   = xlsApplication.workbooks();
        xlsWorkBookCollection.open(filename);
        xlsWorkSheetCollection  = xlsApplication.worksheets();
        xlsWorkSheet            = xlsWorkSheetCollection.itemFromNum(1);
        Cells                   = xlsWorkSheet.Cells();

        nRow = 2;
        RCell = Cells.Item(nRow, 1);

        while(RCell.value().bStr() != "")
        {
            custAccount     = RCell.value().bStr();
            RCell           = Cells.item(nRow,2);
            custGroupId     = RCell.value().bStr();
            RCell           = Cells.item(nRow,3);
            currencyCode    = RCell.value().bStr();

            if(!CustTable::exist(custAccount))
            {
                if(CustGroup::exist(custGroupId) && Currency::exist(currencyCode))
                {
                    custTable.initValue();
                    custTable.AccountNum    = custAccount;
                    custTable.CustGroup     = custGroupId;
                    custTable.Currency      = currencyCode;
                    custTable.insert();
                }
            }
            nRow++;
            RCell = Cells.Item(nRow, 1);
        }
        xlsApplication.quit ();
        xlsApplication.finalize ();
        info("Imported completed");
    }
    catch( Exception::Error)
    {
        //Close Excel.
        xlsApplication.quit ();
        xlsApplication.finalize ();
        ttsabort;
        info("Unable to process the excel import ");
    }
}

Data-upload into AX from CSV file(comma delimited)

Exportfile for AOT version 1.0 or later
Formatversion: 1
***Element: CLS
; Microsoft Dynamics AX Class: ImportDataCSV unloaded
; --------------------------------------------------------------------------------
  CLSVERSION 1
 
  CLASS #ImportDataCSV
    PROPERTIES
      Name                #ImportDataCSV
      Extends             #RunBase
      RunOn               #Called from
    ENDPROPERTIES
   
    METHODS
      Version: 3
      SOURCE #classDeclaration
        #class ImportDataCSV extends RunBase
        #{
        #    FilenameOpen    filename;
        #
        #    CustAccount     custAccount;
        #    CustGroupId     custGroup;
        #    CurrencyCode    currencyCode;
        #
        #    DialogField     dialogFileName;
        #    #define.CurrentVersion(1)
        #    #localmacro.CurrentList
        #            filename
        #    #endmacro
        #}
      ENDSOURCE
      SOURCE #dialog
        #/// <summary>
        #/// The dialog method defines the dialog. The dialog contains a file name.
        #/// </summary>
        #/// <returns>
        #/// The method dialog returns the defined dialog.
        #/// </returns>
        #public Object dialog(DialogRunbase _dialog, boolean _forceOnClient)
        #{
        #    DialogRunbase dialog;
        #    ;
        #
        #    dialog = super(_dialog, _forceOnClient);
        #    dialog.addGroup("Choose File to Upload");
        #    dialogFilename  = dialog.addFieldValue(typeid(FilenameOpen), filename);
        #
        #    return dialog;
        #}
      ENDSOURCE
      SOURCE #getFromDialog
        #public boolean getFromDialog()
        #{
        #    boolean ret;
        #
        #    ret = super();
        #
        #    filename    = dialogFilename.value();
        #
        #    if (!WinApi::fileExists(filename))
        #        ret = checkFailed(strfmt("@SYS18678", filename));
        #
        #    return ret;
        #}
        #
      ENDSOURCE
      SOURCE #pack
        #public container pack()
        #{
        #    return [#CurrentVersion, #CurrentList];
        #}
        #
      ENDSOURCE
      SOURCE #parmFilename
        #public FilenameOpen parmFilename(FilenameOpen _filename = filename)
        #{
        #    ;
        #    filename = _Filename;
        #
        #    return filename;
        #}
        #
      ENDSOURCE
      SOURCE #run
        #public void run()
        #{
        #    AsciiIO             file;
        #    Container           conData;
        #    boolean             first = false;
        #    CustTable           custTable;
        #    ;
        #
        #    file    = new AsciiIO(filename,"R");
        #    if(!file && file.status() != IO_Status::Ok)
        #    {
        #        throw error(strfmt("@SYS19312",filename));
        #    }
        #
        #    file.outRecordDelimiter('\n');
        #    file.inFieldDelimiter(',');
        #
        #    while (file.status() == IO_status::Ok)
        #    {
        #        conData = file.read();
        #
        #        if(first)
        #        {
        #            if(conData != connull())
        #            {
        #                custAccount     = conpeek(conData,1);
        #                custGroup       = conpeek(conData,2);
        #                currencyCode    = conpeek(conData,3);
        #
        #                if(!CustTable::exist(custAccount))
        #                {
        #                    CustTable.initValue();
        #                    CustTable.AccountNum    = custAccount;
        #                    if(CustGroup::exist(custGroup))
        #                    {
        #                        CustTable.CustGroup = custGroup;
        #                    }
        #                    if(Currency::exist(currencyCode))
        #                    {
        #                        CustTable.Currency  = currencyCode;
        #                    }
        #                    CustTable.insert();
        #                }
        #            }
        #        }
        #        first           = true;
        #    }
        #}
        #
      ENDSOURCE
      SOURCE #unpack
        #public boolean unpack(container _packedClass)
        #{
        #    Version version = runbase::getVersion(_packedClass);
        #
        #    switch (version)
        #    {
        #        case #CurrentVersion:
        #            [version, #CurrentList] = _packedClass;
        #            break;
        #
        #        default:
        #            return false;
        #    }
        #
        #    return true;
        #}
        #
      ENDSOURCE
      SOURCE #description
        #client server static ClassDescription description()
        #{
        #    return "Import Customer Data";
        #}
        #
      ENDSOURCE
      SOURCE #main
        #static void main(Args _args)
        #{
        #    ImportDataCSV import = new ImportDataCSV();
        #    ;
        #
        #        if (import.prompt())
        #            import.run();
        #}
        #
      ENDSOURCE
    ENDMETHODS
  ENDCLASS
***Element: END

Thursday, June 16, 2011

Convert Date to UTCDateTime


static void ConvertDate2DateTime(Args _args)
{
    TransDate       fromDate,toDate;
    TimeZone        tz;
    UtcDateTime     fDateTime,tDateTime;
    ;
   
    fromDate    = mkDate(01,06,2011);
    toDate        = mkDate(30,06,2011);
    fDateTime   = Global::datetobeginUtcDateTime(fromDate,tz);
    tDateTime   = Global::datetoendUtcDateTime(toDate,tz);
    print fDateTime;
    print tDateTime;
    pause;
}

Wednesday, June 15, 2011

Number into Indian format

Changing numerals to text in Indian Format

I have made some changes to the "numeralsToTxt_EN" method of the Global Class.

Add the below method to the Global class - which will convert the number into Indian format



static TempStr numeralsToTxt_IN(real _num)

{

int numOfPennies = (decround(frac(_num), 2) * 100) mod 100;

real test = _num - frac(_num);





int numOfTenths;

str 20 ones[19], tenths[9], hundreds, thousands, lakhs, crores;





int64 temp;

str 200 returntxt;

str 200 pennytxt;

int penny;





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)

{

numOfPower = _test 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 10000000 :

{

returntxt = returntxt + ' ' + Crores;

_test = modOperator(_test, 10000000);

break;

}

case 100000 :

{

returntxt = returntxt + ' ' + lakhs;

_test = modOperator(_test, 100000);

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_100000('Lakh')

#Define.text_10000000('Crore')

#Define.text_and('Rupees and')

#Define.text_paise('Paise Only')

#Define.text_ruppe('Rupees Only')





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;

lakhs = #text_100000;

crores = #text_10000000;













test = checkPower(test, 10000000);

test = checkPower(test, 100000);

test = checkPower(test, 1000);

test = checkPower(test, 100);





if (test >= 20)

{

numOfTenths = test div 10;

returntxt = returntxt + ' ' + tenths[numofTenths];

numOfTenths = numOfTenths mod 10;

test = test mod 10;

}

if (test >= 1)

{

numOfTenths = real2int(test);

returntxt = returntxt + ' ' + ones[numOfTenths];

}





if (numOfPennies)

{

if (numOfPennies >= 20)

{

penny = numOfPennies div 10;

pennytxt = tenths[penny];

numOfPennies = numOfPennies mod 10;

}

if (numOfPennies >= 1)

{

pennytxt = pennytxt + ' ' + ones[numOfPennies];

}

returntxt = returntxt + ' ' + #text_and + ' ' + pennytxt + ' ' +#text_paise;

}

else

{

returntxt = returntxt + ' ' + #text_ruppe;

}





return returntxt;

}