Fix list of leave not complete for a manager

This commit is contained in:
Laurent Destailleur 2018-03-21 19:17:42 +01:00
parent a2b9dbfbe3
commit b3bb6d88e6
2 changed files with 120 additions and 119 deletions

View File

@ -50,7 +50,7 @@ class Holiday extends CommonObject
var $date_fin=''; // Date end in PHP server TZ var $date_fin=''; // Date end in PHP server TZ
var $date_debut_gmt=''; // Date start in GMT var $date_debut_gmt=''; // Date start in GMT
var $date_fin_gmt=''; // Date end in GMT var $date_fin_gmt=''; // Date end in GMT
var $halfday=''; var $halfday=''; // 0:Full days, 2:Start afternoon end morning, -1:Start afternoon end afternoon, 1:Start morning end morning
var $statut=''; // 1=draft, 2=validated, 3=approved var $statut=''; // 1=draft, 2=validated, 3=approved
var $fk_validator; var $fk_validator;
var $date_valid=''; var $date_valid='';
@ -276,12 +276,12 @@ class Holiday extends CommonObject
} }
/** /**
* List holidays for a particular user * List holidays for a particular user or list of users
* *
* @param int $user_id ID of user to list * @param int|string $user_id ID of user to list, or comma separated list of IDs of users to list
* @param string $order Sort order * @param string $order Sort order
* @param string $filter SQL Filter * @param string $filter SQL Filter
* @return int -1 if KO, 1 if OK, 2 if no result * @return int -1 if KO, 1 if OK, 2 if no result
*/ */
function fetchByUser($user_id, $order='', $filter='') function fetchByUser($user_id, $order='', $filter='')
{ {
@ -321,8 +321,8 @@ class Holiday extends CommonObject
$sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp, ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua"; $sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp, ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua";
$sql.= " WHERE cp.entity IN (".getEntity('holiday').")"; $sql.= " WHERE cp.entity IN (".getEntity('holiday').")";
$sql.= " AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid "; // Hack pour la recherche sur le tableau $sql.= " AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid"; // Hack pour la recherche sur le tableau
$sql.= " AND cp.fk_user = ".$user_id; $sql.= " AND cp.fk_user IN (".$user_id.")";
// Filtre de séléction // Filtre de séléction
if(!empty($filter)) { if(!empty($filter)) {
@ -553,7 +553,7 @@ class Holiday extends CommonObject
} else { } else {
$error++; $error++;
} }
$sql.= " halfday = ".$this->halfday.","; $sql.= " halfday = ".$this->halfday.",";
if(!empty($this->statut) && is_numeric($this->statut)) { if(!empty($this->statut) && is_numeric($this->statut)) {
$sql.= " statut = ".$this->statut.","; $sql.= " statut = ".$this->statut.",";
} else { } else {
@ -714,10 +714,10 @@ class Holiday extends CommonObject
if ($infos_CP['statut'] == 4) continue; // ignore not validated holidays if ($infos_CP['statut'] == 4) continue; // ignore not validated holidays
if ($infos_CP['statut'] == 5) continue; // ignore not validated holidays if ($infos_CP['statut'] == 5) continue; // ignore not validated holidays
/* /*
var_dump("--"); var_dump("--");
var_dump("old: ".dol_print_date($infos_CP['date_debut'],'dayhour').' '.dol_print_date($infos_CP['date_fin'],'dayhour').' '.$infos_CP['halfday']); var_dump("old: ".dol_print_date($infos_CP['date_debut'],'dayhour').' '.dol_print_date($infos_CP['date_fin'],'dayhour').' '.$infos_CP['halfday']);
var_dump("new: ".dol_print_date($dateStart,'dayhour').' '.dol_print_date($dateEnd,'dayhour').' '.$halfday); var_dump("new: ".dol_print_date($dateStart,'dayhour').' '.dol_print_date($dateEnd,'dayhour').' '.$halfday);
*/ */
if ($halfday == 0) if ($halfday == 0)
{ {
@ -797,7 +797,7 @@ class Holiday extends CommonObject
$sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp"; $sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp";
$sql.= " WHERE cp.entity IN (".getEntity('holiday').")"; $sql.= " WHERE cp.entity IN (".getEntity('holiday').")";
$sql.= " AND cp.fk_user = ".(int) $fk_user; $sql.= " AND cp.fk_user = ".(int) $fk_user;
$sql.= " AND date_debut <= '".$this->db->idate($timestamp)."' AND date_fin >= '".$this->db->idate($timestamp)."'"; $sql.= " AND date_debut <= '".$this->db->idate($timestamp)."' AND date_fin >= '".$this->db->idate($timestamp)."'";
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
@ -837,7 +837,7 @@ class Holiday extends CommonObject
} }
else dol_print_error($this->db); else dol_print_error($this->db);
return array('morning'=>$isavailablemorning, 'afternoon'=>$isavailableafternoon); return array('morning'=>$isavailablemorning, 'afternoon'=>$isavailableafternoon);
} }
@ -860,10 +860,10 @@ class Holiday extends CommonObject
//if ($option != 'nolink') //if ($option != 'nolink')
//{ //{
// Add param to save lastsearch_values or not // Add param to save lastsearch_values or not
$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0); $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1; if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1'; if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
//} //}
$linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
@ -1147,15 +1147,15 @@ class Holiday extends CommonObject
} }
if ($result) if ($result)
{ {
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
else else
{ {
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
} }
return 0; return 0;
@ -1210,7 +1210,7 @@ class Holiday extends CommonObject
return 1; return 1;
} }
else else
{ {
return -1; return -1;
} }
} }
@ -1395,7 +1395,7 @@ class Holiday extends CommonObject
} }
else else
{ {
// We want only list of vacation balance for user ids // We want only list of vacation balance for user ids
$sql = "SELECT DISTINCT cpu.fk_user"; $sql = "SELECT DISTINCT cpu.fk_user";
$sql.= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u"; $sql.= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
$sql.= " WHERE cpu.fk_user = u.user"; $sql.= " WHERE cpu.fk_user = u.user";
@ -1427,7 +1427,7 @@ class Holiday extends CommonObject
return $stringlist; return $stringlist;
} }
else else
{ {
// Erreur SQL // Erreur SQL
$this->error="Error ".$this->db->lasterror(); $this->error="Error ".$this->db->lasterror();
return -1; return -1;
@ -1454,46 +1454,46 @@ class Holiday extends CommonObject
else else
$sql.= " WHERE u.entity IN (0,".$conf->entity.")"; $sql.= " WHERE u.entity IN (0,".$conf->entity.")";
$sql.= " AND u.statut > 0"; $sql.= " AND u.statut > 0";
if ($filters) $sql.=$filters; if ($filters) $sql.=$filters;
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
// Si pas d'erreur SQL // Si pas d'erreur SQL
if ($resql) if ($resql)
{ {
$i = 0; $i = 0;
$tab_result = $this->holiday; $tab_result = $this->holiday;
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
// Boucles du listage des utilisateurs // Boucles du listage des utilisateurs
while($i < $num) { while($i < $num) {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$tab_result[$i]['rowid'] = $obj->rowid; $tab_result[$i]['rowid'] = $obj->rowid;
$tab_result[$i]['name'] = $obj->lastname; // deprecated $tab_result[$i]['name'] = $obj->lastname; // deprecated
$tab_result[$i]['lastname'] = $obj->lastname; $tab_result[$i]['lastname'] = $obj->lastname;
$tab_result[$i]['firstname'] = $obj->firstname; $tab_result[$i]['firstname'] = $obj->firstname;
$tab_result[$i]['gender'] = $obj->gender; $tab_result[$i]['gender'] = $obj->gender;
$tab_result[$i]['status'] = $obj->statut; $tab_result[$i]['status'] = $obj->statut;
$tab_result[$i]['employee'] = $obj->employee; $tab_result[$i]['employee'] = $obj->employee;
$tab_result[$i]['photo'] = $obj->photo; $tab_result[$i]['photo'] = $obj->photo;
$tab_result[$i]['fk_user'] = $obj->fk_user; $tab_result[$i]['fk_user'] = $obj->fk_user;
//$tab_result[$i]['type'] = $obj->type; //$tab_result[$i]['type'] = $obj->type;
//$tab_result[$i]['nb_holiday'] = $obj->nb_holiday; //$tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
$i++; $i++;
}
// Retoune le tableau des utilisateurs
return $tab_result;
}
else
{
// Erreur SQL
$this->errors[]="Error ".$this->db->lasterror();
return -1;
} }
// Retoune le tableau des utilisateurs
return $tab_result;
}
else
{
// Erreur SQL
$this->errors[]="Error ".$this->db->lasterror();
return -1;
}
} }
else else
{ {
@ -1637,32 +1637,32 @@ class Holiday extends CommonObject
$sql.= ")"; $sql.= ")";
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if (! $resql) if (! $resql)
{ {
$error++; $this->errors[]="Error ".$this->db->lasterror(); $error++; $this->errors[]="Error ".$this->db->lasterror();
} }
if (! $error) if (! $error)
{ {
$this->optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday_logs"); $this->optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday_logs");
} }
// Commit or rollback // Commit or rollback
if ($error) if ($error)
{ {
foreach($this->errors as $errmsg) foreach($this->errors as $errmsg)
{ {
dol_syslog(get_class($this)."::addLogCP ".$errmsg, LOG_ERR); dol_syslog(get_class($this)."::addLogCP ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg); $this->error.=($this->error?', '.$errmsg:$errmsg);
} }
$this->db->rollback(); $this->db->rollback();
return -1*$error; return -1*$error;
} }
else else
{ {
$this->db->commit(); $this->db->commit();
return $this->optRowid; return $this->optRowid;
} }
} }
/** /**
@ -1702,43 +1702,43 @@ class Holiday extends CommonObject
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
// Si pas d'erreur SQL // Si pas d'erreur SQL
if ($resql) { if ($resql) {
$i = 0; $i = 0;
$tab_result = $this->logs; $tab_result = $this->logs;
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
// Si pas d'enregistrement // Si pas d'enregistrement
if(!$num) { if(!$num) {
return 2; return 2;
} }
// On liste les résultats et on les ajoutent dans le tableau // On liste les résultats et on les ajoutent dans le tableau
while($i < $num) { while($i < $num) {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$tab_result[$i]['rowid'] = $obj->rowid; $tab_result[$i]['rowid'] = $obj->rowid;
$tab_result[$i]['date_action'] = $obj->date_action; $tab_result[$i]['date_action'] = $obj->date_action;
$tab_result[$i]['fk_user_action'] = $obj->fk_user_action; $tab_result[$i]['fk_user_action'] = $obj->fk_user_action;
$tab_result[$i]['fk_user_update'] = $obj->fk_user_update; $tab_result[$i]['fk_user_update'] = $obj->fk_user_update;
$tab_result[$i]['type_action'] = $obj->type_action; $tab_result[$i]['type_action'] = $obj->type_action;
$tab_result[$i]['prev_solde'] = $obj->prev_solde; $tab_result[$i]['prev_solde'] = $obj->prev_solde;
$tab_result[$i]['new_solde'] = $obj->new_solde; $tab_result[$i]['new_solde'] = $obj->new_solde;
$tab_result[$i]['fk_type'] = $obj->fk_type; $tab_result[$i]['fk_type'] = $obj->fk_type;
$i++; $i++;
} }
// Retourne 1 et ajoute le tableau à la variable // Retourne 1 et ajoute le tableau à la variable
$this->logs = $tab_result; $this->logs = $tab_result;
return 1; return 1;
} }
else else
{ {
// Erreur SQL // Erreur SQL
$this->error="Error ".$this->db->lasterror(); $this->error="Error ".$this->db->lasterror();
return -1; return -1;
} }
} }

View File

@ -48,7 +48,7 @@ $contextpage= GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'myobjectl
$backtopage = GETPOST('backtopage','alpha'); // Go back to a dedicated page $backtopage = GETPOST('backtopage','alpha'); // Go back to a dedicated page
$optioncss = GETPOST('optioncss','aZ'); // Option for the css output (always '' except when 'print') $optioncss = GETPOST('optioncss','aZ'); // Option for the css output (always '' except when 'print')
$childis = $user->getAllChildIds(1); $childids = $user->getAllChildIds(1);
// Security check // Security check
$socid=0; $socid=0;
@ -107,7 +107,6 @@ $fieldstosearchall = array(
'uu.firstname'=>'EmployeeFirstname' 'uu.firstname'=>'EmployeeFirstname'
); );
$childids = $user->getAllChildIds(1);
/* /*
@ -275,14 +274,16 @@ if ($id > 0)
$search_employee = $user_id; $search_employee = $user_id;
} }
// Récupération des congés payés de l'utilisateur ou de tous les users // Récupération des congés payés de l'utilisateur ou de tous les users de sa hierarchy
// Load array $holiday->holiday
if (empty($user->rights->holiday->read_all) || $id > 0) if (empty($user->rights->holiday->read_all) || $id > 0)
{ {
$result = $holiday->fetchByUser($user_id,$order,$filter); // Load array $holiday->holiday if ($id > 0) $result = $holiday->fetchByUser($id, $order, $filter);
else $result = $holiday->fetchByUser(join(',',$childids), $order, $filter);
} }
else else
{ {
$result = $holiday->fetchAll($order,$filter); // Load array $holiday->holiday $result = $holiday->fetchAll($order, $filter);
} }
// Si erreur SQL // Si erreur SQL
if ($result == '-1') if ($result == '-1')