diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index 0e917fb11f1..dc9adcd7725 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -849,25 +849,49 @@ class Holiday extends CommonObject * Return value of a conf parameterfor leave module * TODO Move this into llx_const table * - * @param string $name name of parameter - * @return string value of parameter + * @param string $name Name of parameter + * @param string $createifnotfound 'stringvalue'=Create entry with string value if not found. For example 'YYYYMMDDHHMMSS'. + * @return string Value of parameter. Example: 'YYYYMMDDHHMMSS' or < 0 if error */ - function getConfCP($name) + function getConfCP($name, $createifnotfound='') { $sql = "SELECT value"; $sql.= " FROM ".MAIN_DB_PREFIX."holiday_config"; $sql.= " WHERE name = '".$name."'"; - dol_syslog(get_class($this).'::getConfCP name='.$name.'', LOG_DEBUG); + dol_syslog(get_class($this).'::getConfCP name='.$name.' createifnotfound='.$createifnotfound, LOG_DEBUG); $result = $this->db->query($sql); - // Si pas d'erreur if($result) { - $objet = $this->db->fetch_object($result); - // Retourne la valeur - return $objet->value; - + $obj = $this->db->fetch_object($result); + // Return value + if (empty($obj)) + { + if ($createifnotfound) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_config(name, value)"; + $sql.= " VALUES('".$name."', '".$createifnotfound."')"; + $result = $this->db->query($sql); + if ($result) + { + return $createifnotfound; + } + else + { + $this->error=$this->db->lasterror(); + return -2; + } + } + else + { + return ''; + } + } + else + { + return $obj->value; + } } else { // Erreur SQL @@ -896,26 +920,24 @@ class Holiday extends CommonObject $now=dol_now(); $month = date('m',$now); - + $newdateforlastupdate = dol_print_date($now, '%Y%m%d%H%M%S'); + // Get month of last update - $lastUpdate = $this->getConfCP('lastUpdate'); + $lastUpdate = $this->getConfCP('lastUpdate', $newdateforlastupdate); $monthLastUpdate = $lastUpdate[4].$lastUpdate[5]; - //print 'month: '.$month.' '.$lastUpdate.' '.$monthLastUpdate;exit; + //print 'month: '.$month.' lastUpdate:'.$lastUpdate.' monthLastUpdate:'.$monthLastUpdate;exit; // Si la date du mois n'est pas la même que celle sauvegardée, on met à jour le timestamp if ($month != $monthLastUpdate) { - dol_syslog("A new moth was detected (month=".$month.", monthLastUpdate=".$monthLastUpdate.". We update leave balance."); - $this->db->begin(); $users = $this->fetchUsers(false,false); $nbUser = count($users); $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET"; - $sql.= " value = '".dol_print_date($now,'%Y%m%d%H%M%S')."'"; + $sql.= " value = '".$newdateforlastupdate."'"; $sql.= " WHERE name = 'lastUpdate'"; - $result = $this->db->query($sql); $typeleaves=$this->getTypes(1,1); diff --git a/htdocs/hrm/index.php b/htdocs/hrm/index.php index 504cb4263e2..30d0c911ba1 100644 --- a/htdocs/hrm/index.php +++ b/htdocs/hrm/index.php @@ -62,6 +62,12 @@ if ($user->societe_id > 0) accessforbidden(); $holiday = new Holiday($db); $holidaystatic=new Holiday($db); +// Update sold +if (! empty($conf->holiday->enabled)) +{ + $result = $holiday->updateBalance(); +} + $childids = $user->getAllChildIds(); $childids[]=$user->id; @@ -145,8 +151,7 @@ $langs->load("boxes"); // Last leave requests if (! empty($conf->holiday->enabled) && $user->rights->holiday->read) { - $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.photo, u.statut,"; - $sql.= " x.rowid, x.rowid as ref, x.fk_type, x.date_debut as date_start, x.date_fin as date_end, x.halfday, x.tms as dm, x.statut as status"; + $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.photo, u.statut, x.rowid, x.rowid as ref, x.fk_type, x.date_debut as date_start, x.date_fin as date_end, x.halfday, x.tms as dm, x.statut as status"; $sql.= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u"; $sql.= " WHERE u.rowid = x.fk_user"; $sql.= " AND x.entity = ".$conf->entity; @@ -183,25 +188,23 @@ if (! empty($conf->holiday->enabled) && $user->rights->holiday->read) while ($i < $num && $i < $max) { $obj = $db->fetch_object($result); - $holidaystatic->id=$obj->rowid; $holidaystatic->ref=$obj->ref; - $userstatic->id=$obj->uid; $userstatic->lastname=$obj->lastname; $userstatic->firstname=$obj->firstname; $userstatic->login=$obj->login; $userstatic->photo=$obj->photo; $userstatic->statut=$obj->statut; - - $starthalfday=($obj->halfday == -1 || $obj->halfday == 2)?'afternoon':'morning'; - $endhalfday=($obj->halfday == 1 || $obj->halfday == 2)?'morning':'afternoon'; - print '