src/Entity/Gauge/GaugeUnitPrice.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gauge;
  3. use App\Entity\Extension\HistoricalInterface;
  4. use App\Entity\Extension\HistoricalTrait;
  5. use App\Utils\Segment;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Repository\Gauge\GaugeUnitPriceRepository;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10. * @ORM\Entity(repositoryClass=GaugeUnitPriceRepository::class)
  11. * @ORM\Table(name="gauge_unit_price")
  12. */
  13. class GaugeUnitPrice implements HistoricalInterface
  14. {
  15. public const MEDIUM_SIMPLE = 1; // jednotková smluvní cena média
  16. public const MEDIUM_HIGH_TARIFF = 2; // jednotková smluvní cena média - VT
  17. public const MEDIUM_LOW_TARIFF = 3; // jednotková smluvní cena média - NT
  18. public const MEDIUM_WATER = 4; // jednotková smluvní cena - vodné
  19. public const MEDIUM_SEWER = 5; // jednotková smluvní cena - stočné
  20. /**
  21. * @var string[]
  22. */
  23. public static array $fieldNamesByMedium = [
  24. self::MEDIUM_SIMPLE => 'unitPriceMedium',
  25. self::MEDIUM_HIGH_TARIFF => 'unitPriceHighTariff',
  26. self::MEDIUM_LOW_TARIFF => 'unitPriceLowTariff',
  27. self::MEDIUM_WATER => 'unitPriceWater',
  28. self::MEDIUM_SEWER => 'unitPriceSewer',
  29. ];
  30. use HistoricalTrait;
  31. /**
  32. * @ORM\Id()
  33. * @ORM\GeneratedValue()
  34. * @ORM\Column(type="integer")
  35. */
  36. private int $id;
  37. /**
  38. * @var Gauge $gauge
  39. * @ORM\ManyToOne(targetEntity="App\Entity\Gauge\Gauge", inversedBy="unitPrice")
  40. * @ORM\JoinColumn(name="gauge_id", referencedColumnName="id", nullable=false)
  41. */
  42. private Gauge $gauge;
  43. /**
  44. * values defined above
  45. * @var int
  46. * @ORM\Column(type="smallint")
  47. */
  48. private int $medium;
  49. /**
  50. * @ORM\Column(type="float")
  51. */
  52. private float $price;
  53. /**
  54. * @return int
  55. */
  56. public function getId(): int
  57. {
  58. return $this->id;
  59. }
  60. /**
  61. * @param int $id
  62. * @return GaugeUnitPrice
  63. */
  64. public function setId(int $id): GaugeUnitPrice
  65. {
  66. $this->id = $id;
  67. return $this;
  68. }
  69. /**
  70. * @return Gauge
  71. */
  72. public function getGauge(): Gauge
  73. {
  74. return $this->gauge;
  75. }
  76. /**
  77. * @param Gauge $gauge
  78. * @return GaugeUnitPrice
  79. */
  80. public function setGauge(Gauge $gauge): GaugeUnitPrice
  81. {
  82. $this->gauge = $gauge;
  83. return $this;
  84. }
  85. /**
  86. * @return int
  87. */
  88. public function getMedium(): int
  89. {
  90. return $this->medium;
  91. }
  92. /**
  93. * @param int $medium
  94. * @return GaugeUnitPrice
  95. */
  96. public function setMedium(int $medium): GaugeUnitPrice
  97. {
  98. $this->medium = $medium;
  99. return $this;
  100. }
  101. /**
  102. * @return float
  103. */
  104. public function getPrice(): float
  105. {
  106. return $this->price;
  107. }
  108. /**
  109. * @param float $price
  110. * @return GaugeUnitPrice
  111. */
  112. public function setPrice(float $price): GaugeUnitPrice
  113. {
  114. $this->price = $price;
  115. return $this;
  116. }
  117. /**
  118. * @param int $segment
  119. * @return int
  120. */
  121. public static function getMediumBySegment(int $segment): int
  122. {
  123. $mediumBySegment = [
  124. Segment::SEGMENT_BASIC_CONSUMPTION => self::MEDIUM_SIMPLE,
  125. Segment::SEGMENT_HIGH_TARIFF => self::MEDIUM_HIGH_TARIFF,
  126. Segment::SEGMENT_LOW_TARIFF => self::MEDIUM_LOW_TARIFF,
  127. ];
  128. if (!array_key_exists($segment, $mediumBySegment)) {
  129. return self::MEDIUM_SIMPLE; // default
  130. }
  131. return $mediumBySegment[$segment];
  132. }
  133. }