Support type of leave.

This commit is contained in:
Laurent Destailleur 2015-06-21 23:25:01 +02:00
parent 7d1d1caf30
commit 5975536fcf
3 changed files with 92 additions and 50 deletions

View File

@ -51,7 +51,6 @@ $now=dol_now();
* Actions * Actions
*/ */
// Si création de la demande
if ($action == 'create') if ($action == 'create')
{ {
$cp = new Holiday($db); $cp = new Holiday($db);
@ -66,12 +65,15 @@ if ($action == 'create')
if (! $error) if (! $error)
{ {
$db->begin();
$date_debut = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year')); $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_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_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); $date_fin_gmt = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'), 1);
$starthalfday=GETPOST('starthalfday'); $starthalfday=GETPOST('starthalfday');
$endhalfday=GETPOST('endhalfday'); $endhalfday=GETPOST('endhalfday');
$type=GETPOST('type');
$halfday=0; $halfday=0;
if ($starthalfday == 'afternoon' && $endhalfday == 'morning') $halfday=2; if ($starthalfday == 'afternoon' && $endhalfday == 'morning') $halfday=2;
else if ($starthalfday == 'afternoon') $halfday=-1; else if ($starthalfday == 'afternoon') $halfday=-1;
@ -131,17 +133,22 @@ if ($action == 'create')
$cp->date_fin = $date_fin; $cp->date_fin = $date_fin;
$cp->fk_validator = $valideur; $cp->fk_validator = $valideur;
$cp->halfday = $halfday; $cp->halfday = $halfday;
$cp->fk_type = $type;
$verif = $cp->create($userid); $verif = $cp->create($user);
// Si pas d'erreur SQL on redirige vers la fiche de la demande // Si pas d'erreur SQL on redirige vers la fiche de la demande
if ($verif > 0) if ($verif > 0)
{ {
header('Location: card.php?id='.$verif); $db->commit();
header('Location: card.php?id='.$verif);
exit; exit;
} }
else else
{ {
$db->rollback();
// Sinon on affiche le formulaire de demande avec le message d'erreur SQL // Sinon on affiche le formulaire de demande avec le message d'erreur SQL
header('Location: card.php?action=request&error=SQL_Create&msg='.$cp->error); header('Location: card.php?action=request&error=SQL_Create&msg='.$cp->error);
exit; exit;
@ -242,44 +249,41 @@ if ($action == 'update')
} }
// Si suppression de la demande // Si suppression de la demande
if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes') if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes' && $user->rights->holiday->delete)
{ {
if($user->rights->holiday->delete) $error=0;
{
$error=0;
$db->begin(); $db->begin();
$cp = new Holiday($db); $cp = new Holiday($db);
$cp->fetch($id); $cp->fetch($id);
$canedit=(($user->id == $cp->fk_user && $user->rights->holiday->write) || ($user->id != $cp->fk_user && $user->rights->holiday->write_all)); $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 // Si c'est bien un brouillon
if ($cp->statut == 1 || $cp->statut == 3) if ($cp->statut == 1 || $cp->statut == 3)
{ {
// Si l'utilisateur à le droit de lire cette demande, il peut la supprimer // Si l'utilisateur à le droit de lire cette demande, il peut la supprimer
if ($canedit) if ($canedit)
{ {
$result=$cp->delete($id); $result=$cp->delete($id);
} }
else else
{ {
$error = $langs->trans('ErrorCantDeleteCP'); $error = $langs->trans('ErrorCantDeleteCP');
} }
} }
if (! $error) if (! $error)
{ {
$db->commit(); $db->commit();
header('Location: index.php'); header('Location: index.php');
exit; exit;
} }
else else
{ {
$db->rollback(); $db->rollback();
} }
}
} }
// Si envoi de la demande // Si envoi de la demande
@ -466,7 +470,7 @@ if ($action == 'confirm_valid')
if ($action == 'confirm_refuse') if ($action == 'confirm_refuse')
{ {
if (!empty($_POST['detail_refuse'])) if (! empty($_POST['detail_refuse']))
{ {
$cp = new Holiday($db); $cp = new Holiday($db);
$cp->fetch($_GET['id']); $cp->fetch($_GET['id']);
@ -770,6 +774,8 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tbody>'; print '<tbody>';
// User
print '<tr>'; print '<tr>';
print '<td class="fieldrequired">'.$langs->trans("User").'</td>'; print '<td class="fieldrequired">'.$langs->trans("User").'</td>';
print '<td>'; print '<td>';
@ -781,6 +787,24 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create
else print $form->select_users(GETPOST('userid')?GETPOST('userid'):$user->id,'userid',0,'',0); else print $form->select_users(GETPOST('userid')?GETPOST('userid'):$user->id,'userid',0,'',0);
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
// Type
print '<tr>';
print '<td class="fieldrequired">'.$langs->trans("Type").'</td>';
print '<td>';
$typeleaves=$cp->getTypes(1,1);
$arraytypeleaves=array();
foreach($typeleaves as $key => $val)
{
$labeltoshow = $val['label'];
$labeltoshow .= ($val['delay'] > 0 ? ' ('.$langs->trans("NoticePeriod").': '.$val['delay'].' '.$langs->trans("days").')':'');
$arraytypeleaves[$val['rowid']]=$labeltoshow;
}
print $form->selectarray('type', $arraytypeleaves, (GETPOST('type')?GETPOST('type'):''), 1);
print '</td>';
print '</tr>';
// Date start
print '<tr>'; print '<tr>';
print '<td class="fieldrequired">'.$langs->trans("DateDebCP").' ('.$langs->trans("FirstDayOfHoliday").')</td>'; print '<td class="fieldrequired">'.$langs->trans("DateDebCP").' ('.$langs->trans("FirstDayOfHoliday").')</td>';
print '<td>'; print '<td>';
@ -795,6 +819,8 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create
print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday')?GETPOST('starthalfday'):'morning')); print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday')?GETPOST('starthalfday'):'morning'));
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
// Date end
print '<tr>'; print '<tr>';
print '<td class="fieldrequired">'.$langs->trans("DateFinCP").' ('.$langs->trans("LastDayOfHoliday").')</td>'; print '<td class="fieldrequired">'.$langs->trans("DateFinCP").' ('.$langs->trans("LastDayOfHoliday").')</td>';
print '<td>'; print '<td>';
@ -952,9 +978,9 @@ else
if ($action == 'edit' && $cp->statut == 1) if ($action == 'edit' && $cp->statut == 1)
{ {
$edit = true; $edit = true;
print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$_GET['id'].'">'."\n"; print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$id.'">'."\n";
print '<input type="hidden" name="action" value="update"/>'."\n"; print '<input type="hidden" name="action" value="update"/>'."\n";
print '<input type="hidden" name="holiday_id" value="'.$_GET['id'].'" />'."\n"; print '<input type="hidden" name="holiday_id" value="'.$id.'" />'."\n";
} }
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
@ -974,6 +1000,15 @@ else
print $userRequest->getNomUrl(1); print $userRequest->getNomUrl(1);
print '</td></tr>'; print '</td></tr>';
// Type
print '<tr>';
print '<td>'.$langs->trans("Type").'</td>';
print '<td>';
$typeleaves=$cp->getTypes(1,1);
print $typeleaves[$cp->fk_type]['label'];
print '</td>';
print '</tr>';
$starthalfday=($cp->halfday == -1 || $cp->halfday == 2)?'afternoon':'morning'; $starthalfday=($cp->halfday == -1 || $cp->halfday == 2)?'afternoon':'morning';
$endhalfday=($cp->halfday == 1 || $cp->halfday == 2)?'morning':'afternoon'; $endhalfday=($cp->halfday == 1 || $cp->halfday == 2)?'morning':'afternoon';

View File

@ -53,7 +53,7 @@ class Holiday extends CommonObject
var $date_debut_gmt=''; // Date start in GMT var $date_debut_gmt=''; // Date start in GMT
var $date_fin_gmt=''; // Date end in GMT var $date_fin_gmt=''; // Date end in GMT
var $halfday=''; var $halfday='';
var $statut=''; // 1=draft, 2=validated, 3=approved var $statut=''; // 1=draft, 2=validated, 3=approved
var $fk_validator; var $fk_validator;
var $date_valid=''; var $date_valid='';
var $fk_user_valid; var $fk_user_valid;
@ -62,6 +62,7 @@ class Holiday extends CommonObject
var $date_cancel=''; var $date_cancel='';
var $fk_user_cancel; var $fk_user_cancel;
var $detail_refuse=''; var $detail_refuse='';
var $fk_type;
var $holiday = array(); var $holiday = array();
var $events = array(); var $events = array();
@ -71,6 +72,7 @@ class Holiday extends CommonObject
var $optValue = ''; var $optValue = '';
var $optRowid = ''; var $optRowid = '';
/** /**
* Constructor * Constructor
* *
@ -124,10 +126,10 @@ class Holiday extends CommonObject
$sql.= "date_fin,"; $sql.= "date_fin,";
$sql.= "halfday,"; $sql.= "halfday,";
$sql.= "statut,"; $sql.= "statut,";
$sql.= "fk_validator"; $sql.= "fk_validator,";
$sql.= "fk_type,";
$sql.= "fk_user_create";
$sql.= ") VALUES ("; $sql.= ") VALUES (";
// User
$sql.= "'".$this->fk_user."',"; $sql.= "'".$this->fk_user."',";
$sql.= " '".$this->db->idate($now)."',"; $sql.= " '".$this->db->idate($now)."',";
$sql.= " '".$this->db->escape($this->description)."',"; $sql.= " '".$this->db->escape($this->description)."',";
@ -135,8 +137,9 @@ class Holiday extends CommonObject
$sql.= " '".$this->db->idate($this->date_fin)."',"; $sql.= " '".$this->db->idate($this->date_fin)."',";
$sql.= " ".$this->halfday.","; $sql.= " ".$this->halfday.",";
$sql.= " '1',"; $sql.= " '1',";
$sql.= " '".$this->fk_validator."'"; $sql.= " '".$this->fk_validator."',";
$sql.= " '".$this->fk_type."',";
$sql.= " ".$user->id;
$sql.= ")"; $sql.= ")";
$this->db->begin(); $this->db->begin();
@ -150,7 +153,6 @@ class Holiday extends CommonObject
if (! $error) if (! $error)
{ {
$this->rowid = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday"); $this->rowid = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday");
} }
// Commit or rollback // Commit or rollback
@ -200,7 +202,9 @@ class Holiday extends CommonObject
$sql.= " cp.fk_user_cancel,"; $sql.= " cp.fk_user_cancel,";
$sql.= " cp.detail_refuse,"; $sql.= " cp.detail_refuse,";
$sql.= " cp.note_private,"; $sql.= " cp.note_private,";
$sql.= " cp.note_public"; $sql.= " cp.note_public,";
$sql.= " cp.fk_user_create,";
$sql.= " cp.fk_type";
$sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp"; $sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp";
$sql.= " WHERE cp.rowid = ".$id; $sql.= " WHERE cp.rowid = ".$id;
@ -213,8 +217,8 @@ class Holiday extends CommonObject
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->rowid = $obj->rowid; // deprecated $this->rowid = $obj->rowid; // deprecated
$this->ref = $obj->rowid; $this->ref = $obj->rowid;
$this->fk_user = $obj->fk_user; $this->fk_user = $obj->fk_user;
$this->date_create = $this->db->jdate($obj->date_create); $this->date_create = $this->db->jdate($obj->date_create);
$this->description = $obj->description; $this->description = $obj->description;
@ -234,6 +238,8 @@ class Holiday extends CommonObject
$this->detail_refuse = $obj->detail_refuse; $this->detail_refuse = $obj->detail_refuse;
$this->note_private = $obj->note_private; $this->note_private = $obj->note_private;
$this->note_public = $obj->note_public; $this->note_public = $obj->note_public;
$this->fk_user_create = $obj->fk_user_create;
$this->fk_type = $obj->fk_type;
} }
$this->db->free($resql); $this->db->free($resql);
@ -1841,7 +1847,7 @@ class Holiday extends CommonObject
{ {
while ($obj = $this->db->fetch_object($result)) while ($obj = $this->db->fetch_object($result))
{ {
$types[] = array('rowid'=> $obj->rowid, 'code'=> $obj->code, 'label'=>$obj->label, 'affect'=>$obj->affect, 'delay'=>$obj->delay, 'newByMonth'=>$obj->newByMonth); $types[$obj->rowid] = array('rowid'=> $obj->rowid, 'code'=> $obj->code, 'label'=>$obj->label, 'affect'=>$obj->affect, 'delay'=>$obj->delay, 'newByMonth'=>$obj->newByMonth);
} }
return $types; return $types;

View File

@ -127,6 +127,7 @@ ErrorMailNotSend=An error occurred while sending email:
NoCPforMonth=No leave this month. NoCPforMonth=No leave this month.
nbJours=Number days nbJours=Number days
TitleAdminCP=Configuration of Leaves TitleAdminCP=Configuration of Leaves
NoticePeriod=Notice period
#Messages #Messages
Hello=Hello Hello=Hello
HolidaysToValidate=Validate leave requests HolidaysToValidate=Validate leave requests