You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 line
4.5KB

  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->applyReductionCatalog(
  59. $product,
  60. $this->getPriceByRefUnit($product),
  61. $this->getPriceByRefUnitWithTax($product)
  62. );
  63. }
  64. public function getBuyingPrice(ProductPropertyInterface $product)
  65. {
  66. if ($product->getBehaviorPriceInherited() == 'by-piece') {
  67. return $product->getBuyingPriceInherited() ;
  68. }
  69. elseif ($product->getBehaviorPriceInherited() == 'by-reference-unit') {
  70. if ($product->getQuantityInherited() > 0) {
  71. return $product->getBuyingPriceByRefUnitInherited() * ($product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient());
  72. }
  73. else {
  74. return 0;
  75. }
  76. }
  77. }
  78. public function getBuyingPriceWithTax(ProductPropertyInterface $product)
  79. {
  80. return $this->applyTax(
  81. $this->getBuyingPrice($product),
  82. $product->getTaxRateInherited()->getValue()
  83. );
  84. }
  85. public function getBuyingPriceByRefUnit(ProductPropertyInterface $product)
  86. {
  87. return $product->getBuyingPriceByRefUnitInherited() ;
  88. }
  89. public function getBuyingPriceByRefUnitWithTax(ProductPropertyInterface $product)
  90. {
  91. return $this->applyTax(
  92. $this->getBuyingPriceByRefUnit($product),
  93. $product->getTaxRateInherited()->getValue()
  94. );
  95. }
  96. public function getMultiplyingFactor(ProductPropertyInterface $product)
  97. {
  98. return $this->round($this->getPriceWithTax($product) / $this->getBuyingPrice($product));
  99. }
  100. }