Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Recommended Posts

Posted

I realized today with my site wide qty discounts, that tax is not being shown correct... it is being calculated into the total correctly, but not being shown...

 

here is an example:

Sub-Total: $659.00

Quantity Discount (10%): -$65.90

UPS Ground (Best Way): $7.00

VA TAX 4.5%: $29.65

Total: $626.78

 

the total of $626.78 is correct. but the tax shown is not ($29.65). it is the tax on the old subtotal... the module is set up to re-calculate tax on the new subttotal (659 - 65.90).

 

but the total is correct:

659.00 - 65.90 = 593.10 x (4.5%) = 26.6895

593.10 + 7 + 26.6895 = $626.7895

 

I thought this would do it:

$order->info['tax'] = $order->info['tax'] - $tod_amount;

 

but its not ($tod_amount is the discount applied to the tax; which is the difference between the tax on the old subtotal and the new one)... how can I subtract the tax discount amount from the current tax to get it to show the new tax amount?

Posted

I think the problem here is that these mods have not been update to MS1.

 

MS1 changed the way Tax Group details are stored. Basically this means that when recalculating tax, you have to deduct the change in tax form the tax groups.

 

If you give me a link to the exact contribution you are using I'll try and updat the logic to MS1

Trust me, I'm an Accountant.

Posted

thanks Ian,

 

I sort of got it by looking at your low order fee. but I only have one tax class. Some users may have more than one tax class, so I'd like to update it to MS1 logic for users with more than one class (so it will pick the right class).

 

here is the code for the part that processes the discounts and applies it to the order total (recalculating subtotal, total, and tax if these attributesa re turned on in the admin):

        function process()

       {

               global $order, $currencies, $cart, $ot_subtotal;     

               if ($this->calculate_tax == 'true') {

                   $tod_amount = $this->calculate_discount($order->info['tax']);

               }

               $od_amount = $this->calculate_discount($this->get_order_total());

               if ($od_amount>0)

               {

          	 $tax_description = tep_get_tax_description(1, $order->delivery['country']['id'], $order->delivery['zone_id']);

        if (MODULE_QTY_DISCOUNT_RATE_TYPE == 'percentage') $title_ext = ' ('.$this->calculate_rate($cart->count_contents()).'%)';

        $this->deduction = $od_amount+$tod_amount;

                       $this->output[] = array('title' => $this->title . $title_ext . ':',

                                               'text' => '<b>-' . $currencies->format($od_amount) . '</b>',

                                               'value' => $od_amount);

                       $order->info['total'] -= $this->deduction;

     $order->info['tax'] -= $tod_amount;

     $order->info['tax_groups']["$tax_description"] -= $tod_amount;

       if ($this->sort_order < $ot_subtotal->sort_order) {

        $order->info['subtotal'] -= $this->deduction;

       }

               }

       }

The only thing necessary for evil to flourish is for good men to do nothing

- Edmund Burke

Posted

PS.. maybe I didn't explain myself well, Ian. I am the author of this mod and am trying to get it updated to correct MS1 logic for myself and others.

The only thing necessary for evil to flourish is for good men to do nothing

- Edmund Burke

Posted

it's Ok.

 

Understood you perfectly well the first time :)

 

I'll post the code here later on, I use it in the discount coupon mod and it's just a matter of looping through the tax groups.

 

Cheers

Trust me, I'm an Accountant.

Posted

I appriciate your help on this Ian... looking forward to the tax looping code

The only thing necessary for evil to flourish is for good men to do nothing

- Edmund Burke

Posted

Joshua,

 

These are obviously just code snippets but should help.

 

First there is a little function to find the tax rate for the current tax group.

You can put this function into general.php

 

////

// Get tax rate from tax description

 function tep_get_tax_rate_from_desc($tax_desc) {

   $tax_query = tep_db_query("select tax_rate from " . TABLE_TAX_RATES . " where tax_description = '" . $tax_desc . "'");

   $tax = tep_db_fetch_array($tax_query);

   return $tax['tax_rate'];

 }

 

The first snippet calculates a percentage discounts effect on tax.

