<?phpnamespace App\Entity;use App\Repository\MarkupStrategyExchangeRateRepository;use Doctrine\ORM\Mapping as ORM;use Gedmo\Timestampable\Traits\TimestampableEntity;use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;use Symfony\Component\Validator\Constraints as Assert;/** * Sale rate of a currency pair for the customers priced by a markup strategy : replaces the default sale rate * (CurrencyExchangerate) of the pair in their flight pricing. Only the sale rate : the buy rate is the agency's cost. */#[ORM\Entity(repositoryClass: MarkupStrategyExchangeRateRepository::class)]#[ORM\UniqueConstraint(columns: ['markupStrategy_id', 'currencyFrom', 'currencyTo'])]#[UniqueEntity(fields: ['markupStrategy', 'currencyFrom', 'currencyTo'])]class MarkupStrategyExchangeRate{ use TimestampableEntity; #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] private ?int $id = null; #[ORM\ManyToOne(inversedBy: 'exchangeRates')] #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')] private ?MarkupStrategy $markupStrategy = null; #[ORM\Column(length: 64)] private ?string $currencyFrom = null; #[ORM\Column(length: 64)] private ?string $currencyTo = null; // nullable in PHP only : an emptied form field must reach the form's NotBlank instead of a TypeError #[ORM\Column(type: 'decimal', precision: 10, scale: CurrencyExchangerate::RATE_SCALE)] #[Assert\Positive] private ?float $exchangeRateSale = null; public function getId(): ?int { return $this->id; } public function getMarkupStrategy(): ?MarkupStrategy { return $this->markupStrategy; } public function setMarkupStrategy(?MarkupStrategy $markupStrategy): self { $this->markupStrategy = $markupStrategy; return $this; } public function getCurrencyFrom(): ?string { return $this->currencyFrom; } public function setCurrencyFrom(?string $currencyFrom): self { $this->currencyFrom = $currencyFrom; return $this; } public function getCurrencyTo(): ?string { return $this->currencyTo; } public function setCurrencyTo(?string $currencyTo): self { $this->currencyTo = $currencyTo; return $this; } public function getExchangeRateSale(): ?float { return $this->exchangeRateSale; } public function setExchangeRateSale(?float $exchangeRateSale): self { $this->exchangeRateSale = $exchangeRateSale; return $this; } /** * "Auto reverse" : sets this pair (TO_FROM) to the inverse of $rate (FROM_TO), keeping a current value that already * gives $rate back at the stored precision (see CurrencyExchangerate::setReverseRatesOf) */ public function setReverseRateOf(MarkupStrategyExchangeRate $rate): void { $this->exchangeRateSale = CurrencyExchangerate::reciprocal($rate->getExchangeRateSale(), $this->exchangeRateSale); } #[Assert\IsTrue(message: 'The specified currencies should be different')] public function hasDifferentCurrencies(): bool { return $this->currencyTo != $this->currencyFrom; } public function __toString(): string { return $this->currencyFrom.' => '.$this->currencyTo; }}