<?php
namespace App\Entity;
use App\Repository\LotRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=LotRepository::class)
*/
class Lot
{
const IMAGE_SAVE_PATH = 'uploads/lots_images/';
const BROCHURE_SAVE_PATH = 'uploads/brochures/';
const PLAN_MASSE_SAVE_PATH = 'uploads/plans_masse/';
const STATUTS = [
'vendu' => 'red',
'libre' => 'green',
'option' => 'yellow',
'reserve' => 'purple',
];
const NATURES = [
'appartement' => 'Appartement',
'maison' => 'Maison',
'terrain' => 'Terrain',
'local_commercial' => 'Local commercial',
];
const ETATS_PRODUCTION = [
'incomplet' => 'INCOMPLET',
'en_preparation' => 'EN PREPARATION',
'complet' => 'PRET A L\'ENVOI',
];
const INTITULES_PREDEFINIS = [
'visuels_3d' => 'Visuels 3D',
'localisation' => 'Localisation',
'insertion_3d' => 'Insertion 3D sur plan masse / maquette',
'mise_en_couleur' => 'Mise en couleur du lot',
'flechage_niveau' => 'Fléchage plan de niveau/ plan de coupe',
'flechage_masse' => 'Fléchage sur plan masse/ maquette 3D',
'stationnements' => 'Stationnements / Caves',
'local_velo' => 'Local vélo',
'acces_transports' => 'Accès & Transports',
'prestations_generales' => 'Prestations Générales',
'photos_appartement' => 'Photos de l\'appartement',
'photos_construction' => 'Photos du site de construction',
'photos_environnement' => 'Photos de l\'environnement du site',
'itineraire_geneve' => 'Itinéraire site de construction - Genève',
'itineraire_annecy' => 'Itinéraire site de construction - Lac d\'Annecy',
'itineraire_aeroport' => 'Itinéraire site de construction - aéroport Genève',
'itineraire_gare' => 'Itinéraire site de construction - Gare / CEVA EXPRESS',
'itineraire_personnalise' => 'Itinéraire personnalisé'
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $reference;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $type;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $adresse;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $ville;
/**
* @ORM\Column(type="string", length=10, nullable=true)
*/
private $codePostal;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $prix;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $dateLivraison;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $titre;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $latitude;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $longitude;
/**
* @ORM\Column(type="string", length=64, nullable=true)
*/
private $etage;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $superficie;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $terrasse;
/**
* @ORM\Column(type="string", length=32, nullable=true)
*/
private $orientation;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*/
private $annexes;
/**
* @ORM\Column(type="string", length=64, nullable=true)
*/
private $livraison;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*/
private $promoteur;
/**
* @ORM\Column(type="string", length=64, nullable=true)
*/
private $programme;
/**
* @ORM\OneToMany(targetEntity=PieceJointe::class, mappedBy="lot", cascade={"persist", "remove"})
* @ORM\OrderBy({"ordre" = "ASC"})
*/
private $pjs;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $image;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $jardin;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $terrasse2;
/**
* @ORM\OneToMany(targetEntity=Proposition::class, mappedBy="lot", orphanRemoval=true)
*/
private $propositions;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
private $fraisNotaireType = 'reduits';
/**
* @ORM\Column(type="float", nullable=true)
*/
private $fraisNotaireInclus;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $brochure;
/**
* @ORM\ManyToMany(targetEntity=Historique::class, mappedBy="lots")
*/
private $historiques;
/**
* @ORM\ManyToOne(targetEntity=Programme::class, inversedBy="lots")
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*/
private $programmeParent;
/**
* @ORM\Column(type="text", length=255, nullable=true)
*/
private $planMasse;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $statut;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $nature;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $typeMoteurRecherche;
/**
* @ORM\Column(type="string", length=64, nullable=true)
*/
private $etageMoteurRecherche;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $etatLot;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $pjProgression = [];
public static function getStatutsString() {
$tab = [];
foreach(self::STATUTS as $k => $v) {
$tab[$k] = ucfirst($k);
}
return $tab;
}
public static function getStatutsForForm() {
return [
'Vendu' => 'vendu',
'Libre' => 'libre',
'Option' => 'option',
'Réservé' => 'reserve',
];
}
public function __construct()
{
$this->pjs = new ArrayCollection();
$this->propositions = new ArrayCollection();
$this->historiques = new ArrayCollection();
$this->etatLot = 'incomplet';
}
public function __clone()
{
if ($this->id) {
$this->id = null;
$clonedPjs = new ArrayCollection();
foreach ($this->pjs as $pj) {
$clonedPj = clone $pj;
$clonedPj->setLot($this);
$clonedPjs->add($clonedPj);
}
$this->pjs = $clonedPjs;
}
}
public function __toString() {
if($this->getId() == null) {
return 'Nouveau lot';
} else {
$etatLotKey = $this->getetatLot();
$etatLotValue = array_key_exists($etatLotKey, self::ETATS_PRODUCTION) ? self::ETATS_PRODUCTION[$etatLotKey] : 'N/A';
return trim((trim($this->getReference()) != '' ? 'n°' . $this->getReference() . ' - ' : '')). ' ' . trim((trim($this->getVille()) != '' ? '' . $this->getVille() . ' - ' : '') . $this->getProgramme() . ' (' . $this->getType() . ') - ' . number_format($this->getPrix(), 2, ',', ' ') . '€' . ' - ' . $etatLotValue);
}
}
public function getId(): ?int
{
return $this->id;
}
public function getReference(): ?string
{
return strtoupper($this->reference);
}
public function setReference(?string $reference): self
{
$this->reference = $reference;
return $this;
}
public function getType(): ?string
{
return str_replace('é', 'É',
str_replace('è', 'È',
str_replace('à', 'À',
strtoupper($this->type)
)
)
);
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getAdresse(): ?string
{
return str_replace('é', 'É',
str_replace('è', 'È',
str_replace('à', 'À',
strtoupper($this->adresse)
)
)
);
}
public function setAdresse(?string $adresse): self
{
$this->adresse = $adresse;
return $this;
}
public function getVille(): ?string
{
return strtoupper($this->ville);
}
public function setVille(?string $ville): self
{
$this->ville = $ville;
return $this;
}
public function getCodePostal(): ?string
{
return strtoupper($this->codePostal);
}
public function setCodePostal(?string $codePostal): self
{
$this->codePostal = $codePostal;
return $this;
}
public function getPrix(): ?float
{
return $this->prix;
}
public function setPrix(?float $prix): self
{
$this->prix = $prix;
return $this;
}
public function getDateLivraison(): ?\DateTimeInterface
{
return $this->dateLivraison;
}
public function setDateLivraison(?\DateTimeInterface $dateLivraison): self
{
$this->dateLivraison = $dateLivraison;
return $this;
}
public function getTitre(): ?string
{
return strtoupper($this->titre);
}
public function setTitre(?string $titre): self
{
$this->titre = $titre;
return $this;
}
public function getDescription(): ?string
{
return html_entity_decode(strip_tags($this->description));
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getLatitude(): ?float
{
return $this->latitude;
}
public function setLatitude(?float $latitude): self
{
$this->latitude = $latitude;
return $this;
}
public function getLongitude(): ?float
{
return $this->longitude;
}
public function setLongitude(?float $longitude): self
{
$this->longitude = $longitude;
return $this;
}
public function getEtage(): ?string
{
return strtoupper($this->etage);
}
public function setEtage(?string $etage): self
{
$this->etage = $etage;
return $this;
}
public function getSuperficie(): ?float
{
return $this->superficie;
}
public function setSuperficie(?float $superficie): self
{
$this->superficie = $superficie;
return $this;
}
public function getTerrasse(): ?float
{
return $this->terrasse;
}
public function setTerrasse(?float $terrasse): self
{
$this->terrasse = $terrasse;
return $this;
}
public function getOrientation(): ?string
{
return $this->orientation;
}
public function setOrientation(?string $orientation): self
{
$this->orientation = $orientation;
return $this;
}
public function getAnnexes(): ?string
{
return $this->annexes;
}
public function setAnnexes(?string $annexes): self
{
$this->annexes = $annexes;
return $this;
}
public function getLivraison(): ?string
{
return strtoupper($this->livraison);
}
public function setLivraison(?string $livraison): self
{
$this->livraison = $livraison;
return $this;
}
public function getPromoteur(): ?string
{
return strtoupper($this->promoteur);
}
public function setPromoteur(?string $promoteur): self
{
$this->promoteur = $promoteur;
return $this;
}
public function getProgramme(): ?string
{
if($this->getProgrammeParent()) return strtoupper($this->getProgrammeParent()->getNom());
return strtoupper($this->programme);
}
public function setProgramme(?string $programme): self
{
$this->programme = $programme;
return $this;
}
public function getPlan() {
foreach($this->getPjs() as $pj) {
if($pj->getEstUnPlan()) {
return $pj;
}
}
return null;
}
public function getImageAdminLot() {
foreach($this->getPjs() as $pj) {
if($pj->getEstImageAdmin()) {
return $pj;
}
}
return null;
}
public function getPjByOrdre($ordre) {
foreach($this->getPjs() as $pj) {
if($pj->getOrdre() == $ordre) {
return $pj;
}
}
return null;
}
/**
* @return Collection|PieceJointe[]
*/
public function getPjs(): Collection
{
return $this->pjs;
}
public function addPj(PieceJointe $pj): self
{
if (!$this->pjs->contains($pj)) {
$this->pjs[] = $pj;
$pj->setLot($this);
}
return $this;
}
public function removePj(PieceJointe $pj): self
{
if ($this->pjs->removeElement($pj)) {
// set the owning side to null (unless already changed)
if ($pj->getLot() === $this) {
$pj->setLot(null);
}
}
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function getJardin(): ?float
{
return $this->jardin;
}
public function setJardin(?float $jardin): self
{
$this->jardin = $jardin;
return $this;
}
public function getTerrasse2(): ?float
{
return $this->terrasse2;
}
public function setTerrasse2(?float $terrasse2): self
{
$this->terrasse2 = $terrasse2;
return $this;
}
/**
* @return Collection|Proposition[]
*/
public function getPropositions(): Collection
{
return $this->propositions;
}
public function addProposition(Proposition $proposition): self
{
if (!$this->propositions->contains($proposition)) {
$this->propositions[] = $proposition;
$proposition->setActiveProposition(true);
$proposition->setLot($this);
}
return $this;
}
public function removeProposition(Proposition $proposition): self
{
if ($this->propositions->removeElement($proposition)) {
// set the owning side to null (unless already changed)
if ($proposition->getLot() === $this) {
$proposition->setLot(null);
}
}
return $this;
}
public function getFraisNotaireType(): ?string
{
return $this->fraisNotaireType;
}
public function setFraisNotaireType(?string $fraisNotaireType): self
{
$this->fraisNotaireType = $fraisNotaireType;
return $this;
}
public function getFraisNotaireInclus(): ?float
{
return $this->fraisNotaireInclus;
}
public function setFraisNotaireInclus(?float $fraisNotaireInclus): self
{
$this->fraisNotaireInclus = $fraisNotaireInclus;
return $this;
}
public function getBrochure(): ?string
{
return $this->brochure;
}
public function setBrochure(?string $brochure): self
{
$this->brochure = $brochure;
return $this;
}
/**
* @return Collection|Historique[]
*/
public function getHistoriques(): Collection
{
return $this->historiques;
}
public function addHistorique(Historique $historique): self
{
if (!$this->historiques->contains($historique)) {
$this->historiques[] = $historique;
$historique->addLot($this);
}
return $this;
}
public function removeHistorique(Historique $historique): self
{
if ($this->historiques->removeElement($historique)) {
$historique->removeLot($this);
}
return $this;
}
public function getProgrammeParent(): ?Programme
{
return $this->programmeParent;
}
public function setProgrammeParent(?Programme $programmeParent): self
{
$this->programmeParent = $programmeParent;
return $this;
}
public function getPlanMasse(): ?string
{
return $this->planMasse;
}
public function setPlanMasse(?string $planMasse): self
{
$this->planMasse = $planMasse;
return $this;
}
public function getStatut(): ?string
{
return $this->statut;
}
public function setStatut(?string $statut): self
{
$this->statut = $statut;
return $this;
}
public function getStatutString(): ?String
{
return ucfirst($this->getStatut());
}
public function getStatutClass(): ?String
{
return self::STATUTS[$this->getStatut()];
}
public function getNature(): ?string
{
return $this->nature;
}
public function setNature(?string $nature): self
{
$this->nature = $nature;
return $this;
}
public function getTypeMoteurRecherche(): ?string
{
return $this->typeMoteurRecherche;
}
public function setTypeMoteurRecherche(?string $typeMoteurRecherche): self
{
$this->typeMoteurRecherche = $typeMoteurRecherche;
return $this;
}
public function getEtageMoteurRecherche(): ?string
{
return $this->etageMoteurRecherche;
}
public function setEtageMoteurRecherche(?string $etageMoteurRecherche): self
{
$this->etageMoteurRecherche = $etageMoteurRecherche;
return $this;
}
public function getetatLot(): ?string
{
return $this->etatLot;
}
public function setetatLot(?string $etatLot): self
{
$this->etatLot = $etatLot;
return $this;
}
public function getPjProgression(): ?array
{
return $this->pjProgression;
}
public function setPjProgression(?array $pjProgression): self
{
$this->pjProgression = $pjProgression;
return $this;
}
}