Jump to content
Sign in to follow this  
wemke

Oder Editor tax problem

Recommended Posts

I installed Order Editor: great contrib!!! But I encounter a problem. It shows the order like following:

- subtotal

- shipping

- tax

- total

 

The tax is clearly based on the subtotal.

 

When I add a 10% discount for my regular customers, the order shows as following:

- subtotal

- discount

- shipping

- tax

- total

 

The discount displays correctly, the total changes by 10%, but... the tax is still the same. The amount is based on the subtotal without the discount.

 

Not correct for my administration and the taxes I have to pay 4 times per year. It would be a shame if I can't use the invoices that merge automatically from Order Editor.

 

Who can help me? Or does no one use the invoice that comes with Order Editor? How do you make your final invoices in this case?

 

Hoping to hear from you! Kind regards,

Wemke

Share this post


Link to post
Share on other sites

A lot of people seem to have had this problem over the years, but I did not find an answer anywhere. I have tried to find a solution, or at least a workaround. So I share this here to maybe start a new discussion.

 

There where (at least) two problems with the order editor:

1) For some reason (which I did not find out) it mixed up the order of the different totals.

2) Tax was not calculated on discounts and extras.

 

Here my attempt at a solution. I'm using AJAX, so I only modified edit_orders_ajax.php but it should work the same for edit_orders.php, I guess.

 

1) To define a sort order for components:

At the beginning of edit_orders_ajax.php ADD:

  $sort_order = array('ot_subtotal' => '1',
 'ot_shipping' => '3',
 'ot_modul_spesen' => '4',
 'ot_custom' => '5',
 'ot_total' => '7',
 'ot_tax' => '8');

Or, use whatever sort order you have defined in your order totals modules. However, ot_tax should be placed after discounts and custom totals to ensure that tax is calculated properly.

 

REPLACE all

'sort_order' => $j);

for components that show up in the $order_totals array, WITH:

'sort_order' => ((array_key_exists($order_totals[$i]['code'], $sort_order)) ? $sort_order[$order_totals[$i]['code']] : '5'));

for other components, WITH:

'sort_order' => ((array_key_exists($ot_class, $sort_order)) ? $sort_order[$ot_class] : '5'));

 

2) The tax problem:

AFTER:

if ($ot_title != '') { //7

ADD:

//This changes the value of ot_tax
if ($order_totals[$i]['code'] == 'ot_tax') {
  $order_totals[$i]['value'] += $tax_to_add;
  $order_totals[$i]['text'] = $currencies->format($order_totals[$i]['value'], true, $order->info['currency'], $order->info['currency_value']);
}
//This calculates the tax on additional components
if (($order_totals[$i]['code'] != 'ot_total') && ($order_totals[$i]['code'] != 'ot_subtotal') && ($order_totals[$i]['code'] != 'ot_tax') && ($order_totals[$i]['code'] != 'ot_shipping')) {
  $tax_to_add += $order_totals[$i]['value'] * $tax / (100 + $tax);
}

AFTER:

} elseif ( (tep_not_null($ot_value)) && (tep_not_null($ot_title)) ) {

ADD:

//This calculates tax on ot_custom
$tax_to_add += $ot_value * $tax / (100 + $tax);

Hope it works for others as well...

Share this post


Link to post
Share on other sites
QUOTE (djmonkey1 @ Feb 13 2007, 09:19 PM) *

Find in admin/edit_orders.php

CODE

// 1.4.0.1 Shipping Tax

and a few lines below that change

CODE

if($ot_class == "ot_shipping")//a good place to add in custom total components

to

CODE

if( ($ot_class == "ot_shipping") || ($ot_class == "ot_custom") )//a good place to add in custom total components

 

then find

CODE

//just adding in shipping tax, don't mind me

$ot_shipping_query = tep_db_query("

SELECT value

FROM " . TABLE_ORDERS_TOTAL . "

WHERE orders_id = '" . (int)$oID . "'

AND class = 'ot_shipping'");

and change it to

CODE

//just adding in shipping tax, don't mind me

$ot_shipping_query = tep_db_query("

SELECT value

FROM " . TABLE_ORDERS_TOTAL . "

WHERE orders_id = '" . (int)$oID . "'

AND (class = 'ot_shipping' OR class = 'ot_custom')");

 

and see how it works then.

Share this post


Link to post
Share on other sites

I gave this a try with no luck. You are definitly onto something here as this seems to be the best solution that I have seen so far.

 

I am having a hard time understanding what is going on here. Why cant you just mimick what the calculations for shipping are doing to not count that again. This would be similar to the second solution above this post however, this solution is using a VERY old version of edit_orders.php which isnt even close to the code in the current.

 

Any other ideas out there?

 

 

A lot of people seem to have had this problem over the years, but I did not find an answer anywhere. I have tried to find a solution, or at least a workaround. So I share this here to maybe start a new discussion.

 

There where (at least) two problems with the order editor:

1) For some reason (which I did not find out) it mixed up the order of the different totals.

2) Tax was not calculated on discounts and extras.

 

Here my attempt at a solution. I'm using AJAX, so I only modified edit_orders_ajax.php but it should work the same for edit_orders.php, I guess.

 

1) To define a sort order for components:

At the beginning of edit_orders_ajax.php ADD:

  $sort_order = array('ot_subtotal' => '1',
 'ot_shipping' => '3',
 'ot_modul_spesen' => '4',
 'ot_custom' => '5',
 'ot_total' => '7',
 'ot_tax' => '8');

