Thursday, 25 August 2016

AX 2012 Paralel compilation

Reference:
1. https://msdn.microsoft.com/en-us/library/dn528954.aspx
2. http://dev.goshoom.net/en/2011/12/module-intro/

Go to start>Control Panel>Administrative tools>Microsoft Dynamics Ax 2012 Management shell

Change the default directory to AOS directory

>cd S:\ERPLITE\Server\ERPLITE_DEV\bin

Now run the below command

>.\AXBUILD.EXE XPPCOMPILEALL /S=01 /ALTBIN="C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin" /WORKERS=10

Tuesday, 22 March 2016

How to get sales/purchase tax/GST/VAT info for report?

 https://mycsharpdeveloper.wordpress.com/2015/07/03/how-to-get-salespurchase-taxgstvat-info-for-report/
If we customize Sales Invoice and Free Tax Invoice report for AX2012, we may need to get sales tax information. But how to get it. They are quite several ways to get it, and it depends only type of document you print also.
For posted Sales Invoice report
1
2
select taxTrans where taxTrans.InventTransId == _custInvoiceTrans.InventTransId;
    salesInvoiceTmp.TaxValue = taxTrans.TaxValue;
For posted Free Text Invoice report
1
2
3
4
select taxTrans
    where taxTrans.Source == TaxModuleType::FreeTxtInvoice
        && taxTrans.SourceTableId == tableNum(CustInvoiceTrans)
        && taxTrans.SourceRecId == _custInvoiceTrans.RecId;
For both Sales Invoice and Free Text Invoice report, it can be get like this also if you enable Tax Specification and you are inside SalesInvoiceDP or FreeTextInvoiceDP
1
this.getTaxValue(_taxSpec, _custInvoiceJour);
For none posted Sales Invoice / Free Text Invoice, for eg: Purchase Order confirmation or Sales Order confirmation, you can get data from TaxJournalTrans table.
1
2
3
4
5
6
7
8
TaxJournalTrans taxJournalTrans;

select sum(TaxAmount), TaxValue from taxJournalTrans
    group by TaxValue
    where taxJournalTrans.TransTableId == VendPurchOrderJour.TableId
    && TaxJournalTrans.TransRecId == VendPurchOrderJour.RecId;
//taxJournalTrans.TaxValue; //GST rate
//taxJournalTrans.TaxAmount; //GST amount
For Proforma report, you need to calculate tax using AX SalesTotals or PurchTotals class.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
static void CalcTaxJob(Args _args)
{
    TmpTaxWorkTrans             tmpTax;
    SalesTable                  salesTable;
    SalesTotals                 salesTotals; //Use PurchTotals for Purchase Order
    ;

    salesTable  = SalesTable::find('YourSalesId');
    salesTotals = SalesTotals::construct(salesTable);

    // Calculate Tax
    salesTotals.calc();

    // Load tmpTaxWorkTrans
    tmpTax.setTmpData(salesTotals.tax().tmpTaxWorkTrans());

    // Showing taxes with tax value/rate
    while select tmpTax
    {
        info( strFmt('%1 : %2 : %3' , tmpTax.TaxCode, tmpTax.showTaxValue(), tmpTax.TaxAmount));
    }
}
If you need go to until every line level, you can use
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
static void CalcTaxJob(Args _args)
{
    TaxOnItem       TaxOnItem;
    TaxGroupData    TaxGroupData;
    real            TaxAmount;
    TaxValue        TaxValue;
    SalesLine       SalesLine
    ;
    
    select firstOnly from salesLine where salesLine.SalesId == 'YourSalesId';
    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;
                        TaxAmount = (Salesline.LineAmount * TaxValue) / 100;
                    }
                }
            }
        }
    }
}
Final note is although most of the examples here are for sales side, they are all applicable to purchase side.


Sunday, 14 February 2016

Transaction Tracking System (TTS) in Dynamics Axapta

Transaction Tracking System normally referred to as TTS is used for tracking transactions. The idea is to secure the entire transaction to be committed to the database. This is vital for a relational database and even more for an ERP system.

To say, while performing an invoice posting you must ensure that this does not result in corrupt data if the system crashes. TTS secures that all database operations within a TTS loop are committed entirely or not at all committed.

Every time you are performing an insert, update or delete you should use the TTS. In fact you cannot update a record without doing it in a TTS loop. And every ttsbegin should have a ttscommit, if not provided an error will be thrown.

The below figure is to illustrate the working flow of TTS in Dynamics Ax:

Example (1):
static void DataDic_UpdateRecord(Args _args)
{
MyFirstTable myFirstTable;
;
try
{
    ttsbegin;
    select forupdate firstonly myFirstTable;
    myFirstTable.custName = "Customer updated";
    if (myFirstTable.validateWrite())
    myFirstTable.update();
    ttscommit;
}
catch(Exception::Error)
{
    ttsabort;
    throw error("@SYS93835"); //operation cancelled
}
}
Here, the first record in MyFirstTable is fetched and the field custName is changed before updating via the ttscommit.

If you need to update a record you must always fetch the record using the keyword forupdate in the TTS loop. A common mistake made when selecting forupdate is to fetch your data for update before calling ttsbegin. If you do this an error will occur.