Showing posts with label Technical. Show all posts
Showing posts with label Technical. Show all posts

Wednesday, 18 December 2013

Tax Calculation in X++ :



Method : 1 

void clicked()
{
real tax1;
;
    super();
 tax1 = Tax::calcTaxAmount(Salesline.TaxGroup, Salesline.TaxItemGroup, Systemdateget(), Salesline.CurrencyCode, Salesline.LineAmount, TaxModuleType::Sales);

info(strfmt("%1", tax1));
}

Method : 2
void clicked()
{
TaxOnItem                       TaxOnItem;
TaxGroupData                    TaxGroupData, TaxGroupData_1;
real                            TaxAmount = 0, TaxAmount_1 = 0;
TaxValue                        TaxValue = 0, TaxValue_1 = 0;
;
 
    super();

    if(Salesline.TaxItemGroup && Salesline.TaxGroup && Salesline.LineAmount != 0)
    {
        while select TaxOnItem
             where TaxOnItem.TaxItemGroup == salesline.TaxItemGroup
             {
              if(TaxOnItem)
              {
             while select TaxGroupData
                  where TaxGroupData.TaxGroup == Salesline.TaxGroup
&& TaxGroupData.TaxCode  == TaxOnItem.TaxCode
                   {
                   if(TaxGroupData)
                   {
                    TaxValue  =  TaxData::find(TaxOnItem.TaxCode, Systemdateget(), 0).TaxValue;
                    TaxValue_1  += TaxValue;
                    TaxAmount = (Salesline.LineAmount * TaxValue)/100;
                    TaxAmount_1 += TaxAmount;
                   }
                   }
              }
              }
               info(strfmt("%1", TaxAmount_1));
        }
}

Monday, 16 December 2013

X++ CODE TO READ MS OFFICE WORD DOCUMENT


static void FileIO_ReadFromWord(Args _args)
{     
        str         document = "D:\\Demo Edition.doc";
    COM         wordApplication;
    COM         wordDocuments;
    COM         wordDoc;
    COM         range;
    TextBuffer  txt = new TextBuffer();
    ;

    // Create instance of Word application
    wordApplication = new COM("Word.Application");

    // Get documents property
    wordDocuments = wordApplication.Documents();

    // Add document that you want to read
    wordDoc = wordDocuments.add(document);
    range = wordDoc.range();

    txt.setText(range.text());

    // to replace carriage return with newline char
    txt.replace('\r', '\n');   
   
    info(txt.getText());
}

Sunday, 15 December 2013

LogisticsElectronicAddress phone ,fax details

static void phonefax(Args _args)

{
    InventLocation inventLocation;
    InventSite inventSite;
    LogisticsEntityPostalAddressView logisticsEntityPostalAddressView;
    LogisticsLocation logisticsLocation;
    LogisticsElectronicAddress logisticsElectronicAddress;
    int64 siteid;
    select * from inventSite where inventSite.SiteId == "1";
    select * from logisticsEntityPostalAddressView where logisticsEntityPostalAddressView.Entity == inventSite.RecId;
                                               // && logisticsEntityPostalAddressView.IsPrimary == NoYes::Yes;
     //info(strFmt("%1",logisticsEntityPostalAddressView.Address));
    select * from logisticsLocation where logisticsLocation.RecId == logisticsEntityPostalAddressView.Location;
    siteid = logisticsLocation.RecId + 1;
     while select logisticsElectronicAddress where logisticsElectronicAddress.Location == siteid
                                                       && logisticsElectronicAddress.Type == 1//LogisticsElectronicAddressMethodType::Phone//1
     //                                                  && logisticsElectronicAddress.IsPrimary == NoYes::No//LogisticsElectronicAddressTypes::Phone
    {

    info(strFmt("%1 %2 %3",logisticsElectronicAddress.Type,logisticsElectronicAddress.LocatorExtension,logisticsElectronicAddress.Locator));
    info("hi");
    }
        info("bye");

}
=======================================================================
So this post basically
       - Describes about new data model
       - X++ job to illustrate how address and contact information can be migrated to AX 2012.

