324 lines
13 KiB
PHP
324 lines
13 KiB
PHP
<?php
|
||
use Glpi\Event;
|
||
include ('../inc/includes.php');
|
||
Session::checkLoginUser();
|
||
require_once '../functionsophalglpi.php';
|
||
$root = $CFG_GLPI["root_doc"];
|
||
$res = callWebService('','get_sanctions_year');
|
||
|
||
|
||
//supprimer UTF-8-BOM
|
||
for ($i = 0; $i <= 31; ++$i) {
|
||
$res = str_replace(chr($i), "", $res);
|
||
}
|
||
$res = str_replace(chr(127), "", $res);
|
||
if (0 === strpos(bin2hex($res), 'efbbbf')) {
|
||
$res = substr($res, 3);
|
||
}
|
||
//supprimer UTF-8-BOM
|
||
$res = json_decode($res,true);
|
||
|
||
// echo "<pre>";
|
||
// echo json_encode( $res);
|
||
// echo "</pre>";
|
||
// die();
|
||
|
||
if(is_null($res)){
|
||
$res['sanctions']=[];
|
||
$res['absences']=[];
|
||
$res['period_essai']=[];
|
||
echo "<div style='border: 1px solid;margin: 10px 0px;padding: 15px 10px 15px 50px;background-repeat: no-repeat;background-position: 10px center;color: #D8000C;background-color: #FFBABA;background-image:url('https://i.imgur.com/GnyDvKN.png');'>Le score RH n`est pas à jour (Impossible de se connecter au serveur)</div>";
|
||
}
|
||
echo '<style>
|
||
.loader {
|
||
border: 8px solid #f3f3f3; /* Light grey */
|
||
border-top: 8px solid #3498db; /* Blue */
|
||
border-radius: 50%;
|
||
width: 40px;
|
||
height: 40px;
|
||
display:inline-block;
|
||
animation: spin 1s linear infinite;
|
||
}
|
||
@keyframes spin {
|
||
0% { transform: rotate(0deg); }
|
||
100% { transform: rotate(360deg); }
|
||
}
|
||
</style>';
|
||
if (Session::getCurrentInterface() == "helpdesk") {
|
||
Html::helpHeader("DRH", '', $_SESSION["glpiname"]);
|
||
} else {
|
||
Html::header("DRH", '', "", "");
|
||
}
|
||
$users = getUsers();
|
||
echo "<div class='center'>
|
||
<h2 class='fieldBlockHeader'> Scores Des Employees</h2>
|
||
<div><label><h3>Annee</h3></label>
|
||
<select id='year' name='Year' onchange='reloadData();'>";
|
||
echo '<option value="2021">2021</option>
|
||
<option value="2022">2022</option>;
|
||
<option value="2023" >2023</option>
|
||
<option value="2024" selected>2024</option>';
|
||
echo "</select></div>
|
||
</div><br>
|
||
<div class='center' id='buttonBlock'>
|
||
<a class='vsubmit' onclick='calculate_scores();' title='Scores'>Recalculer Les Scores</a>
|
||
</div>
|
||
<div class='center' id='loadingBlock' style='display:none;'>
|
||
<h2>Veuillez patienter pendant le calcul des scores</h2>
|
||
<div class='loader'></div>
|
||
</div>
|
||
<div class='center'> <H3 id='nbLigneResultat'>" . sizeof($users) . " Employe(s)</H3>
|
||
<div>
|
||
<button onclick='ExportToExcel(\"xlsx\")'>
|
||
Exporter Les Scores</button>
|
||
</div>
|
||
<table id='tabcenter' border='0' class='tab_cadrehov js-dynamitable'>";
|
||
echo "<thead>
|
||
<tr class='tab_bg_2'>";
|
||
echo "<th>Matricule</th>";
|
||
echo "<th>Employee</th>";
|
||
echo "<th>Fonction</th>";
|
||
echo "<th>Structure</th>";
|
||
echo "<th>Responsable Direct</th>";
|
||
echo "<th>Score Performance (Max=70%)</th>";
|
||
echo "<th>Score RH (Max=30%)</th>";
|
||
echo "<th>Score Finale (Max=100%)</th>";
|
||
echo "<th>Sanction/ période d’essai</th>";
|
||
echo "<th>Evaluation</th>";
|
||
echo " </tr>";
|
||
echo "<tr class='tab_bg_2'>";
|
||
echo "<th><input class='form-control center' type='text' name='matricule' placeholder='Matricule' onchange='matriculeChange(this)'></th>";
|
||
echo "<th><input class='form-control center' type='text' name='employee' placeholder='Employee' onchange='employeeChange(this)'></th>";
|
||
echo "<th><input class='form-control center' type='text' name='fonction' placeholder='Fonction' onchange='fonctionChange(this)'></th>";
|
||
echo "<th><input class='form-control center' type='text' name='structure' placeholder='Structure' onchange='structurechange(this)'></th>";
|
||
echo "<th><input class='form-control center' type='text' name='responsable' placeholder='Responsable Direct' onchange='responsableChange(this)'></th>";
|
||
echo "<th><input type='checkbox' id='evalno' name='evalno' value='exist' onchange='evalnochecked(this)'><label for='evalno'> Non effectuées</label></th>";
|
||
echo "<th></th>";
|
||
echo "<th></th>";
|
||
echo "<th></th>";
|
||
echo "<th></th>";
|
||
echo "</tr>";
|
||
echo "</thead> <tbody>";
|
||
?>
|
||
<script type="text/javascript" src="https://unpkg.com/xlsx@0.15.1/dist/xlsx.full.min.js"></script>
|
||
<script>
|
||
var users = <?php echo json_encode($users); ?>;
|
||
var res = <?php echo json_encode($res); ?>;
|
||
var root = <?php echo json_encode($root); ?>;
|
||
console.log("********************************");
|
||
console.log(res);
|
||
$(document).ready(function() {
|
||
$("#c_ssmenu2").html('<ul>' +
|
||
'<li class="breadcrumb_item"><a href="central.php" title="Accueil">Accueil</a></li>' +
|
||
'<li class="breadcrumb_item"><a href="" title="">Ressources Humaines</a></li>' +
|
||
'<li class="breadcrumb_item"><a href="drh.score.employees.php" class="here" title="Scores"><i class="far fa-sticky-note"></i> Scores</a></li>' +
|
||
'</ul>');
|
||
$("tr:odd").css({
|
||
"background-color":"#f2f2f2"});
|
||
for(i in users){
|
||
users[i]['perf_score'] = '';
|
||
users[i]['rh_score'] = '';
|
||
users[i]['final_score'] = '';
|
||
users[i]['id_rfe'] = '';
|
||
users[i]['excluded'] = false;
|
||
}
|
||
loadData();
|
||
get_scores();
|
||
});
|
||
function loadData(){
|
||
let sanctions = res['sanctions'];
|
||
let absences = res['absences'];
|
||
let periodEssai = res['period_essai'];
|
||
let users_abs = [];
|
||
let users_sanctions = [];
|
||
let excluded_users = {};
|
||
// for(i = 0; i < periodEssai.length; i++){
|
||
// excluded_users[periodEssai[i]['Matricule'].trim()] = 'Période d’essai';
|
||
// }
|
||
for(var i = 0; i < absences.length; i++) {
|
||
let abs = parseFloat(absences[i]['absence']);
|
||
let abs_score = 50;
|
||
let base_unit = 1;
|
||
if(abs >= base_unit && abs < (5*base_unit))
|
||
abs_score = 40;
|
||
if(abs >= (5*base_unit) && abs < (10*base_unit))
|
||
abs_score = 30;
|
||
if(abs >= (10*base_unit))
|
||
abs_score = 0;
|
||
// const rmv_usrs= ['0111','0884','0983','1115','1168','1179','1309','1424','1540','1575','1631','1791','1905','1986','2036','2053','2186','2272','2341','2444','2511','2601','2689','2735']
|
||
// if(!rmv_usrs.includes(absences[i]['Matricule'].trim()))
|
||
users_abs[absences[i]['Matricule'].trim()] = abs_score;
|
||
}
|
||
for(var i = 0; i < sanctions.length; i++) {
|
||
let nbr_jr_sanc = parseFloat(sanctions[i]['NbrJour']);
|
||
if(nbr_jr_sanc > 12){
|
||
excluded_users[sanctions[i]['Matricule'].trim()] = 'Sanction';
|
||
}else{
|
||
if(nbr_jr_sanc == 0)
|
||
users_sanctions[sanctions[i]['Matricule'].trim()]= 50;
|
||
if(nbr_jr_sanc >= 1 && nbr_jr_sanc < 6)
|
||
users_sanctions[sanctions[i]['Matricule'].trim()]= 40;
|
||
if(nbr_jr_sanc >= 6 && nbr_jr_sanc <= 12)
|
||
users_sanctions[sanctions[i]['Matricule'].trim()]= 30;
|
||
}
|
||
}
|
||
console.log("users_sanctions",users_sanctions);
|
||
console.log("excluded_users",excluded_users);
|
||
|
||
// excluded_users['2594'] = 'Sanction';
|
||
for(var i = 0; i < users.length; i++) {
|
||
if(excluded_users[users[i]['matricule']] !== undefined){
|
||
users[i]['excluded'] = true;
|
||
users[i]['exclusion_reason'] = excluded_users[users[i]['matricule']];
|
||
}else{
|
||
let tmp_rh_score = 0;
|
||
if (users_abs[users[i]['matricule']] !== undefined)
|
||
tmp_rh_score += users_abs[users[i]['matricule']];
|
||
else
|
||
tmp_rh_score += 50;
|
||
if (users_sanctions[users[i]['matricule']] !== undefined)
|
||
tmp_rh_score += users_sanctions[users[i]['matricule']];
|
||
else
|
||
tmp_rh_score += 50;
|
||
users[i]['rh_score'] = tmp_rh_score;
|
||
}
|
||
}
|
||
console.log("users*********************",users);
|
||
|
||
loadtable(users);
|
||
}
|
||
|
||
function evalnochecked(e) {
|
||
var res = users;
|
||
if(e.checked)
|
||
var res = users.filter(a => a["perf_score"] == '');
|
||
loadtable(res);
|
||
}
|
||
function loadtable(resultsp) {
|
||
$('#tabcenter tr').slice(2).remove();
|
||
if (resultsp.length > 0) {
|
||
for (var i = 0; i < resultsp.length; i++) {
|
||
var row = resultsp[i];
|
||
var warning = '';
|
||
var refrence = '';
|
||
var fonction = row["fonction"] ? row["fonction"] : '';
|
||
var structure = row['structure'] ? row['structure'] : '';
|
||
var matricle = row['matricule'] ? row['matricule'] : '';
|
||
var final_score = 0;
|
||
var perf_score = '';
|
||
if(row['perf_score']!=''){
|
||
perf_score = Math.round((parseFloat(row['perf_score'])*70)/100,2);
|
||
final_score += perf_score ;
|
||
perf_score += "%";
|
||
}
|
||
var rh_score = '';
|
||
if(row['rh_score']!=''){
|
||
rh_score = Math.round((parseFloat(row['rh_score'])*30)/100,2);
|
||
final_score += rh_score;
|
||
rh_score += "%";
|
||
}
|
||
if(final_score==0){
|
||
final_score = "";
|
||
}else{
|
||
final_score += "%";
|
||
}
|
||
if (row['excluded']){
|
||
// perf_score = '0%';
|
||
rh_score = '0%';
|
||
final_score = '0%';
|
||
warning = row['exclusion_reason'] //"<img src='" + root + "/pics/warning.png' alt=''>"
|
||
}
|
||
if (row['id_rfe']!=''){
|
||
refrence = "<span class='fa fa-file pointer' title='Evaluation' onclick='openTab("+row['id_rfe']+")'></span>"
|
||
}
|
||
if (matricle == null){
|
||
matricle = '';
|
||
}
|
||
$('#tabcenter').append(
|
||
"<tr style='height:50px;background-color:#e3e3e3;'>" +
|
||
"<td>" + matricle + "</td>" +
|
||
"<td>" + row["fullname"].trim() + "</td>" +
|
||
"<td>" + fonction + "</td>" +
|
||
"<td>" + structure + "</td>" +
|
||
"<td>" + row["superiorname"] + "</td>" +
|
||
"<td id = '"+row["id"]+"_perf'>"+perf_score+"</td>" +
|
||
"<td id = '"+row["id"]+"_rh'>"+rh_score+"</td>" +
|
||
"<td id = '"+row["id"]+"_final'>"+final_score+"</td>" +
|
||
"<td>"+warning+"</td>" +
|
||
"<td>"+refrence+"</td>" +
|
||
"</tr>"
|
||
);
|
||
}
|
||
document.getElementById("nbLigneResultat").innerHTML = resultsp.length + " Employe(s)";
|
||
}
|
||
$("tr:odd").css({
|
||
"background-color":"#f2f2f2"});
|
||
}
|
||
function openTab(id){
|
||
window.open(root+'/front/fiche.resultat.evaluation.edit.php?idrfe='+id, '_blank');
|
||
}
|
||
function reloadData(){
|
||
for(i in users){
|
||
users[i]['perf_score'] = '';
|
||
users[i]['rh_score'] = '';
|
||
users[i]['final_score'] = '';
|
||
users[i]['id_rfe'] = '';
|
||
users[i]['excluded'] = false;
|
||
}
|
||
loadData();
|
||
get_scores();
|
||
}
|
||
function calculate_scores(){
|
||
$('#buttonBlock').hide();
|
||
$('#loadingBlock').show();
|
||
$.ajax({
|
||
type: "GET",
|
||
url: "fiche.resultat.evaluation.score.php"
|
||
})
|
||
.done(function( msg ) {
|
||
console.log("**********************************",msg);
|
||
$('#buttonBlock').show();
|
||
$('#loadingBlock').hide();
|
||
})
|
||
.fail(function(msg) {
|
||
console.log("fail");
|
||
$('#buttonBlock').show();
|
||
$('#loadingBlock').hide();
|
||
});
|
||
}
|
||
function ExportToExcel(type, fn, dl) {
|
||
var elt = document.getElementById('tabcenter');
|
||
var wb = XLSX.utils.table_to_book(elt, { sheet: "DATA" });
|
||
return dl ?
|
||
XLSX.write(wb, { bookType: type, bookSST: true, type: 'base64' }):
|
||
XLSX.writeFile(wb, fn || ('Scores_eval_'+Date.now()+'.' + (type || 'xlsx')));
|
||
}
|
||
function get_scores(){
|
||
$('#buttonBlock').hide();
|
||
$('#loadingBlock').show();
|
||
$.ajax({
|
||
type: "GET",
|
||
url: root+"/ajax/drh.score.employees.php?action=get_utilisateur_scores&year="+$("#year").val()
|
||
})
|
||
.done(function( msg ) {
|
||
var scores = jQuery.parseJSON(msg);
|
||
for(i in users){
|
||
if (scores[users[i]['id']] !== undefined){
|
||
users[i]['perf_score'] = parseFloat(scores[users[i]['id']][0])*10;
|
||
users[i]['id_rfe'] = scores[users[i]['id']][1]
|
||
}
|
||
}
|
||
console.log("************msg***********");
|
||
console.log(root+"/ajax/drh.score.employees.php?action=get_utilisateur_scores&year="+$("#year").val());
|
||
console.log("************msg***********");
|
||
loadtable(users);
|
||
$('#buttonBlock').show();
|
||
$('#loadingBlock').hide();
|
||
})
|
||
.fail(function(msg) {
|
||
console.log("fail");
|
||
$('#buttonBlock').show();
|
||
$('#loadingBlock').hide();
|
||
});
|
||
}
|
||
</script>
|