From d25778f12b8f9be9b53b9777d271690f591ed0f6 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Sun, 4 May 2014 16:59:13 +0200
Subject: [PATCH] Qual: Removed duplicate column "datea" into table llx_societe
 (duplicated with column tms).

---
 .../install/mysql/migration/3.5.0-3.6.0.sql   |  2 +
 htdocs/install/mysql/tables/llx_societe.sql   |  1 -
 htdocs/societe/class/address.class.php        | 25 +++++------
 htdocs/societe/class/societe.class.php        | 44 ++++++++++---------
 htdocs/webservices/server_thirdparty.php      |  4 +-
 5 files changed, 39 insertions(+), 37 deletions(-)

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 be4d8e0844c..30d3340e4c7 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
@@ -18,6 +18,8 @@
 -- -- VMYSQL4.1 DELETE FROM llx_usergroup_user      WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup);
 
 
+ALTER TABLE llx_societe DROP COLUMN datea;
+
 
 create table llx_c_email_templates
 (
diff --git a/htdocs/install/mysql/tables/llx_societe.sql b/htdocs/install/mysql/tables/llx_societe.sql
index 57e2f6eb26d..3182516b820 100644
--- a/htdocs/install/mysql/tables/llx_societe.sql
+++ b/htdocs/install/mysql/tables/llx_societe.sql
@@ -32,7 +32,6 @@ create table llx_societe
   parent                   integer,
   tms                      timestamp,
   datec	                   datetime,                            		-- creation date
-  datea	                   datetime,                            		-- activation date
 
   status            	   tinyint 		  DEFAULT 1,			        -- cessation d'activité ( 1 -- en activité, 0 -- cessation d'activité)						
 
diff --git a/htdocs/societe/class/address.class.php b/htdocs/societe/class/address.class.php
index 272baf034c3..aaf10b4e780 100644
--- a/htdocs/societe/class/address.class.php
+++ b/htdocs/societe/class/address.class.php
@@ -1,6 +1,6 @@
 <?php
 /* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2006 Laurent Destailleur  <eldy@users.sourceforge.net>
+ * Copyright (C) 2004-2014 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2005-2011 Regis Houssin        <regis.houssin@capnetworks.com>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -264,8 +264,7 @@ class Address
             // Adresses liees a la societe
 			if ($this->socid)
 			{
-				$sql = 'SELECT a.rowid as id, a.label, a.name, a.address, a.datec as dc';
-				$sql .= ', a.tms as date_update, a.fk_soc';
+				$sql = 'SELECT a.rowid as id, a.label, a.name, a.address, a.datec as date_creation, a.tms as date_modification, a.fk_soc';
 				$sql .= ', a.zip, a.town, a.note, a.fk_pays as country_id, a.phone, a.fax';
 				$sql .= ', p.code as country_code, p.libelle as country';
 				$sql .= ' FROM '.MAIN_DB_PREFIX.'societe_address as a';
@@ -284,8 +283,8 @@ class Address
 						$line = new AddressLine($this->db);
 
 						$line->id				= $objp->id;
-						$line->date_creation	= $this->db->jdate($objp->dc);
-						$line->date_update		= $this->db->jdate($objp->date_update);
+						$line->date_creation	 = $this->db->jdate($objp->date_creation);
+						$line->date_modification = $this->db->jdate($objp->date_modification);
 						$line->label			= $objp->label;
 						$line->name				= $objp->name;
 						$line->address			= $objp->address;
@@ -335,8 +334,7 @@ class Address
 		global $langs;
 		global $conf;
 
-		$sql = 'SELECT a.rowid, a.fk_soc, a.label, a.name, a.address, a.datec as date_creation';
-		$sql .= ', a.tms as date_update';
+		$sql = 'SELECT a.rowid, a.fk_soc, a.label, a.name, a.address, a.datec as date_creation, a.tms as date_modification';
 		$sql .= ', a.zip, a.town, a.note, a.fk_pays as country_id, a.phone, a.fax';
 		$sql .= ', p.code as country_code, p.libelle as country';
 		$sql .= ' FROM '.MAIN_DB_PREFIX.'societe_address as a';
@@ -352,7 +350,7 @@ class Address
 				$this->id				= $obj->rowid;
 				$this->socid			= $obj->fk_soc;
 
-				$this->date_update		= $this->db->jdate($obj->date_update);
+				$this->date_modification		= $this->db->jdate($obj->date_modification);
 				$this->date_creation 	= $this->db->jdate($obj->date_creation);
 
 				$this->label 			= $obj->label;
@@ -446,7 +444,7 @@ class Address
 	 */
 	function info($id)
 	{
-		$sql = "SELECT s.rowid, s.nom, datec, datea,";
+		$sql = "SELECT s.rowid, s.nom, datec as date_creation, datea as date_modification,";
 		$sql.= " fk_user_creat, fk_user_modif";
 		$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
 		$sql.= " WHERE s.rowid = ".$id;
@@ -472,8 +470,8 @@ class Address
 					$this->user_modification = $muser;
 				}
 				$this->ref			     = $obj->nom;
