Skip to content

Commit

Permalink
Fix: Nb of holidays was not using correct user
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Feb 17, 2013
1 parent b0695d3 commit d6e907b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 32 deletions.
99 changes: 69 additions & 30 deletions htdocs/holiday/index.php
Expand Up @@ -30,6 +30,11 @@
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';

$langs->load('users');
$langs->load('holidays');

// Protection if external user
if ($user->societe_id > 0) accessforbidden();
Expand All @@ -46,6 +51,8 @@
$pageprev = $page - 1;
$pagenext = $page + 1;

$id = GETPOST('id');

$search_ref = GETPOST('search_ref');
$month_create = GETPOST('month_create');
$year_create = GETPOST('year_create');
Expand All @@ -72,6 +79,7 @@

$holiday = new Holiday($db);
$holidaystatic=new Holiday($db);
$fuser = new User($db);

// Update sold
$holiday->updateSold();
Expand Down Expand Up @@ -151,28 +159,22 @@
// Récupération de l'ID de l'utilisateur
$user_id = $user->id;

if ($id > 0)
{
// Charge utilisateur edite
$fuser->fetch($id);
$fuser->getrights();
$user_id = $fuser->id;
}
// Récupération des congés payés de l'utilisateur ou de tous les users
if (!$user->rights->holiday->lire_tous)
if (!$user->rights->holiday->lire_tous || $id > 0)
{
$holiday_payes = $holiday->fetchByUser($user_id,$order,$filter);
$holiday_payes = $holiday->fetchByUser($user_id,$order,$filter);
}
else
{
$holiday_payes = $holiday->fetchAll($order,$filter);
}

// Si pas de congés payés
if ($holiday_payes == 0)
{
print_fiche_titre($langs->trans('CPTitreMenu'));

print '<div class="tabBar">';
print '<span>'.$langs->trans('NoCPforUser').'<br /><br />';
print '<a href="./fiche.php?mainmenu=agenda&action=request" class="butAction">'.$langs->trans('AddCP').'</a></span>';
print '</div>';
exit();
}

