src/Entity/Company/Company.php line 49

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Company;
  3. use App\Entity\Accounting\OADA\CompanyAccount;
  4. use App\Entity\Accounting\OADA\FiscalYear;
  5. use App\Entity\Accounting\OADA\OADAAccount;
  6. use App\Entity\Accounting\OADA\Transaction;
  7. use App\Entity\ChangeRate;
  8. use App\Entity\Department\Department;
  9. use App\Entity\Department\Section;
  10. use App\Entity\Docs\Finance\Payment\Transfer;
  11. use ApiPlatform\Metadata\ApiResource;
  12. use ApiPlatform\Metadata\Get;
  13. use ApiPlatform\Metadata\GetCollection;
  14. use ApiPlatform\Metadata\Patch;
  15. use App\Entity\Docs\Finance\Project;
  16. use App\Entity\ParamsApp;
  17. use App\Entity\User;
  18. use App\Entity\Utils\Contact;
  19. use Doctrine\Common\Collections\ArrayCollection;
  20. use Doctrine\Common\Collections\Collection;
  21. use Doctrine\ORM\Mapping as ORM;
  22. use App\Entity\Utils\TimestampTrait;
  23. use App\Entity\Utils\AccountVerification;
  24. use Symfony\Component\Validator\Constraints as Assert;
  25. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  26. use Symfony\Component\Serializer\Annotation\Groups as sGroup;
  27. /**
  28.  * @ORM\HasLifecycleCallbacks()
  29.  * @ORM\Entity(repositoryClass="App\Repository\Company\CompanyRepository")
  30.  * @UniqueEntity(fields={"fullname"}, message="Ce nom existe déjà")
  31.  * @UniqueEntity(fields={"representativeEmail"}, message="Cet email existe déjà")
  32.  * @UniqueEntity(fields={"representativePhone"}, message="Ce numéro existe déjà")
  33.  */
  34. #[ApiResource(
  35.     normalizationContext:["groups" => ["company:seach"]]
  36. )]
  37. #[Get(
  38.     security:"is_granted('ROLE_ADMIN')"
  39. )]
  40. #[GetCollection(
  41.     security:"is_granted('ROLE_ADMIN')"
  42. )]
  43. #[Patch(
  44.     security:"is_granted('ROLE_ADMIN')"
  45. )]
  46. class Company
  47. {
  48.     use TimestampTrait;
  49.     /**
  50.      * @ORM\Id()
  51.      * @ORM\GeneratedValue()
  52.      * @ORM\Column(type="integer")
  53.      * @sGroup({"company:seach","rmq:user", "app:params:get"})
  54.      */
  55.     private $id;
  56.     /**
  57.      * @ORM\Column(type="string", length=255, unique=true)
  58.      * @sGroup({"company:seach","rmq:user", "app:params:get"})
  59.      */
  60.     private $fullname;
  61.     /**
  62.      * @ORM\Column(type="string", length=255, nullable=true)
  63.      */
  64.     private $abbreviation;
  65.     /**
  66.      * @ORM\Column(type="string", length=255)
  67.      * @Assert\Length(4)
  68.      */
  69.     private $creationDate;
  70.     /**
  71.      * @ORM\Column(type="string", length=255, unique=true)
  72.      * @Assert\Email
  73.      * 
  74.      */
  75.     private $representativeEmail;
  76.     /**
  77.      * @ORM\Column(type="string", length=255, unique=true)
  78.      * @Assert\Length(10)
  79.      */
  80.     private $representativePhone;
  81.     /**
  82.      * @ORM\OneToOne(targetEntity="App\Entity\Utils\AccountVerification", cascade={"persist", "remove"})
  83.      */
  84.     private $accountVerification;
  85.     /**
  86.      * @ORM\OneToOne(targetEntity="App\Entity\Company\Juridiction", cascade={"persist", "remove"})
  87.      */
  88.     private $juridiction;
  89.     /**
  90.      * @ORM\OneToOne(targetEntity="App\Entity\Company\Certification", cascade={"persist", "remove"})
  91.      */
  92.     private $certification;
  93.     /**
  94.      * @ORM\Column(type="string", length=255)
  95.      */
  96.     private $username;
  97.     /**
  98.      * @ORM\ManyToMany(targetEntity=Department::class, inversedBy="companies",cascade={"persist"})
  99.      */
  100.     private $departments;
  101.     /**
  102.      * @ORM\OneToMany(targetEntity="App\Entity\User", mappedBy="company")
  103.      */
  104.     private $users;
  105.     /**
  106.      * @ORM\OneToMany(targetEntity="App\Entity\User", mappedBy="companyOwner")
  107.      */
  108.     private $owners;
  109.     /**
  110.      * @ORM\OneToMany(targetEntity=Department::class, mappedBy="company")
  111.      */
  112.     private $departmentsAdded;
  113.     /**
  114.      * @ORM\OneToMany(targetEntity=Section::class, mappedBy="company")
  115.      */
  116.     private $sectionsAdded;
  117.     /**
  118.      * @ORM\OneToMany(targetEntity=Contact::class, mappedBy="company")
  119.      */
  120.     private $contacts;
  121.     /**
  122.      * @ORM\OneToMany(targetEntity=Project::class, mappedBy="company", cascade={"persist"})
  123.      */
  124.     private $projects;
  125.     /**
  126.      * @ORM\OneToMany(targetEntity=Transfer::class, mappedBy="company")
  127.      */
  128.     private $transfers;
  129.     /**
  130.      * @ORM\OneToMany(targetEntity=FiscalYear::class, mappedBy="company")
  131.      */
  132.     private $fiscalYears;
  133.     /**
  134.      * @ORM\OneToMany(targetEntity=Transaction::class, mappedBy="company")
  135.      */
  136.     private $transactionCheckout;
  137.     /**
  138.      * @ORM\OneToMany(targetEntity=CompanyAccount::class, mappedBy="company")
  139.      */
  140.     private $companyAccounts;
  141.     /**
  142.      * @ORM\OneToMany(targetEntity=OADAAccount::class, mappedBy="company")
  143.      */
  144.     private $oADAAccounts;
  145.     /**
  146.      * @ORM\OneToMany(targetEntity=ParamsApp::class, mappedBy="company")
  147.      */
  148.     private $paramsApps;
  149.     /**
  150.      * @ORM\OneToMany(targetEntity=ChangeRate::class, mappedBy="company")
  151.      */
  152.     private $changeRates;
  153.     public function __construct()
  154.     {
  155.         $this->departments = new ArrayCollection();
  156.         $this->users = new ArrayCollection();
  157.         $this->owners = new ArrayCollection();
  158.         $this->departmentsAdded = new ArrayCollection();
  159.         $this->sectionsAdded = new ArrayCollection();
  160.         $this->contacts = new ArrayCollection();
  161.         $this->username base64_encode(uniqid());
  162.         $this->projects = new ArrayCollection();
  163.         $this->transfers = new ArrayCollection();
  164.         $this->fiscalYears = new ArrayCollection();
  165.         $this->transactionCheckout = new ArrayCollection();
  166.         $this->companyAccounts = new ArrayCollection();
  167.         $this->oADAAccounts = new ArrayCollection();
  168.         $this->paramsApps = new ArrayCollection();
  169.         $this->changeRates = new ArrayCollection();
  170.     }
  171.     public function getId(): ?int
  172.     {
  173.         return $this->id;
  174.     }
  175.     public function getFullname(): ?string
  176.     {
  177.         return $this->fullname;
  178.     }
  179.     public function setFullname(string $fullname): self
  180.     {
  181.         $this->fullname $fullname;
  182.         return $this;
  183.     }
  184.     public function getAbbreviation(): ?string
  185.     {
  186.         return $this->abbreviation;
  187.     }
  188.     public function setAbbreviation(?string $abbreviation): self
  189.     {
  190.         $this->abbreviation $abbreviation;
  191.         return $this;
  192.     }
  193.     public function getCreationDate(): ?string
  194.     {
  195.         return $this->creationDate;
  196.     }
  197.     public function setCreationDate(string $creationDate): self
  198.     {
  199.         $this->creationDate $creationDate;
  200.         return $this;
  201.     }
  202.     public function getRepresentativeEmail(): ?string
  203.     {
  204.         return $this->representativeEmail;
  205.     }
  206.     public function setRepresentativeEmail(string $representativeEmail): self
  207.     {
  208.         $this->representativeEmail $representativeEmail;
  209.         return $this;
  210.     }
  211.     public function getRepresentativePhone(): ?string
  212.     {
  213.         return $this->representativePhone;
  214.     }
  215.     public function setRepresentativePhone(string $representativePhone): self
  216.     {
  217.         $this->representativePhone $representativePhone;
  218.         return $this;
  219.     }
  220.     public function getAccountVerification(): ?AccountVerification
  221.     {
  222.         return $this->accountVerification;
  223.     }
  224.     public function setAccountVerification(?AccountVerification $accountVerification): self
  225.     {
  226.         $this->accountVerification $accountVerification;
  227.         return $this;
  228.     }
  229.     public function getJuridiction(): ?Juridiction
  230.     {
  231.         return $this->juridiction;
  232.     }
  233.     public function setJuridiction(?Juridiction $juridiction): self
  234.     {
  235.         $this->juridiction $juridiction;
  236.         return $this;
  237.     }
  238.     public function getCertification(): ?Certification
  239.     {
  240.         return $this->certification;
  241.     }
  242.     public function setCertification(?Certification $certification): self
  243.     {
  244.         $this->certification $certification;
  245.         return $this;
  246.     }
  247.     public function getUsername(): ?string
  248.     {
  249.         return $this->username;
  250.     }
  251.     public function setUsername(string $username): self
  252.     {
  253.         $this->username $username;
  254.         return $this;
  255.     }
  256.     /**
  257.      * @return Collection|Department[]
  258.      */
  259.     public function getDepartments(): Collection
  260.     {
  261.         return $this->departments;
  262.     }
  263.     public function addDepartment(Department $department): self
  264.     {
  265.         if (!$this->departments->contains($department)) {
  266.             $this->departments[] = $department;
  267.         }
  268.         return $this;
  269.     }
  270.     public function removeDepartment(Department $department): self
  271.     {
  272.         if ($this->departments->contains($department)) {
  273.             $this->departments->removeElement($department);
  274.         }
  275.         return $this;
  276.     }
  277.     /**
  278.      * @return Collection|User[]
  279.      */
  280.     public function getUsers(): Collection
  281.     {
  282.         return $this->users;
  283.     }
  284.     public function addUser(User $user): self
  285.     {
  286.         if (!$this->users->contains($user)) {
  287.             $this->users[] = $user;
  288.             $user->setCompany($this);
  289.         }
  290.         return $this;
  291.     }
  292.     public function removeUser(User $user): self
  293.     {
  294.         if ($this->users->contains($user)) {
  295.             $this->users->removeElement($user);
  296.             // set the owning side to null (unless already changed)
  297.             if ($user->getCompany() === $this) {
  298.                 $user->setCompany(null);
  299.             }
  300.         }
  301.         return $this;
  302.     }
  303.     /**
  304.      * @return Collection|User[]
  305.      */
  306.     public function getOwners(): Collection
  307.     {
  308.         return $this->owners;
  309.     }
  310.     public function addOwner(User $owner): self
  311.     {
  312.         if (!$this->owners->contains($owner)) {
  313.             $this->owners[] = $owner;
  314.             $owner->setCompanyOwner($this);
  315.         }
  316.         return $this;
  317.     }
  318.     public function removeOwner(User $owner): self
  319.     {
  320.         if ($this->owners->contains($owner)) {
  321.             $this->owners->removeElement($owner);
  322.             // set the owning side to null (unless already changed)
  323.             if ($owner->getCompanyOwner() === $this) {
  324.                 $owner->setCompanyOwner(null);
  325.             }
  326.         }
  327.         return $this;
  328.     }
  329.     /**
  330.      * @return Collection|Department[]
  331.      */
  332.     public function getDepartmentsAdded(): Collection
  333.     {
  334.         return $this->departmentsAdded;
  335.     }
  336.     public function addDepartmentsAdded(Department $departmentsAdded): self
  337.     {
  338.         if (!$this->departmentsAdded->contains($departmentsAdded)) {
  339.             $this->departmentsAdded[] = $departmentsAdded;
  340.             $departmentsAdded->setCompany($this);
  341.         }
  342.         return $this;
  343.     }
  344.     public function removeDepartmentsAdded(Department $departmentsAdded): self
  345.     {
  346.         if ($this->departmentsAdded->contains($departmentsAdded)) {
  347.             $this->departmentsAdded->removeElement($departmentsAdded);
  348.             // set the owning side to null (unless already changed)
  349.             if ($departmentsAdded->getCompany() === $this) {
  350.                 $departmentsAdded->setCompany(null);
  351.             }
  352.         }
  353.         return $this;
  354.     }
  355.     /**
  356.      * @return Collection|Section[]
  357.      */
  358.     public function getSectionsAdded(): Collection
  359.     {
  360.         return $this->sectionsAdded;
  361.     }
  362.     public function addSectionsAdded(Section $sectionsAdded): self
  363.     {
  364.         if (!$this->sectionsAdded->contains($sectionsAdded)) {
  365.             $this->sectionsAdded[] = $sectionsAdded;
  366.             $sectionsAdded->setCompany($this);
  367.         }
  368.         return $this;
  369.     }
  370.     public function removeSectionsAdded(Section $sectionsAdded): self
  371.     {
  372.         if ($this->sectionsAdded->contains($sectionsAdded)) {
  373.             $this->sectionsAdded->removeElement($sectionsAdded);
  374.             // set the owning side to null (unless already changed)
  375.             if ($sectionsAdded->getCompany() === $this) {
  376.                 $sectionsAdded->setCompany(null);
  377.             }
  378.         }
  379.         return $this;
  380.     }
  381.     /**
  382.      * @return Collection|Contact[]
  383.      */
  384.     public function getContacts(): Collection
  385.     {
  386.         return $this->contacts;
  387.     }
  388.     public function addContact(Contact $contact): self
  389.     {
  390.         if (!$this->contacts->contains($contact)) {
  391.             $this->contacts[] = $contact;
  392.             $contact->setCompany($this);
  393.         }
  394.         return $this;
  395.     }
  396.     public function removeContact(Contact $contact): self
  397.     {
  398.         if ($this->contacts->contains($contact)) {
  399.             $this->contacts->removeElement($contact);
  400.             // set the owning side to null (unless already changed)
  401.             if ($contact->getCompany() === $this) {
  402.                 $contact->setCompany(null);
  403.             }
  404.         }
  405.         return $this;
  406.     }
  407.     /**
  408.      * @return Collection|Project[]
  409.      */
  410.     public function getProjects(): Collection
  411.     {
  412.         return $this->projects;
  413.     }
  414.     public function addProject(Project $project): self
  415.     {
  416.         if (!$this->projects->contains($project)) {
  417.             $this->projects[] = $project;
  418.             $project->setCompany($this);
  419.         }
  420.         return $this;
  421.     }
  422.     public function removeProject(Project $project): self
  423.     {
  424.         if ($this->projects->removeElement($project)) {
  425.             // set the owning side to null (unless already changed)
  426.             if ($project->getCompany() === $this) {
  427.                 $project->setCompany(null);
  428.             }
  429.         }
  430.         return $this;
  431.     }
  432.     /**
  433.      * @return Transfer[]
  434.      */
  435.     public function getTransfers(): Collection
  436.     {
  437.         return $this->transfers;
  438.     }
  439.     public function addTransfer(Transfer $transfer): self
  440.     {
  441.         if (!$this->transfers->contains($transfer)) {
  442.             $this->transfers[] = $transfer;
  443.             $transfer->setCompany($this);
  444.         }
  445.         return $this;
  446.     }
  447.     public function removeTransfer(Transfer $transfer): self
  448.     {
  449.         if ($this->transfers->removeElement($transfer)) {
  450.             // set the owning side to null (unless already changed)
  451.             if ($transfer->getCompany() === $this) {
  452.                 $transfer->setCompany(null);
  453.             }
  454.         }
  455.         return $this;
  456.     }
  457.     /**
  458.      * @return float
  459.      */
  460.     public function soldTransferUSD()
  461.     {
  462.         /**
  463.          * @var Transfer[]
  464.          */
  465.         $transfers $this->getTransfers();
  466.         $sum 0;
  467.         foreach ($transfers as $key => $transfer) {
  468.             $sum += floatval($transfer->getCashoutUsd()) ;
  469.         }
  470.         return $sum;
  471.     }
  472.     /**
  473.      * @return float
  474.      * 
  475.      */
  476.     public function soldTransferCDF()
  477.     {
  478.         /**
  479.          * @var Transfer[]
  480.          */
  481.         $transfers $this->getTransfers();
  482.         $sum 0;
  483.         foreach ($transfers as $key => $transfer) {
  484.             $sum += floatval($transfer->getCashoutCdf());
  485.         }
  486.         return $sum;
  487.         
  488.     }
  489.     /**
  490.      * 
  491.      */
  492.     public function firstUser()
  493.     {
  494.         /**
  495.          * @var Department[]
  496.          */
  497.         $departments $this->getDepartments()->toArray();
  498.         foreach ($departments as $key => $department) {
  499.             $user $department->firstUser();
  500.             if (!is_null($user)) {
  501.                 return $user;
  502.             }
  503.         }
  504.         return null;
  505.     }
  506.     /**
  507.      * @return Collection<int, FiscalYear>
  508.      */
  509.     public function getFiscalYears(): Collection
  510.     {
  511.         return $this->fiscalYears;
  512.     }
  513.     public function addFiscalYear(FiscalYear $fiscalYear): self
  514.     {
  515.         if (!$this->fiscalYears->contains($fiscalYear)) {
  516.             $this->fiscalYears[] = $fiscalYear;
  517.             $fiscalYear->setCompany($this);
  518.         }
  519.         return $this;
  520.     }
  521.     public function removeFiscalYear(FiscalYear $fiscalYear): self
  522.     {
  523.         if ($this->fiscalYears->removeElement($fiscalYear)) {
  524.             // set the owning side to null (unless already changed)
  525.             if ($fiscalYear->getCompany() === $this) {
  526.                 $fiscalYear->setCompany(null);
  527.             }
  528.         }
  529.         return $this;
  530.     }
  531.     /**
  532.      * @return Collection<int, Transaction>
  533.      */
  534.     public function getTransactionCheckout(): Collection
  535.     {
  536.         return $this->transactionCheckout;
  537.     }
  538.     public function addTransactionCheckout(Transaction $transactionCheckout): self
  539.     {
  540.         if (!$this->transactionCheckout->contains($transactionCheckout)) {
  541.             $this->transactionCheckout[] = $transactionCheckout;
  542.             $transactionCheckout->setCompany($this);
  543.         }
  544.         return $this;
  545.     }
  546.     public function removeTransactionCheckout(Transaction $transactionCheckout): self
  547.     {
  548.         if ($this->transactionCheckout->removeElement($transactionCheckout)) {
  549.             // set the owning side to null (unless already changed)
  550.             if ($transactionCheckout->getCompany() === $this) {
  551.                 $transactionCheckout->setCompany(null);
  552.             }
  553.         }
  554.         return $this;
  555.     }
  556.     /**
  557.      * @return Collection<int, CompanyAccount>
  558.      */
  559.     public function getCompanyAccounts(): Collection
  560.     {
  561.         return $this->companyAccounts;
  562.     }
  563.     public function addCompanyAccount(CompanyAccount $companyAccount): self
  564.     {
  565.         if (!$this->companyAccounts->contains($companyAccount)) {
  566.             $this->companyAccounts[] = $companyAccount;
  567.             $companyAccount->setCompany($this);
  568.         }
  569.         return $this;
  570.     }
  571.     public function removeCompanyAccount(CompanyAccount $companyAccount): self
  572.     {
  573.         if ($this->companyAccounts->removeElement($companyAccount)) {
  574.             // set the owning side to null (unless already changed)
  575.             if ($companyAccount->getCompany() === $this) {
  576.                 $companyAccount->setCompany(null);
  577.             }
  578.         }
  579.         return $this;
  580.     }
  581.     /**
  582.      * @return Collection<int, OADAAccount>
  583.      */
  584.     public function getOADAAccounts(): Collection
  585.     {
  586.         return $this->oADAAccounts;
  587.     }
  588.     public function addOADAAccount(OADAAccount $oADAAccount): self
  589.     {
  590.         if (!$this->oADAAccounts->contains($oADAAccount)) {
  591.             $this->oADAAccounts[] = $oADAAccount;
  592.             $oADAAccount->setCompany($this);
  593.         }
  594.         return $this;
  595.     }
  596.     public function removeOADAAccount(OADAAccount $oADAAccount): self
  597.     {
  598.         if ($this->oADAAccounts->removeElement($oADAAccount)) {
  599.             // set the owning side to null (unless already changed)
  600.             if ($oADAAccount->getCompany() === $this) {
  601.                 $oADAAccount->setCompany(null);
  602.             }
  603.         }
  604.         return $this;
  605.     }
  606.     /**
  607.      * @return Collection<int, ParamsApp>
  608.      */
  609.     public function getParamsApps(): Collection
  610.     {
  611.         return $this->paramsApps;
  612.     }
  613.     public function addParamsApp(ParamsApp $paramsApp): self
  614.     {
  615.         if (!$this->paramsApps->contains($paramsApp)) {
  616.             $this->paramsApps[] = $paramsApp;
  617.             $paramsApp->setCompany($this);
  618.         }
  619.         return $this;
  620.     }
  621.     public function removeParamsApp(ParamsApp $paramsApp): self
  622.     {
  623.         if ($this->paramsApps->removeElement($paramsApp)) {
  624.             // set the owning side to null (unless already changed)
  625.             if ($paramsApp->getCompany() === $this) {
  626.                 $paramsApp->setCompany(null);
  627.             }
  628.         }
  629.         return $this;
  630.     }
  631.     /**
  632.      * @return Collection<int, ChangeRate>
  633.      */
  634.     public function getChangeRates(): Collection
  635.     {
  636.         return $this->changeRates;
  637.     }
  638.     public function addChangeRate(ChangeRate $changeRate): self
  639.     {
  640.         if (!$this->changeRates->contains($changeRate)) {
  641.             $this->changeRates[] = $changeRate;
  642.             $changeRate->setCompany($this);
  643.         }
  644.         return $this;
  645.     }
  646.     public function removeChangeRate(ChangeRate $changeRate): self
  647.     {
  648.         if ($this->changeRates->removeElement($changeRate)) {
  649.             // set the owning side to null (unless already changed)
  650.             if ($changeRate->getCompany() === $this) {
  651.                 $changeRate->setCompany(null);
  652.             }
  653.         }
  654.         return $this;
  655.     }
  656. }