[#322] Page horaire (#4)
All checks were successful
Auto Tag Develop / tag (push) Successful in 5s

| Numéro du ticket | Titre du ticket |
|------------------|-----------------|
|        #322          |        Page horaire         |

## Description de la PR
[#322] Page horaire

## Modification du .env

## Check list

- [ ] Pas de régression
- [ ] TU/TI/TF rédigée
- [ ] TU/TI/TF OK
- [ ] CHANGELOG modifié

Reviewed-on: #4
Co-authored-by: tristan <tristan@yuno.malio.fr>
Co-committed-by: tristan <tristan@yuno.malio.fr>
This commit was merged in pull request #4.
This commit is contained in:
2026-02-20 11:23:52 +00:00
committed by Autin
parent f6c1f7eead
commit ee16779777
85 changed files with 6232 additions and 242 deletions

View File

@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260216100000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Create work_hours table';
}
public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE work_hours (id SERIAL NOT NULL, employee_id INT NOT NULL, work_date DATE NOT NULL, morning_from VARCHAR(5) DEFAULT NULL, morning_to VARCHAR(5) DEFAULT NULL, afternoon_from VARCHAR(5) DEFAULT NULL, afternoon_to VARCHAR(5) DEFAULT NULL, evening_from VARCHAR(5) DEFAULT NULL, evening_to VARCHAR(5) DEFAULT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_WORK_HOURS_EMPLOYEE ON work_hours (employee_id)');
$this->addSql('CREATE INDEX IDX_WORK_HOURS_DATE ON work_hours (work_date)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_WORK_HOURS_EMPLOYEE_DATE ON work_hours (employee_id, work_date)');
$this->addSql('ALTER TABLE work_hours ADD CONSTRAINT FK_WORK_HOURS_EMPLOYEE FOREIGN KEY (employee_id) REFERENCES employees (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE work_hours DROP CONSTRAINT FK_WORK_HOURS_EMPLOYEE');
$this->addSql('DROP TABLE work_hours');
}
}

View File

@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260217161000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add contract_hours and is_forfait to employees';
}
public function up(Schema $schema): void
{
// Nettoie l'ancien modele "contracts" s'il a deja ete applique.
$this->addSql('ALTER TABLE employees DROP CONSTRAINT IF EXISTS FK_EMPLOYEES_CONTRACT');
$this->addSql('DROP INDEX IF EXISTS IDX_EMPLOYEES_CONTRACT');
$this->addSql('ALTER TABLE employees DROP COLUMN IF EXISTS contract_id');
$this->addSql('DROP TABLE IF EXISTS contracts');
$this->addSql('ALTER TABLE employees ADD COLUMN IF NOT EXISTS contract_hours INT DEFAULT NULL');
$this->addSql('ALTER TABLE employees ADD COLUMN IF NOT EXISTS is_forfait BOOLEAN DEFAULT FALSE NOT NULL');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE employees DROP COLUMN IF EXISTS contract_hours');
$this->addSql('ALTER TABLE employees DROP COLUMN IF EXISTS is_forfait');
}
}

View File

@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260217162000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add is_present and is_valid columns to work_hours';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE work_hours ADD COLUMN IF NOT EXISTS is_present BOOLEAN DEFAULT NULL');
$this->addSql('ALTER TABLE work_hours ADD COLUMN IF NOT EXISTS is_valid BOOLEAN DEFAULT FALSE NOT NULL');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE work_hours DROP COLUMN IF EXISTS is_present');
$this->addSql('ALTER TABLE work_hours DROP COLUMN IF EXISTS is_valid');
}
}

View File

