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.

154 satır
4.7KB

  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->getTaxRate()->getValue()
  104. );
  105. }
  106. public function getTotalWithTaxAndReduction(OrderProductInterface $orderProduct, bool $round = true)
  107. {
  108. return $this->applyReductionCatalog(
  109. $orderProduct,
  110. $this->getTotal($orderProduct),
  111. $this->getTotalWithTax($orderProduct),
  112. $orderProduct->getQuantityOrder(),
  113. null,
  114. true,
  115. $round
  116. );
  117. }
  118. public function getTotalBuyingPriceWithTax(OrderProductInterface $orderProduct)
  119. {
  120. return $this->applyTax(
  121. $this->getTotalBuyingPrice($orderProduct),
  122. $orderProduct->getTaxRate()->getValue()
  123. );
  124. }
  125. //inclus toujours les réductions catalogues
  126. public function getTotalTaxes(OrderProductInterface $orderProduct)
  127. {
  128. return $this->getTotalWithTaxAndReduction($orderProduct) - $this->getTotalWithReduction($orderProduct);
  129. }
  130. }