How to calculate GST for Purchase order Confirmation


Description: How to calculate the GST taxes on purchase order confirmation. Here i am sharing some code to get Taxes details (IGST/CGST/SGST) in AX.

static void GSTForPOLineWise(Args _args)
{
    vendPurchOrderJour                  vendPurchOrderJour;
    PurchLineAllVersions                ObjPurchLineAllVersions;
    ITaxDocument                        taxDocument;
    ITaxDocumentComponentLineEnumerator componentLineEnumerator;
    ITaxDocumentComponentLine           componentLineObject;
    ITaxDocumentMeasureEnumerator       measureEnumerator;

    ITaxDocumentLine                    line;
    ITaxDocumentLineEnumerator          lineEnumerator;

    TaxAmount                           taxAmount,taxValue;
    TaxComponent_IN                     taxComponent;
    ;

    vendPurchOrderJour = vendPurchOrderJour::findRecId(VendPurchOrderJour::findByPurchId("PurchaseOrderId").RecId);
    taxDocument = TaxBusinessService::getTaxDocumentBySource(vendPurchOrderJour.TableId, vendPurchOrderJour.RecId);
    //Tax Document not null,GST Apply start
    if(taxDocument != null)
    {
        componentLineEnumerator = taxDocument.componentLines();
        lineEnumerator = taxDocument.lines();
        //Tax Document not null,GST Apply start-1
        if (taxDocument)
        {
            //lineEnumerator for Current line taxDocument start
            lineEnumerator = taxDocument.lines();
            while(lineEnumerator.moveNext())
            {
                //Getting Current line RecId for GST start
                line = lineEnumerator.current();
                line.setTaxDocument(taxDocument);
                if(line.originSourceRecId() != 0 && line.getInvoiceTax().value() != 0)
                {
                    //componentLineEnumerator for Getting GST Rate,Amount start
                    while(componentLineEnumerator.moveNext())
                    {
                        componentLineObject = componentLineEnumerator.current();
                        taxComponent = componentLineObject.metaData().taxComponent();
                        //GST Calculation start
                        if(taxComponent == "CGST")
                        {
                            //info(strFmt("%1",VendPackingSlipTrans::findInventTransId_RU(PurchLine::findRecId(line.originSourceRecId()).InventTransId).LineNum));
                            taxValue = componentLineObject.getMeasure("Rate").value().value() * 100;
                            taxAmount = componentLineObject.getMeasure("Tax Amount").value().value();

                            info(strFmt("Component %1 ,Rate %2, Amount%3, RecId %4, ItemId %5",taxComponent,taxValue,taxAmount,VendPackingSlipTrans::findInventTransId_RU(PurchLine::findRecId(line.originSourceRecId()).InventTransId).RecId,VendPackingSlipTrans::findInventTransId_RU(PurchLine::findRecId(line.originSourceRecId()).InventTransId).ItemId));
                        }
                        if(taxComponent == "SGST")
                        {
                            //info(strFmt("%1",VendPackingSlipTrans::findInventTransId_RU(PurchLine::findRecId(line.originSourceRecId()).InventTransId).LineNum));
                            taxValue = componentLineObject.getMeasure("Rate").value().value() * 100;
                            taxAmount = componentLineObject.getMeasure("Tax Amount").value().value();

                            info(strFmt("Component %1 ,Rate %2, Amount%3, RecId %4, ItemId %5",taxComponent,taxValue,taxAmount,VendPackingSlipTrans::findInventTransId_RU(PurchLine::findRecId(line.originSourceRecId()).InventTransId).RecId,VendPackingSlipTrans::findInventTransId_RU(PurchLine::findRecId(line.originSourceRecId()).InventTransId).ItemId));
                            break;
                        }
                        if(taxComponent == "IGST")
                        {
                            //info(strFmt("%1",VendPackingSlipTrans::findInventTransId_RU(PurchLine::findRecId(line.originSourceRecId()).InventTransId).LineNum));
                            taxValue = componentLineObject.getMeasure("Rate").value().value() * 100;
                            taxAmount = componentLineObject.getMeasure("Tax Amount").value().value();

                            info(strFmt("Component %1 ,Rate %2, Amount%3, RecId %4, ItemId %5",taxComponent,taxValue,taxAmount,VendPackingSlipTrans::findInventTransId_RU(PurchLine::findRecId(line.originSourceRecId()).InventTransId).RecId,VendPackingSlipTrans::findInventTransId_RU(PurchLine::findRecId(line.originSourceRecId()).InventTransId).ItemId));
                            break;
                        }
                        //GST Calculation end
                    }
                    //componentLineEnumerator for Getting GST Rate,Amount end
                }
                //Getting Current line RecId for GST end
            }
            //lineEnumerator for Current line taxDocument end
        }
        //Tax Document not null,GST Apply end-1
    }
    //Tax Document not null,GST Apply end
}

Related Posts

Previous
Next Post »

Thanks for comments.....