Conditional Actions / Tax miscalculation - New rates effective 10/1/2010

Project:Ubercart Contributions
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description
Project: 
Ubercart

With latest Ubercart 2.X I set up a California Sales tax and went to CA to select California as State it applies to. I then went and checked out with Alaska state selected in delivery area and it returned the California sales tax.

Update:

I can repeat on multiple installs and a clean install, it only happens with two conditions and the "OR" statement as shown on the last image. The use case i am trying for is all of California charged Tax except certain zip codes.

So my first condition is anywhere in california true, and the second is these zip codes false.

Version: 
Ubercart 2.x-dev
PreviewAttachmentSize
California Sales Tax .jpgCalifornia Sales Tax .jpg43.06 KB
Checkout .jpgCheckout .jpg48.06 KB
Review order.jpgReview order.jpg15.96 KB
Two conditions.jpgTwo conditions.jpg56.84 KB
Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Conditional Actions / Tax miscalculation

Hey Tim, I'll be sure to document the use of the condition group operator well when I document the UI. It looks to me like you need the operator to be AND instead of OR. Think about the following statement:

If
  The delivery state is California
OR
  The delivery zip code is not 949**
Then
  Charge the tax.

So, for Alaska, it doesn't pass the first condition, but it does pass the second because the zip is not a 949** zip. If you turned it to AND, then the zip condition would never even be evaluated since the state isn't California.

Hope that helps.

thill's picture
Offline
Joined: 01/25/2008
Juice: 815
Ryan, Thank you, That solved
Assigned to:Ryan» thill

Ryan,

Thank you, That solved the issue, as you can see by the time stamp of 2am I was not thinking clearly. Plus the addition of these stupid California sales tax by zip codes are driving me to the nut house.

dougliser's picture
Offline
Joined: 05/05/2009
Juice: 2
Configuring Those Nasty California County Tax Rates
Assigned to:thill» dougliser

We've got a physical presence in Marin County, CA. That means that the (post 4/1/2009) tax rate for Marin is 9.0% while the rest of California is 8.25%.
I'm new to setting up Ubercart and found it very confusing. When I finally found out how to configure the conditions,
I realized that I would need a pile of conditions to take care of all the zip codes in the county.

Here's what I did:
Added two tax entries, one for CA and one for CA-Marin.

The condition for CA-Marin is PHP code:

if(in_array(substr(trim($order->delivery_postal_code),0,5),array('94920','94924','94925','94976','94929','94930','94978','94933','94904','94937','94914','94938','94939','94977','94940','94941','94942','94946','94945','94947','94948','94949','94998','94950','94956','94957','94960','94979','94963','94964','94974','94901','94903','94912','94913','94915','94965','94966','94970','94971','94973'))) return (TRUE); else return (FALSE);

For the CA tax, we just need to add a condition for state is California AND custom PHP code:

if(in_array(substr(trim($order->delivery_postal_code),0,5),array('94920','94924','94925','94976','94929','94930','94978','94933','94904','94937','94914','94938','94939','94977','94940','94941','94942','94946','94945','94947','94948','94949','94998','94950','94956','94957','94960','94979','94963','94964','94974','94901','94903','94912','94913','94915','94965','94966','94970','94971','94973'))) return (FALSE); else return (TRUE);

This way you get a single tax line CA, CA-Marin, or no tax.

Someone should do a module for configuring California counties.

Hope this helps!

copperIT's picture
Offline
Joined: 11/24/2008
Juice: 25
CA Sales Tax - 13 different Rates
Assigned to:dougliser» copperIT

I'm afraid that CA Sales Tax is even more confusing than described here. While the state has an 8.25% sales tax, individual CITIES have their own which must be added on top of the 8.25%.

I'm building a site for a Book Store in CA, and our Controller says that we need to collect sales tax based on the delivery location. So if the item is shipped to a city in CA, we need to collect the State Sales Tax PLUS any additional local sales tax.

