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.

OrderProductPriceSolver.php 4.6KB

pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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)
  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->getTaxRate()->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. }