Skip to content

Commit

Permalink
Merge pull request #11572 from atm-maxime/fix_holiday_update_solde
Browse files Browse the repository at this point in the history
Fix holiday counter auto update
  • Loading branch information
eldy committed Jul 30, 2019
2 parents 24695a9 + ea92ba2 commit 9e622fe
Showing 1 changed file with 21 additions and 36 deletions.
57 changes: 21 additions & 36 deletions htdocs/holiday/class/holiday.class.php
Expand Up @@ -1132,45 +1132,30 @@ function updateSoldeCP($userID='',$nbHoliday='', $fk_type='')
$result = $this->db->query($sql);

$typeleaves=$this->getTypes(1,1);
foreach($typeleaves as $key => $val)
{
// On ajoute x jours à chaque utilisateurs
$nb_holiday = $val['newByMonth'];
if (empty($nb_holiday)) $nb_holiday=0;

if ($nb_holiday > 0)
{
dol_syslog("We update leavefor everybody for type ".$key, LOG_DEBUG);
// Update each user counter
foreach ($users as $userCounter) {
$nbDaysToAdd = $typeleaves[$userCounter['type']]['newByMonth'];
if(empty($nbDaysToAdd)) continue;

$i = 0;
while ($i < $nbUser)
{
$now_holiday = $this->getCPforUser($users[$i]['rowid'], $val['rowid']);
$new_solde = $now_holiday + $nb_holiday;
dol_syslog("We update leave type id ".$userCounter['type']." for user id ".$userCounter['rowid'], LOG_DEBUG);

// We add a log for each user
$this->addLogCP($user->id, $users[$i]['rowid'], $langs->trans('HolidaysMonthlyUpdate'), $new_solde, $val['rowid']);
$nowHoliday = $userCounter['nb_holiday'];
$newSolde = $nowHoliday + $nbDaysToAdd;

$i++;
}
// We add a log for each user
$this->addLogCP($user->id, $userCounter['rowid'], $langs->trans('HolidaysMonthlyUpdate'), $newSolde, $userCounter['type']);

// Now we update counter for all users at once
$sql2 = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
$sql2.= " nb_holiday = nb_holiday + ".$nb_holiday;
$sql2.= " WHERE fk_type = ".$val['rowid'];
$result = $this->updateSoldeCP($userCounter['rowid'], $newSolde, $userCounter['type'], $langs->trans('HolidaysMonthlyUpdate'));

$result= $this->db->query($sql2);

if (! $result)
{
dol_print_error($this->db);
break;
}
if ($result < 0)
{
$error++;
break;
}
else dol_syslog("No change for leave of type ".$key, LOG_DEBUG);
}

if ($result)
if (! $error)
{
$this->db->commit();
return 1;
Expand Down Expand Up @@ -1495,15 +1480,15 @@ function fetchUsers($stringlist=true, $type=true, $filters='')

$obj = $this->db->fetch_object($resql);

$tab_result[$i]['rowid'] = $obj->rowid;
$tab_result[$i]['rowid'] = $obj->rowid; // rowid of user
$tab_result[$i]['name'] = $obj->lastname; // deprecated
$tab_result[$i]['lastname'] = $obj->lastname;
$tab_result[$i]['firstname'] = $obj->firstname;
$tab_result[$i]['gender'] = $obj->gender;
$tab_result[$i]['status'] = $obj->statut;
$tab_result[$i]['employee'] = $obj->employee;
$tab_result[$i]['photo'] = $obj->photo;
$tab_result[$i]['fk_user'] = $obj->fk_user;
$tab_result[$i]['fk_user'] = $obj->fk_user; // rowid of manager
//$tab_result[$i]['type'] = $obj->type;
//$tab_result[$i]['nb_holiday'] = $obj->nb_holiday;

Expand All @@ -1522,7 +1507,7 @@ function fetchUsers($stringlist=true, $type=true, $filters='')
else
{
// List of vacation balance users
$sql = "SELECT cpu.fk_user, cpu.fk_type, cpu.nb_holiday, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
$sql = "SELECT cpu.fk_user as rowid, cpu.fk_type, cpu.nb_holiday, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
$sql.= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
$sql.= " WHERE cpu.fk_user = u.rowid";
if ($filters) $sql.=$filters;
Expand All @@ -1541,17 +1526,17 @@ function fetchUsers($stringlist=true, $type=true, $filters='')
{
$obj = $this->db->fetch_object($resql);

$tab_result[$i]['rowid'] = $obj->fk_user;
$tab_result[$i]['rowid'] = $obj->rowid; // rowid of user
$tab_result[$i]['name'] = $obj->lastname; // deprecated
$tab_result[$i]['lastname'] = $obj->lastname;
$tab_result[$i]['firstname'] = $obj->firstname;
$tab_result[$i]['gender'] = $obj->gender;
$tab_result[$i]['status'] = $obj->statut;
$tab_result[$i]['employee'] = $obj->employee;
$tab_result[$i]['photo'] = $obj->photo;
$tab_result[$i]['fk_user'] = $obj->fk_user;
$tab_result[$i]['fk_user'] = $obj->fk_user; // rowid of manager

$tab_result[$i]['type'] = $obj->type;
$tab_result[$i]['type'] = $obj->fk_type;
$tab_result[$i]['nb_holiday'] = $obj->nb_holiday;

$i++;
Expand Down

0 comments on commit 9e622fe

Please sign in to comment.