GST Tax Calculation for all formats (SO,PO Confirmation & Invoice) for AX2012,AX2009

Recently many (IND Localization) requirement which needs to print Total Tax Amount in Sales order, Purchase Order Confirmation Report After India GST Update.

Along with that we need to print Tax Amount based on Tax Type (GST ,Custom Duty) & Tax components (i.e CGST, SGST ,IGST etc).

Below is the Job to get Tax amount details based on Tax Type & Tax component for a given Sales Order.

static void GSTTaxCalculation(Args _args)
{
    TmpTaxDocument                      tmpTax;
    PurchCalcTax                        PurchCalcTax;
    SalesTotals                         salesTotals;

    ITaxableDocument                    taxableDocument;
    ITaxDocumentComponentLineEnumerator lineEnumerator;
    ITaxDocument                        taxDocumentObject;
    real                                taxTotalGTE,taxtotal,SGST,CGST,IGST;
    ITaxDocumentMeasure                 taxMeasure;
    ITaxDocumentMeasureEnumerator       taxMeasureEnumerator;
    ITaxDocumentMeasureValue            partyTaxMeasureValue;
    int                                 i;

    salesTotals = SalesTotals::construct(SalesTable::find("SO-XXXXXX"));
    taxableDocument = TaxableDocumentObject::construct(salesTotals.parmTaxableDocumentDescriptor());
    taxDocumentObject = TaxBusinessService::calculateTax(taxableDocument);

    if (taxDocumentObject)
    {
        taxTotalGTE = taxDocumentObject.getTotalTax().amountTransactionCurrency();

        // Calculation of Tax amount for Tax type GST and Tax component SGST
        lineEnumerator = taxDocumentObject.componentLines("GST","SGST");
        while (lineEnumerator.moveNext())
        {
            taxMeasureEnumerator = lineEnumerator.current().measures();
            while (taxMeasureEnumerator.moveNext())
            {
                i++;
                if (i == 3)
                {
                    partyTaxMeasureValue = taxMeasureEnumerator.current().value();
                    SGST += partyTaxMeasureValue.amountTransactionCurrency();
                    i=0;
                    break;
                }
            }
        }

        // Calculation of Tax amount for Tax type GST and Tax component CGST
        lineEnumerator = taxDocumentObject.componentLines("GST","CGST");
        while (lineEnumerator.moveNext())
        {
            taxMeasureEnumerator = lineEnumerator.current().measures();
            while (taxMeasureEnumerator.moveNext())
            {
                i++;
                if (i == 3)
                {
                    partyTaxMeasureValue = taxMeasureEnumerator.current().value();
                    CGST += partyTaxMeasureValue.amountTransactionCurrency();
                    i=0;
                    break;
                }
            }
        }
        
        // Calculation of Tax amount for Tax type GST and Tax component IGST
        lineEnumerator = taxDocumentObject.componentLines("GST","IGST");
        while (lineEnumerator.moveNext())
        {
            taxMeasureEnumerator = lineEnumerator.current().measures();
            while (taxMeasureEnumerator.moveNext())
            {
                i++;
                if (i == 3)
                {
                    partyTaxMeasureValue = taxMeasureEnumerator.current().value();
                    IGST += partyTaxMeasureValue.amountTransactionCurrency();
                    i=0;
                    break;
                }
            }
        }   
    }

    info( strFmt("Total GST value of sales order : %1 " , taxTotalGTE));
    if(IGST)
    {
        info( strFmt("Line IGST value of sales order : %1 " , IGST));
    }
    else
    {
        info( strFmt("Line SGST value of sales order : %1 " , SGST));
        info( strFmt("Line CGST value of sales order : %1 " , CGST));
    }
}

I have done modifications and posted here in this group.

Source Code Courtesy:

https://siddarthax.wordpress.com/2017/06/27/tax-amount-based-on-tax-component-for-a-sales-order-in-ax-2012-r3-after-india-gst-update/

 

Regards,

Arunachalam MR

