feat : ajout de la page de résumé employé
This commit is contained in:
@@ -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