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