@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260218120000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Replace employee contract_hours/is_forfait with contracts table and employee.contract_id';
}
public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE contracts (id SERIAL NOT NULL, name VARCHAR(120) NOT NULL, tracking_mode VARCHAR(20) NOT NULL, weekly_hours INT DEFAULT NULL, is_active BOOLEAN DEFAULT TRUE NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_CONTRACTS_TRACKING_MODE ON contracts (tracking_mode)');
$this->addSql("INSERT INTO contracts (name, tracking_mode, weekly_hours, is_active) VALUES ('Forfait', 'PRESENCE', NULL, TRUE)");
$this->addSql("INSERT INTO contracts (name, tracking_mode, weekly_hours, is_active) SELECT DISTINCT CONCAT(contract_hours::text, 'h'), 'TIME', contract_hours, TRUE FROM employees WHERE contract_hours IS NOT NULL");
$this->addSql("INSERT INTO contracts (name, tracking_mode, weekly_hours, is_active) SELECT '35h', 'TIME', 35, TRUE WHERE NOT EXISTS (SELECT 1 FROM contracts WHERE tracking_mode = 'TIME' AND weekly_hours = 35)");
$this->addSql('ALTER TABLE employees ADD contract_id INT DEFAULT NULL');
$this->addSql('CREATE INDEX IDX_EMPLOYEES_CONTRACT ON employees (contract_id)');
$this->addSql("UPDATE employees e SET contract_id = c.id FROM contracts c WHERE e.is_forfait = TRUE AND c.tracking_mode = 'PRESENCE'");
$this->addSql("UPDATE employees e SET contract_id = c.id FROM contracts c WHERE e.is_forfait = FALSE AND e.contract_hours IS NOT NULL AND c.tracking_mode = 'TIME' AND c.weekly_hours = e.contract_hours");
$this->addSql("UPDATE employees e SET contract_id = c.id FROM contracts c WHERE e.contract_id IS NULL AND c.tracking_mode = 'TIME' AND c.weekly_hours = 35");
$this->addSql('ALTER TABLE employees ALTER COLUMN contract_id SET NOT NULL');
$this->addSql('ALTER TABLE employees ADD CONSTRAINT FK_EMPLOYEES_CONTRACT FOREIGN KEY (contract_id) REFERENCES contracts (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE employees DROP COLUMN contract_hours');
$this->addSql('ALTER TABLE employees DROP COLUMN is_forfait');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE employees ADD contract_hours INT DEFAULT NULL');
$this->addSql('ALTER TABLE employees ADD is_forfait BOOLEAN DEFAULT FALSE NOT NULL');
$this->addSql("UPDATE employees e SET is_forfait = CASE WHEN c.tracking_mode = 'PRESENCE' THEN TRUE ELSE FALSE END, contract_hours = CASE WHEN c.tracking_mode = 'TIME' THEN c.weekly_hours ELSE NULL END FROM contracts c WHERE e.contract_id = c.id");
$this->addSql('ALTER TABLE employees DROP CONSTRAINT FK_EMPLOYEES_CONTRACT');
$this->addSql('DROP INDEX IDX_EMPLOYEES_CONTRACT');
$this->addSql('ALTER TABLE employees DROP COLUMN contract_id');
$this->addSql('DROP INDEX IDX_CONTRACTS_TRACKING_MODE');
$this->addSql('DROP TABLE contracts');
}
}

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260218183000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Replace work_hours.is_present with is_present_morning and is_present_afternoon';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE work_hours DROP COLUMN IF EXISTS is_present');
$this->addSql('ALTER TABLE work_hours ADD COLUMN is_present_morning BOOLEAN DEFAULT FALSE NOT NULL');
$this->addSql('ALTER TABLE work_hours ADD COLUMN is_present_afternoon BOOLEAN DEFAULT FALSE NOT NULL');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE work_hours DROP COLUMN IF EXISTS is_present_morning');
$this->addSql('ALTER TABLE work_hours DROP COLUMN IF EXISTS is_present_afternoon');
$this->addSql('ALTER TABLE work_hours ADD COLUMN is_present BOOLEAN DEFAULT NULL');
}
}

View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260218190000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add count_as_worked_hours on absence_types';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE absence_types ADD count_as_worked_hours BOOLEAN DEFAULT FALSE NOT NULL');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE absence_types DROP count_as_worked_hours');
}
}

View File

@@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use DateInterval;
use DatePeriod;
use DateTimeImmutable;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
final class Version20260219180000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Decoupe les absences multi-jours en lignes journalieres.';
}
public function up(Schema $schema): void
{
$rows = $this->connection->fetchAllAssociative(
'SELECT id, employee_id, type_id, start_date, end_date, start_half, end_half, comment
FROM absences
WHERE start_date < end_date
ORDER BY id ASC'
);
foreach ($rows as $row) {
$start = DateTimeImmutable::createFromFormat('Y-m-d', (string) $row['start_date']);
$end = DateTimeImmutable::createFromFormat('Y-m-d', (string) $row['end_date']);
if (!$start instanceof DateTimeImmutable || !$end instanceof DateTimeImmutable) {
continue;
}
$startHalf = (string) $row['start_half'];
$endHalf = (string) $row['end_half'];
$days = new DatePeriod($start, new DateInterval('P1D'), $end->modify('+1 day'));
foreach ($days as $day) {
$isFirst = $day->format('Y-m-d') === $start->format('Y-m-d');
$isLast = $day->format('Y-m-d') === $end->format('Y-m-d');
if ($isFirst && 'PM' === $startHalf) {
$segmentStartHalf = 'PM';
$segmentEndHalf = 'PM';
} elseif ($isLast && 'AM' === $endHalf) {
$segmentStartHalf = 'AM';
$segmentEndHalf = 'AM';
} else {
$segmentStartHalf = 'AM';
$segmentEndHalf = 'PM';
}
$this->connection->insert('absences', [
'employee_id' => (int) $row['employee_id'],
'type_id' => (int) $row['type_id'],
'start_date' => $day,
'end_date' => $day,
'start_half' => $segmentStartHalf,
'end_half' => $segmentEndHalf,
'comment' => $row['comment'],
], [
'employee_id' => Types::INTEGER,
'type_id' => Types::INTEGER,
'start_date' => Types::DATE_IMMUTABLE,
'end_date' => Types::DATE_IMMUTABLE,
'start_half' => Types::STRING,
'end_half' => Types::STRING,
'comment' => Types::TEXT,
]);
}
$this->connection->delete('absences', ['id' => (int) $row['id']], ['id' => Types::INTEGER]);
}
}
public function down(Schema $schema): void
{
$this->throwIrreversibleMigrationException('Cette migration de decoupage est irreversible.');
}
}