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.

111 line
3.6KB

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