您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

OrderProductPriceUtils.php 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. }