<?php
namespace App\Entity\Adresses;
use App\Entity\Clients\Client;
use App\Entity\Fournisseurs\Fournisseur;
use App\Entity\GestionComerciale\Commande;
use App\Entity\GestionComerciale\CommandeFournisseur;
use App\Entity\Localisation\Zone;
use App\Entity\Transporteurs\Transporteur;
use App\Entity\Transporteurs\ZoneLivraison;
use App\Entity\Utilisateur\Utilisateur;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
use App\Annotations\SecuredEntity;
/**
* Adresse
*
* @ORM\Table("adresse__adresse")
* @ORM\Entity(repositoryClass="App\Repository\Adresses\AdresseRepository")
* @Gedmo\SoftDeleteable(fieldName="dateSuppression",timeAware=false)
* @ORM\HasLifecycleCallbacks()
* @SecuredEntity(name="Adresse", group="VENTES")
*/
class Adresse
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(name="cedex", type="boolean", nullable=true)
*/
protected $cedex;
/**
* @ORM\Column(name="facturation_expedition_defaut", type="boolean", nullable=true)
*/
protected $facturationExpeditionDefaut;
/**
* @ORM\Column(name="fiable", type="boolean", nullable=true)
*/
protected $fiable;
/**
* @ORM\Column(name="id_prestashop", type="string",length=255, nullable=true)
*/
private $id_prestashop;
/**
* @ORM\Column(name="id_import", type="string",length=255, nullable=true)
*/
private $idImport;
/**
* @ORM\Column(name="id_import_2", type="string",length=255, nullable=true)
*/
private $idImport2;
/**
* @ORM\OneToMany(targetEntity="App\Entity\GestionComerciale\Commande", mappedBy="adresseLivraison")
*/
private $commandeLivraison;
/**
* @ORM\OneToMany(targetEntity="App\Entity\GestionComerciale\Commande", mappedBy="adresseFacturation")
*/
private $commandeFacturation;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Localisation\Zone")
* @ORM\JoinColumn(nullable=true)
*/
private $pays;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Transporteurs\ZoneLivraison")
* @ORM\JoinColumn(nullable=true)
* @Assert\NotBlank(message="La zone de livraison est obligatoire")
*/
private $zoneLivraison;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Localisation\Zone")
* @ORM\JoinColumn(nullable=true)
*/
private $ville;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Localisation\Zone")
* @ORM\JoinColumn(nullable=true)
*/
private $codePostal;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Fournisseurs\Fournisseur", inversedBy="adresses")
* @ORM\JoinColumn(nullable=true)
*/
private $fournisseur;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Transporteurs\Transporteur", inversedBy="adresses")
* @ORM\JoinColumn(nullable=true)
*/
private $transporteur;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Clients\Client", inversedBy="adresses", cascade={"persist"})
* @ORM\JoinColumn(nullable=true)
*/
private $client;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Utilisateur\Utilisateur", inversedBy="adresses")
* @ORM\JoinColumn(nullable=true)
*/
private $utilisateur;
/**
* @ORM\Column(name="date", type="datetime", nullable=true)
*/
private $date;
/**
* @ORM\Column(name="dateMaj", type="datetime", nullable=true)
* @Gedmo\Timestampable(on="update")
*/
private $dateMaj;
/**
* @ORM\Column(name="dateSuppression", type="datetime", nullable=true)
*/
private $dateSuppression;
/**
* @ORM\Column(name="numero", type="string", length=255, nullable=true)
*/
private $numero;
/**
* @ORM\Column(name="rue", type="string", length=255, nullable=true)
*/
private $rue;
/**
* @ORM\Column(name="complement", type="string", length=255, nullable=true)
*/
private $complement;
/**
* @ORM\Column(name="complement2", type="string", length=255, nullable=true)
*/
private $complement2;
/**
* @ORM\Column(name="telephone", type="string", length=255, nullable=true)
*/
private $telephone;
/**
* @ORM\Column(name="email", type="string", length=255, nullable=true)
*/
private $email;
/**
* @ORM\Column(name="libelle", type="string", length=255, nullable=true)
* @Assert\NotBlank(message="Libellé obligatoire")
*/
private $libelle;
/**
* @ORM\Column(name="societe", type="string", length=255, nullable=true)
*/
private $societe;
/**
* @ORM\Column(name="commentaire", type="text", nullable=true)
*/
private $commentaire;
/**
* @ORM\Column(name="donnees_import", type="text", nullable=true)
*/
private $donnesImport;
/**
* @ORM\OneToMany(targetEntity="App\Entity\GestionComerciale\CommandeFournisseur", mappedBy="adresseLivraison")
*/
private $commandeFournisseurLivraison;
/**
* @ORM\Column(name="facturation_defaut", type="boolean", nullable=true)
*/
protected $facturationDefaut;
/**
* @ORM\Column(name="livraison_defaut", type="boolean", nullable=true)
*/
protected $livraisonDefaut;
/**
* @ORM\Column(name="visible", type="boolean", options={"default" : 1})
*/
protected $visible;
/**
* @ORM\Column(name="latitude", type="string", length=255, nullable=true)
*/
private $latitude;
/**
* @ORM\Column(name="longitude", type="string", length=255, nullable=true)
*/
private $longitude;
public function __construct()
{
$this->date = new Datetime();
$this->fiable = true;
$this->visible = true;
$this->commandeFournisseurLivraison = new ArrayCollection();
$this->commandeFacturation = new ArrayCollection();
$this->commandeLivraison = new ArrayCollection();
}
private function majAdresseFicheClient()
{
$client = $this->getClient();
if (is_object($client)) {
$adresses = $client->getAdresses();
if (is_array($adresses) && count($adresses)) {
foreach ($adresses as $adresse) {
if ($adresse->getVisible()) {
if ($adresse->getId() == $this->getId() || $this->getId() == '') {
$client->setVille($this->ville);
$client->setCodePostal($this->codePostal);
$client->setPays($this->pays);
}
break;
}
}
}
}
}
public function getId(): int
{
return $this->id;
}
public function setDate(?DateTime $date): Adresse
{
$this->date = $date;
return $this;
}
public function getDate(): ?DateTime
{
return $this->date;
}
public function setDateMaj(?DateTime $dateMaj): Adresse
{
$this->dateMaj = $dateMaj;
return $this;
}
public function getDateMaj(): ?DateTime
{
return $this->dateMaj;
}
public function setDateSuppression(?DateTime $dateSuppression): Adresse
{
$this->dateSuppression = $dateSuppression;
return $this;
}
public function getDateSuppression(): ?DateTime
{
return $this->dateSuppression;
}
public function setNumero(?string $numero): Adresse
{
$this->numero = $numero;
return $this;
}
public function getNumero(): ?string
{
return $this->numero;
}
public function setRue(?string $rue): Adresse
{
$this->rue = $rue;
return $this;
}
public function getRue(): ?string
{
return $this->abreviation($this->rue);
}
public function setComplement(?string $complement): Adresse
{
$this->complement = $complement;
return $this;
}
public function getComplement(): ?string
{
return $this->abreviation($this->complement);
}
public function setLibelle(?string $libelle): Adresse
{
$this->libelle = $libelle;
$this->societe = $libelle;
return $this;
}
public function getLibelle(): ?string
{
return $this->abreviation($this->libelle);
}
public function setPays(?Zone $pays): Adresse
{
$this->pays = $pays;
$this->majAdresseFicheClient();
return $this;
}
public function getPays(): ?Zone
{
return $this->pays;
}
public function setVille(?Zone $ville): Adresse
{
$this->ville = $ville;
$this->majAdresseFicheClient();
return $this;
}
public function getVille(): ?Zone
{
return $this->ville;
}
public function setCodePostal(?Zone $codePostal): Adresse
{
$this->codePostal = $codePostal;
$this->majAdresseFicheClient();
return $this;
}
public function getCodePostal(): ?Zone
{
return $this->codePostal;
}
public function setClient(?Client $client): Adresse
{
$this->client = $client;
return $this;
}
public function getClient(): ?Client
{
return $this->client;
}
public function setUtilisateur(?Utilisateur $utilisateur): Adresse
{
$this->utilisateur = $utilisateur;
return $this;
}
public function getUtilisateur(): ?Utilisateur
{
return $this->utilisateur;
}
public function setCommentaire(?string $commentaire): Adresse
{
$this->commentaire = $commentaire;
return $this;
}
public function getCommentaire(): ?string
{
return $this->commentaire;
}
public function setTransporteur(?Transporteur $transporteur): Adresse
{
$this->transporteur = $transporteur;
return $this;
}
public function getTransporteur(): ?Transporteur
{
return $this->transporteur;
}
public function setFournisseur(?Fournisseur $fournisseur): Adresse
{
$this->fournisseur = $fournisseur;
return $this;
}
public function getFournisseur(): ?Fournisseur
{
return $this->fournisseur;
}
public function __toString()
{
//return $this->abreviation($this->libelle);
$libelleAdresse = $this->getLibelle()." ";
if ($this->getNumero() != "") {
$libelleAdresse .= $this->getNumero().', ';
}
if ($this->getRue() != "") {
$libelleAdresse .= $this->getRue().' ';
}
if ($this->getComplement() != "") {
$libelleAdresse .= $this->getComplement().' ';
}
if ($this->getComplement2() != "") {
$libelleAdresse .= $this->getComplement2().' ';
}
if (is_object($this->getCodePostal())) {
$libelleAdresse .= $this->getCodePostal()->getCodePostal().' ';
}
if (is_object($this->getVille())) {
$libelleAdresse .= $this->getVille()->getTitre().' ';
}
if (is_object($this->getPays())) {
$libelleAdresse .= $this->getPays()->getTitre();
}
return $libelleAdresse;
}
public function addCommandeLivraison(Commande $commandeLivraison): Adresse
{
$this->commandeLivraison[] = $commandeLivraison;
return $this;
}
public function removeCommandeLivraison(Commande $commandeLivraison)
{
$this->commandeLivraison->removeElement($commandeLivraison);
}
public function getCommandeLivraison(): Collection
{
return $this->commandeLivraison;
}
public function addCommandeFacturation(Commande $commandeFacturation): Adresse
{
$this->commandeFacturation[] = $commandeFacturation;
return $this;
}
public function removeCommandeFacturation(Commande $commandeFacturation)
{
$this->commandeFacturation->removeElement($commandeFacturation);
}
public function getCommandeFacturation(): Collection
{
return $this->commandeFacturation;
}
/**
* @ORM\PreRemove
*/
public function supprimerRelationAdresse()
{
// $this->libelle = "AAAA";
// $this->commandeFacturation->setTotal('999999');
}
public function setIdImport(?string $idImport): Adresse
{
$this->idImport = $idImport;
return $this;
}
public function getIdImport(): ?string
{
return $this->idImport;
}
public function setDonnesImport(?string $donnesImport): Adresse
{
$this->donnesImport = $donnesImport;
return $this;
}
public function getDonnesImport(): ?string
{
return $this->donnesImport;
}
public function setZoneLivraison(?ZoneLivraison $zoneLivraison): Adresse
{
$this->zoneLivraison = $zoneLivraison;
return $this;
}
public function getZoneLivraison(): ?ZoneLivraison
{
return $this->zoneLivraison;
}
public function addCommandeFournisseurLivraison(CommandeFournisseur $commandeFournisseurLivraison): Adresse
{
$this->commandeFournisseurLivraison[] = $commandeFournisseurLivraison;
return $this;
}
public function removeCommandeFournisseurLivraison(CommandeFournisseur $commandeFournisseurLivraison)
{
$this->commandeFournisseurLivraison->removeElement($commandeFournisseurLivraison);
}
public function getCommandeFournisseurLivraison(): Collection
{
return $this->commandeFournisseurLivraison;
}
public function setFiable(?bool $fiable): Adresse
{
$this->fiable = $fiable;
return $this;
}
public function getFiable(): ?bool
{
return $this->fiable;
}
public function setComplement2(?string $complement2): Adresse
{
$this->complement2 = $complement2;
return $this;
}
public function getComplement2(): ?string
{
return $this->abreviation($this->complement2);
}
public function setFacturationDefaut(?bool $facturationDefaut): Adresse
{
$this->facturationDefaut = $facturationDefaut;
return $this;
}
public function getFacturationDefaut(): ?bool
{
return $this->facturationDefaut;
}
public function setLivraisonDefaut(?bool $livraisonDefaut): Adresse
{
$this->livraisonDefaut = $livraisonDefaut;
return $this;
}
public function getLivraisonDefaut(): ?bool
{
return $this->livraisonDefaut;
}
public function setTelephone(?string $telephone): Adresse
{
$this->telephone = $telephone;
return $this;
}
public function getTelephone(): ?string
{
return $this->telephone;
}
public function setEmail(?string $email): Adresse
{
$this->email = $email;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setIdPrestashop(?string $idPrestashop): Adresse
{
$this->id_prestashop = $idPrestashop;
return $this;
}
public function getIdPrestashop(): ?string
{
return $this->id_prestashop;
}
public function setVisible(bool $visible): Adresse
{
$this->visible = $visible;
return $this;
}
public function getVisible(): bool
{
return $this->visible;
}
public function setCedex(?bool $cedex): Adresse
{
$this->cedex = $cedex;
return $this;
}
public function getCedex(): ?bool
{
return $this->cedex;
}
public function setFacturationExpeditionDefaut(?bool $facturationExpeditionDefaut): Adresse
{
$this->facturationExpeditionDefaut = $facturationExpeditionDefaut;
return $this;
}
public function getFacturationExpeditionDefaut(): ?bool
{
return $this->facturationExpeditionDefaut;
}
public function setLatitude(?string $latitude): Adresse
{
$this->latitude = $latitude;
return $this;
}
public function getLatitude(): ?string
{
return $this->latitude;
}
public function setLongitude(?string $longitude): Adresse
{
$this->longitude = $longitude;
return $this;
}
public function getLongitude(): ?string
{
return $this->longitude;
}
public function setSociete(?string $societe): Adresse
{
$this->societe = $societe;
return $this;
}
public function getSociete(): string
{
return $this->abreviation($this->societe);
}
public function setIdImport2(?string $idImport2): self
{
$this->idImport2 = $idImport2;
return $this;
}
public function getIdImport2(): ?string
{
return $this->idImport2;
}
public function abreviation($str): string
{
$search = [
'allée',
'avenue.',
'boulevard',
'carrefour',
'chemin',
'chaussée',
'impasse',
'lotissement',
'passage',
'place',
'résidence',
'route',
'batiment',
'étage',
'escalier',
];
$replace = ['All.', 'Av.', 'Bd.', 'Car.', 'Che.', 'Chs.', 'Imp.', 'Lot.', 'Pas.', 'Pl.', 'Res.', 'Rte.', 'Bat.', 'Et.', 'Esc.'];
return str_replace($search, $replace, $str);
}
/**
* @ORM\PreRemove()
*/
public function preRemove()
{
foreach ($this->getCommandeLivraison() as $cl) {
/** @var Commande $cl */
$cl->setAdresseLivraison(null);
$cl->setAdresseFacturation(null);
}
}
}