Let me first apologize on behalf of my countryman, he must've got up at the wrong side of the bed or something...
As a coder and a business owner, here's what I understand of the (relatively simple) rules in the Netherlands:
In your shop consumers must always be shown prices that already have VAT included. Any mention of the price excluding VAT would merely be a service for businesses.
For the bill, all prices are added up and shown as the total price (which the customer must pay). Additionally, near the total price, it shows for each VAT rate the portion of the total price that is the tax. That is calculated as follows: VAT amount = total price / (1 + (VAT percentage / 100))
The easiest way to think about this is to turn it around. The tax is not added to the tax-less prices of each product, but subtracted from the list price and shown for those who can get restitution for it. (ie. people and businesses that are registered for collecting VAT themselves)
The only rounding that takes place is when the total of each VAT rate amount is calculated. Never is this done per-product.
NOW, if your shop deals with VAT registered customers mostly, you can, and it's more convenient to, display prices excluding VAT. In this case, VAT is added to the total price, and it's the total to-be-paid price that is rounded to the nearest cent, in stead of the VAT portion.
- When dealing with consumers, price including VAT is the base price and VAT is subtracted for display on the bill only.
- When dealing with businesses, price excluding VAT is the base price and VAT is added, which customers will have to pay or not, depending on whether they have a VAT number and are foreign, or simply choose to pay VAT in your country in stead of their own.
As far as I know, but I'm not an accountant, these are the basic calculation rules, and the differences in each EU country are only in what information is displayed at what moment and in what way. So I would just implement it like this:
- The shop has a global 'VAT flag' which chooses between base prices being VAT inclusive (VAT portion is rounded) or exclusive (total price is rounded).
- Each product has a 'base price'
- Each product has a 'VAT percentage'
- A product display routine would use the 'VAT flag', 'base price' and 'VAT percentage' to display the locally required information for each product.
- A bill generation routine would use the 'VAT flag', 'base price' and 'VAT percentage' to print the locally required information for the total prices of each group of all products that share the same 'VAT percentage'.
- The final price calculation adds all the total prices on the bill and uses the customer's information and preferences, like country of origin and VAT number, to decided whether or not he pays the final price including or excluding VAT.
If something's missing or wrong, please feel free to correct me, but unless I'm badly mistaken, it's really this simple.