VAT Number

Posts: 534
Joined: 08/13/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer

Hi there,

I'm looking for a way to add a VAT number field in the Store informations and checkout billing address pane and to show them (if filled) in the invoices because it's an obligation in European Union.

I will take few days to try to do that and will submit my modification if I find a solution but I'm not programmer and maybe somebody can find the way to do that is few minutes.

If somebody have advices to gives, don't hesitate....

thanks

zmove

Posts: 534
Joined: 08/13/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer

Ok I successfully added the VAT_Number field in the store informations..

As my windows PC sux and I cannot create a patch I will explain what to do and if a good spirit want to create the patch...

In uc_store.module, in uc_store_store_settings_form() function

about line 1318

After :

<?php
$form
['uc_store_country'] = uc_country_select(t('Country'), variable_get('uc_store_country', 840));
?>

Add :

<?php
$form
['uc_store_vat_number'] = uc_textfield(t('VAT number'), variable_get('uc_store_vat_number', NULL), FALSE, NULL, 64);
?>

That's all. Eye-wink

Now, I will try to find how to add this field in the billing address (and only the billing address) informations when a customer is in the checkout pane. It seems more complex because you can enable or disable the field in the administration page.

When the second step will be done (if done one day Smiling ) I will try to show them in the invoice.

If you have some suggestions, advices, don't hesitate.

Posts: 534
Joined: 08/13/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer

I successfully added the store VAT-number in the invoice. I think I used the good way to do by adding a new token.

So, in the uc_store.module

About line 314 in uc_store_token_values() function
After :

<?php
$values
['store-name'] = variable_get('uc_store_name', t('our store'));
?>

Add :

<?php
$values
['store-vat-number'] = variable_get('uc_store_vat_number', t('our store VAT number'));
?>

About line 335 in uc_store_token_list() function

After :

<?php
$tokens
['global']['store-name'] = t('The Ubercart store name.');
?>

Add :

<?php
$tokens
['global']['store-vat-number'] = t('The Ubercart store VAT number.');
?>

That's all for uc_store.module

Then in customer.itpl.php in uc_order/templates you can put [store-vat-number] whenever you want to show the VAT number.

Now my battleplan will be to add the VAT number in the checkout billing address pane, and to show it in the invoice if filled by the customer.

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

Excellent additions. You may be able to work these into the actual VAT module so you don't lose them if you update. Smiling

Keep 'em coming, and I can help add them in if need be.

Posts: 534
Joined: 08/13/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer

You certainly right, I was hacking the core because it's more understandable for me. (I really have difficulty with module, and I don't know what is possible to do with.)

I will try to make the same thing in the vat module instead of the core uc_store.module.

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

No problem. I can post up here a few tips for adding hooks to custom modules. It's really pretty simple and what makes coding with Drupal such a breeze!

Posts: 534
Joined: 08/13/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer

Ok, I create the field in the vat module setting page. I really don't know if I did that with the good way, so can you check my attached file and say to me if it's good...

Now, I need to register the VAT number entered in this field in the database. I think the best way to store it is in dp_variable because it's an unique variable that give informations on store (like uc_store_name or uc_store_fax already in dp_variable)

I really don't know how to register the value entered in this field in this table so I need help Eye-wink. I need to create a token to be able to call the vat number in invoice and mail templates and I don't know how to do too Smiling

Can you brief me on the way to do that please ?

thanks

zmove

AttachmentSize
uc_vat.module.diff7.13 KB
Posts: 5269
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

To register the variable, you use something like:

<?php
  variable_set
('uc_vat_number', $vat);
?>

However, for that form it will happen automatically based on the form element's name (in your case, it is currently store_vat). You can tell this because the return uses the function system_settings_form() which automatically handles form validation/submission for settings forms and saves the results in Drupal variables based on the form element names.

You can read the value with variable_get() like this:

<?php
  drupal_set_message
('The store VAT number is '. variable_get('store_vat', 'N/A'));
?>

The second argument in that function should be the default value if the user hasn't entered anything yet.

To register the VAT as a value you just need a function similar to the function you added your code to in uc_store.module. In your case, you'd name the function uc_vat_token_values(). You can just copy that and the _token_list functions from the store module, rename them, and remove all the duplicate content.

Posts: 534
Joined: 08/13/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer

Thank you for this helpfull comments Ryan, I think I made it.

So, at the moment, I created a new field in the vat administration that ask for the store VAT number.

If filled, it register the variable in variable table of drupal under the name : uc_store_vat.

I created a token [store-vat] that you can use in the invoice template for example (because it's an obligation on european store).

I join my file, if you can tell me if it's good and if it can be "officially" implemented into the vat module.

Next step will be to ask to customer their VAT number in the checkout billing address pane.

AttachmentSize
uc_vat.module.diff7.58 KB
Posts: 534
Joined: 08/13/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer

Now my problem is to add a VAT Number field in the checkout setting page (/admin/store/settings/checkout/edit/fields) if the VAT module is enabled.

I don't know how to do that (if possible) without hacking the store.module file.

If it's impossible, I would like to provide the same functionnality in the VAT setting pane (but it disperse the fields configuration and it's not very good for store administrator I think)

In addition, as the VAT number is linked with the payement and the invoice, it have to figure only on billing informations, not on the shipping informations. I don't know if the current ubercart system allow to put a field in one pane and not on the other.

Same, if it's impossible to alter the checkout billing information form without hacking the store.module, I would like to show this field in the new TVA pane created by the module.

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

I think your best bet here would be to add it in the custom checkout pane. Just put a field w/ instructions for customers to enter their VAT if they're professionals or something. (Can't remember exactly how the VAT works. Eye-wink )

I was a little nearsighted when I developed the address entry forms and do not have any automatic way for modules to add fields to the shipping/billing information. Something like this is the perfect candidate for the custom checkout pane, though.

Posts: 534
Joined: 08/13/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer

Hi there,

I have a problem I didn't remember about the invoices and the taxes in European Union.

In the European Union invoices, for each products, you need to show :

  • the product name
  • the product quantity
  • the value (in percentage) of the tax applied to the product
  • the price without tax
  • the price of the product with the tax
  • The subtotal without tax
  • The total of taxes applied
  • the subtotal with taxes

So, as you can see, the actual invoice have a lack of informations for european store. I will try to remediate this problem, but it begin to ask big developper skill and time : both things I don't have.

How can I try to do that ? is the invoices templates are powerfull enought to do that or I need to put my nose into the code... if yes, where ?

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

Hey zmove, the invoice template will be all you need, as it's really just an included PHP file. You have several variables at your disposal which are described in the documentation. One of those is an array of the products on the order called $products. This includes the node ID (and the price, quantity, name, etc.), which gives you enough to find out the VAT for that product and make the various calculations you mentioned.

The default invoice template is actually just copied from good old Amazon.com, and I'd be more than happy to change it if someone has a better defaultish template laying around. Smiling

Just be sure you don't work from the actual core template file. You're better off copying it and renaming the copied file. That way you don't lose all your work when you update your code!

Posts: 534
Joined: 08/13/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer

Ok Ryan, I'm happy to see how powerfull is the invoice template system.

I will create a template with all the needs of european invoices and I will submit to you.

thanks

zmove

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

The update for the new Checkout Pane API is quite simple. Just update uc_checkout_pane_vat() to this:

<?php
/**
* Display the VAT contained in the order during checkout.
*/
function uc_checkout_pane_vat($op) {
 
$vat_items = uc_vat_calculate(uc_cart_get_contents());
 
$vat_info = theme('uc_vat_pane', $vat_items);
  switch (
$op) {
    case
'view':
     
$contents['vat'] = array(
       
'#value' => $vat_info,
       
'#weight' => 2,
      );
      return array(
'contents' => $contents);

    case
'review':
      return
$vat_info;
  }
}
?>

Lemme know if it screws up at all. Eye-wink

Posts: 534
Joined: 08/13/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer

Thanks Ryan !

Today I just make modifications to pout vat module compatible with alpha 7c.