Or, use whatever sort order you have defined in your order totals modules. However, ot_tax should be placed after discounts and custom totals to ensure that tax is calculated properly.

 

REPLACE all

'sort_order' => $j);

for components that show up in the $order_totals array, WITH:

'sort_order' => ((array_key_exists($order_totals[$i]['code'], $sort_order)) ? $sort_order[$order_totals[$i]['code']] : '5'));

for other components, WITH:

'sort_order' => ((array_key_exists($ot_class, $sort_order)) ? $sort_order[$ot_class] : '5'));

 

2) The tax problem:

AFTER:

if ($ot_title != '') { //7

ADD:

//This changes the value of ot_tax
if ($order_totals[$i]['code'] == 'ot_tax') {
  $order_totals[$i]['value'] += $tax_to_add;
  $order_totals[$i]['text'] = $currencies->format($order_totals[$i]['value'], true, $order->info['currency'], $order->info['currency_value']);
}
//This calculates the tax on additional components
if (($order_totals[$i]['code'] != 'ot_total') && ($order_totals[$i]['code'] != 'ot_subtotal') && ($order_totals[$i]['code'] != 'ot_tax') && ($order_totals[$i]['code'] != 'ot_shipping')) {
  $tax_to_add += $order_totals[$i]['value'] * $tax / (100 + $tax);
}

AFTER:

} elseif ( (tep_not_null($ot_value)) && (tep_not_null($ot_title)) ) {

ADD:

//This calculates tax on ot_custom
$tax_to_add += $ot_value * $tax / (100 + $tax);

Hope it works for others as well...

Share this post


Link to post
Share on other sites
I gave this a try with no luck. You are definitly onto something here as this seems to be the best solution that I have seen so far.

 

I am having a hard time understanding what is going on here. Why cant you just mimick what the calculations for shipping are doing to not count that again. This would be similar to the second solution above this post however, this solution is using a VERY old version of edit_orders.php which isnt even close to the code in the current.

 

Any other ideas out there?

 

My solution to this was to modify the orders_ajax file directly. NOTE: this works only when a single 10% tax rate is applied to the entire total.

 

about line 42:

 

$orders_total_query = tep_db_query("select * from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . $order_id . "' and class != 'ot_tax' order by sort_order");//first anything but the tax (this part is trickier, let's do it appart)

 

add one line ahead of it:

 

$shiptax = 0;
$orders_total_query = tep_db_query("select * from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . $order_id . "' and class != 'ot_tax' order by sort_order");//first anything but the tax (this part is trickier, let's do it appart)

 

somewhere around line 54 is:

 

		  } else {
		  $total += (float)$order_total['value'];
	  }

 

make it like this:

 

		  } elseif ($order_total['class'] == 'ot_shipping') {
			$shiptax = (float)$order_total['value'] - ((float)$order_total['value']/1.1);
		  $total += (float)$order_total['value'];
	  } else {
		  $total += (float)$order_total['value'];
	  }

 

Now line 75 is:

 

		$new_value = round($taxes[$i]['value'], 4);

 

Change it to:

 

		$new_value = round($taxes[$i]['value'] + $shiptax, 4);

 

Essentially the way this works is when the original code gos through the order totals, when it finds 'ot_shipping' amount, calculates what the 10% tax amount is included (i.e. Australian GST) and then adds that amount to the tax amount in the update query.

 

It is a rather quick and nasty hack, but of you need to do something simple like this for your tax rate, then it will do the trick.

 

Cheers.

Share this post


Link to post
Share on other sites

Hi, I'm having the same problem.

The total price without tax is correct only if no ot_custom field is entered. as soon as one custom field is there, the subtotal becomes the total and the tax field is not updated.... Didi you guys find a solution ?

 

 

 

 

My solution to this was to modify the orders_ajax file directly. NOTE: this works only when a single 10% tax rate is applied to the entire total.

 

about line 42:

 

$orders_total_query = tep_db_query("select * from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . $order_id . "' and class != 'ot_tax' order by sort_order");//first anything but the tax (this part is trickier, let's do it appart)

 

add one line ahead of it:

 

$shiptax = 0;
$orders_total_query = tep_db_query("select * from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . $order_id . "' and class != 'ot_tax' order by sort_order");//first anything but the tax (this part is trickier, let's do it appart)

 

somewhere around line 54 is:

 

		  } else {
		  $total += (float)$order_total['value'];
	  }

 

make it like this:

 

		  } elseif ($order_total['class'] == 'ot_shipping') {
			$shiptax = (float)$order_total['value'] - ((float)$order_total['value']/1.1);
		  $total += (float)$order_total['value'];
	  } else {
		  $total += (float)$order_total['value'];
	  }

 

Now line 75 is:

 

		$new_value = round($taxes[$i]['value'], 4);

 

Change it to:

 

		$new_value = round($taxes[$i]['value'] + $shiptax, 4);

 

Essentially the way this works is when the original code gos through the order totals, when it finds 'ot_shipping' amount, calculates what the 10% tax amount is included (i.e. Australian GST) and then adds that amount to the tax amount in the update query.

 

It is a rather quick and nasty hack, but of you need to do something simple like this for your tax rate, then it will do the trick.

 

Cheers.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×