Esempio n. 1
0
 /**
  * Get configuration setting "Apply Discount On Prices Including Tax" value
  * Always apply discount first since AvaTax does not support line-level item discount amounts
  *
  * @param   null|int $store
  * @return  bool
  */
 public function discountTax($store = null)
 {
     if (Mage::helper('avatax')->isAvataxEnabled($store)) {
         return false;
     }
     return parent::discountTax($store);
 }
Esempio n. 2
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;
 }
Esempio n. 3
0
 /**
  * Check if we need subtract store tax amount from shipping
  *
  * @deprecated after 1.4.0.0
  * @param Mage_Sales_Model_Quote_Address $address
  * @return bool
  */
 protected function _needSubtractShippingTax($address)
 {
     $store = $address->getQuote()->getStore();
     if ($this->_config->shippingPriceIncludesTax($store) || $this->_config->getNeedUseShippingExcludeTax()) {
         return true;
     }
     return false;
 }
 /**
  * Initialize reward points totals
  *
  * @return Enterprise_Reward_Block_Sales_Order_Total
  */
 public function initTotals()
 {
     $store = $this->getStore();
     $source = $this->getSource();
     $parent = $this->getParentBlock();
     $grandototal = $parent->getTotal('grand_total');
     if (!$grandototal || !(double) $source->getGrandTotal()) {
         return $this;
     }
     try {
         if ($this->getOrder()->getDcOrderId() || $this->getOrder()->getFailedCalculation()) {
             if ($this->_config->displaySalesTaxWithGrandTotal($store)) {
                 $value = $source->getImportDutyTax();
                 $baseValue = $source->getBaseImportDutyTax();
                 $title = $this->getOrder()->getDeliveryDutyType() == Dutycalculator_Charge_Helper_Data::DC_DELIVERY_TYPE_DDU ? $this->getOrder()->getFailedCalculation() ? 'Any import duty & taxes are paid upon delivery and are not included in the final price' : 'Estimated import duty & taxes (Not included in grand total, paid upon delivery)' : 'Import duty and taxes';
                 if ($source->getDcOrderId()) {
                     $title .= ' (<a href="' . Mage::getStoreConfig('dc_charge_extension/dccharge/calculation_details_uri') . $source->getDcOrderId() . '/" target="_blank">View details</a>)';
                 }
                 $importDutyAndTaxes = new Varien_Object(array('code' => 'import_duty_tax', 'strong' => false, 'label' => $title, 'no_escape' => true, 'value' => $source instanceof Mage_Sales_Model_Order_Creditmemo ? -$value : $value, 'base_value' => $source instanceof Mage_Sales_Model_Order_Creditmemo ? -$baseValue : $baseValue));
                 $grandTotal = $parent->getTotal('grand_total');
                 $grandTotalIncl = $parent->getTotal('grand_total_incl');
                 if ($grandTotal) {
                     $newGrandTotalExcl = max($grandTotal->value - $source->getImportDutyTax(), 0);
                     $newGrandTotalBaseExcl = max($grandTotal->base_value - $source->getBaseImportDutyTax(), 0);
                     $totalExcl = new Varien_Object(array('code' => 'grand_total', 'strong' => true, 'value' => $newGrandTotalExcl, 'base_value' => $newGrandTotalBaseExcl, 'label' => $grandTotal->getLabel()));
                     $parent->addTotal($totalExcl, 'grand_total');
                     if (!$grandTotalIncl) {
                         $totalIncl = new Varien_Object(array('code' => 'grand_total_incl', 'strong' => true, 'value' => $this->getOrder()->getGrandTotal(), 'base_value' => $this->getOrder()->getBaseGrandTotal(), 'label' => $this->__('Grand Total (Incl.Tax)')));
                         $parent->addTotal($totalIncl, 'tax');
                     }
                 }
             } else {
                 $value = $source->getImportDutyTax();
                 $baseValue = $source->getBaseImportDutyTax();
                 $title = $this->getOrder()->getDeliveryDutyType() == Dutycalculator_Charge_Helper_Data::DC_DELIVERY_TYPE_DDU ? $this->getOrder()->getFailedCalculation() ? 'Any import duty & taxes are paid upon delivery and are not included in the final price' : 'Estimated import duty & taxes (Not included in grand total, paid upon delivery)' : 'Import duty and taxes';
                 if ($source->getDcOrderId()) {
                     $title .= ' (<a href="' . Mage::getStoreConfig('dc_charge_extension/dccharge/calculation_details_uri') . $source->getDcOrderId() . '/" target="_blank">View details</a>)';
                 }
                 $importDutyAndTaxes = new Varien_Object(array('code' => 'import_duty_tax', 'strong' => false, 'label' => $title, 'no_escape' => true, 'value' => $source instanceof Mage_Sales_Model_Order_Creditmemo ? -$value : $value, 'base_value' => $source instanceof Mage_Sales_Model_Order_Creditmemo ? -$baseValue : $baseValue));
             }
             $parent->addTotal($importDutyAndTaxes, $this->getAfterCondition());
         }
     } catch (Exception $ex) {
     }
     return $this;
 }