I put 3 new columns to the cart which are checkable in tapir setup.

  • The % of the VAT applied to a product
  • The price of the product without VAT
  • The amount of the VAT
    • In addition, I added 2 subtotal line at the end of the cart :

      • The Subtotal without VAT
      • The Subtotal of the amount of VAT

      I saw that with hook_table_alter() and hook_form_alter() I could modify the way the cart is displayed without hacking core.

      My first mission now is to design the checkout page. I don't think adding a VAT pane to display the total of a VAT applied is a good solution for user. It could make more sense to change the checkout page by adding these informations for each product with a subtotal on the cart pane. Exactly as I done for the shopping cart page.

      The checkout cart pane don't seems to be generated with the same way of the cart page, why ? It could be goot to just make a copy of the cart page in the checkout cart pane, with the same column you configure. Or, at least, create the same kind of table.
      I searched and I didn't find where to alter the cart checkout pane to show the same column that my shopping cart page.

      When I will resolve that (please, help Eye-wink ) I will add the new lines in the order pane as Mog and michels suggest here. Then I will create a field to ask VAT number to customers and, this need generate my second question : It is possible to ask this number in the billing address pane (without hacking core) with the new checkout system of alpha7c or do I have to create a new pane to ask that to customer ?

      I will post a new release of VAT module soon (at least for the alpha 7c compatibility) but I would like to add these feature before posting it.

      thanks

      zmove

Posts: 534
Joined: 08/13/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer

Hi there,

I continue my work about the VAT module and I think I will be able to post a new release soon...

But there is a thing that give me some problems :

Is is possible to add a step in the checkout process ?

Because I need to know the country of the customer to know if he come from European Union. If yes I have to ask him his TVA number.

So, I cannot place the TVA number asking pane on the same page that the billing address pane, so it is a way to add a step after the first checkout page ? if yes, how ?

Edit : I'm thinking another method. It's to alter the form check function, the one which say 'the field name is required' if the user don't fill the field. It remove the need of extra step just for asking VAT number. So my new question : Is it possible to alter form validation to add extra validation rules without hacking core ? Eye-wink

Posts: 534
Joined: 08/13/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer

Ok, I found a solution. Thanks to the new lead module that help me to understand the behavior of the checkout and order hooks. Smiling

Posts: 534
Joined: 08/13/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer

Hi there,

Today, I thinked about an important thing about VAT managing.

In european society, all calcul are made considering the price without VAT.

In your comptability software, you register your product with No VAT price, you apply discount on No VAT total price etc... (at least, it's the case in the society I work for).

So, I think an european store owner need to put sell price of a product without the VAT. I think it will be better to manage discount, report etc... in harmony with the comptability software.

But, for customer, all prices in the website need to be displayed with VAT, that's why I will try to change the VAT module to add the VAT to the price putted on the 'sell price' field instead of extract the VAT amount.

What do you think about this reflexion, I speak to european store owner.. Did you work with no vat product price in your society ? or did you work with vat price ?

Edit : So I have 2 question to do that

  • To transform the sell price field to ask price without VAT. and I alter the nodeAPI to show products with VAT
  • I dont change the system of the sell price that ask product with VAT by default, and I remove VAT when I want to show price without tax

The problem with the first method is that this is more difficult to implement especially with attributes

The problem with the second method is that the product is registered with VAT in the database, and I think it can pose problem with the interractions of others module (especially report) that I will need to modify each time to show without VAT report...

What do you think about the way to do that ?

Posts: 16
Joined: 09/27/2007

First of all great work on developping this module!
Now I am not enirely sure if I give the answer to your questions but what I would like to see for my dutch store is the selling price with, and without vat on the product page, and of course in the checkout page, invoice etc.
If only there was a product price including vat would be good. Of course I can do that without the tax module. Just use the selling price with tax already included. But that way it wont show up on the checkout page and invoice.

I think I tried your module the past days, but it didn't work for me as I got an error when going to the checkout page.
Also the vat module shows no version number in the modules list.

Regards,

Johan

Posts: 534
Joined: 08/13/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer

In fact, regarding to this post I'm asking myself if the VAT module have a future.

The core included in the alpha 7c version of ubercart already provide to apply different VAT amount for different product Classes. So what bring the VAT module new ? if it's just a checkout pane that show all included VAT, it's useless.

I think the module need to be reoriented to provide, for example, the possibility to register price without Tax in the 'sell price' field, but to show them without ant with VAT, on the website.

Posts: 6
Joined: 11/02/2007

I love to have this VAT support added to the ubercart core.

* the value (in percentage) of the tax applied to the product
* the price without tax
* the price of the product with the tax
* The subtotal without tax
* The total of taxes applied
* the subtotal with taxes

Show product prices with/without tax on the product page.