Top 5 Programming Questions and Answers to Manage VAT Invoices in Magento - Part 1

The e-merchants who sell products in a country where free trade agreements prevail especially outside the Europe needs to sell products with zero vat. Programmers develop a code for them to add the vat feature on their websites. But it’s not an easy task to add this feature so that is why many programmers face issues while integrating VAT feature and they ask for help on the different platform. This article contains most asked questions by top programmers regarding integration of zero vat. The answers in this article are provided by community members and not represents us. These are the following questions regarding Magento Vat Addon.

Question No. 1

A user who has Magento 1.7 is having the issue to remove tax of the customers who entered their vat number on the checkout page.


See the code to override the Tax model generate() in Magento.

class My_Module_Model_Tax_Calculation extends Mage_Tax_Model_Calculation

    public function getRate($request)
        if (!$request->getCountryId() || !$request->getCustomerClassId() || !$request->getProductClassId()) {
            return 0;

        $country_id = $request->getCountryId();

        if ($country_id == 'BE' && $this->getCustomer() && $this->getCustomer()->getTaxvat()) {
            return 0;          

        $cacheKey = $this->_getRequestCacheKey($request);
        if (!isset($this->_rateCache[$cacheKey])) {
            Mage::dispatchEvent('tax_rate_data_fetch', array('request'=>$request));
            if (!$this->hasRateValue()) {
                $rateInfo = $this->_getResource()->getRateInfo($request);
            } else {
            $this->_rateCache[$cacheKey] = $this->getRateValue();
            $this->_rateCalculationProcess[$cacheKey] = $this->getCalculationProcess();
        return $this->_rateCache[$cacheKey];

Question No. 2

A user needs a code help to the rate of Vat. He has this code to get the rate of tax by product.

    //$_product = our product object
    $store = Mage::app()->getStore('default');
    $request = Mage::getSingleton('tax/calculation')->getRateRequest(null, null, null, $store);
    $taxclassid = $product->getData('tax_class_id')
    $percent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxclassid));

He has written this code to get rate via order object but unable to achieve.

     * Get Tax Values By Order
     * @param Mage_Sales_Orders_Model $order
     * @param float $amount [montant à traiter]
     * @param bool $include_tax [indique si $amount contient les taxes]
     * @return array $result [tax_ratio, tax_percent , tax_amount, ttc_amount, ht_amount]
    public function getTaxValuesByOrder($order,$amount,$include_tax = false){

        //On traite le montant passé en paramètre
        $amount = round(floatval($amount),3);

        //On calcule le pourcentage de la taxe
        $tax_info = $order->getFullTaxInfo();
        $tax_percent = round(floatval($tax_info[0]['percent']),2);
        $tax_coeff =100 / (100 + $tax_percent);

            $ttc_amount = $amount;
            $ht_amount = $ttc_amount * $tax_coeff;
            $tax_amount = $ttc_amount - $ht_amount;

            $ht_amount = $amount;
            $tax_amount = $ht_amount * $tax_percent / 100;
            $tcc_amount = $ht_amount + $tax_amount;

        return array(
            'tax_ratio'     =>  $tax_coeff,
            'tax_percent'     =>  $tax_percent,
            'tax_amount'    =>  $tax_amount,
            'ttc_amount' =>  $ttc_amount,
            'ht_amount'     =>  $ht_amount


See the right code below.

 *  Get current rate
 * @return  float   $rate
public function getCurrentRate(){
    $calc = Mage::getSingleton('tax/calculation');
    $rates = $calc->getRatesForAllProductTaxClasses($calc->getRateRequest());

    foreach ($rates as $class=>$rate) {
       $result = $rate;

    return floatval($result);

Use this script for addition and subtraction of tax.

 * ConvertAmount
 * @param   float   $amount     Amount to convert
 * @param   float   $rate       Tax rate (if NULL the rate is automatically selected)
 * @param   bool    $add_tax    Sets the direction of conversion (if true rate ($ rate) will be added, if false it will be deducted)
 * @return float    $amount     Converted amount
public function ConvertAmount($amount,$rate=NULL,$add_tax=true){

    if($rate == NULL)
        $rate = $this->getCurrentRate();

    $tax_coeff =100 / (100 + $rate);

        $amount = $amount / $tax_coeff;
        $amount = $amount * $tax_coeff;
    return round($amount,2);

Question No. 3

A user is having issues while changing the words Tax to Vat in invoices. This is his code at the moment.

Subtotal  £100.97  
Shipping & Handling  £8.00  
Internal Credit  £0.00  
Grand Total (Excl.Tax)  £108.97  
Tax  £20.19 
Grand Total (Incl.Tax)  £129.16  


Please find the right rows containing word tax, just have look at the code having term tax.

grep 'Tax' app/locale/ -rsn

app/locale/en_US/Mage_Adminhtml.csv:250:"Customer Tax Classes","Customer Tax Classes"
app/locale/en_US/Mage_Adminhtml.csv:332:"Excl. Tax","Excl. Tax"
app/locale/en_US/Mage_Adminhtml.csv:406:"Import and Export Tax Rates","Import and Export Tax Rates"
app/locale/en_US/Mage_Adminhtml.csv:416:"Incl. Tax","Incl. Tax"
app/locale/en_US/Mage_Adminhtml.csv:506:"Manage Tax Rules","Manage Tax Rules"
app/locale/en_US/Mage_Adminhtml.csv:507:"Manage Tax Zones and Rates","Manage Tax Zones and Rates"
app/locale/en_US/Mage_Adminhtml.csv:702:"Product Tax Classes","Product Tax Classes"
app/locale/en_US/Mage_Bundle.csv:19:"Excl. Tax","Excl. Tax"
app/locale/en_US/Mage_Bundle.csv:24:"Incl. Tax","Incl. Tax"
app/locale/en_US/Mage_Catalog.csv:36:"Add Tax","Add Tax"
app/locale/en_US/Mage_Catalog.csv:322:"Incl. Tax","Incl. Tax"
app/locale/en_US/Mage_Catalog.csv:699:"Total incl. Tax: %1$s","Total incl. Tax: %1$s"
app/locale/en_US/Mage_Checkout.csv:116:"Estimate Shipping and Tax","Estimate Shipping and Tax"
app/locale/en_US/Mage_Checkout.csv:117:"Excl. Tax","Excl. Tax"
app/locale/en_US/Mage_Checkout.csv:133:"Incl. Tax","Incl. Tax"
app/locale/en_US/Mage_Cms.csv:45:"Customer Tax Class Information","Customer Tax Class Information"
app/locale/en_US/Mage_Cms.csv:93:"Product Tax Class Information","Product Tax Class Information"
app/locale/en_US/Mage_Customer.csv:320:"Show Tax/VAT Number","Show Tax/VAT Number"
app/locale/en_US/Mage_Customer.csv:337:"Tax Class","Tax Class"
app/locale/en_US/Mage_Customer.csv:338:"Tax/VAT number","Tax/VAT number"
app/locale/en_US/Mage_Downloadable.csv:28:"Excl. Tax","Excl. Tax"
app/locale/en_US/Mage_Downloadable.csv:35:"Incl. Tax","Incl. Tax"
app/locale/en_US/Mage_GoogleCheckout.csv:28:"Disable Default Tax Tables","Disable Default Tax Tables"
app/locale/en_US/Mage_GoogleCheckout.csv:29:"Discount Tax","Discount Tax"
app/locale/en_US/Mage_Payment.csv:100:"Tax Amount","Tax Amount"
app/locale/en_US/Mage_Paypal.csv:56:"Buyer\'s Tax ID","Buyer\'s Tax ID"
app/locale/en_US/Mage_Paypal.csv:57:"Buyer\'s Tax ID Type","Buyer\'s Tax ID Type"
app/locale/en_US/Mage_Reports.csv:91:"Order Taxes Report Grouped by Tax Rate","Order Taxes Report Grouped by Tax Rate"
app/locale/en_US/Mage_Sales.csv:229:"Excl. Tax","Excl. Tax"
app/locale/en_US/Mage_Sales.csv:272:"Incl. Tax","Incl. Tax"
app/locale/en_US/Mage_Sales.csv:438:"Order Taxes Report Grouped by Tax Rates","Order Taxes Report Grouped by Tax Rates"
app/locale/en_US/Mage_Sales.csv:563:"Refund Shipping (Excl. Tax)","Refund Shipping (Excl. Tax)"
app/locale/en_US/Mage_Sales.csv:564:"Refund Shipping (Incl. Tax)","Refund Shipping (Incl. Tax)"
app/locale/en_US/Mage_Sales.csv:615:"Sales Tax","Sales Tax"
app/locale/en_US/Mage_Sales.csv:711:"Tax Amount","Tax Amount"
app/locale/en_US/Mage_Sales.csv:712:"Tax Percent","Tax Percent"
app/locale/en_US/Mage_Sales.csv:784:"Total Tax","Total Tax"
app/locale/en_US/Mage_Tax.csv:4:"Add New Tax Rate","Add New Tax Rate"
app/locale/en_US/Mage_Tax.csv:5:"Add New Tax Rule","Add New Tax Rule"
app/locale/en_US/Mage_Tax.csv:15:"Apply Customer Tax","Apply Customer Tax"
app/locale/en_US/Mage_Tax.csv:17:"Apply Tax On","Apply Tax On"
app/locale/en_US/Mage_Tax.csv:18:"Apply discount on price including tax is calculated based on store tax, if ""Apply Tax after Discount"" is selected.","Apply discount on price including tax is calculated based on store tax, if ""Apply Tax after Discount"" is selected."
app/locale/en_US/Mage_Tax.csv:30:"Customer Tax Class","Customer Tax Class"
app/locale/en_US/Mage_Tax.csv:31:"Customer Tax Class Information","Customer Tax Class Information"
app/locale/en_US/Mage_Tax.csv:32:"Customer Tax Classes","Customer Tax Classes"
app/locale/en_US/Mage_Tax.csv:36:"Default Tax Destination Calculation","Default Tax Destination Calculation"
app/locale/en_US/Mage_Tax.csv:40:"Display Full Tax Summary","Display Full Tax Summary"
app/locale/en_US/Mage_Tax.csv:46:"Display Zero Tax Subtotal","Display Zero Tax Subtotal"
app/locale/en_US/Mage_Tax.csv:50:"Edit Tax Rate","Edit Tax Rate"
app/locale/en_US/Mage_Tax.csv:52:"Excl. Tax","Excl. Tax"
app/locale/en_US/Mage_Tax.csv:53:"Excl. Tax:","Excl. Tax:"
app/locale/en_US/Mage_Tax.csv:54:"Excluding Tax","Excluding Tax"
app/locale/en_US/Mage_Tax.csv:55:"Export Tax Rates","Export Tax Rates"
app/locale/en_US/Mage_Tax.csv:56:"Grand Total (Excl. Tax)","Grand Total (Excl. Tax)"
app/locale/en_US/Mage_Tax.csv:57:"Grand Total (Excl.Tax)","Grand Total (Excl.Tax)"
app/locale/en_US/Mage_Tax.csv:58:"Grand Total (Incl. Tax)","Grand Total (Incl. Tax)"
app/locale/en_US/Mage_Tax.csv:59:"Grand Total (Incl.Tax)","Grand Total (Incl.Tax)"
app/locale/en_US/Mage_Tax.csv:60:"Grand Total Excl. Tax","Grand Total Excl. Tax"
app/locale/en_US/Mage_Tax.csv:61:"Grand Total Incl. Tax","Grand Total Incl. Tax"
app/locale/en_US/Mage_Tax.csv:62:"Import / Export Tax Rates","Import / Export Tax Rates"
app/locale/en_US/Mage_Tax.csv:63:"Import Tax Rates","Import Tax Rates"
app/locale/en_US/Mage_Tax.csv:64:"Inc. Tax","Inc. Tax"
app/locale/en_US/Mage_Tax.csv:65:"Incl. Tax","Incl. Tax"
app/locale/en_US/Mage_Tax.csv:66:"Incl. Tax:","Incl. Tax:"
app/locale/en_US/Mage_Tax.csv:67:"Include Tax In Grand Total","Include Tax In Grand Total"
app/locale/en_US/Mage_Tax.csv:68:"Including Tax","Including Tax"
app/locale/en_US/Mage_Tax.csv:69:"Including and Excluding Tax","Including and Excluding Tax"
app/locale/en_US/Mage_Tax.csv:72:"Manage Customer Tax Classes","Manage Customer Tax Classes"
app/locale/en_US/Mage_Tax.csv:73:"Manage Product Tax Classes","Manage Product Tax Classes"
app/locale/en_US/Mage_Tax.csv:74:"Manage Tax Rates","Manage Tax Rates"
app/locale/en_US/Mage_Tax.csv:75:"Manage Tax Rules","Manage Tax Rules"
app/locale/en_US/Mage_Tax.csv:76:"Manage Tax Zones & Rates","Manage Tax Zones & Rates"
app/locale/en_US/Mage_Tax.csv:80:"New Tax Rate","New Tax Rate"
app/locale/en_US/Mage_Tax.csv:88:"Product Tax Class","Product Tax Class"
app/locale/en_US/Mage_Tax.csv:89:"Product Tax Class Information","Product Tax Class Information"
app/locale/en_US/Mage_Tax.csv:90:"Product Tax Classes","Product Tax Classes"
app/locale/en_US/Mage_Tax.csv:102:"Shipping & Handling (Excl.Tax)","Shipping & Handling (Excl.Tax)"
app/locale/en_US/Mage_Tax.csv:103:"Shipping & Handling (Incl.Tax)","Shipping & Handling (Incl.Tax)"
app/locale/en_US/Mage_Tax.csv:104:"Shipping & Handling Tax","Shipping & Handling Tax"
app/locale/en_US/Mage_Tax.csv:105:"Shipping (Excl. Tax)","Shipping (Excl. Tax)"
app/locale/en_US/Mage_Tax.csv:106:"Shipping (Incl. Tax)","Shipping (Incl. Tax)"
app/locale/en_US/Mage_Tax.csv:107:"Shipping Excl. Tax (%s)","Shipping Excl. Tax (%s)"
app/locale/en_US/Mage_Tax.csv:108:"Shipping Incl. Tax (%s)","Shipping Incl. Tax (%s)"
app/locale/en_US/Mage_Tax.csv:114:"Subtotal (Excl. Tax)","Subtotal (Excl. Tax)"
app/locale/en_US/Mage_Tax.csv:115:"Subtotal (Excl.Tax)","Subtotal (Excl.Tax)"
app/locale/en_US/Mage_Tax.csv:116:"Subtotal (Incl. Tax)","Subtotal (Incl. Tax)"
app/locale/en_US/Mage_Tax.csv:117:"Subtotal (Incl.Tax)","Subtotal (Incl.Tax)"
app/locale/en_US/Mage_Tax.csv:119:"Tax Calculation Based On","Tax Calculation Based On"
app/locale/en_US/Mage_Tax.csv:120:"Tax Calculation Method Based On","Tax Calculation Method Based On"
app/locale/en_US/Mage_Tax.csv:121:"Tax Class for Shipping","Tax Class for Shipping"
app/locale/en_US/Mage_Tax.csv:122:"Tax Classes","Tax Classes"
app/locale/en_US/Mage_Tax.csv:123:"Tax Identifier","Tax Identifier"
app/locale/en_US/Mage_Tax.csv:124:"Tax Rate","Tax Rate"
app/locale/en_US/Mage_Tax.csv:125:"Tax Rate Information","Tax Rate Information"
app/locale/en_US/Mage_Tax.csv:126:"Tax Rule Information","Tax Rule Information"
app/locale/en_US/Mage_Tax.csv:127:"Tax Rules","Tax Rules"
app/locale/en_US/Mage_Tax.csv:128:"Tax Section","Tax Section"
app/locale/en_US/Mage_Tax.csv:129:"Tax Titles","Tax Titles"
app/locale/en_US/Mage_Tax.csv:130:"Tax rate cannot be removed. It exists in tax rule","Tax rate cannot be removed. It exists in tax rule"
app/locale/en_US/Mage_Tax.csv:131:"Tax rates at the same priority are added, others are compounded.","Tax rates at the same priority are added, others are compounded."
app/locale/en_US/Mage_Tax.csv:149:"You cannot delete this tax class as it is used in Tax Rules. You have to delete the rules it is used in first.","You cannot delete this tax class as it is used in Tax Rules. You have to delete the rules it is used in first."
app/locale/en_US/Mage_Weee.csv:3:"Apply Tax To FPT","Apply Tax To FPT"
app/locale/en_US/Mage_Weee.csv:11:"Fixed Product Tax","Fixed Product Tax"
app/locale/en_US/Mage_Weee.csv:12:"Fixed Product Taxes","Fixed Product Taxes"
app/locale/en_US/Mage_Weee.csv:18:"Total Incl. Tax","Total Incl. Tax"
app/locale/en_US/Mage_XmlConnect.csv:275:"Grand Total (Excl. Tax)","Grand Total (Excl. Tax)"
app/locale/en_US/Mage_XmlConnect.csv:276:"Grand Total (Incl. Tax)","Grand Total (Incl. Tax)"
app/locale/en_US/Mage_XmlConnect.csv:531:"Subtotal (Excl. Tax)","Subtotal (Excl. Tax)"
app/locale/en_US/Mage_XmlConnect.csv:532:"Subtotal (Incl. Tax)","Subtotal (Incl. Tax)"
app/locale/en_US/Mage_XmlConnect.csv:564:"Total incl. Tax: %1$s","Total incl. Tax: %1$s"

Question No. 4

A user is facing issue regarding the round up the values, his Magento is displaying wrong vat values after rounding up.


Please change the system as follows.

System>VAT>Tax calculation method

Here change tax calculation method from unit price to row and rewrite roundPrice there as

public function roundPrice($price)
   return round($price, 4);

Question No. 5

A user is having floating 0.01 value issue in Magento and he has this situation with code.

$total = '319.00';
$discount = '99.00';
$percentage_discount = number_format((1+($discount/$total)) * 100 - 100, 2, '.', '');

echo $percentage_discount . " %<br>";
echo $discount . "<br>";
echo number_format($total * (1-($percentage_discount / 100)), 2, '.', ''); //echo total


31.03 %


On $persentage_discount use this code

$percentage_discount = ((1 + ($discount / $total)) * 100 - 100);
    $total = '319.00';
    $discount = '99.00';
    $percentage_discount = ($discount / $total) * 100;
    $final = $total * (1-($percentage_discount / 100));

    printf('%.2f<br>', $total);
    printf('%.2f<br>', $discount);
    printf('%.2f%%<br>', $percentage_discount);
    printf('%.2f<br>', $final); 

And the output will be


Download Magento VAT Addon 

magento vat addon

Leave a Reply