Esempio n. 5
0
 /**
  * Add extra amount which should be taxable by regular tax
  *
  * @param   Mage_Sales_Model_Quote_Item_Abstract $item
  * @param   float $value
  * @param   float $baseValue
  * @param   float $rowValue
  * @param   float $baseRowValue
  * @return  Mage_Weee_Model_Total_Quote_Weee
  */
 protected function _processTaxSettings($item, $value, $baseValue, $rowValue, $baseRowValue)
 {
     if ($this->_helper->isTaxable($this->_store) && $rowValue) {
         if (!$this->_config->priceIncludesTax($this->_store)) {
             $item->setExtraTaxableAmount($value)->setBaseExtraTaxableAmount($baseValue)->setExtraRowTaxableAmount($rowValue)->setBaseExtraRowTaxableAmount($baseRowValue);
         }
         $item->unsRowTotalInclTax()->unsBaseRowTotalInclTax()->unsPriceInclTax()->unsBasePriceInclTax();
         $this->_isTaxAffected = true;
     }
     return $this;
 }
 public function priceIncludesTax($store = null)
 {
     $bid_id = Mage::getSingleton('core/session')->getData('bid_id');
     if (!$bid_id) {
         return parent::priceIncludesTax($store);
     } else {
         if ((int) Mage::getStoreConfig('auction/tax/is_included_tax') == 1) {
             return true;
         } else {
             return false;
         }
     }
 }
Esempio n. 7
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();
     $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;
 }
Esempio n. 8
0
 protected function _initGrandTotal()
 {
     $store = $this->getStore();
     $parent = $this->getParentBlock();
     $grandototal = $parent->getTotal('grand_total');
     if (!$grandototal || !(double) $this->_source->getGrandTotal()) {
         return $this;
     }
     if ($this->_config->displaySalesTaxWithGrandTotal($store)) {
         $grandtotal = $this->_source->getGrandTotal();
         $baseGrandtotal = $this->_source->getBaseGrandTotal();
         $grandtotalExcl = $grandtotal - $this->_source->getTaxAmount();
         $baseGrandtotalExcl = $baseGrandtotal - $this->_source->getBaseTaxAmount();
         $grandtotalExcl = max($grandtotalExcl, 0);
         $baseGrandtotalExcl = max($baseGrandtotalExcl, 0);
         $totalExcl = new Varien_Object(array('code' => 'grand_total', 'strong' => true, 'value' => $grandtotalExcl, 'base_value' => $baseGrandtotalExcl, 'label' => $this->__('Grand Total (Excl.Tax)')));
         $totalIncl = new Varien_Object(array('code' => 'grand_total_incl', 'strong' => true, 'value' => $grandtotal, 'base_value' => $baseGrandtotal, 'label' => $this->__('Grand Total (Incl.Tax)')));
         $parent->addTotal($totalExcl, 'grand_total');
         $this->_addTax('grand_total');
         $parent->addTotal($totalIncl, 'tax');
     }
     return $this;
 }
Esempio n. 9
0
 /**
  * Check if shipping prices include tax
  *
  * @param Mage_Core_Model_Store|int $store
  * @return bool
  */
 public function shippingPriceIncludesTax($store = null)
 {
     if ($this->_getDataHelper()->isServiceEnabled($store)) {
         if ($this->_getTaxDataHelper()->priceIncludesTax($store)) {
             return true;
         }
         return false;
     }
     return parent::shippingPriceIncludesTax($store);
 }
Esempio n. 10
0
 /**
  * Return whether cross border trade is enabled or not
  *
  * @param   null|int $store
  * @return boolean
  */
 public function isCrossBorderTradeEnabled($store = null)
 {
     return (bool) $this->_config->crossBorderTradeEnabled($store);
 }
Esempio n. 11
0
 /**
  * Get tax caclulation algorithm code
  *
  * @param   null|int $store
  * @return  string
  */
 public function getCalculationAgorithm($store = null)
 {
     return $this->_config->getAlgorithm($store);
 }