-				$this->date_creation     = $this->db->jdate($obj->datec);
-				$this->date_modification = $this->db->jdate($obj->datea);
+				$this->date_creation     = $this->db->jdate($obj->date_creation);
+				$this->date_modification = $this->db->jdate($obj->date_modification);
 			}
 
 			$this->db->free($result);
@@ -489,15 +487,14 @@ class Address
 
 
 /**
- *  \class 		AddressLine
- *  \brief 		Class to manage one address line
+ *  Class to manage one address line
  */
 class AddressLine
 {
 
 	var $id;
 	var $date_creation;
-	var $date_update;
+	var $date_modification;
 	var $label;
 	var $name;
 	var $address;
diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php
index dc7488c733f..8efc678a57d 100644
--- a/htdocs/societe/class/societe.class.php
+++ b/htdocs/societe/class/societe.class.php
@@ -130,8 +130,8 @@ class Societe extends CommonObject
     var $price_level;
     var $outstanding_limit;
 
-    var $datec;
-    var $date_update;
+    var $date_creation;
+    var $date_modification;
 
     var $commercial_id;  // Id of sales representative to link (used for thirdparty creation). Not filled by a fetch, because we can have several sales representatives.
     var $parent;
@@ -218,8 +218,8 @@ class Societe extends CommonObject
 
         if ($result >= 0)
         {
-            $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, entity, datec, datea, fk_user_creat, canvas, status, ref_int, ref_ext, fk_stcomm, import_key)";
-            $sql.= " VALUES ('".$this->db->escape($this->name)."', ".$conf->entity.", '".$this->db->idate($now)."', '".$this->db->idate($now)."'";
+            $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, entity, datec, fk_user_creat, canvas, status, ref_int, ref_ext, fk_stcomm, import_key)";
+            $sql.= " VALUES ('".$this->db->escape($this->name)."', ".$conf->entity.", '".$this->db->idate($now)."'";
             $sql.= ", ".(! empty($user->id) ? "'".$user->id."'":"null");
             $sql.= ", ".(! empty($this->canvas) ? "'".$this->canvas."'":"null");
             $sql.= ", ".$this->status;
@@ -535,7 +535,6 @@ class Societe extends CommonObject
             $sql  = "UPDATE ".MAIN_DB_PREFIX."societe SET ";
             $sql .= "nom = '" . $this->db->escape($this->name) ."'"; // Required
             $sql .= ",ref_ext = " .(! empty($this->ref_ext)?"'".$this->db->escape($this->ref_ext) ."'":"null");
-            $sql .= ",datea = '".$this->db->idate($now)."'";
             $sql .= ",address = '" . $this->db->escape($this->address) ."'";
 
             $sql .= ",zip = ".(! empty($this->zip)?"'".$this->zip."'":"null");
@@ -732,10 +731,10 @@ class Societe extends CommonObject
 
         if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($ref_int)) return -1;
 
-        $sql = 'SELECT s.rowid, s.nom as name, s.entity, s.ref_ext, s.ref_int, s.address, s.datec as datec, s.prefix_comm';
+        $sql = 'SELECT s.rowid, s.nom as name, s.entity, s.ref_ext, s.ref_int, s.address, s.datec as date_creation, s.prefix_comm';
         $sql .= ', s.status';
         $sql .= ', s.price_level';
-        $sql .= ', s.tms as date_update';
+        $sql .= ', s.tms as date_modification';
         $sql .= ', s.phone, s.fax, s.email, s.skype, s.url, s.zip, s.town, s.note_private, s.note_public, s.client, s.fournisseur';
         $sql .= ', s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6';
         $sql .= ', s.capital, s.tva_intra';