given that the percentage is in $p_deduct

 

          $tod_amount=0;

         reset($order->info['tax_groups']);

         while (list($key, $value) = each($order->info['tax_groups'])) {

           $god_amout=0;

           $tax_rate = tep_get_tax_rate_from_desc($key);

           $net = $tax_rate * $order->info['tax_groups'][$key];

           if ($net>0) {

             $god_amount = $order->info['tax_groups'][$key] * $p_deduct/100;

             $tod_amount += $god_amount;

             $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;

           }

         }           

         $order->info['tax'] -= $tod_amount;

         $order->info['total'] -= $tod_amount;

 

The second re-calculates tax for a fixed deduction in $f_deduct

 

          $tod_amount = 0;

         reset($order->info['tax_groups']);

         while (list($key, $value) = each($order->info['tax_groups'])) {

           $tax_rate = tep_get_tax_rate_from_desc($key);

           $net = $tax_rate * $order->info['tax_groups'][$key];

           if ($net>0) {

             $ratio1 = $f_deduct/$net;

             $god_amount = $order->info['tax_groups'][$key] * $ratio1;

             $tod_amount += $god_amount;

             $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;

           }

         }           

         $order->info['tax'] -= $tod_amount;

         $order->info['total'] -= $tod_amount;

 

HTH

Trust me, I'm an Accountant.

Posted

thanks Ian that gets me started, but I get these errors for these lines:

 

82   reset($order->info['tax_groups']); 

83   while (list($key, $value) = each($order->info['tax_groups'])) {

 

Warning: Variable passed to reset() is not an array or object in C:Inetpubwwwrootmacgamesincludesmodulesorder_totalot_qty_discount.php on line 82

 

Warning: Variable passed to each() is not an array or object in C:Inetpubwwwrootmacgamesincludesmodulesorder_totalot_qty_discount.php on line 83

The only thing necessary for evil to flourish is for good men to do nothing

- Edmund Burke

Posted

whoop my bad... forgot to make $order a global in the recalculate tax function.

The only thing necessary for evil to flourish is for good men to do nothing

- Edmund Burke

Posted

thanks Ian.

 

the percentage recalculation works like a charm :)

 

the fixed discount recalculation isn't working though:

 

Example:

Sub-Total: $579.00

Qty Discount: -$10.00

UPS Ground: $7.00

VA TAX 4.5%: $26.06

Total: $602.06

 

the tax is correct for the old subtotal (579 x .045 = 26.06)

 

but the tax should be 25.61 (569 x .045 = 25.61)

The only thing necessary for evil to flourish is for good men to do nothing

- Edmund Burke

Posted

ok I had made alittle mistake.

 

it is re-calculating the tax for flat discounts now, but still not correctly:

 

Sub-Total: $579.00

Qty Discount: -$10.00

UPS Ground: $7.00

VA TAX 4.5%: $23.83

Total: $599.83

 

the tax should be $25.61

The only thing necessary for evil to flourish is for good men to do nothing

- Edmund Burke

Posted

I have got it Ian.

 

on flat discounts the difference in tax will ALWAYS be the same. just think about it... it doesn't matter the size of the order. here are 2 examples:

 

Sub-Total: $579.00

Qty Discount: -$10.00

UPS Ground: $7.00

VA TAX 4.5%: $25.61

Total: $601.61

 

Sub-Total: $217,993.50

Qty Discount: -$10.00

UPS Ground: $7.00

VA TAX 4.5%: $9,809.26

Total: $227,799.76

 

from one extreme to the other, but the difference in tax each time is exactly the same:

(579 x.045) = 26.055

(569 x .045) = 25.605

difference in tax = .45

 

(217,993.5 x .045) = 9,809.7075

(217,983.5 x .045) = 9,809.2575

difference in tac = .45

 

thinking maybe this was just the magic of the number 10, I tried this with other values ($5, $20, and $18.56 just to throw a loop)... it works the same each time.

 

The difference in tax will always equal the tax rate x the discount / 100

 

so then the calculation for the re-calculation of taxes on flat rate discounts becomes:

	$tod_amount = 0; 

reset($order->info['tax_groups']); 

  while (list($key, $value) = each($order->info['tax_groups'])) { 

 $god_amout=0; 

 $tax_rate = tep_get_tax_rate_from_desc($key); 

 $net = $tax_rate * $order->info['tax_groups'][$key]; 

   if ($net>0) { 

	 $ratio1 = ($tax_rate*$od_amount)/100;

	 $god_amount = $ratio1; 

	 $tod_amount += $god_amount; 

	 $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount; 

   } 

  }            

}

