選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

156 行
4.8KB

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