src/Entity/Contrat.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Repository\ContratRepository;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. /**
  8.  * @ORM\Entity(repositoryClass=ContratRepository::class)
  9.  */
  10. class Contrat
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="integer", nullable=true)
  20.      */
  21.     private $duree;
  22.     /**
  23.      * @ORM\Column(type="float", nullable=true)
  24.      */
  25.     private $valeur;
  26.     /**
  27.      * @ORM\ManyToOne(targetEntity=User::class)
  28.      * @ORM\JoinColumn(nullable=true)
  29.      */
  30.     private $collaborateur;
  31.     /**
  32.      * @ORM\ManyToOne(targetEntity=Entreprise::class, inversedBy="contrats")
  33.      * @ORM\JoinColumn(nullable=true)
  34.      */
  35.     private $entreprise;
  36.     /**
  37.      * @ORM\Column(type="string", length=255, nullable=true)
  38.      */
  39.     private $pdl;
  40.     /**
  41.      * @ORM\Column(type="float", nullable=true, options={"default" : 0})
  42.      */
  43.     private $car 0;
  44.     /**
  45.      * @ORM\Column(type="float", nullable=true, options={"default" : 0})
  46.      */
  47.     private $prix_moyen 0;
  48.     /**
  49.      * @ORM\Column(type="string", length=255, nullable=true)
  50.      */
  51.     private $fournisseur;
  52.     /**
  53.      * @ORM\Column(type="datetime", nullable=true)
  54.      */
  55.     private $date_debut;
  56.     /**
  57.      * @ORM\Column(type="datetime", nullable=true)
  58.      */
  59.     private $date_fin;
  60.     /**
  61.      * @ORM\Column(type="datetime", nullable=true)
  62.      */
  63.     private $date_signature;
  64.     /**
  65.      * @ORM\OneToMany(targetEntity=Facture::class, mappedBy="contrat", orphanRemoval=false, cascade={"persist"})
  66.      */
  67.     private $factures;
  68.     public function __construct()
  69.     {
  70.         $this->factures = new ArrayCollection();
  71.     }
  72.     /** @return Collection|Facture[] */
  73.     public function getFactures(): Collection
  74.     {
  75.         return $this->factures;
  76.     }
  77.     public function addFacture(Facture $facture): self
  78.     {
  79.         if (!$this->factures->contains($facture)) {
  80.             $this->factures[] = $facture;
  81.             $facture->setContrat($this);
  82.         }
  83.         return $this;
  84.     }
  85.     public function removeFacture(Facture $facture): self
  86.     {
  87.         if ($this->factures->removeElement($facture)) {
  88.             if ($facture->getContrat() === $this) {
  89.                 $facture->setContrat(null);
  90.             }
  91.         }
  92.         return $this;
  93.     }
  94.     public function getId(): ?int
  95.     {
  96.         return $this->id;
  97.     }
  98.     public function getDuree(): ?int
  99.     {
  100.         if ($this->date_debut && $this->date_fin) {
  101.             $interval $this->date_debut->diff($this->date_fin);
  102.             return $interval->12 $interval->m;
  103.         }
  104.         return $this->duree;
  105.     }
  106.     public function setDuree(?int $duree): self
  107.     {
  108.         $this->duree $duree;
  109.         return $this;
  110.     }
  111.     public function getValeur(): ?float
  112.     {
  113.         // Note: Actual calculation is now handled by PricingService
  114.         return $this->valeur;
  115.     }
  116.     public function setValeur(?float $valeur): self
  117.     {
  118.         $this->valeur $valeur;
  119.         return $this;
  120.     }
  121.     public function getCollaborateur(): ?User
  122.     {
  123.         return $this->collaborateur;
  124.     }
  125.     public function setCollaborateur(?User $collaborateur): self
  126.     {
  127.         $this->collaborateur $collaborateur;
  128.         return $this;
  129.     }
  130.     public function getEntreprise(): ?Entreprise
  131.     {
  132.         return $this->entreprise;
  133.     }
  134.     public function setEntreprise(?Entreprise $entreprise): self
  135.     {
  136.         $this->entreprise $entreprise;
  137.         return $this;
  138.     }
  139.     public function getPdl(): ?string
  140.     {
  141.         return $this->pdl;
  142.     }
  143.     public function setPdl(?string $pdl): self
  144.     {
  145.         $this->pdl $pdl;
  146.         return $this;
  147.     }
  148.     public function getCar(): ?float
  149.     {
  150.         return $this->car;
  151.     }
  152.     public function setCar($car): self
  153.     {
  154.         if ($car === null) {
  155.             $this->car 0;
  156.             return $this;
  157.         }
  158.         if (is_string($car)) {
  159.             // Replace comma with dot for decimal numbers
  160.             $car str_replace(',''.'$car);
  161.             // Convert to float
  162.             $car = (float)$car;
  163.         }
  164.         $this->car = (float)$car;
  165.         return $this;
  166.     }
  167.     public function getPrixMoyen(): ?float
  168.     {
  169.         return $this->prix_moyen;
  170.     }
  171.     public function setPrixMoyen(?float $prix_moyen): self
  172.     {
  173.         $this->prix_moyen $prix_moyen ?? 0;
  174.         return $this;
  175.     }
  176.     public function getFournisseur(): ?string
  177.     {
  178.         return $this->fournisseur;
  179.     }
  180.     public function setFournisseur(?string $fournisseur): self
  181.     {
  182.         $this->fournisseur $fournisseur;
  183.         return $this;
  184.     }
  185.     public function getDateDebut(): ?\DateTimeInterface
  186.     {
  187.         return $this->date_debut;
  188.     }
  189.     public function setDateDebut(?\DateTimeInterface $date_debut): self
  190.     {
  191.         $this->date_debut $date_debut;
  192.         return $this;
  193.     }
  194.     public function getDateFin(): ?\DateTimeInterface
  195.     {
  196.         return $this->date_fin;
  197.     }
  198.     public function setDateFin(?\DateTimeInterface $date_fin): self
  199.     {
  200.         $this->date_fin $date_fin;
  201.         return $this;
  202.     }
  203.     public function getDateSignature(): ?\DateTimeInterface
  204.     {
  205.         return $this->date_signature;
  206.     }
  207.     public function setDateSignature(?\DateTimeInterface $date_signature): self
  208.     {
  209.         $this->date_signature $date_signature;
  210.         return $this;
  211.     }
  212. }