The only thing necessary for evil to flourish is for good men to do nothing

- Edmund Burke

Posted

Joshua,

 

Congratulatio, you found a bug in the discount coupon code. The code should actually be

 

      

         $ratio1 = $f_deduct/$this->get_order_total();

         $tod_amount = 0; 

         reset($order->info['tax_groups']); 

         while (list($key, $value) = each($order->info['tax_groups'])) { 

           $tax_rate = tep_get_tax_rate_from_desc($key); 

           $net = $tax_rate * $order->info['tax_groups'][$key]; 

           if ($net>0) { 

             $god_amount = $order->info['tax_groups'][$key] * $ratio1; 

             $tod_amount += $god_amount; 

             $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount; 

           } 

         }            

         $order->info['tax'] -= $tod_amount; 

         $order->info['total'] -= $tod_amount;

 

I hope :)

Trust me, I'm an Accountant.

Posted

yeah Ian that works... though seems a little round about way of getting the deduction:

 

take for example (at 4.956% interest):

 

20/256.78 ($f_deduct/$this->get_order_total()) = .077887686...

12.7260168*.07787... ($order->info['tax_groups'][$key] * $ratio1) = .9912

 

that gets you the correct tax difference, but it is much easier & faster to just go:

4.956/100*20 = .9912

 

the difference in the tax (what needs deducted) will always be the tax on the difference of the 2 subtotal (a flat difference in this case)... (it is just simple algebra).

 

take this:

let x = the subtotal prior to discounts.

let y = the flat discount amount.

we will use 5% interest for simplicity.

we are attempting to find D, the tax difference.

 

D = .05x - .05(x - y)

D = .05x - .05x + .05y

D = .05y

 

see, the difference in tax is equal to the amount of tax on the difference. No eral need for any of those fancy ratio calculations. Simple algebra will get ya there much faster :wink:

The only thing necessary for evil to flourish is for good men to do nothing

- Edmund Burke

Posted

Josh,

 

Again your right, the simpler calculation you have is less complicated and in your code situation musch easier.

 

Just to try and justify my solution, my code is lifted (partially) from my discount coupon code. It has to also account for the situation where only some products/categories are eligible for a discount. In this case the get_order_total function takes this into account. Hence the reason I used it in my code above.

 

:)

Trust me, I'm an Accountant.

  • 2 years later...
Posted (edited)

Hi,

 

I'm still having troubles with the right calculation of the tax.

 

This is what I now got :

 

// Calculate tax group deductions

$ratio1 = $f_deduct/$this->get_order_total();

$tod_amount = 0;

reset($order->info['tax_groups']);

while (list($key, $value) = each($order->info['tax_groups'])) {

$god_amount = 0;

$tax_rate = tep_get_tax_rate_from_desc($key);

$net = $tax_rate * $order->info['tax_groups'][$key];

if ($net>0) {

$ratio1 = ($tax_rate*$od_amount)/100;

$god_amount = $ratio1;

$tod_amount += $god_amount;

$order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;

}

}

}

$od_amount = (round($amount*10)/10)*$od_pc/100;

$order->info['tax'] -= $tod_amount;

$order->info['total'] -= $tod_amount;

$od_amount = $od_amount + $tod_amount;

}

return $od_amount;

 

But it still calculates the tax amount over the whole subtotal and shippingcosts together.

Instead of the subtotal - customer discount amount.

 

Could someone point me in the right direction?

 

Regards,

 

Dom?

Edited by cDGo IT Consultancy
  • 4 weeks later...
Posted

NEED HELP!

 

This module doesn't work for me at all. I believe I followed the instructions properly. Just a test, I set

 

2:40,3:50

 

percentage rate type

 

But nothing happens.

 

Help!

 

My site sells DVD. And everything is for $30 (tax included) but we give discounts depending on the quantity.

 

I'm willing to pay anyone who can help me fix this problem.

Posted

Any ecommerce platform needs the abilty to give discounts yet the flaw in the current discount module means that you either give customers the right total (important!) and the wrong VAT amount, or the wrong Total and the right VAT amount (see previous posting http://www.oscommerce.com/forums/index.php?showtopic=167906).

 

Is there really nobody out there able to fix this fundamental flaw? I'm sure those interested will contribute towards the cost?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...