From Tax Document You have to Use TaxDocumentLauncher Class.
this.taxData(purchReqLine,purchReqHead);
public void taxData(PurchReqLine _line, PurchReqTable _head)
{
TaxableDocumentDescriptor bundler;
ClassId bundlerId;
ITaxableDocument taxableDocument;
ITaxDocumentLine taxDocumentLine;
common transactionTable ;
ITaxableDocumentLine taxableDocumentLine;
TaxableDocumentLineObject taxableDocumentObject;
ITaxDocumentComponentLine taxDocumentComponentLine;
ITaxDocumentComponentLineEnumerator taxDocumentComponentLineEnumerator;
TaxAmount CGSTValue,CGSTAmt,SGSTValue,SGSTAmt,IGSTValue,IGSTAmt,TaxValue,TaxAmt;
if(_line)
{
transactionTable = TaxEnginePurchReqHeader::findByPurchReqLineRecId(_line.RecId);
bundler = TaxableDocumentDescriptor::getTaxDocumentdescriptor(54705, transactionTable);
taxableDocument = TaxableDocumentObject::construct(bundler);
TaxBusinessService::calculateTax(taxableDocument, false);
taxableDocumentLine = TaxableDocumentLineObject::construct(_line.TableId, _line.RecId);
if(taxableDocumentLine)
{
taxDocumentLine = taxableDocument.parmTaxDocument().findLineByOrig(
taxableDocumentLine.getTransactionLineTableId(),
taxableDocumentLine.getTransactionLineRecordId());
if (taxDocumentLine)
{
taxDocumentComponentLineEnumerator = taxDocumentLine.componentLines("GST");
while (taxDocumentComponentLineEnumerator.moveNext())
{
taxDocumentComponentLine = taxDocumentComponentLineEnumerator.current();
if (taxDocumentComponentLine.metaData().taxComponent() == "CGST")
{
CGSTAmt = taxDocumentComponentLine.getMeasure("Tax Amount").value().value();
CGSTValue = taxDocumentComponentLine.getMeasure("Rate").value().value() * 100;
}
else if (taxDocumentComponentLine.metaData().taxComponent() == "SGST")
{
SGSTAmt = taxDocumentComponentLine.getMeasure("Tax Amount").value().value();
SGSTValue = taxDocumentComponentLine.getMeasure("Rate").value().value() * 100;
}
else if (taxDocumentComponentLine.metaData().taxComponent() == "IGST")
{
IGSTAmt = taxDocumentComponentLine.getMeasure("Tax Amount").value().value();
IGSTValue = taxDocumentComponentLine.getMeasure("Rate").value().value() * 100;
}
}
}
}
}
TaxValue = IGSTValue + CGSTValue + SGSTValue;
TaxAmt = IGSTAmt + CGSTAmt + SGSTAmt;
}
IF you are using TaxGroup and TaxItemGroup::
private TaxValue getTaxPercent(TaxGroup _taxGroup, TaxItemGroup _taxItemGroup)
{
TaxGroupData taxGroupData ;
TaxOnItem taxOnItem;
TaxData taxData;
select firstonly TaxCode from taxGroupData
index hint TaxGroupIdx
where taxGroupData.TaxGroup == _taxGroup
join taxOnItem
where taxOnItem.TaxItemGroup == _taxItemGroup &&
taxOnItem.TaxCode == taxGroupData.TaxCode;
select firstonly TaxValue from taxData where taxData.TaxCode == taxGroupData.TaxCode;
return taxData.TaxValue;
}
Tax::calcTaxAmount(purchLine.TaxGroup, purchLine.TaxItemGroup, Systemdateget(), purchLine.CurrencyCode, purchLine.LineAmount, TaxModuleType::Purch);
After Invoice::
Code First:
line.CGSTRate = abs(this.TaxRate(_jour,'CGST', transLine));
line.SGSTRate = abs(this.TaxRate(_jour,'SGST', transLine));
line.IGSTRate = abs(this.TaxRate(_jour,'IGST', transLine));
line.CGST = abs(this.TaxAmount(_jour,'CGST', transLine));
line.SGST = abs(this.TaxAmount(_jour,'SGST', transLine));
line.IGST = abs(this.TaxAmount(_jour,'IGST', transLine));
protected Real TaxAmount(CustInvoiceJour invoiceJour, str _component, CustInvoiceTrans invoiceTrans)
{
TaxTrans taxTrans;
select sum(SourceRegulateAmountCur),TaxValue,SourceRecid from taxTrans
where taxTrans.Voucher == invoiceJour.LedgerVoucher
&& taxTrans.TaxCode == _component
&& taxTrans.TransDate == invoiceJour.InvoiceDate
&& taxTrans.InventTransId == invoiceTrans.InventTransId;
return abs(taxtrans.SourceRegulateAmountCur);
}
protected Real TaxRate(CustInvoiceJour invoiceJour, str _component, CustInvoiceTrans invoiceTrans)
{
TaxTrans taxTrans;
select taxTrans where taxTrans.InventTransId == invoiceTrans.InventTransId
&& taxTrans.Voucher == invoiceJour.LedgerVoucher
&& taxTrans.TaxCode == _component;
return abs(taxTrans.TaxValue);
}
Code Second:
protected Real TaxAmount(InventTransferJourLine _inventTransferJournLine,
str _component,
Amount _netAmount)
{
TaxTrans taxtrans, taxtransvalue;
select sum(SourceRegulateAmountCur),TaxValue,SourceRecid from taxtrans
where taxtrans.InventTransId == _inventTransferJournLine.InventTransID
&& taxtrans.Voucher == _inventTransferJournLine.VoucherId
&& taxtrans.TaxCode == _component;
select taxtransvalue where taxtransvalue.inventtransid == _inventTransferJournLine.InventTransID
&& taxtransvalue.Voucher == _inventTransferJournLine.VoucherId
&& taxtransvalue.TaxCode == _component;
return abs(taxtrans.SourceRegulateAmountCur);
}
protected Real TaxRate(InventTransferJourLine _inventTransferJournLine,
str _component,
Amount _netAmount)
{
TaxTrans taxtrans, taxtransvalue;
select sum(SourceRegulateAmountCur),TaxValue,SourceRecid from taxtrans
where taxtrans.InventTransId == _inventTransferJournLine.InventTransID
&& taxtrans.Voucher == _inventTransferJournLine.VoucherId
&& taxtrans.TaxCode == _component;
select taxtransvalue where taxtransvalue.inventtransid == _inventTransferJournLine.InventTransID
&& taxtransvalue.Voucher == _inventTransferJournLine.VoucherId
&& taxtransvalue.TaxCode == _component;
return abs(taxtransvalue.TaxValue);
}
Code Third:
//Tax calculations starts
taxBaseAmount = 0;
taxAmount = 0;
while select taxTrans
where taxTrans.SourceTableId == tableNum(VendInvoiceTrans) &&
taxTrans.SourceRecId == vendInvoiceTrans.RecId &&
taxTrans.Voucher == vendInvoiceJour.LedgerVoucher &&
taxTrans.TransDate == vendInvoiceJour.InvoiceDate &&
taxTrans.InventTransId == VendInvoiceTrans.InventTransId//purchLine.InventTransId
{
//taxBaseAmount = taxTrans.SourceBaseAmountCur * Tax::changeDisplaySign(taxTrans.TaxDirection);
taxAmount += taxTrans.SourceRegulateAmountCur * Tax::changeDisplaySign(taxTrans.TaxDirection);
rptTmp.TaxPercentage_Invoice = taxTrans.TaxValue;
rptTmp.TaxCode_Invoice = taxTrans.TaxCode;
}
rptTmp.TaxBaseAmount = VendInvoiceTrans.LineAmount;//taxBaseAmount;
rptTmp.TaxAmount = taxAmount;
rptTmp.TotalAmount = rptTmp.TaxBaseAmount + rptTmp.taxAmount;
//Tax calculations ends
Before Invoice::
this.taxData(PurchReqLine, PurchReqTable);
Code First:
public void taxData(PurchReqLine _line, PurchReqTable _head)
{
TmpTaxDocument tmpTax;
PurchCalcTax PurchCalcTax;
PurchReqTotals purchreqtotal;
ITaxableDocument taxableDocument;
ITaxDocumentComponentLineEnumerator lineEnumerator;
ITaxDocumentComponentLine componentLine;
TaxComponent_IN taxComponent;
ITaxDocument taxDocumentObject;
ITaxDocumentLine taxDocumentLine;
TaxAmount taxValue,taxAmount;
purchreqtotal = PurchReqTotals::construct(_head, PurchUpdate::All);
taxableDocument = TaxableDocumentObject::construct(purchreqtotal.parmTaxableDocumentDescriptor());
taxDocumentObject = TaxBusinessService::calculateTax(taxableDocument);
taxDocumentLine = taxDocumentObject.findLineBySource(_line.TableId,_line.RecId);
if(taxDocumentLine)
{
lineEnumerator = taxDocumentLine.componentLines();
while(lineEnumerator.moveNext())
{
componentLine = lineEnumerator.current();
if(taxComponent)
{
taxComponent = taxComponent + "/" + componentLine.metaData().taxComponent();
}
else
{
taxComponent = componentLine.metaData().taxComponent();
}
taxValue += componentLine.getMeasure("Rate").value().value() * 100;
taxAmount += componentLine.getMeasure("Tax Amount").value().value();
}
S3_PurchTable_Tmp.TaxCode = taxComponent;
S3_PurchTable_Tmp.TaxValue = taxValue;
S3_PurchTable_Tmp.TaxAmount = taxAmount;
}
}
Code Second:
public void taxData(PurchReqLine _line, PurchReqTable _head)
{
TmpTaxDocument tmpTax;
PurchCalcTax PurchCalcTax;
PurchReqTotals purchreqtotal;
ITaxableDocument taxableDocument;
ITaxDocumentComponentLineEnumerator lineEnumerator;
ITaxDocumentComponentLine componentLine;
ITaxDocument taxDocumentObject;
ITaxDocumentLine taxDocumentLine;
real SGSTAmt,CGSTAmt,IGSTAmt;
TaxAmount SGST, CGST, IGST;
ITaxDocumentMeasure taxMeasure;
ITaxDocumentMeasureEnumerator taxMeasureEnumerator;
ITaxDocumentMeasureValue partyTaxMeasureValue;
int i;
purchreqtotal = PurchReqTotals::construct(_head, PurchUpdate::All);
taxableDocument = TaxableDocumentObject::construct(purchreqtotal.parmTaxableDocumentDescriptor());
taxDocumentObject = TaxBusinessService::calculateTax(taxableDocument);
if (taxDocumentObject)
{
// 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)
{
componentLine = lineEnumerator.current();
partyTaxMeasureValue = taxMeasureEnumerator.current().value();
S3_PurchTable_Tmp.SGSTAmt = partyTaxMeasureValue.amountTransactionCurrency();
S3_PurchTable_Tmp.SGSTValue = componentLine.getMeasure("Rate").value().value()*100;
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)
{
componentLine = lineEnumerator.current();
partyTaxMeasureValue = taxMeasureEnumerator.current().value();
S3_PurchTable_Tmp.CGSTAmt = partyTaxMeasureValue.amountTransactionCurrency();
S3_PurchTable_Tmp.CGSTValue = componentLine.getMeasure("Rate").value().value()*100;
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)
{
componentLine = lineEnumerator.current();
partyTaxMeasureValue = taxMeasureEnumerator.current().value();
S3_PurchTable_Tmp.IGSTAmt = partyTaxMeasureValue.amountTransactionCurrency();
S3_PurchTable_Tmp.IGSTValue = componentLine.getMeasure("Rate").value().value()*100;
i=0;
break;
}
}
}
}
S3_PurchTable_Tmp.TaxAmount = S3_PurchTable_Tmp.CGSTAmt + S3_PurchTable_Tmp.SGSTAmt + S3_PurchTable_Tmp.IGSTAmt;
S3_PurchTable_Tmp.TaxValue = S3_PurchTable_Tmp.CGSTValue + S3_PurchTable_Tmp.SGSTValue + S3_PurchTable_Tmp.IGSTValue;
}
Code Third:
public void taxData(PurchReqLine _line, PurchReqTable _head)
{
ITaxDocument taxDocument;
ITaxDocumentLine taxDocumentLine;
ITaxDocumentComponentLineEnumerator componentLineEnumerator,totalcomponentLineEnumerator;
ITaxDocumentComponentLine componentLineObject;
ITaxDocumentMeasureEnumerator measureEnumerator;
TaxAmount taxAmount,taxValue;
TaxComponent_IN taxComponent;
taxDocument = TaxBusinessService::getTaxDocumentBySource(_head.TableId, _head.RecId);
taxDocumentLine = taxDocument.findLineBySource(_line.TableId,_line.RecId);
componentLineEnumerator = taxDocumentLine.componentLines();
while(componentLineEnumerator.moveNext())
{
componentLineObject = componentLineEnumerator.current();
if(taxComponent)
{
taxComponent = taxComponent + "/" + componentLineObject.metaData().taxComponent();
}
else
{
taxComponent = componentLineObject.metaData().taxComponent();
}
taxValue += componentLineObject.getMeasure("Rate").value().value() * 100;
taxAmount += componentLineObject.getMeasure("Tax Amount").value().value();
}
S3_PurchTable_Tmp.TaxCode = taxComponent;
S3_PurchTable_Tmp.TaxValue = taxValue;
S3_PurchTable_Tmp.TaxAmount = taxAmount;
}