See #476344: Incompatible with uc_discounts_alt

Module is working as expected, but once I start using uc_discounts_alt (http://drupal.org/project/uc_discounts_alt) the prices get mixed up. uc_discounts_alt uses the sell prices to calculte the discount and the price alterer isn't running in the message displayed, so it shows the sell price without VAT, while the shopping cart shows the price including VAT.

CommentFileSizeAuthor
#96 uc_discounts.module.txt82.6 KBdunx
#96 uc_discounts.js_.txt6.36 KBdunx
#96 uc_vat.module.txt48.01 KBdunx
#96 uc_order.line_item.inc_.txt5.4 KBdunx
#96 vat_1.jpg214.3 KBdunx
#88 uc_vat.module.txt48.02 KBjvieille
#84 uc_discounts_alt-6.x-2.4_modified.rar_.test114.28 KBjvieille
#84 uc_order.line_item.inc_.test5.67 KBjvieille
#81 uc_discounts.module.txt84.97 KBjvieille
#68 Image 1.png44.92 KBjoachim desarmenien
#63 uc_discounts_alt-476348.patch12.52 KBdavidburns
#59 uc_discounts.js_.patch3.97 KBmiguel_angel
#59 uc_discounts.module.patch8.24 KBmiguel_angel
#47 uc_discounts.module.patch3.77 KBnicolasb_cdip
#45 functions.txt453 bytesnicolasb_cdip
#42 uc_discounts.module.patch3.36 KBnicolasb_cdip
#39 dic_calculation.PNG149.5 KBgapa
#37 Image 4.png40.02 KBjoachim desarmenien
#37 Image 5.png28.99 KBjoachim desarmenien
#37 Image 6.png45.13 KBjoachim desarmenien
#34 Image 4.png40.02 KBjoachim desarmenien
#33 uc_vat_uc_discount_alt.zip62.96 KBpauljb
#30 uc_discounts.module_b.diff2.44 KBgapa
#28 uc_discounts.module_a.diff2.1 KBgapa
#24 uc_discounts.module.diff1.98 KBgapa
#23 uc_discount_alt_vat.patch2 KBleon kessler
#13 product_price_alterer_field-module-vat.patch827 bytesPoetro
#13 uc_discounts-module-vat.patch1.01 KBPoetro
#11 uc_discounts.module.vat_.patch1.08 KBPoetro
#11 product_price_alterer_field.module.vat_.patch926 bytesPoetro
#10 uc_discounts_vat.patch878 bytesPoetro
#5 uc_taxes.jpg57.5 KBryangroe
#4 476348_cart.png6.81 KBattiks
#4 476348_checkout.png40.06 KBattiks
#4 476348_checkout_review.png15.76 KBattiks

Comments

longwave’s picture

uc_discounts_alt should be calling uc_price() rather than uc_currency_format() to ensure the VAT alterer modifies the price correctly. But I'm not currently sure what context you should be calling uc_price() with, and this will have to be done carefully as tax may need to be calculated differently depending on whether the discount applies to an individual product or the full order - see #475474: Price alterer contexts and VAT support for the current discussion on this in Ubercart core.

ryangroe’s picture

Hi attiks,

I'm unfamiliar with VAT. It works like a tax, correct? Can you give me an example of what the you are getting and what you should get for the following screens?
-cart page
-checkout page
-review page
-product page (if using the product_price_alterer_field submodule of uc_discounts_alt)

I see I'm using $product->price in some areas and $product->sell_price in others. This may be a problem.

This module may doesn't call uc_currency_format() on product fields, only on its own discount amounts. So it may need to get a decimal price using uc_price. We'll see what needs to be done once we have a little more information. Thanks.

attiks’s picture

@ryan, VAT works the same as taxes, this is what i did:
1/ created a tax rule for all products, add 21%
2/ created a discount buy 2 one for free ('2 + 1 gratis')
3/ created a product with sell price 10
4/ product page shows 12,10 as price (dev load shows 10), so VAT is added
5/ added 3 items to cart, the cart shows The discount, '2 + 1 gratis', was applied for a discount of 10,00€. (should be 12,10) while the cart line shows the price including VAT
6/ checkout
- shows price = 30, vat = 6,30, total = 36,30
- enter discount codes pane shows The discount, '2 + 1 gratis', was applied for a discount of 10,00€. (should be 12,10)
- order total preview pane shows
Order total preview:
Subtotal: 30,00€
Afhalen: 0,00€
Total discount: -10,00€
Subtotal excluding taxes: 20,00€
21% BTW: 6,30€ (should be 4,20)
Order total: 26,30€ (should be 24,20)

7/ checkout review shows
Subtotal: 30,00€
2 + 1 gratis: -10,00€
Afhalen: 0,00€
Subtotal excluding taxes: 20,00€
21% BTW: 6,30€ (should be 4,20)
Total: 26,30€ (should be 24,20)

8/ same results on store/orders/nid

I hope it helps, if not let me know

attiks’s picture

StatusFileSize
new15.76 KB
new40.06 KB
new6.81 KB

screenies

ryangroe’s picture

StatusFileSize
new57.5 KB

So the discount calculated by uc_discounts_alt is consistent, it just doesn't take into account VAT.

Since VAT is a tax, it seems like the VAT module should work like uc_taxes. In uc_taxes you can specify which line items each tax is applies to (it's a setting in each tax rule as "Taxed line items"). If the VAT module worked like uc_taxes, you would tell the VAT module to include "Discounts" line items in its calculations. Then VAT would be correctly calculate at 4,20 because it would add 21% to 20 (30 + -10).

Ask Longwave what he thinks about this. Thanks!

longwave’s picture

The VAT module requires uc_taxes and uses the same calculations. However, the problem is that in European stores, the site must show tax-inclusive prices to the customer before checkout, so tax calculations have to be performed every time a product price is displayed. This means that any product discounts displayed on product pages or in the cart need to incorporate this same calculation.

As I said in #1, your module should call uc_price() instead of uc_currency_format() whenever it displays a price, which will do this calculation for you. This function was introduced in Ubercart 6.x-2.x-rc1. However, this function is more complex as it requires a 'context' parameter describing what the price is for, and the exact format of this is still being worked out in #475474: Price alterer contexts and VAT support. At present this will also require specific support in uc_vat depending on the 'location' contexts you use for discount prices, though I am hoping to avoid this by standardising the context parameter if possible.

longwave’s picture

Actually, I'm not sure how this will work when discounts apply to multiple products. If you have a taxed product at $10 and an untaxed product at $10, then you give a $10 discount when both are purchased together, I'm not sure what the correct tax calculation would be in this case - if the discount is"buy X get Y free" then this is a different calculation to "$5 off each product". How does uc_discounts_alt currently handle this?

ryangroe’s picture

As mentioned uc_discounts_alt doesn't call uc_currency_format or uc_price on an item's price because it never displays the price of an item.

With this module, discounts are applied to carts as a whole and not to individual products. This is the case even if the discount applies to a single product. This module adds a separate discount line item for each discount to adjust the total for the cart. So uc_discounts_alt will never change the price, sell_price, etc. of a product. This module may need to perform its calculations using an altered price in some future version but that's not what uc_price provides, right? Isn't uc_price is for showing strings to the user not for getting float price values?

a_lawry’s picture

Hi,

I have this problem as well. I'm trying to use the VAT module for Australian GST.

I'm going to try and hack the module to get it to work for me. Has any work been done on this problem before I start?

It also shows as a problem on the product page. The discounted price shown for the product uses the price without GST as a starting point. Also I notice from a brief look at the code sometimes $product->price is used and sometimes $product->sell_price is this meant to be that way?

Thanks for your help. I'll let you know how I go.

Andrew

Poetro’s picture

StatusFileSize
new878 bytes

I've created a patch that fixes the issues on the cart pane.

Poetro’s picture

Version: 6.x-1.0-beta32 » 6.x-1.0-beta36
Status: Active » Needs review
StatusFileSize
new926 bytes
new1.08 KB

Updated patches to match 6.x-1.0-beta36.

ezra-g’s picture

Version: 6.x-1.0-beta36 » 6.x-2.x-dev
Status: Needs review » Needs work

We should definitely be vat-compatible.

Thanks for the re-roll. This no longer applies to 6.x-2.x. Could you please re-roll against the end of this branch, without the "patched_uc_discounts_alt" directory?

Thanks!

Poetro’s picture

Status: Needs work » Needs review
StatusFileSize
new1.01 KB
new827 bytes

Updated patches for 6.x-2.x-dev

ezra-g’s picture

Thanks for the re-roll. This looks generally good though I'd like to do a bit of testing this week before committing.

DrupalYedi’s picture

The Patch works for me - but there ist another problem with VAT for European Stores into the cart pane:

If you activate a percentage discount for the total order - the discount is calculated in the cart pane by subtotal without VAT.

In germany - like European Stores to - we need to calculate the discount for customers from the subtotal with VAT.

This example show what I mean:

you have a percent discount of 10% of Total Order.
The VAT for each product ist also 10%.

Product A and B costs each 10,- EUR without VAT and 11,-EUR incl. VAT

The customer see on the cart pane:
Product A 11,- EUR (incl. VAT)
Product B 11,- EUR (incl. VAT
Subtotal = 22,- EUR (incl. VAT)

If I activate a 10% discount to subtotal actually is following cart pane shown:
Product A 11,- EUR (incl. VAT)
Product B 11,- EUR (incl. VAT)
Subtotal = 22,- EUR (incl. VAT)
Discount= 2,- EUR (=> The Problem: The Discount is calculated from Subtotal without VAT)
Subtotal incl. Disount=20,- EUR (incl. VAT)

The correct Cart pane would be:
Product A 11,- EUR (incl. VAT)
Product B 11,- EUR (incl. VAT)
Subtotal = 22,- EUR (incl. VAT)
Discount= 2,20- EUR (=> 10% from Subtotal incl. VAT)
Subtotal incl. Disount=19,80 EUR

The checkout pane works correct and calculate the discount from the subtotal incl. VAT - if you apply VAT to discounts in the UC VAT Module.

ezra-g’s picture

Status: Needs review » Needs work

Thanks for the re-roll.

Based on the comment in #15, it seems like this needs work.

miguel_angel’s picture

There's another problem with the calculations when there're products in the order with different vat rates.

There's an option in the vat rate configuration form to include the discount line in that rate calculation. This is correct.

An example:

Price without vat: 100
vat 16%: 16
Price with vat: 116

Applying a 10% discount ->
Price without vat: 90
discount without vat: 10
vat 16%: 14,4
discount with vat: 11,6
Price with vat: 104,4

So, 116 - 11,6 = 104,4 that's correct

But, to include the calculations of the other vat rates in the discount line I need to check that option in the corresponding vat rate configuration form and then the module calculates the vat amount over the discount though there isn't any item of that kind in the order.

In a try to solve this with ca, I've added conditions to every vat rate that limits the product classes this calculation applies but it doesn't work as expected.

Example:
vat rate: 16% applied to products class A and discount line.
Conditional actions for 16%:
Conditions: Product is class A
Actions: Apply 16%

vat rate: 7% applied to products class B and discount line.
Conditional actions for 7%:
Conditions: Product is class B
Actions: Apply 7%

Order with:
1 x Product class A
Price without vat: 100
discount 10%: 10
New price without vat: 90
vat 16%: 14,4
Discount with vat: 11,6
Price with vat: 104,4

1 x Product class B
Price without vat: 2
No discount
vat 7%: 0,14
Price with vat: 2,14

Checkout:
Must be:
Subtotal: 118,14€ (vat incl.)
Total discount: -11,60€ (vat incl.)
Subtotal vat excl.: 92,00€
VAT 16%: 14,40€
VAT 7%: 0,14€
Order total: 106,54€

But, it shows:
Subtotal: 118,14€ (vat incl.)
Total discount: -12,30€ (vat incl.) (wrong!)
Subtotal vat excl.: 92,00€
VAT 16%: 14,40€
VAT 7%: -0,56€ (wrong!)
Order total: 105,84€ (wrong!)

Because it was calculating the 7% vat rate over the 10 € discount of product class A (0.7), too and substracting it from vat 7% (0.14) (0.14 - 0.7 = -0.56) and adding the 0,7 to the real discount of 11,6 (11,6 + 0,7 = 12,30)
The conditions in vat 7% conditional actions says that only must be calculated if product belongs to class B but this isn't taken into account.

celia_ccs’s picture

Hi,
Hi,

UC_discount_alt calculate the discount based on the Price exclusive of VAT .. instead to calculate on the price VAT inclusive.

Ex : I apply a 20% discount on the products.

Standard Price (16% of VAT included) : 100
Discounted price from uc_dicount_alt : 68,97€
REAL discounted price : 80 => that's what it should be.

Is there any patch to solve this? I did apply the patches #13, but I'm still facing the same problem.

Ubercart 2.2
UC_discount_alt 6.x-2.x-dev
UC_vat 6x-1.0

iernst’s picture

Hi,
is there something new regarding this patch? It would be really great to have UC_discount_alt working correctly with VAT like in #17 from miguel_angel described.

Thank you in advance.
yours
ingolf

pauljb’s picture

subscribe

gapa’s picture

Hi,
I also run into this problem. Has anything been made on this.

br,
gapa

leon kessler’s picture

Just discovered this problem and have been working on it.

As far as I can see, the two remaining issues are:
1) The cart page discount total is incorrect (as it's still calculating before VAT is added) - but the checkout page has correct discount rates
2) Having multiple tax rates causes incorrect discount calculations. I replicated this problem, but haven't quite yet understood what is going wrong there.

Well I've fixed problem 1, I think. It basically needed a few changes to the get_discounts_for_order() function (just adding uc_price function where it was taking the sell price value).

I'm going to look into issue 2 tomorrow and hopefully fix that.
I'll come back soon with a patch, will need a bit of testing.

Thanks
Leon

leon kessler’s picture

StatusFileSize
new2 KB

Right, I've got a patch which seems to be working okay for me for both issues.

One thing to note is that you need to de-select the discount line item on the tax rate page.
The reason for this is we don't want tax to be added to our discount, as we've already included the tax using the uc_price() function.

I've tested it with an order consisting of two items with different tax rates and discount rates applied.

ITEM 1
PRICE £6.04
TAX 17.5%
DISCOUNT 6%
QUANTITY 5

5 * (6.04 + 17.5%) = 35.49
Discount: 35.49 * 0.06 = 2.13

ITEM 2
PRICE £20
TAX 10%
DISCOUNT 50%
QUANTITY 3

3 * (£20 + 10%) = £66
Discount: 66 * 0.5 = £33

Subtotal: 35.5 + 66 = 101.5
Discount: 2.13 + 33 = 35.13

Order total: 101.5 - 35.13 = 66.37

This works for me.

Let me know if there's any probs. Also, I havent tested this out without using the vat module. It should work the same as uc_price() will then get the price exc tax, and you could tax the discount by selecting this line item on the tax admin page.

Thanks

Leon

gapa’s picture

StatusFileSize
new1.98 KB

Hi,
Thank you so so much for this!
I had to manually patch this thing (probably because of different module version). I attached my patch if someone else will have this problem.
As far as I could test it it really works. :)
Do you maybe also know how to get products discounted prices into invoice? Couse products on invoice are displayed without discounted price.

thanks again and br,
gapa

leon kessler’s picture

hi gapa,

On the invoice you get the items price and then the total discount below it, the same as on the cart and checkout review pages.
You want the item price to include the discount rather than listing them separately? Isn't that a bit misleading as you're not showing what the normal cost of the product was (plus losing the opportunity to show what the customer saved in discounts).

Anyway, the invoices are php files so I guess you could use the uc_price() method inside them to work out the discounted price.

gapa’s picture

Maybe I forgot to mention that I would like to display both prices of a product. Original, and new discounted. So that customers could see on product basics how much they saved. And also if it is possible to calculate the difference between original and discounted price (you saved: price - discounted price).
This kind of functionality would also be great in product node. So the customers can see right away how much they would save if they bought the product. Also maybe with % display. So that they don't have to do the calculations for them self.
I will try to implement your idea into invoice. Is it also possible to use this idea (using uc_price) in template files node-product.tpl.php?

br,
gapa

pauljb’s picture

Thanks for the patches but, with both patches #23 and #24, I got the message:

patching file uc_discounts.module
Hunk #2 succeeded at 955 (offset 15 lines).
patch: **** malformed patch at line 56: @@ -1387,25 +1422,25 @@

Thanks

gapa’s picture

StatusFileSize
new2.1 KB

I checked again my patch and i think i made a reverse. try again with this one.

pauljb’s picture

gapa,

this one worked
you saved my day, thank you!

gapa’s picture

StatusFileSize
new2.44 KB

I found another error and I applied another patch. This should also correct "Subtotal including discounts:". Now it is displayed with VAT.

br,
gapa

pauljb’s picture

Hi Gapa,

Thanks for your update.

Can't imagine it has to do with the patch but for some reason the field discounted price disappeared.

joachim desarmenien’s picture

hello,

i'm having the same issues with VAT + uc_discount_alt

do i have to aplly all the patches, or just #30
is there a way someone could send me a patched version of the module that would work with VAT
i never could patch a module it always fails ...

thanks to all

pauljb’s picture

StatusFileSize
new62.96 KB

Hi Joachim

I attached the patched versions of uc_vat and uc_discount_alt.
As far as I can see so far it works as aspected.

Paul

joachim desarmenien’s picture

StatusFileSize
new40.02 KB

Hello,

thanks for the file
i updated the module (i sites/default/modules)with the ones you sent me
created a buy one get one free rule
ran cron, emptied caches

and it still calculates discount on VAT non inclusive price
did i forget something ?

see attached file
the website is here http://newsite.lefestin.net/node/802
you can try putting two items in the cart ....

is there a way to output something to see if it works ?

thanks

joachim desarmenien’s picture

i tried uninstalling the module
unchecked it in the module section, deleted the files, ran update.php

reinstalling it
upped the files you gave me, checked discount box in modules section.

my discount rules are still there
and it still isn't working :((((

joachim desarmenien’s picture

BTW : i'm working with three different taxe rate i don't know if this is what makes it uneffective

joachim desarmenien’s picture

StatusFileSize
new45.13 KB
new28.99 KB
new40.02 KB

i tried searching in the admin/store/settings/taxes page
i have three taxe rates one for books, one for magazines, and one for normal product

when in one taxe rate i check the taxable line item option "discount"

it works on checkout but not in the cart

if i check the taxable line item option "discount" on the second taxe rate

on checkout it outputs two taxes (see pic for discount checkboxes)

can anybody tell me what does the "taxable line item" do ? what are "empty line" and "taxe" options for ?

Is there a way to make this work ?

I feel i'm missing something

thanks to all

gapa’s picture

Try deselecting the discount line item on the tax rate page. It is already mentioned in post #23. I don't have discount line in my setup and for me it works. Haven't yet tried your type of discount rule thou.

br,
Gapa

gapa’s picture

StatusFileSize
new149.5 KB

Found another issue. In the attached picture you can see two product with same discount (50% off). Why are this two products rounded differently? If I divide original price (this is VAT inclusive) I get 2,295 and 3,755. As I can see this two are rounded differently. I also tried to do this calculation without VAT inclusive prices and I still get to same result.
I also am trying to get discounted price into invoice template. And as far as I could do I used this code to pass another parameter into ordered products. And "discounted_price" is 2.29 and 3.76. Why is this different than in product display page? I just can't figure it out. To be honest, I am not a coder so I don't understand completely how things works. Any help is welcome.

function uc_discounts_order($op, &$arg1, $arg2) {
  switch ($op) {
    case "load":
      //Get order's codes from database
      $codes_string = uc_discounts_order_codes_get($arg1->order_id);
      $arg1->uc_discounts_codes = get_codes($codes_string);
      foreach ($arg1->products as $product) {
        $item=node_load($product->nid);;
        $discounts = get_codeless_discounts_for_product_and_quantity($item, 1);
        //Sum discount amounts
        $total_discount_amount = 0;
        foreach ($discounts as $discount) $total_discount_amount += $discount->amount;
        $product->discounted_price=$total_discount_amount;
      }
      break;
leon kessler’s picture

hi gapa,

Sorry I havent been helping out with this that much since uploading the patch. I've had to stop work on it because it turns out the project I'm on never required the vat module anyway.

With the rounded prices, have you checked the original sell price? I think I saw this issue before, but found it was calculating the discount from the actual sell price, which is also rounded (separately) for the store. Does that make sense?
So say your second product that was rounding down (.5 should always be rounded up), the original sell price could have been 7.508, which would round correctly to 7.51 for the store and 3.75 for the discount.

As for the discounted prices showing on invoices, this should really be done with tokens. It's something I'm going to have to do myself pretty soon, when I do I'll submit a patch. If you want to do it yourself I would look into using hook_token_values(), or carry on using the code in the template (bit messy) as that seems to round correctly.

Thanks
Leon

gapa’s picture

Thanks for answer leon.nk.
I will check rounding problem and report back what I will found.
As for invoice template. I don't know if tokens are meant to be used this way. Cause every product that would have discounted price should also have it's own token. Or did you have any other idea implementing this?
That's why I thought it would be best to attach discounted price to products that are in order. So I could go through order->products array and display original sell price and discounted price (if product has discounted price). And also total price without discount and total price with discounted price.

br,
gapa

nicolasb_cdip’s picture

StatusFileSize
new3.36 KB

Hello,

I was reading this topic and I used your patches to correct the vat problems. I ran some tests for each kind of possible discounts.
So basically there are two categories : Qualif type = Price or Number and Discount Type = Percent Off, Fixed Amount Off, Fixed Amount Per Qualifying Item, Percent Per Qualifying Item and Free Items.
After testing, I understood what your patches fix but I found new issues which are :
- wrong discount calculation when Qualif type = Price and Discount Type = Fixed Amount Per Qualifying Item

$order_and_discount_product_ids = array_intersect($discount_product_ids, $order_product_ids);
        foreach ($order->products as $this_product)
          if (in_array($this_product->nid, $order_and_discount_product_ids))
            $discount->amount+=$this_product->qty;
		$discount->amount*=$discount->discount_amount;
        break;

instead of

$discount->amount = $discount->discount_amount * $order_qualifying_amount;
        break;

explanation : discount amount was calculated too quickly, should be $discount->discount_amount * the number of qualified items

- wrong discount calculation when Discount Type = Percent Off Per Qualifying Item

$this_product_price = get_uc_price($this_product);

instead of

$this_product_price = $this_product->price;

explanation : not using get_uc_price function

- not including VAT in price of free item(s) when Type = Free Items

$price_info = array(
		    'price' => $cheapest_product->price,
		    'qty' => 1,
		  );
		  $context = array(
		    'type' => 'cart_item',
		    'revision' => 'altered',
		    'subject' => array(
		      'cart_item' => $cheapest_product,
		      'node' => node_load($cheapest_product->nid),
		    ),
		  );
  
          //Add current discount amount to running total
          $discount_amount += $discount_count * uc_price($price_info, $context);

instead of

//Add current discount amount to running total
          $discount_amount += $discount_count * $cheapest_product->price;

explanation : not using the get_uc_price technique to calculate the price of the free item(s) discounted

So I provide a patch which include all the previous modifications on the uc_discounts.module file (of this topic) and adding mines.
If I'm not wrong, only the change made in #13 have to be added, because not in the same module.
I would appreciate having feedback about this contrib because I'm not sure it's completely tested.

gapa’s picture

I have looked at your patch and I think that it doesn't include your new patches. Could you please have another look at this?

br,
gapa

nicolasb_cdip’s picture

You're right, my bad !
I changed it a little bit, using an .inc file containing the function get_uc_price() and allowing to use it with a quantity of 1.
So the functions.txt should be renamed in functions.inc and placed in sites/all/modules/includes/ (create it before).
I did that because a lot of modules don't handle the VAT issue and so need to call this function.
What do you think about that ?
I re attached the patch file, and this one should be complete.

nicolasb_cdip’s picture

StatusFileSize
new453 bytes
gapa’s picture

Don't know why but the file uc_discounts.module.patch is missing (wrong link to file).
But don't know about functions.inc file. I have a feeling that this is not "drupal" way of handling things. But I am not an experienced drupaler so I will let others decide. My personal opinion is that it should stay in module itself. Other modules maybe want to calculate things differently.

br,
gapa

p.s.: do you maybe have an answer to my other problems discussed in posts #39,#40,#41

nicolasb_cdip’s picture

StatusFileSize
new3.77 KB

Re uploading this *** patch :p
I don't know if it's the best way to share this function, I think the Drupal way is to create a module for this. But as it's a very basic function, I used this.
About your issues, I didn't get this problem yet but I will let you know...

gapa’s picture

I have tested few examples (not all), and it works for me. I have also discovered what is with my question in post #39. I have found out how discounts get calculated. It is original price - discount. And if I calculate my numbers this way the results are correct.

br,
gapa

mrandy’s picture

Hi,

Sorry to be a pain but any chance somebody could post a patched version of this module. Having spent a few hours (as a non programmer) trying to work out how to apply a patch under windows (yep I should probably be running Linux, I'll get there one day) frustration is kicking in and i am getting no where. This might be a simple process for most people but not here, it would be a big help if I could just grab the already patched mod from somewhere and upload it.

Thanks a lot to anybody that can help, and to everybody for solving these issues.

Andy

mrandy’s picture

for anybody else wanting to apply a patch, using windows and not having a clue where to start, try using Tortoise SVN, it makes it very simple and is available here:

http://tortoisesvn.net/

and the instructions here meant even I managed to do it:

http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-dug-patch.html

hope this helps somebody else.

Andy

klavs’s picture

I see these get_ucprice patches has been applied to the latest dev version of uc_discounts_alt - also VAT support "almost" works.

I tested on a test site - purchasing 3 items costing a 100 kr. (80 kr. without VAT) and a discount of 30 kr. if 3 is purchased.

The total became 270 - so that was correct, but the VAT amount was still 60 - it should have been 54 (the 6 deducted as the discount amount (30) is 24 + 6 in VAT).

klavs’s picture

if I enable taxes on discount line item the VAT is correct - and the entered discount amount is taken as being excl. VAT (ie. to get a discount of 30 incl. VAT I need to enter 24).

Only issue is the places where it says what your discount is - it states this without VAT - (ie. 24) where it should say 30 - as that is what the customer actually saves.

I'm guessing the "your discount is" output is not run through uc_price ? (I'll have a look at the code and see).

klavs’s picture

the patches with get_uc_price returns a price of 0.

I tried to fix it up - and the below works, except VAT is NOT applied. I can't seem to figure out why :(

function get_uc_price($item) {
$price_info = array(
'price' => $item->price,
'qty' => $item->qty,
);
$context = array(
'type' => 'cart_item',
'revision' => 'altered',
'field' => 'price',
'subject' => array(
'cart_item' => $item,
'node' => node_load($item->nid),
),
);

return uc_price($price_info, $context);
}

klavs’s picture

btw. this is only needed in the cart pane - VAT is correctly done in the checkout section.

klavs’s picture

I fixed it - you need to feed it a proper item - or perhaps try to change from cart_item to line_item - I haven't gotten line_item working yet though.

klavs’s picture

I tried to get get_uc_price to check for an $item->nid, so that calls to get_uc_price with an $item object which has ONLY price and quantity (ie. discounts - ergo line_items) could be calculated as well.

But it doesn't add VAT to line_items and I can't seem to figure out what's missing from the line_item item (and yes - I have selected that Discounts (uc_discounts) be taxed in my tax rule.

If you have ideas - pls. put'em forward - otherwise you can just clone the last $item from the shopping cart and use that - that's what I do now. It is flawed though, as you might have a case where an $item is untaxable (or has a different tax - like books in Sweden, childrens clothing in UK etc.) and the line_item discount still should be taxed.

if ($item->nid) {
$context = array(
'type' => 'cart_item',
'revision' => 'altered',
'field' => 'price',
'subject' => array(
'cart_item' => $item,
'node' => node_load($item->nid),
),
);
}
else {
//This doesn't work - it is however how tax on discount line_items should be calculated
$line_item = new stdClass();
$line_item->type = 'uc_discounts';
$line_item->amount = $item->price;
global $user;
$order = new stdClass();
$order->uid = $user->uid;
$order->line_items[] = array( 'type' => $line_item->type, 'amount' => $line_item->amount);

$context = array(
'type' => 'line_item',
'revision' => 'altered',
'field' => 'price',
'subject' => array(
'order' => $order,
'line_item' => $line_item,
),
);
}

jazzitup’s picture

+1 subscribing

Can we port a final version of all working patches from above that work with the current uc_vat dev, please?

secretuser’s picture

From this entire thread, I am under the impression that there is a version that actually solves the problem. But there is somehow no combined version available for download. So I assume that the problem isn't solved yet and that the patches are incomplete?

miguel_angel’s picture

StatusFileSize
new8.24 KB
new3.97 KB

The discounts and VAT support are a difficult problem to solve for all cases of use (and all countries).
Perhaps the solution is that any module that alters prices must have a price alterer function and find the right order to apply them.

Meanwhile, I've wrote a patch to uc_discounts_alt (6.x-2.x-dev 2010-Aug-24) that handles discounts in orders with mixed VAT rates.
The solution calling uc_price contributed in this thread doesn't work for me.

This patch creates a different line item per vat rate, so you can assign in VAT settings the right discount line item to each vat rate.
For this to work, the discounts created must no mix products of different vat rates.

You can have a vat rate for products class: A, B, C and discount line item "VAT rate 1"
other for products class: D, E and discount line item "VAT rate 2"
and a discount that qualify for products class A, B or C
other discount that qualify for products class D or E
but not discounts that qualify for products B or D, for example (due to different vat rates of B and D classes)

I've tested the patch with modules:
uc_vat, uc_taxes, uc_discounts_alt enabled
uc_vat, uc_taxes disabled and uc_discounts_alt enabled
uc_vat, uc_taxes enabled and uc_discounts_alt disabled

This isn't an elegant solution, but it works.

Please, feel free to try the patch and your feedback is welcome.

Peter76’s picture

Hi,

Can anyone please send me already patched files (uc_discounts.js and uc_discounts.module)?
It give me an error.

jazzitup’s picture

@Peter76: Why would anyone send those patched files to you? Think broader, think about the community and ask to port those patches to dev. That way you will get your patched files, the rest of the community could test it and the maintainer will get more feedback.

Peter76’s picture

madjoe;
Yes you are right.

Can anyone port these parches to dev?

davidburns’s picture

StatusFileSize
new12.52 KB

@Peter76 I believe what @madjoe was getting at, is that this is a community project and the efforts of people like yourself could benefit everyone else.

So instead of waiting around for someone to make the patch for you. You could have taken the time to understand how to manually apply a patch. These patches were relatively small and would have been good experience for you. However, me being the nice guy that I am. I went ahead and created a new patch file for you.

I even took an extra step and hunted down a post here on Drupal.org that explains how you can help out by reapplying patches manually. Then all you would have to do is create a new patch file for everyone else to use.

Apply a patch file manually
Create a patch file
Apply a patch file

Peter76’s picture

davexoxide thank you very much.

sittard’s picture

For testing, I've just checked out the latest release from the CVS head which appears to incorporate the above changes but I'm getting the following error code:

Fatal error: Call to undefined function uc_discounts_add_discount_rate_id() in /sites/all/modules/uc_discounts_alt/uc_discounts/uc_discounts.module on line 1448

It would appear that 'uc_discounts.module' around line 1950 has some code which looks out of place and is effecting the function 'uc_discounts_add_discount_rate_id'.

I'm happy to post my copy 'uc_discounts.module' if that would help.

Rob B’s picture

Any help will be great, I tried to apply the patch above but realised that it was for an older version of the module - having issues myself with the discount calculating the pre-tax value, and also showing the subtotal excluding VAT on the shopping cart page.

Thanks!

mandreato’s picture

Hi all, I've just downloaded the 6.x-2.x-dev version of Ubercart Discounts (Alternative) and tried to manage a term based discount but occurred in the problem described here: the discount is applied before taxes, which is not correct here in Italy. Actually the taxes are managed correctly by Ubercart 2 VAT support module.

I've read the whole thread, even the links posted by davexoxide about patches, then tried to apply patches both manually and using the Eclipse tool, but it seems to me (consider that I'm not an expert), that the patches aren't suitable for current 6.x-2.x-dev release (like stated in the previous post too).

Is there any chance to port the fixes in the -dev version ?

joachim desarmenien’s picture

Title: Incompatible with Ubercart 2 VAT support » Incompatible with Ubercart 2 VAT support
StatusFileSize
new44.92 KB

Hello,

i have a problem with a french site that is online and "working" :(

an acountant told me that the vat is not applied where it should be.

they sell magazine with a vat rate of 5,5%
in this example we have 2 discounts applied using uc_discount_alt, free shipping and 5% off

if i buy 2 magazines at 20 each i should have

total : 40
total HT excluded : 37,92
5% discount : 36,02
vat : 1,98
total to pay : 38
++
shipping : 2
free shipping : - 2
shipping has no vat in France

this is what i get on the site (attached file)

total : 40
5 % discount : - 1,90
shipping : 2
free shiping : - 2
total HT excluded : 36,01
vat : 2,09
total to pay :38,10

I first noticed that the rounding is not done on each articles but on both (36,02 - 36,01)

and the VAT is not correct, customer pay 10 cents more, because it has to be effective once the discounts have been applied (on the vat excluded price)

Is there a way i could change the workflow to have a correct sum ?

do i have to change something in the uc_vat module or in the uc_discount_alt module ?

Thanks to all for all the work

helltae’s picture

To #68
Doing a manual patch (manual for search the strings to change) of uc_discounts.module and using code from #30 works for me.

uc_discounts.module is at: sites/all/modules/uc_discounts_alt/uc_discounts

Using 6.x-2.x-dev

Bronislovas’s picture

The same. #30 manualy applied patch works so far so good. And for product price altered field to display correct price it seems to help the following fix:

After applying the patch in uc_discounts.module in uc_discounts_get_discounted_price_for_product function
REPLACE: return $product->sell_price - $total_discount_amount;
WITH: return get_uc_price($product) - $total_discount_amount;

root66’s picture

There's still a problem with patch #30. The sub-total and total price is correct now, but if you enable "Show VAT amounts in separate columns at checkout." (admin/store/settings/taxes/vat) the VAT amounts ignore the discount(s).

Example and difference between uc_discounts_alt and uc_coupon (which has a special fix for uc_vat):
1 x Product (incl. 19% VAT) - 4,99 €

uc_coupon:
Sub-total: 4,99€
Coupon (20%): -1,00€
Shipping (incl. 19%): 5,95€
Total: 9,94€
incl. 19%: 1,59€

uc_discounts_alt:
Sub-total: 4,99€
20% discount: -1,00€
Shipping (incl. 19%): 5,95€
Total: 9,94€
incl. 19%: 1,75€

Now an example with two products and two different VATs:
Product-A (incl. 19% VAT) - 4,99 €
Product-B (incl. 7% VAT) - 29,00 €

uc_coupon:
Sub-total: 33,99€
Coupon (20%): -6,80€
Shipping (incl. 19% VAT): 5,95€
Total: 33,14€
incl. 7%: 1,52€
incl. 19%: 1,59€

uc_discounts_alt:
Sub-total: 33,99€
20% Discount: -6,80€
Shipping (incl. 19%): 5,95€
Total: 33,14€
incl. 7%: 1,90€
incl. 19%: 1,75€

As you can see everything except the VAT amounts are identical. The VAT amounts ignore the discounts in uc_discounts_alt. I think the solution can be found by looking in the last changes of uc_coupon, because they had the same problems before.

Update:

uc_vat supports a 'tax_adjustment' callback. Take a look into the 'uc_vat_line_item_price_alter' (uc_vat.module) function: $callback = _line_item_data($line_item['type'], 'tax_adjustment');

and uc_coupon registers that callback:

/**
* Implementation of hook_line_item().
*/
function uc_coupon_line_item() {
$items[] = array(
'id' => 'coupon',
'title' => t('Coupon discount'),
'tax_adjustment' => 'uc_coupon_tax_adjustment',
'weight' => 0,
'default' => FALSE,
'stored' => TRUE,
'add_list' => TRUE,
'calculated' => TRUE,
);
return $items;
}

nitebreed’s picture

Subscribing

celia_ccs’s picture

hello,

I have tried many configuration, patches, modules versions ..etc and i just cannot get to the right calculations in the checkout. It's a shame because discounts are actually not usuable for European shops right now. At least I haven't found a solution.

I would be happy to sponsor a development to solve the problems between uc_vat and uc_discounts_alt
Contact me if you are interested.

nitebreed’s picture

Same for me... unfortunately none of the solutions posted seem to work

miguel_angel’s picture

Hi!
This message is for all of you that say "it doesn't work".
My solution at #59 works for my particular case.
If it doesn't work for yours, please, give us information about your problem.
With more detailed information we can get an almost optimal solution.

Thank you.

bartezz’s picture

Priority: Normal » Major
Status: Needs work » Active

A three year old issue that has never been solved... such a shame!

@miguel_angel your patch in #59 ofcourse doesn't run against latest dev anymore. Have you ever updated to latest and do you have a new patch?

I'm also marking this as major. One of the reasons is mentioned by longwave in #6 and others after this, incorrect calculations make this module unusable for EU (and possibly other countries) web shops.

Pointed http://drupal.org/node/1330476 and http://drupal.org/node/824510 to this issue as I believe these are similar issues.

Cheers

bartezz’s picture

Status: Active » Needs review

@Gapa, have tried your patch in #30 and it fixes part of it, but am still having some troubles;

My setup:

  • Drupal (6.22) + Ubercart (6.x-2.7) + UC Vat (6.x-1.2) + UC Discounts Alt (6.x-2.4)
  • Products are added with sell prices exclusive of VAT
  • 6.75 Flat rate shipping rate added exclusive of VAT
  • VAT rate is 19%
  • On admin/store/settings/taxes/1/edit 'discount' unchecked
  • On admin/store/settings/taxes/vat only checked 'Allow per line-item tax adjustments' and 'Use shipping line item settings from the tax rate configuration pages'
  • On admin/store/uc_discounts/add created a discount of 50% on product class with min qualifying amount of 1 item

First I had some troubles with incorrect VAT calculations, possibly due to change in Ubercart 6.x-2.6, this was solved here http://drupal.org/node/1170992#comment-5536898

Then I noticed that discounts on both cart and checkout page were calculated based on sell price exclusive of VAT. Tried many things mentioned in this and other issues and many different settings but nothing worked.

/cart/checkout before patch:

Subtotal                23.68 (correct -> 19.90 incl 19% VAT)
Shipping                 8.03 (correct ->  6.75 incl 19% VAT)    
Total discount           9.95 (should be 23.68 - 50% = 11.84)
Subt ex VAT             16.70 (correct -> 19.90 - 50% + 6.75)
VAT 19%                  5.06 (should be 16.70 * 19% = 3.17)
Order total             21.76 (should be 19.90 - 50% + 6.75 + 19% = 19.87)

I have applied #30 by hand to UC Discounts Alt (6.x-2.4) and since then the discounts are correctly calculated after VAT has been applied. Yet the patch causes the subtotal exclusive of VAT and the VAT line to be incorrect. Seems like they don't know about the discounted prices.

Subtotal                23.68 (correct -> 19.90 + 19%)
Shipping                 8.03 (correct ->  6.75 + 19%)    
Total discount          11.84 (correct -> 23.68 - 50%)
Subt ex VAT             14.81 (should be 19.90 - 50% + 6.75 = 16.70)
VAT 19%                  5.06 (should be (19.90 - 50% + 6.75) * 19% = 3.17)
Order total             19.87 (correct -> 19.90 - 50% + 6.75 + 19%)

So partially there but no complete fix. Tried manually applying patches in #59 but they are based on the dev release from sept 2009 I believe so that's not really working out well.

Back to square one? Can't believe there isn't a live webshop out there that doesn't have uc_vat and uc_discount_alt combined which is working... can anyone who's got this working share a bit more info?!

Cheers

bartezz’s picture

Status: Needs review » Needs work

Sorry, I changed to incorrect status.

Have done some more dubugging. I converted to UC Discounts Alt (6.x-2.4) without patch in #30 and I'm back to the results in the first code block in #77.

Now I went to my VAT setting admin/store/settings/taxes/1/edit and checked the 'discount' as a taxed line item. This resulted in a perfect calculation in the Order Total Preview pane on the checkout form;

Subtotal                23.68 (correct -> 19.90 + 19%)
Shipping                 8.03 (correct ->  6.75 + 19%)    
Total discount          11.84 (correct -> 23.68 - 50%)
Subt ex VAT             16.70 (correct -> 19.90 - 50% + 6.75)
VAT 19%                  3.17 (correct -> (19.90 - 50% + 6.75) * 19%)
Order total             19.87 (correct -> 19.90 - 50% + 6.75 + 19%)

The only issues remaining are the /cart page and the Cart Contents pane on the /cart/checkout page. The discount here is calculated based upon the sell price ex vat which is incorrect. Back to the drawing board!

For now I'm using uc_coupon which works fine but I'd like to switch to uc_discounts_alt!

Cheers

jvieille’s picture

I had related problems mentioned there :
http://drupal.org/node/1909316
http://drupal.org/node/1909052
For me, this module works perfectly without any patch until several tax rates are applied to the discounts line item.
then, taxes are calculated and accrued from each tax rate.

I tried to manually apply #30 method - this does not work at all.
The best I got was with #59 which definitely makes sense - handling every discount as a separate line item.
Together with http://drupal.org/node/1170992 I got the right calculation

Thanks!

jvieille’s picture

#59 is really the way to go.
To make it working with the latest Ubercart and UC Discount:

Apply the #59 patches manually, and :
in uc_discounts.js, as the patch does not totally matches the current code - theer is no more a uc_discountsRemoveDiscountLineItems(updateLineItems) funtion :
Do not alter this unexisting function and replace

//Updates the discount line items list and updates totals
function uc_discountsRenderLineItems(line_items, show_message) {
  if ((window.set_line_item == null) || (line_items == null)) {
    return;
  }

  //Remove total discount line item
  remove_line_item(Drupal.settings.uc_discounts.line_item_key_name);

  var total_amount = 0;
  for (i = 0; i < line_items.length; i++) {
    var line_item = line_items[i];
    total_amount += parseFloat(line_item["amount"]);
  }

  //Add total discount line item
  if (line_items.length > 0) {
    set_line_item(Drupal.settings.uc_discounts.line_item_key_name,
                  Drupal.settings.uc_discounts.total_discount_text, total_amount,
                  parseFloat(Drupal.settings.uc_discounts.line_item_weight) + 0.5,
                  1,
                  false);
  }

  // Update total
  if (window.render_line_items) {
    render_line_items();
  }

  //If there is tax in the system, recalculate tax
  if (window.getTax) {
    getTax();
  }
}

by

 function uc_discountsRenderLineItems(line_items, show_message, discount_rates_ids) {
  if ((window.set_line_item == null) || (line_items == null)) {
    return;
  }
  //Remove total discount line item
    for (i = 0; i < discount_rates_ids.length; i++) {
      remove_line_item(discount_rates_ids[i]);
    }

    // Calculate totals per discount rate id
    var total_amount = [];
    var total_amount_names = [];
    // Reset totals
    for (i = 0; i < line_items.length; i++) {
      var line_item = line_items[i];
      total_amount[parseInt(line_item["rate_type"])] = 0;
      total_amount_names[parseInt(line_item["rate_type"])] = "";
    }
  for (i = 0; i < line_items.length; i++) {
    var line_item = line_items[i];
  //Add total discount line item
        total_amount[parseInt(line_item["rate_type"])] += parseFloat(line_item["amount"]);
        if (line_item["rate_name"] != "") {
          total_amount_names[parseInt(line_item["rate_type"])] = " - " + line_item["rate_name"];
        }
    }

    //Add a total discount line item per rate type
  if (line_items.length > 0) {
        var index = 0;
        for (i = 0; i < discount_rates_ids.length; i++) {
          // Extract the index from discount key name
          suffix = discount_rates_ids[i].substr(12);
          if (suffix == "") {
            suffix = 0;
          }
          index = parseInt(suffix);
          set_line_item(discount_rates_ids[i], 
              Drupal.settings.uc_discounts.total_discount_text + total_amount_names[index], total_amount[index], 
              parseFloat(Drupal.settings.uc_discounts.line_item_weight) + 0.5, 1, false);
        }
  }
  
  // Update total
  if (window.render_line_items) {
      render_line_items();
  }

  //If there is tax in the system, recalculate tax
  if (window.getTax) {
    getTax();
  }
}

in UC order, in uc_order.line_item.inc
replace

function _line_item_data($item_id, $key) {
  $items = _line_item_list();
  foreach ($items as $item) {
    if ($item['id'] == $item_id) {
      return $item[$key];
    }
  }
}

by

function _line_item_data($item_id, $key) {
  $items = _line_item_list();
  foreach ($items as $item) {
    if (strpos($item["id"], "uc_discounts") !== false) {
      if (substr ($item['id'], 0, 12)  == $item_id) {
        return $item[$key];
      }
    }  
    else {
      if ($item['id'] == $item_id) {
         return $item[$key];
      }
    }
  }
}

This discounts module is now a killer!!!

Still need works to provide a patch...

jvieille’s picture

Status: Needs work » Needs review
StatusFileSize
new84.97 KB

There had some other changes needed for making this working smoothly, specifically from the order pane.
I attached the modified uc_discounts.module from 2.4 version.
this file includes 2 other fixes
http://drupal.org/node/1931864
http://drupal.org/node/1067440

This also needed some changes in Ubercart uc_order.lien_item.inc.

function _line_item_data($item_id, $key) {
  $items = _line_item_list();
  foreach ($items as $item) {
/*.. VAT support http://drupal.org/node/476348#comment-7142316 */
    if (strpos($item["id"], "uc_discounts") !== false) {
      if (substr ($item['id'], 0, 12)  == $item_id) {
        return $item[$key];
      }
    }  
    else {
      if ($item['id'] == $item_id) {
         return $item[$key];
      }
    }
/* end */
  }
}
/**
 * Calculates the total value of line items of types that should be calculated.
 */
function uc_line_items_calculate($order) {
  $total = 0;

  $context = array(
    'revision' => 'altered',
    'type' => 'line_item',
    'subject' => array(
      'order' => $order,
    ),
  );

  if (isset($order->line_items) && is_array($order->line_items)) {
    foreach ($order->line_items as $item) {
      $context['subject']['line_item'] = $item;
/*.. VAT support http://drupal.org/node/476348#comment-7142316 */
      if (strpos($item["type"],LINE_ITEM_KEY_NAME) !== false) {
        $total += uc_price($item['amount'], $context);
      }
      else {
        if (_line_item_data($item['type'], 'calculated') == TRUE) {
          $total += uc_price($item['amount'], $context);
        }        
      }
/* end */     
    }
  }
  return $total;
}

Not patch, sorry
robert.koza’s picture

edit..

grabby’s picture

@jvieille I think the reason this issue is still under review is that it’s unclear what exactly is being reviewed. Any chance you could post what your uc_discounts.js ended up being for example? I couldn’t follow all the changes. Thanks.

jvieille’s picture

The issue is about 2 problems
1) getting this module working with VAT: prices are set included VAT, which is a different logic of the standard Ubercart design where product prices are displayed without taxes.
2) Handling multiple tax rates : if you apply a discount to a product, the corresponding tax has to be altered. The module did not care.

The second issue makes this module unusable unless you accept fancy tax amounts when applying a discount to a multi taxes order

I did many changes before getting this module really working.

No patch, just hand changes noted // JV... // end JV...

My working module based on 6.x-2.4 is attached
Also the modified Ubercart file uc_order.line_item.inc
You'll have to remove _.test at the end of these files.

Hope this helps

grabby’s picture

Thanks for that! I am mainly interested in a percentage discount. I set a discount of 10% for a particular product. On the cart and at the top of the checkout page the discount and subtotal including discounts are shown exclusive of VAT, but in the order summary on the checkout page it is shown correctly. Actually the order summary isn’t perfect either, because the line showing discounts exclusive of VAT includes it and the line showing subtotal excluding VAT includes it also. The last two lines, VAT and order total, are correct.

To illustrate, for a product price of 1,000, a VAT of 25% and a discount of 10% the cart shows

Subtotal: 1,000
Total discount: 80
Subtotal incl discounts: 720

The top of the checkout page shows

Price: 1,000
Discount: 80

and the Order Summary shows

Subtotal: 1,000
Total discount - VAT: -100
Subtotal excluding VAT: 800
VAT: 180
Order total: 900

For the above I set “Discount VAT” as a taxed line item on the VAT page. Since there is only one VAT rate there are no issues related to multiple rates.

I’m not sure what I’m doing wrong if this works for you @jvieille or where we go from here. I’m all too happy to help with moving this forward in any way I can!

jvieille’s picture

Did you got this using my code, or the unchanged module?

grabby’s picture

I got it with your attachments, both of them. To use my previous example, with only your modified uc_discounts_alt module but not your uc_order.line_item.inc file – i.e. with the original (6.x-2.12) uc_order.line_item.inc file – I get the following for the cart

Subtotal: 1,000
Total discount: 80
Subtotal incl discounts: 720

The top of the checkout page shows

Price: 1,000
Discount: 80

and the Order Summary shows

Subtotal: 1,000
Total discount - VAT: -100
Subtotal excluding VAT: 720
VAT: 180
Order total: 900

And then going completely back to the original 6.x-2.4 uc_discounts_alt module and original 6.x-2.12 uc_order.line_item.inc file I get the following

Subtotal: 1,000
Total discount: 80
Subtotal incl discounts: 720

The top of the checkout page shows

Price: 1,000
Discount: 80

and the Order Summary shows

Subtotal: 1,000
Total discount - VAT: -80
Subtotal excluding VAT: 720
VAT: 200
Order total: 920

Just to be safe I flushed caches between all variations. Any ideas?

jvieille’s picture

StatusFileSize
new48.02 KB

EDIT: I changed the number with the correct numbers for VAT 25%

This is what I get - in this case, the discount is a fixed amount per item if above a certain quantity, similar result with percentage or when using codes.

I put the number I got and indicated in parenthesis what you should get using your example. This seems to be very different

CART
Line item:
unit price : 12
Quantity 10
Total 120

Subtotal
Excluded VAT 2.1% 117.53 (800)
VAT 2.47 (200)
Subtotal 120 (1000)
(Note : no discount taken in account at this stage)

Discount (2 * 10 € - VAT): 19,59 (80)
Subtotal excluded VAT, including discount : 97.94 (720)
(Note : the discount is correctly calculated excluded VAT as indicated)

CHECKOUT
Cart content
Excluded VAT : 117.53 (800)
VAT : 2.47 (200)
Price 120 (1000)
(Note : yes, this indication is misleading, as it does not take the discount into account)

Command preview
Excluded VAT / VAT / Total

sub-total: 117.53 € / 2.47 € / 120.00 € (800 / 200 / 1000)
Total discount on VAT 2.1% : -19.59 € / -0.41 € / -20.00 € (-80/ -20 / -100)
Total order : 97.94 € / 2.06 € / 100.00 € (720/ 180 / 900)

Just thinking about it, the UC_VAT module was crappy either. I made significant changes to get it calculating correctly.
I am attaching the modified uc_vat.module file.

grabby’s picture

I agree, you’re getting different results than I do, but the results you get aren’t correct for my example either. With the uc_vat.module you attached my results are almost exactly the same as without, namely the cart shows

Subtotal: 1,000
Total discount: 80
Subtotal incl discounts: 720

The top of the checkout page shows

Price: 1,000
Discount: 80

and the Order Summary shows

Subtotal: 1,000
Total discount - VAT: -100
Subtotal excluding VAT: 720
VAT: 180
Order total: 900

The only difference is that the Subtotal excluding VAT on the Order Summary is now correct.

The results you get for my example are incorrect as follows (I am putting the correct results in parentheses)

CART

Subtotal excluding VAT: 750 (800)
VAT: 225 (200)
Subtotal: 1000 (correct)

Discount excluding VAT: 75 (80)
Subtotal excluding VAT including discount: 675 (720)

CHECKOUT

Cart content excluding VAT: 750 (720)
VAT: 250 (180)
Price: 1000 (900)

What I am after is the following result

CART

Subtotal: 1000
Total discount: 100
Subtotal incl discounts: 900

CHECKOUT - top

Price: 1,000
Discount: 100

CHECKOUT – Order Summary

Subtotal: 1,000
Total discount - VAT: -80
Subtotal excluding VAT: 720
VAT: 180
Order total: 900

To summarize the problem, all prices and discounts should include VAT, with VAT and final price not including VAT broken out on the order summary and the payment page. I have yet to find a way to do this. Thanks for your effort, though!

jvieille’s picture

I just guessed the number, did not tried them, so I might have mistaken.
But your data are probably incorrect. VAT is 20%, not 25% - I think I would have put these values if calculated on that basis.

Try replacing the attached file in UC_VAT.

grabby’s picture

As I mentioned, I DID use your attached uc_vat.module. Just to be clear, with an original price of 1000, a VAT of 25% and a discount of 10%, the original VAT is 200 (800 x 1.25 = 1000), the discounted price is 900 (1000 x 0.9 = 900) and the discounted VAT is 180 (720 x 1.25 = 900). The original price of 1000 includes the 25% VAT, as does the discounted price of 900. This is the simplest example I can think of, and one that applies to most VAT countries.

jvieille’s picture

You are correct, I mistaken the VAT calculation.

I edit my post #88 above, hopefully correct now. Is it what you expect / get or not?

The numbers at the top of the checkout page are misleading, as they do not take the discount into account. Maybe it would be better to hide this pane as everything is fine at the bottom of the form.

grabby’s picture

You know, if the cart was accurate and gave the customer an actual idea of how much things cost and how much they were expected to pay, I’d say sure, let’s hide the cart pane at the top of the checkout page. That’s not the case, however. And since the Order Summary isn’t 100% correct there’s not much point in hiding things. Your edit of #88 is closer to what I’m expecting, but I wrote exactly what I’m expecting in #89. If it was up to me I’d change the status of this issue to “active”.

jvieille’s picture

I have to study your numbers closer, but sure, this issue is "active". There is much room for improvement.
The point is for me that it is good enough for a production system. I live with that since 9 months, 1000 orders and nobody complained to date...

grabby’s picture

Status: Needs review » Active

The French must be more forgiving than the Hungarians : - )

