You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OrderProductPriceUtils.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. null,
  48. false
  49. );
  50. }
  51. public function getTotal(OrderProductInterface $orderProduct)
  52. {
  53. return $orderProduct->getQuantityOrder() * $this->getPrice($orderProduct);
  54. }
  55. public function getMargin(OrderProductInterface $orderProduct)
  56. {
  57. return $this->getPriceWithReduction($orderProduct) - $this->getBuyingPrice($orderProduct);
  58. }
  59. public function getMarginPercent(OrderProductInterface $orderProduct)
  60. {
  61. if($this->getBuyingPrice($orderProduct)) {
  62. return ($this->getMargin($orderProduct) / $this->getBuyingPrice($orderProduct)) * 100;
  63. }else{
  64. return 0;
  65. }
  66. }
  67. public function getTotalMargin(OrderProductInterface $orderProduct)
  68. {
  69. return $orderProduct->getQuantityOrder() * $this->getMargin($orderProduct);
  70. }
  71. public function getTotalWithReduction(OrderProductInterface $orderProduct)
  72. {
  73. return $this->applyReductionCatalog(
  74. $orderProduct,
  75. $this->getTotal($orderProduct),
  76. $this->getTotalWithTax($orderProduct),
  77. null,
  78. false
  79. );
  80. }
  81. public function getTotalWithTax(OrderProductInterface $orderProduct)
  82. {
  83. return $this->applyTax(
  84. $this->getTotal($orderProduct),
  85. $orderProduct->getTaxRateInherited()->getValue()
  86. );
  87. }
  88. public function getTotalWithTaxAndReduction(OrderProductInterface $orderProduct)
  89. {
  90. return $this->applyReductionCatalog(
  91. $orderProduct,
  92. $this->getTotal($orderProduct),
  93. $this->getTotalWithTax($orderProduct)
  94. );
  95. }
  96. //inclus toujours les réductions catalogues
  97. public function getTotalTaxes(OrderProductInterface $orderProduct){
  98. return $this->getTotalWithTaxAndReduction($orderProduct) - $this->getTotalWithReduction($orderProduct);
  99. }
  100. }