Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

150 lines
4.6KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Solver\Price;
  3. use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
  4. use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;
  5. use Lc\CaracoleBundle\Solver\Product\ProductSolver;
  6. class OrderProductPriceSolver
  7. {
  8. use PriceSolverTrait;
  9. protected ProductSolver $productSolver;
  10. protected ProductFamilySolver $productFamilySolver;
  11. protected ProductPriceSolver $productPriceSolver;
  12. public function __construct(
  13. ProductPriceSolver $productPriceSolver,
  14. ProductSolver $productSolver,
  15. ProductFamilySolver $productFamilySolver
  16. ) {
  17. $this->productPriceSolver = $productPriceSolver;
  18. $this->productSolver = $productSolver;
  19. $this->productFamilySolver = $productFamilySolver;
  20. }
  21. public function getPrice(OrderProductInterface $orderProduct, $round = false)
  22. {
  23. if ($round) {
  24. return $this->round($orderProduct->getPrice());
  25. } else {
  26. return $orderProduct->getPrice();
  27. }
  28. }
  29. public function getBuyingPrice(OrderProductInterface $orderProduct, $round = false)
  30. {
  31. if ($round) {
  32. return $this->round($orderProduct->getBuyingPrice());
  33. } else {
  34. return $orderProduct->getBuyingPrice();
  35. }
  36. }
  37. public function getPriceWithTax(OrderProductInterface $orderProduct)
  38. {
  39. return $this->applyTax(
  40. $this->getPrice($orderProduct),
  41. $orderProduct->getTaxRate()->getValue()
  42. );
  43. }
  44. public function getPriceWithTaxAndReduction(OrderProductInterface $orderProduct)
  45. {
  46. return $this->applyReductionCatalog(
  47. $orderProduct,
  48. $this->getPrice($orderProduct),
  49. $this->getPriceWithTax($orderProduct)
  50. );
  51. }
  52. public function getPriceWithReduction(OrderProductInterface $orderProduct, $round = true)
  53. {
  54. return $this->applyReductionCatalog(
  55. $orderProduct,
  56. $this->getPrice($orderProduct),
  57. $this->getPriceWithTax($orderProduct),
  58. 1,
  59. null,
  60. false,
  61. $round
  62. );
  63. }
  64. public function getTotal(OrderProductInterface $orderProduct)
  65. {
  66. return $orderProduct->getQuantityOrder() * $this->getPrice($orderProduct);
  67. }
  68. public function getTotalBuyingPrice(OrderProductInterface $orderProduct)
  69. {
  70. return $orderProduct->getQuantityOrder() * $this->getBuyingPrice($orderProduct);
  71. }
  72. public function getMargin(OrderProductInterface $orderProduct)
  73. {
  74. return $this->round($this->getPriceWithReduction($orderProduct, false) - $this->getBuyingPrice($orderProduct));
  75. }
  76. public function getMarginPercent(OrderProductInterface $orderProduct)
  77. {
  78. if ($this->getBuyingPrice($orderProduct) && $this->getPriceWithReduction($orderProduct)) {
  79. return $this->round(($this->getMargin($orderProduct) / $this->getPriceWithReduction($orderProduct)) * 100);
  80. } else {
  81. return 0;
  82. }
  83. }
  84. public function getTotalMargin(OrderProductInterface $orderProduct)
  85. {
  86. return $orderProduct->getQuantityOrder() * $this->getMargin($orderProduct);
  87. }
  88. public function getTotalWithReduction(OrderProductInterface $orderProduct)
  89. {
  90. return $this->applyReductionCatalog(
  91. $orderProduct,
  92. $this->getTotal($orderProduct),
  93. $this->getTotalWithTax($orderProduct),
  94. $orderProduct->getQuantityOrder(),
  95. null,
  96. false
  97. );
  98. }
  99. public function getTotalWithTax(OrderProductInterface $orderProduct)
  100. {
  101. return $this->applyTax(
  102. $this->getTotal($orderProduct),
  103. $orderProduct->getTaxRateInherited()->getValue()
  104. );
  105. }
  106. public function getTotalWithTaxAndReduction(OrderProductInterface $orderProduct)
  107. {
  108. return $this->applyReductionCatalog(
  109. $orderProduct,
  110. $this->getTotal($orderProduct),
  111. $this->getTotalWithTax($orderProduct),
  112. $orderProduct->getQuantityOrder()
  113. );
  114. }
  115. public function getTotalBuyingPriceWithTax(OrderProductInterface $orderProduct)
  116. {
  117. return $this->applyTax(
  118. $this->getTotalBuyingPrice($orderProduct),
  119. $orderProduct->getTaxRateInherited()->getValue()
  120. );
  121. }
  122. //inclus toujours les réductions catalogues
  123. public function getTotalTaxes(OrderProductInterface $orderProduct)
  124. {
  125. return $this->getTotalWithTaxAndReduction($orderProduct) - $this->getTotalWithReduction($orderProduct);
  126. }
  127. }