Support for Value Added Tax (VAT)

Issue tracker: view

Contrib type: 
Module
Status: 
Abandoned
Compatibility: 
Ubercart Alpha 7b
Latest version: 
1.0

Abandonned : see the Add tax to product price module for support.

(*This was posted by olav@drupal.org and will be restored to him when he comes back around.)

This module supports VAT as needed for shops in (at least) Europe. It assumes that products are maintained with their gross prices and allows to assign one of a defined set of VAT rates to each product. During checkout, for each rate, the resulting tax amount is shown.

Related threads: 
AttachmentSize
uc_vat_1.0.tar14.5 KB

user warning, please help

Hi, ubercart sucesfully instaled, everything ok, but after enabled VAT module, i have an error:

user warning: Unknown column 'rate' in 'field list' query: select rate from uc_vat where nid=1 and vid=1 in /data/web/du-sk.com/web/includes/database.mysql.inc on line 172.

I am not very good in php, but i think the path "/data/web/du-sk.com/web/includes/database.mysql.inc" can be wrong... it should be "/data/web/du-sk.com/includes/database.mysql.inc"
how can i fix it?

Alter Table

Hey Ali.

Problem is, that there's missing the row 'rate' in the mysql-table uc_vat.
You can fix that with the SQL-statement "ALTER TABLE `uc_vat` ADD `rate` INT( 11 ) NOT NULL ;"

Then the error isn't displayed anymore. But, after a first look, it seems, that the module still don't work correctly.

Any help welcome.

Edit: Sorry, it works fine after altering the table with the row "rate" (see sql-statement above).
Thanks a lot for that module!

Re: Alter Table

thanks, i did it before 5 minutes Smiling
VAT is displayed, after you add an item, and click on "checkout".

there is a pane displayed:
VAT contained in order
19,0% VAT $478.99

but i think it would be nice to have VAT also in Order total preview

Something like this:
Subtotal: $2,521.01
19,0% VAT: $478.99
Order total: $3,000.00

And, for better funcionality of this module, shop admin have to be able to see amout without tax and with tax also when he add a product.

Re: Alter Table

I looked in olav's install file, and he had provided that query in an update function but forgot to tweak the install function. I've changed this and re-uploaded the file.

Wrong calculation

The formula for calculating the VAT [price * qty * rate / (100 + rate)] is wrong, isn't it?

You must replace the line
+= $item->price * $item->qty * $rate / (100 + $rate);
with
+= $item->price * $item->qty * $rate / (100);

I will also try to add some more features to the Module in the next few days. But I'm just a silly noob in programming drupal modules, so please be patient (and hope the weather will be bad, so that I have the time to read those drupalbooks)

And before I start coding: Is this the only module for displaying VAT? I don't want to do needless work.

greetings from germany!

EDIT: Sorry, that was wrong... Calculation is right, cause you calculate the vat IN the price.

amelioration with hook_line_item

Thanks for this useful module, here is my suggestion :
i saw you try to add "hook_line_item" but doesn't seems to work, but it would be a better integration than make a pane, here is my code (update, better way and show on bill):

<?php

/**
* Implementation of hook_line_item
*/
function uc_vat_line_item() {
 
$items[] = array(
   
'id' => 'vat',
   
'title' => t('VAT'),
   
'weight' => 2,
   
'default' => FALSE,
   
'stored' => FALSE,
   
'calculated' => FALSE,
   
'display_only' => TRUE,
   
'callback' => 'uc_vat_item_vat',
  );
  return
$items;
}
function
uc_vat_item_vat($op, $order) {
  switch (
$op) {
    case
'display':
   
$vat_items = uc_vat_calculate($order->products);
   
$vat_amount = 0;
    foreach (
$vat_items as $rate => $vat) {
       
$vat_name = $vat['name'];
       
$vat_amount += $vat['amount'];
    }
   
$lines[] = array(
       
'id' => 'vat',
       
'title' => t('contains ').$vat_name,
       
'amount' => $vat_amount,
        );
   
$lines[] = array(
       
'id' => 'total_no_vat',
       
'title' => t('Total without VAT'),
       
'amount' => $order->order_total-$vat_amount,
        );
    return
$lines;
    break;
   
    case
'cart-preview':
   
$vat_items = uc_vat_calculate($order);
   
$vat_amount = 0;
    foreach (
$vat_items as $rate => $vat) {
       
$vat_name = $vat['name'];
       
$vat_amount += $vat['amount'];
    }
    foreach (
$order as $item) {
       
$total += ($item->qty) ? $item->qty * $item->price : $item->price;
    }
   
$total = $total-$vat_amount;
    if (
$vat_amount > 0) {
   
drupal_add_js("\$(document).ready( function() { set_line_item('subtotal', '". t('Total without VAT') ."', ". $total .", -1); } );", 'inline');
   
drupal_add_js("\$(document).ready( function() { set_line_item('taxe', '". $vat_name ."', ". $vat_amount .", 0); } );", 'inline');
    }
    break;
  }
}
?>

