No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

125 líneas
4.6KB

  1. <?php
  2. namespace Lc\ShopBundle\Services\Price;
  3. use Doctrine\Common\Collections\Collection;
  4. use Lc\ShopBundle\Context\OrderProductInterface;
  5. use Lc\ShopBundle\Context\OrderShopInterface;
  6. use Lc\ShopBundle\Context\ProductFamilyInterface;
  7. use Lc\ShopBundle\Context\ProductInterface;
  8. use Lc\ShopBundle\Context\ProductPropertyInterface;
  9. use Lc\ShopBundle\Context\ReductionCatalogInterface;
  10. class ProductPriceUtils
  11. {
  12. use PriceUtilsTrait ;
  13. public function getPrice(ProductPropertyInterface $product)
  14. {
  15. if ($product->getBehaviorPriceInherited() == 'by-piece') {
  16. return $product->getPriceInherited();
  17. }
  18. elseif ($product->getBehaviorPriceInherited() == 'by-reference-unit') {
  19. if ($product->getQuantityInherited() > 0) {
  20. return $product->getPriceByRefUnitInherited() * ($product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient());
  21. }else{
  22. return 0;
  23. }
  24. }
  25. }
  26. public function getPriceWithTax(ProductPropertyInterface $product)
  27. {
  28. return $this->applyTax(
  29. $this->getPrice($product),
  30. $product->getTaxRateInherited()->getValue()
  31. );
  32. }
  33. public function getPriceByRefUnit(ProductPropertyInterface $product)
  34. {
  35. if ($product->getBehaviorPriceInherited() == 'by-piece') {
  36. return ($this->getPrice($product) * $product->getUnitInherited()->getCoefficient()) / $product->getQuantityInherited();
  37. } elseif ($product->getBehaviorPriceInherited() == 'by-reference-unit') {
  38. return $product->getPriceByRefUnitInherited();
  39. }
  40. }
  41. public function getPriceByRefUnitWithTax(ProductPropertyInterface $product)
  42. {
  43. return $this->applyTax(
  44. $this->getPriceByRefUnit($product),
  45. $product->getTaxRateInherited()->getValue()
  46. );
  47. }
  48. public function getPriceWithTaxAndReduction(ProductPropertyInterface $product)
  49. {
  50. return $this->applyReductionCatalog(
  51. $product,
  52. $this->getPrice($product),
  53. $this->getPriceWithTax($product)
  54. );
  55. }
  56. public function getPriceByRefUnitWithTaxAndReduction(ProductPropertyInterface $product)
  57. {
  58. return ($this->getPriceByRefUnitWithTax($product) * $this->getPriceWithTaxAndReduction($product))
  59. / $this->getPriceWithTax($product) ;
  60. /*return $this->applyReductionCatalog(
  61. $product,
  62. $this->getPriceByRefUnit($product),
  63. $this->getPriceByRefUnitWithTax($product)
  64. );*/
  65. }
  66. public function getBuyingPrice(ProductPropertyInterface $product)
  67. {
  68. if ($product->getBehaviorPriceInherited() == 'by-piece') {
  69. return $product->getBuyingPriceInherited() ;
  70. }
  71. elseif ($product->getBehaviorPriceInherited() == 'by-reference-unit') {
  72. if ($product->getQuantityInherited() > 0) {
  73. return $product->getBuyingPriceByRefUnitInherited() * ($product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient());
  74. }
  75. else {
  76. return 0;
  77. }
  78. }
  79. }
  80. public function getBuyingPriceWithTax(ProductPropertyInterface $product)
  81. {
  82. return $this->applyTax(
  83. $this->getBuyingPrice($product),
  84. $product->getTaxRateInherited()->getValue()
  85. );
  86. }
  87. public function getBuyingPriceByRefUnit(ProductPropertyInterface $product)
  88. {
  89. return $product->getBuyingPriceByRefUnitInherited() ;
  90. }
  91. public function getBuyingPriceByRefUnitWithTax(ProductPropertyInterface $product)
  92. {
  93. return $this->applyTax(
  94. $this->getBuyingPriceByRefUnit($product),
  95. $product->getTaxRateInherited()->getValue()
  96. );
  97. }
  98. public function getMultiplyingFactor(ProductPropertyInterface $product)
  99. {
  100. return $this->round($this->getPriceWithTax($product) / $this->getBuyingPrice($product));
  101. }
  102. }