src/Entity/Adresses/Adresse.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Adresses;
  3. use App\Entity\Clients\Client;
  4. use App\Entity\Fournisseurs\Fournisseur;
  5. use App\Entity\GestionComerciale\Commande;
  6. use App\Entity\GestionComerciale\CommandeFournisseur;
  7. use App\Entity\Localisation\Zone;
  8. use App\Entity\Transporteurs\Transporteur;
  9. use App\Entity\Transporteurs\ZoneLivraison;
  10. use App\Entity\Utilisateur\Utilisateur;
  11. use DateTime;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Gedmo\Mapping\Annotation as Gedmo;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. use App\Annotations\SecuredEntity;
  18. /**
  19.  * Adresse
  20.  *
  21.  * @ORM\Table("adresse__adresse")
  22.  * @ORM\Entity(repositoryClass="App\Repository\Adresses\AdresseRepository")
  23.  * @Gedmo\SoftDeleteable(fieldName="dateSuppression",timeAware=false)
  24.  * @ORM\HasLifecycleCallbacks()
  25.  * @SecuredEntity(name="Adresse", group="VENTES")
  26.  */
  27. class Adresse
  28. {
  29.     /**
  30.      * @ORM\Column(name="id", type="integer")
  31.      * @ORM\Id
  32.      * @ORM\GeneratedValue(strategy="AUTO")
  33.      */
  34.     private $id;
  35.     /**
  36.      * @ORM\Column(name="cedex", type="boolean", nullable=true)
  37.      */
  38.     protected $cedex;
  39.     /**
  40.      * @ORM\Column(name="facturation_expedition_defaut", type="boolean", nullable=true)
  41.      */
  42.     protected $facturationExpeditionDefaut;
  43.     /**
  44.      * @ORM\Column(name="fiable", type="boolean", nullable=true)
  45.      */
  46.     protected $fiable;
  47.     /**
  48.      * @ORM\Column(name="id_prestashop", type="string",length=255, nullable=true)
  49.      */
  50.     private $id_prestashop;
  51.     /**
  52.      * @ORM\Column(name="id_import", type="string",length=255, nullable=true)
  53.      */
  54.     private $idImport;
  55.     /**
  56.      * @ORM\Column(name="id_import_2", type="string",length=255, nullable=true)
  57.      */
  58.     private $idImport2;
  59.     /**
  60.      * @ORM\OneToMany(targetEntity="App\Entity\GestionComerciale\Commande", mappedBy="adresseLivraison")
  61.      */
  62.     private $commandeLivraison;
  63.     /**
  64.      * @ORM\OneToMany(targetEntity="App\Entity\GestionComerciale\Commande", mappedBy="adresseFacturation")
  65.      */
  66.     private $commandeFacturation;
  67.     /**
  68.      * @ORM\ManyToOne(targetEntity="App\Entity\Localisation\Zone")
  69.      * @ORM\JoinColumn(nullable=true)
  70.      */
  71.     private $pays;
  72.     /**
  73.      * @ORM\ManyToOne(targetEntity="App\Entity\Transporteurs\ZoneLivraison")
  74.      * @ORM\JoinColumn(nullable=true)
  75.      */
  76.     private $zoneLivraison;
  77.     /**
  78.      * @ORM\ManyToOne(targetEntity="App\Entity\Localisation\Zone")
  79.      * @ORM\JoinColumn(nullable=true)
  80.      */
  81.     private $ville;
  82.     /**
  83.      * @ORM\ManyToOne(targetEntity="App\Entity\Localisation\Zone")
  84.      * @ORM\JoinColumn(nullable=true)
  85.      */
  86.     private $codePostal;
  87.     /**
  88.      * @ORM\ManyToOne(targetEntity="App\Entity\Fournisseurs\Fournisseur", inversedBy="adresses")
  89.      * @ORM\JoinColumn(nullable=true)
  90.      */
  91.     private $fournisseur;
  92.     /**
  93.      * @ORM\ManyToOne(targetEntity="App\Entity\Transporteurs\Transporteur", inversedBy="adresses")
  94.      * @ORM\JoinColumn(nullable=true)
  95.      */
  96.     private $transporteur;
  97.     /**
  98.      * @ORM\ManyToOne(targetEntity="App\Entity\Clients\Client", inversedBy="adresses", cascade={"persist"})
  99.      * @ORM\JoinColumn(nullable=true)
  100.      */
  101.     private $client;
  102.     /**
  103.      * @ORM\ManyToOne(targetEntity="App\Entity\Utilisateur\Utilisateur", inversedBy="adresses")
  104.      * @ORM\JoinColumn(nullable=true)
  105.      */
  106.     private $utilisateur;
  107.     /**
  108.      * @ORM\Column(name="date", type="datetime", nullable=true)
  109.      */
  110.     private $date;
  111.     /**
  112.      * @ORM\Column(name="dateMaj", type="datetime", nullable=true)
  113.      * @Gedmo\Timestampable(on="update")
  114.      */
  115.     private $dateMaj;
  116.     /**
  117.      * @ORM\Column(name="dateSuppression", type="datetime", nullable=true)
  118.      */
  119.     private $dateSuppression;
  120.     /**
  121.      * @ORM\Column(name="numero", type="string", length=255, nullable=true)
  122.      */
  123.     private $numero;
  124.     /**
  125.      * @ORM\Column(name="rue", type="string", length=255, nullable=true)
  126.      */
  127.     private $rue;
  128.     /**
  129.      * @ORM\Column(name="complement", type="string", length=255, nullable=true)
  130.      */
  131.     private $complement;
  132.     /**
  133.      * @ORM\Column(name="complement2", type="string", length=255, nullable=true)
  134.      */
  135.     private $complement2;
  136.     /**
  137.      * @ORM\Column(name="telephone", type="string", length=255, nullable=true)
  138.      */
  139.     private $telephone;
  140.     /**
  141.      * @ORM\Column(name="email", type="string", length=255, nullable=true)
  142.      */
  143.     private $email;
  144.     /**
  145.      * @ORM\Column(name="libelle", type="string", length=255, nullable=true)
  146.      */
  147.     private $libelle;
  148.     /**
  149.      * @ORM\Column(name="societe", type="string", length=255, nullable=true)
  150.      */
  151.     private $societe;
  152.     /**
  153.      * @ORM\Column(name="commentaire", type="text", nullable=true)
  154.      */
  155.     private $commentaire;
  156.     /**
  157.      * @ORM\Column(name="donnees_import", type="text", nullable=true)
  158.      */
  159.     private $donnesImport;
  160.     /**
  161.      * @ORM\OneToMany(targetEntity="App\Entity\GestionComerciale\CommandeFournisseur", mappedBy="adresseLivraison")
  162.      */
  163.     private $commandeFournisseurLivraison;
  164.     /**
  165.      * @ORM\Column(name="facturation_defaut", type="boolean", nullable=true)
  166.      */
  167.     protected $facturationDefaut;
  168.     /**
  169.      * @ORM\Column(name="livraison_defaut", type="boolean", nullable=true)
  170.      */
  171.     protected $livraisonDefaut;
  172.     /**
  173.      * @ORM\Column(name="visible", type="boolean", options={"default" : 1})
  174.      */
  175.     protected $visible;
  176.     /**
  177.      * @ORM\Column(name="latitude", type="string", length=255, nullable=true)
  178.      */
  179.     private $latitude;
  180.     /**
  181.      * @ORM\Column(name="longitude", type="string", length=255, nullable=true)
  182.      */
  183.     private $longitude;
  184.     /**
  185.      * @ORM\Column(type="string", length=255, nullable=true)
  186.      */
  187.     private $civilite;
  188.     /**
  189.      * @ORM\Column(type="string", length=255, nullable=true)
  190.      */
  191.     private $prenom;
  192.     /**
  193.      * @ORM\Column(type="string", length=255, nullable=true)
  194.      */
  195.     private $nom;
  196.     public function __construct()
  197.     {
  198.         $this->date                         = new Datetime();
  199.         $this->fiable                        true;
  200.         $this->visible                      true;
  201.         $this->commandeFournisseurLivraison = new ArrayCollection();
  202.         $this->commandeFacturation          = new ArrayCollection();
  203.         $this->commandeLivraison            = new ArrayCollection();
  204.     }
  205.     private function majAdresseFicheClient()
  206.     {
  207.         $client $this->getClient();
  208.         if (is_object($client)) {
  209.             $adresses $client->getAdresses();
  210.             if (is_array($adresses) && count($adresses)) {
  211.                 foreach ($adresses as $adresse) {
  212.                     if ($adresse->getVisible()) {
  213.                         if ($adresse->getId() == $this->getId() || $this->getId() == '') {
  214.                             $client->setVille($this->ville);
  215.                             $client->setCodePostal($this->codePostal);
  216.                             $client->setPays($this->pays);
  217.                         }
  218.                         break;
  219.                     }
  220.                 }
  221.             }
  222.         }
  223.     }
  224.     public function getId(): int
  225.     {
  226.         return $this->id;
  227.     }
  228.     public function setDate(?DateTime $date): Adresse
  229.     {
  230.         $this->date $date;
  231.         return $this;
  232.     }
  233.     public function getDate(): ?DateTime
  234.     {
  235.         return $this->date;
  236.     }
  237.     public function setDateMaj(?DateTime $dateMaj): Adresse
  238.     {
  239.         $this->dateMaj $dateMaj;
  240.         return $this;
  241.     }
  242.     public function getDateMaj(): ?DateTime
  243.     {
  244.         return $this->dateMaj;
  245.     }
  246.     public function setDateSuppression(?DateTime $dateSuppression): Adresse
  247.     {
  248.         $this->dateSuppression $dateSuppression;
  249.         return $this;
  250.     }
  251.     public function getDateSuppression(): ?DateTime
  252.     {
  253.         return $this->dateSuppression;
  254.     }
  255.     public function setNumero(?string $numero): Adresse
  256.     {
  257.         $this->numero $numero;
  258.         return $this;
  259.     }
  260.     public function getNumero(): ?string
  261.     {
  262.         return $this->numero;
  263.     }
  264.     public function setRue(?string $rue): Adresse
  265.     {
  266.         $this->rue $rue;
  267.         return $this;
  268.     }
  269.     public function getRue(): ?string
  270.     {
  271.         return $this->abreviation($this->rue);
  272.     }
  273.     public function setComplement(?string $complement): Adresse
  274.     {
  275.         $this->complement $complement;
  276.         return $this;
  277.     }
  278.     public function getComplement(): ?string
  279.     {
  280.         return $this->abreviation($this->complement);
  281.     }
  282.     public function setLibelle(?string $libelle): Adresse
  283.     {
  284.         $this->libelle $libelle;
  285.         $this->societe $libelle;
  286.         return $this;
  287.     }
  288.     public function getLibelle(): ?string
  289.     {
  290.         return $this->abreviation($this->libelle);
  291.     }
  292.     public function setPays(?Zone $pays): Adresse
  293.     {
  294.         $this->pays $pays;
  295.         $this->majAdresseFicheClient();
  296.         return $this;
  297.     }
  298.     public function getPays(): ?Zone
  299.     {
  300.         return $this->pays;
  301.     }
  302.     public function setVille(?Zone $ville): Adresse
  303.     {
  304.         $this->ville $ville;
  305.         $this->majAdresseFicheClient();
  306.         return $this;
  307.     }
  308.     public function getVille(): ?Zone
  309.     {
  310.         return $this->ville;
  311.     }
  312.     public function setCodePostal(?Zone $codePostal): Adresse
  313.     {
  314.         $this->codePostal $codePostal;
  315.         $this->majAdresseFicheClient();
  316.         return $this;
  317.     }
  318.     public function getCodePostal(): ?Zone
  319.     {
  320.         return $this->codePostal;
  321.     }
  322.     public function setClient(?Client $client): Adresse
  323.     {
  324.         $this->client $client;
  325.         return $this;
  326.     }
  327.     public function getClient(): ?Client
  328.     {
  329.         return $this->client;
  330.     }
  331.     public function setUtilisateur(?Utilisateur $utilisateur): Adresse
  332.     {
  333.         $this->utilisateur $utilisateur;
  334.         return $this;
  335.     }
  336.     public function getUtilisateur(): ?Utilisateur
  337.     {
  338.         return $this->utilisateur;
  339.     }
  340.     public function setCommentaire(?string $commentaire): Adresse
  341.     {
  342.         $this->commentaire $commentaire;
  343.         return $this;
  344.     }
  345.     public function getCommentaire(): ?string
  346.     {
  347.         return $this->commentaire;
  348.     }
  349.     public function setTransporteur(?Transporteur $transporteur): Adresse
  350.     {
  351.         $this->transporteur $transporteur;
  352.         return $this;
  353.     }
  354.     public function getTransporteur(): ?Transporteur
  355.     {
  356.         return $this->transporteur;
  357.     }
  358.     public function setFournisseur(?Fournisseur $fournisseur): Adresse
  359.     {
  360.         $this->fournisseur $fournisseur;
  361.         return $this;
  362.     }
  363.     public function getFournisseur(): ?Fournisseur
  364.     {
  365.         return $this->fournisseur;
  366.     }
  367.     public function __toString()
  368.     {
  369.         //return $this->abreviation($this->libelle);
  370.         $libelleAdresse $this->getLibelle()." ";
  371.         if ($this->getNumero() != "") {
  372.             $libelleAdresse .= $this->getNumero().', ';
  373.         }
  374.         if ($this->getRue() != "") {
  375.             $libelleAdresse .= $this->getRue().' ';
  376.         }
  377.         if ($this->getComplement() != "") {
  378.             $libelleAdresse .= $this->getComplement().' ';
  379.         }
  380.         if ($this->getComplement2() != "") {
  381.             $libelleAdresse .= $this->getComplement2().' ';
  382.         }
  383.         if (is_object($this->getCodePostal())) {
  384.             $libelleAdresse .= $this->getCodePostal()->getCodePostal().' ';
  385.         }
  386.         if (is_object($this->getVille())) {
  387.             $libelleAdresse .= $this->getVille()->getTitre().' ';
  388.         }
  389.         if (is_object($this->getPays())) {
  390.             $libelleAdresse .= $this->getPays()->getTitre();
  391.         }
  392.         return $libelleAdresse;
  393.     }
  394.     public function addCommandeLivraison(Commande $commandeLivraison): Adresse
  395.     {
  396.         $this->commandeLivraison[] = $commandeLivraison;
  397.         return $this;
  398.     }
  399.     public function removeCommandeLivraison(Commande $commandeLivraison)
  400.     {
  401.         $this->commandeLivraison->removeElement($commandeLivraison);
  402.     }
  403.     public function getCommandeLivraison(): Collection
  404.     {
  405.         return $this->commandeLivraison;
  406.     }
  407.     public function addCommandeFacturation(Commande $commandeFacturation): Adresse
  408.     {
  409.         $this->commandeFacturation[] = $commandeFacturation;
  410.         return $this;
  411.     }
  412.     public function removeCommandeFacturation(Commande $commandeFacturation)
  413.     {
  414.         $this->commandeFacturation->removeElement($commandeFacturation);
  415.     }
  416.     public function getCommandeFacturation(): Collection
  417.     {
  418.         return $this->commandeFacturation;
  419.     }
  420.     /**
  421.      * @ORM\PreRemove
  422.      */
  423.     public function supprimerRelationAdresse()
  424.     {
  425.         //    $this->libelle = "AAAA";
  426.         //  $this->commandeFacturation->setTotal('999999');
  427.     }
  428.     public function setIdImport(?string $idImport): Adresse
  429.     {
  430.         $this->idImport $idImport;
  431.         return $this;
  432.     }
  433.     public function getIdImport(): ?string
  434.     {
  435.         return $this->idImport;
  436.     }
  437.     public function setDonnesImport(?string $donnesImport): Adresse
  438.     {
  439.         $this->donnesImport $donnesImport;
  440.         return $this;
  441.     }
  442.     public function getDonnesImport(): ?string
  443.     {
  444.         return $this->donnesImport;
  445.     }
  446.     public function setZoneLivraison(?ZoneLivraison $zoneLivraison): Adresse
  447.     {
  448.         $this->zoneLivraison $zoneLivraison;
  449.         return $this;
  450.     }
  451.     public function getZoneLivraison(): ?ZoneLivraison
  452.     {
  453.         return $this->zoneLivraison;
  454.     }
  455.     public function addCommandeFournisseurLivraison(CommandeFournisseur $commandeFournisseurLivraison): Adresse
  456.     {
  457.         $this->commandeFournisseurLivraison[] = $commandeFournisseurLivraison;
  458.         return $this;
  459.     }
  460.     public function removeCommandeFournisseurLivraison(CommandeFournisseur $commandeFournisseurLivraison)
  461.     {
  462.         $this->commandeFournisseurLivraison->removeElement($commandeFournisseurLivraison);
  463.     }
  464.     public function getCommandeFournisseurLivraison(): Collection
  465.     {
  466.         return $this->commandeFournisseurLivraison;
  467.     }
  468.     public function setFiable(?bool $fiable): Adresse
  469.     {
  470.         $this->fiable $fiable;
  471.         return $this;
  472.     }
  473.     public function getFiable(): ?bool
  474.     {
  475.         return $this->fiable;
  476.     }
  477.     public function setComplement2(?string $complement2): Adresse
  478.     {
  479.         $this->complement2 $complement2;
  480.         return $this;
  481.     }
  482.     public function getComplement2(): ?string
  483.     {
  484.         return $this->abreviation($this->complement2);
  485.     }
  486.     public function setFacturationDefaut(?bool $facturationDefaut): Adresse
  487.     {
  488.         $this->facturationDefaut $facturationDefaut;
  489.         return $this;
  490.     }
  491.     public function getFacturationDefaut(): ?bool
  492.     {
  493.         return $this->facturationDefaut;
  494.     }
  495.     public function setLivraisonDefaut(?bool $livraisonDefaut): Adresse
  496.     {
  497.         $this->livraisonDefaut $livraisonDefaut;
  498.         return $this;
  499.     }
  500.     public function getLivraisonDefaut(): ?bool
  501.     {
  502.         return $this->livraisonDefaut;
  503.     }
  504.     public function setTelephone(?string $telephone): Adresse
  505.     {
  506.         $this->telephone $telephone;
  507.         return $this;
  508.     }
  509.     public function getTelephone(): ?string
  510.     {
  511.         return $this->telephone;
  512.     }
  513.     public function setEmail(?string $email): Adresse
  514.     {
  515.         $this->email $email;
  516.         return $this;
  517.     }
  518.     public function getEmail(): ?string
  519.     {
  520.         return $this->email;
  521.     }
  522.     public function setIdPrestashop(?string $idPrestashop): Adresse
  523.     {
  524.         $this->id_prestashop $idPrestashop;
  525.         return $this;
  526.     }
  527.     public function getIdPrestashop(): ?string
  528.     {
  529.         return $this->id_prestashop;
  530.     }
  531.     public function setVisible(bool $visible): Adresse
  532.     {
  533.         $this->visible $visible;
  534.         return $this;
  535.     }
  536.     public function getVisible(): bool
  537.     {
  538.         return $this->visible;
  539.     }
  540.     public function setCedex(?bool $cedex): Adresse
  541.     {
  542.         $this->cedex $cedex;
  543.         return $this;
  544.     }
  545.     public function getCedex(): ?bool
  546.     {
  547.         return $this->cedex;
  548.     }
  549.     public function setFacturationExpeditionDefaut(?bool $facturationExpeditionDefaut): Adresse
  550.     {
  551.         $this->facturationExpeditionDefaut $facturationExpeditionDefaut;
  552.         return $this;
  553.     }
  554.     public function getFacturationExpeditionDefaut(): ?bool
  555.     {
  556.         return $this->facturationExpeditionDefaut;
  557.     }
  558.     public function setLatitude(?string $latitude): Adresse
  559.     {
  560.         $this->latitude $latitude;
  561.         return $this;
  562.     }
  563.     public function getLatitude(): ?string
  564.     {
  565.         return $this->latitude;
  566.     }
  567.     public function setLongitude(?string $longitude): Adresse
  568.     {
  569.         $this->longitude $longitude;
  570.         return $this;
  571.     }
  572.     public function getLongitude(): ?string
  573.     {
  574.         return $this->longitude;
  575.     }
  576.     public function setSociete(?string $societe): Adresse
  577.     {
  578.         $this->societe $societe;
  579.         return $this;
  580.     }
  581.     public function getSociete(): string
  582.     {
  583.         return $this->abreviation($this->societe);
  584.     }
  585.     public function setIdImport2(?string $idImport2): self
  586.     {
  587.         $this->idImport2 $idImport2;
  588.         return $this;
  589.     }
  590.     public function getIdImport2(): ?string
  591.     {
  592.         return $this->idImport2;
  593.     }
  594.     public function abreviation($str): string
  595.     {
  596.         $search  = [
  597.             'allée',
  598.             'avenue.',
  599.             'boulevard',
  600.             'carrefour',
  601.             'chemin',
  602.             'chaussée',
  603.             'impasse',
  604.             'lotissement',
  605.             'passage',
  606.             'place',
  607.             'résidence',
  608.             'route',
  609.             'batiment',
  610.             'étage',
  611.             'escalier',
  612.         ];
  613.         $replace = ['All.''Av.''Bd.''Car.''Che.''Chs.''Imp.''Lot.''Pas.''Pl.''Res.''Rte.''Bat.''Et.''Esc.'];
  614.         return str_replace($search$replace$str);
  615.     }
  616.     /**
  617.      * @ORM\PreRemove()
  618.      */
  619.     public function preRemove()
  620.     {
  621.         foreach ($this->getCommandeLivraison() as $cl) {
  622.             /** @var Commande $cl */
  623.             $cl->setAdresseLivraison(null);
  624.             $cl->setAdresseFacturation(null);
  625.         }
  626.     }
  627.     public function getCivilite(): ?string
  628.     {
  629.         return $this->civilite;
  630.     }
  631.     public function setCivilite(?string $civilite): self
  632.     {
  633.         $this->civilite $civilite;
  634.         return $this;
  635.     }
  636.     public function getPrenom(): ?string
  637.     {
  638.         return $this->prenom;
  639.     }
  640.     public function setPrenom(?string $prenom): self
  641.     {
  642.         $this->prenom $prenom;
  643.         return $this;
  644.     }
  645.     public function getNom(): ?string
  646.     {
  647.         return $this->nom;
  648.     }
  649.     public function setNom(?string $nom): self
  650.     {
  651.         $this->nom $nom;
  652.         return $this;
  653.     }
  654. }