diff --git a/ChangeLog b/ChangeLog index 9a5a532146a..8bf7668ec2c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -60,6 +60,7 @@ For users: - New: When a subscription is recorded with invoice and payment: - the document (PDF) of invoice is also generated. - the invoice is set to status paid. +- New: Can enter holiday for someone else if user has permission for. - Fix: Project Task numbering customs rule works. - Fix: Add actions events not implemented. - Fix: Price min of composition is not supplier price min by quantity. diff --git a/htdocs/core/modules/modHoliday.class.php b/htdocs/core/modules/modHoliday.class.php index 4bf687c9704..eadfa84ba6c 100644 --- a/htdocs/core/modules/modHoliday.class.php +++ b/htdocs/core/modules/modHoliday.class.php @@ -134,42 +134,42 @@ class modHoliday extends DolibarrModules $r=0; $this->rights[$r][0] = 20001; // Permission id (must not be already used) - $this->rights[$r][1] = 'Lire/créer/modifier ses demandes de congés payés'; // Permission label + $this->rights[$r][1] = 'Create/modify your own holidays'; // Permission label $this->rights[$r][3] = 1; // Permission by default for new user (0/1) $this->rights[$r][4] = 'write'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $r++; $this->rights[$r][0] = 20002; // Permission id (must not be already used) - $this->rights[$r][1] = 'Lire/créer/modifier toutes les demandes de congés payés'; // Permission label + $this->rights[$r][1] = 'Create/modify hollidays for everybody'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) - $this->rights[$r][4] = 'lire_tous'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) + $this->rights[$r][4] = 'write_all'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $r++; $this->rights[$r][0] = 20003; // Permission id (must not be already used) - $this->rights[$r][1] = 'Supprimer des demandes de congés payés'; // Permission label + $this->rights[$r][1] = 'Delete holidays'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) $this->rights[$r][4] = 'delete'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $r++; $this->rights[$r][0] = 20004; // Permission id (must not be already used) - $this->rights[$r][1] = 'Définir les congés payés des utilisateurs'; // Permission label + $this->rights[$r][1] = 'Setup holidays of users'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) $this->rights[$r][4] = 'define_holiday'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $r++; $this->rights[$r][0] = 20005; // Permission id (must not be already used) - $this->rights[$r][1] = 'Voir les logs de modification des congés payés'; // Permission label + $this->rights[$r][1] = 'See logs for holidays requests'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) $this->rights[$r][4] = 'view_log'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $r++; $this->rights[$r][0] = 20006; // Permission id (must not be already used) - $this->rights[$r][1] = 'Accéder au rapport mensuel des congés payés'; // Permission label + $this->rights[$r][1] = 'Read holidays monthly report'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) $this->rights[$r][4] = 'month_report'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) @@ -179,7 +179,7 @@ class modHoliday extends DolibarrModules $this->menus = array(); // List of menus to add $r=0; - + /* Move to HRM menu // Add here entries to declare new menus $this->menu[$r]=array( 'fk_menu'=>0, // Put 0 if this is a top menu @@ -261,7 +261,7 @@ class modHoliday extends DolibarrModules 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both $r++; */ - + // Exports $r=1; diff --git a/htdocs/holiday/fiche.php b/htdocs/holiday/fiche.php index 10fb4121147..d66d1c8cfbd 100644 --- a/htdocs/holiday/fiche.php +++ b/htdocs/holiday/fiche.php @@ -6,7 +6,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or + * the Free Software Foundation; either version 3 of the License, orwrite * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -38,11 +38,11 @@ require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php'; $myparam = GETPOST("myparam"); $action=GETPOST('action', 'alpha'); $id=GETPOST('id', 'int'); +$userid = GETPOST('userid')?GETPOST('userid'):$user->id; // Protection if external user if ($user->societe_id > 0) accessforbidden(); -$user_id = $user->id; $now=dol_now(); @@ -56,93 +56,96 @@ if ($action == 'create') $cp = new Holiday($db); // Si pas le droit de créer une demande - if(!$user->rights->holiday->write) + if (($userid == $user->id && empty($user->rights->holiday->write)) || ($userid != $user->id && empty($user->rights->holiday->write_all))) { - header('Location: fiche.php?action=request&error=CantCreate'); - exit; + $error++; + setEventMessage($langs->trans('CantCreateCP')); + $action='request'; } - $date_debut = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year')); - $date_fin = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year')); - $date_debut_gmt = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'), 1); - $date_fin_gmt = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'), 1); - $starthalfday=GETPOST('starthalfday'); - $endhalfday=GETPOST('endhalfday'); - $halfday=0; - if ($starthalfday == 'afternoon' && $endhalfday == 'morning') $halfday=2; - else if ($starthalfday == 'afternoon') $halfday=-1; - else if ($endhalfday == 'morning') $halfday=1; - - $valideur = GETPOST('valideur'); - $description = trim(GETPOST('description')); - $userID = GETPOST('userID'); - - // Si pas de date de début - if (empty($date_debut)) + if (! $error) { - header('Location: fiche.php?action=request&error=nodatedebut'); - exit; + $date_debut = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year')); + $date_fin = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year')); + $date_debut_gmt = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'), 1); + $date_fin_gmt = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'), 1); + $starthalfday=GETPOST('starthalfday'); + $endhalfday=GETPOST('endhalfday'); + $halfday=0; + if ($starthalfday == 'afternoon' && $endhalfday == 'morning') $halfday=2; + else if ($starthalfday == 'afternoon') $halfday=-1; + else if ($endhalfday == 'morning') $halfday=1; + + $valideur = GETPOST('valideur'); + $description = trim(GETPOST('description')); + $userID = GETPOST('userID'); + + // Si pas de date de début + if (empty($date_debut)) + { + header('Location: fiche.php?action=request&error=nodatedebut'); + exit; + } + + // Si pas de date de fin + if (empty($date_fin)) + { + header('Location: fiche.php?action=request&error=nodatefin'); + exit; + } + + // Si date de début après la date de fin + if ($date_debut > $date_fin) + { + header('Location: fiche.php?action=request&error=datefin'); + exit; + } + + // Check if there is already holiday for this period + $verifCP = $cp->verifDateHolidayCP($userID, $date_debut, $date_fin, $halfday); + if (! $verifCP) + { + header('Location: fiche.php?action=request&error=alreadyCP'); + exit; + } + + // Si aucun jours ouvrés dans la demande + $nbopenedday=num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday); + if($nbopenedday < 1) + { + header('Location: fiche.php?action=request&error=DureeHoliday'); + exit; + } + + // Si pas de validateur choisi + if ($valideur < 1) + { + header('Location: fiche.php?action=request&error=Valideur'); + exit; + } + + $cp->fk_user = $userid; + $cp->description = $description; + $cp->date_debut = $date_debut; + $cp->date_fin = $date_fin; + $cp->fk_validator = $valideur; + $cp->halfday = $halfday; + + $verif = $cp->create($userid); + + // Si pas d'erreur SQL on redirige vers la fiche de la demande + if ($verif > 0) + { + header('Location: fiche.php?id='.$verif); + exit; + } + else + { + // Sinon on affiche le formulaire de demande avec le message d'erreur SQL + header('Location: fiche.php?action=request&error=SQL_Create&msg='.$cp->error); + exit; + } } - - // Si pas de date de fin - if (empty($date_fin)) - { - header('Location: fiche.php?action=request&error=nodatefin'); - exit; - } - - // Si date de début après la date de fin - if ($date_debut > $date_fin) - { - header('Location: fiche.php?action=request&error=datefin'); - exit; - } - - // Check if there is already holiday for this period - $verifCP = $cp->verifDateHolidayCP($userID, $date_debut, $date_fin, $halfday); - if (! $verifCP) - { - header('Location: fiche.php?action=request&error=alreadyCP'); - exit; - } - - // Si aucun jours ouvrés dans la demande - $nbopenedday=num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday); - if($nbopenedday < 1) - { - header('Location: fiche.php?action=request&error=DureeHoliday'); - exit; - } - - // Si pas de validateur choisi - if ($valideur < 1) - { - header('Location: fiche.php?action=request&error=Valideur'); - exit; - } - - $cp->fk_user = $user_id; - $cp->description = $description; - $cp->date_debut = $date_debut; - $cp->date_fin = $date_fin; - $cp->fk_validator = $valideur; - $cp->halfday = $halfday; - - $verif = $cp->create($user_id); - - // Si pas d'erreur SQL on redirige vers la fiche de la demande - if ($verif > 0) - { - header('Location: fiche.php?id='.$verif); - exit; - } - else - { - // Sinon on affiche le formulaire de demande avec le message d'erreur SQL - header('Location: fiche.php?action=request&error=SQL_Create&msg='.$cp->error); - exit; - } - } if ($action == 'update') @@ -159,7 +162,7 @@ if ($action == 'update') else if ($endhalfday == 'morning') $halfday=1; // Si pas le droit de modifier une demande - if(!$user->rights->holiday->write) + if (! $user->rights->holiday->write) { header('Location: fiche.php?action=request&error=CantUpdate'); exit; @@ -168,11 +171,13 @@ if ($action == 'update') $cp = new Holiday($db); $cp->fetch($_POST['holiday_id']); - // Si en attente de validation + $canedit=(($user->id == $cp->fk_user && $user->rights->holiday->write) || ($user->id != $cp->fk_user && $user->rights->holiday->write_all)); + + // Si en attente de validation if ($cp->statut == 1) { // Si c'est le créateur ou qu'il a le droit de tout lire / modifier - if ($user->id == $cp->fk_user || $user->rights->holiday->lire_tous) + if ($canedit) { $valideur = $_POST['valideur']; $description = trim($_POST['description']); @@ -247,11 +252,13 @@ if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes') $cp = new Holiday($db); $cp->fetch($id); + $canedit=(($user->id == $cp->fk_user && $user->rights->holiday->write) || ($user->id != $cp->fk_user && $user->rights->holiday->write_all)); + // Si c'est bien un brouillon if ($cp->statut == 1 || $cp->statut == 3) { // Si l'utilisateur à le droit de lire cette demande, il peut la supprimer - if ($user->id == $cp->fk_user || $user->rights->holiday->lire_tous) + if ($canedit) { $result=$cp->delete($id); } @@ -653,13 +660,12 @@ $cp = new Holiday($db); $listhalfday=array('morning'=>$langs->trans("Morning"),"afternoon"=>$langs->trans("Afternoon")); - llxHeader(array(),$langs->trans('CPTitreMenu')); -if (empty($id) || $action == 'add' || $action == 'request') +if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create') { // Si l'utilisateur n'a pas le droit de faire une demande - if(!$user->rights->holiday->write) + if (($userid == $user->id && empty($user->rights->holiday->write)) || ($userid != $user->id && empty($user->rights->holiday->write_all))) { $errors[]=$langs->trans('CantCreateCP'); } @@ -739,16 +745,26 @@ if (empty($id) || $action == 'add' || $action == 'request') // Formulaire de demande print '
'."\n"; print ''."\n"; - print ''."\n"; + print ''."\n"; print '
'; print ''.$langs->trans('DelayToRequestCP',$cp->getConfCP('delayForRequest')).'

