Calculated Trade Discount and Sales Tax Amount

How does Sage 500 ERP calculate the trade discount and sales tax amounts? I keep getting the warning " Calculated Trade Discount Amt not the same as value passed in." after running the stored procedure, "spsoAPISalesOrdIns", and it keeps defaulting the value to 0. Any help on this would be appreciated.

Also, which stored procedures calculate these values?