pour prod

This commit is contained in:
Loic Masi
2026-08-07 16:13:43 +02:00
commit 5fbf76868f
157 changed files with 24085 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
-- ============================================================================
-- PTA V7.5 - Quota PTA sur l'année civile
-- MySQL 8+
-- À exécuter après la V7 / V7.4.
-- ============================================================================
-- Règle métier :
-- * 1607 h à 100 % sont planifiées sur l'année civile : 01/01 -> 31/12.
-- * la date de début du contrat reste une information RH et ne décale plus
-- la période annuelle du PTA ;
-- * un agent peut participer à des équipes périscolaires ET extrascolaires.
-- Aucun type périscolaire/extrascolaire n'est porté par l'agent.
--
-- Cette migration ne supprime pas les anciens PTA construits sur une période
-- contractuelle. Elle crée, si besoin, une ligne civile équivalente afin de
-- conserver l'historique et d'éviter une migration destructive.
-- ============================================================================
START TRANSACTION;
UPDATE quota_agent_annuel
SET commentaire = 'Quota PTA de référence - année civile'
WHERE commentaire IS NULL
OR commentaire LIKE '%contrat%'
OR commentaire LIKE '%période%';
-- Recrée une ligne PTA civile à partir des anciennes lignes non civiles.
-- INSERT IGNORE évite tout conflit si la ligne annuelle existe déjà.
INSERT IGNORE INTO pta_annuel (
id_agent,
date_debut,
date_fin,
quotite_travail,
quota_reference_minutes,
quota_cible_minutes,
enveloppe_formation_minutes,
conges_annuels_jours_cible,
jours_fractionnement_cible,
statut,
commentaire,
date_validation
)
SELECT
pa.id_agent,
STR_TO_DATE(CONCAT(YEAR(pa.date_debut), '-01-01'), '%Y-%m-%d') AS date_debut,
STR_TO_DATE(CONCAT(YEAR(pa.date_debut), '-12-31'), '%Y-%m-%d') AS date_fin,
pa.quotite_travail,
pa.quota_reference_minutes,
pa.quota_cible_minutes,
pa.enveloppe_formation_minutes,
pa.conges_annuels_jours_cible,
pa.jours_fractionnement_cible,
pa.statut,
CONCAT(
COALESCE(NULLIF(pa.commentaire, ''), ''),
CASE WHEN COALESCE(NULLIF(pa.commentaire, ''), '') = '' THEN '' ELSE ' - ' END,
'Période convertie en année civile par migration V7.5'
),
pa.date_validation
FROM pta_annuel pa
WHERE pa.date_debut <> STR_TO_DATE(CONCAT(YEAR(pa.date_debut), '-01-01'), '%Y-%m-%d')
OR pa.date_fin <> STR_TO_DATE(CONCAT(YEAR(pa.date_debut), '-12-31'), '%Y-%m-%d');
-- La vue de synthèse ne présente désormais que les PTA civils.
CREATE OR REPLACE VIEW v_pta_annuel_synthese AS
SELECT
pa.id_pta,
pa.id_agent,
a.matricule,
a.nom,
a.prenom,
po.code AS poste_code,
po.libelle AS poste_libelle,
a.type_contrat,
pa.date_debut,
pa.date_fin,
pa.quotite_travail,
pa.quota_cible_minutes,
COALESCE(SUM(CASE WHEN mp.compte_dans_quota = TRUE THEN TIMESTAMPDIFF(MINUTE, CONCAT(ch.date_jour, ' ', ch.heure_debut), CONCAT(ch.date_jour, ' ', ch.heure_fin)) ELSE 0 END), 0) AS minutes_decomptees,
pa.quota_cible_minutes - COALESCE(SUM(CASE WHEN mp.compte_dans_quota = TRUE THEN TIMESTAMPDIFF(MINUTE, CONCAT(ch.date_jour, ' ', ch.heure_debut), CONCAT(ch.date_jour, ' ', ch.heure_fin)) ELSE 0 END), 0) AS minutes_restantes,
pa.statut
FROM pta_annuel pa
JOIN agent a ON a.id_agent = pa.id_agent
LEFT JOIN poste_agent po ON po.id_poste = a.id_poste
LEFT JOIN planning p ON p.id_agent = pa.id_agent
LEFT JOIN creneau_horaire ch
ON ch.id_planning = p.id_planning
AND ch.date_jour BETWEEN pa.date_debut AND pa.date_fin
LEFT JOIN motif_planning mp ON mp.id_motif = ch.id_motif
WHERE pa.date_debut = STR_TO_DATE(CONCAT(YEAR(pa.date_debut), '-01-01'), '%Y-%m-%d')
AND pa.date_fin = STR_TO_DATE(CONCAT(YEAR(pa.date_debut), '-12-31'), '%Y-%m-%d')
GROUP BY pa.id_pta, pa.id_agent, a.matricule, a.nom, a.prenom, po.code, po.libelle,
a.type_contrat, pa.date_debut, pa.date_fin, pa.quotite_travail,
pa.quota_cible_minutes, pa.statut;
COMMIT;