News:

Support the VirtueMart project and become a member

Main Menu

Tax per Bill displaying tax that is not configured to display

Started by jchudzik, June 13, 2013, 23:48:59 PM

Previous topic - Next topic

jchudzik

I'm trying to set up multiple taxes so that the separate taxes are displayed on the bill to account for Canadian GST, PST, and HST.

We need to calculate the tax differently for each product because we are using VirtueMart as the payment processor for our training courses and the taxes are dependent on the city where the training course is being held. The tax is not based on the shipping address of the shopper like most online stores.

I could set up the tax rules for each province to be "Tax by Product" and then set up the products to use these rules this works, but when it displays in the cart, it accumulates the GST and PST together and we want it to show the PST and GST separately.

Instead, I set up separate Tax Rules for each province in Canada (for the PST, or HST) and gave them each a unique category based on the province. I then created products and put them in the categories by province (e.g BC, Alberta, Sask., Manitoba). This seems to give us what need in that the PST and GST is displayed separately on the bill. The problem I'm seeing with this method is that the cart is displaying an extra tax. The extra tax seems to be from the record with the highest id in the #__virtuemart_calcs table.

I attached screenshots of the cart and also how the tax rules and product are set up. I don't see a reason why it would display the Newfoundland HST for a product that has a category of Manitoba. The cart is displaying the GST and PST correctly for the product.

This is for Joomla 2.5, VirtueMart 2.0.20b.

[attachment cleanup by admin]

jchudzik

I added the screenshot for the HST NF.

[attachment cleanup by admin]

jchudzik

After some investigation, it looks like the $trule['subTotal'] for the taxRule is not being set properly in calculationh.php:
It seems to be set in this section for all tax rules but later on, there is a tax rule with subTotal as unset and this is what causes the issue with the extra tax.

if(!empty($this->_cartData['taxRulesBill'])) {
foreach($this->_cartData['taxRulesBill'] as $k=>&$trule){
//                    echo "id: ". $trule['virtuemart_calc_id'];
//                    echo "trule isset before: ".isset($trule['subTotal']);
if(!isset($trule['subTotal'])) $trule['subTotal'] = 0.0;
if($product->product_tax_id != 0) {
if($product->product_tax_id == $k) {
$trule['subTotal']+= $this->_cartPrices[$cartproductkey]['subtotal_with_tax'];
}
}
elseif(!empty($trule['calc_categories'])){
$set = array_intersect($trule['calc_categories'],$product->categories);
if(count($set)>0){
$trule['subTotal'] += $this->_cartPrices[$cartproductkey]['subtotal_with_tax'];
//                            echo 'DB Rule '.$trule['calc_name'].' is per category subTotal '.$trule['subTotal'];
vmdebug('DB Rule '.$trule['calc_name'].' is per category subTotal '.$trule['subTotal']);
}
}
else {
$trule['subTotal'] += $this->_cartPrices[$cartproductkey]['subtotal_with_tax'];
}
//                    echo "trule isset: ".isset($trule['subTotal']);                                   
//                    echo "trule subtotal: ".$trule['subTotal'];
}
}


I added the following code just before cartRuleCalculation is called for the taxRulesBill to make sure that all unset subTotals get initialized to 0.0. There is probably a better way to resolve this problem but I am no php expert.

foreach($this->_cartData['taxRulesBill'] as $k=>&$trule){
    if(!isset($trule['subTotal'])) $trule['subTotal'] = 0.0;
}
$cartTax = $this->roundInternal($this->cartRuleCalculation($this->_cartData['taxRulesBill'], $toTax));

jchudzik

There is code in setCartPrices in vmpsplugin.php that is unsetting the subTotal values for the rules in under taxRulesBill:


//This construction makes trouble, if there are products with different vats in the cart
//on the other side, it is very unlikely to have different vats in the cart and simultan it is not possible to use a fixed tax rule for the shipment
if(!empty($calculator->_cartData['VatTax']) and count ($calculator->_cartData['VatTax']) == 1){
  $taxrules = $calculator->_cartData['VatTax'];
  foreach($taxrules as &$rule){
    $rule['subTotal'] = $cart_prices[$this->_psType . 'Value'];
  }
} else {
  $taxrules = $calculator->_cartData['taxRulesBill'];
  foreach($taxrules as &$rule){
        unset($rule['subTotal']);
  }
}


I'm not sure why this code unsets the subtotal but it is definitely the cause of the problem in this issue and other cases where we use TaxPerBill. In our case, we don't need to calculate the Shipping tax because we are using Virtual Shipping. Therefore, I disabled the call to setCartPrices for the Virtual Shipping case in the function onSelectedCalculatePrice in vmpsplugin.php:


if (strpos($cart_prices_name, "Virtual Shipment") == true) {
    return NULL;
}
$this->setCartPrices ($cart, $cart_prices, $method);


I'm not sure if this is a bug in the Virtual Shipment shipping method module or in vmpsplugin.php.