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