protected function _saveAppliedTaxes(Mage_Sales_Model_Quote_Address $address, $applied, $amount, $baseAmount, $rate)
 {
     $previouslyAppliedTaxes = $address->getAppliedTaxes();
     $process = count($previouslyAppliedTaxes);
     foreach ($applied as $row) {
         if (!isset($previouslyAppliedTaxes[$row['id']])) {
             $row['process'] = $process;
             $row['amount'] = 0;
             $row['base_amount'] = 0;
             $previouslyAppliedTaxes[$row['id']] = $row;
         }
         if (!is_null($row['percent'])) {
             $row['percent'] = $row['percent'] ? $row['percent'] : 1;
             $rate = $rate ? $rate : 1;
             $appliedAmount = $amount;
             $baseAppliedAmount = $baseAmount;
         } else {
             $appliedAmount = 0;
             $baseAppliedAmount = 0;
             foreach ($row['rates'] as $rate) {
                 $appliedAmount += $rate['amount'];
                 $baseAppliedAmount += $rate['base_amount'];
             }
         }
         if ($appliedAmount || $previouslyAppliedTaxes[$row['id']]['amount']) {
             $previouslyAppliedTaxes[$row['id']]['amount'] = $appliedAmount;
             $previouslyAppliedTaxes[$row['id']]['base_amount'] = $baseAppliedAmount;
         } else {
             unset($previouslyAppliedTaxes[$row['id']]);
         }
     }
     $address->setAppliedTaxes($previouslyAppliedTaxes);
 }
Beispiel #2
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $address->setPaymentCharge(0);
     $address->setBasePaymentCharge(0);
     $storeId = Mage::app()->getStore()->getId();
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $paymentMethod = $address->getQuote()->getPayment()->getMethod();
     $quote = $address->getQuote();
     if ($paymentMethod && substr($paymentMethod, 0, 11) == 'pay_payment') {
         $baseAmount = Mage::helper('pay_payment')->getPaymentCharge($paymentMethod, $address->getQuote());
         $amount = Mage::helper('directory')->currencyConvert($baseAmount, Mage::app()->getWebsite()->getConfig('currency/options/default'), Mage::app()->getStore()->getCurrentCurrencyCode());
         $address->setPaymentCharge($amount);
         $address->setBasePaymentCharge($baseAmount);
         $taxClass = Mage::helper('pay_payment')->getPaymentChargeTaxClass($paymentMethod);
         $taxCalculationModel = Mage::getSingleton('tax/calculation');
         $request = $taxCalculationModel->getRateRequest($quote->getShippingAddress(), $quote->getBillingAddress(), null, $storeId);
         $request->setStore(Mage::app()->getStore());
         $rate = $taxCalculationModel->getRate($request->setProductClassId($taxClass));
         //$rate = 21;
         if ($rate > 0) {
             //                $includesTax = Mage::getStoreConfig('tax/calculation/price_includes_tax');
             $baseChargeTax = round($address->getBasePaymentCharge() / (1 + $rate / 100) * ($rate / 100), 2);
             $chargeTax = round($address->getPaymentCharge() / (1 + $rate / 100) * ($rate / 100), 2);
         } else {
             $baseChargeTax = 0;
             $chargeTax = 0;
         }
         $rates = array();
         $applied = false;
         foreach ($address->getAppliedTaxes() as $arrRate) {
             // maximaal 1 keer de btw voor de extra kosten toevoegen
             if ($arrRate['percent'] == $rate && !$applied) {
                 $applied = true;
                 $arrRate['amount'] = $arrRate['amount'] + $chargeTax;
                 $arrRate['base_amount'] = $arrRate['base_amount'] + $baseChargeTax;
             }
             $rates[] = $arrRate;
         }
         $address->setAppliedTaxes($rates);
         $address->setBaseTaxAmount($address->getBaseTaxAmount() + $baseChargeTax);
         $address->setTaxAmount($address->getTaxAmount() + $chargeTax);
         $address->setGrandTotal($address->getGrandTotal() + $address->getPaymentCharge());
         $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBasePaymentCharge());
     }
     return $this;
 }
Beispiel #3
0
 public function fetch(Mage_Sales_Model_Quote_Address $address)
 {
     $applied = $address->getAppliedTaxes();
     $store = $address->getQuote()->getStore();
     $amount = $address->getTaxAmount();
     if ($amount != 0 || Mage::helper('tax')->displayZeroTax($store)) {
         $address->addTotal(array('code' => $this->getCode(), 'title' => Mage::helper('sales')->__('Tax'), 'full_info' => $applied ? $applied : array(), 'value' => $amount));
     }
     return $this;
 }
