<?php
namespace App\Entity;
use App\Repository\MagasinRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\MagasinRepository")
*/
class Magasin
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $nommagasin;
/**
* @ORM\Column(type="text")
*/
private $journalmagasin;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $datesuppressionmagasin;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $datecreationmagasin;
/**
* @var integer
* @ORM\ManyToOne(targetEntity="Produit" )
* @ORM\JoinColumn(name="produitid", referencedColumnName="id", nullable=true )
*/
private $produitid;
/* ───────── Champs RH (Phase HRM) ───────── */
/**
* @ORM\ManyToOne(targetEntity="Employe")
* @ORM\JoinColumn(name="rh_responsable_id", referencedColumnName="id", nullable=true)
*/
private $rhResponsable;
/** @ORM\Column(type="integer", nullable=true, name="rh_effectif_theorique") */
private $rhEffectifTheorique;
/** @ORM\Column(type="string", length=30, nullable=true, name="rh_type") */
private $rhType;
/** @ORM\Column(type="string", length=30, nullable=true, name="rh_zone_geographique") */
private $rhZoneGeographique;
/** @ORM\Column(type="boolean", options={"default":1}, name="rh_actif") */
private $rhActif = true;
/** @ORM\Column(type="string", length=200, nullable=true, name="rh_adresse") */
private $rhAdresse;
/** @ORM\Column(type="string", length=20, nullable=true, name="rh_telephone") */
private $rhTelephone;
/* ───────── Multi-société + Géolocalisation (Phase GES) ───────── */
/**
* @ORM\ManyToOne(targetEntity="Entite")
* @ORM\JoinColumn(name="entite_id", referencedColumnName="id", nullable=true)
*/
private $entite;
/** @ORM\Column(type="decimal", precision=10, scale=7, nullable=true) */
private $latitude;
/** @ORM\Column(type="decimal", precision=10, scale=7, nullable=true) */
private $longitude;
/** @ORM\Column(type="integer", options={"default":150}, name="rayon_geofencing_metres") */
private $rayonGeofencingMetres = 150;
/**
* Produits explicitement affectés à ce magasin.
* Si vide → le magasin hérite de tous les produits de son entité.
*
* @ORM\ManyToMany(targetEntity=Produit::class)
* @ORM\JoinTable(name="magasin_produit",
* joinColumns={@ORM\JoinColumn(name="magasin_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="produit_id", referencedColumnName="id")}
* )
*/
private Collection $produits;
public function __construct()
{
$this->produits = new ArrayCollection();
}
public function getProduits(): Collection { return $this->produits; }
public function addProduit(Produit $p): self { if (!$this->produits->contains($p)) { $this->produits->add($p); } return $this; }
public function removeProduit(Produit $p): self { $this->produits->removeElement($p); return $this; }
/**
* Produits effectifs du magasin :
* - ses propres produits si définis
* - sinon tous les produits de son entité (fallback)
*/
public function getProduitsEffectifs(): Collection
{
if ($this->produits->count() > 0) {
return $this->produits;
}
return $this->entite ? $this->entite->getProduits() : new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getNommagasin(): ?string
{
return $this->nommagasin;
}
public function setNommagasin(string $nommagasin): static
{
$this->nommagasin = $nommagasin;
return $this;
}
public function getJournalmagasin(): ?string
{
return $this->journalmagasin;
}
public function setJournalmagasin(string $journalmagasin): static
{
$this->journalmagasin = $journalmagasin;
return $this;
}
public function getDatesuppressionmagasin(): ?\DateTimeInterface
{
return $this->datesuppressionmagasin;
}
public function setDatesuppressionmagasin(?\DateTimeInterface $datesuppressionmagasin): static
{
$this->datesuppressionmagasin = $datesuppressionmagasin;
return $this;
}
public function getDatecreationmagasin(): ?\DateTimeInterface
{
return $this->datecreationmagasin;
}
public function setDatecreationmagasin(?\DateTimeInterface $datecreationmagasin): static
{
$this->datecreationmagasin = $datecreationmagasin;
return $this;
}
public function getProduitid(): ?Produit
{
return $this->produitid;
}
public function setProduitid(?Produit $produitid): static
{
$this->produitid = $produitid;
return $this;
}
/* ───────── Getters/Setters RH (Phase HRM) ───────── */
public function getRhResponsable(): ?Employe { return $this->rhResponsable; }
public function setRhResponsable(?Employe $e): static { $this->rhResponsable = $e; return $this; }
public function getRhEffectifTheorique(): ?int { return $this->rhEffectifTheorique; }
public function setRhEffectifTheorique(?int $n): static { $this->rhEffectifTheorique = $n; return $this; }
public function getRhType(): ?string { return $this->rhType; }
public function setRhType(?string $t): static { $this->rhType = $t; return $this; }
public function getRhZoneGeographique(): ?string { return $this->rhZoneGeographique; }
public function setRhZoneGeographique(?string $z): static { $this->rhZoneGeographique = $z; return $this; }
public function isRhActif(): bool { return (bool)($this->rhActif ?? true); }
public function setRhActif(bool $a): static { $this->rhActif = $a; return $this; }
public function getRhAdresse(): ?string { return $this->rhAdresse; }
public function setRhAdresse(?string $a): static { $this->rhAdresse = $a; return $this; }
public function getRhTelephone(): ?string { return $this->rhTelephone; }
public function setRhTelephone(?string $t): static { $this->rhTelephone = $t; return $this; }
/* ───────── Getters/Setters Multi-société + GPS (Phase GES) ───────── */
public function getEntite(): ?Entite { return $this->entite; }
public function setEntite(?Entite $e): static { $this->entite = $e; return $this; }
public function getLatitude() { return $this->latitude; }
public function setLatitude($l): static { $this->latitude = $l; return $this; }
public function getLongitude() { return $this->longitude; }
public function setLongitude($l): static { $this->longitude = $l; return $this; }
public function getRayonGeofencingMetres(): int { return (int)($this->rayonGeofencingMetres ?? 150); }
public function setRayonGeofencingMetres(int $r): static { $this->rayonGeofencingMetres = $r; return $this; }
/**
* Snapshot scalaire pour le journal d'actions (audit log).
*/
public function toArray(): array
{
return [
'id' => $this->id,
'nommagasin' => $this->nommagasin,
'journalmagasin' => $this->journalmagasin,
'datesuppressionmagasin' => $this->datesuppressionmagasin?->format(\DateTimeInterface::ATOM),
'datecreationmagasin' => $this->datecreationmagasin?->format(\DateTimeInterface::ATOM),
'produitid' => $this->produitid?->getId(),
'rh_responsable_id' => $this->rhResponsable?->getId(),
'rh_effectif_theorique' => $this->rhEffectifTheorique,
'rh_type' => $this->rhType,
'rh_zone_geographique' => $this->rhZoneGeographique,
'rh_actif' => $this->rhActif ?? true,
'rh_adresse' => $this->rhAdresse,
'rh_telephone' => $this->rhTelephone,
'entite_id' => $this->entite?->getId(),
'latitude' => $this->latitude,
'longitude' => $this->longitude,
'rayon_geofencing_metres'=> $this->getRayonGeofencingMetres(),
];
}
}