feat : ajout d'une date d'entrée pour les employés
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
This commit is contained in:
@@ -7,7 +7,18 @@
|
||||
"Bash(docker compose:*)",
|
||||
"Bash(make test:*)",
|
||||
"Bash(grep:*)",
|
||||
"Bash(docker exec:*)"
|
||||
"Bash(docker exec:*)",
|
||||
"Bash(php8.3 bin/phpunit tests/State/EmployeeWriteProcessorTest.php --filter=testSetsEntryDateOnNewEmployee 2>&1)",
|
||||
"Read(//usr/bin/**)",
|
||||
"Read(//usr/local/bin/**)",
|
||||
"Bash(command -v php8.2)",
|
||||
"Bash(command -v php8.1)",
|
||||
"Bash(ls /usr/bin/php*)",
|
||||
"Read(//opt/**)",
|
||||
"Read(//home/m-tristan/.nix-profile/**)",
|
||||
"Read(//home/m-tristan/.local/bin/**)",
|
||||
"Bash(env)",
|
||||
"Bash(ls /home/m-tristan/workspace/SIRH/docker* /home/m-tristan/workspace/SIRH/Makefile 2>/dev/null; cat /home/m-tristan/workspace/SIRH/Makefile 2>/dev/null | grep -E \"\\(phpunit|test|php\\)\" | head -20)"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,12 @@
|
||||
|
||||
<div v-else class="flex min-h-0 flex-1 flex-col">
|
||||
<div class="flex items-center justify-between">
|
||||
<h1 class="text-4xl font-bold text-primary-500">{{ employee.firstName }} {{ employee.lastName }}</h1>
|
||||
<div>
|
||||
<h1 class="text-[32px] font-bold">{{ employee.firstName }} {{ employee.lastName }}</h1>
|
||||
<p>Date d'entrée : {{ employee.entryDate ? employee.entryDate.split('-').reverse().join('/') : '-' }}</p>
|
||||
</div>
|
||||
<div class="text-right">
|
||||
<p class="font-bold text-[20px]">{{ contractNatureLabel(employee.currentContractNature) }} {{ employeeContractWorkLabel }}</p>
|
||||
<p class="font-bold text-[22px]">{{ contractNatureLabel(employee.currentContractNature) }} {{ employeeContractWorkLabel }}</p>
|
||||
<p class="text-[18px]">{{ employee.site?.name ?? '-' }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
<p><strong>Type:</strong> {{ contractNatureLabel(employee.currentContractNature) }}</p>
|
||||
<p><strong>Temps de travail:</strong> {{ employee.contract?.name ?? '-' }}</p>
|
||||
<p><strong>Site:</strong> {{ employee.site?.name ?? '-' }}</p>
|
||||
<p><strong>Date d'entrée :</strong> {{ employee.entryDate ? employee.entryDate.split('-').reverse().join('/') : '-' }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</NuxtLink>
|
||||
|
||||
@@ -22,4 +22,5 @@ export type Employee = {
|
||||
currentContractEndDate?: string | null
|
||||
contractHistory?: ContractHistoryItem[]
|
||||
displayOrder?: number
|
||||
entryDate?: string | null
|
||||
}
|
||||
|
||||
26
migrations/Version20260312120000.php
Normal file
26
migrations/Version20260312120000.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20260312120000 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Add entry_date column to employees table';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE employees ADD entry_date DATE DEFAULT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE employees DROP entry_date');
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,9 @@ use DateTimeImmutable;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Context;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
||||
|
||||
#[ApiResource(
|
||||
normalizationContext: ['groups' => ['employee:read', 'site:read']],
|
||||
@@ -57,6 +59,11 @@ class Employee
|
||||
#[Groups(['employee:read', 'employee:write'])]
|
||||
private int $displayOrder = 0;
|
||||
|
||||
#[ORM\Column(type: 'date_immutable', nullable: true)]
|
||||
#[Groups(['employee:read'])]
|
||||
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
|
||||
private ?DateTimeImmutable $entryDate = null;
|
||||
|
||||
#[ORM\Column(type: 'datetime_immutable')]
|
||||
private DateTimeImmutable $createdAt;
|
||||
|
||||
@@ -166,6 +173,18 @@ class Employee
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEntryDate(): ?DateTimeImmutable
|
||||
{
|
||||
return $this->entryDate;
|
||||
}
|
||||
|
||||
public function setEntryDate(?DateTimeImmutable $entryDate): self
|
||||
{
|
||||
$this->entryDate = $entryDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContractNature(): ?string
|
||||
{
|
||||
return $this->contractNature;
|
||||
|
||||
@@ -68,6 +68,9 @@ final readonly class EmployeeWriteProcessor implements ProcessorInterface
|
||||
nature: $nature
|
||||
);
|
||||
|
||||
$data->setEntryDate($startDate);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace App\Tests\State;
|
||||
|
||||
use ApiPlatform\Metadata\Delete;
|
||||
use ApiPlatform\Metadata\Patch;
|
||||
use ApiPlatform\Metadata\Post;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use App\Entity\Contract;
|
||||
use App\Entity\Employee;
|
||||
@@ -194,6 +195,54 @@ final class EmployeeWriteProcessorTest extends TestCase
|
||||
self::assertSame($employee, $result);
|
||||
}
|
||||
|
||||
public function testSetsEntryDateOnNewEmployee(): void
|
||||
{
|
||||
$employee = new Employee();
|
||||
$employee->setFirstName('Jane');
|
||||
$employee->setLastName('Doe');
|
||||
$employee->setContractStartDate('2026-04-01');
|
||||
$employee->setContractNature('CDI');
|
||||
|
||||
$contract = new Contract()
|
||||
->setName('35h')
|
||||
->setTrackingMode(Contract::TRACKING_TIME)
|
||||
->setWeeklyHours(35)
|
||||
;
|
||||
$employee->setContract($contract);
|
||||
|
||||
$persistProcessor = $this->createMock(ProcessorInterface::class);
|
||||
$removeProcessor = $this->createStub(ProcessorInterface::class);
|
||||
$entityManager = $this->createStub(EntityManagerInterface::class);
|
||||
$periodRepository = $this->createStub(EmployeeContractPeriodReadRepositoryInterface::class);
|
||||
$changeRequestFactory = new EmployeeContractChangeRequestFactory();
|
||||
$periodManager = $this->createMock(EmployeeContractPeriodManagerInterface::class);
|
||||
|
||||
$persistProcessor
|
||||
->expects(self::once())
|
||||
->method('process')
|
||||
->willReturn($employee)
|
||||
;
|
||||
|
||||
$periodManager
|
||||
->expects(self::once())
|
||||
->method('ensureContractPeriodExists')
|
||||
;
|
||||
|
||||
$processor = new EmployeeWriteProcessor(
|
||||
$persistProcessor,
|
||||
$removeProcessor,
|
||||
$entityManager,
|
||||
$periodRepository,
|
||||
$changeRequestFactory,
|
||||
$periodManager
|
||||
);
|
||||
|
||||
$processor->process($employee, new Post());
|
||||
|
||||
self::assertNotNull($employee->getEntryDate());
|
||||
self::assertSame('2026-04-01', $employee->getEntryDate()->format('Y-m-d'));
|
||||
}
|
||||
|
||||
public function testDeleteOperationDelegatesToRemoveProcessor(): void
|
||||
{
|
||||
$employee = $this->buildEmployeeWithId(45);
|
||||
|
||||
Reference in New Issue
Block a user