I’ll change the status to active and see if anyone complains.

dunx’s picture

Issue summary: View changes
StatusFileSize
new214.3 KB
new5.4 KB
new48.01 KB
new6.36 KB
new82.6 KB

After 5 days I have this working (for me at least).

Scenario is I'm in the UK and charging 20% VAT. I've created a 10% discount when multiple products are purchased. The product costs £15 (including VAT).

Expected result is if I purchase 2 products for a normal price of £30.00, I should see a £3.00 discount made up of £2.50 on the product and £0.50 on the VAT, for a final price of £27.00.

I used the solutions given in #30, #59, #80 and #81, plus additional tweaks of my own. I've attached the 4 files I'm using, plus a screenshot showing the Baskets, Checkout (top and bottom) and Review pages. I have uc_order v2.14, uc_discounts (alt) v2.4 and uc_vat v1.2 installed, but with some of the files being overwritten entirely from other contributions above, I'm not 100% sure what I've ended up with! Use at your own risk.

Under VAT settings /admin/store/settings/taxes the "Discount VAT" item is checked. Yours may not be called that until you've placed the new file versions.

I've used hook_form_alter to add the "Any discounts are shown below." to the top Checkout panel, which is floated right using CSS.

function mymodule_form_alter(&$form, &$form_state, $form_id) {

  switch ($form_id) {
  case 'uc_cart_checkout_form':
    if (module_exists('uc_discounts')) {
      $form['panes']['cart']['cart']['#value'] .= '<div class="discount_msg">Any discounts are shown below.</div>';
    }
    break;
  }

Drupal 6 seems seems to be too near end of life to spend the effort of turning these 4 file changes in to patches for 3 different modules controlled by 3 different authors and have any hope they'd be released synchronously in any useful fashion. Hopefully this solution is useful for somebody who isn't yet moving to Drupal 7.

dunx’s picture

Tweak for VAT rounding.

In uc_discounts.module remove the code to round the discounts:

          $messages[] = t("The discount, '@short_description', was applied @times_applied times for a discount of @discount_total", $options);
        }
      }
    }

>> Comment this out...
    //Don't round discounts!
    //$discount->amount = round($discount->amount, 2);

    //Add this discount's amount to running total
    $total_discount_amount += $discount->amount;

    //Add this discount to list of discounts applied to order
    $discounts[] = $discount;
  }


In uc_vat.module add code to round VAT down:

    else {
      $context['type'] = 'line_item';
      $context['subject']['line_item'] = $line;
      $altered = uc_price($line['amount'], $context);
    }

>> Add these lines...
    // Always round VAT down from unrounded value calculated in uc_discounts.
    if ( strstr($line['type'], 'uc_discounts') ) {
      $line['amount'] = floor($line['amount']*100)/100;
    }

    $rows[] = array(
      array('data' => '<b>' . check_plain($title) . ':</b>', 'align' => 'right'),

This is fine for UK HMRC rules (round 0.5p or more up to 1p, else round down) as we are rounding the VAT discount for display purposes. The total amount of VAT on the order total is still calculated and displayed correctly.