|
|
|
|
|
|
|
|
<?php |
|
|
<?php |
|
|
|
|
|
|
|
|
namespace Lc\ShopBundle\Services ; |
|
|
|
|
|
|
|
|
namespace Lc\ShopBundle\Services; |
|
|
|
|
|
|
|
|
use Doctrine\Common\Collections\Collection; |
|
|
use Doctrine\Common\Collections\Collection; |
|
|
use Lc\ShopBundle\Context\OrderProductInterface; |
|
|
use Lc\ShopBundle\Context\OrderProductInterface; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getPrice($entity) |
|
|
public function getPrice($entity) |
|
|
{ |
|
|
{ |
|
|
if($entity instanceof ProductPropertyInterface) { |
|
|
|
|
|
if($entity->getBehaviorPriceInherited() == 'by-piece') { |
|
|
|
|
|
return $entity->getPriceInherited() ; |
|
|
|
|
|
} |
|
|
|
|
|
elseif($entity->getBehaviorPriceInherited() == 'by-reference-unit') { |
|
|
|
|
|
if($entity->getQuantityInherited() > 0) { |
|
|
|
|
|
return $entity->getPriceByRefUnitInherited() * ($entity->getQuantityInherited() / $entity->getUnitInherited()->getCoefficient()) ; |
|
|
|
|
|
|
|
|
if ($entity instanceof ProductPropertyInterface) { |
|
|
|
|
|
if ($entity->getBehaviorPriceInherited() == 'by-piece') { |
|
|
|
|
|
return $entity->getPriceInherited(); |
|
|
|
|
|
} elseif ($entity->getBehaviorPriceInherited() == 'by-reference-unit') { |
|
|
|
|
|
if ($entity->getQuantityInherited() > 0) { |
|
|
|
|
|
return $entity->getPriceByRefUnitInherited() * ($entity->getQuantityInherited() / $entity->getUnitInherited()->getCoefficient()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if($entity instanceof OrderProductInterface) { |
|
|
|
|
|
return $entity->getPrice() ; |
|
|
|
|
|
|
|
|
if ($entity instanceof OrderProductInterface) { |
|
|
|
|
|
return $entity->getPrice(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return null ; |
|
|
|
|
|
|
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getPriceWithTax($entity) |
|
|
public function getPriceWithTax($entity) |
|
|
|
|
|
|
|
|
return $this->applyTax( |
|
|
return $this->applyTax( |
|
|
$this->getPrice($entity), |
|
|
$this->getPrice($entity), |
|
|
$entity->getTaxRateInherited()->getValue() |
|
|
$entity->getTaxRateInherited()->getValue() |
|
|
) ; |
|
|
|
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getPriceWithTaxAndReduction($entity) |
|
|
public function getPriceWithTaxAndReduction($entity) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getPriceByRefUnit($entity) |
|
|
public function getPriceByRefUnit($entity) |
|
|
{ |
|
|
{ |
|
|
if($entity instanceof ProductPropertyInterface) { |
|
|
|
|
|
if($entity->getBehaviorPriceInherited() == 'by-piece') { |
|
|
|
|
|
return ($this->getPrice($entity) * $entity->getUnitInherited()->getCoefficient()) / $entity->getQuantityInherited() ; |
|
|
|
|
|
} |
|
|
|
|
|
elseif($entity->getBehaviorPriceInherited() == 'by-reference-unit') { |
|
|
|
|
|
return $entity->getPriceByRefUnitInherited() ; |
|
|
|
|
|
|
|
|
if ($entity instanceof ProductPropertyInterface) { |
|
|
|
|
|
if ($entity->getBehaviorPriceInherited() == 'by-piece') { |
|
|
|
|
|
return ($this->getPrice($entity) * $entity->getUnitInherited()->getCoefficient()) / $entity->getQuantityInherited(); |
|
|
|
|
|
} elseif ($entity->getBehaviorPriceInherited() == 'by-reference-unit') { |
|
|
|
|
|
return $entity->getPriceByRefUnitInherited(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if($entity instanceof OrderProductInterface) { |
|
|
|
|
|
return ($this->getPrice($entity) * $entity->getUnitInherited()->getCoefficient()) / $entity->getQuantityProduct() ; |
|
|
|
|
|
|
|
|
if ($entity instanceof OrderProductInterface) { |
|
|
|
|
|
return ($this->getPrice($entity) * $entity->getUnitInherited()->getCoefficient()) / $entity->getQuantityProduct(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return null ; |
|
|
|
|
|
|
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getPriceByRefUnitWithTax($entity) |
|
|
public function getPriceByRefUnitWithTax($entity) |
|
|
|
|
|
|
|
|
return $this->applyTax( |
|
|
return $this->applyTax( |
|
|
$this->getPriceByRefUnit($entity), |
|
|
$this->getPriceByRefUnit($entity), |
|
|
$entity->getTaxRateInherited()->getValue() |
|
|
$entity->getTaxRateInherited()->getValue() |
|
|
) ; |
|
|
|
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getPriceByRefUnitWithTaxAndReduction($entity) |
|
|
public function getPriceByRefUnitWithTaxAndReduction($entity) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getTotal($entity) |
|
|
public function getTotal($entity) |
|
|
{ |
|
|
{ |
|
|
if($entity instanceof OrderProductInterface) { |
|
|
|
|
|
return $entity->getQuantityOrder() * $this->getPrice($entity) ; |
|
|
|
|
|
|
|
|
if ($entity instanceof OrderProductInterface) { |
|
|
|
|
|
return $entity->getQuantityOrder() * $this->getPrice($entity); |
|
|
} |
|
|
} |
|
|
if($entity instanceof OrderShopInterface) { |
|
|
|
|
|
$total = 0 ; |
|
|
|
|
|
foreach($entity->getOrderProducts() as $orderProduct) { |
|
|
|
|
|
$total += $this->getTotal($orderProduct) ; |
|
|
|
|
|
|
|
|
if ($entity instanceof OrderShopInterface) { |
|
|
|
|
|
$total = 0; |
|
|
|
|
|
foreach ($entity->getOrderProducts() as $orderProduct) { |
|
|
|
|
|
$total += $this->getTotal($orderProduct); |
|
|
} |
|
|
} |
|
|
return $total ; |
|
|
|
|
|
|
|
|
return $total; |
|
|
} |
|
|
} |
|
|
return null ; |
|
|
|
|
|
|
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getTotalWithTax($entity) |
|
|
public function getTotalWithTax($entity) |
|
|
{ |
|
|
{ |
|
|
if($entity instanceof OrderProductInterface) { |
|
|
|
|
|
|
|
|
if ($entity instanceof OrderProductInterface) { |
|
|
return $this->applyTax( |
|
|
return $this->applyTax( |
|
|
$this->getTotal($entity), |
|
|
$this->getTotal($entity), |
|
|
$entity->getTaxRateInherited()->getValue() |
|
|
$entity->getTaxRateInherited()->getValue() |
|
|
) ; |
|
|
|
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
if($entity instanceof OrderShopInterface) { |
|
|
|
|
|
$total = 0 ; |
|
|
|
|
|
foreach($entity->getOrderProducts() as $orderProduct) { |
|
|
|
|
|
$total += $this->getTotalWithTax($orderProduct) ; |
|
|
|
|
|
|
|
|
if ($entity instanceof OrderShopInterface) { |
|
|
|
|
|
$total = 0; |
|
|
|
|
|
foreach ($entity->getOrderProducts() as $orderProduct) { |
|
|
|
|
|
$total += $this->getTotalWithTax($orderProduct); |
|
|
} |
|
|
} |
|
|
return $total ; |
|
|
|
|
|
|
|
|
return $total; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//C'est bizzare ce truc là |
|
|
//C'est bizzare ce truc là |
|
|
//if($entity instanceof OrderShopInterface) { |
|
|
//if($entity instanceof OrderShopInterface) { |
|
|
// return $this->getTotalOrderProducts($entity->getOrderProducts(), true) ; |
|
|
// return $this->getTotalOrderProducts($entity->getOrderProducts(), true) ; |
|
|
//} |
|
|
//} |
|
|
return null ; |
|
|
|
|
|
|
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getTotalWithTaxAndReduction($entity) |
|
|
public function getTotalWithTaxAndReduction($entity) |
|
|
{ |
|
|
{ |
|
|
if($entity instanceof OrderProductInterface) { |
|
|
|
|
|
|
|
|
if ($entity instanceof OrderProductInterface) { |
|
|
return $this->getPriceWithTaxAndReductionCatalog( |
|
|
return $this->getPriceWithTaxAndReductionCatalog( |
|
|
$entity, |
|
|
$entity, |
|
|
$this->getTotal($entity), |
|
|
$this->getTotal($entity), |
|
|
$this->getTotalWithTax($entity) |
|
|
$this->getTotalWithTax($entity) |
|
|
) ; |
|
|
|
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if($entity instanceof OrderShopInterface) { |
|
|
|
|
|
return $this->getTotalOrderProductsWithTaxAndReduction($entity->getOrderProducts(), true, true) ; |
|
|
|
|
|
|
|
|
if ($entity instanceof OrderShopInterface) { |
|
|
|
|
|
return $this->getTotalOrderProductsWithTaxAndReduction($entity->getOrderProducts(), true, true); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getTotalWithReduction($entity) |
|
|
public function getTotalWithReduction($entity) |
|
|
{ |
|
|
{ |
|
|
if($entity instanceof OrderProductInterface) { |
|
|
|
|
|
|
|
|
if ($entity instanceof OrderProductInterface) { |
|
|
return $this->getPriceWithReductionCatalog( |
|
|
return $this->getPriceWithReductionCatalog( |
|
|
$entity, |
|
|
$entity, |
|
|
$this->getTotal($entity), |
|
|
$this->getTotal($entity), |
|
|
$this->getTotalWithTax($entity) |
|
|
$this->getTotalWithTax($entity) |
|
|
) ; |
|
|
|
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if($entity instanceof OrderShopInterface) { |
|
|
|
|
|
return $this->getTotalOrderProductsWithReduction($entity->getOrderProducts(), true, true) ; |
|
|
|
|
|
|
|
|
if ($entity instanceof OrderShopInterface) { |
|
|
|
|
|
return $this->getTotalOrderProductsWithReduction($entity->getOrderProducts(), true, true); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getTotalOrderProductsWithReductionCart(OrderShopInterface $order) |
|
|
|
|
|
{ |
|
|
|
|
|
$this->_getTotalOrderProductsWithReductionCartGeneric($order, false); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getTotalOrderProductsWithTaxAndReductionCart(OrderShopInterface $order) |
|
|
|
|
|
{ |
|
|
|
|
|
$this->_getTotalOrderProductsWithReductionCartGeneric($order, true); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private function _getTotalOrderProductsWithReductionCartGeneric(OrderShopInterface $order, $withTax = true) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
if ($withTax) { |
|
|
|
|
|
$priceToReturn = $this->getTotalOrderProductsWithTaxAndReductionCatalog(); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
$priceToReturn = $this->getTotalOrderProductsWithReductionCatalog(); |
|
|
|
|
|
} |
|
|
|
|
|
foreach ($order->getOrderReductionCarts() as $orderReductionCart) { |
|
|
|
|
|
if ($orderReductionCart->getUnit() == 'percent') { |
|
|
|
|
|
|
|
|
|
|
|
$priceToReturn = $this->applyReductionPercent( |
|
|
|
|
|
$priceToReturn, |
|
|
|
|
|
$orderReductionCart->getValue |
|
|
|
|
|
); |
|
|
|
|
|
} else if ($orderReductionCart->getUnit() == 'amount') { |
|
|
|
|
|
if ($orderReductionCart->getBehaviorTaxRate() == 'tax-inlcluded') { |
|
|
|
|
|
$priceToReturn = |
|
|
|
|
|
$this->applyReductionAmount( |
|
|
|
|
|
$priceToReturn, |
|
|
|
|
|
$orderReductionCart->getValue() |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getTotalOrderProducts($entity) |
|
|
public function getTotalOrderProducts($entity) |
|
|
{ |
|
|
{ |
|
|
return $this->getSumOrderProductsDispatch($entity) ; |
|
|
|
|
|
|
|
|
return $this->getSumOrderProductsDispatch($entity); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getTotalOrderProductsWithTax($entity) |
|
|
public function getTotalOrderProductsWithTax($entity) |
|
|
{ |
|
|
{ |
|
|
return $this->getSumOrderProductsDispatch($entity, true) ; |
|
|
|
|
|
|
|
|
return $this->getSumOrderProductsDispatch($entity, true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getTotalOrderProductsWithReduction($entity) |
|
|
|
|
|
|
|
|
public function getTotalOrderProductsWithReductionCatalog($entity) |
|
|
{ |
|
|
{ |
|
|
return $this->getSumOrderProductsDispatch($entity, false, true) ; |
|
|
|
|
|
|
|
|
return $this->getSumOrderProductsDispatch($entity, false, true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getTotalOrderProductsWithTaxAndReduction($entity) |
|
|
|
|
|
|
|
|
public function getTotalOrderProductsWithTaxAndReductionCatalog($entity) |
|
|
{ |
|
|
{ |
|
|
return $this->getSumOrderProductsDispatch($entity, true, true) ; |
|
|
|
|
|
|
|
|
return $this->getSumOrderProductsDispatch($entity, true, true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getSumOrderProductsDispatch($entity, $withTax = false, $withReduction = false) |
|
|
|
|
|
|
|
|
public function getSumOrderProductsDispatch($entity, $withTax = false, $withReductionCatalog = false) |
|
|
{ |
|
|
{ |
|
|
if($entity instanceof OrderShopInterface) { |
|
|
|
|
|
return $this->getSumOrderProducts($entity->getOrderProducts(), $withTax, $withReduction) ; |
|
|
|
|
|
|
|
|
if ($entity instanceof OrderShopInterface) { |
|
|
|
|
|
return $this->getSumOrderProducts($entity->getOrderProducts(), $withTax, $withReductionCatalog); |
|
|
} |
|
|
} |
|
|
if($entity instanceof Collection || is_array($entity)) { |
|
|
|
|
|
return $this->getSumOrderProducts($entity, $withTax, $withReduction) ; |
|
|
|
|
|
|
|
|
if ($entity instanceof Collection || is_array($entity)) { |
|
|
|
|
|
return $this->getSumOrderProducts($entity, $withTax, $withReductionCatalog); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getSumOrderProducts($orderProducts, $withTax = false, $withReduction = false) |
|
|
|
|
|
|
|
|
public function getSumOrderProducts($orderProducts, $withTax = false, $withReductionCatalog = false) |
|
|
{ |
|
|
{ |
|
|
$total = 0 ; |
|
|
|
|
|
foreach($orderProducts as $orderProduct) { |
|
|
|
|
|
if($withTax && $withReduction) { |
|
|
|
|
|
$total += $this->getTotalWithTaxAndReduction($orderProduct) ; |
|
|
|
|
|
} |
|
|
|
|
|
elseif($withTax) { |
|
|
|
|
|
$total += $this->getTotalWithTax($orderProduct) ; |
|
|
|
|
|
} |
|
|
|
|
|
elseif($withReduction) { |
|
|
|
|
|
$total += $this->getTotalWithReduction($orderProduct) ; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
$total += $this->getTotal($orderProduct) ; |
|
|
|
|
|
|
|
|
$total = 0; |
|
|
|
|
|
foreach ($orderProducts as $orderProduct) { |
|
|
|
|
|
if ($withTax && $withReductionCatalog) { |
|
|
|
|
|
$total += $this->getTotalWithTaxAndReduction($orderProduct); |
|
|
|
|
|
} elseif ($withTax) { |
|
|
|
|
|
$total += $this->getTotalWithTax($orderProduct); |
|
|
|
|
|
} elseif ($withReductionCatalog) { |
|
|
|
|
|
$total += $this->getTotalWithReduction($orderProduct); |
|
|
|
|
|
} else { |
|
|
|
|
|
$total += $this->getTotal($orderProduct); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return $total ; |
|
|
|
|
|
|
|
|
return $total; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getPriceWithTaxAndReductionCatalog($entity, $price, $priceWithTax, $reductionCatalog = null) |
|
|
public function getPriceWithTaxAndReductionCatalog($entity, $price, $priceWithTax, $reductionCatalog = null) |
|
|
{ |
|
|
{ |
|
|
return $this->getPriceWithReductionCatalogGeneric($entity, $price, $priceWithTax, $reductionCatalog, true) ; |
|
|
|
|
|
|
|
|
return $this->getPriceWithReductionCatalogGeneric($entity, $price, $priceWithTax, $reductionCatalog, true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getPriceWithReductionCatalog($entity, $price, $priceWithTax, $reductionCatalog = null) |
|
|
public function getPriceWithReductionCatalog($entity, $price, $priceWithTax, $reductionCatalog = null) |
|
|
{ |
|
|
{ |
|
|
return $this->getPriceWithReductionCatalogGeneric($entity, $price, $priceWithTax, $reductionCatalog, false) ; |
|
|
|
|
|
|
|
|
return $this->getPriceWithReductionCatalogGeneric($entity, $price, $priceWithTax, $reductionCatalog, false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getPriceWithReductionCatalogGeneric($entity, $price, $priceWithTax, $reductionCatalog = null, $withTax = true): ?float |
|
|
public function getPriceWithReductionCatalogGeneric($entity, $price, $priceWithTax, $reductionCatalog = null, $withTax = true): ?float |
|
|
{ |
|
|
{ |
|
|
if($reductionCatalog) { |
|
|
|
|
|
$reductionCatalogValue = $reductionCatalog->getValue() ; |
|
|
|
|
|
$reductionCatalogUnit = $reductionCatalog->getUnit() ; |
|
|
|
|
|
$reductionCatalogBehaviorTaxRate = $reductionCatalog->getBehaviorTaxRate() ; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
if($entity instanceof ProductPropertyInterface) { |
|
|
|
|
|
$reductionCatalog = $entity->getReductionCatalogInherited() ; |
|
|
|
|
|
|
|
|
|
|
|
if($reductionCatalog) { |
|
|
|
|
|
$reductionCatalogValue = $reductionCatalog->getValue() ; |
|
|
|
|
|
$reductionCatalogUnit = $reductionCatalog->getUnit() ; |
|
|
|
|
|
$reductionCatalogBehaviorTaxRate = $reductionCatalog->getBehaviorTaxRate() ; |
|
|
|
|
|
|
|
|
if ($reductionCatalog) { |
|
|
|
|
|
$reductionCatalogValue = $reductionCatalog->getValue(); |
|
|
|
|
|
$reductionCatalogUnit = $reductionCatalog->getUnit(); |
|
|
|
|
|
$reductionCatalogBehaviorTaxRate = $reductionCatalog->getBehaviorTaxRate(); |
|
|
|
|
|
} else { |
|
|
|
|
|
if ($entity instanceof ProductPropertyInterface) { |
|
|
|
|
|
$reductionCatalog = $entity->getReductionCatalogInherited(); |
|
|
|
|
|
|
|
|
|
|
|
if ($reductionCatalog) { |
|
|
|
|
|
$reductionCatalogValue = $reductionCatalog->getValue(); |
|
|
|
|
|
$reductionCatalogUnit = $reductionCatalog->getUnit(); |
|
|
|
|
|
$reductionCatalogBehaviorTaxRate = $reductionCatalog->getBehaviorTaxRate(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if($entity instanceof OrderProductInterface) { |
|
|
|
|
|
$orderProductReductionCatalog = $entity->getOrderProductReductionCatalog() ; |
|
|
|
|
|
if($orderProductReductionCatalog) { |
|
|
|
|
|
$reductionCatalogValue = $orderProductReductionCatalog->getValue() ; |
|
|
|
|
|
$reductionCatalogUnit = $orderProductReductionCatalog->getUnit() ; |
|
|
|
|
|
$reductionCatalogBehaviorTaxRate = $orderProductReductionCatalog->getBehaviorTaxRate() ; |
|
|
|
|
|
|
|
|
if ($entity instanceof OrderProductInterface) { |
|
|
|
|
|
$orderProductReductionCatalog = $entity->getOrderProductReductionCatalog(); |
|
|
|
|
|
if ($orderProductReductionCatalog) { |
|
|
|
|
|
$reductionCatalogValue = $orderProductReductionCatalog->getValue(); |
|
|
|
|
|
$reductionCatalogUnit = $orderProductReductionCatalog->getUnit(); |
|
|
|
|
|
$reductionCatalogBehaviorTaxRate = $orderProductReductionCatalog->getBehaviorTaxRate(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(isset($reductionCatalogValue) && isset($reductionCatalogUnit) && isset($reductionCatalogBehaviorTaxRate)) { |
|
|
|
|
|
|
|
|
if (isset($reductionCatalogValue) && isset($reductionCatalogUnit) && isset($reductionCatalogBehaviorTaxRate)) { |
|
|
if ($reductionCatalogUnit == 'percent') { |
|
|
if ($reductionCatalogUnit == 'percent') { |
|
|
$priceWithTax = $this->applyReductionPercent( |
|
|
$priceWithTax = $this->applyReductionPercent( |
|
|
$priceWithTax, |
|
|
$priceWithTax, |
|
|
$reductionCatalogValue |
|
|
$reductionCatalogValue |
|
|
); |
|
|
); |
|
|
} |
|
|
|
|
|
elseif ($reductionCatalogUnit == 'amount') { |
|
|
|
|
|
if($reductionCatalogBehaviorTaxRate == 'tax-excluded') { |
|
|
|
|
|
|
|
|
} elseif ($reductionCatalogUnit == 'amount') { |
|
|
|
|
|
if ($reductionCatalogBehaviorTaxRate == 'tax-excluded') { |
|
|
$priceWithTax = $this->applyTax( |
|
|
$priceWithTax = $this->applyTax( |
|
|
$this->applyReductionAmount( |
|
|
$this->applyReductionAmount( |
|
|
$price, |
|
|
$price, |
|
|
|
|
|
|
|
|
), |
|
|
), |
|
|
$entity->getTaxRateInherited()->getValue() |
|
|
$entity->getTaxRateInherited()->getValue() |
|
|
); |
|
|
); |
|
|
} |
|
|
|
|
|
elseif($reductionCatalogBehaviorTaxRate == 'tax-included') { |
|
|
|
|
|
|
|
|
} elseif ($reductionCatalogBehaviorTaxRate == 'tax-included') { |
|
|
$priceWithTax = $this->applyReductionAmount( |
|
|
$priceWithTax = $this->applyReductionAmount( |
|
|
$priceWithTax, |
|
|
$priceWithTax, |
|
|
$reductionCatalogValue |
|
|
$reductionCatalogValue |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if($withTax) { |
|
|
|
|
|
$priceReturn = $priceWithTax ; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
$priceReturn = $this->applyPercentNegative($priceWithTax, $entity->getTaxRateInherited()->getValue()) ; |
|
|
|
|
|
|
|
|
if ($withTax) { |
|
|
|
|
|
$priceReturn = $priceWithTax; |
|
|
|
|
|
} else { |
|
|
|
|
|
$priceReturn = $this->applyPercentNegative($priceWithTax, $entity->getTaxRateInherited()->getValue()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $this->round($priceReturn) ; |
|
|
|
|
|
|
|
|
return $this->round($priceReturn); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getTotalTaxes($entity) |
|
|
public function getTotalTaxes($entity) |
|
|
{ |
|
|
{ |
|
|
if($entity instanceof OrderProductInterface) { |
|
|
|
|
|
return $this->getTotalWithReduction($entity) * ($entity->getTaxRateInherited()->getValue() / 100) ; |
|
|
|
|
|
|
|
|
if ($entity instanceof OrderProductInterface) { |
|
|
|
|
|
return $this->getTotalWithReduction($entity) * ($entity->getTaxRateInherited()->getValue() / 100); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if($entity instanceof OrderShopInterface) { |
|
|
|
|
|
$totalTaxes = 0 ; |
|
|
|
|
|
foreach($entity->getOrderProducts() as $orderProduct) { |
|
|
|
|
|
$totalTaxes += $this->getTotalTaxes($orderProduct) ; |
|
|
|
|
|
|
|
|
if ($entity instanceof OrderShopInterface) { |
|
|
|
|
|
$totalTaxes = 0; |
|
|
|
|
|
foreach ($entity->getOrderProducts() as $orderProduct) { |
|
|
|
|
|
$totalTaxes += $this->getTotalTaxes($orderProduct); |
|
|
} |
|
|
} |
|
|
return $totalTaxes ; |
|
|
|
|
|
|
|
|
return $totalTaxes; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return 0 ; |
|
|
|
|
|
|
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function applyTax($price, $taxRateValue) |
|
|
public function applyTax($price, $taxRateValue) |
|
|
{ |
|
|
{ |
|
|
return $this->round($this->applyPercent($price, $taxRateValue)) ; |
|
|
|
|
|
|
|
|
return $this->round($this->applyPercent($price, $taxRateValue)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function applyReductionPercent($price, $percentage) |
|
|
public function applyReductionPercent($price, $percentage) |
|
|
{ |
|
|
{ |
|
|
return $this->applyPercent($price, -$percentage) ; |
|
|
|
|
|
|
|
|
return $this->applyPercent($price, -$percentage); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function applyReductionAmount($price, $amount) |
|
|
public function applyReductionAmount($price, $amount) |
|
|
{ |
|
|
{ |
|
|
return $price - $amount ; |
|
|
|
|
|
|
|
|
return $price - $amount; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function applyPercent($price, $percentage) |
|
|
public function applyPercent($price, $percentage) |
|
|
{ |
|
|
{ |
|
|
return $price * ($percentage / 100 + 1) ; |
|
|
|
|
|
|
|
|
return $price * ($percentage / 100 + 1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function applyPercentNegative($price, $percentage) |
|
|
public function applyPercentNegative($price, $percentage) |
|
|
{ |
|
|
{ |
|
|
return $price / ($percentage / 100 + 1) ; |
|
|
|
|
|
|
|
|
return $price / ($percentage / 100 + 1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function round($price) |
|
|
public function round($price) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|