diff --git a/Js/fonctions.js b/Js/fonctions.js
index db589be..63c7ac2 100755
--- a/Js/fonctions.js
+++ b/Js/fonctions.js
@@ -61,8 +61,9 @@ $(function() {
// On ne lance le timer que si l'utilisateur est connecté (pas sur la vue Connexion)
if (vueActuelle !== "Connexion") {
setInterval(function() {
-
+ console.log("Actualisation gabarit");
raffraichier_gabarit();
+
/* On vérifie si l'onglet est actif pour éviter des requêtes inutiles
if (!document.hidden) {
@@ -523,15 +524,8 @@ function afficher_quittances_police_periode() {
}
// 3. Préparation de l'interface (Loader)
- $conteneur.html(`
-
-
- Chargement...
-
-
Affichage des graphiques en cours...
+ showLoader("#div_graphique", { size: 3 });
+
+ $.ajax({
+ url: $("#racineWeb").val() + "Ajaxgraphiquesinistres/api/",
+ type: "get",
+ dataType: "json",
+ success: function (data) {
+ const exportLabel = t("exportPdf");
+
+ const html = `
+
+
+ ${exportLabel}
+
- `);
+
+
+
+
+
${t("charts.claimsTitle")}
+
+
+
+
+
+
+
+
${t("charts.monthlyTitle")}
+
+
+
+
+
+
+
+
${t("charts.lossRatioTitle")}
+
+
+
+
+
+ `;
+ hideLoader("#div_graphique", html);
- $.ajax({
- url: $("#racineWeb").val() + "Ajaxgraphiquesinistres/api/",
- type: 'get',
- dataType: 'json',
- success: function(data) {
- console.log("Réponse JSON reçue:", data);
+ // Render charts with localized labels
+ renderClaimsChart(data.claims);
+ renderClaimsMonthChart(data.claimsMonth);
+ renderLossRatioChart(data.lossRatio);
- // Layout HTML
- $("#div_graphique").html(`
-
-
- Exporter le tableau de bord en PDF
-
-
-
-
-
-
-
Répartition des sinistres
-
-
-
-
-
-
-
-
Évolution mensuelle
-
-
-
-
-
-
-
-
Ratio de sinistralité
-
-
-
-
-
- `);
+ setupExportPdf();
+ },
+ error: function (err) {
+ console.error("Erreur AJAX:", err);
+ hideLoader("#div_graphique", `
+
${t("errors.ajax")}
+ `);
+ }
+ });
+}
- // --- Graphiques Chart.js ---
+// --- Charts ---
- // 1. Répartition
- new Chart(document.getElementById('claimsChart'), {
- type: 'bar',
- data: {
- labels: data.claims.claimsLabels,
- datasets: [{
- label: 'Nombre de sinistres',
- data: data.claims.claimsValues,
- backgroundColor: 'rgba(54, 162, 235, 0.6)'
- }]
- }
- });
+function renderClaimsChart(claims) {
+ new Chart(document.getElementById("claimsChart"), {
+ type: "bar",
+ data: {
+ labels: claims.claimsLabels,
+ datasets: [{
+ label: t("charts.claimsCount"),
+ data: claims.claimsValues,
+ backgroundColor: "rgba(54, 162, 235, 0.6)"
+ }]
+ },
+ options: {
+ plugins: {
+ legend: { display: true }
+ },
+ scales: {
+ x: { title: { display: false } },
+ y: { title: { display: false }, beginAtZero: true }
+ }
+ }
+ });
+}
- // 2. Évolution mensuelle
- new Chart(document.getElementById('claimsMonthChart'), {
- type: 'line',
- data: {
- labels: data.claimsMonth.months,
- datasets: [
- {
- label: 'Sinistres mensuels',
- data: data.claimsMonth.monthlyClaims,
- borderColor: 'rgba(255, 99, 132, 0.8)',
- fill: false
- },
- {
- label: 'Sinistres uniques',
- data: data.claimsMonth.singleClaims,
- borderColor: 'rgba(75, 192, 192, 0.8)',
- fill: false
- }
- ]
- }
- });
+function renderClaimsMonthChart(claimsMonth) {
+ const labels = localizeMonths(claimsMonth.months);
- // 3. Ratio de sinistralité
- new Chart(document.getElementById('lossRatioChart'), {
- type: 'line',
- data: {
- labels: data.lossRatio.lossRatioLabels,
- datasets: [{
- label: 'Ratio de sinistralité',
- data: data.lossRatio.lossRatioValues,
- borderColor: 'rgba(255, 206, 86, 0.8)',
- fill: false
- }]
- }
- });
-
- // --- Export PDF ---
- $("#exportPdfBtn").on("click", function() {
- if (!window.jspdf) {
- alert("Erreur : jsPDF n'est pas chargé.");
- return;
- }
-
- const { jsPDF } = window.jspdf;
- const pdf = new jsPDF('p', 'mm', 'a4');
-
- pdf.setFontSize(18);
- pdf.text("Tableau de bord - Synthèse", 10, 20);
-
- // Ajout des graphiques
- addChartToPdf(pdf, 'claimsChart', 'Répartition des sinistres', 40);
- addChartToPdf(pdf, 'claimsMonthChart', 'Évolution mensuelle', 120);
-
- pdf.addPage();
- addChartToPdf(pdf, 'lossRatioChart', 'Ratio de sinistralité', 40);
-
- pdf.save('Tableau_de_bord.pdf');
- });
-
- function addChartToPdf(pdf, canvasId, title, startY) {
- const canvas = document.getElementById(canvasId);
- if (canvas) {
- const imgData = canvas.toDataURL('image/png', 1.0);
- pdf.setFontSize(14);
- pdf.text(title, 10, startY);
- pdf.addImage(imgData, 'PNG', 10, startY + 5, 180, 60);
- }
- }
+ new Chart(document.getElementById("claimsMonthChart"), {
+ type: "line",
+ data: {
+ labels,
+ datasets: [
+ {
+ label: t("charts.monthlyCumulative"),
+ data: claimsMonth.monthlyClaims,
+ borderColor: "rgba(255, 99, 132, 0.8)",
+ backgroundColor: "rgba(255, 99, 132, 0.2)",
+ tension: 0.25,
+ fill: false
},
- error: function(err) {
- console.error("Erreur AJAX:", err);
- $("#div_graphique").html(`
-
- Impossible de charger les graphiques.
-
- `);
+ {
+ label: t("charts.monthlySingle"),
+ data: claimsMonth.singleClaims,
+ borderColor: "rgba(75, 192, 192, 0.8)",
+ backgroundColor: "rgba(75, 192, 192, 0.2)",
+ tension: 0.25,
+ fill: false
}
- });
-}
\ No newline at end of file
+ ]
+ },
+ options: {
+ plugins: {
+ legend: { display: true }
+ },
+ scales: {
+ x: { title: { display: false } },
+ y: { title: { display: false }, beginAtZero: true }
+ }
+ }
+ });
+}
+
+function renderLossRatioChart(lossRatio) {
+ const labels = localizeMonths(lossRatio.lossRatioLabels);
+
+ new Chart(document.getElementById("lossRatioChart"), {
+ type: "line",
+ data: {
+ labels,
+ datasets: [{
+ label: t("charts.lossRatioLabel"),
+ data: lossRatio.lossRatioValues,
+ borderColor: "rgba(255, 206, 86, 0.8)",
+ backgroundColor: "rgba(255, 206, 86, 0.2)",
+ tension: 0.25,
+ fill: false
+ }]
+ },
+ options: {
+ plugins: {
+ legend: { display: true }
+ },
+ scales: {
+ x: { title: { display: false } },
+ y: { title: { display: false }, beginAtZero: true }
+ }
+ }
+ });
+}
+
+// --- Export PDF ---
+
+function setupExportPdf() {
+ $("#exportPdfBtn").on("click", function () {
+ if (!window.jspdf) {
+ alert(t("errors.pdfLib"));
+ return;
+ }
+ const { jsPDF } = window.jspdf;
+ const pdf = new jsPDF("p", "mm", "a4");
+
+ pdf.setFontSize(18);
+ pdf.text(t("dashboardTitle"), 10, 20);
+
+ addChartToPdf(pdf, "claimsChart", t("charts.claimsTitle"), 40);
+ addChartToPdf(pdf, "claimsMonthChart", t("charts.monthlyTitle"), 120);
+
+ pdf.addPage();
+ addChartToPdf(pdf, "lossRatioChart", t("charts.lossRatioTitle"), 40);
+
+ pdf.save("Tableau_de_bord.pdf"); // you can also localize the filename if needed
+ });
+}
+
+function addChartToPdf(pdf, canvasId, title, startY) {
+ const canvas = document.getElementById(canvasId);
+ if (canvas) {
+ const imgData = canvas.toDataURL("image/png", 1.0);
+ pdf.setFontSize(14);
+ pdf.text(title, 10, startY);
+ pdf.addImage(imgData, "PNG", 10, startY + 5, 180, 60);
+ }
+}
diff --git a/Vue/gabarit.php b/Vue/gabarit.php
index c2ae9e4..b03acfc 100755
--- a/Vue/gabarit.php
+++ b/Vue/gabarit.php
@@ -599,7 +599,7 @@ $activeChildId = $menuData['child'];
-
+