Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

96 lines
3.5KB

  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. }