src/Entity/Mutuality.php line 17

  1. <?php
  2. namespace App\Entity;
  3. use App\Model\Wallet\WalletInterface;
  4. use App\Repository\MutualityRepository;
  5. use App\Trait\ActivableTrait;
  6. use App\Trait\ArrayableTrait;
  7. use App\Trait\DateTrait;
  8. use App\Trait\DeletableTrait;
  9. use App\Trait\WalletTrait;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. #[ORM\Entity(repositoryClassMutualityRepository::class)]
  14. class Mutuality implements WalletInterface
  15. {
  16.     use DateTrait {
  17.         DateTrait::__construct as dateConstruct;
  18.     }
  19.     use ActivableTrait;
  20.     use DeletableTrait;
  21.     use ArrayableTrait;
  22.     use WalletTrait;
  23.     #[ORM\Id]
  24.     #[ORM\GeneratedValue]
  25.     #[ORM\Column]
  26.     private ?int $id null;
  27.     #[ORM\ManyToOne(cascade: ["persist"], inversedBy'mutualities')]
  28.     private ?User $user null;
  29.     #[ORM\ManyToOne(inversedBy'mutualities')]
  30.     private ?Establishment $establishment null;
  31.     #[ORM\Column]
  32.     private ?float $amount null;
  33.     #[ORM\ManyToOne]
  34.     private ?Currency $currency null;
  35.     #[ORM\ManyToOne(inversedBy'mutualities')]
  36.     private ?Client $client null;
  37.     #[ORM\ManyToMany(targetEntityArticleDepartment::class, cascade: ['persist'])]
  38.     private Collection $articles;
  39.     private ?string $fullname "";
  40.     #[ORM\OneToMany(mappedBy'mutuality'targetEntityDocument::class)]
  41.     private Collection $documents;
  42.     #[ORM\OneToOne(cascade: ['persist''remove'])]
  43.     private ?Address $address null;
  44.     #[ORM\OneToMany(mappedBy'mutuality'targetEntityCard::class)]
  45.     private Collection $cards;
  46.     #[ORM\ManyToOne(inversedBy'mutualities')]
  47.     private ?Employee $employee null;
  48.     #[ORM\Column(length255uniquetrue)]
  49.     private ?string $ref null;
  50.     #[ORM\ManyToOne(inversedBy'mutualities')]
  51.     private ?MutualityCategory $category null;
  52.     public function __construct()
  53.     {
  54.         $this->dateConstruct();
  55.         $this->articles = new ArrayCollection();
  56.         if (!$this->getUser()) {
  57.             $this->fullname =  $this->getClient() ?? $this->getEmployee() ?? $this->getUser();
  58.         }
  59.         $this->documents = new ArrayCollection();
  60.         $this->cards = new ArrayCollection();
  61.     }
  62.     public function __toString(): string
  63.     {
  64.         return $this->getFullname();
  65.     }
  66.     public function getId(): ?int
  67.     {
  68.         return $this->id;
  69.     }
  70.     public function getUser(): ?User
  71.     {
  72.         return $this->user;
  73.     }
  74.     public function setUser(?User $user): static
  75.     {
  76.         $this->user $user;
  77.         return $this;
  78.     }
  79.     public function getEstablishment(): ?Establishment
  80.     {
  81.         return $this->establishment;
  82.     }
  83.     public function setEstablishment(?Establishment $establishment): static
  84.     {
  85.         $this->establishment $establishment;
  86.         return $this;
  87.     }
  88.     public function getAmount(): ?float
  89.     {
  90.         return $this->amount;
  91.     }
  92.     public function setAmount(float $amount): static
  93.     {
  94.         $this->amount $amount;
  95.         return $this;
  96.     }
  97.     public function getCurrency(): ?Currency
  98.     {
  99.         return $this->currency;
  100.     }
  101.     public function setCurrency(?Currency $currency): static
  102.     {
  103.         $this->currency $currency;
  104.         return $this;
  105.     }
  106.     public function getClient(): ?Client
  107.     {
  108.         return $this->client;
  109.     }
  110.     public function setClient(?Client $client): static
  111.     {
  112.         $this->client $client;
  113.         return $this;
  114.     }
  115.     /**
  116.      * @return Collection<int, ArticleDepartment>
  117.      */
  118.     public function getArticles(): Collection
  119.     {
  120.         return $this->articles;
  121.     }
  122.     public function addArticle(ArticleDepartment $article): static
  123.     {
  124.         if (!$this->articles->contains($article)) {
  125.             $this->articles->add($article);
  126.         }
  127.         return $this;
  128.     }
  129.     public function removeArticle(ArticleDepartment $article): static
  130.     {
  131.         $this->articles->removeElement($article);
  132.         return $this;
  133.     }
  134.     /**
  135.      * @return Collection<int, Document>
  136.      */
  137.     public function getDocuments(): Collection
  138.     {
  139.         return $this->documents;
  140.     }
  141.     public function addDocument(Document $document): static
  142.     {
  143.         if (!$this->documents->contains($document)) {
  144.             $this->documents->add($document);
  145.             $document->setMutuality($this);
  146.         }
  147.         return $this;
  148.     }
  149.     public function removeDocument(Document $document): static
  150.     {
  151.         if ($this->documents->removeElement($document)) {
  152.             // set the owning side to null (unless already changed)
  153.             if ($document->getMutuality() === $this) {
  154.                 $document->setMutuality(null);
  155.             }
  156.         }
  157.         return $this;
  158.     }
  159.     public function getAddress(): ?Address
  160.     {
  161.         return $this->address;
  162.     }
  163.     public function setAddress(?Address $address): static
  164.     {
  165.         $this->address $address;
  166.         return $this;
  167.     }
  168.     public function getFullname(): string
  169.     {
  170.         $this->fullname $this->getClient() ?? $this->getEmployee() ?? $this->getUser();
  171.         return $this->fullname;
  172.     }
  173.     /**
  174.      * @return Collection<int, Card>
  175.      */
  176.     public function getCards(): Collection
  177.     {
  178.         return $this->cards;
  179.     }
  180.     public function addCard(Card $card): static
  181.     {
  182.         if (!$this->cards->contains($card)) {
  183.             $this->cards->add($card);
  184.             $card->setMutuality($this);
  185.         }
  186.         return $this;
  187.     }
  188.     public function removeCard(Card $card): static
  189.     {
  190.         if ($this->cards->removeElement($card)) {
  191.             // set the owning side to null (unless already changed)
  192.             if ($card->getMutuality() === $this) {
  193.                 $card->setMutuality(null);
  194.             }
  195.         }
  196.         return $this;
  197.     }
  198.     public function getEmployee(): ?Employee
  199.     {
  200.         return $this->employee;
  201.     }
  202.     public function setEmployee(?Employee $employee): static
  203.     {
  204.         $this->employee $employee;
  205.         return $this;
  206.     }
  207.     public function getRef(): ?string
  208.     {
  209.         return $this->ref;
  210.     }
  211.     public function setRef(string $ref): static
  212.     {
  213.         $this->ref $ref;
  214.         return $this;
  215.     }
  216.     public function getCategory(): ?MutualityCategory
  217.     {
  218.         return $this->category;
  219.     }
  220.     public function setCategory(?MutualityCategory $category): static
  221.     {
  222.         $this->category $category;
  223.         return $this;
  224.     }
  225. }