Added credit card fee to a sales order

I'm trying to calculate the extension amount of a miscellaneous charge code.  When "/CCFEE" is entered as the charge code, I want the extension amount to be the total amount multiplied by .025.

Here is my script.  I'm getting the following error when clicking on the Totals tab.

OrderAmt = 0
FeeAmt = 0
NonTaxAmt = 0
SalesTaxAmt = 0
TaxAmt = 0
FreightAmt = 0
TaxAmt = 0


ItemNumber = ""

retVal = oHeaderObj.GetValue("NonTaxableAmt", NonTaxAmt)
retVal = oHeaderObj.GetValue("TaxableAmt", TaxAmt)
retVal = oHeaderObj.GetValue("SalesTaxAmt", SalesTaxAmt)
retVal = oHeaderObj.GetValue("FrieghtAmt", FreightAmt)

retVAL = OBusobj.GetValue("ItemCode$",ItemNumber)

OrderAmt = NonTaxAmt + TaxAmt + SalesTaxAmt + FreightAmt

FeeAmt = OrderAmt * .025

if ItemNumber = "/CCFEE" then retVAL = oBusobj.setValue("ExtensionAmt", FeeAmt) end if

  • What's your script trigger?  PreTotals?  If so, there is no oHeaderObj, and you can't rely on the header totals (not calculated yet).  Since you want to include SalesTaxAmt in your base formula, you'll probably have to change your script to a button on the Totals tab, instead of a PreTotals event... restructuring the script properly, with a line loop to find the fee line.

  • in reply to Kevin M

    It's working now.  I had an incorrect event script running on the sales order header.  Once that was deleted, the script works great.

  • in reply to BShockley

    Ah... makes sense. 

    Be sure to click Totals before adding the fee line.  Header totals don't get calculated until then.

  • in reply to BShockley

    You will want to make sure your script works if changes to existing lines or freight are made or new lines are added. 

  • in reply to connex

    Good point.  Handling back-orders is also a bit complicated.

    You should also check into the legality of charging a CC fee.  Some jurisdiction prohibit such fees.

  • in reply to Kevin M

    I use a UDT to qualify states so that the administrator can keep it up to date without having to change the script. 

  • in reply to Kevin M

    Kevin,

    I found your response here and using a button on the Totals tab is exactly how I want to handle it.  I want a new Misc Charge Code line to be added every time the button is pushed.  I see the script above and I've read other posts and came up with the following script.  But nothing happens.  I know  I'm standing on the shoulders of others, but any guidance you could give will help.

    Dim retVal
    retVal = 0

    Dim AmtTaxable
    AmtTaxable = 0

    Dim AmtNonTax
    AmtNonTax = 0

    Dim AmtFreight
    AmtFreight = 0

    Dim AmtDiscnt
    AmtDiscnt = 0

    Dim InvTotal
    InvTotal = 0

    Dim CCProFee
    CCProFee = 0

    Dim sInvTotal
    sInvTotal = ""

    Dim sCCProFee
    sCCProFee = ""

    Dim Comment
    Comment = ""

    retVal = oBusObj.GetValue("TaxableAmt", AmtTaxable)
    retVal = oBusObj.GetValue("NonTaxableAmt", AmtNonTax)
    retVal = oBusObj.GetValue("FreightAmt", AmtFreight)
    retVal = oBusObj.GetValue("DiscountAmt", AmtDiscnt)

    InvTotal = Round((AmtTaxable + AmtNonTax + AmtFreight - AmtDiscnt), 2)
    sInvTotal = CStr(InvTotal)

    CCProFee = Round((InvTotal * 0.03), 2)
    sCCProFee = CStr(CCProFee)

    Comment = "Invoice Total $" & sInvTotal & vbNewLine & "CC Pro Fee $" & sCCProFee

    Dim oLines
    Set oLines = oSession.AsObject(oBusObj.Lines)

    oLines.AddLine
    oLines.SetValue "ItemCode$", "/CC PRO FEE"
    oLines.SetValue "QuantityOrdered", 1
    oLines.SetValue "ExtensionAmt", CCProFee
    oLines.SetValue "CommentText$", Comment

    oLines.Write

  • in reply to Rodney Roberts

    Is the script even running?  Check Company Maintenance for Allow External Access (necessary for scripts).

    Add MessageBox pop-ups to verify the different variables / retVal / LastErrorMsg values.  Go through things step by step and track down where things stop working as expected.  It could be something simple like a missing GL account within the Misc item... but you have to do that troubleshooting yourself.

  • in reply to Kevin M

    Kevin, You rock!  That was exactly the issue; no GL in the Misc Charge Code.  The button works just the way I wanted.  Many thanks.

  • in reply to Kevin M

    Kevin,

    Would you happen to know the function that will force a recalculation of the numbers on the Totals Tab?