From 044feab00fd887d226e64863475b945861589cc8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@destailleur.fr> Date: Tue, 29 Aug 2017 17:52:10 +0200 Subject: [PATCH] Fix duplicate code --- htdocs/holiday/list.php | 53 +++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/htdocs/holiday/list.php b/htdocs/holiday/list.php index 8541454e549..9c7ff195018 100644 --- a/htdocs/holiday/list.php +++ b/htdocs/holiday/list.php @@ -260,9 +260,16 @@ if ($id > 0) dol_banner_tab($fuser,'id',$linkback,$user->rights->user->user->lire || $user->admin); - print '<div class="underbanner clearboth"></div>'; + if (empty($conf->global->HOLIDAY_HIDE_BALANCE)) + { + print '<div class="underbanner clearboth"></div>'; + + print '<br>'; - print '<br>'; + showMyBalance($holiday, $user_id); + } + + dol_fiche_end(); } else { @@ -270,23 +277,43 @@ else //print count($holiday->holiday); print_barre_liste($langs->trans("ListeCP"), $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, "", $num, count($holiday->holiday), 'title_hrm.png', 0, '', '', $limit); - dol_fiche_head(''); + if (empty($conf->global->HOLIDAY_HIDE_BALANCE)) + { + dol_fiche_head(''); + + showMyBalance($holiday, $user_id); + + dol_fiche_end(); + } } -$alltypeleaves=$holiday->getTypes(1,-1); // To have labels -$out=''; -$typeleaves=$holiday->getTypes(1,1); -foreach($typeleaves as $key => $val) + +/** + * Show balance of user + * + * @param Holiday $holiday Object $holiday + * @param int $user_id User id + * @return string Html code with balance + */ +function showMyBalance($holiday, $user_id) { - $nb_type = $holiday->getCPforUser($user_id, $val['rowid']); - $nb_holiday += $nb_type; - $out .= ' - '.$val['label'].': <strong>'.($nb_type?price2num($nb_type):0).'</strong><br>'; + global $conf, $langs; + + $alltypeleaves=$holiday->getTypes(1,-1); // To have labels + + $out=''; + $typeleaves=$holiday->getTypes(1,1); + foreach($typeleaves as $key => $val) + { + $nb_type = $holiday->getCPforUser($user_id, $val['rowid']); + $nb_holiday += $nb_type; + $out .= ' - '.$val['label'].': <strong>'.($nb_type?price2num($nb_type):0).'</strong><br>'; + } + print $langs->trans('SoldeCPUser', round($nb_holiday,5)).'<br>'; + print $out; } -print $langs->trans('SoldeCPUser', round($nb_holiday,5)).'<br>'; -print $out; -dol_fiche_end(); if ($id > 0) print '<br>'; -- GitLab