codice:
function fetchBadgeDetails(idDipendente, detailsRowId) {
  fetch("../php/countbdgpag.php", {
    method: "POST",
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
    body: `iddip=${idDipendente}`,
  })
    .then((response) => response.json())
    .then((data) => {
      const detailsContent = document.getElementById(
        `details-content-${idDipendente}`
      );
      let badgesHTML = `<table class="badge-details">

              <thead>
                  <tr>
                      <th class="hidden-id">ID BADGE</th>
                      <th class="hidden-id">ID DIPENDENTE</th>
                      <th>BADGE N°</th>
                      <th>NFC</th>
                      <th>RICHIESTO IL</th>
                      <th>RILASCIATO IL</th>
                      <th>CAUSALE</th>
                      <th>RILASCIO COME</th>
                      <th>FOTO</th>
                  </tr>
              </thead>

              <tbody>`;

              data.data.forEach((badge) => {
              badgesHTML += `<tr onclick="alert('ID Badge cliccato: ${badge.idbadge}')">
                    <td class="hidden-id">${badge.idbadge}</td>
                    <td class="hidden-id">${badge.iddip}</td>
                    <td>${badge.nbadge}</td>
                    <td>${badge.nfc}</td>
                    <td>${badge.richiesto}</td>
                    <td>${badge.rilascio}</td>
                    <td>${badge.causale}</td>
                    <td>${badge.rilascioper}</td>
                    <td>${badge.foto}</td>
              </tr>`;
      });

          badgesHTML += `</tbody></table>`;
          badgesHTML += `<div>${data.dettaglioBadge}</div>`; // Aggiungi il dettaglio dei conteggi dei badge
          detailsContent.innerHTML = badgesHTML; // Inserisce i dettagli dei badge nel contenitore appropriato
    })
    .catch((error) => {
      console.error(
        "Errore durante il caricamento dei dettagli dei badge:",
        error
      );    
      detailsContent.innerHTML = "Errore nel caricamento dei dati.";
    });
}