src/Entity/Gestiform/Admin/Tarifs/TarifVenteTheme.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gestiform\Admin\Tarifs;
  3. use App\Repository\Gestiform\Admin\Tarifs\TarifVenteThemeRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=TarifVenteThemeRepository::class)
  9.  */
  10. class TarifVenteTheme extends TarifVente
  11. {
  12.     /**
  13.      * @ORM\Column(type="boolean",nullable=true)
  14.      */
  15.     private ?bool $tarifJour null;
  16.     /**
  17.      * @ORM\OneToMany(targetEntity=TarifVenteThemeLg::class, mappedBy="tarifVenteTheme", cascade={"persist", "remove"}, orphanRemoval=TRUE)
  18.      */
  19.     private Collection $lignes;
  20.     public function __construct()
  21.     {
  22.         $this->lignes = new ArrayCollection();
  23.     }
  24.     public function isTarifJour(): ?bool
  25.     {
  26.         return $this->tarifJour;
  27.     }
  28.     public function setTarifJour(?bool $tarifJour): self
  29.     {
  30.         $this->tarifJour $tarifJour;
  31.         return $this;
  32.     }
  33.     /**
  34.      * @return Collection<int, TarifVenteThemeLg>
  35.      */
  36.     public function getLignes(): Collection
  37.     {
  38.         return $this->lignes;
  39.     }
  40.     public function addLigne(TarifVenteThemeLg $ligne): self
  41.     {
  42.         if (!$this->lignes->contains($ligne)) {
  43.             $this->lignes->add($ligne);
  44.             $ligne->setTarifVenteTheme($this);
  45.         }
  46.         return $this;
  47.     }
  48.     public function removeLigne(TarifVenteThemeLg $ligne): self
  49.     {
  50.         if ($this->lignes->removeElement($ligne)) {
  51.             // set the owning side to null (unless already changed)
  52.             if ($ligne->getTarifVenteTheme() === $this) {
  53.                 $ligne->setTarifVenteTheme(null);
  54.             }
  55.         }
  56.         return $this;
  57.     }
  58.     public function getTarifForValue($combien)
  59.     {
  60.         $lignemax=$this->getLignemax($this->isTarifjour());
  61.         if($this->isTarifjour())
  62.         {
  63.             $lignemax=$this->getLignemax(true);
  64.             foreach($this->getLignes() as $ligne)
  65.             {
  66.                 if($ligne->isTarifjour() && $ligne->getValeurmin()===$combien){
  67.                     return $ligne;
  68.                 }
  69.             }
  70.         }else{
  71.             $lignemax=$this->getLignemax(false);
  72.             foreach($this->getLignes() as $ligne)
  73.             {
  74.                 if(!$ligne->isTarifjour() && $ligne->getValeurmin()<=$combien && $ligne->getValeurmax()>=$combien){
  75.                     return $ligne;
  76.                 }
  77.             }
  78.         }
  79.         return $lignemax;
  80.         $lignemax=$this->getLignemax($this->isTarifjour());
  81.         return $lignemax;
  82.     }
  83.     public function getMontantForValue($combien)
  84.     {
  85.         $montant=0;
  86.         $nb=1;
  87.         if($this->isTarifjour())
  88.         {
  89.             foreach($this->getLignes() as $ligne)
  90.             {
  91.                 if($ligne->isTarifjour() && $nb <= $combien && $ligne->getValeurmin() === $nb) {
  92.                     $montant+=$ligne->getTarif();
  93.                     $nb++;
  94.                 }
  95.             }
  96.             return $montant;
  97.         }
  98.         $lignemax=$this->getLignemax(false);
  99.         foreach($this->getLignes() as $ligne)
  100.         {
  101.             if(!$ligne->isTarifjour() && $ligne->getValeurmin()<=
  102.                 $combien && $ligne->getValeurmax()>=$combien){
  103.                 return $ligne;
  104.             }
  105.         }
  106.         return $lignemax;
  107.         $lignemax=$this->getLignemax($this->isTarifjour());
  108.         return $lignemax;
  109.     }
  110.     public function getLignemax($tarifjour)
  111.     {
  112.         $lignemax=null;
  113.         $valeurmax=0;
  114.         foreach($this->getLignes() as $ligne)
  115.         {
  116.             if(($ligne->isTarifjour() === $tarifjour) && $ligne->getValeurmin() >= $valeurmax) {
  117.                 $valeurmax=$ligne->getValeurmin();
  118.                 $lignemax=$ligne;
  119.             }
  120.         }
  121.         return $lignemax;
  122.     }
  123. }