<?php
namespace App\Entity\Gestiform\Admin\Tarifs;
use App\Repository\Gestiform\Admin\Tarifs\TarifVenteThemeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=TarifVenteThemeRepository::class)
*/
class TarifVenteTheme extends TarifVente
{
/**
* @ORM\Column(type="boolean",nullable=true)
*/
private ?bool $tarifJour = null;
/**
* @ORM\OneToMany(targetEntity=TarifVenteThemeLg::class, mappedBy="tarifVenteTheme", cascade={"persist", "remove"}, orphanRemoval=TRUE)
*/
private Collection $lignes;
public function __construct()
{
$this->lignes = new ArrayCollection();
}
public function isTarifJour(): ?bool
{
return $this->tarifJour;
}
public function setTarifJour(?bool $tarifJour): self
{
$this->tarifJour = $tarifJour;
return $this;
}
/**
* @return Collection<int, TarifVenteThemeLg>
*/
public function getLignes(): Collection
{
return $this->lignes;
}
public function addLigne(TarifVenteThemeLg $ligne): self
{
if (!$this->lignes->contains($ligne)) {
$this->lignes->add($ligne);
$ligne->setTarifVenteTheme($this);
}
return $this;
}
public function removeLigne(TarifVenteThemeLg $ligne): self
{
if ($this->lignes->removeElement($ligne)) {
// set the owning side to null (unless already changed)
if ($ligne->getTarifVenteTheme() === $this) {
$ligne->setTarifVenteTheme(null);
}
}
return $this;
}
public function getTarifForValue($combien)
{
$lignemax=$this->getLignemax($this->isTarifjour());
if($this->isTarifjour())
{
$lignemax=$this->getLignemax(true);
foreach($this->getLignes() as $ligne)
{
if($ligne->isTarifjour() && $ligne->getValeurmin()===$combien){
return $ligne;
}
}
}else{
$lignemax=$this->getLignemax(false);
foreach($this->getLignes() as $ligne)
{
if(!$ligne->isTarifjour() && $ligne->getValeurmin()<=$combien && $ligne->getValeurmax()>=$combien){
return $ligne;
}
}
}
return $lignemax;
$lignemax=$this->getLignemax($this->isTarifjour());
return $lignemax;
}
public function getMontantForValue($combien)
{
$montant=0;
$nb=1;
if($this->isTarifjour())
{
foreach($this->getLignes() as $ligne)
{
if($ligne->isTarifjour() && $nb <= $combien && $ligne->getValeurmin() === $nb) {
$montant+=$ligne->getTarif();
$nb++;
}
}
return $montant;
}
$lignemax=$this->getLignemax(false);
foreach($this->getLignes() as $ligne)
{
if(!$ligne->isTarifjour() && $ligne->getValeurmin()<=
$combien && $ligne->getValeurmax()>=$combien){
return $ligne;
}
}
return $lignemax;
$lignemax=$this->getLignemax($this->isTarifjour());
return $lignemax;
}
public function getLignemax($tarifjour)
{
$lignemax=null;
$valeurmax=0;
foreach($this->getLignes() as $ligne)
{
if(($ligne->isTarifjour() === $tarifjour) && $ligne->getValeurmin() >= $valeurmax) {
$valeurmax=$ligne->getValeurmin();
$lignemax=$ligne;
}
}
return $lignemax;
}
}