Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ProductPriceSolver.php 4.8KB

pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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\Solver\Product\ProductFamilySolver;
  7. use Lc\CaracoleBundle\Solver\Product\ProductSolver;
  8. class ProductPriceSolver
  9. {
  10. use PriceSolverTrait;
  11. protected ProductSolver $productSolver;
  12. protected ProductFamilySolver $productFamilySolver;
  13. public function __construct(ProductSolver $productSolver, ProductFamilySolver $productFamilySolver)
  14. {
  15. $this->productSolver = $productSolver;
  16. $this->productFamilySolver = $productFamilySolver;
  17. }
  18. public function getSolver(ProductPropertyInterface $product)
  19. {
  20. if($product instanceof ProductFamilyInterface) {
  21. return $this->productFamilySolver;
  22. }
  23. if($product instanceof ProductInterface) {
  24. return $this->productSolver;
  25. }
  26. }
  27. public function getPrice(ProductPropertyInterface $product)
  28. {
  29. $solver = $this->getSolver($product);
  30. if ($solver->getBehaviorPriceInherited($product) == 'by-piece') {
  31. return $solver->getPriceInherited($product);
  32. } elseif ($solver->getBehaviorPriceInherited($product) == 'by-reference-unit') {
  33. if ($solver->getQuantityInherited($product) > 0) {
  34. return $solver->getPriceByRefUnitInherited($product) * ($solver->getQuantityInherited($product
  35. ) / $solver->getUnitInherited($product)->getCoefficient());
  36. } else {
  37. return 0;
  38. }
  39. }
  40. }
  41. public function getPriceWithTax(ProductPropertyInterface $product)
  42. {
  43. return $this->applyTax(
  44. $this->getPrice($product),
  45. $this->productFamilySolver->getTaxRateInherited($product)->getValue()
  46. );
  47. }
  48. public function getPriceByRefUnit(ProductPropertyInterface $product)
  49. {
  50. $solver = $this->getSolver($product);
  51. if ($solver->getBehaviorPriceInherited($product) == 'by-piece') {
  52. return ($this->getPrice($product) * $solver->getUnitInherited($product)->getCoefficient(
  53. )) / $solver->getQuantityInherited($product);
  54. } elseif ($solver->getBehaviorPriceInherited($product) == 'by-reference-unit') {
  55. return $solver->getPriceByRefUnitInherited($product);
  56. }
  57. }
  58. public function getPriceByRefUnitWithTax(ProductPropertyInterface $product)
  59. {
  60. return $this->applyTax(
  61. $this->getPriceByRefUnit($product),
  62. $this->productFamilySolver->getTaxRateInherited($product)->getValue()
  63. );
  64. }
  65. public function getPriceWithTaxAndReduction(ProductPropertyInterface $product)
  66. {
  67. return $this->applyReductionCatalog(
  68. $product,
  69. $this->getPrice($product),
  70. $this->getPriceWithTax($product)
  71. );
  72. }
  73. public function getPriceByRefUnitWithTaxAndReduction(ProductPropertyInterface $product)
  74. {
  75. return ($this->getPriceByRefUnitWithTax($product) * $this->getPriceWithTaxAndReduction($product))
  76. / $this->getPriceWithTax($product);
  77. }
  78. public function getBuyingPrice(ProductPropertyInterface $product)
  79. {
  80. $solver = $this->getSolver($product);
  81. if ($solver->getBehaviorPriceInherited($product) == 'by-piece') {
  82. return $solver->getBuyingPriceInherited($product);
  83. } elseif ($solver->getBehaviorPriceInherited($product) == 'by-reference-unit') {
  84. if ($solver->getQuantityInherited($product) > 0) {
  85. return $solver->getBuyingPriceByRefUnitInherited($product) * ($solver->getQuantityInherited($product
  86. ) / $solver->getUnitInherited($product)->getCoefficient());
  87. } else {
  88. return 0;
  89. }
  90. }
  91. }
  92. public function getBuyingPriceWithTax(ProductPropertyInterface $product)
  93. {
  94. return $this->applyTax(
  95. $this->getBuyingPrice($product),
  96. $this->productFamilySolver->getTaxRateInherited($product)->getValue()
  97. );
  98. }
  99. public function getBuyingPriceByRefUnit(ProductPropertyInterface $product)
  100. {
  101. return $this->getSolver($product)->getBuyingPriceByRefUnitInherited($product);
  102. }
  103. public function getBuyingPriceByRefUnitWithTax(ProductPropertyInterface $product)
  104. {
  105. return $this->applyTax(
  106. $this->getBuyingPriceByRefUnit($product),
  107. $this->productFamilySolver->getTaxRateInherited($product)->getValue()
  108. );
  109. }
  110. public function getMultiplyingFactor(ProductPropertyInterface $product)
  111. {
  112. return $this->round($this->getPriceWithTax($product) / $this->getBuyingPrice($product));
  113. }
  114. }