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