diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml
new file mode 100644
index 0000000..3fadc3d
--- /dev/null
+++ b/.idea/sqldialects.xml
@@ -0,0 +1,6 @@
+
+
{{ getRowAbsenceLabel(employee.id) || '—' }}
diff --git a/migrations/Version20260220133000.php b/migrations/Version20260220133000.php new file mode 100644 index 0000000..1e96ce5 --- /dev/null +++ b/migrations/Version20260220133000.php @@ -0,0 +1,40 @@ +addSql('CREATE TABLE employee_contract_periods (id SERIAL NOT NULL, employee_id INT NOT NULL, contract_id INT NOT NULL, start_date DATE NOT NULL, end_date DATE DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX idx_emp_contract_period_employee_start ON employee_contract_periods (employee_id, start_date)'); + $this->addSql('CREATE INDEX idx_emp_contract_period_employee_end ON employee_contract_periods (employee_id, end_date)'); + $this->addSql('CREATE INDEX IDX_831EED7A8C03F15C ON employee_contract_periods (employee_id)'); + $this->addSql('CREATE INDEX IDX_831EED7A2576E0FD ON employee_contract_periods (contract_id)'); + $this->addSql('ALTER TABLE employee_contract_periods ADD CONSTRAINT FK_831EED7A8C03F15C FOREIGN KEY (employee_id) REFERENCES employees (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE employee_contract_periods ADD CONSTRAINT FK_831EED7A2576E0FD FOREIGN KEY (contract_id) REFERENCES contracts (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + + // Initialise l\'historique avec le contrat actuel de chaque employé. + $this->addSql("INSERT INTO employee_contract_periods (employee_id, contract_id, start_date, end_date, created_at) + SELECT id, contract_id, DATE '1970-01-01', NULL, NOW() + FROM employees + WHERE contract_id IS NOT NULL"); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE employee_contract_periods DROP CONSTRAINT FK_831EED7A8C03F15C'); + $this->addSql('ALTER TABLE employee_contract_periods DROP CONSTRAINT FK_831EED7A2576E0FD'); + $this->addSql('DROP TABLE employee_contract_periods'); + } +} diff --git a/src/Entity/Employee.php b/src/Entity/Employee.php index 4403b73..9d35561 100644 --- a/src/Entity/Employee.php +++ b/src/Entity/Employee.php @@ -7,6 +7,7 @@ namespace App\Entity; use ApiPlatform\Metadata\ApiProperty; use ApiPlatform\Metadata\ApiResource; use App\Repository\EmployeeRepository; +use App\State\EmployeeWriteProcessor; use DateTimeImmutable; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Attribute\Groups; @@ -15,7 +16,8 @@ use Symfony\Component\Serializer\Attribute\Groups; normalizationContext: ['groups' => ['employee:read', 'site:read']], denormalizationContext: ['groups' => ['employee:write']], paginationEnabled: false, - security: "is_granted('ROLE_ADMIN')" + security: "is_granted('ROLE_ADMIN')", + processor: EmployeeWriteProcessor::class, )] #[ORM\Entity(repositoryClass: EmployeeRepository::class)] #[ORM\Table(name: 'employees')] diff --git a/src/Entity/EmployeeContractPeriod.php b/src/Entity/EmployeeContractPeriod.php new file mode 100644 index 0000000..67720ee --- /dev/null +++ b/src/Entity/EmployeeContractPeriod.php @@ -0,0 +1,102 @@ +createdAt = new DateTimeImmutable(); + $this->startDate = new DateTimeImmutable('today'); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getEmployee(): ?Employee + { + return $this->employee; + } + + public function setEmployee(?Employee $employee): self + { + $this->employee = $employee; + + return $this; + } + + public function getContract(): ?Contract + { + return $this->contract; + } + + public function setContract(?Contract $contract): self + { + $this->contract = $contract; + + return $this; + } + + public function getStartDate(): DateTimeImmutable + { + return $this->startDate; + } + + public function setStartDate(DateTimeImmutable $startDate): self + { + $this->startDate = $startDate; + + return $this; + } + + public function getEndDate(): ?DateTimeImmutable + { + return $this->endDate; + } + + public function setEndDate(?DateTimeImmutable $endDate): self + { + $this->endDate = $endDate; + + return $this; + } + + public function getCreatedAt(): DateTimeImmutable + { + return $this->createdAt; + } +} diff --git a/src/Repository/EmployeeContractPeriodRepository.php b/src/Repository/EmployeeContractPeriodRepository.php new file mode 100644 index 0000000..72efa74 --- /dev/null +++ b/src/Repository/EmployeeContractPeriodRepository.php @@ -0,0 +1,75 @@ + + */ +final class EmployeeContractPeriodRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, EmployeeContractPeriod::class); + } + + /** + * @param list