MS Dynamics AX Developer.

  • Thanks Arun,

    I am asking the Tax calculation for Purchase Order not for Sales Order or Purchase Invoice.
    But, you have given for Sales Order and I am thinking that you have given for AX 2012. I am requesting for Ax 2009.

    Regards,
    G.Rajkumar
  • In reply to Rajkumar Govindan:

    I have given for both :) For Purchase Order, u replace the sales objects into purchase. and it will work for 2009 also.

     

    Regards,

    Arun

  • In reply to Arunachalam MR:

    Thanks,

    Finally, found the solution using this code.

    Regards,
    G.Rajkumar
  • In reply to Arunachalam MR:

    hello arunachalam,

    i have used same code for purchase order but system will show the error, kindly read the given bellow code and whare is bugs kindly inform.

    error is " Error executing code: PurchTotals object not initialized.



    (C)\Classes\PurchTotals\parmTaxableDocumentDescriptor
    (C)\Jobs\GSTTaxCalculation - line 17
    "


    static void GSTTaxCalculation(Args _args)
    {
    TmpTaxDocument tmpTax;
    PurchCalcTax PurchCalcTax;
    //SalesTotals salesTotals1;
    purchtotals purchtotals1;
    ITaxableDocument taxableDocument;
    ITaxDocumentComponentLineEnumerator lineEnumerator;
    ITaxDocument taxDocumentObject;
    real taxTotalGTE,taxtotal,SGST,CGST,IGST;
    ITaxDocumentMeasure taxMeasure;
    ITaxDocumentMeasureEnumerator taxMeasureEnumerator;
    ITaxDocumentMeasureValue partyTaxMeasureValue;
    int i;

    purchtotals1 = purchtotals::construct(purchtable::find('00136646_052'));
    taxableDocument = TaxableDocumentObject::construct(purchtotals1.parmTaxableDocumentDescriptor());
    taxDocumentObject = TaxBusinessService::calculateTax(taxableDocument);

    if (taxDocumentObject)
    {
    taxTotalGTE = taxDocumentObject.getTotalTax().amountTransactionCurrency();

    // Calculation of Tax amount for Tax type GST and Tax component SGST
    lineEnumerator = taxDocumentObject.componentLines('GST','SGST');
    while (lineEnumerator.moveNext())
    {
    taxMeasureEnumerator = lineEnumerator.current().measures();
    while (taxMeasureEnumerator.moveNext())
    {
    i++;
    if (i == 3)
    {
    partyTaxMeasureValue = taxMeasureEnumerator.current().value();
    SGST += partyTaxMeasureValue.amountTransactionCurrency();
    i=0;
    break;
    }
    }
    }

    // Calculation of Tax amount for Tax type GST and Tax component CGST
    lineEnumerator = taxDocumentObject.componentLines('GST','CGST');
    while (lineEnumerator.moveNext())
    {
    taxMeasureEnumerator = lineEnumerator.current().measures();
    while (taxMeasureEnumerator.moveNext())
    {
    i++;
    if (i == 3)
    {
    partyTaxMeasureValue = taxMeasureEnumerator.current().value();
    CGST += partyTaxMeasureValue.amountTransactionCurrency();
    i=0;
    break;
    }
    }
    }

    // Calculation of Tax amount for Tax type GST and Tax component IGST
    lineEnumerator = taxDocumentObject.componentLines('GST','IGST');
    while (lineEnumerator.moveNext())
    {
    taxMeasureEnumerator = lineEnumerator.current().measures();
    while (taxMeasureEnumerator.moveNext())
    {
    i++;
    if (i == 3)
    {
    partyTaxMeasureValue = taxMeasureEnumerator.current().value();
    IGST += partyTaxMeasureValue.amountTransactionCurrency();
    i=0;
    break;
    }
    }
    }
    }

    info( strFmt('Total GST value of sales order : %1 ' , taxTotalGTE));
    if(IGST)
    {
    info( strFmt('Line IGST value of sales order : %1 ' , IGST));
    }
    else
    {
    info( strFmt('Line SGST value of sales order : %1 ' , SGST));
    info( strFmt('Line CGST value of sales order : %1 ' , CGST));
    }
    }
  • In reply to Forever:

    we are using microsoft dynamics ax 2009
  • In reply to Rajkumar Govindan:

    dear can you give me code for purchase order.
  • In reply to Forever:

    use purchTotals = PurchTotals::newPurchTable(purchTable);

    Revert back if any issues
  • In reply to Arunachalam MR:

    thanks arunachalam,

    this is the total purchase order gst display.
    we need to calculate after purchase order confirmation and item wise. We are preparing the purchase order with multiple line item with different hsn no.

    I want to print gst value in purchase order report item line wise. Please please help me.
    regards,

    vinay
  • In reply to Forever:

    Hi Arunachalam,

    your code is very helpful. i have small query..How to get TaxRate each component wise ...help me

    Thanks

  • In reply to Kumar:

    just use the formulae,
    i.e., ( taxamount / base amount ) * 100

    you will get the tax rate. you can use this logic accordingly in your code.
  • In reply to Forever:

    Hi Vinay,

    The same code only,
    dynamicsuser.net/.../490271

    just remove the summing
    actual:
    CGST += partyTaxMeasureValue.amountTransactionCurrency();
    Replace with:
    CGST = partyTaxMeasureValue.amountTransactionCurrency();

    remove the summation on every loop.

    just debug the code and change accordingly in all applicable places.
  • In reply to Forever:

    void GSTItem_TaxCalculation()
    {
    TmpTaxDocument tmpTax;
    PurchCalcTax PurchCalcTax;
    SalesTotals salesTotals;
    PurchTotals purchTotals;
    ITaxableDocument taxableDocument;
    ITaxDocumentComponentLineEnumerator lineEnumerator;
    ITaxDocument taxDocumentObject;
    real taxTotalGTE,taxtotal,SGST,CGST,IGST;
    ITaxDocumentMeasure taxMeasure;
    ITaxDocumentMeasureEnumerator taxMeasureEnumerator;
    ITaxDocumentMeasureValue partyTaxMeasureValue;
    int j,Line_loop;
    ;

    // SGST_Value = 0; CGST_Value = 0; IGST_Value = 0;
    purchTotals = PurchTotals::POconstruct(PurchTable::find(vendPurchOrderJour.PurchId));
    taxableDocument = TaxableDocumentObject::construct(purchTotals.parmTaxableDocumentDescriptor());
    taxDocumentObject = TaxBusinessService::calculateTax(taxableDocument);

    if (taxDocumentObject)
    {
    taxTotalGTE = taxDocumentObject.getTotalTax().amountTransactionCurrency();

    // Calculation of Tax amount for Tax type GST and Tax component SGST
    Line_Loop = 0;
    lineEnumerator = taxDocumentObject.componentLines("GST","SGST");
    while (lineEnumerator.moveNext())
    {
    Line_Loop++;
    taxMeasureEnumerator = lineEnumerator.current().measures();
    while (taxMeasureEnumerator.moveNext())
    {
    j++;
    if (j == 3)
    {
    partyTaxMeasureValue = taxMeasureEnumerator.current().value();
    SGST_Arr[Line_Loop] = partyTaxMeasureValue.amountTransactionCurrency();
    j=0;
    break;
    }
    }
    }

    // Calculation of Tax amount for Tax type GST and Tax component CGST
    Line_Loop = 0;
    lineEnumerator = taxDocumentObject.componentLines("GST","CGST");
    while (lineEnumerator.moveNext())
    {
    Line_Loop++;
    taxMeasureEnumerator = lineEnumerator.current().measures();
    while (taxMeasureEnumerator.moveNext())
    {
    j++;
    if (j == 3)
    {
    partyTaxMeasureValue = taxMeasureEnumerator.current().value();
    CGST_Arr[Line_Loop] = partyTaxMeasureValue.amountTransactionCurrency();
    j=0;
    break;
    }
    }
    }

    // Calculation of Tax amount for Tax type GST and Tax component IGST
    Line_Loop = 0;
    lineEnumerator = taxDocumentObject.componentLines("GST","IGST");
    while (lineEnumerator.moveNext())
    {
    Line_Loop++;
    taxMeasureEnumerator = lineEnumerator.current().measures();
    while (taxMeasureEnumerator.moveNext())
    {
    j++;
    if (j == 3)
    {
    partyTaxMeasureValue = taxMeasureEnumerator.current().value();
    IGST_Arr[Line_Loop] = partyTaxMeasureValue.amountTransactionCurrency();
    j=0;
    break;
    }
    }
    }
    }
    }
    Array has to be declare in the classdeclaration itself.

    You have to create the below method in the PurchTotals class.

    static PurchTotals POconstruct(Common _purchTable,
    PurchUpdate _specQty = PurchUpdate::All,
    AccountOrder _sumBy = AccountOrder::None,
    ParmId _parmId = '',
    PurchId _sumPurchId = '',
    DocumentStatus _documentStatus = DocumentStatus::None)
    {
    PurchTable purchTable;
    ;
    if (_purchTable.TableId)
    {
    if (_purchTable.TableId == tablenum(PurchParmTable))
    {
    purchTable = _purchTable.purchTable();
    }
    else
    {
    purchTable = _purchTable;
    }
    if (_parmId == '')
    return new PurchTotals_Trans(_purchTable, _specQty);
    }
    Else
    {
    return null;
    }
    }
  • In reply to Forever:

    Hi Forever,

    i need also tax caluclation item wise after PO confirmation . help me.

    Thanks,
  • In reply to Kumar:

    Hi Kumar,

    U can use the above code for item wise calculation.

    Regards,
    G.Rajkumar
Related
Recommended