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.

преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 ProductPriceUtils
  11. {
  12. use PriceUtilsTrait ;
  13. public function getPrice(ProductPropertyInterface $product)
  14. {
  15. if ($product->getBehaviorPriceInherited() == 'by-piece') {
  16. return $product->getPriceInherited();
  17. }
  18. elseif ($product->getBehaviorPriceInherited() == 'by-reference-unit') {
  19. if ($product->getQuantityInherited() > 0) {
  20. return $product->getPriceByRefUnitInherited() * ($product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient());
  21. }else{
  22. return 0;
  23. }
  24. }
  25. }
  26. public function getPriceWithTax(ProductPropertyInterface $product)
  27. {
  28. return $this->applyTax(
  29. $this->getPrice($product),
  30. $product->getTaxRateInherited()->getValue()
  31. );
  32. }
  33. public function getPriceByRefUnit(ProductPropertyInterface $product)
  34. {
  35. if ($product->getBehaviorPriceInherited() == 'by-piece') {
  36. return ($this->getPrice($product) * $product->getUnitInherited()->getCoefficient()) / $product->getQuantityInherited();
  37. } elseif ($product->getBehaviorPriceInherited() == 'by-reference-unit') {
  38. return $product->getPriceByRefUnitInherited();
  39. }
  40. }
  41. public function getPriceByRefUnitWithTax(ProductPropertyInterface $product)
  42. {
  43. return $this->applyTax(
  44. $this->getPriceByRefUnit($product),
  45. $product->getTaxRateInherited()->getValue()
  46. );
  47. }
  48. public function getPriceWithTaxAndReduction(ProductPropertyInterface $product)
  49. {
  50. return $this->applyReductionCatalog(
  51. $product,
  52. $this->getPrice($product),
  53. $this->getPriceWithTax($product)
  54. );
  55. }
  56. public function getPriceByRefUnitWithTaxAndReduction(ProductPropertyInterface $product)
  57. {
  58. return $this->applyReductionCatalog(
  59. $product,
  60. $this->getPriceByRefUnit($product),
  61. $this->getPriceByRefUnitWithTax($product)
  62. );
  63. }
  64. public function getBuyingPrice(ProductPropertyInterface $product)
  65. {
  66. if ($product->getBehaviorPriceInherited() == 'by-piece') {
  67. return $product->getBuyingPriceInherited();
  68. }
  69. elseif ($product->getBehaviorPriceInherited() == 'by-reference-unit') {
  70. if ($product->getQuantityInherited() > 0) {
  71. return $product->getBuyingPriceByRefUnitInherited() * ($product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient());
  72. }else{
  73. return 0;
  74. }
  75. }
  76. }
  77. public function getMultiplyingFactor(ProductPropertyInterface $product){
  78. return $this->round($this->getPriceWithTax($product) / $this->getBuyingPrice($product));
  79. }
  80. }