Florida tax module, how to interface with uc_taxes module?

Posts: 73
Joined: 12/16/2007
Uber Donor

As mentioned in another thread, I am starting to work on my first Drupal module. It is a module to add Florida discretionary surtax to a regular tax item.

So far so good, the module adds an option to a tax item's settings (Add Florida Discretionary Surtax).

My question: How do I interface with the current tax module? I would like the module, if enabled, to calculate the appropriate county tax and then add it to the 'regular' state tax. So, somehow the module would have to hook into the tax module. Is this even possible?

I know this is vague, but if I could get some assistance I think I am up to the task and am willing to put in the time and effort. This is must-have functionality for any Ubercarter selling goods in Florida!

Posts: 73
Joined: 12/16/2007
Uber Donor

I have spent the last few days researching, looking through code and experimenting. I would just like to know if what I am trying to do is even possible (please help).

As mentioned above, I need to implement a ways to add the Florida surtax (per county) on top of the State sales tax. I, of course, do not want to hack the core tax module.

The way I see this working is to install a contributed FL tax module. It adds an option into existing tax items to "Enable FL surtax charge". This part is done already.

What I need to know is if there is any way for this module to go through the order's line items after the regular tax is calculated, and if the tax line items new FL tax feature is enabled, then calculate the FL county tax.

Is there any way (with out hacking core) to have a module cycle through the line items after the tax module does it's calculations?

Any input, even a simple yes/no is appreciated. I don't mind spending the time in development, I just want to know if this is possible.

Thanks,

Shawn~

Posts: 2267
Joined: 08/07/2007
AdministratoreLiTe!

Since line items just kind of happen all at once, there isn't really a good way to wait until they're all done to put any more on. Taxes barely manage to do that already.

What I think you could do is develop an extra workflow-ng action that you can attach to the Florida state tax configuration. Make it so that it doesn't depend on the amount of the regular tax item if you can, because W-ng doesn't guarantee the order of actions in earlier versions.

Posts: 73
Joined: 12/16/2007
Uber Donor

Smart... that's a much better way of handling it. I am looking into how to develop this now. Thanks for the input.

Posts: 73
Joined: 12/16/2007
Uber Donor

I've got thing working pretty well accept for accessing the existing calculated tax. It's pretty much the same issue I had trying to do this the first way.

I've created a workflow-ng action (pretty much used your code from your tax module, I've verified that the new action is running after the first tax calculation but the line item doesn't seem to exist yet.

Any ideas of how I can get a handle on an existing tax line item in this scenario:

W-gn condition triggers two actions.

  • Action one tax module calculates regular tax.
  • Action two FL tax module calculates FL surtax

Here is the current way I am trying to access the first tax value from my FL tax w-ng action - but the line items are empty...

<?php
function uc_taxes_floridasurtax_action_apply_fl_tax($order, $tax){

foreach (
$order->line_items as $key => $line_item){
      if (
$line_item['type'] == 'tax'){
                
$current_tax = $line_item['amount'];
      }
}
}
?>

Posts: 2267
Joined: 08/07/2007
AdministratoreLiTe!

The line items don't get saved to the order until the entire workflow event has been processed. This is a real problem when you have to know how much tax has already been calculated. That's why $order->taxes is constructed by the other taxes as they are calculated.

Unless there are other funny tax laws I don't know about, I would think you only need the products and shipping totals. The shipping quotes trigger a tax calculation, so that should be in the line items eventually.

Posts: 73
Joined: 12/16/2007
Uber Donor

I've finished my first module, the Florida Discretionary Surtax module. All is well and it seems to be functioning correctly.

Instead of trying to pull the first tax and adding to that I ended up taking the default tax rule action out of the workflow-ng event and adding one that this module creates. In essence, overriding the small part of tax calculating w-ng event. Initially, I didn't want to do it like that but I think it was the only way to accomplish this.

In short, how it works:

  • Creates and populates two tables. Table one contains all Florida Zipcodes and Counties. Table two contains all counties and tax rates. (Table two is much smaller than table one and can easily be updated with new tax rates as the change
  • Creates a new option in the tax form "Add Florida Discretionary Surtax"
  • Create a new workflow-ng action to calculate tax and county surtax
  • Action pulls delivery zip from order, looks up county then looks up tax rate.
  • Add tax rate as specified in tax rule (6%) then add Florida Discretionary Surtax to first $5000 of order as FL tax law specifies

That's basically it. Since this is my first module I was wondering if there was anything wrong with this general way of calculating the tax(?).

Also, as I had discovered before - the tax line calculation doesn't fire when using an auto-fill feature like in the Google Toolbar. This is a problem. I know there is significant amount of people who use this feature instead of typing in the information. Is there any way to account for and prevent this problem?

I will upload the module soon for anyone else who may need it. Thanks!

Complete Computer Care | The Cosmic Gift | Florida Fossils | Team Hope Evangelism

Posts: 5367
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Hey, that sounds great. I hope it works out well! Regarding the Google Toolbar thing, there's not much we can do if the toolbar is filling in forms w/o firing any JS events. Right now tax calculation is based on the onchange event... so I don't know what to tell you. Puzzled You may need to tweak the JS until you find an event that Google works with, but they really should be doing the onchanges themselves.

Posts: 96
Joined: 10/29/2007
Bug Finder

Did you prep this for upload, I'm in FL and right now I'm doing 7% across teh board on UC, but would like it to be correct.

Posts: 73
Joined: 12/16/2007
Uber Donor

Yes, it's in the contrib downloads. Please give me some feedback on how it works for you.

Complete Computer Care | The Cosmic Gift | Florida Fossils | Team Hope Evangelism