web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Get GST values for Project invoice proposal from tax document

(0) ShareShare
ReportReport
Posted on by 333

Hi,

I am trying to fetch GST tax components for Project invoice proposal (Invoice Format - User defined).

I have written the below code but , the looping seems incorrect as it is printing tax for all lines .Tax should be calculated line wise.

Not sure what I am missing.

public container NAVGetGSTTaxComponent(Common invoicejournal)
    {
        TaxDocumentComponentTransaction taxDocumentComponentTransaction;
        TaxDocumentRowTransaction taxDocumentRowTransaction;
        TaxComponent_IN taxComponent;
        TaxValue taxComponentRate;
        TaxAmount taxComponentAmount;
        ITaxableDocument                    taxableDocument;
        str  hSNOrSACCode;
        //int tabledid = _tableID;
        //Common invoicejournal;



        

        if(taxComponent == '')
        {
            ITaxDocumentLineEnumerator          taxDocumentLineEnumerator;
            ITaxDocumentComponentLineEnumerator componentLines;
            RefRecId sourceRecId;
            RefTableId sourceTableId;
            const str GST = 'GST';
            RefRecId LocalLineRecId;
            RefTableId LocalTableId;
            ProjProposalOnAcc projProposalOnAcc;
            ProjProposalRevenue projProposalRevenue;
            ProjProposalCost    projProposalCost;
            ProjProposalItem    projProposalItem;
            ProjProposalEmpl    projProposalEmpl;
            TableId                         lineTableId;
            RecId                           lineRecId;
            RefRecId proposalLineRecId;
            ITaxDocumentLine taxDocumentLine;
            ITaxDocumentComponentLine       taxDocumentComponentLine;

          
            PSAProjInvoiceContract contract = this.parmDataContract() as PSAProjInvoiceContract;
          
            ProjProposalTotals   ProjProposalTotals;
            Amount                    taxAmount;
            Amount                    taxRate;
     ProjProposalTotals  = new  ProjProposalTotals(ProjProposaljour::find( projInvoiceJour.ProposalId));
     ProjProposalJour projproposaljour = ProjProposalJour::find(projInvoiceJour.ProposalId);


            //if (invoicejournal)
            //{
                ITaxDocument taxDocumentObject ;
                taxableDocument = TaxableDocumentObject::construct(projProposalTotals.parmTaxableDocDescriptorRevenueTrans());

                taxDocumentObject = TaxBusinessService::calculateTax(taxableDocument);

                if (taxDocumentObject)
                {
                    
                    if (taxDocumentObject.getGUID())
                    {
                        taxDocumentExtension_in taxDocumentExtension = taxDocumentExtension_in::findByTaxDocument(taxDocumentObject.getGUID());
                    }
                    taxDocumentLineEnumerator = taxDocumentObject.lines();
                     
                    while (taxDocumentLineEnumerator.moveNext())
                   {
                        taxDocumentLine = taxDocumentLineEnumerator.current();
                        //taxDocumentLine = taxDocumentObject.lines();
                        componentLines = taxDocumentLine.componentLines(GST);
                       // componentLines = taxDocumentObject.componentLines(GST);
                        sourceRecId = taxDocumentLine.originSourceRecId();
                        sourceTableId = taxDocumentLine.originSourceTableId();
                        lineTableId = taxDocumentLine.sourceTableId();
                        lineRecId = taxDocumentLine.sourceRecId();
                        //LocalLineRecId = invoicejournal.RecId;
                        //lineTableId = invoiceJournal.TableId;
                        //LocalTableId = lineTableId;
                        lineTableId = invoiceJournal.tableid;

                       
                    //taxComponentAmount=0;
                    //taxDocumentComponentLine = componentLines.current();
                   
                       while(componentLines.moveNext())
                      {
                          taxComponentAmount=0;
                        taxDocumentComponentLine = componentLines.current();
                        if(taxDocumentComponentLine)
                        {
                        ITaxDocumentMeasure taxRateMeasure = taxDocumentComponentLine.getMeasure(TaxEngineModelLineMeasuresConstants::TaxRate);
                        if (taxRateMeasure)
                        {
                            taxComponentRate = taxRateMeasure.value().value();
                        }

                        ITaxDocumentMeasure taxAmountMeasure = taxDocumentComponentLine.getMeasure(TaxEngineModelLineMeasuresConstants::TaxAmount);
                        if (taxAmountMeasure)
                        {
                            taxComponentAmount = taxAmountMeasure.value().value();
                        }
                        //taxComponentRate   = taxDocumentComponentLine.getMeasure('Rate').value().value();
                         //   taxComponentAmount = taxDocumentComponentLine.getMeasure('Tax Amount').value().value();
                        taxComponent = taxDocumentComponentLine.metaData().taxComponent();
                        hSNOrSACCode = taxDocumentLine.getFieldValue(TaxEngineModelFieldsConstants::HSNCode) ? taxDocumentLine.getFieldValue(TaxEngineModelFieldsConstants::HSNCode) : taxDocumentLine.getFieldValue(TaxEngineModelFieldsConstants::SAC);
                        }
                       
                        
                       }

                   //}
               // }
                       
                    
                    }
                //}
            }
        }
        return [taxComponent, taxComponentRate, taxComponentAmount,hSNOrSACCode];
    }

 if(tmpPSAManageInvoice.taxcomponent=="")
        {
            TaxTrans taxtrans;
            TaxComponent_IN navTaxComponent;
            TaxValue        navTaxComponentRate;
            TaxAmount          navTaxComponentAmount,navTaxComponentAmountPost;
            str navhSNOrSACCode;
            [navTaxComponent, navTaxComponentRate, navTaxComponentAmount,navhSNOrSACCode] =this.NAVGetGSTTaxComponent(_cursor);


            //for posted 
            if(!navTaxComponentAmount)
            {
                while select taxtrans where taxtrans.Voucher == projInvoiceJour.LedgerVoucher && taxtrans.TransDate == projInvoiceJour.InvoiceDate
                {
                    navTaxComponent = taxtrans.TaxCode;
                    navTaxComponentRate = taxtrans.TaxValue/100;
                    navTaxComponentAmountPost =  navTaxComponentAmountPost   abs(taxtrans.TaxAmountCur);
                }

            }

            if(navTaxComponent == 'CGST')
            {
                tmpPSAManageInvoice.NAVHSNGSTComponent = strFmt('CGST & SGST - %1 %', navTaxComponentRate*100);
               tmpPSAManageInvoice.CGSTAmount = navTaxComponentAmount;
                tmpPSAManageInvoice.CGSTAmountPost = navTaxComponentAmountPost;
            }

            if(navTaxComponent == 'SGST')
            {
                tmpPSAManageInvoice.NAVHSNGSTComponent = strFmt('CGST & SGST - %1 %', navTaxComponentRate*100);
                tmpPSAManageInvoice.SGSTAmount = navTaxComponentAmount;
                tmpPSAManageInvoice.SGSTAmountPost = navTaxComponentAmountPost;
            }

            else
            {
                tmpPSAManageInvoice.NAVHSNGSTComponent = strFmt('IGST - %1 %', navTaxComponentRate*100);
                tmpPSAManageInvoice.IGSTAmount = navTaxComponentAmount;
                tmpPSAManageInvoice.IGSTAmountPost = navTaxComponentAmountPost;
            }

            tmpPSAManageInvoice.NAVHSNGSTComponent = strFmt('%1 \n %2', tmpPSAManageInvoice.HSNOrSACCode, tmpPSAManageInvoice.NAVHSNGSTComponent);
        }

