Create a credit note from an invoice with expense lines (costs). When printing the invoice proposal, Reports\ProjInvoice, lines sometimes print as positive, but should be negative (they're credits). The invoice total is correct.
From what I can tell, this comes from method PSASendDetailLine. There are nested loops to find lines for managed invoices, tables PSAProjInvoiceDetailLine and PSAProjInvoiceDetailTrans. Within this there's a switch on the detailTrans tablenum. When it's a cost item, it retrieves ProjInvoiceCost using ProjInvoiceCost::find(tPSAProjInvoiceDetailTrans.TransId). This find does the expected select where TransId, but also adds an and on ! RefRecId. If no ProjInvoiceCost are found with RefRecId of zero, then it does a select just by TransId directly, which would mean it would find the first one availalable, in unspecified order.
When I run in debug, I am seeing it find records with the find(). The problem is that it's finding records from a different invoice. Seems to occur when Billing Dept creates a credit note to reverse an expense billing, then re-invoices it. From what I can tell, the RefRecId's are filled in to cross reference the original invoice with the reversing entry. So the one with RefRecId of zero is a third (sometimes fifth!) copy of the same line. In any case, the ProjInvoiceCost with RefRecId of zero is now the one that is a re-invoice, so a positive transaction, not the credit.
It all goes back to doing the find on ProjInvoiceCost.TransId; it's not unique. Adding RefRecId only seems to help, but what I'm seeing is it doesn't find the correct line. I need a way for PSASendDetailLine to uniquely find the correct ProjInvoiceCost records; the credit note lines do have negative LineAmounts, it's just not finding them. Anyone have any ideas?