src/Entity/Client.php line 37

  1. <?php
  2. /*
  3.  *  @author Guerby Duval <info@tranzaksyon.com>
  4.  *  @link https://tranzaksyon.com
  5.  *  @copyright You are not allowed to remove this author "Guerby Duval <info@tranzaksyon.com>", the link "https://tranzaksyon.com" neither this copyright.
  6.  */
  7. namespace App\Entity;
  8. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  9. use ApiPlatform\Metadata\ApiFilter;
  10. use ApiPlatform\Metadata\ApiResource;
  11. use ApiPlatform\Metadata\Delete;
  12. use ApiPlatform\Metadata\Get;
  13. use ApiPlatform\Metadata\GetCollection;
  14. use ApiPlatform\Metadata\Post;
  15. use ApiPlatform\Metadata\Put;
  16. use App\Enums\NaturalezaClient;
  17. use App\Enums\TipoOperacionEnum;
  18. use App\Interfaces\OwnerCompanyInterface;
  19. use App\Repository\ClientRepository;
  20. use App\Validator\EmailMultiple;
  21. use App\Validator\RazonSocial;
  22. use Doctrine\Common\Collections\ArrayCollection;
  23. use Doctrine\Common\Collections\Collection;
  24. use Doctrine\DBAL\Types\Types;
  25. use Doctrine\ORM\Mapping as ORM;
  26. use Symfony\Component\Serializer\Annotation\Groups;
  27. use Symfony\Component\Validator\Constraints\Length;
  28. use Symfony\Component\Validator\Constraints\NotBlank;
  29. use Symfony\Component\Validator\Constraints\NotNull;
  30. use Symfony\Component\Validator\Constraints\When;
  31. #[ORM\Entity(repositoryClassClientRepository::class)]
  32. #[ORM\UniqueConstraint(fields: ['idClient''typeId''sriInfo'])]
  33. #[RazonSocial()]
  34. class Client implements OwnerCompanyInterface
  35. {
  36.     #[ORM\Id]
  37.     #[ORM\GeneratedValue]
  38.     #[ORM\Column]
  39.     #[Groups(['client_out'])]
  40.     private ?int $id null;
  41.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  42.     #[Groups(['client_out'])]
  43.     private ?\DateTimeInterface $dateCreated;
  44.     #[ORM\Column(length255)]
  45.     #[NotBlank(groups: ['NewClient''Default'])]
  46.     #[Groups(['client_out''client_in'])]
  47.     private ?string $razonSocial null;
  48.     #[ORM\Column(length20)]
  49.     #[NotBlank(groups: ['NewClient''Default''Manual'])]
  50.     #[Length(min5groups: ['NewClient''Default''Manual'])]
  51.     #[Groups(['client_out''client_in'])]
  52.     private ?string $idClient null;
  53.     #[ORM\Column(length5)]
  54.     #[NotBlank(groups: ['NewClient''Default''Manual'])]
  55.     #[Length(exactly1groups: ['NewClient''Default''Manual'])]
  56.     #[Groups(['client_out''client_in'])]
  57.     private ?string $typeId null;
  58.     #[ORM\Column(length255nullabletrue)]
  59. //    #[NotBlank(groups: ['NewClient', 'Default', 'Manual'])]
  60.     #[Length(min3groups: ['NewClient''Default''Manual'])]
  61.     #[Groups(['client_out''client_in'])]
  62.     private ?string $location null;
  63.     #[ORM\OneToMany(mappedBy'client'targetEntityInvoice::class)]
  64.     private Collection $invoices;
  65.     #[ORM\ManyToOne(inversedBy'clients')]
  66.     #[ORM\JoinColumn(nullablefalse)]
  67.     private ?SriInfo $sriInfo null;
  68.     #[ORM\Column(length80nullabletrue)]
  69.     #[Groups(['client_out''client_in'])]
  70.     private ?string $name null;
  71.     #[ORM\Column(length80nullabletrue)]
  72.     #[Groups(['client_out''client_in'])]
  73.     private ?string $lastname null;
  74.     #[ORM\Column(length500nullabletrue)]
  75.     #[NotBlank(groups: ['NewClient''Default''Manual'])]
  76.     #[EmailMultiple(groups: ['NewClient''Default''Manual'])]
  77.     #[Groups(['client_out''client_in'])]
  78.     private ?string $email null;
  79.     #[ORM\Column(length20nullabletrue)]
  80.     #[Groups(['client_out''client_in'])]
  81.     #[Length(max20)]
  82.     private ?string $phone null;
  83.     #[ORM\Column(length50nullabletrue)]
  84.     private ?string $externalId null;
  85.     #[ORM\Column(nullabletrue)]
  86.     #[When('!this.getId() && this.getPhone() !== null and this.getPhone() !== ""', [
  87.         new NotNull(groups: ['NewClient''Default''Manual'])
  88.     ])]
  89.     private ?int $phoneAreaCode 595;
  90.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  91.     private ?\DateTimeInterface $birthDate null;
  92.     #[ORM\Column(enumTypeNaturalezaClient::class)]
  93.     #[NotBlank]
  94.     #[Groups(['client_out''client_in'])]
  95.     private ?NaturalezaClient $naturaleza null;
  96.     #[ORM\Column(enumTypeTipoOperacionEnum::class)]
  97.     #[Groups(['client_out''client_in'])]
  98.     #[NotBlank]
  99.     private ?TipoOperacionEnum $tipoOperacion null;
  100.     #[ORM\Column(length3)]
  101.     #[NotBlank]
  102.     #[Groups(['client_out''client_in'])]
  103.     private ?string $codigoPais null;
  104.     #[ORM\Column(length30)]
  105.     #[Groups(['client_out''client_in'])]
  106.     private ?string $nombrePais null;
  107.     #[ORM\Column(nullabletrue)]
  108.     #[Groups(['client_out''client_in'])]
  109.     private ?int $tipoContribuyente null;
  110.     #[ORM\Column(length255nullabletrue)]
  111.     #[Groups(['client_out''client_in'])]
  112.     private ?string $nombreFantasia null;
  113.     #[ORM\Column(length255nullabletrue)]
  114.     #[Groups(['client_out''client_in'])]
  115.     private ?string $numeroCasa null;
  116.     #[ORM\Column(nullabletrue)]
  117.     #[Groups(['client_out''client_in'])]
  118.     private ?int $codigoDepartamento null;
  119.     #[ORM\Column(length255nullabletrue)]
  120.     #[Groups(['client_out''client_in'])]
  121.     private ?string $departamento null;
  122.     #[ORM\Column(nullabletrue)]
  123.     #[Groups(['client_out''client_in'])]
  124.     private ?int $codigoDistrito null;
  125.     #[ORM\Column(length30nullabletrue)]
  126.     #[Groups(['client_out''client_in'])]
  127.     private ?string $distrito null;
  128.     #[ORM\Column(nullabletrue)]
  129.     #[Groups(['client_out''client_in'])]
  130.     private ?int $codigoCiudad null;
  131.     #[ORM\Column(length30nullabletrue)]
  132.     #[Groups(['client_out''client_in'])]
  133.     private ?string $ciudad null;
  134.     public function __construct()
  135.     {
  136.         $this->invoices = new ArrayCollection();
  137.         $this->dateCreated = new \DateTime();
  138.     }
  139.     public function getId(): ?int
  140.     {
  141.         return $this->id;
  142.     }
  143.     public function getDateCreated(): ?\DateTimeInterface
  144.     {
  145.         return $this->dateCreated;
  146.     }
  147.     public function setDateCreated(\DateTimeInterface $dateCreated): self
  148.     {
  149.         $this->dateCreated $dateCreated;
  150.         return $this;
  151.     }
  152.     public function getRazonSocial(): ?string
  153.     {
  154.         return $this->razonSocial;
  155.     }
  156.     public function setRazonSocial(?string $razonSocial): self
  157.     {
  158.         $this->razonSocial $razonSocial;
  159.         return $this;
  160.     }
  161.     public function getIdClient(): ?string
  162.     {
  163.         return $this->idClient;
  164.     }
  165.     public function setIdClient(string $idClient): self
  166.     {
  167.         $this->idClient $idClient;
  168.         return $this;
  169.     }
  170.     public function getTypeId(): ?string
  171.     {
  172.         return $this->typeId;
  173.     }
  174.     public function setTypeId(string $typeId): self
  175.     {
  176.         $this->typeId $typeId;
  177.         return $this;
  178.     }
  179.     public function getLocation(): ?string
  180.     {
  181.         return $this->location;
  182.     }
  183.     public function setLocation(?string $location): self
  184.     {
  185.         $this->location $location;
  186.         return $this;
  187.     }
  188.     /**
  189.      * @return Collection<int, Invoice>
  190.      */
  191.     public function getInvoices(): Collection
  192.     {
  193.         return $this->invoices;
  194.     }
  195.     public function addInvoice(Invoice $invoice): self
  196.     {
  197.         if (!$this->invoices->contains($invoice)) {
  198.             $this->invoices->add($invoice);
  199.             $invoice->setClient($this);
  200.         }
  201.         return $this;
  202.     }
  203.     public function removeInvoice(Invoice $invoice): self
  204.     {
  205.         if ($this->invoices->removeElement($invoice)) {
  206.             // set the owning side to null (unless already changed)
  207.             if ($invoice->getClient() === $this) {
  208.                 $invoice->setClient(null);
  209.             }
  210.         }
  211.         return $this;
  212.     }
  213.     public function getSriInfo(): ?SriInfo
  214.     {
  215.         return $this->sriInfo;
  216.     }
  217.     public function setSriInfo(?SriInfo $sriInfo): self
  218.     {
  219.         $this->sriInfo $sriInfo;
  220.         return $this;
  221.     }
  222.     public function getName(): ?string
  223.     {
  224.         return $this->name;
  225.     }
  226.     public function setName(?string $name): self
  227.     {
  228.         $this->name $name;
  229.         return $this;
  230.     }
  231.     public function getLastname(): ?string
  232.     {
  233.         return $this->lastname;
  234.     }
  235.     public function setLastname(?string $lastname): self
  236.     {
  237.         $this->lastname $lastname;
  238.         return $this;
  239.     }
  240.     public function getEmail(): ?string
  241.     {
  242.         return $this->email;
  243.     }
  244.     public function setEmail(?string $email): self
  245.     {
  246.         $this->email $email;
  247.         return $this;
  248.     }
  249.     public function getPhone(): ?string
  250.     {
  251.         return $this->phone;
  252.     }
  253.     public function setPhone(?string $phone): self
  254.     {
  255.         $this->phone $phone;
  256.         return $this;
  257.     }
  258.     public function getFormName(): string
  259.     {
  260.         return $this->razonSocial ' (' $this->idClient ')';
  261.     }
  262.     public function getExternalId(): ?string
  263.     {
  264.         return $this->externalId;
  265.     }
  266.     public function setExternalId(?string $externalId): static
  267.     {
  268.         $this->externalId $externalId;
  269.         return $this;
  270.     }
  271.     public function getPhoneAreaCode(): ?int
  272.     {
  273.         return $this->phoneAreaCode;
  274.     }
  275.     public function setPhoneAreaCode(?int $phoneAreaCode): static
  276.     {
  277.         $this->phoneAreaCode $phoneAreaCode;
  278.         return $this;
  279.     }
  280.     public function getBirthDate(): ?\DateTimeInterface
  281.     {
  282.         return $this->birthDate;
  283.     }
  284.     public function setBirthDate(?\DateTimeInterface $birthDate): static
  285.     {
  286.         $this->birthDate $birthDate;
  287.         return $this;
  288.     }
  289.     public function getNaturaleza(): ?NaturalezaClient
  290.     {
  291.         return $this->naturaleza;
  292.     }
  293.     public function setNaturaleza(?NaturalezaClient $naturaleza): static
  294.     {
  295.         $this->naturaleza $naturaleza;
  296.         return $this;
  297.     }
  298.     public function getTipoOperacion(): ?TipoOperacionEnum
  299.     {
  300.         return $this->tipoOperacion;
  301.     }
  302.     public function setTipoOperacion(?TipoOperacionEnum $tipoOperacion): static
  303.     {
  304.         $this->tipoOperacion $tipoOperacion;
  305.         return $this;
  306.     }
  307.     public function getCodigoPais(): ?string
  308.     {
  309.         return $this->codigoPais;
  310.     }
  311.     public function setCodigoPais(string $codigoPais): static
  312.     {
  313.         $this->codigoPais $codigoPais;
  314.         return $this;
  315.     }
  316.     public function getNombrePais(): ?string
  317.     {
  318.         return $this->nombrePais;
  319.     }
  320.     public function setNombrePais(string $nombrePais): static
  321.     {
  322.         $this->nombrePais $nombrePais;
  323.         return $this;
  324.     }
  325.     public function getTipoContribuyente(): ?int
  326.     {
  327.         return $this->tipoContribuyente;
  328.     }
  329.     public function setTipoContribuyente(?int $tipoContribuyente): static
  330.     {
  331.         $this->tipoContribuyente $tipoContribuyente;
  332.         return $this;
  333.     }
  334.     public function getNombreFantasia(): ?string
  335.     {
  336.         return $this->nombreFantasia;
  337.     }
  338.     public function setNombreFantasia(?string $nombreFantasia): static
  339.     {
  340.         $this->nombreFantasia $nombreFantasia;
  341.         return $this;
  342.     }
  343.     public function getNumeroCasa(): ?string
  344.     {
  345.         return $this->numeroCasa;
  346.     }
  347.     public function setNumeroCasa(?string $numeroCasa): static
  348.     {
  349.         $this->numeroCasa $numeroCasa;
  350.         return $this;
  351.     }
  352.     public function getCodigoDepartamento(): ?int
  353.     {
  354.         return $this->codigoDepartamento;
  355.     }
  356.     public function setCodigoDepartamento(?int $codigoDepartamento): static
  357.     {
  358.         $this->codigoDepartamento $codigoDepartamento;
  359.         return $this;
  360.     }
  361.     public function getDepartamento(): ?string
  362.     {
  363.         return $this->departamento;
  364.     }
  365.     public function setDepartamento(?string $departamento): static
  366.     {
  367.         $this->departamento $departamento;
  368.         return $this;
  369.     }
  370.     public function getCodigoDistrito(): ?int
  371.     {
  372.         return $this->codigoDistrito;
  373.     }
  374.     public function setCodigoDistrito(?int $codigoDistrito): static
  375.     {
  376.         $this->codigoDistrito $codigoDistrito;
  377.         return $this;
  378.     }
  379.     public function getDistrito(): ?string
  380.     {
  381.         return $this->distrito;
  382.     }
  383.     public function setDistrito(?string $distrito): static
  384.     {
  385.         $this->distrito $distrito;
  386.         return $this;
  387.     }
  388.     public function getCodigoCiudad(): ?int
  389.     {
  390.         return $this->codigoCiudad;
  391.     }
  392.     public function setCodigoCiudad(?int $codigoCiudad): static
  393.     {
  394.         $this->codigoCiudad $codigoCiudad;
  395.         return $this;
  396.     }
  397.     public function getCiudad(): ?string
  398.     {
  399.         return $this->ciudad;
  400.     }
  401.     public function setCiudad(?string $ciudad): static
  402.     {
  403.         $this->ciudad $ciudad;
  404.         return $this;
  405.     }
  406.     public function copy(Client $client)
  407.     {
  408. //        $propertyAccessor = PropertyAccess::createPropertyAccessor();
  409. //
  410. //        foreach (get_class_methods($client) as $method) {
  411. //            if (strpos($method, 'get') === 0 && $method !== 'getId') {
  412. //                $property = lcfirst(substr($method, 3));
  413. //                if ($propertyAccessor->isWritable($this, $property)) {
  414. //                    $value = $propertyAccessor->getValue($client, $property);
  415. //                    $propertyAccessor->setValue($this, $property, $value);
  416. //                }
  417. //            }
  418. //        }
  419.         $this->setNumeroCasa($client->getNumeroCasa())
  420.             ->setLocation($client->getLocation())
  421.             ->setCodigoPais($client->getCodigoPais())
  422.             ->setName($client->getName())
  423.             ->setPhone($client->getPhone())
  424.             ->setRazonSocial($client->getRazonSocial())
  425.             ->setIdClient($client->getIdClient())
  426.             ->setTypeId($client->getTypeId())
  427.             ->setTipoContribuyente($client->getTipoContribuyente())
  428.             ->setNaturaleza($client->getNaturaleza())
  429.             ->setTipoOperacion($client->getTipoOperacion())
  430.             ->setDepartamento($client->getDepartamento())
  431.             ->setDistrito($client->getDistrito())
  432.             ->setNombreFantasia($client->getNombreFantasia())
  433.             ->setCodigoCiudad($client->getCodigoCiudad())
  434.             ->setCodigoDepartamento($client->getCodigoDepartamento())
  435.             ->setCodigoDistrito($client->getCodigoDistrito());
  436.     }
  437. }