<?php
namespace App\Entity;
use App\Repository\WorkingFromAbroadRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: WorkingFromAbroadRepository::class)]
class WorkingFromAbroad
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'workingFromAbroads')]
private ?User $user = null;
#[ORM\Column(length: 255)]
private ?string $title = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $confirmationDate = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $departureDate = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $returnDate = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $wfaStartDate = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $wfaEndDate = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $destinationAddress = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $country = null;
#[ORM\Column(length: 255)]
private ?string $status = null;
#[ORM\Column]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $updatedAt = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $deletedAt = null;
#[ORM\Column(length: 255)]
private ?string $generatedId = null;
#[ORM\Column(nullable: true)]
private ?bool $isApproved = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $submittedAt = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $approvedAt = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $rejectedAt = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $archivedAt = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $notes = null;
public function getId(): ?int
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getConfirmationDate(): ?\DateTimeImmutable
{
return $this->confirmationDate;
}
public function setConfirmationDate(?\DateTimeImmutable $confirmationDate): self
{
$this->confirmationDate = $confirmationDate;
return $this;
}
public function getDepartureDate(): ?\DateTimeImmutable
{
return $this->departureDate;
}
public function setDepartureDate(?\DateTimeImmutable $departureDate): self
{
$this->departureDate = $departureDate;
return $this;
}
public function getReturnDate(): ?\DateTimeImmutable
{
return $this->returnDate;
}
public function setReturnDate(?\DateTimeImmutable $returnDate): self
{
$this->returnDate = $returnDate;
return $this;
}
public function getWfaStartDate(): ?\DateTimeImmutable
{
return $this->wfaStartDate;
}
public function setWfaStartDate(\DateTimeImmutable $wfaStartDate): self
{
$this->wfaStartDate = $wfaStartDate;
return $this;
}
public function getWfaEndDate(): ?\DateTimeImmutable
{
return $this->wfaEndDate;
}
public function setWfaEndDate(?\DateTimeImmutable $wfaEndDate): self
{
$this->wfaEndDate = $wfaEndDate;
return $this;
}
public function getDestinationAddress(): ?string
{
return $this->destinationAddress;
}
public function setDestinationAddress(?string $destinationAddress): self
{
$this->destinationAddress = $destinationAddress;
return $this;
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(?string $country): self
{
$this->country = $country;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function getStatusChoices()
{
$approvalMade = $this->isIsApproved() == true ? 'Approved' : ($this->isIsApproved() == false ? 'Rejected' : 'Approval Made');
return [
'Draft' => 1,
'Pending Approval' => 2,
$approvalMade => 3,
'Archived' => 4,
];
}
public function getStatusBadgeClass()
{
$status = $this->getStatus();
$isApproved = $this->isIsApproved();
$badge = 'badge badge-secondary';
switch ($status) {
case 1:
$badge = 'badge badge-light';
break;
case 2:
$badge = 'badge badge-warning';
break;
case 3:
if ($isApproved === true) {
$badge = 'badge badge-success';
} elseif ($isApproved === false) {
$badge = 'badge badge-danger';
}
break;
case 4:
$badge = 'badge badge-secondary';
break;
default:
$badge = 'badge badge-secondary';
}
return $badge;
}
public function getStatusText()
{
$status = $this->getStatus();
$isApproved = $this->isIsApproved();
$statuses = array_flip($this->getStatusChoices());
return isset($statuses[$status]) ? $statuses[$status] : null;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getDeletedAt(): ?\DateTimeImmutable
{
return $this->deletedAt;
}
public function setDeletedAt(?\DateTimeImmutable $deletedAt): self
{
$this->deletedAt = $deletedAt;
return $this;
}
public function getGeneratedId(): ?string
{
return $this->generatedId;
}
public function setGeneratedId(string $generatedId): self
{
$this->generatedId = $generatedId;
return $this;
}
public function isIsApproved(): ?bool
{
return $this->isApproved;
}
public function setIsApproved(?bool $isApproved): self
{
$this->isApproved = $isApproved;
return $this;
}
public function getWfaDays(){
global $kernel;
$bankHolidayService = $kernel->getContainer()->get('BankHolidayService');
$holidays = $bankHolidayService->getHoliday($this->departureDate, $this->returnDate, $this->user->getOffice()->getCountry());
$days = 0;
if ($this->getDepartureDate() && $this->getReturnDate()) {
$startDate = $this->getDepartureDate();
$endDate = $this->getReturnDate();
$currentDate = \DateTime::createFromFormat('Y-m-d', $startDate->format('Y-m-d'));
while ($currentDate->format('Ymd') <= $endDate->format('Ymd')) {
if ($currentDate->format('N') < 6 && !in_array($currentDate->format('Y-m-d'), $holidays)) {
$days++;
}
$currentDate->modify('+1 day');
}
return $days;
}
}
public function getSubmittedAt(): ?\DateTimeImmutable
{
return $this->submittedAt;
}
public function setSubmittedAt(?\DateTimeImmutable $submittedAt): self
{
$this->submittedAt = $submittedAt;
return $this;
}
public function getApprovedAt(): ?\DateTimeImmutable
{
return $this->approvedAt;
}
public function setApprovedAt(?\DateTimeImmutable $approvedAt): self
{
$this->approvedAt = $approvedAt;
return $this;
}
public function getRejectedAt(): ?\DateTimeImmutable
{
return $this->rejectedAt;
}
public function setRejectedAt(?\DateTimeImmutable $rejectedAt): self
{
$this->rejectedAt = $rejectedAt;
return $this;
}
public function getArchivedAt(): ?\DateTimeImmutable
{
return $this->archivedAt;
}
public function setArchivedAt(?\DateTimeImmutable $archivedAt): self
{
$this->archivedAt = $archivedAt;
return $this;
}
public function getNotes(): ?string
{
return $this->notes;
}
public function setNotes(?string $notes): self
{
$this->notes = $notes;
return $this;
}
}