2013-11-26 88 views
0

我正在與Magento合作,我需要獲得當前國家(法國)的增值稅稅率。我只知道不含稅價格的信息,有時僅含稅價格的信息,但從來都不是。你能給我解決方案嗎?謝謝如何在沒有訂單對象或產品的情況下獲得Magento的增值稅稅率

PS:請原諒我蹩腳的英語

對於GET稅率由產品:

<?php 
    //$_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)); 
?> 

我創建了一段代碼,以獲得通過訂單對象這樣的速度:

/** 
    * 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); 

     if($include_tax){ 
      $ttc_amount = $amount; 
      $ht_amount = $ttc_amount * $tax_coeff; 
      $tax_amount = $ttc_amount - $ht_amount; 

     } 
     else{ 
      $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 
     ); 
    } 

它向我返回一個包含轉換比率,稅率,稅額,免稅金額和最終稅額的數組

+0

你想看哪個部分?我在談論稅務助理,所以我不知道你會怎麼看待... –

回答

2

Merciàtous ceux qui m'ontrépondu,cependant voici la solutionàmonproblème。

伊爾suffit D'ajouter CETTE fonction連接附加費德稅幫手:

/** 
* 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); 
} 

要進一步這裏用的是加還是減的稅功能:

/** 
* 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); 


    if($add_tax){ 
     $amount = $amount/$tax_coeff; 
    } 
    else{ 
     $amount = $amount * $tax_coeff; 
    } 
    return round($amount,2); 
} 
相關問題