@@ -793,8 +792,8 @@ class Societe extends CommonObject
                 $this->ref_ext      = $obj->ref_ext;
                 $this->ref_int      = $obj->ref_int;
 
-                $this->datec = $this->db->jdate($obj->datec);
-                $this->date_update = $this->db->jdate($obj->date_update);
+                $this->date_creation = $this->db->jdate($obj->date_creation);
+                $this->date_modification = $this->db->jdate($obj->date_modification);
 
                 $this->address 		= $obj->address;
                 $this->zip 			= $obj->zip;
@@ -1382,17 +1381,21 @@ class Societe extends CommonObject
         {
         	$now=dol_now();
 
-            $sql  = "UPDATE ".MAIN_DB_PREFIX."societe ";
+            $sql  = "UPDATE ".MAIN_DB_PREFIX."societe";
             $sql .= " SET price_level = '".$price_level."'";
             $sql .= " WHERE rowid = " . $this->id;
 
-            $this->db->query($sql);
+            if (! $this->db->query($sql))
+            {
+                dol_print_error($this->db);
+                return -1;
+            }
 
-            $sql  = "INSERT INTO ".MAIN_DB_PREFIX."societe_prices ";
-            $sql .= " ( datec, fk_soc, price_level, fk_user_author )";
+            $sql  = "INSERT INTO ".MAIN_DB_PREFIX."societe_prices";
+            $sql .= " (datec, fk_soc, price_level, fk_user_author)";
             $sql .= " VALUES ('".$this->db->idate($now)."',".$this->id.",'".$price_level."',".$user->id.")";
 
-            if (! $this->db->query($sql) )
+            if (! $this->db->query($sql))
             {
                 dol_print_error($this->db);
                 return -1;
@@ -2334,14 +2337,14 @@ class Societe extends CommonObject
 
 
     /**
-     *  Charge les informations d'ordre info dans l'objet societe
+     *  Load information for tab info
      *
-     *  @param  int		$id     Id de la societe a charger
+     *  @param  int		$id     Id of thirdparty to load
      *  @return	void
      */
     function info($id)
     {
-        $sql = "SELECT s.rowid, s.nom as name, s.datec, s.datea,";
+        $sql = "SELECT s.rowid, s.nom as name, s.datec as date_creation, tms as date_modification,";
         $sql.= " fk_user_creat, fk_user_modif";
         $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
         $sql.= " WHERE s.rowid = ".$id;
@@ -2366,16 +2369,17 @@ class Societe extends CommonObject
                     $muser->fetch($obj->fk_user_modif);
                     $this->user_modification = $muser;
                 }
+
                 $this->ref			     = $obj->name;
-                $this->date_creation     = $this->db->jdate($obj->datec);
-                $this->date_modification = $this->db->jdate($obj->datea);
+                $this->date_creation     = $this->db->jdate($obj->date_creation);
+                $this->date_modification = $this->db->jdate($obj->date_modification);
             }
 
             $this->db->free($result);
 
         }
         else
-        {
+		{
             dol_print_error($this->db);
         }
     }
diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php
index 6010306a98a..c5ac0c8c686 100644
--- a/htdocs/webservices/server_thirdparty.php
+++ b/htdocs/webservices/server_thirdparty.php
@@ -303,8 +303,8 @@ function getThirdParty($authentication,$id='',$ref='',$ref_ext='')
 				        'customer_code_accountancy' => $thirdparty->code_compta,
 			            'supplier_code_accountancy' => $thirdparty->code_compta_fournisseur,
 			            'fk_user_author' => $thirdparty->fk_user_author,
-			    		'date_creation' => dol_print_date($thirdparty->datec,'dayhourrfc'),
-			    		'date_modification' => dol_print_date($thirdparty->date_update,'dayhourrfc'),
+			    		'date_creation' => dol_print_date($thirdparty->date_creation,'dayhourrfc'),
+			    		'date_modification' => dol_print_date($thirdparty->date_modification,'dayhourrfc'),
 			            'address' => $thirdparty->address,
 				        'zip' => $thirdparty->zip,
 				        'town' => $thirdparty->town,
-- 
GitLab