This commit is contained in:
KONE SOREL 2026-03-29 09:24:23 +00:00
parent 2f4186684e
commit 6aabd6b578
3 changed files with 86 additions and 66 deletions

View File

@ -360,70 +360,94 @@ function changer_langue_connexion() {
}
/**
* CONFIGURATION DATATABLES
* Initialise un tableau DataTable avec options génériques.
*
* @param {string|jQuery} selector - Sélecteur du tableau (ex: '.tabliste' ou '#myTable')
* @param {object} options - Options personnalisées (langue, boutons, ordre, etc.)
* Initialise DataTables avec support multilingue, exports personnalisés et entêtes fixes.
* * @param {string} selector - Sélecteur jQuery de la table (ex: '.tabliste')
* @param {object} options - Options DataTables spécifiques pour surcharger par défaut
* @param {string} titreDoc - Titre principal pour les exports (PDF/Excel/Print)
* @param {string} message - Informations de police/contexte sous le titre (messageTop)
*/
function appliquerDataTable(selector = '.tabliste', options = {}, titreDoc = "Rapport", message = "") {
// 1. Détection de la langue via un champ caché dans votre header
const codeLangue = $("#codeLangue").val() || 'fr_FR';
// 2. Dictionnaire de traduction
const translations = {
fr_FR: {
lengthMenu: "Affiche _MENU_ par page",
zeroRecords: "Aucune donnée trouvée",
info: "_PAGE_ sur _PAGES_",
search: "Recherche:",
paginate: { next: "►", previous: "◄" }
infoEmpty: "Aucun enregistrement disponible",
infoFiltered: "(filtré de _MAX_ total)",
search: "Recherche rapide :",
paginate: {
next: "Suivant ►",
previous: "◄ Précédent"
}
},
en_US: {
lengthMenu: "Display _MENU_ records",
zeroRecords: "Nothing found",
info: "Showing page _PAGE_ of _PAGES_",
search: "Search:",
paginate: { next: "►", previous: "◄" }
infoEmpty: "No records available",
infoFiltered: "(filtered from _MAX_ total)",
search: "Quick Search:",
paginate: {
next: "Next ►",
previous: "◄ Previous"
}
}
};
$(selector).each(function() {
const $table = $(this);
// 3. Gestion automatique des colonnes masquées (via l'attribut data-hidden="true" sur le TH)
const hiddenTargets = [];
$table.find('thead th').each((idx, th) => {
if ($(th).data('hidden')) hiddenTargets.push(idx);
if ($(th).data('hidden')) {
hiddenTargets.push(idx);
}
});
// Configuration des boutons avec Titre ET Message de haut de page
const exportButtons = [
{
extend: 'excel',
title: titreDoc,
messageTop: message // Ajoute les infos en haut de l'Excel
},
{
extend: 'pdf',
title: titreDoc,
messageTop: message, // Ajoute les infos en haut du PDF
orientation: 'landscape'
},
{
extend: 'print',
title: titreDoc,
messageTop: message // Ajoute les infos sur l'impression
// 4. Configuration des boutons d'export avec Titre et Message Contextuel
const exportConfig = {
title: titreDoc,
messageTop: message,
exportOptions: {
columns: ':visible' // Exporte uniquement ce qui est affiché à l'écran
}
];
};
// 5. Initialisation de l'instance DataTable
const instance = $table.DataTable($.extend(true, {
destroy: true,
responsive: true,
order: [[0, "desc"]],
destroy: true, // Permet de réinitialiser la table si elle existe déjà
responsive: true, // Adaptation mobile
pageLength: 25, // Nombre de lignes par défaut
order: [[0, "desc"]], // Tri par défaut sur la 1ère colonne
dom: 'Bfrtip', // Positionnement des éléments (Buttons, filter, processing, table, info, pagination)
language: translations[codeLangue] || translations.fr_FR,
columnDefs: [{ targets: hiddenTargets, visible: false }],
dom: 'Bfrtip',
buttons: exportButtons
columnDefs: [
{ targets: hiddenTargets, visible: false } // Masque les colonnes techniques
],
// Activation du Header et Footer collants (Nécessite l'extension FixedHeader)
fixedHeader: {
header: true,
footer: true
},
buttons: [
$.extend(true, {}, exportConfig, { extend: 'copy', className: 'btn btn-sm btn-light' }),
$.extend(true, {}, exportConfig, { extend: 'excel', className: 'btn btn-sm btn-success' }),
$.extend(true, {}, exportConfig, {
extend: 'pdf',
className: 'btn btn-sm btn-danger',
orientation: 'landscape',
pageSize: 'A4'
}),
$.extend(true, {}, exportConfig, { extend: 'print', className: 'btn btn-sm btn-dark' })
]
}, options));
// 6. Recalcul de la largeur des colonnes après le rendu initial
$table.on('init.dt', function () {
if (instance && instance.responsive) {
instance.columns.adjust();

View File

@ -15,11 +15,9 @@
<small class="text-uppercase opacity-75 d-block"><?= _("Ratio Moyen") ?></small>
<span class="h5 fw-bold text-info"><?= number_format((float)$rpsinistres_total['ratio_moyen'], 2, ',', ' ') ?> %</span>
</div>
<div class="col-md-3">
<div class="col-md-3 text-start">
<i class="fas fa-info-circle me-1 text-info"></i>
<small class="small d-block text-start" style="font-size: 7.5pt;">
<?= _("Affichage limité aux 200 premières lignes. Utilisez l'export Excel pour le rapport complet.") ?>
</small>
<small style="font-size: 7.5pt;"><?= _("Affichage limité aux 200 premières lignes. Utilisez Excel pour le rapport complet.") ?></small>
</div>
</div>
</div>
@ -42,7 +40,6 @@
<?php foreach ($rpsinistres as $rpsinistre):
$nbligne++;
$ratio = (float)$rpsinistre['ratio'];
// Couleur dynamique pour le ratio selon la gravité
$ratioClass = ($ratio > 100) ? 'text-danger fw-bold' : (($ratio > 70) ? 'text-warning' : 'text-success');
?>
<tr>
@ -51,33 +48,30 @@
<td class="text-center text-muted"><?= dateLang($this->nettoyer($rpsinistre['dateEffetAdherent']), $_SESSION['lang']) ?></td>
<td class="text-center"><?= $this->nettoyer($rpsinistre['duree_acquise']) ?> <small><?= _("j") ?></small></td>
<td class="text-center fw-bold"><?= format_N($rpsinistre['sinistres']) ?></td>
<td class="text-center <?= $ratioClass ?>">
<?= number_format($ratio, 2, ',', ' ') ?> %
</td>
<td class="text-center <?= $ratioClass ?>"><?= number_format($ratio, 2, ',', ' ') ?> %</td>
<td class="text-center">
<span class="badge bg-secondary-subtle text-secondary border border-secondary-subtle">
<?= $this->nettoyer($rpsinistre['codeProduit']) ?>
</span>
</td>
</tr>
<?php
if ($nbligne == 200) {
$nbligne = "> " . $nbligne . " => " . _("Excel");
break;
}
?>
<?php if ($nbligne == 200) { $nbligne = "> 200"; break; } ?>
<?php endforeach; ?>
</tbody>
<tfoot class="table-light border-top border-dark">
<tr>
<td colspan="4" class="text-center fw-bold text-uppercase"><?= _("Total Général") ?></td>
<td class="text-center fw-bold text-dark fs-6"><?= format_N($rpsinistres_total['sinistres_total']) ?></td>
<td class="text-center fw-bold text-info fs-6"><?= number_format((float)$rpsinistres_total['ratio_moyen'], 2, ',', ' ') ?> %</td>
<td class="bg-light"></td>
</tr>
</tfoot>
</table>
</div>
<div class="card-footer bg-white d-flex justify-content-between align-items-center py-2">
<span class="text-muted small italic">
<i class="fas fa-clock me-1"></i><?= _("Généré le") ?> <?= date('d/m/Y H:i') ?>
</span>
<span class="text-muted small italic"><i class="fas fa-clock me-1"></i><?= _("Généré le") ?> <?= date('d/m/Y H:i') ?></span>
<span class="badge bg-dark px-3"><?= $_SESSION['numeroPolice_C'] ?></span>
</div>
@ -86,26 +80,28 @@
<script>
$(document).ready(function() {
const titreRapport = "<?= mb_strtoupper(_('RAPPORT RÉSUMÉ DES SINISTRES'), 'UTF-8'); ?>";
// 1. Préparation des textes
const titreRapport = <?= json_encode(mb_strtoupper(_('RAPPORT RÉSUMÉ DES SINISTRES'), 'UTF-8')) ?>;
// Construction des informations de police pour l'export
const infosPolice =
// 2. Préparation du bloc d'infos Subscriber/Policy/Period
const infosEntete =
"<?= _('Souscripteur') ?> : <?= $_SESSION['nomClient_C'] ?>\n" +
"<?= _('Numéro Police') ?> : <?= $_SESSION['numeroPolice_C'] ?>\n" +
"<?= _('Période du') ?> : <?= $_SESSION['dateDebutRequete'] ?> <?= _('au') ?> <?= $_SESSION['dateFinRequete'] ?>";
// Initialisation DataTable
// 3. Appel de la fonction COMMUNE appliquerDataTable()
// On passe 'footer: true' dans les boutons pour que le <tfoot> soit exporté
appliquerDataTable('#table_resume_sinistres', {
pageLength: 50,
order: [[5, "desc"]], // Tri par ratio décroissant pour voir les dossiers critiques
order: [[5, "desc"]], // Tri par Ratio décroissant
buttons: [
{ extend: 'excel', title: titreRapport, messageTop: infosPolice },
{ extend: 'pdf', title: titreRapport, messageTop: infosPolice, orientation: 'landscape' },
{ extend: 'print', title: titreRapport, messageTop: infosPolice }
{ extend: 'excel', title: titreRapport, messageTop: infosEntete, footer: true },
{ extend: 'pdf', title: titreRapport, messageTop: infosEntete, orientation: 'landscape', footer: true },
{ extend: 'print', title: titreRapport, messageTop: infosEntete, footer: true }
]
}, titreRapport, infosPolice);
}, titreRapport, infosEntete);
// Mise à jour automatique du champ "Lignes" dans l'entête de recherche
// 4. Mise à jour du compteur global (l'input dans ton formulaire de recherche)
$('#nbligne').val($('#nbligne_info').val());
});
</script>

View File

@ -710,7 +710,7 @@ $photoAssureCrypte = $_SESSION['photoAssureCrypte'];
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<!-- Application Scripts -->
<script src="/Js/fonctions.js?ver=2026.03.28.07"></script>
<script src="/Js/fonctions.js?ver=2026.03.29.00"></script>
<script type="text/javascript">
raffraichier_gabarit();