Ben, the code you gave me is doing funky stuff. On an invoice with a subtotal of $100.00 and a discount of 5%, the discount amount becomes $10,307,921.51, for an invoice total of $10,308,021.51.
While my boss would like to see such an invoice going out I don't think the customer would be too happy.
I made the following changes and the numbers on the screen
appear correct:
// Calculates the discount amount
Subroutine CalculateCustomerDiscount()
var vPosDiscAmt as Double
var vDiscountUnrounded as Money
IF Details_Customer_Discount_Percentage > 0
THEN
{
vPosDiscAmt = (@ToNumber(Subtotal) * (Details_Customer_Discount_Percentage/100))
vDiscountUnrounded = (0 - vPosDiscAmt)
Details_Discount_Amount = @Round(vDiscountUnrounded, 2)
// if @error then WriteLn("Error calculating discount amount")
}
ELSE
IF (@ISBLANK(Details_Customer_Discount_Percentage) OR Details_Customer_Discount_Percentage = 0)
THEN
{
CLEAR(Details_Discount_Amount)
IF (@ISBLANK(Details_Discount_Amount) AND Details_Customer_Discount_label = "CUSTOMER DISCOUNT")
THEN
{
CLEAR(Details_Customer_Discount_label)
}
}
End Subroutine
I also put a statement elsewhere in my programming to round my grand total every time it is calculated. I'll need to run some reports to see if this is working. It's early in the day yet so I'll be experimenting for a while before you see this, but when you do, if there's something else I should be doing please let me know. Thanks for your help.