Monday 8 December 2014

Import Opening Stock in ax 2012

public class ImportOpeningStock extends RunBase
{
    SysExcelApplication application;
    SysExcelWorkbooks workbooks;
    SysExcelWorkbook workbook;
    SysExcelWorksheets worksheets;
    SysExcelWorksheet worksheet;
    SysExcelCells cells;
    COMVariantType type;
    int row;
    InventJournalTrans          InventJournalTrans,_ValueJournalTrans,_ValueJournalTranslocal,_ValueJournalnum,_ValueJournalupdate;
    InventDim                   InventDim;
    InventTransOrigin           InventTransOrigin;
    InventJournalTransTaxExtensionIN   InventJournalTransTaxExtensionIN;
    TaxInformation_IN            TaxInformationIN;
    inventJournalTable            inventJournalTable;
    Filename                    filename,Jounralid;
    DialogField                 dialogFilename,dialogJounalid;
    counter                     icount,inserted;
    Amount                      amount;
    int                         cutoffdays,prevcutoffdays;
    currencycode                currencycode;
    str                         AccountNum,date1;
    args                        args;
    container productDimensions;
    #define.CurrentVersion(2)
    #localmacro.CurrentList
    filename,
    insertIncorrectRecords,
    #endmacro
    #localmacro.ListVersion1
    filename,
    insertIncorrectRecords
    #endmacro
    #File
}

