Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ProductPriceSolver.php 5.5KB

il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace Lc\CaracoleBundle\Solver\Price;
  3. use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface;
  4. use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
  5. use Lc\CaracoleBundle\Model\Product\ProductInterface;
  6. use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;
  7. use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;
  8. use Lc\CaracoleBundle\Solver\Product\ProductSolver;
  9. class ProductPriceSolver
  10. {
  11. use PriceSolverTrait;
  12. protected ProductSolver $productSolver;
  13. protected ProductFamilySolver $productFamilySolver;
  14. public function __construct(ProductSolver $productSolver, ProductFamilySolver $productFamilySolver)
  15. {
  16. $this->productSolver = $productSolver;
  17. $this->productFamilySolver = $productFamilySolver;
  18. }
  19. public function getSolver(ProductPropertyInterface $product)
  20. {
  21. if ($product instanceof ProductFamilyInterface) {
  22. return $this->productFamilySolver;
  23. }
  24. if ($product instanceof ProductInterface) {
  25. return $this->productSolver;
  26. }
  27. }
  28. public function getPrice(ProductPropertyInterface $product)
  29. {
  30. $solver = $this->getSolver($product);
  31. if ($solver->getBehaviorPriceInherited($product) == 'by-piece') {
  32. return $solver->getPriceInherited($product);
  33. } elseif ($solver->getBehaviorPriceInherited($product) == 'by-reference-unit') {
  34. if ($solver->getQuantityInherited($product) > 0) {
  35. return $solver->getPriceByRefUnitInherited($product) * ($solver->getQuantityInherited(
  36. $product
  37. ) / $solver->getUnitInherited($product)->getCoefficient());
  38. } else {
  39. return 0;
  40. }
  41. }
  42. }
  43. public function getPriceWithTax(ProductPropertyInterface $product)
  44. {
  45. return $this->applyTax(
  46. $this->getPrice($product),
  47. $this->productFamilySolver->getTaxRateInherited($product)->getValue()
  48. );
  49. }
  50. public function getPriceByRefUnit(ProductPropertyInterface $product)
  51. {
  52. $solver = $this->getSolver($product);
  53. if ($solver->getBehaviorPriceInherited($product) == 'by-piece') {
  54. return ($this->getPrice($product) * $solver->getUnitInherited($product)->getCoefficient(
  55. )) / $solver->getQuantityInherited($product);
  56. } elseif ($solver->getBehaviorPriceInherited($product) == 'by-reference-unit') {
  57. return $solver->getPriceByRefUnitInherited($product);
  58. }
  59. }
  60. public function getPriceByRefUnitWithTax(ProductPropertyInterface $product)
  61. {
  62. return $this->applyTax(
  63. $this->getPriceByRefUnit($product),
  64. $this->productFamilySolver->getTaxRateInherited($product)->getValue()
  65. );
  66. }
  67. public function getPriceWithTaxAndReduction(ProductPropertyInterface $product)
  68. {
  69. return $this->applyReductionCatalog(
  70. $product,
  71. $this->getPrice($product),
  72. $this->getPriceWithTax($product)
  73. );
  74. }
  75. //Bridge pour applyReductionCatalog qui ne peut pas être appeler à cause du call
  76. public function getPriceWithTaxByReduction(
  77. ProductPropertyInterface $product,
  78. ReductionCatalogInterface $reductionCatalog
  79. ) {
  80. return $this->applyReductionCatalog(
  81. $product,
  82. $this->getPrice($product),
  83. $this->getPriceWithTax($product),
  84. 1,
  85. $reductionCatalog
  86. );
  87. }
  88. public function getPriceByRefUnitWithTaxAndReduction(ProductPropertyInterface $product)
  89. {
  90. $priceWithTax = $this->getPriceWithTax($product);
  91. if ($priceWithTax) {
  92. return ($this->getPriceByRefUnitWithTax($product) * $this->getPriceWithTaxAndReduction($product))
  93. / $priceWithTax;
  94. }
  95. return 0;
  96. }
  97. public function getBuyingPrice(ProductPropertyInterface $product)
  98. {
  99. $solver = $this->getSolver($product);
  100. if ($solver->getBehaviorPriceInherited($product) == 'by-piece') {
  101. return $solver->getBuyingPriceInherited($product);
  102. } elseif ($solver->getBehaviorPriceInherited($product) == 'by-reference-unit') {
  103. if ($solver->getQuantityInherited($product) > 0) {
  104. return $solver->getBuyingPriceByRefUnitInherited($product) * ($solver->getQuantityInherited(
  105. $product
  106. ) / $solver->getUnitInherited($product)->getCoefficient());
  107. } else {
  108. return 0;
  109. }
  110. }
  111. }
  112. public function getBuyingPriceWithTax(ProductPropertyInterface $product)
  113. {
  114. return $this->applyTax(
  115. $this->getBuyingPrice($product),
  116. $this->productFamilySolver->getTaxRateInherited($product)->getValue()
  117. );
  118. }
  119. public function getBuyingPriceByRefUnit(ProductPropertyInterface $product)
  120. {
  121. return $this->getSolver($product)->getBuyingPriceByRefUnitInherited($product);
  122. }
  123. public function getBuyingPriceByRefUnitWithTax(ProductPropertyInterface $product)
  124. {
  125. return $this->applyTax(
  126. $this->getBuyingPriceByRefUnit($product),
  127. $this->productFamilySolver->getTaxRateInherited($product)->getValue()
  128. );
  129. }
  130. public function getMultiplyingFactor(ProductPropertyInterface $product)
  131. {
  132. return $this->round($this->getPriceWithTax($product) / $this->getBuyingPrice($product));
  133. }
  134. }