Compare commits
1 Commits
d09154ef9a
...
feature/li
| Author | SHA1 | Date | |
|---|---|---|---|
| f45ff7793d |
@@ -2,34 +2,6 @@ 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"},
|
||||
@@ -49,31 +21,12 @@ 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'));
|
||||
@@ -91,11 +44,6 @@ 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;
|
||||
@@ -111,10 +59,6 @@ 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 => {
|
||||
|
||||
@@ -83,13 +83,6 @@
|
||||
</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 %}
|
||||
|
||||
@@ -24,9 +24,4 @@ urlpatterns = [
|
||||
views.validation_de_conge,
|
||||
name='validation-des-conges'
|
||||
),
|
||||
path(
|
||||
'demande/<int:conge_id>/supprimer/',
|
||||
views.supprimer_demande_conge,
|
||||
name='supprimer-demande-conge',
|
||||
),
|
||||
]
|
||||
@@ -234,56 +234,4 @@ 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."})
|
||||
|
||||
|
||||
|
||||
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."}
|
||||
)
|
||||
|
||||
return JsonResponse({"message": "La décision a été enregistrée avec succès."})
|
||||
@@ -29,6 +29,7 @@ tableau_liste_employe.on("rowClick", function (row, rowData) {
|
||||
const data = rowData.getData();
|
||||
|
||||
document.getElementById('detail-id').value = data.id;
|
||||
document.querySelector("#modalContratsEmploye").dataset.employeId = data.id;
|
||||
document.getElementById('detail-matricule').value = data.matricule;
|
||||
document.getElementById('detail-employe').value = data.employe;
|
||||
document.getElementById('detail-fonction').value = data.fonction;
|
||||
@@ -270,68 +271,86 @@ const listeContratExpirant = new Tabulator("#listeContratExpirant", {
|
||||
ajaxURL: $("boutonContratExpirants").dataset.urlexpirants,
|
||||
})
|
||||
|
||||
/* let tabContrats = null;
|
||||
|
||||
document.getElementById("modalContratsEmploye").addEventListener("show.bs.modal", function () {
|
||||
|
||||
const employeId = document.getElementById("detail-id").value;
|
||||
let tabContrats = null;
|
||||
|
||||
$("boutonVoirContrats").addEventListener("click", function () {
|
||||
const employeId = $("detail-id").value;
|
||||
if (!employeId) {
|
||||
alert("Aucun employé sélectionné");
|
||||
$("nom-employe-contrat").textContent = "Aucun employé sélectionné.";
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`/employé/employe/${employeId}/contrats/`)
|
||||
$("modalContratsEmploye").dataset.employeId = employeId;
|
||||
|
||||
const modalDetail = $("modalDetailEmploye");
|
||||
modalDetail.addEventListener(
|
||||
"hidden.bs.modal",
|
||||
() => bootstrap.Modal.getOrCreateInstance($("modalContratsEmploye")).show(),
|
||||
{once: true}
|
||||
);
|
||||
bootstrap.Modal.getOrCreateInstance(modalDetail).hide();
|
||||
});
|
||||
|
||||
$("modalContratsEmploye").addEventListener("shown.bs.modal", function () {
|
||||
const employeId = this.dataset.employeId;
|
||||
const urlTemplate = this.dataset.urlTemplate;
|
||||
const tableElement = $("table-contrats-tabulator");
|
||||
|
||||
if (tabContrats) {
|
||||
tabContrats.destroy();
|
||||
tabContrats = null;
|
||||
}
|
||||
|
||||
if (!employeId) {
|
||||
$("nom-employe-contrat").textContent = "Aucun employé sélectionné.";
|
||||
return;
|
||||
}
|
||||
|
||||
tableElement.replaceChildren();
|
||||
$("nom-employe-contrat").textContent = "Chargement...";
|
||||
const url = urlTemplate.replace("123456789", employeId);
|
||||
|
||||
fetch(url)
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error("Erreur HTTP " + response.status);
|
||||
throw new Error(`Erreur HTTP ${response.status}`);
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
$("nom-employe-contrat").textContent = data.employe;
|
||||
|
||||
document.getElementById("nom-employe-contrat").innerText =
|
||||
data.employe;
|
||||
|
||||
if (tabContrats) {
|
||||
tabContrats.destroy();
|
||||
}
|
||||
|
||||
tabContrats = new Tabulator(
|
||||
"#table-contrats-tabulator",
|
||||
{
|
||||
data: data.contrats,
|
||||
layout: "fitColumns",
|
||||
placeholder: "Aucun contrat",
|
||||
|
||||
columns: [
|
||||
{ title: "Numéro", field: "numero_contrat" },
|
||||
{ title: "Type", field: "type_contrat" },
|
||||
{ title: "Date début", field: "date_debut" },
|
||||
{ title: "Date fin", field: "date_fin" },
|
||||
{ title: "Salaire", field: "salaire_mensuel" },
|
||||
{ title: "Statut", field: "statut" },
|
||||
|
||||
{
|
||||
title: "Contrat",
|
||||
field: "fichier",
|
||||
formatter: function(cell) {
|
||||
const url = cell.getValue();
|
||||
|
||||
if (!url) {
|
||||
return "<span class='text-danger'>Aucun fichier</span>";
|
||||
}
|
||||
|
||||
return `<a href="${url}" target="_blank" class="btn btn-sm btn-primary">
|
||||
<i class="bi bi-file-earmark-pdf"></i> Ouvrir
|
||||
</a>`;
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
);
|
||||
tabContrats = new Tabulator(tableElement, {
|
||||
data: data.contrats,
|
||||
layout: "fitColumns",
|
||||
pagination: true,
|
||||
paginationSize: 10,
|
||||
placeholder: "Aucun contrat",
|
||||
columns: [
|
||||
{title: "Numéro", field: "numero_contrat"},
|
||||
{title: "Type", field: "type_contrat"},
|
||||
{title: "Date début", field: "date_debut"},
|
||||
{title: "Date fin", field: "date_fin"},
|
||||
{title: "Salaire", field: "salaire_mensuel"},
|
||||
{title: "Statut", field: "statut"},
|
||||
{
|
||||
title: "Contrat",
|
||||
field: "fichier",
|
||||
formatter: "link",
|
||||
formatterParams: {target: "_blank"},
|
||||
},
|
||||
],
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Erreur :", error);
|
||||
console.error("Erreur lors du chargement des contrats :", error);
|
||||
$("nom-employe-contrat").textContent =
|
||||
"Impossible de charger les contrats.";
|
||||
tableElement.textContent =
|
||||
"Une erreur est survenue lors du chargement des contrats.";
|
||||
});
|
||||
}); */
|
||||
});
|
||||
|
||||
$("modalContratsEmploye").addEventListener("hidden.bs.modal", function () {
|
||||
bootstrap.Modal.getOrCreateInstance($("modalDetailEmploye")).show();
|
||||
});
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
{% block 'modal' %}
|
||||
{% include "gestion_employe/parts/modalDetailEmploye.html" %}
|
||||
{% include "gestion_employe/parts/modalCreationContrat.html" %}
|
||||
{% include "gestion_employe/parts/modalContratsEmploye.html" %}
|
||||
{% include "gestion_employe/parts/modalAffectationProjet.html" %}
|
||||
{% include "gestion_employe/parts/modalDocument.html" %}
|
||||
{% include "gestion_employe/parts/modalListeContratExpirants.html" %}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<div class="modal fade" id="modalContratsEmploye" tabindex="-1">
|
||||
<div class="modal fade" id="modalContratsEmploye" data-url-template="{% url 'gestion_employe:contrats-employe' 123456789 %}" tabindex="-1">
|
||||
<div class="modal-dialog modal-xl">
|
||||
<div class="modal-content">
|
||||
|
||||
@@ -14,4 +14,3 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -97,11 +97,15 @@
|
||||
<i class="bi bi-file-earmark-text me-2"></i> Liste des Contrats
|
||||
</h5>
|
||||
{% if user|has_group:"ressource_humaine" %}
|
||||
<div>
|
||||
<button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#modalContrat{{ item.employe.id }}">
|
||||
<div class="d-flex gap-2">
|
||||
<button type="button" class="btn btn-outline-primary" id="boutonVoirContrats">
|
||||
<i class="bi bi-files"></i> Voir tous les contrats
|
||||
</button>
|
||||
<button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#modalContrat">
|
||||
<i class="bi bi-file-earmark-text"></i> Créer contrat
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
</div>
|
||||
{% csrf_token %}
|
||||
|
||||
@@ -90,5 +90,10 @@ urlpatterns = [
|
||||
"liste-contrat-expirants",
|
||||
views.liste_contrat_expirants,
|
||||
name='liste-contrat-expirants'
|
||||
)
|
||||
),
|
||||
path(
|
||||
"liste-contrats-employe/<int:id_employe>/",
|
||||
views.liste_contrats_employe,
|
||||
name="liste-contrats-employe"
|
||||
)
|
||||
]
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import requests
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from decouple import config
|
||||
from django.contrib.auth import update_session_auth_hash
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.models import User
|
||||
@@ -300,6 +299,8 @@ def creation_contrat(request):
|
||||
|
||||
@login_required
|
||||
def contrats_employe(request, employe_id):
|
||||
if not request.user.groups.filter(name="ressource_humaine").exists():
|
||||
return JsonResponse({"error": "Accès non autorisé"}, status=403)
|
||||
|
||||
try:
|
||||
employe = Employe.objects.get(id=employe_id)
|
||||
@@ -506,42 +507,55 @@ def supprimer_formation(request, id_formation):
|
||||
def modifier_mot_passe(request):
|
||||
"""Vue pour permettre à un employé de modifier son mot de passe"""
|
||||
if request.method == "POST":
|
||||
username = request.user.username
|
||||
ancien_mdp = request.POST.get("ancien-mdp")
|
||||
nouveau_mdp = request.POST.get("nouveau-mdp")
|
||||
confirmation_mdp = request.POST.get("confirmation-mdp")
|
||||
|
||||
if not request.user.check_password(ancien_mdp):
|
||||
messages.error(request, "L'ancien mot de passe est incorrect.")
|
||||
return redirect("gestion_employe:mon-profil")
|
||||
|
||||
if nouveau_mdp != confirmation_mdp:
|
||||
messages.error(request, "Les nouveaux mots de passe ne correspondent pas.")
|
||||
return redirect("gestion_employe:mon-profil")
|
||||
|
||||
try:
|
||||
validate_password(nouveau_mdp, user=request.user)
|
||||
except ValidationError as e:
|
||||
messages.error(request, f"Erreur : {' '.join(e.messages)}")
|
||||
return redirect("gestion_employe:mon-profil")
|
||||
|
||||
donnees = {
|
||||
"username": username,
|
||||
"ancien_mdp": ancien_mdp,
|
||||
"nouveau_mdp": nouveau_mdp,
|
||||
"confirmation_mdp": confirmation_mdp
|
||||
}
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json",
|
||||
}
|
||||
|
||||
response = requests.post(
|
||||
f"{config('SERVEUR_AUTHENTIFICATION')}modifier-mot-de-passe/",
|
||||
json=donnees,
|
||||
headers=headers
|
||||
)
|
||||
|
||||
data = response.json()
|
||||
cle = next(iter(data.keys()))
|
||||
valeur = next(iter(data.values()))
|
||||
|
||||
if cle == "success":
|
||||
messages.success(request, valeur)
|
||||
else:
|
||||
messages.error(request, valeur)
|
||||
request.user.set_password(nouveau_mdp)
|
||||
request.user.save(update_fields=["password"])
|
||||
update_session_auth_hash(request, request.user)
|
||||
messages.success(request, "Mot de passe modifié avec succès.")
|
||||
|
||||
return redirect("gestion_employe:mon-profil")
|
||||
|
||||
def liste_contrats_employe(request, id_employe):
|
||||
"""Vue pour retourner la liste des contrats d'un employé spécifique"""
|
||||
try:
|
||||
employe = Employe.objects.get(id=id_employe)
|
||||
except Employe.DoesNotExist:
|
||||
return JsonResponse({"error": "Employé non trouvé"}, status=404)
|
||||
|
||||
contrats = Contrat.objects.filter(employe=employe).order_by("-date_debut")
|
||||
|
||||
data = [
|
||||
{
|
||||
"id": contrat.id,
|
||||
"numero_contrat": contrat.numero_contrat,
|
||||
"type_contrat": dict(Contrat.TYPE_CONTRAT).get(contrat.type_contrat),
|
||||
"date_debut": contrat.date_debut.strftime("%Y-%m-%d"),
|
||||
"date_fin": contrat.date_fin.strftime("%Y-%m-%d") if contrat.date_fin else "",
|
||||
"salaire_mensuel": contrat.salaire_mensuel,
|
||||
"statut": dict(Contrat.STATUT_CONTRAT).get(contrat.statut),
|
||||
"fichier_contrat": contrat.fichier_contrat.url if contrat.fichier_contrat else "",
|
||||
}
|
||||
for contrat in contrats
|
||||
]
|
||||
|
||||
return JsonResponse({
|
||||
"employe": f"{employe.user.first_name} {employe.user.last_name}",
|
||||
"contrats": data
|
||||
})
|
||||
Reference in New Issue
Block a user