Scripting

  • 1.  Working with Sales Tax Exemptions & National Accou

    Posted 09-23-2016 08:14
    Working with Sales Tax Exemptions & National Accounts. I need the Exemption number to come in from the Bill To Customer & correct the sales tax calculation on the Sales Order. I have it coming into a UDF on the Sales Order Header, but having trouble getting it to populate the Exemption number on the SO Sales Tax Summary table. I am surprised this is not a Bill To/Ship To option that could be set. I've tried a few different approaches: 1. Map the UDF to the Tax Summary table & then script the UDF to overwrite the Tax Exempt field. 2. Script on the SO Header, PreTotals, to assign the Exemption to the Summary from the UDF 3. Script on the SO Sales Tax Summary to pull in & assign the UDF to the Exemption None are working. So either I have bad scripts or not placing it as the correct Event. Mostly, I am not getting errors, the script just doesn't do anything. Which method should I be using? What type of event is it? Can you only pull data into a table, or can I push data from SO Header to SO Sales Tax Summary?


  • 2.  RE: Working with Sales Tax Exemptions & National Accou

    Posted 09-23-2016 08:39
    Taxes are based on ship to location, and the bill to could be somewhere else entirely, so the tax codes aren't necessarily going to line up. My first inclination would be: - Pre-write script on the SO Sales Tax Summary table. - Get the TaxCode for the line. - Query the invoice to get the Bill-To customer. - Open the customer sales tax exemption table for that bill-to customer and TaxCode. - if you find an exemption #, write that back to the transaction's tax table line. When a script seemly does nothing, I add pop-ups to walk through progress within the script, to trace where the problem may be.


  • 3.  RE: Working with Sales Tax Exemptions & National Accou

    Posted 09-23-2016 08:59
    I will try this. I do usually put in debugging, but I was kinda lost on which way I should even attack this. Thanks!


  • 4.  RE: Working with Sales Tax Exemptions & National Accou

    Posted 09-23-2016 23:45
    Maybe the approach is to have a Pre-Validate on CustomerNo. Check if it has a Bill To parent. If so then check if it has an entry in AR Customer Ship To Exemptions table. If so create the same entry for the Sold To customer in that table. Maybe also fire that script if the default Ship To code is changed. I'm prolly missing a consideration here about how the tax code from the tax schedule plays into this but the point is when you click on Totals tab hopefully the exemption is set at that point as you would see by clicking the Tax Detail button. Alternately have a script on table Pre-Totals or Pre-Write that would verify there's a Sold To customer, the Bill To has an exemption for the Ship To then then go through each line and set the Tax Class to NT if it's TX to force no sales tax on the order (it would still be TX in CI_Item). Then write your own EXEMPT text on a UDF so you can print that on the SO form (One caveat to that is you have taxable freight, sales tax would still be calculated on the freight).


  • 5.  RE: Working with Sales Tax Exemptions & National Accou

    Posted 09-25-2016 22:22
    A couple of other things: 1) An entry in AR_CustomerShipToTaxExemptions does not require a ShipToCode even though it's part of the key. This makes sense ShipToCode isn't reqd on a sales order. 2) If you have the TaxCode in AR_CustomerShipToTaxExemptions for the BillTo parent and now need to see if Tax Schedule on the order includes that tax code: Set oTaxSch = oSession.AsObject(oSession.GetObject(""SY_SalesTaxSchedule_Svc"")) 'Down side of this is user need role permissions for View Only access to Tax Schedules 'Alternatively: Set oTaxSch = oBusObj.AsObject(oBusObj.GetChildHandle(""TaxSchedule"")) 'Use whatever works Set oTaxSchLines = oTaxSch.AsObject(oTaxSch.Lines) 'Assume TaxSchedule is MI DET and TaxCode from exemptions is MI retVal = oTaxSchLines.MoveFirst() Do Until cBool(oTaxSchLines.Eof) = True retVal = oTaxSchLines.SetBrowseIndex(""KTAXCODE"","""") 'search directly by TaxCode retVal = oTaxSchLines.SetBrowseFilter(""MI"") Found = oTaxSchLines.MoveNext() If Found = 1 Then 'woohoo now create an exemption record for the SoldTo customer Exit Do 'force an early exit End If Loop retVal = oTaxSchLines.SetBrowseIndex(""KPRIMARY"","""") retVal = oTaxSchLines.SetBrowseFilter("""")


  • 6.  RE: Working with Sales Tax Exemptions & National Accou

    Posted 09-26-2016 07:37
    I like Alnoor's idea for creating ShipTo codes on the BillTo customer. Much better from a business perspective, and more flexible for multiple tax codes. (Also, the code to get to tax schedule lines... I was wondering about how to do that!).


  • 7.  RE: Working with Sales Tax Exemptions & National Accou

    Posted 10-06-2016 11:23
    Ok...thank you for the help so far, but still stuck. A couple things. 1. There is no pre-defined Bill To/Sold To link in Customer Maintenance; they are all on-the-fly in Sales Order Entry. Its like whoever won the bid, is the Bill To, so they are not picking it until the Address Tab in SO Entry. 2. I can't put the Ship To locations on the Bill To 3. Avatax is being used 4. I have the Bill To Exemption # coming into a UDF on the SO Header already. So, I have this working using the null Ship-To code, etc. I thought I could just look at that UDF on the SO & use that data to populate the Exemption field in the SO Sales Tax tables. What I found is when I go to the Totals tab with this Pre-Write script, the debugging shows blank data from that UDF. But, if I accept the Order & then go back in, add an item, & then move to Totals tab, my UDF data shows up. I am assuming this is because there is no data written yet for the SO Header when I am in there the first time around. The only field I can link on to the SO Sales Tax Summary is Sales Order No. So, even if I wanted to look at the Bill To Customer No on the Sales Order, this is still not written yet. Its like I need to push data from SO Header into SO Sales Tax Summary instead of already being on the Tax table & pulling data in. Is this even possible?


  • 8.  RE: Working with Sales Tax Exemptions & National Accou

    Posted 10-06-2016 16:47
    Dana I would not have come closed to guessing they pick the Bill To customer on-the-fly or that they have AvaTax. It throws all ideas out the door. You're right with scripting it's not possible to populate the Exemption field in SO Order Tax Summary (or any other field in there) while you're creating the order. In fact it's not even possible with a mod unless the mod overrides the whole Sage SalesTaxCalculation() method. However that's exactly what AvaTax is already doing. Normally an M/D can ""come in 2nd"" on the same ""class override"" but in this case I'm not sure but you may need an actual AvaTax mod. There is only 1 other way I can think of which is a button script that runs after the order is saved and while no other orders are open by any users. Let's say they create 20 orders but before the print orders or pick sheets they run your button which will loop through the 20 orders and change SO Sales Tax Summary (maybe you identify the 20 by checking for a header UDF you set earlier). At the end, when you Write() via your object for SO_SalesOrderTaxSummary_bus (oTaxSum or whatever) it will automatically write-back and update the SalesTaxAmt on the order itself so don't try to SetValue() or Write() the order header. I've done this exact technique as a mod via button for Invoice Data Entry. Should work for scripting too assuming it's practical to do so.


  • 9.  RE: Working with Sales Tax Exemptions & National Accou

    Posted 10-07-2016 04:28
    Ok, thank you for the feedback! I will review this as an option. I appreciate the follow up!


  • 10.  RE: Working with Sales Tax Exemptions & National Accou

    Posted 10-07-2016 07:23
    Try talking to Avalara. Surely you are not the first one with this need?


  • 11.  RE: Working with Sales Tax Exemptions & National Accou

    Posted 10-07-2016 07:38
    I think Avalara is our only option at this point. Thanks!