Files
CRM/MonitoringVM.php
BACHIR SOULDI 2794e62571 first commit
2025-09-28 08:49:37 +01:00

246 lines
16 KiB
PHP

<?php
require_once 'MonitoringVMHeader.php';
require_once 'MonitoringDBRequest.php';
if(isset($_POST['year'])){
$year = $_POST['year'];
}
$result = getResultatVMVisite($year,$roleid);
$result = checkVM($result,$roleid);
echo getMonitoringMainBar(2,$roleid).getMonitoringVisiteSubBar(1,$roleid).
'<div class="main-container main-container-Accounts">
<div id="scrollbar" style="margin:15px 15px 15px 15px; border:1px solid #ecf0f1; overflow-y: scroll; overflow-x: scroll; height:462.709px ;border:1px solid #bdc3c7;">'.
getTopTextSelect('Nombre de visites crée en', $year).
'<hr>
<div class="form-row">
<div class="form-group col-md-4">
<label for="inputCity">Nom & Prénom</label>
<input class="form-control mb-4 w-20" type="text" name="nomprenom" placeholder="Rechercher" onKeyUp="fullNameChange(this)">
</div>'.getRegionSelectSubmit($roleid, false).getRolesSelect().'
</div>';
echo '<table id="tabcenter" class="table table-bordered table-striped" >
<tr class="center borderline">
<th id="role" >Poste</th>
<th id="region">Region</th>
<th id="fullname" > Nom & Prenom</th>
<th> janvier</th>
<th> février</th>
<th> mars</th>
<th>avril</th>
<th> mai</th>
<th>juin</th>
<th>juillet</th>
<th> août</th>
<th> septembre</th>
<th> octobre</th>
<th>novembre</th>
<th>décembre</th>
<th>Total</th>
</tr>
<tbody id="values"></tbody>
</table>
</div></div>';
$viewer->view('CustomDashboardFooter.tpl');
?>
<script>
function convertArray(data) {
var a=[];
var c=[];
if(data.length > 0) {
for(var i = 0; i < data.length; i++) {
var row = data[i];
if(row['month'] !== null && row['visite'] !== null){
if(a.indexOf(row[0]) == -1){
var b=[0,[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]];
a.push(row[0]);
b[0]=row[0];
b[row['month']]=[parseInt(row['visite']), parseInt(row['visiteheld'])];
setJobRegionVM(b, row['role']);
c[a.length-1]=b;
} else {
b[row['month']]=[parseInt(row['visite']), parseInt(row['visiteheld'])];
setJobRegionVM(b, row['role']);
c[a.length-1]=b;
}
}else{
var b=[0,[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]];
a.push(row[0]);
b[0]=row[0];
setJobRegionVM(b, row['role']);
c[a.length-1]=b;
}
}
}
return c
}
//filtre nom/prenom
function fullNameChange(e) {
document.getElementById("role").value = "All";
document.getElementById("region").value = "All";
var res = result.filter(a => a.fullname.toUpperCase().includes(e.value.toUpperCase()) );
loadTable(convertArray(res));
}
var year = <?php echo json_encode($year); ?>;
var greenlimit = 90;
var yellowmin = 85;
function loadTable(data) {
$('#tabcenter tr').slice(1).remove();
if(data.length > 0) {
for(var i = 0; i < data.length; i++) {
var row = data[i];
var click = "";
var p1 = ((row[1][1]/row[1][0])*100).toFixed(0);
var title1 = "Nombre Total de visite (A eu lieu): "+row[1][1]+"&#13;Nombre Total de visite (A eu lieu/N&#39;a pas eu lieu/Planifié) : "+row[1][0]+"&#13;("+row[1][1]+"*100)/"+row[1][0]+" = "+p1+"%";
if(isNaN(p1)){ p1 = 0; title1 = "";}
var p2 = ((row[2][1]/row[2][0])*100).toFixed(0);
var title2 = "Nombre Total de visite (A eu lieu): "+row[2][1]+"&#13;Nombre Total de visite (A eu lieu/N&#39;a pas eu lieu/Planifié) : "+row[2][0]+"&#13;("+row[2][1]+"*100)/"+row[2][0]+" = "+p2+"%";
if(isNaN(p2)){ p2 = 0;title1 = "";}
var p3 = ((row[3][1]/row[3][0])*100).toFixed(0);
var title3 = "Nombre Total de visite (A eu lieu): "+row[3][1]+"&#13;Nombre Total de visite (A eu lieu/N&#39;a pas eu lieu/Planifié) : "+row[3][0]+"&#13;("+row[3][1]+"*100)/"+row[3][0]+" = "+p3+"%";
if(isNaN(p3)){ p3 = 0;title3 = "";}
var p4 = ((row[4][1]/row[4][0])*100).toFixed(0);
var title4 = "Nombre Total de visite (A eu lieu): "+row[4][1]+"&#13;Nombre Total de visite (A eu lieu/N&#39;a pas eu lieu/Planifié) : "+row[4][0]+"&#13;("+row[4][1]+"*100)/"+row[4][0]+" = "+p4+"%";
if(isNaN(p4)){ p4 = 0;title4 = "";}
var p5 = ((row[5][1]/row[5][0])*100).toFixed(0);
var title5 = "Nombre Total de visite (A eu lieu): "+row[5][1]+"&#13;Nombre Total de visite (A eu lieu/N&#39;a pas eu lieu/Planifié) : "+row[5][0]+"&#13;("+row[5][1]+"*100)/"+row[5][0]+" = "+p5+"%";
if(isNaN(p5)){ p5 = 0; title5 = "";}
var p6 = ((row[6][1]/row[6][0])*100).toFixed(0);
var title6 = "Nombre Total de visite (A eu lieu): "+row[6][1]+"&#13;Nombre Total de visite (A eu lieu/N&#39;a pas eu lieu/Planifié) : "+row[6][0]+"&#13;("+row[6][1]+"*100)/"+row[6][0]+" = "+p6+"%";
if(isNaN(p6)){ p6 = 0; title6 = "";}
var p7 = ((row[7][1]/row[7][0])*100).toFixed(0);
var title7 = "Nombre Total de visite (A eu lieu): "+row[7][1]+"&#13;Nombre Total de visite (A eu lieu/N&#39;a pas eu lieu/Planifié) : "+row[7][0]+"&#13;("+row[7][1]+"*100)/"+row[7][0]+" = "+p7+"%";
if(isNaN(p7)){ p7 = 0; title7 = "";}
var p8 = ((row[8][1]/row[8][0])*100).toFixed(0);
var title8 = "Nombre Total de visite (A eu lieu): "+row[8][1]+"&#13;Nombre Total de visite (A eu lieu/N&#39;a pas eu lieu/Planifié) : "+row[8][0]+"&#13;("+row[8][1]+"*100)/"+row[8][0]+" = "+p8+"%";
if(isNaN(p8)){ p8 = 0; title8 = "";}
var p9 = ((row[9][1]/row[9][0])*100).toFixed(0);
var title9 = "Nombre Total de visite (A eu lieu): "+row[9][1]+"&#13;Nombre Total de visite (A eu lieu/N&#39;a pas eu lieu/Planifié) : "+row[9][0]+"&#13;("+row[9][1]+"*100)/"+row[9][0]+" = "+p9+"%";
if(isNaN(p9)){ p9 = 0; title9 = "";}
var p10 = ((row[10][1]/row[10][0])*100).toFixed(0);
var title10 = "Nombre Total de visite (A eu lieu): "+row[10][1]+"&#13;Nombre Total de visite (A eu lieu/N&#39;a pas eu lieu/Planifié) : "+row[10][0]+"&#13;("+row[10][1]+"*100)/"+row[10][0]+" = "+p10+"%";
if(isNaN(p10)){ p10 = 0; title10 = "";}
var p11 = ((row[11][1]/row[11][0])*100).toFixed(0);
var title11 = "Nombre Total de visite (A eu lieu): "+row[11][1]+"&#13;Nombre Total de visite (A eu lieu/N&#39;a pas eu lieu/Planifié) : "+row[11][0]+"&#13;("+row[11][1]+"*100)/"+row[11][0]+" = "+p11+"%";
if(isNaN(p11)) {p11 = 0; title11 = "";}
var p12 = ((row[12][1]/row[12][0])*100).toFixed(0);
var title12 = "Nombre Total de visite (A eu lieu): "+row[12][1]+"&#13;Nombre Total de visite (A eu lieu/N&#39;a pas eu lieu/Planifié) : "+row[12][0]+"&#13;("+row[12][1]+"*100)/"+row[12][0]+" = "+p12+"%";
if(isNaN(p12)){ p12 = 0; title12 = "";}
var c1 = "transparent";
if(p1 < 80 && p1 != 0) c1 = "red";
if(p1 < 100 && p1 > 80) c1 = "orange";
if(p1 > yellowmin) c1 = "yellow";
if(p1 > greenlimit) c1 = "green";
var c2 = "transparent";
if(p2 < 80 && p2 != 0) c2 = "red";
if(p2 < 100 && p2 > 80) c2 = "orange";
if(p2 > yellowmin) c2 = "yellow";
if(p2 > greenlimit) c2 = "green";
var c3 = "transparent";
if(p3 < 80 && p3 != 0) c3 = "red";
if(p3 < 100 && p3 > 80) c3 = "orange";
if(p3 > yellowmin) c3 = "yellow";
if(p3 > greenlimit) c3 = "green";
var c4 = "transparent";
if(p4 < 80 && p4 != 0) c4 = "red";
if(p4 < 100 && p4 > 80) c4 = "orange";
if(p4 > yellowmin) c4 = "yellow";
if(p4 > greenlimit) c4 = "green";
var c5 = "transparent";
if(p5 < 80 && p5 != 0) c5 = "red";
if(p5 < 100 && p5 > 80) c5 = "orange";
if(p5 > yellowmin) c5 = "yellow";
if(p5 > greenlimit) c5 = "green";
var c6 = "transparent";
if(p6 < 80 && p6 != 0) c6 = "red";
if(p6 < 100 && p6 > 80) c6 = "orange";
if(p6 > yellowmin) c6 = "yellow";
if(p6 > greenlimit) c6 = "green";
var c7 = "transparent";
if(p7 < 80 && p7 != 0) c7 = "red";
if(p7 < 100 && p7 > 80) c7 = "orange";
if(p7 > yellowmin) c7 = "yellow";
if(p7 > greenlimit) c7 = "green";
var c8 = "transparent";
if(p8 < 80 && p8 != 0) c8 = "red";
if(p8 < 100 && p8 > 80) c8 = "orange";
if(p8 > yellowmin) c8 = "yellow";
if(p8 > greenlimit) c8 = "green";
var c9 = "transparent";
if(p9 < 80 && p9 != 0) c93 = "red";
if(p9 < 100 && p9 > 80) c9 = "orange";
if(p9 > yellowmin) c9 = "yellow";
if(p9 > greenlimit) c9 = "green";
var c10 = "transparent";
if(p10 < 80 && p10 != 0) c10 = "red";
if(p10 < 100 && p10 > 80) c10 = "orange";
if(p10 > yellowmin) c10 = "yellow";
if(p10 > greenlimit) c10 = "green";
var c11 = "transparent";
if(p11 < 80 && p11 != 0) c11 = "red";
if(p11 < 100 && p11 > 80) c11 = "orange";
if(p11 > yellowmin) c11 = "yellow";
if(p11 > greenlimit) c11 = "green";
var c12 = "transparent";
if(p12 < 80 && p12 != 0) c12 = "red";
if(p12 < 100 && p12 > 80) c12 = "orange";
if(p12 > yellowmin) c12 = "yellow";
if(p12 > greenlimit) c12 = "green";
$('#tabcenter').append(
"<tr class='center borderline'"+click+">"
+"<td>"+row[13]+"</td>"
+"<td>"+row[14]+"</td>"
+"<td >"+row[0].trim()+"</td>"
+"<td title='"+title1+"' style='background: "+c1+"' onclick=\"location.href='?module=Calendar&view=List&search_params=[[[%22assigned_user_id%22,%22c%22,%22"+row[0]+"%22],[%22date_start%22,%22bw%22,%2201-01-"+year+",31-01-"+year+"%22]]]'\">"+row[1][0]+"<br>"+p1+"%</td>"
+"<td title='"+title2+"' style='background: "+c2+"' onclick=\"location.href='?module=Calendar&view=List&search_params=[[[%22assigned_user_id%22,%22c%22,%22"+row[0]+"%22],[%22date_start%22,%22bw%22,%2201-02-"+year+",29-02-"+year+"%22]]]'\">"+row[2][0]+"<br>"+p2+"%</td>"
+"<td title='"+title3+"' style='background: "+c3+"' onclick=\"location.href='?module=Calendar&view=List&search_params=[[[%22assigned_user_id%22,%22c%22,%22"+row[0]+"%22],[%22date_start%22,%22bw%22,%2201-03-"+year+",31-03-"+year+"%22]]]'\">"+row[3][0]+"<br>"+p3+"%</td>"
+"<td title='"+title4+"' style='background: "+c4+"' onclick=\"location.href='?module=Calendar&view=List&search_params=[[[%22assigned_user_id%22,%22c%22,%22"+row[0]+"%22],[%22date_start%22,%22bw%22,%2201-04-"+year+",30-04-"+year+"%22]]]'\">"+row[4][0]+"<br>"+p4+"%</td>"
+"<td title='"+title5+"' style='background: "+c5+"' onclick=\"location.href='?module=Calendar&view=List&search_params=[[[%22assigned_user_id%22,%22c%22,%22"+row[0]+"%22],[%22date_start%22,%22bw%22,%2201-05-"+year+",31-05-"+year+"%22]]]'\">"+row[5][0]+"<br>"+p5+"%</td>"
+"<td title='"+title6+"' style='background: "+c6+"' onclick=\"location.href='?module=Calendar&view=List&search_params=[[[%22assigned_user_id%22,%22c%22,%22"+row[0]+"%22],[%22date_start%22,%22bw%22,%2201-06-"+year+",30-06-"+year+"%22]]]'\">"+row[6][0]+"<br>"+p6+"%</td>"
+"<td title='"+title7+"' style='background: "+c7+"' onclick=\"location.href='?module=Calendar&view=List&search_params=[[[%22assigned_user_id%22,%22c%22,%22"+row[0]+"%22],[%22date_start%22,%22bw%22,%2201-07-"+year+",31-07-"+year+"%22]]]'\">"+row[7][0]+"<br>"+p7+"%</td>"
+"<td title='"+title8+"' style='background: "+c8+"' onclick=\"location.href='?module=Calendar&view=List&search_params=[[[%22assigned_user_id%22,%22c%22,%22"+row[0]+"%22],[%22date_start%22,%22bw%22,%2201-08-"+year+",31-08-"+year+"%22]]]'\">"+row[8][0]+"<br>"+p8+"%</td>"
+"<td title='"+title9+"' style='background: "+c9+"' onclick=\"location.href='?module=Calendar&view=List&search_params=[[[%22assigned_user_id%22,%22c%22,%22"+row[0]+"%22],[%22date_start%22,%22bw%22,%2201-09-"+year+",30-09-"+year+"%22]]]'\">"+row[9][0]+"<br>"+p9+"%</td>"
+"<td title='"+title10+"' style='background: "+c10+"' onclick=\"location.href='?module=Calendar&view=List&search_params=[[[%22assigned_user_id%22,%22c%22,%22"+row[0]+"%22],[%22date_start%22,%22bw%22,%2201-10-"+year+",31-10-"+year+"%22]]]'\">"+row[10][0]+"<br>"+p10+"%</td>"
+"<td title='"+title11+"' style='background: "+c11+"' onclick=\"location.href='?module=Calendar&view=List&search_params=[[[%22assigned_user_id%22,%22c%22,%22"+row[0]+"%22],[%22date_start%22,%22bw%22,%2201-11-"+year+",30-11-"+year+"%22]]]'\">"+row[11][0]+"<br>"+p11+"%</td>"
+"<td title='"+title12+"' style='background: "+c12+"' onclick=\"location.href='?module=Calendar&view=List&search_params=[[[%22assigned_user_id%22,%22c%22,%22"+row[0]+"%22],[%22date_start%22,%22bw%22,%2201-12-"+year+",31-12-"+year+"%22]]]'\">"+row[12][0]+"<br>"+p12+"%</td>"
+"<td style=' background:#7f8fa6; color: #ffffff;'>"+(row[1][0]+row[2][0]+row[3][0]+row[4][0]+row[5][0]+row[6][0]+row[7][0]+row[8][0]+row[9][0]+row[10][0]+row[11][0]+row[12][0])+"</td>"
+"</tr>"
);
}
var totals = [];
var allTotals = 0;
for (var i = 1; i < 13; i++) {
var sum = 0;
for(var j = 0; j < data.length; j++) {
var row = data[j];
sum += row[i][0];
}
totals.push(sum);
allTotals += sum;
}
allTotals = parseInt(allTotals);
$('#tabcenter').append(
"<tr class='center borderline'"+click+">"
+"<td>TOTAL</td>"
+"<td></td>"
+"<td ></td>"
+"<td>"+totals[0]+"</td>"
+"<td>"+totals[1]+"</td>"
+"<td>"+totals[2]+"</td>"
+"<td>"+totals[3]+"</td>"
+"<td>"+totals[4]+"</td>"
+"<td>"+totals[5]+"</td>"
+"<td>"+totals[6]+"</td>"
+"<td>"+totals[7]+"</td>"
+"<td>"+totals[8]+"</td>"
+"<td>"+totals[9]+"</td>"
+"<td>"+totals[10]+"</td>"
+"<td>"+totals[11]+"</td>"
+"<td style=' background:#7f8fa6; color: #ffffff; font-weight: bold;'>"+allTotals+"</td>"
+"</tr>"
);
}
}
var result = <?php echo json_encode($result); ?>;
function loadByFullName() {
var fullnames = Array.prototype.slice.call(result).sort(function(a, b){
if(a.fullname < b.fullname) { return -1; }
if(a.fullname > b.fullname) { return 1; }
return 0;
});
loadTable(convertArray(fullnames));
}
roleChange("DELEGUE MEDICAL");
//filtre region
function regionChange(e) {
document.getElementById("role").value = "All";
var arrayFiltre=convertArray(result);
var filteredValue = arrayFiltre.filter(function (item) {
return item[14] === e ;
});
if(e== "All"){filteredValue=arrayFiltre;}
loadTable(filteredValue);
}
//filtre Role
function roleChange(e) {
if(document.getElementById("region").options.length > 1)
document.getElementById("region").value = "All";
var arrayFiltre=convertArray(result);
var filteredValue = arrayFiltre.filter(function (item) {
return item[13] === e ;
});
if(e== "All"){filteredValue=arrayFiltre;}
loadTable(filteredValue);
}
</script>
</body>
</html>