src/Entity/Cliente.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Validator as PerseoAssert;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. use JMS\Serializer\Annotation as JMS;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. use Symfony\Component\HttpFoundation\File\File;
  12. use Symfony\Component\Intl\Countries;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  15. /**
  16.  * @ORM\Table(name="cliente")
  17.  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true)
  18.  * @ORM\Entity(repositoryClass="App\Repository\ClienteRepository")
  19.  * @Vich\Uploadable
  20.  * @UniqueEntity("identificacion")
  21.  * @PerseoAssert\ContraintsValidarEntidadCp()
  22.  */
  23. class Cliente
  24. {
  25.     /**
  26.      * @ORM\Id
  27.      * @ORM\Column(type="bigint", options={"unsigned":true})
  28.      * @ORM\GeneratedValue(strategy="AUTO")
  29.      * @JMS\Groups({
  30.      *     "api_v1_cliente_serialize",
  31.      *     "api_v1_cliente_list_serialize",
  32.      *     "api_v1_valoracion_serialize",
  33.      *     "api_v1_operacion_list_serialize",
  34.      *     "api_v1_operacion_show_serialize"
  35.      * })
  36.      */
  37.     public $id;
  38.     /**
  39.      * @ORM\Column(type="string", nullable=true, name="razon_social")
  40.      * @JMS\Groups({
  41.      *      "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  42.      *      "api_v1_cliente_list_serialize",
  43.      *      "api_v1_valoracion_serialize",
  44.      *      "api_v1_operacion_list_serialize",
  45.      *      "api_v1_operacion_show_serialize"
  46.      *  })
  47.      */
  48.     protected $razonSocial;
  49.     /**
  50.      * @ORM\Column(type="string", nullable=true, name="alias")
  51.      * @JMS\Groups({
  52.      *     "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  53.      *     "api_v1_valoracion_serialize"
  54.      * })
  55.      */
  56.     protected $alias;
  57.     /**
  58.      * @ORM\Column(type="string", nullable=true, options={"comment":"DNI, Pasaporte, Licencia de Condución"})
  59.      * @JMS\Groups({
  60.      *     "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  61.      *     "api_v1_cliente_list_serialize",
  62.      *     "api_v1_valoracion_serialize"
  63.      *  })
  64.      */
  65.     protected $identificacionTipo;
  66.     /**
  67.      * @ORM\Column(type="string", nullable=true)
  68.      * @JMS\Groups({
  69.      *      "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  70.      *      "api_v1_cliente_list_serialize",
  71.      *      "api_v1_valoracion_serialize",
  72.      *      "api_v1_operacion_show_serialize"
  73.      *  })
  74.      */
  75.     protected $identificacion;
  76.     /**
  77.      * @ORM\Column(type="string", nullable=true)
  78.      * @JMS\Groups({
  79.      *     "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  80.      *     "api_v1_valoracion_serialize",
  81.      *     "api_v1_operacion_show_serialize"
  82.      * })
  83.      */
  84.     protected $direccion;
  85.     /**
  86.      * @ORM\Column(type="string", length=12, nullable=true)
  87.      * @Assert\Length(min = 5, max = 12)
  88.      * @JMS\Groups({
  89.      *      "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  90.      *      "api_v1_valoracion_serialize",
  91.      *      "api_v1_operacion_show_serialize"
  92.      *  })
  93.      */
  94.     protected $cp;
  95.     /**
  96.      * @ORM\Column(type="string", nullable=true)
  97.      * @JMS\Groups({
  98.      *      "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  99.      *      "api_v1_cliente_list_serialize",
  100.      *      "api_v1_valoracion_serialize",
  101.      *      "api_v1_operacion_show_serialize"
  102.      *  })
  103.      */
  104.     protected $region;
  105.     /**
  106.      * @ORM\Column(type="string", nullable=true)
  107.      * @JMS\Groups({
  108.      *       "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  109.      *       "api_v1_cliente_list_serialize",
  110.      *       "api_v1_valoracion_serialize",
  111.      *       "api_v1_operacion_show_serialize"
  112.      *   })
  113.      *  })
  114.      */
  115.     protected $ciudad;
  116.     /**
  117.      * @ORM\Column(type="string", nullable=true)
  118.      * @JMS\Groups({
  119.      *     "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  120.      *     "api_v1_valoracion_serialize",
  121.      *     "api_v1_operacion_show_serialize"
  122.      * })
  123.      */
  124.     protected $telefono;
  125.     /**
  126.      * @ORM\Column(type="string", nullable=true)
  127.      * @JMS\Groups({
  128.      *      "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  129.      *      "api_v1_valoracion_serialize",
  130.      *      "api_v1_operacion_show_serialize"
  131.      *  })
  132.      */
  133.     protected $email;
  134.     /**
  135.      * @ORM\Column(type="string", nullable=true)
  136.      * @JMS\Groups({
  137.      *      "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  138.      *      "api_v1_valoracion_serialize",
  139.      *      "api_v1_operacion_show_serialize"
  140.      *  })
  141.      */
  142.     protected $identificacionFrontal;
  143.     /**
  144.      * @Vich\UploadableField(mapping="cliente", fileNameProperty="identificacionFrontal")
  145.      * @Assert\File(
  146.      *      maxSize = "15M",
  147.      *      mimeTypes = {
  148.      *          "image/jpeg",
  149.      *          "image/png",
  150.      *          "image/gif",
  151.      *          "image/webp",
  152.      *          "application/pdf"
  153.      *      },
  154.      *      mimeTypesMessage = "Solo se permiten imágenes (JPEG, PNG, GIF, WEBP) o archivos PDF."
  155.      *  )
  156.      * @var File
  157.      */
  158.     protected $identificacionFrontalFile;
  159.     /**
  160.      * @ORM\Column(type="string", nullable=true)
  161.      * @JMS\Groups({
  162.      *      "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  163.      *      "api_v1_valoracion_serialize",
  164.      *      "api_v1_operacion_show_serialize"
  165.      *  })
  166.      */
  167.     protected $identificacionTrasera;
  168.     /**
  169.      * @Vich\UploadableField(mapping="cliente", fileNameProperty="identificacionTrasera")
  170.      * @Assert\File(
  171.      *      maxSize = "15M",
  172.      *      mimeTypes = {
  173.      *          "image/jpeg",
  174.      *          "image/png",
  175.      *          "image/gif",
  176.      *          "image/webp",
  177.      *          "application/pdf"
  178.      *      },
  179.      *      mimeTypesMessage = "Solo se permiten imágenes (JPEG, PNG, GIF, WEBP) o archivos PDF."
  180.      *  )
  181.      * @var File
  182.      */
  183.     protected $identificacionTraseraFile;
  184.     /**
  185.      * @ORM\Column(type="string", length=2, nullable=true)
  186.      * @JMS\Groups({
  187.      *      "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  188.      *      "api_v1_cliente_list_serialize",
  189.      *      "api_v1_valoracion_serialize",
  190.      *      "api_v1_operacion_show_serialize"
  191.      *  })
  192.      */
  193.     protected $idioma;
  194.     /**
  195.      * @ORM\Column(type="string", nullable=true, name="entidad_bancaria")
  196.      * @JMS\Groups({
  197.      *       "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  198.      *       "api_v1_valoracion_serialize",
  199.      *       "api_v1_operacion_show_serialize"
  200.      *   })
  201.      */
  202.     protected $entidadBancaria;
  203.     /**
  204.      * @ORM\Column(type="string", nullable=true)
  205.      * @JMS\Groups({
  206.      *       "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  207.      *       "api_v1_valoracion_serialize",
  208.      *       "api_v1_operacion_show_serialize"
  209.      *   })
  210.      */
  211.     protected $iban;
  212.     /**
  213.      * @ORM\Column(type="string", nullable=true)
  214.      * @JMS\Groups({
  215.      *       "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  216.      *       "api_v1_valoracion_serialize",
  217.      *       "api_v1_operacion_show_serialize"
  218.      *   })
  219.      */
  220.     protected $swift;
  221.     /**
  222.      * @ORM\Column(type="text", nullable=true)
  223.      * @JMS\Groups({
  224.      *     "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  225.      *     "api_v1_valoracion_serialize"
  226.      * })
  227.      */
  228.     protected $observaciones;
  229.     /**
  230.      * @ORM\Column(type="datetime", nullable=true, name="deleted_at")
  231.      * @JMS\Groups({
  232.      *     "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  233.      *     "api_v1_cliente_list_serialize",
  234.      *     "api_v1_valoracion_serialize",
  235.      *     "api_v1_operacion_list_serialize",
  236.      *     "api_v1_operacion_show_serialize"
  237.      *   })
  238.      */
  239.     protected $deletedAt;
  240.     /**
  241.      * @ORM\Column(type="datetime", nullable=false, name="updated_at", options={"default":"2022-01-01 00:00:00"})
  242.      * @Gedmo\Timestampable(on="update")
  243.      */
  244.     protected $updatedAt;
  245.     /**
  246.      * @ORM\Column(type="datetime", nullable=false, name="created_at", options={"default":"2022-01-01 00:00:00"})
  247.      * @Gedmo\Timestampable(on="create")
  248.      */
  249.     protected $createdAt;
  250.     /**
  251.      * @ORM\Column(type="string", length=2, nullable=true, name="pais")
  252.      * @JMS\Groups({
  253.      *      "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  254.      *      "api_v1_cliente_list_serialize",
  255.      *      "api_v1_valoracion_serialize",
  256.      *      "api_v1_operacion_show_serialize"
  257.      *  })
  258.      */
  259.     protected $pais;
  260.     /**
  261.      * @ORM\OneToOne(targetEntity="App\Entity\User", mappedBy="cliente")
  262.      */
  263.     protected $user;
  264.     /**
  265.      * @ORM\OneToMany(targetEntity="App\Entity\Valoracion", mappedBy="cliente")
  266.      */
  267.     protected $valoraciones;
  268.     /**
  269.      * @ORM\OneToMany(targetEntity=\App\Entity\ActividadAbstract::class, mappedBy="cliente")
  270.      */
  271.     private $actividades;
  272.     /**
  273.      * @ORM\OneToMany(targetEntity="App\Entity\Operacion", mappedBy="cliente")
  274.      */
  275.     protected $operaciones;
  276.     /*
  277.      * @ORM\ManyToOne(targetEntity="App\Entity\Ciudad", inversedBy="clientes")
  278.      * @ORM\JoinColumn(name="ciudad_id", referencedColumnName="id")
  279.      */
  280.     //protected $ciudad;
  281.     /**
  282.      * @ORM\ManyToOne(targetEntity="App\Entity\CCAA", inversedBy="clientes")
  283.      * @ORM\JoinColumn(name="ccaa_id", referencedColumnName="id")
  284.      * @JMS\Type(CCAA::class)
  285.      * @JMS\Groups({
  286.      *     "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  287.      *     "api_v1_valoracion_serialize",
  288.      *     "api_v1_operacion_show_serialize"
  289.      * })
  290.      */
  291.     protected $ccaa;
  292.     /**
  293.      * @ORM\ManyToOne(targetEntity="App\Entity\Provincia", inversedBy="clientes")
  294.      * @ORM\JoinColumn(name="provincia_id", referencedColumnName="id")
  295.      * @JMS\Type(Provincia::class)
  296.      * @JMS\Groups({
  297.      *      "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  298.      *      "api_v1_valoracion_serialize",
  299.      *      "api_v1_operacion_show_serialize"
  300.      *  })
  301.      */
  302.     protected $provincia;
  303.     public function __construct()
  304.     {
  305.         $this->valoraciones = new ArrayCollection();
  306.         $this->operaciones = new ArrayCollection();
  307.         $this->actividades = new ArrayCollection();
  308.     }
  309.     public function __toString(): string
  310.     {
  311.         return $this->getRazonSocial() ? $this->getRazonSocial() : ($this->getUser() ? $this->getUser()?->getNombreCompleto() : '---');
  312.     }
  313.     public function getId(): ?string
  314.     {
  315.         return $this->id;
  316.     }
  317.     public function getRazonSocial(): ?string
  318.     {
  319.         return $this->razonSocial;
  320.     }
  321.     public function setRazonSocial(?string $razonSocial): self
  322.     {
  323.         $this->razonSocial $razonSocial;
  324.         return $this;
  325.     }
  326.     public function getAlias(): ?string
  327.     {
  328.         return $this->alias;
  329.     }
  330.     public function setAlias(?string $alias): self
  331.     {
  332.         $this->alias $alias;
  333.         return $this;
  334.     }
  335.     public function getIdentificacionTipo(): ?string
  336.     {
  337.         return $this->identificacionTipo;
  338.     }
  339.     public function setIdentificacionTipo(?string $identificacionTipo): self
  340.     {
  341.         $this->identificacionTipo $identificacionTipo;
  342.         return $this;
  343.     }
  344.     public function getIdentificacion(): ?string
  345.     {
  346.         return $this->identificacion;
  347.     }
  348.     public function setIdentificacion(?string $identificacion): self
  349.     {
  350.         $this->identificacion $identificacion;
  351.         return $this;
  352.     }
  353.     public function getIdentificacionFrontal(): ?string
  354.     {
  355.         return $this->identificacionFrontal;
  356.     }
  357.     public function setIdentificacionFrontal(?string $identificacionFrontal): self
  358.     {
  359.         $this->identificacionFrontal $identificacionFrontal;
  360.         return $this;
  361.     }
  362.     public function getIdentificacionFrontalFile(): ?File
  363.     {
  364.         return $this->identificacionFrontalFile;
  365.     }
  366.     public function setIdentificacionFrontalFile(?File $identificacionFrontalFile): self
  367.     {
  368.         $this->identificacionFrontalFile $identificacionFrontalFile;
  369.         if ($identificacionFrontalFile) {
  370.             // if 'updatedAt' is not defined in your entity, use another property
  371.             $this->setUpdatedAt(new \DateTime('now'));
  372.         }
  373.         return $this;
  374.     }
  375.     public function getIdentificacionTrasera(): ?string
  376.     {
  377.         return $this->identificacionTrasera;
  378.     }
  379.     public function setIdentificacionTrasera(?string $identificacionTrasera): self
  380.     {
  381.         $this->identificacionTrasera $identificacionTrasera;
  382.         return $this;
  383.     }
  384.     public function getIdentificacionTraseraFile(): ?File
  385.     {
  386.         return $this->identificacionTraseraFile;
  387.     }
  388.     public function setIdentificacionTraseraFile(?File $identificacionTraseraFile): self
  389.     {
  390.         $this->identificacionTraseraFile $identificacionTraseraFile;
  391.         if ($identificacionTraseraFile) {
  392.             // if 'updatedAt' is not defined in your entity, use another property
  393.             $this->setUpdatedAt(new \DateTime('now'));
  394.         }
  395.         return $this;
  396.     }
  397.     public function getIdioma(): ?string
  398.     {
  399.         return $this->idioma;
  400.     }
  401.     public function setIdioma(?string $idioma): self
  402.     {
  403.         $this->idioma $idioma;
  404.         return $this;
  405.     }
  406.     public function getEntidadBancaria(): ?string
  407.     {
  408.         return $this->entidadBancaria;
  409.     }
  410.     public function setEntidadBancaria(?string $entidadBancaria): self
  411.     {
  412.         $this->entidadBancaria $entidadBancaria;
  413.         return $this;
  414.     }
  415.     public function getIban(): ?string
  416.     {
  417.         return $this->iban;
  418.     }
  419.     public function setIban(?string $iban): self
  420.     {
  421.         $this->iban $iban;
  422.         return $this;
  423.     }
  424.     public function getObservaciones(): ?string
  425.     {
  426.         return $this->observaciones;
  427.     }
  428.     public function setObservaciones(?string $observaciones): self
  429.     {
  430.         $this->observaciones $observaciones;
  431.         return $this;
  432.     }
  433.     public function getDeletedAt(): ?\DateTimeInterface
  434.     {
  435.         return $this->deletedAt;
  436.     }
  437.     public function setDeletedAt(?\DateTimeInterface $deletedAt): self
  438.     {
  439.         $this->deletedAt $deletedAt;
  440.         return $this;
  441.     }
  442.     public function getUpdatedAt(): ?\DateTimeInterface
  443.     {
  444.         return $this->updatedAt;
  445.     }
  446.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  447.     {
  448.         $this->updatedAt $updatedAt;
  449.         return $this;
  450.     }
  451.     public function getCreatedAt(): ?\DateTimeInterface
  452.     {
  453.         return $this->createdAt;
  454.     }
  455.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  456.     {
  457.         $this->createdAt $createdAt;
  458.         return $this;
  459.     }
  460.     public function getUser(): ?User
  461.     {
  462.         return $this->user;
  463.     }
  464.     public function setUser(?User $user): self
  465.     {
  466.         // unset the owning side of the relation if necessary
  467.         if ($user === null && $this->user !== null) {
  468.             $this->user->setCliente(null);
  469.         }
  470.         // set the owning side of the relation if necessary
  471.         if ($user !== null && $user->getCliente() !== $this) {
  472.             $user->setCliente($this);
  473.         }
  474.         $this->user $user;
  475.         return $this;
  476.     }
  477.     /**
  478.      * @return Collection|Valoracion[]
  479.      */
  480.     public function getValoraciones(): Collection
  481.     {
  482.         return $this->valoraciones;
  483.     }
  484.     public function addValoracione(Valoracion $valoracione): self
  485.     {
  486.         if (!$this->valoraciones->contains($valoracione)) {
  487.             $this->valoraciones[] = $valoracione;
  488.             $valoracione->setCliente($this);
  489.         }
  490.         return $this;
  491.     }
  492.     public function removeValoracione(Valoracion $valoracione): self
  493.     {
  494.         if ($this->valoraciones->removeElement($valoracione)) {
  495.             // set the owning side to null (unless already changed)
  496.             if ($valoracione->getCliente() === $this) {
  497.                 $valoracione->setCliente(null);
  498.             }
  499.         }
  500.         return $this;
  501.     }
  502.     /**
  503.      * @return Collection|Operacion[]
  504.      */
  505.     public function getOperaciones(): Collection
  506.     {
  507.         return $this->operaciones;
  508.     }
  509.     public function addOperacione(Operacion $operacione): self
  510.     {
  511.         if (!$this->operaciones->contains($operacione)) {
  512.             $this->operaciones[] = $operacione;
  513.             $operacione->setCliente($this);
  514.         }
  515.         return $this;
  516.     }
  517.     public function removeOperacione(Operacion $operacione): self
  518.     {
  519.         if ($this->operaciones->removeElement($operacione)) {
  520.             // set the owning side to null (unless already changed)
  521.             if ($operacione->getCliente() === $this) {
  522.                 $operacione->setCliente(null);
  523.             }
  524.         }
  525.         return $this;
  526.     }
  527.     public function getTelefono(): ?string
  528.     {
  529.         return $this->telefono;
  530.     }
  531.     public function setTelefono(?string $telefono): self
  532.     {
  533.         $this->telefono $telefono;
  534.         return $this;
  535.     }
  536.     public function getEmail(): ?string
  537.     {
  538.         return $this->email;
  539.     }
  540.     public function setEmail(?string $email): self
  541.     {
  542.         $this->email $email;
  543.         return $this;
  544.     }
  545.     public function getDireccion(): ?string
  546.     {
  547.         return $this->direccion;
  548.     }
  549.     public function setDireccion(?string $direccion): self
  550.     {
  551.         $this->direccion $direccion;
  552.         return $this;
  553.     }
  554.     public function getCp(): ?string
  555.     {
  556.         return $this->cp;
  557.     }
  558.     public function setCp(?string $cp): self
  559.     {
  560.         $this->cp $cp;
  561.         return $this;
  562.     }
  563.     public function getCiudad(): ?string
  564.     {
  565.         return $this->ciudad;
  566.     }
  567.     public function setCiudad(?string $ciudad): self
  568.     {
  569.         $this->ciudad $ciudad;
  570.         return $this;
  571.     }
  572.     public function getCcaa(): ?CCAA
  573.     {
  574.         return $this->ccaa;
  575.     }
  576.     public function setCcaa(?CCAA $ccaa): self
  577.     {
  578.         $this->ccaa $ccaa;
  579.         return $this;
  580.     }
  581.     public function getPais(): ?string
  582.     {
  583.         return $this->pais;
  584.     }
  585.     public function setPais(?string $pais): self
  586.     {
  587.         $this->pais $pais;
  588.         return $this;
  589.     }
  590.     public function getProvincia(): ?Provincia
  591.     {
  592.         return $this->provincia;
  593.     }
  594.     public function setProvincia(?Provincia $provincia): self
  595.     {
  596.         $this->provincia $provincia;
  597.         return $this;
  598.     }
  599.     /**
  600.      * @return Collection<int, ActividadAbstract>
  601.      */
  602.     public function getActividades(): Collection
  603.     {
  604.         return $this->actividades;
  605.     }
  606.     public function addActividade(ActividadAbstract $actividade): static
  607.     {
  608.         if (!$this->actividades->contains($actividade)) {
  609.             $this->actividades->add($actividade);
  610.             $actividade->setCliente($this);
  611.         }
  612.         return $this;
  613.     }
  614.     public function removeActividade(ActividadAbstract $actividade): static
  615.     {
  616.         if ($this->actividades->removeElement($actividade)) {
  617.             // set the owning side to null (unless already changed)
  618.             if ($actividade->getCliente() === $this) {
  619.                 $actividade->setCliente(null);
  620.             }
  621.         }
  622.         return $this;
  623.     }
  624.     public function getRegion(): ?string
  625.     {
  626.         return $this->region;
  627.     }
  628.     public function setRegion(?string $region): static
  629.     {
  630.         $this->region $region;
  631.         return $this;
  632.     }
  633.     public function getExportPais(): ?string
  634.     {
  635.         return $this->getPais() ? Countries::getName($this->getPais()) : null;
  636.     }
  637.     public function getSwift(): ?string
  638.     {
  639.         return $this->swift;
  640.     }
  641.     public function setSwift(?string $swift): static
  642.     {
  643.         $this->swift $swift;
  644.         return $this;
  645.     }
  646. }