Tuesday, February 20, 2024

Project intercompany invoice sales tax calculation bug in 10.0.37

 While Microsoft working on this issue, let me show you how you can fix it in the current code running on 10.0.37 or lower.

Scenario

When using the project intercompany customer invoice form in Project management and accounting module , you can create a customer invoice to bill to an intercompany customer. As the customer is intercompany, there is a legal entity (LE) associated with that customer. When posting the intercompany customer invoice, a pending vendor invoice is created in the customer’s LE with the same lines from the customer invoice.





You can see calculated Sales taxes via Sales tax button













Issue

If you try to add more lines, it will be added with line number 1, and sales taxes won't be added with this newly added line. Note: If you delete any line here and then you add more, it works fine.

This bug leads to missed taxes transactions in all TaxUncommitted, TmpTaxWorkTrans, and eventually in TaxTrans tables

Fix

Create an extension class with the following code



[ExtensionOf(classStr(ProjIntercompanyCustomerInvoiceCreator))]
final class myProjIntercompanyCustomerInvoiceCreator_Extension
{
    
    public CustInvoiceTable createInvoice()
    {
        // we need to increase the next line number to avoid duplicates in case when new lines added to initially created ones
        lineNum             = this.myGetNextLineNum();

        custInvoiceTable    = next createInvoice();

        if(origTransList.elements())
        {
            TaxUncommitted::deleteForDocumentHeader(tableNum(CustInvoiceTable), custInvoiceTable.RecId);
        }
        
        return custInvoiceTable;
    }


    public LineNum myGetNextLineNum()
    {
        CustInvoiceLine custInvoiceLine;
        
        select maxof(lineNum) from custInvoiceLine
            where custInvoiceLine.ParentRecId == custInvoiceTable.RecId;

        return custInvoiceLine.LineNum + 1;
    }

}

Friday, January 5, 2024

Check your data via SQL

 Sometimes we need to check or validate some data in a dev box. The fastest way to do that is to run a query directly in MS SQL management studio.

For example, I have hundreds legal entities and want to know in which of them I have some Purchase orders. Voila:




select
dataareaid as Company, count(RECID) as 'Number of PO'
from PURCHTABLE
group by DATAAREAID
having count(RECID) > 1