Script to add CC Fee to Invoice - getting an error!

SOLVED

I know there are several posts about adding a line to an invoice to charge a fee.  I've modified a script I found either here or in a Sage scripting class, but for some reason, I can't get it to work this time.

When I put it on the Pre-Write event, it doesn't update the Invoice total after the CC Fee line is added.  When I put it on Post-Write, I get an error "' 'SY_SalesTaxClass' does not have correct permissions" and does not save the changes.  

I'm very frustrated!  I have another script that adds a line on Pre-Write, but I can't do that for this script because we need to get the totals, including the Sales Tax Amount, in order to calculate the fee.

Can anyone see what is wrong in my script, or has a suggestion to fix this?  Here it is!

CCRate= .03 : ordertotal=0 : taxable=0 : nontaxable=0 : freight=0 : discount=0

ccfee=0 : salestax=0 : found=False : sItemCode = "" : ccOrig=0

retVal = oBusObj.GetValue("FreightAmt", freight)
retVal = oBusObj.GetValue("TaxableAmt", taxable)
retVal = oBusObj.GetValue("NonTaxableAmt", nontaxable)
retVal = oBusObj.GetValue("DiscountAmt", discount)
retVal = oBusObj.GetValue("SalesTaxAmt", salestax)

msgbox "freight = " & freight
msgbox "taxable = " & taxable
msgbox "nontaxable = " & nontaxable

ordertotal = freight+taxable+nontaxable+salestax-discount

ccfee = ordertotal * CCrate

If ccfee >0 Then

'First scroll through the lines to see if the fee is already there
Set oLines = oBusObj.AsObject(oBusObj.Lines) 'get handle to invoice detail object
oLines.MoveFirst()
Do While CBool(oLines.EOF) = False
retVal = oLines.GetValue("ItemCode$", sItemCode)

If sItemCode = "/CCFEE" Then

'Fee is found, update the line
retVal = oLines.GetValue("ExtensionAmt", ccOrig)
ordertotal = ordertotal - ccOrig
msgbox "ordertotal = " & ordertotal
ccfee = ordertotal * CCrate
msgbox "cc fee " & ccfee
retVal = oLines.SetValue("ExtensionAmt", ccfee)
retWrite = oLines.Write()
found=True
If retWrite <> 0 Then
' Just fall through
Exit Do
End If 'retWrite
End If 'item code
retVal = oLines.MoveNext()
Loop
msgbox found

'Fee item is not found, add the line
If not found then
retVal = oLines.AddLine()
retVal = oLines.SetValue("ItemCode$","/CCFEE")
retVal = oLines.SetValue("ExtensionAmt", ccfee)
retVal = oLines.Write()
If retVal <>0 then
oScript.LinesAdded = 1
End If
End If 'not found

End if 'ccfee

Parents
  • 0

    Sage 100 Standard v2019.  Do I need to deactivate the procedure before I write?  I bet I do.

  • +1 in reply to hyanaga
    verified answer

    See CalculateTotals, SalesTaxRecalclation, RecalculateFreightFromSalesOrder. No need to deactivate because you can let the system write it for you as you are in a pre-write event (can work in both sales order entry and invoice data entry). Rather than update an existing line fee why not just:

    1. scan through and delete any existing fee lines
    2. recalculate sales tax
    3. if processing an invoice recalculate the freight and totals
    4. calculate your fee based on the updated totals
    5. add your fee line
    6. recalculate sales tax
    7. if processing an invoice recalculate the freight and totals

    If you ship out of state you should consider adding a UDT of states that don't allow charging a credit card fee and whether all your divisions would charge a fee. This is what has worked for my clients.

  • 0 in reply to connex

    I've only added / recalculated a line fee in a PreTotals event (getting amounts from a line loop), but that doesn't allow inclusion of tax amounts in the fee calculation.  This looks like an excellent technique to use when that is required.

  • +1 in reply to connex
    verified answer

    The SalesTaxRecalculation method appears to handle both recalculating taxes and recalculating the header totals.

    If this is on the pre-write event attached to SO_InvoiceHeader, after calling the final SalesTaxRecalculation method, you need to follow it up with a call to the CheckForCreditMemo method otherwise if the SalesTaxRecalculation method is called against a credit memo, it will mess up the sign of the totals and your postings will be all messed up.

Reply
  • +1 in reply to connex
    verified answer

    The SalesTaxRecalculation method appears to handle both recalculating taxes and recalculating the header totals.

    If this is on the pre-write event attached to SO_InvoiceHeader, after calling the final SalesTaxRecalculation method, you need to follow it up with a call to the CheckForCreditMemo method otherwise if the SalesTaxRecalculation method is called against a credit memo, it will mess up the sign of the totals and your postings will be all messed up.

Children