x++ code to calculate the cgst and sgst amount for a particular invoice in a sales order
The code below is calculating for all invoices in a sales order. But not for a single invoice . Please help.
private void calc_GST(SalesId _invoiceId)
{
TmpTaxDocument tmpTax;
SalesCalcTax PurchCalcTax;
SalesTotals salesTotals;
ITaxableDocument taxableDocument;
ITaxDocumentComponentLineEnumerator lineEnumerator;
ITaxDocument taxDocumentObject;
ITaxDocumentMeasure taxMeasure;
ITaxDocumentMeasureEnumerator taxMeasureEnumerator;
ITaxDocumentMeasureValue partyTaxMeasureValue;
int i;
salesTotals = SalesTotals::construct(SalesTable::find(_invoiceId));
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));
}
}