affichage_liste_contrat_employer #41
@@ -261,3 +261,76 @@ 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;
|
||||
|
||||
console.log("Employe ID :", employeId);
|
||||
|
||||
if (!employeId) {
|
||||
alert("Aucun employé sélectionné");
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`/employé/employe/${employeId}/contrats/`)
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error("Erreur HTTP " + response.status);
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
|
||||
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>`;
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Erreur :", error);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -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" %}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<div class="modal fade" id="modalContratsEmploye" tabindex="-1">
|
||||
<div class="modal-dialog modal-xl">
|
||||
<div class="modal-content">
|
||||
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">
|
||||
Contrats de <span id="nom-employe-contrat"></span>
|
||||
</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<div id="table-contrats-tabulator"></div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -93,8 +93,8 @@
|
||||
</h5>
|
||||
{% if user|has_group:"ressource_humaine" %}
|
||||
<div>
|
||||
<button class="btn btn-secondary" disabled>
|
||||
<i class="bi bi-file-earmark-lock"></i> Contrat actif
|
||||
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#modalContratsEmploye">
|
||||
Liste contrat
|
||||
</button>
|
||||
<button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#modalContrat{{ item.employe.id }}">
|
||||
<i class="bi bi-file-earmark-text"></i> Créer contrat
|
||||
|
||||
@@ -29,11 +29,17 @@ urlpatterns = [
|
||||
views.creation_contrat,
|
||||
name='creation-contrat'
|
||||
),
|
||||
path(
|
||||
'employe/<int:employe_id>/contrats/'
|
||||
, views.contrats_employe,
|
||||
name="contrats-employe"
|
||||
),
|
||||
path(
|
||||
'contrat/supprimer/',
|
||||
views.suppression_contrat,
|
||||
name='supprimer-contrat'
|
||||
),
|
||||
|
||||
path(
|
||||
'Affectation/affectation/',
|
||||
views.affecter_employe_projet,
|
||||
|
||||
@@ -289,6 +289,45 @@ def creation_contrat(request):
|
||||
'contrat_form': form
|
||||
})
|
||||
|
||||
|
||||
@login_required
|
||||
def contrats_employe(request, employe_id):
|
||||
|
||||
try:
|
||||
employe = Employe.objects.get(id=employe_id)
|
||||
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.fichier_contrat.url if contrat.fichier_contrat else "",
|
||||
|
||||
}
|
||||
for contrat in contrats
|
||||
]
|
||||
|
||||
return JsonResponse({
|
||||
"employe": employe.user.get_full_name(),
|
||||
"contrats": data
|
||||
})
|
||||
@login_required
|
||||
def enregistrer_detail_employe(request):
|
||||
"""Vue pour permettre à un utilisateur de modifier les détails d'un employé via une requête AJAX"""
|
||||
@@ -307,6 +346,7 @@ def enregistrer_detail_employe(request):
|
||||
else:
|
||||
return JsonResponse({"message": "Méthode non autorisée."}, status=405)
|
||||
|
||||
|
||||
@login_required
|
||||
def liste_employe(request):
|
||||
""" Vue pour retourner la liste de tous les employés """
|
||||
|
||||
Reference in New Issue
Block a user