In many D365FO implementations (especially India GST projects), we often need:
Line-wise Other Charges Tax Amount
Split into IGST, CGST, and SGST
For Posted Customer Invoice Lines (CustInvoiceTrans)
By default, D365FO stores:
-
Invoice Lines →
CustInvoiceTrans -
Charges →
MarkupTrans -
Tax →
TaxTrans
To get accurate charges tax per invoice line, we must follow proper table relation hierarchy.
π Table Relationship Structure
CustInvoiceTrans
→ MarkupTrans
→ TaxTrans
Relationship Logic:
-
MarkupTrans.TransTableId == tableNum(CustInvoiceTrans) -
MarkupTrans.TransRecId == CustInvoiceTrans.RecId -
TaxTrans.SourceTableId == tableNum(MarkupTrans) -
TaxTrans.SourceRecId == MarkupTrans.RecId
This ensures we fetch only Charges Tax, not Item Tax.
π§ Business Requirement
For each invoice line, we need:
-
IGST Amount
-
CGST Amount
-
SGST Amount
-
Converted to positive value (if negative)
π» X++ Code – Line Wise Charges Tax Calculation
CustInvoiceTrans custInvoiceTrans;
MarkupTrans markupTrans;
TaxTrans taxTrans;
AmountCur igstAmount = 0;
AmountCur cgstAmount = 0;
AmountCur sgstAmount = 0;
while select taxTrans
exists join markupTrans
where markupTrans.RecId == taxTrans.SourceRecId
&& taxTrans.SourceTableId == tableNum(MarkupTrans)
&& markupTrans.TransTableId == tableNum(CustInvoiceTrans)
&& markupTrans.TransRecId == custInvoiceTrans.RecId
{
switch (taxTrans.TaxCode)
{
case "IGST":
igstAmount += taxTrans.SourceRegulateAmountCur;
break;
case "CGST":
cgstAmount += taxTrans.SourceRegulateAmountCur;
break;
case "SGST":
sgstAmount += taxTrans.SourceRegulateAmountCur;
break;
}
}
// Convert negative to positive (Best Practice)
igstAmount = abs(igstAmount);
cgstAmount = abs(cgstAmount);
sgstAmount = abs(sgstAmount);
info(strFmt("IGST: %1, CGST: %2, SGST: %3",
igstAmount, cgstAmount, sgstAmount));
Comments
Post a Comment