How to use DocTaxCalculator class to add tax amount per line to Project, Free text and Sales invoices

By default in the standard SSRS report output tax amounts are not shown per line.

This was most likely done because adding tax amounts per line requires logic that impacts the performance of reporting execution, so please be aware of the possible performance impact.

Docentric allows you to add the tax amounts by line by extending the appropriate Docentric DSP class to use the custom DocTaxCalculator class.

Code examples:

  1. Project invoice report:
class DocPsaProjInvoiceWithLineTaxAmount extends DocPsaProjInvoiceDSP
{
    protected void addDataFieldsForLine(DocXmlRecord _addingRecord, PSAProjInvoiceTmp _currentLine)
    {
        super(_addingRecord, _currentLine);

        AmountCur taxLineAmount;
        // Populate the calculate line tax amount field  with the proper value, which does not get populated in the SSRS data provider class PSAProjInvoiceDP.
        switch (_currentLine.SourceTableId_DR)
        {
            case tableNum(ProjInvoiceEmpl):
                ProjInvoiceEmpl projInvoiceEmpl = this.projInvoiceEmpl(_currentline.SourceRecId_DR);
                taxLineAmount = DocTaxCalculator::getLineTaxAmount(tableNum(ProjInvoiceEmpl), projInvoiceEmpl.RecId);
                break;
            case tableNum(ProjInvoiceCost):
                ProjInvoiceCost projInvoiceCost = this.projInvoiceCost(_currentline.SourceRecId_DR);
                taxLineAmount = DocTaxCalculator::getLineTaxAmount(tableNum(ProjInvoiceCost), projInvoiceCost.RecId);
                break;
            case tableNum(ProjInvoiceItem):
                ProjInvoiceItem projInvoiceItem = this.projInvoiceItem(_currentline.SourceRecId_DR);
                taxLineAmount = DocTaxCalculator::getLineTaxAmount(tableNum(ProjInvoiceItem), projInvoiceItem.RecId);
                break;
            case tableNum(ProjInvoiceOnAcc):
                ProjInvoiceOnAcc projInvoiceOnAcc = this.projInvoiceOnAcc(_currentline.SourceRecId_DR);
                taxLineAmount = DocTaxCalculator::getLineTaxAmount(tableNum(ProjInvoiceOnAcc), projInvoiceOnAcc.RecId);
                break;
            case tableNum(ProjInvoiceRevenue):
                ProjInvoiceRevenue projInvoiceRevenue = this.projInvoiceRevenue(_currentline.SourceRecId_DR);
                taxLineAmount = DocTaxCalculator::getLineTaxAmount(tableNum(ProjInvoiceRevenue), projInvoiceRevenue.RecId);
                break;
            case tableNum(ProjProposalEmpl):
                ProjProposalEmpl projProposalEmpl = ProjProposalEmpl::findRecId(_currentLine.SourceRecId_DR);
                taxLineAmount = DocTaxCalculator::getProformaTaxProjectInvoiceLineAmount(this.projProposalJour(), projProposalEmpl.TableId, projProposalEmpl.RecId);
                break;
            case tableNum(ProjProposalItem):
                ProjProposalItem projProposalItem = ProjProposalItem::findRecId(_currentLine.SourceRecId_DR);
                taxLineAmount = DocTaxCalculator::getProformaTaxProjectInvoiceLineAmount(this.projProposalJour(), projProposalItem.TableId, projProposalItem.RecId);
                break;
            case tableNum(ProjProposalCost):
                ProjProposalCost projProposalCost = ProjProposalCost::findRecId(_currentLine.SourceRecId_DR);
                taxLineAmount = DocTaxCalculator::getProformaTaxProjectInvoiceLineAmount(this.projProposalJour(), projProposalCost.TableId, projProposalCost.RecId);
                break;
            case tableNum(ProjProposalOnAcc):
                ProjProposalOnAcc projProposalOnAcc = ProjProposalOnAcc::findRecId(_currentLine.SourceRecId_DR);
                taxLineAmount = DocTaxCalculator::getProformaTaxProjectInvoiceLineAmount(this.projProposalJour(), projProposalOnAcc.TableId, projProposalOnAcc.RecId);
                break;
            case tableNum(ProjProposalRevenue):
                ProjProposalRevenue projProposalRevenue = ProjProposalRevenue::findRecId(_currentLine.SourceRecId_DR);
                taxLineAmount = DocTaxCalculator::getProformaTaxProjectInvoiceLineAmount(this.projProposalJour(), projProposalRevenue.TableId, projProposalRevenue.RecId);
                break;
        }

        // Add line tax amount as calculated field.
        _addingRecord.addCalculatedField("SummaryLineTaxAmount", taxLineAmount);
    }

}
  1. Free text invoice:
class DocFreeTextInvoiceWithLineTaxAmountDSP extends DocFreeTextInvoiceReportDSP
{
    protected void addDataFieldsForLine(DocXmlRecord _addingRecord, FreeTextInvoiceTmp _currentLine)
    {
        super(_addingRecord, _currentLine);

        CustInvoiceTrans custInvoiceTrans = custInvoiceTrans::findRecId(_currentLine.JourTransRecId_DR);
        AmountCur taxLineAmount = DocTaxCalculator::getLineTaxAmount(tableNum(CustInvoiceTrans), custInvoiceTrans.RecId);

        _addingRecord.addCalculatedField('LineTaxAmount', taxLineAmount, 'Line tax amount');
    }

}
  1. Sales invoice:
class DocSalesInvoiceWithLineTaxAmountDSP extends DocSalesInvoiceReportDSP
{
    protected void addDataFieldsForLine(DocXmlRecord _addingRecord, SalesInvoiceTmp _currentLine)
    {
        super(_addingRecord, _currentLine);

        CustInvoiceTrans custInvoiceTrans = custInvoiceTrans::findRecId(_currentLine.JourTransRecId_DR);
        AmountCur taxLineAmount = DocTaxCalculator::getLineTaxAmount(tableNum(CustInvoiceTrans), custInvoiceTrans.RecId);

        _addingRecord.addCalculatedField('LineTaxAmount', taxLineAmount, 'Line tax amount');
    }

}

The high-level steps to accomplish this are:

  1. Create a new DSP class that inherits the report-specific DSP class that you want to extend (for example, DocPsaProjInvoiceDSP for Project invoice).
    You can use the code from the examples above as a starting point.
  2. Build the code.
  3. Select the newly created DSP class on the Docentric AX reports form.
  4. Continue to debug and modify the code as needed to fit the needs of your specific implementation.