Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

141 lines
4.2KB

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