Beispiel #4
0
 /**
  * Add tax totals information to address object
  *
  * @param   Mage_Sales_Model_Quote_Address $address
  * @return  Mage_Tax_Model_Sales_Total_Quote
  */
 public function fetch(Mage_Sales_Model_Quote_Address $address)
 {
     $applied = $address->getAppliedTaxes();
     $store = $address->getQuote()->getStore();
     $amount = $address->getTaxAmount();
     $area = null;
     if ($this->_config->displayCartTaxWithGrandTotal($store) && $address->getGrandTotal()) {
         $area = 'taxes';
     }
     if ($amount != 0 || $this->_config->displayCartZeroTax($store)) {
         $address->addTotal(array('code' => $this->getCode(), 'title' => Mage::helper('tax')->__('Tax'), 'full_info' => $applied ? $applied : array(), 'value' => $amount, 'area' => $area));
     }
     $store = $address->getQuote()->getStore();
     /**
      * Modify subtotal
      */
     if ($this->_config->displayCartSubtotalBoth($store) || $this->_config->displayCartSubtotalInclTax($store)) {
         if ($address->getSubtotalInclTax() > 0) {
             $subtotalInclTax = $address->getSubtotalInclTax();
         } else {
             $subtotalInclTax = $address->getSubtotal() + $address->getTaxAmount() - $address->getShippingTaxAmount();
         }
         $address->addTotal(array('code' => 'subtotal', 'title' => Mage::helper('sales')->__('Subtotal'), 'value' => $subtotalInclTax, 'value_incl_tax' => $subtotalInclTax, 'value_excl_tax' => $address->getSubtotal()));
     }
     return $this;
 }
 /**
  * Add tax totals information to address object
  *
  * @param   Mage_Sales_Model_Quote_Address $address
  * @return  Mage_Tax_Model_Sales_Total_Quote
  */
 public function fetch(Mage_Sales_Model_Quote_Address $address)
 {
     $applied = $address->getAppliedTaxes();
     $store = $address->getQuote()->getStore();
     $amount = $address->getTaxAmount();
     $items = $this->_getAddressItems($address);
     $discountTaxCompensation = 0;
     foreach ($items as $item) {
         $discountTaxCompensation += $item->getDiscountTaxCompensation();
     }
     $taxAmount = $amount + $discountTaxCompensation;
     /*
      * when weee discount is not included in extraTaxAmount, we need to add it to the total tax
      */
     if ($this->_weeeHelper->isEnabled()) {
         if (!$this->_weeeHelper->includeInSubtotal()) {
             $taxAmount += $address->getWeeeDiscount();
         }
     }
     $area = null;
     if ($this->_config->displayCartTaxWithGrandTotal($store) && $address->getGrandTotal()) {
         $area = 'taxes';
     }
     if ($amount != 0 || $this->_config->displayCartZeroTax($store)) {
         $address->addTotal(array('code' => $this->getCode(), 'title' => Mage::helper('tax')->__('Tax'), 'full_info' => $applied ? $applied : array(), 'value' => $amount, 'area' => $area));
     }
     $store = $address->getQuote()->getStore();
     /**
      * Modify subtotal
      */
     if ($this->_config->displayCartSubtotalBoth($store) || $this->_config->displayCartSubtotalInclTax($store)) {
         if ($address->getSubtotalInclTax() > 0) {
             $subtotalInclTax = $address->getSubtotalInclTax();
         } else {
             $subtotalInclTax = $address->getSubtotal() + $taxAmount - $address->getShippingTaxAmount();
         }
         $address->addTotal(array('code' => 'subtotal', 'title' => Mage::helper('sales')->__('Subtotal'), 'value' => $subtotalInclTax, 'value_incl_tax' => $subtotalInclTax, 'value_excl_tax' => $address->getSubtotal()));
     }
     return $this;
 }
Beispiel #6
0
 /**
  * Add tax totals information to address object
  *
  * @param   Mage_Sales_Model_Quote_Address $address
  * @return  $this
  */
 public function fetch(Mage_Sales_Model_Quote_Address $address)
 {
     $config = Mage::getSingleton('tax/config');
     $quote = $address->getQuote();
     $store = $quote->getStore();
     $amount = $address->getTaxAmount();
     if ($amount != 0 || Mage::helper('tax')->displayZeroTax($store)) {
         $address->addTotal(array('code' => $this->getCode(), 'title' => Mage::helper('tax')->__('Tax'), 'full_info' => $address->getAppliedTaxes(), 'value' => $amount, 'area' => null));
     }
     /**
      * Modify subtotal
      */
     if (method_exists($config, "displayCartSubtotalBoth") && method_exists($config, "displayCartSubtotalInclTax") && ($config->displayCartSubtotalBoth($store) || $config->displayCartSubtotalInclTax($store))) {
         if ($address->getSubtotalInclTax() > 0) {
             $subtotalInclTax = $address->getSubtotalInclTax();
         } else {
             $subtotalInclTax = $address->getSubtotal() + $address->getTaxAmount() - $address->getShippingTaxAmount();
         }
         $address->addTotal(array('code' => 'subtotal', 'title' => Mage::helper('sales')->__('Subtotal'), 'value' => $subtotalInclTax, 'value_incl_tax' => $subtotalInclTax, 'value_excl_tax' => $address->getSubtotal()));
     }
     return $this;
 }