feat : ajout de la page de résumé employé
This commit is contained in:
25
src/Dto/Employees/ContractHistoryItem.php
Normal file
25
src/Dto/Employees/ContractHistoryItem.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Dto\Employees;
|
||||
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
final class ContractHistoryItem
|
||||
{
|
||||
public function __construct(
|
||||
#[Groups(['employee:read'])]
|
||||
public ?int $contractId,
|
||||
#[Groups(['employee:read'])]
|
||||
public ?string $contractName,
|
||||
#[Groups(['employee:read'])]
|
||||
public ?float $weeklyHours,
|
||||
#[Groups(['employee:read'])]
|
||||
public string $contractNature,
|
||||
#[Groups(['employee:read'])]
|
||||
public string $startDate,
|
||||
#[Groups(['employee:read'])]
|
||||
public ?string $endDate,
|
||||
) {}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use App\Dto\Employees\ContractHistoryItem;
|
||||
use App\Enum\ContractNature;
|
||||
use App\Repository\EmployeeRepository;
|
||||
use App\State\EmployeeWriteProcessor;
|
||||
@@ -204,6 +205,35 @@ class Employee
|
||||
return $this->resolveCurrentContractPeriod()?->getEndDate()?->format('Y-m-d');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<ContractHistoryItem>
|
||||
*/
|
||||
#[Groups(['employee:read'])]
|
||||
public function getContractHistory(): array
|
||||
{
|
||||
$periods = $this->contractPeriods->toArray();
|
||||
usort(
|
||||
$periods,
|
||||
static fn (EmployeeContractPeriod $a, EmployeeContractPeriod $b): int => $b->getStartDate() <=> $a->getStartDate()
|
||||
);
|
||||
|
||||
return array_map(
|
||||
static function (EmployeeContractPeriod $period): ContractHistoryItem {
|
||||
$contract = $period->getContract();
|
||||
|
||||
return new ContractHistoryItem(
|
||||
contractId: $contract?->getId(),
|
||||
contractName: $contract?->getName(),
|
||||
weeklyHours: $contract?->getWeeklyHours(),
|
||||
contractNature: $period->getContractNatureEnum()->value,
|
||||
startDate: $period->getStartDate()->format('Y-m-d'),
|
||||
endDate: $period->getEndDate()?->format('Y-m-d'),
|
||||
);
|
||||
},
|
||||
$periods
|
||||
);
|
||||
}
|
||||
|
||||
private function resolveCurrentContractPeriod(): ?EmployeeContractPeriod
|
||||
{
|
||||
$today = new DateTimeImmutable('today');
|
||||
|
||||
Reference in New Issue
Block a user