public Object dialog()
{
    DialogRunbase       dialog = super();
    ;
    dialogFilename  = dialog.addField(extendedTypeStr(FilenameOpen));
    dialogFilename.value(filename);
    dialog.filenameLookupFilter(["All files", #AllFiles]);
    return dialog;
}
public boolean getFromDialog()
{
    filename                = dialogFilename.value();
    return true;
}

void OpeningStockloc(JounalID  _JounalID)
{
    itemid                             itemId ;
    InventSiteId                       Site;
    InventLocationId                   Warehouse;
    InventDim                          _InventDim;
    RecId                              i,Countvalue;
    Qty                                mslQTY,CostPrice;
    InventJournalNameId             inventJournalName;
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    try
    {
        workbooks.open(filename);
    }
    catch (Exception::Error)
    {
        throw error("File cannot be opened.");
    }
    workbook = workbooks.item(1);
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();
    row = 1;
    do
    {
        row++;
        itemId      = cells.item(row, 1).value().bStr();
        Site        = cells.item(row, 3).value().bStr();
        Warehouse   = cells.item(row, 4).value().bStr();
        mslQTY      = cells.item(row, 7).value().double();
        //CostPrice   = cells.item(row, 6).value().double();
        ttsBegin;
        if(mslQTY)
        {
            select InventDim where InventDim.InventSiteId     == Site &&  InventDim.InventLocationId == Warehouse;
            InventDim.InventSiteId     = Site;
            InventDim.InventLocationId = Warehouse;
            _InventDim = InventDim::findOrCreate(InventDim);
             select forupdate _ValueJournalnum where _ValueJournalnum.JournalId   == _JounalID
                                                  && _ValueJournalnum.InventDimId ==  _InventDim.inventDimId
                                                  && _ValueJournalnum.ItemId      == itemId;
            if(!_ValueJournalnum.RecId)
            {
                inventJournalTrans.clear();
                inventJournalTable = InventJournalTable::find(_JounalID);
                inventJournalTrans.initFromInventJournalTable(inventJournalTable);
                inventJournalTrans.TransDate = systemDateGet();
                inventJournalTrans.ItemId = itemId;
                inventJournalTrans.initFromInventTable(InventTable::find(itemId));
                inventJournalTrans.Qty = mslQTY;
                inventDim.InventSiteId  = Site;
                inventDim.InventLocationId = Warehouse;
                inventJournalTrans.InventDimId = _InventDim.inventDimId;
                inventJournalTrans.insert();
            }
            else
            {
                select forupdate _ValueJournalupdate where _ValueJournalupdate.JournalId   == _JounalID
                                                        && _ValueJournalupdate.InventDimId == _InventDim.inventDimId
                                                        && _ValueJournalupdate.ItemId      == itemId;
                {
                    _ValueJournalupdate.Qty       = mslQTY;
                    _ValueJournalupdate.doupdate();
                }
            }
            ttsCommit;
       }
        type = cells.item(row+1, 1).value().variantType();
    }while (type != COMVariantType::VT_EMPTY);
    ttsBegin;
    select count(RecId) from _ValueJournalTranslocal where _ValueJournalTranslocal.JournalId ==_JounalID;
    Countvalue = _ValueJournalTranslocal.RecId;
    select forUpdate  InventJournalTable where InventJournalTable.JournalId == _JounalID;
    InventJournalTable.NumOfLines =  Countvalue;
    InventJournalTable.doUpdate();
    ttsCommit;
    application.quit();
}

// Here goes a description of the class
static ClassDescription description()
{
    return "Upload Opening stock from template";
}
static void main(Args  args)
{
    ImportOpeningStock      _ImportOpeningStock;
    JournalForm                 journalForm;
    InventJournalTable          journalTable;
    JounalID                _JounalID;
    ;
    journalForm         = JournalForm::fromArgs(args);
    journalTable        = journalForm.journalTableData().journalTable();
    _JounalID  =journalTable.JournalId;
    _ImportOpeningStock =  new ImportOpeningStock();
    if(_ImportOpeningStock.prompt())
    {
        _ImportOpeningStock.OpeningStockloc(_JounalID);
    }
}



Open other form with one form and get data form other form
Form init method:
public void init()
{
    CustTable       custTable;
    HcmWorker       hcmworker;
    Args  args = new Args();
    ;

    if (element.args().dataset() == tableNum (CustTable) && element.args().record())
    {
        custTable = element.args().record();
        custId    = custTable.AccountNum;
    }
    if (element.args().dataset() == tableNum (HcmWorker) && element.args().record())
    {
        hcmworker      = element.args().record();
        HcmWorkerRecId = hcmworker.RecId;
    }

    super();
  
}
DATASOURCE EXECUTE QUERY
public void executeQuery()
{
    if(HcmWorkerRecId)
    {
        this.query().dataSourceNo(1).addRange(fieldNum(CustomerSalesType,adcHcmWorkerRecId)).value(SysQuery::value(HcmWorkerRecId));

    }
    else if(custId)
    {
       this.query().dataSourceNo(1).addRange(fieldNum(CustomerSalesType,ADCCustomerAccountNum)).value(SysQuery::value(custId));

    }
    super();
}






Price list report with parameters call in ax EP 2012

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="PriceListView.ascx.cs" Inherits="PriceListView" %>
<%@ Register Assembly="Microsoft.Dynamics.Framework.Portal, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        Namespace="Microsoft.Dynamics.Framework.Portal.UI.WebControls" TagPrefix="dynamics" %>
<style type="text/css">
    .style1
    {
        width: 70px;
    }
    .style5
    {
        width: 60px;
    }
    .style7
    {
        width: 108px;
    }
    .style8
    {
        width: 125px;
    }
</style>
<dynamics:AxMultiSection ID="EPPriceByRegionMultiSection" runat="server" 
    Height="40px">
    <dynamics:AxSection ID="EPPriceByRegionSection" runat="server">
     <table>
            <tr>
                <td style="padding-left:19px;" align="right" class="style1">                
                    <asp:Label ID="lblBPGroup" runat="server" AssociatedControlID="tbBPGroup"
                        Text="BP Group" style="font-weight: 700"></asp:Label> 
                </td>
                <td align="right">
                    <asp:TextBox class="AxInputField" ID="tbBPGroup" Width="100%"  
                        ToolTip="<%$Axlabel:@SYS191513%>" runat="server" ReadOnly="False" 
                        Enabled="True" style="margin-left: 0px"></asp:TextBox>
                </td>
                <td>
                <dynamics:AxLookup ID="DropDownBPSelection" runat="server" AutoPostBack="true" 
                TargetControlId="tbBPGroup"
                OnLookup="DropDownBPSelection_Lookup" TabIndex="1" 
                onokclicked="DropDownBPSelection_OkClicked">
                </dynamics:AxLookup>
                </td>
                <td align="right" class="style7">
                    <asp:Label ID="lblProductGroup" runat="server" AssociatedControlID="tbProductGroup"
                        Text="Product Group" style="font-weight: 700"></asp:Label>
                </td>
                <td align="right">
                    <asp:TextBox class="AxInputField" ID="tbProductGroup" Width="100%"  ToolTip="<%$Axlabel:@SYS191513%>" runat="server" ReadOnly="False" Enabled="True"></asp:TextBox>
                </td>
                <td>
                <dynamics:AxLookup ID="AxLookup2" runat="server" AutoPostBack="true" 
                TargetControlId="tbProductGroup"
                OnLookup="DropDownProductBPSelection_Lookup" TabIndex="1" 
                onokclicked="DropDownProductBPSelection_OkClicked">
                </dynamics:AxLookup>
                </td>  
                <td align="right" class="style8">
                    <asp:Label ID="lblParentCategory" runat="server" AssociatedControlID="tbParentCategory"
                        Text="Product Category" style="font-weight: 700"></asp:Label>
                </td>
                <td align="right">
                    <asp:TextBox class="AxInputField" ID="tbParentCategory" Width="100%"  ToolTip="<%$Axlabel:@SYS191513%>" runat="server" ReadOnly="False" Enabled="True"></asp:TextBox>
                </td>
                 <td>
                <dynamics:AxLookup ID="AxLookup3" runat="server" AutoPostBack="true" 
                TargetControlId="tbParentCategory"
                OnLookup="DropDownProductCatSelection_Lookup" TabIndex="1" 
                onokclicked="DropDownProductCatBPSelection_OkClicked">
                </dynamics:AxLookup>
                </td>
                 <td align="right" class="style5">
                    <asp:Label ID="lblModel" runat="server" AssociatedControlID="tbModel"
                        Text="Model" style="font-weight: 700"></asp:Label>
                </td>
                <td align="right">
                    <asp:TextBox class="AxInputField" ID="tbModel" Width="100%"  ToolTip="<%$Axlabel:@SYS191513%>" runat="server" ReadOnly="False" Enabled="True"></asp:TextBox>
                </td>
                <td>
                <dynamics:AxLookup ID="AxLookup4" runat="server" AutoPostBack="true" 
                TargetControlId="tbModel"
                OnLookup="DropDownItemidSelection_Lookup" TabIndex="1" 
                onokclicked="DropDownItemidSelection_OkClicked">
                </dynamics:AxLookup>
                </td>
            
            
            <td style="padding-left:12px;" align="right">
            <asp:Button runat="server" ID="Button1" 
            Text="View Price List " onclick="ViewReportButton_Click1" 
                    style="font-weight: 700"  />
            </td>
        </tr>
        </table>
    </dynamics:AxSection>
    
</dynamics:AxMultiSection>
<p>
    &nbsp;    
    <dynamics:AxReportViewer runat="server" ID="SalesByRegion" MenuItemName="PriceListview" />
</p>

________________________________________________________________________________________
using System;
using System.Collections.Generic;
using Microsoft.Dynamics.Framework.Portal.UI.WebControls;
using Microsoft.Dynamics.AX.Framework.Services.Client;
using Microsoft.Dynamics.Framework.BusinessConnector.Session;
using Microsoft.Dynamics.Framework.Portal.UI.WebControls.WebParts;
using Microsoft.Dynamics.AX.Framework.Reporting.Shared;
using Microsoft.Dynamics.Framework.Portal.UI;
using BCProxy = Microsoft.Dynamics.Framework.BusinessConnector.Proxy;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.WebControls;
using Microsoft.Dynamics.Framework.Portal.UI.WebControls;
using System.Data;
using System.Collections;
using Microsoft.Dynamics.Framework.BusinessConnector.Adapter;
using Microsoft.Dynamics.AX.Framework.Portal.Data;
public partial class PriceListView : System.Web.UI.UserControl
{
     /// <summary>
    /// Web part private
    /// </summary>
    AxBaseWebPart _baseWebpart = null;
    #region Properties
    /// <summary>
    /// Webpart 
    /// </summary>
    AxBaseWebPart BaseWebpart
    {
        get
        {
            //return the basewebpart if it is not null
            if (this._baseWebpart != null)
                return this._baseWebpart;
            //get the webpart if basewebpart is null
            this._baseWebpart = AxBaseWebPart.GetWebpart(this);
            return this._baseWebpart;
        }
    }
    /// <summary>
    /// Gets the current Web Part Session.
    /// </summary>
    ISession AxSession
    {
        get
        {
            return BaseWebpart.Session;
        }
    }
    #endregion
  
    #region Events
    protected void Page_Load(object sender, EventArgs e)
    {
        string curUserId = AxSession.SessionInfo.UserId;
        bool accepted = bool.Parse(AxSession.AxaptaAdapter.CallStaticRecordMethod("UserAcceptanceTable", "exists", curUserId).ToString());
        if (accepted == false)
        {
            AxUrlMenuItem urlHomePage = new AxUrlMenuItem("Test");
            Response.Redirect(urlHomePage.Url.OriginalString, true);
        }
        if (!this.IsPostBack)
        {
           // this.setValues();
            Dictionary<string, object> parms = new Dictionary<string, object>();
            this.SalesByRegion.AddParameters(parms);
        }
    }    protected void ViewReportButton_Click1(object sender, EventArgs e)
    {
        Dictionary<string, object> parms = new Dictionary<string, object>();
       
        parms.Add("PriceListDs_BPGroup", this.tbBPGroup.Text);
        parms.Add("PriceListDs_ProdGroup", this.tbProductGroup.Text);
        parms.Add("PriceListDs_ProdCat", this.tbParentCategory.Text);
        parms.Add("PriceListDs_ItemId", this.tbModel.Text);
        parms.Add("PriceListDs_priceListView", this.DropDownListSorting.SelectedItem.Text);
        this.SalesByRegion.AddParameters(parms);
       
    }
    protected void DropDownListSorting_init(object sender, EventArgs e)
    {
        int enumNum = EnumMetadata.EnumNum(this.AxSession, "PriceListView");
        using (BCProxy.DictEnum dictEnum = new BCProxy.DictEnum(this.AxSession.AxaptaAdapter, enumNum))
        {
            int noOfElements = dictEnum.values();
            for (int counter = 0; counter < noOfElements; counter++)
            {
                this.DropDownListSorting.Items.Add(dictEnum.index2Label(counter));
            }
        }
    }
    protected void DropDownBPSelection_OkClicked(object sender, AxLookupEventArgs e)
    {
        //this.loadProdGroupDrpDown();
    }
    protected void DropDownBPSelection_Lookup(object sender, AxLookupEventArgs e)
    {
        AxLookup nameLookup = e.LookupControl;
        //TxtWarehouseCode.Text = "";
        try
        {
            AxLookup lookup = (AxLookup)sender;
            // Create the lookup dataset - we will do a lookup in the DirPartyTable table
            using (BCProxy.SysDataSetBuilder sysDataSetBuilder = BCProxy.SysDataSetBuilder.constructLookupDataSet(this.AxSession.AxaptaAdapter, TableMetadata.TableNum(this.AxSession, "EcoresCategory")))
            {
                // Set the run time generated data set as the lookup data set
                nameLookup.LookupDataSet = new Microsoft.Dynamics.AX.Framework.Portal.Data.DataSet(this.AxSession, sysDataSetBuilder.toDataSet());
            }
            // DataSet has to be init'ed before accessing the data sources
            nameLookup.LookupDataSet.Init();
            // Filter the lookup 
            using (BCProxy.Query query = nameLookup.LookupDataSet.DataSetViews[0].MasterDataSource.query())
            {
                using (BCProxy.QueryBuildDataSource qbds = query.dataSourceNo(1))
                {
                    qbds.addRange(TableDataFieldMetadata.FieldNum(this.AxSession, "EcoResCategory", "Level")).value = "2";
                    qbds.addRange(TableDataFieldMetadata.FieldNum(this.AxSession, "EcoResCategory", "ShowOnEP")).value = "Yes";
                    qbds.addOrderByField(TableDataFieldMetadata.FieldNum(this.AxSession, "EcoResCategory", "Name"));
                    qbds.orderMode = (int)OrderMode.GroupBy;
                }
            }
            // Specify the lookup fields used
            nameLookup.Fields.Add(AxBoundFieldFactory.Create(this.AxSession, nameLookup.LookupDataSetViewMetadata.ViewFields["Name"]));
            // Specify the select field
            nameLookup.SelectField = "Name";
        }
        catch (System.Exception ex)
        {
            AxExceptionCategory exceptionCategory;
            // This returns true if the exception can be handled here
            if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))
            {
                // The exception is system fatal - in this case we re-throw.                                    
                throw;
            }
        }
    }
    protected void DropDownProductBPSelection_OkClicked(object sender, AxLookupEventArgs e)
    {
        //this.loadProdGroupDrpDown();
    }
    protected void DropDownProductBPSelection_Lookup(object sender, AxLookupEventArgs e)
    {
        AxLookup nameLookup = e.LookupControl;
        //TxtWarehouseCode.Text = "";
        try
        {
            AxLookup lookup = (AxLookup)sender;
            // Create the lookup dataset - we will do a lookup in the DirPartyTable table
            using (BCProxy.SysDataSetBuilder sysDataSetBuilder = BCProxy.SysDataSetBuilder.constructLookupDataSet(this.AxSession.AxaptaAdapter, TableMetadata.TableNum(this.AxSession, "PriceMasterTable")))
            {
                // Set the run time generated data set as the lookup data set
                nameLookup.LookupDataSet = new Microsoft.Dynamics.AX.Framework.Portal.Data.DataSet(this.AxSession, sysDataSetBuilder.toDataSet());
            }
            // DataSet has to be init'ed before accessing the data sources
            nameLookup.LookupDataSet.Init();
            // Filter the lookup 
            using (BCProxy.Query query = nameLookup.LookupDataSet.DataSetViews[0].MasterDataSource.query())
            {
                using (BCProxy.QueryBuildDataSource qbds = query.dataSourceNo(1))
                {
                    qbds.addRange(TableDataFieldMetadata.FieldNum(this.AxSession, "PriceMasterTable", "BPGroup")).value = this.tbBPGroup.Text;
                    qbds.addOrderByField(TableDataFieldMetadata.FieldNum(this.AxSession, "PriceMasterTable", "ProdGroup"));
                    qbds.orderMode = (int)OrderMode.GroupBy;
                }
            }
            // Specify the lookup fields used
            nameLookup.Fields.Add(AxBoundFieldFactory.Create(this.AxSession, nameLookup.LookupDataSetViewMetadata.ViewFields["ProdGroup"]));
            // Specify the select field
            nameLookup.SelectField = "ProdGroup";
        }
        catch (System.Exception ex)
        {
            AxExceptionCategory exceptionCategory;
            // This returns true if the exception can be handled here
            if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))
            {
                // The exception is system fatal - in this case we re-throw.                                    
                throw;
            }
        }
    }
    protected void DropDownProductCatBPSelection_OkClicked(object sender, AxLookupEventArgs e)
    {
        //this.loadProdGroupDrpDown();
    }
    protected void DropDownProductCatSelection_Lookup(object sender, AxLookupEventArgs e)
    {
        AxLookup nameLookup = e.LookupControl;
        //TxtWarehouseCode.Text = "";
        try
        {
            AxLookup lookup = (AxLookup)sender;
            // Create the lookup dataset - we will do a lookup in the DirPartyTable table
            using (BCProxy.SysDataSetBuilder sysDataSetBuilder = BCProxy.SysDataSetBuilder.constructLookupDataSet(this.AxSession.AxaptaAdapter, TableMetadata.TableNum(this.AxSession, "PriceMasterTable")))
            {
                // Set the run time generated data set as the lookup data set
                nameLookup.LookupDataSet = new Microsoft.Dynamics.AX.Framework.Portal.Data.DataSet(this.AxSession, sysDataSetBuilder.toDataSet());
            }
            // DataSet has to be init'ed before accessing the data sources
            nameLookup.LookupDataSet.Init();
            // Filter the lookup 
            using (BCProxy.Query query = nameLookup.LookupDataSet.DataSetViews[0].MasterDataSource.query())
            {
                using (BCProxy.QueryBuildDataSource qbds = query.dataSourceNo(1))
                {
                    qbds.addRange(TableDataFieldMetadata.FieldNum(this.AxSession, "PriceMasterTable", "BPGroup")).value = this.tbBPGroup.Text;
                    qbds.addRange(TableDataFieldMetadata.FieldNum(this.AxSession, "PriceMasterTable", "ProdGroup")).value = this.tbProductGroup.Text;
                    qbds.addOrderByField(TableDataFieldMetadata.FieldNum(this.AxSession, "PriceMasterTable", "ProdCategory"));
                    qbds.orderMode = (int)OrderMode.GroupBy;
                }
            }
            // Specify the lookup fields used
            nameLookup.Fields.Add(AxBoundFieldFactory.Create(this.AxSession, nameLookup.LookupDataSetViewMetadata.ViewFields["ProdCategory"]));
            // Specify the select field
            nameLookup.SelectField = "ProdCategory";
        }
        catch (System.Exception ex)
        {
            AxExceptionCategory exceptionCategory;
            // This returns true if the exception can be handled here
            if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))
            {
                // The exception is system fatal - in this case we re-throw.                                    
                throw;
            }
        }
    }
    protected void DropDownItemidSelection_OkClicked(object sender, AxLookupEventArgs e)
    {
        //this.loadProdGroupDrpDown();
    }
    protected void DropDownItemidSelection_Lookup(object sender, AxLookupEventArgs e)
    {
        AxLookup nameLookup = e.LookupControl;
        //TxtWarehouseCode.Text = "";
        try
        {
            AxLookup lookup = (AxLookup)sender;
            // Create the lookup dataset - we will do a lookup in the DirPartyTable table
            using (BCProxy.SysDataSetBuilder sysDataSetBuilder = BCProxy.SysDataSetBuilder.constructLookupDataSet(this.AxSession.AxaptaAdapter, TableMetadata.TableNum(this.AxSession, "PriceMasterTable")))
            {
                // Set the run time generated data set as the lookup data set
                nameLookup.LookupDataSet = new Microsoft.Dynamics.AX.Framework.Portal.Data.DataSet(this.AxSession, sysDataSetBuilder.toDataSet());
            }
            // DataSet has to be init'ed before accessing the data sources
            nameLookup.LookupDataSet.Init();
            // Filter the lookup 
            using (BCProxy.Query query = nameLookup.LookupDataSet.DataSetViews[0].MasterDataSource.query())
            {
                using (BCProxy.QueryBuildDataSource qbds = query.dataSourceNo(1))
                {
                    qbds.addRange(TableDataFieldMetadata.FieldNum(this.AxSession, "PriceMasterTable", "BPGroup")).value = this.tbBPGroup.Text;
                    qbds.addRange(TableDataFieldMetadata.FieldNum(this.AxSession, "PriceMasterTable", "ProdGroup")).value = this.tbProductGroup.Text;
                    qbds.addRange(TableDataFieldMetadata.FieldNum(this.AxSession, "PriceMasterTable", "ProdCategory")).value = this.tbProductGroup.Text;
                    qbds.addOrderByField(TableDataFieldMetadata.FieldNum(this.AxSession, "PriceMasterTable", "ItemCode"));
                    qbds.orderMode = (int)OrderMode.GroupBy;
                }
            }
            // Specify the lookup fields used
            nameLookup.Fields.Add(AxBoundFieldFactory.Create(this.AxSession, nameLookup.LookupDataSetViewMetadata.ViewFields["ItemCode"]));
            // Specify the select field
            nameLookup.SelectField = "ItemCode";
        }
        catch (System.Exception ex)
        {
            AxExceptionCategory exceptionCategory;
            // This returns true if the exception can be handled here
            if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))
            {
                // The exception is system fatal - in this case we re-throw.                                    
                throw;
            }
        }
    }
}
#endregion

