function dateDiffInDays(a) { if (!a || a === 'Missing' || a === ' ') return 999; // Sécurité const _MS_PER_DAY = 1000 * 60 * 60 * 24; return Math.floor((Date.now() - new Date(a)) / _MS_PER_DAY); } $(function() { $('#button').click(function () { var $data = $('#t1').bootstrapTable('getData'); var $dl = $data.length; if ($dl === 0) return; var $nSCCM=0, $nAD=0, $nGLPI=0, $nEPO=0, $nNBU=0, $nOS=0, $nSCOM=0, $nZabbix=0, $nS1=0; for(var $i=0 ; $i < $dl ; $i++ ){ // Vérification AD if ($data[$i]['AD'] !== 'Missing') { $nAD++; var adDate = ($data[$i]['ADlu'] || '').split(" ")[0]; if (dateDiffInDays(adDate) > 45 || adDate === '') { $nAD--; } } // Vérification SCCM if ($data[$i]['SCCM'] !== 'Missing') { $nSCCM++; var sccmDate = ($data[$i]['SCCMlu'] || '').split(" ")[0]; if (dateDiffInDays(sccmDate) > 7 || sccmDate === '') { $nSCCM--; } } // Vérification GLPI if ($data[$i]['GLPI'] !== 'Missing') { $nGLPI++; var glpiDate = ($data[$i]['GLPIlu'] || '').split(" ")[0]; if (dateDiffInDays(glpiDate) > 7 || glpiDate === '') { $nGLPI--; } } // NESSUS if ($data[$i]['NESSUS'] !== 'Missing' && $data[$i]['NESSUS'] !== ' ') { $nEPO++; } // BACKUP if ($data[$i]['Backup'] !== 'Missing') { $nNBU++; var nbuDate = ($data[$i]['NBUlu'] || '').split(" ")[0]; if (dateDiffInDays(nbuDate) > 30 || nbuDate === '') { $nNBU--; } } // OS (Supporté) var os = $data[$i]['OS'] || ''; if (!(os.includes('XP') || os.includes('2000') || os.includes('2003') || os.includes('2008') || os.includes('2012') || os.includes('7')) && os !== ' ') { $nOS++; } // SCOM & Zabbix if ($data[$i]['SCOM'] !== 'Missing') { $nSCOM++; } if ($data[$i]['Zabbix'] !== 'Missing') { $nZabbix++; } // S1 if ($data[$i]['S1'] !== 'Missing') { $nS1++; var s1Date = ($data[$i]['S1lu'] || '').split(" ")[0]; if (dateDiffInDays(s1Date) > 7 || s1Date === '') { $nS1--; } } } document.getElementById("KPIAD").innerHTML = Math.round($nAD/$dl*1000)/10 + "%"; if(Math.round($nAD/$dl*100) >=90){ document.getElementById("KPIAD").className = "badge text-bg-success font-weight-bold"; }else if(Math.round($nAD/$dl*100) >=75){ document.getElementById("KPIAD").className = "badge text-bg-warning font-weight-bold"; }else{ document.getElementById("KPIAD").className = "badge text-bg-danger font-weight-bold"; } document.getElementById("KPIGLPI").innerHTML = Math.round($nGLPI/$dl*1000)/10 + "%"; if(Math.round($nGLPI/$dl*100) >=90){ document.getElementById("KPIGLPI").className = "badge text-bg-success font-weight-bold"; }else if(Math.round($nGLPI/$dl*100) >=75){ document.getElementById("KPIGLPI").className = "badge text-bg-warning font-weight-bold"; }else{ document.getElementById("KPIGLPI").className = "badge text-bg-danger font-weight-bold"; } document.getElementById("KPISCCM").innerHTML = Math.round($nSCCM/$dl*1000)/10 + "%"; if(Math.round($nSCCM/$dl*100) >=90){ document.getElementById("KPISCCM").className = "badge text-bg-success font-weight-bold"; }else if(Math.round($nSCCM/$dl*100) >=75){ document.getElementById("KPISCCM").className = "badge text-bg-warning font-weight-bold"; }else{ document.getElementById("KPISCCM").className = "badge text-bg-danger font-weight-bold"; } document.getElementById("KPIEPO").innerHTML = Math.round($nEPO/$dl*1000)/10 + "%"; if(Math.round($nEPO/$dl*100) >=90){ document.getElementById("KPIEPO").className = "badge text-bg-success font-weight-bold"; }else if(Math.round($nEPO/$dl*100) >=75){ document.getElementById("KPIEPO").className = "badge text-bg-warning font-weight-bold"; }else{ document.getElementById("KPIEPO").className = "badge text-bg-danger font-weight-bold"; } document.getElementById("KPINBU").innerHTML = Math.round($nNBU/$dl*1000)/10 + "%"; if(Math.round($nNBU/$dl*100) >=90){ document.getElementById("KPINBU").className = "badge text-bg-success font-weight-bold"; }else if(Math.round($nNBU/$dl*100) >=75){ document.getElementById("KPINBU").className = "badge text-bg-warning font-weight-bold"; }else{ document.getElementById("KPINBU").className = "badge text-bg-danger font-weight-bold"; } document.getElementById("KPIOS").innerHTML = Math.round($nOS/$dl*1000)/10 + "%"; if(Math.round($nOS/$dl*100) >=90){ document.getElementById("KPIOS").className = "badge text-bg-success font-weight-bold"; }else if(Math.round($nOS/$dl*100) >=75){ document.getElementById("KPIOS").className = "badge text-bg-warning font-weight-bold"; }else{ document.getElementById("KPIOS").className = "badge text-bg-danger font-weight-bold"; } document.getElementById("KPISCOM").innerHTML = Math.round($nSCOM/$dl*1000)/10 + "%"; if(Math.round($nSCOM/$dl*100) >=90){ document.getElementById("KPISCOM").className = "badge text-bg-success font-weight-bold"; }else if(Math.round($nSCOM/$dl*100) >=75){ document.getElementById("KPISCOM").className = "badge text-bg-warning font-weight-bold"; }else{ document.getElementById("KPISCOM").className = "badge text-bg-danger font-weight-bold"; } document.getElementById("KPIzabbix").innerHTML = Math.round($nZabbix/$dl*1000)/10 + "%"; if(Math.round($nZabbix/$dl*100) >=90){ document.getElementById("KPIzabbix").className = "badge text-bg-success font-weight-bold"; }else if(Math.round($nZabbix/$dl*100) >=75){ document.getElementById("KPIzabbix").className = "badge text-bg-warning font-weight-bold"; }else{ document.getElementById("KPIzabbix").className = "badge text-bg-danger font-weight-bold"; } document.getElementById("KPIS1").innerHTML = Math.round($nS1/$dl*1000)/10 + "%"; if(Math.round($nS1/$dl*100) >=90){ document.getElementById("KPIS1").className = "badge text-bg-success font-weight-bold"; }else if(Math.round($nS1/$dl*100) >=75){ document.getElementById("KPIS1").className = "badge text-bg-warning font-weight-bold"; }else{ document.getElementById("KPIS1").className = "badge text-bg-danger font-weight-bold"; } document.getElementById("KPIDEVICE").innerHTML = $dl; }) })