src/Entity/User.php line 24

  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\Currency;
  4. use App\Enum\UnitType;
  5. use App\Enum\EmployeeStatus;
  6. use App\Enum\GroupName;
  7. use App\Enum\RegionEnum;
  8. use App\Repository\UserRepository;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\DBAL\Types\Types;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  14. use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  15. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  16. use Symfony\Component\Security\Core\User\UserInterface;
  17. use Gedmo\Timestampable\Traits\TimestampableEntity;
  18. #[ORM\Entity(repositoryClassUserRepository::class)]
  19. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  20. class User implements UserInterfacePasswordAuthenticatedUserInterface
  21. {
  22.     use TimestampableEntity;
  23.     public const ROLE_SUPER_ADMIN 'ROLE_SUPER_ADMIN';
  24.     public const ROLE_ADMIN 'ROLE_ADMIN';
  25.     public const ROLE_USER 'ROLE_USER';
  26.     public const ROLE_INDIVIDUAL_PAYEE 'ROLE_INDIVIDUAL_PAYEE';
  27.     public const ROLE_MANAGER 'ROLE_MANAGER';
  28.     public const ROLE_EXECUTIVE 'ROLE_EXECUTIVE';
  29.     public const ROLE_DEFAULT 'ROLE_USER';
  30.     #[ORM\Id]
  31.     #[ORM\GeneratedValue]
  32.     #[ORM\Column]
  33.     private ?int $id null;
  34.     #[ORM\Column(length320uniquetrue)]
  35.     private ?string $email null;
  36.     #[ORM\Column]
  37.     private array $roles = [];
  38.     /**
  39.      * @var string The hashed password
  40.      */
  41.     #[ORM\Column]
  42.     private ?string $password null;
  43.     public $plainPassword;
  44.     #[ORM\Column]
  45.     private bool $incentAccess true;
  46.     #[ORM\Column(length255nullabletrue)]
  47.     private ?GroupName $groupName null;
  48.     #[ORM\ManyToOne(targetEntityself::class, fetch"EAGER")]
  49.     private ?self $manager null;
  50.     #[ORM\Column(nullabletrue)]
  51.     private ?bool $creditEligible true;
  52.     #[ORM\Column(nullabletrue)]
  53.     private ?bool $commissionEligible true;
  54.     #[ORM\Column(length255nullabletrue)]
  55.     private ?string $employeeID null;
  56.     #[ORM\ManyToOne(fetch"EAGER")]
  57.     private ?Plan $plan null;
  58.     #[ORM\Column(length255nullabletrue)]
  59.     private ?EmployeeStatus $employeeStatus EmployeeStatus::ACTIVE;
  60.     #[ORM\Column(nullabletrue)]
  61.     private ?int $guaranteePeriod 0;
  62.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  63.     private ?\DateTimeInterface $guaranteeStartDate null;
  64.     #[ORM\OneToMany(mappedBy'user'targetEntityUserPaymentPeriod::class, orphanRemovaltrue)]
  65.     private Collection $userPaymentPeriods;
  66.     #[ORM\OneToMany(mappedBy'user'targetEntityAggregatedTrueUp::class)]
  67.     private Collection $aggregatedTrueUps;
  68.     #[ORM\Column(length255nullabletrue)]
  69.     private ?string $firstName null;
  70.     #[ORM\Column(length255nullabletrue)]
  71.     private ?string $lastName null;
  72.     #[ORM\OneToMany(mappedBy'user'targetEntityPosition::class, fetch'EAGER')]
  73.     private Collection $positions;
  74.     #[ORM\Column(length255nullabletrue)]
  75.     private ?string $managerName null;
  76.     #[ORM\Column(length500nullabletrue)]
  77.     private ?string $titleRole null;
  78.     #[ORM\Column(nullabletrue)]
  79.     private ?float $guaranteeAmount null;
  80.     #[ORM\Column(length255nullabletrue)]
  81.     private ?UnitType $guaranteeAmountUnitType null;
  82.     #[ORM\Column(length255nullabletrue)]
  83.     private ?UnitType $guaranteePeriodUnitType null;
  84.     #[ORM\OneToMany(mappedBy'user'targetEntityCommission::class)]
  85.     private Collection $commissions;
  86.     #[ORM\OneToMany(mappedBy'user'targetEntityCredit::class)]
  87.     private Collection $credits;
  88.     #[ORM\Column(length255nullabletrue)]
  89.     private ?string $middleName null;
  90.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  91.     private ?\DateTimeInterface $effectiveStartDate null;
  92.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  93.     private ?string $description null;
  94.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  95.     private ?\DateTimeInterface $hireDate null;
  96.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  97.     private ?\DateTimeInterface $terminationDate null;
  98.     #[ORM\Column]
  99.     private ?float $personalTarget 0;
  100.     #[ORM\Column]
  101.     private ?float $proratedPersonalTarget 0;
  102.     #[ORM\Column(length255)]
  103.     private ?Currency $personalCurrency Currency::USD;
  104.     #[ORM\Column]
  105.     private ?float $proratedSalary 0;
  106.     #[ORM\Column(length255)]
  107.     private ?Currency $paymentCurrency Currency::USD;
  108.     #[ORM\Column]
  109.     private ?float $salary 0;
  110.     #[ORM\Column(length255)]
  111.     private ?Currency $salaryCurrency Currency::USD;
  112.     #[ORM\OneToMany(mappedBy'user'targetEntityManualPayment::class)]
  113.     private Collection $manualPayments;
  114.     #[ORM\ManyToOne(inversedBy'users'fetch'EAGER')]
  115.     private ?Title $title null;
  116.     #[ORM\OneToMany(mappedBy'user'targetEntityOrderAssignment::class)]
  117.     private Collection $orderAssignments;
  118.     #[ORM\OneToMany(mappedBy'user'targetEntityEmployeeRepCode::class)]
  119.     private Collection $employeeRepCodes;
  120.     #[ORM\OneToMany(mappedBy'fromUser'targetEntityNamedRelationshipPosition::class)]
  121.     private Collection $fromNamedRelationshipPositions;
  122.     #[ORM\OneToMany(mappedBy'toUser'targetEntityNamedRelationshipPosition::class)]
  123.     private Collection $toNamedRelationshipPositions;
  124.     #[ORM\OneToMany(mappedBy'assignedUser'targetEntityLookUpTable::class)]
  125.     private Collection $lookUpTables;
  126.     #[ORM\OneToMany(mappedBy'user'targetEntityRateTableAssignment::class)]
  127.     private Collection $rateTableAssignments;
  128.     #[ORM\OneToMany(mappedBy'User'targetEntityRuleCondition::class)]
  129.     private Collection $ruleConditions;
  130.     #[ORM\OneToMany(mappedBy'user'targetEntityHierarchy::class, cascade: ['persist''remove'])]
  131.     private Collection $hierarchies;
  132.     #[ORM\OneToMany(mappedBy'parentUser'targetEntityHierarchy::class)]
  133.     #[ORM\OrderBy(['effectiveStartDate' => 'ASC'])]
  134.     private Collection $parentHierarchies;
  135.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  136.     private ?\DateTimeInterface $earningCommissionsStartDate null;
  137.     #[ORM\Column(nullabletrue)]
  138.     private ?int $earningCommissionsPeriod null;
  139.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  140.     private ?\DateTimeInterface $guaranteeAlertSentAt null;
  141.     #[ORM\ManyToOne(inversedBy'users'fetch'EAGER')]
  142.     private ?Region $region null;
  143.     #[ORM\OneToMany(mappedBy'user'targetEntityUserLogin::class)]
  144.     private Collection $userLogins;
  145.     #[ORM\OneToMany(mappedBy'user'targetEntityAdMapping::class)]
  146.     private Collection $adMappings;
  147.     #[ORM\OneToMany(mappedBy'user'targetEntityUserRegion::class, cascade: ['persist''remove'])]
  148.     private Collection $userRegions;
  149.     #[ORM\OneToMany(mappedBy'toUser'targetEntityCommissionShareRule::class)]
  150.     private Collection $commissionShareRulesTo;
  151.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  152.     private ?\DateTimeInterface $leaveOfAbsenceStartDate null;
  153.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  154.     private ?\DateTimeInterface $leaveOfAbsenceEndDate null;
  155.     public function __construct()
  156.     {
  157.         $this->userPaymentPeriods = new ArrayCollection();
  158.         $this->aggregatedTrueUps = new ArrayCollection();
  159.         $this->positions = new ArrayCollection();
  160.         $this->commissions = new ArrayCollection();
  161.         $this->credits = new ArrayCollection();
  162.         $this->manualPayments = new ArrayCollection();
  163.         $this->orderAssignments = new ArrayCollection();
  164.         $this->employeeRepCodes = new ArrayCollection();
  165.         $this->fromNamedRelationshipPositions = new ArrayCollection();
  166.         $this->toNamedRelationshipPositions = new ArrayCollection();
  167.         $this->lookUpTables = new ArrayCollection();
  168.         $this->rateTableAssignments = new ArrayCollection();
  169.         $this->ruleConditions = new ArrayCollection();
  170.         $this->hierarchies = new ArrayCollection();
  171.         $this->parentHierarchies = new ArrayCollection();
  172.         $this->userLogins = new ArrayCollection();
  173.         $this->adMappings = new ArrayCollection();
  174.         $this->userRegions = new ArrayCollection();
  175.         $this->hireDate = new \DateTime();
  176.         $this->commissionShareRulesTo = new ArrayCollection();
  177.     }
  178.     public function getId(): ?int
  179.     {
  180.         return $this->id;
  181.     }
  182.     public function getEmail(): ?string
  183.     {
  184.         return $this->email;
  185.     }
  186.     public function setEmail(string $email): self
  187.     {
  188.         $this->email $email;
  189.         return $this;
  190.     }
  191.     /**
  192.      * A visual identifier that represents this user.
  193.      *
  194.      * @see UserInterface
  195.      */
  196.     public function getUserIdentifier(): string
  197.     {
  198.         return (string) $this->email;
  199.     }
  200.     /**
  201.      * @see UserInterface
  202.      */
  203.     public function getRoles(): array
  204.     {
  205.         $roles $this->roles;
  206.         // guarantee every user at least has ROLE_USER
  207.         $roles[] = 'ROLE_USER';
  208.         return array_unique($roles);
  209.     }
  210.     public function setRoles(array $roles): self
  211.     {
  212.         $this->roles $roles;
  213.         return $this;
  214.     }
  215.     public function addRole($role): self
  216.     {
  217.         $roles $this->roles;
  218.         $roles[] = $role;
  219.         $this->setRoles(array_unique($roles));
  220.         return $this;
  221.     }
  222.     public static function getRolesList($secure false): array
  223.     {
  224.         $roles = [
  225.             self::ROLE_USER => 'User',
  226.             self::ROLE_SUPER_ADMIN => 'Super Admin',
  227.             self::ROLE_ADMIN => 'Admin',
  228.             self::ROLE_INDIVIDUAL_PAYEE => 'Individual Payee',
  229.             self::ROLE_MANAGER => 'Manager',
  230.             self::ROLE_EXECUTIVE => 'Executive',
  231.         ];
  232.         return $roles;
  233.     }
  234.     public function getRolesLabels(): string
  235.     {
  236.         $rolesList self::getRolesList();
  237.         $roles = [];
  238.         foreach ($this->getRoles() as $role) {
  239.             $label 'label-info';
  240.             if ($role === self::ROLE_SUPER_ADMIN){
  241.                 $label 'label-warning';
  242.             }
  243.             if ($role === self::ROLE_ADMIN){
  244.                 $label 'label-primary';
  245.             }
  246.             if ($role !== self::ROLE_DEFAULT) {
  247.                 $roles[] = "<span class='label {$label}'>{$rolesList[$role]}</span>&nbsp;";
  248.             }
  249.         }
  250.         return implode(' '$roles);
  251.     }
  252.     /**
  253.      * {@inheritdoc}
  254.      */
  255.     public function hasRole($role): bool
  256.     {
  257.         return in_array(strtoupper($role), $this->getRoles(), true);
  258.     }
  259.     /**
  260.      * @see PasswordAuthenticatedUserInterface
  261.      */
  262.     public function getPassword(): ?string
  263.     {
  264.         return $this->password;
  265.     }
  266.     public function setPassword(string $password): self
  267.     {
  268.         $this->password $password;
  269.         return $this;
  270.     }
  271.     /**
  272.      * @see UserInterface
  273.      */
  274.     public function eraseCredentials()
  275.     {
  276.         // If you store any temporary, sensitive data on the user, clear it here
  277.         // $this->plainPassword = null;
  278.     }
  279.     public function isIncentAccess(): ?bool
  280.     {
  281.         return $this->incentAccess;
  282.     }
  283.     public function setIncentAccess(bool $incentAccess): self
  284.     {
  285.         $this->incentAccess $incentAccess;
  286.         return $this;
  287.     }
  288.     public function getFullName(): ?string
  289.     {
  290.         $string sprintf('%s %s'$this->firstName$this->lastName);
  291.         if($this->getEmployeeID()){
  292.             $string sprintf('%s (%s)'$string$this->getEmployeeID());
  293.         }
  294.         return $string;
  295.     }
  296.     public function getGroupName(): ?GroupName
  297.     {
  298.         return $this->groupName;
  299.     }
  300.     public function setGroupName(?GroupName $groupName): self
  301.     {
  302.         $this->groupName $groupName;
  303.         return $this;
  304.     }
  305.     public function getManager(): ?self
  306.     {
  307.         return $this->manager;
  308.     }
  309.     public function setManager(?self $manager): self
  310.     {
  311.         $this->manager $manager;
  312.         return $this;
  313.     }
  314.     public function isCreditEligible(): ?bool
  315.     {
  316.         return $this->creditEligible;
  317.     }
  318.     public function setCreditEligible(?bool $creditEligible): self
  319.     {
  320.         $this->creditEligible $creditEligible;
  321.         return $this;
  322.     }
  323.     public function isCommissionEligible(): ?bool
  324.     {
  325.         return $this->commissionEligible;
  326.     }
  327.     public function setCommissionEligible(?bool $commissionEligible): self
  328.     {
  329.         $this->commissionEligible $commissionEligible;
  330.         return $this;
  331.     }
  332.     public function getEmployeeID(): ?string
  333.     {
  334.         return $this->employeeID;
  335.     }
  336.     public function setEmployeeID(?string $employeeID): self
  337.     {
  338.         $this->employeeID $employeeID;
  339.         return $this;
  340.     }
  341.     public function getPlan(): ?Plan
  342.     {
  343.         return $this->plan;
  344.     }
  345.     public function setPlan(?Plan $plan): self
  346.     {
  347.         $this->plan $plan;
  348.         return $this;
  349.     }
  350.     public function getEmployeeStatus(): ?EmployeeStatus
  351.     {
  352.         return $this->employeeStatus;
  353.     }
  354.     public function setEmployeeStatus(?EmployeeStatus $employeeStatus): self
  355.     {
  356.         $this->employeeStatus $employeeStatus;
  357.         return $this;
  358.     }
  359.     public function __toString()
  360.     {
  361.         return $this->getFullName() ?: $this->email;
  362.     }
  363.     public function getGuaranteePeriod(): ?int
  364.     {
  365.         return $this->guaranteePeriod;
  366.     }
  367.     public function setGuaranteePeriod(?int $guaranteePeriod): self
  368.     {
  369.         $this->guaranteePeriod $guaranteePeriod;
  370.         // reset alert sent at
  371.         $this->guaranteeAlertSentAt null;
  372.         return $this;
  373.     }
  374.     public function getGuaranteeStartDate(): ?\DateTimeInterface
  375.     {
  376.         return $this->guaranteeStartDate;
  377.     }
  378.     public function setGuaranteeStartDate(?\DateTimeInterface $guaranteeStartDate): self
  379.     {
  380.         $this->guaranteeStartDate $guaranteeStartDate;
  381.         // reset alert sent at
  382.         $this->guaranteeAlertSentAt null;
  383.         return $this;
  384.     }
  385.     public function getGuaranteeEndDate(): ?\DateTimeInterface
  386.     {
  387.         $startDate = clone $this->getGuaranteeStartDate();
  388.         if($startDate){
  389.             $startDate->modify("+{$this->getGuaranteePeriod()} months")->sub(new \DateInterval('P1D'));
  390.         }
  391.         return $startDate;
  392.     }
  393.     /**
  394.      * @return Collection<int, UserPaymentPeriod>
  395.      */
  396.     public function getFilteredUserPaymentPeriods(\DateTime $start\DateTime $end): Collection
  397.     {
  398.         return $this->userPaymentPeriods;
  399.     }
  400.     /**
  401.      * @return Collection<int, UserPaymentPeriod>
  402.      */
  403.     public function getUserPaymentPeriods(): Collection
  404.     {
  405.         return $this->userPaymentPeriods;
  406.     }
  407.     public function addUserPaymentPeriod(UserPaymentPeriod $userPaymentPeriod): self
  408.     {
  409.         if (!$this->userPaymentPeriods->contains($userPaymentPeriod)) {
  410.             $this->userPaymentPeriods->add($userPaymentPeriod);
  411.             $userPaymentPeriod->setUser($this);
  412.         }
  413.         return $this;
  414.     }
  415.     public function removeUserPaymentPeriod(UserPaymentPeriod $userPaymentPeriod): self
  416.     {
  417.         if ($this->userPaymentPeriods->removeElement($userPaymentPeriod)) {
  418.             // set the owning side to null (unless already changed)
  419.             if ($userPaymentPeriod->getUser() === $this) {
  420.                 $userPaymentPeriod->setUser(null);
  421.             }
  422.         }
  423.         return $this;
  424.     }
  425.     public function getUserPaymentPeriodsByDateRange(\DateTime $start\DateTime $end)
  426.     {
  427.         $upp = [];
  428.         foreach($this->userPaymentPeriods as $cand) {
  429.             if ($cand->getPaymentPeriod()->getStart() >= $start && $cand->getPaymentPeriod()->getEnd() <= $end) {
  430.                 $upp[] = $cand;
  431.             }
  432.         }
  433.         return $upp;
  434.     }
  435.     /**
  436.      * @return Collection<int, AggregatedTrueUp>
  437.      */
  438.     public function getAggregatedTrueUps(): Collection
  439.     {
  440.         return $this->aggregatedTrueUps;
  441.     }
  442.     public function addAggregatedTrueUp(AggregatedTrueUp $aggregatedTrueUp): self
  443.     {
  444.         if (!$this->aggregatedTrueUps->contains($aggregatedTrueUp)) {
  445.             $this->aggregatedTrueUps->add($aggregatedTrueUp);
  446.             $aggregatedTrueUp->setUser($this);
  447.         }
  448.         return $this;
  449.     }
  450.     public function removeAggregatedTrueUp(AggregatedTrueUp $aggregatedTrueUp): self
  451.     {
  452.         if ($this->aggregatedTrueUps->removeElement($aggregatedTrueUp)) {
  453.             // set the owning side to null (unless already changed)
  454.             if ($aggregatedTrueUp->getUser() === $this) {
  455.                 $aggregatedTrueUp->setUser(null);
  456.             }
  457.         }
  458.         return $this;
  459.     }
  460.     public static function getUserRoleChoices()
  461.     {
  462.         return [
  463.             self::ROLE_USER => self::ROLE_USER,
  464.             self::ROLE_ADMIN => self::ROLE_ADMIN
  465.         ];
  466.     }
  467.     public function getFirstName(): ?string
  468.     {
  469.         return $this->firstName;
  470.     }
  471.     public function setFirstName(?string $firstName): static
  472.     {
  473.         $this->firstName $firstName;
  474.         return $this;
  475.     }
  476.     public function getLastName(): ?string
  477.     {
  478.         return $this->lastName;
  479.     }
  480.     public function setLastName(?string $lastName): static
  481.     {
  482.         $this->lastName $lastName;
  483.         return $this;
  484.     }
  485.     /**
  486.      * @return Collection<int, Position>
  487.      */
  488.     public function getPositions(): Collection
  489.     {
  490.         return $this->positions;
  491.     }
  492.     public function addPosition(Position $position): static
  493.     {
  494.         if (!$this->positions->contains($position)) {
  495.             $this->positions->add($position);
  496.             $position->setUser($this);
  497.         }
  498.         return $this;
  499.     }
  500.     public function removePosition(Position $position): static
  501.     {
  502.         if ($this->positions->removeElement($position)) {
  503.             // set the owning side to null (unless already changed)
  504.             if ($position->getUser() === $this) {
  505.                 $position->setUser(null);
  506.             }
  507.         }
  508.         return $this;
  509.     }
  510.     public function getManagerName(): ?string
  511.     {
  512.         return $this->managerName;
  513.     }
  514.     public function setManagerName(?string $managerName): static
  515.     {
  516.         $this->managerName $managerName;
  517.         return $this;
  518.     }
  519.     public function getTitleRole(): ?string
  520.     {
  521.         return $this->titleRole;
  522.     }
  523.     public function setTitleRole(?string $titleRole): self
  524.     {
  525.         $this->titleRole $titleRole;
  526.         return $this;
  527.     }
  528.     public function getGuaranteeAmount(): ?float
  529.     {
  530.         return $this->guaranteeAmount;
  531.     }
  532.     public function setGuaranteeAmount(?float $guaranteeAmount): self
  533.     {
  534.         $this->guaranteeAmount $guaranteeAmount;
  535.         return $this;
  536.     }
  537.     public function getGuaranteeAmountUnitType(): ?UnitType
  538.     {
  539.         return $this->guaranteeAmountUnitType;
  540.     }
  541.     public function setGuaranteeAmountUnitType(?UnitType $guaranteeAmountUnitType): self
  542.     {
  543.         $this->guaranteeAmountUnitType $guaranteeAmountUnitType;
  544.         return $this;
  545.     }
  546.     public function getGuaranteePeriodUnitType(): ?UnitType
  547.     {
  548.         return $this->guaranteePeriodUnitType;
  549.     }
  550.     public function setGuaranteePeriodUnitType(?UnitType $guaranteePeriodUnitType): self
  551.     {
  552.         $this->guaranteePeriodUnitType $guaranteePeriodUnitType;
  553.         return $this;
  554.     }
  555.     /**
  556.      * @return Collection<int, Commission>
  557.      */
  558.     public function getCommissions(): Collection
  559.     {
  560.         return $this->commissions;
  561.     }
  562.     public function addCommission(Commission $commission): static
  563.     {
  564.         if (!$this->commissions->contains($commission)) {
  565.             $this->commissions->add($commission);
  566.             $commission->setUser($this);
  567.         }
  568.         return $this;
  569.     }
  570.     public function removeCommission(Commission $commission): static
  571.     {
  572.         if ($this->commissions->removeElement($commission)) {
  573.             // set the owning side to null (unless already changed)
  574.             if ($commission->getUser() === $this) {
  575.                 $commission->setUser(null);
  576.             }
  577.         }
  578.         return $this;
  579.     }
  580.     /**
  581.      * @return Collection<int, Credit>
  582.      */
  583.     public function getCredits(): Collection
  584.     {
  585.         return $this->credits;
  586.     }
  587.     public function addCredit(Credit $credit): static
  588.     {
  589.         if (!$this->credits->contains($credit)) {
  590.             $this->credits->add($credit);
  591.             $credit->setUser($this);
  592.         }
  593.         return $this;
  594.     }
  595.     public function removeCredit(Credit $credit): static
  596.     {
  597.         if ($this->credits->removeElement($credit)) {
  598.             // set the owning side to null (unless already changed)
  599.             if ($credit->getUser() === $this) {
  600.                 $credit->setUser(null);
  601.             }
  602.         }
  603.         return $this;
  604.     }
  605.     public function getMiddleName(): ?string
  606.     {
  607.         return $this->middleName;
  608.     }
  609.     public function setMiddleName(?string $middleName): static
  610.     {
  611.         $this->middleName $middleName;
  612.         return $this;
  613.     }
  614.     public function getEffectiveStartDate(): ?\DateTimeInterface
  615.     {
  616.         return $this->effectiveStartDate;
  617.     }
  618.     public function setEffectiveStartDate(?\DateTimeInterface $effectiveStartDate): static
  619.     {
  620.         $this->effectiveStartDate $effectiveStartDate;
  621.         return $this;
  622.     }
  623.     public function getDescription(): ?string
  624.     {
  625.         return $this->description;
  626.     }
  627.     public function setDescription(?string $description): static
  628.     {
  629.         $this->description $description;
  630.         return $this;
  631.     }
  632.     public function getHireDate(): ?\DateTimeInterface
  633.     {
  634.         return $this->hireDate;
  635.     }
  636.     public function setHireDate(?\DateTimeInterface $hireDate): static
  637.     {
  638.         $this->hireDate $hireDate;
  639.         return $this;
  640.     }
  641.     public function getTerminationDate(): ?\DateTimeInterface
  642.     {
  643.         return $this->terminationDate;
  644.     }
  645.     public function setTerminationDate(?\DateTimeInterface $terminationDate): static
  646.     {
  647.         $this->terminationDate $terminationDate;
  648.         return $this;
  649.     }
  650.     public function getPersonalTarget(): ?float
  651.     {
  652.         return $this->personalTarget;
  653.     }
  654.     public function setPersonalTarget(float $personalTarget): static
  655.     {
  656.         $this->personalTarget $personalTarget;
  657.         return $this;
  658.     }
  659.     public function getProratedPersonalTarget(): ?float
  660.     {
  661.         return $this->proratedPersonalTarget;
  662.     }
  663.     public function setProratedPersonalTarget(float $proratedPersonalTarget): static
  664.     {
  665.         $this->proratedPersonalTarget $proratedPersonalTarget;
  666.         return $this;
  667.     }
  668.     public function getPersonalCurrency(): ?Currency
  669.     {
  670.         return $this->personalCurrency;
  671.     }
  672.     public function setPersonalCurrency(Currency $personalCurrency): static
  673.     {
  674.         $this->personalCurrency $personalCurrency;
  675.         return $this;
  676.     }
  677.     public function getProratedSalary(): ?float
  678.     {
  679.         return $this->proratedSalary;
  680.     }
  681.     public function setProratedSalary(float $proratedSalary): static
  682.     {
  683.         $this->proratedSalary $proratedSalary;
  684.         return $this;
  685.     }
  686.     public function getPaymentCurrency(): ?Currency
  687.     {
  688.         return $this->paymentCurrency;
  689.     }
  690.     public function setPaymentCurrency(Currency $paymentCurrency): static
  691.     {
  692.         $this->paymentCurrency $paymentCurrency;
  693.         return $this;
  694.     }
  695.     public function getSalary(): ?FLOAT
  696.     {
  697.         return $this->salary;
  698.     }
  699.     public function setSalary(float $salary): static
  700.     {
  701.         $this->salary $salary;
  702.         return $this;
  703.     }
  704.     public function getSalaryCurrency(): ?Currency
  705.     {
  706.         return $this->salaryCurrency;
  707.     }
  708.     public function setSalaryCurrency(Currency $salaryCurrency): static
  709.     {
  710.         $this->salaryCurrency $salaryCurrency;
  711.         return $this;
  712.     }
  713.     /**
  714.      * @return Collection<int, ManualPayment>
  715.      */
  716.     public function getManualPayments(): Collection
  717.     {
  718.         return $this->manualPayments;
  719.     }
  720.     public function addManualPayment(ManualPayment $manualPayment): static
  721.     {
  722.         if (!$this->manualPayments->contains($manualPayment)) {
  723.             $this->manualPayments->add($manualPayment);
  724.             $manualPayment->setUser($this);
  725.         }
  726.         return $this;
  727.     }
  728.     public function removeManualPayment(ManualPayment $manualPayment): static
  729.     {
  730.         if ($this->manualPayments->removeElement($manualPayment)) {
  731.             // set the owning side to null (unless already changed)
  732.             if ($manualPayment->getUser() === $this) {
  733.                 $manualPayment->setUser(null);
  734.             }
  735.         }
  736.         return $this;
  737.     }
  738.     public function getTitle(): ?Title
  739.     {
  740.         return $this->title;
  741.     }
  742.     public function setTitle(?Title $title): static
  743.     {
  744.         $this->title $title;
  745.         return $this;
  746.     }
  747.     public function getPositionTitleByDate($date)
  748.     {
  749.         if ($this->positions->isEmpty()) {
  750.             return $this->getTitle();
  751.         }
  752.         $positions $this->positions->toArray();
  753.         usort($positions, function($a$b) {
  754.             return $b->getEffectiveStartDate() <=> $a->getEffectiveStartDate();
  755.         });
  756.         foreach ($positions as $position) {
  757.             if ($position->getEffectiveStartDate() <= $date) {
  758.                 return $position->getTitle();
  759.             }
  760.         }
  761.         return $this->getTitle();
  762.     }
  763.     /**
  764.      * @return Collection<int, OrderAssignment>
  765.      */
  766.     public function getOrderAssignments(): Collection
  767.     {
  768.         return $this->orderAssignments;
  769.     }
  770.     public function addOrderAssignment(OrderAssignment $orderAssignment): static
  771.     {
  772.         if (!$this->orderAssignments->contains($orderAssignment)) {
  773.             $this->orderAssignments->add($orderAssignment);
  774.             $orderAssignment->setUser($this);
  775.         }
  776.         return $this;
  777.     }
  778.     public function removeOrderAssignment(OrderAssignment $orderAssignment): static
  779.     {
  780.         if ($this->orderAssignments->removeElement($orderAssignment)) {
  781.             // set the owning side to null (unless already changed)
  782.             if ($orderAssignment->getUser() === $this) {
  783.                 $orderAssignment->setUser(null);
  784.             }
  785.         }
  786.         return $this;
  787.     }
  788.     /**
  789.      * @return Collection<int, EmployeeRepCode>
  790.      */
  791.     public function getEmployeeRepCodes(): Collection
  792.     {
  793.         return $this->employeeRepCodes;
  794.     }
  795.     public function addEmployeeRepCode(EmployeeRepCode $employeeRepCode): static
  796.     {
  797.         if (!$this->employeeRepCodes->contains($employeeRepCode)) {
  798.             $this->employeeRepCodes->add($employeeRepCode);
  799.             $employeeRepCode->setUser($this);
  800.         }
  801.         return $this;
  802.     }
  803.     public function removeEmployeeRepCode(EmployeeRepCode $employeeRepCode): static
  804.     {
  805.         if ($this->employeeRepCodes->removeElement($employeeRepCode)) {
  806.             // set the owning side to null (unless already changed)
  807.             if ($employeeRepCode->getUser() === $this) {
  808.                 $employeeRepCode->setUser(null);
  809.             }
  810.         }
  811.         return $this;
  812.     }
  813.     /**
  814.      * @return Collection<int, NamedRelationshipPosition>
  815.      */
  816.     public function getFromNamedRelationshipPositions(): Collection
  817.     {
  818.         return $this->fromNamedRelationshipPositions;
  819.     }
  820.     public function addFromNamedRelationshipPosition(NamedRelationshipPosition $fromNamedRelationshipPosition): static
  821.     {
  822.         if (!$this->fromNamedRelationshipPositions->contains($fromNamedRelationshipPosition)) {
  823.             $this->fromNamedRelationshipPositions->add($fromNamedRelationshipPosition);
  824.             $fromNamedRelationshipPosition->setFromUser($this);
  825.         }
  826.         return $this;
  827.     }
  828.     public function removeFromNamedRelationshipPosition(NamedRelationshipPosition $fromNamedRelationshipPosition): static
  829.     {
  830.         if ($this->fromNamedRelationshipPositions->removeElement($fromNamedRelationshipPosition)) {
  831.             // set the owning side to null (unless already changed)
  832.             if ($fromNamedRelationshipPosition->getFromUser() === $this) {
  833.                 $fromNamedRelationshipPosition->setFromUser(null);
  834.             }
  835.         }
  836.         return $this;
  837.     }
  838.     /**
  839.      * @return Collection<int, NamedRelationshipPosition>
  840.      */
  841.     public function getToNamedRelationshipPositions(): Collection
  842.     {
  843.         return $this->toNamedRelationshipPositions;
  844.     }
  845.     public function addToNamedRelationshipPosition(NamedRelationshipPosition $toNamedRelationshipPosition): static
  846.     {
  847.         if (!$this->toNamedRelationshipPositions->contains($toNamedRelationshipPosition)) {
  848.             $this->toNamedRelationshipPositions->add($toNamedRelationshipPosition);
  849.             $toNamedRelationshipPosition->setToUser($this);
  850.         }
  851.         return $this;
  852.     }
  853.     public function removeToNamedRelationshipPosition(NamedRelationshipPosition $toNamedRelationshipPosition): static
  854.     {
  855.         if ($this->toNamedRelationshipPositions->removeElement($toNamedRelationshipPosition)) {
  856.             // set the owning side to null (unless already changed)
  857.             if ($toNamedRelationshipPosition->getToUser() === $this) {
  858.                 $toNamedRelationshipPosition->setToUser(null);
  859.             }
  860.         }
  861.         return $this;
  862.     }
  863.     /**
  864.      * @return Collection<int, LookUpTable>
  865.      */
  866.     public function getLookUpTables(): Collection
  867.     {
  868.         return $this->lookUpTables;
  869.     }
  870.     public function addLookUpTable(LookUpTable $lookUpTable): static
  871.     {
  872.         if (!$this->lookUpTables->contains($lookUpTable)) {
  873.             $this->lookUpTables->add($lookUpTable);
  874.             $lookUpTable->setAssignedUser($this);
  875.         }
  876.         return $this;
  877.     }
  878.     public function removeLookUpTable(LookUpTable $lookUpTable): static
  879.     {
  880.         if ($this->lookUpTables->removeElement($lookUpTable)) {
  881.             // set the owning side to null (unless already changed)
  882.             if ($lookUpTable->getAssignedUser() === $this) {
  883.                 $lookUpTable->setAssignedUser(null);
  884.             }
  885.         }
  886.         return $this;
  887.     }
  888.     /**
  889.      * @return Collection<int, RateTableAssignment>
  890.      */
  891.     public function getRateTableAssignments(): Collection
  892.     {
  893.         return $this->rateTableAssignments;
  894.     }
  895.     public function addRateTableAssignment(RateTableAssignment $rateTableAssignment): static
  896.     {
  897.         if (!$this->rateTableAssignments->contains($rateTableAssignment)) {
  898.             $this->rateTableAssignments->add($rateTableAssignment);
  899.             $rateTableAssignment->setUser($this);
  900.         }
  901.         return $this;
  902.     }
  903.     public function removeRateTableAssignment(RateTableAssignment $rateTableAssignment): static
  904.     {
  905.         if ($this->rateTableAssignments->removeElement($rateTableAssignment)) {
  906.             // set the owning side to null (unless already changed)
  907.             if ($rateTableAssignment->getUser() === $this) {
  908.                 $rateTableAssignment->setUser(null);
  909.             }
  910.         }
  911.         return $this;
  912.     }
  913.     /**
  914.      * @return Collection<int, RuleCondition>
  915.      */
  916.     public function getRuleConditions(): Collection
  917.     {
  918.         return $this->ruleConditions;
  919.     }
  920.     public function addRuleCondition(RuleCondition $ruleCondition): static
  921.     {
  922.         if (!$this->ruleConditions->contains($ruleCondition)) {
  923.             $this->ruleConditions->add($ruleCondition);
  924.             $ruleCondition->setUser($this);
  925.         }
  926.         return $this;
  927.     }
  928.     public function removeRuleCondition(RuleCondition $ruleCondition): static
  929.     {
  930.         if ($this->ruleConditions->removeElement($ruleCondition)) {
  931.             // set the owning side to null (unless already changed)
  932.             if ($ruleCondition->getUser() === $this) {
  933.                 $ruleCondition->setUser(null);
  934.             }
  935.         }
  936.         return $this;
  937.     }
  938.     /**
  939.      * @return Collection<int, Hierarchy>
  940.      */
  941.     public function getHierarchies(): Collection
  942.     {
  943.         return $this->hierarchies;
  944.     }
  945.     public function addHierarchy(Hierarchy $hierarchy): static
  946.     {
  947.         if (!$this->hierarchies->contains($hierarchy)) {
  948.             $this->hierarchies->add($hierarchy);
  949.             $hierarchy->setUser($this);
  950.         }
  951.         return $this;
  952.     }
  953.     public function removeHierarchy(Hierarchy $hierarchy): static
  954.     {
  955.         if ($this->hierarchies->removeElement($hierarchy)) {
  956.             // set the owning side to null (unless already changed)
  957.             if ($hierarchy->getUser() === $this) {
  958.                 $hierarchy->setUser(null);
  959.             }
  960.         }
  961.         return $this;
  962.     }
  963.     /**
  964.      * @return Collection<int, Hierarchy>
  965.      */
  966.     public function getParentHierarchies(): Collection
  967.     {
  968.         return $this->parentHierarchies;
  969.     }
  970.     public function addParentHierarchy(Hierarchy $parentHierarchy): static
  971.     {
  972.         if (!$this->parentHierarchies->contains($parentHierarchy)) {
  973.             $this->parentHierarchies->add($parentHierarchy);
  974.             $parentHierarchy->setParentUser($this);
  975.         }
  976.         return $this;
  977.     }
  978.     public function removeParentHierarchy(Hierarchy $parentHierarchy): static
  979.     {
  980.         if ($this->parentHierarchies->removeElement($parentHierarchy)) {
  981.             // set the owning side to null (unless already changed)
  982.             if ($parentHierarchy->getParentUser() === $this) {
  983.                 $parentHierarchy->setParentUser(null);
  984.             }
  985.         }
  986.         return $this;
  987.     }
  988.     public function getInitials(): string
  989.     {
  990.         $firstInitial '';
  991.         $lastInitial '';
  992.         if($this->getFirstName()) {
  993.             $firstInitial mb_substr($this->getFirstName(), 01);
  994.         }
  995.         if($this->getLastName()) {
  996.             $lastInitial mb_substr($this->getLastName(), 01);
  997.         }
  998.         return  $firstInitial $lastInitial;
  999.     }
  1000.     public function isAdmin(): bool
  1001.     {
  1002.         return $this->hasRole(self::ROLE_SUPER_ADMIN) || $this->hasRole(self::ROLE_ADMIN);
  1003.     }
  1004.     public function getEarningCommissionsStartDate(): ?\DateTimeInterface
  1005.     {
  1006.         return $this->earningCommissionsStartDate;
  1007.     }
  1008.     public function setEarningCommissionsStartDate(?\DateTimeInterface $earningCommissionsStartDate): static
  1009.     {
  1010.         $this->earningCommissionsStartDate $earningCommissionsStartDate;
  1011.         return $this;
  1012.     }
  1013.     public function getEarningCommissionsPeriod(): ?int
  1014.     {
  1015.         return $this->earningCommissionsPeriod;
  1016.     }
  1017.     public function setEarningCommissionsPeriod(?int $earningCommissionsPeriod): static
  1018.     {
  1019.         $this->earningCommissionsPeriod $earningCommissionsPeriod;
  1020.         return $this;
  1021.     }
  1022.     public function getGuaranteeAlertSentAt(): ?\DateTimeInterface
  1023.     {
  1024.         return $this->guaranteeAlertSentAt;
  1025.     }
  1026.     public function setGuaranteeAlertSentAt(?\DateTimeInterface $guaranteeAlertSentAt): static
  1027.     {
  1028.         $this->guaranteeAlertSentAt $guaranteeAlertSentAt;
  1029.         return $this;
  1030.     }
  1031.     public function getRegion(): ?Region
  1032.     {
  1033.         return $this->region;
  1034.     }
  1035.     public function setRegion(?Region $region): static
  1036.     {
  1037.         $this->region $region;
  1038.         return $this;
  1039.     }
  1040.     /**
  1041.      * @return Collection<int, UserLogin>
  1042.      */
  1043.     public function getUserLogins(): Collection
  1044.     {
  1045.         return $this->userLogins;
  1046.     }
  1047.     public function addUserLogin(UserLogin $userLogin): static
  1048.     {
  1049.         if (!$this->userLogins->contains($userLogin)) {
  1050.             $this->userLogins->add($userLogin);
  1051.             $userLogin->setUser($this);
  1052.         }
  1053.         return $this;
  1054.     }
  1055.     public function removeUserLogin(UserLogin $userLogin): static
  1056.     {
  1057.         if ($this->userLogins->removeElement($userLogin)) {
  1058.             // set the owning side to null (unless already changed)
  1059.             if ($userLogin->getUser() === $this) {
  1060.                 $userLogin->setUser(null);
  1061.             }
  1062.         }
  1063.         return $this;
  1064.     }
  1065.     /**
  1066.      * @return Collection<int, AdMapping>
  1067.      */
  1068.     public function getAdMappings(): Collection
  1069.     {
  1070.         return $this->adMappings;
  1071.     }
  1072.     public function addAdMapping(AdMapping $adMapping): static
  1073.     {
  1074.         if (!$this->adMappings->contains($adMapping)) {
  1075.             $this->adMappings->add($adMapping);
  1076.             $adMapping->setUser($this);
  1077.         }
  1078.         return $this;
  1079.     }
  1080.     public function removeAdMapping(AdMapping $adMapping): static
  1081.     {
  1082.         if ($this->adMappings->removeElement($adMapping)) {
  1083.             // set the owning side to null (unless already changed)
  1084.             if ($adMapping->getUser() === $this) {
  1085.                 $adMapping->setUser(null);
  1086.             }
  1087.         }
  1088.         return $this;
  1089.     }
  1090.     /**
  1091.      * @return Collection<int, UserRegion>
  1092.      */
  1093.     public function getUserRegions(): Collection
  1094.     {
  1095.         return $this->userRegions;
  1096.     }
  1097.     public function addUserRegion(UserRegion $userRegion): static
  1098.     {
  1099.         if (!$this->userRegions->contains($userRegion)) {
  1100.             $this->userRegions->add($userRegion);
  1101.             $userRegion->setUser($this);
  1102.         }
  1103.         return $this;
  1104.     }
  1105.     public function removeUserRegion(UserRegion $userRegion): static
  1106.     {
  1107.         if ($this->userRegions->removeElement($userRegion)) {
  1108.             // set the owning side to null (unless already changed)
  1109.             if ($userRegion->getUser() === $this) {
  1110.                 $userRegion->setUser(null);
  1111.             }
  1112.         }
  1113.         return $this;
  1114.     }
  1115.     /**
  1116.      * @return Collection<int, CommissionShareRule>
  1117.      */
  1118.     public function getCommissionShareRulesTo(): Collection
  1119.     {
  1120.         return $this->commissionShareRulesTo;
  1121.     }
  1122.     public function addCommissionShareRulesTo(CommissionShareRule $commissionShareRulesTo): static
  1123.     {
  1124.         if (!$this->commissionShareRulesTo->contains($commissionShareRulesTo)) {
  1125.             $this->commissionShareRulesTo->add($commissionShareRulesTo);
  1126.             $commissionShareRulesTo->setToUser($this);
  1127.         }
  1128.         return $this;
  1129.     }
  1130.     public function removeCommissionShareRulesTo(CommissionShareRule $commissionShareRulesTo): static
  1131.     {
  1132.         if ($this->commissionShareRulesTo->removeElement($commissionShareRulesTo)) {
  1133.             // set the owning side to null (unless already changed)
  1134.             if ($commissionShareRulesTo->getToUser() === $this) {
  1135.                 $commissionShareRulesTo->setToUser(null);
  1136.             }
  1137.         }
  1138.         return $this;
  1139.     }
  1140.     public function getLeaveOfAbsenceStartDate(): ?\DateTimeInterface
  1141.     {
  1142.         return $this->leaveOfAbsenceStartDate;
  1143.     }
  1144.     public function setLeaveOfAbsenceStartDate(?\DateTimeInterface $leaveOfAbsenceStartDate): static
  1145.     {
  1146.         $this->leaveOfAbsenceStartDate $leaveOfAbsenceStartDate;
  1147.         return $this;
  1148.     }
  1149.     public function getLeaveOfAbsenceEndDate(): ?\DateTimeInterface
  1150.     {
  1151.         return $this->leaveOfAbsenceEndDate;
  1152.     }
  1153.     public function setLeaveOfAbsenceEndDate(?\DateTimeInterface $leaveOfAbsenceEndDate): static
  1154.     {
  1155.         $this->leaveOfAbsenceEndDate $leaveOfAbsenceEndDate;
  1156.         return $this;
  1157.     }
  1158.     public function isOnLeaveOfAbsence(?\DateTimeInterface $date null): bool
  1159.     {
  1160.         if ($this->employeeStatus !== EmployeeStatus::LEAVE_OF_ABSENCE) {
  1161.             return false;
  1162.         }
  1163.         if ($this->leaveOfAbsenceStartDate === null || $this->leaveOfAbsenceEndDate === null) {
  1164.             return false;
  1165.         }
  1166.         $checkDate $date ?? new \DateTime();
  1167.         return $checkDate >= $this->leaveOfAbsenceStartDate && $checkDate <= $this->leaveOfAbsenceEndDate;
  1168.     }
  1169. }