Sunday 7 December 2014

Calculate tax for sales order in axapta in ax 2012

Following Tax classes used to calculate tax for sales order in axapta

1. Taxsales
2. Tax
3. TaxRegulation.

In Tax class there is  a method CalcTax on which tax calculate for particular tax code. First tax itemgroup takes from Sales Line then its take formula then formulate evaluated by using evabuf method.

tmptaxworkTrans is a temporary table which shows temporary tax calculation.If there is tax adjustment then you need to apply tax button on salestax form to get effects. 

Corrected Tax or tax adjustment stored in field SourceRegulateAmountCur of Tmptaxworktrans and 
Regular tax  field is  sourceTaxAmountCur.

Before posting table is
 tmptax and tmptaxworktrans,tmptaxregulation

After posting Tax table is 
TaxTrans,ledgerTrans,CustInvoiceJour.

static void saleslinewisetax(Args _args)
{
    SalesTotals   salesTotals;
    SalesTable   salesTable;
    container   displayFields;
    str    totalTax, amountWithoutTax, amountInclTax;
    SalesLine   SalesLine;
    TmpTaxWorkTrans taxWorkTrans;
    tax tax;
    int    i;
    taxcode TaxName;
    salesTable = salesTable::find('PWI-0001058');
    salesTotals  =  SalesTotals::construct(salesTable, salesUpdate::All);
    salesTotals.calc();
    tax = salesTotals::getTax(salesTable);
    taxWorkTrans.setTmpData(tax.tmpTaxWorkTrans());
    while select taxWorkTrans
    {
        //info (strFmt('%1-%2-%3-%4', taxWorkTrans.TaxCode, taxWorkTrans.TaxAmount,taxWorkTrans.SourceRecId,taxWorkTrans.SourceTableId));
        I++;
        if(I==1)
        {
            TaxName = taxWorkTrans.TaxCode;
        }
        else
        {
            TaxName =TaxName+","+taxWorkTrans.TaxCode;
        }
    }
    displayFields =  salesTotals.displayFieldsCurrency(salesTotals.currencyCode());
   // Total sales tax for perticular sales order
    /*
    amountWithoutTax  = conpeek(displayFields, TradeTotals::posBalance());
    amountInclTax   = conpeek(displayFields, TradeTotals::posTotalAmount());
    totalTax    = conpeek(displayFields,TradeTotals::posTaxTotal());
    */
}

