Creating Sales Tax Code
I have a requirement to create a sales tax code within the SAP B1 database using the DI API but, to be hinest, am confused about how to do this in code. I have searched the SDK help and noted the SalesTaxCodes and SalesTaxCodes_Lines which I think I know how it fits together but what are the SalesTaxAuthorities and SalesTaxAuthorities_Lines objectes and how do they fit into the whole structure? Bascially what i am trying to do is enter the following type of data:
Tax Code: "R"
Tax Rate: 10.0%
Tax Description: "Reduced Rate VAT"
Is there an easy way of doing this?
Ok to start from scratch, the first step is to create a new sales tax jurisdiction type. I created one called Country and it has the type "1" (which I got from querying OSTT). The jusrisdiction type is like a category of tax.
Next I have to create a new sales tax jurisdiction - So I created one called USA Test with the code USA, with a base rate of 10% and it is of type 1 (country).
Dim oTax As SAPbobsCOM.SalesTaxAuthorities Set oTax = oCompany.GetBusinessObject(oSalesTaxAuthorities) oTax.Name = "USA Test" oTax.Rate = 10 oTax.Code = "USA" oTax.Type = 1 oReturn = oTax.Add If oReturn <> 0 Then oCompany.GetLastError oError, errMsg MsgBox (errMsg) Else MsgBox ("Sales Tax Jurisdiction Added") End If
This adds a new sales jurisdiction - however, if I want to use it, I now have to add a Sales Tax Code and reference this jurisdiction:
Dim oCode As SAPbobsCOM.SalesTaxCodes Set oCode = oCompany.GetBusinessObject(oSalesTaxCodes) oCode.Code = "US1" oCode.Name = "USA Region 1" oCode.Lines.STACode = "USA" oCode.Lines.STAType = "1" oReturn = oCode.Add If oReturn <> 0 Then oCompany.GetLastError oError, errMsg MsgBox (errMsg) Else MsgBox ("Sales Tax Code Added") End If
Now if you go to Administration --> Setup --> Financials --> Tax --> Sales Tax Codes and search for the Tax Code "US1", you will find it there with one line added to it (the country jurisdiction of USA).
The rates of tax of each of the SalesTaxCode_Lines for a SalesTaxCode are added together to create the overall tax rate for that code. (for example, if you want to create a Tax Code for a city in the US and the United States has a tax of 10%, the state has an additional tax of 5% and the city of 2% you will get an overall rate of 17%).
Even from reading back over this I think its a bit complicated, but I think if you play around with that code and try creating and modifying a few jurisdictions and codes it should become clearer.
This is all relevant to the USA localisation. If you are working on a localisation that does not use SalesTaxCodes Jurisdictions it is as simple as this:
Dim oCode As SAPbobsCOM.VatGroups Set oCode = oCompany.GetBusinessObject(oVatGroups) oCode.Code = "R" oCode.Name = "Reduced Rate VAT" oCode.VatGroups_Lines.Rate = 10 oCode.VatGroups_Lines.Effectivefrom = Now oReturn = oCode.Add If oReturn <> 0 Then oCompany.GetLastError oError, errMsg MsgBox (errMsg) Else MsgBox "Tax Code added" End If
Hope this is useful,
SAP Business One Forums.