選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

OrderProductPriceUtils.php 4.2KB

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