The state Board of Equalization has a link (http://www.boe.ca.gov/sutax/pam71.htm) to a table listing the 1773 cities in CA and their rates (go to the bottom of the page to find the link to the excel or cvs doc).

I grabbed the spreadsheet and sorted it by Tax Rate, and there were 13 different rates. So I used the code from the post above to set up separate tax rates based on the delivery city of the order. Note that you can't use zip code, because some CA towns are small enough to share a zip with a neighbor, who has a different rate (example Sebastopol, CA is 9.25% and Freestone, CA is 9.00%, both have 95472 as zip code).

To set up the Tax Rate, I would set up a rate where the first condition was that the shipping address was in California. Then I set up a second condition using PHP code. Here's a sample of the code that gets loaded into the text field:

////////////////////////////////////////////////
// The following CA cities have a tax rate of
// 8.875% effective 4.1.2009, per the CA
// Board Of Equalization

$cities = array(
'Ceres',
'Nevada City',
'Truckee'
);

if (in_array($order->delivery_city, $cities)) return (TRUE); else return (FALSE);

So there's a rate for every rate ABOVE the 8.25%, then a final one for the 8.25 that lists all the cities with HIGHER rates, and essentially says that if the delivery city is not in the list of higher paying cities, just charge the base rate. (hint to avoid paying full tax, just write 'Loos Angles' in the city field).

I've attached a .txt file with each of the php code snippets that get dropped in.

I'm sure there's a better way to do this, but I'm in a hurry.

-dave.

AttachmentSize
uc_CA_salestax.txt 39.11 KB
2440media's picture
Offline
Joined: 03/12/2009
Juice: 29
Re: CA Sales Tax - 13 different Rates
Assigned to:copperIT» 2440media

@copperIT, Thanks, your method helped me out, you just need to keep an eye out for rate changes. Your values were all for 4/1/09, but there are a lot of changes in the 7/1/09 file.

fymbscu's picture
Offline
Joined: 01/14/2010
Juice: 21
#6
Category:» support request
Assigned to:2440media» Guest

Hi guys,

I can follow what is happening in your examples. I need to do a similar setup for Los Angeles county, which has some 500+ zip codes. I don't understand where to place your php code in the conditional action framework.

I've setup the look up state portion, but I don't see a place for the php code. The zip code action field is much too limited. I've tried to add the code to the conditional action description field in hopes that this was the right place, albeit mislabeled.
It didn't work for me.

Could you offer a more explicit explanation for connecting the conditional action to the php code? Thank you very much.

Regards,

Mark Harrison

Sborsody's picture
Offline
Joined: 07/06/2009
Juice: 123
#7

CopperIT wrote: "While the state has an 8.25% sales tax, individual CITIES have their own which must be added on top of the 8.25%."

You only have to add on top of the statewide rate if you have nexus in those areas.

You *can* collect the additional tax then you have to tell the user that you're collecting a use tax on their behalf on a separate line item (normally use tax is the duty of the purchaser, not vendor).

See both CA Publication 105: http://www.boe.ca.gov/pdf/pub105.pdf regarding when municipal tax (special district tax) is to be collected and
CA Publication 100: http://www.boe.ca.gov/pdf/pub100.pdf regarding when to tax shipping and handling.

ccharlton's picture
Offline
Joined: 05/19/2010
Juice: 18
#8

I like @copperIT's code and think this needs to be wrapped into a UC module.

~ ~ ~ ~ ~
- Chris Charlton // LA Drupal Manager
... Learn how to theme Drupal! Watch my videos at http://tinyurl.com/theme-drupal
... Download software for Drupal, Eclipse IDE, and Adobe Dreamweaver: http://xtnd.us

ccharlton's picture
Offline
Joined: 05/19/2010
Juice: 18
#9

I like @copperIT's code and think this needs to be wrapped into a UC module.

Here's a screenshot of what I'm trying to setup using @copperIT's example and txt file, but updated for 2010. I'll share after I get it working. (screenshot: http://www.ubercart.org/files/Screen shot 2010-05-20 at 10.06.36 PM.png)

AttachmentSize
Screen shot 2010-05-20 at 10.06.36 PM.png 76.2 KB

~ ~ ~ ~ ~
- Chris Charlton // LA Drupal Manager
... Learn how to theme Drupal! Watch my videos at http://tinyurl.com/theme-drupal
... Download software for Drupal, Eclipse IDE, and Adobe Dreamweaver: http://xtnd.us

ccharlton's picture
Offline
Joined: 05/19/2010
Juice: 18
#10

As promised here are the updated conditional actions for California 2010 taxes (April 1, 2010). As mentioned above this code is used in conjunction with the shipping state conditional action.

Step 1. Add each tax group (8.25%-10.75%)
Step 2. Edit each Conditional Action (per tax group) to have two (2) conditional actions: 1st is Shipping State/Province (set to California), 2nd is "Custom PHP Code" and paste the right chunk of code from the text file attached.

I've also attached two spreadsheets if anyone doesn't want to review/redo/alter the work I did but would like to save a couple hours of time. Smiling The spreadsheet files are in CSV and OpenOffice formats.

AttachmentSize
uc_CA_salestax-2010-04-01.txt 30.96 KB
city_rates.ods 63.97 KB
city_rates.csv_.zip 13.04 KB

~ ~ ~ ~ ~
- Chris Charlton // LA Drupal Manager
... Learn how to theme Drupal! Watch my videos at http://tinyurl.com/theme-drupal
... Download software for Drupal, Eclipse IDE, and Adobe Dreamweaver: http://xtnd.us

focal55's picture
Offline
Joined: 05/08/2009
Juice: 11
#11

Thank you so much for this forum thread. Special thanks to ccharlton for the latest list.

I just discovered a pretty critical bug in the script. When it checks the $order->delivery_city array for a match, it check with case sensitivity. I just had an order go through with no sales tax applied because the user enter the city with all caps. I went back and added a string manipulation that first sets the $order->delivery_city value to lower case, an then appies a title case on it so that it accurately checks against the list provided by ccharlton. Each tax bracket does a simple check to see if that city is in the array. Here is my adjustment to that check:

<?php
//Previous check
if (in_array($order->delivery_city, $cities)) return (TRUE); else return (FALSE);

//Revised check
if (in_array(ucwords(strtolower($order->delivery_city)), $cities)) return (TRUE); else return (FALSE);
?>

I tried to only use ucwords but discovered that ucwords method doesnt seem to work on a string in all caps. Please let me know if there is better syntax for doing this. For the time being this put out my fire. Hope it helps someone else.

daveX99's picture
Offline
Joined: 03/20/2010
Juice: 31
#13

I posted here 2 days ago, and that post is either pending moderation or lost in the ether somewhere.

In either case, I found a related thread that might even be more appropriate to the topic of Localizing California Sales Tax Rates, as this thread is ostensibly an 'issue' about Conditional Actions.

...So I posted there as well that I have revised the chunks of php code that breaks out the various California cities by Tax Rate. The file is attached to that post and contains detailed instructions on how to use it.

The link to that forum thread is here:
http://www.ubercart.org/forum/support/8492/ca_sales_tax

-dave (formerly 'copperIT')

EDIT: I think I never actually posted the other day (sigh). I have a feeling I didn't complete the captcha part of that post... So I'm adding the text file here as an attachment as well as to that other post. It will have to be in another post, since I can't add it to this one now that it's been submitted.

daveX99's picture
Offline
Joined: 03/20/2010
Juice: 31
#14
Title:Conditional Actions / Tax miscalculation» Conditional Actions / Tax miscalculation - New rates effective 10/1/2010

Here's the new text file I mentioned. It also contains some instructions (the kind I need) for how to set this up.

If anyone has questions or comments, please feel free to add them, but it might be better on the other thread.

-dave.

EDIT: GAAAH! I consider myself a fairly smart guy, but the process for posting things in this forum is causing me serious doubts.

Apparently I can't post the same fiile in 2 different posts, so the attachment to this post is meaningless. The file IS attached to my post in the other thread, or you can use this direct link to the file:

http://www.ubercart.org/files/uc_CA_salestax-2010-10-01.txt

I'm done posting now. Phew. Happy holidays.

-dave.

AttachmentSize
uc_CA_salestax-2010-10-01.txt 43.53 KB
monicadear's picture
Offline
Joined: 08/17/2011
Juice: 6
#15

Here is the updated file for July 2011 from the DOE, with an updated 7.25% sales tax rate + all the city taxes sorted.

AttachmentSize
correctCaliforniaSalesTaxrates_2011_07_01.txt 57.68 KB
monicadear's picture
Offline
Joined: 08/17/2011
Juice: 6
#16

Corrected file.

AttachmentSize
correctCaliforniaSalesTaxrates_2011_07_01_corrected.txt 49.2 KB
imrubio's picture
Offline
Joined: 01/28/2011
Juice: 44
#17

Thanks for this. It worked great except for one thing. Customers were being double-taxed the CA Tax rate of 7.25% if their shipping city was included in the 7.25% list. To fix this I had to add the same list of cities to the other 7.25% tax list which is negated for cities with tax rates greater than 7.25% to avoid applying the double tax.

veryberry's picture
Offline
Joined: 03/01/2012
Juice: 33
#18

Hello, I'm trying to accomplish what is essentially the same thing, but thankfully a little less confusing. This is for Ohio county sales tax. Right now I'm testing it with two zip codes in Columbus. Here's my PHP code:

<?php

if(in_array(substr(trim($order->delivery_postal_code),0,5),array('43203','43224'))) return (TRUE); else return (FALSE);
?>

However, it doesn't seem to be applying the tax when entering one of those zip codes. Am I missing something?

focal55's picture
Offline
Joined: 05/08/2009
Juice: 11
#19

Are you using Product Classes by chance? Or do you just have one content type set as your "product"

imrubio's picture
Offline
Joined: 01/28/2011
Juice: 44
#20

Try simplifying your code first and see if that helps.

<?php
$del_postal_code
= substr(trim($order->delivery_postal_code),0,5);
$zipcodes = array('43203','43224');

if (

in_array($del_postal_code,$zipcodes)) return (TRUE); else return (FALSE);
?>

I have a similar format and it works.

veryberry's picture
Offline
Joined: 03/01/2012
Juice: 33
#21

#19 — no product classes, just one content type for product.

#20 — no, that did not work either. Am I putting it in the right place? I have it under the Conditions for my tax (in the value field).

EDIT

I put it under Execute custom PHP code and am now getting this error:

Parse error: syntax error, unexpected $end in /drupal/sites/all/modules/rules/modules/php.eval.inc(146) : eval()'d code on line 1

I'm on Drupal 7 if that matters.

veryberry's picture
Offline
Joined: 03/01/2012
Juice: 33
#22

I'm an idiot. I guess that's what happens when you work for too long. I apparently did not read this line: Enter PHP code without <? php ?> delimiters.

That works!!! Thank you so much!!