Job to find SalesTax totals – Ax2012
static void SalesTaxTotal(Args _args)
 {
 SalesTotals salesTotals;
 SalesTable salesTable;
 container displayFields;
 str totalTax, amountWithoutTax, amountInclTax;
salesTable = salesTable::find(‘000870');
 salesTotals = SalesTotals::construct(salesTable, salesUpdate::All);
salesTotals.calc();
 displayFields = salesTotals.displayFieldsCurrency(salesTotals.currencyCode());
amountWithoutTax = conpeek(displayFields, TradeTotals::posBalance());
 amountInclTax = conpeek(displayFields, TradeTotals::posTotalAmount());
 totalTax = conpeek(displayFields,TradeTotals::posTaxTotal());
 print totalTax;
 pause;
}

static void PSI_SalesTax_per_POLine(Args _args)
 {
 TaxTmpWorkTransForm     taxTmpWorkTransForm;
 PurchTotals             purchTotals;
 TaxPurch                 taxPurch;
purchTotals = PurchTotals::newPurchTable(PurchTable::find(‘PO0000004CA’));
purchTotals.calc();
 taxPurch = purchTotals.tax();
taxTmpWorkTransForm = TaxTmpWorkTransForm::construct();
 taxTmpWorkTransForm.parmTaxObject(taxPurch);
 taxTmpWorkTransForm.updateTaxShowTaxesSourceSingleLine(tableNum(PurchLine), PurchLine::find(‘PO0000004CA’,2,false).RecId, true);
 info(strFmt(‘%1',taxTmpWorkTransForm.parmTaxAmountCurTotal()));
 }

DIXF import \Export in AX 2012 R3:

http://shafeaa.blogspot.in/2015/04/install-dynamics-ax-2012-r3-step-by_12.html
https://daxusers.wordpress.com/2014/08/06/import-customer-master-data-through-data-import-export-framework-in-ax-2012/
http://us.hitachi-solutions.com/2015/06/01/data-migration-microsoft-dynamics-ax-2012-r2-r3/
http://axkanha.blogspot.in/2015/03/microsoft-dynamics-ax-2012-dixf.html
http://dynamicsaxspaingermany.blogspot.de/2013/03/dmf-create-custom-entity-for-importing.html
http://ax2012dmfdataimport.blogspot.com/2014/10/microsoft-dynamics-ax-2012-dixf.html