src/Entity/ContractSeason.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ContractSeasonRepository;
  4. use DateTimeInterface;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Validator\Constraints as Asserts;
  10. #[ORM\Entity(repositoryClassContractSeasonRepository::class)]
  11. class ContractSeason
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column(type'integer')]
  16.     private $id;
  17.     #[ORM\ManyToOne(targetEntityHotelContract::class, inversedBy'contractSeasons')]
  18.     #[ORM\JoinColumn(nullablefalse)]
  19.     #[Asserts\NotBlank]
  20.     private ?HotelContract $hotelContract;
  21.     #[Asserts\NotBlank]
  22.     #[ORM\Column(type'datetime'nullablefalse)]
  23.     private ?DateTimeInterface $startdate;
  24.     #[Asserts\NotBlank]
  25.     #[ORM\Column(type'datetime'nullablefalse)]
  26.     private ?DateTimeInterface $enddate;
  27.     #[ORM\Column(type'string'length32nullabletrue)]
  28.     private ?string $commCalculType// or margeCalculType depending on pricingType
  29.     #[ORM\Column(type'float'nullabletrue)]
  30.     #[Asserts\PositiveOrZero]
  31.     private ?float $commValue// or margeValue depending on pricingType
  32.     #[ORM\ManyToOne(targetEntityMarket::class)]
  33.     #[ORM\JoinColumn(nullablefalse)]
  34.     private ?Market $market;
  35.     #[ORM\OneToMany(mappedBy'season'targetEntityPricing::class, cascade: ['persist'])]
  36.     #[ORM\JoinColumn(name"season_id"referencedColumnName"season_id"onDelete"CASCADE")]
  37.     private $pricings;
  38.     #[ORM\Column(typeTypes::SMALLINT)]
  39.     private ?int $pricingType null;
  40.     #[ORM\ManyToOne]
  41.     private ?Arrangement $baseArrangement null;
  42.     #[ORM\Column(nullabletrue)]
  43.     private ?int $byPerson null;
  44.     #[ORM\Column(nullabletrue)]
  45.     private ?bool $NRF null;
  46.     #[ORM\Column(nullabletrue)]
  47.     private ?int $minimumStay null;
  48.     public function __construct()
  49.     {
  50.         $this->pricings = new ArrayCollection();
  51.     }
  52.     public function getId(): ?int
  53.     {
  54.         return $this->id;
  55.     }
  56.     public function getHotelContract(): ?HotelContract
  57.     {
  58.         return $this->hotelContract;
  59.     }
  60.     public function setHotelContract(?HotelContract $hotelContract): self
  61.     {
  62.         $this->hotelContract $hotelContract;
  63.         return $this;
  64.     }
  65.     public function getStartdate(): ?DateTimeInterface
  66.     {
  67.         return $this->startdate;
  68.     }
  69.     public function setStartdate(?DateTimeInterface $startdate): self
  70.     {
  71.         $this->startdate $startdate;
  72.         return $this;
  73.     }
  74.     public function getEnddate(): ?DateTimeInterface
  75.     {
  76.         return $this->enddate;
  77.     }
  78.     public function setEnddate(?DateTimeInterface $enddate): self
  79.     {
  80.         $this->enddate $enddate;
  81.         return $this;
  82.     }
  83.     public function getCommCalculType(): ?string
  84.     {
  85.         return $this->commCalculType;
  86.     }
  87.     public function setCommCalculType(?string $commCalculType): self
  88.     {
  89.         $this->commCalculType $commCalculType;
  90.         return $this;
  91.     }
  92.     public function getCommValue(): ?float
  93.     {
  94.         return $this->commValue;
  95.     }
  96.     public function setCommValue(?float $commValue): self
  97.     {
  98.         $this->commValue $commValue;
  99.         return $this;
  100.     }
  101.     public function getMarket(): ?Market
  102.     {
  103.         return $this->market;
  104.     }
  105.     public function setMarket(?Market $market): self
  106.     {
  107.         $this->market $market;
  108.         return $this;
  109.     }
  110.     /**
  111.      * @return Collection<int, Pricing>
  112.      */
  113.     public function getPricings(): Collection
  114.     {
  115.         return $this->pricings;
  116.     }
  117.     public function addPricing(Pricing $pricing): self
  118.     {
  119.         if (!$this->pricings->contains($pricing)) {
  120.             $this->pricings[] = $pricing;
  121.             $pricing->setSeason($this);
  122.         }
  123.         return $this;
  124.     }
  125.     public function removePricing(Pricing $pricing): self
  126.     {
  127.         if ($this->pricings->removeElement($pricing)) {
  128.             // set the owning side to null (unless already changed)
  129.             if ($pricing->getSeason() === $this) {
  130.                 $pricing->setSeason(null);
  131.             }
  132.         }
  133.         return $this;
  134.     }
  135.     public function __clone(): void
  136.     {
  137.         if ($this->id) {
  138.             $this->id null;
  139.             $saved_cloned_operations = [];
  140.             // cloning the relation pricings which is a OneToMany
  141.             $pricingsClonedCollection = new ArrayCollection();
  142.             foreach ($this->getPricings() as $pricing) {
  143.                 $pricingClone = clone $pricing;
  144.                 $pricingClone->setSeason(null);
  145.                 foreach ($pricing->getOperations() as $operation){
  146.                     if ( array_key_exists($operation->getId(), $saved_cloned_operations)){
  147.                         $operationClone $saved_cloned_operations[$operation->getId()];
  148.                     }else
  149.                     {
  150.                         $operationClone $operation->getCopy();
  151.                         $saved_cloned_operations[$operation->getId()] = $operationClone;
  152.                     }
  153.                     $operationClone->addPricing($pricingClone);
  154.                     $pricingClone->addOperation($operationClone);
  155.                     //dd($pricingClone);
  156.                 }
  157.                 $pricingClone->setSeason($this);
  158.                 $pricingsClonedCollection->add($pricingClone);
  159.             }
  160.             $this->pricings $pricingsClonedCollection;
  161.         }
  162.     }
  163.     public function __toString(): string
  164.     {
  165.         return 'Season '.$this->startdate->format('d/m/Y')." - ".$this->enddate->format('d/m/Y');
  166.     }
  167.     #[Asserts\IsTrue(message:'already exist')]
  168.     function isExist(): bool
  169.     {
  170.         // TODO CHECK THIS FUCNTION isExist
  171.         return   $this->getStartdate() && $this->getEnddate() && $this->getMarket();
  172.     }
  173.     public function getHotelRoomTypes() : array{
  174.         $hrt_array = [];
  175.         foreach ($this->pricings as $pricing){
  176.             $hrt $pricing->getHotelRoomTypeArrangement()->getHotelRoomType();
  177.             if(!in_array($hrt$hrt_array))
  178.                 $hrt_array[] = $hrt;
  179.         }
  180.         return $hrt_array;
  181.     }
  182.     public function getArrangements() : ?array{
  183.         $arrangements = [];
  184.         foreach ($this->pricings as $pricing){
  185.             $arrangement $pricing->getHotelRoomTypeArrangement()->getArrangement();
  186.             if(!in_array($arrangement$arrangements))
  187.                 $arrangements[] = $arrangement;
  188.         }
  189.         return $arrangements;
  190.     }
  191.     public function getPricingType(): ?int
  192.     {
  193.         return $this->pricingType;
  194.     }
  195.     public function setPricingType(int $pricingType): self
  196.     {
  197.         $this->pricingType $pricingType;
  198.         return $this;
  199.     }
  200.     public function getBaseArrangement(): ?Arrangement
  201.     {
  202.         return $this->baseArrangement;
  203.     }
  204.     public function setBaseArrangement(?Arrangement $baseArrangement): self
  205.     {
  206.         $this->baseArrangement $baseArrangement;
  207.         return $this;
  208.     }
  209.     public function overlap(ContractSeason $old_season): bool
  210.     {
  211.         // overlap means (StartA <= EndB) and (EndA >= StartB)
  212.         return
  213.             $this->startdate <= $old_season->enddate and
  214.             $this->enddate >= $old_season->startdate ;
  215.     }
  216.     public function isByPerson(): ?int
  217.     {
  218.         return $this->byPerson;
  219.     }
  220.     public function setByPerson(?int $byPerson): self
  221.     {
  222.         $this->byPerson $byPerson;
  223.         return $this;
  224.     }
  225.     public function isNRF(): ?bool
  226.     {
  227.         return $this->NRF;
  228.     }
  229.     public function setNRF(?bool $NRF): self
  230.     {
  231.         $this->NRF $NRF;
  232.         return $this;
  233.     }
  234.     public function getMinimumStay(): ?int
  235.     {
  236.         return $this->minimumStay;
  237.     }
  238.     public function setMinimumStay(?int $minimumStay): self
  239.     {
  240.         $this->minimumStay $minimumStay;
  241.         return $this;
  242.     }
  243. }