Droit à l'enveloppe de formation par agent, et motif « Formation » filtré à la saisie
Nouvelle colonne `agent.droit_enveloppe_formation`, cochée par défaut, saisie à la création de l'agent et modifiable depuis sa fiche. Un agent sans ce droit : - ne voit plus le motif « Formation » dans le sélecteur de motif de l'éditeur de planning ni dans le modal de la vue individuelle ; - se voit refuser toute affectation de ce motif par le serveur, avec un message qui nomme le motif et l'agent (save_planning.php et update_agent_entry.php) ; - a une enveloppe de formation de 0 min au PTA annuel, et une ALERTE FORMATION_SANS_DROIT si des heures de formation subsistent dans son planning. À ne pas confondre avec `formation_repartition_annuelle`, qui existait déjà : celle-ci dit que la formation est déjà comptée dans la répartition annuelle — l'agent y a droit, l'enveloppe complémentaire n'est simplement pas ajoutée. Les deux règles sont désormais rassemblées dans AgentModel::trainingEnvelopeMinutes(), qui remplace les deux calculs « 840 ou 0 » jusque-là dupliqués. Le motif interdit reste affiché lorsqu'il est déjà celui de la plage en cours d'édition : le retirer de la liste changerait silencieusement le motif d'une saisie existante. C'est le contrôle de saisie, puis le serveur, qui demandent alors de corriger la plage. La migration est nommée v7_9b et non v7_10 : les fichiers sont joués dans l'ordre alphabétique, où « v7_10 » passerait avant « v7_8 ». Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,11 +10,40 @@ use Throwable;
|
||||
|
||||
final class AgentModel extends BaseModel
|
||||
{
|
||||
/** Enveloppe annuelle complémentaire de formation : 14 h. */
|
||||
public const ENVELOPPE_FORMATION_MINUTES = 840;
|
||||
|
||||
/**
|
||||
* Un agent sans droit à l'enveloppe de formation ne peut pas se voir
|
||||
* affecter le motif « Formation ». Le droit vaut par défaut lorsque
|
||||
* l'information n'est pas projetée : ne jamais retirer un droit sur une
|
||||
* donnée absente.
|
||||
*/
|
||||
public static function hasTrainingRight(array $agent): bool
|
||||
{
|
||||
return (int) ($agent['droit_enveloppe_formation'] ?? 1) === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Minutes de formation ouvertes à l'agent sur l'année : rien s'il n'y a pas
|
||||
* droit, rien non plus si sa formation est déjà comptée dans la répartition
|
||||
* annuelle, l'enveloppe complémentaire sinon.
|
||||
*/
|
||||
public static function trainingEnvelopeMinutes(array $agent): int
|
||||
{
|
||||
if (!self::hasTrainingRight($agent) || !empty($agent['formation_repartition_annuelle'])) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return self::ENVELOPPE_FORMATION_MINUTES;
|
||||
}
|
||||
|
||||
private const AGENT_SELECT = <<<'SQL'
|
||||
SELECT a.id_agent, a.matricule, a.nom, a.prenom, a.email,
|
||||
a.telephone, a.adresse, a.est_diplome, a.diplome_libelle,
|
||||
a.date_debut_contrat, a.date_fin_contrat, a.type_contrat,
|
||||
a.formation_repartition_annuelle, a.commentaire_pta,
|
||||
a.formation_repartition_annuelle, a.droit_enveloppe_formation,
|
||||
a.commentaire_pta,
|
||||
a.id_poste, po.code AS poste_code, po.libelle AS poste_libelle,
|
||||
po.famille AS poste_famille, po.heures_mercredi_minutes,
|
||||
po.heures_extrascolaire_minutes, po.autorise_preparation,
|
||||
@@ -129,7 +158,10 @@ final class AgentModel extends BaseModel
|
||||
$periodEnd = new DateTimeImmutable(sprintf('%04d-12-31', $year));
|
||||
$quotaReference = QuotaModel::REFERENCE_MINUTES;
|
||||
$quotaTarget = (int) round($quotaReference * ((float) $data['quotite_travail'] / 100));
|
||||
$trainingEnvelope = !empty($data['formation_repartition_annuelle']) ? 0 : 840;
|
||||
$trainingEnvelope = self::trainingEnvelopeMinutes([
|
||||
'droit_enveloppe_formation' => !empty($data['droit_enveloppe_formation']) ? 1 : 0,
|
||||
'formation_repartition_annuelle' => $data['formation_repartition_annuelle'],
|
||||
]);
|
||||
|
||||
try {
|
||||
$this->pdo->beginTransaction();
|
||||
@@ -139,14 +171,14 @@ final class AgentModel extends BaseModel
|
||||
matricule, nom, prenom, email, telephone, adresse,
|
||||
est_diplome, diplome_libelle, date_debut_contrat,
|
||||
id_poste, type_contrat, date_fin_contrat,
|
||||
formation_repartition_annuelle, commentaire_pta,
|
||||
id_structure, actif
|
||||
formation_repartition_annuelle, droit_enveloppe_formation,
|
||||
commentaire_pta, id_structure, actif
|
||||
) VALUES (
|
||||
:matricule, :nom, :prenom, :email, :telephone, :adresse,
|
||||
:est_diplome, :diplome_libelle, :date_debut_contrat,
|
||||
:id_poste, :type_contrat, :date_fin_contrat,
|
||||
:formation_repartition_annuelle, :commentaire_pta,
|
||||
:structure_id, TRUE
|
||||
:formation_repartition_annuelle, :droit_enveloppe_formation,
|
||||
:commentaire_pta, :structure_id, TRUE
|
||||
)'
|
||||
);
|
||||
$insertAgent->execute([
|
||||
@@ -163,6 +195,7 @@ final class AgentModel extends BaseModel
|
||||
'type_contrat' => $data['type_contrat'],
|
||||
'date_fin_contrat' => $contractEnd?->format('Y-m-d'),
|
||||
'formation_repartition_annuelle' => $data['formation_repartition_annuelle'] ? 1 : 0,
|
||||
'droit_enveloppe_formation' => !empty($data['droit_enveloppe_formation']) ? 1 : 0,
|
||||
'commentaire_pta' => $data['commentaire_pta'],
|
||||
'structure_id' => $data['structure_id'],
|
||||
]);
|
||||
@@ -261,6 +294,7 @@ final class AgentModel extends BaseModel
|
||||
type_contrat = :type_contrat,
|
||||
date_fin_contrat = :date_fin_contrat,
|
||||
formation_repartition_annuelle = :formation_repartition_annuelle,
|
||||
droit_enveloppe_formation = :droit_enveloppe_formation,
|
||||
commentaire_pta = :commentaire_pta,
|
||||
id_structure = :structure_id
|
||||
WHERE id_agent = :agent_id'
|
||||
@@ -276,6 +310,7 @@ final class AgentModel extends BaseModel
|
||||
$update->bindValue(':type_contrat', $data['type_contrat']);
|
||||
$update->bindValue(':date_fin_contrat', $data['date_fin_contrat']);
|
||||
$update->bindValue(':formation_repartition_annuelle', $data['formation_repartition_annuelle'] ? 1 : 0, PDO::PARAM_INT);
|
||||
$update->bindValue(':droit_enveloppe_formation', !empty($data['droit_enveloppe_formation']) ? 1 : 0, PDO::PARAM_INT);
|
||||
$update->bindValue(':commentaire_pta', $data['commentaire_pta']);
|
||||
if ($newStructureId === null) {
|
||||
$update->bindValue(':structure_id', null, PDO::PARAM_NULL);
|
||||
|
||||
Reference in New Issue
Block a user