'; - $nb_holiday = $cp->getCPforUser($user->id) / $cp->getConfCP('nbHolidayDeducted'); - - print ''.$langs->trans('SoldeCPUser', round($nb_holiday,0)).'

'; print ''; print ''; print ''; + print ''; + print ''; + print ''; + print ''; print ''; print ''; print ''; + print ''; + print ''; + $starthalfday=($cp->halfday == -1 || $cp->halfday == 2)?'afternoon':'morning'; $endhalfday=($cp->halfday == 1 || $cp->halfday == 2)?'morning':'afternoon'; @@ -1019,19 +1041,24 @@ else print '

'; - + // Info workflow print '
'.$langs->trans("User").''; + if (empty($user->rights->holiday->write_all)) + { + print $form->select_users($userid,'useridbis',0,'',1); + print ''; + } + else print $form->select_users(GETPOST('userid')?GETPOST('userid'):$user->id,'userid',0,'',0); + $nb_holiday = $cp->getCPforUser($user->id) / $cp->getConfCP('nbHolidayDeducted'); + print '   '.$langs->trans('SoldeCPUser', round($nb_holiday,0)).''; + print '
'.$langs->trans("DateDebCP").' ('.$langs->trans("FirstDayOfHoliday").')'; // Si la demande ne vient pas de l'agenda @@ -829,6 +845,8 @@ else { $cp->fetch($id); + $canedit=(($user->id == $cp->fk_user && $user->rights->holiday->write) || ($user->id != $cp->fk_user && $user->rights->holiday->write_all)); + $valideur = new User($db); $valideur->fetch($cp->fk_validator); @@ -875,9 +893,8 @@ else } // On vérifie si l'utilisateur à le droit de lire cette demande - if($user->id == $cp->fk_user || $user->rights->holiday->lire_tous) + if ($canedit) { - if ($action == 'delete') { if($user->rights->holiday->delete) @@ -915,7 +932,7 @@ else dol_fiche_head($head,'card',$langs->trans("CPTitreMenu"),0,'holiday'); - if ($action == 'edit' && $user->id == $cp->fk_user && $cp->statut == 1) + if ($action == 'edit' && $cp->statut == 1) { $edit = true; print ''."\n"; @@ -935,6 +952,11 @@ else print '
'.$langs->trans("User").''; + print $userRequest->getNomUrl(1); + print '
'."\n"; print ''; print ''; print ''; print ''; - print ''; - print ''; - print ''; - print ''; + if (! empty($cp->fk_user_create)) + { + $userCreate=new User($db); + $userCreate->fetch($cp->fk_user_create); + print ''; + print ''; + print ''; + print ''; + } - if(!$edit) { + if (!$edit) { print ''; print ''; print ''; @@ -1076,10 +1103,10 @@ else print ''; print '
'.$langs->trans("InfosWorkflowCP").'
'.$langs->trans('RequestByCP').''.$userRequest->getNomUrl(1).'
'.$langs->trans('RequestByCP').''.$userCreate->getNomUrl(1).'
'.$langs->trans('ReviewedByCP').''.$valideur->getNomUrl(1).'
'; - if ($edit && $user->id == $cp->fk_user && $cp->statut == 1) + if ($action == 'edit' && $cp->statut == 1) { print '
'; - if($user->rights->holiday->write && $_GET['action'] == 'edit' && $cp->statut == 1) + if ($canedit && $cp->statut == 1) { print ''; } @@ -1095,11 +1122,11 @@ else print '
'; // Boutons d'actions - if($user->rights->holiday->write && $_GET['action'] != 'edit' && $cp->statut == 1) + if ($canedit && $cp->statut == 1) { print ''.$langs->trans("EditCP").''; } - if($user->id == $cp->fk_user && $cp->statut == 1) + if ($canedit && $cp->statut == 1) { print ''.$langs->trans("Validate").''; } diff --git a/htdocs/holiday/index.php b/htdocs/holiday/index.php index 906fa9c2d6e..cea61ea5b59 100644 --- a/htdocs/holiday/index.php +++ b/htdocs/holiday/index.php @@ -173,7 +173,7 @@ if ($id > 0) $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 || $id > 0) +if (!$user->rights->holiday->write_all || $id > 0) { $holiday_payes = $holiday->fetchByUser($user_id,$order,$filter); } @@ -278,7 +278,7 @@ $formother->select_year($year_create,'year_create',1, $min_year, 0); print ''; // UTILISATEUR -if($user->rights->holiday->lire_tous) { +if($user->rights->holiday->write_all) { print ''; $form->select_users($search_employe,"search_employe",1,"",0,''); print ''; @@ -287,7 +287,7 @@ if($user->rights->holiday->lire_tous) { } // VALIDEUR -if($user->rights->holiday->lire_tous) +if($user->rights->holiday->write_all) { print ''; diff --git a/htdocs/install/mysql/migration/3.5.0-3.6.0.sql b/htdocs/install/mysql/migration/3.5.0-3.6.0.sql index 30d3340e4c7..35b8571813a 100644 --- a/htdocs/install/mysql/migration/3.5.0-3.6.0.sql +++ b/htdocs/install/mysql/migration/3.5.0-3.6.0.sql @@ -20,6 +20,10 @@ ALTER TABLE llx_societe DROP COLUMN datea; +ALTER TABLE llx_holiday ADD COLUMN fk_user_create integer; +ALTER TABLE llx_holiday ADD INDEX idx_holiday_fk_user_create (fk_user_create); +ALTER TABLE llx_holiday ADD INDEX idx_holiday_date_create (date_create); +ALTER TABLE llx_holiday ADD INDEX idx_holiday_fk_validator (fk_validator); create table llx_c_email_templates ( diff --git a/htdocs/install/mysql/tables/llx_holiday.key.sql b/htdocs/install/mysql/tables/llx_holiday.key.sql index 76034904484..8c66d2d80d4 100644 --- a/htdocs/install/mysql/tables/llx_holiday.key.sql +++ b/htdocs/install/mysql/tables/llx_holiday.key.sql @@ -17,5 +17,8 @@ -- =================================================================== ALTER TABLE llx_holiday ADD INDEX idx_holiday_fk_user (fk_user); +ALTER TABLE llx_holiday ADD INDEX idx_holiday_fk_user_create (fk_user_create); +ALTER TABLE llx_holiday ADD INDEX idx_holiday_date_create (date_create); ALTER TABLE llx_holiday ADD INDEX idx_holiday_date_debut (date_debut); ALTER TABLE llx_holiday ADD INDEX idx_holiday_date_fin (date_fin); +ALTER TABLE llx_holiday ADD INDEX idx_holiday_fk_validator (fk_validator); diff --git a/htdocs/install/mysql/tables/llx_holiday.sql b/htdocs/install/mysql/tables/llx_holiday.sql index 582b00034ff..fa9e7a070dc 100644 --- a/htdocs/install/mysql/tables/llx_holiday.sql +++ b/htdocs/install/mysql/tables/llx_holiday.sql @@ -20,6 +20,7 @@ CREATE TABLE llx_holiday ( rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY, fk_user integer NOT NULL, +fk_user_create integer, date_create DATETIME NOT NULL, description VARCHAR( 255 ) NOT NULL, date_debut DATE NOT NULL, diff --git a/htdocs/langs/en_US/holiday.lang b/htdocs/langs/en_US/holiday.lang index f5b104b8301..0c755ca3301 100644 --- a/htdocs/langs/en_US/holiday.lang +++ b/htdocs/langs/en_US/holiday.lang @@ -141,9 +141,10 @@ HolidaysRefused=Denied holidays HolidaysRefusedBody=Your request for holidays for %s to %s has been denied for the following reason : HolidaysCanceled=Canceled holidays HolidaysCanceledBody=Your request for holidays for %s to %s has been canceled. -Permission20001=Read/create/modify their holidays -Permission20002=Read/modify all requests of holidays -Permission20003=Delete their holidays requests -Permission20004=Define users holidays +Permission20000=Read you own holidays +Permission20001=Create/modify your holidays +Permission20002=Create/modify holidays for everybody +Permission20003=Delete holidays requests +Permission20004=Setup users holidays Permission20005=Review log of modified holidays -Permission20006=Access holidays monthly report +Permission20006=Read holidays monthly report