From b717d530cdb8608a0562f0fe0f0a2fde538be441 Mon Sep 17 00:00:00 2001
From: arnaud <arnaud.saint-patrice@atm-consulting.fr>
Date: Tue, 27 Sep 2016 15:16:16 +0200
Subject: [PATCH] NEW User date of employment added

---
 .../install/mysql/migration/4.0.0-5.0.0.sql   |  1 +
 htdocs/install/mysql/tables/llx_user.sql      |  1 +
 htdocs/langs/en_US/users.lang                 |  1 +
 htdocs/langs/fr_FR/users.lang                 |  1 +
 htdocs/user/card.php                          | 25 +++++++++++++++++++
 htdocs/user/class/user.class.php              | 12 ++++++++-
 6 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/htdocs/install/mysql/migration/4.0.0-5.0.0.sql b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql
index 81872e8d10d..a44cc81eef4 100644
--- a/htdocs/install/mysql/migration/4.0.0-5.0.0.sql
+++ b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql
@@ -24,6 +24,7 @@
 
 ALTER TABLE llx_user DROP COLUMN phenix_login;
 ALTER TABLE llx_user DROP COLUMN phenix_pass;
+ALTER TABLE llx_user ADD COLUMN dateemployment datetime;
 
 ALTER TABLE llx_societe ADD COLUMN fk_account integer;
 
diff --git a/htdocs/install/mysql/tables/llx_user.sql b/htdocs/install/mysql/tables/llx_user.sql
index 6b3c5b83f6d..84a36881020 100644
--- a/htdocs/install/mysql/tables/llx_user.sql
+++ b/htdocs/install/mysql/tables/llx_user.sql
@@ -80,5 +80,6 @@ create table llx_user
   tjm				double(24,8),
   salary			double(24,8),
   salaryextra		double(24,8),
+  dateemployment	datetime,
   weeklyhours		double(16,8)
 )ENGINE=innodb;
diff --git a/htdocs/langs/en_US/users.lang b/htdocs/langs/en_US/users.lang
index a8447504235..2c6eb77eec1 100644
--- a/htdocs/langs/en_US/users.lang
+++ b/htdocs/langs/en_US/users.lang
@@ -100,3 +100,4 @@ WeeklyHours=Weekly hours
 ColorUser=Color of the user
 DisabledInMonoUserMode=Disabled in maintenance mode
 UserAccountancyCode=User accountancy code
+DateEmployment=Date of Employment
diff --git a/htdocs/langs/fr_FR/users.lang b/htdocs/langs/fr_FR/users.lang
index 5e549f607a4..1000fd233d4 100644
--- a/htdocs/langs/fr_FR/users.lang
+++ b/htdocs/langs/fr_FR/users.lang
@@ -100,3 +100,4 @@ WeeklyHours=Heures de travail hebdomadaires
 ColorUser=Couleur de l'utilisateur
 DisabledInMonoUserMode=Désactivé en mode maintenance
 UserAccountancyCode=Code comptable utilisateur