Esempio n. 12
0
 /**
  * Collect totals information about shipping
  *
  * @param   Mage_Sales_Model_Quote_Address $address
  * @return  Mage_Sales_Model_Quote_Address_Total_Shipping
  */
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     parent::collect($address);
     $calc = $this->_calculator;
     $store = $address->getQuote()->getStore();
     $storeTaxRequest = $calc->getRateOriginRequest($store);
     $addressTaxRequest = $calc->getRateRequest($address, $address->getQuote()->getBillingAddress(), $address->getQuote()->getCustomerTaxClassId(), $store);
     $shippingTaxClass = $this->_config->getShippingTaxClass($store);
     $storeTaxRequest->setProductClassId($shippingTaxClass);
     $addressTaxRequest->setProductClassId($shippingTaxClass);
     $priceIncludesTax = $this->_config->shippingPriceIncludesTax($store);
     if ($priceIncludesTax) {
         $this->_areTaxRequestsSimilar = $calc->compareRequests($addressTaxRequest, $storeTaxRequest);
     }
     $shipping = $taxShipping = $address->getShippingAmount();
     $baseShipping = $baseTaxShipping = $address->getBaseShippingAmount();
     $rate = $calc->getRate($addressTaxRequest);
     if ($priceIncludesTax) {
         if ($this->_areTaxRequestsSimilar) {
             $tax = $this->_round($calc->calcTaxAmount($shipping, $rate, true, false), $rate, true);
             $baseTax = $this->_round($calc->calcTaxAmount($baseShipping, $rate, true, false), $rate, true, 'base');
             $taxShipping = $shipping;
             $baseTaxShipping = $baseShipping;
             $shipping = $shipping - $tax;
             $baseShipping = $baseShipping - $baseTax;
             $taxable = $taxShipping;
             $baseTaxable = $baseTaxShipping;
             $isPriceInclTax = true;
         } else {
             $storeRate = $calc->getStoreRate($addressTaxRequest, $store);
             $storeTax = $calc->calcTaxAmount($shipping, $storeRate, true, false);
             $baseStoreTax = $calc->calcTaxAmount($baseShipping, $storeRate, true, false);
             $shipping = $calc->round($shipping - $storeTax);
             $baseShipping = $calc->round($baseShipping - $baseStoreTax);
             $tax = $this->_round($calc->calcTaxAmount($shipping, $rate, false, false), $rate, false);
             $baseTax = $this->_round($calc->calcTaxAmount($baseShipping, $rate, false, false), $rate, false, 'base');
             $taxShipping = $shipping + $tax;
             $baseTaxShipping = $baseShipping + $baseTax;
             $taxable = $shipping;
             $baseTaxable = $baseShipping;
             $isPriceInclTax = false;
         }
     } else {
         $tax = $this->_round($calc->calcTaxAmount($shipping, $rate, false, false), $rate, false);
         $baseTax = $this->_round($calc->calcTaxAmount($baseShipping, $rate, false, false), $rate, false, 'base');
         $taxShipping = $shipping + $tax;
         $baseTaxShipping = $baseShipping + $baseTax;
         $taxable = $shipping;
         $baseTaxable = $baseShipping;
         $isPriceInclTax = false;
     }
     $address->setTotalAmount('shipping', $shipping);
     $address->setBaseTotalAmount('shipping', $baseShipping);
     $address->setShippingInclTax($taxShipping);
     $address->setBaseShippingInclTax($baseTaxShipping);
     $address->setShippingTaxable($taxable);
     $address->setBaseShippingTaxable($baseTaxable);
     $address->setIsShippingInclTax($isPriceInclTax);
     if ($this->_config->discountTax($store)) {
         $address->setShippingAmountForDiscount($taxShipping);
         $address->setBaseShippingAmountForDiscount($baseTaxShipping);
     }
     return $this;
 }
Esempio n. 13
0
 /**
  * Check if display sales shipping include and exclude tax
  *
  * @param mixed $store
  * @return bool
  */
 public function displaySalesShippingBoth($store = null)
 {
     if ($this->_getDataHelper()->isAvataxEnabled($store)) {
         return false;
     }
     return parent::displaySalesShippingBoth($store);
 }