New Data Model

Monday, 25 November 2013

How to create and import CSV files in AX

static void RB_ReadCsvFile(Args _args)
{
    #File
    IO  iO;
    CustAccount custAccount;
    CustName custname;
    CustGroupId custgroup;
    CustCurrencyCode currency;
    FilenameOpen        filename = "c:\\Customers.csv";
    Container           record,c;
    boolean first = true;
    int len;
    ;

    iO = new CommaTextIo(filename,#IO_Read);

    //len = conLen(c);
    //info(strFmt("%1",len));

    if (! iO || iO.status() != IO_Status::Ok)
    {
        throw error("@SYS19358");
    }
    while (iO.status() == IO_Status::Ok)
    {
        record = iO.read();
        if (record)
        {
            if (first)  // to exclude the header
            {
                first = false;
            }
            else
            {
                custAccount = conpeek(record, 1);
                custgroup = conpeek(record, 2);
                currency  = conPeek (record,3);
                info(strfmt('%1--%2--%3',custAccount,custgroup,currency));
            }
        }
    }
}
======================================================================

static void WriteCsvFile(Args _args)
{
     CommaIo     fileOut;
    FileName    fileName = "c:\\Customers.csv";
    CustTable   custTable;
;
    #File
    fileOut = new CommaIo(filename, #io_write);
    if (fileOut)
    {
        while select custTable
        {
            fileOut.write(custTable.accountNum,
                              //custTable.name,
                              custTable.custGroup,
                              custTable.currency);
        }
    }
}

Thursday, 17 October 2013

How to get Multiple Select Lookup in form


How  to get Multiple Select Lookup in form :

Class Declaration of Form :
SysLookupMultiSelectCtrl msCtrl;
In  Data Source Execute query :
#define.seperator(', ')
    container c,v;
    int i;
    boolean first;
    Name allPackIds;
 
  v = msCtrl.getSelectedFieldValues();
 
        first = true;
        for (i = 1; i <= conLen(v);i++)
        {
             if(first)
                {
                    first = false;
                    allPackIds = conPeek(v,i);
                }
            else
                allPackIds += ( #seperator + conPeek(v,i));
        }
 
   if(Amenities.valueStr())
        qbrAmenities.value(allPackIds);
    else
    {
       qbrAmenities.value(SysQuery::valueUnlimited());
    }
 
 
Init of Form :
msCtrl = SysLookupMultiSelectCtrl::construct(element, Amenities, querystr( AmenitiesQuery));
Amenities – Ctrl name in form .
 
In  Modified method :
    RentalInquiryTmp_ds.executeQuery();
    RentalInquiryTmp_ds.refresh();
    RentalInquiryTmp_ds.reread();
 

Tuesday, 15 October 2013

Adding Image to Form



Adding Image to every record :

1. For that one first we have add one container field (logo) to table and it is extended from Bitmap
2. add one button in to action pane and write the code in clicked method as
void clicked()
    {
        Image image1            = new Image();
        IPMFinancialCompanies  _ImageTable; //Table name
        FilenameOpen           filename;
        dialogField            dialogFilename;
        DialogGroup            dialoggroup;
        DialogField            SID;
        //EmployeeIDTxt
        Dialog                 dialog;
        container              con;
        str                    photoname;
        ;
        super();
         dialog              =   new Dialog(“Image Upload”);
         DialogGroup=dialog.addGroup(“Details”);
         SID            =        dialog.addFieldValue(extendedTypeStr(IPMCompanyID),IPMFinancialCompanies_IPMCompanyID1.valueStr(),
                                                                                   “IPMCompany ID”);

           // change our edt ,our form design level unique field ,and the label


         dialogFilename      =   dialog.addField(extendedTypeStr(FilenameOpen),”File Name”);
         dialog.filenameLookupFilter([".jpeg"]);
         dialog.filenameLookupTitle(“Upload Image”);
         dialog.caption(“PHOTO Upload”);
         dialogFilename.value(photoname);
         if(!dialog.run())
            return;
              photoname            =   dialogFilename.value();
              if (Image::canLoad(photoname))
                {
                    image1.loadImage(photoname);
                    con=image1.getData();//,Emp_Id.text()];
                    _ImageTable.IPMCompanyID = SID.value(); //change our unique  field
                    _ImageTable.logo=con;
                    ttsBegin;
                    select forupdate _ImageTable where _ImageTable.IPMCompanyID == IPMFinancialCompanies.IPMCompanyID;
                    if(_ImageTable)
                    {
                    IPMFinancialCompanies.logo = con;
                    IPMFinancialCompanies.update();
                    }
                    else
                    {
                        IPMFinancialCompanies.logo = con;
                    IPMFinancialCompanies.insert();
                    }
                    ttsCommit;
                   // _ImageTable.insert();
                    info(“Your Photo Uploaded”);
                 }
}
3. add one image type controller in to our form and assign the datasource and data field(logo)
  

When we click that button it shown following screen shot

After that we select the path
  3. add one image type controller in to our form and assign the datasource and data field(logo)
 Then it will displayed form as

Coloring for the rows in grid based on conditions




To display color to the selected row in display option

public void displayOption(Common _record, FormRowDisplayOption _options)
{
   RentalInquiryTmp rentalInquiry;
    rentalInquiry = _record;
    switch(rentalInquiry.Occupied)
    {
        case NetOccupied::Vacant:
            _options.backColor(65535);
           
            //_options.backColor(WinAPI::RGB2int(161,161,255));
            break;

        case NetOccupied::Occupied:
            _options.backColor(8421631);
          // _options.backColor(WinAPI::RGB2int(255,0,0));
            break;

        case NetOccupied::Inactive:
            _options.backColor(65408);
           //_options.backColor(WinAPI::RGB2int(0,0,255));
            break;
    }
    //super(_record, _options);
}

=====================================================================

Changing color of records/Individual fields based on flag in AX.


Hi,
The below code will provide different colors for different records in salestable form based on salesstatus enum..
public void displayOption(Common _record, FormRowDisplayOption _options)
{
SalesTable prodtablelocal;
prodtablelocal = _record;
Switch(prodtablelocal.SalesStatus)
{
Case SalesStatus::Delivered:
_options.backColor(65535); //Light Yellow
//_options.affectedElementsByControl(Salestable_SalesId.id());
Break;
Case SalesStatus::Invoiced:
_options.backColor(8421631); //Light Red
//_options.affectedElementsByControl(Salestable_SalesId.id());
Break;
Case SalesStatus::Backorder:
_options.backColor(65408); //Light Green
//_options.affectedElementsByControl(Salestable_SalesId.id());
_options.textColor(12582912);
Break;
}
}
Output:
IMG_08032013_145736
The below code will provide different colors for (only for selected fields) salesid field for a record in salestable form based on sales status enum.. this is done by uncommenting the _options.affectedElementsByControl(Salestable_SalesId.id()); lines.
In the same way, you can add different fields by setting autodecalaration to ‘Yes’ in design for respective fields in design > control names from the form.
public void displayOption(Common _record, FormRowDisplayOption _options)
{
SalesTable prodtablelocal;
prodtablelocal = _record;
Switch(prodtablelocal.SalesStatus)
{
Case SalesStatus::Delivered:
_options.backColor(65535); //Light Yellow
_options.affectedElementsByControl(Salestable_SalesId.id());
Break;
Case SalesStatus::Invoiced:
_options.backColor(8421631); //Light Red
_options.affectedElementsByControl(Salestable_SalesId.id());
Break;
Case SalesStatus::Backorder:
_options.backColor(65408); //Light Green
_options.affectedElementsByControl(Salestable_SalesId.id());
_options.textColor(12582912);
Break;
}
}
Output:
IMG_08032013_144737