diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..10a233e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +db.sqlite3 +venv/* +media/* \ No newline at end of file diff --git a/SIRH/__pycache__/__init__.cpython-312.pyc b/SIRH/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..d7a38f5 Binary files /dev/null and b/SIRH/__pycache__/__init__.cpython-312.pyc differ diff --git a/SIRH/__pycache__/settings.cpython-312.pyc b/SIRH/__pycache__/settings.cpython-312.pyc new file mode 100644 index 0000000..36f61e4 Binary files /dev/null and b/SIRH/__pycache__/settings.cpython-312.pyc differ diff --git a/SIRH/__pycache__/urls.cpython-312.pyc b/SIRH/__pycache__/urls.cpython-312.pyc new file mode 100644 index 0000000..6a4d43b Binary files /dev/null and b/SIRH/__pycache__/urls.cpython-312.pyc differ diff --git a/SIRH/__pycache__/views.cpython-312.pyc b/SIRH/__pycache__/views.cpython-312.pyc new file mode 100644 index 0000000..64da710 Binary files /dev/null and b/SIRH/__pycache__/views.cpython-312.pyc differ diff --git a/SIRH/__pycache__/wsgi.cpython-312.pyc b/SIRH/__pycache__/wsgi.cpython-312.pyc new file mode 100644 index 0000000..fded293 Binary files /dev/null and b/SIRH/__pycache__/wsgi.cpython-312.pyc differ diff --git a/SIRH/settings.py b/SIRH/settings.py index 62d8d8d..2d2857c 100644 --- a/SIRH/settings.py +++ b/SIRH/settings.py @@ -81,22 +81,20 @@ WSGI_APPLICATION = 'SIRH.wsgi.application' # DATABASES = { # 'default': { -# 'ENGINE': 'django.db.backends.sqlite3', -# 'NAME': BASE_DIR / 'db.sqlite3', -# } +# 'ENGINE': 'django.db.backends.mysql', +# 'NAME': 'sirh', +# 'USER': 'test', +# 'PASSWORD': 'test-django', +# 'HOST': 'localhost', +# 'PORT': '3306', # } DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.mysql', - 'NAME': 'sirh', - 'USER': 'test', - 'PASSWORD': 'test-django', - 'HOST': 'localhost', # Or the server IP - 'PORT': '3306', # Default MySQL port + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } } -} - # Password validation # https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators @@ -156,4 +154,6 @@ EMAIL_USE_SSL = True EMAIL_USE_TLS = False EMAIL_HOST_USER = 'support.it@cerfig.org' EMAIL_HOST_PASSWORD = 'Cerfig2025' -DEFAULT_FROM_EMAIL = EMAIL_HOST_USER \ No newline at end of file +DEFAULT_FROM_EMAIL = EMAIL_HOST_USER + + diff --git a/SIRH/templates/SIRH/parts/menu_principal.html b/SIRH/templates/SIRH/parts/menu_principal.html index b9021f3..d2989ce 100644 --- a/SIRH/templates/SIRH/parts/menu_principal.html +++ b/SIRH/templates/SIRH/parts/menu_principal.html @@ -2,6 +2,20 @@ {% load tags_personnaliser %}
+
+ {% if user.employe.photo %} + + {% else %} + + {% endif %} +
+ {{ user.username }} +
+
Mon profil diff --git a/fonction_utilitaire/__pycache__/fonctions_utilitaire.cpython-312.pyc b/fonction_utilitaire/__pycache__/fonctions_utilitaire.cpython-312.pyc new file mode 100644 index 0000000..99904e8 Binary files /dev/null and b/fonction_utilitaire/__pycache__/fonctions_utilitaire.cpython-312.pyc differ diff --git a/fonction_utilitaire/fonctions_utilitaire.py b/fonction_utilitaire/fonctions_utilitaire.py index 1ccdba0..de18744 100644 --- a/fonction_utilitaire/fonctions_utilitaire.py +++ b/fonction_utilitaire/fonctions_utilitaire.py @@ -1,7 +1,8 @@ from django.utils import timezone from gestion_employe.models import Contrat from gestion_conge.models import Conge - +from django.core.mail import send_mail +from gestion_salle.models import Reservation QUOTA_CONGE_ANNUEL = 30 NOMBRE_PAGINATION = 8 @@ -11,7 +12,6 @@ DUREE_FIN_CONTRAT = 90 def solde_conge(employe): """Fonction de calcul du solde de congé restant l'employé""" contrat = Contrat.objects.filter(employe=employe, statut='actif').order_by('-date_debut').first() - if contrat is None or not contrat.date_debut: return { "success": False, @@ -31,4 +31,38 @@ def solde_conge(employe): "success": True, "quota_annuel": QUOTA_CONGE_ANNUEL - jours_conges_valider, "nombre_jours_valide": jours_conges_valider - } \ No newline at end of file + } + +def envoyer_email(type_notification, utilisateur, contexte=None): + sujet = "" + message = "" + nom = f"{utilisateur.first_name} {utilisateur.last_name}" + + if type_notification == "reservation_creee": + sujet = "Confirmation de votre réservation" + message = f"Bonjour {nom}, votre réservation a été enregistrée." + + elif type_notification == "reservation_validee": + sujet = "Réservation validée" + message = f"Bonjour {nom}, votre réservation a été validée." + + elif type_notification == "reservation_refusee": + sujet = "Réservation refusée" + message = f"Bonjour {nom}, votre réservation a été refusée." + + elif type_notification == "reservation_annulee": + sujet = "Réservation annulée" + message = f"Bonjour {nom}, votre réservation a été annulée." + + elif type_notification == "lien_zoom": + sujet = "Lien Zoom ajouté" + message = f"Bonjour {nom}, un lien Zoom a été ajouté à votre réservation : {Reservation.lien_zoom}" + + send_mail( + sujet, + message, + "admin@tonsite.com", + [utilisateur.email], + fail_silently=False, + ) + diff --git a/gestion_conge/__pycache__/__init__.cpython-312.pyc b/gestion_conge/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..3163171 Binary files /dev/null and b/gestion_conge/__pycache__/__init__.cpython-312.pyc differ diff --git a/gestion_conge/__pycache__/admin.cpython-312.pyc b/gestion_conge/__pycache__/admin.cpython-312.pyc new file mode 100644 index 0000000..fc5338f Binary files /dev/null and b/gestion_conge/__pycache__/admin.cpython-312.pyc differ diff --git a/gestion_conge/__pycache__/apps.cpython-312.pyc b/gestion_conge/__pycache__/apps.cpython-312.pyc new file mode 100644 index 0000000..9e13ffe Binary files /dev/null and b/gestion_conge/__pycache__/apps.cpython-312.pyc differ diff --git a/gestion_conge/__pycache__/forms.cpython-312.pyc b/gestion_conge/__pycache__/forms.cpython-312.pyc new file mode 100644 index 0000000..a39b119 Binary files /dev/null and b/gestion_conge/__pycache__/forms.cpython-312.pyc differ diff --git a/gestion_conge/__pycache__/models.cpython-312.pyc b/gestion_conge/__pycache__/models.cpython-312.pyc new file mode 100644 index 0000000..3f9a896 Binary files /dev/null and b/gestion_conge/__pycache__/models.cpython-312.pyc differ diff --git a/gestion_conge/__pycache__/urls.cpython-312.pyc b/gestion_conge/__pycache__/urls.cpython-312.pyc new file mode 100644 index 0000000..c39278b Binary files /dev/null and b/gestion_conge/__pycache__/urls.cpython-312.pyc differ diff --git a/gestion_conge/__pycache__/views.cpython-312.pyc b/gestion_conge/__pycache__/views.cpython-312.pyc new file mode 100644 index 0000000..a77c215 Binary files /dev/null and b/gestion_conge/__pycache__/views.cpython-312.pyc differ diff --git a/gestion_conge/migrations/__pycache__/0001_initial.cpython-312.pyc b/gestion_conge/migrations/__pycache__/0001_initial.cpython-312.pyc new file mode 100644 index 0000000..9390055 Binary files /dev/null and b/gestion_conge/migrations/__pycache__/0001_initial.cpython-312.pyc differ diff --git a/gestion_conge/migrations/__pycache__/__init__.cpython-312.pyc b/gestion_conge/migrations/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..dad8cda Binary files /dev/null and b/gestion_conge/migrations/__pycache__/__init__.cpython-312.pyc differ diff --git a/gestion_conge/static/gestion_conge/js/detail_conges.js b/gestion_conge/static/gestion_conge/js/detail_conges.js index fd39b94..d7aff14 100644 --- a/gestion_conge/static/gestion_conge/js/detail_conges.js +++ b/gestion_conge/static/gestion_conge/js/detail_conges.js @@ -36,14 +36,12 @@ if(bouton_enregistrer_detail){ if(document.getElementById("validation_hierarchique_refuse")){ document.getElementById("validation_hierarchique_refuse").addEventListener('click', function(){ if(this.checked){ - alert("coucou"); document.getElementById("motif_refus_container").className="d-block form-group mt-3"; }else{ document.getElementById("motif_refus_container").className="d-none"; } }) } - if(document.getElementById("validation_hierarchique_refuse")){ document.getElementById("validation_hierarchique_refuse").addEventListener('click', function(){ if(this.checked){ @@ -67,9 +65,9 @@ if(document.getElementById("validation_hierarchique_valide")){ if(document.getElementById("validation_direction_valide")){ document.getElementById("validation_direction_valide").addEventListener('click', function(){ if(this.checked){ - document.getElementById("motif_refus_container").className="d-block form-group mt-3"; - }else{ document.getElementById("motif_refus_container").className="d-none"; + }else{ + document.getElementById("motif_refus_container").className="d-block form-group mt-3"; } }) } \ No newline at end of file diff --git a/gestion_conge/templates/gestion_conge/parts/modalDetailConge.html b/gestion_conge/templates/gestion_conge/parts/modalDetailConge.html index d3d3051..5c81ca0 100644 --- a/gestion_conge/templates/gestion_conge/parts/modalDetailConge.html +++ b/gestion_conge/templates/gestion_conge/parts/modalDetailConge.html @@ -65,7 +65,7 @@
Validation par le directeur
- +
diff --git a/gestion_employe/__pycache__/__init__.cpython-312.pyc b/gestion_employe/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..cc1b99e Binary files /dev/null and b/gestion_employe/__pycache__/__init__.cpython-312.pyc differ diff --git a/gestion_employe/__pycache__/admin.cpython-312.pyc b/gestion_employe/__pycache__/admin.cpython-312.pyc new file mode 100644 index 0000000..10d005f Binary files /dev/null and b/gestion_employe/__pycache__/admin.cpython-312.pyc differ diff --git a/gestion_employe/__pycache__/forms.cpython-312.pyc b/gestion_employe/__pycache__/forms.cpython-312.pyc new file mode 100644 index 0000000..af0aa03 Binary files /dev/null and b/gestion_employe/__pycache__/forms.cpython-312.pyc differ diff --git a/gestion_employe/__pycache__/models.cpython-312.pyc b/gestion_employe/__pycache__/models.cpython-312.pyc new file mode 100644 index 0000000..25334f8 Binary files /dev/null and b/gestion_employe/__pycache__/models.cpython-312.pyc differ diff --git a/gestion_employe/__pycache__/urls.cpython-312.pyc b/gestion_employe/__pycache__/urls.cpython-312.pyc new file mode 100644 index 0000000..4a6237c Binary files /dev/null and b/gestion_employe/__pycache__/urls.cpython-312.pyc differ diff --git a/gestion_employe/__pycache__/views.cpython-312.pyc b/gestion_employe/__pycache__/views.cpython-312.pyc new file mode 100644 index 0000000..86e62fa Binary files /dev/null and b/gestion_employe/__pycache__/views.cpython-312.pyc differ diff --git a/gestion_employe/migrations/__pycache__/0001_initial.cpython-312.pyc b/gestion_employe/migrations/__pycache__/0001_initial.cpython-312.pyc new file mode 100644 index 0000000..dcb5fe0 Binary files /dev/null and b/gestion_employe/migrations/__pycache__/0001_initial.cpython-312.pyc differ diff --git a/gestion_employe/migrations/__pycache__/__init__.cpython-312.pyc b/gestion_employe/migrations/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..f712f59 Binary files /dev/null and b/gestion_employe/migrations/__pycache__/__init__.cpython-312.pyc differ diff --git a/gestion_employe/static/gestion_employe/js/index.js b/gestion_employe/static/gestion_employe/js/index.js index 95eb1d8..0d04aaa 100644 --- a/gestion_employe/static/gestion_employe/js/index.js +++ b/gestion_employe/static/gestion_employe/js/index.js @@ -1,6 +1,7 @@ const $ = (element) => document.getElementById(element); const url_liste_employe = $("tableau_liste_employe").dataset.url; + const tableau_liste_employe = new Tabulator("#tableau_liste_employe", { columns: [ {"title": "Matricule", "field": "matricule"}, @@ -12,6 +13,8 @@ const tableau_liste_employe = new Tabulator("#tableau_liste_employe", { // ajaxURL: url_liste_employe, pagination: true, paginationSize: 10, + + }) fetch(url_liste_employe) @@ -44,6 +47,8 @@ tableau_liste_employe.on("rowClick", function (row, rowData) { document.getElementById('document-diplome').href = data.diplome; document.getElementById('document-diplome').textContent = data.diplome || "Aucun diplôme"; + document.getElementById('document-photo').href = data.photo; + document.getElementById('document-photo').textContent = data.photo || "Aucune photo"; document.getElementById('document-cv').href = data.CV; document.getElementById('document-cv').textContent = data.CV || "Aucun CV"; document.getElementById('document-rib').href = data.rib; @@ -123,6 +128,7 @@ tableau_liste_employe.on("rowClick", function (row, rowData) {
` }; + const supprimerButtons = document.getElementsByClassName("btn-supprimer-contrat"); Array.from(supprimerButtons).forEach(button => { @@ -144,8 +150,46 @@ tableau_liste_employe.on("rowClick", function (row, rowData) { location.reload(); }) }); - }) + }), + + document.addEventListener("click", function (e) { + if (e.target.closest(".btn-modifier-contrat")) { + + const button = e.target.closest(".btn-modifier-contrat"); + const parent = button.closest(".col-6"); + + const contratId = button.dataset.contratid; + + const data = { + type_contrat: parent.querySelector("select").value, + date_debut: parent.querySelectorAll("input")[1].value, + date_fin: parent.querySelectorAll("input")[2].value, + salaire_mensuel: parent.querySelectorAll("input")[3].value, + statut: parent.querySelectorAll("input")[4].value, + }; + + fetch(`/contrat/modifier/${contratId}/`, { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-CSRFToken": document.querySelector('[name=csrfmiddlewaretoken]').value + }, + body: JSON.stringify(data) + }) + .then(response => response.json()) + .then(data => { + if (data.message) { + alert(data.message); + } else { + alert(data.error || "Erreur"); + } + }) + .catch(error => { + console.error("Erreur:", error); + }); + } + }); document.getElementById("affectation-nom-employe").textContent = data.employe || "Employé inconnu"; document.getElementById("affecter_employe_id").value = data.id; @@ -204,7 +248,7 @@ tableau_liste_employe.on("rowClick", function (row, rowData) { const modal = new bootstrap.Modal($("modalDetailEmploye")); modal.show(); }) - + $("enregistrerDetail").addEventListener("click", function() { const id_ = document.getElementById('detail-id').value; const fonction = document.getElementById('detail-fonction').value; diff --git a/gestion_employe/static/gestion_employe/js/mon_profil.js b/gestion_employe/static/gestion_employe/js/mon_profil.js index 64c77f9..186e5a4 100644 --- a/gestion_employe/static/gestion_employe/js/mon_profil.js +++ b/gestion_employe/static/gestion_employe/js/mon_profil.js @@ -16,27 +16,36 @@ const tableau_certificat = new Tabulator("#tableau-certificat", { ], ajaxURL: url_certificat, }) - const enregistrerProfil = $("enregistrerProfil"); + enregistrerProfil.addEventListener("click", (e) => { + const url = $("information-personnelles").dataset.url; const csrftoken = document.querySelector("[name='csrfmiddlewaretoken']").value; + + const formData = new FormData(); + + formData.append("nom", $("nom").value); + formData.append("prenom", $("prenom").value); + formData.append("email", $("email").value); + formData.append("telephone", $("telephone").value); + formData.append("adresse", $("adresse").value); + formData.append("sexe", $("sexe").value); + formData.append("date_naissance", $("date_naissance").value); + + const photoInput = $("photo"); + if (photoInput.files.length > 0) { + formData.append("photo", photoInput.files[0]); + } + fetch(url, { - method: 'POST', + method: "POST", headers: { - 'Content-Type': 'application/json', - 'X-CSRFToken': csrftoken + "X-CSRFToken": csrftoken }, - body: JSON.stringify({ - "nom": $("nom").value, - "prenom": $("prenom").value, - "email": $("email").value, - "telephone": $("telephone").value, - "adresse": $("adresse").value, - "sexe": $("sexe").value, - "date_naissance": $("date_naissance").value, - }) + body: formData }) .then(response => response.json()) .then(data => alert(data.message)) -}) \ No newline at end of file + .catch(error => console.error("Erreur:", error)); +}); \ No newline at end of file diff --git a/gestion_employe/templates/gestion_employe/monprofil.html b/gestion_employe/templates/gestion_employe/monprofil.html index 410fd7f..850837f 100644 --- a/gestion_employe/templates/gestion_employe/monprofil.html +++ b/gestion_employe/templates/gestion_employe/monprofil.html @@ -19,17 +19,14 @@ {% endfor %} {% endif %} - -{% if expiration_contrat %} - {% if contrat_nb_jours_restant %} +{% if not expiration_contrat %} +
+ Important : Les informations sur votre contrat n'ont pas été renseignées, veuillez contacter les ressources humaines. +
+{% elif contrat_nb_jours_restant %}
Important : Votre contrat de travail expire dans {{ contrat_nb_jours_restant }} jours, veuillez contacter les ressources humaines.
- {% endif %} -{% else %} -
- Important : Les informations sur votre contrat n'ont pas été renseignées, veuillez contacter les ressources humaines. -
{% endif %}
@@ -44,6 +41,13 @@
{% csrf_token %}
+
+ + {% if employe.photo %} + Fichier actuel : {{employe.photo}} + {% endif %} + +
@@ -63,12 +67,13 @@
+ +
+
-
-
@@ -167,6 +172,13 @@ {% csrf_token %}
+
{% if employe.CV %} diff --git a/gestion_employe/templates/gestion_employe/parts/modalDetailEmploye.html b/gestion_employe/templates/gestion_employe/parts/modalDetailEmploye.html index 187ef49..e2db54f 100644 --- a/gestion_employe/templates/gestion_employe/parts/modalDetailEmploye.html +++ b/gestion_employe/templates/gestion_employe/parts/modalDetailEmploye.html @@ -88,22 +88,23 @@
-
+
G Liste des Contrats
{% if user|has_group:"ressource_humaine" %}
- -
+ +
{% endif %}
{% csrf_token %} -
+
+

diff --git a/gestion_employe/templates/gestion_employe/parts/modalDocument.html b/gestion_employe/templates/gestion_employe/parts/modalDocument.html index 4eeb124..c8aa90e 100644 --- a/gestion_employe/templates/gestion_employe/parts/modalDocument.html +++ b/gestion_employe/templates/gestion_employe/parts/modalDocument.html @@ -11,6 +11,10 @@
    +
  • + Photo : + +
  • Diplôme : diff --git a/gestion_employe/templatetags/__pycache__/tags_personnaliser.cpython-312.pyc b/gestion_employe/templatetags/__pycache__/tags_personnaliser.cpython-312.pyc new file mode 100644 index 0000000..19f72ad Binary files /dev/null and b/gestion_employe/templatetags/__pycache__/tags_personnaliser.cpython-312.pyc differ diff --git a/gestion_employe/urls.py b/gestion_employe/urls.py index 992dbd7..d9befdb 100644 --- a/gestion_employe/urls.py +++ b/gestion_employe/urls.py @@ -34,6 +34,12 @@ urlpatterns = [ views.suppression_contrat, name='supprimer-contrat' ), + + path( + "contrat/modifier/", + views.modifier_contrat, + name="modifier-contrat" + ), path( 'Affectation/affectation/', views.affecter_employe_projet, diff --git a/gestion_employe/views.py b/gestion_employe/views.py index 4740abf..56e78cf 100644 --- a/gestion_employe/views.py +++ b/gestion_employe/views.py @@ -1,12 +1,12 @@ import json -from datetime import timedelta, datetime +from datetime import date, timedelta, datetime from dateutil.relativedelta import relativedelta from django.utils import timezone from django.contrib import messages from django.contrib.auth.models import User from django.contrib.auth import authenticate -from django.shortcuts import render, redirect +from django.shortcuts import get_object_or_404, render, redirect from django.contrib.auth.decorators import login_required from django.http import JsonResponse @@ -124,8 +124,8 @@ def mon_profil(request): except Employe.DoesNotExist: messages.error(request, "Impossible d'acceder au menu 'Mon profil' car votre profil Utilisateur n'est lié à aucun profil Employé. Veuillez contacter l'Administrateur.") return redirect("gestion_conges:conge") - contrats = Contrat.objects.filter(employe=employe, statut='actif').first() + projets = Affectation.objects.filter( employe = employe, date_fin_daffectation__gte = timezone.now().date() @@ -140,6 +140,7 @@ def mon_profil(request): **model_to_dict(contrats), "type_contrat": dict(Contrat.TYPE_CONTRAT).get(contrats.type_contrat), "statut": dict(Contrat.STATUT_CONTRAT).get(contrats.statut), + # "salaire_mensuel": dict(Contrat.SALAIRR_MENSSUEL).get(contrats.salaire_mensuel), "fichier_contrat": contrats.fichier_contrat.url if contrats.fichier_contrat else "", } if contrats else []], 'projets': [ @@ -192,7 +193,8 @@ def modifier_employer(request): employe.telephone = data['telephone'] employe.adresse = data['adresse'] employe.sexe = data['sexe'] - + if request.FILES.get("photo"): + employe.photo = request.FILES["photo"] if data['date_naissance']: difference = relativedelta(timezone.now().date(), datetime.strptime(data['date_naissance'], "%Y-%m-%d").date()) if difference.years >= 18: @@ -201,18 +203,18 @@ def modifier_employer(request): return JsonResponse({"message": "Veuillez entrez une date de naissance correcte."}) employe.save() user.save() - return JsonResponse({"message": "Profil mis à jour avec succès."}) def enregistrement_document(request): - employe = Employe.objects.get(user__username=request.user) + employe = Employe.objects.get(user=request.user) if request.method == "POST": - employe.CV = request.FILES["cv"] if 'cv' in request.FILES else employe.CV - employe.diplome = request.FILES["diplome"] if 'diplome' in request.FILES else employe.diplome - employe.rib = request.FILES["rib"] if 'rib' in request.FILES else employe.rib - employe.casier_judiciaire = request.FILES["casier_judiciaire"] if 'casier_judiciaire' in request.FILES else employe.casier_judiciaire - messages.success(request, "Documents enregistrés avec succès.") + if request.FILES.get("photo"):employe.photo = request.FILES["photo"] + if "cv" in request.FILES:employe.CV = request.FILES["cv"] + if "diplome" in request.FILES: employe.diplome = request.FILES["diplome"] + if "rib" in request.FILES: employe.rib = request.FILES["rib"] + if "casier_judiciaire" in request.FILES:employe.casier_judiciaire = request.FILES["casier_judiciaire"] employe.save() + messages.success(request, "Documents enregistrés avec succès.") return redirect("gestion_employe:mon-profil") @@ -240,14 +242,25 @@ def suppression_affectation(request): return JsonResponse({"message": "Affectation supprimée avec succès."}) def creation_contrat(request): - """Vue pour permettre à un utilisateur de créer un contrat pour un employé""" + """Créer un contrat pour un employé (avec contrôle d'existence de contrat actif)""" + try: employe = Employe.objects.get(id=request.POST.get('employe_id')) except Employe.DoesNotExist: messages.error(request, "Employé non trouvé.") return redirect('employe-index') - + contrat_actif = Contrat.objects.filter( + employe=employe, + date_fin__gte=date.today() + ).exists() + if request.method == "POST": + if contrat_actif: + messages.error( + request, + "Impossible de créer un contrat : cet employé a déjà un contrat actif." + ) + return redirect('gestion_employe:index') form = ContratForm(request.POST, request.FILES) if form.is_valid(): contrat = form.save(commit=False) @@ -256,9 +269,13 @@ def creation_contrat(request): messages.success(request, "Contrat créé avec succès.") return redirect('gestion_employe:index') messages.error(request, "Formulaire non valide") + else: form = ContratForm(initial={'employe': employe}) - return render(request, 'gestion_employe/index.html', {'contrat_form': form}) + + return render(request, 'gestion_employe/index.html', { + 'contrat_form': form + }) @login_required def enregistrer_detail_employe(request): @@ -281,76 +298,106 @@ def enregistrer_detail_employe(request): @login_required def liste_employe(request): """ Vue pour retourner la liste de tous les employés """ + + employes = Employe.objects.exclude(user__first_name = '', user__last_name = '') data = [] for employe in employes: - if employe.user.first_name == ' ' and employe.user.last_name == ' ': - projets = [ - ", ".join([ - a.projet.nom_projet for a in Affectation.objects.filter( - employe=employe, - date_fin_daffectation__gte=timezone.now().date() - ) - ]) - ] - formations = [ - { - "titre": formation.titre, - "organisme": formation.organisme, - "description": formation.description, - "date_obtention": formation.date_obtention, - "date_fin": formation.date_fin, - "certificat": formation.certificat.url if formation.certificat else "", - } for formation in Formation.objects.filter(employe=employe) - ] - - contrats = [ - { - "numero_contrat": contrat.numero_contrat, - "type_contrat": contrat.type_contrat, - "date_debut": contrat.date_debut, - "date_fin": contrat.date_fin, - "salaire_mensuel": contrat.salaire_mensuel, - "statut": contrat.statut, - "fichier_contrat": contrat.fichier_contrat.url if contrat.fichier_contrat else "", - } for contrat in Contrat.objects.filter(employe=employe, statut='actif') - ] - - affectations = [ - {**model_to_dict(affectation), "projet": affectation.projet.nom_projet} - for affectation in Affectation.objects.filter( + projets = [ + ", ".join([ + a.projet.nom_projet for a in Affectation.objects.filter( employe=employe, date_fin_daffectation__gte=timezone.now().date() ) - ] + ]) + ] + formations = [ + { + "titre": formation.titre, + "organisme": formation.organisme, + "description": formation.description, + "date_obtention": formation.date_obtention, + "date_fin": formation.date_fin, + "certificat": formation.certificat.url if formation.certificat else "", + } for formation in Formation.objects.filter(employe=employe) + ] - data.append( - { - "id": employe.id, - "employe": f"{employe.user.first_name} {employe.user.last_name}", - "matricule": employe.matricule, - "email": employe.user.email, - "formations": formations, - "affectations": affectations, - "projet": projets, - "contrats": contrats, - "departement": employe.departement.nom if employe.departement else "", - "fonction": employe.fonction, - "date_embauche": employe.date_embauche, - "adresse": employe.adresse, - "telephone": employe.telephone, - "sexe": employe.sexe, - "CV": employe.CV.url if employe.CV else "", - "diplome": employe.diplome.url if employe.diplome else "", - "rib": employe.rib.url if employe.rib else "", - "photo": employe.photo.url if employe.photo else "", - "casier_judiciaire": employe.casier_judiciaire.url if employe.casier_judiciaire else "", - "date_naissance": employe.date_naissance, - } + contrats = [ + { + "numero_contrat": contrat.numero_contrat, + "type_contrat": contrat.type_contrat, + "date_debut": contrat.date_debut, + "date_fin": contrat.date_fin, + "salaire_mensuel": contrat.salaire_mensuel, + "statut": contrat.statut, + "fichier_contrat": contrat.fichier_contrat.url if contrat.fichier_contrat else "", + } for contrat in Contrat.objects.filter(employe=employe, statut='actif') + ] + + affectations = [ + {**model_to_dict(affectation), "projet": affectation.projet.nom_projet} + for affectation in Affectation.objects.filter( + employe=employe, + date_fin_daffectation__gte=timezone.now().date() ) + ] + + data.append( + { + "id": employe.id, + "employe": f"{employe.user.first_name} {employe.user.last_name}", + "matricule": employe.matricule, + "email": employe.user.email, + "formations": formations, + "affectations": affectations, + "projet": projets, + "contrats": contrats, + "departement": employe.departement.nom if employe.departement else "", + "fonction": employe.fonction, + "date_embauche": employe.date_embauche, + "adresse": employe.adresse, + "telephone": employe.telephone, + "sexe": employe.sexe, + "CV": employe.CV.url if employe.CV else "", + "diplome": employe.diplome.url if employe.diplome else "", + "rib": employe.rib.url if employe.rib else "", + "photo": employe.photo.url if employe.photo else "", + "casier_judiciaire": employe.casier_judiciaire.url if employe.casier_judiciaire else "", + "date_naissance": employe.date_naissance, + } + ) return JsonResponse({'success': True, 'data': data}, safe=False) + + +@login_required +def modifier_contrat(request): + + """vue pour la modification du contrat """ + + id_contrat = json.loads(request.body)['id'] + try: + contrat = Contrat.objects.get(numero_contrat = id_contrat) + except Contrat.DoesNotExist: + messages.error(request, "Contrat non trouvé.") + return JsonResponse({"message": "Contrat non trouvé."}, status=404) + + try: + data = json.loads(request.body) + id_contrat = data.get("id") + contrat = get_object_or_404(Contrat, id=id_contrat) + contrat.type_contrat = data.get("type_contrat") + contrat.date_debut = data.get("date_debut") + contrat.date_fin = data.get("date_fin") + contrat.salaire_mensuel = data.get("salaire_mensuel") + contrat.statut = data.get("statut") + contrat.save() + + return JsonResponse({"message": "Contrat modifié avec succès"}) + + except Exception as e: + return JsonResponse({"message": str(e)}, status=400) @login_required def ajouter_formation(request): """Vue pour permettre à un employé d'ajouter une formation à son profil""" diff --git a/gestion_projet/__pycache__/__init__.cpython-312.pyc b/gestion_projet/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..a02ff83 Binary files /dev/null and b/gestion_projet/__pycache__/__init__.cpython-312.pyc differ diff --git a/gestion_projet/__pycache__/admin.cpython-312.pyc b/gestion_projet/__pycache__/admin.cpython-312.pyc new file mode 100644 index 0000000..af6943c Binary files /dev/null and b/gestion_projet/__pycache__/admin.cpython-312.pyc differ diff --git a/gestion_projet/__pycache__/forms.cpython-312.pyc b/gestion_projet/__pycache__/forms.cpython-312.pyc new file mode 100644 index 0000000..f3dcc44 Binary files /dev/null and b/gestion_projet/__pycache__/forms.cpython-312.pyc differ diff --git a/gestion_projet/__pycache__/models.cpython-312.pyc b/gestion_projet/__pycache__/models.cpython-312.pyc new file mode 100644 index 0000000..877ce9e Binary files /dev/null and b/gestion_projet/__pycache__/models.cpython-312.pyc differ diff --git a/gestion_projet/__pycache__/urls.cpython-312.pyc b/gestion_projet/__pycache__/urls.cpython-312.pyc new file mode 100644 index 0000000..a9d8935 Binary files /dev/null and b/gestion_projet/__pycache__/urls.cpython-312.pyc differ diff --git a/gestion_projet/__pycache__/views.cpython-312.pyc b/gestion_projet/__pycache__/views.cpython-312.pyc new file mode 100644 index 0000000..a00a3b8 Binary files /dev/null and b/gestion_projet/__pycache__/views.cpython-312.pyc differ diff --git a/gestion_projet/migrations/__pycache__/0001_initial.cpython-312.pyc b/gestion_projet/migrations/__pycache__/0001_initial.cpython-312.pyc new file mode 100644 index 0000000..bb11fee Binary files /dev/null and b/gestion_projet/migrations/__pycache__/0001_initial.cpython-312.pyc differ diff --git a/gestion_projet/migrations/__pycache__/__init__.cpython-312.pyc b/gestion_projet/migrations/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..b862c6f Binary files /dev/null and b/gestion_projet/migrations/__pycache__/__init__.cpython-312.pyc differ diff --git a/gestion_projet/static/gestion_projet/js/enregistrement_bailleur.js b/gestion_projet/static/gestion_projet/js/enregistrement_bailleur.js index afe12ea..c09f502 100644 --- a/gestion_projet/static/gestion_projet/js/enregistrement_bailleur.js +++ b/gestion_projet/static/gestion_projet/js/enregistrement_bailleur.js @@ -1,4 +1,5 @@ const btnEnregistrerBailleur = document.getElementById('btnEnregistrerBailleur'); +let table; btnEnregistrerBailleur.addEventListener('click', function() { const form = document.getElementById('formBailleur'); @@ -20,4 +21,31 @@ btnEnregistrerBailleur.addEventListener('click', function() { alert('Ce bailleur existe déjà dans la base de données.'); } }); -}); \ No newline at end of file +}); + +document.addEventListener("DOMContentLoaded", function () { + + table = new Tabulator("#table-bailleurs", { + ajaxURL: "/gestion-projet/bailleurs/", + layout: "fitColumns", + pagination: "local", + paginationSize: 5, + + columns: [ + {title: "#", formatter: "rownum", width: 60}, + {title: "Organisme", field: "nom_organisme"}, + {title: "Contact", field: "contact"}, + {title: "Email", field: "email"}, + {title: "Pays", field: "pays"}, + ], + rowDblClick: function(e, row) { + const data = row.getData(); + + if (confirm(`Voulez-vous vraiment supprimer ${data.nom_organisme} ?`)) { + supprimerBailleur(data.id); + } + } + }); + +}); + diff --git a/gestion_projet/templates/gestion_projet/parts/creation_bailleur.html b/gestion_projet/templates/gestion_projet/parts/creation_bailleur.html index 6fe4194..2f31a37 100644 --- a/gestion_projet/templates/gestion_projet/parts/creation_bailleur.html +++ b/gestion_projet/templates/gestion_projet/parts/creation_bailleur.html @@ -1,20 +1,51 @@
-
\ No newline at end of file +
diff --git a/gestion_projet/urls.py b/gestion_projet/urls.py index 6e3f087..06e898e 100644 --- a/gestion_projet/urls.py +++ b/gestion_projet/urls.py @@ -19,6 +19,12 @@ urlpatterns = [ views.creation_projet, name='creation-projet' ), + path( + 'bailleurs/', + views.liste_bailleur, + name='liste-bailleurs' + ), + path( 'projet/modifier//', views.modification_projet, @@ -84,6 +90,7 @@ urlpatterns = [ views.liste_activites_projet, name='liste-activites-projet' ), + # path( # 'projet/ajout-de-document/', # views.ajouter_document_projet, @@ -119,4 +126,6 @@ urlpatterns = [ views.mises_a_jour_projet, name='mises-a-jour-projet' ) -] \ No newline at end of file + +] + diff --git a/gestion_projet/views.py b/gestion_projet/views.py index 69bd619..80a4ba4 100644 --- a/gestion_projet/views.py +++ b/gestion_projet/views.py @@ -2,6 +2,7 @@ from datetime import date from decimal import Decimal, InvalidOperation from django.http import JsonResponse from django.shortcuts import redirect, render +from django.urls import reverse from django.utils import timezone from django.contrib import messages from django.contrib.auth.decorators import login_required @@ -143,6 +144,22 @@ def creation_bailleur(request): return JsonResponse({'success': True}) return JsonResponse({'success': False}) +@login_required +def liste_bailleur(request): + """ Vue pour retourner la liste de tous les bailleurs """ + bailleurs = Bailleur.objects.all().order_by('-id') + data = [] + for b in bailleurs: + data.append({ + "id": b.id, + "nom_organisme": b.nom_organisme, + "contact": b.contact, + "email": b.email, + "pays": b.pays, + }) + return JsonResponse(data, safe=False) + + @login_required def ajouter_financement_projet(request): """Ajoute un financement à un projet en vérifiant que le total ne dépasse pas 100%""" @@ -318,6 +335,7 @@ def activites_projet(request): } return render(request, 'gestion_projet/suivi_activite.html', context) + @login_required def ajouter_activite_projet(request): """Vue pour ajouter une activité à un projet spécifique via un formulaire""" diff --git a/gestion_salle/__pycache__/__init__.cpython-312.pyc b/gestion_salle/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..ea21754 Binary files /dev/null and b/gestion_salle/__pycache__/__init__.cpython-312.pyc differ diff --git a/gestion_salle/__pycache__/admin.cpython-312.pyc b/gestion_salle/__pycache__/admin.cpython-312.pyc new file mode 100644 index 0000000..e59353e Binary files /dev/null and b/gestion_salle/__pycache__/admin.cpython-312.pyc differ diff --git a/gestion_salle/__pycache__/apps.cpython-312.pyc b/gestion_salle/__pycache__/apps.cpython-312.pyc new file mode 100644 index 0000000..0b1761e Binary files /dev/null and b/gestion_salle/__pycache__/apps.cpython-312.pyc differ diff --git a/gestion_salle/__pycache__/forms.cpython-312.pyc b/gestion_salle/__pycache__/forms.cpython-312.pyc new file mode 100644 index 0000000..d0dd40a Binary files /dev/null and b/gestion_salle/__pycache__/forms.cpython-312.pyc differ diff --git a/gestion_salle/__pycache__/models.cpython-312.pyc b/gestion_salle/__pycache__/models.cpython-312.pyc new file mode 100644 index 0000000..5c61561 Binary files /dev/null and b/gestion_salle/__pycache__/models.cpython-312.pyc differ diff --git a/gestion_salle/__pycache__/urls.cpython-312.pyc b/gestion_salle/__pycache__/urls.cpython-312.pyc new file mode 100644 index 0000000..f47b223 Binary files /dev/null and b/gestion_salle/__pycache__/urls.cpython-312.pyc differ diff --git a/gestion_salle/__pycache__/views.cpython-312.pyc b/gestion_salle/__pycache__/views.cpython-312.pyc new file mode 100644 index 0000000..19e63bd Binary files /dev/null and b/gestion_salle/__pycache__/views.cpython-312.pyc differ diff --git a/gestion_salle/migrations/__pycache__/0001_initial.cpython-312.pyc b/gestion_salle/migrations/__pycache__/0001_initial.cpython-312.pyc new file mode 100644 index 0000000..02d9eb0 Binary files /dev/null and b/gestion_salle/migrations/__pycache__/0001_initial.cpython-312.pyc differ diff --git a/gestion_salle/migrations/__pycache__/__init__.cpython-312.pyc b/gestion_salle/migrations/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..1212ed9 Binary files /dev/null and b/gestion_salle/migrations/__pycache__/__init__.cpython-312.pyc differ diff --git a/gestion_salle/templates/gestion_salle/parts/modalCreationReservation.html b/gestion_salle/templates/gestion_salle/parts/modalCreationReservation.html index 0db15f8..c49142e 100644 --- a/gestion_salle/templates/gestion_salle/parts/modalCreationReservation.html +++ b/gestion_salle/templates/gestion_salle/parts/modalCreationReservation.html @@ -20,4 +20,6 @@
-
\ No newline at end of file +
+ + diff --git a/gestion_salle/templates/gestion_salle/parts/modalDetailResevation.html b/gestion_salle/templates/gestion_salle/parts/modalDetailResevation.html index fb84ee8..27d7d1f 100644 --- a/gestion_salle/templates/gestion_salle/parts/modalDetailResevation.html +++ b/gestion_salle/templates/gestion_salle/parts/modalDetailResevation.html @@ -21,8 +21,12 @@
- - + + +
+
+ +
@@ -48,10 +52,6 @@
-
- - -
{% if appartient_au_departement_informatique %} @@ -59,8 +59,9 @@ {% if appartient_direction and reservation.statut == "en_attente" %} {% endif %} + - {% if appartient_direction %} + {% if appartient_direction and reservation.statut == "en_attente" %} {% endif %}
@@ -68,4 +69,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/gestion_salle/views.py b/gestion_salle/views.py index de589cf..2f8aeb9 100644 --- a/gestion_salle/views.py +++ b/gestion_salle/views.py @@ -16,8 +16,7 @@ def index(request:HttpRequest): employe = Employe.objects.get(user=request.user) except Employe.DoesNotExist: messages.error(request, "Impossible d'accéder au menu 'Reservation de salle' car votre profil Utilisateur n'est lié à aucun profil Employe. Veuillez contacter l'administrateur.") - return redirect('gestion_conges:conge') - + return redirect('gestion_conges:conge') if request.method == "POST": form = ReservationForm(request.POST) if form.is_valid(): @@ -29,7 +28,7 @@ def index(request:HttpRequest): motif_reservation = form.cleaned_data.get('motif_reservation') besoin_zoom = form.cleaned_data.get('besoin_zoom') besoin_ordi = form.cleaned_data.get('besoin_ordi') - + while date_debut <= date_fin : reservation = Reservation( employe = employe, @@ -42,12 +41,24 @@ def index(request:HttpRequest): besoin_ordi = besoin_ordi, motif_reservation=motif_reservation, ) - reservation.save() - date_debut = date_debut + timedelta(days=1) - + if heure_fin <= heure_debut: + messages.error( + request, + "Erreur : l'heure de fin ne peut pas être inférieure ou égale à l'heure de début." + ) + return redirect('gestion_salle:reservation-salle') + first_name = (employe.user.first_name or "").strip() + last_name = (employe.user.last_name or "").strip() + if not first_name or not last_name: + messages.error( + request, + "Vous devez renseigner un nom et prénom valides avant de faire une réservation." + ) + return redirect('gestion_salle:reservation-salle') + reservation.save() + date_debut = date_debut + timedelta(days=1) messages.success(request, "Réservation(s) créées avec succès.") return redirect('gestion_salle:reservation-salle') - formulaire_reservation = ReservationForm() departement = Employe.objects.get(user__username=request.user).departement appartient_direction = 'direction' in request.user.groups.values_list('name', flat=True) @@ -86,7 +97,6 @@ def liste_reservation(request:HttpRequest): "end": reservation.heure_fin, "color": color, }) - return JsonResponse(liste_reservation, safe=False) @login_required @@ -105,21 +115,22 @@ def liste_reservation_attente(request): def detail_reservation(request:HttpRequest, reservation_id:int): reservation = Reservation.objects.get(id=reservation_id) employe = reservation.employe.user + reservation_json = { + 'id_reservation': reservation_id, 'employe': f"{employe.first_name} {employe.last_name}", 'salle': reservation.salle, 'statut': reservation.statut, - 'date_evenement': reservation.date_debut.strftime('%Y-%m-%d'), + 'date_debut': reservation.date_debut.strftime('%Y-%m-%d'), + 'date_fin': reservation.date_fin.strftime('%Y-%m-%d'), 'heure_debut': reservation.heure_debut.strftime('%H:%M'), 'heure_fin': reservation.heure_fin.strftime('%H:%M'), 'motif_reservation': reservation.motif_reservation, 'besoin_zoom': reservation.besoin_zoom, 'besoin_ordinateur': reservation.besoin_ordi, 'lien_zoom': reservation.lien_zoom or '', - 'motif_refus': reservation.motif_refus or '', } - return JsonResponse(reservation_json, safe=True) @login_required