// Si erreur SQL
if ($holiday_payes == '-1')
{
Expand All @@ -189,14 +191,48 @@
* Affichage du tableau des congés payés
*************************************/

$var=true; $num = count($holiday->holiday);
$html = new Form($db);
$htmlother = new FormOther($db);
print_barre_liste($langs->trans("ListeCP"), $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, "", $num);
$var=true; $num = count($holiday->holiday);
$form = new Form($db);
$formother = new FormOther($db);

print '<div class="tabBar">';
if ($id > 0)
{
$head = user_prepare_head($fuser);

$title = $langs->trans("User");
dol_fiche_head($head, 'paidholidays', $title, 0, 'user');

print '<table class="border" width="100%">';

// Ref
print '<tr><td width="25%" valign="top">'.$langs->trans("Ref").'</td>';
print '<td colspan="2">';
print $form->showrefnav($fuser,'id','',$user->rights->user->user->lire || $user->admin);
print '</td>';
print '</tr>';

// Nom
print '<tr><td width="25%" valign="top">'.$langs->trans("LastName").'</td>';
print '<td colspan="2">'.$fuser->lastname.'</td>';
print "</tr>\n";

// Prenom
print '<tr><td width="25%" valign="top">'.$langs->trans("FirstName").'</td>';
print '<td colspan="2">'.$fuser->firstname.'</td>';
print "</tr>\n";

print '</table><br>';

}
else
{
print_barre_liste($langs->trans("ListeCP"), $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, "", $num);

$nbaquis=$holiday->getCPforUser($user->id);
print '<div class="tabBar">';
}


$nbaquis=$holiday->getCPforUser($user_id);
$nbdeduced=$holiday->getConfCP('nbHolidayDeducted');
$nb_holiday = $nbaquis / $nbdeduced;
print $langs->trans('SoldeCPUser',round($nb_holiday,2)).($nbdeduced != 1 ? ' ('.$nbaquis.' / '.$nbdeduced.')' : '');
Expand All @@ -223,13 +259,13 @@
// DATE CREATE
print '<td class="liste_titre" colspan="1" align="center">';
print '<input class="flat" type="text" size="1" maxlength="2" name="month_create" value="'.$month_create.'">';
$htmlother->select_year($year_create,'year_create',1, $min_year, $max_year);
$formother->select_year($year_create,'year_create',1, $min_year, $max_year);
print '</td>';

// UTILISATEUR
if($user->rights->holiday->lire_tous) {
print '<td class="liste_titre" align="left">';
$html->select_users($search_employe,"search_employe",1,"",0,'');
$form->select_users($search_employe,"search_employe",1,"",0,'');
print '</td>';
} else {
print '<td class="liste_titre">&nbsp;</td>';
Expand All @@ -246,7 +282,7 @@
$validator = new UserGroup($db,$idGroupValid);
$valideur = $validator->listUsersForGroup();

$html->select_users($search_valideur,"search_valideur",1,"",0,$valideur,'');
$form->select_users($search_valideur,"search_valideur",1,"",0,$valideur,'');
print '</td>';
} else {
print '<td class="liste_titre">&nbsp;</td>';
Expand All @@ -255,13 +291,13 @@
// DATE DEBUT
print '<td class="liste_titre" colspan="1" align="center">';
print '<input class="flat" type="text" size="1" maxlength="2" name="month_start" value="'.$month_start.'">';
$htmlother->select_year($year_start,'year_start',1, $min_year, $max_year);
$formother->select_year($year_start,'year_start',1, $min_year, $max_year);
print '</td>';

// DATE FIN
print '<td class="liste_titre" colspan="1" align="center">';
print '<input class="flat" type="text" size="1" maxlength="2" name="month_end" value="'.$month_end.'">';
$htmlother->select_year($year_end,'year_end',1, $min_year, $max_year);
$formother->select_year($year_end,'year_end',1, $min_year, $max_year);
print '</td>';

// DUREE
Expand Down Expand Up @@ -327,10 +363,13 @@
print '</table>';
print '</form>';

print '<br>';
print '<div style="float: right; margin-top: 8px;">';
print '<a href="./fiche.php?action=request" class="butAction">'.$langs->trans('AddCP').'</a>';
print '</div>';
if ($user_id == $user->id)
{
print '<br>';
print '<div style="float: right; margin-top: 8px;">';
print '<a href="./fiche.php?action=request" class="butAction">'.$langs->trans('AddCP').'</a>';
print '</div>';
}

llxFooter();

Expand Down
2 changes: 1 addition & 1 deletion htdocs/langs/en_US/holiday.lang
Expand Up @@ -26,7 +26,7 @@ SendRequestCP=Creating demand for holidays
DelayToRequestCP=Applications for holidays must be made at least <b>%s day(s)</b> before them.
MenuConfCP=Edit balance of holidays
UpdateAllCP=Update the holidays
SoldeCPUser=Your balance of holidays is <b>%s</b> days.
SoldeCPUser=Holidays balance is <b>%s</b> days.
ErrorEndDateCP=You must select an end date greater than the start date.
ErrorSQLCreateCP=An SQL error occurred during the creation:
ErrorIDFicheCP=An error has occurred, the request for holidays does not exist.
Expand Down
2 changes: 1 addition & 1 deletion htdocs/langs/fr_FR/holiday.lang
Expand Up @@ -26,7 +26,7 @@ SendRequestCP=Envoyer la demande de congés
DelayToRequestCP=Les demandes de congés doivent être faites au moins <b>%s jours</b> avant la date</b> de ceux-ci.
MenuConfCP=Mettre à jour solde
UpdateAllCP=Mettre à jour les congés
SoldeCPUser=Votre solde de congés est de <b>%s jours</b>.
SoldeCPUser=Solde de congés: <b>%s jours</b>.
ErrorEndDateCP=Vous devez choisir une date de fin supérieur à la date de début.
ErrorSQLCreateCP=Une erreur SQL est survenue durant la création :
ErrorIDFicheCP=Une erreur est survenue, cette demande de congés n'existe pas.
Expand Down

0 comments on commit d6e907b

Please sign in to comment.