src/Entity/Establishment.php line 62

  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\Establishment\ApiEstablishmentGetByUserController;
  8. use App\Controller\Api\Establishment\ApiEstablishmentLoginController;
  9. use App\Controller\Api\Establishment\ApiEstablishmentJoinController;
  10. use App\Controller\Api\Establishment\ApiEstablishmentRegisterController;
  11. use App\Controller\Api\Order\ApiEstablishmentOrderNewController;
  12. use App\Kimia;
  13. use App\Model\Wallet\WalletInterface;
  14. use App\Repository\EstablishmentRepository;
  15. use App\Trait\ActivableTrait;
  16. use App\Trait\ArrayableTrait;
  17. use App\Trait\CurrentStateTrait;
  18. use App\Trait\DateTrait;
  19. use App\Trait\DeletableTrait;
  20. use App\Trait\WalletTrait;
  21. use DateTimeImmutable;
  22. use Doctrine\Common\Collections\ArrayCollection;
  23. use Doctrine\Common\Collections\Collection;
  24. use Doctrine\Common\Collections\ReadableCollection;
  25. use Doctrine\DBAL\Types\Types;
  26. use Doctrine\ORM\Mapping as ORM;
  27. use Symfony\Component\Serializer\Annotation\Groups;
  28. #[ORM\Entity(repositoryClass: EstablishmentRepository::class)]
  29. #[ApiResource(
  30.     operations: [
  31.         new GetCollection(
  32.             uriTemplate: 'user/establishments',
  33.             controller: ApiEstablishmentGetByUserController::class,
  34.         ),
  35.         new GetCollection(),
  36.         new Get(
  37.             normalizationContext: ['groups' => ['establishment:list', 'establishment:view']]
  38.         ),
  39.         new Post(
  40.             uriTemplate: '/establishment/login/{key}',
  41.             controller: ApiEstablishmentLoginController::class,
  42.             read: false,
  43.             deserialize: false
  44.         ),
  45.         new Post(
  46.             uriTemplate: '/establishment/join',
  47.             controller: ApiEstablishmentJoinController::class,
  48.             read: false,
  49.         ),
  50.         new Post(
  51.             uriTemplate: '/establishment/register',
  52.             controller: ApiEstablishmentRegisterController::class,
  53.             denormalizationContext: ['groups' => ['establishment:register']],
  54.             write: false
  55.         ),
  56.     ],
  57.     normalizationContext: ['groups' => ['establishment:list']]
  58. )]
  59. class Establishment implements WalletInterface
  60. {
  61.     use DateTrait;
  62.     use ActivableTrait;
  63.     use ArrayableTrait;
  64.     use CurrentStateTrait;
  65.     use DeletableTrait;
  66.     use WalletTrait;
  67.     #[ORM\Id]
  68.     #[ORM\GeneratedValue]
  69.     #[ORM\Column]
  70.     #[Groups(['establishment:list'])]
  71.     private ?int $id = null;
  72.     #[ORM\Column(length: 255)]
  73.     #[Groups(['establishment:list', 'establishment:register', 'establishment:login'])]
  74.     private ?string $name = null;
  75.     #[ORM\Column(length: 255, nullable: true)]
  76.     #[Groups(['establishment:list', 'establishment:register'])]
  77.     private ?string $slogan = null;
  78.     #[ORM\Column(type: Types::TEXT)]
  79.     #[Groups(['establishment:view', 'establishment:register'])]
  80.     private ?string $content = null;
  81.     #[ORM\ManyToOne(cascade: ["persist", "remove"])]
  82.     #[ORM\JoinColumn(nullable: true)]
  83.     #[Groups(['establishment:list'])]
  84.     private ?Attachment $thumbnail = null;
  85.     #[ORM\ManyToOne(cascade: ["persist", "remove"])]
  86.     #[ORM\JoinColumn(nullable: true)]
  87.     #[Groups(['establishment:list'])]
  88.     private ?Attachment $thumbnailSmall = null;
  89.     #[ORM\ManyToOne(cascade: ["persist", "remove"])]
  90.     #[ORM\JoinColumn(nullable: true)]
  91.     #[Groups(['establishment:list'])]
  92.     private ?Attachment $thumbnailBlack = null;
  93.     #[ORM\ManyToOne(cascade: ["persist", "remove"])]
  94.     #[ORM\JoinColumn(nullable: true)]
  95.     #[Groups(['establishment:list'])]
  96.     private ?Attachment $thumbnailBlackSmall = null;
  97.     #[ORM\Column(length: 255, nullable: true)]
  98.     private ?string $thumbnailDisplay;
  99.     #[ORM\ManyToOne(inversedBy: 'establishments')]
  100.     #[ORM\JoinColumn(nullable: false)]
  101.     private ?User $user = null;
  102.     #[ORM\ManyToOne(cascade: ["persist"])]
  103.     #[ORM\JoinColumn(nullable: false)]
  104.     #[Groups(['establishment:view', 'establishment:register'])]
  105.     private ?Address $address = null;
  106.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Department::class, orphanRemoval: true)]
  107.     private Collection $departments;
  108.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Document::class, cascade: ["persist", "remove"], orphanRemoval: true)]
  109.     #[Groups(['establishment:view'])]
  110.     private Collection $documents;
  111.     #[ORM\Column(length: 180)]
  112.     #[Groups(['establishment:view', 'establishment:register'])]
  113.     private ?string $email = null;
  114.     #[ORM\Column(length: 15)]
  115.     #[Groups(['establishment:view', 'establishment:register'])]
  116.     private ?string $phone = null;
  117.     #[ORM\Column(nullable: true, options: ["unsigned" => true])]
  118.     #[Groups(['establishment:view', 'establishment:register'])]
  119.     private ?int $size = 0;
  120.     #[ORM\Column(length: 255)]
  121.     #[Groups(['establishment:view', 'establishment:register'])]
  122.     private ?string $type = '';
  123.     #[ORM\Column(length: 255)]
  124.     #[Groups(['establishment:view', 'establishment:register'])]
  125.     private ?string $objective = '';
  126.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: ConnectionLog::class, orphanRemoval: true)]
  127.     private Collection $connectionLogs;
  128.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Client::class, orphanRemoval: true)]
  129.     private Collection $clients;
  130.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Planning::class, orphanRemoval: true)]
  131.     private Collection $plannings;
  132.     #[ORM\ManyToOne]
  133.     #[Groups(['establishment:list'])]
  134.     private ?Currency $currency = null;
  135.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Invitation::class)]
  136.     private Collection $invitations;
  137.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Operation::class, orphanRemoval: true)]
  138.     private Collection $operations;
  139.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Article::class, orphanRemoval: true)]
  140.     private Collection $articles;
  141.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Collections::class, orphanRemoval: true)]
  142.     private Collection $collections;
  143.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Journal::class, orphanRemoval: true)]
  144.     private Collection $journals;
  145.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Supply::class, orphanRemoval: true)]
  146.     private Collection $supplies;
  147.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Promotion::class, orphanRemoval: true)]
  148.     private Collection $promotions;
  149.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Rate::class, orphanRemoval: true, cascade: ['persist'])]
  150.     private Collection $rates;
  151.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Employee::class)]
  152.     private Collection $employees;
  153.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Subscription::class, cascade: ["all"])]
  154.     private Collection $subscriptions;
  155.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Order::class, orphanRemoval: true)]
  156.     private Collection $orders;
  157.     #[ORM\OneToOne(mappedBy: 'establishment', cascade: ['persist', 'remove'])]
  158.     private ?Configuration $configuration = null;
  159.     #[ORM\ManyToOne]
  160.     private ?Model $model = null;
  161.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Menu::class, orphanRemoval: true)]
  162.     private Collection $menus;
  163.     #[ORM\Column(length: 255, nullable: true)]
  164.     private ?string $slug = null;
  165.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: QrCode::class, orphanRemoval: true)]
  166.     private Collection $qrCodes;
  167.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Bot::class, orphanRemoval: true)]
  168.     private Collection $bots;
  169.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Role::class)]
  170.     private Collection $roleWorkers;
  171.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Advertisement::class, orphanRemoval: true)]
  172.     private Collection $advertisements;
  173.     #[ORM\Column(length: 255, nullable: true)]
  174.     private ?string $rccm = null;
  175.     #[ORM\Column(length: 255, nullable: true)]
  176.     private ?string $idNat = null;
  177.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Contract::class)]
  178.     private Collection $contracts;
  179.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Mutuality::class)]
  180.     private Collection $mutualities;
  181.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: MutualityCategory::class)]
  182.     private Collection $mutualityCategories;
  183.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: CardType::class)]
  184.     private Collection $cardTypes;
  185.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Gateway::class, orphanRemoval: true)]
  186.     private Collection $gateways;
  187.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: Currency::class, orphanRemoval: true, cascade: ['persist'])]
  188.     private Collection $currencies;
  189.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: ArticleDepartment::class, orphanRemoval: true)]
  190.     private Collection $articleDepartments;
  191.     #[ORM\OneToMany(mappedBy: 'establishment', targetEntity: WalletOperation::class)]
  192.     private Collection $walletOperations;
  193.     public function __construct()
  194.     {
  195.         $this->isActive = 0;
  196.         $this->currentState = 'draft';
  197.         if (!$this->createdAt) $this->createdAt = new DateTimeImmutable();
  198.         $this->updatedAt = new DateTimeImmutable();
  199.         $this->thumbnailDisplay = Kimia::THUMBNAIL_PROFILE;
  200.         $this->supportWallets();
  201.         $this->departments = new ArrayCollection();
  202.         $this->articles = new ArrayCollection();
  203.         $this->collections = new ArrayCollection();
  204.         $this->promotions = new ArrayCollection();
  205.         $this->supplies = new ArrayCollection();
  206.         $this->clients = new ArrayCollection();
  207.         $this->operations = new ArrayCollection();
  208.         $this->plannings = new ArrayCollection();
  209.         $this->invitations = new ArrayCollection();
  210.         $this->documents = new ArrayCollection();
  211.         $this->journals = new ArrayCollection();
  212.         $this->connectionLogs = new ArrayCollection();
  213.         $this->rates = new ArrayCollection();
  214.         $this->employees = new ArrayCollection();
  215.         $this->subscriptions = new ArrayCollection();
  216.         $this->orders = new ArrayCollection();
  217.         $this->menus = new ArrayCollection();
  218.         $this->qrCodes = new ArrayCollection();
  219.         $this->bots = new ArrayCollection();
  220.         $this->roleWorkers = new ArrayCollection();
  221.         $this->advertisements = new ArrayCollection();
  222.         $this->contracts = new ArrayCollection();
  223.         $this->mutualities = new ArrayCollection();
  224.         $this->mutualityCategories = new ArrayCollection();
  225.         $this->cardTypes = new ArrayCollection();
  226.         $this->gateways = new ArrayCollection();
  227.         $this->currencies = new ArrayCollection();
  228.         $this->articleDepartments = new ArrayCollection();
  229.         $this->walletOperations = new ArrayCollection();
  230.     }
  231.     public function getId(): ?int
  232.     {
  233.         return $this->id;
  234.     }
  235.     public function getName(): ?string
  236.     {
  237.         return $this->name;
  238.     }
  239.     public function setName(string $name): self
  240.     {
  241.         $this->name = $name;
  242.         return $this;
  243.     }
  244.     public function getSlogan(): ?string
  245.     {
  246.         return $this->slogan;
  247.     }
  248.     public function setSlogan(?string $slogan): self
  249.     {
  250.         $this->slogan = $slogan;
  251.         return $this;
  252.     }
  253.     public function getContent(): ?string
  254.     {
  255.         return $this->content;
  256.     }
  257.     public function setContent(string $content): self
  258.     {
  259.         $this->content = $content;
  260.         return $this;
  261.     }
  262.     public function getThumbnail(): ?Attachment
  263.     {
  264.         return $this->thumbnail;
  265.     }
  266.     public function setThumbnail(?Attachment $thumbnail): self
  267.     {
  268.         $this->thumbnail = $thumbnail;
  269.         return $this;
  270.     }
  271.     public function getThumbnailSmall(): ?Attachment
  272.     {
  273.         return $this->thumbnailSmall;
  274.     }
  275.     public function setThumbnailSmall(?Attachment $thumbnailSmall): self
  276.     {
  277.         $this->thumbnailSmall = $thumbnailSmall;
  278.         return $this;
  279.     }
  280.     public function getThumbnailBlack(): ?Attachment
  281.     {
  282.         return $this->thumbnailBlack;
  283.     }
  284.     public function setThumbnailBlack(?Attachment $thumbnail): self
  285.     {
  286.         $this->thumbnailBlack = $thumbnail;
  287.         return $this;
  288.     }
  289.     public function getThumbnailBlackSmall(): ?Attachment
  290.     {
  291.         return $this->thumbnailBlackSmall;
  292.     }
  293.     public function setThumbnailBlackSmall(?Attachment $thumbnailSmall): self
  294.     {
  295.         $this->thumbnailBlackSmall = $thumbnailSmall;
  296.         return $this;
  297.     }
  298.     public function getThumbnailDisplay(): ?string
  299.     {
  300.         return $this->thumbnailDisplay;
  301.     }
  302.     public function setThumbnailDisplay(?string $thumbnailDisplay): self
  303.     {
  304.         $this->thumbnailDisplay = $thumbnailDisplay;
  305.         return $this;
  306.     }
  307.     public function getUser(): ?User
  308.     {
  309.         return $this->user;
  310.     }
  311.     public function setUser(?User $user): self
  312.     {
  313.         $this->user = $user;
  314.         return $this;
  315.     }
  316.     public function getAddress(): ?Address
  317.     {
  318.         return $this->address;
  319.     }
  320.     public function setAddress(?Address $address): self
  321.     {
  322.         $this->address = $address;
  323.         return $this;
  324.     }
  325.     /**
  326.      * @return Collection<int, Department>
  327.      */
  328.     public function getDepartments(): Collection
  329.     {
  330.         return $this->departments;
  331.     }
  332.     public function addDepartment(Department $department): self
  333.     {
  334.         if (!$this->departments->contains($department)) {
  335.             $this->departments->add($department);
  336.             $department->setEstablishment($this);
  337.         }
  338.         return $this;
  339.     }
  340.     public function removeDepartment(Department $department): self
  341.     {
  342.         if ($this->departments->removeElement($department)) {
  343.             // set the owning side to null (unless already changed)
  344.             if ($department->getEstablishment() === $this) {
  345.                 $department->setEstablishment(null);
  346.             }
  347.         }
  348.         return $this;
  349.     }
  350.     /**
  351.      * @return Collection<int, Document>
  352.      */
  353.     public function getDocuments(): Collection
  354.     {
  355.         return $this->documents;
  356.     }
  357.     public function addDocument(Document $document): self
  358.     {
  359.         if (!$this->documents->contains($document)) {
  360.             $this->documents->add($document);
  361.             $document->setEstablishment($this);
  362.         }
  363.         return $this;
  364.     }
  365.     public function removeDocument(Document $document): self
  366.     {
  367.         if ($this->documents->removeElement($document)) {
  368.             // set the owning side to null (unless already changed)
  369.             if ($document->getEstablishment() === $this) {
  370.                 $document->setEstablishment(null);
  371.             }
  372.         }
  373.         return $this;
  374.     }
  375.     public function getEmail(): ?string
  376.     {
  377.         return $this->email;
  378.     }
  379.     public function setEmail(string $email): self
  380.     {
  381.         $this->email = $email;
  382.         return $this;
  383.     }
  384.     public function getPhone(): ?string
  385.     {
  386.         return $this->phone;
  387.     }
  388.     public function setPhone(string $phone): self
  389.     {
  390.         $this->phone = preg_replace('/^(\+243|0|00243)([0-9]{9})$/', '243$2', $phone);
  391.         return $this;
  392.     }
  393.     public function getSize(): ?int
  394.     {
  395.         return $this->size;
  396.     }
  397.     public function setSize(?int $size): self
  398.     {
  399.         $this->size = $size;
  400.         return $this;
  401.     }
  402.     public function getType(): ?string
  403.     {
  404.         return $this->type;
  405.     }
  406.     public static function getTypeList(): array
  407.     {
  408.         return [
  409.             "Facturation" => Kimia::TYPE_BILLING,
  410.             "Billetterie" => Kimia::TYPE_TICKET,
  411.         ];
  412.     }
  413.     public function setType(string $type): self
  414.     {
  415.         $this->type = $type;
  416.         return $this;
  417.     }
  418.     public function getObjective(): ?string
  419.     {
  420.         return $this->objective;
  421.     }
  422.     public function setObjective(string $objective): self
  423.     {
  424.         $this->objective = $objective;
  425.         return $this;
  426.     }
  427.     /**
  428.      * @return Collection<int, ConnectionLog>
  429.      */
  430.     public function getConnectionLogs(): Collection
  431.     {
  432.         return $this->connectionLogs;
  433.     }
  434.     public function addConnectionLog(ConnectionLog $connectionLog): self
  435.     {
  436.         if (!$this->connectionLogs->contains($connectionLog)) {
  437.             $this->connectionLogs->add($connectionLog);
  438.             $connectionLog->setEstablishment($this);
  439.         }
  440.         return $this;
  441.     }
  442.     public function removeConnectionLog(ConnectionLog $connectionLog): self
  443.     {
  444.         if ($this->connectionLogs->removeElement($connectionLog)) {
  445.             // set the owning side to null (unless already changed)
  446.             if ($connectionLog->getEstablishment() === $this) {
  447.                 $connectionLog->setEstablishment(null);
  448.             }
  449.         }
  450.         return $this;
  451.     }
  452.     /**
  453.      * @return Collection<int, Client>
  454.      */
  455.     public function getClients(): Collection
  456.     {
  457.         return $this->clients;
  458.     }
  459.     public function addClient(Client $client): self
  460.     {
  461.         if (!$this->clients->contains($client)) {
  462.             $this->clients->add($client);
  463.             $client->setEstablishment($this);
  464.         }
  465.         return $this;
  466.     }
  467.     public function removeClient(Client $client): self
  468.     {
  469.         if ($this->clients->removeElement($client)) {
  470.             // set the owning side to null (unless already changed)
  471.             if ($client->getEstablishment() === $this) {
  472.                 $client->setEstablishment(null);
  473.             }
  474.         }
  475.         return $this;
  476.     }
  477.     /**
  478.      * @return Collection<int, Planning>
  479.      */
  480.     public function getPlannings(): Collection
  481.     {
  482.         return $this->plannings;
  483.     }
  484.     public function addPlanning(Planning $planning): self
  485.     {
  486.         if (!$this->plannings->contains($planning)) {
  487.             $this->plannings->add($planning);
  488.             $planning->setEstablishment($this);
  489.         }
  490.         return $this;
  491.     }
  492.     public function removePlanning(Planning $planning): self
  493.     {
  494.         if ($this->plannings->removeElement($planning)) {
  495.             // set the owning side to null (unless already changed)
  496.             if ($planning->getEstablishment() === $this) {
  497.                 $planning->setEstablishment(null);
  498.             }
  499.         }
  500.         return $this;
  501.     }
  502.     public function getCurrency(): ?Currency
  503.     {
  504.         return $this->currency;
  505.     }
  506.     public function setCurrency(?Currency $currency): self
  507.     {
  508.         $this->currency = $currency;
  509.         return $this;
  510.     }
  511.     /**
  512.      * @return Collection<int, Invitation>
  513.      */
  514.     public function getInvitations(): Collection
  515.     {
  516.         return $this->invitations;
  517.     }
  518.     public function addInvitation(Invitation $invitation): self
  519.     {
  520.         if (!$this->invitations->contains($invitation)) {
  521.             $this->invitations->add($invitation);
  522.             $invitation->setEstablishment($this);
  523.         }
  524.         return $this;
  525.     }
  526.     public function removeInvitation(Invitation $invitation): self
  527.     {
  528.         if ($this->invitations->removeElement($invitation)) {
  529.             // set the owning side to null (unless already changed)
  530.             if ($invitation->getEstablishment() === $this) {
  531.                 $invitation->setEstablishment(null);
  532.             }
  533.         }
  534.         return $this;
  535.     }
  536.     /**
  537.      * @return Collection<int, Operation>
  538.      */
  539.     public function getOperations(): Collection
  540.     {
  541.         return $this->operations;
  542.     }
  543.     public function addOperation(Operation $operation): self
  544.     {
  545.         if (!$this->operations->contains($operation)) {
  546.             $this->operations->add($operation);
  547.             $operation->setEstablishment($this);
  548.         }
  549.         return $this;
  550.     }
  551.     public function removeOperation(Operation $operation): self
  552.     {
  553.         if ($this->operations->removeElement($operation)) {
  554.             // set the owning side to null (unless already changed)
  555.             if ($operation->getEstablishment() === $this) {
  556.                 $operation->setEstablishment(null);
  557.             }
  558.         }
  559.         return $this;
  560.     }
  561.     /**
  562.      * @return Collection<int, Article>
  563.      */
  564.     public function getArticles(): Collection
  565.     {
  566.         return $this->articles;
  567.     }
  568.     public function addArticle(Article $article): self
  569.     {
  570.         if (!$this->articles->contains($article)) {
  571.             $this->articles->add($article);
  572.             $article->setEstablishment($this);
  573.         }
  574.         return $this;
  575.     }
  576.     public function removeArticle(Article $article): self
  577.     {
  578.         if ($this->articles->removeElement($article)) {
  579.             // set the owning side to null (unless already changed)
  580.             if ($article->getEstablishment() === $this) {
  581.                 $article->setEstablishment(null);
  582.             }
  583.         }
  584.         return $this;
  585.     }
  586.     /**
  587.      * @return Collection<int, Collections>
  588.      */
  589.     public function getCollections(): Collection
  590.     {
  591.         return $this->collections;
  592.     }
  593.     public function addCollection(Collections $collection): self
  594.     {
  595.         if (!$this->collections->contains($collection)) {
  596.             $this->collections->add($collection);
  597.             $collection->setEstablishment($this);
  598.         }
  599.         return $this;
  600.     }
  601.     public function removeCollection(Collections $collection): self
  602.     {
  603.         if ($this->collections->removeElement($collection)) {
  604.             // set the owning side to null (unless already changed)
  605.             if ($collection->getEstablishment() === $this) {
  606.                 $collection->setEstablishment(null);
  607.             }
  608.         }
  609.         return $this;
  610.     }
  611.     /**
  612.      * @return Collection<int, Journal>
  613.      */
  614.     public function getJournals(): Collection
  615.     {
  616.         return $this->journals;
  617.     }
  618.     public function addJournal(Journal $journal): self
  619.     {
  620.         if (!$this->journals->contains($journal)) {
  621.             $this->journals->add($journal);
  622.             $journal->setEstablishment($this);
  623.         }
  624.         return $this;
  625.     }
  626.     public function removeJournal(Journal $journal): self
  627.     {
  628.         if ($this->journals->removeElement($journal)) {
  629.             // set the owning side to null (unless already changed)
  630.             if ($journal->getEstablishment() === $this) {
  631.                 $journal->setEstablishment(null);
  632.             }
  633.         }
  634.         return $this;
  635.     }
  636.     /**
  637.      * @return Collection<int, Supply>
  638.      */
  639.     public function getSupplies(): Collection
  640.     {
  641.         return $this->supplies;
  642.     }
  643.     public function addSupply(Supply $supply): self
  644.     {
  645.         if (!$this->supplies->contains($supply)) {
  646.             $this->supplies->add($supply);
  647.             $supply->setEstablishment($this);
  648.         }
  649.         return $this;
  650.     }
  651.     public function removeSupply(Supply $supply): self
  652.     {
  653.         if ($this->supplies->removeElement($supply)) {
  654.             // set the owning side to null (unless already changed)
  655.             if ($supply->getEstablishment() === $this) {
  656.                 $supply->setEstablishment(null);
  657.             }
  658.         }
  659.         return $this;
  660.     }
  661.     /**
  662.      * @return Collection<int, Promotion>
  663.      */
  664.     public function getPromotions(): Collection
  665.     {
  666.         return $this->promotions;
  667.     }
  668.     public function addPromotion(Promotion $promotion): self
  669.     {
  670.         if (!$this->promotions->contains($promotion)) {
  671.             $this->promotions->add($promotion);
  672.             $promotion->setEstablishment($this);
  673.         }
  674.         return $this;
  675.     }
  676.     public function removePromotion(Promotion $promotion): self
  677.     {
  678.         if ($this->promotions->removeElement($promotion)) {
  679.             // set the owning side to null (unless already changed)
  680.             if ($promotion->getEstablishment() === $this) {
  681.                 $promotion->setEstablishment(null);
  682.             }
  683.         }
  684.         return $this;
  685.     }
  686.     /**
  687.      * @return Collection<int, Rate>
  688.      */
  689.     public function getRates(): Collection
  690.     {
  691.         return $this->rates;
  692.     }
  693.     public function addRate(Rate $rate): self
  694.     {
  695.         if (!$this->rates->contains($rate)) {
  696.             $this->rates->add($rate);
  697.             $rate->setEstablishment($this);
  698.         }
  699.         return $this;
  700.     }
  701.     public function removeRate(Rate $rate): self
  702.     {
  703.         if ($this->rates->removeElement($rate)) {
  704.             // set the owning side to null (unless already changed)
  705.             if ($rate->getEstablishment() === $this) {
  706.                 $rate->setEstablishment(null);
  707.             }
  708.         }
  709.         return $this;
  710.     }
  711.     /**
  712.      * @return Collection<int, Employee>
  713.      */
  714.     public function getEmployees(): Collection
  715.     {
  716.         return $this->employees;
  717.     }
  718.     public function addEmployee(Employee $employee): self
  719.     {
  720.         if (!$this->employees->contains($employee)) {
  721.             $this->employees->add($employee);
  722.             $employee->setEstablishment($this);
  723.         }
  724.         return $this;
  725.     }
  726.     public function removeEmployee(Employee $employee): self
  727.     {
  728.         if ($this->employees->removeElement($employee)) {
  729.             // set the owning side to null (unless already changed)
  730.             if ($employee->getEstablishment() === $this) {
  731.                 $employee->setEstablishment(null);
  732.             }
  733.         }
  734.         return $this;
  735.     }
  736.     public function getSubscription(): ?Subscription
  737.     {
  738.         return $this->subscriptions->last();
  739.     }
  740.     /**
  741.      * @return Collection<int, Subscription>
  742.      */
  743.     public function getSubscriptions(): Collection
  744.     {
  745.         return $this->subscriptions;
  746.     }
  747.     public function addSubscription(Subscription $subscription): self
  748.     {
  749.         if (!$this->subscriptions->contains($subscription)) {
  750.             $this->subscriptions->add($subscription);
  751.             $subscription->setEstablishment($this);
  752.         }
  753.         return $this;
  754.     }
  755.     public function removeSubscription(Subscription $subscription): self
  756.     {
  757.         if ($this->subscriptions->removeElement($subscription)) {
  758.             // set the owning side to null (unless already changed)
  759.             if ($subscription->getEstablishment() === $this) {
  760.                 $subscription->setEstablishment(null);
  761.             }
  762.         }
  763.         return $this;
  764.     }
  765.     /**
  766.      * @return Collection<int, Order>
  767.      */
  768.     public function getOrders(): Collection
  769.     {
  770.         return $this->orders;
  771.     }
  772.     public function addOrder(Order $order): self
  773.     {
  774.         if (!$this->orders->contains($order)) {
  775.             $this->orders->add($order);
  776.             $order->setEstablishment($this);
  777.         }
  778.         return $this;
  779.     }
  780.     public function removeOrder(Order $order): self
  781.     {
  782.         if ($this->orders->removeElement($order)) {
  783.             // set the owning side to null (unless already changed)
  784.             if ($order->getEstablishment() === $this) {
  785.                 $order->setEstablishment(null);
  786.             }
  787.         }
  788.         return $this;
  789.     }
  790.     public function getConfiguration(): ?Configuration
  791.     {
  792.         return $this->configuration;
  793.     }
  794.     public function setConfiguration(Configuration $configuration): self
  795.     {
  796.         // set the owning side of the relation if necessary
  797.         if ($configuration->getEstablishment() !== $this) {
  798.             $configuration->setEstablishment($this);
  799.         }
  800.         $this->configuration = $configuration;
  801.         return $this;
  802.     }
  803.     public function getModel(): ?Model
  804.     {
  805.         return $this->model;
  806.     }
  807.     public function setModel(?Model $model): self
  808.     {
  809.         $this->model = $model;
  810.         return $this;
  811.     }
  812.     /**
  813.      * @return Collection<int, Menu>
  814.      */
  815.     public function getMenus(): Collection
  816.     {
  817.         return $this->menus;
  818.     }
  819.     public function addMenu(Menu $menu): self
  820.     {
  821.         if (!$this->menus->contains($menu)) {
  822.             $this->menus->add($menu);
  823.             $menu->setEstablishment($this);
  824.         }
  825.         return $this;
  826.     }
  827.     public function removeMenu(Menu $menu): self
  828.     {
  829.         if ($this->menus->removeElement($menu)) {
  830.             // set the owning side to null (unless already changed)
  831.             if ($menu->getEstablishment() === $this) {
  832.                 $menu->setEstablishment(null);
  833.             }
  834.         }
  835.         return $this;
  836.     }
  837.     public function getSlug(): ?string
  838.     {
  839.         return $this->slug;
  840.     }
  841.     public function setSlug(?string $slug): self
  842.     {
  843.         $this->slug = $slug;
  844.         return $this;
  845.     }
  846.     public function checkSubscription(): null|Subscription
  847.     {
  848.         $last_subscription = $this->getSubscriptions()->last();
  849.         if ($last_subscription && $last_subscription->getExpirationDays()) {
  850.             return $last_subscription;
  851.         }
  852.         return null;
  853.     }
  854.     public function checkUserMember(User $user): bool|ReadableCollection
  855.     {
  856.         $isAdmin = $user === $this->getUser();
  857.         return $isAdmin ??
  858.             $this->getEmployees()->map(fn(Employee $e) => $user === $e->getUser()) ??
  859.             $this->getInvitations()->map(fn(Invitation $i) => $user->getEmail() === $i->getEmail());
  860.     }
  861.     /**
  862.      * @return Collection<int, QrCode>
  863.      */
  864.     public function getQrCodes(): Collection
  865.     {
  866.         return $this->qrCodes;
  867.     }
  868.     public function addQrCode(QrCode $qrCode): static
  869.     {
  870.         if (!$this->qrCodes->contains($qrCode)) {
  871.             $this->qrCodes->add($qrCode);
  872.             $qrCode->setEstablishment($this);
  873.         }
  874.         return $this;
  875.     }
  876.     public function removeQrCode(QrCode $qrCode): static
  877.     {
  878.         if ($this->qrCodes->removeElement($qrCode)) {
  879.             // set the owning side to null (unless already changed)
  880.             if ($qrCode->getEstablishment() === $this) {
  881.                 $qrCode->setEstablishment(null);
  882.             }
  883.         }
  884.         return $this;
  885.     }
  886.     /**
  887.      * @return Collection<int, Bot>
  888.      */
  889.     public function getBots(): Collection
  890.     {
  891.         return $this->bots;
  892.     }
  893.     public function addBot(Bot $bot): static
  894.     {
  895.         if (!$this->bots->contains($bot)) {
  896.             $this->bots->add($bot);
  897.             $bot->setEstablishment($this);
  898.         }
  899.         return $this;
  900.     }
  901.     public function removeBot(Bot $bot): static
  902.     {
  903.         if ($this->bots->removeElement($bot)) {
  904.             // set the owning side to null (unless already changed)
  905.             if ($bot->getEstablishment() === $this) {
  906.                 $bot->setEstablishment(null);
  907.             }
  908.         }
  909.         return $this;
  910.     }
  911.     public function getRapportWallets(): array
  912.     {
  913.         $wallets = [];
  914.         $this->departments
  915.             ->map(function (Department $department) use (&$wallets) {
  916.                 $wallets = array_merge($wallets, $department->getWallets());
  917.             });
  918.         return $wallets;
  919.     }
  920.     public function __toString(): string
  921.     {
  922.         return $this->name;
  923.     }
  924.     /**
  925.      * @return Collection<int, Role>
  926.      */
  927.     public function getRoleWorkers(): Collection
  928.     {
  929.         return $this->roleWorkers;
  930.     }
  931.     public function addRoleWorker(Role $roleWorker): static
  932.     {
  933.         if (!$this->roleWorkers->contains($roleWorker)) {
  934.             $this->roleWorkers->add($roleWorker);
  935.             $roleWorker->setEstablishment($this);
  936.         }
  937.         return $this;
  938.     }
  939.     public function removeRoleWorker(Role $roleWorker): static
  940.     {
  941.         if ($this->roleWorkers->removeElement($roleWorker)) {
  942.             // set the owning side to null (unless already changed)
  943.             if ($roleWorker->getEstablishment() === $this) {
  944.                 $roleWorker->setEstablishment(null);
  945.             }
  946.         }
  947.         return $this;
  948.     }
  949.     /**
  950.      * @return Collection<int, Advertisement>
  951.      */
  952.     public function getAdvertisements(): Collection
  953.     {
  954.         return $this->advertisements;
  955.     }
  956.     public function addAdvertisement(Advertisement $advertisement): static
  957.     {
  958.         if (!$this->advertisements->contains($advertisement)) {
  959.             $this->advertisements->add($advertisement);
  960.             $advertisement->setEstablishment($this);
  961.         }
  962.         return $this;
  963.     }
  964.     public function removeAdvertisement(Advertisement $advertisement): static
  965.     {
  966.         if ($this->advertisements->removeElement($advertisement)) {
  967.             // set the owning side to null (unless already changed)
  968.             if ($advertisement->getEstablishment() === $this) {
  969.                 $advertisement->setEstablishment(null);
  970.             }
  971.         }
  972.         return $this;
  973.     }
  974.     public function getRccm(): ?string
  975.     {
  976.         return $this->rccm;
  977.     }
  978.     public function setRccm(?string $rccm): static
  979.     {
  980.         $this->rccm = $rccm;
  981.         return $this;
  982.     }
  983.     public function getIdNat(): ?string
  984.     {
  985.         return $this->idNat;
  986.     }
  987.     public function setIdNat(?string $idNat): static
  988.     {
  989.         $this->idNat = $idNat;
  990.         return $this;
  991.     }
  992.     /**
  993.      * @return Collection<int, Contract>
  994.      */
  995.     public function getContracts(): Collection
  996.     {
  997.         return $this->contracts;
  998.     }
  999.     public function addContract(Contract $contract): static
  1000.     {
  1001.         if (!$this->contracts->contains($contract)) {
  1002.             $this->contracts->add($contract);
  1003.             $contract->setEstablishment($this);
  1004.         }
  1005.         return $this;
  1006.     }
  1007.     public function removeContract(Contract $contract): static
  1008.     {
  1009.         if ($this->contracts->removeElement($contract)) {
  1010.             // set the owning side to null (unless already changed)
  1011.             if ($contract->getEstablishment() === $this) {
  1012.                 $contract->setEstablishment(null);
  1013.             }
  1014.         }
  1015.         return $this;
  1016.     }
  1017.     /**
  1018.      * @return Collection<int, Mutuality>
  1019.      */
  1020.     public function getMutualities(): Collection
  1021.     {
  1022.         return $this->mutualities;
  1023.     }
  1024.     public function addMutuality(Mutuality $mutuality): static
  1025.     {
  1026.         if (!$this->mutualities->contains($mutuality)) {
  1027.             $this->mutualities->add($mutuality);
  1028.             $mutuality->setEstablishment($this);
  1029.         }
  1030.         return $this;
  1031.     }
  1032.     public function removeMutuality(Mutuality $mutuality): static
  1033.     {
  1034.         if ($this->mutualities->removeElement($mutuality)) {
  1035.             // set the owning side to null (unless already changed)
  1036.             if ($mutuality->getEstablishment() === $this) {
  1037.                 $mutuality->setEstablishment(null);
  1038.             }
  1039.         }
  1040.         return $this;
  1041.     }
  1042.     /**
  1043.      * @return Collection<int, MutualityCategory>
  1044.      */
  1045.     public function getMutualityCategories(): Collection
  1046.     {
  1047.         return $this->mutualityCategories;
  1048.     }
  1049.     public function addMutualityCategory(MutualityCategory $mutualityCategory): static
  1050.     {
  1051.         if (!$this->mutualityCategories->contains($mutualityCategory)) {
  1052.             $this->mutualityCategories->add($mutualityCategory);
  1053.             $mutualityCategory->setEstablishment($this);
  1054.         }
  1055.         return $this;
  1056.     }
  1057.     public function removeMutualityCategory(MutualityCategory $mutualityCategory): static
  1058.     {
  1059.         if ($this->mutualityCategories->removeElement($mutualityCategory)) {
  1060.             // set the owning side to null (unless already changed)
  1061.             if ($mutualityCategory->getEstablishment() === $this) {
  1062.                 $mutualityCategory->setEstablishment(null);
  1063.             }
  1064.         }
  1065.         return $this;
  1066.     }
  1067.     /**
  1068.      * @return Collection<int, CardType>
  1069.      */
  1070.     public function getCardTypes(): Collection
  1071.     {
  1072.         return $this->cardTypes;
  1073.     }
  1074.     public function addCardType(CardType $cardType): static
  1075.     {
  1076.         if (!$this->cardTypes->contains($cardType)) {
  1077.             $this->cardTypes->add($cardType);
  1078.             $cardType->setEstablishment($this);
  1079.         }
  1080.         return $this;
  1081.     }
  1082.     public function removeCardType(CardType $cardType): static
  1083.     {
  1084.         if ($this->cardTypes->removeElement($cardType)) {
  1085.             // set the owning side to null (unless already changed)
  1086.             if ($cardType->getEstablishment() === $this) {
  1087.                 $cardType->setEstablishment(null);
  1088.             }
  1089.         }
  1090.         return $this;
  1091.     }
  1092.     /**
  1093.      * @return Collection<int, Gateway>
  1094.      */
  1095.     public function getGateways(): Collection
  1096.     {
  1097.         return $this->gateways;
  1098.     }
  1099.     public function addGateway(Gateway $gateway): static
  1100.     {
  1101.         if (!$this->gateways->contains($gateway)) {
  1102.             $this->gateways->add($gateway);
  1103.             $gateway->setEstablishment($this);
  1104.         }
  1105.         return $this;
  1106.     }
  1107.     public function removeGateway(Gateway $gateway): static
  1108.     {
  1109.         if ($this->gateways->removeElement($gateway)) {
  1110.             // set the owning side to null (unless already changed)
  1111.             if ($gateway->getEstablishment() === $this) {
  1112.                 $gateway->setEstablishment(null);
  1113.             }
  1114.         }
  1115.         return $this;
  1116.     }
  1117.     /**
  1118.      * @return Collection<int, Currency>
  1119.      */
  1120.     public function getCurrencies(): Collection
  1121.     {
  1122.         return $this->currencies;
  1123.     }
  1124.     public function addCurrency(Currency $currency): static
  1125.     {
  1126.         if (!$this->currencies->contains($currency)) {
  1127.             $this->currencies->add($currency);
  1128.             $currency->setEstablishment($this);
  1129.         }
  1130.         return $this;
  1131.     }
  1132.     public function removeCurrency(Currency $currency): static
  1133.     {
  1134.         if ($this->currencies->removeElement($currency)) {
  1135.             // set the owning side to null (unless already changed)
  1136.             if ($currency->getEstablishment() === $this) {
  1137.                 $currency->setEstablishment(null);
  1138.             }
  1139.         }
  1140.         return $this;
  1141.     }
  1142.     /**
  1143.      * @return Collection<int, ArticleDepartment>
  1144.      */
  1145.     public function getArticleDepartments(): Collection
  1146.     {
  1147.         return $this->articleDepartments;
  1148.     }
  1149.     public function addArticleDepartment(ArticleDepartment $articleDepartment): static
  1150.     {
  1151.         if (!$this->articleDepartments->contains($articleDepartment)) {
  1152.             $this->articleDepartments->add($articleDepartment);
  1153.             $articleDepartment->setEstablishment($this);
  1154.         }
  1155.         return $this;
  1156.     }
  1157.     public function removeArticleDepartment(ArticleDepartment $articleDepartment): static
  1158.     {
  1159.         if ($this->articleDepartments->removeElement($articleDepartment)) {
  1160.             // set the owning side to null (unless already changed)
  1161.             if ($articleDepartment->getEstablishment() === $this) {
  1162.                 $articleDepartment->setEstablishment(null);
  1163.             }
  1164.         }
  1165.         return $this;
  1166.     }
  1167.     public function getCurrencyDefault()
  1168.     {
  1169.         return $this->getCurrencies()
  1170.             ->filter(fn(Currency $currency) => $currency->isIsDefault())
  1171.             ->first();
  1172.     }
  1173.     /**
  1174.      * @return Collection<int, WalletOperation>
  1175.      */
  1176.     public function getWalletOperations(): Collection
  1177.     {
  1178.         return $this->walletOperations;
  1179.     }
  1180.     public function addWalletOperation(WalletOperation $walletOperation): static
  1181.     {
  1182.         if (!$this->walletOperations->contains($walletOperation)) {
  1183.             $this->walletOperations->add($walletOperation);
  1184.             $walletOperation->setEstablishment($this);
  1185.         }
  1186.         return $this;
  1187.     }
  1188.     public function removeWalletOperation(WalletOperation $walletOperation): static
  1189.     {
  1190.         if ($this->walletOperations->removeElement($walletOperation)) {
  1191.             // set the owning side to null (unless already changed)
  1192.             if ($walletOperation->getEstablishment() === $this) {
  1193.                 $walletOperation->setEstablishment(null);
  1194.             }
  1195.         }
  1196.         return $this;
  1197.     }
  1198. }