Esempio n. 14
0
 /**
  * Calculate item price and row total including/excluding tax based on 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 _totalBaseCalculation($item, $request)
 {
     $calc = $this->_calculator;
     $request->setProductClassId($item->getProduct()->getTaxClassId());
     $rate = $calc->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)) {
             if ($taxOnOrigPrice) {
                 $rowTax = $this->_deltaRound($calc->calcTaxAmount($origSubtotal, $rate, true, false), $rate, true);
                 $baseRowTax = $this->_deltaRound($calc->calcTaxAmount($baseOrigSubtotal, $rate, true, false), $rate, true, 'base');
                 $taxable = $origSubtotal;
                 $baseTaxable = $baseOrigSubtotal;
             } else {
                 $rowTax = $this->_deltaRound($calc->calcTaxAmount($subtotal, $rate, true, false), $rate, true);
                 $baseRowTax = $this->_deltaRound($calc->calcTaxAmount($baseSubtotal, $rate, true, false), $rate, true, 'base');
                 $taxable = $subtotal;
                 $baseTaxable = $baseSubtotal;
             }
             $taxPrice = $price;
             $baseTaxPrice = $basePrice;
             $taxSubtotal = $subtotal;
             $baseTaxSubtotal = $baseSubtotal;
             $subtotal = $subtotal - $rowTax;
             $baseSubtotal = $baseSubtotal - $baseRowTax;
             $price = $calc->round($subtotal / $qty);
             $basePrice = $calc->round($baseSubtotal / $qty);
             $isPriceInclTax = true;
         } else {
             $storeRate = $calc->getStoreRate($request, $this->_store);
             if ($taxOnOrigPrice) {
                 $storeTax = $calc->calcTaxAmount($origSubtotal, $storeRate, true, false);
                 $baseStoreTax = $calc->calcTaxAmount($baseOrigSubtotal, $storeRate, true, false);
             } else {
                 $storeTax = $calc->calcTaxAmount($subtotal, $storeRate, true, false);
                 $baseStoreTax = $calc->calcTaxAmount($baseSubtotal, $storeRate, true, false);
             }
             $subtotal = $calc->round($subtotal - $storeTax);
             $baseSubtotal = $calc->round($baseSubtotal - $baseStoreTax);
             $price = $calc->round($subtotal / $qty);
             $basePrice = $calc->round($baseSubtotal / $qty);
             $rowTax = $this->_deltaRound($calc->calcTaxAmount($subtotal, $rate, false, false), $rate, true);
             $baseRowTax = $this->_deltaRound($calc->calcTaxAmount($baseSubtotal, $rate, false, false), $rate, true, 'base');
             $taxSubtotal = $subtotal + $rowTax;
             $baseTaxSubtotal = $baseSubtotal + $baseRowTax;
             $taxPrice = $calc->round($taxSubtotal / $qty);
             $baseTaxPrice = $calc->round($baseTaxSubtotal / $qty);
             $taxable = $subtotal;
             $baseTaxable = $baseSubtotal;
             $isPriceInclTax = false;
         }
     } else {
         if ($taxOnOrigPrice) {
             $rowTax = $this->_deltaRound($calc->calcTaxAmount($origSubtotal, $rate, false, false), $rate, true);
             $baseRowTax = $this->_deltaRound($calc->calcTaxAmount($baseOrigSubtotal, $rate, false, false), $rate, true, 'base');
             $taxable = $origSubtotal;
             $baseTaxable = $baseOrigSubtotal;
         } else {
             $rowTax = $this->_deltaRound($calc->calcTaxAmount($subtotal, $rate, false, false), $rate, true);
             $baseRowTax = $this->_deltaRound($calc->calcTaxAmount($baseSubtotal, $rate, false, false), $rate, true, 'base');
             $taxable = $subtotal;
             $baseTaxable = $baseSubtotal;
         }
         $taxSubtotal = $subtotal + $rowTax;
         $baseTaxSubtotal = $baseSubtotal + $baseRowTax;
         $taxPrice = $calc->round($taxSubtotal / $qty);
         $baseTaxPrice = $calc->round($baseTaxSubtotal / $qty);
         $isPriceInclTax = false;
     }
     if ($item->hasCustomPrice()) {
         /**
          * Initialize item original price before declaring custom price
          */
         $item->getOriginalPrice();
         $item->setCustomPrice($price);
         $item->setBaseCustomPrice($basePrice);
     } else {
         $item->setConvertedPrice($price);
     }
     $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;
 }
Esempio n. 15
0
 /**
  * @magentoConfigFixture current_store tax/calculation/price_includes_tax 1
  */
 public function testPriceIncludesTaxNonDefault()
 {
     $this->assertTrue($this->_model->priceIncludesTax());
 }