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.

86 lines
3.0KB

  1. <?php
  2. namespace Lc\ShopBundle\Price\Services;
  3. use Lc\ShopBundle\Context\OrderShopInterface;
  4. use Lc\ShopBundle\Context\OrderShopPriceUtilsInterface;
  5. class OrderShopPriceUtils implements OrderShopPriceUtilsInterface
  6. {
  7. use PriceUtilsTrait ;
  8. protected $orderProductPriceUtils ;
  9. public function __construct(OrderProductPriceUtils $orderProductPriceUtils)
  10. {
  11. $this->orderProductPriceUtils = $orderProductPriceUtils ;
  12. }
  13. //Inclus les ReductionCatalog des OrderProducts
  14. public function getTotalOrderProducts(OrderShopInterface $orderShop):float
  15. {
  16. // A tester calculer ce montant en faisant TotalOrderWithTax - TotalOrderTaxes
  17. $total = 0;
  18. foreach ($orderShop->getOrderProducts() as $orderProduct) {
  19. $total += $this->orderProductPriceUtils->getTotalWithReduction($orderProduct);
  20. }
  21. return $total;
  22. }
  23. public function getTotalOrderProductsWithTax(OrderShopInterface $orderShop):float
  24. {
  25. $total = 0;
  26. foreach ($orderShop->getOrderProducts() as $orderProduct) {
  27. $total += $this->orderProductPriceUtils->getTotalWithTaxAndReduction($orderProduct);
  28. }
  29. return $total;
  30. }
  31. public function getTotalOrderProductsTaxes(OrderShopInterface $orderShop):float {
  32. }
  33. public function getOrderProductsTaxesAsArray(OrderShopInterface $orderShop):array
  34. {
  35. $orderProductsTaxes = [];
  36. foreach ($orderShop->getOrderProducts() as $orderProduct) {
  37. $idTaxRate = $orderProduct->getTaxRate()->getId() ;
  38. if(!isset($orderProductsTaxes[$idTaxRate])) {
  39. $orderProductsTaxes[$idTaxRate] = [
  40. 'label' => $orderProduct->getTaxRate()->getValue() . '%',
  41. 'totalOrderProducts' => 0,
  42. 'totalTaxes' => 0,
  43. ];
  44. }
  45. $orderProductsTaxes[$idTaxRate]['totalOrderProducts'] += $this->orderProductPriceUtils->getTotalWithReduction($orderProduct) * $this->getReductionsCoef($orderShop);
  46. $orderProductsTaxes[$idTaxRate]['totalTaxes'] += $this->orderProductPriceUtils->getTotalTaxes($orderProduct) * $this->getReductionsCoef($orderShop) ;
  47. }
  48. return $orderProductsTaxes ;
  49. }
  50. private function getReductionsCoef(OrderShopInterface $orderShop) :float
  51. {
  52. return $this->getTotalOrderProducts($orderShop) / $this->getTotalOrderProductsWithReductions($orderShop);
  53. }
  54. public function getTotalOrderProductsWithReductions(OrderShopInterface $orderShop)
  55. {
  56. }
  57. public function getTotalWithTaxAndReductions(OrderShopInterface $orderShop)
  58. {
  59. }
  60. }