2 Commits

Author SHA1 Message Date
d09154ef9a Merge branch 'main' into feature/suppression_demande_conge
All checks were successful
Organisation/sirh/pipeline/pr-main This commit looks good
2026-10-08 12:42:34 +00:00
65497cd669 Ajout de la suppression des demandes de congé
Some checks failed
Organisation/sirh/pipeline/head There was a failure building this commit
Organisation/sirh/pipeline/pr-main There was a failure building this commit
2026-10-06 16:12:42 +00:00
9 changed files with 125 additions and 76 deletions

View File

@@ -2,6 +2,34 @@ const $ = (element) => document.getElementById(element);
const url_liste_conge_attente = $("liste-demande-conges").dataset.url
function supprimerDemandeConge(congeId) {
if (!window.confirm("Voulez-vous vraiment supprimer cette demande de congé en attente ?")) {
return;
}
const form = $("form-detail-conge");
const csrftoken = new FormData(form).get("csrfmiddlewaretoken");
const url = $("bouton-supprimer-demande-conge").dataset.url.replace(
"/0/",
`/${congeId}/`
);
fetch(url, {
method: "POST",
headers: {"X-CSRFToken": csrftoken},
})
.then(response => response.json().then(data => ({response, data})))
.then(({response, data}) => {
window.alert(data.message);
if (response.ok && data.success) {
window.location.reload();
}
})
.catch(() => {
window.alert("La suppression a échoué. Veuillez réessayer.");
});
}
const tableau_liste_demande_conge = new Tabulator("#liste-demande-conges", {
columns: [
{"title": "Nom et Prénom", "field": "prenom_nom"},
@@ -21,12 +49,31 @@ const tableau_liste_demande_conge = new Tabulator("#liste-demande-conges", {
{"title": "Validation par supérieur hiérarchique", "field": "validation_direction", formatter:"tickCross", formatterParams :{
allowEmpty : true ,
}},
{
title: "Action",
hozAlign: "center",
formatter: (cell) => {
const data = cell.getRow().getData();
if (!data.est_proprietaire || !data.en_attente) {
return "";
}
return '<button type="button" class="btn btn-danger btn-sm">Supprimer</button>';
},
cellClick: (event, cell) => {
const data = cell.getRow().getData();
if (data.est_proprietaire && data.en_attente) {
event.stopPropagation();
supprimerDemandeConge(data.id);
}
},
},
],
pagination: true,
paginationSize: 5,
})
const bouton_demande_conges = $("bouton-demande-conge");
const bouton_supprimer_conge = $("bouton-supprimer-demande-conge");
bouton_demande_conges.addEventListener("click", (e) => {
var modalDemandeConge = new bootstrap.Modal(document.getElementById('modalDemandeConge'));
@@ -44,6 +91,11 @@ tableau_liste_demande_conge.on("rowClick", function(row, rowData) {
$("nombre_jours").value = data.nombre_jours;
$("solde_restant").value = data.solde_conge;
$("motif_refus").value = data.motif_refus;
bouton_supprimer_conge.classList.toggle(
"d-none",
!(data.est_proprietaire && data.en_attente)
);
bouton_supprimer_conge.dataset.congeId = data.id;
if($("validation_hierarchique_valide") & $("validation_hierarchique_refuse")){
$("validation_hierarchique_valide").checked = data.validation_hierarchique === true;
@@ -59,6 +111,10 @@ tableau_liste_demande_conge.on("rowClick", function(row, rowData) {
modal.show();
});
bouton_supprimer_conge.addEventListener("click", () => {
supprimerDemandeConge(bouton_supprimer_conge.dataset.congeId);
});
fetch(url_liste_conge_attente)
.then(response => response.json())
.then(data => {

View File

@@ -83,6 +83,13 @@
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fermer</button>
{% if conge.validation_hierarchique == None and conge.validation_direction == None%}
<button type="button" class="btn btn-danger " id="bouton-supprimer-demande-conge"
data-url="{% url 'gestion_conges:supprimer-demande-conge' 0 %}"
>
Supprimer ma demande
</button>
{% endif %}
{% if employe_est_il_chef or membre_de_la_direction or est_chef_projet %}
<button type="button" class="btn btn-success" id="bouton-enregistrer-detail-conge">Enregistrer</button>
{% endif %}

View File

@@ -24,4 +24,9 @@ urlpatterns = [
views.validation_de_conge,
name='validation-des-conges'
),
path(
'demande/<int:conge_id>/supprimer/',
views.supprimer_demande_conge,
name='supprimer-demande-conge',
),
]

View File

@@ -234,4 +234,56 @@ def validation_de_conge(request):
conge.motif_refus = motif_refus if validation_direction == "refuse" else ""
conge.save()
return JsonResponse({"message": "La décision a été enregistrée avec succès."})
return JsonResponse({"message": "La décision a été enregistrée avec succès."})
def _conge_est_en_attente(conge):
return (
conge.validation_hierarchique is not False
and conge.validation_direction is not False
and not (
conge.validation_hierarchique is True
and conge.validation_direction is True
)
)
@login_required
def supprimer_demande_conge(request, conge_id):
if request.method != "POST":
return JsonResponse(
{"success": False, "message": "Méthode non autorisée."},
status=405,
)
try:
employe = Employe.objects.get(user=request.user)
except Employe.DoesNotExist:
return JsonResponse(
{"success": False, "message": "Profil employé introuvable."},
status=403,
)
try:
conge = Conge.objects.get(pk=conge_id, employe=employe)
except Conge.DoesNotExist:
return JsonResponse(
{"success": False, "message": "Demande introuvable ou accès non autorisé."},
status=404,
)
if not _conge_est_en_attente(conge):
return JsonResponse(
{
"success": False,
"message": "Seules les demandes en attente peuvent être supprimées.",
},
status=400,
)
conge.delete()
return JsonResponse(
{"success": True, "message": "Votre demande de congé en attente a été supprimée."}
)

View File

@@ -14,20 +14,6 @@ const tableau_liste_employe = new Tabulator("#tableau_liste_employe", {
responsiveLayout : "hide"
})
const tableauToutesAffectations = new Tabulator("#tableauToutesAffectations", {
layout: "fitColumns",
pagination: "local",
paginationSize: 10,
placeholder: "Aucune affectation enregistrée pour cet employé.",
columns: [
{title: "Projet", field: "projet"},
{title: "Rôle", field: "role"},
{title: "Pourcentage", field: "pourcentage_temps_affectation", formatter: cell => `${cell.getValue()} %`},
{title: "Date de début", field: "date_affectation"},
{title: "Date de fin", field: "date_fin_daffectation", formatter: cell => cell.getValue() || "Non définie"},
],
})
fetch(url_liste_employe)
.then(response => response.json())
.then(data => {
@@ -163,9 +149,6 @@ tableau_liste_employe.on("rowClick", function (row, rowData) {
document.getElementById("affectation-nom-employe").textContent = data.employe || "Employé inconnu";
document.getElementById("affecter_employe_id").value = data.id;
$("liste-affectations-nom-employe").textContent = data.employe || "Employé inconnu";
tableauToutesAffectations.setData(data.toutes_affectations);
document.getElementById("affectations-list").innerHTML = "";
for (const affectation of data.affectations) {
document.getElementById("affectations-list").innerHTML += `
@@ -222,23 +205,6 @@ tableau_liste_employe.on("rowClick", function (row, rowData) {
modal.show();
})
$("btnAfficherToutesAffectations").addEventListener("click", function() {
const modalDetail = $("modalDetailEmploye");
const modalAffectations = $("modalListeAffectations");
modalDetail.addEventListener("hidden.bs.modal", function ouvrirListe() {
modalDetail.removeEventListener("hidden.bs.modal", ouvrirListe);
bootstrap.Modal.getOrCreateInstance(modalAffectations).show();
}, {once: true});
modalAffectations.addEventListener("hidden.bs.modal", function revenirAuDetail() {
modalAffectations.removeEventListener("hidden.bs.modal", revenirAuDetail);
bootstrap.Modal.getOrCreateInstance(modalDetail).show();
}, {once: true});
bootstrap.Modal.getOrCreateInstance(modalDetail).hide();
})
$("enregistrerDetail").addEventListener("click", function() {
const id_ = document.getElementById('detail-id').value;
const fonction = document.getElementById('detail-fonction').value;

View File

@@ -61,7 +61,6 @@
{% include "gestion_employe/parts/modalAffectationProjet.html" %}
{% include "gestion_employe/parts/modalDocument.html" %}
{% include "gestion_employe/parts/modalListeContratExpirants.html" %}
{% include "gestion_employe/parts/modalListeAffectations.html" %}
{% endblock %}
{% block 'js' %}
<script type="text/javascript" src="{% static 'gestion_employe/js/index.js' %}"></script>

View File

@@ -112,16 +112,11 @@
<div class="row d-flex g-3">
<div class="d-flex justify-content-between">
<h5><i class="bi bi-pin-angle me-2"></i> Affectations</h5>
<div class="d-flex gap-2">
<button type="button" class="btn btn-outline-primary" id="btnAfficherToutesAffectations">
<i class="bi bi-list-ul"></i> Voir toutes les affectations
{% if user|has_group:"ressource_humaine" %}
<button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#modalAffectation" onclick="setEmployeId()">
<i class="bi bi-file-earmark-text"></i>Affecter
</button>
{% if user|has_group:"ressource_humaine" %}
<button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#modalAffectation" onclick="setEmployeId()">
<i class="bi bi-file-earmark-text"></i> Affecter
</button>
{% endif %}
</div>
{% endif %}
</div>
<div class="row">
<div id="affectations-list"></div>

View File

@@ -1,20 +0,0 @@
<div class="modal fade" id="modalListeAffectations" tabindex="-1" aria-labelledby="modalListeAffectationsLabel" aria-hidden="true">
<div class="modal-dialog modal-xl modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modalListeAffectationsLabel">
Toutes les affectations de <span id="liste-affectations-nom-employe"></span>
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Fermer"></button>
</div>
<div class="modal-body">
<div id="tableauToutesAffectations"></div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">
<i class="bi bi-x-circle"></i> Fermer
</button>
</div>
</div>
</div>
</div>

View File

@@ -418,16 +418,6 @@ def liste_employe(request):
date_fin_daffectation__gte=timezone.now().date()
)
]
toutes_affectations = [
{
"projet": affectation.projet.nom_projet,
"role": dict(Affectation.ROLE_CHOICES).get(affectation.role, affectation.role),
"pourcentage_temps_affectation": affectation.pourcentage_temps_affectation,
"date_affectation": affectation.date_affectation,
"date_fin_daffectation": affectation.date_fin_daffectation,
}
for affectation in Affectation.objects.filter(employe=employe).select_related("projet")
]
data.append(
{
@@ -437,7 +427,6 @@ def liste_employe(request):
"email": employe.user.email,
"formations": formations,
"affectations": affectations,
"toutes_affectations": toutes_affectations,
"projet": projets,
"contrats": contrats,
"departement": employe.departement.id if employe.departement else "",