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.      * @JMS\Groups({
  249.      *      "api_v1_cliente_serialize",
  250.      *      "api_v1_cliente_list_serialize",
  251.      *      "api_v1_valoracion_serialize",
  252.      *      "api_v1_operacion_list_serialize",
  253.      *      "api_v1_operacion_show_serialize"
  254.      *  })
  255.      */
  256.     protected $createdAt;
  257.     /**
  258.      * @ORM\Column(type="string", length=2, nullable=true, name="pais")
  259.      * @JMS\Groups({
  260.      *      "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  261.      *      "api_v1_cliente_list_serialize",
  262.      *      "api_v1_valoracion_serialize",
  263.      *      "api_v1_operacion_show_serialize"
  264.      *  })
  265.      */
  266.     protected $pais;
  267.     /**
  268.      * @ORM\OneToOne(targetEntity="App\Entity\User", mappedBy="cliente")
  269.      */
  270.     protected $user;
  271.     /**
  272.      * @ORM\OneToMany(targetEntity="App\Entity\Valoracion", mappedBy="cliente")
  273.      */
  274.     protected $valoraciones;
  275.     /**
  276.      * @ORM\OneToMany(targetEntity=\App\Entity\ActividadAbstract::class, mappedBy="cliente")
  277.      */
  278.     private $actividades;
  279.     /**
  280.      * @ORM\OneToMany(targetEntity="App\Entity\Operacion", mappedBy="cliente")
  281.      */
  282.     protected $operaciones;
  283.     /*
  284.      * @ORM\ManyToOne(targetEntity="App\Entity\Ciudad", inversedBy="clientes")
  285.      * @ORM\JoinColumn(name="ciudad_id", referencedColumnName="id")
  286.      */
  287.     //protected $ciudad;
  288.     /**
  289.      * @ORM\ManyToOne(targetEntity="App\Entity\CCAA", inversedBy="clientes")
  290.      * @ORM\JoinColumn(name="ccaa_id", referencedColumnName="id")
  291.      * @JMS\Type(CCAA::class)
  292.      * @JMS\Groups({
  293.      *     "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  294.      *     "api_v1_valoracion_serialize",
  295.      *     "api_v1_operacion_show_serialize"
  296.      * })
  297.      */
  298.     protected $ccaa;
  299.     /**
  300.      * @ORM\ManyToOne(targetEntity="App\Entity\Provincia", inversedBy="clientes")
  301.      * @ORM\JoinColumn(name="provincia_id", referencedColumnName="id")
  302.      * @JMS\Type(Provincia::class)
  303.      * @JMS\Groups({
  304.      *      "api_v1_cliente_serialize", "api_v1_cliente_deserialize",
  305.      *      "api_v1_valoracion_serialize",
  306.      *      "api_v1_operacion_show_serialize"
  307.      *  })
  308.      */
  309.     protected $provincia;
  310.     public function __construct()
  311.     {
  312.         $this->valoraciones = new ArrayCollection();
  313.         $this->operaciones = new ArrayCollection();
  314.         $this->actividades = new ArrayCollection();
  315.     }
  316.     public function __toString(): string
  317.     {
  318.         return $this->getRazonSocial() ? $this->getRazonSocial() : ($this->getUser() ? $this->getUser()?->getNombreCompleto() : '---');
  319.     }
  320.     public function getId(): ?string
  321.     {
  322.         return $this->id;
  323.     }
  324.     public function getRazonSocial(): ?string
  325.     {
  326.         return $this->razonSocial;
  327.     }
  328.     public function setRazonSocial(?string $razonSocial): self
  329.     {
  330.         $this->razonSocial $razonSocial;
  331.         return $this;
  332.     }
  333.     public function getAlias(): ?string
  334.     {
  335.         return $this->alias;
  336.     }
  337.     public function setAlias(?string $alias): self
  338.     {
  339.         $this->alias $alias;
  340.         return $this;
  341.     }
  342.     public function getIdentificacionTipo(): ?string
  343.     {
  344.         return $this->identificacionTipo;
  345.     }
  346.     public function setIdentificacionTipo(?string $identificacionTipo): self
  347.     {
  348.         $this->identificacionTipo $identificacionTipo;
  349.         return $this;
  350.     }
  351.     public function getIdentificacion(): ?string
  352.     {
  353.         return $this->identificacion;
  354.     }
  355.     public function setIdentificacion(?string $identificacion): self
  356.     {
  357.         $this->identificacion $identificacion;
  358.         return $this;
  359.     }
  360.     public function getIdentificacionFrontal(): ?string
  361.     {
  362.         return $this->identificacionFrontal;
  363.     }
  364.     public function setIdentificacionFrontal(?string $identificacionFrontal): self
  365.     {
  366.         $this->identificacionFrontal $identificacionFrontal;
  367.         return $this;
  368.     }
  369.     public function getIdentificacionFrontalFile(): ?File
  370.     {
  371.         return $this->identificacionFrontalFile;
  372.     }
  373.     public function setIdentificacionFrontalFile(?File $identificacionFrontalFile): self
  374.     {
  375.         $this->identificacionFrontalFile $identificacionFrontalFile;
  376.         if ($identificacionFrontalFile) {
  377.             // if 'updatedAt' is not defined in your entity, use another property
  378.             $this->setUpdatedAt(new \DateTime('now'));
  379.         }
  380.         return $this;
  381.     }
  382.     public function getIdentificacionTrasera(): ?string
  383.     {
  384.         return $this->identificacionTrasera;
  385.     }
  386.     public function setIdentificacionTrasera(?string $identificacionTrasera): self
  387.     {
  388.         $this->identificacionTrasera $identificacionTrasera;
  389.         return $this;
  390.     }
  391.     public function getIdentificacionTraseraFile(): ?File
  392.     {
  393.         return $this->identificacionTraseraFile;
  394.     }
  395.     public function setIdentificacionTraseraFile(?File $identificacionTraseraFile): self
  396.     {
  397.         $this->identificacionTraseraFile $identificacionTraseraFile;
  398.         if ($identificacionTraseraFile) {
  399.             // if 'updatedAt' is not defined in your entity, use another property
  400.             $this->setUpdatedAt(new \DateTime('now'));
  401.         }
  402.         return $this;
  403.     }
  404.     public function getIdioma(): ?string
  405.     {
  406.         return $this->idioma;
  407.     }
  408.     public function setIdioma(?string $idioma): self
  409.     {
  410.         $this->idioma $idioma;
  411.         return $this;
  412.     }
  413.     public function getEntidadBancaria(): ?string
  414.     {
  415.         return $this->entidadBancaria;
  416.     }
  417.     public function setEntidadBancaria(?string $entidadBancaria): self
  418.     {
  419.         $this->entidadBancaria $entidadBancaria;
  420.         return $this;
  421.     }
  422.     public function getIban(): ?string
  423.     {
  424.         return $this->iban;
  425.     }
  426.     public function setIban(?string $iban): self
  427.     {
  428.         $this->iban $iban;
  429.         return $this;
  430.     }
  431.     public function getObservaciones(): ?string
  432.     {
  433.         return $this->observaciones;
  434.     }
  435.     public function setObservaciones(?string $observaciones): self
  436.     {
  437.         $this->observaciones $observaciones;
  438.         return $this;
  439.     }
  440.     public function getDeletedAt(): ?\DateTimeInterface
  441.     {
  442.         return $this->deletedAt;
  443.     }
  444.     public function setDeletedAt(?\DateTimeInterface $deletedAt): self
  445.     {
  446.         $this->deletedAt $deletedAt;
  447.         return $this;
  448.     }
  449.     public function getUpdatedAt(): ?\DateTimeInterface
  450.     {
  451.         return $this->updatedAt;
  452.     }
  453.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  454.     {
  455.         $this->updatedAt $updatedAt;
  456.         return $this;
  457.     }
  458.     public function getCreatedAt(): ?\DateTimeInterface
  459.     {
  460.         return $this->createdAt;
  461.     }
  462.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  463.     {
  464.         $this->createdAt $createdAt;
  465.         return $this;
  466.     }
  467.     public function getUser(): ?User
  468.     {
  469.         return $this->user;
  470.     }
  471.     public function setUser(?User $user): self
  472.     {
  473.         // unset the owning side of the relation if necessary
  474.         if ($user === null && $this->user !== null) {
  475.             $this->user->setCliente(null);
  476.         }
  477.         // set the owning side of the relation if necessary
  478.         if ($user !== null && $user->getCliente() !== $this) {
  479.             $user->setCliente($this);
  480.         }
  481.         $this->user $user;
  482.         return $this;
  483.     }
  484.     /**
  485.      * @return Collection|Valoracion[]
  486.      */
  487.     public function getValoraciones(): Collection
  488.     {
  489.         return $this->valoraciones;
  490.     }
  491.     public function addValoracione(Valoracion $valoracione): self
  492.     {
  493.         if (!$this->valoraciones->contains($valoracione)) {
  494.             $this->valoraciones[] = $valoracione;
  495.             $valoracione->setCliente($this);
  496.         }
  497.         return $this;
  498.     }
  499.     public function removeValoracione(Valoracion $valoracione): self
  500.     {
  501.         if ($this->valoraciones->removeElement($valoracione)) {
  502.             // set the owning side to null (unless already changed)
  503.             if ($valoracione->getCliente() === $this) {
  504.                 $valoracione->setCliente(null);
  505.             }
  506.         }
  507.         return $this;
  508.     }
  509.     /**
  510.      * @return Collection|Operacion[]
  511.      */
  512.     public function getOperaciones(): Collection
  513.     {
  514.         return $this->operaciones;
  515.     }
  516.     public function addOperacione(Operacion $operacione): self
  517.     {
  518.         if (!$this->operaciones->contains($operacione)) {
  519.             $this->operaciones[] = $operacione;
  520.             $operacione->setCliente($this);
  521.         }
  522.         return $this;
  523.     }
  524.     public function removeOperacione(Operacion $operacione): self
  525.     {
  526.         if ($this->operaciones->removeElement($operacione)) {
  527.             // set the owning side to null (unless already changed)
  528.             if ($operacione->getCliente() === $this) {
  529.                 $operacione->setCliente(null);
  530.             }
  531.         }
  532.         return $this;
  533.     }
  534.     public function getTelefono(): ?string
  535.     {
  536.         return $this->telefono;
  537.     }
  538.     public function setTelefono(?string $telefono): self
  539.     {
  540.         $this->telefono $telefono;
  541.         return $this;
  542.     }
  543.     public function getEmail(): ?string
  544.     {
  545.         return $this->email;
  546.     }
  547.     public function setEmail(?string $email): self
  548.     {
  549.         $this->email $email;
  550.         return $this;
  551.     }
  552.     public function getDireccion(): ?string
  553.     {
  554.         return $this->direccion;
  555.     }
  556.     public function setDireccion(?string $direccion): self
  557.     {
  558.         $this->direccion $direccion;
  559.         return $this;
  560.     }
  561.     public function getCp(): ?string
  562.     {
  563.         return $this->cp;
  564.     }
  565.     public function setCp(?string $cp): self
  566.     {
  567.         $this->cp $cp;
  568.         return $this;
  569.     }
  570.     public function getCiudad(): ?string
  571.     {
  572.         return $this->ciudad;
  573.     }
  574.     public function setCiudad(?string $ciudad): self
  575.     {
  576.         $this->ciudad $ciudad;
  577.         return $this;
  578.     }
  579.     public function getCcaa(): ?CCAA
  580.     {
  581.         return $this->ccaa;
  582.     }
  583.     public function setCcaa(?CCAA $ccaa): self
  584.     {
  585.         $this->ccaa $ccaa;
  586.         return $this;
  587.     }
  588.     public function getPais(): ?string
  589.     {
  590.         return $this->pais;
  591.     }
  592.     public function setPais(?string $pais): self
  593.     {
  594.         $this->pais $pais;
  595.         return $this;
  596.     }
  597.     public function getProvincia(): ?Provincia
  598.     {
  599.         return $this->provincia;
  600.     }
  601.     public function setProvincia(?Provincia $provincia): self
  602.     {
  603.         $this->provincia $provincia;
  604.         return $this;
  605.     }
  606.     /**
  607.      * @return Collection<int, ActividadAbstract>
  608.      */
  609.     public function getActividades(): Collection
  610.     {
  611.         return $this->actividades;
  612.     }
  613.     public function addActividade(ActividadAbstract $actividade): static
  614.     {
  615.         if (!$this->actividades->contains($actividade)) {
  616.             $this->actividades->add($actividade);
  617.             $actividade->setCliente($this);
  618.         }
  619.         return $this;
  620.     }
  621.     public function removeActividade(ActividadAbstract $actividade): static
  622.     {
  623.         if ($this->actividades->removeElement($actividade)) {
  624.             // set the owning side to null (unless already changed)
  625.             if ($actividade->getCliente() === $this) {
  626.                 $actividade->setCliente(null);
  627.             }
  628.         }
  629.         return $this;
  630.     }
  631.     public function getRegion(): ?string
  632.     {
  633.         return $this->region;
  634.     }
  635.     public function setRegion(?string $region): static
  636.     {
  637.         $this->region $region;
  638.         return $this;
  639.     }
  640.     public function getExportPais(): ?string
  641.     {
  642.         return $this->getPais() ? Countries::getName($this->getPais()) : null;
  643.     }
  644.     public function getSwift(): ?string
  645.     {
  646.         return $this->swift;
  647.     }
  648.     public function setSwift(?string $swift): static
  649.     {
  650.         $this->swift $swift;
  651.         return $this;
  652.     }
  653. }