/** * Aggregate row totals per tax rate in array * * @param Mage_Sales_Model_Quote_Item_Abstract $item * @param float $rate * @param array $taxGroups * @return Mage_Tax_Model_Sales_Total_Quote */ protected function _aggregateTaxPerRate($item, $rate, &$taxGroups) { $inclTax = $item->getIsPriceInclTax(); $rateKey = (string) $rate; $taxSubtotal = $subtotal = $item->getTaxableAmount() + $item->getExtraRowTaxableAmount(); $baseTaxSubtotal = $baseSubtotal = $item->getBaseTaxableAmount() + $item->getBaseExtraRowTaxableAmount(); $item->setTaxPercent($rate); if (!isset($taxGroups[$rateKey]['totals'])) { $taxGroups[$rateKey]['totals'] = array(); $taxGroups[$rateKey]['base_totals'] = array(); } $hiddenTax = null; $baseHiddenTax = null; switch ($this->_helper->getCalculationSequence($this->_store)) { case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_EXCL: case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_INCL: $rowTax = $this->_calculator->calcTaxAmount($subtotal, $rate, $inclTax, false); $baseRowTax = $this->_calculator->calcTaxAmount($baseSubtotal, $rate, $inclTax, false); break; case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_EXCL: case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_INCL: if ($this->_helper->applyTaxOnOriginalPrice($this->_store)) { $discount = $item->getOriginalDiscountAmount(); $baseDiscount = $item->getBaseOriginalDiscountAmount(); } else { $discount = $item->getDiscountAmount(); $baseDiscount = $item->getBaseDiscountAmount(); } $taxSubtotal = max($subtotal - $discount, 0); $baseTaxSubtotal = max($baseSubtotal - $baseDiscount, 0); $rowTax = $this->_calculator->calcTaxAmount($taxSubtotal, $rate, $inclTax, false); $baseRowTax = $this->_calculator->calcTaxAmount($baseTaxSubtotal, $rate, $inclTax, false); if (!$item->getNoDiscount() && $item->getWeeeTaxApplied()) { $rowTaxBeforeDiscount = $this->_calculator->calcTaxAmount($subtotal, $rate, $inclTax, false); $baseRowTaxBeforeDiscount = $this->_calculator->calcTaxAmount($baseSubtotal, $rate, $inclTax, false); } if ($inclTax && $discount > 0) { $hiddenTax = $this->_calculator->calcTaxAmount($discount, $rate, $inclTax, false); $baseHiddenTax = $this->_calculator->calcTaxAmount($baseDiscount, $rate, $inclTax, false); $this->_hiddenTaxes[] = array('rate_key' => $rateKey, 'qty' => 1, 'item' => $item, 'value' => $hiddenTax, 'base_value' => $baseHiddenTax, 'incl_tax' => $inclTax); } break; } $rowTax = $this->_deltaRound($rowTax, $rateKey, $inclTax); $baseRowTax = $this->_deltaRound($baseRowTax, $rateKey, $inclTax, 'base'); $item->setTaxAmount(max(0, $rowTax)); $item->setBaseTaxAmount(max(0, $baseRowTax)); if (isset($rowTaxBeforeDiscount) && isset($baseRowTaxBeforeDiscount)) { $taxBeforeDiscount = max(0, $this->_deltaRound($rowTaxBeforeDiscount, $rateKey, $inclTax)); $baseTaxBeforeDiscount = max(0, $this->_deltaRound($baseRowTaxBeforeDiscount, $rateKey, $inclTax, 'base')); $item->setDiscountTaxCompensation($taxBeforeDiscount - max(0, $rowTax)); $item->setBaseDiscountTaxCompensation($baseTaxBeforeDiscount - max(0, $baseRowTax)); } $taxGroups[$rateKey]['totals'][] = max(0, $taxSubtotal); $taxGroups[$rateKey]['base_totals'][] = max(0, $baseTaxSubtotal); return $this; }
/** * Aggregate row totals per tax rate in array * * @param Mage_Sales_Model_Quote_Item_Abstract $item * @param float $rate * @param array $taxGroups * @return Mage_Tax_Model_Sales_Total_Quote */ protected function _aggregateTaxPerRate($item, $rate, &$taxGroups) { $inclTax = $item->getIsPriceInclTax(); $rateKey = (string) $rate; $taxSubtotal = $subtotal = $item->getTaxableAmount() + $item->getExtraRowTaxableAmount(); $baseTaxSubtotal = $baseSubtotal = $item->getBaseTaxableAmount() + $item->getBaseExtraRowTaxableAmount(); $item->setTaxPercent($rate); if (!isset($taxGroups[$rateKey]['totals'])) { $taxGroups[$rateKey]['totals'] = array(); $taxGroups[$rateKey]['base_totals'] = array(); } $hiddenTax = null; $baseHiddenTax = null; switch ($this->_helper->getCalculationSequence($this->_store)) { case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_EXCL: case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_INCL: $rowTax = $this->_calculator->calcTaxAmount($subtotal, $rate, $inclTax, false); $baseRowTax = $this->_calculator->calcTaxAmount($baseSubtotal, $rate, $inclTax, false); break; case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_EXCL: case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_INCL: $discount = $item->getDiscountAmount(); $baseDiscount = $item->getBaseDiscountAmount(); $taxSubtotal = max($subtotal - $discount, 0); $baseTaxSubtotal = max($baseSubtotal - $baseDiscount, 0); $rowTax = $this->_calculator->calcTaxAmount($taxSubtotal, $rate, $inclTax, false); $baseRowTax = $this->_calculator->calcTaxAmount($baseTaxSubtotal, $rate, $inclTax, false); break; } $rowTax = $this->_deltaRound($rowTax, $rateKey, $inclTax); $baseRowTax = $this->_deltaRound($baseRowTax, $rateKey, $inclTax, 'base'); if ($inclTax && !empty($discount)) { /** * Becouse of delta hidden tax should be calculated based on discount amount $hiddenTax = $item->getRowTotalInclTax() - $item->getRowTotal() - $rowTax; $baseHiddenTax = $item->getBaseRowTotalInclTax() - $item->getBaseRowTotal() - $baseRowTax; */ $hiddenTax = $this->_calculator->calcTaxAmount($discount, $rate, $inclTax, false); $hiddenTax = $this->_deltaRound($hiddenTax, $rateKey, $inclTax, 'hidden'); $baseHiddenTax = $this->_calculator->calcTaxAmount($baseDiscount, $rate, $inclTax, false); $baseHiddenTax = $this->_deltaRound($baseHiddenTax, $rate, $inclTax, 'base_hidden'); } elseif (!empty($discount) && $discount > $subtotal) { // case with 100% discount on price incl. tax $hiddenTax = $discount - $subtotal; $baseHiddenTax = $baseDiscount - $baseSubtotal; } $item->setTaxAmount(max(0, $rowTax)); $item->setBaseTaxAmount(max(0, $baseRowTax)); $item->setHiddenTaxAmount(max(0, $hiddenTax)); $item->setBaseHiddenTaxAmount(max(0, $baseHiddenTax)); $taxGroups[$rateKey]['totals'][] = max(0, $taxSubtotal); $taxGroups[$rateKey]['base_totals'][] = max(0, $baseTaxSubtotal); return $this; }
/** * Calculate the Weee tax based on the discount and rate * * @param float $rate * @param Mage_Sales_Model_Quote_Item_Abstract $item * @param float $discountAmount * @param float $weeeAmountIncludingTax * @param float $weeeAmountExclTax * @return mixed */ private function _getWeeeTax($rate, $item, $discountAmount, $weeeAmountIncludingTax, $weeeAmountExclTax) { $isWeeeTaxAlreadyIncluded = $this->_weeeHelper->isTaxIncluded($this->_store); if ($rate == $this->_calculator->getStoreRateForItem($item) && $isWeeeTaxAlreadyIncluded) { if (!$discountAmount || $discountAmount <= 0) { //We want to skip the re calculation and return the difference return max($weeeAmountIncludingTax - $weeeAmountExclTax, 0); } else { return $this->_calculator->calcTaxAmount($weeeAmountIncludingTax - $discountAmount, $rate, true, true); } } $discountAmount = !$discountAmount ? 0 : $discountAmount; ///Regular case where weee does not have the tax and we want to calculate the tax return $this->_calculator->calcTaxAmount($weeeAmountExclTax - $discountAmount, $rate, false, true); }
/** * Calculates tax amounts for the row item using $this->_calculator * * @param Mage_Sales_Model_Quote_Item $item * @return $this */ protected function _calcTaxAmounts(&$item) { //@nelkaake -a 16/11/10: Calculator only works in magento 1.4 and up. if (!Mage::helper('rewards/version')->isMageVersionAtLeast('1.4.2')) { return $this; } // @nelkaake -a 16/11/10: Tax calculation methods $tax = $this->_calculator->calcTaxAmount($item->getRowTotal(), $item->getTaxPercent(), false); $baseTax = $this->_calculator->calcTaxAmount($item->getBaseRowTotal(), $item->getTaxPercent(), false); $item->setTaxAmount($tax); $item->setBaseTaxAmount($baseTax); $item->setTaxableAmount($item->getRowTotal()); $item->setBaseTaxableAmount($item->getBaseRowTotal()); //@nelkaake -a 26/01/11: We don't set this so that we can later use the row total including tax to find out // how much of the order was discounted due to catalog redemption rules. $item->setRowTotalInclTax($item->getRowTotal() + $tax); $item->setBaseRowTotalInclTax($item->getBaseRowTotal() + $baseTax); return $this; }
/** * Recollect item price and row total using after taxes subtract. * Declare item price including tax attributes * * @deprecated after 1.4.1 * * @param Mage_Sales_Model_Quote_Address $address * @param Mage_Sales_Model_Quote_Item_Abstract $item * * @return Mage_Tax_Model_Sales_Total_Quote_Subtotal */ protected function _recollectItem($address, Mage_Sales_Model_Quote_Item_Abstract $item) { $store = $address->getQuote()->getStore(); $request = $this->_getStoreTaxRequest($address); $request->setProductClassId($item->getProduct()->getTaxClassId()); $rate = $this->_calculator->getRate($request); $qty = $item->getTotalQty(); $price = $taxPrice = $item->getCalculationPriceOriginal(); $basePrice = $baseTaxPrice = $item->getBaseCalculationPriceOriginal(); $subtotal = $taxSubtotal = $item->getRowTotal(); $baseSubtotal = $baseTaxSubtotal = $item->getBaseRowTotal(); if ($this->_config->discountTax($store)) { $item->setDiscountCalculationPrice($price); $item->setBaseDiscountCalculationPrice($basePrice); } /** * Use original price for tax calculation */ if ($item->hasCustomPrice() && !$this->_helper->applyTaxOnCustomPrice($store)) { $taxPrice = $item->getOriginalPrice(); $baseTaxPrice = $item->getBaseOriginalPrice(); $taxSubtotal = $taxPrice * $qty; $baseTaxSubtotal = $baseTaxPrice * $qty; } if ($this->_areTaxRequestsSimilar) { $item->setRowTotalInclTax($subtotal); $item->setBaseRowTotalInclTax($baseSubtotal); $item->setPriceInclTax($price); $item->setBasePriceInclTax($basePrice); $item->setTaxCalcPrice($taxPrice); $item->setBaseTaxCalcPrice($baseTaxPrice); $item->setTaxCalcRowTotal($taxSubtotal); $item->setBaseTaxCalcRowTotal($baseTaxSubtotal); } $this->_subtotalInclTax += $subtotal; $this->_baseSubtotalInclTax += $baseSubtotal; if ($this->_config->getAlgorithm($store) == Mage_Tax_Model_Calculation::CALC_UNIT_BASE) { $taxAmount = $this->_calculator->calcTaxAmount($taxPrice, $rate, true); $baseTaxAmount = $this->_calculator->calcTaxAmount($baseTaxPrice, $rate, true); $unitPrice = $this->_calculator->round($price - $taxAmount); $baseUnitPrice = $this->_calculator->round($basePrice - $baseTaxAmount); $subtotal = $this->_calculator->round($unitPrice * $qty); $baseSubtotal = $this->_calculator->round($baseUnitPrice * $qty); } else { $taxAmount = $this->_calculator->calcTaxAmount($taxSubtotal, $rate, true, false); $baseTaxAmount = $this->_calculator->calcTaxAmount($baseTaxSubtotal, $rate, true, false); $unitPrice = ($subtotal - $taxAmount) / $qty; $baseUnitPrice = ($baseSubtotal - $baseTaxAmount) / $qty; $subtotal = $this->_calculator->round($subtotal - $taxAmount); $baseSubtotal = $this->_calculator->round($baseSubtotal - $baseTaxAmount); } if ($item->hasCustomPrice()) { $item->setCustomPrice($unitPrice); $item->setBaseCustomPrice($baseUnitPrice); } $item->setPrice($baseUnitPrice); $item->setOriginalPrice($unitPrice); $item->setBasePrice($baseUnitPrice); $item->setRowTotal($subtotal); $item->setBaseRowTotal($baseSubtotal); return $this; }
/** * Calculate tax for amount * * @param float $price * @param float $taxRate * @return float */ protected function _calcTaxAmount($price) { return $this->_taxCalculationModel->calcTaxAmount($price, $this->_rate); }
/** * Aggregate row totals per tax rate in array * * @param Mage_Sales_Model_Quote_Item_Abstract $item * @param float $rate * @param array $taxGroups * @return Mage_Tax_Model_Sales_Total_Quote */ protected function _aggregateTaxPerRate($item, $rate, &$taxGroups) { $store = $item->getStore(); $inclTax = $this->_usePriceIncludeTax($store); if ($inclTax) { $subtotal = $item->getTaxCalcRowTotal(); $baseSubtotal = $item->getBaseTaxCalcRowTotal(); } else { if ($item->hasCustomPrice() && $this->_helper->applyTaxOnCustomPrice($store)) { $subtotal = $item->getRowTotal(); $baseSubtotal = $item->getBaseRowTotal(); } else { $subtotal = $item->getTotalQty() * $item->getOriginalPrice(); $baseSubtotal = $item->getTotalQty() * $item->getBaseOriginalPrice(); } } $discountAmount = $item->getDiscountAmount(); $baseDiscountAmount = $item->getBaseDiscountAmount(); $qty = $item->getTotalQty(); $rateKey = (string) $rate; /** * Add extra amounts which can be taxable too */ $calcTotal = $subtotal + $item->getExtraRowTaxableAmount(); $baseCalcTotal = $baseSubtotal + $item->getBaseExtraRowTaxableAmount(); $item->setTaxPercent($rate); if (!isset($taxGroups[$rateKey]['totals'])) { $taxGroups[$rateKey]['totals'] = array(); } if (!isset($taxGroups[$rateKey]['totals'])) { $taxGroups[$rateKey]['base_totals'] = array(); } $calculationSequence = $this->_helper->getCalculationSequence($store); switch ($calculationSequence) { case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_EXCL: $rowTax = $this->_calculator->calcTaxAmount($calcTotal, $rate, $inclTax, false); $baseRowTax = $this->_calculator->calcTaxAmount($baseCalcTotal, $rate, $inclTax, false); break; case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_INCL: $rowTax = $this->_calculator->calcTaxAmount($calcTotal, $rate, $inclTax, false); $baseRowTax = $this->_calculator->calcTaxAmount($baseCalcTotal, $rate, $inclTax, false); $discountPrice = $inclTax ? $subtotal / $qty : ($subtotal + $rowTax) / $qty; $baseDiscountPrice = $inclTax ? $baseSubtotal / $qty : ($baseSubtotal + $baseRowTax) / $qty; $item->setDiscountCalculationPrice($discountPrice); $item->setBaseDiscountCalculationPrice($baseDiscountPrice); break; case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_EXCL: case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_INCL: $calcTotal = $calcTotal - $discountAmount; $baseCalcTotal = $baseCalcTotal - $baseDiscountAmount; $rowTax = $this->_calculator->calcTaxAmount($calcTotal, $rate, $inclTax, false); $baseRowTax = $this->_calculator->calcTaxAmount($baseCalcTotal, $rate, $inclTax, false); break; } /** * "Delta" rounding */ $delta = isset($this->_roundingDeltas[$rateKey]) ? $this->_roundingDeltas[$rateKey] : 0; $baseDelta = isset($this->_baseRoundingDeltas[$rateKey]) ? $this->_baseRoundingDeltas[$rateKey] : 0; $rowTax += $delta; $baseRowTax += $baseDelta; $this->_roundingDeltas[$rateKey] = $rowTax - $this->_calculator->round($rowTax); $this->_baseRoundingDeltas[$rateKey] = $baseRowTax - $this->_calculator->round($baseRowTax); $rowTax = $this->_calculator->round($rowTax); $baseRowTax = $this->_calculator->round($baseRowTax); /** * Renew item amounts in case if we are working with price include tax */ if ($inclTax) { $unitTax = $this->_calculator->round($rowTax / $qty); $baseUnitTax = $this->_calculator->round($baseRowTax / $qty); if ($item->hasCustomPrice()) { $item->setCustomPrice($item->getPriceInclTax() - $unitTax); $item->setBaseCustomPrice($item->getBasePriceInclTax() - $baseUnitTax); } else { $item->setOriginalPrice($item->getPriceInclTax() - $unitTax); $item->setPrice($item->getBasePriceInclTax() - $baseUnitTax); $item->setBasePrice($item->getBasePriceInclTax() - $baseUnitTax); } $item->setRowTotal($item->getRowTotalInclTax() - $rowTax); $item->setBaseRowTotal($item->getBaseRowTotalInclTax() - $baseRowTax); } $item->setTaxAmount($rowTax); $item->setBaseTaxAmount($baseRowTax); $taxGroups[$rateKey]['totals'][] = $calcTotal; $taxGroups[$rateKey]['base_totals'][] = $baseCalcTotal; return $this; }
/** * Calculate item price and row total including/excluding tax based on row total price rounding level * * @param Mage_Sales_Model_Quote_Item_Abstract $item * @param Varien_Object $request * @return Mage_Tax_Model_Sales_Total_Quote_Subtotal */ protected function _rowBaseCalculation($item, $request) { $request->setProductClassId($item->getProduct()->getTaxClassId()); $rate = $this->_calculator->getRate($request); $qty = $item->getTotalQty(); $price = $taxPrice = $item->getCalculationPriceOriginal(); $basePrice = $baseTaxPrice = $item->getBaseCalculationPriceOriginal(); $subtotal = $taxSubtotal = $item->getRowTotal(); $baseSubtotal = $baseTaxSubtotal = $item->getBaseRowTotal(); $taxOnOrigPrice = !$this->_helper->applyTaxOnCustomPrice($this->_store) && $item->hasCustomPrice(); if ($taxOnOrigPrice) { $origSubtotal = $item->getOriginalPrice() * $qty; $baseOrigSubtotal = $item->getBaseOriginalPrice() * $qty; } $item->setTaxPercent($rate); if ($this->_config->priceIncludesTax($this->_store)) { if ($this->_sameRateAsStore($request)) { $rowTax = $this->_calculator->calcTaxAmount($subtotal, $rate, true, false); $baseRowTax = $this->_calculator->calcTaxAmount($baseSubtotal, $rate, true, false); $taxPrice = $price; $baseTaxPrice = $basePrice; $taxSubtotal = $subtotal; $baseTaxSubtotal = $baseSubtotal; $subtotal = $this->_calculator->round($subtotal - $rowTax); $baseSubtotal = $this->_calculator->round($baseSubtotal - $baseRowTax); $price = $this->_calculator->round($subtotal / $qty); $basePrice = $this->_calculator->round($baseSubtotal / $qty); if ($taxOnOrigPrice) { $taxable = $origSubtotal; $baseTaxable = $baseOrigSubtotal; } else { $taxable = $taxSubtotal; $baseTaxable = $baseTaxSubtotal; } $isPriceInclTax = true; } else { $storeRate = $this->_calculator->getStoreRate($request, $this->_store); $storeTax = $this->_calculator->calcTaxAmount($subtotal, $storeRate, true, false); $baseStoreTax = $this->_calculator->calcTaxAmount($baseSubtotal, $storeRate, true, false); $subtotal = $this->_calculator->round($subtotal - $storeTax); $baseSubtotal = $this->_calculator->round($baseSubtotal - $baseStoreTax); $price = $this->_calculator->round($subtotal / $qty); $basePrice = $this->_calculator->round($baseSubtotal / $qty); $rowTax = $this->_calculator->calcTaxAmount($subtotal, $rate, false, false); $baseRowTax = $this->_calculator->calcTaxAmount($baseSubtotal, $rate, false, false); $taxSubtotal = $subtotal + $rowTax; $baseTaxSubtotal = $baseSubtotal + $baseRowTax; $taxPrice = $this->_calculator->round($taxSubtotal / $qty); $baseTaxPrice = $this->_calculator->round($baseTaxSubtotal / $qty); if ($taxOnOrigPrice) { $taxable = $this->_calculator->round($origSubtotal - $storeTax); $baseTaxable = $this->_calculator->round($baseOrigSubtotal - $baseStoreTax); } else { $taxable = $subtotal; $baseTaxable = $baseSubtotal; } $isPriceInclTax = false; } } else { $rowTax = $this->_calculator->calcTaxAmount($subtotal, $rate, false, false); $baseRowTax = $this->_calculator->calcTaxAmount($baseSubtotal, $rate, false, false); $taxSubtotal = $subtotal + $rowTax; $baseTaxSubtotal = $baseSubtotal + $baseRowTax; $taxPrice = $this->_calculator->round($taxSubtotal / $qty); $baseTaxPrice = $this->_calculator->round($baseTaxSubtotal / $qty); if ($taxOnOrigPrice) { $taxable = $origSubtotal; $baseTaxable = $baseOrigSubtotal; } else { $taxable = $subtotal; $baseTaxable = $baseSubtotal; } $isPriceInclTax = false; } if ($item->hasCustomPrice()) { /** * Initialize item original price before declaring custom price */ $item->getOriginalPrice(); $item->setCustomPrice($price); $item->setBaseCustomPrice($basePrice); } $item->setPrice($basePrice); $item->setBasePrice($basePrice); $item->setRowTotal($subtotal); $item->setBaseRowTotal($baseSubtotal); $item->setPriceInclTax($taxPrice); $item->setBasePriceInclTax($baseTaxPrice); $item->setRowTotalInclTax($taxSubtotal); $item->setBaseRowTotalInclTax($baseTaxSubtotal); $item->setTaxableAmount($taxable); $item->setBaseTaxableAmount($baseTaxable); $item->setIsPriceInclTax($isPriceInclTax); if ($this->_config->discountTax($this->_store)) { $item->setDiscountCalculationPrice($taxSubtotal / $qty); $item->setBaseDiscountCalculationPrice($baseTaxSubtotal / $qty); } elseif ($isPriceInclTax) { $item->setDiscountCalculationPrice($subtotal / $qty); $item->setBaseDiscountCalculationPrice($baseSubtotal / $qty); } return $this; }
/** * Aggregate row totals per tax rate in array * * @param Mage_Sales_Model_Quote_Item_Abstract $item * @param float $rate * @param array $taxGroups * @return Mage_Tax_Model_Sales_Total_Quote */ protected function _aggregateTaxPerRate($item, $rate, &$taxGroups) { $inclTax = $item->getIsPriceInclTax(); $rateKey = (string) $rate; $taxSubtotal = $subtotal = $item->getTaxableAmount(); $baseTaxSubtotal = $baseSubtotal = $item->getBaseTaxableAmount(); $isWeeeEnabled = $this->_weeeHelper->isEnabled(); $isWeeeTaxable = $this->_weeeHelper->isTaxable(); $item->setTaxPercent($rate); if (!isset($taxGroups[$rateKey]['totals'])) { $taxGroups[$rateKey]['totals'] = array(); $taxGroups[$rateKey]['base_totals'] = array(); $taxGroups[$rateKey]['weee_tax'] = array(); $taxGroups[$rateKey]['base_weee_tax'] = array(); } $hiddenTax = null; $baseHiddenTax = null; switch ($this->_helper->getCalculationSequence($this->_store)) { case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_EXCL: case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_INCL: $rowTax = $this->_calculator->calcTaxAmount($subtotal, $rate, $inclTax, false); $baseRowTax = $this->_calculator->calcTaxAmount($baseSubtotal, $rate, $inclTax, false); if ($isWeeeEnabled && $isWeeeTaxable) { $weeeTax = $item->getWeeeTaxAppliedRowAmount() * $rate / 100; $baseWeeeTax = $item->getBaseWeeeTaxAppliedRowAmount() * $rate / 100; $rowTax += $weeeTax; $baseRowTax += $baseWeeeTax; $taxGroups[$rateKey]['weee_tax'][] = $this->_deltaRound($weeeTax, $rateKey, $inclTax); $taxGroups[$rateKey]['base_weee_tax'][] = $this->_deltaRound($baseWeeeTax, $rateKey, $inclTax); } break; case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_EXCL: case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_INCL: if ($this->_helper->applyTaxOnOriginalPrice($this->_store)) { $discount = $item->getOriginalDiscountAmount(); $baseDiscount = $item->getBaseOriginalDiscountAmount(); } else { $discount = $item->getDiscountAmount(); $baseDiscount = $item->getBaseDiscountAmount(); } //weee discount should be removed when calculating hidden tax if ($isWeeeEnabled) { $discount = $discount - $item->getWeeeDiscount(); $baseDiscount = $baseDiscount - $item->getBaseWeeeDiscount(); } $taxSubtotal = max($subtotal - $discount, 0); $baseTaxSubtotal = max($baseSubtotal - $baseDiscount, 0); $rowTax = $this->_calculator->calcTaxAmount($taxSubtotal, $rate, $inclTax, false); $baseRowTax = $this->_calculator->calcTaxAmount($baseTaxSubtotal, $rate, $inclTax, false); if ($isWeeeEnabled && $this->_weeeHelper->isTaxable()) { $weeeTax = ($item->getWeeeTaxAppliedRowAmount() - $item->getWeeeDiscount()) * $rate / 100; $rowTax += $weeeTax; $baseWeeeTax = ($item->getBaseWeeeTaxAppliedRowAmount() - $item->getBaseWeeeDiscount()) * $rate / 100; $baseRowTax += $baseWeeeTax; $taxGroups[$rateKey]['weee_tax'][] = $weeeTax; $taxGroups[$rateKey]['base_weee_tax'][] = $baseWeeeTax; } if (!$item->getNoDiscount() && $item->getWeeeTaxApplied()) { $rowTaxBeforeDiscount = $this->_calculator->calcTaxAmount($subtotal, $rate, $inclTax, false); $baseRowTaxBeforeDiscount = $this->_calculator->calcTaxAmount($baseSubtotal, $rate, $inclTax, false); if ($isWeeeTaxable) { $rowTaxBeforeDiscount += $item->getWeeeTaxAppliedRowAmount() * $rate / 100; $baseRowTaxBeforeDiscount += $item->getBaseWeeeTaxAppliedRowAmount() * $rate / 100; } } if ($inclTax && $discount > 0) { $hiddenTax = $this->_calculator->calcTaxAmount($discount, $rate, $inclTax, false); $baseHiddenTax = $this->_calculator->calcTaxAmount($baseDiscount, $rate, $inclTax, false); $this->_hiddenTaxes[] = array('rate_key' => $rateKey, 'qty' => 1, 'item' => $item, 'value' => $hiddenTax, 'base_value' => $baseHiddenTax, 'incl_tax' => $inclTax); } break; } $rowTax = $this->_deltaRound($rowTax, $rateKey, $inclTax); $baseRowTax = $this->_deltaRound($baseRowTax, $rateKey, $inclTax, 'base'); $item->setTaxAmount(max(0, $rowTax)); $item->setBaseTaxAmount(max(0, $baseRowTax)); if (isset($rowTaxBeforeDiscount) && isset($baseRowTaxBeforeDiscount)) { $taxBeforeDiscount = max(0, $this->_deltaRound($rowTaxBeforeDiscount, $rateKey, $inclTax, 'tax_before_discount')); $baseTaxBeforeDiscount = max(0, $this->_deltaRound($baseRowTaxBeforeDiscount, $rateKey, $inclTax, 'tax_before_discount_base')); $item->setDiscountTaxCompensation($taxBeforeDiscount - max(0, $rowTax)); $item->setBaseDiscountTaxCompensation($baseTaxBeforeDiscount - max(0, $baseRowTax)); } $rowTotalInclTax = $item->getRowTotalInclTax(); if (!isset($rowTotalInclTax)) { $weeeTaxBeforeDiscount = 0; $baseWeeeTaxBeforeDiscount = 0; if ($isWeeeTaxable) { $weeeTaxBeforeDiscount = $item->getWeeeTaxAppliedRowAmount() * $rate / 100; $baseWeeeTaxBeforeDiscount = $item->getBaseWeeeTaxAppliedRowAmount() * $rate / 100; } if ($this->_config->priceIncludesTax($this->_store)) { $item->setRowTotalInclTax($subtotal + $weeeTaxBeforeDiscount); $item->setBaseRowTotalInclTax($baseSubtotal + $baseWeeeTaxBeforeDiscount); } else { $taxCompensation = $item->getDiscountTaxCompensation() ? $item->getDiscountTaxCompensation() : 0; $item->setRowTotalInclTax($subtotal + $rowTax + $taxCompensation); $item->setBaseRowTotalInclTax($baseSubtotal + $baseRowTax + $item->getBaseDiscountTaxCompensation()); } } $taxGroups[$rateKey]['totals'][] = max(0, $taxSubtotal); $taxGroups[$rateKey]['base_totals'][] = max(0, $baseTaxSubtotal); return $this; }