src/Entity/WorkingFromAbroad.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\WorkingFromAbroadRepository;
  4. use Doctrine\DBAL\Types\Types;
  5. use Doctrine\ORM\Mapping as ORM;
  6. #[ORM\Entity(repositoryClassWorkingFromAbroadRepository::class)]
  7. class WorkingFromAbroad
  8. {
  9.     #[ORM\Id]
  10.     #[ORM\GeneratedValue]
  11.     #[ORM\Column]
  12.     private ?int $id null;
  13.     #[ORM\ManyToOne(inversedBy'workingFromAbroads')]
  14.     private ?User $user null;
  15.     #[ORM\Column(length255)]
  16.     private ?string $title null;
  17.     #[ORM\Column(nullabletrue)]
  18.     private ?\DateTimeImmutable $confirmationDate null;
  19.     #[ORM\Column(nullabletrue)]
  20.     private ?\DateTimeImmutable $departureDate null;
  21.     #[ORM\Column(nullabletrue)]
  22.     private ?\DateTimeImmutable $returnDate null;
  23.     #[ORM\Column(nullabletrue)]
  24.     private ?\DateTimeImmutable $wfaStartDate null;
  25.     #[ORM\Column(nullabletrue)]
  26.     private ?\DateTimeImmutable $wfaEndDate null;
  27.     #[ORM\Column(length255nullabletrue)]
  28.     private ?string $destinationAddress null;
  29.     #[ORM\Column(length255nullabletrue)]
  30.     private ?string $country null;
  31.     #[ORM\Column(length255)]
  32.     private ?string $status null;
  33.     #[ORM\Column]
  34.     private ?\DateTimeImmutable $createdAt null;
  35.     #[ORM\Column(nullabletrue)]
  36.     private ?\DateTimeImmutable $updatedAt null;
  37.     #[ORM\Column(nullabletrue)]
  38.     private ?\DateTimeImmutable $deletedAt null;
  39.     #[ORM\Column(length255)]
  40.     private ?string $generatedId null;
  41.     #[ORM\Column(nullabletrue)]
  42.     private ?bool $isApproved null;
  43.     #[ORM\Column(nullabletrue)]
  44.     private ?\DateTimeImmutable $submittedAt null;
  45.     #[ORM\Column(nullabletrue)]
  46.     private ?\DateTimeImmutable $approvedAt null;
  47.     #[ORM\Column(nullabletrue)]
  48.     private ?\DateTimeImmutable $rejectedAt null;
  49.     #[ORM\Column(nullabletrue)]
  50.     private ?\DateTimeImmutable $archivedAt null;
  51.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  52.     private ?string $notes null;
  53.     public function getId(): ?int
  54.     {
  55.         return $this->id;
  56.     }
  57.     public function getUser(): ?User
  58.     {
  59.         return $this->user;
  60.     }
  61.     public function setUser(?User $user): self
  62.     {
  63.         $this->user $user;
  64.         return $this;
  65.     }
  66.     public function getTitle(): ?string
  67.     {
  68.         return $this->title;
  69.     }
  70.     public function setTitle(string $title): self
  71.     {
  72.         $this->title $title;
  73.         return $this;
  74.     }
  75.     public function getConfirmationDate(): ?\DateTimeImmutable
  76.     {
  77.         return $this->confirmationDate;
  78.     }
  79.     public function setConfirmationDate(?\DateTimeImmutable $confirmationDate): self
  80.     {
  81.         $this->confirmationDate $confirmationDate;
  82.         return $this;
  83.     }
  84.     public function getDepartureDate(): ?\DateTimeImmutable
  85.     {
  86.         return $this->departureDate;
  87.     }
  88.     public function setDepartureDate(?\DateTimeImmutable $departureDate): self
  89.     {
  90.         $this->departureDate $departureDate;
  91.         return $this;
  92.     }
  93.     public function getReturnDate(): ?\DateTimeImmutable
  94.     {
  95.         return $this->returnDate;
  96.     }
  97.     public function setReturnDate(?\DateTimeImmutable $returnDate): self
  98.     {
  99.         $this->returnDate $returnDate;
  100.         return $this;
  101.     }
  102.     public function getWfaStartDate(): ?\DateTimeImmutable
  103.     {
  104.         return $this->wfaStartDate;
  105.     }
  106.     public function setWfaStartDate(\DateTimeImmutable $wfaStartDate): self
  107.     {
  108.         $this->wfaStartDate $wfaStartDate;
  109.         return $this;
  110.     }
  111.     public function getWfaEndDate(): ?\DateTimeImmutable
  112.     {
  113.         return $this->wfaEndDate;
  114.     }
  115.     public function setWfaEndDate(?\DateTimeImmutable $wfaEndDate): self
  116.     {
  117.         $this->wfaEndDate $wfaEndDate;
  118.         return $this;
  119.     }
  120.     public function getDestinationAddress(): ?string
  121.     {
  122.         return $this->destinationAddress;
  123.     }
  124.     public function setDestinationAddress(?string $destinationAddress): self
  125.     {
  126.         $this->destinationAddress $destinationAddress;
  127.         return $this;
  128.     }
  129.     public function getCountry(): ?string
  130.     {
  131.         return $this->country;
  132.     }
  133.     public function setCountry(?string $country): self
  134.     {
  135.         $this->country $country;
  136.         return $this;
  137.     }
  138.     public function getStatus(): ?string
  139.     {
  140.         return $this->status;
  141.     }
  142.     public function getStatusChoices()
  143.     {
  144.         $approvalMade $this->isIsApproved() == true 'Approved' : ($this->isIsApproved() == false 'Rejected' 'Approval Made');
  145.         return [
  146.             'Draft' => 1,
  147.             'Pending Approval' => 2,
  148.             $approvalMade => 3,
  149.             'Archived' => 4,
  150.         ];
  151.     }
  152.     public function getStatusBadgeClass()
  153.     {
  154.         $status $this->getStatus();
  155.         $isApproved $this->isIsApproved();
  156.         $badge 'badge badge-secondary';
  157.         switch ($status) {
  158.           case 1:
  159.               $badge 'badge badge-light';
  160.               break;
  161.           case 2:
  162.               $badge 'badge badge-warning';
  163.               break;
  164.           case 3:
  165.               if ($isApproved === true) {
  166.                   $badge 'badge badge-success';
  167.               } elseif ($isApproved === false) {
  168.                   $badge 'badge badge-danger';
  169.               }
  170.               break;
  171.           case 4:
  172.               $badge 'badge badge-secondary';
  173.               break;
  174.           default:
  175.               $badge 'badge badge-secondary';
  176.         }
  177.         return $badge;
  178.     }
  179.     public function getStatusText()
  180.     {
  181.         $status $this->getStatus();
  182.         $isApproved $this->isIsApproved();
  183.         $statuses array_flip($this->getStatusChoices());
  184.         return isset($statuses[$status]) ? $statuses[$status] : null;
  185.     }
  186.     public function setStatus(string $status): self
  187.     {
  188.         $this->status $status;
  189.         return $this;
  190.     }
  191.     public function getCreatedAt(): ?\DateTimeImmutable
  192.     {
  193.         return $this->createdAt;
  194.     }
  195.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  196.     {
  197.         $this->createdAt $createdAt;
  198.         return $this;
  199.     }
  200.     public function getUpdatedAt(): ?\DateTimeImmutable
  201.     {
  202.         return $this->updatedAt;
  203.     }
  204.     public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self
  205.     {
  206.         $this->updatedAt $updatedAt;
  207.         return $this;
  208.     }
  209.     public function getDeletedAt(): ?\DateTimeImmutable
  210.     {
  211.         return $this->deletedAt;
  212.     }
  213.     public function setDeletedAt(?\DateTimeImmutable $deletedAt): self
  214.     {
  215.         $this->deletedAt $deletedAt;
  216.         return $this;
  217.     }
  218.     public function getGeneratedId(): ?string
  219.     {
  220.         return $this->generatedId;
  221.     }
  222.     public function setGeneratedId(string $generatedId): self
  223.     {
  224.         $this->generatedId $generatedId;
  225.         return $this;
  226.     }
  227.     public function isIsApproved(): ?bool
  228.     {
  229.         return $this->isApproved;
  230.     }
  231.     public function setIsApproved(?bool $isApproved): self
  232.     {
  233.         $this->isApproved $isApproved;
  234.         return $this;
  235.     }
  236.     public function getWfaDays(){
  237.         global $kernel;
  238.         $bankHolidayService $kernel->getContainer()->get('BankHolidayService');
  239.         $holidays $bankHolidayService->getHoliday($this->departureDate$this->returnDate$this->user->getOffice()->getCountry());
  240.         $days 0;
  241.         if ($this->getDepartureDate() && $this->getReturnDate()) {
  242.             $startDate $this->getDepartureDate();
  243.             $endDate $this->getReturnDate();
  244.             $currentDate \DateTime::createFromFormat('Y-m-d'$startDate->format('Y-m-d'));
  245.             while ($currentDate->format('Ymd') <= $endDate->format('Ymd')) {
  246.                 if ($currentDate->format('N') < && !in_array($currentDate->format('Y-m-d'), $holidays)) {
  247.                     $days++;
  248.                 }
  249.                 $currentDate->modify('+1 day');
  250.             }
  251.             return $days;
  252.         }
  253.     }
  254.     public function getSubmittedAt(): ?\DateTimeImmutable
  255.     {
  256.         return $this->submittedAt;
  257.     }
  258.     public function setSubmittedAt(?\DateTimeImmutable $submittedAt): self
  259.     {
  260.         $this->submittedAt $submittedAt;
  261.         return $this;
  262.     }
  263.     public function getApprovedAt(): ?\DateTimeImmutable
  264.     {
  265.         return $this->approvedAt;
  266.     }
  267.     public function setApprovedAt(?\DateTimeImmutable $approvedAt): self
  268.     {
  269.         $this->approvedAt $approvedAt;
  270.         return $this;
  271.     }
  272.     public function getRejectedAt(): ?\DateTimeImmutable
  273.     {
  274.         return $this->rejectedAt;
  275.     }
  276.     public function setRejectedAt(?\DateTimeImmutable $rejectedAt): self
  277.     {
  278.         $this->rejectedAt $rejectedAt;
  279.         return $this;
  280.     }
  281.     public function getArchivedAt(): ?\DateTimeImmutable
  282.     {
  283.         return $this->archivedAt;
  284.     }
  285.     public function setArchivedAt(?\DateTimeImmutable $archivedAt): self
  286.     {
  287.         $this->archivedAt $archivedAt;
  288.         return $this;
  289.     }
  290.     public function getNotes(): ?string
  291.     {
  292.         return $this->notes;
  293.     }
  294.     public function setNotes(?string $notes): self
  295.     {
  296.         $this->notes $notes;
  297.         return $this;
  298.     }
  299. }