|
|
@@ -138,6 +138,21 @@ class PriceUtils |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function getTotalWithReduction($entity) |
|
|
|
{ |
|
|
|
if($entity instanceof OrderProductInterface) { |
|
|
|
return $this->getPriceWithReductionCatalog( |
|
|
|
$entity, |
|
|
|
$this->getTotal($entity), |
|
|
|
$this->getTotalWithTax($entity) |
|
|
|
) ; |
|
|
|
} |
|
|
|
|
|
|
|
if($entity instanceof OrderShopInterface) { |
|
|
|
return $this->getTotalOrderProductsWithReduction($entity->getOrderProducts(), true, true) ; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function getTotalOrderProducts($entity) |
|
|
|
{ |
|
|
|
return $this->getSumOrderProductsDispatch($entity) ; |
|
|
@@ -148,6 +163,11 @@ class PriceUtils |
|
|
|
return $this->getSumOrderProductsDispatch($entity, true) ; |
|
|
|
} |
|
|
|
|
|
|
|
public function getTotalOrderProductsWithReduction($entity) |
|
|
|
{ |
|
|
|
return $this->getSumOrderProductsDispatch($entity, false, true) ; |
|
|
|
} |
|
|
|
|
|
|
|
public function getTotalOrderProductsWithTaxAndReduction($entity) |
|
|
|
{ |
|
|
|
return $this->getSumOrderProductsDispatch($entity, true, true) ; |
|
|
@@ -173,6 +193,9 @@ class PriceUtils |
|
|
|
elseif($withTax) { |
|
|
|
$total += $this->getTotalWithTax($orderProduct) ; |
|
|
|
} |
|
|
|
elseif($withReduction) { |
|
|
|
$total += $this->getTotalWithReduction($orderProduct) ; |
|
|
|
} |
|
|
|
else { |
|
|
|
$total += $this->getTotal($orderProduct) ; |
|
|
|
} |
|
|
@@ -180,7 +203,17 @@ class PriceUtils |
|
|
|
return $total ; |
|
|
|
} |
|
|
|
|
|
|
|
public function getPriceWithTaxAndReductionCatalog($entity, $price, $priceWithTax, $reductionCatalog = null): ?float |
|
|
|
public function getPriceWithTaxAndReductionCatalog($entity, $price, $priceWithTax, $reductionCatalog = null) |
|
|
|
{ |
|
|
|
return $this->getPriceWithReductionCatalogGeneric($entity, $price, $priceWithTax, $reductionCatalog, true) ; |
|
|
|
} |
|
|
|
|
|
|
|
public function getPriceWithReductionCatalog($entity, $price, $priceWithTax, $reductionCatalog = null) |
|
|
|
{ |
|
|
|
return $this->getPriceWithReductionCatalogGeneric($entity, $price, $priceWithTax, $reductionCatalog, false) ; |
|
|
|
} |
|
|
|
|
|
|
|
public function getPriceWithReductionCatalogGeneric($entity, $price, $priceWithTax, $reductionCatalog = null, $withTax = true): ?float |
|
|
|
{ |
|
|
|
if($reductionCatalog) { |
|
|
|
$reductionCatalogValue = $reductionCatalog->getValue() ; |
|
|
@@ -234,7 +267,31 @@ class PriceUtils |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return $this->round($priceWithTax) ; |
|
|
|
if($withTax) { |
|
|
|
$priceReturn = $priceWithTax ; |
|
|
|
} |
|
|
|
else { |
|
|
|
$priceReturn = $this->applyPercentNegative($priceWithTax, $entity->getTaxRateInherited()->getValue()) ; |
|
|
|
} |
|
|
|
|
|
|
|
return $this->round($priceReturn) ; |
|
|
|
} |
|
|
|
|
|
|
|
public function getTotalTaxes($entity) |
|
|
|
{ |
|
|
|
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) ; |
|
|
|
} |
|
|
|
return $totalTaxes ; |
|
|
|
} |
|
|
|
|
|
|
|
return 0 ; |
|
|
|
} |
|
|
|
|
|
|
|
public function applyTax($price, $taxRateValue) |
|
|
@@ -257,6 +314,11 @@ class PriceUtils |
|
|
|
return $price * ($percentage / 100 + 1) ; |
|
|
|
} |
|
|
|
|
|
|
|
public function applyPercentNegative($price, $percentage) |
|
|
|
{ |
|
|
|
return $price / ($percentage / 100 + 1) ; |
|
|
|
} |
|
|
|
|
|
|
|
public function round($price) |
|
|
|
{ |
|
|
|
return round((($price * 100)) / 100, 2); |