Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

150 Zeilen
5.2KB

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