This is more of an FYI. I have a solution but was wondering if anyone else ran into this. Hard to describe this.
For v2020.2 Advanced, a portion of a Header PreWrite script conditionally inserts misc item (type 5) lines as surcharges in S/O Invoice Data Entry the charge amt. It uses InsertLine not AddLine. In manual entry it works fine. A typical invoice has 5 regular items, 4 of which are subject to surcharge and so 4 misc item lines are inserted
after each regular item for a total of 9. Prior to invoicing, they use Shipping Data Entry along with Starship and scanning with Scanco WMS . However, I can dupe issue on my system v2019.4 Standard with just Shipping and Invoice Data Entry.
So everything was fine until they ran an existing V/I job that updates Invoice Date and Ship Date on many batches/invoices. The Data tab only has BatchNo, InvoiceNo, InvoiceDate, and ShipDate. No line fields. The import fires off the PreWrite script which is by design, to add or recalc the surcharges. This is important because it is the primary means to get the surcharges in there to begin with. Due to conflicts in Shipping (Starship, Scanco scanning, and the infernal Pkg Tracking feature which has never been improved since invented), I'm not firing off the script there. Note if it was misc charge (type 3) lines, I could definitely run in Shipping w/o issue.
The problem is after import if you review these invoices, the Lines total is correct and you see the surcharge lines. But the Nontaxable Amt and Taxable Amt do not reflect that and stay unchanged. So it is Out of Balance (OOB). But if I make a quick change to the invoice (e.g. set the header comment) and save, it causes script to fire off again and recalc, which corrects the OOB.
** The problem is forever fixed by moving the script to Pre-Totals but it introduced a new problem with V/I job as since there are no line fields, it won't fire off Pre-Totals. So I added some Perform Logic on Before Write of Header to just AddLine() and Delete() so the script would fire off. Also for the 1000s of OOB invoices that were exactly off by the amount of the surcharge, I created a button script utility to find the OOBs and then send an AddLine() and Delete() so the main script would get triggered to fix those.
Earlier this year for S/O Entry, as you know, there were critical OOBs that were occurring in v2019 - 2021 for which there was a hotfix. I did check to see if that fix (Browse Filter reset) was needed. It turns out that condition is not present but I added the fix code anyway to Inv Data Entry as a test and it made no difference.
Here is the snippet. It uses InsertLine with an "A" (A=after, B=before) instead of AddLine b/c I need to specifically place the misc item after the item code. AddLine always adds a new line at the bottom. I wonder if the problem doesn't occur with AddLine.
If nAmtToAdd <> 0 Then
r=oScript.DebugPrint("TypeOfLine=1 so about to InsertLine for Item Code: " & sItemCode)
rV = oLines.InsertLine(sLineSeqNo,"A")
rV = oLines.SetValue("ItemCode$", sMiscCode)
rV = oLines.SetValue("QuantityOrdered", nQO) 'To avoid hard stop of Qty Shipped exceeds Qty Ordered message
rV = oLines.SetValue("QuantityShipped", nQS)
rV = oLines.SetValue("QuantityBackordered", nQBO)'If nQBO>0 system will use this for ExtensionAmt calc
rV = oLines.SetValue("UnitPrice", nItemSurchargeUnitAmt)
rW = oLines.Write() : r=oScript.DebugPrint("rW after InsertLine for TypeOfLine=1 = " & rW)
If rW = 0 Then
sMsg = "oLines.Write failed on InsertLine-A for TypeOfLine=1 with " & oLines.LastErrorMsg
r = oScript.DebugPrint(sMsg)
End If
End If 'check if nAmtToAdd>0
------------------------------
Alnoor Cassim
Email:
alnoor@asifocus.comPh: 949-689-9887
Orange County, CA
------------------------------