it works, but sometimes, on checkout page, need some refresh to get good line, saw post about this, i'll look tomorow.

Re: amelioration with hook_line_item

i am not sure how to add or replace this code in module...

hook_line_item / details

You can place it line 130 (there is coment line of hook_line_item), and so you can remove (or just coment) hook pane function, line 174 to 221.

Hey Mog. Seems to be good.

Hey Mog.

Seems to be good. Thanks for the work.
But the code has one problem: It doesn't consider the shipping cost and other generic line-items.
Maybe you can try to change this.

Just a hint:
Instead of:

<?php
    $vat_items
= uc_vat_calculate($order->products);
   
$vat_amount = 0;
    foreach (
$vat_items as $rate => $vat) {
       
$vat_name = $vat['name'];
       
$vat_amount += $vat['amount'];
    }
?>

use something like this:
<?php
$vat_value
= 19; //VAT of your country  @todo:Considering different VAT values
$total = uc_order_get_total($order);
$vat = $total * $vat_value / (100 + $vat_value);
?>

It's dirty. But it works (just tested on the checkout-review page).

greetings mic

TTC display

I have installed module ans french translation.
No probleme with tables, I have created VAT rates without problem.
After editing some products, I have the word "TTC" (french abriviation for "with taxes") added before the SKU, without space.
How can I change this display, I think it should be better near price.

Frederic

Re: TTC display

I tested the module, it is very usefull for european shop. Thanks

If I can suggest a new feature, it coule be really great to add a role and a country selection to apply a VAT. Why ?

Because, in the case of a shop that sell to personal and professionnal people all over the world, the following rules apply :

In my example, the shop is based in an European Union country...

  • If you sell products to personal people all over the world, you have to include the VAT, so, actually, the module works well for this case.
  • However, if you sell to professionnal people, the rules are more complex :
    • If the professionnal is in the country of the shop, you apply the VAT
    • If the professionnal is not in the country of the shop, you don't apply the VAT

That's why it could be great to provide a role and a country selection to be able to configure the VAT without hacking the module.

VAT number

As I say in this post, in Europe, company have an unique VAT number that have to figure on all invoices.

I'm working on the modification of the VAT module to allow 2 things :

  • Store the store VAT number and create a [store-vat] token to allow the display of this number on the invoice template system
  • To ask the customer VAT number on the checkout billing information pane (because if you sell products to another professionnal, both VAT number (your store and his store) have to figure on the invoice)

Edit : The first step is pretty finished.

Edit 2 : For the second step, I think it could be great to provide in the administration page the possibility to check or uncheck if you want to see the VAT number field on the checkout billing pane. I don't know if my developpers skill will allow that. See this post to provide your suggestions, help etc...

Re: amelioration with hook_line_item

Mog, does your work on the hook_line_item progress ?

I'm improving VAT module and I would like to implement your possibility. I pass a couple of hours to try to find why, sometimes, you need to refresh page to get good lines.

I don't find PHP problem, it seems to come from set_line_item javascript function...

not compatible with alpha7d

It seams that the module does not work with alpha7d

Fatal error: Call to undefined function uc_cart_checkout_new_pane() in /var/www/html/drupal/sites/all/modules/uc_vat/uc_vat.module on line 196

Any update?

PS. It seams that module is not in any repository?!

Re: not compatible with alpha7d

You can see on the related thread how to make it compatible with newest version of Ubercart.

I think I will not support this module anymore for several reasons discuted in several others thread about the VAT :

  • My deadlines is very close and I need to put 100% of my brain on others module I need
  • The Taxe do a similar job to the VAT module, you can set different tax for different product classes etc... The only things that the VAT module do is to show VAT on checkout pane
  • The VAT module need a big changement to allow to manage and put product prices without VAT on your shop to have "not wrong" google analytic reports etc...

Instead of working on VAT module, I will work on a module that allow to put price with VAT when you put your sell price without VAT. But I think it will be another module that the VAT module.