Bläddra i källkod

Support type of leave.

Laurent Destailleur 10 år sedan
förälder
incheckning
5975536fcf
3 ändrade filer med 93 tillägg och 51 borttagningar
  1. 75 40
      htdocs/holiday/card.php
  2. 17 11
      htdocs/holiday/class/holiday.class.php
  3. 1 0
      htdocs/langs/en_US/holiday.lang

+ 75 - 40
htdocs/holiday/card.php

@@ -51,7 +51,6 @@ $now=dol_now();
  * Actions
  */
 
-// Si création de la demande
 if ($action == 'create')
 {
 	$cp = new Holiday($db);
@@ -66,12 +65,15 @@ if ($action == 'create')
 
     if (! $error)
     {
+    	$db->begin();
+
 	    $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');
+	    $type=GETPOST('type');
 	    $halfday=0;
 	    if ($starthalfday == 'afternoon' && $endhalfday == 'morning') $halfday=2;
 	    else if ($starthalfday == 'afternoon') $halfday=-1;
@@ -131,17 +133,22 @@ if ($action == 'create')
 	    $cp->date_fin = $date_fin;
 	    $cp->fk_validator = $valideur;
 		$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
 	    if ($verif > 0)
 	    {
-	        header('Location: card.php?id='.$verif);
+			$db->commit();
+
+	    	header('Location: card.php?id='.$verif);
 	        exit;
 	    }
 	    else
-	    {
+		{
+	    	$db->rollback();
+
 	        // 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);
 	        exit;
@@ -242,44 +249,41 @@ if ($action == 'update')
 }
 
 // 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->fetch($id);
-
-        $canedit=(($user->id == $cp->fk_user && $user->rights->holiday->write) || ($user->id != $cp->fk_user && $user->rights->holiday->write_all));
+	$cp = new Holiday($db);
+	$cp->fetch($id);
 
-        // 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 ($canedit)
-            {
-                $result=$cp->delete($id);
-            }
-            else
-            {
-                $error = $langs->trans('ErrorCantDeleteCP');
-            }
-        }
+	$canedit=(($user->id == $cp->fk_user && $user->rights->holiday->write) || ($user->id != $cp->fk_user && $user->rights->holiday->write_all));
 
-       	if (! $error)
-        {
-          	$db->commit();
-           	header('Location: index.php');
-           	exit;
-        }
-        else
-        {
-        	$db->rollback();
-        }
-    }
+	// 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 ($canedit)
+		{
+			$result=$cp->delete($id);
+		}
+		else
+		{
+			$error = $langs->trans('ErrorCantDeleteCP');
+		}
+	}
+
+	if (! $error)
+	{
+		$db->commit();
+		header('Location: index.php');
+		exit;
+	}
+	else
+	{
+		$db->rollback();
+	}
 }
 
 // Si envoi de la demande
@@ -466,7 +470,7 @@ if ($action == 'confirm_valid')
 
 if ($action == 'confirm_refuse')
 {
-    if (!empty($_POST['detail_refuse']))
+    if (! empty($_POST['detail_refuse']))
     {
         $cp = new Holiday($db);
         $cp->fetch($_GET['id']);
@@ -770,6 +774,8 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create
 
         print '<table class="border" width="100%">';
         print '<tbody>';
+
+        // User
         print '<tr>';
         print '<td class="fieldrequired">'.$langs->trans("User").'</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);
         print '</td>';
         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 '<td class="fieldrequired">'.$langs->trans("DateDebCP").' ('.$langs->trans("FirstDayOfHoliday").')</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 '</td>';
         print '</tr>';
+
+        // Date end
         print '<tr>';
         print '<td class="fieldrequired">'.$langs->trans("DateFinCP").' ('.$langs->trans("LastDayOfHoliday").')</td>';
         print '<td>';
@@ -952,9 +978,9 @@ else
                 if ($action == 'edit' && $cp->statut == 1)
                 {
                     $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="holiday_id" value="'.$_GET['id'].'" />'."\n";
+                    print '<input type="hidden" name="holiday_id" value="'.$id.'" />'."\n";
                 }
 
                 print '<table class="border" width="100%">';
@@ -974,6 +1000,15 @@ else
         		print $userRequest->getNomUrl(1);
         		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';
 			    $endhalfday=($cp->halfday == 1 || $cp->halfday == 2)?'morning':'afternoon';
 

+ 17 - 11
htdocs/holiday/class/holiday.class.php

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

+ 1 - 0
htdocs/langs/en_US/holiday.lang

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