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

451 lines
13 KiB
PHP

<?php
$dbvp = true;
require_once 'MonitoringVMHeader.php';
require_once 'MonitoringDBRequest.php';
$userId = $current_user->get('id');
if(isTopDG($roleid)){$roleid="H10";}
if(isset($_POST['year']))
$year = $_POST['year'];
$result = getResultatBCobjective($year,$roleid ,$userId);
echo getMonitoringMainBarVP(8).
'<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('Objectif par VP 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).getRolesSelectVP().'
</div>';
echo '<table id="tabcenter" class="table table-bordered table-striped" >
<tr class="center borderline">
<th id="role" >Post</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>
</table></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];
var row2 = data[i];
if(row['month'] !== null && row['bc'] !== 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];
if(row['mntobjectif'] != null){
b[row['month']]=parseFloat(((row['bc']/row['mntobjectif'])*100)).toFixed(2);
var title1 = "Objectif à atteindre : "+row['mntobjectif']+" &#13;Montant Total des BC : "+row['bc']+" &#13; ("+row['bc']+"/"+row['mntobjectif']+")*100="+b[row['month']];
b[row['month']] = [b[row['month']],title1];
}else{
b[row['month']]=parseFloat(((row['bc']/row['bc'])*100)).toFixed(2);
var title2 = "Objectif à atteindre : 0 &#13;Montant Total des BC : "+row['bc']+" &#13;("+row['bc']+"/"+row['bc']+")*100="+b[row['month']];var title = "("+row['bc']+"/"+row['bc']+")*100="+b[row['month']];
b[row['month']] = [b[row['month']],title2];
}
setJobRegion(b, row['role']);
c[a.length-1]=b;
} else {
if(row['mntobjectif'] != null){
b[row['month']]=parseFloat(((row['bc']/row['mntobjectif'])*100)).toFixed(2);
var title3 ="Objectif à atteindre : "+row['mntobjectif']+" &#13;Montant Total des BC : "+row['bc']+" &#13;("+row['bc']+"/"+row['mntobjectif']+")*100="+b[row['month']];
b[row['month']] = [b[row['month']],title3];
}else{
b[row['month']]=parseFloat(((row['bc']/row['bc'])*100)).toFixed(2);
var title4 ="Objectif à atteindre : 0 &#13;Montant Total des BC : "+row['bc']+" &#13;("+row['bc']+"/"+row['bc']+")*100="+b[row['month']];
b[row['month']] = [b[row['month']],title4];
}
setJobRegion(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];
setJobRegion(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); ?>;
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][0];
var p2 = row[2][0];
var p3 = row[3][0];
var p4 = row[4][0];
var p5 = row[5][0];
var p6 = row[6][0];
var p7 = row[7][0];
var p8 = row[8][0];
var p9 = row[9][0];
var p10 = row[10][0];
var p11 = row[11][0];
var p12 = row[12][0];
var c1 = "transparent";
if(p1 < 80 && p1 != 0) c1 = "red";
if(p1 < 100 && p1 > 80) c1 = "orange";
if(p1 > 95) c1 = "green";
var c2 = "transparent";
if(p2 < 80 && p2 != 0) c2 = "red";
if(p2 < 100 && p2 > 80) c2 = "orange";
if(p2 > 95) c2 = "green";
var c3 = "transparent";
if(p3 < 80 && p3 != 0) c3 = "red";
if(p3 < 100 && p3 > 80) c3 = "orange";
if(p3 > 95) c3 = "green";
var c4 = "transparent";
if(p4 < 80 && p4 != 0) c4 = "red";
if(p4 < 100 && p4 > 80) c4 = "orange";
if(p4 > 95) c4 = "green";
var c5 = "transparent";
if(p5 < 80 && p5 != 0) c5 = "red";
if(p5 < 100 && p5 > 80) c5 = "orange";
if(p5 > 95) c5 = "green";
var c6 = "transparent";
if(p6 < 80 && p6 != 0) c6 = "red";
if(p6 < 100 && p6 > 80) c6 = "orange";
if(p6 > 95) c6 = "green";
var c7 = "transparent";
if(p7 < 80 && p7 != 0) c7 = "red";
if(p7 < 100 && p7 > 80) c7 = "orange";
if(p7 > 95) c7 = "green";
var c8 = "transparent";
if(p8 < 80 && p8 != 0) c8 = "red";
if(p8 < 100 && p8 > 80) c8 = "orange";
if(p8 > 95) c8 = "green";
var c9 = "transparent";
if(p9 < 80 && p9 != 0) c9 = "red";
if(p9 < 100 && p9 > 80) c9 = "orange";
if(p9 > 95) c9 = "green";
var c10 = "transparent";
if(p10 < 80 && p10 != 0) c10 = "red";
if(p10 < 100 && p10 > 80) c10 = "orange";
if(p10 > 95) c10 = "green";
var c11 = "transparent";
if(p11 < 80 && p11 != 0) c11 = "red";
if(p11 < 100 && p11 > 80) c11 = "orange";
if(p11 > 95) c11 = "green";
var c12 = "transparent";
if(p12 < 80 && p12 != 0) c12 = "red";
if(p12 < 100 && p12 > 80) c12 = "orange";
if(p12 > 95) c12 = "green";
$('#tabcenter').append(
"<tr class='center borderline'"+click+">"
+"<td>"+row[13]+"</td>"
+"<td>"+row[14]+"</td>"
+"<td >"+row[0].trim()+"</td>"
+"<td style='background: "+c1+"' onclick=\"location.href='?module=Objectives&view=Objectives&userId=%22"+row[0]+"%22&month=%221-"+year+"%22'\" title='"+row[1][1]+"'>"+row[1][0]+"%</td>"
+"<td style='background: "+c2+"' onclick=\"location.href='?module=Objectives&view=Objectives&userId=%22"+row[0]+"%22&month=%222-"+year+"%22'\" title='"+row[2][1]+"'>"+row[2][0]+"%</td>"
+"<td style='background: "+c3+"' onclick=\"location.href='?module=Objectives&view=Objectives&userId=%22"+row[0]+"%22&month=%223-"+year+"%22'\" title='"+row[3][1]+"'>"+row[3][0]+"%</td>"
+"<td style='background: "+c4+"' onclick=\"location.href='?module=Objectives&view=Objectives&userId=%22"+row[0]+"%22&month=%224-"+year+"%22'\" title='"+row[4][1]+"'>"+row[4][0]+"%</td>"
+"<td style='background: "+c5+"' onclick=\"location.href='?module=Objectives&view=Objectives&userId=%22"+row[0]+"%22&month=%225-"+year+"%22'\" title='"+row[5][1]+"'>"+row[5][0]+"%</td>"
+"<td style='background: "+c6+"' onclick=\"location.href='?module=Objectives&view=Objectives&userId=%22"+row[0]+"%22&month=%226-"+year+"%22'\" title='"+row[6][1]+"'>"+row[6][0]+"%</td>"
+"<td style='background: "+c7+"' onclick=\"location.href='?module=Objectives&view=Objectives&userId=%22"+row[0]+"%22&month=%227-"+year+"%22'\" title='"+row[7][1]+"'>"+row[7][0]+"%</td>"
+"<td style='background: "+c8+"' onclick=\"location.href='?module=Objectives&view=Objectives&userId=%22"+row[0]+"%22&month=%228-"+year+"%22'\" title='"+row[8][1]+"'>"+row[8][0]+"%</td>"
+"<td style='background: "+c9+"' onclick=\"location.href='?module=Objectives&view=Objectives&userId=%22"+row[0]+"%22&month=%229-"+year+"%22'\" title='"+row[9][1]+"'>"+row[9][0]+"%</td>"
+"<td style='background: "+c10+"' onclick=\"location.href='?module=Objectives&view=Objectives&userId=%22"+row[0]+"%22&month=%2210-"+year+"%22'\" title='"+row[10][1]+"'>"+row[10][0]+"%</td>"
+"<td style='background: "+c11+"' onclick=\"location.href='?module=Objectives&view=Objectives&userId=%22"+row[0]+"%22&month=%2211-"+year+"%22'\" title='"+row[11][1]+"'>"+row[11][0]+"%</td>"
+"<td style='background: "+c12+"' onclick=\"location.href='?module=Objectives&view=Objectives&userId=%22"+row[0]+"%22&month=%2212-"+year+"%22'\" title='"+row[12][1]+"'>"+row[12][0]+"%</td>"
+"<td style=' background:#7f8fa6; color: #ffffff;'>"+(parseFloat((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]))/12).toFixed(2)+"%</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]*1;
}
totals.push(sum);
allTotals += sum;
}
allTotals = (allTotals/data.length);
$('#tabcenter').append(
"<tr class='center borderline'"+click+">"
+"<td>TOTAL</td>"
+"<td></td>"
+"<td ></td>"
+"<td>"+(totals[0]/data.length).toFixed(2)+"%</td>"
+"<td>"+(totals[1]/data.length).toFixed(2)+"%</td>"
+"<td>"+(totals[2]/data.length).toFixed(2)+"%</td>"
+"<td>"+(totals[3]/data.length).toFixed(2)+"%</td>"
+"<td>"+(totals[4]/data.length).toFixed(2)+"%</td>"
+"<td>"+(totals[5]/data.length).toFixed(2)+"%</td>"
+"<td>"+(totals[6]/data.length).toFixed(2)+"%</td>"
+"<td>"+(totals[7]/data.length).toFixed(2)+"%</td>"
+"<td>"+(totals[8]/data.length).toFixed(2)+"%</td>"
+"<td>"+(totals[9]/data.length).toFixed(2)+"%</td>"
+"<td>"+(totals[10]/data.length).toFixed(2)+"%</td>"
+"<td>"+(totals[11]/data.length).toFixed(2)+"%</td>"
+"<td style=' background:#7f8fa6; color: #ffffff; font-weight: bold;'>-</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 COMMERCIAL");
//filtre region
function regionChange(e) {
document.getElementById("role").value = "All";
var arrayFiltre;
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>