src/Entity/Magasin.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\MagasinRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity(repositoryClass="App\Repository\MagasinRepository")
  10.  */ 
  11. class Magasin
  12. {
  13.     /**
  14.      * @ORM\Id()
  15.      * @ORM\GeneratedValue()
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=255)
  21.      */
  22.     private $nommagasin;
  23.  
  24.     
  25.     /**
  26.      * @ORM\Column(type="text")
  27.      */
  28.     private $journalmagasin;
  29.  
  30.     
  31.     /**
  32.      * @ORM\Column(type="datetime", nullable=true)
  33.      */
  34.     private $datesuppressionmagasin;
  35.     /**
  36.      * @ORM\Column(type="datetime", nullable=true)
  37.      */
  38.     private $datecreationmagasin;
  39.     
  40.       
  41.     /**
  42.      * @var integer
  43.      * @ORM\ManyToOne(targetEntity="Produit" )
  44.      * @ORM\JoinColumn(name="produitid", referencedColumnName="id",  nullable=true )
  45.      */
  46.     private $produitid;
  47.     /* ───────── Champs RH (Phase HRM) ───────── */
  48.     /**
  49.      * @ORM\ManyToOne(targetEntity="Employe")
  50.      * @ORM\JoinColumn(name="rh_responsable_id", referencedColumnName="id", nullable=true)
  51.      */
  52.     private $rhResponsable;
  53.     /** @ORM\Column(type="integer", nullable=true, name="rh_effectif_theorique") */
  54.     private $rhEffectifTheorique;
  55.     /** @ORM\Column(type="string", length=30, nullable=true, name="rh_type") */
  56.     private $rhType;
  57.     /** @ORM\Column(type="string", length=30, nullable=true, name="rh_zone_geographique") */
  58.     private $rhZoneGeographique;
  59.     /** @ORM\Column(type="boolean", options={"default":1}, name="rh_actif") */
  60.     private $rhActif true;
  61.     /** @ORM\Column(type="string", length=200, nullable=true, name="rh_adresse") */
  62.     private $rhAdresse;
  63.     /** @ORM\Column(type="string", length=20, nullable=true, name="rh_telephone") */
  64.     private $rhTelephone;
  65.     /* ───────── Multi-société + Géolocalisation (Phase GES) ───────── */
  66.     /**
  67.      * @ORM\ManyToOne(targetEntity="Entite")
  68.      * @ORM\JoinColumn(name="entite_id", referencedColumnName="id", nullable=true)
  69.      */
  70.     private $entite;
  71.     /** @ORM\Column(type="decimal", precision=10, scale=7, nullable=true) */
  72.     private $latitude;
  73.     /** @ORM\Column(type="decimal", precision=10, scale=7, nullable=true) */
  74.     private $longitude;
  75.     /** @ORM\Column(type="integer", options={"default":150}, name="rayon_geofencing_metres") */
  76.     private $rayonGeofencingMetres 150;
  77.     /**
  78.      * Produits explicitement affectés à ce magasin.
  79.      * Si vide → le magasin hérite de tous les produits de son entité.
  80.      *
  81.      * @ORM\ManyToMany(targetEntity=Produit::class)
  82.      * @ORM\JoinTable(name="magasin_produit",
  83.      *     joinColumns={@ORM\JoinColumn(name="magasin_id", referencedColumnName="id")},
  84.      *     inverseJoinColumns={@ORM\JoinColumn(name="produit_id", referencedColumnName="id")}
  85.      * )
  86.      */
  87.     private Collection $produits;
  88.     public function __construct()
  89.     {
  90.         $this->produits = new ArrayCollection();
  91.     }
  92.     public function getProduits(): Collection { return $this->produits; }
  93.     public function addProduit(Produit $p): self { if (!$this->produits->contains($p)) { $this->produits->add($p); } return $this; }
  94.     public function removeProduit(Produit $p): self $this->produits->removeElement($p); return $this; }
  95.     /**
  96.      * Produits effectifs du magasin :
  97.      * - ses propres produits si définis
  98.      * - sinon tous les produits de son entité (fallback)
  99.      */
  100.     public function getProduitsEffectifs(): Collection
  101.     {
  102.         if ($this->produits->count() > 0) {
  103.             return $this->produits;
  104.         }
  105.         return $this->entite $this->entite->getProduits() : new ArrayCollection();
  106.     }
  107.     public function getId(): ?int
  108.     {
  109.         return $this->id;
  110.     }
  111.     public function getNommagasin(): ?string
  112.     {
  113.         return $this->nommagasin;
  114.     }
  115.     public function setNommagasin(string $nommagasin): static
  116.     {
  117.         $this->nommagasin $nommagasin;
  118.         return $this;
  119.     }
  120.     public function getJournalmagasin(): ?string
  121.     {
  122.         return $this->journalmagasin;
  123.     }
  124.     public function setJournalmagasin(string $journalmagasin): static
  125.     {
  126.         $this->journalmagasin $journalmagasin;
  127.         return $this;
  128.     }
  129.     public function getDatesuppressionmagasin(): ?\DateTimeInterface
  130.     {
  131.         return $this->datesuppressionmagasin;
  132.     }
  133.     public function setDatesuppressionmagasin(?\DateTimeInterface $datesuppressionmagasin): static
  134.     {
  135.         $this->datesuppressionmagasin $datesuppressionmagasin;
  136.         return $this;
  137.     }
  138.     public function getDatecreationmagasin(): ?\DateTimeInterface
  139.     {
  140.         return $this->datecreationmagasin;
  141.     }
  142.     public function setDatecreationmagasin(?\DateTimeInterface $datecreationmagasin): static
  143.     {
  144.         $this->datecreationmagasin $datecreationmagasin;
  145.         return $this;
  146.     }
  147.     public function getProduitid(): ?Produit
  148.     {
  149.         return $this->produitid;
  150.     }
  151.     public function setProduitid(?Produit $produitid): static
  152.     {
  153.         $this->produitid $produitid;
  154.         return $this;
  155.     }
  156.     /* ───────── Getters/Setters RH (Phase HRM) ───────── */
  157.     public function getRhResponsable(): ?Employe { return $this->rhResponsable; }
  158.     public function setRhResponsable(?Employe $e): static { $this->rhResponsable $e; return $this; }
  159.     public function getRhEffectifTheorique(): ?int { return $this->rhEffectifTheorique; }
  160.     public function setRhEffectifTheorique(?int $n): static { $this->rhEffectifTheorique $n; return $this; }
  161.     public function getRhType(): ?string { return $this->rhType; }
  162.     public function setRhType(?string $t): static { $this->rhType $t; return $this; }
  163.     public function getRhZoneGeographique(): ?string { return $this->rhZoneGeographique; }
  164.     public function setRhZoneGeographique(?string $z): static { $this->rhZoneGeographique $z; return $this; }
  165.     public function isRhActif(): bool { return (bool)($this->rhActif ?? true); }
  166.     public function setRhActif(bool $a): static { $this->rhActif $a; return $this; }
  167.     public function getRhAdresse(): ?string { return $this->rhAdresse; }
  168.     public function setRhAdresse(?string $a): static { $this->rhAdresse $a; return $this; }
  169.     public function getRhTelephone(): ?string { return $this->rhTelephone; }
  170.     public function setRhTelephone(?string $t): static { $this->rhTelephone $t; return $this; }
  171.     /* ───────── Getters/Setters Multi-société + GPS (Phase GES) ───────── */
  172.     public function getEntite(): ?Entite { return $this->entite; }
  173.     public function setEntite(?Entite $e): static { $this->entite $e; return $this; }
  174.     public function getLatitude() { return $this->latitude; }
  175.     public function setLatitude($l): static { $this->latitude $l; return $this; }
  176.     public function getLongitude() { return $this->longitude; }
  177.     public function setLongitude($l): static { $this->longitude $l; return $this; }
  178.     public function getRayonGeofencingMetres(): int { return (int)($this->rayonGeofencingMetres ?? 150); }
  179.     public function setRayonGeofencingMetres(int $r): static { $this->rayonGeofencingMetres $r; return $this; }
  180.     /**
  181.      * Snapshot scalaire pour le journal d'actions (audit log).
  182.      */
  183.     public function toArray(): array
  184.     {
  185.         return [
  186.             'id'                     => $this->id,
  187.             'nommagasin'             => $this->nommagasin,
  188.             'journalmagasin'         => $this->journalmagasin,
  189.             'datesuppressionmagasin' => $this->datesuppressionmagasin?->format(\DateTimeInterface::ATOM),
  190.             'datecreationmagasin'    => $this->datecreationmagasin?->format(\DateTimeInterface::ATOM),
  191.             'produitid'              => $this->produitid?->getId(),
  192.             'rh_responsable_id'      => $this->rhResponsable?->getId(),
  193.             'rh_effectif_theorique'  => $this->rhEffectifTheorique,
  194.             'rh_type'                => $this->rhType,
  195.             'rh_zone_geographique'   => $this->rhZoneGeographique,
  196.             'rh_actif'               => $this->rhActif ?? true,
  197.             'rh_adresse'             => $this->rhAdresse,
  198.             'rh_telephone'           => $this->rhTelephone,
  199.             'entite_id'              => $this->entite?->getId(),
  200.             'latitude'               => $this->latitude,
  201.             'longitude'              => $this->longitude,
  202.             'rayon_geofencing_metres'=> $this->getRayonGeofencingMetres(),
  203.         ];
  204.     }
  205. }