feat : ajout du nouveau système de contrat et ajout de filtre d'impression
All checks were successful
Auto Tag Develop / tag (push) Successful in 5s
All checks were successful
Auto Tag Develop / tag (push) Successful in 5s
This commit is contained in:
@@ -6,9 +6,12 @@ namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use App\Enum\ContractNature;
|
||||
use App\Repository\EmployeeRepository;
|
||||
use App\State\EmployeeWriteProcessor;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
@@ -56,9 +59,25 @@ class Employee
|
||||
#[ORM\Column(type: 'datetime_immutable')]
|
||||
private DateTimeImmutable $createdAt;
|
||||
|
||||
/**
|
||||
* @var Collection<int, EmployeeContractPeriod>
|
||||
*/
|
||||
#[ORM\OneToMany(mappedBy: 'employee', targetEntity: EmployeeContractPeriod::class)]
|
||||
private Collection $contractPeriods;
|
||||
|
||||
#[Groups(['employee:write'])]
|
||||
private ?string $contractNature = null;
|
||||
|
||||
#[Groups(['employee:write'])]
|
||||
private ?string $contractStartDate = null;
|
||||
|
||||
#[Groups(['employee:write'])]
|
||||
private ?string $contractEndDate = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new DateTimeImmutable();
|
||||
$this->createdAt = new DateTimeImmutable();
|
||||
$this->contractPeriods = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
@@ -130,4 +149,81 @@ class Employee
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContractNature(): ?string
|
||||
{
|
||||
return $this->contractNature;
|
||||
}
|
||||
|
||||
public function setContractNature(?string $contractNature): self
|
||||
{
|
||||
$this->contractNature = $contractNature;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContractStartDate(): ?string
|
||||
{
|
||||
return $this->contractStartDate;
|
||||
}
|
||||
|
||||
public function setContractStartDate(?string $contractStartDate): self
|
||||
{
|
||||
$this->contractStartDate = $contractStartDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContractEndDate(): ?string
|
||||
{
|
||||
return $this->contractEndDate;
|
||||
}
|
||||
|
||||
public function setContractEndDate(?string $contractEndDate): self
|
||||
{
|
||||
$this->contractEndDate = $contractEndDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
#[Groups(['employee:read'])]
|
||||
public function getCurrentContractNature(): string
|
||||
{
|
||||
return $this->resolveCurrentContractPeriod()?->getContractNatureEnum()->value ?? ContractNature::CDI->value;
|
||||
}
|
||||
|
||||
#[Groups(['employee:read'])]
|
||||
public function getCurrentContractStartDate(): ?string
|
||||
{
|
||||
return $this->resolveCurrentContractPeriod()?->getStartDate()->format('Y-m-d');
|
||||
}
|
||||
|
||||
#[Groups(['employee:read'])]
|
||||
public function getCurrentContractEndDate(): ?string
|
||||
{
|
||||
return $this->resolveCurrentContractPeriod()?->getEndDate()?->format('Y-m-d');
|
||||
}
|
||||
|
||||
private function resolveCurrentContractPeriod(): ?EmployeeContractPeriod
|
||||
{
|
||||
$today = new DateTimeImmutable('today');
|
||||
$current = null;
|
||||
|
||||
foreach ($this->contractPeriods as $period) {
|
||||
if ($period->getStartDate() > $today) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$endDate = $period->getEndDate();
|
||||
if (null !== $endDate && $endDate < $today) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (null === $current || $period->getStartDate() > $current->getStartDate()) {
|
||||
$current = $period;
|
||||
}
|
||||
}
|
||||
|
||||
return $current;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Enum\ContractNature;
|
||||
use App\Repository\EmployeeContractPeriodRepository;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
@@ -19,7 +20,7 @@ class EmployeeContractPeriod
|
||||
#[ORM\Column(type: 'integer')]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: Employee::class)]
|
||||
#[ORM\ManyToOne(targetEntity: Employee::class, inversedBy: 'contractPeriods')]
|
||||
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
|
||||
private ?Employee $employee = null;
|
||||
|
||||
@@ -33,6 +34,9 @@ class EmployeeContractPeriod
|
||||
#[ORM\Column(type: 'date_immutable', nullable: true)]
|
||||
private ?DateTimeImmutable $endDate = null;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 20, options: ['default' => ContractNature::CDI->value])]
|
||||
private string $contractNature = ContractNature::CDI->value;
|
||||
|
||||
#[ORM\Column(type: 'datetime_immutable')]
|
||||
private DateTimeImmutable $createdAt;
|
||||
|
||||
@@ -95,6 +99,24 @@ class EmployeeContractPeriod
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContractNature(): string
|
||||
{
|
||||
return $this->contractNature;
|
||||
}
|
||||
|
||||
public function getContractNatureEnum(): ContractNature
|
||||
{
|
||||
return ContractNature::tryFrom($this->contractNature) ?? ContractNature::CDI;
|
||||
}
|
||||
|
||||
public function setContractNature(ContractNature|string $contractNature): self
|
||||
{
|
||||
$value = $contractNature instanceof ContractNature ? $contractNature->value : $contractNature;
|
||||
$this->contractNature = ContractNature::tryFrom($value)?->value ?? ContractNature::CDI->value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreatedAt(): DateTimeImmutable
|
||||
{
|
||||
return $this->createdAt;
|
||||
|
||||
Reference in New Issue
Block a user