No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

OrderShopPriceUtils.php 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace Lc\ShopBundle\Price\Services;
  3. use Lc\ShopBundle\Context\OrderReductionCreditInterface;
  4. use Lc\ShopBundle\Context\OrderShopInterface;
  5. use Lc\ShopBundle\Context\OrderShopPriceUtilsInterface;
  6. use Lc\ShopBundle\Model\ReductionCart;
  7. class OrderShopPriceUtils implements OrderShopPriceUtilsInterface
  8. {
  9. use PriceUtilsTrait ;
  10. protected $orderProductPriceUtils ;
  11. public function __construct(OrderProductPriceUtils $orderProductPriceUtils)
  12. {
  13. $this->orderProductPriceUtils = $orderProductPriceUtils ;
  14. }
  15. //Inclus les ReductionCatalog des OrderProducts
  16. public function getTotalOrderProducts(OrderShopInterface $orderShop):float
  17. {
  18. // A tester calculer ce montant en faisant TotalOrderWithTax - TotalOrderTaxes
  19. $total = 0;
  20. foreach ($orderShop->getOrderProducts() as $orderProduct) {
  21. $total += $this->orderProductPriceUtils->getTotalWithReduction($orderProduct);
  22. }
  23. return $total;
  24. }
  25. public function getTotalOrderProductsWithTax(OrderShopInterface $orderShop):float
  26. {
  27. $total = 0;
  28. foreach ($orderShop->getOrderProducts() as $orderProduct) {
  29. $total += $this->orderProductPriceUtils->getTotalWithTaxAndReduction($orderProduct);
  30. }
  31. return $total;
  32. }
  33. public function getTotalOrderProductsTaxes(OrderShopInterface $orderShop):float {
  34. }
  35. public function getOrderProductsTaxesAsArray(OrderShopInterface $orderShop):array
  36. {
  37. $orderProductsTaxes = [];
  38. foreach ($orderShop->getOrderProducts() as $orderProduct) {
  39. $idTaxRate = $orderProduct->getTaxRate()->getId() ;
  40. if(!isset($orderProductsTaxes[$idTaxRate])) {
  41. $orderProductsTaxes[$idTaxRate] = [
  42. 'label' => $orderProduct->getTaxRate()->getValue() . '%',
  43. 'totalOrderProducts' => 0,
  44. 'totalTaxes' => 0,
  45. ];
  46. }
  47. $orderProductsTaxes[$idTaxRate]['totalOrderProducts'] += $this->orderProductPriceUtils->getTotalWithReduction($orderProduct) * $this->getReductionsCoef($orderShop);
  48. $orderProductsTaxes[$idTaxRate]['totalTaxes'] += $this->orderProductPriceUtils->getTotalTaxes($orderProduct) * $this->getReductionsCoef($orderShop) ;
  49. }
  50. return $orderProductsTaxes ;
  51. }
  52. private function getReductionsCoef(OrderShopInterface $orderShop) :float
  53. {
  54. return $this->getTotalOrderProducts($orderShop) / $this->getTotalOrderProductsWithReductions($orderShop);
  55. }
  56. private function getTaxRateAverage(OrderShopInterface $order):float
  57. {
  58. return $this->getTotalOrderProductsWithTax() / $this->getTotalOrderProducts();
  59. }
  60. public function getTotalOrderProductsWithReductions(OrderShopInterface $orderShop)
  61. {
  62. $total = $this->getTotalOrderProducts($orderShop) ;
  63. $totalReductionAmount = 0 ;
  64. foreach ($orderShop->getOrderReductionCarts() as $orderReductionCart) {
  65. $totalReductionAmount += $this->amountOrderProductsReductionCart($orderShop,$orderReductionCart);
  66. }
  67. $total -= $totalReductionAmount ;
  68. return $total ;
  69. }
  70. public function getTotalWithTaxAndReductions(OrderShopInterface $orderShop)
  71. {
  72. }
  73. public function getOrderProductsReductionCartAmountWithoutTax(OrderShopInterface $order, $orderReductionCart)
  74. {
  75. if($orderReductionCart->getAppliedTo() === ReductionCart::APPLIED_TO_ORDER_PRODUCTS) {
  76. if ($orderReductionCart->getUnit() == 'percent') {
  77. $price = $this->amountReductionByPercentValue(
  78. $this->getTotalOrderProducts($order),
  79. $orderReductionCart->getValue()
  80. );
  81. } else if ($orderReductionCart->getUnit() == 'amount') {
  82. if ($orderReductionCart->getBehaviorTaxRate() == 'tax-excluded') {
  83. $price = $orderReductionCart->getValue();
  84. } else if ($orderReductionCart->getBehaviorTaxRate() == 'tax-included') {
  85. $price = $orderReductionCart->getValue() / $this->getTaxRateAverage();
  86. }
  87. }
  88. }
  89. }
  90. public function getOrderProductsReductionCartAmountWithTax(OrderShopInterface $order, $orderReductionCart)
  91. {
  92. if($orderReductionCart->getAppliedTo() === ReductionCart::APPLIED_TO_ORDER_PRODUCTS) {
  93. if ($orderReductionCart->getUnit() == 'percent') {
  94. $price = $this->amountReductionByPercentValue(
  95. $this->getTotalOrderProductsWithTax($order),
  96. $orderReductionCart->getValue()
  97. );
  98. } else if ($orderReductionCart->getUnit() == 'amount') {
  99. if ($orderReductionCart->getBehaviorTaxRate() == 'tax-excluded') {
  100. $price = $orderReductionCart->getValue() * $this->getTaxRateAverage();
  101. } else if ($orderReductionCart->getBehaviorTaxRate() == 'tax-included') {
  102. $price = $orderReductionCart->getValue() ;
  103. }
  104. }
  105. }
  106. }
  107. public function getOrderProductsReductionCreditAmountWithoutTax(OrderShopInterface $order, OrderReductionCreditInterface $orderReductionCredit)
  108. {
  109. if ($orderReductionCredit->getBehaviorTaxRate() == 'tax-excluded') {
  110. $amount = $orderReductionCredit->getValue();
  111. } else if ($orderReductionCredit->getBehaviorTaxRate() == 'tax-included') {
  112. $amount = $orderReductionCredit->getValue() / $this->getTaxRateAverage();
  113. }
  114. return $amount;
  115. }
  116. public function getOrderProductsReductionCreditAmountWithTax(OrderShopInterface $order, OrderReductionCreditInterface $orderReductionCredit)
  117. {
  118. if ($orderReductionCredit->getBehaviorTaxRate() == 'tax-excluded') {
  119. $amountWithTax = $orderReductionCredit->getValue() * $this->getTaxRateAverage();
  120. } else if ($orderReductionCredit->getBehaviorTaxRate() == 'tax-included') {
  121. $amountWithTax = $orderReductionCredit->getValue();
  122. }
  123. return $amountWithTax;
  124. }
  125. }