Exemplo n.º 1
0
 /**
  * Get included tax list
  *
  * @param boolean $override Override calculation flag OPTIONAL
  * 
  * @return array
  */
 public function getIncludedTaxList($override = false)
 {
     if (!isset($this->includedTaxList) || $override) {
         $this->includedTaxList = \XLite\Module\CDev\VAT\Logic\Product\Tax::getInstance()->calculateProductTaxes($this, $this->getNetPrice());
     }
     return $this->includedTaxList;
 }
Exemplo n.º 2
0
 /**
  * Get surcharge absolute value
  *
  * @return float
  */
 public function getDisplaySurchargePrice()
 {
     $value = parent::getAbsoluteValue();
     $product = $this->getOption()->getGroup()->getProduct();
     $value = \XLite\Module\CDev\VAT\Logic\Product\Tax::getInstance()->deductTaxFromPrice($product, $value);
     if (\XLite\Core\Config::getInstance()->CDev->VAT->display_prices_including_vat) {
         $value += \XLite\Module\CDev\VAT\Logic\Product\Tax::getInstance()->getVATValue($product, $value);
     }
     return $value;
 }
Exemplo n.º 3
0
 /**
  * Assign price range-based search condition
  *
  * @param \Doctrine\ORM\QueryBuilder $queryBuilder Query builder
  * @param float                      $min          Minimum
  * @param float                      $max          Maximum
  *
  * @return void
  */
 protected function assignPriceRangeCondition(\Doctrine\ORM\QueryBuilder $queryBuilder, $min, $max)
 {
     if (\XLite::isAdminZone()) {
         parent::assignPriceRangeCondition($queryBuilder, $min, $max);
     } else {
         $queryBuilder->leftJoin('p.classes', 'classes', 'WITH');
         $cnd = \XLite\Module\CDev\VAT\Logic\Product\Tax::getInstance()->getSearchPriceCondition('p.price', 'classes');
         if (isset($min)) {
             $queryBuilder->andWhere($cnd . ' > :minPrice')->setParameter('minPrice', doubleval($min));
         }
         if (isset($max)) {
             $queryBuilder->andWhere($cnd . ' < :maxPrice')->setParameter('maxPrice', doubleval($max));
         }
     }
 }
Exemplo n.º 4
0
 public function testSearchByPrice()
 {
     $tax = \XLite\Core\Database::getRepo('XLite\\Module\\CDev\\VAT\\Model\\Tax')->getTax();
     foreach ($tax->getRates() as $rate) {
         \XLite\Core\Database::getEM()->remove($rate);
     }
     $tax->getRates()->clear();
     $tax->setEnabled(true);
     $rate = new \XLite\Module\CDev\VAT\Model\Tax\Rate();
     $rate->setValue(10);
     $rate->setPosition(1);
     \XLite\Core\Database::getEM()->persist($rate);
     $tax->addRates($rate);
     $rate->setTax($tax);
     \XLite\Core\Database::getEM()->flush();
     $memberships = \XLite\Core\Database::getRepo('XLite\\Model\\Membership')->findAll();
     $membership = array_shift($memberships);
     $rate = new \XLite\Module\CDev\VAT\Model\Tax\Rate();
     $rate->setValue(20);
     $rate->setPosition(0);
     $rate->setMembership($membership);
     $rate->setTax($tax);
     $tax->setVATMembership($membership);
     $tax->addRates($rate);
     \XLite\Core\Database::getRepo('XLite\\Module\\CDev\\VAT\\Model\\Tax\\Rate')->insert($rate);
     \XLite\Module\CDev\VAT\Logic\Product\Tax::resetInstance();
     $cnd = new \XLite\Core\CommonCell(array(\XLite\Model\Repo\Product::P_PRICE => array(1, 2)));
     $result = \XLite\Core\Database::getRepo('\\XLite\\Model\\Product')->search($cnd);
     $this->assertEquals(2, count($result), 'check count');
     $result[0]->setPrice(1.01);
     \XLite\Core\Database::getEM()->flush();
     $result = \XLite\Core\Database::getRepo('\\XLite\\Model\\Product')->search($cnd);
     $this->assertEquals(1, count($result), 'check count #2');
     $rate->setPosition(2);
     \XLite\Core\Database::getEM()->flush();
     \XLite\Module\CDev\VAT\Logic\Product\Tax::resetInstance();
     $result = \XLite\Core\Database::getRepo('\\XLite\\Model\\Product')->search($cnd);
     $this->assertEquals(3, count($result), 'check count #3');
     $result[0]->setPrice(1);
     \XLite\Core\Database::getEM()->flush();
     $result = \XLite\Core\Database::getRepo('\\XLite\\Model\\Product')->search($cnd);
     $this->assertEquals(2, count($result), 'check count #4');
 }
Exemplo n.º 5
0
 /**
  * Modify money 
  * 
  * @param float                $value     Value
  * @param \XLite\Model\AEntity $model     Model
  * @param string               $property  Model's property
  * @param array                $behaviors Behaviors
  * @param string               $purpose   Purpose
  *  
  * @return void
  */
 public static function modifyMoney($value, \XLite\Model\AEntity $model, $property, array $behaviors, $purpose)
 {
     $obj = $model instanceof \XLite\Model\Product ? $model : $model->getProduct();
     return \XLite\Module\CDev\VAT\Logic\Product\Tax::getInstance()->deductTaxFromPrice($obj, $value);
 }