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.

140 Zeilen
4.7KB

  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)
  19. {
  20. return $orderProduct->getPrice();
  21. }
  22. public function getBuyingPrice(OrderProductInterface $orderProduct)
  23. {
  24. return $orderProduct->getBuyingPrice();
  25. }
  26. public function getPriceWithTax(OrderProductInterface $orderProduct)
  27. {
  28. return $this->applyTax(
  29. $this->getPrice($orderProduct),
  30. $orderProduct->getTaxRate()->getValue()
  31. );
  32. }
  33. public function getPriceWithTaxAndReduction(OrderProductInterface $orderProduct)
  34. {
  35. return $this->applyReductionCatalog(
  36. $orderProduct,
  37. $this->getPrice($orderProduct),
  38. $this->getPriceWithTax($orderProduct)
  39. );
  40. }
  41. public function getPriceWithReduction(OrderProductInterface $orderProduct)
  42. {
  43. return $this->applyReductionCatalog(
  44. $orderProduct,
  45. $this->getPrice($orderProduct),
  46. $this->getPriceWithTax($orderProduct),
  47. 1,
  48. null,
  49. false
  50. );
  51. }
  52. public function getTotal(OrderProductInterface $orderProduct)
  53. {
  54. return $orderProduct->getQuantityOrder() * $this->getPrice($orderProduct);
  55. }
  56. public function getTotalBuyingPrice(OrderProductInterface $orderProduct)
  57. {
  58. return $orderProduct->getQuantityOrder() * $this->getBuyingPrice($orderProduct);
  59. }
  60. public function getMargin(OrderProductInterface $orderProduct)
  61. {
  62. return $this->getPriceWithReduction($orderProduct) - $this->getBuyingPrice($orderProduct);
  63. }
  64. public function getMarginPercent(OrderProductInterface $orderProduct)
  65. {
  66. if($this->getBuyingPrice($orderProduct)) {
  67. return $this->round(($this->getMargin($orderProduct) / $this->getPriceWithReduction($orderProduct)) * 100);
  68. }else{
  69. return 0;
  70. }
  71. }
  72. public function getTotalMargin(OrderProductInterface $orderProduct)
  73. {
  74. return $orderProduct->getQuantityOrder() * $this->getMargin($orderProduct);
  75. }
  76. public function getTotalWithReduction(OrderProductInterface $orderProduct)
  77. {
  78. return $this->applyReductionCatalog(
  79. $orderProduct,
  80. $this->getTotal($orderProduct),
  81. $this->getTotalWithTax($orderProduct),
  82. $orderProduct->getQuantityOrder(),
  83. null,
  84. false
  85. );
  86. }
  87. public function getTotalWithTax(OrderProductInterface $orderProduct)
  88. {
  89. return $this->applyTax(
  90. $this->getTotal($orderProduct),
  91. $orderProduct->getTaxRateInherited()->getValue()
  92. );
  93. }
  94. public function getTotalWithTaxAndReduction(OrderProductInterface $orderProduct)
  95. {
  96. return $this->applyReductionCatalog(
  97. $orderProduct,
  98. $this->getTotal($orderProduct),
  99. $this->getTotalWithTax($orderProduct),
  100. $orderProduct->getQuantityOrder()
  101. );
  102. }
  103. public function getTotalBuyingPriceWithTax(OrderProductInterface $orderProduct)
  104. {
  105. return $this->applyTax(
  106. $this->getTotalBuyingPrice($orderProduct),
  107. $orderProduct->getTaxRateInherited()->getValue()
  108. );
  109. }
  110. //inclus toujours les réductions catalogues
  111. public function getTotalTaxes(OrderProductInterface $orderProduct){
  112. return $this->getTotalWithTaxAndReduction($orderProduct) - $this->getTotalWithReduction($orderProduct);
  113. }
  114. }