Author Topic: Tax is added for product with no tax  (Read 17911 times)

aravot

  • Peter
  • Moderator
  • Sr. Member
  • *
  • Posts: 2874
    • VirtueMart Extensions
Tax is added for product with no tax
« on: May 19, 2011, 20:11:41 pm »
Tax is added for product with no tax; VAT Id = 0 none
(If not mistaken I remember this was fixed, tried to look at old tracker but no more)

Product display is different for different configuration but in all configuration tax is add but it shouldn't. Will try to explain with images.

Tax mode = Based on shipping address.


Product has no tax assign to it; VAT Id = 0 (-none-) hence no tax should be added.


Product in front-end is shown correctly without tax.


However product in checkout has tax applied to it; Wrong




Tax mode = Based on vendor address.


Product has no tax assign to it; VAT Id = 0 (-none-) hence no tax should be added.


Product in front-end is shown incorrectly (it shows with tax it shouldn't because product has no tax assign to it).


Product in checkout has tax applied to it; Wrong


Price display changes when in 'Shopper Group'-> 'Show Prices including tax' is checked/unchecked but the final result (checkout) product has tax.

hadassah

  • Beginner
  • *
  • Posts: 16
Re: Tax is added for product with no tax
« Reply #1 on: June 19, 2011, 19:08:48 pm »
To solve this problem, go to SHOPPER->LIST SHOPPER GROUPS.

Edit the DEFAULT shopper. Uncheck the "Show Prices Including Tax" checkbox.

That fixed it for me.

aravot

  • Peter
  • Moderator
  • Sr. Member
  • *
  • Posts: 2874
    • VirtueMart Extensions
Re: Tax is added for product with no tax
« Reply #2 on: June 19, 2011, 19:25:40 pm »
To solve this problem, go to SHOPPER->LIST SHOPPER GROUPS.

Edit the DEFAULT shopper. Uncheck the "Show Prices Including Tax" checkbox.

That fixed it for me.

Your reply has nothing to do with the bug, the bug is about when VAT Id is equal to ZERO

Dansterpower

  • Beginner
  • *
  • Posts: 11
Re: Tax is added for product with no tax
« Reply #3 on: December 15, 2011, 04:04:29 am »
Hello, I am having this exact same problem.

No VAT (sales) tax is assigned to a Virtuemart product but Virtuemart is still charging tax.

Joomla 1.5.25 and Virtuemart 1.1.8.

Does anyone have a fix for this problem?

We are willing to pay a consultant for any advice or a fix.

patrixshah

  • Beginner
  • *
  • Posts: 1
Re: Tax is added for product with no tax
« Reply #4 on: December 19, 2011, 12:45:05 pm »
I was facing the same issue with my Joomla 1.5.22 and VirtueMart 1.1.8 stable version.

After debugging I found the solution of same.

Actual Problem with code:
--------------------------------
- While getting tax rate  from VM system using call of get_taxrate( $ship_to_info_id = '' ) method in joomlavm/administrator/components/com_virtuemart/classes/ps_product.php file.
- In that function have some conditions which stores the taxrate in session, and that is based on vendor_id.
- Every products with same vendor_id will be applied with same taxrate. Though in Admin panel we have not set VAT/TAX Rate field value. (i.e. 0 - none ).

/**
    * Get the tax rate...
    * @author soeren
    * @return int The tax rate found
    */
   function get_taxrate( $ship_to_info_id = '' ) {
      global $page;
      $ps_vendor_id = $_SESSION["ps_vendor_id"];
      $auth = $_SESSION['auth'];

      if( !defined('_VM_IS_BACKEND' ) || $page == 'product.product_list' || $page == 'order.order_print') {

         $db = new ps_DB;

         if ($auth["show_price_including_tax"] == 1) {

            require_once( CLASSPATH . 'ps_checkout.php' );
            if (! ps_checkout::tax_based_on_vendor_address ($ship_to_info_id) ) {
               if( $auth["user_id"] > 0 ) {

                  $ship_to_info_id = !empty($ship_to_info_id)? $ship_to_info_id : vmGet( $_REQUEST, 'ship_to_info_id');

                     //**  Select country and state  */
                     if( empty($ship_to_info_id)){                           
                        $q = "SELECT state, country FROM #__{vm}_user_info WHERE user_id='". $auth["user_id"] . "'";
                        $db->query($q);
                        $db->next_record();
                        $state = $db->f("state");
                        $country = $db->f("country");
                     }
                     else {
                        $q  = "SELECT country, state FROM #__{vm}_user_info WHERE user_info_id='" . $ship_to_info_id."'";
                        $db->query($q);
                        $db->next_record();
                        $state = $db->f("state");
                        $country = $db->f("country");
                     }

                  $q = "SELECT tax_rate FROM #__{vm}_tax_rate WHERE tax_country='$country'\n";
                  if( !empty($state)) {
                     $q .= "AND (tax_state='$state' OR tax_state=' $state ' OR tax_state='-')";
                  }
                  $db->query($q);
                  if ($db->next_record()) {
                     $_SESSION['taxrate'][$ps_vendor_id] = $db->f("tax_rate");
                  }
                  else {
                     $_SESSION['taxrate'][$ps_vendor_id] = 0;
                  }
               }
               else {
                  $_SESSION['taxrate'][$ps_vendor_id] = 0;
               }

            }
            else {
               if( !isset( $_SESSION['taxrate'][$ps_vendor_id] )) {
                  // let's get the store's tax rate
                  $q = "SELECT `tax_rate` FROM #__{vm}_vendor, #__{vm}_tax_rate ";
                  $q .= "WHERE tax_country=vendor_country AND #__{vm}_vendor.vendor_id=1 ";
                  // !! Important !! take the highest available tax rate for the store's country
                  $q .= "ORDER BY `tax_rate` DESC";
                  $db->query($q);
                  if ($db->next_record()) {
                     $_SESSION['taxrate'][$ps_vendor_id] = $db->f("tax_rate");
                  }
                  else {
                     $_SESSION['taxrate'][$ps_vendor_id] = 0;
                  }
               }
               return $_SESSION['taxrate'][$ps_vendor_id];
            }

         }
         else {
            $_SESSION['taxrate'][$ps_vendor_id] = 0;
         }

         return $_SESSION['taxrate'][$ps_vendor_id];
      }
      else {
         return 0;
      }
   }

Solution with Code:
-------------------------
File Paht: joomlavm/administrator/components/com_virtuemart/classes/ps_product.php
------------------------------------------------------------------------------------------------------------------
Replace the entire method with this:
-------------------------

/**
    * Get the tax rate...
    * @author soeren
    * @return int The tax rate found
    */
   function get_taxrate( $ship_to_info_id = '' ) {
      global $page;
      $ps_vendor_id = $_SESSION["ps_vendor_id"];
      $auth = $_SESSION['auth'];

      if( !defined('_VM_IS_BACKEND' ) || $page == 'product.product_list' || $page == 'order.order_print') {

         $db = new ps_DB;

         if ($auth["show_price_including_tax"] == 1) {

            require_once( CLASSPATH . 'ps_checkout.php' );
            if (! ps_checkout::tax_based_on_vendor_address ($ship_to_info_id) ) {
               if( $auth["user_id"] > 0 ) {

                  $ship_to_info_id = !empty($ship_to_info_id)? $ship_to_info_id : vmGet( $_REQUEST, 'ship_to_info_id');

                     //**  Select country and state  */
                     if( empty($ship_to_info_id)){                           
                        $q = "SELECT state, country FROM #__{vm}_user_info WHERE user_id='". $auth["user_id"] . "'";
                        $db->query($q);
                        $db->next_record();
                        $state = $db->f("state");
                        $country = $db->f("country");
                     }
                     else {
                        $q  = "SELECT country, state FROM #__{vm}_user_info WHERE user_info_id='" . $ship_to_info_id."'";
                        $db->query($q);
                        $db->next_record();
                        $state = $db->f("state");
                        $country = $db->f("country");
                     }

                  $q = "SELECT tax_rate FROM #__{vm}_tax_rate WHERE tax_country='$country'\n";
                  if( !empty($state)) {
                     $q .= "AND (tax_state='$state' OR tax_state=' $state ' OR tax_state='-')";
                  }
                  $db->query($q);
                  if ($db->next_record()) {
                     $_SESSION['taxrate'][$ps_vendor_id] = $db->f("tax_rate");
                  }
                  else {
                     $_SESSION['taxrate'][$ps_vendor_id] = 0;
                  }
               }
               else {
                  $_SESSION['taxrate'][$ps_vendor_id] = 0;
               }

            }
            else {
               if( !isset( $_SESSION['taxrate'][$ps_vendor_id] )) {
                  // let's get the store's tax rate
                  $q = "SELECT `tax_rate` FROM #__{vm}_vendor, #__{vm}_tax_rate ";
                  $q .= "WHERE tax_country=vendor_country AND #__{vm}_vendor.vendor_id=1 ";
                  // !! Important !! take the highest available tax rate for the store's country
                  $q .= "ORDER BY `tax_rate` DESC";
                  $db->query($q);
                  if ($db->next_record()) {
                     $_SESSION['taxrate'][$ps_vendor_id] = $db->f("tax_rate");
                  }
                  else {
                     $_SESSION['taxrate'][$ps_vendor_id] = 0;
                  }
               }
               /**
                * Added Patch in Joomla VM for VAT auto added to all Products.
                * In Admin we have set VAT combo with value "0".
                * But in Front-end its calculate value by applying VAT. As the Shopper Module have facility to include TAX check box.
                *
                * Patch to avoid VAT include in case product table have field and value product_tax_id=0 then
                * Avoid to include VAT in front-end by reset $_SESSION['taxrate'][$ps_vendor_id] with value 0.
                *
                * @author Pratik Shah
                * @since  December 2011
                *
                * @package JoomlaVM
                */
               if ($this->get_field($product_id, 'product_tax_id')>0)
                  return $_SESSION['taxrate'][$ps_vendor_id];
               else
               {
                  $_SESSION['taxrate'][$ps_vendor_id] = 0;
               }

            }

         }
         else {
            $_SESSION['taxrate'][$ps_vendor_id] = 0;
         }

         return $_SESSION['taxrate'][$ps_vendor_id];
      }
      else {
         return 0;
      }
   }


Good Luck All.