src/Entity/Client.php line 42

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\GetCollection;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\Post;
  7. use App\Controller\Api\Client\ApiClientInvoicesController;
  8. use App\Kimia;
  9. use App\Model\Wallet\WalletInterface;
  10. use App\Repository\ClientRepository;
  11. use App\Service\GeoIP;
  12. use App\Trait\ActivableTrait;
  13. use App\Trait\ArrayableTrait;
  14. use App\Trait\DateTrait;
  15. use App\Trait\DeletableTrait;
  16. use App\Trait\WalletTrait;
  17. use DateTimeImmutable;
  18. use Doctrine\Common\Collections\ArrayCollection;
  19. use Doctrine\Common\Collections\Collection;
  20. use Doctrine\ORM\Mapping as ORM;
  21. use Symfony\Component\Serializer\Annotation\Groups;
  22. #[ORM\Entity(repositoryClassClientRepository::class)]
  23. #[ApiResource(
  24.     operations: [
  25.         new GetCollection(
  26.             normalizationContext: ['groups' => ['client:list']]
  27.         ),
  28.         new Get(),
  29.         new Post(
  30.             uriTemplate"/clients/invoices",
  31.             controllerApiClientInvoicesController::class,
  32.             normalizationContext: ['groups' => ['client:list''client:invoices']],
  33.             denormalizationContext: ['groups' => ['client:invoices:get']],
  34.             writefalse,
  35.         )
  36.     ],
  37.     normalizationContext: ['groups' => ['client:list''client:view']]
  38. )]
  39. class Client implements WalletInterface
  40. {
  41.     use ArrayableTrait;
  42.     use DateTrait {__construct as private constructDate;}
  43.     use ActivableTrait;
  44.     use DeletableTrait;
  45.     use WalletTrait;
  46.     #[ORM\Id]
  47.     #[ORM\GeneratedValue]
  48.     #[ORM\Column]
  49.     #[Groups(['client:list''client:invoices''attendance:list'])]
  50.     private ?int $id null;
  51.     #[ORM\Column(length255)]
  52.     #[Groups(['client:list''order:list''attendance:list'])]
  53.     private ?string $firstname null;
  54.     #[ORM\Column(length255nullabletrue)]
  55.     #[Groups(['client:list''order:list''attendance:list'])]
  56.     private ?string $lastname null;
  57.     #[ORM\Column(length180nullabletrue)]
  58.     #[Groups(['client:list''order:view''attendance:list'])]
  59.     private ?string $email null;
  60.     #[ORM\Column(length15nullabletrue)]
  61.     #[Groups(['client:list''order:view''attendance:list'])]
  62.     private ?string $phone null;
  63.     #[ORM\Column(length255nullabletrue)]
  64.     #[Groups(['client:list''order:view'])]
  65.     private ?string $comment null;
  66.     #[ORM\ManyToOne(inversedBy'clients')]
  67.     #[ORM\JoinColumn(nullabletrue)]
  68.     private ?Department $department null;
  69.     #[ORM\ManyToOne(inversedBy'clients')]
  70.     #[ORM\JoinColumn(nullablefalse)]
  71.     private ?Establishment $establishment null;
  72.     #[ORM\ManyToMany(targetEntityOrder::class, mappedBy'clients')]
  73.     private Collection $orders;
  74.     #[ORM\Column]
  75.     private ?int $quota 0;
  76.     #[ORM\Column(options: ['default' => true])]
  77.     private ?bool $isTaxable true;
  78.     #[ORM\Column(length255nullabletrue)]
  79.     #[Groups(['client:invoices:get'])]
  80.     private ?string $ref null;
  81.     #[ORM\OneToMany(mappedBy'client'targetEntityInvoice::class)]
  82.     #[Groups(['client:invoices'])]
  83.     private Collection $invoices;
  84.     #[ORM\ManyToOne(cascade: ["persist"])]
  85.     #[ORM\JoinColumn(nullabletrue)]
  86.     private ?Attachment $thumbnail null;
  87.     #[ORM\Column(length2nullabletrue)]
  88.     private ?string $country;
  89.     #[ORM\Column(length255nullabletrue)]
  90.     private ?string $name null;
  91.     #[ORM\OneToMany(mappedBy'client'targetEntityAddress::class, cascade: ['persist'])]
  92.     private Collection $addresses;
  93.     #[ORM\OneToMany(mappedBy'client'targetEntityDocument::class, cascade: ['persist'])]
  94.     private Collection $documents;
  95.     #[ORM\OneToMany(mappedBy'client'targetEntityMutuality::class)]
  96.     private Collection $mutualities;
  97.     #[ORM\OneToMany(mappedBy'client'targetEntityAttendance::class)]
  98.     private Collection $attendances;
  99.     #[ORM\OneToMany(mappedBy'client'targetEntityCard::class)]
  100.     private Collection $cards;
  101.     #[ORM\Column(length255nullabletrue)]
  102.     private ?string $city null;
  103.     public function __construct()
  104.     {
  105.         $this->constructDate();
  106.         $this->isActive Kimia::ACTIVE;
  107.         $this->orders = new ArrayCollection();
  108.         $this->invoices = new ArrayCollection();
  109.         $this->addresses = new ArrayCollection();
  110.         $this->country 'CD';
  111.         $this->documents = new ArrayCollection();
  112.         $this->mutualities = new ArrayCollection();
  113.         $this->attendances = new ArrayCollection();
  114.         $this->cards = new ArrayCollection();
  115.         $this->ordersList = new ArrayCollection();
  116.     }
  117.     public function getId(): ?int
  118.     {
  119.         return $this->id;
  120.     }
  121.     public function getFullname(): ?string
  122.     {
  123.         return "$this->firstname $this->lastname";
  124.     }
  125.     public function getFirstname(): ?string
  126.     {
  127.         return $this->firstname;
  128.     }
  129.     public function setFirstname(string $firstname): self
  130.     {
  131.         $this->firstname $firstname;
  132.         return $this;
  133.     }
  134.     public function getLastname(): ?string
  135.     {
  136.         return $this->lastname;
  137.     }
  138.     public function setLastname(?string $lastname): self
  139.     {
  140.         $this->lastname $lastname;
  141.         return $this;
  142.     }
  143.     public function getEmail(): ?string
  144.     {
  145.         return $this->email;
  146.     }
  147.     public function setEmail(?string $email): self
  148.     {
  149.         $this->email $email;
  150.         return $this;
  151.     }
  152.     public function getPhone(): ?string
  153.     {
  154.         return $this->phone;
  155.     }
  156.     public function setPhone(?string $phone): self
  157.     {
  158.         $this->phone GeoIP::phoneResolve($phone$this->country);
  159.         return $this;
  160.     }
  161.     public function getComment(): ?string
  162.     {
  163.         return $this->comment;
  164.     }
  165.     public function setComment(?string $comment): self
  166.     {
  167.         $this->comment $comment;
  168.         return $this;
  169.     }
  170.     public function __toString(): string
  171.     {
  172.         return $this->getName() ?? $this->getEmail() ?? $this->getPhone() ?? "";
  173.     }
  174.     public function getDepartment(): ?Department
  175.     {
  176.         return $this->department;
  177.     }
  178.     public function setDepartment(?Department $department): self
  179.     {
  180.         $this->department $department;
  181.         return $this;
  182.     }
  183.     public function getEstablishment(): ?Establishment
  184.     {
  185.         return $this->establishment;
  186.     }
  187.     public function setEstablishment(?Establishment $establishment): self
  188.     {
  189.         $this->establishment $establishment;
  190.         return $this;
  191.     }
  192.     public function getQuota(): ?int
  193.     {
  194.         return $this->quota;
  195.     }
  196.     public function setQuota(int $quota): self
  197.     {
  198.         $this->quota $quota;
  199.         return $this;
  200.     }
  201.     public function incrementQuota(int $quota 1): self
  202.     {
  203.         $this->quota += $quota;
  204.         return $this;
  205.     }
  206.     public function decrementQuota(): void
  207.     {
  208.         $this->quota $this->getQuota() - 1;
  209.     }
  210.     public function isIsTaxable(): ?bool
  211.     {
  212.         return $this->isTaxable;
  213.     }
  214.     public function setIsTaxable(bool $isTaxable): self
  215.     {
  216.         $this->isTaxable $isTaxable;
  217.         return $this;
  218.     }
  219.     public function getRef(): ?string
  220.     {
  221.         return $this->ref;
  222.     }
  223.     public function setRef(?string $ref): static
  224.     {
  225.         $this->ref $ref;
  226.         return $this;
  227.     }
  228.     /**
  229.      * @return Collection<int, Invoice>
  230.      */
  231.     public function getInvoices(): Collection
  232.     {
  233.         return $this->invoices;
  234.     }
  235.     public function addInvoice(Invoice $invoice): static
  236.     {
  237.         if (!$this->invoices->contains($invoice)) {
  238.             $this->invoices->add($invoice);
  239.             $invoice->setClient($this);
  240.         }
  241.         return $this;
  242.     }
  243.     public function removeInvoice(Invoice $invoice): static
  244.     {
  245.         if ($this->invoices->removeElement($invoice)) {
  246.             // set the owning side to null (unless already changed)
  247.             if ($invoice->getClient() === $this) {
  248.                 $invoice->setClient(null);
  249.             }
  250.         }
  251.         return $this;
  252.     }
  253.     public function getThumbnail(): ?Attachment
  254.     {
  255.         return $this->thumbnail;
  256.     }
  257.     public function setThumbnail(?Attachment $thumbnail): self
  258.     {
  259.         $this->thumbnail $thumbnail;
  260.         return $this;
  261.     }
  262.     public function getCountry(): ?string
  263.     {
  264.         return $this->country;
  265.     }
  266.     public function setCountry(?string $country): static
  267.     {
  268.         $this->country $country;
  269.         return $this;
  270.     }
  271.     public function getName(): ?string
  272.     {
  273.         return $this->name;
  274.     }
  275.     public function setName(?string $name): static
  276.     {
  277.         $this->name $name;
  278.         return $this;
  279.     }
  280.     /**
  281.      * @return Collection<int, Address>
  282.      */
  283.     public function getAddresses(): Collection
  284.     {
  285.         return $this->addresses;
  286.     }
  287.     public function addAddress(Address $address): static
  288.     {
  289.         if (!$this->addresses->contains($address)) {
  290.             $this->addresses->add($address);
  291.             $address->setClient($this);
  292.         }
  293.         return $this;
  294.     }
  295.     public function removeAddress(Address $address): static
  296.     {
  297.         if ($this->addresses->removeElement($address)) {
  298.             // set the owning side to null (unless already changed)
  299.             if ($address->getClient() === $this) {
  300.                 $address->setClient(null);
  301.             }
  302.         }
  303.         return $this;
  304.     }
  305.     /**
  306.      * @return Collection<int, Document>
  307.      */
  308.     public function getDocuments(): Collection
  309.     {
  310.         return $this->documents;
  311.     }
  312.     public function addDocument(Document $document): static
  313.     {
  314.         if (!$this->documents->contains($document)) {
  315.             $this->documents->add($document);
  316.             $document->setClient($this);
  317.         }
  318.         return $this;
  319.     }
  320.     public function removeDocument(Document $document): static
  321.     {
  322.         if ($this->documents->removeElement($document)) {
  323.             // set the owning side to null (unless already changed)
  324.             if ($document->getClient() === $this) {
  325.                 $document->setClient(null);
  326.             }
  327.         }
  328.         return $this;
  329.     }
  330.     /**
  331.      * @return Collection<int, Mutuality>
  332.      */
  333.     public function getMutualities(): Collection
  334.     {
  335.         return $this->mutualities;
  336.     }
  337.     public function addMutuality(Mutuality $mutuality): static
  338.     {
  339.         if (!$this->mutualities->contains($mutuality)) {
  340.             $this->mutualities->add($mutuality);
  341.             $mutuality->setClient($this);
  342.         }
  343.         return $this;
  344.     }
  345.     public function removeMutuality(Mutuality $mutuality): static
  346.     {
  347.         if ($this->mutualities->removeElement($mutuality)) {
  348.             // set the owning side to null (unless already changed)
  349.             if ($mutuality->getClient() === $this) {
  350.                 $mutuality->setClient(null);
  351.             }
  352.         }
  353.         return $this;
  354.     }
  355.     /**
  356.      * @return Collection<int, Attendance>
  357.      */
  358.     public function getAttendances(): Collection
  359.     {
  360.         return $this->attendances;
  361.     }
  362.     public function addAttendance(Attendance $attendance): static
  363.     {
  364.         if (!$this->attendances->contains($attendance)) {
  365.             $this->attendances->add($attendance);
  366.             $attendance->setClient($this);
  367.         }
  368.         return $this;
  369.     }
  370.     public function removeAttendance(Attendance $attendance): static
  371.     {
  372.         if ($this->attendances->removeElement($attendance)) {
  373.             // set the owning side to null (unless already changed)
  374.             if ($attendance->getClient() === $this) {
  375.                 $attendance->setClient(null);
  376.             }
  377.         }
  378.         return $this;
  379.     }
  380.     /**
  381.      * @return Collection<int, Card>
  382.      */
  383.     public function getCards(): Collection
  384.     {
  385.         return $this->cards;
  386.     }
  387.     public function addCard(Card $card): static
  388.     {
  389.         if (!$this->cards->contains($card)) {
  390.             $this->cards->add($card);
  391.             $card->setClient($this);
  392.         }
  393.         return $this;
  394.     }
  395.     public function removeCard(Card $card): static
  396.     {
  397.         if ($this->cards->removeElement($card)) {
  398.             // set the owning side to null (unless already changed)
  399.             if ($card->getClient() === $this) {
  400.                 $card->setClient(null);
  401.             }
  402.         }
  403.         return $this;
  404.     }
  405.     public function getCity(): ?string
  406.     {
  407.         return $this->city;
  408.     }
  409.     public function setCity(?string $city): static
  410.     {
  411.         $this->city $city;
  412.         return $this;
  413.     }
  414.     /**
  415.      * @return Collection<int, Order>
  416.      */
  417.     public function getOrders(): Collection
  418.     {
  419.         return $this->ordersList;
  420.     }
  421.     public function addOrders(Order $orders): static
  422.     {
  423.         if (!$this->ordersList->contains($orders)) {
  424.             $this->ordersList->add($orders);
  425.             $orders->addClient($this);
  426.         }
  427.         return $this;
  428.     }
  429.     public function removeOrders(Order $orders): static
  430.     {
  431.         if ($this->ordersList->removeElement($orders)) {
  432.             $orders->removeClient($this);
  433.         }
  434.         return $this;
  435.     }
  436. }