+DateEmployment=Date d'embauche
diff --git a/htdocs/user/card.php b/htdocs/user/card.php
index 032628e4e67..bbbf738ddf2 100644
--- a/htdocs/user/card.php
+++ b/htdocs/user/card.php
@@ -215,7 +215,9 @@ if (empty($reshook)) {
 			$object->salaryextra = GETPOST("salaryextra") != '' ? GETPOST("salaryextra") : '';
 			$object->weeklyhours = GETPOST("weeklyhours") != '' ? GETPOST("weeklyhours") : '';
 
+			$date = dol_mktime(0, 0, 0, GETPOST('dateemploymentmonth'), GETPOST('dateemploymentday'), GETPOST('dateemploymentyear'));
 			$object->color = GETPOST("color") != '' ? GETPOST("color") : '';
+			$object->dateemployment = $date != '' ? $date : '';
 
 			// Fill array 'array_options' with data from add form
 			$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
@@ -360,6 +362,8 @@ if (empty($reshook)) {
 					$object->weeklyhours = GETPOST("weeklyhours") != '' ? GETPOST("weeklyhours") : '';
 
 					$object->color = GETPOST("color") != '' ? GETPOST("color") : '';
+					$date = dol_mktime(0, 0, 0, GETPOST('dateemploymentmonth'), GETPOST('dateemploymentday'), GETPOST('dateemploymentyear'));
+					$object->dateemployment = $date != '' ? $date : '';
 
 					if (! empty($conf->multicompany->enabled))
 					{
@@ -1060,6 +1064,13 @@ if (($action == 'create') || ($action == 'adduserldap'))
     print '<input size="8" type="text" name="weeklyhours" value="'.GETPOST('weeklyhours').'">';
     print '</td>';
     print "</tr>\n";
+	
+    // Date employment
+    print '<tr><td>'.$langs->trans("DateEmployment").'</td>';
+    print '<td>';
+	echo $form->select_date(GETPOST('dateemployment'),'dateemployment',0,0,1,'form'.'dateemployment',1,0,1);
+	print '</td>';
+    print "</tr>\n";
 
 	// Accountancy code
 	if ($conf->accounting->enabled)
@@ -1415,6 +1426,13 @@ else
 				print '<td>'.$object->accountancy_code.'</td>';
 			}
 
+		    // Date employment
+		    print '<tr><td>'.$langs->trans("DateEmployment").'</td>';
+		    print '<td>';
+			print $object->dateemployment;
+		    print '</td>';
+		    print "</tr>\n";
+
 			print '</table>';
 
 	        print '</div>';
@@ -2189,6 +2207,13 @@ else
 		    print '</td>';
 		    print "</tr>\n";
 
+		    // Date employment
+		    print '<tr><td>'.$langs->trans("DateEmployment").'</td>';
+		    print '<td>';
+			echo $form->select_date(GETPOST('dateemployment')?GETPOST('dateemployment'):$object->dateemployment,'dateemployment',0,0,1,'form'.'dateemployment',1,0,1);
+			print '</td>';
+		    print "</tr>\n";
+
 		    // Accountancy code
 			if ($conf->accounting->enabled)
     		{
diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php
index d10585fe12d..c26a040543d 100644
--- a/htdocs/user/class/user.class.php
+++ b/htdocs/user/class/user.class.php
@@ -122,6 +122,8 @@ class User extends CommonObject
 	var $weeklyhours;				// Weekly hours
 
 	var $color;						// Define background color for user in agenda
+	
+	var $dateemployment;			// Define date of employment by company
 
 	/**
 	 *    Constructor de la classe
@@ -187,6 +189,7 @@ class User extends CommonObject
 		$sql.= " u.salaryextra,";
 		$sql.= " u.weeklyhours,";
 		$sql.= " u.color,";
+		$sql.= " u.dateemployment,";
 		$sql.= " u.ref_int, u.ref_ext,";
         $sql.= " c.code as country_code, c.label as country,";
         $sql.= " d.code_departement as state_code, d.nom as state";
@@ -286,6 +289,7 @@ class User extends CommonObject
 				$this->salaryextra	= $obj->salaryextra;
 				$this->weeklyhours	= $obj->weeklyhours;
 				$this->color		= $obj->color;
+				$this->dateemployment	= $obj->dateemployment;
 
 				$this->datec				= $this->db->jdate($obj->datec);
 				$this->datem				= $this->db->jdate($obj->datem);
@@ -1260,6 +1264,7 @@ class User extends CommonObject
 		$this->town			= empty($this->town)?'':$this->town;
 		$this->accountancy_code = trim($this->accountancy_code);
 		$this->color 		= empty($this->color)?'':$this->color;
+		$this->dateemployment 	= empty($this->dateemployment)?'':$this->dateemployment;
 
 		// Check parameters
 		if (! empty($conf->global->USER_MAIL_REQUIRED) && ! isValidEMail($this->email))
@@ -1300,6 +1305,11 @@ class User extends CommonObject
 		$sql.= ", signature = '".$this->db->escape($this->signature)."'";
 		$sql.= ", accountancy_code = '".$this->db->escape($this->accountancy_code)."'";
 		$sql.= ", color = '".$this->db->escape($this->color)."'";
+		if (!empty($this->dateemployment)) {
+			$sql.= ", dateemployment = '".$this->db->idate($this->dateemployment)."'";
+		} else {
+			$sql.= ", dateemployment = NULL";
+		}
 		$sql.= ", note = '".$this->db->escape($this->note)."'";
 		$sql.= ", photo = ".($this->photo?"'".$this->db->escape($this->photo)."'":"null");
 		$sql.= ", openid = ".($this->openid?"'".$this->db->escape($this->openid)."'":"null");
@@ -1311,7 +1321,7 @@ class User extends CommonObject
 		$sql.= ", weeklyhours= ".($this->weeklyhours != ''?"'".$this->db->escape($this->weeklyhours)."'":"null");
 		$sql.= ", entity = '".$this->db->escape($this->entity)."'";
 		$sql.= " WHERE rowid = ".$this->id;
-
+		
 		dol_syslog(get_class($this)."::update", LOG_DEBUG);
 		$resql = $this->db->query($sql);
 		if ($resql)
-- 
GitLab