Please help. If any reference , please suggest.

Thanks,

Priya

I have the same question (0)
  • Martin Dráb Profile Picture
    237,089 Most Valuable Professional on at
    RE: Get GST values for Project invoice proposal from tax document

    You'll make your (and our) life easier if you write less chaotic code. For example, most of the variables are useless - they complicate code for no reason.

    Let me simplify your navGetGSTTaxComponent() method:

    public container navGetGSTTaxComponent(Common _invoiceJournal) //TODO: Didn't you meant to use the parameter for something?
    {
    	TaxComponent_IN taxComponent;
    	TaxValue 		taxComponentRate;
    	TaxAmount 		taxComponentAmount;
    	str				hSNOrSACCode;
    	const str 		GST = 'GST';
    
    	ProjProposalTotals projProposalTotals = new ProjProposalTotals(ProjProposaljour::find(projInvoiceJour.ProposalId));
    	ProjProposalJour projproposaljour = ProjProposalJour::find(projInvoiceJour.ProposalId);
    
    	ITaxableDocument taxableDocument = TaxableDocumentObject::construct(projProposalTotals.parmTaxableDocDescriptorRevenueTrans());
    	ITaxDocument taxDocumentObject = TaxBusinessService::calculateTax(taxableDocument);
    
    	if (taxDocumentObject)
    	{
    		ITaxDocumentLineEnumerator taxDocumentLineEnumerator = taxDocumentObject.lines();
    		 
    		while (taxDocumentLineEnumerator.moveNext())
    		{
    			ITaxDocumentLine taxDocumentLine = taxDocumentLineEnumerator.current();
    			ITaxDocumentComponentLineEnumerator componentLines = taxDocumentLine.componentLines(GST);
    
    			while (componentLines.moveNext())
    			{
    				taxComponentAmount = 0;
    				
    				ITaxDocumentComponentLine taxDocumentComponentLine = componentLines.current();
    				if (taxDocumentComponentLine)
    				{
    					ITaxDocumentMeasure taxRateMeasure = taxDocumentComponentLine.getMeasure(TaxEngineModelLineMeasuresConstants::TaxRate);
    					if (taxRateMeasure)
    					{
    						taxComponentRate = taxRateMeasure.value().value();
    					}
    
    					ITaxDocumentMeasure taxAmountMeasure = taxDocumentComponentLine.getMeasure(TaxEngineModelLineMeasuresConstants::TaxAmount);
    					if (taxAmountMeasure)
    					{
    						taxComponentAmount = taxAmountMeasure.value().value();
    					}
    
    					taxComponent = taxDocumentComponentLine.metaData().taxComponent();
    					hSNOrSACCode = taxDocumentLine.getFieldValue(TaxEngineModelFieldsConstants::HSNCode)
    						? taxDocumentLine.getFieldValue(TaxEngineModelFieldsConstants::HSNCode)
    						: taxDocumentLine.getFieldValue(TaxEngineModelFieldsConstants::SAC);
    				}
    		   }
    		}
    	}
    
    	return [taxComponent, taxComponentRate, taxComponentAmount, hSNOrSACCode];
    }

    Now I see a significant problem in your code. You iterate lines, but you keep overwriting the values, therefore your method will return values just for the very last line.

  • PriyaDutta Profile Picture
    333 on at
    RE: Get GST values for Project invoice proposal from tax document

    Hi Martin,

    You are right .I am trying to add break in the 2nd while condition but the same issue is there.

    Where should I put the break or how do I iterate ?

    Can you please help showing in the code itself.

    Thanks,

    Priya

  • Martin Dráb Profile Picture
    237,089 Most Valuable Professional on at
    RE: Get GST values for Project invoice proposal from tax document

    The problem that I describe doesn't mean that you don't know how to iterate. You're iterating lines, but you ignore values from all lines except of the last line. If you want to change that, you need define what other behavior you want.

    For example, maybe you want to return a collection of values, or summarize values in some way. Or maybe the method doesn't do anything close to what you need and you need to design a different solution.

    If you know what you want and you need our help with the implement, explain the required behavior to us.

    If you're not sure what you want to get, you'll need to do more work on analysis.

  • PriyaDutta Profile Picture
    333 on at
    RE: Get GST values for Project invoice proposal from tax document

    Hi Martin,

    I want to return GST values line wise.

    So only the lines having GST values should return the values else it should return empty.

  • Martin Dráb Profile Picture
    237,089 Most Valuable Professional on at
    RE: Get GST values for Project invoice proposal from tax document

    If you want to return values for multiple lines, you need to return a collection, such as a list or a container of containers.

    I would use a list of objects. For example:

    public List navGetGSTTaxComponent(Common _invoiceJournal) //TODO: Didn't you meant to use the parameter for something?
    {
    	List taxDataList = new List(Types::Class);
    	const str GST = 'GST';
    
    	ProjProposalTotals projProposalTotals = new ProjProposalTotals(ProjProposaljour::find(projInvoiceJour.ProposalId));
    	ProjProposalJour projproposaljour = ProjProposalJour::find(projInvoiceJour.ProposalId);
    
    	ITaxableDocument taxableDocument = TaxableDocumentObject::construct(projProposalTotals.parmTaxableDocDescriptorRevenueTrans());
    	ITaxDocument taxDocumentObject = TaxBusinessService::calculateTax(taxableDocument);
    
    	if (taxDocumentObject)
    	{
    		ITaxDocumentLineEnumerator taxDocumentLineEnumerator = taxDocumentObject.lines();
    		 
    		while (taxDocumentLineEnumerator.moveNext())
    		{
    			ITaxDocumentLine taxDocumentLine = taxDocumentLineEnumerator.current();
    			ITaxDocumentComponentLineEnumerator componentLines = taxDocumentLine.componentLines(GST);
    
    			while (componentLines.moveNext())
    			{
    				ITaxDocumentComponentLine taxDocumentComponentLine = componentLines.current();
    				ITaxDocumentMeasure taxRateMeasure = taxDocumentComponentLine.getMeasure(TaxEngineModelLineMeasuresConstants::TaxRate);
    
    				if (!taxRateMeasure)
    				{
    					continue;
    				}
    
    				TaxAmount taxComponentAmount;
    				ITaxDocumentMeasure taxAmountMeasure = taxDocumentComponentLine.getMeasure(TaxEngineModelLineMeasuresConstants::TaxAmount);
    				if (taxAmountMeasure)
    				{
    					taxComponentAmount = taxAmountMeasure.value().value();
    				}
    
    				str hSNOrSACCode = taxDocumentLine.getFieldValue(TaxEngineModelFieldsConstants::HSNCode)
    					? taxDocumentLine.getFieldValue(TaxEngineModelFieldsConstants::HSNCode)
    					: taxDocumentLine.getFieldValue(TaxEngineModelFieldsConstants::SAC);
    					
    				MyTaxData taxtData = MyTaxData::construct();
    				taxtData.parmTaxComponent(taxDocumentComponentLine.metaData().taxComponent();
    				taxtData.parmTaxComponentRate(taxRateMeasure.value().value());
    				taxtData.parmTaxComponentAmount(taxComponentAmount);
    				taxtData.parmHSNOrSACCode(hsnOrSACCode);
    				
    				taxDataList.addEnd(taxtData);
    		   }
    		}
    	}
    
    	return taxDataList;
    }

  • PriyaDutta Profile Picture
    333 on at
    RE: Get GST values for Project invoice proposal from tax document

    Hi Martin,

    What is MyTaxData here ?

  • Martin Dráb Profile Picture
    237,089 Most Valuable Professional on at
    RE: Get GST values for Project invoice proposal from tax document

    I said I would use an object rather than a container, therefore this is an example of using an object. You'd simply create such a class.

    Whether you follow this design or not is up to you, but using objects rather than containers leads to code that is easier to understand and extend.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 667 Most Valuable Professional

#2
CU05031448-0 Profile Picture

CU05031448-0 584

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 554 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans