Test Failed
Push — master ( 2740c1...0ba343 )
by Alxarafe
43:23 queued 04:12
created
dolibarr/htdocs/societe/class/societeaccount.class.php 3 patches
Indentation   +452 added lines, -452 removed lines patch added patch discarded remove patch
@@ -35,320 +35,320 @@  discard block
 block discarded – undo
35 35
  */
36 36
 class SocieteAccount extends CommonObject
37 37
 {
38
-	/**
39
-	 * @var string ID to identify managed object
40
-	 */
41
-	public $element = 'societeaccount';
42
-
43
-	/**
44
-	 * @var string Name of table without prefix where object is stored
45
-	 */
46
-	public $table_element = 'societe_account';
47
-
48
-	/**
49
-	 * @var array  Does societeaccount support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
50
-	 */
51
-	public $ismultientitymanaged = 0;
52
-
53
-	/**
54
-	 * @var string String with name of icon for societeaccount. Must be the part after the 'object_' into object_myobject.png
55
-	 */
56
-	public $picto = 'lock';
57
-
58
-
59
-	/**
60
-	 *  'type' if the field format.
61
-	 *  'label' the translation key.
62
-	 *  'enabled' is a condition when the field must be managed.
63
-	 *  'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing)
64
-	 *  'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
65
-	 *  'index' if we want an index in database.
66
-	 *  'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
67
-	 *  'position' is the sort order of field.
68
-	 *  'searchall' is 1 if we want to search in this field when making a search from the quick search button.
69
-	 *  'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
70
-	 *  'help' is a string visible as a tooltip on field
71
-	 *  'comment' is not used. You can store here any text of your choice. It is not used by application.
72
-	 *  'default' is a default value for creation (can still be replaced by the global setup of default values)
73
-	 *  'showoncombobox' if field must be shown into the label of combobox
74
-	 */
75
-
76
-	// BEGIN MODULEBUILDER PROPERTIES
77
-	/**
78
-	 * @var array  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
79
-	 */
80
-	public $fields=array(
81
-		'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>-2, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>'Id',),
82
-		'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>0, 'enabled'=>1, 'position'=>5, 'default'=>1),
83
-		'key_account' => array('type'=>'varchar(128)', 'label'=>'KeyAccount', 'visible'=>-1, 'enabled'=>1, 'position'=>10, 'notnull'=>1, 'index'=>1, 'searchall'=>1, 'comment'=>'Key account',),
84
-		'login' => array('type'=>'varchar(64)', 'label'=>'Login', 'visible'=>1, 'enabled'=>1, 'position'=>10),
85
-		'pass_encoding' => array('type'=>'varchar(24)', 'label'=>'PassEncoding', 'visible'=>0, 'enabled'=>1, 'position'=>30),
86
-		'pass_crypted' => array('type'=>'varchar(128)', 'label'=>'Password', 'visible'=>1, 'enabled'=>1, 'position'=>31, 'notnull'=>1),
87
-		'pass_temp'    => array('type'=>'varchar(128)', 'label'=>'Temp', 'visible'=>0, 'enabled'=>0, 'position'=>32, 'notnull'=>-1,),
88
-		'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'visible'=>1, 'enabled'=>1, 'position'=>40, 'notnull'=>-1, 'index'=>1),
89
-		'site' => array('type'=>'varchar(128)', 'label'=>'Site', 'visible'=>-1, 'enabled'=>1, 'position'=>41),
90
-		'fk_website' => array('type'=>'integer:Website:website/class/website.class.php', 'label'=>'WebSite', 'visible'=>1, 'enabled'=>1, 'position'=>42, 'notnull'=>-1, 'index'=>1),
91
-		'date_last_login' => array('type'=>'datetime', 'label'=>'LastConnexion', 'visible'=>2, 'enabled'=>1, 'position'=>50, 'notnull'=>0,),
92
-		'date_previous_login' => array('type'=>'datetime', 'label'=>'PreviousConnexion', 'visible'=>2, 'enabled'=>1, 'position'=>51, 'notnull'=>0,),
93
-		//'note_public' => array('type'=>'text', 'label'=>'NotePublic', 'visible'=>-1, 'enabled'=>1, 'position'=>45, 'notnull'=>-1,),
94
-		'note_private' => array('type'=>'text', 'label'=>'NotePrivate', 'visible'=>-1, 'enabled'=>1, 'position'=>46, 'notnull'=>-1,),
95
-		'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
96
-		'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
97
-		'fk_user_creat' => array('type'=>'integer', 'label'=>'UserAuthor', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
98
-		'fk_user_modif' => array('type'=>'integer', 'label'=>'UserModif', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>-1,),
99
-		'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'visible'=>-2, 'enabled'=>1, 'position'=>1000, 'notnull'=>-1, 'index'=>1,),
100
-		'status' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>1000, 'notnull'=>1, 'index'=>1, 'default'=>1, 'arrayofkeyval'=>array('1'=>'Active','0'=>'Disabled')),
101
-	);
102
-
103
-	/**
104
-	 * @var int ID
105
-	 */
106
-	public $rowid;
107
-
108
-	/**
109
-	 * @var int Entity
110
-	 */
111
-	public $entity;
112
-
113
-	public $key_account;
114
-	public $login;
115
-	public $pass_encoding;
116
-	public $pass_crypted;
117
-	public $pass_temp;
118
-
119
-	/**
120
-	 * @var int Thirdparty ID
121
-	 */
38
+    /**
39
+     * @var string ID to identify managed object
40
+     */
41
+    public $element = 'societeaccount';
42
+
43
+    /**
44
+     * @var string Name of table without prefix where object is stored
45
+     */
46
+    public $table_element = 'societe_account';
47
+
48
+    /**
49
+     * @var array  Does societeaccount support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
50
+     */
51
+    public $ismultientitymanaged = 0;
52
+
53
+    /**
54
+     * @var string String with name of icon for societeaccount. Must be the part after the 'object_' into object_myobject.png
55
+     */
56
+    public $picto = 'lock';
57
+
58
+
59
+    /**
60
+     *  'type' if the field format.
61
+     *  'label' the translation key.
62
+     *  'enabled' is a condition when the field must be managed.
63
+     *  'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing)
64
+     *  'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
65
+     *  'index' if we want an index in database.
66
+     *  'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
67
+     *  'position' is the sort order of field.
68
+     *  'searchall' is 1 if we want to search in this field when making a search from the quick search button.
69
+     *  'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
70
+     *  'help' is a string visible as a tooltip on field
71
+     *  'comment' is not used. You can store here any text of your choice. It is not used by application.
72
+     *  'default' is a default value for creation (can still be replaced by the global setup of default values)
73
+     *  'showoncombobox' if field must be shown into the label of combobox
74
+     */
75
+
76
+    // BEGIN MODULEBUILDER PROPERTIES
77
+    /**
78
+     * @var array  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
79
+     */
80
+    public $fields=array(
81
+        'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>-2, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>'Id',),
82
+        'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>0, 'enabled'=>1, 'position'=>5, 'default'=>1),
83
+        'key_account' => array('type'=>'varchar(128)', 'label'=>'KeyAccount', 'visible'=>-1, 'enabled'=>1, 'position'=>10, 'notnull'=>1, 'index'=>1, 'searchall'=>1, 'comment'=>'Key account',),
84
+        'login' => array('type'=>'varchar(64)', 'label'=>'Login', 'visible'=>1, 'enabled'=>1, 'position'=>10),
85
+        'pass_encoding' => array('type'=>'varchar(24)', 'label'=>'PassEncoding', 'visible'=>0, 'enabled'=>1, 'position'=>30),
86
+        'pass_crypted' => array('type'=>'varchar(128)', 'label'=>'Password', 'visible'=>1, 'enabled'=>1, 'position'=>31, 'notnull'=>1),
87
+        'pass_temp'    => array('type'=>'varchar(128)', 'label'=>'Temp', 'visible'=>0, 'enabled'=>0, 'position'=>32, 'notnull'=>-1,),
88
+        'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'visible'=>1, 'enabled'=>1, 'position'=>40, 'notnull'=>-1, 'index'=>1),
89
+        'site' => array('type'=>'varchar(128)', 'label'=>'Site', 'visible'=>-1, 'enabled'=>1, 'position'=>41),
90
+        'fk_website' => array('type'=>'integer:Website:website/class/website.class.php', 'label'=>'WebSite', 'visible'=>1, 'enabled'=>1, 'position'=>42, 'notnull'=>-1, 'index'=>1),
91
+        'date_last_login' => array('type'=>'datetime', 'label'=>'LastConnexion', 'visible'=>2, 'enabled'=>1, 'position'=>50, 'notnull'=>0,),
92
+        'date_previous_login' => array('type'=>'datetime', 'label'=>'PreviousConnexion', 'visible'=>2, 'enabled'=>1, 'position'=>51, 'notnull'=>0,),
93
+        //'note_public' => array('type'=>'text', 'label'=>'NotePublic', 'visible'=>-1, 'enabled'=>1, 'position'=>45, 'notnull'=>-1,),
94
+        'note_private' => array('type'=>'text', 'label'=>'NotePrivate', 'visible'=>-1, 'enabled'=>1, 'position'=>46, 'notnull'=>-1,),
95
+        'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
96
+        'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
97
+        'fk_user_creat' => array('type'=>'integer', 'label'=>'UserAuthor', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
98
+        'fk_user_modif' => array('type'=>'integer', 'label'=>'UserModif', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>-1,),
99
+        'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'visible'=>-2, 'enabled'=>1, 'position'=>1000, 'notnull'=>-1, 'index'=>1,),
100
+        'status' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>1000, 'notnull'=>1, 'index'=>1, 'default'=>1, 'arrayofkeyval'=>array('1'=>'Active','0'=>'Disabled')),
101
+    );
102
+
103
+    /**
104
+     * @var int ID
105
+     */
106
+    public $rowid;
107
+
108
+    /**
109
+     * @var int Entity
110
+     */
111
+    public $entity;
112
+
113
+    public $key_account;
114
+    public $login;
115
+    public $pass_encoding;
116
+    public $pass_crypted;
117
+    public $pass_temp;
118
+
119
+    /**
120
+     * @var int Thirdparty ID
121
+     */
122 122
     public $fk_soc;
123 123
 
124
-	public $site;
125
-	public $date_last_login;
126
-	public $date_previous_login;
127
-	public $note_private;
128
-	public $date_creation;
129
-	public $tms;
124
+    public $site;
125
+    public $date_last_login;
126
+    public $date_previous_login;
127
+    public $note_private;
128
+    public $date_creation;
129
+    public $tms;
130 130
 
131
-	/**
131
+    /**
132 132
      * @var int ID
133 133
      */
134
-	public $fk_user_creat;
134
+    public $fk_user_creat;
135 135
 
136
-	/**
136
+    /**
137 137
      * @var int ID
138 138
      */
139
-	public $fk_user_modif;
140
-
141
-	public $import_key;
142
-
143
-	/**
144
-	 * @var int Status
145
-	 */
146
-	public $status;
147
-
148
-	// END MODULEBUILDER PROPERTIES
149
-
150
-
151
-
152
-
153
-	// If this object has a subtable with lines
154
-
155
-	/**
156
-	 * @var int    Name of subtable line
157
-	 */
158
-	//public $table_element_line = 'societe_accountdet';
159
-	/**
160
-	 * @var int    Field with ID of parent key if this field has a parent
161
-	 */
162
-	//public $fk_element = 'fk_societe_account';
163
-	/**
164
-	 * @var int    Name of subtable class that manage subtable lines
165
-	 */
166
-	//public $class_element_line = 'societeAccountline';
167
-	/**
168
-	 * @var array  Array of child tables (child tables to delete before deleting a record)
169
-	 */
170
-	//protected $childtables=array('societe_accountdet');
171
-	/**
172
-	 * @var societeAccountLine[]     Array of subtable lines
173
-	 */
174
-	//public $lines = array();
175
-
176
-
177
-
178
-	/**
179
-	 * Constructor
180
-	 *
181
-	 * @param DoliDb $db Database handler
182
-	 */
183
-	public function __construct(DoliDB $db)
184
-	{
185
-		global $conf;
186
-
187
-		$this->db = $db;
188
-
189
-		if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->fields['rowid']['visible']=0;
190
-	}
191
-
192
-	/**
193
-	 * Create object into database
194
-	 *
195
-	 * @param  User $user      User that creates
196
-	 * @param  bool $notrigger false=launch triggers after, true=disable triggers
197
-	 * @return int             <0 if KO, Id of created object if OK
198
-	 */
199
-	public function create(User $user, $notrigger = false)
200
-	{
201
-		return $this->createCommon($user, $notrigger);
202
-	}
203
-
204
-	/**
205
-	 * Clone and object into another one
206
-	 *
207
-	 * @param  	User 	$user      	User that creates
208
-	 * @param  	int 	$fromid     Id of object to clone
209
-	 * @return 	mixed 				New object created, <0 if KO
210
-	 */
211
-	public function createFromClone(User $user, $fromid)
212
-	{
213
-		global $hookmanager, $langs;
214
-	    $error = 0;
215
-
216
-	    dol_syslog(__METHOD__, LOG_DEBUG);
217
-
218
-	    $object = new self($this->db);
219
-
220
-	    $this->db->begin();
221
-
222
-	    // Load source object
223
-	    $object->fetchCommon($fromid);
224
-	    // Reset some properties
225
-	    unset($object->id);
226
-	    unset($object->fk_user_creat);
227
-	    unset($object->import_key);
228
-
229
-	    // Clear fields
230
-	    $object->ref = "copy_of_".$object->ref;
231
-	    $object->title = $langs->trans("CopyOf")." ".$object->title;
232
-	    // ...
233
-
234
-	    // Create clone
235
-		$object->context['createfromclone'] = 'createfromclone';
236
-	    $result = $object->createCommon($user);
237
-	    if ($result < 0) {
238
-	        $error++;
239
-	        $this->error = $object->error;
240
-	        $this->errors = $object->errors;
241
-	    }
242
-
243
-	    // End
244
-	    if (!$error) {
245
-	        $this->db->commit();
246
-	        return $object;
247
-	    } else {
248
-	        $this->db->rollback();
249
-	        return -1;
250
-	    }
251
-	}
252
-
253
-	/**
254
-	 * Load object in memory from the database
255
-	 *
256
-	 * @param int    $id   Id object
257
-	 * @param string $ref  Ref
258
-	 * @return int         <0 if KO, 0 if not found, >0 if OK
259
-	 */
260
-	public function fetch($id, $ref = null)
261
-	{
262
-		$result = $this->fetchCommon($id, $ref);
263
-		if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();
264
-		return $result;
265
-	}
266
-
267
-	/**
268
-	 * Load object lines in memory from the database
269
-	 *
270
-	 * @return int         <0 if KO, 0 if not found, >0 if OK
271
-	 */
272
-	public function fetchLines()
273
-	{
274
-		$this->lines=array();
275
-
276
-		// Load lines with object societeAccountLine
277
-
278
-		return count($this->lines)?1:0;
279
-	}
280
-
281
-	/**
282
-	 * Try to find the external customer id of a thirdparty for an another site/system.
283
-	 *
284
-	 * @param	int		$id			Id of third party
285
-	 * @param	string	$site		Site (example: 'stripe', '...')
286
-	 * @param	int		$status		Status (0=test, 1=live)
287
-	 * @return	string				Stripe customer ref 'cu_xxxxxxxxxxxxx' or ''
288
-	 */
289
-	public function getCustomerAccount($id, $site, $status=0)
290
-	{
291
-		$sql = "SELECT sa.key_account as key_account, sa.entity";
292
-		$sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa";
293
-		$sql.= " WHERE sa.fk_soc = " . $id;
294
-		$sql.= " AND sa.entity IN (".getEntity('societe').")";
295
-		$sql.= " AND sa.site = '".$this->db->escape($site)."' AND sa.status = ".((int) $status);
296
-		$sql.= " AND key_account IS NOT NULL AND key_account <> ''";
297
-		//$sql.= " ORDER BY sa.key_account DESC";
298
-
299
-		dol_syslog(get_class($this) . "::getCustomerAccount Try to find the first system customer id for ".$site." of thirdparty id=".$id." (exemple: cus_.... for stripe)", LOG_DEBUG);
300
-		$result = $this->db->query($sql);
301
-		if ($result) {
302
-			if ($this->db->num_rows($result)) {
303
-				$obj = $this->db->fetch_object($result);
304
-				$key = $obj->key_account;
305
-			} else {
306
-				$key = '';
307
-			}
308
-		} else {
309
-			$key = '';
310
-		}
311
-
312
-		return $key;
313
-	}
314
-
315
-	/**
316
-	 * Update object into database
317
-	 *
318
-	 * @param  User $user      User that modifies
319
-	 * @param  bool $notrigger false=launch triggers after, true=disable triggers
320
-	 * @return int             <0 if KO, >0 if OK
321
-	 */
322
-	public function update(User $user, $notrigger = false)
323
-	{
324
-		return $this->updateCommon($user, $notrigger);
325
-	}
326
-
327
-	/**
328
-	 * Delete object in database
329
-	 *
330
-	 * @param User $user       User that deletes
331
-	 * @param bool $notrigger  false=launch triggers after, true=disable triggers
332
-	 * @return int             <0 if KO, >0 if OK
333
-	 */
334
-	public function delete(User $user, $notrigger = false)
335
-	{
336
-		return $this->deleteCommon($user, $notrigger);
337
-	}
338
-
339
-	/**
340
-	 *  Return a link to the object card (with optionaly the picto)
341
-	 *
342
-	 *	@param	int		$withpicto					Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
343
-	 *	@param	string	$option						On what the link point to ('nolink', ...)
139
+    public $fk_user_modif;
140
+
141
+    public $import_key;
142
+
143
+    /**
144
+     * @var int Status
145
+     */
146
+    public $status;
147
+
148
+    // END MODULEBUILDER PROPERTIES
149
+
150
+
151
+
152
+
153
+    // If this object has a subtable with lines
154
+
155
+    /**
156
+     * @var int    Name of subtable line
157
+     */
158
+    //public $table_element_line = 'societe_accountdet';
159
+    /**
160
+     * @var int    Field with ID of parent key if this field has a parent
161
+     */
162
+    //public $fk_element = 'fk_societe_account';
163
+    /**
164
+     * @var int    Name of subtable class that manage subtable lines
165
+     */
166
+    //public $class_element_line = 'societeAccountline';
167
+    /**
168
+     * @var array  Array of child tables (child tables to delete before deleting a record)
169
+     */
170
+    //protected $childtables=array('societe_accountdet');
171
+    /**
172
+     * @var societeAccountLine[]     Array of subtable lines
173
+     */
174
+    //public $lines = array();
175
+
176
+
177
+
178
+    /**
179
+     * Constructor
180
+     *
181
+     * @param DoliDb $db Database handler
182
+     */
183
+    public function __construct(DoliDB $db)
184
+    {
185
+        global $conf;
186
+
187
+        $this->db = $db;
188
+
189
+        if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->fields['rowid']['visible']=0;
190
+    }
191
+
192
+    /**
193
+     * Create object into database
194
+     *
195
+     * @param  User $user      User that creates
196
+     * @param  bool $notrigger false=launch triggers after, true=disable triggers
197
+     * @return int             <0 if KO, Id of created object if OK
198
+     */
199
+    public function create(User $user, $notrigger = false)
200
+    {
201
+        return $this->createCommon($user, $notrigger);
202
+    }
203
+
204
+    /**
205
+     * Clone and object into another one
206
+     *
207
+     * @param  	User 	$user      	User that creates
208
+     * @param  	int 	$fromid     Id of object to clone
209
+     * @return 	mixed 				New object created, <0 if KO
210
+     */
211
+    public function createFromClone(User $user, $fromid)
212
+    {
213
+        global $hookmanager, $langs;
214
+        $error = 0;
215
+
216
+        dol_syslog(__METHOD__, LOG_DEBUG);
217
+
218
+        $object = new self($this->db);
219
+
220
+        $this->db->begin();
221
+
222
+        // Load source object
223
+        $object->fetchCommon($fromid);
224
+        // Reset some properties
225
+        unset($object->id);
226
+        unset($object->fk_user_creat);
227
+        unset($object->import_key);
228
+
229
+        // Clear fields
230
+        $object->ref = "copy_of_".$object->ref;
231
+        $object->title = $langs->trans("CopyOf")." ".$object->title;
232
+        // ...
233
+
234
+        // Create clone
235
+        $object->context['createfromclone'] = 'createfromclone';
236
+        $result = $object->createCommon($user);
237
+        if ($result < 0) {
238
+            $error++;
239
+            $this->error = $object->error;
240
+            $this->errors = $object->errors;
241
+        }
242
+
243
+        // End
244
+        if (!$error) {
245
+            $this->db->commit();
246
+            return $object;
247
+        } else {
248
+            $this->db->rollback();
249
+            return -1;
250
+        }
251
+    }
252
+
253
+    /**
254
+     * Load object in memory from the database
255
+     *
256
+     * @param int    $id   Id object
257
+     * @param string $ref  Ref
258
+     * @return int         <0 if KO, 0 if not found, >0 if OK
259
+     */
260
+    public function fetch($id, $ref = null)
261
+    {
262
+        $result = $this->fetchCommon($id, $ref);
263
+        if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();
264
+        return $result;
265
+    }
266
+
267
+    /**
268
+     * Load object lines in memory from the database
269
+     *
270
+     * @return int         <0 if KO, 0 if not found, >0 if OK
271
+     */
272
+    public function fetchLines()
273
+    {
274
+        $this->lines=array();
275
+
276
+        // Load lines with object societeAccountLine
277
+
278
+        return count($this->lines)?1:0;
279
+    }
280
+
281
+    /**
282
+     * Try to find the external customer id of a thirdparty for an another site/system.
283
+     *
284
+     * @param	int		$id			Id of third party
285
+     * @param	string	$site		Site (example: 'stripe', '...')
286
+     * @param	int		$status		Status (0=test, 1=live)
287
+     * @return	string				Stripe customer ref 'cu_xxxxxxxxxxxxx' or ''
288
+     */
289
+    public function getCustomerAccount($id, $site, $status=0)
290
+    {
291
+        $sql = "SELECT sa.key_account as key_account, sa.entity";
292
+        $sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa";
293
+        $sql.= " WHERE sa.fk_soc = " . $id;
294
+        $sql.= " AND sa.entity IN (".getEntity('societe').")";
295
+        $sql.= " AND sa.site = '".$this->db->escape($site)."' AND sa.status = ".((int) $status);
296
+        $sql.= " AND key_account IS NOT NULL AND key_account <> ''";
297
+        //$sql.= " ORDER BY sa.key_account DESC";
298
+
299
+        dol_syslog(get_class($this) . "::getCustomerAccount Try to find the first system customer id for ".$site." of thirdparty id=".$id." (exemple: cus_.... for stripe)", LOG_DEBUG);
300
+        $result = $this->db->query($sql);
301
+        if ($result) {
302
+            if ($this->db->num_rows($result)) {
303
+                $obj = $this->db->fetch_object($result);
304
+                $key = $obj->key_account;
305
+            } else {
306
+                $key = '';
307
+            }
308
+        } else {
309
+            $key = '';
310
+        }
311
+
312
+        return $key;
313
+    }
314
+
315
+    /**
316
+     * Update object into database
317
+     *
318
+     * @param  User $user      User that modifies
319
+     * @param  bool $notrigger false=launch triggers after, true=disable triggers
320
+     * @return int             <0 if KO, >0 if OK
321
+     */
322
+    public function update(User $user, $notrigger = false)
323
+    {
324
+        return $this->updateCommon($user, $notrigger);
325
+    }
326
+
327
+    /**
328
+     * Delete object in database
329
+     *
330
+     * @param User $user       User that deletes
331
+     * @param bool $notrigger  false=launch triggers after, true=disable triggers
332
+     * @return int             <0 if KO, >0 if OK
333
+     */
334
+    public function delete(User $user, $notrigger = false)
335
+    {
336
+        return $this->deleteCommon($user, $notrigger);
337
+    }
338
+
339
+    /**
340
+     *  Return a link to the object card (with optionaly the picto)
341
+     *
342
+     *	@param	int		$withpicto					Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
343
+     *	@param	string	$option						On what the link point to ('nolink', ...)
344 344
      *  @param	int  	$notooltip					1=Disable tooltip
345 345
      *  @param  string  $morecss            		Add more css on link
346 346
      *  @param  int     $save_lastsearch_value    	-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
347
-	 *	@return	string								String with URL
348
-	 */
349
-	function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
350
-	{
351
-		global $db, $conf, $langs;
347
+     *	@return	string								String with URL
348
+     */
349
+    function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
350
+    {
351
+        global $db, $conf, $langs;
352 352
         global $dolibarr_main_authentication, $dolibarr_main_demo;
353 353
         global $menumanager;
354 354
 
@@ -368,10 +368,10 @@  discard block
 block discarded – undo
368 368
 
369 369
         if ($option != 'nolink')
370 370
         {
371
-	        // Add param to save lastsearch_values or not
372
-	        $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
373
-	        if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
374
-	        if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
371
+            // Add param to save lastsearch_values or not
372
+            $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
373
+            if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
374
+            if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
375 375
         }
376 376
 
377 377
         $linkclose='';
@@ -387,152 +387,152 @@  discard block
 block discarded – undo
387 387
         }
388 388
         else $linkclose = ($morecss?' class="'.$morecss.'"':'');
389 389
 
390
-		$linkstart = '<a href="'.$url.'"';
391
-		$linkstart.=$linkclose.'>';
392
-		$linkend='</a>';
393
-
394
-		$result .= $linkstart;
395
-		if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
396
-		if ($withpicto != 2) $result.= $this->ref;
397
-		$result .= $linkend;
398
-
399
-		return $result;
400
-	}
401
-
402
-	/**
403
-	 * Return link to download file from a direct external access
404
-	 *
405
-	 * @param	int				$withpicto			Add download picto into link
406
-	 * @return	string			HTML link to file
407
-	 */
408
-	function getDirectExternalLink($withpicto=0)
409
-	{
410
-		return 'todo';
411
-	}
412
-
413
-	/**
414
-	 *  Retourne le libelle du status d'un user (actif, inactif)
415
-	 *
416
-	 *  @param	int		$mode          0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
417
-	 *  @return	string 			       Label of status
418
-	 */
419
-	function getLibStatut($mode=0)
420
-	{
421
-		return $this->LibStatut($this->status,$mode);
422
-	}
390
+        $linkstart = '<a href="'.$url.'"';
391
+        $linkstart.=$linkclose.'>';
392
+        $linkend='</a>';
393
+
394
+        $result .= $linkstart;
395
+        if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
396
+        if ($withpicto != 2) $result.= $this->ref;
397
+        $result .= $linkend;
398
+
399
+        return $result;
400
+    }
401
+
402
+    /**
403
+     * Return link to download file from a direct external access
404
+     *
405
+     * @param	int				$withpicto			Add download picto into link
406
+     * @return	string			HTML link to file
407
+     */
408
+    function getDirectExternalLink($withpicto=0)
409
+    {
410
+        return 'todo';
411
+    }
412
+
413
+    /**
414
+     *  Retourne le libelle du status d'un user (actif, inactif)
415
+     *
416
+     *  @param	int		$mode          0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
417
+     *  @return	string 			       Label of status
418
+     */
419
+    function getLibStatut($mode=0)
420
+    {
421
+        return $this->LibStatut($this->status,$mode);
422
+    }
423 423
 
424 424
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
425
-	/**
426
-	 *  Return the status
427
-	 *
428
-	 *  @param	int		$status        	Id status
429
-	 *  @param  int		$mode          	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
430
-	 *  @return string 			       	Label of status
431
-	 */
432
-	static function LibStatut($status,$mode=0)
433
-	{
425
+    /**
426
+     *  Return the status
427
+     *
428
+     *  @param	int		$status        	Id status
429
+     *  @param  int		$mode          	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
430
+     *  @return string 			       	Label of status
431
+     */
432
+    static function LibStatut($status,$mode=0)
433
+    {
434 434
         // phpcs:enable
435
-		global $langs;
436
-
437
-		if ($mode == 0)
438
-		{
439
-			$prefix='';
440
-			if ($status == 1) return $langs->trans('Enabled');
441
-			elseif ($status == 0) return $langs->trans('Disabled');
442
-		}
443
-		elseif ($mode == 1)
444
-		{
445
-			if ($status == 1) return $langs->trans('Enabled');
446
-			elseif ($status == 0) return $langs->trans('Disabled');
447
-		}
448
-		elseif ($mode == 2)
449
-		{
450
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
451
-			elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
452
-		}
453
-		elseif ($mode == 3)
454
-		{
455
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4');
456
-			elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5');
457
-		}
458
-		elseif ($mode == 4)
459
-		{
460
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
461
-			elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
462
-		}
463
-		elseif ($mode == 5)
464
-		{
465
-			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
466
-			elseif ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
467
-		}
468
-		elseif ($mode == 6)
469
-		{
470
-			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
471
-			elseif ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
472
-		}
473
-	}
474
-
475
-	/**
476
-	 *	Charge les informations d'ordre info dans l'objet commande
477
-	 *
478
-	 *	@param  int		$id       Id of order
479
-	 *	@return	void
480
-	 */
481
-	function info($id)
482
-	{
483
-		$sql = 'SELECT rowid, date_creation as datec, tms as datem,';
484
-		$sql.= ' fk_user_creat, fk_user_modif';
485
-		$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
486
-		$sql.= ' WHERE t.rowid = '.$id;
487
-		$result=$this->db->query($sql);
488
-		if ($result)
489
-		{
490
-			if ($this->db->num_rows($result))
491
-			{
492
-				$obj = $this->db->fetch_object($result);
493
-				$this->id = $obj->rowid;
494
-				if ($obj->fk_user_author)
495
-				{
496
-					$cuser = new User($this->db);
497
-					$cuser->fetch($obj->fk_user_author);
498
-					$this->user_creation   = $cuser;
499
-				}
500
-
501
-				if ($obj->fk_user_valid)
502
-				{
503
-					$vuser = new User($this->db);
504
-					$vuser->fetch($obj->fk_user_valid);
505
-					$this->user_validation = $vuser;
506
-				}
507
-
508
-				if ($obj->fk_user_cloture)
509
-				{
510
-					$cluser = new User($this->db);
511
-					$cluser->fetch($obj->fk_user_cloture);
512
-					$this->user_cloture   = $cluser;
513
-				}
514
-
515
-				$this->date_creation     = $this->db->jdate($obj->datec);
516
-				$this->date_modification = $this->db->jdate($obj->datem);
517
-				$this->date_validation   = $this->db->jdate($obj->datev);
518
-			}
519
-
520
-			$this->db->free($result);
521
-		}
522
-		else
523
-		{
524
-			dol_print_error($this->db);
525
-		}
526
-	}
527
-
528
-	/**
529
-	 * Initialise object with example values
530
-	 * Id must be 0 if object instance is a specimen
531
-	 *
532
-	 * @return void
533
-	 */
534
-	public function initAsSpecimen()
535
-	{
536
-		$this->initAsSpecimenCommon();
537
-	}
435
+        global $langs;
436
+
437
+        if ($mode == 0)
438
+        {
439
+            $prefix='';
440
+            if ($status == 1) return $langs->trans('Enabled');
441
+            elseif ($status == 0) return $langs->trans('Disabled');
442
+        }
443
+        elseif ($mode == 1)
444
+        {
445
+            if ($status == 1) return $langs->trans('Enabled');
446
+            elseif ($status == 0) return $langs->trans('Disabled');
447
+        }
448
+        elseif ($mode == 2)
449
+        {
450
+            if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
451
+            elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
452
+        }
453
+        elseif ($mode == 3)
454
+        {
455
+            if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4');
456
+            elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5');
457
+        }
458
+        elseif ($mode == 4)
459
+        {
460
+            if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
461
+            elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
462
+        }
463
+        elseif ($mode == 5)
464
+        {
465
+            if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
466
+            elseif ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
467
+        }
468
+        elseif ($mode == 6)
469
+        {
470
+            if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
471
+            elseif ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
472
+        }
473
+    }
474
+
475
+    /**
476
+     *	Charge les informations d'ordre info dans l'objet commande
477
+     *
478
+     *	@param  int		$id       Id of order
479
+     *	@return	void
480
+     */
481
+    function info($id)
482
+    {
483
+        $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
484
+        $sql.= ' fk_user_creat, fk_user_modif';
485
+        $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
486
+        $sql.= ' WHERE t.rowid = '.$id;
487
+        $result=$this->db->query($sql);
488
+        if ($result)
489
+        {
490
+            if ($this->db->num_rows($result))
491
+            {
492
+                $obj = $this->db->fetch_object($result);
493
+                $this->id = $obj->rowid;
494
+                if ($obj->fk_user_author)
495
+                {
496
+                    $cuser = new User($this->db);
497
+                    $cuser->fetch($obj->fk_user_author);
498
+                    $this->user_creation   = $cuser;
499
+                }
500
+
501
+                if ($obj->fk_user_valid)
502
+                {
503
+                    $vuser = new User($this->db);
504
+                    $vuser->fetch($obj->fk_user_valid);
505
+                    $this->user_validation = $vuser;
506
+                }
507
+
508
+                if ($obj->fk_user_cloture)
509
+                {
510
+                    $cluser = new User($this->db);
511
+                    $cluser->fetch($obj->fk_user_cloture);
512
+                    $this->user_cloture   = $cluser;
513
+                }
514
+
515
+                $this->date_creation     = $this->db->jdate($obj->datec);
516
+                $this->date_modification = $this->db->jdate($obj->datem);
517
+                $this->date_validation   = $this->db->jdate($obj->datev);
518
+            }
519
+
520
+            $this->db->free($result);
521
+        }
522
+        else
523
+        {
524
+            dol_print_error($this->db);
525
+        }
526
+    }
527
+
528
+    /**
529
+     * Initialise object with example values
530
+     * Id must be 0 if object instance is a specimen
531
+     *
532
+     * @return void
533
+     */
534
+    public function initAsSpecimen()
535
+    {
536
+        $this->initAsSpecimenCommon();
537
+    }
538 538
 }
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
  */
27 27
 
28 28
 // Put here all includes required by your class file
29
-require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
29
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30 30
 //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
31 31
 //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
32 32
 
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 	/**
78 78
 	 * @var array  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
79 79
 	 */
80
-	public $fields=array(
80
+	public $fields = array(
81 81
 		'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>-2, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>'Id',),
82 82
 		'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>0, 'enabled'=>1, 'position'=>5, 'default'=>1),
83 83
 		'key_account' => array('type'=>'varchar(128)', 'label'=>'KeyAccount', 'visible'=>-1, 'enabled'=>1, 'position'=>10, 'notnull'=>1, 'index'=>1, 'searchall'=>1, 'comment'=>'Key account',),
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 		'fk_user_creat' => array('type'=>'integer', 'label'=>'UserAuthor', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
98 98
 		'fk_user_modif' => array('type'=>'integer', 'label'=>'UserModif', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>-1,),
99 99
 		'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'visible'=>-2, 'enabled'=>1, 'position'=>1000, 'notnull'=>-1, 'index'=>1,),
100
-		'status' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>1000, 'notnull'=>1, 'index'=>1, 'default'=>1, 'arrayofkeyval'=>array('1'=>'Active','0'=>'Disabled')),
100
+		'status' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>1000, 'notnull'=>1, 'index'=>1, 'default'=>1, 'arrayofkeyval'=>array('1'=>'Active', '0'=>'Disabled')),
101 101
 	);
102 102
 
103 103
 	/**
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 
187 187
 		$this->db = $db;
188 188
 
189
-		if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->fields['rowid']['visible']=0;
189
+		if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->fields['rowid']['visible'] = 0;
190 190
 	}
191 191
 
192 192
 	/**
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 	public function fetch($id, $ref = null)
261 261
 	{
262 262
 		$result = $this->fetchCommon($id, $ref);
263
-		if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();
263
+		if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
264 264
 		return $result;
265 265
 	}
266 266
 
@@ -271,11 +271,11 @@  discard block
 block discarded – undo
271 271
 	 */
272 272
 	public function fetchLines()
273 273
 	{
274
-		$this->lines=array();
274
+		$this->lines = array();
275 275
 
276 276
 		// Load lines with object societeAccountLine
277 277
 
278
-		return count($this->lines)?1:0;
278
+		return count($this->lines) ? 1 : 0;
279 279
 	}
280 280
 
281 281
 	/**
@@ -286,17 +286,17 @@  discard block
 block discarded – undo
286 286
 	 * @param	int		$status		Status (0=test, 1=live)
287 287
 	 * @return	string				Stripe customer ref 'cu_xxxxxxxxxxxxx' or ''
288 288
 	 */
289
-	public function getCustomerAccount($id, $site, $status=0)
289
+	public function getCustomerAccount($id, $site, $status = 0)
290 290
 	{
291 291
 		$sql = "SELECT sa.key_account as key_account, sa.entity";
292
-		$sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa";
293
-		$sql.= " WHERE sa.fk_soc = " . $id;
294
-		$sql.= " AND sa.entity IN (".getEntity('societe').")";
295
-		$sql.= " AND sa.site = '".$this->db->escape($site)."' AND sa.status = ".((int) $status);
296
-		$sql.= " AND key_account IS NOT NULL AND key_account <> ''";
292
+		$sql .= " FROM ".MAIN_DB_PREFIX."societe_account as sa";
293
+		$sql .= " WHERE sa.fk_soc = ".$id;
294
+		$sql .= " AND sa.entity IN (".getEntity('societe').")";
295
+		$sql .= " AND sa.site = '".$this->db->escape($site)."' AND sa.status = ".((int) $status);
296
+		$sql .= " AND key_account IS NOT NULL AND key_account <> ''";
297 297
 		//$sql.= " ORDER BY sa.key_account DESC";
298 298
 
299
-		dol_syslog(get_class($this) . "::getCustomerAccount Try to find the first system customer id for ".$site." of thirdparty id=".$id." (exemple: cus_.... for stripe)", LOG_DEBUG);
299
+		dol_syslog(get_class($this)."::getCustomerAccount Try to find the first system customer id for ".$site." of thirdparty id=".$id." (exemple: cus_.... for stripe)", LOG_DEBUG);
300 300
 		$result = $this->db->query($sql);
301 301
 		if ($result) {
302 302
 			if ($this->db->num_rows($result)) {
@@ -346,54 +346,54 @@  discard block
 block discarded – undo
346 346
      *  @param  int     $save_lastsearch_value    	-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
347 347
 	 *	@return	string								String with URL
348 348
 	 */
349
-	function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
349
+	function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
350 350
 	{
351 351
 		global $db, $conf, $langs;
352 352
         global $dolibarr_main_authentication, $dolibarr_main_demo;
353 353
         global $menumanager;
354 354
 
355
-        if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
355
+        if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
356 356
 
357 357
         $result = '';
358 358
         $companylink = '';
359 359
 
360 360
         $this->ref = $this->login;
361 361
 
362
-        $label = '<u>' . $langs->trans("SocieteAccount") . '</u>';
363
-        $label.= '<br>';
364
-        $label.= '<b>' . $langs->trans('Login') . ':</b> ' . $this->ref;
362
+        $label = '<u>'.$langs->trans("SocieteAccount").'</u>';
363
+        $label .= '<br>';
364
+        $label .= '<b>'.$langs->trans('Login').':</b> '.$this->ref;
365 365
         //$label.= '<b>' . $langs->trans('WebSite') . ':</b> ' . $this->ref;
366 366
 
367
-        $url = dol_buildpath('/website/websiteaccount_card.php',1).'?id='.$this->id;
367
+        $url = dol_buildpath('/website/websiteaccount_card.php', 1).'?id='.$this->id;
368 368
 
369 369
         if ($option != 'nolink')
370 370
         {
371 371
 	        // Add param to save lastsearch_values or not
372
-	        $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
373
-	        if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
374
-	        if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
372
+	        $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
373
+	        if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
374
+	        if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
375 375
         }
376 376
 
377
-        $linkclose='';
377
+        $linkclose = '';
378 378
         if (empty($notooltip))
379 379
         {
380
-            if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
380
+            if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
381 381
             {
382
-                $label=$langs->trans("ShowsocieteAccount");
383
-                $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
382
+                $label = $langs->trans("ShowsocieteAccount");
383
+                $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
384 384
             }
385
-            $linkclose.=' title="'.dol_escape_htmltag($label, 1).'"';
386
-            $linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
385
+            $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
386
+            $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
387 387
         }
388
-        else $linkclose = ($morecss?' class="'.$morecss.'"':'');
388
+        else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
389 389
 
390 390
 		$linkstart = '<a href="'.$url.'"';
391
-		$linkstart.=$linkclose.'>';
392
-		$linkend='</a>';
391
+		$linkstart .= $linkclose.'>';
392
+		$linkend = '</a>';
393 393
 
394 394
 		$result .= $linkstart;
395
-		if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
396
-		if ($withpicto != 2) $result.= $this->ref;
395
+		if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
396
+		if ($withpicto != 2) $result .= $this->ref;
397 397
 		$result .= $linkend;
398 398
 
399 399
 		return $result;
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
 	 * @param	int				$withpicto			Add download picto into link
406 406
 	 * @return	string			HTML link to file
407 407
 	 */
408
-	function getDirectExternalLink($withpicto=0)
408
+	function getDirectExternalLink($withpicto = 0)
409 409
 	{
410 410
 		return 'todo';
411 411
 	}
@@ -416,9 +416,9 @@  discard block
 block discarded – undo
416 416
 	 *  @param	int		$mode          0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
417 417
 	 *  @return	string 			       Label of status
418 418
 	 */
419
-	function getLibStatut($mode=0)
419
+	function getLibStatut($mode = 0)
420 420
 	{
421
-		return $this->LibStatut($this->status,$mode);
421
+		return $this->LibStatut($this->status, $mode);
422 422
 	}
423 423
 
424 424
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -429,14 +429,14 @@  discard block
 block discarded – undo
429 429
 	 *  @param  int		$mode          	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
430 430
 	 *  @return string 			       	Label of status
431 431
 	 */
432
-	static function LibStatut($status,$mode=0)
432
+	static function LibStatut($status, $mode = 0)
433 433
 	{
434 434
         // phpcs:enable
435 435
 		global $langs;
436 436
 
437 437
 		if ($mode == 0)
438 438
 		{
439
-			$prefix='';
439
+			$prefix = '';
440 440
 			if ($status == 1) return $langs->trans('Enabled');
441 441
 			elseif ($status == 0) return $langs->trans('Disabled');
442 442
 		}
@@ -447,28 +447,28 @@  discard block
 block discarded – undo
447 447
 		}
448 448
 		elseif ($mode == 2)
449 449
 		{
450
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
451
-			elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
450
+			if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled');
451
+			elseif ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled');
452 452
 		}
453 453
 		elseif ($mode == 3)
454 454
 		{
455
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4');
456
-			elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5');
455
+			if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4');
456
+			elseif ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5');
457 457
 		}
458 458
 		elseif ($mode == 4)
459 459
 		{
460
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
461
-			elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
460
+			if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled');
461
+			elseif ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled');
462 462
 		}
463 463
 		elseif ($mode == 5)
464 464
 		{
465
-			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
466
-			elseif ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
465
+			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'), 'statut4');
466
+			elseif ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'), 'statut5');
467 467
 		}
468 468
 		elseif ($mode == 6)
469 469
 		{
470
-			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
471
-			elseif ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
470
+			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'), 'statut4');
471
+			elseif ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'), 'statut5');
472 472
 		}
473 473
 	}
474 474
 
@@ -481,10 +481,10 @@  discard block
 block discarded – undo
481 481
 	function info($id)
482 482
 	{
483 483
 		$sql = 'SELECT rowid, date_creation as datec, tms as datem,';
484
-		$sql.= ' fk_user_creat, fk_user_modif';
485
-		$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
486
-		$sql.= ' WHERE t.rowid = '.$id;
487
-		$result=$this->db->query($sql);
484
+		$sql .= ' fk_user_creat, fk_user_modif';
485
+		$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
486
+		$sql .= ' WHERE t.rowid = '.$id;
487
+		$result = $this->db->query($sql);
488 488
 		if ($result)
489 489
 		{
490 490
 			if ($this->db->num_rows($result))
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
 				{
496 496
 					$cuser = new User($this->db);
497 497
 					$cuser->fetch($obj->fk_user_author);
498
-					$this->user_creation   = $cuser;
498
+					$this->user_creation = $cuser;
499 499
 				}
500 500
 
501 501
 				if ($obj->fk_user_valid)
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
 				{
510 510
 					$cluser = new User($this->db);
511 511
 					$cluser->fetch($obj->fk_user_cloture);
512
-					$this->user_cloture   = $cluser;
512
+					$this->user_cloture = $cluser;
513 513
 				}
514 514
 
515 515
 				$this->date_creation     = $this->db->jdate($obj->datec);
Please login to merge, or discard this patch.
Braces   +66 added lines, -36 removed lines patch added patch discarded remove patch
@@ -186,7 +186,9 @@  discard block
 block discarded – undo
186 186
 
187 187
 		$this->db = $db;
188 188
 
189
-		if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->fields['rowid']['visible']=0;
189
+		if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
190
+		    $this->fields['rowid']['visible']=0;
191
+		}
190 192
 	}
191 193
 
192 194
 	/**
@@ -260,7 +262,9 @@  discard block
 block discarded – undo
260 262
 	public function fetch($id, $ref = null)
261 263
 	{
262 264
 		$result = $this->fetchCommon($id, $ref);
263
-		if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();
265
+		if ($result > 0 && ! empty($this->table_element_line)) {
266
+		    $this->fetchLines();
267
+		}
264 268
 		return $result;
265 269
 	}
266 270
 
@@ -352,7 +356,10 @@  discard block
 block discarded – undo
352 356
         global $dolibarr_main_authentication, $dolibarr_main_demo;
353 357
         global $menumanager;
354 358
 
355
-        if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
359
+        if (! empty($conf->dol_no_mouse_hover)) {
360
+            $notooltip=1;
361
+        }
362
+        // Force disable tooltips
356 363
 
357 364
         $result = '';
358 365
         $companylink = '';
@@ -370,8 +377,12 @@  discard block
 block discarded – undo
370 377
         {
371 378
 	        // Add param to save lastsearch_values or not
372 379
 	        $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
373
-	        if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
374
-	        if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
380
+	        if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) {
381
+	            $add_save_lastsearch_values=1;
382
+	        }
383
+	        if ($add_save_lastsearch_values) {
384
+	            $url.='&save_lastsearch_values=1';
385
+	        }
375 386
         }
376 387
 
377 388
         $linkclose='';
@@ -384,16 +395,21 @@  discard block
 block discarded – undo
384 395
             }
385 396
             $linkclose.=' title="'.dol_escape_htmltag($label, 1).'"';
386 397
             $linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
398
+        } else {
399
+            $linkclose = ($morecss?' class="'.$morecss.'"':'');
387 400
         }
388
-        else $linkclose = ($morecss?' class="'.$morecss.'"':'');
389 401
 
390 402
 		$linkstart = '<a href="'.$url.'"';
391 403
 		$linkstart.=$linkclose.'>';
392 404
 		$linkend='</a>';
393 405
 
394 406
 		$result .= $linkstart;
395
-		if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
396
-		if ($withpicto != 2) $result.= $this->ref;
407
+		if ($withpicto) {
408
+		    $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
409
+		}
410
+		if ($withpicto != 2) {
411
+		    $result.= $this->ref;
412
+		}
397 413
 		$result .= $linkend;
398 414
 
399 415
 		return $result;
@@ -437,38 +453,53 @@  discard block
 block discarded – undo
437 453
 		if ($mode == 0)
438 454
 		{
439 455
 			$prefix='';
440
-			if ($status == 1) return $langs->trans('Enabled');
441
-			elseif ($status == 0) return $langs->trans('Disabled');
442
-		}
443
-		elseif ($mode == 1)
456
+			if ($status == 1) {
457
+			    return $langs->trans('Enabled');
458
+			} elseif ($status == 0) {
459
+			    return $langs->trans('Disabled');
460
+			}
461
+		} elseif ($mode == 1)
444 462
 		{
445
-			if ($status == 1) return $langs->trans('Enabled');
446
-			elseif ($status == 0) return $langs->trans('Disabled');
447
-		}
448
-		elseif ($mode == 2)
463
+			if ($status == 1) {
464
+			    return $langs->trans('Enabled');
465
+			} elseif ($status == 0) {
466
+			    return $langs->trans('Disabled');
467
+			}
468
+		} elseif ($mode == 2)
449 469
 		{
450
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
451
-			elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
452
-		}
453
-		elseif ($mode == 3)
470
+			if ($status == 1) {
471
+			    return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
472
+			} elseif ($status == 0) {
473
+			    return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
474
+			}
475
+		} elseif ($mode == 3)
454 476
 		{
455
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4');
456
-			elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5');
457
-		}
458
-		elseif ($mode == 4)
477
+			if ($status == 1) {
478
+			    return img_picto($langs->trans('Enabled'),'statut4');
479
+			} elseif ($status == 0) {
480
+			    return img_picto($langs->trans('Disabled'),'statut5');
481
+			}
482
+		} elseif ($mode == 4)
459 483
 		{
460
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
461
-			elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
462
-		}
463
-		elseif ($mode == 5)
484
+			if ($status == 1) {
485
+			    return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
486
+			} elseif ($status == 0) {
487
+			    return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
488
+			}
489
+		} elseif ($mode == 5)
464 490
 		{
465
-			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
466
-			elseif ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
467
-		}
468
-		elseif ($mode == 6)
491
+			if ($status == 1) {
492
+			    return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
493
+			} elseif ($status == 0) {
494
+			    return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
495
+			}
496
+		} elseif ($mode == 6)
469 497
 		{
470
-			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
471
-			elseif ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
498
+			if ($status == 1) {
499
+			    return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
500
+			} elseif ($status == 0) {
501
+			    return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
502
+			}
472 503
 		}
473 504
 	}
474 505
 
@@ -518,8 +549,7 @@  discard block
 block discarded – undo
518 549
 			}
519 550
 
520 551
 			$this->db->free($result);
521
-		}
522
-		else
552
+		} else
523 553
 		{
524 554
 			dol_print_error($this->db);
525 555
 		}
Please login to merge, or discard this patch.
dolibarr/htdocs/societe/class/client.class.php 3 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
     public $cacheprospectstatus=array();
35 35
 
36 36
 
37
-	/**
37
+    /**
38 38
      *  Constructor
39 39
      *
40 40
      *  @param	DoliDB	$db		Database handler
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
         $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
66 66
         if (!$user->rights->societe->client->voir && !$user->societe_id)
67 67
         {
68
-        	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
69
-        	$sql.= " WHERE sc.fk_user = " .$user->id;
70
-        	$clause = "AND";
68
+            $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
69
+            $sql.= " WHERE sc.fk_user = " .$user->id;
70
+            $clause = "AND";
71 71
         }
72 72
         $sql.= " ".$clause." s.client IN (1,2,3)";
73 73
         $sql.= ' AND s.entity IN ('.getEntity($this->element).')';
@@ -92,27 +92,27 @@  discard block
 block discarded – undo
92 92
         }
93 93
     }
94 94
 
95
-	/**
96
-	 *  Load array of prospect status
97
-	 *
98
-	 *  @param	int		$active     1=Active only, 0=Not active only, -1=All
99
-	 *  @return int					<0 if KO, >0 if OK
100
-	 */
95
+    /**
96
+     *  Load array of prospect status
97
+     *
98
+     *  @param	int		$active     1=Active only, 0=Not active only, -1=All
99
+     *  @return int					<0 if KO, >0 if OK
100
+     */
101 101
     function loadCacheOfProspStatus($active=1)
102 102
     {
103
-    	global $langs;
103
+        global $langs;
104 104
 
105
-   		$sql="SELECT id, code, libelle as label FROM ".MAIN_DB_PREFIX."c_stcomm";
106
-   		if ($active >= 0) $sql.=" WHERE active = ".$active;
107
-		$resql=$this->db->query($sql);
108
-		$num=$this->db->num_rows($resql);
109
-		$i=0;
110
-		while ($i < $num)
111
-		{
112
-			$obj=$this->db->fetch_object($resql);
113
-			$this->cacheprospectstatus[$obj->id]=array('id'=>$obj->id, 'code'=>$obj->code, 'label'=> ($langs->trans("ST_".strtoupper($obj->code))=="ST_".strtoupper($obj->code))?$obj->label:$langs->trans("ST_".strtoupper($obj->code)));
114
-			$i++;
115
-		}
116
-		return 1;
105
+            $sql="SELECT id, code, libelle as label FROM ".MAIN_DB_PREFIX."c_stcomm";
106
+            if ($active >= 0) $sql.=" WHERE active = ".$active;
107
+        $resql=$this->db->query($sql);
108
+        $num=$this->db->num_rows($resql);
109
+        $i=0;
110
+        while ($i < $num)
111
+        {
112
+            $obj=$this->db->fetch_object($resql);
113
+            $this->cacheprospectstatus[$obj->id]=array('id'=>$obj->id, 'code'=>$obj->code, 'label'=> ($langs->trans("ST_".strtoupper($obj->code))=="ST_".strtoupper($obj->code))?$obj->label:$langs->trans("ST_".strtoupper($obj->code)));
114
+            $i++;
115
+        }
116
+        return 1;
117 117
     }
118 118
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -29,9 +29,9 @@  discard block
 block discarded – undo
29 29
  */
30 30
 class Client extends Societe
31 31
 {
32
-    public $next_prev_filter="te.client in (1,2,3)";	// Used to add a filter in Form::showrefnav method
32
+    public $next_prev_filter = "te.client in (1,2,3)"; // Used to add a filter in Form::showrefnav method
33 33
 
34
-    public $cacheprospectstatus=array();
34
+    public $cacheprospectstatus = array();
35 35
 
36 36
 
37 37
 	/**
@@ -58,28 +58,28 @@  discard block
 block discarded – undo
58 58
         // phpcs:enable
59 59
         global $user;
60 60
 
61
-        $this->nb=array("customers" => 0,"prospects" => 0);
61
+        $this->nb = array("customers" => 0, "prospects" => 0);
62 62
         $clause = "WHERE";
63 63
 
64 64
         $sql = "SELECT count(s.rowid) as nb, s.client";
65
-        $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
65
+        $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
66 66
         if (!$user->rights->societe->client->voir && !$user->societe_id)
67 67
         {
68
-        	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
69
-        	$sql.= " WHERE sc.fk_user = " .$user->id;
68
+        	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
69
+        	$sql .= " WHERE sc.fk_user = ".$user->id;
70 70
         	$clause = "AND";
71 71
         }
72
-        $sql.= " ".$clause." s.client IN (1,2,3)";
73
-        $sql.= ' AND s.entity IN ('.getEntity($this->element).')';
74
-        $sql.= " GROUP BY s.client";
72
+        $sql .= " ".$clause." s.client IN (1,2,3)";
73
+        $sql .= ' AND s.entity IN ('.getEntity($this->element).')';
74
+        $sql .= " GROUP BY s.client";
75 75
 
76
-        $resql=$this->db->query($sql);
76
+        $resql = $this->db->query($sql);
77 77
         if ($resql)
78 78
         {
79
-            while ($obj=$this->db->fetch_object($resql))
79
+            while ($obj = $this->db->fetch_object($resql))
80 80
             {
81
-                if ($obj->client == 1 || $obj->client == 3) $this->nb["customers"]+=$obj->nb;
82
-                if ($obj->client == 2 || $obj->client == 3) $this->nb["prospects"]+=$obj->nb;
81
+                if ($obj->client == 1 || $obj->client == 3) $this->nb["customers"] += $obj->nb;
82
+                if ($obj->client == 2 || $obj->client == 3) $this->nb["prospects"] += $obj->nb;
83 83
             }
84 84
             $this->db->free($resql);
85 85
             return 1;
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
         else
88 88
         {
89 89
             dol_print_error($this->db);
90
-            $this->error=$this->db->lasterror();
90
+            $this->error = $this->db->lasterror();
91 91
             return -1;
92 92
         }
93 93
     }
@@ -98,19 +98,19 @@  discard block
 block discarded – undo
98 98
 	 *  @param	int		$active     1=Active only, 0=Not active only, -1=All
99 99
 	 *  @return int					<0 if KO, >0 if OK
100 100
 	 */
101
-    function loadCacheOfProspStatus($active=1)
101
+    function loadCacheOfProspStatus($active = 1)
102 102
     {
103 103
     	global $langs;
104 104
 
105
-   		$sql="SELECT id, code, libelle as label FROM ".MAIN_DB_PREFIX."c_stcomm";
106
-   		if ($active >= 0) $sql.=" WHERE active = ".$active;
107
-		$resql=$this->db->query($sql);
108
-		$num=$this->db->num_rows($resql);
109
-		$i=0;
105
+   		$sql = "SELECT id, code, libelle as label FROM ".MAIN_DB_PREFIX."c_stcomm";
106
+   		if ($active >= 0) $sql .= " WHERE active = ".$active;
107
+		$resql = $this->db->query($sql);
108
+		$num = $this->db->num_rows($resql);
109
+		$i = 0;
110 110
 		while ($i < $num)
111 111
 		{
112
-			$obj=$this->db->fetch_object($resql);
113
-			$this->cacheprospectstatus[$obj->id]=array('id'=>$obj->id, 'code'=>$obj->code, 'label'=> ($langs->trans("ST_".strtoupper($obj->code))=="ST_".strtoupper($obj->code))?$obj->label:$langs->trans("ST_".strtoupper($obj->code)));
112
+			$obj = $this->db->fetch_object($resql);
113
+			$this->cacheprospectstatus[$obj->id] = array('id'=>$obj->id, 'code'=>$obj->code, 'label'=> ($langs->trans("ST_".strtoupper($obj->code)) == "ST_".strtoupper($obj->code)) ? $obj->label : $langs->trans("ST_".strtoupper($obj->code)));
114 114
 			$i++;
115 115
 		}
116 116
 		return 1;
Please login to merge, or discard this patch.
Braces   +10 added lines, -5 removed lines patch added patch discarded remove patch
@@ -78,13 +78,16 @@  discard block
 block discarded – undo
78 78
         {
79 79
             while ($obj=$this->db->fetch_object($resql))
80 80
             {
81
-                if ($obj->client == 1 || $obj->client == 3) $this->nb["customers"]+=$obj->nb;
82
-                if ($obj->client == 2 || $obj->client == 3) $this->nb["prospects"]+=$obj->nb;
81
+                if ($obj->client == 1 || $obj->client == 3) {
82
+                    $this->nb["customers"]+=$obj->nb;
83
+                }
84
+                if ($obj->client == 2 || $obj->client == 3) {
85
+                    $this->nb["prospects"]+=$obj->nb;
86
+                }
83 87
             }
84 88
             $this->db->free($resql);
85 89
             return 1;
86
-        }
87
-        else
90
+        } else
88 91
         {
89 92
             dol_print_error($this->db);
90 93
             $this->error=$this->db->lasterror();
@@ -103,7 +106,9 @@  discard block
 block discarded – undo
103 106
     	global $langs;
104 107
 
105 108
    		$sql="SELECT id, code, libelle as label FROM ".MAIN_DB_PREFIX."c_stcomm";
106
-   		if ($active >= 0) $sql.=" WHERE active = ".$active;
109
+   		if ($active >= 0) {
110
+   		    $sql.=" WHERE active = ".$active;
111
+   		}
107 112
 		$resql=$this->db->query($sql);
108 113
 		$num=$this->db->num_rows($resql);
109 114
 		$i=0;
Please login to merge, or discard this patch.
dolibarr/htdocs/societe/class/api_thirdparties.class.php 3 patches
Indentation   +1621 added lines, -1621 removed lines patch added patch discarded remove patch
@@ -28,1644 +28,1644 @@
 block discarded – undo
28 28
  */
29 29
 class Thirdparties extends DolibarrApi
30 30
 {
31
-	/**
32
-	 *
33
-	 * @var array   $FIELDS     Mandatory fields, checked when create and update object
34
-	 */
35
-	static $FIELDS = array(
36
-		'name'
37
-	);
38
-
39
-	/**
40
-	 * @var Societe $company {@type Societe}
41
-	 */
42
-	public $company;
43
-
44
-	/**
45
-	 * Constructor
46
-	 */
47
-	function __construct()
48
-	{
49
-		global $db, $conf;
50
-		$this->db = $db;
51
-
52
-		require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
53
-		require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
54
-		require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
55
-		require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
56
-
57
-		$this->company = new Societe($this->db);
58
-
59
-		if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY)) {
60
-			static::$FIELDS[] = 'email';
61
-		}
62
-	}
63
-
64
-	/**
65
-	 * Get properties of a thirdparty object
66
-	 *
67
-	 * Return an array with thirdparty informations
68
-	 *
69
-	 * @param 	int 	$id ID of thirdparty
70
-	 * @return 	array|mixed data without useless information
71
-	 *
72
-	 * @throws 	RestException
73
-	 */
74
-	function get($id)
75
-	{
76
-		if(! DolibarrApiAccess::$user->rights->societe->lire) {
77
-			throw new RestException(401);
78
-		}
79
-
80
-		$result = $this->company->fetch($id);
81
-		if( ! $result ) {
82
-			throw new RestException(404, 'Thirdparty not found');
83
-		}
84
-
85
-		if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
86
-			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
87
-		}
88
-
89
-		if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
90
-			$filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
91
-			$filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
92
-		} else {
93
-			$filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
94
-			$filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
95
-		}
96
-
97
-		$absolute_discount = $this->company->getAvailableDiscounts('', $filterabsolutediscount);
98
-		$absolute_creditnote = $this->company->getAvailableDiscounts('', $filtercreditnote);
99
-		$this->company->absolute_discount = price2num($absolute_discount, 'MT');
100
-		$this->company->absolute_creditnote = price2num($absolute_creditnote, 'MT');
101
-
102
-		return $this->_cleanObjectDatas($this->company);
103
-	}
104
-
105
-	/**
106
-	 * List thirdparties
107
-	 *
108
-	 * Get a list of thirdparties
109
-	 *
110
-	 * @param   string  $sortfield  Sort field
111
-	 * @param   string  $sortorder  Sort order
112
-	 * @param   int     $limit      Limit for list
113
-	 * @param   int     $page       Page number
114
-	 * @param   int     $mode       Set to 1 to show only customers
115
-	 *                              Set to 2 to show only prospects
116
-	 *                              Set to 3 to show only those are not customer neither prospect
117
-	 * @param   string  $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.nom:like:'TheCompany%') and (t.date_creation:<:'20160101')"
118
-	 * @return  array               Array of thirdparty objects
119
-	 */
120
-	function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode=0, $sqlfilters = '')
31
+    /**
32
+     *
33
+     * @var array   $FIELDS     Mandatory fields, checked when create and update object
34
+     */
35
+    static $FIELDS = array(
36
+        'name'
37
+    );
38
+
39
+    /**
40
+     * @var Societe $company {@type Societe}
41
+     */
42
+    public $company;
43
+
44
+    /**
45
+     * Constructor
46
+     */
47
+    function __construct()
121 48
     {
122
-		global $db, $conf;
123
-
124
-		$obj_ret = array();
125
-
126
-		// case of external user, we force socids
127
-		$socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : '';
128
-
129
-		// If the internal user must only see his customers, force searching by him
130
-		$search_sale = 0;
131
-		if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
132
-
133
-		$sql = "SELECT t.rowid";
134
-		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
135
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe as t";
136
-
137
-		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
138
-		$sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st";
139
-		$sql.= " WHERE t.fk_stcomm = st.id";
140
-		if ($mode == 1) $sql.= " AND t.client IN (1, 3)";
141
-		if ($mode == 2) $sql.= " AND t.client IN (2, 3)";
142
-		if ($mode == 3) $sql.= " AND t.client IN (0)";
143
-		$sql.= ' AND t.entity IN ('.getEntity('societe').')';
144
-		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";
145
-		//if ($email != NULL) $sql.= " AND s.email = \"".$email."\"";
146
-		if ($socid) $sql.= " AND t.rowid IN (".$socids.")";
147
-		if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";		// Join for the needed table to filter by sale
148
-		// Insert sale filter
149
-		if ($search_sale > 0)
150
-		{
151
-			$sql .= " AND sc.fk_user = ".$search_sale;
152
-		}
153
-		// Add sql filters
154
-		if ($sqlfilters)
155
-		{
156
-			if (! DolibarrApi::_checkFilters($sqlfilters))
157
-			{
158
-				throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
159
-			}
160
-			$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
161
-			$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
162
-		}
163
-
164
-		$sql.= $db->order($sortfield, $sortorder);
165
-
166
-		if ($limit) {
167
-			if ($page < 0)
168
-			{
169
-				$page = 0;
170
-			}
171
-			$offset = $limit * $page;
172
-
173
-			$sql.= $db->plimit($limit + 1, $offset);
174
-		}
175
-
176
-		$result = $db->query($sql);
177
-		if ($result)
178
-		{
179
-			$num = $db->num_rows($result);
180
-			$min = min($num, ($limit <= 0 ? $num : $limit));
181
-			while ($i < $min)
182
-			{
183
-				$obj = $db->fetch_object($result);
184
-				$soc_static = new Societe($db);
185
-				if($soc_static->fetch($obj->rowid)) {
186
-					$obj_ret[] = $this->_cleanObjectDatas($soc_static);
187
-				}
188
-				$i++;
189
-			}
190
-		}
191
-		else {
192
-			throw new RestException(503, 'Error when retrieve thirdparties : '.$db->lasterror());
193
-		}
194
-		if( ! count($obj_ret)) {
195
-			throw new RestException(404, 'Thirdparties not found');
196
-		}
197
-		return $obj_ret;
198
-	}
199
-
200
-	/**
201
-	 * Create thirdparty object
202
-	 *
203
-	 * @param array $request_data   Request datas
204
-	 * @return int  ID of thirdparty
205
-	 */
206
-	function post($request_data = null)
207
-	{
208
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
209
-			throw new RestException(401);
210
-		}
211
-		// Check mandatory fields
212
-		$result = $this->_validate($request_data);
213
-
214
-		foreach($request_data as $field => $value) {
215
-			$this->company->$field = $value;
216
-		}
217
-		if ($this->company->create(DolibarrApiAccess::$user) < 0)
218
-			throw new RestException(500, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors));
219
-
220
-		return $this->company->id;
221
-	}
222
-
223
-	/**
224
-	 * Update thirdparty
225
-	 *
226
-	 * @param int   $id             Id of thirdparty to update
227
-	 * @param array $request_data   Datas
228
-	 * @return int
229
-	 */
230
-	function put($id, $request_data = null)
231
-	{
232
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
233
-			throw new RestException(401);
234
-		}
235
-
236
-		$result = $this->company->fetch($id);
237
-		if( ! $result ) {
238
-			throw new RestException(404, 'Thirdparty not found');
239
-		}
240
-
241
-		if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
242
-			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
243
-		}
244
-
245
-		foreach($request_data as $field => $value) {
246
-			if ($field == 'id') continue;
247
-			$this->company->$field = $value;
248
-		}
249
-
250
-		if($this->company->update($id, DolibarrApiAccess::$user,1,'','','update'))
251
-			return $this->get($id);
252
-
253
-		return false;
254
-	}
255
-
256
-	/**
257
-	 * Merge a thirdparty into another one.
258
-	 *
259
-	 * Merge content (properties, notes) and objects (like invoices, events, orders, proposals, ...) of a thirdparty into a target thirdparty,
260
-	 * then delete the merged thirdparty.
261
-	 * If a property has a defined value both in thirdparty to delete and thirdparty to keep, the value into the thirdparty to
262
-	 * delete will be ignored, the value of target thirdparty will remain, except for notes (content is concatenated).
263
-	 *
264
-	 * @param int   $id             ID of thirdparty to keep (the target thirdparty)
265
-	 * @param int   $idtodelete     ID of thirdparty to remove (the thirdparty to delete), once data has been merged into the target thirdparty.
266
-	 * @return int
267
-	 *
268
-	 * @url PUT {id}/merge/{idtodelete}
269
-	 */
270
-	function merge($id, $idtodelete)
271
-	{
272
-		global $db, $hookmanager;
273
-
274
-		$error = 0;
275
-
276
-		if ($id == $idtodelete)
277
-		{
278
-			throw new RestException(400, 'Try to merge a thirdparty into itself');
279
-		}
280
-
281
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
282
-			throw new RestException(401);
283
-		}
284
-
285
-		$result = $this->company->fetch($id);	// include the fetch of extra fields
286
-		if( ! $result ) {
287
-			throw new RestException(404, 'Thirdparty not found');
288
-		}
289
-
290
-		if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
291
-			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
292
-		}
293
-
294
-		$this->companytoremove = new Societe($db);
295
-
296
-		$result = $this->companytoremove->fetch($idtodelete);	// include the fetch of extra fields
297
-		if( ! $result ) {
298
-			throw new RestException(404, 'Thirdparty not found');
299
-		}
300
-
301
-		if( ! DolibarrApi::_checkAccessToResource('societe',$this->companytoremove->id)) {
302
-			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
303
-		}
304
-
305
-		$soc_origin = $this->companytoremove;
306
-		$object = $this->company;
307
-		$user = DolibarrApiAccess::$user;
308
-
309
-
310
-		// Call same code than into action 'confirm_merge'
311
-
312
-
313
-		$db->begin();
314
-
315
-		// Recopy some data
316
-		$object->client = $object->client | $soc_origin->client;
317
-		$object->fournisseur = $object->fournisseur | $soc_origin->fournisseur;
318
-		$listofproperties=array(
319
-			'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'skype', 'url', 'barcode',
320
-			'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6',
321
-			'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'remise_supplier_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis',
322
-			'stcomm_id', 'outstanding_limit', 'price_level', 'parent', 'default_lang', 'ref', 'ref_ext', 'import_key', 'fk_incoterms', 'fk_multicurrency',
323
-			'code_client', 'code_fournisseur', 'code_compta', 'code_compta_fournisseur',
324
-			'model_pdf', 'fk_projet'
325
-		);
326
-		foreach ($listofproperties as $property)
327
-		{
328
-			if (empty($object->$property)) $object->$property = $soc_origin->$property;
329
-		}
330
-
331
-		// Concat some data
332
-		$listofproperties=array(
333
-			'note_public', 'note_private'
334
-		);
335
-		foreach ($listofproperties as $property)
336
-		{
337
-			$object->$property = dol_concatdesc($object->$property, $soc_origin->$property);
338
-		}
339
-
340
-		// Merge extrafields
341
-		if (is_array($soc_origin->array_options))
342
-		{
343
-			foreach ($soc_origin->array_options as $key => $val)
344
-			{
345
-				if (empty($object->array_options[$key])) $object->array_options[$key] = $val;
346
-			}
347
-		}
348
-
349
-		// Merge categories
350
-		$static_cat = new Categorie($db);
351
-		$custcats = $static_cat->containing($soc_origin->id, 'customer', 'id');
352
-		$object->setCategories($custcats, 'customer');
353
-		$suppcats = $static_cat->containing($soc_origin->id, 'supplier', 'id');
354
-		$object->setCategories($suppcats, 'supplier');
355
-
356
-		// If thirdparty has a new code that is same than origin, we clean origin code to avoid duplicate key from database unique keys.
357
-		if ($soc_origin->code_client == $object->code_client
358
-			|| $soc_origin->code_fournisseur == $object->code_fournisseur
359
-			|| $soc_origin->barcode == $object->barcode)
360
-		{
361
-			dol_syslog("We clean customer and supplier code so we will be able to make the update of target");
362
-			$soc_origin->code_client = '';
363
-			$soc_origin->code_fournisseur = '';
364
-			$soc_origin->barcode = '';
365
-			$soc_origin->update($soc_origin->id, $user, 0, 1, 1, 'merge');
366
-		}
367
-
368
-		// Update
369
-		$result = $object->update($object->id, $user, 0, 1, 1, 'merge');
370
-		if ($result < 0)
371
-		{
372
-			$error++;
373
-		}
374
-
375
-		// Move links
376
-		if (! $error)
377
-		{
378
-			$objects = array(
379
-				'Adherent' => '/adherents/class/adherent.class.php',
380
-				'Societe' => '/societe/class/societe.class.php',
381
-				'Categorie' => '/categories/class/categorie.class.php',
382
-				'ActionComm' => '/comm/action/class/actioncomm.class.php',
383
-				'Propal' => '/comm/propal/class/propal.class.php',
384
-				'Commande' => '/commande/class/commande.class.php',
385
-				'Facture' => '/compta/facture/class/facture.class.php',
386
-				'FactureRec' => '/compta/facture/class/facture-rec.class.php',
387
-				'LignePrelevement' => '/compta/prelevement/class/ligneprelevement.class.php',
388
-				'Contact' => '/contact/class/contact.class.php',
389
-				'Contrat' => '/contrat/class/contrat.class.php',
390
-				'Expedition' => '/expedition/class/expedition.class.php',
391
-				'Fichinter' => '/fichinter/class/fichinter.class.php',
392
-				'CommandeFournisseur' => '/fourn/class/fournisseur.commande.class.php',
393
-				'FactureFournisseur' => '/fourn/class/fournisseur.facture.class.php',
394
-				'SupplierProposal' => '/supplier_proposal/class/supplier_proposal.class.php',
395
-				'ProductFournisseur' => '/fourn/class/fournisseur.product.class.php',
396
-				'Livraison' => '/livraison/class/livraison.class.php',
397
-				'Product' => '/product/class/product.class.php',
398
-				'Project' => '/projet/class/project.class.php',
399
-				'User' => '/user/class/user.class.php',
400
-			);
401
-
402
-			//First, all core objects must update their tables
403
-			foreach ($objects as $object_name => $object_file)
404
-			{
405
-				require_once DOL_DOCUMENT_ROOT.$object_file;
406
-
407
-				if (!$errors && !$object_name::replaceThirdparty($db, $soc_origin->id, $object->id))
408
-				{
409
-					$errors++;
410
-					//setEventMessages($db->lasterror(), null, 'errors');
411
-				}
412
-			}
413
-		}
414
-
415
-		// External modules should update their ones too
416
-		if (!$errors)
417
-		{
418
-			$reshook = $hookmanager->executeHooks('replaceThirdparty', array(
419
-				'soc_origin' => $soc_origin->id,
420
-				'soc_dest' => $object->id
421
-			), $soc_dest, $action);
422
-
423
-			if ($reshook < 0)
424
-			{
425
-				//setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
426
-				$errors++;
427
-			}
428
-		}
429
-
430
-
431
-		if (! $error)
432
-		{
433
-			$object->context=array('merge'=>1, 'mergefromid'=>$soc_origin->id);
434
-
435
-			// Call trigger
436
-			$result=$object->call_trigger('COMPANY_MODIFY',$user);
437
-			if ($result < 0)
438
-			{
439
-				//setEventMessages($object->error, $object->errors, 'errors');
440
-				$error++;
441
-			}
442
-			// End call triggers
443
-		}
444
-
445
-		if (! $error)
446
-		{
447
-			//We finally remove the old thirdparty
448
-			if ($soc_origin->delete($soc_origin->id, $user) < 1)
449
-			{
450
-				$errors++;
451
-			}
452
-		}
453
-
454
-		// End of merge
455
-
456
-		if ($error)
457
-		{
458
-			$db->rollback();
459
-
460
-			throw new RestException(500, 'Error failed to merged thirdparty '.$this->companytoremove->id.' into '.$id.'. Enable and read log file for more information.');
461
-		}
462
-		else
463
-		{
464
-			$db->commit();
465
-		}
466
-
467
-		return $this->get($id);
468
-	}
469
-
470
-	/**
471
-	 * Delete thirdparty
472
-	 *
473
-	 * @param int $id   Thirparty ID
474
-	 * @return integer
475
-	 */
476
-	function delete($id)
477
-	{
478
-		if(! DolibarrApiAccess::$user->rights->societe->supprimer) {
479
-			throw new RestException(401);
480
-		}
481
-		$result = $this->company->fetch($id);
482
-		if( ! $result ) {
483
-			throw new RestException(404, 'Thirdparty not found');
484
-		}
485
-		if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
486
-			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
487
-		}
488
-		return $this->company->delete($id);
489
-	}
490
-
491
-	/**
492
-	 * Get customer categories for a thirdparty
493
-	 *
494
-	 * @param int		$id         ID of thirdparty
495
-	 * @param string	$sortfield	Sort field
496
-	 * @param string	$sortorder	Sort order
497
-	 * @param int		$limit		Limit for list
498
-	 * @param int		$page		Page number
499
-	 *
500
-	 * @return mixed
501
-	 *
502
-	 * @url GET {id}/categories
503
-	 */
504
-	function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
505
-	{
506
-		if (! DolibarrApiAccess::$user->rights->categorie->lire) {
507
-			throw new RestException(401);
508
-		}
509
-
510
-		$result = $this->company->fetch($id);
511
-		if( ! $result )
512
-		{
513
-			throw new RestException(404, 'Thirdparty not found');
514
-		}
515
-
516
-		$categories = new Categorie($this->db);
517
-
518
-		$result = $categories->getListForItem($id, 'customer', $sortfield, $sortorder, $limit, $page);
519
-
520
-		if (is_numeric($result) && $result < 0)
521
-		{
522
-			throw new RestException(503, 'Error when retrieve category list : '.$categories->error);
523
-		}
524
-
525
-		if (is_numeric($result) && $result == 0)	// To fix a return of 0 instead of empty array of method getListForItem
526
-		{
527
-			return array();
528
-		}
529
-
530
-		return $result;
531
-	}
532
-
533
-	/**
534
-	 * Add a customer category to a thirdparty
535
-	 *
536
-	 * @param int		$id				Id of thirdparty
537
-	 * @param int       $category_id	Id of category
538
-	 *
539
-	 * @return mixed
540
-	 *
541
-	 * @url POST {id}/categories/{category_id}
542
-	 */
543
-	function addCategory($id, $category_id)
544
-	{
545
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
546
-			throw new RestException(401);
547
-		}
548
-
549
-		$result = $this->company->fetch($id);
550
-		if( ! $result ) {
551
-			throw new RestException(404, 'Thirdparty not found');
552
-		}
553
-		$category = new Categorie($this->db);
554
-		$result = $category->fetch($category_id);
555
-		if( ! $result ) {
556
-			throw new RestException(404, 'category not found');
557
-		}
558
-
559
-		if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
560
-			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
561
-		}
562
-		if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) {
563
-			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
564
-		}
565
-
566
-		$category->add_type($this->company,'customer');
567
-
568
-		return $this->_cleanObjectDatas($this->company);
569
-	}
570
-
571
-	/**
572
-	 * Remove the link between a customer category and the thirdparty
573
-	 *
574
-	 * @param int		$id				Id of thirdparty
575
-	 * @param int		$category_id	Id of category
576
-	 *
577
-	 * @return mixed
578
-	 *
579
-	 * @url DELETE {id}/categories/{category_id}
580
-	 */
581
-	function deleteCategory($id, $category_id)
582
-	{
583
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
584
-			throw new RestException(401);
585
-		}
586
-
587
-		$result = $this->company->fetch($id);
588
-		if( ! $result ) {
589
-			throw new RestException(404, 'Thirdparty not found');
590
-		}
591
-		$category = new Categorie($this->db);
592
-		$result = $category->fetch($category_id);
593
-		if( ! $result ) {
594
-			throw new RestException(404, 'category not found');
595
-		}
596
-
597
-		if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
598
-			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
599
-		}
600
-		if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) {
601
-			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
602
-		}
603
-
604
-		$category->del_type($this->company,'customer');
605
-
606
-		return $this->_cleanObjectDatas($this->company);
607
-	}
608
-
609
-	/**
610
-	 * Get supplier categories for a thirdparty
611
-	 *
612
-	 * @param int		$id         ID of thirdparty
613
-	 * @param string	$sortfield	Sort field
614
-	 * @param string	$sortorder	Sort order
615
-	 * @param int		$limit		Limit for list
616
-	 * @param int		$page		Page number
617
-	 *
618
-	 * @return mixed
619
-	 *
620
-	 * @url GET {id}/supplier_categories
621
-	 */
622
-	function getSupplierCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
623
-	{
624
-		if (! DolibarrApiAccess::$user->rights->categorie->lire) {
625
-			throw new RestException(401);
626
-		}
627
-
628
-		$result = $this->company->fetch($id);
629
-		if( ! $result )
630
-		{
631
-			throw new RestException(404, 'Thirdparty not found');
632
-		}
633
-
634
-		$categories = new Categorie($this->db);
635
-
636
-		$result = $categories->getListForItem($id, 'supplier', $sortfield, $sortorder, $limit, $page);
637
-
638
-		if (is_numeric($result) && $result < 0)
639
-		{
640
-			throw new RestException(503, 'Error when retrieve category list : '.$categories->error);
641
-		}
642
-
643
-		if (is_numeric($result) && $result == 0)	// To fix a return of 0 instead of empty array of method getListForItem
644
-		{
645
-			return array();
646
-		}
647
-
648
-		return $result;
649
-	}
650
-
651
-	/**
652
-	 * Add a supplier category to a thirdparty
653
-	 *
654
-	 * @param int		$id				Id of thirdparty
655
-	 * @param int       $category_id	Id of category
656
-	 *
657
-	 * @return mixed
658
-	 *
659
-	 * @url POST {id}/supplier_categories/{category_id}
660
-	 */
661
-	function addSupplierCategory($id, $category_id)
662
-	{
663
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
664
-			throw new RestException(401);
665
-		}
666
-
667
-		$result = $this->company->fetch($id);
668
-		if( ! $result ) {
669
-			throw new RestException(404, 'Thirdparty not found');
670
-		}
671
-		$category = new Categorie($this->db);
672
-		$result = $category->fetch($category_id);
673
-		if( ! $result ) {
674
-			throw new RestException(404, 'category not found');
675
-		}
676
-
677
-		if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
678
-			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
679
-		}
680
-		if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) {
681
-			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
682
-		}
683
-
684
-		$category->add_type($this->company,'supplier');
685
-
686
-		return $this->_cleanObjectDatas($this->company);
687
-	}
688
-
689
-	/**
690
-	 * Remove the link between a category and the thirdparty
691
-	 *
692
-	 * @param int		$id				Id of thirdparty
693
-	 * @param int		$category_id	Id of category
694
-	 *
695
-	 * @return mixed
696
-	 *
697
-	 * @url DELETE {id}/supplier_categories/{category_id}
698
-	 */
699
-	function deleteSupplierCategory($id, $category_id)
700
-	{
701
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
702
-			throw new RestException(401);
703
-		}
704
-
705
-		$result = $this->company->fetch($id);
706
-		if( ! $result ) {
707
-			throw new RestException(404, 'Thirdparty not found');
708
-		}
709
-		$category = new Categorie($this->db);
710
-		$result = $category->fetch($category_id);
711
-		if( ! $result ) {
712
-			throw new RestException(404, 'category not found');
713
-		}
714
-
715
-		if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
716
-			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
717
-		}
718
-		if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) {
719
-			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
720
-		}
721
-
722
-		$category->del_type($this->company,'supplier');
723
-
724
-		return $this->_cleanObjectDatas($this->company);
725
-	}
726
-
727
-
728
-	/**
729
-	 * Get outstanding proposals of thirdparty
730
-	 *
731
-	 * @param 	int 	$id			ID of the thirdparty
732
-	 * @param 	string 	$mode		'customer' or 'supplier'
733
-	 *
734
-	 * @url     GET {id}/outstandingproposals
735
-	 *
736
-	 * @return array  				List of outstandings proposals of thirdparty
737
-	 *
738
-	 * @throws 400
739
-	 * @throws 401
740
-	 * @throws 404
741
-	 */
742
-	function getOutStandingProposals($id, $mode='customer')
743
-	{
744
-		$obj_ret = array();
745
-
746
-		if(! DolibarrApiAccess::$user->rights->societe->lire) {
747
-			throw new RestException(401);
748
-		}
749
-
750
-		if(empty($id)) {
751
-			throw new RestException(400, 'Thirdparty ID is mandatory');
752
-		}
753
-
754
-		if( ! DolibarrApi::_checkAccessToResource('societe',$id)) {
755
-			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
756
-		}
757
-
758
-		$result = $this->company->fetch($id);
759
-		if( ! $result ) {
760
-			throw new RestException(404, 'Thirdparty not found');
761
-		}
762
-
763
-		$result = $this->company->getOutstandingProposals($mode);
764
-
765
-		unset($result['total_ht']);
766
-		unset($result['total_ttc']);
767
-
768
-		return $result;
769
-	}
770
-
771
-
772
-	/**
773
-	 * Get outstanding orders of thirdparty
774
-	 *
775
-	 * @param 	int 	$id			ID of the thirdparty
776
-	 * @param 	string 	$mode		'customer' or 'supplier'
777
-	 *
778
-	 * @url     GET {id}/outstandingorders
779
-	 *
780
-	 * @return array  				List of outstandings orders of thirdparty
781
-	 *
782
-	 * @throws 400
783
-	 * @throws 401
784
-	 * @throws 404
785
-	 */
786
-	function getOutStandingOrder($id, $mode='customer')
787
-	{
788
-		$obj_ret = array();
789
-
790
-		if(! DolibarrApiAccess::$user->rights->societe->lire) {
791
-			throw new RestException(401);
792
-		}
793
-
794
-		if(empty($id)) {
795
-			throw new RestException(400, 'Thirdparty ID is mandatory');
796
-		}
797
-
798
-		if( ! DolibarrApi::_checkAccessToResource('societe',$id)) {
799
-			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
800
-		}
801
-
802
-		$result = $this->company->fetch($id);
803
-		if( ! $result ) {
804
-			throw new RestException(404, 'Thirdparty not found');
805
-		}
806
-
807
-		$result = $this->company->getOutstandingOrders($mode);
808
-
809
-		unset($result['total_ht']);
810
-		unset($result['total_ttc']);
811
-
812
-		return $result;
813
-	}
814
-
815
-	/**
816
-	 * Get outstanding invoices of thirdparty
817
-	 *
818
-	 * @param 	int 	$id			ID of the thirdparty
819
-	 * @param 	string 	$mode		'customer' or 'supplier'
820
-	 *
821
-	 * @url     GET {id}/outstandinginvoices
822
-	 *
823
-	 * @return array  				List of outstandings invoices of thirdparty
824
-	 *
825
-	 * @throws 400
826
-	 * @throws 401
827
-	 * @throws 404
828
-	 */
829
-	function getOutStandingInvoices($id, $mode='customer')
830
-	{
831
-		$obj_ret = array();
832
-
833
-		if(! DolibarrApiAccess::$user->rights->societe->lire) {
834
-			throw new RestException(401);
835
-		}
836
-
837
-		if(empty($id)) {
838
-			throw new RestException(400, 'Thirdparty ID is mandatory');
839
-		}
840
-
841
-		if( ! DolibarrApi::_checkAccessToResource('societe',$id)) {
842
-			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
843
-		}
844
-
845
-		$result = $this->company->fetch($id);
846
-		if( ! $result ) {
847
-			throw new RestException(404, 'Thirdparty not found');
848
-		}
849
-
850
-		$result = $this->company->getOutstandingBills($mode);
851
-
852
-		unset($result['total_ht']);
853
-		unset($result['total_ttc']);
854
-
855
-		return $result;
856
-	}
857
-
858
-	/**
859
-	 * Get fixed amount discount of a thirdparty (all sources: deposit, credit note, commercial offers...)
860
-	 *
861
-	 * @param 	int 	$id             ID of the thirdparty
862
-	 * @param 	string 	$filter    	Filter exceptional discount. "none" will return every discount, "available" returns unapplied discounts, "used" returns applied discounts   {@choice none,available,used}
863
-	 * @param   string  $sortfield  	Sort field
864
-	 * @param   string  $sortorder  	Sort order
865
-	 *
866
-	 * @url     GET {id}/fixedamountdiscounts
867
-	 *
868
-	 * @return array  List of fixed discount of thirdparty
869
-	 *
870
-	 * @throws 400
871
-	 * @throws 401
872
-	 * @throws 404
873
-	 * @throws 503
874
-	 */
875
-	function getFixedAmountDiscounts($id, $filter="none", $sortfield = "f.type", $sortorder = 'ASC')
876
-	{
877
-		$obj_ret = array();
878
-
879
-		if(! DolibarrApiAccess::$user->rights->societe->lire) {
880
-			throw new RestException(401);
881
-		}
882
-
883
-		if(empty($id)) {
884
-			throw new RestException(400, 'Thirdparty ID is mandatory');
885
-		}
886
-
887
-		if( ! DolibarrApi::_checkAccessToResource('societe',$id)) {
888
-			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
889
-		}
890
-
891
-		$result = $this->company->fetch($id);
892
-		if( ! $result ) {
893
-			throw new RestException(404, 'Thirdparty not found');
894
-		}
895
-
896
-
897
-		$sql = "SELECT f.ref, f.type as factype, re.fk_facture_source, re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc, re.description, re.fk_facture, re.fk_facture_line";
898
-		$sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
899
-		$sql .= " WHERE f.rowid = re.fk_facture_source AND re.fk_soc = ".$id;
900
-		if ($filter == "available")  $sql .= " AND re.fk_facture IS NULL AND re.fk_facture_line IS NULL";
901
-		if ($filter == "used")  $sql .= " AND (re.fk_facture IS NOT NULL OR re.fk_facture_line IS NOT NULL)";
902
-
903
-		$sql.= $this->db->order($sortfield, $sortorder);
904
-
905
-		$result = $this->db->query($sql);
906
-		if( ! $result ) {
907
-			throw new RestException(503, $this->db->lasterror());
908
-		} else {
909
-			$num = $this->db->num_rows($result);
910
-			while ( $obj = $this->db->fetch_object($result) ) {
911
-				$obj_ret[] = $obj;
912
-			}
913
-		}
914
-
915
-		return $obj_ret;
916
-	}
917
-
918
-
919
-
920
-	/**
921
-	 * Return list of invoices qualified to be replaced by another invoice.
922
-	 *
923
-	 * @param int   $id             Id of thirdparty
924
-	 *
925
-	 * @url     GET {id}/getinvoicesqualifiedforreplacement
926
-	 *
927
-	 * @return array
928
-	 * @throws 400
929
-	 * @throws 401
930
-	 * @throws 404
931
-	 * @throws 405
932
-	 */
933
-	function getInvoicesQualifiedForReplacement($id)
49
+        global $db, $conf;
50
+        $this->db = $db;
51
+
52
+        require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
53
+        require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
54
+        require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
55
+        require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
56
+
57
+        $this->company = new Societe($this->db);
58
+
59
+        if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY)) {
60
+            static::$FIELDS[] = 'email';
61
+        }
62
+    }
63
+
64
+    /**
65
+     * Get properties of a thirdparty object
66
+     *
67
+     * Return an array with thirdparty informations
68
+     *
69
+     * @param 	int 	$id ID of thirdparty
70
+     * @return 	array|mixed data without useless information
71
+     *
72
+     * @throws 	RestException
73
+     */
74
+    function get($id)
75
+    {
76
+        if(! DolibarrApiAccess::$user->rights->societe->lire) {
77
+            throw new RestException(401);
78
+        }
79
+
80
+        $result = $this->company->fetch($id);
81
+        if( ! $result ) {
82
+            throw new RestException(404, 'Thirdparty not found');
83
+        }
84
+
85
+        if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
86
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
87
+        }
88
+
89
+        if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
90
+            $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
91
+            $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
92
+        } else {
93
+            $filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
94
+            $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
95
+        }
96
+
97
+        $absolute_discount = $this->company->getAvailableDiscounts('', $filterabsolutediscount);
98
+        $absolute_creditnote = $this->company->getAvailableDiscounts('', $filtercreditnote);
99
+        $this->company->absolute_discount = price2num($absolute_discount, 'MT');
100
+        $this->company->absolute_creditnote = price2num($absolute_creditnote, 'MT');
101
+
102
+        return $this->_cleanObjectDatas($this->company);
103
+    }
104
+
105
+    /**
106
+     * List thirdparties
107
+     *
108
+     * Get a list of thirdparties
109
+     *
110
+     * @param   string  $sortfield  Sort field
111
+     * @param   string  $sortorder  Sort order
112
+     * @param   int     $limit      Limit for list
113
+     * @param   int     $page       Page number
114
+     * @param   int     $mode       Set to 1 to show only customers
115
+     *                              Set to 2 to show only prospects
116
+     *                              Set to 3 to show only those are not customer neither prospect
117
+     * @param   string  $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.nom:like:'TheCompany%') and (t.date_creation:<:'20160101')"
118
+     * @return  array               Array of thirdparty objects
119
+     */
120
+    function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode=0, $sqlfilters = '')
121
+    {
122
+        global $db, $conf;
123
+
124
+        $obj_ret = array();
125
+
126
+        // case of external user, we force socids
127
+        $socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : '';
128
+
129
+        // If the internal user must only see his customers, force searching by him
130
+        $search_sale = 0;
131
+        if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
132
+
133
+        $sql = "SELECT t.rowid";
134
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
135
+        $sql.= " FROM ".MAIN_DB_PREFIX."societe as t";
136
+
137
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
138
+        $sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st";
139
+        $sql.= " WHERE t.fk_stcomm = st.id";
140
+        if ($mode == 1) $sql.= " AND t.client IN (1, 3)";
141
+        if ($mode == 2) $sql.= " AND t.client IN (2, 3)";
142
+        if ($mode == 3) $sql.= " AND t.client IN (0)";
143
+        $sql.= ' AND t.entity IN ('.getEntity('societe').')';
144
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";
145
+        //if ($email != NULL) $sql.= " AND s.email = \"".$email."\"";
146
+        if ($socid) $sql.= " AND t.rowid IN (".$socids.")";
147
+        if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";		// Join for the needed table to filter by sale
148
+        // Insert sale filter
149
+        if ($search_sale > 0)
150
+        {
151
+            $sql .= " AND sc.fk_user = ".$search_sale;
152
+        }
153
+        // Add sql filters
154
+        if ($sqlfilters)
155
+        {
156
+            if (! DolibarrApi::_checkFilters($sqlfilters))
157
+            {
158
+                throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
159
+            }
160
+            $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
161
+            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
162
+        }
163
+
164
+        $sql.= $db->order($sortfield, $sortorder);
165
+
166
+        if ($limit) {
167
+            if ($page < 0)
168
+            {
169
+                $page = 0;
170
+            }
171
+            $offset = $limit * $page;
172
+
173
+            $sql.= $db->plimit($limit + 1, $offset);
174
+        }
175
+
176
+        $result = $db->query($sql);
177
+        if ($result)
178
+        {
179
+            $num = $db->num_rows($result);
180
+            $min = min($num, ($limit <= 0 ? $num : $limit));
181
+            while ($i < $min)
182
+            {
183
+                $obj = $db->fetch_object($result);
184
+                $soc_static = new Societe($db);
185
+                if($soc_static->fetch($obj->rowid)) {
186
+                    $obj_ret[] = $this->_cleanObjectDatas($soc_static);
187
+                }
188
+                $i++;
189
+            }
190
+        }
191
+        else {
192
+            throw new RestException(503, 'Error when retrieve thirdparties : '.$db->lasterror());
193
+        }
194
+        if( ! count($obj_ret)) {
195
+            throw new RestException(404, 'Thirdparties not found');
196
+        }
197
+        return $obj_ret;
198
+    }
199
+
200
+    /**
201
+     * Create thirdparty object
202
+     *
203
+     * @param array $request_data   Request datas
204
+     * @return int  ID of thirdparty
205
+     */
206
+    function post($request_data = null)
207
+    {
208
+        if(! DolibarrApiAccess::$user->rights->societe->creer) {
209
+            throw new RestException(401);
210
+        }
211
+        // Check mandatory fields
212
+        $result = $this->_validate($request_data);
213
+
214
+        foreach($request_data as $field => $value) {
215
+            $this->company->$field = $value;
216
+        }
217
+        if ($this->company->create(DolibarrApiAccess::$user) < 0)
218
+            throw new RestException(500, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors));
219
+
220
+        return $this->company->id;
221
+    }
222
+
223
+    /**
224
+     * Update thirdparty
225
+     *
226
+     * @param int   $id             Id of thirdparty to update
227
+     * @param array $request_data   Datas
228
+     * @return int
229
+     */
230
+    function put($id, $request_data = null)
231
+    {
232
+        if(! DolibarrApiAccess::$user->rights->societe->creer) {
233
+            throw new RestException(401);
234
+        }
235
+
236
+        $result = $this->company->fetch($id);
237
+        if( ! $result ) {
238
+            throw new RestException(404, 'Thirdparty not found');
239
+        }
240
+
241
+        if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
242
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
243
+        }
244
+
245
+        foreach($request_data as $field => $value) {
246
+            if ($field == 'id') continue;
247
+            $this->company->$field = $value;
248
+        }
249
+
250
+        if($this->company->update($id, DolibarrApiAccess::$user,1,'','','update'))
251
+            return $this->get($id);
252
+
253
+        return false;
254
+    }
255
+
256
+    /**
257
+     * Merge a thirdparty into another one.
258
+     *
259
+     * Merge content (properties, notes) and objects (like invoices, events, orders, proposals, ...) of a thirdparty into a target thirdparty,
260
+     * then delete the merged thirdparty.
261
+     * If a property has a defined value both in thirdparty to delete and thirdparty to keep, the value into the thirdparty to
262
+     * delete will be ignored, the value of target thirdparty will remain, except for notes (content is concatenated).
263
+     *
264
+     * @param int   $id             ID of thirdparty to keep (the target thirdparty)
265
+     * @param int   $idtodelete     ID of thirdparty to remove (the thirdparty to delete), once data has been merged into the target thirdparty.
266
+     * @return int
267
+     *
268
+     * @url PUT {id}/merge/{idtodelete}
269
+     */
270
+    function merge($id, $idtodelete)
271
+    {
272
+        global $db, $hookmanager;
273
+
274
+        $error = 0;
275
+
276
+        if ($id == $idtodelete)
277
+        {
278
+            throw new RestException(400, 'Try to merge a thirdparty into itself');
279
+        }
280
+
281
+        if(! DolibarrApiAccess::$user->rights->societe->creer) {
282
+            throw new RestException(401);
283
+        }
284
+
285
+        $result = $this->company->fetch($id);	// include the fetch of extra fields
286
+        if( ! $result ) {
287
+            throw new RestException(404, 'Thirdparty not found');
288
+        }
289
+
290
+        if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
291
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
292
+        }
293
+
294
+        $this->companytoremove = new Societe($db);
295
+
296
+        $result = $this->companytoremove->fetch($idtodelete);	// include the fetch of extra fields
297
+        if( ! $result ) {
298
+            throw new RestException(404, 'Thirdparty not found');
299
+        }
300
+
301
+        if( ! DolibarrApi::_checkAccessToResource('societe',$this->companytoremove->id)) {
302
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
303
+        }
304
+
305
+        $soc_origin = $this->companytoremove;
306
+        $object = $this->company;
307
+        $user = DolibarrApiAccess::$user;
308
+
309
+
310
+        // Call same code than into action 'confirm_merge'
311
+
312
+
313
+        $db->begin();
314
+
315
+        // Recopy some data
316
+        $object->client = $object->client | $soc_origin->client;
317
+        $object->fournisseur = $object->fournisseur | $soc_origin->fournisseur;
318
+        $listofproperties=array(
319
+            'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'skype', 'url', 'barcode',
320
+            'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6',
321
+            'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'remise_supplier_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis',
322
+            'stcomm_id', 'outstanding_limit', 'price_level', 'parent', 'default_lang', 'ref', 'ref_ext', 'import_key', 'fk_incoterms', 'fk_multicurrency',
323
+            'code_client', 'code_fournisseur', 'code_compta', 'code_compta_fournisseur',
324
+            'model_pdf', 'fk_projet'
325
+        );
326
+        foreach ($listofproperties as $property)
327
+        {
328
+            if (empty($object->$property)) $object->$property = $soc_origin->$property;
329
+        }
330
+
331
+        // Concat some data
332
+        $listofproperties=array(
333
+            'note_public', 'note_private'
334
+        );
335
+        foreach ($listofproperties as $property)
336
+        {
337
+            $object->$property = dol_concatdesc($object->$property, $soc_origin->$property);
338
+        }
339
+
340
+        // Merge extrafields
341
+        if (is_array($soc_origin->array_options))
342
+        {
343
+            foreach ($soc_origin->array_options as $key => $val)
344
+            {
345
+                if (empty($object->array_options[$key])) $object->array_options[$key] = $val;
346
+            }
347
+        }
348
+
349
+        // Merge categories
350
+        $static_cat = new Categorie($db);
351
+        $custcats = $static_cat->containing($soc_origin->id, 'customer', 'id');
352
+        $object->setCategories($custcats, 'customer');
353
+        $suppcats = $static_cat->containing($soc_origin->id, 'supplier', 'id');
354
+        $object->setCategories($suppcats, 'supplier');
355
+
356
+        // If thirdparty has a new code that is same than origin, we clean origin code to avoid duplicate key from database unique keys.
357
+        if ($soc_origin->code_client == $object->code_client
358
+            || $soc_origin->code_fournisseur == $object->code_fournisseur
359
+            || $soc_origin->barcode == $object->barcode)
360
+        {
361
+            dol_syslog("We clean customer and supplier code so we will be able to make the update of target");
362
+            $soc_origin->code_client = '';
363
+            $soc_origin->code_fournisseur = '';
364
+            $soc_origin->barcode = '';
365
+            $soc_origin->update($soc_origin->id, $user, 0, 1, 1, 'merge');
366
+        }
367
+
368
+        // Update
369
+        $result = $object->update($object->id, $user, 0, 1, 1, 'merge');
370
+        if ($result < 0)
371
+        {
372
+            $error++;
373
+        }
374
+
375
+        // Move links
376
+        if (! $error)
377
+        {
378
+            $objects = array(
379
+                'Adherent' => '/adherents/class/adherent.class.php',
380
+                'Societe' => '/societe/class/societe.class.php',
381
+                'Categorie' => '/categories/class/categorie.class.php',
382
+                'ActionComm' => '/comm/action/class/actioncomm.class.php',
383
+                'Propal' => '/comm/propal/class/propal.class.php',
384
+                'Commande' => '/commande/class/commande.class.php',
385
+                'Facture' => '/compta/facture/class/facture.class.php',
386
+                'FactureRec' => '/compta/facture/class/facture-rec.class.php',
387
+                'LignePrelevement' => '/compta/prelevement/class/ligneprelevement.class.php',
388
+                'Contact' => '/contact/class/contact.class.php',
389
+                'Contrat' => '/contrat/class/contrat.class.php',
390
+                'Expedition' => '/expedition/class/expedition.class.php',
391
+                'Fichinter' => '/fichinter/class/fichinter.class.php',
392
+                'CommandeFournisseur' => '/fourn/class/fournisseur.commande.class.php',
393
+                'FactureFournisseur' => '/fourn/class/fournisseur.facture.class.php',
394
+                'SupplierProposal' => '/supplier_proposal/class/supplier_proposal.class.php',
395
+                'ProductFournisseur' => '/fourn/class/fournisseur.product.class.php',
396
+                'Livraison' => '/livraison/class/livraison.class.php',
397
+                'Product' => '/product/class/product.class.php',
398
+                'Project' => '/projet/class/project.class.php',
399
+                'User' => '/user/class/user.class.php',
400
+            );
401
+
402
+            //First, all core objects must update their tables
403
+            foreach ($objects as $object_name => $object_file)
404
+            {
405
+                require_once DOL_DOCUMENT_ROOT.$object_file;
406
+
407
+                if (!$errors && !$object_name::replaceThirdparty($db, $soc_origin->id, $object->id))
408
+                {
409
+                    $errors++;
410
+                    //setEventMessages($db->lasterror(), null, 'errors');
411
+                }
412
+            }
413
+        }
414
+
415
+        // External modules should update their ones too
416
+        if (!$errors)
417
+        {
418
+            $reshook = $hookmanager->executeHooks('replaceThirdparty', array(
419
+                'soc_origin' => $soc_origin->id,
420
+                'soc_dest' => $object->id
421
+            ), $soc_dest, $action);
422
+
423
+            if ($reshook < 0)
424
+            {
425
+                //setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
426
+                $errors++;
427
+            }
428
+        }
429
+
430
+
431
+        if (! $error)
432
+        {
433
+            $object->context=array('merge'=>1, 'mergefromid'=>$soc_origin->id);
434
+
435
+            // Call trigger
436
+            $result=$object->call_trigger('COMPANY_MODIFY',$user);
437
+            if ($result < 0)
438
+            {
439
+                //setEventMessages($object->error, $object->errors, 'errors');
440
+                $error++;
441
+            }
442
+            // End call triggers
443
+        }
444
+
445
+        if (! $error)
446
+        {
447
+            //We finally remove the old thirdparty
448
+            if ($soc_origin->delete($soc_origin->id, $user) < 1)
449
+            {
450
+                $errors++;
451
+            }
452
+        }
453
+
454
+        // End of merge
455
+
456
+        if ($error)
457
+        {
458
+            $db->rollback();
459
+
460
+            throw new RestException(500, 'Error failed to merged thirdparty '.$this->companytoremove->id.' into '.$id.'. Enable and read log file for more information.');
461
+        }
462
+        else
463
+        {
464
+            $db->commit();
465
+        }
466
+
467
+        return $this->get($id);
468
+    }
469
+
470
+    /**
471
+     * Delete thirdparty
472
+     *
473
+     * @param int $id   Thirparty ID
474
+     * @return integer
475
+     */
476
+    function delete($id)
934 477
     {
935
-		if(! DolibarrApiAccess::$user->rights->facture->lire) {
936
-			throw new RestException(401);
937
-		}
938
-		if(empty($id)) {
939
-			throw new RestException(400, 'Thirdparty ID is mandatory');
940
-		}
941
-
942
-		if( ! DolibarrApi::_checkAccessToResource('societe',$id)) {
943
-			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
944
-		}
945
-
946
-		/*$result = $this->thirdparty->fetch($id);
478
+        if(! DolibarrApiAccess::$user->rights->societe->supprimer) {
479
+            throw new RestException(401);
480
+        }
481
+        $result = $this->company->fetch($id);
482
+        if( ! $result ) {
483
+            throw new RestException(404, 'Thirdparty not found');
484
+        }
485
+        if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
486
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
487
+        }
488
+        return $this->company->delete($id);
489
+    }
490
+
491
+    /**
492
+     * Get customer categories for a thirdparty
493
+     *
494
+     * @param int		$id         ID of thirdparty
495
+     * @param string	$sortfield	Sort field
496
+     * @param string	$sortorder	Sort order
497
+     * @param int		$limit		Limit for list
498
+     * @param int		$page		Page number
499
+     *
500
+     * @return mixed
501
+     *
502
+     * @url GET {id}/categories
503
+     */
504
+    function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
505
+    {
506
+        if (! DolibarrApiAccess::$user->rights->categorie->lire) {
507
+            throw new RestException(401);
508
+        }
509
+
510
+        $result = $this->company->fetch($id);
511
+        if( ! $result )
512
+        {
513
+            throw new RestException(404, 'Thirdparty not found');
514
+        }
515
+
516
+        $categories = new Categorie($this->db);
517
+
518
+        $result = $categories->getListForItem($id, 'customer', $sortfield, $sortorder, $limit, $page);
519
+
520
+        if (is_numeric($result) && $result < 0)
521
+        {
522
+            throw new RestException(503, 'Error when retrieve category list : '.$categories->error);
523
+        }
524
+
525
+        if (is_numeric($result) && $result == 0)	// To fix a return of 0 instead of empty array of method getListForItem
526
+        {
527
+            return array();
528
+        }
529
+
530
+        return $result;
531
+    }
532
+
533
+    /**
534
+     * Add a customer category to a thirdparty
535
+     *
536
+     * @param int		$id				Id of thirdparty
537
+     * @param int       $category_id	Id of category
538
+     *
539
+     * @return mixed
540
+     *
541
+     * @url POST {id}/categories/{category_id}
542
+     */
543
+    function addCategory($id, $category_id)
544
+    {
545
+        if(! DolibarrApiAccess::$user->rights->societe->creer) {
546
+            throw new RestException(401);
547
+        }
548
+
549
+        $result = $this->company->fetch($id);
550
+        if( ! $result ) {
551
+            throw new RestException(404, 'Thirdparty not found');
552
+        }
553
+        $category = new Categorie($this->db);
554
+        $result = $category->fetch($category_id);
555
+        if( ! $result ) {
556
+            throw new RestException(404, 'category not found');
557
+        }
558
+
559
+        if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
560
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
561
+        }
562
+        if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) {
563
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
564
+        }
565
+
566
+        $category->add_type($this->company,'customer');
567
+
568
+        return $this->_cleanObjectDatas($this->company);
569
+    }
570
+
571
+    /**
572
+     * Remove the link between a customer category and the thirdparty
573
+     *
574
+     * @param int		$id				Id of thirdparty
575
+     * @param int		$category_id	Id of category
576
+     *
577
+     * @return mixed
578
+     *
579
+     * @url DELETE {id}/categories/{category_id}
580
+     */
581
+    function deleteCategory($id, $category_id)
582
+    {
583
+        if(! DolibarrApiAccess::$user->rights->societe->creer) {
584
+            throw new RestException(401);
585
+        }
586
+
587
+        $result = $this->company->fetch($id);
588
+        if( ! $result ) {
589
+            throw new RestException(404, 'Thirdparty not found');
590
+        }
591
+        $category = new Categorie($this->db);
592
+        $result = $category->fetch($category_id);
593
+        if( ! $result ) {
594
+            throw new RestException(404, 'category not found');
595
+        }
596
+
597
+        if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
598
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
599
+        }
600
+        if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) {
601
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
602
+        }
603
+
604
+        $category->del_type($this->company,'customer');
605
+
606
+        return $this->_cleanObjectDatas($this->company);
607
+    }
608
+
609
+    /**
610
+     * Get supplier categories for a thirdparty
611
+     *
612
+     * @param int		$id         ID of thirdparty
613
+     * @param string	$sortfield	Sort field
614
+     * @param string	$sortorder	Sort order
615
+     * @param int		$limit		Limit for list
616
+     * @param int		$page		Page number
617
+     *
618
+     * @return mixed
619
+     *
620
+     * @url GET {id}/supplier_categories
621
+     */
622
+    function getSupplierCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
623
+    {
624
+        if (! DolibarrApiAccess::$user->rights->categorie->lire) {
625
+            throw new RestException(401);
626
+        }
627
+
628
+        $result = $this->company->fetch($id);
629
+        if( ! $result )
630
+        {
631
+            throw new RestException(404, 'Thirdparty not found');
632
+        }
633
+
634
+        $categories = new Categorie($this->db);
635
+
636
+        $result = $categories->getListForItem($id, 'supplier', $sortfield, $sortorder, $limit, $page);
637
+
638
+        if (is_numeric($result) && $result < 0)
639
+        {
640
+            throw new RestException(503, 'Error when retrieve category list : '.$categories->error);
641
+        }
642
+
643
+        if (is_numeric($result) && $result == 0)	// To fix a return of 0 instead of empty array of method getListForItem
644
+        {
645
+            return array();
646
+        }
647
+
648
+        return $result;
649
+    }
650
+
651
+    /**
652
+     * Add a supplier category to a thirdparty
653
+     *
654
+     * @param int		$id				Id of thirdparty
655
+     * @param int       $category_id	Id of category
656
+     *
657
+     * @return mixed
658
+     *
659
+     * @url POST {id}/supplier_categories/{category_id}
660
+     */
661
+    function addSupplierCategory($id, $category_id)
662
+    {
663
+        if(! DolibarrApiAccess::$user->rights->societe->creer) {
664
+            throw new RestException(401);
665
+        }
666
+
667
+        $result = $this->company->fetch($id);
668
+        if( ! $result ) {
669
+            throw new RestException(404, 'Thirdparty not found');
670
+        }
671
+        $category = new Categorie($this->db);
672
+        $result = $category->fetch($category_id);
673
+        if( ! $result ) {
674
+            throw new RestException(404, 'category not found');
675
+        }
676
+
677
+        if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
678
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
679
+        }
680
+        if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) {
681
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
682
+        }
683
+
684
+        $category->add_type($this->company,'supplier');
685
+
686
+        return $this->_cleanObjectDatas($this->company);
687
+    }
688
+
689
+    /**
690
+     * Remove the link between a category and the thirdparty
691
+     *
692
+     * @param int		$id				Id of thirdparty
693
+     * @param int		$category_id	Id of category
694
+     *
695
+     * @return mixed
696
+     *
697
+     * @url DELETE {id}/supplier_categories/{category_id}
698
+     */
699
+    function deleteSupplierCategory($id, $category_id)
700
+    {
701
+        if(! DolibarrApiAccess::$user->rights->societe->creer) {
702
+            throw new RestException(401);
703
+        }
704
+
705
+        $result = $this->company->fetch($id);
706
+        if( ! $result ) {
707
+            throw new RestException(404, 'Thirdparty not found');
708
+        }
709
+        $category = new Categorie($this->db);
710
+        $result = $category->fetch($category_id);
711
+        if( ! $result ) {
712
+            throw new RestException(404, 'category not found');
713
+        }
714
+
715
+        if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
716
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
717
+        }
718
+        if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) {
719
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
720
+        }
721
+
722
+        $category->del_type($this->company,'supplier');
723
+
724
+        return $this->_cleanObjectDatas($this->company);
725
+    }
726
+
727
+
728
+    /**
729
+     * Get outstanding proposals of thirdparty
730
+     *
731
+     * @param 	int 	$id			ID of the thirdparty
732
+     * @param 	string 	$mode		'customer' or 'supplier'
733
+     *
734
+     * @url     GET {id}/outstandingproposals
735
+     *
736
+     * @return array  				List of outstandings proposals of thirdparty
737
+     *
738
+     * @throws 400
739
+     * @throws 401
740
+     * @throws 404
741
+     */
742
+    function getOutStandingProposals($id, $mode='customer')
743
+    {
744
+        $obj_ret = array();
745
+
746
+        if(! DolibarrApiAccess::$user->rights->societe->lire) {
747
+            throw new RestException(401);
748
+        }
749
+
750
+        if(empty($id)) {
751
+            throw new RestException(400, 'Thirdparty ID is mandatory');
752
+        }
753
+
754
+        if( ! DolibarrApi::_checkAccessToResource('societe',$id)) {
755
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
756
+        }
757
+
758
+        $result = $this->company->fetch($id);
759
+        if( ! $result ) {
760
+            throw new RestException(404, 'Thirdparty not found');
761
+        }
762
+
763
+        $result = $this->company->getOutstandingProposals($mode);
764
+
765
+        unset($result['total_ht']);
766
+        unset($result['total_ttc']);
767
+
768
+        return $result;
769
+    }
770
+
771
+
772
+    /**
773
+     * Get outstanding orders of thirdparty
774
+     *
775
+     * @param 	int 	$id			ID of the thirdparty
776
+     * @param 	string 	$mode		'customer' or 'supplier'
777
+     *
778
+     * @url     GET {id}/outstandingorders
779
+     *
780
+     * @return array  				List of outstandings orders of thirdparty
781
+     *
782
+     * @throws 400
783
+     * @throws 401
784
+     * @throws 404
785
+     */
786
+    function getOutStandingOrder($id, $mode='customer')
787
+    {
788
+        $obj_ret = array();
789
+
790
+        if(! DolibarrApiAccess::$user->rights->societe->lire) {
791
+            throw new RestException(401);
792
+        }
793
+
794
+        if(empty($id)) {
795
+            throw new RestException(400, 'Thirdparty ID is mandatory');
796
+        }
797
+
798
+        if( ! DolibarrApi::_checkAccessToResource('societe',$id)) {
799
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
800
+        }
801
+
802
+        $result = $this->company->fetch($id);
803
+        if( ! $result ) {
804
+            throw new RestException(404, 'Thirdparty not found');
805
+        }
806
+
807
+        $result = $this->company->getOutstandingOrders($mode);
808
+
809
+        unset($result['total_ht']);
810
+        unset($result['total_ttc']);
811
+
812
+        return $result;
813
+    }
814
+
815
+    /**
816
+     * Get outstanding invoices of thirdparty
817
+     *
818
+     * @param 	int 	$id			ID of the thirdparty
819
+     * @param 	string 	$mode		'customer' or 'supplier'
820
+     *
821
+     * @url     GET {id}/outstandinginvoices
822
+     *
823
+     * @return array  				List of outstandings invoices of thirdparty
824
+     *
825
+     * @throws 400
826
+     * @throws 401
827
+     * @throws 404
828
+     */
829
+    function getOutStandingInvoices($id, $mode='customer')
830
+    {
831
+        $obj_ret = array();
832
+
833
+        if(! DolibarrApiAccess::$user->rights->societe->lire) {
834
+            throw new RestException(401);
835
+        }
836
+
837
+        if(empty($id)) {
838
+            throw new RestException(400, 'Thirdparty ID is mandatory');
839
+        }
840
+
841
+        if( ! DolibarrApi::_checkAccessToResource('societe',$id)) {
842
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
843
+        }
844
+
845
+        $result = $this->company->fetch($id);
846
+        if( ! $result ) {
847
+            throw new RestException(404, 'Thirdparty not found');
848
+        }
849
+
850
+        $result = $this->company->getOutstandingBills($mode);
851
+
852
+        unset($result['total_ht']);
853
+        unset($result['total_ttc']);
854
+
855
+        return $result;
856
+    }
857
+
858
+    /**
859
+     * Get fixed amount discount of a thirdparty (all sources: deposit, credit note, commercial offers...)
860
+     *
861
+     * @param 	int 	$id             ID of the thirdparty
862
+     * @param 	string 	$filter    	Filter exceptional discount. "none" will return every discount, "available" returns unapplied discounts, "used" returns applied discounts   {@choice none,available,used}
863
+     * @param   string  $sortfield  	Sort field
864
+     * @param   string  $sortorder  	Sort order
865
+     *
866
+     * @url     GET {id}/fixedamountdiscounts
867
+     *
868
+     * @return array  List of fixed discount of thirdparty
869
+     *
870
+     * @throws 400
871
+     * @throws 401
872
+     * @throws 404
873
+     * @throws 503
874
+     */
875
+    function getFixedAmountDiscounts($id, $filter="none", $sortfield = "f.type", $sortorder = 'ASC')
876
+    {
877
+        $obj_ret = array();
878
+
879
+        if(! DolibarrApiAccess::$user->rights->societe->lire) {
880
+            throw new RestException(401);
881
+        }
882
+
883
+        if(empty($id)) {
884
+            throw new RestException(400, 'Thirdparty ID is mandatory');
885
+        }
886
+
887
+        if( ! DolibarrApi::_checkAccessToResource('societe',$id)) {
888
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
889
+        }
890
+
891
+        $result = $this->company->fetch($id);
892
+        if( ! $result ) {
893
+            throw new RestException(404, 'Thirdparty not found');
894
+        }
895
+
896
+
897
+        $sql = "SELECT f.ref, f.type as factype, re.fk_facture_source, re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc, re.description, re.fk_facture, re.fk_facture_line";
898
+        $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
899
+        $sql .= " WHERE f.rowid = re.fk_facture_source AND re.fk_soc = ".$id;
900
+        if ($filter == "available")  $sql .= " AND re.fk_facture IS NULL AND re.fk_facture_line IS NULL";
901
+        if ($filter == "used")  $sql .= " AND (re.fk_facture IS NOT NULL OR re.fk_facture_line IS NOT NULL)";
902
+
903
+        $sql.= $this->db->order($sortfield, $sortorder);
904
+
905
+        $result = $this->db->query($sql);
906
+        if( ! $result ) {
907
+            throw new RestException(503, $this->db->lasterror());
908
+        } else {
909
+            $num = $this->db->num_rows($result);
910
+            while ( $obj = $this->db->fetch_object($result) ) {
911
+                $obj_ret[] = $obj;
912
+            }
913
+        }
914
+
915
+        return $obj_ret;
916
+    }
917
+
918
+
919
+
920
+    /**
921
+     * Return list of invoices qualified to be replaced by another invoice.
922
+     *
923
+     * @param int   $id             Id of thirdparty
924
+     *
925
+     * @url     GET {id}/getinvoicesqualifiedforreplacement
926
+     *
927
+     * @return array
928
+     * @throws 400
929
+     * @throws 401
930
+     * @throws 404
931
+     * @throws 405
932
+     */
933
+    function getInvoicesQualifiedForReplacement($id)
934
+    {
935
+        if(! DolibarrApiAccess::$user->rights->facture->lire) {
936
+            throw new RestException(401);
937
+        }
938
+        if(empty($id)) {
939
+            throw new RestException(400, 'Thirdparty ID is mandatory');
940
+        }
941
+
942
+        if( ! DolibarrApi::_checkAccessToResource('societe',$id)) {
943
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
944
+        }
945
+
946
+        /*$result = $this->thirdparty->fetch($id);
947 947
 		 if( ! $result ) {
948 948
 		 throw new RestException(404, 'Thirdparty not found');
949 949
 		 }*/
950 950
 
951
-		$invoice = new Facture($this->db);
952
-		$result = $invoice->list_replacable_invoices($id);
953
-		if( $result < 0) {
954
-			throw new RestException(405, $this->thirdparty->error);
955
-		}
956
-
957
-		return $result;
958
-	}
959
-
960
-	/**
961
-	 * Return list of invoices qualified to be corrected by a credit note.
962
-	 * Invoices matching the following rules are returned
963
-	 * (validated + payment on process) or classified (payed completely or payed partialy) + not already replaced + not already a credit note
964
-	 *
965
-	 * @param int   $id             Id of thirdparty
966
-	 *
967
-	 * @url     GET {id}/getinvoicesqualifiedforcreditnote
968
-	 *
969
-	 * @return array
970
-	 * @throws 400
971
-	 * @throws 401
972
-	 * @throws 404
973
-	 * @throws 405
974
-	 */
975
-	function getInvoicesQualifiedForCreditNote($id)
951
+        $invoice = new Facture($this->db);
952
+        $result = $invoice->list_replacable_invoices($id);
953
+        if( $result < 0) {
954
+            throw new RestException(405, $this->thirdparty->error);
955
+        }
956
+
957
+        return $result;
958
+    }
959
+
960
+    /**
961
+     * Return list of invoices qualified to be corrected by a credit note.
962
+     * Invoices matching the following rules are returned
963
+     * (validated + payment on process) or classified (payed completely or payed partialy) + not already replaced + not already a credit note
964
+     *
965
+     * @param int   $id             Id of thirdparty
966
+     *
967
+     * @url     GET {id}/getinvoicesqualifiedforcreditnote
968
+     *
969
+     * @return array
970
+     * @throws 400
971
+     * @throws 401
972
+     * @throws 404
973
+     * @throws 405
974
+     */
975
+    function getInvoicesQualifiedForCreditNote($id)
976 976
     {
977
-		if(! DolibarrApiAccess::$user->rights->facture->lire) {
978
-			throw new RestException(401);
979
-		}
980
-		if(empty($id)) {
981
-			throw new RestException(400, 'Thirdparty ID is mandatory');
982
-		}
983
-
984
-		if( ! DolibarrApi::_checkAccessToResource('societe',$id)) {
985
-			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
986
-		}
987
-
988
-		/*$result = $this->thirdparty->fetch($id);
977
+        if(! DolibarrApiAccess::$user->rights->facture->lire) {
978
+            throw new RestException(401);
979
+        }
980
+        if(empty($id)) {
981
+            throw new RestException(400, 'Thirdparty ID is mandatory');
982
+        }
983
+
984
+        if( ! DolibarrApi::_checkAccessToResource('societe',$id)) {
985
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
986
+        }
987
+
988
+        /*$result = $this->thirdparty->fetch($id);
989 989
 		 if( ! $result ) {
990 990
 		 throw new RestException(404, 'Thirdparty not found');
991 991
 		 }*/
992 992
 
993
-		$invoice = new Facture($this->db);
994
-		$result = $invoice->list_qualified_avoir_invoices($id);
995
-		if( $result < 0) {
996
-			throw new RestException(405, $this->thirdparty->error);
997
-		}
998
-
999
-		return $result;
1000
-	}
1001
-
1002
-	/**
1003
-	 * Get CompanyBankAccount objects for thirdparty
1004
-	 *
1005
-	 * @param int $id ID of thirdparty
1006
-	 *
1007
-	 * @return array
1008
-	 *
1009
-	 * @url GET {id}/bankaccounts
1010
-	 */
1011
-	function getCompanyBankAccount($id)
993
+        $invoice = new Facture($this->db);
994
+        $result = $invoice->list_qualified_avoir_invoices($id);
995
+        if( $result < 0) {
996
+            throw new RestException(405, $this->thirdparty->error);
997
+        }
998
+
999
+        return $result;
1000
+    }
1001
+
1002
+    /**
1003
+     * Get CompanyBankAccount objects for thirdparty
1004
+     *
1005
+     * @param int $id ID of thirdparty
1006
+     *
1007
+     * @return array
1008
+     *
1009
+     * @url GET {id}/bankaccounts
1010
+     */
1011
+    function getCompanyBankAccount($id)
1012
+    {
1013
+        global $db, $conf;
1014
+
1015
+        if(! DolibarrApiAccess::$user->rights->facture->lire) {
1016
+            throw new RestException(401);
1017
+        }
1018
+        if(empty($id)) {
1019
+            throw new RestException(400, 'Thirdparty ID is mandatory');
1020
+        }
1021
+
1022
+        if( ! DolibarrApi::_checkAccessToResource('societe',$id)) {
1023
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
1024
+        }
1025
+
1026
+        /**
1027
+         * We select all the records that match the socid
1028
+         */
1029
+
1030
+        $sql = "SELECT rowid, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,";
1031
+        $sql.= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur";
1032
+        $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib";
1033
+        if ($id) $sql.= " WHERE fk_soc  = ".$id." ";
1034
+
1035
+
1036
+        $result = $db->query($sql);
1037
+
1038
+        if($result->num_rows == 0 ){
1039
+            throw new RestException(404, 'Account not found');
1040
+        }
1041
+
1042
+        $i=0;
1043
+
1044
+        $accounts =[];
1045
+
1046
+        if ($result)
1047
+        {
1048
+            $num = $db->num_rows($result);
1049
+            while ($i < $num)
1050
+            {
1051
+                $obj = $db->fetch_object($result);
1052
+                $account = new CompanyBankAccount($db);
1053
+                if($account->fetch($obj->rowid)) {
1054
+                    $accounts[] = $account;
1055
+                }
1056
+                $i++;
1057
+            }
1058
+        }
1059
+        else{
1060
+            throw new RestException(404, 'Account not found');
1061
+        }
1062
+
1063
+
1064
+        $fields = ['socid', 'default_rib', 'frstrecur', '1000110000001', 'datec', 'datem', 'label', 'bank', 'bic', 'iban', 'id', 'rum'];
1065
+
1066
+        $returnAccounts = [];
1067
+
1068
+        foreach($accounts as $account){
1069
+            $object= [];
1070
+            foreach($account as $key => $value)
1071
+                if(in_array($key, $fields)){
1072
+                    $object[$key] = $value;
1073
+                }
1074
+            $returnAccounts[] = $object;
1075
+        }
1076
+
1077
+        return $returnAccounts;
1078
+    }
1079
+
1080
+    /**
1081
+     * Create CompanyBankAccount object for thirdparty
1082
+     * @param int  $id ID of thirdparty
1083
+     * @param array $request_data Request data
1084
+     *
1085
+     * @return object  ID of thirdparty
1086
+     *
1087
+     * @url POST {id}/bankaccounts
1088
+     */
1089
+    function createCompanyBankAccount($id, $request_data = null)
1090
+    {
1091
+        if(! DolibarrApiAccess::$user->rights->societe->creer) {
1092
+            throw new RestException(401);
1093
+        }
1094
+
1095
+        $account = new CompanyBankAccount($this->db);
1096
+
1097
+        $account->socid = $id;
1098
+
1099
+        foreach($request_data as $field => $value) {
1100
+            $account->$field = $value;
1101
+        }
1102
+
1103
+        if ($account->create(DolibarrApiAccess::$user) < 0)
1104
+            throw new RestException(500, 'Error creating Company Bank account');
1105
+
1106
+
1107
+        if ($account->update(DolibarrApiAccess::$user) < 0)
1108
+            throw new RestException(500, 'Error updating values');
1109
+
1110
+        return $account;
1111
+    }
1112
+
1113
+    /**
1114
+     * Update CompanyBankAccount object for thirdparty
1115
+     *
1116
+     * @param int $id ID of thirdparty
1117
+     * @param int  $bankaccount_id ID of CompanyBankAccount
1118
+     * @param array $request_data Request data
1119
+     *
1120
+     * @return object  ID of thirdparty
1121
+     *
1122
+     * @url PUT {id}/bankaccounts/{bankaccount_id}
1123
+     */
1124
+    function updateCompanyBankAccount($id, $bankaccount_id, $request_data = null)
1125
+    {
1126
+        if(! DolibarrApiAccess::$user->rights->societe->creer) {
1127
+            throw new RestException(401);
1128
+        }
1129
+
1130
+        $account = new CompanyBankAccount($this->db);
1131
+
1132
+        $account->fetch($bankaccount_id, $id, -1, '');
1133
+
1134
+        if($account->socid != $id){
1135
+            throw new RestException(401);
1136
+        }
1137
+
1138
+
1139
+        foreach($request_data as $field => $value) {
1140
+            $account->$field = $value;
1141
+        }
1142
+
1143
+        if ($account->update(DolibarrApiAccess::$user) < 0)
1144
+            throw new RestException(500, 'Error updating values');
1145
+
1146
+        return $account;
1147
+    }
1148
+
1149
+    /**
1150
+     * Delete a bank account attached to a thirdparty
1151
+     *
1152
+     * @param int $id ID of thirdparty
1153
+     * @param int $bankaccount_id ID of CompanyBankAccount
1154
+     *
1155
+     * @return int -1 if error 1 if correct deletion
1156
+     *
1157
+     * @url DELETE {id}/bankaccounts/{bankaccount_id}
1158
+     */
1159
+    function deleteCompanyBankAccount($id, $bankaccount_id)
1160
+    {
1161
+        if(! DolibarrApiAccess::$user->rights->societe->creer) {
1162
+            throw new RestException(401);
1163
+        }
1164
+
1165
+        $account = new CompanyBankAccount($this->db);
1166
+
1167
+        $account->fetch($bankaccount_id);
1168
+
1169
+        if(!$account->socid == $id)
1170
+            throw new RestException(401);
1171
+
1172
+        return $account->delete(DolibarrApiAccess::$user);
1173
+    }
1174
+
1175
+    /**
1176
+     * Generate a Document from a bank account record (like SEPA mandate)
1177
+     *
1178
+     * @param int 		$id 			Thirdparty id
1179
+     * @param int 		$companybankid 	Companybank id
1180
+     * @param string 	$model 			Model of document to generate
1181
+     * @return void
1182
+     *
1183
+     * @url GET {id}/generateBankAccountDocument/{companybankid}/{model}
1184
+     */
1185
+    public function generateBankAccountDocument($id, $companybankid = null, $model = 'sepamandate')
1186
+    {
1187
+        global $conf;
1188
+
1189
+        $this->langs->loadLangs(array("main","dict","commercial","products","companies","banks","bills","withdrawals"));
1190
+
1191
+        $this->company->fetch($id);
1192
+
1193
+        $action = 'builddoc';
1194
+        if(! DolibarrApiAccess::$user->rights->societe->creer)
1195
+            throw new RestException(401);
1196
+
1197
+        $this->company->setDocModel(DolibarrApiAccess::$user, $model);
1198
+
1199
+        $this->company->fk_bank = $this->company->fk_account;
1200
+
1201
+        $outputlangs = $this->langs;
1202
+        $newlang='';
1203
+
1204
+        if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
1205
+        if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->thirdparty->default_lang)) $newlang=$this->company->thirdparty->default_lang;  // for proposal, order, invoice, ...
1206
+        if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->default_lang)) $newlang=$this->company->default_lang;                  // for thirdparty
1207
+        if (! empty($newlang)) {
1208
+            $outputlangs = new Translate("",$conf);
1209
+            $outputlangs->setDefaultLang($newlang);
1210
+        }
1211
+
1212
+        // To be sure vars is defined
1213
+        $hidedetails = $hidedesc = $hideref = 0;
1214
+        $moreparams=null;
1215
+        if (empty($hidedetails)) $hidedetails=0;
1216
+        if (empty($hidedesc)) $hidedesc=0;
1217
+        if (empty($hideref)) $hideref=0;
1218
+        if (empty($moreparams)) $moreparams=null;
1219
+
1220
+
1221
+        $sql = "SELECT rowid";
1222
+        $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib";
1223
+        if ($id) $sql.= " WHERE fk_soc  = ".$id." ";
1224
+        if ($companybankid) $sql.= " AND id = ".$companybankid."";
1225
+
1226
+        $i=0;
1227
+        $accounts=array();
1228
+
1229
+        $result = $this->db->query($sql);
1230
+        if ($result)
1231
+        {
1232
+            if ($result->num_rows == 0) {
1233
+                throw new RestException(404, 'Bank account not found');
1234
+            }
1235
+
1236
+            $num = $this->db->num_rows($result);
1237
+            while ($i < $num)
1238
+            {
1239
+                $obj = $this->db->fetch_object($result);
1240
+
1241
+                $account = new CompanyBankAccount($this->db);
1242
+                if ($account->fetch($obj->rowid)) {
1243
+                    $accounts[] = $account;
1244
+                }
1245
+                $i++;
1246
+            }
1247
+        }
1248
+        else
1249
+        {
1250
+            throw new RestException(404, 'Bank account not found');
1251
+        }
1252
+
1253
+        $moreparams = array(
1254
+            'use_companybankid'=>$accounts[0]->id,
1255
+            'force_dir_output'=>$this->conf->societe->multidir_output[$this->company->entity].'/'.dol_sanitizeFileName($this->company->id)
1256
+        );
1257
+
1258
+        $result = 0;
1259
+
1260
+        $result = $this->company->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1261
+
1262
+        if ($result > 0)
1263
+        {
1264
+            return array("success" => $result);
1265
+        }
1266
+        else
1267
+        {
1268
+            throw new RestException(500);
1269
+        }
1270
+    }
1271
+
1272
+    /**
1273
+     * Get a specific gateway attached to a thirdparty (by specifying the site key)
1274
+     *
1275
+     * @param int $id ID of thirdparty
1276
+     * @param string $site Site key
1277
+     *
1278
+     * @return SocieteAccount[]
1279
+     * @throws 401 Unauthorized: User does not have permission to read thirdparties
1280
+     * @throws 404 Not Found: Specified thirdparty ID does not belongs to an existing thirdparty
1281
+     *
1282
+     * @url GET {id}/gateways/
1283
+     */
1284
+    function getSocieteAccounts($id, $site=null)
1285
+    {
1286
+        global $db, $conf;
1287
+
1288
+        if(!DolibarrApiAccess::$user->rights->societe->lire) {
1289
+            throw new RestException(401);
1290
+        }
1291
+
1292
+        if(!DolibarrApi::_checkAccessToResource('societe',$id)) {
1293
+            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
1294
+        }
1295
+
1296
+        /**
1297
+         * We select all the records that match the socid
1298
+         */
1299
+        $sql = "SELECT rowid, fk_soc, key_account, site, date_creation, tms FROM ".MAIN_DB_PREFIX."societe_account";
1300
+        $sql.= " WHERE fk_soc = $id";
1301
+        if($site) $sql .= " AND site ='$site'";
1302
+
1303
+        $result = $db->query($sql);
1304
+
1305
+        if($result->num_rows == 0){
1306
+            throw new RestException(404, 'This thirdparty does not have any gateway attached or does not exist.');
1307
+        }
1308
+
1309
+        $i=0;
1310
+
1311
+        $accounts =[];
1312
+
1313
+        $num = $db->num_rows($result);
1314
+        while ($i < $num)
1315
+        {
1316
+            $obj = $db->fetch_object($result);
1317
+            $account = new SocieteAccount($db);
1318
+
1319
+            if($account->fetch($obj->rowid)) {
1320
+                $accounts[] = $account;
1321
+            }
1322
+            $i++;
1323
+        }
1324
+
1325
+        $fields = ['id', 'fk_soc', 'key_account', 'site', 'date_creation', 'tms'];
1326
+
1327
+        $returnAccounts = [];
1328
+
1329
+        foreach($accounts as $account){
1330
+            $object= [];
1331
+            foreach($account as $key => $value)
1332
+                if(in_array($key, $fields)){
1333
+                    $object[$key] = $value;
1334
+                }
1335
+            $returnAccounts[] = $object;
1336
+        }
1337
+
1338
+        return $returnAccounts;
1339
+    }
1340
+
1341
+    /**
1342
+     * Create and attach a new gateway to an existing thirdparty
1343
+     *
1344
+     * Possible fields for request_data (request body) are specified in <code>llx_societe_account</code> table.<br>
1345
+     * See <a href="https://wiki.dolibarr.org/index.php/Table_llx_societe_account">Table llx_societe_account</a> wiki page for more information<br><br>
1346
+     * <u>Example body payload :</u> <pre>{"key_account": "cus_DAVkLSs1LYyYI", "site": "stripe"}</pre>
1347
+     *
1348
+     * @param int $id ID of thirdparty
1349
+     * @param array $request_data Request data
1350
+     *
1351
+     * @return SocieteAccount
1352
+     * @throws 401 Unauthorized: User does not have permission to read thirdparties
1353
+     * @throws 409 Conflict: A SocieteAccount entity (gateway) already exists for this company and site.
1354
+     * @throws 422 Unprocessable Entity: You must pass the site attribute in your request data !
1355
+     * @throws 500 Internal Server Error: Error creating SocieteAccount account
1356
+     * @status 201
1357
+     *
1358
+     * @url POST {id}/gateways
1359
+     */
1360
+    function createSocieteAccount($id, $request_data = null)
1361
+    {
1362
+        global $db;
1363
+
1364
+        if(! DolibarrApiAccess::$user->rights->societe->creer) {
1365
+            throw new RestException(401);
1366
+        }
1367
+
1368
+        if(!isset($request_data['site'])) {
1369
+            throw new RestException(422, 'Unprocessable Entity: You must pass the site attribute in your request data !');
1370
+        }
1371
+
1372
+        $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = ".$id." AND site = '". $request_data['site']."' ";
1373
+        $result = $db->query($sql);
1374
+
1375
+        if($result->num_rows == 0 ){
1376
+            $account = new SocieteAccount($this->db);
1377
+            if(!isset($request_data['login'])) {
1378
+                $account->login = "";
1379
+            }
1380
+            $account->fk_soc = $id;
1381
+
1382
+            foreach($request_data as $field => $value) {
1383
+                $account->$field = $value;
1384
+            }
1385
+
1386
+            if ($account->create(DolibarrApiAccess::$user) < 0)
1387
+                throw new RestException(500, 'Error creating SocieteAccount entity. Ensure that the ID of thirdparty provided does exist!');
1388
+
1389
+            $this->_cleanObjectDatas($account);
1390
+
1391
+            return $account;
1392
+        } else {
1393
+            throw new RestException(409, 'A SocieteAccount entity already exists for this company and site.');
1394
+        }
1395
+    }
1396
+
1397
+    /**
1398
+     * Create and attach a new (or replace an existing) specific site gateway to a thirdparty
1399
+     *
1400
+     * You <strong>MUST</strong> pass all values to keep (otherwise, they will be deleted) !<br>
1401
+     * If you just need to update specific fields prefer <code>PATCH /thirdparties/{id}/gateways/{site}</code> endpoint.<br><br>
1402
+     * When a <strong>SocieteAccount</strong> entity does not exist for the <code>id</code> and <code>site</code>
1403
+     * supplied, a new one will be created. In that case <code>fk_soc</code> and <code>site</code> members form
1404
+     * request body payload will be ignored and <code>id</code> and <code>site</code> query strings parameters
1405
+     * will be used instead.
1406
+     *
1407
+     * @param int $id ID of thirdparty
1408
+     * @param string $site Site key
1409
+     * @param array $request_data Request data
1410
+     *
1411
+     * @return SocieteAccount
1412
+     * @throws 401 Unauthorized: User does not have permission to read thirdparties
1413
+     * @throws 422 Unprocessable Entity: You must pass the site attribute in your request data !
1414
+     * @throws 500 Internal Server Error: Error updating SocieteAccount entity
1415
+     *
1416
+     * @throws RestException
1417
+     * @url PUT {id}/gateways/{site}
1418
+     */
1419
+    function putSocieteAccount($id, $site, $request_data = null)
1012 1420
     {
1013
-		global $db, $conf;
1014
-
1015
-		if(! DolibarrApiAccess::$user->rights->facture->lire) {
1016
-			throw new RestException(401);
1017
-		}
1018
-		if(empty($id)) {
1019
-			throw new RestException(400, 'Thirdparty ID is mandatory');
1020
-		}
1021
-
1022
-		if( ! DolibarrApi::_checkAccessToResource('societe',$id)) {
1023
-			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
1024
-		}
1025
-
1026
-		/**
1027
-		 * We select all the records that match the socid
1028
-		 */
1029
-
1030
-		$sql = "SELECT rowid, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,";
1031
-		$sql.= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur";
1032
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe_rib";
1033
-		if ($id) $sql.= " WHERE fk_soc  = ".$id." ";
1034
-
1035
-
1036
-		$result = $db->query($sql);
1037
-
1038
-		if($result->num_rows == 0 ){
1039
-			throw new RestException(404, 'Account not found');
1040
-		}
1041
-
1042
-		$i=0;
1043
-
1044
-		$accounts =[];
1045
-
1046
-		if ($result)
1047
-		{
1048
-			$num = $db->num_rows($result);
1049
-			while ($i < $num)
1050
-			{
1051
-				$obj = $db->fetch_object($result);
1052
-				$account = new CompanyBankAccount($db);
1053
-				if($account->fetch($obj->rowid)) {
1054
-					$accounts[] = $account;
1055
-				}
1056
-				$i++;
1057
-			}
1058
-		}
1059
-		else{
1060
-			throw new RestException(404, 'Account not found');
1061
-		}
1062
-
1063
-
1064
-		$fields = ['socid', 'default_rib', 'frstrecur', '1000110000001', 'datec', 'datem', 'label', 'bank', 'bic', 'iban', 'id', 'rum'];
1065
-
1066
-		$returnAccounts = [];
1067
-
1068
-		foreach($accounts as $account){
1069
-			$object= [];
1070
-			foreach($account as $key => $value)
1071
-				if(in_array($key, $fields)){
1072
-					$object[$key] = $value;
1073
-				}
1074
-			$returnAccounts[] = $object;
1075
-		}
1076
-
1077
-		return $returnAccounts;
1078
-	}
1079
-
1080
-	/**
1081
-	 * Create CompanyBankAccount object for thirdparty
1082
-	 * @param int  $id ID of thirdparty
1083
-	 * @param array $request_data Request data
1084
-	 *
1085
-	 * @return object  ID of thirdparty
1086
-	 *
1087
-	 * @url POST {id}/bankaccounts
1088
-	 */
1089
-	function createCompanyBankAccount($id, $request_data = null)
1090
-	{
1091
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
1092
-			throw new RestException(401);
1093
-		}
1094
-
1095
-		$account = new CompanyBankAccount($this->db);
1096
-
1097
-		$account->socid = $id;
1098
-
1099
-		foreach($request_data as $field => $value) {
1100
-			$account->$field = $value;
1101
-		}
1102
-
1103
-		if ($account->create(DolibarrApiAccess::$user) < 0)
1104
-			throw new RestException(500, 'Error creating Company Bank account');
1105
-
1106
-
1107
-		if ($account->update(DolibarrApiAccess::$user) < 0)
1108
-			throw new RestException(500, 'Error updating values');
1109
-
1110
-		return $account;
1111
-	}
1112
-
1113
-	/**
1114
-	 * Update CompanyBankAccount object for thirdparty
1115
-	 *
1116
-	 * @param int $id ID of thirdparty
1117
-	 * @param int  $bankaccount_id ID of CompanyBankAccount
1118
-	 * @param array $request_data Request data
1119
-	 *
1120
-	 * @return object  ID of thirdparty
1121
-	 *
1122
-	 * @url PUT {id}/bankaccounts/{bankaccount_id}
1123
-	 */
1124
-	function updateCompanyBankAccount($id, $bankaccount_id, $request_data = null)
1125
-	{
1126
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
1127
-			throw new RestException(401);
1128
-		}
1129
-
1130
-		$account = new CompanyBankAccount($this->db);
1131
-
1132
-		$account->fetch($bankaccount_id, $id, -1, '');
1133
-
1134
-		if($account->socid != $id){
1135
-			throw new RestException(401);
1136
-		}
1137
-
1138
-
1139
-		foreach($request_data as $field => $value) {
1140
-			$account->$field = $value;
1141
-		}
1142
-
1143
-		if ($account->update(DolibarrApiAccess::$user) < 0)
1144
-			throw new RestException(500, 'Error updating values');
1145
-
1146
-		return $account;
1147
-	}
1148
-
1149
-	/**
1150
-	 * Delete a bank account attached to a thirdparty
1151
-	 *
1152
-	 * @param int $id ID of thirdparty
1153
-	 * @param int $bankaccount_id ID of CompanyBankAccount
1154
-	 *
1155
-	 * @return int -1 if error 1 if correct deletion
1156
-	 *
1157
-	 * @url DELETE {id}/bankaccounts/{bankaccount_id}
1158
-	 */
1159
-	function deleteCompanyBankAccount($id, $bankaccount_id)
1421
+        global $db;
1422
+
1423
+        if(! DolibarrApiAccess::$user->rights->societe->creer) {
1424
+            throw new RestException(401);
1425
+        }
1426
+
1427
+        $sql = "SELECT rowid, fk_user_creat, date_creation FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id AND site = '$site' ";
1428
+        $result = $db->query($sql);
1429
+
1430
+        // We do not found an existing SocieteAccount entity for this fk_soc and site ; we then create a new one.
1431
+        if($result->num_rows == 0 ){
1432
+            if(!isset($request_data['key_account'])) {
1433
+                throw new RestException(422, 'Unprocessable Entity: You must pass the key_account attribute in your request data !');
1434
+            }
1435
+            $account = new SocieteAccount($this->db);
1436
+            if(!isset($request_data['login'])) {
1437
+                $account->login = "";
1438
+            }
1439
+
1440
+            foreach($request_data as $field => $value) {
1441
+                $account->$field = $value;
1442
+            }
1443
+
1444
+            $account->fk_soc = $id;
1445
+            $account->site = $site;
1446
+
1447
+            if ($account->create(DolibarrApiAccess::$user) < 0)
1448
+                throw new RestException(500, 'Error creating SocieteAccount entity.');
1449
+        // We found an existing SocieteAccount entity, we are replacing it
1450
+        } else {
1451
+
1452
+            if(isset($request_data['site']) && $request_data['site'] !== $site) {
1453
+                $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = ".$id." AND site = '". $request_data['site']."' ";
1454
+                $result = $db->query($sql);
1455
+
1456
+                if($result->num_rows !== 0)
1457
+                    throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) from $site to ".$request_data['site'] . " but another SocieteAccount entity already exists with this site key.");
1458
+            }
1459
+
1460
+            $obj = $db->fetch_object($result);
1461
+
1462
+            $account = new SocieteAccount($this->db);
1463
+            $account->id = $obj->rowid;
1464
+            $account->fk_soc = $id;
1465
+            $account->site = $site;
1466
+            if(!isset($request_data['login'])) {
1467
+                $account->login = "";
1468
+            }
1469
+            $account->fk_user_creat = $obj->fk_user_creat;
1470
+            $account->date_creation = $obj->date_creation;
1471
+
1472
+            foreach($request_data as $field => $value) {
1473
+                $account->$field = $value;
1474
+            }
1475
+
1476
+            if ($account->update(DolibarrApiAccess::$user) < 0)
1477
+                throw new RestException(500, 'Error updating SocieteAccount entity.');
1478
+        }
1479
+
1480
+        $this->_cleanObjectDatas($account);
1481
+
1482
+        return $account;
1483
+    }
1484
+
1485
+    /**
1486
+     * Update specified values of a specific site gateway attached to a thirdparty
1487
+     *
1488
+     * @param int $id Id of thirdparty
1489
+     * @param string  $site Site key
1490
+     * @param array $request_data Request data
1491
+     *
1492
+     * @return SocieteAccount
1493
+     * @throws 401 Unauthorized: User does not have permission to read thirdparties
1494
+     * @throws 404 Not Found: Specified thirdparty ID does not belongs to an existing thirdparty
1495
+     * @throws 409 Conflict: Another SocieteAccount entity already exists for this thirdparty with this site key.
1496
+     * @throws 500 Internal Server Error: Error updating SocieteAccount entity
1497
+     *
1498
+     * @url PATCH {id}/gateways/{site}
1499
+     */
1500
+    function patchSocieteAccount($id, $site, $request_data = null)
1160 1501
     {
1161
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
1162
-			throw new RestException(401);
1163
-		}
1164
-
1165
-		$account = new CompanyBankAccount($this->db);
1166
-
1167
-		$account->fetch($bankaccount_id);
1168
-
1169
-		if(!$account->socid == $id)
1170
-			throw new RestException(401);
1171
-
1172
-		return $account->delete(DolibarrApiAccess::$user);
1173
-	}
1174
-
1175
-	/**
1176
-	 * Generate a Document from a bank account record (like SEPA mandate)
1177
-	 *
1178
-	 * @param int 		$id 			Thirdparty id
1179
-	 * @param int 		$companybankid 	Companybank id
1180
-	 * @param string 	$model 			Model of document to generate
1181
-	 * @return void
1182
-	 *
1183
-	 * @url GET {id}/generateBankAccountDocument/{companybankid}/{model}
1184
-	 */
1185
-	public function generateBankAccountDocument($id, $companybankid = null, $model = 'sepamandate')
1186
-	{
1187
-		global $conf;
1188
-
1189
-		$this->langs->loadLangs(array("main","dict","commercial","products","companies","banks","bills","withdrawals"));
1190
-
1191
-		$this->company->fetch($id);
1192
-
1193
-		$action = 'builddoc';
1194
-		if(! DolibarrApiAccess::$user->rights->societe->creer)
1195
-			throw new RestException(401);
1196
-
1197
-		$this->company->setDocModel(DolibarrApiAccess::$user, $model);
1198
-
1199
-		$this->company->fk_bank = $this->company->fk_account;
1200
-
1201
-		$outputlangs = $this->langs;
1202
-		$newlang='';
1203
-
1204
-		if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
1205
-		if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->thirdparty->default_lang)) $newlang=$this->company->thirdparty->default_lang;  // for proposal, order, invoice, ...
1206
-		if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->default_lang)) $newlang=$this->company->default_lang;                  // for thirdparty
1207
-		if (! empty($newlang)) {
1208
-			$outputlangs = new Translate("",$conf);
1209
-			$outputlangs->setDefaultLang($newlang);
1210
-		}
1211
-
1212
-		// To be sure vars is defined
1213
-		$hidedetails = $hidedesc = $hideref = 0;
1214
-		$moreparams=null;
1215
-		if (empty($hidedetails)) $hidedetails=0;
1216
-		if (empty($hidedesc)) $hidedesc=0;
1217
-		if (empty($hideref)) $hideref=0;
1218
-		if (empty($moreparams)) $moreparams=null;
1219
-
1220
-
1221
-		$sql = "SELECT rowid";
1222
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe_rib";
1223
-		if ($id) $sql.= " WHERE fk_soc  = ".$id." ";
1224
-		if ($companybankid) $sql.= " AND id = ".$companybankid."";
1225
-
1226
-		$i=0;
1227
-		$accounts=array();
1228
-
1229
-		$result = $this->db->query($sql);
1230
-		if ($result)
1231
-		{
1232
-			if ($result->num_rows == 0) {
1233
-				throw new RestException(404, 'Bank account not found');
1234
-			}
1235
-
1236
-			$num = $this->db->num_rows($result);
1237
-			while ($i < $num)
1238
-			{
1239
-				$obj = $this->db->fetch_object($result);
1240
-
1241
-				$account = new CompanyBankAccount($this->db);
1242
-				if ($account->fetch($obj->rowid)) {
1243
-					$accounts[] = $account;
1244
-				}
1245
-				$i++;
1246
-			}
1247
-		}
1248
-		else
1249
-		{
1250
-			throw new RestException(404, 'Bank account not found');
1251
-		}
1252
-
1253
-		$moreparams = array(
1254
-			'use_companybankid'=>$accounts[0]->id,
1255
-			'force_dir_output'=>$this->conf->societe->multidir_output[$this->company->entity].'/'.dol_sanitizeFileName($this->company->id)
1256
-		);
1257
-
1258
-		$result = 0;
1259
-
1260
-		$result = $this->company->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1261
-
1262
-		if ($result > 0)
1263
-		{
1264
-			return array("success" => $result);
1265
-		}
1266
-		else
1267
-		{
1268
-			throw new RestException(500);
1269
-		}
1502
+        global $db;
1503
+
1504
+        if(! DolibarrApiAccess::$user->rights->societe->creer) {
1505
+            throw new RestException(401);
1506
+        }
1507
+
1508
+        $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = $id AND site = '$site' ";
1509
+        $result = $db->query($sql);
1510
+
1511
+        if($result->num_rows == 0 ){
1512
+            throw new RestException(404, "This thirdparty does not have $site gateway attached or does not exist.");
1513
+        } else {
1514
+
1515
+            // If the user tries to edit the site member, we check first if
1516
+            if(isset($request_data['site']) && $request_data['site'] !== $site) {
1517
+                $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = ".$id." AND site = '". $request_data['site']."' ";
1518
+                $result = $db->query($sql);
1519
+
1520
+                if($result->num_rows !== 0)
1521
+                    throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) site member from $site to ".$request_data['site'] . " but another SocieteAccount entity already exists for this thirdparty with this site key.");
1522
+            }
1523
+
1524
+            $obj = $db->fetch_object($result);
1525
+            $account = new SocieteAccount($this->db);
1526
+            $account->fetch($obj->rowid);
1527
+
1528
+            foreach($request_data as $field => $value) {
1529
+                $account->$field = $value;
1530
+            }
1531
+
1532
+            if ($account->update(DolibarrApiAccess::$user) < 0)
1533
+                throw new RestException(500, 'Error updating SocieteAccount account');
1534
+
1535
+            $this->_cleanObjectDatas($account);
1536
+
1537
+            return $account;
1538
+        }
1270 1539
     }
1271 1540
 
1272
-  /**
1273
-	 * Get a specific gateway attached to a thirdparty (by specifying the site key)
1274
-	 *
1275
-	 * @param int $id ID of thirdparty
1276
-	 * @param string $site Site key
1277
-	 *
1278
-	 * @return SocieteAccount[]
1279
-	 * @throws 401 Unauthorized: User does not have permission to read thirdparties
1280
-	 * @throws 404 Not Found: Specified thirdparty ID does not belongs to an existing thirdparty
1281
-	 *
1282
-	 * @url GET {id}/gateways/
1283
-	 */
1284
-	function getSocieteAccounts($id, $site=null)
1541
+    /**
1542
+     * Delete a specific site gateway attached to a thirdparty (by gateway id)
1543
+     *
1544
+     * @param int $id ID of thirdparty
1545
+     * @param int $site Site key
1546
+     *
1547
+     * @return void
1548
+     * @throws 401 Unauthorized: User does not have permission to delete thirdparties gateways
1549
+     * @throws 404 Not Found: Specified thirdparty ID does not belongs to an existing thirdparty
1550
+     * @throws 500 Internal Server Error: Error deleting SocieteAccount entity
1551
+     *
1552
+     * @url DELETE {id}/gateways/{site}
1553
+     */
1554
+    function deleteSocieteAccount($id, $site)
1285 1555
     {
1286
-		global $db, $conf;
1287
-
1288
-		if(!DolibarrApiAccess::$user->rights->societe->lire) {
1289
-			throw new RestException(401);
1290
-		}
1291
-
1292
-		if(!DolibarrApi::_checkAccessToResource('societe',$id)) {
1293
-			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
1294
-		}
1295
-
1296
-		/**
1297
-		 * We select all the records that match the socid
1298
-		 */
1299
-		$sql = "SELECT rowid, fk_soc, key_account, site, date_creation, tms FROM ".MAIN_DB_PREFIX."societe_account";
1300
-		$sql.= " WHERE fk_soc = $id";
1301
-		if($site) $sql .= " AND site ='$site'";
1302
-
1303
-		$result = $db->query($sql);
1304
-
1305
-		if($result->num_rows == 0){
1306
-			throw new RestException(404, 'This thirdparty does not have any gateway attached or does not exist.');
1307
-		}
1308
-
1309
-		$i=0;
1310
-
1311
-		$accounts =[];
1312
-
1313
-		$num = $db->num_rows($result);
1314
-		while ($i < $num)
1315
-		{
1316
-			$obj = $db->fetch_object($result);
1317
-			$account = new SocieteAccount($db);
1318
-
1319
-			if($account->fetch($obj->rowid)) {
1320
-				$accounts[] = $account;
1321
-			}
1322
-			$i++;
1323
-		}
1324
-
1325
-		$fields = ['id', 'fk_soc', 'key_account', 'site', 'date_creation', 'tms'];
1326
-
1327
-		$returnAccounts = [];
1328
-
1329
-		foreach($accounts as $account){
1330
-			$object= [];
1331
-			foreach($account as $key => $value)
1332
-				if(in_array($key, $fields)){
1333
-					$object[$key] = $value;
1334
-				}
1335
-			$returnAccounts[] = $object;
1336
-		}
1337
-
1338
-		return $returnAccounts;
1339
-	}
1340
-
1341
-	/**
1342
-	 * Create and attach a new gateway to an existing thirdparty
1343
-	 *
1344
-	 * Possible fields for request_data (request body) are specified in <code>llx_societe_account</code> table.<br>
1345
-	 * See <a href="https://wiki.dolibarr.org/index.php/Table_llx_societe_account">Table llx_societe_account</a> wiki page for more information<br><br>
1346
-	 * <u>Example body payload :</u> <pre>{"key_account": "cus_DAVkLSs1LYyYI", "site": "stripe"}</pre>
1347
-	 *
1348
-	 * @param int $id ID of thirdparty
1349
-	 * @param array $request_data Request data
1350
-	 *
1351
-	 * @return SocieteAccount
1352
-	 * @throws 401 Unauthorized: User does not have permission to read thirdparties
1353
-	 * @throws 409 Conflict: A SocieteAccount entity (gateway) already exists for this company and site.
1354
-	 * @throws 422 Unprocessable Entity: You must pass the site attribute in your request data !
1355
-	 * @throws 500 Internal Server Error: Error creating SocieteAccount account
1356
-	 * @status 201
1357
-	 *
1358
-	 * @url POST {id}/gateways
1359
-	 */
1360
-	function createSocieteAccount($id, $request_data = null)
1361
-	{
1362
-		global $db;
1363
-
1364
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
1365
-			throw new RestException(401);
1366
-		}
1367
-
1368
-		if(!isset($request_data['site'])) {
1369
-			throw new RestException(422, 'Unprocessable Entity: You must pass the site attribute in your request data !');
1370
-		}
1371
-
1372
-		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = ".$id." AND site = '". $request_data['site']."' ";
1373
-		$result = $db->query($sql);
1374
-
1375
-		if($result->num_rows == 0 ){
1376
-			$account = new SocieteAccount($this->db);
1377
-			if(!isset($request_data['login'])) {
1378
-				$account->login = "";
1379
-			}
1380
-			$account->fk_soc = $id;
1381
-
1382
-			foreach($request_data as $field => $value) {
1383
-				$account->$field = $value;
1384
-			}
1385
-
1386
-			if ($account->create(DolibarrApiAccess::$user) < 0)
1387
-				throw new RestException(500, 'Error creating SocieteAccount entity. Ensure that the ID of thirdparty provided does exist!');
1388
-
1389
-			$this->_cleanObjectDatas($account);
1390
-
1391
-			return $account;
1392
-		} else {
1393
-			throw new RestException(409, 'A SocieteAccount entity already exists for this company and site.');
1394
-		}
1395
-	}
1396
-
1397
-	/**
1398
-	 * Create and attach a new (or replace an existing) specific site gateway to a thirdparty
1399
-	 *
1400
-	 * You <strong>MUST</strong> pass all values to keep (otherwise, they will be deleted) !<br>
1401
-	 * If you just need to update specific fields prefer <code>PATCH /thirdparties/{id}/gateways/{site}</code> endpoint.<br><br>
1402
-	 * When a <strong>SocieteAccount</strong> entity does not exist for the <code>id</code> and <code>site</code>
1403
-	 * supplied, a new one will be created. In that case <code>fk_soc</code> and <code>site</code> members form
1404
-	 * request body payload will be ignored and <code>id</code> and <code>site</code> query strings parameters
1405
-	 * will be used instead.
1406
-	 *
1407
-	 * @param int $id ID of thirdparty
1408
-	 * @param string $site Site key
1409
-	 * @param array $request_data Request data
1410
-	 *
1411
-	 * @return SocieteAccount
1412
-	 * @throws 401 Unauthorized: User does not have permission to read thirdparties
1413
-	 * @throws 422 Unprocessable Entity: You must pass the site attribute in your request data !
1414
-	 * @throws 500 Internal Server Error: Error updating SocieteAccount entity
1415
-	 *
1416
-	 * @throws RestException
1417
-	 * @url PUT {id}/gateways/{site}
1418
-	 */
1419
-	function putSocieteAccount($id, $site, $request_data = null)
1420
-	{
1421
-		global $db;
1422
-
1423
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
1424
-			throw new RestException(401);
1425
-		}
1426
-
1427
-		$sql = "SELECT rowid, fk_user_creat, date_creation FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id AND site = '$site' ";
1428
-		$result = $db->query($sql);
1429
-
1430
-		// We do not found an existing SocieteAccount entity for this fk_soc and site ; we then create a new one.
1431
-		if($result->num_rows == 0 ){
1432
-			if(!isset($request_data['key_account'])) {
1433
-				throw new RestException(422, 'Unprocessable Entity: You must pass the key_account attribute in your request data !');
1434
-			}
1435
-			$account = new SocieteAccount($this->db);
1436
-			if(!isset($request_data['login'])) {
1437
-				$account->login = "";
1438
-			}
1439
-
1440
-			foreach($request_data as $field => $value) {
1441
-				$account->$field = $value;
1442
-			}
1443
-
1444
-			$account->fk_soc = $id;
1445
-			$account->site = $site;
1446
-
1447
-			if ($account->create(DolibarrApiAccess::$user) < 0)
1448
-				throw new RestException(500, 'Error creating SocieteAccount entity.');
1449
-		// We found an existing SocieteAccount entity, we are replacing it
1450
-		} else {
1451
-
1452
-			if(isset($request_data['site']) && $request_data['site'] !== $site) {
1453
-				$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = ".$id." AND site = '". $request_data['site']."' ";
1454
-				$result = $db->query($sql);
1455
-
1456
-				if($result->num_rows !== 0)
1457
-					throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) from $site to ".$request_data['site'] . " but another SocieteAccount entity already exists with this site key.");
1458
-			}
1459
-
1460
-			$obj = $db->fetch_object($result);
1461
-
1462
-			$account = new SocieteAccount($this->db);
1463
-			$account->id = $obj->rowid;
1464
-			$account->fk_soc = $id;
1465
-			$account->site = $site;
1466
-			if(!isset($request_data['login'])) {
1467
-				$account->login = "";
1468
-			}
1469
-			$account->fk_user_creat = $obj->fk_user_creat;
1470
-			$account->date_creation = $obj->date_creation;
1471
-
1472
-			foreach($request_data as $field => $value) {
1473
-				$account->$field = $value;
1474
-			}
1475
-
1476
-			if ($account->update(DolibarrApiAccess::$user) < 0)
1477
-				throw new RestException(500, 'Error updating SocieteAccount entity.');
1478
-		}
1479
-
1480
-		$this->_cleanObjectDatas($account);
1481
-
1482
-		return $account;
1483
-	}
1484
-
1485
-	/**
1486
-	 * Update specified values of a specific site gateway attached to a thirdparty
1487
-	 *
1488
-	 * @param int $id Id of thirdparty
1489
-	 * @param string  $site Site key
1490
-	 * @param array $request_data Request data
1491
-	 *
1492
-	 * @return SocieteAccount
1493
-	 * @throws 401 Unauthorized: User does not have permission to read thirdparties
1494
-	 * @throws 404 Not Found: Specified thirdparty ID does not belongs to an existing thirdparty
1495
-	 * @throws 409 Conflict: Another SocieteAccount entity already exists for this thirdparty with this site key.
1496
-	 * @throws 500 Internal Server Error: Error updating SocieteAccount entity
1497
-	 *
1498
-	 * @url PATCH {id}/gateways/{site}
1499
-	 */
1500
-	function patchSocieteAccount($id, $site, $request_data = null)
1501
-	{
1502
-		global $db;
1503
-
1504
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
1505
-			throw new RestException(401);
1506
-		}
1507
-
1508
-		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = $id AND site = '$site' ";
1509
-		$result = $db->query($sql);
1510
-
1511
-		if($result->num_rows == 0 ){
1512
-			throw new RestException(404, "This thirdparty does not have $site gateway attached or does not exist.");
1513
-		} else {
1514
-
1515
-			// If the user tries to edit the site member, we check first if
1516
-			if(isset($request_data['site']) && $request_data['site'] !== $site) {
1517
-				$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = ".$id." AND site = '". $request_data['site']."' ";
1518
-				$result = $db->query($sql);
1519
-
1520
-				if($result->num_rows !== 0)
1521
-					throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) site member from $site to ".$request_data['site'] . " but another SocieteAccount entity already exists for this thirdparty with this site key.");
1522
-			}
1523
-
1524
-			$obj = $db->fetch_object($result);
1525
-			$account = new SocieteAccount($this->db);
1526
-			$account->fetch($obj->rowid);
1527
-
1528
-			foreach($request_data as $field => $value) {
1529
-				$account->$field = $value;
1530
-			}
1531
-
1532
-			if ($account->update(DolibarrApiAccess::$user) < 0)
1533
-				throw new RestException(500, 'Error updating SocieteAccount account');
1534
-
1535
-			$this->_cleanObjectDatas($account);
1536
-
1537
-			return $account;
1538
-		}
1539
-	}
1540
-
1541
-	/**
1542
-	 * Delete a specific site gateway attached to a thirdparty (by gateway id)
1543
-	 *
1544
-	 * @param int $id ID of thirdparty
1545
-	 * @param int $site Site key
1546
-	 *
1547
-	 * @return void
1548
-	 * @throws 401 Unauthorized: User does not have permission to delete thirdparties gateways
1549
-	 * @throws 404 Not Found: Specified thirdparty ID does not belongs to an existing thirdparty
1550
-	 * @throws 500 Internal Server Error: Error deleting SocieteAccount entity
1551
-	 *
1552
-	 * @url DELETE {id}/gateways/{site}
1553
-	 */
1554
-	function deleteSocieteAccount($id, $site)
1556
+        global /** @var Database $db */
1557
+        $db;
1558
+
1559
+        if(! DolibarrApiAccess::$user->rights->societe->creer) {
1560
+            throw new RestException(401);
1561
+        }
1562
+
1563
+        $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = $id AND site = '$site' ";
1564
+        $result = $db->query($sql);
1565
+
1566
+        if($result->num_rows == 0 ){
1567
+            throw new RestException(404);
1568
+        } else {
1569
+            $obj = $db->fetch_object($result);
1570
+            $account = new SocieteAccount($this->db);
1571
+            $account->fetch($obj->rowid);
1572
+
1573
+            if($account->delete(DolibarrApiAccess::$user) < 0) {
1574
+                throw new RestException(500, "Error while deleting $site gateway attached to this third party");
1575
+            }
1576
+        }
1577
+    }
1578
+
1579
+    /**
1580
+     * Delete all gateways attached to a thirdparty
1581
+     *
1582
+     * @param int $id ID of thirdparty
1583
+     *
1584
+     * @return void
1585
+     * @throws 401 Unauthorized: User does not have permission to delete thirdparties gateways
1586
+     * @throws 404 Not Found: Specified thirdparty ID does not belongs to an existing thirdparty
1587
+     * @throws 500 Internal Server Error: Error deleting SocieteAccount entity
1588
+     *
1589
+     * @url DELETE {id}/gateways
1590
+     */
1591
+    function deleteSocieteAccounts($id)
1555 1592
     {
1556
-		global /** @var Database $db */
1557
-		$db;
1558
-
1559
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
1560
-			throw new RestException(401);
1561
-		}
1562
-
1563
-		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = $id AND site = '$site' ";
1564
-		$result = $db->query($sql);
1565
-
1566
-		if($result->num_rows == 0 ){
1567
-			throw new RestException(404);
1568
-		} else {
1569
-			$obj = $db->fetch_object($result);
1570
-			$account = new SocieteAccount($this->db);
1571
-			$account->fetch($obj->rowid);
1572
-
1573
-			if($account->delete(DolibarrApiAccess::$user) < 0) {
1574
-				throw new RestException(500, "Error while deleting $site gateway attached to this third party");
1575
-			}
1576
-		}
1577
-	}
1578
-
1579
-	/**
1580
-	 * Delete all gateways attached to a thirdparty
1581
-	 *
1582
-	 * @param int $id ID of thirdparty
1583
-	 *
1584
-	 * @return void
1585
-	 * @throws 401 Unauthorized: User does not have permission to delete thirdparties gateways
1586
-	 * @throws 404 Not Found: Specified thirdparty ID does not belongs to an existing thirdparty
1587
-	 * @throws 500 Internal Server Error: Error deleting SocieteAccount entity
1588
-	 *
1589
-	 * @url DELETE {id}/gateways
1590
-	 */
1591
-	function deleteSocieteAccounts($id)
1593
+        global /** @var Database $db */
1594
+        $db;
1595
+
1596
+        if(! DolibarrApiAccess::$user->rights->societe->creer) {
1597
+            throw new RestException(401);
1598
+        }
1599
+
1600
+        /**
1601
+         * We select all the records that match the socid
1602
+         */
1603
+
1604
+        $sql = "SELECT rowid, fk_soc, key_account, site, date_creation, tms";
1605
+        $sql.= " FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = $id ";
1606
+
1607
+        $result = $db->query($sql);
1608
+
1609
+        if($result->num_rows == 0 ){
1610
+            throw new RestException(404, 'This third party does not have any gateway attached or does not exist.');
1611
+        } else {
1612
+            $i=0;
1613
+
1614
+            $num = $db->num_rows($result);
1615
+            while ($i < $num)
1616
+            {
1617
+                $obj = $db->fetch_object($result);
1618
+                $account = new SocieteAccount($db);
1619
+                $account->fetch($obj->rowid);
1620
+
1621
+                if($account->delete(DolibarrApiAccess::$user) < 0) {
1622
+                    throw new RestException(500, 'Error while deleting gateways attached to this third party');
1623
+                }
1624
+                $i++;
1625
+            }
1626
+        }
1627
+    }
1628
+
1629
+    /**
1630
+     * Clean sensible object datas
1631
+     *
1632
+     * @param   object  $object    Object to clean
1633
+     * @return    array    Array of cleaned object properties
1634
+     */
1635
+    function _cleanObjectDatas($object)
1592 1636
     {
1593
-		global /** @var Database $db */
1594
-		$db;
1595
-
1596
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
1597
-			throw new RestException(401);
1598
-		}
1599
-
1600
-		/**
1601
-		 * We select all the records that match the socid
1602
-		 */
1603
-
1604
-		$sql = "SELECT rowid, fk_soc, key_account, site, date_creation, tms";
1605
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = $id ";
1606
-
1607
-		$result = $db->query($sql);
1608
-
1609
-		if($result->num_rows == 0 ){
1610
-			throw new RestException(404, 'This third party does not have any gateway attached or does not exist.');
1611
-		} else {
1612
-			$i=0;
1613
-
1614
-			$num = $db->num_rows($result);
1615
-			while ($i < $num)
1616
-			{
1617
-				$obj = $db->fetch_object($result);
1618
-				$account = new SocieteAccount($db);
1619
-				$account->fetch($obj->rowid);
1620
-
1621
-				if($account->delete(DolibarrApiAccess::$user) < 0) {
1622
-					throw new RestException(500, 'Error while deleting gateways attached to this third party');
1623
-				}
1624
-				$i++;
1625
-			}
1626
-		}
1627
-	}
1628
-
1629
-	/**
1630
-	 * Clean sensible object datas
1631
-	 *
1632
-	 * @param   object  $object    Object to clean
1633
-	 * @return    array    Array of cleaned object properties
1634
-	 */
1635
-	function _cleanObjectDatas($object)
1637
+        $object = parent::_cleanObjectDatas($object);
1638
+
1639
+        unset($object->nom);	// ->name already defined and nom deprecated
1640
+
1641
+        unset($object->total_ht);
1642
+        unset($object->total_tva);
1643
+        unset($object->total_localtax1);
1644
+        unset($object->total_localtax2);
1645
+        unset($object->total_ttc);
1646
+
1647
+        unset($object->lines);
1648
+        unset($object->thirdparty);
1649
+
1650
+        return $object;
1651
+    }
1652
+
1653
+    /**
1654
+     * Validate fields before create or update object
1655
+     *
1656
+     * @param array $data   Datas to validate
1657
+     * @return array
1658
+     *
1659
+     * @throws RestException
1660
+     */
1661
+    function _validate($data)
1636 1662
     {
1637
-		$object = parent::_cleanObjectDatas($object);
1638
-
1639
-		unset($object->nom);	// ->name already defined and nom deprecated
1640
-
1641
-		unset($object->total_ht);
1642
-		unset($object->total_tva);
1643
-		unset($object->total_localtax1);
1644
-		unset($object->total_localtax2);
1645
-		unset($object->total_ttc);
1646
-
1647
-		unset($object->lines);
1648
-		unset($object->thirdparty);
1649
-
1650
-		return $object;
1651
-	}
1652
-
1653
-	/**
1654
-	 * Validate fields before create or update object
1655
-	 *
1656
-	 * @param array $data   Datas to validate
1657
-	 * @return array
1658
-	 *
1659
-	 * @throws RestException
1660
-	 */
1661
-	function _validate($data)
1662
-	{
1663
-		$thirdparty = array();
1664
-		foreach (Thirdparties::$FIELDS as $field) {
1665
-			if (!isset($data[$field]))
1666
-				throw new RestException(400, "$field field missing");
1667
-			$thirdparty[$field] = $data[$field];
1668
-		}
1669
-		return $thirdparty;
1670
-	}
1663
+        $thirdparty = array();
1664
+        foreach (Thirdparties::$FIELDS as $field) {
1665
+            if (!isset($data[$field]))
1666
+                throw new RestException(400, "$field field missing");
1667
+            $thirdparty[$field] = $data[$field];
1668
+        }
1669
+        return $thirdparty;
1670
+    }
1671 1671
 }
Please login to merge, or discard this patch.
Spacing   +195 added lines, -195 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 
57 57
 		$this->company = new Societe($this->db);
58 58
 
59
-		if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY)) {
59
+		if (!empty($conf->global->SOCIETE_EMAIL_MANDATORY)) {
60 60
 			static::$FIELDS[] = 'email';
61 61
 		}
62 62
 	}
@@ -73,20 +73,20 @@  discard block
 block discarded – undo
73 73
 	 */
74 74
 	function get($id)
75 75
 	{
76
-		if(! DolibarrApiAccess::$user->rights->societe->lire) {
76
+		if (!DolibarrApiAccess::$user->rights->societe->lire) {
77 77
 			throw new RestException(401);
78 78
 		}
79 79
 
80 80
 		$result = $this->company->fetch($id);
81
-		if( ! $result ) {
81
+		if (!$result) {
82 82
 			throw new RestException(404, 'Thirdparty not found');
83 83
 		}
84 84
 
85
-		if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
85
+		if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
86 86
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
87 87
 		}
88 88
 
89
-		if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
89
+		if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
90 90
 			$filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
91 91
 			$filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
92 92
 		} else {
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 	 * @param   string  $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.nom:like:'TheCompany%') and (t.date_creation:<:'20160101')"
118 118
 	 * @return  array               Array of thirdparty objects
119 119
 	 */
120
-	function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode=0, $sqlfilters = '')
120
+	function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode = 0, $sqlfilters = '')
121 121
     {
122 122
 		global $db, $conf;
123 123
 
@@ -128,23 +128,23 @@  discard block
 block discarded – undo
128 128
 
129 129
 		// If the internal user must only see his customers, force searching by him
130 130
 		$search_sale = 0;
131
-		if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
131
+		if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
132 132
 
133 133
 		$sql = "SELECT t.rowid";
134 134
 		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
135
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe as t";
136
-
137
-		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
138
-		$sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st";
139
-		$sql.= " WHERE t.fk_stcomm = st.id";
140
-		if ($mode == 1) $sql.= " AND t.client IN (1, 3)";
141
-		if ($mode == 2) $sql.= " AND t.client IN (2, 3)";
142
-		if ($mode == 3) $sql.= " AND t.client IN (0)";
143
-		$sql.= ' AND t.entity IN ('.getEntity('societe').')';
144
-		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";
135
+		$sql .= " FROM ".MAIN_DB_PREFIX."societe as t";
136
+
137
+		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
138
+		$sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st";
139
+		$sql .= " WHERE t.fk_stcomm = st.id";
140
+		if ($mode == 1) $sql .= " AND t.client IN (1, 3)";
141
+		if ($mode == 2) $sql .= " AND t.client IN (2, 3)";
142
+		if ($mode == 3) $sql .= " AND t.client IN (0)";
143
+		$sql .= ' AND t.entity IN ('.getEntity('societe').')';
144
+		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc";
145 145
 		//if ($email != NULL) $sql.= " AND s.email = \"".$email."\"";
146
-		if ($socid) $sql.= " AND t.rowid IN (".$socids.")";
147
-		if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";		// Join for the needed table to filter by sale
146
+		if ($socid) $sql .= " AND t.rowid IN (".$socids.")";
147
+		if ($search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
148 148
 		// Insert sale filter
149 149
 		if ($search_sale > 0)
150 150
 		{
@@ -153,15 +153,15 @@  discard block
 block discarded – undo
153 153
 		// Add sql filters
154 154
 		if ($sqlfilters)
155 155
 		{
156
-			if (! DolibarrApi::_checkFilters($sqlfilters))
156
+			if (!DolibarrApi::_checkFilters($sqlfilters))
157 157
 			{
158 158
 				throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
159 159
 			}
160
-			$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
161
-			$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
160
+			$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
161
+			$sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
162 162
 		}
163 163
 
164
-		$sql.= $db->order($sortfield, $sortorder);
164
+		$sql .= $db->order($sortfield, $sortorder);
165 165
 
166 166
 		if ($limit) {
167 167
 			if ($page < 0)
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 			}
171 171
 			$offset = $limit * $page;
172 172
 
173
-			$sql.= $db->plimit($limit + 1, $offset);
173
+			$sql .= $db->plimit($limit + 1, $offset);
174 174
 		}
175 175
 
176 176
 		$result = $db->query($sql);
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 			{
183 183
 				$obj = $db->fetch_object($result);
184 184
 				$soc_static = new Societe($db);
185
-				if($soc_static->fetch($obj->rowid)) {
185
+				if ($soc_static->fetch($obj->rowid)) {
186 186
 					$obj_ret[] = $this->_cleanObjectDatas($soc_static);
187 187
 				}
188 188
 				$i++;
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 		else {
192 192
 			throw new RestException(503, 'Error when retrieve thirdparties : '.$db->lasterror());
193 193
 		}
194
-		if( ! count($obj_ret)) {
194
+		if (!count($obj_ret)) {
195 195
 			throw new RestException(404, 'Thirdparties not found');
196 196
 		}
197 197
 		return $obj_ret;
@@ -205,13 +205,13 @@  discard block
 block discarded – undo
205 205
 	 */
206 206
 	function post($request_data = null)
207 207
 	{
208
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
208
+		if (!DolibarrApiAccess::$user->rights->societe->creer) {
209 209
 			throw new RestException(401);
210 210
 		}
211 211
 		// Check mandatory fields
212 212
 		$result = $this->_validate($request_data);
213 213
 
214
-		foreach($request_data as $field => $value) {
214
+		foreach ($request_data as $field => $value) {
215 215
 			$this->company->$field = $value;
216 216
 		}
217 217
 		if ($this->company->create(DolibarrApiAccess::$user) < 0)
@@ -229,25 +229,25 @@  discard block
 block discarded – undo
229 229
 	 */
230 230
 	function put($id, $request_data = null)
231 231
 	{
232
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
232
+		if (!DolibarrApiAccess::$user->rights->societe->creer) {
233 233
 			throw new RestException(401);
234 234
 		}
235 235
 
236 236
 		$result = $this->company->fetch($id);
237
-		if( ! $result ) {
237
+		if (!$result) {
238 238
 			throw new RestException(404, 'Thirdparty not found');
239 239
 		}
240 240
 
241
-		if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
241
+		if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
242 242
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
243 243
 		}
244 244
 
245
-		foreach($request_data as $field => $value) {
245
+		foreach ($request_data as $field => $value) {
246 246
 			if ($field == 'id') continue;
247 247
 			$this->company->$field = $value;
248 248
 		}
249 249
 
250
-		if($this->company->update($id, DolibarrApiAccess::$user,1,'','','update'))
250
+		if ($this->company->update($id, DolibarrApiAccess::$user, 1, '', '', 'update'))
251 251
 			return $this->get($id);
252 252
 
253 253
 		return false;
@@ -278,27 +278,27 @@  discard block
 block discarded – undo
278 278
 			throw new RestException(400, 'Try to merge a thirdparty into itself');
279 279
 		}
280 280
 
281
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
281
+		if (!DolibarrApiAccess::$user->rights->societe->creer) {
282 282
 			throw new RestException(401);
283 283
 		}
284 284
 
285
-		$result = $this->company->fetch($id);	// include the fetch of extra fields
286
-		if( ! $result ) {
285
+		$result = $this->company->fetch($id); // include the fetch of extra fields
286
+		if (!$result) {
287 287
 			throw new RestException(404, 'Thirdparty not found');
288 288
 		}
289 289
 
290
-		if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
290
+		if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
291 291
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
292 292
 		}
293 293
 
294 294
 		$this->companytoremove = new Societe($db);
295 295
 
296
-		$result = $this->companytoremove->fetch($idtodelete);	// include the fetch of extra fields
297
-		if( ! $result ) {
296
+		$result = $this->companytoremove->fetch($idtodelete); // include the fetch of extra fields
297
+		if (!$result) {
298 298
 			throw new RestException(404, 'Thirdparty not found');
299 299
 		}
300 300
 
301
-		if( ! DolibarrApi::_checkAccessToResource('societe',$this->companytoremove->id)) {
301
+		if (!DolibarrApi::_checkAccessToResource('societe', $this->companytoremove->id)) {
302 302
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
303 303
 		}
304 304
 
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 		// Recopy some data
316 316
 		$object->client = $object->client | $soc_origin->client;
317 317
 		$object->fournisseur = $object->fournisseur | $soc_origin->fournisseur;
318
-		$listofproperties=array(
318
+		$listofproperties = array(
319 319
 			'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'skype', 'url', 'barcode',
320 320
 			'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6',
321 321
 			'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'remise_supplier_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis',
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 		}
330 330
 
331 331
 		// Concat some data
332
-		$listofproperties=array(
332
+		$listofproperties = array(
333 333
 			'note_public', 'note_private'
334 334
 		);
335 335
 		foreach ($listofproperties as $property)
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
 		}
374 374
 
375 375
 		// Move links
376
-		if (! $error)
376
+		if (!$error)
377 377
 		{
378 378
 			$objects = array(
379 379
 				'Adherent' => '/adherents/class/adherent.class.php',
@@ -428,12 +428,12 @@  discard block
 block discarded – undo
428 428
 		}
429 429
 
430 430
 
431
-		if (! $error)
431
+		if (!$error)
432 432
 		{
433
-			$object->context=array('merge'=>1, 'mergefromid'=>$soc_origin->id);
433
+			$object->context = array('merge'=>1, 'mergefromid'=>$soc_origin->id);
434 434
 
435 435
 			// Call trigger
436
-			$result=$object->call_trigger('COMPANY_MODIFY',$user);
436
+			$result = $object->call_trigger('COMPANY_MODIFY', $user);
437 437
 			if ($result < 0)
438 438
 			{
439 439
 				//setEventMessages($object->error, $object->errors, 'errors');
@@ -442,7 +442,7 @@  discard block
 block discarded – undo
442 442
 			// End call triggers
443 443
 		}
444 444
 
445
-		if (! $error)
445
+		if (!$error)
446 446
 		{
447 447
 			//We finally remove the old thirdparty
448 448
 			if ($soc_origin->delete($soc_origin->id, $user) < 1)
@@ -475,14 +475,14 @@  discard block
 block discarded – undo
475 475
 	 */
476 476
 	function delete($id)
477 477
 	{
478
-		if(! DolibarrApiAccess::$user->rights->societe->supprimer) {
478
+		if (!DolibarrApiAccess::$user->rights->societe->supprimer) {
479 479
 			throw new RestException(401);
480 480
 		}
481 481
 		$result = $this->company->fetch($id);
482
-		if( ! $result ) {
482
+		if (!$result) {
483 483
 			throw new RestException(404, 'Thirdparty not found');
484 484
 		}
485
-		if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
485
+		if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
486 486
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
487 487
 		}
488 488
 		return $this->company->delete($id);
@@ -503,12 +503,12 @@  discard block
 block discarded – undo
503 503
 	 */
504 504
 	function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
505 505
 	{
506
-		if (! DolibarrApiAccess::$user->rights->categorie->lire) {
506
+		if (!DolibarrApiAccess::$user->rights->categorie->lire) {
507 507
 			throw new RestException(401);
508 508
 		}
509 509
 
510 510
 		$result = $this->company->fetch($id);
511
-		if( ! $result )
511
+		if (!$result)
512 512
 		{
513 513
 			throw new RestException(404, 'Thirdparty not found');
514 514
 		}
@@ -542,28 +542,28 @@  discard block
 block discarded – undo
542 542
 	 */
543 543
 	function addCategory($id, $category_id)
544 544
 	{
545
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
545
+		if (!DolibarrApiAccess::$user->rights->societe->creer) {
546 546
 			throw new RestException(401);
547 547
 		}
548 548
 
549 549
 		$result = $this->company->fetch($id);
550
-		if( ! $result ) {
550
+		if (!$result) {
551 551
 			throw new RestException(404, 'Thirdparty not found');
552 552
 		}
553 553
 		$category = new Categorie($this->db);
554 554
 		$result = $category->fetch($category_id);
555
-		if( ! $result ) {
555
+		if (!$result) {
556 556
 			throw new RestException(404, 'category not found');
557 557
 		}
558 558
 
559
-		if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
559
+		if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
560 560
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
561 561
 		}
562
-		if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) {
562
+		if (!DolibarrApi::_checkAccessToResource('category', $category->id)) {
563 563
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
564 564
 		}
565 565
 
566
-		$category->add_type($this->company,'customer');
566
+		$category->add_type($this->company, 'customer');
567 567
 
568 568
 		return $this->_cleanObjectDatas($this->company);
569 569
 	}
@@ -580,28 +580,28 @@  discard block
 block discarded – undo
580 580
 	 */
581 581
 	function deleteCategory($id, $category_id)
582 582
 	{
583
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
583
+		if (!DolibarrApiAccess::$user->rights->societe->creer) {
584 584
 			throw new RestException(401);
585 585
 		}
586 586
 
587 587
 		$result = $this->company->fetch($id);
588
-		if( ! $result ) {
588
+		if (!$result) {
589 589
 			throw new RestException(404, 'Thirdparty not found');
590 590
 		}
591 591
 		$category = new Categorie($this->db);
592 592
 		$result = $category->fetch($category_id);
593
-		if( ! $result ) {
593
+		if (!$result) {
594 594
 			throw new RestException(404, 'category not found');
595 595
 		}
596 596
 
597
-		if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
597
+		if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
598 598
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
599 599
 		}
600
-		if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) {
600
+		if (!DolibarrApi::_checkAccessToResource('category', $category->id)) {
601 601
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
602 602
 		}
603 603
 
604
-		$category->del_type($this->company,'customer');
604
+		$category->del_type($this->company, 'customer');
605 605
 
606 606
 		return $this->_cleanObjectDatas($this->company);
607 607
 	}
@@ -621,12 +621,12 @@  discard block
 block discarded – undo
621 621
 	 */
622 622
 	function getSupplierCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
623 623
 	{
624
-		if (! DolibarrApiAccess::$user->rights->categorie->lire) {
624
+		if (!DolibarrApiAccess::$user->rights->categorie->lire) {
625 625
 			throw new RestException(401);
626 626
 		}
627 627
 
628 628
 		$result = $this->company->fetch($id);
629
-		if( ! $result )
629
+		if (!$result)
630 630
 		{
631 631
 			throw new RestException(404, 'Thirdparty not found');
632 632
 		}
@@ -660,28 +660,28 @@  discard block
 block discarded – undo
660 660
 	 */
661 661
 	function addSupplierCategory($id, $category_id)
662 662
 	{
663
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
663
+		if (!DolibarrApiAccess::$user->rights->societe->creer) {
664 664
 			throw new RestException(401);
665 665
 		}
666 666
 
667 667
 		$result = $this->company->fetch($id);
668
-		if( ! $result ) {
668
+		if (!$result) {
669 669
 			throw new RestException(404, 'Thirdparty not found');
670 670
 		}
671 671
 		$category = new Categorie($this->db);
672 672
 		$result = $category->fetch($category_id);
673
-		if( ! $result ) {
673
+		if (!$result) {
674 674
 			throw new RestException(404, 'category not found');
675 675
 		}
676 676
 
677
-		if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
677
+		if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
678 678
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
679 679
 		}
680
-		if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) {
680
+		if (!DolibarrApi::_checkAccessToResource('category', $category->id)) {
681 681
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
682 682
 		}
683 683
 
684
-		$category->add_type($this->company,'supplier');
684
+		$category->add_type($this->company, 'supplier');
685 685
 
686 686
 		return $this->_cleanObjectDatas($this->company);
687 687
 	}
@@ -698,28 +698,28 @@  discard block
 block discarded – undo
698 698
 	 */
699 699
 	function deleteSupplierCategory($id, $category_id)
700 700
 	{
701
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
701
+		if (!DolibarrApiAccess::$user->rights->societe->creer) {
702 702
 			throw new RestException(401);
703 703
 		}
704 704
 
705 705
 		$result = $this->company->fetch($id);
706
-		if( ! $result ) {
706
+		if (!$result) {
707 707
 			throw new RestException(404, 'Thirdparty not found');
708 708
 		}
709 709
 		$category = new Categorie($this->db);
710 710
 		$result = $category->fetch($category_id);
711
-		if( ! $result ) {
711
+		if (!$result) {
712 712
 			throw new RestException(404, 'category not found');
713 713
 		}
714 714
 
715
-		if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
715
+		if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
716 716
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
717 717
 		}
718
-		if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) {
718
+		if (!DolibarrApi::_checkAccessToResource('category', $category->id)) {
719 719
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
720 720
 		}
721 721
 
722
-		$category->del_type($this->company,'supplier');
722
+		$category->del_type($this->company, 'supplier');
723 723
 
724 724
 		return $this->_cleanObjectDatas($this->company);
725 725
 	}
@@ -739,24 +739,24 @@  discard block
 block discarded – undo
739 739
 	 * @throws 401
740 740
 	 * @throws 404
741 741
 	 */
742
-	function getOutStandingProposals($id, $mode='customer')
742
+	function getOutStandingProposals($id, $mode = 'customer')
743 743
 	{
744 744
 		$obj_ret = array();
745 745
 
746
-		if(! DolibarrApiAccess::$user->rights->societe->lire) {
746
+		if (!DolibarrApiAccess::$user->rights->societe->lire) {
747 747
 			throw new RestException(401);
748 748
 		}
749 749
 
750
-		if(empty($id)) {
750
+		if (empty($id)) {
751 751
 			throw new RestException(400, 'Thirdparty ID is mandatory');
752 752
 		}
753 753
 
754
-		if( ! DolibarrApi::_checkAccessToResource('societe',$id)) {
754
+		if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
755 755
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
756 756
 		}
757 757
 
758 758
 		$result = $this->company->fetch($id);
759
-		if( ! $result ) {
759
+		if (!$result) {
760 760
 			throw new RestException(404, 'Thirdparty not found');
761 761
 		}
762 762
 
@@ -783,24 +783,24 @@  discard block
 block discarded – undo
783 783
 	 * @throws 401
784 784
 	 * @throws 404
785 785
 	 */
786
-	function getOutStandingOrder($id, $mode='customer')
786
+	function getOutStandingOrder($id, $mode = 'customer')
787 787
 	{
788 788
 		$obj_ret = array();
789 789
 
790
-		if(! DolibarrApiAccess::$user->rights->societe->lire) {
790
+		if (!DolibarrApiAccess::$user->rights->societe->lire) {
791 791
 			throw new RestException(401);
792 792
 		}
793 793
 
794
-		if(empty($id)) {
794
+		if (empty($id)) {
795 795
 			throw new RestException(400, 'Thirdparty ID is mandatory');
796 796
 		}
797 797
 
798
-		if( ! DolibarrApi::_checkAccessToResource('societe',$id)) {
798
+		if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
799 799
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
800 800
 		}
801 801
 
802 802
 		$result = $this->company->fetch($id);
803
-		if( ! $result ) {
803
+		if (!$result) {
804 804
 			throw new RestException(404, 'Thirdparty not found');
805 805
 		}
806 806
 
@@ -826,24 +826,24 @@  discard block
 block discarded – undo
826 826
 	 * @throws 401
827 827
 	 * @throws 404
828 828
 	 */
829
-	function getOutStandingInvoices($id, $mode='customer')
829
+	function getOutStandingInvoices($id, $mode = 'customer')
830 830
 	{
831 831
 		$obj_ret = array();
832 832
 
833
-		if(! DolibarrApiAccess::$user->rights->societe->lire) {
833
+		if (!DolibarrApiAccess::$user->rights->societe->lire) {
834 834
 			throw new RestException(401);
835 835
 		}
836 836
 
837
-		if(empty($id)) {
837
+		if (empty($id)) {
838 838
 			throw new RestException(400, 'Thirdparty ID is mandatory');
839 839
 		}
840 840
 
841
-		if( ! DolibarrApi::_checkAccessToResource('societe',$id)) {
841
+		if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
842 842
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
843 843
 		}
844 844
 
845 845
 		$result = $this->company->fetch($id);
846
-		if( ! $result ) {
846
+		if (!$result) {
847 847
 			throw new RestException(404, 'Thirdparty not found');
848 848
 		}
849 849
 
@@ -872,24 +872,24 @@  discard block
 block discarded – undo
872 872
 	 * @throws 404
873 873
 	 * @throws 503
874 874
 	 */
875
-	function getFixedAmountDiscounts($id, $filter="none", $sortfield = "f.type", $sortorder = 'ASC')
875
+	function getFixedAmountDiscounts($id, $filter = "none", $sortfield = "f.type", $sortorder = 'ASC')
876 876
 	{
877 877
 		$obj_ret = array();
878 878
 
879
-		if(! DolibarrApiAccess::$user->rights->societe->lire) {
879
+		if (!DolibarrApiAccess::$user->rights->societe->lire) {
880 880
 			throw new RestException(401);
881 881
 		}
882 882
 
883
-		if(empty($id)) {
883
+		if (empty($id)) {
884 884
 			throw new RestException(400, 'Thirdparty ID is mandatory');
885 885
 		}
886 886
 
887
-		if( ! DolibarrApi::_checkAccessToResource('societe',$id)) {
887
+		if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
888 888
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
889 889
 		}
890 890
 
891 891
 		$result = $this->company->fetch($id);
892
-		if( ! $result ) {
892
+		if (!$result) {
893 893
 			throw new RestException(404, 'Thirdparty not found');
894 894
 		}
895 895
 
@@ -900,14 +900,14 @@  discard block
 block discarded – undo
900 900
 		if ($filter == "available")  $sql .= " AND re.fk_facture IS NULL AND re.fk_facture_line IS NULL";
901 901
 		if ($filter == "used")  $sql .= " AND (re.fk_facture IS NOT NULL OR re.fk_facture_line IS NOT NULL)";
902 902
 
903
-		$sql.= $this->db->order($sortfield, $sortorder);
903
+		$sql .= $this->db->order($sortfield, $sortorder);
904 904
 
905 905
 		$result = $this->db->query($sql);
906
-		if( ! $result ) {
906
+		if (!$result) {
907 907
 			throw new RestException(503, $this->db->lasterror());
908 908
 		} else {
909 909
 			$num = $this->db->num_rows($result);
910
-			while ( $obj = $this->db->fetch_object($result) ) {
910
+			while ($obj = $this->db->fetch_object($result)) {
911 911
 				$obj_ret[] = $obj;
912 912
 			}
913 913
 		}
@@ -932,14 +932,14 @@  discard block
 block discarded – undo
932 932
 	 */
933 933
 	function getInvoicesQualifiedForReplacement($id)
934 934
     {
935
-		if(! DolibarrApiAccess::$user->rights->facture->lire) {
935
+		if (!DolibarrApiAccess::$user->rights->facture->lire) {
936 936
 			throw new RestException(401);
937 937
 		}
938
-		if(empty($id)) {
938
+		if (empty($id)) {
939 939
 			throw new RestException(400, 'Thirdparty ID is mandatory');
940 940
 		}
941 941
 
942
-		if( ! DolibarrApi::_checkAccessToResource('societe',$id)) {
942
+		if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
943 943
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
944 944
 		}
945 945
 
@@ -950,7 +950,7 @@  discard block
 block discarded – undo
950 950
 
951 951
 		$invoice = new Facture($this->db);
952 952
 		$result = $invoice->list_replacable_invoices($id);
953
-		if( $result < 0) {
953
+		if ($result < 0) {
954 954
 			throw new RestException(405, $this->thirdparty->error);
955 955
 		}
956 956
 
@@ -974,14 +974,14 @@  discard block
 block discarded – undo
974 974
 	 */
975 975
 	function getInvoicesQualifiedForCreditNote($id)
976 976
     {
977
-		if(! DolibarrApiAccess::$user->rights->facture->lire) {
977
+		if (!DolibarrApiAccess::$user->rights->facture->lire) {
978 978
 			throw new RestException(401);
979 979
 		}
980
-		if(empty($id)) {
980
+		if (empty($id)) {
981 981
 			throw new RestException(400, 'Thirdparty ID is mandatory');
982 982
 		}
983 983
 
984
-		if( ! DolibarrApi::_checkAccessToResource('societe',$id)) {
984
+		if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
985 985
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
986 986
 		}
987 987
 
@@ -992,7 +992,7 @@  discard block
 block discarded – undo
992 992
 
993 993
 		$invoice = new Facture($this->db);
994 994
 		$result = $invoice->list_qualified_avoir_invoices($id);
995
-		if( $result < 0) {
995
+		if ($result < 0) {
996 996
 			throw new RestException(405, $this->thirdparty->error);
997 997
 		}
998 998
 
@@ -1012,14 +1012,14 @@  discard block
 block discarded – undo
1012 1012
     {
1013 1013
 		global $db, $conf;
1014 1014
 
1015
-		if(! DolibarrApiAccess::$user->rights->facture->lire) {
1015
+		if (!DolibarrApiAccess::$user->rights->facture->lire) {
1016 1016
 			throw new RestException(401);
1017 1017
 		}
1018
-		if(empty($id)) {
1018
+		if (empty($id)) {
1019 1019
 			throw new RestException(400, 'Thirdparty ID is mandatory');
1020 1020
 		}
1021 1021
 
1022
-		if( ! DolibarrApi::_checkAccessToResource('societe',$id)) {
1022
+		if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
1023 1023
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
1024 1024
 		}
1025 1025
 
@@ -1028,20 +1028,20 @@  discard block
 block discarded – undo
1028 1028
 		 */
1029 1029
 
1030 1030
 		$sql = "SELECT rowid, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,";
1031
-		$sql.= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur";
1032
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe_rib";
1033
-		if ($id) $sql.= " WHERE fk_soc  = ".$id." ";
1031
+		$sql .= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur";
1032
+		$sql .= " FROM ".MAIN_DB_PREFIX."societe_rib";
1033
+		if ($id) $sql .= " WHERE fk_soc  = ".$id." ";
1034 1034
 
1035 1035
 
1036 1036
 		$result = $db->query($sql);
1037 1037
 
1038
-		if($result->num_rows == 0 ){
1038
+		if ($result->num_rows == 0) {
1039 1039
 			throw new RestException(404, 'Account not found');
1040 1040
 		}
1041 1041
 
1042
-		$i=0;
1042
+		$i = 0;
1043 1043
 
1044
-		$accounts =[];
1044
+		$accounts = [];
1045 1045
 
1046 1046
 		if ($result)
1047 1047
 		{
@@ -1050,13 +1050,13 @@  discard block
 block discarded – undo
1050 1050
 			{
1051 1051
 				$obj = $db->fetch_object($result);
1052 1052
 				$account = new CompanyBankAccount($db);
1053
-				if($account->fetch($obj->rowid)) {
1053
+				if ($account->fetch($obj->rowid)) {
1054 1054
 					$accounts[] = $account;
1055 1055
 				}
1056 1056
 				$i++;
1057 1057
 			}
1058 1058
 		}
1059
-		else{
1059
+		else {
1060 1060
 			throw new RestException(404, 'Account not found');
1061 1061
 		}
1062 1062
 
@@ -1065,10 +1065,10 @@  discard block
 block discarded – undo
1065 1065
 
1066 1066
 		$returnAccounts = [];
1067 1067
 
1068
-		foreach($accounts as $account){
1069
-			$object= [];
1070
-			foreach($account as $key => $value)
1071
-				if(in_array($key, $fields)){
1068
+		foreach ($accounts as $account) {
1069
+			$object = [];
1070
+			foreach ($account as $key => $value)
1071
+				if (in_array($key, $fields)) {
1072 1072
 					$object[$key] = $value;
1073 1073
 				}
1074 1074
 			$returnAccounts[] = $object;
@@ -1088,7 +1088,7 @@  discard block
 block discarded – undo
1088 1088
 	 */
1089 1089
 	function createCompanyBankAccount($id, $request_data = null)
1090 1090
 	{
1091
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
1091
+		if (!DolibarrApiAccess::$user->rights->societe->creer) {
1092 1092
 			throw new RestException(401);
1093 1093
 		}
1094 1094
 
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
 
1097 1097
 		$account->socid = $id;
1098 1098
 
1099
-		foreach($request_data as $field => $value) {
1099
+		foreach ($request_data as $field => $value) {
1100 1100
 			$account->$field = $value;
1101 1101
 		}
1102 1102
 
@@ -1123,7 +1123,7 @@  discard block
 block discarded – undo
1123 1123
 	 */
1124 1124
 	function updateCompanyBankAccount($id, $bankaccount_id, $request_data = null)
1125 1125
 	{
1126
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
1126
+		if (!DolibarrApiAccess::$user->rights->societe->creer) {
1127 1127
 			throw new RestException(401);
1128 1128
 		}
1129 1129
 
@@ -1131,12 +1131,12 @@  discard block
 block discarded – undo
1131 1131
 
1132 1132
 		$account->fetch($bankaccount_id, $id, -1, '');
1133 1133
 
1134
-		if($account->socid != $id){
1134
+		if ($account->socid != $id) {
1135 1135
 			throw new RestException(401);
1136 1136
 		}
1137 1137
 
1138 1138
 
1139
-		foreach($request_data as $field => $value) {
1139
+		foreach ($request_data as $field => $value) {
1140 1140
 			$account->$field = $value;
1141 1141
 		}
1142 1142
 
@@ -1158,7 +1158,7 @@  discard block
 block discarded – undo
1158 1158
 	 */
1159 1159
 	function deleteCompanyBankAccount($id, $bankaccount_id)
1160 1160
     {
1161
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
1161
+		if (!DolibarrApiAccess::$user->rights->societe->creer) {
1162 1162
 			throw new RestException(401);
1163 1163
 		}
1164 1164
 
@@ -1166,7 +1166,7 @@  discard block
 block discarded – undo
1166 1166
 
1167 1167
 		$account->fetch($bankaccount_id);
1168 1168
 
1169
-		if(!$account->socid == $id)
1169
+		if (!$account->socid == $id)
1170 1170
 			throw new RestException(401);
1171 1171
 
1172 1172
 		return $account->delete(DolibarrApiAccess::$user);
@@ -1186,12 +1186,12 @@  discard block
 block discarded – undo
1186 1186
 	{
1187 1187
 		global $conf;
1188 1188
 
1189
-		$this->langs->loadLangs(array("main","dict","commercial","products","companies","banks","bills","withdrawals"));
1189
+		$this->langs->loadLangs(array("main", "dict", "commercial", "products", "companies", "banks", "bills", "withdrawals"));
1190 1190
 
1191 1191
 		$this->company->fetch($id);
1192 1192
 
1193 1193
 		$action = 'builddoc';
1194
-		if(! DolibarrApiAccess::$user->rights->societe->creer)
1194
+		if (!DolibarrApiAccess::$user->rights->societe->creer)
1195 1195
 			throw new RestException(401);
1196 1196
 
1197 1197
 		$this->company->setDocModel(DolibarrApiAccess::$user, $model);
@@ -1199,32 +1199,32 @@  discard block
 block discarded – undo
1199 1199
 		$this->company->fk_bank = $this->company->fk_account;
1200 1200
 
1201 1201
 		$outputlangs = $this->langs;
1202
-		$newlang='';
1202
+		$newlang = '';
1203 1203
 
1204
-		if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
1205
-		if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->thirdparty->default_lang)) $newlang=$this->company->thirdparty->default_lang;  // for proposal, order, invoice, ...
1206
-		if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->default_lang)) $newlang=$this->company->default_lang;                  // for thirdparty
1207
-		if (! empty($newlang)) {
1208
-			$outputlangs = new Translate("",$conf);
1204
+		if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
1205
+		if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->thirdparty->default_lang)) $newlang = $this->company->thirdparty->default_lang; // for proposal, order, invoice, ...
1206
+		if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->default_lang)) $newlang = $this->company->default_lang; // for thirdparty
1207
+		if (!empty($newlang)) {
1208
+			$outputlangs = new Translate("", $conf);
1209 1209
 			$outputlangs->setDefaultLang($newlang);
1210 1210
 		}
1211 1211
 
1212 1212
 		// To be sure vars is defined
1213 1213
 		$hidedetails = $hidedesc = $hideref = 0;
1214
-		$moreparams=null;
1215
-		if (empty($hidedetails)) $hidedetails=0;
1216
-		if (empty($hidedesc)) $hidedesc=0;
1217
-		if (empty($hideref)) $hideref=0;
1218
-		if (empty($moreparams)) $moreparams=null;
1214
+		$moreparams = null;
1215
+		if (empty($hidedetails)) $hidedetails = 0;
1216
+		if (empty($hidedesc)) $hidedesc = 0;
1217
+		if (empty($hideref)) $hideref = 0;
1218
+		if (empty($moreparams)) $moreparams = null;
1219 1219
 
1220 1220
 
1221 1221
 		$sql = "SELECT rowid";
1222
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe_rib";
1223
-		if ($id) $sql.= " WHERE fk_soc  = ".$id." ";
1224
-		if ($companybankid) $sql.= " AND id = ".$companybankid."";
1222
+		$sql .= " FROM ".MAIN_DB_PREFIX."societe_rib";
1223
+		if ($id) $sql .= " WHERE fk_soc  = ".$id." ";
1224
+		if ($companybankid) $sql .= " AND id = ".$companybankid."";
1225 1225
 
1226
-		$i=0;
1227
-		$accounts=array();
1226
+		$i = 0;
1227
+		$accounts = array();
1228 1228
 
1229 1229
 		$result = $this->db->query($sql);
1230 1230
 		if ($result)
@@ -1281,15 +1281,15 @@  discard block
 block discarded – undo
1281 1281
 	 *
1282 1282
 	 * @url GET {id}/gateways/
1283 1283
 	 */
1284
-	function getSocieteAccounts($id, $site=null)
1284
+	function getSocieteAccounts($id, $site = null)
1285 1285
     {
1286 1286
 		global $db, $conf;
1287 1287
 
1288
-		if(!DolibarrApiAccess::$user->rights->societe->lire) {
1288
+		if (!DolibarrApiAccess::$user->rights->societe->lire) {
1289 1289
 			throw new RestException(401);
1290 1290
 		}
1291 1291
 
1292
-		if(!DolibarrApi::_checkAccessToResource('societe',$id)) {
1292
+		if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
1293 1293
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
1294 1294
 		}
1295 1295
 
@@ -1297,18 +1297,18 @@  discard block
 block discarded – undo
1297 1297
 		 * We select all the records that match the socid
1298 1298
 		 */
1299 1299
 		$sql = "SELECT rowid, fk_soc, key_account, site, date_creation, tms FROM ".MAIN_DB_PREFIX."societe_account";
1300
-		$sql.= " WHERE fk_soc = $id";
1301
-		if($site) $sql .= " AND site ='$site'";
1300
+		$sql .= " WHERE fk_soc = $id";
1301
+		if ($site) $sql .= " AND site ='$site'";
1302 1302
 
1303 1303
 		$result = $db->query($sql);
1304 1304
 
1305
-		if($result->num_rows == 0){
1305
+		if ($result->num_rows == 0) {
1306 1306
 			throw new RestException(404, 'This thirdparty does not have any gateway attached or does not exist.');
1307 1307
 		}
1308 1308
 
1309
-		$i=0;
1309
+		$i = 0;
1310 1310
 
1311
-		$accounts =[];
1311
+		$accounts = [];
1312 1312
 
1313 1313
 		$num = $db->num_rows($result);
1314 1314
 		while ($i < $num)
@@ -1316,7 +1316,7 @@  discard block
 block discarded – undo
1316 1316
 			$obj = $db->fetch_object($result);
1317 1317
 			$account = new SocieteAccount($db);
1318 1318
 
1319
-			if($account->fetch($obj->rowid)) {
1319
+			if ($account->fetch($obj->rowid)) {
1320 1320
 				$accounts[] = $account;
1321 1321
 			}
1322 1322
 			$i++;
@@ -1326,10 +1326,10 @@  discard block
 block discarded – undo
1326 1326
 
1327 1327
 		$returnAccounts = [];
1328 1328
 
1329
-		foreach($accounts as $account){
1330
-			$object= [];
1331
-			foreach($account as $key => $value)
1332
-				if(in_array($key, $fields)){
1329
+		foreach ($accounts as $account) {
1330
+			$object = [];
1331
+			foreach ($account as $key => $value)
1332
+				if (in_array($key, $fields)) {
1333 1333
 					$object[$key] = $value;
1334 1334
 				}
1335 1335
 			$returnAccounts[] = $object;
@@ -1361,25 +1361,25 @@  discard block
 block discarded – undo
1361 1361
 	{
1362 1362
 		global $db;
1363 1363
 
1364
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
1364
+		if (!DolibarrApiAccess::$user->rights->societe->creer) {
1365 1365
 			throw new RestException(401);
1366 1366
 		}
1367 1367
 
1368
-		if(!isset($request_data['site'])) {
1368
+		if (!isset($request_data['site'])) {
1369 1369
 			throw new RestException(422, 'Unprocessable Entity: You must pass the site attribute in your request data !');
1370 1370
 		}
1371 1371
 
1372
-		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = ".$id." AND site = '". $request_data['site']."' ";
1372
+		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = ".$id." AND site = '".$request_data['site']."' ";
1373 1373
 		$result = $db->query($sql);
1374 1374
 
1375
-		if($result->num_rows == 0 ){
1375
+		if ($result->num_rows == 0) {
1376 1376
 			$account = new SocieteAccount($this->db);
1377
-			if(!isset($request_data['login'])) {
1377
+			if (!isset($request_data['login'])) {
1378 1378
 				$account->login = "";
1379 1379
 			}
1380 1380
 			$account->fk_soc = $id;
1381 1381
 
1382
-			foreach($request_data as $field => $value) {
1382
+			foreach ($request_data as $field => $value) {
1383 1383
 				$account->$field = $value;
1384 1384
 			}
1385 1385
 
@@ -1420,7 +1420,7 @@  discard block
 block discarded – undo
1420 1420
 	{
1421 1421
 		global $db;
1422 1422
 
1423
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
1423
+		if (!DolibarrApiAccess::$user->rights->societe->creer) {
1424 1424
 			throw new RestException(401);
1425 1425
 		}
1426 1426
 
@@ -1428,16 +1428,16 @@  discard block
 block discarded – undo
1428 1428
 		$result = $db->query($sql);
1429 1429
 
1430 1430
 		// We do not found an existing SocieteAccount entity for this fk_soc and site ; we then create a new one.
1431
-		if($result->num_rows == 0 ){
1432
-			if(!isset($request_data['key_account'])) {
1431
+		if ($result->num_rows == 0) {
1432
+			if (!isset($request_data['key_account'])) {
1433 1433
 				throw new RestException(422, 'Unprocessable Entity: You must pass the key_account attribute in your request data !');
1434 1434
 			}
1435 1435
 			$account = new SocieteAccount($this->db);
1436
-			if(!isset($request_data['login'])) {
1436
+			if (!isset($request_data['login'])) {
1437 1437
 				$account->login = "";
1438 1438
 			}
1439 1439
 
1440
-			foreach($request_data as $field => $value) {
1440
+			foreach ($request_data as $field => $value) {
1441 1441
 				$account->$field = $value;
1442 1442
 			}
1443 1443
 
@@ -1449,12 +1449,12 @@  discard block
 block discarded – undo
1449 1449
 		// We found an existing SocieteAccount entity, we are replacing it
1450 1450
 		} else {
1451 1451
 
1452
-			if(isset($request_data['site']) && $request_data['site'] !== $site) {
1453
-				$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = ".$id." AND site = '". $request_data['site']."' ";
1452
+			if (isset($request_data['site']) && $request_data['site'] !== $site) {
1453
+				$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = ".$id." AND site = '".$request_data['site']."' ";
1454 1454
 				$result = $db->query($sql);
1455 1455
 
1456
-				if($result->num_rows !== 0)
1457
-					throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) from $site to ".$request_data['site'] . " but another SocieteAccount entity already exists with this site key.");
1456
+				if ($result->num_rows !== 0)
1457
+					throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) from $site to ".$request_data['site']." but another SocieteAccount entity already exists with this site key.");
1458 1458
 			}
1459 1459
 
1460 1460
 			$obj = $db->fetch_object($result);
@@ -1463,13 +1463,13 @@  discard block
 block discarded – undo
1463 1463
 			$account->id = $obj->rowid;
1464 1464
 			$account->fk_soc = $id;
1465 1465
 			$account->site = $site;
1466
-			if(!isset($request_data['login'])) {
1466
+			if (!isset($request_data['login'])) {
1467 1467
 				$account->login = "";
1468 1468
 			}
1469 1469
 			$account->fk_user_creat = $obj->fk_user_creat;
1470 1470
 			$account->date_creation = $obj->date_creation;
1471 1471
 
1472
-			foreach($request_data as $field => $value) {
1472
+			foreach ($request_data as $field => $value) {
1473 1473
 				$account->$field = $value;
1474 1474
 			}
1475 1475
 
@@ -1501,31 +1501,31 @@  discard block
 block discarded – undo
1501 1501
 	{
1502 1502
 		global $db;
1503 1503
 
1504
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
1504
+		if (!DolibarrApiAccess::$user->rights->societe->creer) {
1505 1505
 			throw new RestException(401);
1506 1506
 		}
1507 1507
 
1508 1508
 		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = $id AND site = '$site' ";
1509 1509
 		$result = $db->query($sql);
1510 1510
 
1511
-		if($result->num_rows == 0 ){
1511
+		if ($result->num_rows == 0) {
1512 1512
 			throw new RestException(404, "This thirdparty does not have $site gateway attached or does not exist.");
1513 1513
 		} else {
1514 1514
 
1515 1515
 			// If the user tries to edit the site member, we check first if
1516
-			if(isset($request_data['site']) && $request_data['site'] !== $site) {
1517
-				$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = ".$id." AND site = '". $request_data['site']."' ";
1516
+			if (isset($request_data['site']) && $request_data['site'] !== $site) {
1517
+				$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = ".$id." AND site = '".$request_data['site']."' ";
1518 1518
 				$result = $db->query($sql);
1519 1519
 
1520
-				if($result->num_rows !== 0)
1521
-					throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) site member from $site to ".$request_data['site'] . " but another SocieteAccount entity already exists for this thirdparty with this site key.");
1520
+				if ($result->num_rows !== 0)
1521
+					throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) site member from $site to ".$request_data['site']." but another SocieteAccount entity already exists for this thirdparty with this site key.");
1522 1522
 			}
1523 1523
 
1524 1524
 			$obj = $db->fetch_object($result);
1525 1525
 			$account = new SocieteAccount($this->db);
1526 1526
 			$account->fetch($obj->rowid);
1527 1527
 
1528
-			foreach($request_data as $field => $value) {
1528
+			foreach ($request_data as $field => $value) {
1529 1529
 				$account->$field = $value;
1530 1530
 			}
1531 1531
 
@@ -1556,21 +1556,21 @@  discard block
 block discarded – undo
1556 1556
 		global /** @var Database $db */
1557 1557
 		$db;
1558 1558
 
1559
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
1559
+		if (!DolibarrApiAccess::$user->rights->societe->creer) {
1560 1560
 			throw new RestException(401);
1561 1561
 		}
1562 1562
 
1563 1563
 		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = $id AND site = '$site' ";
1564 1564
 		$result = $db->query($sql);
1565 1565
 
1566
-		if($result->num_rows == 0 ){
1566
+		if ($result->num_rows == 0) {
1567 1567
 			throw new RestException(404);
1568 1568
 		} else {
1569 1569
 			$obj = $db->fetch_object($result);
1570 1570
 			$account = new SocieteAccount($this->db);
1571 1571
 			$account->fetch($obj->rowid);
1572 1572
 
1573
-			if($account->delete(DolibarrApiAccess::$user) < 0) {
1573
+			if ($account->delete(DolibarrApiAccess::$user) < 0) {
1574 1574
 				throw new RestException(500, "Error while deleting $site gateway attached to this third party");
1575 1575
 			}
1576 1576
 		}
@@ -1593,7 +1593,7 @@  discard block
 block discarded – undo
1593 1593
 		global /** @var Database $db */
1594 1594
 		$db;
1595 1595
 
1596
-		if(! DolibarrApiAccess::$user->rights->societe->creer) {
1596
+		if (!DolibarrApiAccess::$user->rights->societe->creer) {
1597 1597
 			throw new RestException(401);
1598 1598
 		}
1599 1599
 
@@ -1602,14 +1602,14 @@  discard block
 block discarded – undo
1602 1602
 		 */
1603 1603
 
1604 1604
 		$sql = "SELECT rowid, fk_soc, key_account, site, date_creation, tms";
1605
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = $id ";
1605
+		$sql .= " FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = $id ";
1606 1606
 
1607 1607
 		$result = $db->query($sql);
1608 1608
 
1609
-		if($result->num_rows == 0 ){
1609
+		if ($result->num_rows == 0) {
1610 1610
 			throw new RestException(404, 'This third party does not have any gateway attached or does not exist.');
1611 1611
 		} else {
1612
-			$i=0;
1612
+			$i = 0;
1613 1613
 
1614 1614
 			$num = $db->num_rows($result);
1615 1615
 			while ($i < $num)
@@ -1618,7 +1618,7 @@  discard block
 block discarded – undo
1618 1618
 				$account = new SocieteAccount($db);
1619 1619
 				$account->fetch($obj->rowid);
1620 1620
 
1621
-				if($account->delete(DolibarrApiAccess::$user) < 0) {
1621
+				if ($account->delete(DolibarrApiAccess::$user) < 0) {
1622 1622
 					throw new RestException(500, 'Error while deleting gateways attached to this third party');
1623 1623
 				}
1624 1624
 				$i++;
@@ -1636,7 +1636,7 @@  discard block
 block discarded – undo
1636 1636
     {
1637 1637
 		$object = parent::_cleanObjectDatas($object);
1638 1638
 
1639
-		unset($object->nom);	// ->name already defined and nom deprecated
1639
+		unset($object->nom); // ->name already defined and nom deprecated
1640 1640
 
1641 1641
 		unset($object->total_ht);
1642 1642
 		unset($object->total_tva);
Please login to merge, or discard this patch.
Braces   +139 added lines, -69 removed lines patch added patch discarded remove patch
@@ -128,23 +128,44 @@  discard block
 block discarded – undo
128 128
 
129 129
 		// If the internal user must only see his customers, force searching by him
130 130
 		$search_sale = 0;
131
-		if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
131
+		if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) {
132
+		    $search_sale = DolibarrApiAccess::$user->id;
133
+		}
132 134
 
133 135
 		$sql = "SELECT t.rowid";
134
-		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
136
+		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
137
+		    $sql .= ", sc.fk_soc, sc.fk_user";
138
+		}
139
+		// We need these fields in order to filter by sale (including the case where the user can only see his prospects)
135 140
 		$sql.= " FROM ".MAIN_DB_PREFIX."societe as t";
136 141
 
137
-		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
142
+		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
143
+		    $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
144
+		}
145
+		// We need this table joined to the select in order to filter by sale
138 146
 		$sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st";
139 147
 		$sql.= " WHERE t.fk_stcomm = st.id";
140
-		if ($mode == 1) $sql.= " AND t.client IN (1, 3)";
141
-		if ($mode == 2) $sql.= " AND t.client IN (2, 3)";
142
-		if ($mode == 3) $sql.= " AND t.client IN (0)";
148
+		if ($mode == 1) {
149
+		    $sql.= " AND t.client IN (1, 3)";
150
+		}
151
+		if ($mode == 2) {
152
+		    $sql.= " AND t.client IN (2, 3)";
153
+		}
154
+		if ($mode == 3) {
155
+		    $sql.= " AND t.client IN (0)";
156
+		}
143 157
 		$sql.= ' AND t.entity IN ('.getEntity('societe').')';
144
-		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";
158
+		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
159
+		    $sql.= " AND t.rowid = sc.fk_soc";
160
+		}
145 161
 		//if ($email != NULL) $sql.= " AND s.email = \"".$email."\"";
146
-		if ($socid) $sql.= " AND t.rowid IN (".$socids.")";
147
-		if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";		// Join for the needed table to filter by sale
162
+		if ($socid) {
163
+		    $sql.= " AND t.rowid IN (".$socids.")";
164
+		}
165
+		if ($search_sale > 0) {
166
+		    $sql.= " AND t.rowid = sc.fk_soc";
167
+		}
168
+		// Join for the needed table to filter by sale
148 169
 		// Insert sale filter
149 170
 		if ($search_sale > 0)
150 171
 		{
@@ -187,8 +208,7 @@  discard block
 block discarded – undo
187 208
 				}
188 209
 				$i++;
189 210
 			}
190
-		}
191
-		else {
211
+		} else {
192 212
 			throw new RestException(503, 'Error when retrieve thirdparties : '.$db->lasterror());
193 213
 		}
194 214
 		if( ! count($obj_ret)) {
@@ -214,8 +234,9 @@  discard block
 block discarded – undo
214 234
 		foreach($request_data as $field => $value) {
215 235
 			$this->company->$field = $value;
216 236
 		}
217
-		if ($this->company->create(DolibarrApiAccess::$user) < 0)
218
-			throw new RestException(500, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors));
237
+		if ($this->company->create(DolibarrApiAccess::$user) < 0) {
238
+					throw new RestException(500, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors));
239
+		}
219 240
 
220 241
 		return $this->company->id;
221 242
 	}
@@ -243,12 +264,15 @@  discard block
 block discarded – undo
243 264
 		}
244 265
 
245 266
 		foreach($request_data as $field => $value) {
246
-			if ($field == 'id') continue;
267
+			if ($field == 'id') {
268
+			    continue;
269
+			}
247 270
 			$this->company->$field = $value;
248 271
 		}
249 272
 
250
-		if($this->company->update($id, DolibarrApiAccess::$user,1,'','','update'))
251
-			return $this->get($id);
273
+		if($this->company->update($id, DolibarrApiAccess::$user,1,'','','update')) {
274
+					return $this->get($id);
275
+		}
252 276
 
253 277
 		return false;
254 278
 	}
@@ -325,7 +349,9 @@  discard block
 block discarded – undo
325 349
 		);
326 350
 		foreach ($listofproperties as $property)
327 351
 		{
328
-			if (empty($object->$property)) $object->$property = $soc_origin->$property;
352
+			if (empty($object->$property)) {
353
+			    $object->$property = $soc_origin->$property;
354
+			}
329 355
 		}
330 356
 
331 357
 		// Concat some data
@@ -342,7 +368,9 @@  discard block
 block discarded – undo
342 368
 		{
343 369
 			foreach ($soc_origin->array_options as $key => $val)
344 370
 			{
345
-				if (empty($object->array_options[$key])) $object->array_options[$key] = $val;
371
+				if (empty($object->array_options[$key])) {
372
+				    $object->array_options[$key] = $val;
373
+				}
346 374
 			}
347 375
 		}
348 376
 
@@ -458,8 +486,7 @@  discard block
 block discarded – undo
458 486
 			$db->rollback();
459 487
 
460 488
 			throw new RestException(500, 'Error failed to merged thirdparty '.$this->companytoremove->id.' into '.$id.'. Enable and read log file for more information.');
461
-		}
462
-		else
489
+		} else
463 490
 		{
464 491
 			$db->commit();
465 492
 		}
@@ -522,10 +549,12 @@  discard block
 block discarded – undo
522 549
 			throw new RestException(503, 'Error when retrieve category list : '.$categories->error);
523 550
 		}
524 551
 
525
-		if (is_numeric($result) && $result == 0)	// To fix a return of 0 instead of empty array of method getListForItem
552
+		if (is_numeric($result) && $result == 0) {
553
+		    // To fix a return of 0 instead of empty array of method getListForItem
526 554
 		{
527 555
 			return array();
528 556
 		}
557
+		}
529 558
 
530 559
 		return $result;
531 560
 	}
@@ -640,10 +669,12 @@  discard block
 block discarded – undo
640 669
 			throw new RestException(503, 'Error when retrieve category list : '.$categories->error);
641 670
 		}
642 671
 
643
-		if (is_numeric($result) && $result == 0)	// To fix a return of 0 instead of empty array of method getListForItem
672
+		if (is_numeric($result) && $result == 0) {
673
+		    // To fix a return of 0 instead of empty array of method getListForItem
644 674
 		{
645 675
 			return array();
646 676
 		}
677
+		}
647 678
 
648 679
 		return $result;
649 680
 	}
@@ -897,8 +928,12 @@  discard block
 block discarded – undo
897 928
 		$sql = "SELECT f.ref, f.type as factype, re.fk_facture_source, re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc, re.description, re.fk_facture, re.fk_facture_line";
898 929
 		$sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
899 930
 		$sql .= " WHERE f.rowid = re.fk_facture_source AND re.fk_soc = ".$id;
900
-		if ($filter == "available")  $sql .= " AND re.fk_facture IS NULL AND re.fk_facture_line IS NULL";
901
-		if ($filter == "used")  $sql .= " AND (re.fk_facture IS NOT NULL OR re.fk_facture_line IS NOT NULL)";
931
+		if ($filter == "available") {
932
+		    $sql .= " AND re.fk_facture IS NULL AND re.fk_facture_line IS NULL";
933
+		}
934
+		if ($filter == "used") {
935
+		    $sql .= " AND (re.fk_facture IS NOT NULL OR re.fk_facture_line IS NOT NULL)";
936
+		}
902 937
 
903 938
 		$sql.= $this->db->order($sortfield, $sortorder);
904 939
 
@@ -1030,7 +1065,9 @@  discard block
 block discarded – undo
1030 1065
 		$sql = "SELECT rowid, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,";
1031 1066
 		$sql.= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur";
1032 1067
 		$sql.= " FROM ".MAIN_DB_PREFIX."societe_rib";
1033
-		if ($id) $sql.= " WHERE fk_soc  = ".$id." ";
1068
+		if ($id) {
1069
+		    $sql.= " WHERE fk_soc  = ".$id." ";
1070
+		}
1034 1071
 
1035 1072
 
1036 1073
 		$result = $db->query($sql);
@@ -1055,8 +1092,7 @@  discard block
 block discarded – undo
1055 1092
 				}
1056 1093
 				$i++;
1057 1094
 			}
1058
-		}
1059
-		else{
1095
+		} else{
1060 1096
 			throw new RestException(404, 'Account not found');
1061 1097
 		}
1062 1098
 
@@ -1067,9 +1103,10 @@  discard block
 block discarded – undo
1067 1103
 
1068 1104
 		foreach($accounts as $account){
1069 1105
 			$object= [];
1070
-			foreach($account as $key => $value)
1071
-				if(in_array($key, $fields)){
1106
+			foreach($account as $key => $value) {
1107
+							if(in_array($key, $fields)){
1072 1108
 					$object[$key] = $value;
1109
+			}
1073 1110
 				}
1074 1111
 			$returnAccounts[] = $object;
1075 1112
 		}
@@ -1100,12 +1137,14 @@  discard block
 block discarded – undo
1100 1137
 			$account->$field = $value;
1101 1138
 		}
1102 1139
 
1103
-		if ($account->create(DolibarrApiAccess::$user) < 0)
1104
-			throw new RestException(500, 'Error creating Company Bank account');
1140
+		if ($account->create(DolibarrApiAccess::$user) < 0) {
1141
+					throw new RestException(500, 'Error creating Company Bank account');
1142
+		}
1105 1143
 
1106 1144
 
1107
-		if ($account->update(DolibarrApiAccess::$user) < 0)
1108
-			throw new RestException(500, 'Error updating values');
1145
+		if ($account->update(DolibarrApiAccess::$user) < 0) {
1146
+					throw new RestException(500, 'Error updating values');
1147
+		}
1109 1148
 
1110 1149
 		return $account;
1111 1150
 	}
@@ -1140,8 +1179,9 @@  discard block
 block discarded – undo
1140 1179
 			$account->$field = $value;
1141 1180
 		}
1142 1181
 
1143
-		if ($account->update(DolibarrApiAccess::$user) < 0)
1144
-			throw new RestException(500, 'Error updating values');
1182
+		if ($account->update(DolibarrApiAccess::$user) < 0) {
1183
+					throw new RestException(500, 'Error updating values');
1184
+		}
1145 1185
 
1146 1186
 		return $account;
1147 1187
 	}
@@ -1166,8 +1206,9 @@  discard block
 block discarded – undo
1166 1206
 
1167 1207
 		$account->fetch($bankaccount_id);
1168 1208
 
1169
-		if(!$account->socid == $id)
1170
-			throw new RestException(401);
1209
+		if(!$account->socid == $id) {
1210
+					throw new RestException(401);
1211
+		}
1171 1212
 
1172 1213
 		return $account->delete(DolibarrApiAccess::$user);
1173 1214
 	}
@@ -1191,8 +1232,9 @@  discard block
 block discarded – undo
1191 1232
 		$this->company->fetch($id);
1192 1233
 
1193 1234
 		$action = 'builddoc';
1194
-		if(! DolibarrApiAccess::$user->rights->societe->creer)
1195
-			throw new RestException(401);
1235
+		if(! DolibarrApiAccess::$user->rights->societe->creer) {
1236
+					throw new RestException(401);
1237
+		}
1196 1238
 
1197 1239
 		$this->company->setDocModel(DolibarrApiAccess::$user, $model);
1198 1240
 
@@ -1201,9 +1243,17 @@  discard block
 block discarded – undo
1201 1243
 		$outputlangs = $this->langs;
1202 1244
 		$newlang='';
1203 1245
 
1204
-		if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
1205
-		if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->thirdparty->default_lang)) $newlang=$this->company->thirdparty->default_lang;  // for proposal, order, invoice, ...
1206
-		if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->default_lang)) $newlang=$this->company->default_lang;                  // for thirdparty
1246
+		if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) {
1247
+		    $newlang=GETPOST('lang_id','aZ09');
1248
+		}
1249
+		if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->thirdparty->default_lang)) {
1250
+		    $newlang=$this->company->thirdparty->default_lang;
1251
+		}
1252
+		// for proposal, order, invoice, ...
1253
+		if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->default_lang)) {
1254
+		    $newlang=$this->company->default_lang;
1255
+		}
1256
+		// for thirdparty
1207 1257
 		if (! empty($newlang)) {
1208 1258
 			$outputlangs = new Translate("",$conf);
1209 1259
 			$outputlangs->setDefaultLang($newlang);
@@ -1212,16 +1262,28 @@  discard block
 block discarded – undo
1212 1262
 		// To be sure vars is defined
1213 1263
 		$hidedetails = $hidedesc = $hideref = 0;
1214 1264
 		$moreparams=null;
1215
-		if (empty($hidedetails)) $hidedetails=0;
1216
-		if (empty($hidedesc)) $hidedesc=0;
1217
-		if (empty($hideref)) $hideref=0;
1218
-		if (empty($moreparams)) $moreparams=null;
1265
+		if (empty($hidedetails)) {
1266
+		    $hidedetails=0;
1267
+		}
1268
+		if (empty($hidedesc)) {
1269
+		    $hidedesc=0;
1270
+		}
1271
+		if (empty($hideref)) {
1272
+		    $hideref=0;
1273
+		}
1274
+		if (empty($moreparams)) {
1275
+		    $moreparams=null;
1276
+		}
1219 1277
 
1220 1278
 
1221 1279
 		$sql = "SELECT rowid";
1222 1280
 		$sql.= " FROM ".MAIN_DB_PREFIX."societe_rib";
1223
-		if ($id) $sql.= " WHERE fk_soc  = ".$id." ";
1224
-		if ($companybankid) $sql.= " AND id = ".$companybankid."";
1281
+		if ($id) {
1282
+		    $sql.= " WHERE fk_soc  = ".$id." ";
1283
+		}
1284
+		if ($companybankid) {
1285
+		    $sql.= " AND id = ".$companybankid."";
1286
+		}
1225 1287
 
1226 1288
 		$i=0;
1227 1289
 		$accounts=array();
@@ -1244,8 +1306,7 @@  discard block
 block discarded – undo
1244 1306
 				}
1245 1307
 				$i++;
1246 1308
 			}
1247
-		}
1248
-		else
1309
+		} else
1249 1310
 		{
1250 1311
 			throw new RestException(404, 'Bank account not found');
1251 1312
 		}
@@ -1262,8 +1323,7 @@  discard block
 block discarded – undo
1262 1323
 		if ($result > 0)
1263 1324
 		{
1264 1325
 			return array("success" => $result);
1265
-		}
1266
-		else
1326
+		} else
1267 1327
 		{
1268 1328
 			throw new RestException(500);
1269 1329
 		}
@@ -1298,7 +1358,9 @@  discard block
 block discarded – undo
1298 1358
 		 */
1299 1359
 		$sql = "SELECT rowid, fk_soc, key_account, site, date_creation, tms FROM ".MAIN_DB_PREFIX."societe_account";
1300 1360
 		$sql.= " WHERE fk_soc = $id";
1301
-		if($site) $sql .= " AND site ='$site'";
1361
+		if($site) {
1362
+		    $sql .= " AND site ='$site'";
1363
+		}
1302 1364
 
1303 1365
 		$result = $db->query($sql);
1304 1366
 
@@ -1328,9 +1390,10 @@  discard block
 block discarded – undo
1328 1390
 
1329 1391
 		foreach($accounts as $account){
1330 1392
 			$object= [];
1331
-			foreach($account as $key => $value)
1332
-				if(in_array($key, $fields)){
1393
+			foreach($account as $key => $value) {
1394
+							if(in_array($key, $fields)){
1333 1395
 					$object[$key] = $value;
1396
+			}
1334 1397
 				}
1335 1398
 			$returnAccounts[] = $object;
1336 1399
 		}
@@ -1383,8 +1446,9 @@  discard block
 block discarded – undo
1383 1446
 				$account->$field = $value;
1384 1447
 			}
1385 1448
 
1386
-			if ($account->create(DolibarrApiAccess::$user) < 0)
1387
-				throw new RestException(500, 'Error creating SocieteAccount entity. Ensure that the ID of thirdparty provided does exist!');
1449
+			if ($account->create(DolibarrApiAccess::$user) < 0) {
1450
+							throw new RestException(500, 'Error creating SocieteAccount entity. Ensure that the ID of thirdparty provided does exist!');
1451
+			}
1388 1452
 
1389 1453
 			$this->_cleanObjectDatas($account);
1390 1454
 
@@ -1444,8 +1508,9 @@  discard block
 block discarded – undo
1444 1508
 			$account->fk_soc = $id;
1445 1509
 			$account->site = $site;
1446 1510
 
1447
-			if ($account->create(DolibarrApiAccess::$user) < 0)
1448
-				throw new RestException(500, 'Error creating SocieteAccount entity.');
1511
+			if ($account->create(DolibarrApiAccess::$user) < 0) {
1512
+							throw new RestException(500, 'Error creating SocieteAccount entity.');
1513
+			}
1449 1514
 		// We found an existing SocieteAccount entity, we are replacing it
1450 1515
 		} else {
1451 1516
 
@@ -1453,8 +1518,9 @@  discard block
 block discarded – undo
1453 1518
 				$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = ".$id." AND site = '". $request_data['site']."' ";
1454 1519
 				$result = $db->query($sql);
1455 1520
 
1456
-				if($result->num_rows !== 0)
1457
-					throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) from $site to ".$request_data['site'] . " but another SocieteAccount entity already exists with this site key.");
1521
+				if($result->num_rows !== 0) {
1522
+									throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) from $site to ".$request_data['site'] . " but another SocieteAccount entity already exists with this site key.");
1523
+				}
1458 1524
 			}
1459 1525
 
1460 1526
 			$obj = $db->fetch_object($result);
@@ -1473,8 +1539,9 @@  discard block
 block discarded – undo
1473 1539
 				$account->$field = $value;
1474 1540
 			}
1475 1541
 
1476
-			if ($account->update(DolibarrApiAccess::$user) < 0)
1477
-				throw new RestException(500, 'Error updating SocieteAccount entity.');
1542
+			if ($account->update(DolibarrApiAccess::$user) < 0) {
1543
+							throw new RestException(500, 'Error updating SocieteAccount entity.');
1544
+			}
1478 1545
 		}
1479 1546
 
1480 1547
 		$this->_cleanObjectDatas($account);
@@ -1517,8 +1584,9 @@  discard block
 block discarded – undo
1517 1584
 				$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc  = ".$id." AND site = '". $request_data['site']."' ";
1518 1585
 				$result = $db->query($sql);
1519 1586
 
1520
-				if($result->num_rows !== 0)
1521
-					throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) site member from $site to ".$request_data['site'] . " but another SocieteAccount entity already exists for this thirdparty with this site key.");
1587
+				if($result->num_rows !== 0) {
1588
+									throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) site member from $site to ".$request_data['site'] . " but another SocieteAccount entity already exists for this thirdparty with this site key.");
1589
+				}
1522 1590
 			}
1523 1591
 
1524 1592
 			$obj = $db->fetch_object($result);
@@ -1529,8 +1597,9 @@  discard block
 block discarded – undo
1529 1597
 				$account->$field = $value;
1530 1598
 			}
1531 1599
 
1532
-			if ($account->update(DolibarrApiAccess::$user) < 0)
1533
-				throw new RestException(500, 'Error updating SocieteAccount account');
1600
+			if ($account->update(DolibarrApiAccess::$user) < 0) {
1601
+							throw new RestException(500, 'Error updating SocieteAccount account');
1602
+			}
1534 1603
 
1535 1604
 			$this->_cleanObjectDatas($account);
1536 1605
 
@@ -1662,8 +1731,9 @@  discard block
 block discarded – undo
1662 1731
 	{
1663 1732
 		$thirdparty = array();
1664 1733
 		foreach (Thirdparties::$FIELDS as $field) {
1665
-			if (!isset($data[$field]))
1666
-				throw new RestException(400, "$field field missing");
1734
+			if (!isset($data[$field])) {
1735
+							throw new RestException(400, "$field field missing");
1736
+			}
1667 1737
 			$thirdparty[$field] = $data[$field];
1668 1738
 		}
1669 1739
 		return $thirdparty;
Please login to merge, or discard this patch.
dolibarr/htdocs/societe/societecontact.php 3 patches
Indentation   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -54,60 +54,60 @@  discard block
 block discarded – undo
54 54
 
55 55
 if ($action == 'addcontact' && $user->rights->societe->creer)
56 56
 {
57
-	$result = $object->fetch($id);
57
+    $result = $object->fetch($id);
58 58
 
59 59
     if ($result > 0 && $id > 0)
60 60
     {
61
-    	$contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int'));
62
-  		$result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
61
+        $contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int'));
62
+            $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
63 63
     }
64 64
 
65
-	if ($result >= 0)
66
-	{
67
-		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
68
-		exit;
69
-	}
70
-	else
71
-	{
72
-		if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
73
-		{
74
-			$langs->load("errors");
75
-			$mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
76
-		}
77
-		else
78
-		{
79
-			$mesg = '<div class="error">'.$object->error.'</div>';
80
-		}
81
-	}
65
+    if ($result >= 0)
66
+    {
67
+        header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
68
+        exit;
69
+    }
70
+    else
71
+    {
72
+        if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
73
+        {
74
+            $langs->load("errors");
75
+            $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
76
+        }
77
+        else
78
+        {
79
+            $mesg = '<div class="error">'.$object->error.'</div>';
80
+        }
81
+    }
82 82
 }
83 83
 
84 84
 // bascule du statut d'un contact
85 85
 else if ($action == 'swapstatut' && $user->rights->societe->creer)
86 86
 {
87
-	if ($object->fetch($id))
88
-	{
89
-	    $result=$object->swapContactStatus(GETPOST('ligne'));
90
-	}
91
-	else
92
-	{
93
-		dol_print_error($db);
94
-	}
87
+    if ($object->fetch($id))
88
+    {
89
+        $result=$object->swapContactStatus(GETPOST('ligne'));
90
+    }
91
+    else
92
+    {
93
+        dol_print_error($db);
94
+    }
95 95
 }
96 96
 
97 97
 // Efface un contact
98 98
 else if ($action == 'deletecontact' && $user->rights->societe->creer)
99 99
 {
100
-	$object->fetch($id);
101
-	$result = $object->delete_contact($_GET["lineid"]);
102
-
103
-	if ($result >= 0)
104
-	{
105
-		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
106
-		exit;
107
-	}
108
-	else {
109
-		dol_print_error($db);
110
-	}
100
+    $object->fetch($id);
101
+    $result = $object->delete_contact($_GET["lineid"]);
102
+
103
+    if ($result >= 0)
104
+    {
105
+        header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
106
+        exit;
107
+    }
108
+    else {
109
+        dol_print_error($db);
110
+    }
111 111
 }
112 112
 /*
113 113
 else if ($action == 'setaddress' && $user->rights->societe->creer)
@@ -141,28 +141,28 @@  discard block
 block discarded – undo
141 141
 
142 142
 if ($id > 0 || ! empty($ref))
143 143
 {
144
-	if ($object->fetch($id, $ref) > 0)
145
-	{
146
-		$soc = new Societe($db);
147
-		$soc->fetch($object->socid);
144
+    if ($object->fetch($id, $ref) > 0)
145
+    {
146
+        $soc = new Societe($db);
147
+        $soc->fetch($object->socid);
148 148
 
149
-		$head = societe_prepare_head($object);
150
-		dol_fiche_head($head, 'contact', $langs->trans("ThirdParty"), -1, 'company');
149
+        $head = societe_prepare_head($object);
150
+        dol_fiche_head($head, 'contact', $langs->trans("ThirdParty"), -1, 'company');
151 151
 
152
-		print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
153
-		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
152
+        print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
153
+        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
154 154
 
155 155
         $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
156 156
 
157 157
         dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
158 158
 
159
-    	print '<div class="fichecenter">';
159
+        print '<div class="fichecenter">';
160 160
 
161 161
         print '<div class="underbanner clearboth"></div>';
162
-		print '<table class="border centpercent">';
162
+        print '<table class="border centpercent">';
163 163
 
164
-    	// Prospect/Customer
165
-    	/*print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>';
164
+        // Prospect/Customer
165
+        /*print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>';
166 166
     	print $object->getLibCustProspStatut();
167 167
     	print '</td></tr>';
168 168
 
@@ -171,175 +171,175 @@  discard block
 block discarded – undo
171 171
     	print yn($object->fournisseur);
172 172
     	print '</td></tr>';*/
173 173
 
174
-		if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
175
-		{
176
-		    print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
177
-		}
178
-
179
-		if ($object->client)
180
-		{
181
-		    print '<tr><td class="titlefield">';
182
-		    print $langs->trans('CustomerCode').'</td><td colspan="3">';
183
-		    print $object->code_client;
184
-		    if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
185
-		    print '</td></tr>';
186
-		}
187
-
188
-		if ($object->fournisseur)
189
-		{
190
-		    print '<tr><td class="titlefield">';
191
-		    print $langs->trans('SupplierCode').'</td><td colspan="3">';
192
-		    print $object->code_fournisseur;
193
-		    if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
194
-		    print '</td></tr>';
195
-		}
196
-		print '</table>';
197
-
198
-		print '</div>';
199
-
200
-		print '</form>';
201
-		print '<br>';
202
-
203
-		// Contacts lines (modules that overwrite templates must declare this into descriptor)
204
-		$dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
205
-		foreach($dirtpls as $reldir)
206
-		{
207
-			$res=@include dol_buildpath($reldir.'/contacts.tpl.php');
208
-			if ($res) break;
209
-		}
210
-
211
-		// additionnal list with adherents of company
212
-		if (! empty($conf->adherent->enabled) && $user->rights->adherent->lire)
213
-		{
214
-			require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
215
-			require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
216
-
217
-			$membertypestatic=new AdherentType($db);
218
-			$memberstatic=new Adherent($db);
219
-
220
-			$langs->load("members");
221
-			$sql = "SELECT d.rowid, d.login, d.lastname, d.firstname, d.societe as company, d.fk_soc,";
222
-			$sql.= " d.datefin,";
223
-			$sql.= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut,";
224
-			$sql.= " t.libelle as type, t.subscription";
225
-			$sql.= " FROM ".MAIN_DB_PREFIX."adherent as d";
226
-			$sql.= ", ".MAIN_DB_PREFIX."adherent_type as t";
227
-			$sql.= " WHERE d.fk_soc = ".$id;
228
-			$sql.= " AND d.fk_adherent_type = t.rowid";
229
-
230
-			dol_syslog("get list sql=".$sql);
231
-			$resql = $db->query($sql);
232
-			if ($resql)
233
-			{
234
-				$num = $db->num_rows($resql);
235
-
236
-				if ($num  > 0 )
237
-				{
238
-					$titre=$langs->trans("MembersListOfTiers");
239
-					print '<br>';
240
-
241
-					print_barre_liste($titre,$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords,'');
242
-
243
-					print "<table class=\"noborder\" width=\"100%\">";
244
-					print '<tr class="liste_titre">';
245
-					print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"d.rowid",$param,"","",$sortfield,$sortorder);
246
-					print_liste_field_titre( $langs->trans("Name")." / ".$langs->trans("Company"),$_SERVER["PHP_SELF"],"d.lastname",$param,"","",$sortfield,$sortorder);
247
-					print_liste_field_titre("Login",$_SERVER["PHP_SELF"],"d.login",$param,"","",$sortfield,$sortorder);
248
-					print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"t.libelle",$param,"","",$sortfield,$sortorder);
249
-					print_liste_field_titre("Person",$_SERVER["PHP_SELF"],"d.morphy",$param,"","",$sortfield,$sortorder);
250
-					print_liste_field_titre("EMail",$_SERVER["PHP_SELF"],"d.email",$param,"","",$sortfield,$sortorder);
251
-					print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"d.statut,d.datefin",$param,"","",$sortfield,$sortorder);
252
-					print_liste_field_titre("EndSubscription",$_SERVER["PHP_SELF"],"d.datefin",$param,"",'align="center"',$sortfield,$sortorder);
253
-					print "</tr>\n";
254
-
255
-					$i=0;
256
-					while ($i < $num && $i < $conf->liste_limit)
257
-					{
258
-						$objp = $db->fetch_object($resql);
259
-
260
-						$datefin=$db->jdate($objp->datefin);
261
-						$memberstatic->id=$objp->rowid;
262
-						$memberstatic->ref=$objp->rowid;
263
-						$memberstatic->lastname=$objp->lastname;
264
-						$memberstatic->firstname=$objp->firstname;
265
-						$memberstatic->statut=$objp->statut;
266
-						$memberstatic->datefin=$db->jdate($objp->datefin);
267
-
268
-						$companyname=$objp->company;
269
-
270
-						print '<tr class="oddeven">';
271
-
272
-						// Ref
273
-						print "<td>";
274
-						print $memberstatic->getNomUrl(1);
275
-						print "</td>\n";
276
-
277
-						// Lastname
278
-						print "<td><a href=\"card.php?rowid=$objp->rowid\">";
279
-						print ((! empty($objp->lastname) || ! empty($objp->firstname)) ? dol_trunc($memberstatic->getFullName($langs)) : '');
280
-						print (((! empty($objp->lastname) || ! empty($objp->firstname)) && ! empty($companyname)) ? ' / ' : '');
281
-						print (! empty($companyname) ? dol_trunc($companyname, 32) : '');
282
-						print "</a></td>\n";
283
-
284
-						// Login
285
-						print "<td>".$objp->login."</td>\n";
286
-
287
-						// Type
288
-						$membertypestatic->id=$objp->type_id;
289
-						$membertypestatic->libelle=$objp->type;
290
-						print '<td class="nowrap">';
291
-						print $membertypestatic->getNomUrl(1,32);
292
-						print '</td>';
293
-
294
-						// Moral/Physique
295
-						print "<td>".$memberstatic->getmorphylib($objp->morphy)."</td>\n";
296
-
297
-						// EMail
298
-						print "<td>".dol_print_email($objp->email,0,0,1)."</td>\n";
299
-
300
-						// Statut
301
-						print '<td class="nowrap">';
302
-						print $memberstatic->LibStatut($objp->statut,$objp->subscription,$datefin,2);
303
-						print "</td>";
304
-
305
-						// End of subscription date
306
-						if ($datefin)
307
-						{
308
-							print '<td align="center" class="nowrap">';
309
-							print dol_print_date($datefin,'day');
310
-							if ($memberstatic->hasDelay()) {
311
-								print " ".img_warning($langs->trans("SubscriptionLate"));
312
-							}
313
-							print '</td>';
314
-						}
315
-						else
316
-						{
317
-							print '<td align="left" class="nowrap">';
318
-							if ($objp->subscription == 'yes')
319
-							{
320
-								print $langs->trans("SubscriptionNotReceived");
321
-								if ($objp->statut > 0) print " ".img_warning();
322
-							}
323
-							else
324
-							{
325
-								print '&nbsp;';
326
-							}
327
-							print '</td>';
328
-						}
329
-
330
-						print "</tr>\n";
331
-						$i++;
332
-					}
333
-					print "</table>\n";
334
-				}
335
-			}
336
-		}
337
-	}
338
-	else
339
-	{
340
-		// Contrat non trouve
341
-		print "ErrorRecordNotFound";
342
-	}
174
+        if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
175
+        {
176
+            print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
177
+        }
178
+
179
+        if ($object->client)
180
+        {
181
+            print '<tr><td class="titlefield">';
182
+            print $langs->trans('CustomerCode').'</td><td colspan="3">';
183
+            print $object->code_client;
184
+            if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
185
+            print '</td></tr>';
186
+        }
187
+
188
+        if ($object->fournisseur)
189
+        {
190
+            print '<tr><td class="titlefield">';
191
+            print $langs->trans('SupplierCode').'</td><td colspan="3">';
192
+            print $object->code_fournisseur;
193
+            if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
194
+            print '</td></tr>';
195
+        }
196
+        print '</table>';
197
+
198
+        print '</div>';
199
+
200
+        print '</form>';
201
+        print '<br>';
202
+
203
+        // Contacts lines (modules that overwrite templates must declare this into descriptor)
204
+        $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
205
+        foreach($dirtpls as $reldir)
206
+        {
207
+            $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
208
+            if ($res) break;
209
+        }
210
+
211
+        // additionnal list with adherents of company
212
+        if (! empty($conf->adherent->enabled) && $user->rights->adherent->lire)
213
+        {
214
+            require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
215
+            require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
216
+
217
+            $membertypestatic=new AdherentType($db);
218
+            $memberstatic=new Adherent($db);
219
+
220
+            $langs->load("members");
221
+            $sql = "SELECT d.rowid, d.login, d.lastname, d.firstname, d.societe as company, d.fk_soc,";
222
+            $sql.= " d.datefin,";
223
+            $sql.= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut,";
224
+            $sql.= " t.libelle as type, t.subscription";
225
+            $sql.= " FROM ".MAIN_DB_PREFIX."adherent as d";
226
+            $sql.= ", ".MAIN_DB_PREFIX."adherent_type as t";
227
+            $sql.= " WHERE d.fk_soc = ".$id;
228
+            $sql.= " AND d.fk_adherent_type = t.rowid";
229
+
230
+            dol_syslog("get list sql=".$sql);
231
+            $resql = $db->query($sql);
232
+            if ($resql)
233
+            {
234
+                $num = $db->num_rows($resql);
235
+
236
+                if ($num  > 0 )
237
+                {
238
+                    $titre=$langs->trans("MembersListOfTiers");
239
+                    print '<br>';
240
+
241
+                    print_barre_liste($titre,$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords,'');
242
+
243
+                    print "<table class=\"noborder\" width=\"100%\">";
244
+                    print '<tr class="liste_titre">';
245
+                    print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"d.rowid",$param,"","",$sortfield,$sortorder);
246
+                    print_liste_field_titre( $langs->trans("Name")." / ".$langs->trans("Company"),$_SERVER["PHP_SELF"],"d.lastname",$param,"","",$sortfield,$sortorder);
247
+                    print_liste_field_titre("Login",$_SERVER["PHP_SELF"],"d.login",$param,"","",$sortfield,$sortorder);
248
+                    print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"t.libelle",$param,"","",$sortfield,$sortorder);
249
+                    print_liste_field_titre("Person",$_SERVER["PHP_SELF"],"d.morphy",$param,"","",$sortfield,$sortorder);
250
+                    print_liste_field_titre("EMail",$_SERVER["PHP_SELF"],"d.email",$param,"","",$sortfield,$sortorder);
251
+                    print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"d.statut,d.datefin",$param,"","",$sortfield,$sortorder);
252
+                    print_liste_field_titre("EndSubscription",$_SERVER["PHP_SELF"],"d.datefin",$param,"",'align="center"',$sortfield,$sortorder);
253
+                    print "</tr>\n";
254
+
255
+                    $i=0;
256
+                    while ($i < $num && $i < $conf->liste_limit)
257
+                    {
258
+                        $objp = $db->fetch_object($resql);
259
+
260
+                        $datefin=$db->jdate($objp->datefin);
261
+                        $memberstatic->id=$objp->rowid;
262
+                        $memberstatic->ref=$objp->rowid;
263
+                        $memberstatic->lastname=$objp->lastname;
264
+                        $memberstatic->firstname=$objp->firstname;
265
+                        $memberstatic->statut=$objp->statut;
266
+                        $memberstatic->datefin=$db->jdate($objp->datefin);
267
+
268
+                        $companyname=$objp->company;
269
+
270
+                        print '<tr class="oddeven">';
271
+
272
+                        // Ref
273
+                        print "<td>";
274
+                        print $memberstatic->getNomUrl(1);
275
+                        print "</td>\n";
276
+
277
+                        // Lastname
278
+                        print "<td><a href=\"card.php?rowid=$objp->rowid\">";
279
+                        print ((! empty($objp->lastname) || ! empty($objp->firstname)) ? dol_trunc($memberstatic->getFullName($langs)) : '');
280
+                        print (((! empty($objp->lastname) || ! empty($objp->firstname)) && ! empty($companyname)) ? ' / ' : '');
281
+                        print (! empty($companyname) ? dol_trunc($companyname, 32) : '');
282
+                        print "</a></td>\n";
283
+
284
+                        // Login
285
+                        print "<td>".$objp->login."</td>\n";
286
+
287
+                        // Type
288
+                        $membertypestatic->id=$objp->type_id;
289
+                        $membertypestatic->libelle=$objp->type;
290
+                        print '<td class="nowrap">';
291
+                        print $membertypestatic->getNomUrl(1,32);
292
+                        print '</td>';
293
+
294
+                        // Moral/Physique
295
+                        print "<td>".$memberstatic->getmorphylib($objp->morphy)."</td>\n";
296
+
297
+                        // EMail
298
+                        print "<td>".dol_print_email($objp->email,0,0,1)."</td>\n";
299
+
300
+                        // Statut
301
+                        print '<td class="nowrap">';
302
+                        print $memberstatic->LibStatut($objp->statut,$objp->subscription,$datefin,2);
303
+                        print "</td>";
304
+
305
+                        // End of subscription date
306
+                        if ($datefin)
307
+                        {
308
+                            print '<td align="center" class="nowrap">';
309
+                            print dol_print_date($datefin,'day');
310
+                            if ($memberstatic->hasDelay()) {
311
+                                print " ".img_warning($langs->trans("SubscriptionLate"));
312
+                            }
313
+                            print '</td>';
314
+                        }
315
+                        else
316
+                        {
317
+                            print '<td align="left" class="nowrap">';
318
+                            if ($objp->subscription == 'yes')
319
+                            {
320
+                                print $langs->trans("SubscriptionNotReceived");
321
+                                if ($objp->statut > 0) print " ".img_warning();
322
+                            }
323
+                            else
324
+                            {
325
+                                print '&nbsp;';
326
+                            }
327
+                            print '</td>';
328
+                        }
329
+
330
+                        print "</tr>\n";
331
+                        $i++;
332
+                    }
333
+                    print "</table>\n";
334
+                }
335
+            }
336
+        }
337
+    }
338
+    else
339
+    {
340
+        // Contrat non trouve
341
+        print "ErrorRecordNotFound";
342
+    }
343 343
 }
344 344
 
345 345
 // End of page
Please login to merge, or discard this patch.
Braces   +25 added lines, -20 removed lines patch added patch discarded remove patch
@@ -39,7 +39,9 @@  discard block
 block discarded – undo
39 39
 $action=GETPOST('action','alpha');
40 40
 
41 41
 // Security check
42
-if ($user->societe_id) $socid=$user->societe_id;
42
+if ($user->societe_id) {
43
+    $socid=$user->societe_id;
44
+}
43 45
 $result = restrictedArea($user, 'societe', $id,'');
44 46
 
45 47
 $object = new Societe($db);
@@ -66,15 +68,13 @@  discard block
 block discarded – undo
66 68
 	{
67 69
 		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
68 70
 		exit;
69
-	}
70
-	else
71
+	} else
71 72
 	{
72 73
 		if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
73 74
 		{
74 75
 			$langs->load("errors");
75 76
 			$mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
76
-		}
77
-		else
77
+		} else
78 78
 		{
79 79
 			$mesg = '<div class="error">'.$object->error.'</div>';
80 80
 		}
@@ -87,8 +87,7 @@  discard block
 block discarded – undo
87 87
 	if ($object->fetch($id))
88 88
 	{
89 89
 	    $result=$object->swapContactStatus(GETPOST('ligne'));
90
-	}
91
-	else
90
+	} else
92 91
 	{
93 92
 		dol_print_error($db);
94 93
 	}
@@ -104,8 +103,7 @@  discard block
 block discarded – undo
104 103
 	{
105 104
 		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
106 105
 		exit;
107
-	}
108
-	else {
106
+	} else {
109 107
 		dol_print_error($db);
110 108
 	}
111 109
 }
@@ -171,17 +169,21 @@  discard block
 block discarded – undo
171 169
     	print yn($object->fournisseur);
172 170
     	print '</td></tr>';*/
173 171
 
174
-		if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
172
+		if (! empty($conf->global->SOCIETE_USEPREFIX)) {
173
+		    // Old not used prefix field
175 174
 		{
176 175
 		    print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
177 176
 		}
177
+		}
178 178
 
179 179
 		if ($object->client)
180 180
 		{
181 181
 		    print '<tr><td class="titlefield">';
182 182
 		    print $langs->trans('CustomerCode').'</td><td colspan="3">';
183 183
 		    print $object->code_client;
184
-		    if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
184
+		    if ($object->check_codeclient() <> 0) {
185
+		        print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
186
+		    }
185 187
 		    print '</td></tr>';
186 188
 		}
187 189
 
@@ -190,7 +192,9 @@  discard block
 block discarded – undo
190 192
 		    print '<tr><td class="titlefield">';
191 193
 		    print $langs->trans('SupplierCode').'</td><td colspan="3">';
192 194
 		    print $object->code_fournisseur;
193
-		    if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
195
+		    if ($object->check_codefournisseur() <> 0) {
196
+		        print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
197
+		    }
194 198
 		    print '</td></tr>';
195 199
 		}
196 200
 		print '</table>';
@@ -205,7 +209,9 @@  discard block
 block discarded – undo
205 209
 		foreach($dirtpls as $reldir)
206 210
 		{
207 211
 			$res=@include dol_buildpath($reldir.'/contacts.tpl.php');
208
-			if ($res) break;
212
+			if ($res) {
213
+			    break;
214
+			}
209 215
 		}
210 216
 
211 217
 		// additionnal list with adherents of company
@@ -311,16 +317,16 @@  discard block
 block discarded – undo
311 317
 								print " ".img_warning($langs->trans("SubscriptionLate"));
312 318
 							}
313 319
 							print '</td>';
314
-						}
315
-						else
320
+						} else
316 321
 						{
317 322
 							print '<td align="left" class="nowrap">';
318 323
 							if ($objp->subscription == 'yes')
319 324
 							{
320 325
 								print $langs->trans("SubscriptionNotReceived");
321
-								if ($objp->statut > 0) print " ".img_warning();
322
-							}
323
-							else
326
+								if ($objp->statut > 0) {
327
+								    print " ".img_warning();
328
+								}
329
+							} else
324 330
 							{
325 331
 								print '&nbsp;';
326 332
 							}
@@ -334,8 +340,7 @@  discard block
 block discarded – undo
334 340
 				}
335 341
 			}
336 342
 		}
337
-	}
338
-	else
343
+	} else
339 344
 	{
340 345
 		// Contrat non trouve
341 346
 		print "ErrorRecordNotFound";
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 
30 30
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
31 31
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
32
-require DOL_BASE_PATH . 'main.inc.php';
32
+require DOL_BASE_PATH.'main.inc.php';
33 33
 
34 34
 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
35 35
 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
@@ -38,18 +38,18 @@  discard block
 block discarded – undo
38 38
 
39 39
 $langs->loadLangs(array("orders", "companies"));
40 40
 
41
-$id=GETPOST('id','int')?GETPOST('id','int'):GETPOST('socid','int');
42
-$ref=GETPOST('ref','alpha');
43
-$action=GETPOST('action','alpha');
41
+$id = GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('socid', 'int');
42
+$ref = GETPOST('ref', 'alpha');
43
+$action = GETPOST('action', 'alpha');
44 44
 
45 45
 // Security check
46
-if ($user->societe_id) $socid=$user->societe_id;
47
-$result = restrictedArea($user, 'societe', $id,'');
46
+if ($user->societe_id) $socid = $user->societe_id;
47
+$result = restrictedArea($user, 'societe', $id, '');
48 48
 
49 49
 $object = new Societe($db);
50 50
 
51 51
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
52
-$hookmanager->initHooks(array('contactthirdparty','globalcard'));
52
+$hookmanager->initHooks(array('contactthirdparty', 'globalcard'));
53 53
 
54 54
 
55 55
 /*
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 
63 63
     if ($result > 0 && $id > 0)
64 64
     {
65
-    	$contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int'));
65
+    	$contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
66 66
   		$result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
67 67
     }
68 68
 
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 {
91 91
 	if ($object->fetch($id))
92 92
 	{
93
-	    $result=$object->swapContactStatus(GETPOST('ligne'));
93
+	    $result = $object->swapContactStatus(GETPOST('ligne'));
94 94
 	}
95 95
 	else
96 96
 	{
@@ -126,15 +126,15 @@  discard block
 block discarded – undo
126 126
  * View
127 127
  */
128 128
 
129
-$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
130
-llxHeader('',$langs->trans("ThirdParty"),$help_url);
129
+$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
130
+llxHeader('', $langs->trans("ThirdParty"), $help_url);
131 131
 
132 132
 
133 133
 $form = new Form($db);
134 134
 $formcompany = new FormCompany($db);
135 135
 $formother = new FormOther($db);
136
-$contactstatic=new Contact($db);
137
-$userstatic=new User($db);
136
+$contactstatic = new Contact($db);
137
+$userstatic = new User($db);
138 138
 
139 139
 
140 140
 /* *************************************************************************** */
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 /*                                                                             */
144 144
 /* *************************************************************************** */
145 145
 
146
-if ($id > 0 || ! empty($ref))
146
+if ($id > 0 || !empty($ref))
147 147
 {
148 148
 	if ($object->fetch($id, $ref) > 0)
149 149
 	{
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 
159 159
         $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
160 160
 
161
-        dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
161
+        dol_banner_tab($object, 'socid', $linkback, ($user->societe_id ? 0 : 1), 'rowid', 'nom');
162 162
 
163 163
     	print '<div class="fichecenter">';
164 164
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
     	print yn($object->fournisseur);
176 176
     	print '</td></tr>';*/
177 177
 
178
-		if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
178
+		if (!empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
179 179
 		{
180 180
 		    print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
181 181
 		}
@@ -205,31 +205,31 @@  discard block
 block discarded – undo
205 205
 		print '<br>';
206 206
 
207 207
 		// Contacts lines (modules that overwrite templates must declare this into descriptor)
208
-		$dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
209
-		foreach($dirtpls as $reldir)
208
+		$dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
209
+		foreach ($dirtpls as $reldir)
210 210
 		{
211
-			$res=@include dol_buildpath($reldir.'/contacts.tpl.php');
211
+			$res = @include dol_buildpath($reldir.'/contacts.tpl.php');
212 212
 			if ($res) break;
213 213
 		}
214 214
 
215 215
 		// additionnal list with adherents of company
216
-		if (! empty($conf->adherent->enabled) && $user->rights->adherent->lire)
216
+		if (!empty($conf->adherent->enabled) && $user->rights->adherent->lire)
217 217
 		{
218 218
 			require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
219 219
 			require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
220 220
 
221
-			$membertypestatic=new AdherentType($db);
222
-			$memberstatic=new Adherent($db);
221
+			$membertypestatic = new AdherentType($db);
222
+			$memberstatic = new Adherent($db);
223 223
 
224 224
 			$langs->load("members");
225 225
 			$sql = "SELECT d.rowid, d.login, d.lastname, d.firstname, d.societe as company, d.fk_soc,";
226
-			$sql.= " d.datefin,";
227
-			$sql.= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut,";
228
-			$sql.= " t.libelle as type, t.subscription";
229
-			$sql.= " FROM ".MAIN_DB_PREFIX."adherent as d";
230
-			$sql.= ", ".MAIN_DB_PREFIX."adherent_type as t";
231
-			$sql.= " WHERE d.fk_soc = ".$id;
232
-			$sql.= " AND d.fk_adherent_type = t.rowid";
226
+			$sql .= " d.datefin,";
227
+			$sql .= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut,";
228
+			$sql .= " t.libelle as type, t.subscription";
229
+			$sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
230
+			$sql .= ", ".MAIN_DB_PREFIX."adherent_type as t";
231
+			$sql .= " WHERE d.fk_soc = ".$id;
232
+			$sql .= " AND d.fk_adherent_type = t.rowid";
233 233
 
234 234
 			dol_syslog("get list sql=".$sql);
235 235
 			$resql = $db->query($sql);
@@ -237,39 +237,39 @@  discard block
 block discarded – undo
237 237
 			{
238 238
 				$num = $db->num_rows($resql);
239 239
 
240
-				if ($num  > 0 )
240
+				if ($num > 0)
241 241
 				{
242
-					$titre=$langs->trans("MembersListOfTiers");
242
+					$titre = $langs->trans("MembersListOfTiers");
243 243
 					print '<br>';
244 244
 
245
-					print_barre_liste($titre,$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords,'');
245
+					print_barre_liste($titre, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '');
246 246
 
247 247
 					print "<table class=\"noborder\" width=\"100%\">";
248 248
 					print '<tr class="liste_titre">';
249
-					print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"d.rowid",$param,"","",$sortfield,$sortorder);
250
-					print_liste_field_titre( $langs->trans("Name")." / ".$langs->trans("Company"),$_SERVER["PHP_SELF"],"d.lastname",$param,"","",$sortfield,$sortorder);
251
-					print_liste_field_titre("Login",$_SERVER["PHP_SELF"],"d.login",$param,"","",$sortfield,$sortorder);
252
-					print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"t.libelle",$param,"","",$sortfield,$sortorder);
253
-					print_liste_field_titre("Person",$_SERVER["PHP_SELF"],"d.morphy",$param,"","",$sortfield,$sortorder);
254
-					print_liste_field_titre("EMail",$_SERVER["PHP_SELF"],"d.email",$param,"","",$sortfield,$sortorder);
255
-					print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"d.statut,d.datefin",$param,"","",$sortfield,$sortorder);
256
-					print_liste_field_titre("EndSubscription",$_SERVER["PHP_SELF"],"d.datefin",$param,"",'align="center"',$sortfield,$sortorder);
249
+					print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", $param, "", "", $sortfield, $sortorder);
250
+					print_liste_field_titre($langs->trans("Name")." / ".$langs->trans("Company"), $_SERVER["PHP_SELF"], "d.lastname", $param, "", "", $sortfield, $sortorder);
251
+					print_liste_field_titre("Login", $_SERVER["PHP_SELF"], "d.login", $param, "", "", $sortfield, $sortorder);
252
+					print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "t.libelle", $param, "", "", $sortfield, $sortorder);
253
+					print_liste_field_titre("Person", $_SERVER["PHP_SELF"], "d.morphy", $param, "", "", $sortfield, $sortorder);
254
+					print_liste_field_titre("EMail", $_SERVER["PHP_SELF"], "d.email", $param, "", "", $sortfield, $sortorder);
255
+					print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "d.statut,d.datefin", $param, "", "", $sortfield, $sortorder);
256
+					print_liste_field_titre("EndSubscription", $_SERVER["PHP_SELF"], "d.datefin", $param, "", 'align="center"', $sortfield, $sortorder);
257 257
 					print "</tr>\n";
258 258
 
259
-					$i=0;
259
+					$i = 0;
260 260
 					while ($i < $num && $i < $conf->liste_limit)
261 261
 					{
262 262
 						$objp = $db->fetch_object($resql);
263 263
 
264
-						$datefin=$db->jdate($objp->datefin);
265
-						$memberstatic->id=$objp->rowid;
266
-						$memberstatic->ref=$objp->rowid;
267
-						$memberstatic->lastname=$objp->lastname;
268
-						$memberstatic->firstname=$objp->firstname;
269
-						$memberstatic->statut=$objp->statut;
270
-						$memberstatic->datefin=$db->jdate($objp->datefin);
264
+						$datefin = $db->jdate($objp->datefin);
265
+						$memberstatic->id = $objp->rowid;
266
+						$memberstatic->ref = $objp->rowid;
267
+						$memberstatic->lastname = $objp->lastname;
268
+						$memberstatic->firstname = $objp->firstname;
269
+						$memberstatic->statut = $objp->statut;
270
+						$memberstatic->datefin = $db->jdate($objp->datefin);
271 271
 
272
-						$companyname=$objp->company;
272
+						$companyname = $objp->company;
273 273
 
274 274
 						print '<tr class="oddeven">';
275 275
 
@@ -280,37 +280,37 @@  discard block
 block discarded – undo
280 280
 
281 281
 						// Lastname
282 282
 						print "<td><a href=\"card.php?rowid=$objp->rowid\">";
283
-						print ((! empty($objp->lastname) || ! empty($objp->firstname)) ? dol_trunc($memberstatic->getFullName($langs)) : '');
284
-						print (((! empty($objp->lastname) || ! empty($objp->firstname)) && ! empty($companyname)) ? ' / ' : '');
285
-						print (! empty($companyname) ? dol_trunc($companyname, 32) : '');
283
+						print ((!empty($objp->lastname) || !empty($objp->firstname)) ? dol_trunc($memberstatic->getFullName($langs)) : '');
284
+						print (((!empty($objp->lastname) || !empty($objp->firstname)) && !empty($companyname)) ? ' / ' : '');
285
+						print (!empty($companyname) ? dol_trunc($companyname, 32) : '');
286 286
 						print "</a></td>\n";
287 287
 
288 288
 						// Login
289 289
 						print "<td>".$objp->login."</td>\n";
290 290
 
291 291
 						// Type
292
-						$membertypestatic->id=$objp->type_id;
293
-						$membertypestatic->libelle=$objp->type;
292
+						$membertypestatic->id = $objp->type_id;
293
+						$membertypestatic->libelle = $objp->type;
294 294
 						print '<td class="nowrap">';
295
-						print $membertypestatic->getNomUrl(1,32);
295
+						print $membertypestatic->getNomUrl(1, 32);
296 296
 						print '</td>';
297 297
 
298 298
 						// Moral/Physique
299 299
 						print "<td>".$memberstatic->getmorphylib($objp->morphy)."</td>\n";
300 300
 
301 301
 						// EMail
302
-						print "<td>".dol_print_email($objp->email,0,0,1)."</td>\n";
302
+						print "<td>".dol_print_email($objp->email, 0, 0, 1)."</td>\n";
303 303
 
304 304
 						// Statut
305 305
 						print '<td class="nowrap">';
306
-						print $memberstatic->LibStatut($objp->statut,$objp->subscription,$datefin,2);
306
+						print $memberstatic->LibStatut($objp->statut, $objp->subscription, $datefin, 2);
307 307
 						print "</td>";
308 308
 
309 309
 						// End of subscription date
310 310
 						if ($datefin)
311 311
 						{
312 312
 							print '<td align="center" class="nowrap">';
313
-							print dol_print_date($datefin,'day');
313
+							print dol_print_date($datefin, 'day');
314 314
 							if ($memberstatic->hasDelay()) {
315 315
 								print " ".img_warning($langs->trans("SubscriptionLate"));
316 316
 							}
Please login to merge, or discard this patch.
dolibarr/htdocs/societe/project.php 3 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -62,23 +62,23 @@  discard block
 block discarded – undo
62 62
 
63 63
 if ($socid)
64 64
 {
65
-	require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
66
-	require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
65
+    require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
66
+    require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
67 67
 
68
-	$langs->load("companies");
68
+    $langs->load("companies");
69 69
 
70 70
 
71
-	$object = new Societe($db);
72
-	$result = $object->fetch($socid);
71
+    $object = new Societe($db);
72
+    $result = $object->fetch($socid);
73 73
 
74
-	$title=$langs->trans("Projects");
75
-	if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
76
-	llxHeader('',$title);
74
+    $title=$langs->trans("Projects");
75
+    if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
76
+    llxHeader('',$title);
77 77
 
78
-	if (! empty($conf->notification->enabled)) $langs->load("mails");
79
-	$head = societe_prepare_head($object);
78
+    if (! empty($conf->notification->enabled)) $langs->load("mails");
79
+    $head = societe_prepare_head($object);
80 80
 
81
-	dol_fiche_head($head, 'project', $langs->trans("ThirdParty"), -1, 'company');
81
+    dol_fiche_head($head, 'project', $langs->trans("ThirdParty"), -1, 'company');
82 82
 
83 83
     $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
84 84
 
@@ -87,36 +87,36 @@  discard block
 block discarded – undo
87 87
     print '<div class="fichecenter">';
88 88
 
89 89
     print '<div class="underbanner clearboth"></div>';
90
-	print '<table class="border centpercent">';
90
+    print '<table class="border centpercent">';
91 91
 
92 92
     if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
93 93
     {
94 94
         print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
95 95
     }
96 96
 
97
-	if ($object->client)
98
-	{
99
-		print '<tr><td class="titlefield">';
100
-		print $langs->trans('CustomerCode').'</td><td colspan="3">';
101
-		print $object->code_client;
102
-		if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
103
-		print '</td></tr>';
104
-	}
97
+    if ($object->client)
98
+    {
99
+        print '<tr><td class="titlefield">';
100
+        print $langs->trans('CustomerCode').'</td><td colspan="3">';
101
+        print $object->code_client;
102
+        if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
103
+        print '</td></tr>';
104
+    }
105 105
 
106
-	if ($object->fournisseur)
107
-	{
108
-		print '<tr><td class="titlefield">';
109
-		print $langs->trans('SupplierCode').'</td><td colspan="3">';
110
-		print $object->code_fournisseur;
111
-		if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
112
-		print '</td></tr>';
113
-	}
106
+    if ($object->fournisseur)
107
+    {
108
+        print '<tr><td class="titlefield">';
109
+        print $langs->trans('SupplierCode').'</td><td colspan="3">';
110
+        print $object->code_fournisseur;
111
+        if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
112
+        print '</td></tr>';
113
+    }
114 114
 
115
-	print '</table>';
115
+    print '</table>';
116 116
 
117
-	print '</div>';
117
+    print '</div>';
118 118
 
119
-	dol_fiche_end();
119
+    dol_fiche_end();
120 120
 
121 121
 
122 122
     /*
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
     {
130 130
     	if (! empty($conf->projet->enabled) && ! empty($user->rights->projet->creer))
131 131
     	{*/
132
-        	$addbutton = '<a href="'.DOL_URL_ROOT.'/projet/card.php?action=create&socid='.$object->id.'&amp;backtopage='.urlencode($backtopage).'">'.$langs->trans("AddProject").'</a>';
132
+            $addbutton = '<a href="'.DOL_URL_ROOT.'/projet/card.php?action=create&socid='.$object->id.'&amp;backtopage='.urlencode($backtopage).'">'.$langs->trans("AddProject").'</a>';
133 133
     /*	}
134 134
     	else
135 135
     	{
@@ -142,8 +142,8 @@  discard block
 block discarded – undo
142 142
     print '<br>';
143 143
 
144 144
 
145
-	// Projects list
146
-	$result=show_projects($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id, 1, $addbutton);
145
+    // Projects list
146
+    $result=show_projects($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id, 1, $addbutton);
147 147
 }
148 148
 
149 149
 // End of page
Please login to merge, or discard this patch.
Braces   +21 added lines, -7 removed lines patch added patch discarded remove patch
@@ -35,7 +35,9 @@  discard block
 block discarded – undo
35 35
 
36 36
 // Security check
37 37
 $socid = GETPOST('socid','int');
38
-if ($user->societe_id) $socid=$user->societe_id;
38
+if ($user->societe_id) {
39
+    $socid=$user->societe_id;
40
+}
39 41
 $result = restrictedArea($user, 'societe', $socid, '&societe');
40 42
 
41 43
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
@@ -48,7 +50,9 @@  discard block
 block discarded – undo
48 50
 
49 51
 $parameters=array('id'=>$socid);
50 52
 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
51
-if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
53
+if ($reshook < 0) {
54
+    setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
55
+}
52 56
 
53 57
 
54 58
 
@@ -72,10 +76,14 @@  discard block
 block discarded – undo
72 76
 	$result = $object->fetch($socid);
73 77
 
74 78
 	$title=$langs->trans("Projects");
75
-	if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
79
+	if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) {
80
+	    $title=$object->name." - ".$title;
81
+	}
76 82
 	llxHeader('',$title);
77 83
 
78
-	if (! empty($conf->notification->enabled)) $langs->load("mails");
84
+	if (! empty($conf->notification->enabled)) {
85
+	    $langs->load("mails");
86
+	}
79 87
 	$head = societe_prepare_head($object);
80 88
 
81 89
 	dol_fiche_head($head, 'project', $langs->trans("ThirdParty"), -1, 'company');
@@ -89,17 +97,21 @@  discard block
 block discarded – undo
89 97
     print '<div class="underbanner clearboth"></div>';
90 98
 	print '<table class="border centpercent">';
91 99
 
92
-    if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
100
+    if (! empty($conf->global->SOCIETE_USEPREFIX)) {
101
+        // Old not used prefix field
93 102
     {
94 103
         print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
95 104
     }
105
+    }
96 106
 
97 107
 	if ($object->client)
98 108
 	{
99 109
 		print '<tr><td class="titlefield">';
100 110
 		print $langs->trans('CustomerCode').'</td><td colspan="3">';
101 111
 		print $object->code_client;
102
-		if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
112
+		if ($object->check_codeclient() <> 0) {
113
+		    print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
114
+		}
103 115
 		print '</td></tr>';
104 116
 	}
105 117
 
@@ -108,7 +120,9 @@  discard block
 block discarded – undo
108 120
 		print '<tr><td class="titlefield">';
109 121
 		print $langs->trans('SupplierCode').'</td><td colspan="3">';
110 122
 		print $object->code_fournisseur;
111
-		if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
123
+		if ($object->check_codefournisseur() <> 0) {
124
+		    print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
125
+		}
112 126
 		print '</td></tr>';
113 127
 	}
114 128
 
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 
31 31
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
32 32
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
33
-require DOL_BASE_PATH . 'main.inc.php';
33
+require DOL_BASE_PATH.'main.inc.php';
34 34
 
35 35
 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
36 36
 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
@@ -38,8 +38,8 @@  discard block
 block discarded – undo
38 38
 $langs->loadLangs(array("companies", "projects"));
39 39
 
40 40
 // Security check
41
-$socid = GETPOST('socid','int');
42
-if ($user->societe_id) $socid=$user->societe_id;
41
+$socid = GETPOST('socid', 'int');
42
+if ($user->societe_id) $socid = $user->societe_id;
43 43
 $result = restrictedArea($user, 'societe', $socid, '&societe');
44 44
 
45 45
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
  *	Actions
51 51
  */
52 52
 
53
-$parameters=array('id'=>$socid);
54
-$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
53
+$parameters = array('id'=>$socid);
54
+$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
55 55
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
56 56
 
57 57
 
@@ -75,25 +75,25 @@  discard block
 block discarded – undo
75 75
 	$object = new Societe($db);
76 76
 	$result = $object->fetch($socid);
77 77
 
78
-	$title=$langs->trans("Projects");
79
-	if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
80
-	llxHeader('',$title);
78
+	$title = $langs->trans("Projects");
79
+	if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->name." - ".$title;
80
+	llxHeader('', $title);
81 81
 
82
-	if (! empty($conf->notification->enabled)) $langs->load("mails");
82
+	if (!empty($conf->notification->enabled)) $langs->load("mails");
83 83
 	$head = societe_prepare_head($object);
84 84
 
85 85
 	dol_fiche_head($head, 'project', $langs->trans("ThirdParty"), -1, 'company');
86 86
 
87 87
     $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
88 88
 
89
-    dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
89
+    dol_banner_tab($object, 'socid', $linkback, ($user->societe_id ? 0 : 1), 'rowid', 'nom');
90 90
 
91 91
     print '<div class="fichecenter">';
92 92
 
93 93
     print '<div class="underbanner clearboth"></div>';
94 94
 	print '<table class="border centpercent">';
95 95
 
96
-    if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
96
+    if (!empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
97 97
     {
98 98
         print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
99 99
     }
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 
148 148
 
149 149
 	// Projects list
150
-	$result=show_projects($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id, 1, $addbutton);
150
+	$result = show_projects($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id, 1, $addbutton);
151 151
 }
152 152
 
153 153
 // End of page
Please login to merge, or discard this patch.
dolibarr/htdocs/societe/notify/card.php 3 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -78,12 +78,12 @@  discard block
 block discarded – undo
78 78
     {
79 79
         if (empty($contactid))
80 80
         {
81
-    	    setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Contact")), null, 'errors');
81
+            setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Contact")), null, 'errors');
82 82
             $error++;
83 83
         }
84 84
         if ($actionid <= 0)
85 85
         {
86
-    	    setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Action")), null, 'errors');
86
+            setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Action")), null, 'errors');
87 87
             $error++;
88 88
         }
89 89
 
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
     print '<br>'.$langs->trans("NotificationsDescUser");
213 213
     print '<br>'.$langs->trans("NotificationsDescContact");
214 214
     print '<br>'.$langs->trans("NotificationsDescGlobal");
215
-	print '</div>';
215
+    print '</div>';
216 216
 
217 217
     print '<br><br>'."\n";
218 218
 
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
     print_liste_field_titre("Action",$_SERVER["PHP_SELF"],"",'',$param,'"width="35%"',$sortfield,$sortorder);
234 234
     print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"n.type",'',$param,'"width="10%"',$sortfield,$sortorder);
235 235
     print_liste_field_titre('');
236
-	print "</tr>\n";
236
+    print "</tr>\n";
237 237
 
238 238
     $var=false;
239 239
     $listofemails=$object->thirdparty_and_contact_email_array();
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 
248 248
         foreach($listofmanagedeventfornotification as $managedeventfornotification)
249 249
         {
250
- 			$label=($langs->trans("Notify_".$managedeventfornotification['code'])!="Notify_".$managedeventfornotification['code']?$langs->trans("Notify_".$managedeventfornotification['code']):$managedeventfornotification['label']);
250
+                $label=($langs->trans("Notify_".$managedeventfornotification['code'])!="Notify_".$managedeventfornotification['code']?$langs->trans("Notify_".$managedeventfornotification['code']):$managedeventfornotification['label']);
251 251
             $actions[$managedeventfornotification['rowid']]=$label;
252 252
         }
253 253
         print '<tr class="oddeven"><td class="maxwidthonsmartphone">';
@@ -310,8 +310,8 @@  discard block
 block discarded – undo
310 310
     print_liste_field_titre('','','');
311 311
     print '</tr>';
312 312
 
313
-	$langs->load("errors");
314
-	$langs->load("other");
313
+    $langs->load("errors");
314
+    $langs->load("other");
315 315
 
316 316
     if ($num)
317 317
     {
@@ -431,8 +431,8 @@  discard block
 block discarded – undo
431 431
         $nbtotalofrecords = $db->num_rows($result);
432 432
         if (($page * $limit) > $nbtotalofrecords)	// if total resultset is smaller then paging size (filtering), goto and load page 0
433 433
         {
434
-        	$page = 0;
435
-        	$offset = 0;
434
+            $page = 0;
435
+            $offset = 0;
436 436
         }
437 437
     }
438 438
 
@@ -487,15 +487,15 @@  discard block
 block discarded – undo
487 487
             print '<tr class="oddeven"><td>';
488 488
             if ($obj->id > 0)
489 489
             {
490
-	            $contactstatic->id=$obj->id;
491
-	            $contactstatic->lastname=$obj->lastname;
492
-	            $contactstatic->firstname=$obj->firstname;
493
-	            print $contactstatic->getNomUrl(1);
494
-	            print $obj->email?' &lt;'.$obj->email.'&gt;':$langs->trans("NoMail");
490
+                $contactstatic->id=$obj->id;
491
+                $contactstatic->lastname=$obj->lastname;
492
+                $contactstatic->firstname=$obj->firstname;
493
+                print $contactstatic->getNomUrl(1);
494
+                print $obj->email?' &lt;'.$obj->email.'&gt;':$langs->trans("NoMail");
495 495
             }
496 496
             else
497
-			{
498
-				print $obj->email;
497
+            {
498
+                print $obj->email;
499 499
             }
500 500
             print '</td>';
501 501
             print '<td>';
Please login to merge, or discard this patch.
Braces   +57 added lines, -31 removed lines patch added patch discarded remove patch
@@ -38,15 +38,21 @@  discard block
 block discarded – undo
38 38
 $actionid=GETPOST('actionid');
39 39
 
40 40
 // Security check
41
-if ($user->societe_id) $socid=$user->societe_id;
41
+if ($user->societe_id) {
42
+    $socid=$user->societe_id;
43
+}
42 44
 $result = restrictedArea($user, 'societe','','');
43 45
 
44 46
 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
45 47
 $sortfield=GETPOST("sortfield",'alpha');
46 48
 $sortorder=GETPOST("sortorder",'alpha');
47 49
 $page=GETPOST("page",'int');
48
-if (! $sortorder) $sortorder="DESC";
49
-if (! $sortfield) $sortfield="n.daten";
50
+if (! $sortorder) {
51
+    $sortorder="DESC";
52
+}
53
+if (! $sortfield) {
54
+    $sortfield="n.daten";
55
+}
50 56
 if (empty($page) || $page == -1) { $page = 0; }
51 57
 $offset = $limit * $page;
52 58
 $pageprev = $page - 1;
@@ -67,7 +73,9 @@  discard block
 block discarded – undo
67 73
 
68 74
 $parameters=array('id'=>$socid);
69 75
 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
70
-if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
76
+if ($reshook < 0) {
77
+    setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
78
+}
71 79
 
72 80
 if (empty($reshook))
73 81
 {
@@ -103,8 +111,7 @@  discard block
 block discarded – undo
103 111
                     $error++;
104 112
                     dol_print_error($db);
105 113
                 }
106
-            }
107
-            else
114
+            } else
108 115
             {
109 116
                 dol_print_error($db);
110 117
             }
@@ -112,8 +119,7 @@  discard block
 block discarded – undo
112 119
             if (! $error)
113 120
             {
114 121
                 $db->commit();
115
-            }
116
-            else
122
+            } else
117 123
             {
118 124
                 $db->rollback();
119 125
             }
@@ -140,7 +146,9 @@  discard block
 block discarded – undo
140 146
 $result=$object->fetch($socid);
141 147
 
142 148
 $title=$langs->trans("ThirdParty").' - '.$langs->trans("Notification");
143
-if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name.' - '.$langs->trans("Notification");
149
+if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) {
150
+    $title=$object->name.' - '.$langs->trans("Notification");
151
+}
144 152
 $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
145 153
 llxHeader('',$title,$help_url);
146 154
 
@@ -163,17 +171,21 @@  discard block
 block discarded – undo
163 171
     print '<table class="border centpercent">';
164 172
 
165 173
     // Prefix
166
-    if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
174
+    if (! empty($conf->global->SOCIETE_USEPREFIX)) {
175
+        // Old not used prefix field
167 176
     {
168 177
         print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
169 178
     }
179
+    }
170 180
 
171 181
     if ($object->client)
172 182
     {
173 183
         print '<tr><td class="titlefield">';
174 184
         print $langs->trans('CustomerCode').'</td><td colspan="3">';
175 185
         print $object->code_client;
176
-        if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
186
+        if ($object->check_codeclient() <> 0) {
187
+            print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
188
+        }
177 189
         print '</td></tr>';
178 190
     }
179 191
 
@@ -182,7 +194,9 @@  discard block
 block discarded – undo
182 194
         print '<tr><td class="titlefield">';
183 195
         print $langs->trans('SupplierCode').'</td><td colspan="3">';
184 196
         print $object->code_fournisseur;
185
-        if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
197
+        if ($object->check_codefournisseur() <> 0) {
198
+            print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
199
+        }
186 200
         print '</td></tr>';
187 201
     }
188 202
 
@@ -262,8 +276,7 @@  discard block
 block discarded – undo
262 276
         print '</td>';
263 277
         print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
264 278
         print '</tr>';
265
-    }
266
-    else
279
+    } else
267 280
     {
268 281
         print '<tr class="oddeven"><td colspan="4" class="opacitymedium">';
269 282
         print $langs->trans("YouMustCreateContactFirst");
@@ -292,8 +305,7 @@  discard block
 block discarded – undo
292 305
     if ($resql)
293 306
     {
294 307
         $num = $db->num_rows($resql);
295
-    }
296
-    else
308
+    } else
297 309
     {
298 310
         dol_print_error($db);
299 311
     }
@@ -332,8 +344,7 @@  discard block
 block discarded – undo
332 344
                 if (isValidEmail($obj->email))
333 345
                 {
334 346
                     print ' &lt;'.$obj->email.'&gt;';
335
-                }
336
-                else
347
+                } else
337 348
                 {
338 349
                     $langs->load("errors");
339 350
                     print ' &nbsp; '.img_warning().' '.$langs->trans("ErrorBadEMail",$obj->email);
@@ -345,8 +356,12 @@  discard block
 block discarded – undo
345 356
             print $label;
346 357
             print '</td>';
347 358
             print '<td>';
348
-            if ($obj->type == 'email') print $langs->trans("Email");
349
-            if ($obj->type == 'sms') print $langs->trans("SMS");
359
+            if ($obj->type == 'email') {
360
+                print $langs->trans("Email");
361
+            }
362
+            if ($obj->type == 'sms') {
363
+                print $langs->trans("SMS");
364
+            }
350 365
             print '</td>';
351 366
             print '<td align="right"><a href="card.php?socid='.$socid.'&action=delete&actid='.$obj->rowid.'">'.img_delete().'</a></td>';
352 367
             print '</tr>';
@@ -429,9 +444,11 @@  discard block
 block discarded – undo
429 444
     {
430 445
         $result = $db->query($sql);
431 446
         $nbtotalofrecords = $db->num_rows($result);
432
-        if (($page * $limit) > $nbtotalofrecords)	// if total resultset is smaller then paging size (filtering), goto and load page 0
447
+        if (($page * $limit) > $nbtotalofrecords) {
448
+            // if total resultset is smaller then paging size (filtering), goto and load page 0
433 449
         {
434 450
         	$page = 0;
451
+        }
435 452
         	$offset = 0;
436 453
         }
437 454
     }
@@ -442,18 +459,23 @@  discard block
 block discarded – undo
442 459
     if ($resql)
443 460
     {
444 461
         $num = $db->num_rows($resql);
445
-    }
446
-    else
462
+    } else
447 463
     {
448 464
         dol_print_error($db);
449 465
     }
450 466
 
451 467
     $param='&socid='.$object->id;
452
-    if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
453
-    if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
468
+    if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
469
+        $param.='&contextpage='.$contextpage;
470
+    }
471
+    if ($limit > 0 && $limit != $conf->liste_limit) {
472
+        $param.='&limit='.$limit;
473
+    }
454 474
 
455 475
     print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
456
-    if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
476
+    if ($optioncss != '') {
477
+        print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
478
+    }
457 479
     print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
458 480
     print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
459 481
     print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
@@ -492,8 +514,7 @@  discard block
 block discarded – undo
492 514
 	            $contactstatic->firstname=$obj->firstname;
493 515
 	            print $contactstatic->getNomUrl(1);
494 516
 	            print $obj->email?' &lt;'.$obj->email.'&gt;':$langs->trans("NoMail");
495
-            }
496
-            else
517
+            } else
497 518
 			{
498 519
 				print $obj->email;
499 520
             }
@@ -503,8 +524,12 @@  discard block
 block discarded – undo
503 524
             print $label;
504 525
             print '</td>';
505 526
             print '<td>';
506
-            if ($obj->type == 'email') print $langs->trans("Email");
507
-            if ($obj->type == 'sms') print $langs->trans("Sms");
527
+            if ($obj->type == 'email') {
528
+                print $langs->trans("Email");
529
+            }
530
+            if ($obj->type == 'sms') {
531
+                print $langs->trans("Sms");
532
+            }
508 533
             print '</td>';
509 534
             // TODO Add link to object here for other types
510 535
             /*print '<td>';
@@ -526,8 +551,9 @@  discard block
 block discarded – undo
526 551
     print '</table>';
527 552
 
528 553
     print '</form>';
554
+} else {
555
+    dol_print_error('','RecordNotFound');
529 556
 }
530
-else dol_print_error('','RecordNotFound');
531 557
 
532 558
 // End of page
533 559
 llxFooter();
Please login to merge, or discard this patch.
Spacing   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
29 29
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
30
-require DOL_BASE_PATH . 'main.inc.php';
30
+require DOL_BASE_PATH.'main.inc.php';
31 31
 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
32 32
 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
33 33
 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
@@ -35,32 +35,32 @@  discard block
 block discarded – undo
35 35
 
36 36
 $langs->loadLangs(array("companies", "mails", "admin", "other"));
37 37
 
38
-$socid = GETPOST("socid",'int');
39
-$action = GETPOST('action','aZ09');
40
-$contactid=GETPOST('contactid');    // May be an int or 'thirdparty'
41
-$actionid=GETPOST('actionid');
38
+$socid = GETPOST("socid", 'int');
39
+$action = GETPOST('action', 'aZ09');
40
+$contactid = GETPOST('contactid'); // May be an int or 'thirdparty'
41
+$actionid = GETPOST('actionid');
42 42
 
43 43
 // Security check
44
-if ($user->societe_id) $socid=$user->societe_id;
45
-$result = restrictedArea($user, 'societe','','');
46
-
47
-$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
48
-$sortfield=GETPOST("sortfield",'alpha');
49
-$sortorder=GETPOST("sortorder",'alpha');
50
-$page=GETPOST("page",'int');
51
-if (! $sortorder) $sortorder="DESC";
52
-if (! $sortfield) $sortfield="n.daten";
44
+if ($user->societe_id) $socid = $user->societe_id;
45
+$result = restrictedArea($user, 'societe', '', '');
46
+
47
+$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
48
+$sortfield = GETPOST("sortfield", 'alpha');
49
+$sortorder = GETPOST("sortorder", 'alpha');
50
+$page = GETPOST("page", 'int');
51
+if (!$sortorder) $sortorder = "DESC";
52
+if (!$sortfield) $sortfield = "n.daten";
53 53
 if (empty($page) || $page == -1) { $page = 0; }
54 54
 $offset = $limit * $page;
55 55
 $pageprev = $page - 1;
56 56
 $pagenext = $page + 1;
57 57
 
58
-$now=dol_now();
58
+$now = dol_now();
59 59
 
60 60
 $object = new Societe($db);
61 61
 
62 62
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
63
-$hookmanager->initHooks(array('thirdpartynotification','globalcard'));
63
+$hookmanager->initHooks(array('thirdpartynotification', 'globalcard'));
64 64
 
65 65
 
66 66
 
@@ -68,29 +68,29 @@  discard block
 block discarded – undo
68 68
  * Actions
69 69
  */
70 70
 
71
-$parameters=array('id'=>$socid);
72
-$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
71
+$parameters = array('id'=>$socid);
72
+$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
73 73
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
74 74
 
75 75
 if (empty($reshook))
76 76
 {
77
-    $error=0;
77
+    $error = 0;
78 78
 
79 79
     // Add a notification
80 80
     if ($action == 'add')
81 81
     {
82 82
         if (empty($contactid))
83 83
         {
84
-    	    setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Contact")), null, 'errors');
84
+    	    setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Contact")), null, 'errors');
85 85
             $error++;
86 86
         }
87 87
         if ($actionid <= 0)
88 88
         {
89
-    	    setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Action")), null, 'errors');
89
+    	    setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Action")), null, 'errors');
90 90
             $error++;
91 91
         }
92 92
 
93
-        if (! $error)
93
+        if (!$error)
94 94
         {
95 95
             $db->begin();
96 96
 
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
                 $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify_def (datec,fk_soc, fk_contact, fk_action)";
102 102
                 $sql .= " VALUES ('".$db->idate($now)."',".$socid.",".$contactid.",".$actionid.")";
103 103
 
104
-                if (! $db->query($sql))
104
+                if (!$db->query($sql))
105 105
                 {
106 106
                     $error++;
107 107
                     dol_print_error($db);
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
                 dol_print_error($db);
113 113
             }
114 114
 
115
-            if (! $error)
115
+            if (!$error)
116 116
             {
117 117
                 $db->commit();
118 118
             }
@@ -140,12 +140,12 @@  discard block
 block discarded – undo
140 140
 $form = new Form($db);
141 141
 
142 142
 $object = new Societe($db);
143
-$result=$object->fetch($socid);
143
+$result = $object->fetch($socid);
144 144
 
145
-$title=$langs->trans("ThirdParty").' - '.$langs->trans("Notification");
146
-if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name.' - '.$langs->trans("Notification");
147
-$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
148
-llxHeader('',$title,$help_url);
145
+$title = $langs->trans("ThirdParty").' - '.$langs->trans("Notification");
146
+if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->name.' - '.$langs->trans("Notification");
147
+$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
148
+llxHeader('', $title, $help_url);
149 149
 
150 150
 
151 151
 if ($result > 0)
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 
159 159
     $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
160 160
 
161
-    dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
161
+    dol_banner_tab($object, 'socid', $linkback, ($user->societe_id ? 0 : 1), 'rowid', 'nom');
162 162
 
163 163
     print '<div class="fichecenter">';
164 164
 
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
     print '<table class="border centpercent">';
167 167
 
168 168
     // Prefix
169
-    if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
169
+    if (!empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
170 170
     {
171 171
         print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
172 172
     }
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
         print '</td></tr>';
181 181
     }
182 182
 
183
-    if (! empty($conf->fournisseur->enabled) && $object->fournisseur && ! empty($user->rights->fournisseur->lire))
183
+    if (!empty($conf->fournisseur->enabled) && $object->fournisseur && !empty($user->rights->fournisseur->lire))
184 184
     {
185 185
         print '<tr><td class="titlefield">';
186 186
         print $langs->trans('SupplierCode').'</td><td colspan="3">';
@@ -221,37 +221,37 @@  discard block
 block discarded – undo
221 221
 
222 222
 
223 223
     // Add notification form
224
-    print load_fiche_titre($langs->trans("AddNewNotification"),'','');
224
+    print load_fiche_titre($langs->trans("AddNewNotification"), '', '');
225 225
 
226 226
     print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$socid.'" method="post">';
227 227
     print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
228 228
     print '<input type="hidden" name="action" value="add">';
229 229
 
230
-    $param="&socid=".$socid;
230
+    $param = "&socid=".$socid;
231 231
 
232 232
     // Line with titles
233 233
     print '<table width="100%" class="noborder">';
234 234
     print '<tr class="liste_titre">';
235
-    print_liste_field_titre("Target",$_SERVER["PHP_SELF"],"c.lastname,c.firstname",'',$param,'"width="45%"',$sortfield,$sortorder);
236
-    print_liste_field_titre("Action",$_SERVER["PHP_SELF"],"",'',$param,'"width="35%"',$sortfield,$sortorder);
237
-    print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"n.type",'',$param,'"width="10%"',$sortfield,$sortorder);
235
+    print_liste_field_titre("Target", $_SERVER["PHP_SELF"], "c.lastname,c.firstname", '', $param, '"width="45%"', $sortfield, $sortorder);
236
+    print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "", '', $param, '"width="35%"', $sortfield, $sortorder);
237
+    print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "n.type", '', $param, '"width="10%"', $sortfield, $sortorder);
238 238
     print_liste_field_titre('');
239 239
 	print "</tr>\n";
240 240
 
241
-    $var=false;
242
-    $listofemails=$object->thirdparty_and_contact_email_array();
241
+    $var = false;
242
+    $listofemails = $object->thirdparty_and_contact_email_array();
243 243
     if (count($listofemails) > 0)
244 244
     {
245
-        $actions=array();
245
+        $actions = array();
246 246
 
247 247
         // Load array of available notifications
248
-        $notificationtrigger=new InterfaceNotification($db);
249
-        $listofmanagedeventfornotification=$notificationtrigger->getListOfManagedEvents();
248
+        $notificationtrigger = new InterfaceNotification($db);
249
+        $listofmanagedeventfornotification = $notificationtrigger->getListOfManagedEvents();
250 250
 
251
-        foreach($listofmanagedeventfornotification as $managedeventfornotification)
251
+        foreach ($listofmanagedeventfornotification as $managedeventfornotification)
252 252
         {
253
- 			$label=($langs->trans("Notify_".$managedeventfornotification['code'])!="Notify_".$managedeventfornotification['code']?$langs->trans("Notify_".$managedeventfornotification['code']):$managedeventfornotification['label']);
254
-            $actions[$managedeventfornotification['rowid']]=$label;
253
+ 			$label = ($langs->trans("Notify_".$managedeventfornotification['code']) != "Notify_".$managedeventfornotification['code'] ? $langs->trans("Notify_".$managedeventfornotification['code']) : $managedeventfornotification['label']);
254
+            $actions[$managedeventfornotification['rowid']] = $label;
255 255
         }
256 256
         print '<tr class="oddeven"><td class="maxwidthonsmartphone">';
257 257
         print $form->selectarray("contactid", $listofemails, '', 0, 0, 0, '', 0, 0, 0, '', 'maxwidthonsmartphone');
@@ -260,8 +260,8 @@  discard block
 block discarded – undo
260 260
         print $form->selectarray("actionid", $actions, '', 1, 0, 0, '', 0, 0, 0, '', 'maxwidthonsmartphone');
261 261
         print '</td>';
262 262
         print '<td>';
263
-        $type=array('email'=>$langs->trans("EMail"));
264
-        print $form->selectarray("typeid",$type);
263
+        $type = array('email'=>$langs->trans("EMail"));
264
+        print $form->selectarray("typeid", $type);
265 265
         print '</td>';
266 266
         print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
267 267
         print '</tr>';
@@ -282,16 +282,16 @@  discard block
 block discarded – undo
282 282
 
283 283
     // List of notifications enabled for contacts
284 284
     $sql = "SELECT n.rowid, n.type,";
285
-    $sql.= " a.code, a.label,";
286
-    $sql.= " c.rowid as contactid, c.lastname, c.firstname, c.email";
287
-    $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,";
288
-    $sql.= " ".MAIN_DB_PREFIX."notify_def as n,";
289
-    $sql.= " ".MAIN_DB_PREFIX."socpeople c";
290
-    $sql.= " WHERE a.rowid = n.fk_action";
291
-    $sql.= " AND c.rowid = n.fk_contact";
292
-    $sql.= " AND c.fk_soc = ".$object->id;
293
-
294
-    $resql=$db->query($sql);
285
+    $sql .= " a.code, a.label,";
286
+    $sql .= " c.rowid as contactid, c.lastname, c.firstname, c.email";
287
+    $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,";
288
+    $sql .= " ".MAIN_DB_PREFIX."notify_def as n,";
289
+    $sql .= " ".MAIN_DB_PREFIX."socpeople c";
290
+    $sql .= " WHERE a.rowid = n.fk_action";
291
+    $sql .= " AND c.rowid = n.fk_contact";
292
+    $sql .= " AND c.fk_soc = ".$object->id;
293
+
294
+    $resql = $db->query($sql);
295 295
     if ($resql)
296 296
     {
297 297
         $num = $db->num_rows($resql);
@@ -302,15 +302,15 @@  discard block
 block discarded – undo
302 302
     }
303 303
 
304 304
     // List of active notifications
305
-    print load_fiche_titre($langs->trans("ListOfActiveNotifications").' ('.$num.')','','');
305
+    print load_fiche_titre($langs->trans("ListOfActiveNotifications").' ('.$num.')', '', '');
306 306
 
307 307
     // Line with titles
308 308
     print '<table width="100%" class="noborder">';
309 309
     print '<tr class="liste_titre">';
310
-    print_liste_field_titre("Target",$_SERVER["PHP_SELF"],"c.lastname,c.firstname",'',$param,'"width="45%"',$sortfield,$sortorder);
311
-    print_liste_field_titre("Action",$_SERVER["PHP_SELF"],"",'',$param,'"width="35%"',$sortfield,$sortorder);
312
-    print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"n.type",'',$param,'"width="10%"',$sortfield,$sortorder);
313
-    print_liste_field_titre('','','');
310
+    print_liste_field_titre("Target", $_SERVER["PHP_SELF"], "c.lastname,c.firstname", '', $param, '"width="45%"', $sortfield, $sortorder);
311
+    print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "", '', $param, '"width="35%"', $sortfield, $sortorder);
312
+    print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "n.type", '', $param, '"width="10%"', $sortfield, $sortorder);
313
+    print_liste_field_titre('', '', '');
314 314
     print '</tr>';
315 315
 
316 316
 	$langs->load("errors");
@@ -320,15 +320,15 @@  discard block
 block discarded – undo
320 320
     {
321 321
         $i = 0;
322 322
 
323
-        $contactstatic=new Contact($db);
323
+        $contactstatic = new Contact($db);
324 324
 
325 325
         while ($i < $num)
326 326
         {
327 327
             $obj = $db->fetch_object($resql);
328 328
 
329
-            $contactstatic->id=$obj->contactid;
330
-            $contactstatic->lastname=$obj->lastname;
331
-            $contactstatic->firstname=$obj->firstname;
329
+            $contactstatic->id = $obj->contactid;
330
+            $contactstatic->lastname = $obj->lastname;
331
+            $contactstatic->firstname = $obj->firstname;
332 332
             print '<tr class="oddeven"><td>'.$contactstatic->getNomUrl(1);
333 333
             if ($obj->type == 'email')
334 334
             {
@@ -339,12 +339,12 @@  discard block
 block discarded – undo
339 339
                 else
340 340
                 {
341 341
                     $langs->load("errors");
342
-                    print ' &nbsp; '.img_warning().' '.$langs->trans("ErrorBadEMail",$obj->email);
342
+                    print ' &nbsp; '.img_warning().' '.$langs->trans("ErrorBadEMail", $obj->email);
343 343
                 }
344 344
             }
345 345
             print '</td>';
346 346
             print '<td>';
347
-            $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
347
+            $label = ($langs->trans("Notify_".$obj->code) != "Notify_".$obj->code ? $langs->trans("Notify_".$obj->code) : $obj->label);
348 348
             print $label;
349 349
             print '</td>';
350 350
             print '<td>';
@@ -417,14 +417,14 @@  discard block
 block discarded – undo
417 417
 
418 418
     // List
419 419
     $sql = "SELECT n.rowid, n.daten, n.email, n.objet_type as object_type, n.objet_id as object_id, n.type,";
420
-    $sql.= " c.rowid as id, c.lastname, c.firstname, c.email as contactemail,";
421
-    $sql.= " a.code, a.label";
422
-    $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,";
423
-    $sql.= " ".MAIN_DB_PREFIX."notify as n ";
424
-    $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as c ON n.fk_contact = c.rowid";
425
-    $sql.= " WHERE a.rowid = n.fk_action";
426
-    $sql.= " AND n.fk_soc = ".$object->id;
427
-    $sql.= $db->order($sortfield, $sortorder);
420
+    $sql .= " c.rowid as id, c.lastname, c.firstname, c.email as contactemail,";
421
+    $sql .= " a.code, a.label";
422
+    $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,";
423
+    $sql .= " ".MAIN_DB_PREFIX."notify as n ";
424
+    $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as c ON n.fk_contact = c.rowid";
425
+    $sql .= " WHERE a.rowid = n.fk_action";
426
+    $sql .= " AND n.fk_soc = ".$object->id;
427
+    $sql .= $db->order($sortfield, $sortorder);
428 428
 
429 429
     // Count total nb of records
430 430
     $nbtotalofrecords = '';
@@ -439,9 +439,9 @@  discard block
 block discarded – undo
439 439
         }
440 440
     }
441 441
 
442
-    $sql.= $db->plimit($limit+1, $offset);
442
+    $sql .= $db->plimit($limit + 1, $offset);
443 443
 
444
-    $resql=$db->query($sql);
444
+    $resql = $db->query($sql);
445 445
     if ($resql)
446 446
     {
447 447
         $num = $db->num_rows($resql);
@@ -451,9 +451,9 @@  discard block
 block discarded – undo
451 451
         dol_print_error($db);
452 452
     }
453 453
 
454
-    $param='&socid='.$object->id;
455
-    if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
456
-    if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
454
+    $param = '&socid='.$object->id;
455
+    if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage;
456
+    if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit;
457 457
 
458 458
     print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
459 459
     if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
@@ -470,18 +470,18 @@  discard block
 block discarded – undo
470 470
     // Line with titles
471 471
     print '<table width="100%" class="noborder">';
472 472
     print '<tr class="liste_titre">';
473
-    print_liste_field_titre("Target",$_SERVER["PHP_SELF"],"c.lastname,c.firstname",'',$param,'',$sortfield,$sortorder);
474
-    print_liste_field_titre("Action",$_SERVER["PHP_SELF"],"",'',$param,'',$sortfield,$sortorder);
475
-    print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"n.type",'',$param,'',$sortfield,$sortorder);
473
+    print_liste_field_titre("Target", $_SERVER["PHP_SELF"], "c.lastname,c.firstname", '', $param, '', $sortfield, $sortorder);
474
+    print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder);
475
+    print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "n.type", '', $param, '', $sortfield, $sortorder);
476 476
     //print_liste_field_titre("Object",$_SERVER["PHP_SELF"],"",'',$param,'"',$sortfield,$sortorder);
477
-    print_liste_field_titre("Date",$_SERVER["PHP_SELF"],"n.daten",'',$param,'align="right"',$sortfield,$sortorder);
477
+    print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "n.daten", '', $param, 'align="right"', $sortfield, $sortorder);
478 478
     print '</tr>';
479 479
 
480 480
     if ($num > 0)
481 481
     {
482 482
         $i = 0;
483 483
 
484
-        $contactstatic=new Contact($db);
484
+        $contactstatic = new Contact($db);
485 485
 
486 486
         while ($i < $num)
487 487
         {
@@ -490,11 +490,11 @@  discard block
 block discarded – undo
490 490
             print '<tr class="oddeven"><td>';
491 491
             if ($obj->id > 0)
492 492
             {
493
-	            $contactstatic->id=$obj->id;
494
-	            $contactstatic->lastname=$obj->lastname;
495
-	            $contactstatic->firstname=$obj->firstname;
493
+	            $contactstatic->id = $obj->id;
494
+	            $contactstatic->lastname = $obj->lastname;
495
+	            $contactstatic->firstname = $obj->firstname;
496 496
 	            print $contactstatic->getNomUrl(1);
497
-	            print $obj->email?' &lt;'.$obj->email.'&gt;':$langs->trans("NoMail");
497
+	            print $obj->email ? ' &lt;'.$obj->email.'&gt;' : $langs->trans("NoMail");
498 498
             }
499 499
             else
500 500
 			{
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
             }
503 503
             print '</td>';
504 504
             print '<td>';
505
-            $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
505
+            $label = ($langs->trans("Notify_".$obj->code) != "Notify_".$obj->code ? $langs->trans("Notify_".$obj->code) : $obj->label);
506 506
             print $label;
507 507
             print '</td>';
508 508
             print '<td>';
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
 
531 531
     print '</form>';
532 532
 }
533
-else dol_print_error('','RecordNotFound');
533
+else dol_print_error('', 'RecordNotFound');
534 534
 
535 535
 // End of page
536 536
 llxFooter();
Please login to merge, or discard this patch.
dolibarr/htdocs/societe/notify/index.php 3 patches
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -28,17 +28,17 @@  discard block
 block discarded – undo
28 28
 // S�curit� acc�s client
29 29
 if ($user->societe_id > 0)
30 30
 {
31
-	$action = '';
32
-	$socid = $user->societe_id;
31
+    $action = '';
32
+    $socid = $user->societe_id;
33 33
 }
34 34
 
35 35
 if ($sortorder == "")
36 36
 {
37
-  $sortorder="ASC";
37
+    $sortorder="ASC";
38 38
 }
39 39
 if ($sortfield == "")
40 40
 {
41
-  $sortfield="s.nom";
41
+    $sortfield="s.nom";
42 42
 }
43 43
 
44 44
 if ($page == -1 || $page == null) { $page = 0 ; }
@@ -72,36 +72,36 @@  discard block
 block discarded – undo
72 72
 $result = $db->query($sql);
73 73
 if ($result)
74 74
 {
75
-	$num = $db->num_rows($result);
76
-	$i = 0;
77
-
78
-	$paramlist='';
79
-	print_barre_liste($langs->trans("ListOfNotificationsDone"), $page, $_SERVER["PHP_SELF"], $paramlist, $sortfield,$sortorder,'',$num);
80
-
81
-	print '<table class="noborder" width="100%">';
82
-	print '<tr class="liste_titre">';
83
-	print_liste_field_titre("Company",$_SERVER["PHP_SELF"],"s.nom","","",'valign="center"',$sortfield,$sortorder);
84
-	print_liste_field_titre("Contact",$_SERVER["PHP_SELF"],"c.lastname","","",'valign="center"',$sortfield,$sortorder);
85
-	print_liste_field_titre("Action",$_SERVER["PHP_SELF"],"a.titre","","",'valign="center"',$sortfield,$sortorder);
86
-	print "</tr>\n";
87
-
88
-	while ($i < $num)
89
-	{
90
-		$obj = $db->fetch_object($result);
91
-
92
-		print '<tr class="oddeven">';
93
-		print "<td><a href=\"card.php?socid=".$obj->socid."\">".$obj->name."</a></td>\n";
94
-		print "<td>".dolGetFirstLastname($obj->firstname, $obj->lastname)."</td>\n";
95
-		print "<td>".$obj->titre."</td>\n";
96
-		print "</tr>\n";
97
-		$i++;
98
-	}
99
-	print "</table>";
100
-	$db->free();
75
+    $num = $db->num_rows($result);
76
+    $i = 0;
77
+
78
+    $paramlist='';
79
+    print_barre_liste($langs->trans("ListOfNotificationsDone"), $page, $_SERVER["PHP_SELF"], $paramlist, $sortfield,$sortorder,'',$num);
80
+
81
+    print '<table class="noborder" width="100%">';
82
+    print '<tr class="liste_titre">';
83
+    print_liste_field_titre("Company",$_SERVER["PHP_SELF"],"s.nom","","",'valign="center"',$sortfield,$sortorder);
84
+    print_liste_field_titre("Contact",$_SERVER["PHP_SELF"],"c.lastname","","",'valign="center"',$sortfield,$sortorder);
85
+    print_liste_field_titre("Action",$_SERVER["PHP_SELF"],"a.titre","","",'valign="center"',$sortfield,$sortorder);
86
+    print "</tr>\n";
87
+
88
+    while ($i < $num)
89
+    {
90
+        $obj = $db->fetch_object($result);
91
+
92
+        print '<tr class="oddeven">';
93
+        print "<td><a href=\"card.php?socid=".$obj->socid."\">".$obj->name."</a></td>\n";
94
+        print "<td>".dolGetFirstLastname($obj->firstname, $obj->lastname)."</td>\n";
95
+        print "<td>".$obj->titre."</td>\n";
96
+        print "</tr>\n";
97
+        $i++;
98
+    }
99
+    print "</table>";
100
+    $db->free();
101 101
 }
102 102
 else
103 103
 {
104
-	dol_print_error($db);
104
+    dol_print_error($db);
105 105
 }
106 106
 
107 107
 // End of page
Please login to merge, or discard this patch.
Braces   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -64,7 +64,9 @@  discard block
 block discarded – undo
64 64
 $sql.= " AND a.rowid = n.fk_action";
65 65
 $sql.= " AND n.fk_soc = s.rowid";
66 66
 $sql.= " AND s.entity IN (".getEntity('societe').")";
67
-if ($socid > 0)	$sql.= " AND s.rowid = " . $user->societe_id;
67
+if ($socid > 0) {
68
+    $sql.= " AND s.rowid = " . $user->societe_id;
69
+}
68 70
 
69 71
 $sql.= $db->order($sortfield,$sortorder);
70 72
 $sql.= $db->plimit($conf->liste_limit, $offset);
@@ -98,8 +100,7 @@  discard block
 block discarded – undo
98 100
 	}
99 101
 	print "</table>";
100 102
 	$db->free();
101
-}
102
-else
103
+} else
103 104
 {
104 105
 	dol_print_error($db);
105 106
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 
26 26
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
27 27
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
28
-require DOL_BASE_PATH . 'main.inc.php';
28
+require DOL_BASE_PATH.'main.inc.php';
29 29
 $langs->loadLangs(array("companies", "banks"));
30 30
 
31 31
 // S�curit� acc�s client
@@ -37,16 +37,16 @@  discard block
 block discarded – undo
37 37
 
38 38
 if ($sortorder == "")
39 39
 {
40
-  $sortorder="ASC";
40
+  $sortorder = "ASC";
41 41
 }
42 42
 if ($sortfield == "")
43 43
 {
44
-  $sortfield="s.nom";
44
+  $sortfield = "s.nom";
45 45
 }
46 46
 
47
-if ($page == -1 || $page == null) { $page = 0 ; }
47
+if ($page == -1 || $page == null) { $page = 0; }
48 48
 
49
-$offset = $conf->liste_limit * $page ;
49
+$offset = $conf->liste_limit * $page;
50 50
 $pageprev = $page - 1;
51 51
 $pagenext = $page + 1;
52 52
 
@@ -59,18 +59,18 @@  discard block
 block discarded – undo
59 59
 llxHeader();
60 60
 
61 61
 $sql = "SELECT s.nom as name, s.rowid as socid, c.lastname, c.firstname, a.label, n.rowid";
62
-$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c,";
63
-$sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
64
-$sql.= " ".MAIN_DB_PREFIX."notify_def as n,";
65
-$sql.= " ".MAIN_DB_PREFIX."societe as s";
66
-$sql.= " WHERE n.fk_contact = c.rowid";
67
-$sql.= " AND a.rowid = n.fk_action";
68
-$sql.= " AND n.fk_soc = s.rowid";
69
-$sql.= " AND s.entity IN (".getEntity('societe').")";
70
-if ($socid > 0)	$sql.= " AND s.rowid = " . $user->societe_id;
71
-
72
-$sql.= $db->order($sortfield,$sortorder);
73
-$sql.= $db->plimit($conf->liste_limit, $offset);
62
+$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c,";
63
+$sql .= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
64
+$sql .= " ".MAIN_DB_PREFIX."notify_def as n,";
65
+$sql .= " ".MAIN_DB_PREFIX."societe as s";
66
+$sql .= " WHERE n.fk_contact = c.rowid";
67
+$sql .= " AND a.rowid = n.fk_action";
68
+$sql .= " AND n.fk_soc = s.rowid";
69
+$sql .= " AND s.entity IN (".getEntity('societe').")";
70
+if ($socid > 0)	$sql .= " AND s.rowid = ".$user->societe_id;
71
+
72
+$sql .= $db->order($sortfield, $sortorder);
73
+$sql .= $db->plimit($conf->liste_limit, $offset);
74 74
 
75 75
 $result = $db->query($sql);
76 76
 if ($result)
@@ -78,14 +78,14 @@  discard block
 block discarded – undo
78 78
 	$num = $db->num_rows($result);
79 79
 	$i = 0;
80 80
 
81
-	$paramlist='';
82
-	print_barre_liste($langs->trans("ListOfNotificationsDone"), $page, $_SERVER["PHP_SELF"], $paramlist, $sortfield,$sortorder,'',$num);
81
+	$paramlist = '';
82
+	print_barre_liste($langs->trans("ListOfNotificationsDone"), $page, $_SERVER["PHP_SELF"], $paramlist, $sortfield, $sortorder, '', $num);
83 83
 
84 84
 	print '<table class="noborder" width="100%">';
85 85
 	print '<tr class="liste_titre">';
86
-	print_liste_field_titre("Company",$_SERVER["PHP_SELF"],"s.nom","","",'valign="center"',$sortfield,$sortorder);
87
-	print_liste_field_titre("Contact",$_SERVER["PHP_SELF"],"c.lastname","","",'valign="center"',$sortfield,$sortorder);
88
-	print_liste_field_titre("Action",$_SERVER["PHP_SELF"],"a.titre","","",'valign="center"',$sortfield,$sortorder);
86
+	print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "", 'valign="center"', $sortfield, $sortorder);
87
+	print_liste_field_titre("Contact", $_SERVER["PHP_SELF"], "c.lastname", "", "", 'valign="center"', $sortfield, $sortorder);
88
+	print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "a.titre", "", "", 'valign="center"', $sortfield, $sortorder);
89 89
 	print "</tr>\n";
90 90
 
91 91
 	while ($i < $num)
Please login to merge, or discard this patch.
dolibarr/htdocs/societe/card.php 3 patches
Indentation   +1029 added lines, -1029 removed lines patch added patch discarded remove patch
@@ -76,9 +76,9 @@  discard block
 block discarded – undo
76 76
 
77 77
 if (! ($object->id > 0) && $action == 'view')
78 78
 {
79
-	$langs->load("errors");
80
-	print($langs->trans('ErrorRecordNotFound'));
81
-	exit;
79
+    $langs->load("errors");
80
+    print($langs->trans('ErrorRecordNotFound'));
81
+    exit;
82 82
 }
83 83
 
84 84
 // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
@@ -116,191 +116,191 @@  discard block
 block discarded – undo
116 116
         }
117 117
     }
118 118
 
119
-	if ($action == 'confirm_merge' && $confirm == 'yes' && $user->rights->societe->creer)
120
-	{
121
-		$error = 0;
122
-		$soc_origin_id = GETPOST('soc_origin', 'int');
123
-		$soc_origin = new Societe($db);
124
-
125
-		if ($soc_origin_id <= 0)
126
-		{
127
-			$langs->load('errors');
128
-			$langs->load('companies');
129
-			setEventMessages($langs->trans('ErrorThirdPartyIdIsMandatory', $langs->trans('MergeOriginThirdparty')), null, 'errors');
130
-		}
131
-		else
132
-		{
133
-			if (!$error && $soc_origin->fetch($soc_origin_id) < 1)
134
-			{
135
-				setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
136
-				$error++;
137
-			}
138
-
139
-			if (!$error)
140
-			{
141
-			    // TODO Move the merge function into class of object.
142
-
143
-				$db->begin();
144
-
145
-				// Recopy some data
146
-				$object->client = $object->client | $soc_origin->client;
147
-				$object->fournisseur = $object->fournisseur | $soc_origin->fournisseur;
148
-				$listofproperties=array(
149
-					'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'skype', 'twitter', 'facebook', 'url', 'barcode',
150
-					'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6',
151
-					'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'remise_supplier_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis',
152
-					'stcomm_id', 'outstanding_limit', 'price_level', 'parent', 'default_lang', 'ref', 'ref_ext', 'import_key', 'fk_incoterms', 'fk_multicurrency',
153
-					'code_client', 'code_fournisseur', 'code_compta', 'code_compta_fournisseur',
154
-					'model_pdf', 'fk_projet'
155
-				);
156
-				foreach ($listofproperties as $property)
157
-				{
158
-					if (empty($object->$property)) $object->$property = $soc_origin->$property;
159
-				}
119
+    if ($action == 'confirm_merge' && $confirm == 'yes' && $user->rights->societe->creer)
120
+    {
121
+        $error = 0;
122
+        $soc_origin_id = GETPOST('soc_origin', 'int');
123
+        $soc_origin = new Societe($db);
160 124
 
161
-				// Concat some data
162
-				$listofproperties=array(
163
-				    'note_public', 'note_private'
164
-				);
165
-				foreach ($listofproperties as $property)
166
-				{
167
-				    $object->$property = dol_concatdesc($object->$property, $soc_origin->$property);
168
-				}
125
+        if ($soc_origin_id <= 0)
126
+        {
127
+            $langs->load('errors');
128
+            $langs->load('companies');
129
+            setEventMessages($langs->trans('ErrorThirdPartyIdIsMandatory', $langs->trans('MergeOriginThirdparty')), null, 'errors');
130
+        }
131
+        else
132
+        {
133
+            if (!$error && $soc_origin->fetch($soc_origin_id) < 1)
134
+            {
135
+                setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
136
+                $error++;
137
+            }
169 138
 
170
-				// Merge extrafields
171
-				if (is_array($soc_origin->array_options))
172
-				{
173
-					foreach ($soc_origin->array_options as $key => $val)
174
-					{
175
-					    if (empty($object->array_options[$key])) $object->array_options[$key] = $val;
176
-					}
177
-				}
139
+            if (!$error)
140
+            {
141
+                // TODO Move the merge function into class of object.
178 142
 
179
-				// Merge categories
180
-				$static_cat = new Categorie($db);
181
-
182
-				$custcats_ori = $static_cat->containing($soc_origin->id, 'customer', 'id');
183
-				$custcats = $static_cat->containing($object->id, 'customer', 'id');
184
-				$custcats = array_merge($custcats,$custcats_ori);
185
-				$object->setCategories($custcats, 'customer');
186
-
187
-				$suppcats_ori = $static_cat->containing($soc_origin->id, 'supplier', 'id');
188
-				$suppcats = $static_cat->containing($object->id, 'supplier', 'id');
189
-				$suppcats = array_merge($suppcats,$suppcats_ori);
190
-				$object->setCategories($suppcats, 'supplier');
191
-
192
-				// If thirdparty has a new code that is same than origin, we clean origin code to avoid duplicate key from database unique keys.
193
-				if ($soc_origin->code_client == $object->code_client
194
-					|| $soc_origin->code_fournisseur == $object->code_fournisseur
195
-					|| $soc_origin->barcode == $object->barcode)
196
-				{
197
-					dol_syslog("We clean customer and supplier code so we will be able to make the update of target");
198
-					$soc_origin->code_client = '';
199
-					$soc_origin->code_fournisseur = '';
200
-					$soc_origin->barcode = '';
201
-					$soc_origin->update($soc_origin->id, $user, 0, 1, 1, 'merge');
202
-				}
143
+                $db->begin();
203 144
 
204
-				// Update
205
-				$object->update($object->id, $user, 0, 1, 1, 'merge');
206
-				if ($result < 0)
207
-				{
208
-					$error++;
209
-				}
145
+                // Recopy some data
146
+                $object->client = $object->client | $soc_origin->client;
147
+                $object->fournisseur = $object->fournisseur | $soc_origin->fournisseur;
148
+                $listofproperties=array(
149
+                    'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'skype', 'twitter', 'facebook', 'url', 'barcode',
150
+                    'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6',
151
+                    'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'remise_supplier_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis',
152
+                    'stcomm_id', 'outstanding_limit', 'price_level', 'parent', 'default_lang', 'ref', 'ref_ext', 'import_key', 'fk_incoterms', 'fk_multicurrency',
153
+                    'code_client', 'code_fournisseur', 'code_compta', 'code_compta_fournisseur',
154
+                    'model_pdf', 'fk_projet'
155
+                );
156
+                foreach ($listofproperties as $property)
157
+                {
158
+                    if (empty($object->$property)) $object->$property = $soc_origin->$property;
159
+                }
210 160
 
211
-				// Move links
212
-				if (! $error)
213
-				{
214
-					$objects = array(
215
-						'Adherent' => '/adherents/class/adherent.class.php',
216
-						'Societe' => '/societe/class/societe.class.php',
217
-						//'Categorie' => '/categories/class/categorie.class.php',
218
-						'ActionComm' => '/comm/action/class/actioncomm.class.php',
219
-						'Propal' => '/comm/propal/class/propal.class.php',
220
-						'Commande' => '/commande/class/commande.class.php',
221
-						'Facture' => '/compta/facture/class/facture.class.php',
222
-						'FactureRec' => '/compta/facture/class/facture-rec.class.php',
223
-						'LignePrelevement' => '/compta/prelevement/class/ligneprelevement.class.php',
224
-						'Contact' => '/contact/class/contact.class.php',
225
-						'Contrat' => '/contrat/class/contrat.class.php',
226
-						'Expedition' => '/expedition/class/expedition.class.php',
227
-						'Fichinter' => '/fichinter/class/fichinter.class.php',
228
-						'CommandeFournisseur' => '/fourn/class/fournisseur.commande.class.php',
229
-						'FactureFournisseur' => '/fourn/class/fournisseur.facture.class.php',
230
-						'SupplierProposal' => '/supplier_proposal/class/supplier_proposal.class.php',
231
-						'ProductFournisseur' => '/fourn/class/fournisseur.product.class.php',
232
-						'Livraison' => '/livraison/class/livraison.class.php',
233
-						'Product' => '/product/class/product.class.php',
234
-						'Project' => '/projet/class/project.class.php',
235
-						'User' => '/user/class/user.class.php',
236
-					);
237
-
238
-					//First, all core objects must update their tables
239
-					foreach ($objects as $object_name => $object_file)
240
-					{
241
-						require_once DOL_DOCUMENT_ROOT.$object_file;
161
+                // Concat some data
162
+                $listofproperties=array(
163
+                    'note_public', 'note_private'
164
+                );
165
+                foreach ($listofproperties as $property)
166
+                {
167
+                    $object->$property = dol_concatdesc($object->$property, $soc_origin->$property);
168
+                }
242 169
 
243
-						if (!$error && !$object_name::replaceThirdparty($db, $soc_origin->id, $object->id))
244
-						{
245
-							$error++;
246
-							setEventMessages($db->lasterror(), null, 'errors');
247
-						}
248
-					}
249
-				}
170
+                // Merge extrafields
171
+                if (is_array($soc_origin->array_options))
172
+                {
173
+                    foreach ($soc_origin->array_options as $key => $val)
174
+                    {
175
+                        if (empty($object->array_options[$key])) $object->array_options[$key] = $val;
176
+                    }
177
+                }
250 178
 
251
-				// External modules should update their ones too
252
-				if (! $error)
253
-				{
254
-					$reshook = $hookmanager->executeHooks('replaceThirdparty', array(
255
-						'soc_origin' => $soc_origin->id,
256
-						'soc_dest' => $object->id
257
-					), $soc_dest, $action);
179
+                // Merge categories
180
+                $static_cat = new Categorie($db);
258 181
 
259
-					if ($reshook < 0)
260
-					{
261
-						setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
262
-						$error++;
263
-					}
264
-				}
182
+                $custcats_ori = $static_cat->containing($soc_origin->id, 'customer', 'id');
183
+                $custcats = $static_cat->containing($object->id, 'customer', 'id');
184
+                $custcats = array_merge($custcats,$custcats_ori);
185
+                $object->setCategories($custcats, 'customer');
265 186
 
187
+                $suppcats_ori = $static_cat->containing($soc_origin->id, 'supplier', 'id');
188
+                $suppcats = $static_cat->containing($object->id, 'supplier', 'id');
189
+                $suppcats = array_merge($suppcats,$suppcats_ori);
190
+                $object->setCategories($suppcats, 'supplier');
266 191
 
267
-				if (! $error)
268
-				{
269
-					$object->context=array('merge'=>1, 'mergefromid'=>$soc_origin->id);
192
+                // If thirdparty has a new code that is same than origin, we clean origin code to avoid duplicate key from database unique keys.
193
+                if ($soc_origin->code_client == $object->code_client
194
+                    || $soc_origin->code_fournisseur == $object->code_fournisseur
195
+                    || $soc_origin->barcode == $object->barcode)
196
+                {
197
+                    dol_syslog("We clean customer and supplier code so we will be able to make the update of target");
198
+                    $soc_origin->code_client = '';
199
+                    $soc_origin->code_fournisseur = '';
200
+                    $soc_origin->barcode = '';
201
+                    $soc_origin->update($soc_origin->id, $user, 0, 1, 1, 'merge');
202
+                }
270 203
 
271
-					// Call trigger
272
-					$result=$object->call_trigger('COMPANY_MODIFY',$user);
273
-					if ($result < 0)
274
-					{
275
-						setEventMessages($object->error, $object->errors, 'errors');
276
-						$error++;
277
-					}
278
-					// End call triggers
279
-				}
204
+                // Update
205
+                $object->update($object->id, $user, 0, 1, 1, 'merge');
206
+                if ($result < 0)
207
+                {
208
+                    $error++;
209
+                }
280 210
 
281
-				if (!$error)
282
-				{
283
-					//We finally remove the old thirdparty
284
-					if ($soc_origin->delete($soc_origin->id, $user) < 1)
285
-					{
286
-						$error++;
287
-					}
288
-				}
211
+                // Move links
212
+                if (! $error)
213
+                {
214
+                    $objects = array(
215
+                        'Adherent' => '/adherents/class/adherent.class.php',
216
+                        'Societe' => '/societe/class/societe.class.php',
217
+                        //'Categorie' => '/categories/class/categorie.class.php',
218
+                        'ActionComm' => '/comm/action/class/actioncomm.class.php',
219
+                        'Propal' => '/comm/propal/class/propal.class.php',
220
+                        'Commande' => '/commande/class/commande.class.php',
221
+                        'Facture' => '/compta/facture/class/facture.class.php',
222
+                        'FactureRec' => '/compta/facture/class/facture-rec.class.php',
223
+                        'LignePrelevement' => '/compta/prelevement/class/ligneprelevement.class.php',
224
+                        'Contact' => '/contact/class/contact.class.php',
225
+                        'Contrat' => '/contrat/class/contrat.class.php',
226
+                        'Expedition' => '/expedition/class/expedition.class.php',
227
+                        'Fichinter' => '/fichinter/class/fichinter.class.php',
228
+                        'CommandeFournisseur' => '/fourn/class/fournisseur.commande.class.php',
229
+                        'FactureFournisseur' => '/fourn/class/fournisseur.facture.class.php',
230
+                        'SupplierProposal' => '/supplier_proposal/class/supplier_proposal.class.php',
231
+                        'ProductFournisseur' => '/fourn/class/fournisseur.product.class.php',
232
+                        'Livraison' => '/livraison/class/livraison.class.php',
233
+                        'Product' => '/product/class/product.class.php',
234
+                        'Project' => '/projet/class/project.class.php',
235
+                        'User' => '/user/class/user.class.php',
236
+                    );
237
+
238
+                    //First, all core objects must update their tables
239
+                    foreach ($objects as $object_name => $object_file)
240
+                    {
241
+                        require_once DOL_DOCUMENT_ROOT.$object_file;
289 242
 
290
-				if (!$error)
291
-				{
292
-					setEventMessages($langs->trans('ThirdpartiesMergeSuccess'), null, 'mesgs');
293
-					$db->commit();
294
-				}
295
-				else
296
-				{
297
-				    $langs->load("errors");
298
-					setEventMessages($langs->trans('ErrorsThirdpartyMerge'), null, 'errors');
299
-					$db->rollback();
300
-				}
301
-			}
302
-		}
303
-	}
243
+                        if (!$error && !$object_name::replaceThirdparty($db, $soc_origin->id, $object->id))
244
+                        {
245
+                            $error++;
246
+                            setEventMessages($db->lasterror(), null, 'errors');
247
+                        }
248
+                    }
249
+                }
250
+
251
+                // External modules should update their ones too
252
+                if (! $error)
253
+                {
254
+                    $reshook = $hookmanager->executeHooks('replaceThirdparty', array(
255
+                        'soc_origin' => $soc_origin->id,
256
+                        'soc_dest' => $object->id
257
+                    ), $soc_dest, $action);
258
+
259
+                    if ($reshook < 0)
260
+                    {
261
+                        setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
262
+                        $error++;
263
+                    }
264
+                }
265
+
266
+
267
+                if (! $error)
268
+                {
269
+                    $object->context=array('merge'=>1, 'mergefromid'=>$soc_origin->id);
270
+
271
+                    // Call trigger
272
+                    $result=$object->call_trigger('COMPANY_MODIFY',$user);
273
+                    if ($result < 0)
274
+                    {
275
+                        setEventMessages($object->error, $object->errors, 'errors');
276
+                        $error++;
277
+                    }
278
+                    // End call triggers
279
+                }
280
+
281
+                if (!$error)
282
+                {
283
+                    //We finally remove the old thirdparty
284
+                    if ($soc_origin->delete($soc_origin->id, $user) < 1)
285
+                    {
286
+                        $error++;
287
+                    }
288
+                }
289
+
290
+                if (!$error)
291
+                {
292
+                    setEventMessages($langs->trans('ThirdpartiesMergeSuccess'), null, 'mesgs');
293
+                    $db->commit();
294
+                }
295
+                else
296
+                {
297
+                    $langs->load("errors");
298
+                    setEventMessages($langs->trans('ErrorsThirdpartyMerge'), null, 'errors');
299
+                    $db->rollback();
300
+                }
301
+            }
302
+        }
303
+    }
304 304
 
305 305
     if (GETPOST('getcustomercode'))
306 306
     {
@@ -316,17 +316,17 @@  discard block
 block discarded – undo
316 316
 
317 317
     if($action=='set_localtax1')
318 318
     {
319
-    	//obtidre selected del combobox
320
-    	$value=GETPOST('lt1');
321
-    	$object->fetch($socid);
322
-    	$res=$object->setValueFrom('localtax1_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
319
+        //obtidre selected del combobox
320
+        $value=GETPOST('lt1');
321
+        $object->fetch($socid);
322
+        $res=$object->setValueFrom('localtax1_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
323 323
     }
324 324
     if($action=='set_localtax2')
325 325
     {
326
-    	//obtidre selected del combobox
327
-    	$value=GETPOST('lt2');
328
-    	$object->fetch($socid);
329
-    	$res=$object->setValueFrom('localtax2_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
326
+        //obtidre selected del combobox
327
+        $value=GETPOST('lt2');
328
+        $object->fetch($socid);
329
+        $res=$object->setValueFrom('localtax2_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
330 330
     }
331 331
 
332 332
     if ($action == 'update_extras') {
@@ -341,12 +341,12 @@  discard block
 block discarded – undo
341 341
 
342 342
         if (! $error)
343 343
         {
344
-        	$result = $object->insertExtraFields('COMPANY_MODIFY');
345
-        	if ($result < 0)
346
-        	{
347
-        		setEventMessages($object->error, $object->errors, 'errors');
348
-        		$error++;
349
-        	}
344
+            $result = $object->insertExtraFields('COMPANY_MODIFY');
345
+            if ($result < 0)
346
+            {
347
+                setEventMessages($object->error, $object->errors, 'errors');
348
+                $error++;
349
+            }
350 350
         }
351 351
 
352 352
         if ($error) $action = 'edit_extras';
@@ -376,145 +376,145 @@  discard block
 block discarded – undo
376 376
 
377 377
         if (! $error)
378 378
         {
379
-        	if ($action == 'update')
380
-	        {
381
-	        	$ret=$object->fetch($socid);
382
-				$object->oldcopy = clone $object;
383
-	        }
384
-			else $object->canvas=$canvas;
385
-
386
-	        if (GETPOST("private") == 1)	// Ask to create a contact
387
-	        {
388
-	            $object->particulier		= GETPOST("private");
389
-
390
-	            $object->name				= dolGetFirstLastname(GETPOST('firstname','alpha'),GETPOST('name','alpha'));
391
-	            $object->civility_id		= GETPOST('civility_id');	// Note: civility id is a code, not an int
392
-	            // Add non official properties
393
-	            $object->name_bis			= GETPOST('name','alpha');
394
-	            $object->firstname			= GETPOST('firstname','alpha');
395
-	        }
396
-	        else
397
-	        {
398
-	            $object->name				= GETPOST('name', 'alpha');
399
-	        }
400
-	        $object->entity					= (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity);
401
-	        $object->name_alias				= GETPOST('name_alias');
402
-	        $object->address				= GETPOST('address');
403
-	        $object->zip					= GETPOST('zipcode', 'alpha');
404
-	        $object->town					= GETPOST('town', 'alpha');
405
-	        $object->country_id				= GETPOST('country_id', 'int');
406
-	        $object->state_id				= GETPOST('state_id', 'int');
407
-	        $object->skype					= GETPOST('skype', 'alpha');
408
-	        $object->twitter				= GETPOST('twitter', 'alpha');
409
-	        $object->facebook				= GETPOST('facebook', 'alpha');
410
-	        $object->phone					= GETPOST('phone', 'alpha');
411
-	        $object->fax					= GETPOST('fax','alpha');
412
-	        $object->email					= trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL));
413
-	        $object->url					= trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL));
414
-	        $object->idprof1				= trim(GETPOST('idprof1', 'alpha'));
415
-	        $object->idprof2				= trim(GETPOST('idprof2', 'alpha'));
416
-	        $object->idprof3				= trim(GETPOST('idprof3', 'alpha'));
417
-	        $object->idprof4				= trim(GETPOST('idprof4', 'alpha'));
418
-	        $object->idprof5				= trim(GETPOST('idprof5', 'alpha'));
419
-	        $object->idprof6				= trim(GETPOST('idprof6', 'alpha'));
420
-	        $object->prefix_comm			= GETPOST('prefix_comm', 'alpha');
421
-	        $object->code_client			= GETPOSTISSET('customer_code')?GETPOST('customer_code', 'alpha'):GETPOST('code_client', 'alpha');
422
-	        $object->code_fournisseur		= GETPOSTISSET('supplier_code')?GETPOST('supplier_code', 'alpha'):GETPOST('code_fournisseur', 'alpha');
423
-	        $object->capital				= GETPOST('capital', 'alpha');
424
-	        $object->barcode				= GETPOST('barcode', 'alpha');
425
-
426
-	        $object->tva_intra				= GETPOST('tva_intra', 'alpha');
427
-	        $object->tva_assuj				= GETPOST('assujtva_value', 'alpha');
428
-	        $object->status					= GETPOST('status', 'alpha');
429
-
430
-	        // Local Taxes
431
-	        $object->localtax1_assuj		= GETPOST('localtax1assuj_value', 'alpha');
432
-	        $object->localtax2_assuj		= GETPOST('localtax2assuj_value', 'alpha');
433
-
434
-	        $object->localtax1_value		= GETPOST('lt1', 'alpha');
435
-	        $object->localtax2_value		= GETPOST('lt2', 'alpha');
436
-
437
-	        $object->forme_juridique_code	= GETPOST('forme_juridique_code', 'int');
438
-	        $object->effectif_id			= GETPOST('effectif_id', 'int');
439
-	        $object->typent_id				= GETPOST('typent_id','int');
440
-
441
-	        $object->typent_code			= dol_getIdFromCode($db, $object->typent_id, 'c_typent', 'id', 'code');	// Force typent_code too so check in verify() will be done on new type
442
-
443
-	        $object->client					= GETPOST('client', 'int');
444
-	        $object->fournisseur			= GETPOST('fournisseur', 'int');
445
-
446
-	        $object->commercial_id			= GETPOST('commercial_id', 'int');
447
-	        $object->default_lang			= GETPOST('default_lang');
448
-
449
-	        // Webservices url/key
450
-	        $object->webservices_url		= GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
451
-	        $object->webservices_key		= GETPOST('webservices_key', 'san_alpha');
452
-
453
-			// Incoterms
454
-			if (!empty($conf->incoterm->enabled))
455
-			{
456
-				$object->fk_incoterms		= GETPOST('incoterm_id', 'int');
457
-				$object->location_incoterms	= GETPOST('location_incoterms', 'alpha');
458
-			}
459
-
460
-			// Multicurrency
461
-			if (!empty($conf->multicurrency->enabled))
462
-			{
463
-				$object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
464
-			}
465
-
466
-	        // Fill array 'array_options' with data from add form
467
-	        $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
468
-			if ($ret < 0)
469
-			{
470
-				 $error++;
471
-			}
472
-
473
-	        if (GETPOST('deletephoto')) $object->logo = '';
474
-	        else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
475
-
476
-	        // Check parameters
477
-	        if (! GETPOST('cancel','alpha'))
478
-	        {
479
-	            if (! empty($object->email) && ! isValidEMail($object->email))
480
-	            {
481
-	                $langs->load("errors");
482
-	                $error++;
483
-	                setEventMessages('', $langs->trans("ErrorBadEMail",$object->email), 'errors');
484
-	            }
485
-	            if (! empty($object->url) && ! isValidUrl($object->url))
486
-	            {
487
-	                $langs->load("errors");
488
-	                setEventMessages('', $langs->trans("ErrorBadUrl",$object->url), 'errors');
489
-	            }
490
-	            if (! empty($object->webservices_url)) {
491
-	                //Check if has transport, without any the soap client will give error
492
-	                if (strpos($object->webservices_url, "http") === false)
493
-	                {
494
-	                    $object->webservices_url = "http://".$object->webservices_url;
495
-	                }
496
-	                if (! isValidUrl($object->webservices_url)) {
497
-	                    $langs->load("errors");
498
-	                    $error++; $errors[] = $langs->trans("ErrorBadUrl",$object->webservices_url);
499
-	                }
500
-	            }
501
-
502
-	            // We set country_id, country_code and country for the selected country
503
-	            $object->country_id=GETPOST('country_id')!=''?GETPOST('country_id'):$mysoc->country_id;
504
-	            if ($object->country_id)
505
-	            {
506
-	            	$tmparray=getCountry($object->country_id,'all');
507
-	            	$object->country_code=$tmparray['code'];
508
-	            	$object->country=$tmparray['label'];
509
-	            }
510
-	        }
379
+            if ($action == 'update')
380
+            {
381
+                $ret=$object->fetch($socid);
382
+                $object->oldcopy = clone $object;
383
+            }
384
+            else $object->canvas=$canvas;
385
+
386
+            if (GETPOST("private") == 1)	// Ask to create a contact
387
+            {
388
+                $object->particulier		= GETPOST("private");
389
+
390
+                $object->name				= dolGetFirstLastname(GETPOST('firstname','alpha'),GETPOST('name','alpha'));
391
+                $object->civility_id		= GETPOST('civility_id');	// Note: civility id is a code, not an int
392
+                // Add non official properties
393
+                $object->name_bis			= GETPOST('name','alpha');
394
+                $object->firstname			= GETPOST('firstname','alpha');
395
+            }
396
+            else
397
+            {
398
+                $object->name				= GETPOST('name', 'alpha');
399
+            }
400
+            $object->entity					= (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity);
401
+            $object->name_alias				= GETPOST('name_alias');
402
+            $object->address				= GETPOST('address');
403
+            $object->zip					= GETPOST('zipcode', 'alpha');
404
+            $object->town					= GETPOST('town', 'alpha');
405
+            $object->country_id				= GETPOST('country_id', 'int');
406
+            $object->state_id				= GETPOST('state_id', 'int');
407
+            $object->skype					= GETPOST('skype', 'alpha');
408
+            $object->twitter				= GETPOST('twitter', 'alpha');
409
+            $object->facebook				= GETPOST('facebook', 'alpha');
410
+            $object->phone					= GETPOST('phone', 'alpha');
411
+            $object->fax					= GETPOST('fax','alpha');
412
+            $object->email					= trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL));
413
+            $object->url					= trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL));
414
+            $object->idprof1				= trim(GETPOST('idprof1', 'alpha'));
415
+            $object->idprof2				= trim(GETPOST('idprof2', 'alpha'));
416
+            $object->idprof3				= trim(GETPOST('idprof3', 'alpha'));
417
+            $object->idprof4				= trim(GETPOST('idprof4', 'alpha'));
418
+            $object->idprof5				= trim(GETPOST('idprof5', 'alpha'));
419
+            $object->idprof6				= trim(GETPOST('idprof6', 'alpha'));
420
+            $object->prefix_comm			= GETPOST('prefix_comm', 'alpha');
421
+            $object->code_client			= GETPOSTISSET('customer_code')?GETPOST('customer_code', 'alpha'):GETPOST('code_client', 'alpha');
422
+            $object->code_fournisseur		= GETPOSTISSET('supplier_code')?GETPOST('supplier_code', 'alpha'):GETPOST('code_fournisseur', 'alpha');
423
+            $object->capital				= GETPOST('capital', 'alpha');
424
+            $object->barcode				= GETPOST('barcode', 'alpha');
425
+
426
+            $object->tva_intra				= GETPOST('tva_intra', 'alpha');
427
+            $object->tva_assuj				= GETPOST('assujtva_value', 'alpha');
428
+            $object->status					= GETPOST('status', 'alpha');
429
+
430
+            // Local Taxes
431
+            $object->localtax1_assuj		= GETPOST('localtax1assuj_value', 'alpha');
432
+            $object->localtax2_assuj		= GETPOST('localtax2assuj_value', 'alpha');
433
+
434
+            $object->localtax1_value		= GETPOST('lt1', 'alpha');
435
+            $object->localtax2_value		= GETPOST('lt2', 'alpha');
436
+
437
+            $object->forme_juridique_code	= GETPOST('forme_juridique_code', 'int');
438
+            $object->effectif_id			= GETPOST('effectif_id', 'int');
439
+            $object->typent_id				= GETPOST('typent_id','int');
440
+
441
+            $object->typent_code			= dol_getIdFromCode($db, $object->typent_id, 'c_typent', 'id', 'code');	// Force typent_code too so check in verify() will be done on new type
442
+
443
+            $object->client					= GETPOST('client', 'int');
444
+            $object->fournisseur			= GETPOST('fournisseur', 'int');
445
+
446
+            $object->commercial_id			= GETPOST('commercial_id', 'int');
447
+            $object->default_lang			= GETPOST('default_lang');
448
+
449
+            // Webservices url/key
450
+            $object->webservices_url		= GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
451
+            $object->webservices_key		= GETPOST('webservices_key', 'san_alpha');
452
+
453
+            // Incoterms
454
+            if (!empty($conf->incoterm->enabled))
455
+            {
456
+                $object->fk_incoterms		= GETPOST('incoterm_id', 'int');
457
+                $object->location_incoterms	= GETPOST('location_incoterms', 'alpha');
458
+            }
459
+
460
+            // Multicurrency
461
+            if (!empty($conf->multicurrency->enabled))
462
+            {
463
+                $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
464
+            }
465
+
466
+            // Fill array 'array_options' with data from add form
467
+            $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
468
+            if ($ret < 0)
469
+            {
470
+                    $error++;
471
+            }
472
+
473
+            if (GETPOST('deletephoto')) $object->logo = '';
474
+            else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
475
+
476
+            // Check parameters
477
+            if (! GETPOST('cancel','alpha'))
478
+            {
479
+                if (! empty($object->email) && ! isValidEMail($object->email))
480
+                {
481
+                    $langs->load("errors");
482
+                    $error++;
483
+                    setEventMessages('', $langs->trans("ErrorBadEMail",$object->email), 'errors');
484
+                }
485
+                if (! empty($object->url) && ! isValidUrl($object->url))
486
+                {
487
+                    $langs->load("errors");
488
+                    setEventMessages('', $langs->trans("ErrorBadUrl",$object->url), 'errors');
489
+                }
490
+                if (! empty($object->webservices_url)) {
491
+                    //Check if has transport, without any the soap client will give error
492
+                    if (strpos($object->webservices_url, "http") === false)
493
+                    {
494
+                        $object->webservices_url = "http://".$object->webservices_url;
495
+                    }
496
+                    if (! isValidUrl($object->webservices_url)) {
497
+                        $langs->load("errors");
498
+                        $error++; $errors[] = $langs->trans("ErrorBadUrl",$object->webservices_url);
499
+                    }
500
+                }
501
+
502
+                // We set country_id, country_code and country for the selected country
503
+                $object->country_id=GETPOST('country_id')!=''?GETPOST('country_id'):$mysoc->country_id;
504
+                if ($object->country_id)
505
+                {
506
+                    $tmparray=getCountry($object->country_id,'all');
507
+                    $object->country_code=$tmparray['code'];
508
+                    $object->country=$tmparray['label'];
509
+                }
510
+            }
511 511
         }
512 512
 
513 513
         if (! $error)
514 514
         {
515 515
             if ($action == 'add')
516 516
             {
517
-            	$error = 0;
517
+                $error = 0;
518 518
 
519 519
                 $db->begin();
520 520
 
@@ -523,45 +523,45 @@  discard block
 block discarded – undo
523 523
 
524 524
                 $result = $object->create($user);
525 525
 
526
-				if ($result >= 0)
527
-				{
528
-					if ($object->particulier)
529
-					{
530
-						dol_syslog("We ask to create a contact/address too", LOG_DEBUG);
531
-						$result=$object->create_individual($user);
532
-						if ($result < 0)
533
-						{
534
-							setEventMessages($object->error, $object->errors, 'errors');
535
-							$error++;
536
-						}
537
-					}
526
+                if ($result >= 0)
527
+                {
528
+                    if ($object->particulier)
529
+                    {
530
+                        dol_syslog("We ask to create a contact/address too", LOG_DEBUG);
531
+                        $result=$object->create_individual($user);
532
+                        if ($result < 0)
533
+                        {
534
+                            setEventMessages($object->error, $object->errors, 'errors');
535
+                            $error++;
536
+                        }
537
+                    }
538 538
 
539
-					// Links with users
540
-					$salesreps = GETPOST('commercial', 'array');
541
-					$result = $object->setSalesRep($salesreps);
542
-					if ($result < 0)
543
-					{
544
-						$error++;
545
-						setEventMessages($object->error, $object->errors, 'errors');
546
-					}
539
+                    // Links with users
540
+                    $salesreps = GETPOST('commercial', 'array');
541
+                    $result = $object->setSalesRep($salesreps);
542
+                    if ($result < 0)
543
+                    {
544
+                        $error++;
545
+                        setEventMessages($object->error, $object->errors, 'errors');
546
+                    }
547 547
 
548
-					// Customer categories association
549
-					$custcats = GETPOST('custcats', 'array');
550
-					$result = $object->setCategories($custcats, 'customer');
551
-					if ($result < 0)
552
-					{
553
-						$error++;
554
-						setEventMessages($object->error, $object->errors, 'errors');
555
-					}
548
+                    // Customer categories association
549
+                    $custcats = GETPOST('custcats', 'array');
550
+                    $result = $object->setCategories($custcats, 'customer');
551
+                    if ($result < 0)
552
+                    {
553
+                        $error++;
554
+                        setEventMessages($object->error, $object->errors, 'errors');
555
+                    }
556 556
 
557
-					// Supplier categories association
558
-					$suppcats = GETPOST('suppcats', 'array');
559
-					$result = $object->setCategories($suppcats, 'supplier');
560
-					if ($result < 0)
561
-					{
562
-						$error++;
563
-						setEventMessages($object->error, $object->errors, 'errors');
564
-					}
557
+                    // Supplier categories association
558
+                    $suppcats = GETPOST('suppcats', 'array');
559
+                    $result = $object->setCategories($suppcats, 'supplier');
560
+                    if ($result < 0)
561
+                    {
562
+                        $error++;
563
+                        setEventMessages($object->error, $object->errors, 'errors');
564
+                    }
565 565
 
566 566
                     // Logo/Photo save
567 567
                     $dir     = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos/";
@@ -590,52 +590,52 @@  discard block
 block discarded – undo
590 590
                         }
591 591
                     }
592 592
                     else
593
-					{
594
-						switch($_FILES['photo']['error'])
595
-						{
596
-						    case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
597
-						    case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
598
-						      $errors[] = "ErrorFileSizeTooLarge";
599
-						      break;
600
-	      					case 3: //uploaded file was only partially uploaded
601
-						      $errors[] = "ErrorFilePartiallyUploaded";
602
-						      break;
603
-						}
604
-	                }
593
+                    {
594
+                        switch($_FILES['photo']['error'])
595
+                        {
596
+                            case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
597
+                            case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
598
+                              $errors[] = "ErrorFileSizeTooLarge";
599
+                                break;
600
+                                case 3: //uploaded file was only partially uploaded
601
+                              $errors[] = "ErrorFilePartiallyUploaded";
602
+                                break;
603
+                        }
604
+                    }
605 605
                     // Gestion du logo de la société
606 606
                 }
607 607
                 else
608
-				{
609
-				    if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') // TODO Sometime errors on duplicate on profid and not on code, so we must manage this case
610
-					{
611
-						$duplicate_code_error = true;
612
-						$object->code_fournisseur = null;
613
-						$object->code_client = null;
614
-					}
608
+                {
609
+                    if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') // TODO Sometime errors on duplicate on profid and not on code, so we must manage this case
610
+                    {
611
+                        $duplicate_code_error = true;
612
+                        $object->code_fournisseur = null;
613
+                        $object->code_client = null;
614
+                    }
615 615
 
616 616
                     setEventMessages($object->error, $object->errors, 'errors');
617
-                   	$error++;
617
+                        $error++;
618 618
                 }
619 619
 
620 620
                 if ($result >= 0 && ! $error)
621 621
                 {
622 622
                     $db->commit();
623 623
 
624
-                	if (! empty($backtopage))
625
-                	{
626
-                	    if (preg_match('/\?/', $backtopage)) $backtopage.='&socid='.$object->id;
627
-               		    header("Location: ".$backtopage);
628
-                    	exit;
629
-                	}
630
-                	else
631
-                	{
632
-                    	$url=$_SERVER["PHP_SELF"]."?socid=".$object->id;
633
-                    	if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $url=DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
634
-                    	else if ($object->fournisseur == 1) $url=DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
635
-
636
-                		header("Location: ".$url);
637
-                    	exit;
638
-                	}
624
+                    if (! empty($backtopage))
625
+                    {
626
+                        if (preg_match('/\?/', $backtopage)) $backtopage.='&socid='.$object->id;
627
+                            header("Location: ".$backtopage);
628
+                        exit;
629
+                    }
630
+                    else
631
+                    {
632
+                        $url=$_SERVER["PHP_SELF"]."?socid=".$object->id;
633
+                        if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $url=DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
634
+                        else if ($object->fournisseur == 1) $url=DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
635
+
636
+                        header("Location: ".$url);
637
+                        exit;
638
+                    }
639 639
                 }
640 640
                 else
641 641
                 {
@@ -646,20 +646,20 @@  discard block
 block discarded – undo
646 646
 
647 647
             if ($action == 'update')
648 648
             {
649
-            	$error = 0;
649
+                $error = 0;
650 650
 
651 651
                 if (GETPOST('cancel','alpha'))
652 652
                 {
653
-                	if (! empty($backtopage))
654
-                	{
655
-               		    header("Location: ".$backtopage);
656
-                    	exit;
657
-                	}
658
-                	else
659
-                	{
660
-               		    header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
661
-                    	exit;
662
-                	}
653
+                    if (! empty($backtopage))
654
+                    {
655
+                            header("Location: ".$backtopage);
656
+                        exit;
657
+                    }
658
+                    else
659
+                    {
660
+                            header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
661
+                        exit;
662
+                    }
663 663
                 }
664 664
 
665 665
                 // To not set code if third party is not concerned. But if it had values, we keep them.
@@ -674,36 +674,36 @@  discard block
 block discarded – undo
674 674
                     $error++;
675 675
                 }
676 676
 
677
-				// Links with users
678
-				$salesreps = GETPOST('commercial', 'array');
679
-				$result = $object->setSalesRep($salesreps);
680
-				if ($result < 0)
681
-				{
682
-					$error++;
683
-					setEventMessages($object->error, $object->errors, 'errors');
684
-				}
677
+                // Links with users
678
+                $salesreps = GETPOST('commercial', 'array');
679
+                $result = $object->setSalesRep($salesreps);
680
+                if ($result < 0)
681
+                {
682
+                    $error++;
683
+                    setEventMessages($object->error, $object->errors, 'errors');
684
+                }
685 685
 
686
-				// Prevent thirdparty's emptying if a user hasn't rights $user->rights->categorie->lire (in such a case, post of 'custcats' is not defined)
687
-				if (! $error && !empty($user->rights->categorie->lire))
688
-				{
689
-					// Customer categories association
690
-					$categories = GETPOST( 'custcats', 'array' );
691
-					$result = $object->setCategories($categories, 'customer');
692
-					if ($result < 0)
693
-					{
694
-						$error++;
695
-						setEventMessages($object->error, $object->errors, 'errors');
696
-					}
686
+                // Prevent thirdparty's emptying if a user hasn't rights $user->rights->categorie->lire (in such a case, post of 'custcats' is not defined)
687
+                if (! $error && !empty($user->rights->categorie->lire))
688
+                {
689
+                    // Customer categories association
690
+                    $categories = GETPOST( 'custcats', 'array' );
691
+                    $result = $object->setCategories($categories, 'customer');
692
+                    if ($result < 0)
693
+                    {
694
+                        $error++;
695
+                        setEventMessages($object->error, $object->errors, 'errors');
696
+                    }
697 697
 
698
-					// Supplier categories association
699
-					$categories = GETPOST('suppcats', 'array');
700
-					$result = $object->setCategories($categories, 'supplier');
701
-					if ($result < 0)
702
-					{
703
-						$error++;
704
-						setEventMessages($object->error, $object->errors, 'errors');
705
-					}
706
-				}
698
+                    // Supplier categories association
699
+                    $categories = GETPOST('suppcats', 'array');
700
+                    $result = $object->setCategories($categories, 'supplier');
701
+                    if ($result < 0)
702
+                    {
703
+                        $error++;
704
+                        setEventMessages($object->error, $object->errors, 'errors');
705
+                    }
706
+                }
707 707
 
708 708
                 // Logo/Photo save
709 709
                 $dir     = $conf->societe->multidir_output[$object->entity]."/".$object->id."/logos";
@@ -732,38 +732,38 @@  discard block
 block discarded – undo
732 732
                             }
733 733
                             else
734 734
                             {
735
-                            	// Create thumbs
736
-                            	$object->addThumbs($newfile);
735
+                                // Create thumbs
736
+                                $object->addThumbs($newfile);
737 737
 
738 738
                                 // Index file in database
739 739
                                 if (! empty($conf->global->THIRDPARTY_LOGO_ALLOW_EXTERNAL_DOWNLOAD))
740 740
                                 {
741
-                                	require_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php';
742
-                                	// the dir dirname($newfile) is directory of logo, so we should have only one file at once into index, so we delete indexes for the dir
743
-                                	deleteFilesIntoDatabaseIndex(dirname($newfile), '', '', 'uploaded', 1);
744
-                                	// now we index the uploaded logo file
745
-                                	addFileIntoDatabaseIndex(dirname($newfile), basename($newfile), '', 'uploaded', 1);
741
+                                    require_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php';
742
+                                    // the dir dirname($newfile) is directory of logo, so we should have only one file at once into index, so we delete indexes for the dir
743
+                                    deleteFilesIntoDatabaseIndex(dirname($newfile), '', '', 'uploaded', 1);
744
+                                    // now we index the uploaded logo file
745
+                                    addFileIntoDatabaseIndex(dirname($newfile), basename($newfile), '', 'uploaded', 1);
746 746
                                 }
747 747
                             }
748 748
                         }
749 749
                     }
750 750
                     else
751
-					{
751
+                    {
752 752
                         $errors[] = "ErrorBadImageFormat";
753 753
                     }
754 754
                 }
755 755
                 else
756 756
                 {
757
-					switch($_FILES['photo']['error'])
758
-					{
759
-					    case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
760
-					    case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
761
-					      $errors[] = "ErrorFileSizeTooLarge";
762
-					      break;
763
-      					case 3: //uploaded file was only partially uploaded
764
-					      $errors[] = "ErrorFilePartiallyUploaded";
765
-					      break;
766
-					}
757
+                    switch($_FILES['photo']['error'])
758
+                    {
759
+                        case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
760
+                        case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
761
+                          $errors[] = "ErrorFileSizeTooLarge";
762
+                            break;
763
+                            case 3: //uploaded file was only partially uploaded
764
+                          $errors[] = "ErrorFilePartiallyUploaded";
765
+                            break;
766
+                    }
767 767
                 }
768 768
                 // Gestion du logo de la société
769 769
 
@@ -772,28 +772,28 @@  discard block
 block discarded – undo
772 772
                 if (! $error && $object->fk_soc > 0)
773 773
                 {
774 774
 
775
-                	$sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
776
-                	$sql.= " SET fk_soc = NULL WHERE fk_soc = " . $id;
777
-                	if (! $object->db->query($sql))
778
-                	{
779
-                		$error++;
780
-                		$object->error .= $object->db->lasterror();
781
-                		setEventMessages($object->error, $object->errors, 'errors');
782
-                	}
775
+                    $sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
776
+                    $sql.= " SET fk_soc = NULL WHERE fk_soc = " . $id;
777
+                    if (! $object->db->query($sql))
778
+                    {
779
+                        $error++;
780
+                        $object->error .= $object->db->lasterror();
781
+                        setEventMessages($object->error, $object->errors, 'errors');
782
+                    }
783 783
                 }
784 784
 
785 785
                 if (! $error && ! count($errors))
786 786
                 {
787
-                	if (! empty($backtopage))
788
-                	{
789
-               		    header("Location: ".$backtopage);
790
-                    	exit;
791
-                	}
792
-                	else
793
-                	{
794
-               		    header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
795
-                    	exit;
796
-                	}
787
+                    if (! empty($backtopage))
788
+                    {
789
+                            header("Location: ".$backtopage);
790
+                        exit;
791
+                    }
792
+                    else
793
+                    {
794
+                            header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
795
+                        exit;
796
+                    }
797 797
                 }
798 798
                 else
799 799
                 {
@@ -804,7 +804,7 @@  discard block
 block discarded – undo
804 804
         }
805 805
         else
806 806
         {
807
-        	$action = ($action=='add'?'create':'edit');
807
+            $action = ($action=='add'?'create':'edit');
808 808
         }
809 809
     }
810 810
 
@@ -822,8 +822,8 @@  discard block
 block discarded – undo
822 822
         else
823 823
         {
824 824
             $langs->load("errors");
825
-           	setEventMessages($object->error, $object->errors, 'errors');
826
-           	$error++;
825
+                setEventMessages($object->error, $object->errors, 'errors');
826
+                $error++;
827 827
             $action='';
828 828
         }
829 829
     }
@@ -831,15 +831,15 @@  discard block
 block discarded – undo
831 831
     // Set parent company
832 832
     if ($action == 'set_thirdparty' && $user->rights->societe->creer)
833 833
     {
834
-    	$object->fetch($socid);
835
-    	$result = $object->set_parent(GETPOST('editparentcompany','int'));
834
+        $object->fetch($socid);
835
+        $result = $object->set_parent(GETPOST('editparentcompany','int'));
836 836
     }
837 837
 
838 838
     // Set incoterm
839 839
     if ($action == 'set_incoterms' && !empty($conf->incoterm->enabled))
840 840
     {
841
-    	$object->fetch($socid);
842
-    	$result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
841
+        $object->fetch($socid);
842
+        $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
843 843
     }
844 844
 
845 845
     $id=$socid;
@@ -872,7 +872,7 @@  discard block
 block discarded – undo
872 872
 if ($socid > 0 && empty($object->id))
873 873
 {
874 874
     $result=$object->fetch($socid);
875
-	if ($result <= 0) dol_print_error('',$object->error);
875
+    if ($result <= 0) dol_print_error('',$object->error);
876 876
 }
877 877
 
878 878
 $title=$langs->trans("ThirdParty");
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
     // -----------------------------------------
888 888
     // When used with CANVAS
889 889
     // -----------------------------------------
890
-   	$objcanvas->assign_values($action, $object->id, $object->ref);	// Set value for templates
890
+        $objcanvas->assign_values($action, $object->id, $object->ref);	// Set value for templates
891 891
     $objcanvas->display_canvas($action);							// Show template
892 892
 }
893 893
 else
@@ -900,9 +900,9 @@  discard block
 block discarded – undo
900 900
         /*
901 901
          *  Creation
902 902
          */
903
-		$private=GETPOST("private","int");
904
-		if (! empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT) && ! isset($_GET['private']) && ! isset($_POST['private'])) $private=1;
905
-    	if (empty($private)) $private=0;
903
+        $private=GETPOST("private","int");
904
+        if (! empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT) && ! isset($_GET['private']) && ! isset($_POST['private'])) $private=1;
905
+        if (empty($private)) $private=0;
906 906
 
907 907
         // Load object modCodeTiers
908 908
         $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
@@ -948,12 +948,12 @@  discard block
 block discarded – undo
948 948
         $object->client				= GETPOST('client')?GETPOST('client'):$object->client;
949 949
 
950 950
         if(empty($duplicate_code_error)) {
951
-	        $object->code_client		= GETPOST('customer_code', 'alpha');
952
-	        $object->fournisseur		= GETPOST('fournisseur')?GETPOST('fournisseur'):$object->fournisseur;
951
+            $object->code_client		= GETPOST('customer_code', 'alpha');
952
+            $object->fournisseur		= GETPOST('fournisseur')?GETPOST('fournisseur'):$object->fournisseur;
953
+        }
954
+        else {
955
+            setEventMessages($langs->trans('NewCustomerSupplierCodeProposed'),'', 'warnings');
953 956
         }
954
-		else {
955
-			setEventMessages($langs->trans('NewCustomerSupplierCodeProposed'),'', 'warnings');
956
-		}
957 957
 
958 958
         $object->code_fournisseur	= GETPOST('supplier_code', 'alpha');
959 959
         $object->address			= GETPOST('address', 'alpha');
@@ -1107,18 +1107,18 @@  discard block
 block discarded – undo
1107 1107
             print '<div class="hideonsmartphone float">';
1108 1108
             print $langs->trans("ThirdPartyType").': &nbsp; &nbsp; ';
1109 1109
             print '</div>';
1110
-	        print '<label for="radiocompany" class="radiocompany">';
1110
+            print '<label for="radiocompany" class="radiocompany">';
1111 1111
             print '<input type="radio" id="radiocompany" class="flat" name="private"  value="0"'.($private?'':' checked').'>';
1112
-	        print '&nbsp;';
1112
+            print '&nbsp;';
1113 1113
             print $langs->trans("CreateThirdPartyOnly");
1114
-	        print '</label>';
1114
+            print '</label>';
1115 1115
             print ' &nbsp; &nbsp; ';
1116
-	        print '<label for="radioprivate" class="radioprivate">';
1116
+            print '<label for="radioprivate" class="radioprivate">';
1117 1117
             $text ='<input type="radio" id="radioprivate" class="flat" name="private" value="1"'.($private?' checked':'').'>';
1118
-	        $text.='&nbsp;';
1119
-	        $text.= $langs->trans("CreateThirdPartyAndContact");
1120
-	        $htmltext=$langs->trans("ToCreateContactWithSameName");
1121
-	        print $form->textwithpicto($text, $htmltext, 1, 'help', '', 0, 3);
1118
+            $text.='&nbsp;';
1119
+            $text.= $langs->trans("CreateThirdPartyAndContact");
1120
+            $htmltext=$langs->trans("ToCreateContactWithSameName");
1121
+            print $form->textwithpicto($text, $htmltext, 1, 'help', '', 0, 3);
1122 1122
             print '</label>';
1123 1123
             print '</div>';
1124 1124
             print "<br>\n";
@@ -1142,28 +1142,28 @@  discard block
 block discarded – undo
1142 1142
         print '<table class="border" width="100%">';
1143 1143
 
1144 1144
         // Name, firstname
1145
-	    print '<tr><td class="titlefieldcreate">';
1145
+        print '<tr><td class="titlefieldcreate">';
1146 1146
         if ($object->particulier || $private)
1147 1147
         {
1148
-	        print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName','name').'</span>';
1148
+            print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName','name').'</span>';
1149 1149
         }
1150 1150
         else
1151
-		{
1152
-			print '<span id="TypeName" class="fieldrequired">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0).'</span>';
1151
+        {
1152
+            print '<span id="TypeName" class="fieldrequired">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0).'</span>';
1153 1153
         }
1154
-	    print '</td><td'.(empty($conf->global->SOCIETE_USEPREFIX)?' colspan="3"':'').'>';
1155
-	    print '<input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.$object->name.'" autofocus="autofocus"></td>';
1156
-	    if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1157
-	    {
1158
-		    print '<td>'.$langs->trans('Prefix').'</td><td><input type="text" size="5" maxlength="5" name="prefix_comm" value="'.$object->prefix_comm.'"></td>';
1159
-	    }
1160
-	    print '</tr>';
1154
+        print '</td><td'.(empty($conf->global->SOCIETE_USEPREFIX)?' colspan="3"':'').'>';
1155
+        print '<input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.$object->name.'" autofocus="autofocus"></td>';
1156
+        if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1157
+        {
1158
+            print '<td>'.$langs->trans('Prefix').'</td><td><input type="text" size="5" maxlength="5" name="prefix_comm" value="'.$object->prefix_comm.'"></td>';
1159
+        }
1160
+        print '</tr>';
1161 1161
 
1162 1162
         // If javascript on, we show option individual
1163 1163
         if ($conf->use_javascript_ajax)
1164 1164
         {
1165 1165
             print '<tr class="individualline"><td>'.$form->editfieldkey('FirstName', 'firstname', '', $object, 0).'</td>';
1166
-	        print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="firstname" id="firstname" value="'.$object->firstname.'"></td>';
1166
+            print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="firstname" id="firstname" value="'.$object->firstname.'"></td>';
1167 1167
             print '</tr>';
1168 1168
             // Title
1169 1169
             print '<tr class="individualline"><td>'.$form->editfieldkey('UserTitle', 'civility_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
@@ -1173,12 +1173,12 @@  discard block
 block discarded – undo
1173 1173
 
1174 1174
         // Alias names (commercial, trademark or alias names)
1175 1175
         print '<tr id="name_alias"><td><label for="name_alias_input">'.$langs->trans('AliasNames').'</label></td>';
1176
-	    print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.$object->name_alias.'"></td></tr>';
1176
+        print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.$object->name_alias.'"></td></tr>';
1177 1177
 
1178 1178
         // Prospect/Customer
1179 1179
         print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).'</td>';
1180
-	    print '<td class="maxwidthonsmartphone">';
1181
-	    $selected=GETPOST('client','int')!=''?GETPOST('client','int'):$object->client;
1180
+        print '<td class="maxwidthonsmartphone">';
1181
+        $selected=GETPOST('client','int')!=''?GETPOST('client','int'):$object->client;
1182 1182
         print '<select class="flat" name="client" id="customerprospect">';
1183 1183
         if (GETPOST("type") == '') print '<option value="-1">&nbsp;</option>';
1184 1184
         if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($selected==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
@@ -1189,7 +1189,7 @@  discard block
 block discarded – undo
1189 1189
 
1190 1190
         print '<td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
1191 1191
         print '<table class="nobordernopadding"><tr><td>';
1192
-		$tmpcode=$object->code_client;
1192
+        $tmpcode=$object->code_client;
1193 1193
         if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object,0);
1194 1194
         print '<input type="text" name="customer_code" id="customer_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1195 1195
         print '</td><td>';
@@ -1199,7 +1199,7 @@  discard block
 block discarded – undo
1199 1199
         print '</td></tr>';
1200 1200
 
1201 1201
         if ((! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1202
-        	|| (! empty($conf->supplier_proposal->enabled) && ! empty($user->rights->supplier_proposal->lire)))
1202
+            || (! empty($conf->supplier_proposal->enabled) && ! empty($user->rights->supplier_proposal->lire)))
1203 1203
         {
1204 1204
             // Supplier
1205 1205
             print '<tr>';
@@ -1211,19 +1211,19 @@  discard block
 block discarded – undo
1211 1211
             print '<td>';
1212 1212
             if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1213 1213
             {
1214
-            	print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0);
1214
+                print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0);
1215 1215
             }
1216 1216
             print '</td><td>';
1217 1217
             if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1218 1218
             {
1219
-	            print '<table class="nobordernopadding"><tr><td>';
1220
-	            $tmpcode=$object->code_fournisseur;
1221
-	            if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1222
-	            print '<input type="text" name="supplier_code" id="supplier_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1223
-	            print '</td><td>';
1224
-	            $s=$modCodeFournisseur->getToolTip($langs,$object,1);
1225
-	            print $form->textwithpicto('',$s,1);
1226
-	            print '</td></tr></table>';
1219
+                print '<table class="nobordernopadding"><tr><td>';
1220
+                $tmpcode=$object->code_fournisseur;
1221
+                if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1222
+                print '<input type="text" name="supplier_code" id="supplier_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1223
+                print '</td><td>';
1224
+                $s=$modCodeFournisseur->getToolTip($langs,$object,1);
1225
+                print $form->textwithpicto('',$s,1);
1226
+                print '</td></tr></table>';
1227 1227
             }
1228 1228
             print '</td></tr>';
1229 1229
         }
@@ -1237,13 +1237,13 @@  discard block
 block discarded – undo
1237 1237
         if (! empty($conf->barcode->enabled))
1238 1238
         {
1239 1239
             print '<tr><td>'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).'</td>';
1240
-	        print '<td colspan="3"><input type="text" name="barcode" id="barcode" value="'.$object->barcode.'">';
1240
+            print '<td colspan="3"><input type="text" name="barcode" id="barcode" value="'.$object->barcode.'">';
1241 1241
             print '</td></tr>';
1242 1242
         }
1243 1243
 
1244 1244
         // Address
1245 1245
         print '<tr><td class="tdtop">'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
1246
-	    print '<td colspan="3"><textarea name="address" id="address" class="quatrevingtpercent" rows="'.ROWS_2.'" wrap="soft">';
1246
+        print '<td colspan="3"><textarea name="address" id="address" class="quatrevingtpercent" rows="'.ROWS_2.'" wrap="soft">';
1247 1247
         print $object->address;
1248 1248
         print '</textarea></td></tr>';
1249 1249
 
@@ -1279,43 +1279,43 @@  discard block
 block discarded – undo
1279 1279
 
1280 1280
         // Email / Web
1281 1281
         print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', $conf->global->SOCIETE_EMAIL_MANDATORY).'</td>';
1282
-	    print '<td colspan="3"><input type="text" name="email" id="email" value="'.$object->email.'"></td></tr>';
1282
+        print '<td colspan="3"><input type="text" name="email" id="email" value="'.$object->email.'"></td></tr>';
1283 1283
         print '<tr><td>'.$form->editfieldkey('Web', 'url', '', $object, 0).'</td>';
1284
-	    print '<td colspan="3"><input type="text" name="url" id="url" value="'.$object->url.'"></td></tr>';
1284
+        print '<td colspan="3"><input type="text" name="url" id="url" value="'.$object->url.'"></td></tr>';
1285 1285
 
1286 1286
         if (! empty($conf->socialnetworks->enabled))
1287 1287
         {
1288
-        	// Skype
1289
-        	if (! empty($conf->global->SOCIALNETWORKS_SKYPE))
1290
-        	{
1291
-        		print '<tr><td>'.$form->editfieldkey('Skype', 'skype', '', $object, 0).'</td>';
1292
-				print '<td colspan="3">';
1293
-				print '<input type="text" name="skype" class="minwidth100" maxlength="80" id="skype" value="'.dol_escape_htmltag(GETPOSTISSET("skype")?GETPOST("skype",'alpha'):$object->skype).'">';
1294
-				print '</td></tr>';
1295
-        	}
1296
-        	// Twitter
1297
-        	if (! empty($conf->global->SOCIALNETWORKS_TWITTER))
1298
-        	{
1299
-        		print '<tr><td>'.$form->editfieldkey('Twitter', 'twitter', '', $object, 0).'</td>';
1300
-				print '<td colspan="3">';
1301
-				print '<input type="text" name="twitter" class="minwidth100" maxlength="80" id="twitter" value="'.dol_escape_htmltag(GETPOSTISSET("twitter")?GETPOST("twitter",'alpha'):$object->twitter).'">';
1302
-				print '</td></tr>';
1303
-        	}
1304
-        	// Facebook
1305
-        	if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK))
1306
-        	{
1307
-	        	print '<tr><td>'.$form->editfieldkey('Facebook', 'facebook', '', $object, 0).'</td>';
1308
-				print '<td colspan="3">';
1309
-				print '<input type="text" name="facebook" class="minwidth100" maxlength="80" id="facebook" value="'.dol_escape_htmltag(GETPOSTISSET("facebook")?GETPOST("facebook",'alpha'):$object->facebook).'">';
1310
-				print '</td></tr>';
1311
-        	}
1288
+            // Skype
1289
+            if (! empty($conf->global->SOCIALNETWORKS_SKYPE))
1290
+            {
1291
+                print '<tr><td>'.$form->editfieldkey('Skype', 'skype', '', $object, 0).'</td>';
1292
+                print '<td colspan="3">';
1293
+                print '<input type="text" name="skype" class="minwidth100" maxlength="80" id="skype" value="'.dol_escape_htmltag(GETPOSTISSET("skype")?GETPOST("skype",'alpha'):$object->skype).'">';
1294
+                print '</td></tr>';
1295
+            }
1296
+            // Twitter
1297
+            if (! empty($conf->global->SOCIALNETWORKS_TWITTER))
1298
+            {
1299
+                print '<tr><td>'.$form->editfieldkey('Twitter', 'twitter', '', $object, 0).'</td>';
1300
+                print '<td colspan="3">';
1301
+                print '<input type="text" name="twitter" class="minwidth100" maxlength="80" id="twitter" value="'.dol_escape_htmltag(GETPOSTISSET("twitter")?GETPOST("twitter",'alpha'):$object->twitter).'">';
1302
+                print '</td></tr>';
1303
+            }
1304
+            // Facebook
1305
+            if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK))
1306
+            {
1307
+                print '<tr><td>'.$form->editfieldkey('Facebook', 'facebook', '', $object, 0).'</td>';
1308
+                print '<td colspan="3">';
1309
+                print '<input type="text" name="facebook" class="minwidth100" maxlength="80" id="facebook" value="'.dol_escape_htmltag(GETPOSTISSET("facebook")?GETPOST("facebook",'alpha'):$object->facebook).'">';
1310
+                print '</td></tr>';
1311
+            }
1312 1312
         }
1313 1313
 
1314 1314
         // Phone / Fax
1315 1315
         print '<tr><td>'.$form->editfieldkey('Phone', 'phone', '', $object, 0).'</td>';
1316
-	    print '<td><input type="text" name="phone" id="phone" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->phone.'"></td>';
1316
+        print '<td><input type="text" name="phone" id="phone" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->phone.'"></td>';
1317 1317
         print '<td>'.$form->editfieldkey('Fax', 'fax', '', $object, 0).'</td>';
1318
-	    print '<td><input type="text" name="fax" id="fax" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->fax.'"></td></tr>';
1318
+        print '<td><input type="text" name="fax" id="fax" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->fax.'"></td></tr>';
1319 1319
 
1320 1320
         // Prof ids
1321 1321
         $i=1; $j=0;
@@ -1324,7 +1324,7 @@  discard block
 block discarded – undo
1324 1324
             $idprof=$langs->transcountry('ProfId'.$i,$object->country_code);
1325 1325
             if ($idprof!='-')
1326 1326
             {
1327
-	            $key='idprof'.$i;
1327
+                $key='idprof'.$i;
1328 1328
 
1329 1329
                 if (($j % 2) == 0) print '<tr>';
1330 1330
 
@@ -1423,7 +1423,7 @@  discard block
 block discarded – undo
1423 1423
 
1424 1424
         // Capital
1425 1425
         print '<tr><td>'.$form->editfieldkey('Capital', 'capital', '', $object, 0).'</td>';
1426
-	    print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="'.$object->capital.'"> ';
1426
+        print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="'.$object->capital.'"> ';
1427 1427
         print '<span class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
1428 1428
 
1429 1429
         if (! empty($conf->global->MAIN_MULTILANGS))
@@ -1434,47 +1434,47 @@  discard block
 block discarded – undo
1434 1434
             print '</tr>';
1435 1435
         }
1436 1436
 
1437
-		// Incoterms
1438
-		if (!empty($conf->incoterm->enabled))
1439
-		{
1440
-			print '<tr>';
1441
-			print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
1442
-	        print '<td colspan="3" class="maxwidthonsmartphone">';
1443
-	        print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
1444
-			print '</td></tr>';
1445
-		}
1446
-
1447
-		// Categories
1448
-		if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
1449
-		{
1450
-			$langs->load('categories');
1451
-
1452
-			// Customer
1453
-			//if ($object->prospect || $object->client || (! $object->fournisseur && ! empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER))) {
1454
-			print '<tr class="visibleifcustomer"><td class="toptd">' . $form->editfieldkey('CustomersProspectsCategoriesShort', 'custcats', '', $object, 0) . '</td><td colspan="3">';
1455
-			$cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, 'parent', null, null, 1);
1456
-			print $form->multiselectarray('custcats', $cate_arbo, GETPOST('custcats', 'array'), null, null, null, null, "90%");
1457
-			print "</td></tr>";
1458
-			//}
1459
-
1460
-			// Supplier
1461
-			//if ($object->fournisseur) {
1462
-			print '<tr class="visibleifsupplier"><td class="toptd">' . $form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0) . '</td><td colspan="3">';
1463
-			$cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, 'parent', null, null, 1);
1464
-			print $form->multiselectarray('suppcats', $cate_arbo, GETPOST('suppcats', 'array'), null, null, null, null, "90%");
1465
-			print "</td></tr>";
1466
-			//}
1467
-		}
1468
-
1469
-		// Multicurrency
1470
-		if (! empty($conf->multicurrency->enabled))
1471
-		{
1472
-			print '<tr>';
1473
-			print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
1474
-	        print '<td colspan="3" class="maxwidthonsmartphone">';
1475
-	        print $form->selectMultiCurrency(($object->multicurrency_code ? $object->multicurrency_code : $conf->currency), 'multicurrency_code', 1);
1476
-			print '</td></tr>';
1477
-		}
1437
+        // Incoterms
1438
+        if (!empty($conf->incoterm->enabled))
1439
+        {
1440
+            print '<tr>';
1441
+            print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
1442
+            print '<td colspan="3" class="maxwidthonsmartphone">';
1443
+            print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
1444
+            print '</td></tr>';
1445
+        }
1446
+
1447
+        // Categories
1448
+        if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
1449
+        {
1450
+            $langs->load('categories');
1451
+
1452
+            // Customer
1453
+            //if ($object->prospect || $object->client || (! $object->fournisseur && ! empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER))) {
1454
+            print '<tr class="visibleifcustomer"><td class="toptd">' . $form->editfieldkey('CustomersProspectsCategoriesShort', 'custcats', '', $object, 0) . '</td><td colspan="3">';
1455
+            $cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, 'parent', null, null, 1);
1456
+            print $form->multiselectarray('custcats', $cate_arbo, GETPOST('custcats', 'array'), null, null, null, null, "90%");
1457
+            print "</td></tr>";
1458
+            //}
1459
+
1460
+            // Supplier
1461
+            //if ($object->fournisseur) {
1462
+            print '<tr class="visibleifsupplier"><td class="toptd">' . $form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0) . '</td><td colspan="3">';
1463
+            $cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, 'parent', null, null, 1);
1464
+            print $form->multiselectarray('suppcats', $cate_arbo, GETPOST('suppcats', 'array'), null, null, null, null, "90%");
1465
+            print "</td></tr>";
1466
+            //}
1467
+        }
1468
+
1469
+        // Multicurrency
1470
+        if (! empty($conf->multicurrency->enabled))
1471
+        {
1472
+            print '<tr>';
1473
+            print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
1474
+            print '<td colspan="3" class="maxwidthonsmartphone">';
1475
+            print $form->selectMultiCurrency(($object->multicurrency_code ? $object->multicurrency_code : $conf->currency), 'multicurrency_code', 1);
1476
+            print '</td></tr>';
1477
+        }
1478 1478
 
1479 1479
         // Other attributes
1480 1480
         $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
@@ -1482,17 +1482,17 @@  discard block
 block discarded – undo
1482 1482
         print $hookmanager->resPrint;
1483 1483
         if (empty($reshook))
1484 1484
         {
1485
-        	print $object->showOptionals($extrafields,'edit');
1485
+            print $object->showOptionals($extrafields,'edit');
1486 1486
         }
1487 1487
 
1488
-		// Assign a sale representative
1489
-		print '<tr>';
1490
-		print '<td>'.$form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0).'</td>';
1491
-		print '<td colspan="3" class="maxwidthonsmartphone">';
1492
-		$userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, '', 0, '', '', 0, 1);
1493
-		// Note: If user has no right to "see all thirdparties", we for selection of sale representative to him, so after creation he can see the record.
1494
-		print $form->multiselectarray('commercial', $userlist, (count(GETPOST('commercial', 'array')) > 0?GETPOST('commercial', 'array'):(empty($user->rights->societe->client->voir)?array($user->id):array())), null, null, null, null, "90%");
1495
-		print '</td></tr>';
1488
+        // Assign a sale representative
1489
+        print '<tr>';
1490
+        print '<td>'.$form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0).'</td>';
1491
+        print '<td colspan="3" class="maxwidthonsmartphone">';
1492
+        $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, '', 0, '', '', 0, 1);
1493
+        // Note: If user has no right to "see all thirdparties", we for selection of sale representative to him, so after creation he can see the record.
1494
+        print $form->multiselectarray('commercial', $userlist, (count(GETPOST('commercial', 'array')) > 0?GETPOST('commercial', 'array'):(empty($user->rights->societe->client->voir)?array($user->id):array())), null, null, null, null, "90%");
1495
+        print '</td></tr>';
1496 1496
 
1497 1497
         // Ajout du logo
1498 1498
         print '<tr class="hideonsmartphone">';
@@ -1528,10 +1528,10 @@  discard block
 block discarded – undo
1528 1528
 
1529 1529
         if ($socid)
1530 1530
         {
1531
-        	$res=$object->fetch_optionals();
1531
+            $res=$object->fetch_optionals();
1532 1532
             //if ($res < 0) { dol_print_error($db); exit; }
1533 1533
 
1534
-	        $head = societe_prepare_head($object);
1534
+            $head = societe_prepare_head($object);
1535 1535
 
1536 1536
             // Load object modCodeTiers
1537 1537
             $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
@@ -1569,7 +1569,7 @@  discard block
 block discarded – undo
1569 1569
                 $prefixSupplierIsUsed = $modCodeFournisseur->verif_prefixIsUsed();
1570 1570
             }
1571 1571
 
1572
-			$object->oldcopy = clone $object;
1572
+            $object->oldcopy = clone $object;
1573 1573
 
1574 1574
             if (GETPOSTISSET('name'))
1575 1575
             {
@@ -1613,12 +1613,12 @@  discard block
 block discarded – undo
1613 1613
                 $object->webservices_url        = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
1614 1614
                 $object->webservices_key        = GETPOST('webservices_key', 'san_alpha');
1615 1615
 
1616
-				//Incoterms
1617
-				if (!empty($conf->incoterm->enabled))
1618
-				{
1619
-					$object->fk_incoterms			= GETPOST('incoterm_id', 'int');
1620
-					$object->location_incoterms		= GETPOST('lcoation_incoterms', 'alpha');
1621
-				}
1616
+                //Incoterms
1617
+                if (!empty($conf->incoterm->enabled))
1618
+                {
1619
+                    $object->fk_incoterms			= GETPOST('incoterm_id', 'int');
1620
+                    $object->location_incoterms		= GETPOST('lcoation_incoterms', 'alpha');
1621
+                }
1622 1622
 
1623 1623
                 //Local Taxes
1624 1624
                 $object->localtax1_assuj		= GETPOST('localtax1assuj_value');
@@ -1630,23 +1630,23 @@  discard block
 block discarded – undo
1630 1630
                 // We set country_id, and country_code label of the chosen country
1631 1631
                 if ($object->country_id > 0)
1632 1632
                 {
1633
-                	$tmparray=getCountry($object->country_id,'all');
1633
+                    $tmparray=getCountry($object->country_id,'all');
1634 1634
                     $object->country_code	= $tmparray['code'];
1635 1635
                     $object->country		= $tmparray['label'];
1636 1636
                 }
1637 1637
             }
1638 1638
 
1639 1639
             if($object->localtax1_assuj==0){
1640
-            	$sub=0;
1640
+                $sub=0;
1641 1641
             }else{$sub=1;}
1642 1642
             if($object->localtax2_assuj==0){
1643
-            	$sub2=0;
1643
+                $sub2=0;
1644 1644
             }else{$sub2=1;}
1645 1645
 
1646 1646
             if ($conf->use_javascript_ajax)
1647 1647
             {
1648
-            	print "\n".'<script type="text/javascript">';
1649
-            	print '$(document).ready(function () {
1648
+                print "\n".'<script type="text/javascript">';
1649
+                print '$(document).ready(function () {
1650 1650
     			var val='.$sub.';
1651 1651
     			var val2='.$sub2.';
1652 1652
     			if("#localtax1assuj_value".value==undefined){
@@ -1735,20 +1735,20 @@  discard block
 block discarded – undo
1735 1735
             print '<table class="border" width="100%">';
1736 1736
 
1737 1737
             // Ref/ID
1738
-			if (! empty($conf->global->MAIN_SHOW_TECHNICAL_ID))
1739
-			{
1740
-		        print '<tr><td class="titlefieldcreate">'.$langs->trans("ID").'</td><td colspan="3">';
1741
-            	print $object->ref;
1742
-            	print '</td></tr>';
1743
-			}
1738
+            if (! empty($conf->global->MAIN_SHOW_TECHNICAL_ID))
1739
+            {
1740
+                print '<tr><td class="titlefieldcreate">'.$langs->trans("ID").'</td><td colspan="3">';
1741
+                print $object->ref;
1742
+                print '</td></tr>';
1743
+            }
1744 1744
 
1745 1745
             // Name
1746 1746
             print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0, 'string', '', 1).'</td>';
1747
-	        print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.dol_escape_htmltag($object->name).'" autofocus="autofocus"></td></tr>';
1747
+            print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.dol_escape_htmltag($object->name).'" autofocus="autofocus"></td></tr>';
1748 1748
 
1749
-	        // Alias names (commercial, trademark or alias names)
1750
-	        print '<tr id="name_alias"><td><label for="name_alias_input">'.$langs->trans('AliasNames').'</label></td>';
1751
-	        print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.dol_escape_htmltag($object->name_alias).'"></td></tr>';
1749
+            // Alias names (commercial, trademark or alias names)
1750
+            print '<tr id="name_alias"><td><label for="name_alias_input">'.$langs->trans('AliasNames').'</label></td>';
1751
+            print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.dol_escape_htmltag($object->name_alias).'"></td></tr>';
1752 1752
 
1753 1753
             // Prefix
1754 1754
             if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
@@ -1769,7 +1769,7 @@  discard block
 block discarded – undo
1769 1769
 
1770 1770
             // Prospect/Customer
1771 1771
             print '<tr><td>'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).'</td>';
1772
-	        print '<td class="maxwidthonsmartphone"><select class="flat" name="client" id="customerprospect">';
1772
+            print '<td class="maxwidthonsmartphone"><select class="flat" name="client" id="customerprospect">';
1773 1773
             if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($object->client==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1774 1774
             if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="3"'.($object->client==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1775 1775
             if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($object->client==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
@@ -1787,7 +1787,7 @@  discard block
 block discarded – undo
1787 1787
             }
1788 1788
             else if ($object->codeclient_modifiable())
1789 1789
             {
1790
-            	print '<input type="text" name="customer_code" id="customer_code" size="16" value="'.dol_escape_htmltag($object->code_client).'" maxlength="15">';
1790
+                print '<input type="text" name="customer_code" id="customer_code" size="16" value="'.dol_escape_htmltag($object->code_client).'" maxlength="15">';
1791 1791
             }
1792 1792
             else
1793 1793
             {
@@ -1803,7 +1803,7 @@  discard block
 block discarded – undo
1803 1803
 
1804 1804
             // Supplier
1805 1805
             if ((! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1806
-            	|| (! empty($conf->supplier_proposal->enabled) && ! empty($user->rights->supplier_proposal->lire)))
1806
+                || (! empty($conf->supplier_proposal->enabled) && ! empty($user->rights->supplier_proposal->lire)))
1807 1807
             {
1808 1808
                 print '<tr>';
1809 1809
                 print '<td>'.$form->editfieldkey('Supplier', 'fournisseur', '', $object, 0, 'string', '', 1).'</td><td class="maxwidthonsmartphone">';
@@ -1812,32 +1812,32 @@  discard block
 block discarded – undo
1812 1812
                 print '<td>';
1813 1813
                 if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1814 1814
                 {
1815
-                	print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0);
1815
+                    print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0);
1816 1816
                 }
1817 1817
                 print '</td><td>';
1818 1818
                 if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1819 1819
                 {
1820
-	                print '<table class="nobordernopadding"><tr><td>';
1821
-	                if ((!$object->code_fournisseur || $object->code_fournisseur == -1) && $modCodeFournisseur->code_auto)
1822
-	                {
1823
-	                    $tmpcode=$object->code_fournisseur;
1824
-	                    if (empty($tmpcode) && ! empty($object->oldcopy->code_fournisseur)) $tmpcode=$object->oldcopy->code_fournisseur; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1825
-	                    if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1826
-	                    print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1827
-	                }
1828
-	                else if ($object->codefournisseur_modifiable())
1829
-	                {
1830
-	                    print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.$object->code_fournisseur.'" maxlength="15">';
1831
-	                }
1832
-	                else
1833
-	              {
1834
-	                    print $object->code_fournisseur;
1835
-	                    print '<input type="hidden" name="supplier_code" value="'.$object->code_fournisseur.'">';
1836
-	                }
1837
-	                print '</td><td>';
1838
-	                $s=$modCodeFournisseur->getToolTip($langs,$object,1);
1839
-	                print $form->textwithpicto('',$s,1);
1840
-	                print '</td></tr></table>';
1820
+                    print '<table class="nobordernopadding"><tr><td>';
1821
+                    if ((!$object->code_fournisseur || $object->code_fournisseur == -1) && $modCodeFournisseur->code_auto)
1822
+                    {
1823
+                        $tmpcode=$object->code_fournisseur;
1824
+                        if (empty($tmpcode) && ! empty($object->oldcopy->code_fournisseur)) $tmpcode=$object->oldcopy->code_fournisseur; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1825
+                        if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1826
+                        print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1827
+                    }
1828
+                    else if ($object->codefournisseur_modifiable())
1829
+                    {
1830
+                        print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.$object->code_fournisseur.'" maxlength="15">';
1831
+                    }
1832
+                    else
1833
+                    {
1834
+                        print $object->code_fournisseur;
1835
+                        print '<input type="hidden" name="supplier_code" value="'.$object->code_fournisseur.'">';
1836
+                    }
1837
+                    print '</td><td>';
1838
+                    $s=$modCodeFournisseur->getToolTip($langs,$object,1);
1839
+                    print $form->textwithpicto('',$s,1);
1840
+                    print '</td></tr></table>';
1841 1841
                 }
1842 1842
                 print '</td></tr>';
1843 1843
             }
@@ -1846,7 +1846,7 @@  discard block
 block discarded – undo
1846 1846
             if (! empty($conf->barcode->enabled))
1847 1847
             {
1848 1848
                 print '<tr><td class="tdtop">'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).'</td>';
1849
-	            print '<td colspan="3"><input type="text" name="barcode" id="barcode" value="'.$object->barcode.'">';
1849
+                print '<td colspan="3"><input type="text" name="barcode" id="barcode" value="'.$object->barcode.'">';
1850 1850
                 print '</td></tr>';
1851 1851
             }
1852 1852
 
@@ -1857,7 +1857,7 @@  discard block
 block discarded – undo
1857 1857
 
1858 1858
             // Address
1859 1859
             print '<tr><td class="tdtop">'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
1860
-	        print '<td colspan="3"><textarea name="address" id="address" class="quatrevingtpercent" rows="3" wrap="soft">';
1860
+            print '<td colspan="3"><textarea name="address" id="address" class="quatrevingtpercent" rows="3" wrap="soft">';
1861 1861
             print $object->address;
1862 1862
             print '</textarea></td></tr>';
1863 1863
 
@@ -1892,37 +1892,37 @@  discard block
 block discarded – undo
1892 1892
 
1893 1893
             // EMail / Web
1894 1894
             print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', (! empty($conf->global->SOCIETE_EMAIL_MANDATORY))).'</td>';
1895
-	        print '<td colspan="3"><input type="text" name="email" id="email" size="32" value="'.$object->email.'"></td></tr>';
1895
+            print '<td colspan="3"><input type="text" name="email" id="email" size="32" value="'.$object->email.'"></td></tr>';
1896 1896
             print '<tr><td>'.$form->editfieldkey('Web', 'url', '', $object, 0).'</td>';
1897
-	        print '<td colspan="3"><input type="text" name="url" id="url" size="32" value="'.$object->url.'"></td></tr>';
1898
-
1899
-	        if (! empty($conf->socialnetworks->enabled))
1900
-	        {
1901
-	        	// Skype
1902
-	        	if (! empty($conf->global->SOCIALNETWORKS_SKYPE))
1903
-	        	{
1904
-	        		print '<tr><td>'.$form->editfieldkey('Skype', 'skype', '', $object, 0).'</td>';
1905
-	        		print '<td colspan="3"><input type="text" name="skype" id="skype" value="'.$object->skype.'"></td></tr>';
1906
-	        	}
1907
-	        	// Twitter
1908
-	        	if (! empty($conf->global->SOCIALNETWORKS_TWITTER))
1909
-	        	{
1910
-	        		print '<tr><td>'.$form->editfieldkey('Twitter', 'twitter', '', $object, 0).'</td>';
1911
-	        		print '<td colspan="3"><input type="text" name="twitter" id="twitter" value="'.$object->twitter.'"></td></tr>';
1912
-	        	}
1913
-	        	// Facebook
1914
-	        	if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK))
1915
-	        	{
1916
-	        		print '<tr><td>'.$form->editfieldkey('Facebook', 'facebook', '', $object, 0).'</td>';
1917
-	        		print '<td colspan="3"><input type="text" name="facebook" id="facebook" value="'.$object->facebook.'"></td></tr>';
1918
-	        	}
1919
-	        }
1897
+            print '<td colspan="3"><input type="text" name="url" id="url" size="32" value="'.$object->url.'"></td></tr>';
1898
+
1899
+            if (! empty($conf->socialnetworks->enabled))
1900
+            {
1901
+                // Skype
1902
+                if (! empty($conf->global->SOCIALNETWORKS_SKYPE))
1903
+                {
1904
+                    print '<tr><td>'.$form->editfieldkey('Skype', 'skype', '', $object, 0).'</td>';
1905
+                    print '<td colspan="3"><input type="text" name="skype" id="skype" value="'.$object->skype.'"></td></tr>';
1906
+                }
1907
+                // Twitter
1908
+                if (! empty($conf->global->SOCIALNETWORKS_TWITTER))
1909
+                {
1910
+                    print '<tr><td>'.$form->editfieldkey('Twitter', 'twitter', '', $object, 0).'</td>';
1911
+                    print '<td colspan="3"><input type="text" name="twitter" id="twitter" value="'.$object->twitter.'"></td></tr>';
1912
+                }
1913
+                // Facebook
1914
+                if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK))
1915
+                {
1916
+                    print '<tr><td>'.$form->editfieldkey('Facebook', 'facebook', '', $object, 0).'</td>';
1917
+                    print '<td colspan="3"><input type="text" name="facebook" id="facebook" value="'.$object->facebook.'"></td></tr>';
1918
+                }
1919
+            }
1920 1920
 
1921 1921
             // Phone / Fax
1922 1922
             print '<tr><td>'.$form->editfieldkey('Phone', 'phone', '', $object, 0).'</td>';
1923
-	        print '<td><input type="text" name="phone" id="phone" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->phone.'"></td>';
1923
+            print '<td><input type="text" name="phone" id="phone" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->phone.'"></td>';
1924 1924
             print '<td>'.$form->editfieldkey('Fax', 'fax', '', $object, 0).'</td>';
1925
-	        print '<td><input type="text" name="fax" id="fax" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->fax.'"></td></tr>';
1925
+            print '<td><input type="text" name="fax" id="fax" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->fax.'"></td></tr>';
1926 1926
 
1927 1927
             // Prof ids
1928 1928
             $i=1; $j=0;
@@ -1931,13 +1931,13 @@  discard block
 block discarded – undo
1931 1931
                 $idprof=$langs->transcountry('ProfId'.$i,$object->country_code);
1932 1932
                 if ($idprof!='-')
1933 1933
                 {
1934
-	                $key='idprof'.$i;
1934
+                    $key='idprof'.$i;
1935 1935
 
1936
-	                if (($j % 2) == 0) print '<tr>';
1936
+                    if (($j % 2) == 0) print '<tr>';
1937 1937
 
1938
-	                $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
1939
-	                print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', ! (empty($conf->global->$idprof_mandatory) || ! $object->isACompany())).'</td><td>';
1940
-	                print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
1938
+                    $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
1939
+                    print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', ! (empty($conf->global->$idprof_mandatory) || ! $object->isACompany())).'</td><td>';
1940
+                    print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
1941 1941
                     print '</td>';
1942 1942
                     if (($j % 2) == 1) print '</tr>';
1943 1943
                     $j++;
@@ -2047,9 +2047,9 @@  discard block
 block discarded – undo
2047 2047
 
2048 2048
             // Capital
2049 2049
             print '<tr><td>'.$form->editfieldkey('Capital', 'capital', '', $object, 0).'</td>';
2050
-	        print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="';
2051
-	        print $object->capital != '' ? dol_escape_htmltag(price($object->capital)) : '';
2052
-	        print '"> <font class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</font></td></tr>';
2050
+            print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="';
2051
+            print $object->capital != '' ? dol_escape_htmltag(price($object->capital)) : '';
2052
+            print '"> <font class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</font></td></tr>';
2053 2053
 
2054 2054
             // Default language
2055 2055
             if (! empty($conf->global->MAIN_MULTILANGS))
@@ -2063,52 +2063,52 @@  discard block
 block discarded – undo
2063 2063
             // Incoterms
2064 2064
             if (!empty($conf->incoterm->enabled))
2065 2065
             {
2066
-            	print '<tr>';
2067
-      				print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
2068
-            	print '<td colspan="3" class="maxwidthonsmartphone">';
2069
-            	print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
2070
-            	print '</td></tr>';
2071
-            }
2072
-
2073
-			// Categories
2074
-			if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
2075
-			{
2076
-				// Customer
2077
-				print '<tr class="visibleifcustomer"><td>' . $form->editfieldkey('CustomersCategoriesShort', 'custcats', '', $object, 0) . '</td>';
2078
-				print '<td colspan="3">';
2079
-				$cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, null, null, null, 1);
2080
-				$c = new Categorie($db);
2081
-				$cats = $c->containing($object->id, Categorie::TYPE_CUSTOMER);
2082
-				$arrayselected=array();
2083
-				foreach ($cats as $cat) {
2084
-					$arrayselected[] = $cat->id;
2085
-				}
2086
-				print $form->multiselectarray('custcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%');
2087
-				print "</td></tr>";
2088
-
2089
-				// Supplier
2090
-				print '<tr class="visibleifsupplier"><td>' . $form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0) . '</td>';
2091
-				print '<td colspan="3">';
2092
-				$cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, null, null, null, 1);
2093
-				$c = new Categorie($db);
2094
-				$cats = $c->containing($object->id, Categorie::TYPE_SUPPLIER);
2095
-				$arrayselected=array();
2096
-				foreach ($cats as $cat) {
2097
-					$arrayselected[] = $cat->id;
2098
-				}
2099
-				print $form->multiselectarray('suppcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%');
2100
-				print "</td></tr>";
2101
-			}
2102
-
2103
-			// Multicurrency
2104
-			if (! empty($conf->multicurrency->enabled))
2105
-			{
2106
-				print '<tr>';
2107
-				print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
2108
-		        print '<td colspan="3" class="maxwidthonsmartphone">';
2109
-		        print $form->selectMultiCurrency(($object->multicurrency_code ? $object->multicurrency_code : $conf->currency), 'multicurrency_code', 1);
2110
-				print '</td></tr>';
2111
-			}
2066
+                print '<tr>';
2067
+                        print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
2068
+                print '<td colspan="3" class="maxwidthonsmartphone">';
2069
+                print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
2070
+                print '</td></tr>';
2071
+            }
2072
+
2073
+            // Categories
2074
+            if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
2075
+            {
2076
+                // Customer
2077
+                print '<tr class="visibleifcustomer"><td>' . $form->editfieldkey('CustomersCategoriesShort', 'custcats', '', $object, 0) . '</td>';
2078
+                print '<td colspan="3">';
2079
+                $cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, null, null, null, 1);
2080
+                $c = new Categorie($db);
2081
+                $cats = $c->containing($object->id, Categorie::TYPE_CUSTOMER);
2082
+                $arrayselected=array();
2083
+                foreach ($cats as $cat) {
2084
+                    $arrayselected[] = $cat->id;
2085
+                }
2086
+                print $form->multiselectarray('custcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%');
2087
+                print "</td></tr>";
2088
+
2089
+                // Supplier
2090
+                print '<tr class="visibleifsupplier"><td>' . $form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0) . '</td>';
2091
+                print '<td colspan="3">';
2092
+                $cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, null, null, null, 1);
2093
+                $c = new Categorie($db);
2094
+                $cats = $c->containing($object->id, Categorie::TYPE_SUPPLIER);
2095
+                $arrayselected=array();
2096
+                foreach ($cats as $cat) {
2097
+                    $arrayselected[] = $cat->id;
2098
+                }
2099
+                print $form->multiselectarray('suppcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%');
2100
+                print "</td></tr>";
2101
+            }
2102
+
2103
+            // Multicurrency
2104
+            if (! empty($conf->multicurrency->enabled))
2105
+            {
2106
+                print '<tr>';
2107
+                print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
2108
+                print '<td colspan="3" class="maxwidthonsmartphone">';
2109
+                print $form->selectMultiCurrency(($object->multicurrency_code ? $object->multicurrency_code : $conf->currency), 'multicurrency_code', 1);
2110
+                print '</td></tr>';
2111
+            }
2112 2112
 
2113 2113
             // Other attributes
2114 2114
             $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
@@ -2116,7 +2116,7 @@  discard block
 block discarded – undo
2116 2116
             print $hookmanager->resPrint;
2117 2117
             if (empty($reshook))
2118 2118
             {
2119
-            	print $object->showOptionals($extrafields,'edit');
2119
+                print $object->showOptionals($extrafields,'edit');
2120 2120
             }
2121 2121
 
2122 2122
             // Webservices url/key
@@ -2158,7 +2158,7 @@  discard block
 block discarded – undo
2158 2158
             print '</table>';
2159 2159
             print '</div>';
2160 2160
 
2161
-	          dol_fiche_end();
2161
+                dol_fiche_end();
2162 2162
 
2163 2163
             print '<div align="center">';
2164 2164
             print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
@@ -2171,7 +2171,7 @@  discard block
 block discarded – undo
2171 2171
     }
2172 2172
     else
2173 2173
     {
2174
-    	/*
2174
+        /*
2175 2175
          * View
2176 2176
          */
2177 2177
 
@@ -2189,19 +2189,19 @@  discard block
 block discarded – undo
2189 2189
             print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("DeleteACompany"), $langs->trans("ConfirmDeleteCompany"), "confirm_delete", '', 0, "action-delete");
2190 2190
         }
2191 2191
 
2192
-	    if ($action == 'merge')
2193
-	    {
2194
-		    $formquestion = array(
2195
-			    array(
2196
-				    'name' => 'soc_origin',
2197
-			    	'label' => $langs->trans('MergeOriginThirdparty'),
2198
-				    'type' => 'other',
2199
-				    'value' => $form->select_company('', 'soc_origin', 's.rowid != '.$object->id, 'SelectThirdParty', 0, 0, array(), 0, 'minwidth200')
2200
-			    )
2201
-		    );
2202
-
2203
-		    print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("MergeThirdparties"), $langs->trans("ConfirmMergeThirdparties"), "confirm_merge", $formquestion, 'no', 1, 250);
2204
-	    }
2192
+        if ($action == 'merge')
2193
+        {
2194
+            $formquestion = array(
2195
+                array(
2196
+                    'name' => 'soc_origin',
2197
+                    'label' => $langs->trans('MergeOriginThirdparty'),
2198
+                    'type' => 'other',
2199
+                    'value' => $form->select_company('', 'soc_origin', 's.rowid != '.$object->id, 'SelectThirdParty', 0, 0, array(), 0, 'minwidth200')
2200
+                )
2201
+            );
2202
+
2203
+            print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("MergeThirdparties"), $langs->trans("ConfirmMergeThirdparties"), "confirm_merge", $formquestion, 'no', 1, 250);
2204
+        }
2205 2205
 
2206 2206
         dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error');
2207 2207
 
@@ -2216,20 +2216,20 @@  discard block
 block discarded – undo
2216 2216
         print '<div class="underbanner clearboth"></div>';
2217 2217
         print '<table class="border tableforfield" width="100%">';
2218 2218
 
2219
-    	// Prospect/Customer
2220
-    	print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>';
2221
-    	print $object->getLibCustProspStatut();
2222
-    	print '</td></tr>';
2219
+        // Prospect/Customer
2220
+        print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>';
2221
+        print $object->getLibCustProspStatut();
2222
+        print '</td></tr>';
2223 2223
 
2224
-    	// Supplier
2225
-   		if (! empty($conf->fournisseur->enabled) || ! empty($conf->supplier_proposal->enabled))
2226
-    	{
2227
-    		print '<tr><td>'.$langs->trans('Supplier').'</td><td>';
2228
-    		print yn($object->fournisseur);
2229
-    		print '</td></tr>';
2230
-    	}
2224
+        // Supplier
2225
+            if (! empty($conf->fournisseur->enabled) || ! empty($conf->supplier_proposal->enabled))
2226
+        {
2227
+            print '<tr><td>'.$langs->trans('Supplier').'</td><td>';
2228
+            print yn($object->fournisseur);
2229
+            print '</td></tr>';
2230
+        }
2231 2231
 
2232
-    	// Prefix
2232
+        // Prefix
2233 2233
         if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
2234 2234
         {
2235 2235
             print '<tr><td>'.$langs->trans('Prefix').'</td><td>'.$object->prefix_comm.'</td>';
@@ -2267,9 +2267,9 @@  discard block
 block discarded – undo
2267 2267
             print '<tr><td>';
2268 2268
             print $langs->trans('Gencod').'</td><td>'.$object->barcode;
2269 2269
             print '</td>';
2270
-			if ($htmllogobar) $htmllogobar.=$form->showbarcode($object);
2270
+            if ($htmllogobar) $htmllogobar.=$form->showbarcode($object);
2271 2271
             print $htmllogobar;
2272
-			$htmllogobar='';
2272
+            $htmllogobar='';
2273 2273
             print '</tr>';
2274 2274
         }
2275 2275
 
@@ -2282,7 +2282,7 @@  discard block
 block discarded – undo
2282 2282
             {
2283 2283
                 //if (($j % 2) == 0) print '<tr>';
2284 2284
                 print '<tr>';
2285
-            	print '<td>'.$idprof.'</td><td>';
2285
+                print '<td>'.$idprof.'</td><td>';
2286 2286
                 $key='idprof'.$i;
2287 2287
                 print $object->$key;
2288 2288
                 if ($object->$key)
@@ -2306,108 +2306,108 @@  discard block
 block discarded – undo
2306 2306
 
2307 2307
         if ($object->fournisseur)
2308 2308
         {
2309
-	        // VAT is used
2310
-	        print '<tr><td>';
2311
-	        print $form->textwithpicto($langs->trans('VATIsUsed'),$langs->trans('VATIsUsedWhenSelling'));
2312
-	        print '</td><td>';
2313
-	        print yn($object->tva_assuj);
2314
-	        print '</td>';
2315
-			print '</tr>';
2309
+            // VAT is used
2310
+            print '<tr><td>';
2311
+            print $form->textwithpicto($langs->trans('VATIsUsed'),$langs->trans('VATIsUsedWhenSelling'));
2312
+            print '</td><td>';
2313
+            print yn($object->tva_assuj);
2314
+            print '</td>';
2315
+            print '</tr>';
2316 2316
         }
2317 2317
 
2318
-		// Local Taxes
2318
+        // Local Taxes
2319 2319
         if ($object->fournisseur || $mysoc->country_code=='ES')
2320 2320
         {
2321
-        	if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
2322
-			{
2323
-			    print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
2324
-			    print yn($object->localtax1_assuj);
2325
-			    print '</td></tr><tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
2326
-			    print yn($object->localtax2_assuj);
2327
-			    print '</td></tr>';
2328
-
2329
-			    if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1)))
2330
-			    {
2331
-			        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2332
-			        print '<input type="hidden" name="action" value="set_localtax1">';
2333
-			        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2334
-			        print '<tr><td>'.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2335
-			        if($action == 'editRE')
2336
-			        {
2337
-			            print '<td align="left">';
2338
-			            $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2339
-			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2340
-			        }
2341
-			        else
2342
-			        {
2343
-			            print '<td>'.$object->localtax1_value.'</td>';
2344
-			        }
2345
-			        print '</tr></form>';
2346
-			    }
2347
-			    if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2)))
2348
-			    {
2349
-			        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2350
-			        print '<input type="hidden" name="action" value="set_localtax2">';
2351
-			        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2352
-			        print '<tr><td>'.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2353
-			        if($action == 'editIRPF'){
2354
-			            print '<td align="left">';
2355
-			            $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2356
-			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2357
-			        }else{
2358
-			            print '<td>'.$object->localtax2_value.'</td>';
2359
-			        }
2360
-			        print '</tr></form>';
2361
-			    }
2362
-			}
2363
-			elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
2364
-			{
2365
-			    print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
2366
-			    print yn($object->localtax1_assuj);
2367
-			    print '</td></tr>';
2368
-			    if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1)))
2369
-			    {
2370
-			        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2371
-			        print '<input type="hidden" name="action" value="set_localtax1">';
2372
-			        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2373
-			        print '<tr><td> '.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2374
-			        if($action == 'editRE'){
2375
-			            print '<td align="left">';
2376
-			            $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2377
-			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2378
-			        }else{
2379
-			            print '<td>'.$object->localtax1_value.'</td>';
2380
-			        }
2381
-			        print '</tr></form>';
2382
-			    }
2383
-			}
2384
-			elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
2385
-			{
2386
-			    print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
2387
-			    print yn($object->localtax2_assuj);
2388
-			    print '</td></tr>';
2389
-			    if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2)))
2390
-			    {
2391
-
2392
-			        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2393
-			        print '<input type="hidden" name="action" value="set_localtax2">';
2394
-			        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2395
-			        print '<tr><td> '.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2396
-			        if($action == 'editIRPF'){
2397
-			            print '<td align="left">';
2398
-			            $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2399
-			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2400
-			        }else{
2401
-			            print '<td>'.$object->localtax2_value.'</td>';
2402
-			        }
2403
-			        print '</tr></form>';
2404
-			    }
2405
-			}
2321
+            if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
2322
+            {
2323
+                print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
2324
+                print yn($object->localtax1_assuj);
2325
+                print '</td></tr><tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
2326
+                print yn($object->localtax2_assuj);
2327
+                print '</td></tr>';
2328
+
2329
+                if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1)))
2330
+                {
2331
+                    print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2332
+                    print '<input type="hidden" name="action" value="set_localtax1">';
2333
+                    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2334
+                    print '<tr><td>'.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2335
+                    if($action == 'editRE')
2336
+                    {
2337
+                        print '<td align="left">';
2338
+                        $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2339
+                        print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2340
+                    }
2341
+                    else
2342
+                    {
2343
+                        print '<td>'.$object->localtax1_value.'</td>';
2344
+                    }
2345
+                    print '</tr></form>';
2346
+                }
2347
+                if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2)))
2348
+                {
2349
+                    print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2350
+                    print '<input type="hidden" name="action" value="set_localtax2">';
2351
+                    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2352
+                    print '<tr><td>'.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2353
+                    if($action == 'editIRPF'){
2354
+                        print '<td align="left">';
2355
+                        $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2356
+                        print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2357
+                    }else{
2358
+                        print '<td>'.$object->localtax2_value.'</td>';
2359
+                    }
2360
+                    print '</tr></form>';
2361
+                }
2362
+            }
2363
+            elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
2364
+            {
2365
+                print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
2366
+                print yn($object->localtax1_assuj);
2367
+                print '</td></tr>';
2368
+                if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1)))
2369
+                {
2370
+                    print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2371
+                    print '<input type="hidden" name="action" value="set_localtax1">';
2372
+                    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2373
+                    print '<tr><td> '.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2374
+                    if($action == 'editRE'){
2375
+                        print '<td align="left">';
2376
+                        $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2377
+                        print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2378
+                    }else{
2379
+                        print '<td>'.$object->localtax1_value.'</td>';
2380
+                    }
2381
+                    print '</tr></form>';
2382
+                }
2383
+            }
2384
+            elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
2385
+            {
2386
+                print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
2387
+                print yn($object->localtax2_assuj);
2388
+                print '</td></tr>';
2389
+                if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2)))
2390
+                {
2391
+
2392
+                    print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2393
+                    print '<input type="hidden" name="action" value="set_localtax2">';
2394
+                    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2395
+                    print '<tr><td> '.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2396
+                    if($action == 'editIRPF'){
2397
+                        print '<td align="left">';
2398
+                        $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2399
+                        print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2400
+                    }else{
2401
+                        print '<td>'.$object->localtax2_value.'</td>';
2402
+                    }
2403
+                    print '</tr></form>';
2404
+                }
2405
+            }
2406 2406
         }
2407 2407
 
2408 2408
         // Sale tax code (VAT code)
2409 2409
         print '<tr>';
2410
-		print '<td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
2410
+        print '<td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
2411 2411
         if ($object->tva_intra)
2412 2412
         {
2413 2413
             $s='';
@@ -2458,25 +2458,25 @@  discard block
 block discarded – undo
2458 2458
         print '<div class="underbanner clearboth"></div>';
2459 2459
         print '<table class="border tableforfield" width="100%">';
2460 2460
 
2461
-    	// Tags / categories
2462
-		if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
2463
-		{
2464
-			// Customer
2465
-			if ($object->prospect || $object->client || (! $object->fournisseur && ! empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER))) {
2466
-				print '<tr><td>' . $langs->trans("CustomersCategoriesShort") . '</td>';
2467
-				print '<td>';
2468
-				print $form->showCategories($object->id, 'customer', 1);
2469
-				print "</td></tr>";
2470
-			}
2471
-
2472
-			// Supplier
2473
-			if ($object->fournisseur) {
2474
-				print '<tr><td>' . $langs->trans("SuppliersCategoriesShort") . '</td>';
2475
-				print '<td>';
2476
-				print $form->showCategories($object->id, 'supplier', 1);
2477
-				print "</td></tr>";
2478
-			}
2479
-		}
2461
+        // Tags / categories
2462
+        if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
2463
+        {
2464
+            // Customer
2465
+            if ($object->prospect || $object->client || (! $object->fournisseur && ! empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER))) {
2466
+                print '<tr><td>' . $langs->trans("CustomersCategoriesShort") . '</td>';
2467
+                print '<td>';
2468
+                print $form->showCategories($object->id, 'customer', 1);
2469
+                print "</td></tr>";
2470
+            }
2471
+
2472
+            // Supplier
2473
+            if ($object->fournisseur) {
2474
+                print '<tr><td>' . $langs->trans("SuppliersCategoriesShort") . '</td>';
2475
+                print '<td>';
2476
+                print $form->showCategories($object->id, 'supplier', 1);
2477
+                print "</td></tr>";
2478
+            }
2479
+        }
2480 2480
 
2481 2481
         // Legal
2482 2482
         print '<tr><td class="titlefield">'.$langs->trans('JuridicalStatus').'</td><td>'.$object->forme_juridique.'</td></tr>';
@@ -2503,61 +2503,61 @@  discard block
 block discarded – undo
2503 2503
         // Incoterms
2504 2504
         if (!empty($conf->incoterm->enabled))
2505 2505
         {
2506
-        	print '<tr><td>';
2507
-        	print '<table width="100%" class="nobordernopadding"><tr><td>';
2508
-        	print $langs->trans('IncotermLabel');
2509
-        	print '<td><td align="right">';
2510
-        	if ($user->rights->societe->creer) print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$object->id.'&action=editincoterm">'.img_edit('',1).'</a>';
2511
-        	else print '&nbsp;';
2512
-        	print '</td></tr></table>';
2513
-        	print '</td>';
2514
-        	print '<td colspan="3">';
2515
-        	if ($action != 'editincoterm')
2516
-        	{
2517
-        		print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1);
2518
-        	}
2519
-        	else
2520
-        	{
2521
-        		print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?socid='.$object->id);
2522
-        	}
2523
-        	print '</td></tr>';
2524
-        }
2525
-
2526
-		// Multicurrency
2527
-		if (! empty($conf->multicurrency->enabled))
2528
-		{
2529
-			print '<tr>';
2530
-			print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
2531
-	        print '<td>';
2532
-	        print !empty($object->multicurrency_code) ? currency_name($object->multicurrency_code,1) : '';
2533
-			print '</td></tr>';
2534
-		}
2535
-
2536
-		// Other attributes
2537
-		$parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
2538
-		include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
2506
+            print '<tr><td>';
2507
+            print '<table width="100%" class="nobordernopadding"><tr><td>';
2508
+            print $langs->trans('IncotermLabel');
2509
+            print '<td><td align="right">';
2510
+            if ($user->rights->societe->creer) print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$object->id.'&action=editincoterm">'.img_edit('',1).'</a>';
2511
+            else print '&nbsp;';
2512
+            print '</td></tr></table>';
2513
+            print '</td>';
2514
+            print '<td colspan="3">';
2515
+            if ($action != 'editincoterm')
2516
+            {
2517
+                print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1);
2518
+            }
2519
+            else
2520
+            {
2521
+                print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?socid='.$object->id);
2522
+            }
2523
+            print '</td></tr>';
2524
+        }
2525
+
2526
+        // Multicurrency
2527
+        if (! empty($conf->multicurrency->enabled))
2528
+        {
2529
+            print '<tr>';
2530
+            print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
2531
+            print '<td>';
2532
+            print !empty($object->multicurrency_code) ? currency_name($object->multicurrency_code,1) : '';
2533
+            print '</td></tr>';
2534
+        }
2535
+
2536
+        // Other attributes
2537
+        $parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
2538
+        include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
2539 2539
 
2540 2540
         // Parent company
2541 2541
         if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY))
2542 2542
         {
2543
-        	// Payment term
2544
-        	print '<tr><td>';
2545
-        	print '<table class="nobordernopadding" width="100%"><tr><td>';
2546
-        	print $langs->trans('ParentCompany');
2547
-        	print '</td>';
2548
-        	if ($action != 'editparentcompany') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</a></td>';
2549
-        	print '</tr></table>';
2550
-        	print '</td><td colspan="3">';
2551
-        	if ($action == 'editparentcompany')
2552
-        	{
2553
-        		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'editparentcompany','s.rowid <> '.$object->id,1);
2554
-        	}
2555
-        	else
2556
-        	{
2557
-        		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'none','s.rowid <> '.$object->id,1);
2558
-        	}
2559
-        	print '</td>';
2560
-        	print '</tr>';
2543
+            // Payment term
2544
+            print '<tr><td>';
2545
+            print '<table class="nobordernopadding" width="100%"><tr><td>';
2546
+            print $langs->trans('ParentCompany');
2547
+            print '</td>';
2548
+            if ($action != 'editparentcompany') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</a></td>';
2549
+            print '</tr></table>';
2550
+            print '</td><td colspan="3">';
2551
+            if ($action == 'editparentcompany')
2552
+            {
2553
+                $form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'editparentcompany','s.rowid <> '.$object->id,1);
2554
+            }
2555
+            else
2556
+            {
2557
+                $form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'none','s.rowid <> '.$object->id,1);
2558
+            }
2559
+            print '</td>';
2560
+            print '</tr>';
2561 2561
         }
2562 2562
 
2563 2563
         // Sales representative
@@ -2591,7 +2591,7 @@  discard block
 block discarded – undo
2591 2591
         }
2592 2592
 
2593 2593
         print '</table>';
2594
-		print '</div>';
2594
+        print '</div>';
2595 2595
 
2596 2596
         print '</div></div>';
2597 2597
         print '<div style="clear:both"></div>';
@@ -2604,128 +2604,128 @@  discard block
 block discarded – undo
2604 2604
          */
2605 2605
         if ($action != 'presend')
2606 2606
         {
2607
-	        print '<div class="tabsAction">'."\n";
2608
-
2609
-			$parameters=array();
2610
-			$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
2611
-			if (empty($reshook))
2612
-			{
2613
-				$at_least_one_email_contact = false;
2614
-				$TContact = $object->contact_array_objects();
2615
-				foreach ($TContact as &$contact)
2616
-				{
2617
-					if (!empty($contact->email))
2618
-					{
2619
-						$at_least_one_email_contact = true;
2620
-						break;
2621
-					}
2622
-				}
2607
+            print '<div class="tabsAction">'."\n";
2623 2608
 
2624
-		        if (! empty($object->email) || $at_least_one_email_contact)
2625
-		        {
2626
-		        	$langs->load("mails");
2627
-		        	print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'&amp;action=presend&amp;mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';
2628
-		        }
2629
-		        else
2630
-				{
2631
-		        	$langs->load("mails");
2632
-		       		print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans('SendMail').'</a></div>';
2633
-		        }
2634
-
2635
-		        if ($user->rights->societe->creer)
2636
-		        {
2637
-		            print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a></div>'."\n";
2638
-		        }
2639
-
2640
-		        if ($user->rights->societe->supprimer)
2641
-		        {
2642
-		        	print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?action=merge&socid='.$object->id.'" title="'.dol_escape_htmltag($langs->trans("MergeThirdparties")).'">'.$langs->trans('Merge').'</a></div>';
2643
-		        }
2644
-
2645
-		        if ($user->rights->societe->supprimer)
2646
-		        {
2647
-		            if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))	// We can't use preloaded confirm form with jmobile
2648
-		            {
2649
-		                print '<div class="inline-block divButAction"><span id="action-delete" class="butActionDelete">'.$langs->trans('Delete').'</span></div>'."\n";
2650
-		            }
2651
-		            else
2652
-					{
2653
-		                print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a></div>'."\n";
2654
-		            }
2655
-		        }
2656
-			}
2609
+            $parameters=array();
2610
+            $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
2611
+            if (empty($reshook))
2612
+            {
2613
+                $at_least_one_email_contact = false;
2614
+                $TContact = $object->contact_array_objects();
2615
+                foreach ($TContact as &$contact)
2616
+                {
2617
+                    if (!empty($contact->email))
2618
+                    {
2619
+                        $at_least_one_email_contact = true;
2620
+                        break;
2621
+                    }
2622
+                }
2623
+
2624
+                if (! empty($object->email) || $at_least_one_email_contact)
2625
+                {
2626
+                    $langs->load("mails");
2627
+                    print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'&amp;action=presend&amp;mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';
2628
+                }
2629
+                else
2630
+                {
2631
+                    $langs->load("mails");
2632
+                        print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans('SendMail').'</a></div>';
2633
+                }
2634
+
2635
+                if ($user->rights->societe->creer)
2636
+                {
2637
+                    print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a></div>'."\n";
2638
+                }
2639
+
2640
+                if ($user->rights->societe->supprimer)
2641
+                {
2642
+                    print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?action=merge&socid='.$object->id.'" title="'.dol_escape_htmltag($langs->trans("MergeThirdparties")).'">'.$langs->trans('Merge').'</a></div>';
2643
+                }
2657 2644
 
2658
-	        print '</div>'."\n";
2645
+                if ($user->rights->societe->supprimer)
2646
+                {
2647
+                    if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))	// We can't use preloaded confirm form with jmobile
2648
+                    {
2649
+                        print '<div class="inline-block divButAction"><span id="action-delete" class="butActionDelete">'.$langs->trans('Delete').'</span></div>'."\n";
2650
+                    }
2651
+                    else
2652
+                    {
2653
+                        print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a></div>'."\n";
2654
+                    }
2655
+                }
2656
+            }
2657
+
2658
+            print '</div>'."\n";
2659 2659
         }
2660 2660
 
2661 2661
         //Select mail models is same action as presend
2662
-		if (GETPOST('modelselected')) {
2663
-			$action = 'presend';
2664
-		}
2662
+        if (GETPOST('modelselected')) {
2663
+            $action = 'presend';
2664
+        }
2665 2665
 
2666
-		if ($action != 'presend')
2667
-		{
2668
-			print '<div class="fichecenter"><div class="fichehalfleft">';
2666
+        if ($action != 'presend')
2667
+        {
2668
+            print '<div class="fichecenter"><div class="fichehalfleft">';
2669 2669
 
2670
-	        if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC))
2671
-	        {
2672
-				print '<a name="builddoc"></a>'; // ancre
2670
+            if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC))
2671
+            {
2672
+                print '<a name="builddoc"></a>'; // ancre
2673 2673
 
2674
-	            /*
2674
+                /*
2675 2675
 	             * Documents generes
2676 2676
 	             */
2677
-	            $filedir=$conf->societe->multidir_output[$object->entity].'/'.$object->id;
2678
-	            $urlsource=$_SERVER["PHP_SELF"]."?socid=".$object->id;
2679
-	            $genallowed=$user->rights->societe->lire;
2680
-	            $delallowed=$user->rights->societe->creer;
2677
+                $filedir=$conf->societe->multidir_output[$object->entity].'/'.$object->id;
2678
+                $urlsource=$_SERVER["PHP_SELF"]."?socid=".$object->id;
2679
+                $genallowed=$user->rights->societe->lire;
2680
+                $delallowed=$user->rights->societe->creer;
2681 2681
 
2682
-	            print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang);
2683
-	        }
2682
+                print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang);
2683
+            }
2684 2684
 
2685
-			// Subsidiaries list
2686
-			if (empty($conf->global->SOCIETE_DISABLE_SUBSIDIARIES))
2687
-			{
2688
-				$result=show_subsidiaries($conf,$langs,$db,$object);
2689
-			}
2685
+            // Subsidiaries list
2686
+            if (empty($conf->global->SOCIETE_DISABLE_SUBSIDIARIES))
2687
+            {
2688
+                $result=show_subsidiaries($conf,$langs,$db,$object);
2689
+            }
2690 2690
 
2691
-			print '</div><div class="fichehalfright"><div class="ficheaddleft">';
2691
+            print '</div><div class="fichehalfright"><div class="ficheaddleft">';
2692 2692
 
2693
-			$MAXEVENT = 10;
2693
+            $MAXEVENT = 10;
2694 2694
 
2695
-			$morehtmlright = '<a href="'.DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id.'">';
2696
-			$morehtmlright.= $langs->trans("SeeAll");
2697
-			$morehtmlright.= '</a>';
2695
+            $morehtmlright = '<a href="'.DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id.'">';
2696
+            $morehtmlright.= $langs->trans("SeeAll");
2697
+            $morehtmlright.= '</a>';
2698 2698
 
2699
-			// List of actions on element
2700
-			include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
2701
-			$formactions = new FormActions($db);
2702
-			$somethingshown = $formactions->showactions($object, '', $socid, 1, '', $MAXEVENT, '', $morehtmlright);		// Show all action for thirdparty
2699
+            // List of actions on element
2700
+            include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
2701
+            $formactions = new FormActions($db);
2702
+            $somethingshown = $formactions->showactions($object, '', $socid, 1, '', $MAXEVENT, '', $morehtmlright);		// Show all action for thirdparty
2703 2703
 
2704
-			print '</div></div></div>';
2704
+            print '</div></div></div>';
2705 2705
 
2706
-			if (! empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD))
2707
-			{
2708
-				// Contacts list
2709
-				if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
2710
-				{
2711
-					$result=show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
2712
-				}
2706
+            if (! empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD))
2707
+            {
2708
+                // Contacts list
2709
+                if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
2710
+                {
2711
+                    $result=show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
2712
+                }
2713 2713
 
2714
-				// Addresses list
2715
-				if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))
2716
-				{
2717
-					$result=show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
2718
-				}
2719
-			}
2720
-		}
2714
+                // Addresses list
2715
+                if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))
2716
+                {
2717
+                    $result=show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
2718
+                }
2719
+            }
2720
+        }
2721 2721
 
2722
-		// Presend form
2723
-		$modelmail='thirdparty';
2724
-		$defaulttopic='Information';
2725
-		$diroutput = $conf->societe->dir_output;
2726
-		$trackid = 'thi'.$object->id;
2722
+        // Presend form
2723
+        $modelmail='thirdparty';
2724
+        $defaulttopic='Information';
2725
+        $diroutput = $conf->societe->dir_output;
2726
+        $trackid = 'thi'.$object->id;
2727 2727
 
2728
-		include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2728
+        include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2729 2729
     }
2730 2730
 }
2731 2731
 
Please login to merge, or discard this patch.
Braces   +291 added lines, -181 removed lines patch added patch discarded remove patch
@@ -45,12 +45,20 @@  discard block
 block discarded – undo
45 45
 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
46 46
 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
47 47
 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
48
-if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
48
+if (! empty($conf->adherent->enabled)) {
49
+    require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
50
+}
49 51
 
50 52
 $langs->loadLangs(array("companies","commercial","bills","banks","users"));
51
-if (! empty($conf->categorie->enabled)) $langs->load("categories");
52
-if (! empty($conf->incoterm->enabled)) $langs->load("incoterm");
53
-if (! empty($conf->notification->enabled)) $langs->load("mails");
53
+if (! empty($conf->categorie->enabled)) {
54
+    $langs->load("categories");
55
+}
56
+if (! empty($conf->incoterm->enabled)) {
57
+    $langs->load("incoterm");
58
+}
59
+if (! empty($conf->notification->enabled)) {
60
+    $langs->load("mails");
61
+}
54 62
 
55 63
 $mesg=''; $error=0; $errors=array();
56 64
 
@@ -60,8 +68,12 @@  discard block
 block discarded – undo
60 68
 $confirm	= GETPOST('confirm','alpha');
61 69
 
62 70
 $socid		= GETPOST('socid','int')?GETPOST('socid','int'):GETPOST('id','int');
63
-if ($user->societe_id) $socid=$user->societe_id;
64
-if (empty($socid) && $action == 'view') $action='create';
71
+if ($user->societe_id) {
72
+    $socid=$user->societe_id;
73
+}
74
+if (empty($socid) && $action == 'view') {
75
+    $action='create';
76
+}
65 77
 
66 78
 $object = new Societe($db);
67 79
 $extrafields = new ExtraFields($db);
@@ -72,7 +84,9 @@  discard block
 block discarded – undo
72 84
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
73 85
 $hookmanager->initHooks(array('thirdpartycard','globalcard'));
74 86
 
75
-if ($socid > 0) $object->fetch($socid);
87
+if ($socid > 0) {
88
+    $object->fetch($socid);
89
+}
76 90
 
77 91
 if (! ($object->id > 0) && $action == 'view')
78 92
 {
@@ -102,7 +116,9 @@  discard block
 block discarded – undo
102 116
 
103 117
 $parameters=array('id'=>$socid, 'objcanvas'=>$objcanvas);
104 118
 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
105
-if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
119
+if ($reshook < 0) {
120
+    setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
121
+}
106 122
 
107 123
 if (empty($reshook))
108 124
 {
@@ -127,8 +143,7 @@  discard block
 block discarded – undo
127 143
 			$langs->load('errors');
128 144
 			$langs->load('companies');
129 145
 			setEventMessages($langs->trans('ErrorThirdPartyIdIsMandatory', $langs->trans('MergeOriginThirdparty')), null, 'errors');
130
-		}
131
-		else
146
+		} else
132 147
 		{
133 148
 			if (!$error && $soc_origin->fetch($soc_origin_id) < 1)
134 149
 			{
@@ -155,7 +170,9 @@  discard block
 block discarded – undo
155 170
 				);
156 171
 				foreach ($listofproperties as $property)
157 172
 				{
158
-					if (empty($object->$property)) $object->$property = $soc_origin->$property;
173
+					if (empty($object->$property)) {
174
+					    $object->$property = $soc_origin->$property;
175
+					}
159 176
 				}
160 177
 
161 178
 				// Concat some data
@@ -172,7 +189,9 @@  discard block
 block discarded – undo
172 189
 				{
173 190
 					foreach ($soc_origin->array_options as $key => $val)
174 191
 					{
175
-					    if (empty($object->array_options[$key])) $object->array_options[$key] = $val;
192
+					    if (empty($object->array_options[$key])) {
193
+					        $object->array_options[$key] = $val;
194
+					    }
176 195
 					}
177 196
 				}
178 197
 
@@ -291,8 +310,7 @@  discard block
 block discarded – undo
291 310
 				{
292 311
 					setEventMessages($langs->trans('ThirdpartiesMergeSuccess'), null, 'mesgs');
293 312
 					$db->commit();
294
-				}
295
-				else
313
+				} else
296 314
 				{
297 315
 				    $langs->load("errors");
298 316
 					setEventMessages($langs->trans('ErrorsThirdpartyMerge'), null, 'errors');
@@ -337,7 +355,9 @@  discard block
 block discarded – undo
337 355
         // Fill array 'array_options' with data from update form
338 356
         $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
339 357
         $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute','none'));
340
-        if ($ret < 0) $error++;
358
+        if ($ret < 0) {
359
+            $error++;
360
+        }
341 361
 
342 362
         if (! $error)
343 363
         {
@@ -349,7 +369,9 @@  discard block
 block discarded – undo
349 369
         	}
350 370
         }
351 371
 
352
-        if ($error) $action = 'edit_extras';
372
+        if ($error) {
373
+            $action = 'edit_extras';
374
+        }
353 375
     }
354 376
 
355 377
     // Add new or update third party
@@ -380,20 +402,22 @@  discard block
 block discarded – undo
380 402
 	        {
381 403
 	        	$ret=$object->fetch($socid);
382 404
 				$object->oldcopy = clone $object;
383
-	        }
384
-			else $object->canvas=$canvas;
405
+	        } else {
406
+			    $object->canvas=$canvas;
407
+			}
385 408
 
386
-	        if (GETPOST("private") == 1)	// Ask to create a contact
409
+	        if (GETPOST("private") == 1) {
410
+	            // Ask to create a contact
387 411
 	        {
388 412
 	            $object->particulier		= GETPOST("private");
413
+	        }
389 414
 
390 415
 	            $object->name				= dolGetFirstLastname(GETPOST('firstname','alpha'),GETPOST('name','alpha'));
391 416
 	            $object->civility_id		= GETPOST('civility_id');	// Note: civility id is a code, not an int
392 417
 	            // Add non official properties
393 418
 	            $object->name_bis			= GETPOST('name','alpha');
394 419
 	            $object->firstname			= GETPOST('firstname','alpha');
395
-	        }
396
-	        else
420
+	        } else
397 421
 	        {
398 422
 	            $object->name				= GETPOST('name', 'alpha');
399 423
 	        }
@@ -470,8 +494,11 @@  discard block
 block discarded – undo
470 494
 				 $error++;
471 495
 			}
472 496
 
473
-	        if (GETPOST('deletephoto')) $object->logo = '';
474
-	        else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
497
+	        if (GETPOST('deletephoto')) {
498
+	            $object->logo = '';
499
+	        } else if (! empty($_FILES['photo']['name'])) {
500
+	            $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
501
+	        }
475 502
 
476 503
 	        // Check parameters
477 504
 	        if (! GETPOST('cancel','alpha'))
@@ -518,8 +545,12 @@  discard block
 block discarded – undo
518 545
 
519 546
                 $db->begin();
520 547
 
521
-                if (empty($object->client))      $object->code_client='';
522
-                if (empty($object->fournisseur)) $object->code_fournisseur='';
548
+                if (empty($object->client)) {
549
+                    $object->code_client='';
550
+                }
551
+                if (empty($object->fournisseur)) {
552
+                    $object->code_fournisseur='';
553
+                }
523 554
 
524 555
                 $result = $object->create($user);
525 556
 
@@ -580,16 +611,14 @@  discard block
 block discarded – undo
580 611
                                 if (! $result > 0)
581 612
                                 {
582 613
                                     $errors[] = "ErrorFailedToSaveFile";
583
-                                }
584
-                                else
614
+                                } else
585 615
                                 {
586 616
                                     // Create thumbs
587 617
                                     $object->addThumbs($newfile);
588 618
                                 }
589 619
                             }
590 620
                         }
591
-                    }
592
-                    else
621
+                    } else
593 622
 					{
594 623
 						switch($_FILES['photo']['error'])
595 624
 						{
@@ -603,12 +632,13 @@  discard block
 block discarded – undo
603 632
 						}
604 633
 	                }
605 634
                     // Gestion du logo de la société
606
-                }
607
-                else
635
+                } else
608 636
 				{
609
-				    if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') // TODO Sometime errors on duplicate on profid and not on code, so we must manage this case
637
+				    if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
638
+				        // TODO Sometime errors on duplicate on profid and not on code, so we must manage this case
610 639
 					{
611 640
 						$duplicate_code_error = true;
641
+				    }
612 642
 						$object->code_fournisseur = null;
613 643
 						$object->code_client = null;
614 644
 					}
@@ -623,21 +653,24 @@  discard block
 block discarded – undo
623 653
 
624 654
                 	if (! empty($backtopage))
625 655
                 	{
626
-                	    if (preg_match('/\?/', $backtopage)) $backtopage.='&socid='.$object->id;
656
+                	    if (preg_match('/\?/', $backtopage)) {
657
+                	        $backtopage.='&socid='.$object->id;
658
+                	    }
627 659
                		    header("Location: ".$backtopage);
628 660
                     	exit;
629
-                	}
630
-                	else
661
+                	} else
631 662
                 	{
632 663
                     	$url=$_SERVER["PHP_SELF"]."?socid=".$object->id;
633
-                    	if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $url=DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
634
-                    	else if ($object->fournisseur == 1) $url=DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
664
+                    	if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
665
+                    	    $url=DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
666
+                    	} else if ($object->fournisseur == 1) {
667
+                    	    $url=DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
668
+                    	}
635 669
 
636 670
                 		header("Location: ".$url);
637 671
                     	exit;
638 672
                 	}
639
-                }
640
-                else
673
+                } else
641 674
                 {
642 675
                     $db->rollback();
643 676
                     $action='create';
@@ -654,8 +687,7 @@  discard block
 block discarded – undo
654 687
                 	{
655 688
                		    header("Location: ".$backtopage);
656 689
                     	exit;
657
-                	}
658
-                	else
690
+                	} else
659 691
                 	{
660 692
                		    header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
661 693
                     	exit;
@@ -663,8 +695,12 @@  discard block
 block discarded – undo
663 695
                 }
664 696
 
665 697
                 // To not set code if third party is not concerned. But if it had values, we keep them.
666
-                if (empty($object->client) && empty($object->oldcopy->code_client))          $object->code_client='';
667
-                if (empty($object->fournisseur)&& empty($object->oldcopy->code_fournisseur)) $object->code_fournisseur='';
698
+                if (empty($object->client) && empty($object->oldcopy->code_client)) {
699
+                    $object->code_client='';
700
+                }
701
+                if (empty($object->fournisseur)&& empty($object->oldcopy->code_fournisseur)) {
702
+                    $object->code_fournisseur='';
703
+                }
668 704
                 //var_dump($object);exit;
669 705
 
670 706
                 $result = $object->update($socid, $user, 1, $object->oldcopy->codeclient_modifiable(), $object->oldcopy->codefournisseur_modifiable(), 'update', 0);
@@ -729,8 +765,7 @@  discard block
 block discarded – undo
729 765
                             if (! $result > 0)
730 766
                             {
731 767
                                 $errors[] = "ErrorFailedToSaveFile";
732
-                            }
733
-                            else
768
+                            } else
734 769
                             {
735 770
                             	// Create thumbs
736 771
                             	$object->addThumbs($newfile);
@@ -746,13 +781,11 @@  discard block
 block discarded – undo
746 781
                                 }
747 782
                             }
748 783
                         }
749
-                    }
750
-                    else
784
+                    } else
751 785
 					{
752 786
                         $errors[] = "ErrorBadImageFormat";
753 787
                     }
754
-                }
755
-                else
788
+                } else
756 789
                 {
757 790
 					switch($_FILES['photo']['error'])
758 791
 					{
@@ -788,21 +821,18 @@  discard block
 block discarded – undo
788 821
                 	{
789 822
                		    header("Location: ".$backtopage);
790 823
                     	exit;
791
-                	}
792
-                	else
824
+                	} else
793 825
                 	{
794 826
                		    header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
795 827
                     	exit;
796 828
                 	}
797
-                }
798
-                else
829
+                } else
799 830
                 {
800 831
                     $object->id = $socid;
801 832
                     $action= "edit";
802 833
                 }
803 834
             }
804
-        }
805
-        else
835
+        } else
806 836
         {
807 837
         	$action = ($action=='add'?'create':'edit');
808 838
         }
@@ -818,8 +848,7 @@  discard block
 block discarded – undo
818 848
         {
819 849
             header("Location: ".DOL_URL_ROOT."/societe/list.php?restore_lastsearch_values=1&delsoc=".urlencode($object->name));
820 850
             exit;
821
-        }
822
-        else
851
+        } else
823 852
         {
824 853
             $langs->load("errors");
825 854
            	setEventMessages($object->error, $object->errors, 'errors');
@@ -872,11 +901,15 @@  discard block
 block discarded – undo
872 901
 if ($socid > 0 && empty($object->id))
873 902
 {
874 903
     $result=$object->fetch($socid);
875
-	if ($result <= 0) dol_print_error('',$object->error);
876
-}
904
+	if ($result <= 0) {
905
+	    dol_print_error('',$object->error);
906
+	}
907
+	}
877 908
 
878 909
 $title=$langs->trans("ThirdParty");
879
-if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$langs->trans('Card');
910
+if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) {
911
+    $title=$object->name." - ".$langs->trans('Card');
912
+}
880 913
 $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
881 914
 llxHeader('',$title,$help_url);
882 915
 
@@ -889,8 +922,7 @@  discard block
 block discarded – undo
889 922
     // -----------------------------------------
890 923
    	$objcanvas->assign_values($action, $object->id, $object->ref);	// Set value for templates
891 924
     $objcanvas->display_canvas($action);							// Show template
892
-}
893
-else
925
+} else
894 926
 {
895 927
     // -----------------------------------------
896 928
     // When used in standard mode
@@ -901,8 +933,12 @@  discard block
 block discarded – undo
901 933
          *  Creation
902 934
          */
903 935
 		$private=GETPOST("private","int");
904
-		if (! empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT) && ! isset($_GET['private']) && ! isset($_POST['private'])) $private=1;
905
-    	if (empty($private)) $private=0;
936
+		if (! empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT) && ! isset($_GET['private']) && ! isset($_POST['private'])) {
937
+		    $private=1;
938
+		}
939
+    	if (empty($private)) {
940
+    	    $private=0;
941
+    	}
906 942
 
907 943
         // Load object modCodeTiers
908 944
         $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
@@ -914,7 +950,9 @@  discard block
 block discarded – undo
914 950
         foreach ($dirsociete as $dirroot)
915 951
         {
916 952
             $res=dol_include_once($dirroot.$module.'.php');
917
-            if ($res) break;
953
+            if ($res) {
954
+                break;
955
+            }
918 956
         }
919 957
         $modCodeClient = new $module;
920 958
         // Load object modCodeFournisseur
@@ -927,7 +965,9 @@  discard block
 block discarded – undo
927 965
         foreach ($dirsociete as $dirroot)
928 966
         {
929 967
             $res=dol_include_once($dirroot.$module.'.php');
930
-            if ($res) break;
968
+            if ($res) {
969
+                break;
970
+            }
931 971
         }
932 972
         $modCodeFournisseur = new $module;
933 973
 
@@ -950,8 +990,7 @@  discard block
 block discarded – undo
950 990
         if(empty($duplicate_code_error)) {
951 991
 	        $object->code_client		= GETPOST('customer_code', 'alpha');
952 992
 	        $object->fournisseur		= GETPOST('fournisseur')?GETPOST('fournisseur'):$object->fournisseur;
953
-        }
954
-		else {
993
+        } else {
955 994
 			setEventMessages($langs->trans('NewCustomerSupplierCodeProposed'),'', 'warnings');
956 995
 		}
957 996
 
@@ -1013,8 +1052,7 @@  discard block
 block discarded – undo
1013 1052
                     if (! $result > 0)
1014 1053
                     {
1015 1054
                         $errors[] = "ErrorFailedToSaveFile";
1016
-                    }
1017
-                    else
1055
+                    } else
1018 1056
                     {
1019 1057
                         // Create thumbs
1020 1058
                         $object->addThumbs($newfile);
@@ -1135,7 +1173,9 @@  discard block
 block discarded – undo
1135 1173
         print '<input type="hidden" name="type" value='.GETPOST("type",'alpha').'>';
1136 1174
         print '<input type="hidden" name="LastName" value="'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName').'">';
1137 1175
         print '<input type="hidden" name="ThirdPartyName" value="'.$langs->trans('ThirdPartyName').'">';
1138
-        if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) print '<input type="hidden" name="code_auto" value="1">';
1176
+        if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) {
1177
+            print '<input type="hidden" name="code_auto" value="1">';
1178
+        }
1139 1179
 
1140 1180
         dol_fiche_head(null, 'card', '', 0, '');
1141 1181
 
@@ -1146,17 +1186,18 @@  discard block
 block discarded – undo
1146 1186
         if ($object->particulier || $private)
1147 1187
         {
1148 1188
 	        print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName','name').'</span>';
1149
-        }
1150
-        else
1189
+        } else
1151 1190
 		{
1152 1191
 			print '<span id="TypeName" class="fieldrequired">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0).'</span>';
1153 1192
         }
1154 1193
 	    print '</td><td'.(empty($conf->global->SOCIETE_USEPREFIX)?' colspan="3"':'').'>';
1155 1194
 	    print '<input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.$object->name.'" autofocus="autofocus"></td>';
1156
-	    if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1195
+	    if (! empty($conf->global->SOCIETE_USEPREFIX)) {
1196
+	        // Old not used prefix field
1157 1197
 	    {
1158 1198
 		    print '<td>'.$langs->trans('Prefix').'</td><td><input type="text" size="5" maxlength="5" name="prefix_comm" value="'.$object->prefix_comm.'"></td>';
1159 1199
 	    }
1200
+	    }
1160 1201
 	    print '</tr>';
1161 1202
 
1162 1203
         // If javascript on, we show option individual
@@ -1180,17 +1221,27 @@  discard block
 block discarded – undo
1180 1221
 	    print '<td class="maxwidthonsmartphone">';
1181 1222
 	    $selected=GETPOST('client','int')!=''?GETPOST('client','int'):$object->client;
1182 1223
         print '<select class="flat" name="client" id="customerprospect">';
1183
-        if (GETPOST("type") == '') print '<option value="-1">&nbsp;</option>';
1184
-        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($selected==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1185
-        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) print '<option value="3"'.($selected==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1186
-        if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($selected==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1224
+        if (GETPOST("type") == '') {
1225
+            print '<option value="-1">&nbsp;</option>';
1226
+        }
1227
+        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
1228
+            print '<option value="2"'.($selected==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1229
+        }
1230
+        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) {
1231
+            print '<option value="3"'.($selected==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1232
+        }
1233
+        if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
1234
+            print '<option value="1"'.($selected==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1235
+        }
1187 1236
         print '<option value="0"'.((string) $selected == '0'?' selected':'').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1188 1237
         print '</select></td>';
1189 1238
 
1190 1239
         print '<td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
1191 1240
         print '<table class="nobordernopadding"><tr><td>';
1192 1241
 		$tmpcode=$object->code_client;
1193
-        if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object,0);
1242
+        if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) {
1243
+            $tmpcode=$modCodeClient->getNextValue($object,0);
1244
+        }
1194 1245
         print '<input type="text" name="customer_code" id="customer_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1195 1246
         print '</td><td>';
1196 1247
         $s=$modCodeClient->getToolTip($langs,$object,0);
@@ -1205,7 +1256,9 @@  discard block
 block discarded – undo
1205 1256
             print '<tr>';
1206 1257
             print '<td>'.$form->editfieldkey('Supplier', 'fournisseur', '', $object, 0, 'string', '', 1).'</td><td>';
1207 1258
             $default = -1;
1208
-            if (! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)) $default=1;
1259
+            if (! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)) {
1260
+                $default=1;
1261
+            }
1209 1262
             print $form->selectyesno("fournisseur", (GETPOST('fournisseur','int')!=''?GETPOST('fournisseur','int'):(GETPOST("type",'alpha') == '' ? $default : $object->fournisseur)), 1, 0, (GETPOST("type",'alpha') == '' ? 1 : 0));
1210 1263
             print '</td>';
1211 1264
             print '<td>';
@@ -1218,7 +1271,9 @@  discard block
 block discarded – undo
1218 1271
             {
1219 1272
 	            print '<table class="nobordernopadding"><tr><td>';
1220 1273
 	            $tmpcode=$object->code_fournisseur;
1221
-	            if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1274
+	            if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) {
1275
+	                $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1276
+	            }
1222 1277
 	            print '<input type="text" name="supplier_code" id="supplier_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1223 1278
 	            print '</td><td>';
1224 1279
 	            $s=$modCodeFournisseur->getToolTip($langs,$object,1);
@@ -1257,7 +1312,9 @@  discard block
 block discarded – undo
1257 1312
         // Country
1258 1313
         print '<tr><td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1259 1314
         print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id));
1260
-        if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1315
+        if ($user->admin) {
1316
+            print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1317
+        }
1261 1318
         print '</td></tr>';
1262 1319
 
1263 1320
         // State
@@ -1266,14 +1323,16 @@  discard block
 block discarded – undo
1266 1323
             if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1267 1324
             {
1268 1325
                 print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1269
-            }
1270
-            else
1326
+            } else
1271 1327
             {
1272 1328
                 print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1273 1329
             }
1274 1330
 
1275
-            if ($object->country_id) print $formcompany->select_state($object->state_id,$object->country_code);
1276
-            else print $countrynotdefined;
1331
+            if ($object->country_id) {
1332
+                print $formcompany->select_state($object->state_id,$object->country_code);
1333
+            } else {
1334
+                print $countrynotdefined;
1335
+            }
1277 1336
             print '</td></tr>';
1278 1337
         }
1279 1338
 
@@ -1326,19 +1385,25 @@  discard block
 block discarded – undo
1326 1385
             {
1327 1386
 	            $key='idprof'.$i;
1328 1387
 
1329
-                if (($j % 2) == 0) print '<tr>';
1388
+                if (($j % 2) == 0) {
1389
+                    print '<tr>';
1390
+                }
1330 1391
 
1331 1392
                 $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
1332 1393
                 print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', (empty($conf->global->$idprof_mandatory)?0:1)).'</td><td>';
1333 1394
 
1334 1395
                 print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
1335 1396
                 print '</td>';
1336
-                if (($j % 2) == 1) print '</tr>';
1397
+                if (($j % 2) == 1) {
1398
+                    print '</tr>';
1399
+                }
1337 1400
                 $j++;
1338 1401
             }
1339 1402
             $i++;
1340 1403
         }
1341
-        if ($j % 2 == 1) print '<td colspan="2"></td></tr>';
1404
+        if ($j % 2 == 1) {
1405
+            print '<td colspan="2"></td></tr>';
1406
+        }
1342 1407
 
1343 1408
         // Vat is used
1344 1409
         print '<tr><td>'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).'</td>';
@@ -1364,8 +1429,7 @@  discard block
 block discarded – undo
1364 1429
                 print "\n";
1365 1430
                 $s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
1366 1431
                 $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
1367
-            }
1368
-            else
1432
+            } else
1369 1433
             {
1370 1434
                 $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
1371 1435
             }
@@ -1383,14 +1447,12 @@  discard block
 block discarded – undo
1383 1447
             print '</td><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
1384 1448
             print $form->selectyesno('localtax2assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0),1);
1385 1449
             print '</td></tr>';
1386
-        }
1387
-        elseif($mysoc->localtax1_assuj=="1")
1450
+        } elseif($mysoc->localtax1_assuj=="1")
1388 1451
         {
1389 1452
             print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td colspan="3">';
1390 1453
             print $form->selectyesno('localtax1assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1:0),1);
1391 1454
             print '</td></tr>';
1392
-        }
1393
-        elseif($mysoc->localtax2_assuj=="1")
1455
+        } elseif($mysoc->localtax2_assuj=="1")
1394 1456
         {
1395 1457
             print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td colspan="3">';
1396 1458
             print $form->selectyesno('localtax2assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0),1);
@@ -1401,11 +1463,15 @@  discard block
 block discarded – undo
1401 1463
         print '<tr><td>'.$form->editfieldkey('ThirdPartyType', 'typent_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">'."\n";
1402 1464
         $sortparam=(empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT); // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on label.
1403 1465
         print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, $sortparam);
1404
-        if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1466
+        if ($user->admin) {
1467
+            print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1468
+        }
1405 1469
         print '</td>';
1406 1470
         print '<td>'.$form->editfieldkey('Staff', 'effectif_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
1407 1471
         print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id);
1408
-        if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1472
+        if ($user->admin) {
1473
+            print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1474
+        }
1409 1475
         print '</td></tr>';
1410 1476
 
1411 1477
         // Legal Form
@@ -1414,8 +1480,7 @@  discard block
 block discarded – undo
1414 1480
         if ($object->country_id)
1415 1481
         {
1416 1482
             print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code');
1417
-        }
1418
-        else
1483
+        } else
1419 1484
         {
1420 1485
             print $countrynotdefined;
1421 1486
         }
@@ -1512,8 +1577,7 @@  discard block
 block discarded – undo
1512 1577
         {
1513 1578
             print ' &nbsp; &nbsp; ';
1514 1579
             print '<input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'">';
1515
-        }
1516
-        else
1580
+        } else
1517 1581
         {
1518 1582
             print ' &nbsp; &nbsp; ';
1519 1583
             print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
@@ -1521,8 +1585,7 @@  discard block
 block discarded – undo
1521 1585
         print '</div>'."\n";
1522 1586
 
1523 1587
         print '</form>'."\n";
1524
-    }
1525
-    elseif ($action == 'edit')
1588
+    } elseif ($action == 'edit')
1526 1589
     {
1527 1590
         //print load_fiche_titre($langs->trans("EditCompany"));
1528 1591
 
@@ -1543,7 +1606,9 @@  discard block
 block discarded – undo
1543 1606
             foreach ($dirsociete as $dirroot)
1544 1607
             {
1545 1608
                 $res=dol_include_once($dirroot.$module.'.php');
1546
-                if ($res) break;
1609
+                if ($res) {
1610
+                    break;
1611
+                }
1547 1612
             }
1548 1613
             $modCodeClient = new $module($db);
1549 1614
             // We verified if the tag prefix is used
@@ -1560,7 +1625,9 @@  discard block
 block discarded – undo
1560 1625
             foreach ($dirsociete as $dirroot)
1561 1626
             {
1562 1627
                 $res=dol_include_once($dirroot.$module.'.php');
1563
-                if ($res) break;
1628
+                if ($res) {
1629
+                    break;
1630
+                }
1564 1631
             }
1565 1632
             $modCodeFournisseur = new $module($db);
1566 1633
             // On verifie si la balise prefix est utilisee
@@ -1638,10 +1705,10 @@  discard block
 block discarded – undo
1638 1705
 
1639 1706
             if($object->localtax1_assuj==0){
1640 1707
             	$sub=0;
1641
-            }else{$sub=1;}
1708
+            } else{$sub=1;}
1642 1709
             if($object->localtax2_assuj==0){
1643 1710
             	$sub2=0;
1644
-            }else{$sub2=1;}
1711
+            } else{$sub2=1;}
1645 1712
 
1646 1713
             if ($conf->use_javascript_ajax)
1647 1714
             {
@@ -1726,7 +1793,9 @@  discard block
 block discarded – undo
1726 1793
             print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1727 1794
             print '<input type="hidden" name="socid" value="'.$object->id.'">';
1728 1795
             print '<input type="hidden" name="entity" value="'.$object->entity.'">';
1729
-            if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) print '<input type="hidden" name="code_auto" value="1">';
1796
+            if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) {
1797
+                print '<input type="hidden" name="code_auto" value="1">';
1798
+            }
1730 1799
 
1731 1800
 
1732 1801
             dol_fiche_head($head, 'card', $langs->trans("ThirdParty"), 0, 'company');
@@ -1751,16 +1820,17 @@  discard block
 block discarded – undo
1751 1820
 	        print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.dol_escape_htmltag($object->name_alias).'"></td></tr>';
1752 1821
 
1753 1822
             // Prefix
1754
-            if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1823
+            if (! empty($conf->global->SOCIETE_USEPREFIX)) {
1824
+                // Old not used prefix field
1755 1825
             {
1756 1826
                 print '<tr><td>'.$form->editfieldkey('Prefix', 'prefix', '', $object, 0).'</td><td colspan="3">';
1827
+            }
1757 1828
                 // It does not change the prefix mode using the auto numbering prefix
1758 1829
                 if (($prefixCustomerIsUsed || $prefixSupplierIsUsed) && $object->prefix_comm)
1759 1830
                 {
1760 1831
                     print '<input type="hidden" name="prefix_comm" value="'.dol_escape_htmltag($object->prefix_comm).'">';
1761 1832
                     print $object->prefix_comm;
1762
-                }
1763
-                else
1833
+                } else
1764 1834
                 {
1765 1835
                     print '<input type="text" size="5" maxlength="5" name="prefix_comm" id="prefix" value="'.dol_escape_htmltag($object->prefix_comm).'">';
1766 1836
                 }
@@ -1770,9 +1840,15 @@  discard block
 block discarded – undo
1770 1840
             // Prospect/Customer
1771 1841
             print '<tr><td>'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).'</td>';
1772 1842
 	        print '<td class="maxwidthonsmartphone"><select class="flat" name="client" id="customerprospect">';
1773
-            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($object->client==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1774
-            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="3"'.($object->client==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1775
-            if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($object->client==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1843
+            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
1844
+                print '<option value="2"'.($object->client==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1845
+            }
1846
+            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
1847
+                print '<option value="3"'.($object->client==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1848
+            }
1849
+            if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
1850
+                print '<option value="1"'.($object->client==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1851
+            }
1776 1852
             print '<option value="0"'.($object->client==0?' selected':'').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1777 1853
             print '</select></td>';
1778 1854
             print '<td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
@@ -1781,15 +1857,18 @@  discard block
 block discarded – undo
1781 1857
             if ((!$object->code_client || $object->code_client == -1) && $modCodeClient->code_auto)
1782 1858
             {
1783 1859
                 $tmpcode=$object->code_client;
1784
-                if (empty($tmpcode) && ! empty($object->oldcopy->code_client)) $tmpcode=$object->oldcopy->code_client; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1785
-                if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object,0);
1860
+                if (empty($tmpcode) && ! empty($object->oldcopy->code_client)) {
1861
+                    $tmpcode=$object->oldcopy->code_client;
1862
+                }
1863
+                // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1864
+                if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) {
1865
+                    $tmpcode=$modCodeClient->getNextValue($object,0);
1866
+                }
1786 1867
                 print '<input type="text" name="customer_code" id="customer_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1787
-            }
1788
-            else if ($object->codeclient_modifiable())
1868
+            } else if ($object->codeclient_modifiable())
1789 1869
             {
1790 1870
             	print '<input type="text" name="customer_code" id="customer_code" size="16" value="'.dol_escape_htmltag($object->code_client).'" maxlength="15">';
1791
-            }
1792
-            else
1871
+            } else
1793 1872
             {
1794 1873
                 print $object->code_client;
1795 1874
                 print '<input type="hidden" name="customer_code" value="'.dol_escape_htmltag($object->code_client).'">';
@@ -1821,15 +1900,18 @@  discard block
 block discarded – undo
1821 1900
 	                if ((!$object->code_fournisseur || $object->code_fournisseur == -1) && $modCodeFournisseur->code_auto)
1822 1901
 	                {
1823 1902
 	                    $tmpcode=$object->code_fournisseur;
1824
-	                    if (empty($tmpcode) && ! empty($object->oldcopy->code_fournisseur)) $tmpcode=$object->oldcopy->code_fournisseur; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1825
-	                    if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1903
+	                    if (empty($tmpcode) && ! empty($object->oldcopy->code_fournisseur)) {
1904
+	                        $tmpcode=$object->oldcopy->code_fournisseur;
1905
+	                    }
1906
+	                    // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1907
+	                    if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) {
1908
+	                        $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1909
+	                    }
1826 1910
 	                    print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1827
-	                }
1828
-	                else if ($object->codefournisseur_modifiable())
1911
+	                } else if ($object->codefournisseur_modifiable())
1829 1912
 	                {
1830 1913
 	                    print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.$object->code_fournisseur.'" maxlength="15">';
1831
-	                }
1832
-	                else
1914
+	                } else
1833 1915
 	              {
1834 1916
 	                    print $object->code_fournisseur;
1835 1917
 	                    print '<input type="hidden" name="supplier_code" value="'.$object->code_fournisseur.'">';
@@ -1871,7 +1953,9 @@  discard block
 block discarded – undo
1871 1953
             // Country
1872 1954
             print '<tr><td>'.$form->editfieldkey('Country', 'selectcounty_id', '', $object, 0).'</td><td colspan="3">';
1873 1955
             print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id),'country_id');
1874
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1956
+            if ($user->admin) {
1957
+                print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1958
+            }
1875 1959
             print '</td></tr>';
1876 1960
 
1877 1961
             // State
@@ -1880,8 +1964,7 @@  discard block
 block discarded – undo
1880 1964
                 if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1881 1965
                 {
1882 1966
                     print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td colspan="3">';
1883
-                }
1884
-                else
1967
+                } else
1885 1968
                 {
1886 1969
                     print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td colspan="3">';
1887 1970
                 }
@@ -1933,18 +2016,24 @@  discard block
 block discarded – undo
1933 2016
                 {
1934 2017
 	                $key='idprof'.$i;
1935 2018
 
1936
-	                if (($j % 2) == 0) print '<tr>';
2019
+	                if (($j % 2) == 0) {
2020
+	                    print '<tr>';
2021
+	                }
1937 2022
 
1938 2023
 	                $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
1939 2024
 	                print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', ! (empty($conf->global->$idprof_mandatory) || ! $object->isACompany())).'</td><td>';
1940 2025
 	                print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
1941 2026
                     print '</td>';
1942
-                    if (($j % 2) == 1) print '</tr>';
2027
+                    if (($j % 2) == 1) {
2028
+                        print '</tr>';
2029
+                    }
1943 2030
                     $j++;
1944 2031
                 }
1945 2032
                 $i++;
1946 2033
             }
1947
-            if ($j % 2 == 1) print '<td colspan="2"></td></tr>';
2034
+            if ($j % 2 == 1) {
2035
+                print '<td colspan="2"></td></tr>';
2036
+            }
1948 2037
 
1949 2038
             // VAT is used
1950 2039
             print '<tr><td>'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).'</td><td colspan="3">';
@@ -1974,8 +2063,7 @@  discard block
 block discarded – undo
1974 2063
                     print '</span>';
1975 2064
                 }
1976 2065
                 print '</td></tr>';
1977
-            }
1978
-            elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
2066
+            } elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
1979 2067
             {
1980 2068
                 print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed",$mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td colspan="3">';
1981 2069
                 print $form->selectyesno('localtax1assuj_value',$object->localtax1_assuj,1);
@@ -1986,8 +2074,7 @@  discard block
 block discarded – undo
1986 2074
                     print '</span>';
1987 2075
                 }
1988 2076
                 print '</td></tr>';
1989
-            }
1990
-            elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
2077
+            } elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
1991 2078
             {
1992 2079
                 print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed",$mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td colspan="3">';
1993 2080
                 print $form->selectyesno('localtax2assuj_value',$object->localtax2_assuj,1);
@@ -2020,8 +2107,7 @@  discard block
 block discarded – undo
2020 2107
                     print "\n";
2021 2108
                     $s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
2022 2109
                     $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
2023
-                }
2024
-                else
2110
+                } else
2025 2111
                 {
2026 2112
                     $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
2027 2113
                 }
@@ -2033,11 +2119,15 @@  discard block
 block discarded – undo
2033 2119
             // Type - Size
2034 2120
             print '<tr><td>'.$form->editfieldkey('ThirdPartyType', 'typent_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
2035 2121
             print $form->selectarray("typent_id",$formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
2036
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
2122
+            if ($user->admin) {
2123
+                print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
2124
+            }
2037 2125
             print '</td>';
2038 2126
             print '<td>'.$form->editfieldkey('Staff', 'effectif_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
2039 2127
             print $form->selectarray("effectif_id",$formcompany->effectif_array(0), $object->effectif_id);
2040
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
2128
+            if ($user->admin) {
2129
+                print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
2130
+            }
2041 2131
             print '</td></tr>';
2042 2132
 
2043 2133
             // Juridical type
@@ -2131,13 +2221,19 @@  discard block
 block discarded – undo
2131 2221
             print '<tr class="hideonsmartphone">';
2132 2222
             print '<td>'.$form->editfieldkey('Logo', 'photoinput', '', $object, 0).'</td>';
2133 2223
             print '<td colspan="3">';
2134
-            if ($object->logo) print $form->showphoto('societe',$object);
2224
+            if ($object->logo) {
2225
+                print $form->showphoto('societe',$object);
2226
+            }
2135 2227
             $caneditfield=1;
2136 2228
             if ($caneditfield)
2137 2229
             {
2138
-                if ($object->logo) print "<br>\n";
2230
+                if ($object->logo) {
2231
+                    print "<br>\n";
2232
+                }
2139 2233
                 print '<table class="nobordernopadding">';
2140
-                if ($object->logo) print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
2234
+                if ($object->logo) {
2235
+                    print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
2236
+                }
2141 2237
                 //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
2142 2238
                 print '<tr><td><input type="file" class="flat" name="photo" id="photoinput"></td></tr>';
2143 2239
                 print '</table>';
@@ -2151,7 +2247,9 @@  discard block
 block discarded – undo
2151 2247
             print '<td colspan="3" class="maxwidthonsmartphone">';
2152 2248
             $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, '', 0, '', '', 0, 1);
2153 2249
             $arrayselected = GETPOST('commercial', 'array');
2154
-            if (empty($arrayselected)) $arrayselected = $object->getSalesRepresentatives($user, 1);
2250
+            if (empty($arrayselected)) {
2251
+                $arrayselected = $object->getSalesRepresentatives($user, 1);
2252
+            }
2155 2253
             print $form->multiselectarray('commercial', $userlist, $arrayselected, null, null, null, null, "90%");
2156 2254
             print '</td></tr>';
2157 2255
 
@@ -2168,14 +2266,15 @@  discard block
 block discarded – undo
2168 2266
 
2169 2267
             print '</form>';
2170 2268
         }
2171
-    }
2172
-    else
2269
+    } else
2173 2270
     {
2174 2271
     	/*
2175 2272
          * View
2176 2273
          */
2177 2274
 
2178
-        if (!empty($object->id)) $res=$object->fetch_optionals();
2275
+        if (!empty($object->id)) {
2276
+            $res=$object->fetch_optionals();
2277
+        }
2179 2278
         //if ($res < 0) { dol_print_error($db); exit; }
2180 2279
 
2181 2280
 
@@ -2230,9 +2329,11 @@  discard block
 block discarded – undo
2230 2329
     	}
2231 2330
 
2232 2331
     	// Prefix
2233
-        if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
2332
+        if (! empty($conf->global->SOCIETE_USEPREFIX)) {
2333
+            // Old not used prefix field
2234 2334
         {
2235 2335
             print '<tr><td>'.$langs->trans('Prefix').'</td><td>'.$object->prefix_comm.'</td>';
2336
+        }
2236 2337
             print $htmllogobar; $htmllogobar='';
2237 2338
             print '</tr>';
2238 2339
         }
@@ -2243,7 +2344,9 @@  discard block
 block discarded – undo
2243 2344
             print '<tr><td>';
2244 2345
             print $langs->trans('CustomerCode').'</td><td>';
2245 2346
             print $object->code_client;
2246
-            if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
2347
+            if ($object->check_codeclient() <> 0) {
2348
+                print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
2349
+            }
2247 2350
             print '</td>';
2248 2351
             print $htmllogobar; $htmllogobar='';
2249 2352
             print '</tr>';
@@ -2255,7 +2358,9 @@  discard block
 block discarded – undo
2255 2358
             print '<tr><td>';
2256 2359
             print $langs->trans('SupplierCode').'</td><td>';
2257 2360
             print $object->code_fournisseur;
2258
-            if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
2361
+            if ($object->check_codefournisseur() <> 0) {
2362
+                print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
2363
+            }
2259 2364
             print '</td>';
2260 2365
             print $htmllogobar; $htmllogobar='';
2261 2366
             print '</tr>';
@@ -2267,7 +2372,9 @@  discard block
 block discarded – undo
2267 2372
             print '<tr><td>';
2268 2373
             print $langs->trans('Gencod').'</td><td>'.$object->barcode;
2269 2374
             print '</td>';
2270
-			if ($htmllogobar) $htmllogobar.=$form->showbarcode($object);
2375
+			if ($htmllogobar) {
2376
+			    $htmllogobar.=$form->showbarcode($object);
2377
+			}
2271 2378
             print $htmllogobar;
2272 2379
 			$htmllogobar='';
2273 2380
             print '</tr>';
@@ -2287,8 +2394,11 @@  discard block
 block discarded – undo
2287 2394
                 print $object->$key;
2288 2395
                 if ($object->$key)
2289 2396
                 {
2290
-                    if ($object->id_prof_check($i,$object) > 0) print ' &nbsp; '.$object->id_prof_url($i,$object);
2291
-                    else print ' <font class="error">('.$langs->trans("ErrorWrongValue").')</font>';
2397
+                    if ($object->id_prof_check($i,$object) > 0) {
2398
+                        print ' &nbsp; '.$object->id_prof_url($i,$object);
2399
+                    } else {
2400
+                        print ' <font class="error">('.$langs->trans("ErrorWrongValue").')</font>';
2401
+                    }
2292 2402
                 }
2293 2403
                 print '</td>';
2294 2404
                 //if (($j % 2) == 1) print '</tr>';
@@ -2337,8 +2447,7 @@  discard block
 block discarded – undo
2337 2447
 			            print '<td align="left">';
2338 2448
 			            $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2339 2449
 			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2340
-			        }
2341
-			        else
2450
+			        } else
2342 2451
 			        {
2343 2452
 			            print '<td>'.$object->localtax1_value.'</td>';
2344 2453
 			        }
@@ -2354,13 +2463,12 @@  discard block
 block discarded – undo
2354 2463
 			            print '<td align="left">';
2355 2464
 			            $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2356 2465
 			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2357
-			        }else{
2466
+			        } else{
2358 2467
 			            print '<td>'.$object->localtax2_value.'</td>';
2359 2468
 			        }
2360 2469
 			        print '</tr></form>';
2361 2470
 			    }
2362
-			}
2363
-			elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
2471
+			} elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
2364 2472
 			{
2365 2473
 			    print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
2366 2474
 			    print yn($object->localtax1_assuj);
@@ -2375,13 +2483,12 @@  discard block
 block discarded – undo
2375 2483
 			            print '<td align="left">';
2376 2484
 			            $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2377 2485
 			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2378
-			        }else{
2486
+			        } else{
2379 2487
 			            print '<td>'.$object->localtax1_value.'</td>';
2380 2488
 			        }
2381 2489
 			        print '</tr></form>';
2382 2490
 			    }
2383
-			}
2384
-			elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
2491
+			} elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
2385 2492
 			{
2386 2493
 			    print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
2387 2494
 			    print yn($object->localtax2_assuj);
@@ -2397,7 +2504,7 @@  discard block
 block discarded – undo
2397 2504
 			            print '<td align="left">';
2398 2505
 			            $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2399 2506
 			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2400
-			        }else{
2507
+			        } else{
2401 2508
 			            print '<td>'.$object->localtax2_value.'</td>';
2402 2509
 			        }
2403 2510
 			        print '</tr></form>';
@@ -2429,15 +2536,13 @@  discard block
 block discarded – undo
2429 2536
                     print "\n";
2430 2537
                     $s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT( $(\'#tva_intra\').val() );">'.$langs->trans("VATIntraCheck").'</a>';
2431 2538
                     $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
2432
-                }
2433
-                else
2539
+                } else
2434 2540
                 {
2435 2541
                     $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
2436 2542
                 }
2437 2543
             }
2438 2544
             print $s;
2439
-        }
2440
-        else
2545
+        } else
2441 2546
         {
2442 2547
             print '&nbsp;';
2443 2548
         }
@@ -2483,8 +2588,11 @@  discard block
 block discarded – undo
2483 2588
 
2484 2589
         // Capital
2485 2590
         print '<tr><td>'.$langs->trans('Capital').'</td><td>';
2486
-        if ($object->capital) print price($object->capital,'',$langs,0,-1,-1, $conf->currency);
2487
-        else print '&nbsp;';
2591
+        if ($object->capital) {
2592
+            print price($object->capital,'',$langs,0,-1,-1, $conf->currency);
2593
+        } else {
2594
+            print '&nbsp;';
2595
+        }
2488 2596
         print '</td></tr>';
2489 2597
 
2490 2598
         // Default language
@@ -2507,16 +2615,18 @@  discard block
 block discarded – undo
2507 2615
         	print '<table width="100%" class="nobordernopadding"><tr><td>';
2508 2616
         	print $langs->trans('IncotermLabel');
2509 2617
         	print '<td><td align="right">';
2510
-        	if ($user->rights->societe->creer) print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$object->id.'&action=editincoterm">'.img_edit('',1).'</a>';
2511
-        	else print '&nbsp;';
2618
+        	if ($user->rights->societe->creer) {
2619
+        	    print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$object->id.'&action=editincoterm">'.img_edit('',1).'</a>';
2620
+        	} else {
2621
+        	    print '&nbsp;';
2622
+        	}
2512 2623
         	print '</td></tr></table>';
2513 2624
         	print '</td>';
2514 2625
         	print '<td colspan="3">';
2515 2626
         	if ($action != 'editincoterm')
2516 2627
         	{
2517 2628
         		print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1);
2518
-        	}
2519
-        	else
2629
+        	} else
2520 2630
         	{
2521 2631
         		print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?socid='.$object->id);
2522 2632
         	}
@@ -2545,14 +2655,15 @@  discard block
 block discarded – undo
2545 2655
         	print '<table class="nobordernopadding" width="100%"><tr><td>';
2546 2656
         	print $langs->trans('ParentCompany');
2547 2657
         	print '</td>';
2548
-        	if ($action != 'editparentcompany') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</a></td>';
2658
+        	if ($action != 'editparentcompany') {
2659
+        	    print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</a></td>';
2660
+        	}
2549 2661
         	print '</tr></table>';
2550 2662
         	print '</td><td colspan="3">';
2551 2663
         	if ($action == 'editparentcompany')
2552 2664
         	{
2553 2665
         		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'editparentcompany','s.rowid <> '.$object->id,1);
2554
-        	}
2555
-        	else
2666
+        	} else
2556 2667
         	{
2557 2668
         		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'none','s.rowid <> '.$object->id,1);
2558 2669
         	}
@@ -2575,8 +2686,7 @@  discard block
 block discarded – undo
2575 2686
             {
2576 2687
                 $adh->ref=$adh->getFullName($langs);
2577 2688
                 print $adh->getNomUrl(1);
2578
-            }
2579
-            else
2689
+            } else
2580 2690
             {
2581 2691
                 print '<span class="opacitymedium">'.$langs->trans("ThirdpartyNotLinkedToMember").'</span>';
2582 2692
             }
@@ -2625,8 +2735,7 @@  discard block
 block discarded – undo
2625 2735
 		        {
2626 2736
 		        	$langs->load("mails");
2627 2737
 		        	print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'&amp;action=presend&amp;mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';
2628
-		        }
2629
-		        else
2738
+		        } else
2630 2739
 				{
2631 2740
 		        	$langs->load("mails");
2632 2741
 		       		print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans('SendMail').'</a></div>';
@@ -2644,11 +2753,12 @@  discard block
 block discarded – undo
2644 2753
 
2645 2754
 		        if ($user->rights->societe->supprimer)
2646 2755
 		        {
2647
-		            if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))	// We can't use preloaded confirm form with jmobile
2756
+		            if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)) {
2757
+		                // We can't use preloaded confirm form with jmobile
2648 2758
 		            {
2649 2759
 		                print '<div class="inline-block divButAction"><span id="action-delete" class="butActionDelete">'.$langs->trans('Delete').'</span></div>'."\n";
2650 2760
 		            }
2651
-		            else
2761
+		            } else
2652 2762
 					{
2653 2763
 		                print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a></div>'."\n";
2654 2764
 		            }
Please login to merge, or discard this patch.
Spacing   +482 added lines, -482 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 
38 38
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
39 39
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
40
-require DOL_BASE_PATH . 'main.inc.php';
40
+require DOL_BASE_PATH.'main.inc.php';
41 41
 
42 42
 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
43 43
 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
@@ -49,36 +49,36 @@  discard block
 block discarded – undo
49 49
 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
50 50
 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
51 51
 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
52
-if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
52
+if (!empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
53 53
 
54
-$langs->loadLangs(array("companies","commercial","bills","banks","users"));
55
-if (! empty($conf->categorie->enabled)) $langs->load("categories");
56
-if (! empty($conf->incoterm->enabled)) $langs->load("incoterm");
57
-if (! empty($conf->notification->enabled)) $langs->load("mails");
54
+$langs->loadLangs(array("companies", "commercial", "bills", "banks", "users"));
55
+if (!empty($conf->categorie->enabled)) $langs->load("categories");
56
+if (!empty($conf->incoterm->enabled)) $langs->load("incoterm");
57
+if (!empty($conf->notification->enabled)) $langs->load("mails");
58 58
 
59
-$mesg=''; $error=0; $errors=array();
59
+$mesg = ''; $error = 0; $errors = array();
60 60
 
61
-$action		= (GETPOST('action','aZ09') ? GETPOST('action','aZ09') : 'view');
62
-$cancel		= GETPOST('cancel','alpha');
63
-$backtopage	= GETPOST('backtopage','alpha');
64
-$confirm	= GETPOST('confirm','alpha');
61
+$action		= (GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view');
62
+$cancel		= GETPOST('cancel', 'alpha');
63
+$backtopage = GETPOST('backtopage', 'alpha');
64
+$confirm	= GETPOST('confirm', 'alpha');
65 65
 
66
-$socid		= GETPOST('socid','int')?GETPOST('socid','int'):GETPOST('id','int');
67
-if ($user->societe_id) $socid=$user->societe_id;
68
-if (empty($socid) && $action == 'view') $action='create';
66
+$socid = GETPOST('socid', 'int') ?GETPOST('socid', 'int') : GETPOST('id', 'int');
67
+if ($user->societe_id) $socid = $user->societe_id;
68
+if (empty($socid) && $action == 'view') $action = 'create';
69 69
 
70 70
 $object = new Societe($db);
71 71
 $extrafields = new ExtraFields($db);
72 72
 
73 73
 // fetch optionals attributes and labels
74
-$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
74
+$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
75 75
 
76 76
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
77
-$hookmanager->initHooks(array('thirdpartycard','globalcard'));
77
+$hookmanager->initHooks(array('thirdpartycard', 'globalcard'));
78 78
 
79 79
 if ($socid > 0) $object->fetch($socid);
80 80
 
81
-if (! ($object->id > 0) && $action == 'view')
81
+if (!($object->id > 0) && $action == 'view')
82 82
 {
83 83
 	$langs->load("errors");
84 84
 	print($langs->trans('ErrorRecordNotFound'));
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
 
88 88
 // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
89 89
 $object->getCanvas($socid);
90
-$canvas = $object->canvas?$object->canvas:GETPOST("canvas");
91
-$objcanvas=null;
92
-if (! empty($canvas))
90
+$canvas = $object->canvas ? $object->canvas : GETPOST("canvas");
91
+$objcanvas = null;
92
+if (!empty($canvas))
93 93
 {
94 94
     require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
95 95
     $objcanvas = new Canvas($db, $action);
@@ -104,16 +104,16 @@  discard block
 block discarded – undo
104 104
  * Actions
105 105
  */
106 106
 
107
-$parameters=array('id'=>$socid, 'objcanvas'=>$objcanvas);
108
-$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
107
+$parameters = array('id'=>$socid, 'objcanvas'=>$objcanvas);
108
+$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
109 109
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
110 110
 
111 111
 if (empty($reshook))
112 112
 {
113 113
     if ($cancel)
114 114
     {
115
-        $action='';
116
-        if (! empty($backtopage))
115
+        $action = '';
116
+        if (!empty($backtopage))
117 117
         {
118 118
             header("Location: ".$backtopage);
119 119
             exit;
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 				// Recopy some data
150 150
 				$object->client = $object->client | $soc_origin->client;
151 151
 				$object->fournisseur = $object->fournisseur | $soc_origin->fournisseur;
152
-				$listofproperties=array(
152
+				$listofproperties = array(
153 153
 					'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'skype', 'twitter', 'facebook', 'url', 'barcode',
154 154
 					'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6',
155 155
 					'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'remise_supplier_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis',
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 				}
164 164
 
165 165
 				// Concat some data
166
-				$listofproperties=array(
166
+				$listofproperties = array(
167 167
 				    'note_public', 'note_private'
168 168
 				);
169 169
 				foreach ($listofproperties as $property)
@@ -185,12 +185,12 @@  discard block
 block discarded – undo
185 185
 
186 186
 				$custcats_ori = $static_cat->containing($soc_origin->id, 'customer', 'id');
187 187
 				$custcats = $static_cat->containing($object->id, 'customer', 'id');
188
-				$custcats = array_merge($custcats,$custcats_ori);
188
+				$custcats = array_merge($custcats, $custcats_ori);
189 189
 				$object->setCategories($custcats, 'customer');
190 190
 
191 191
 				$suppcats_ori = $static_cat->containing($soc_origin->id, 'supplier', 'id');
192 192
 				$suppcats = $static_cat->containing($object->id, 'supplier', 'id');
193
-				$suppcats = array_merge($suppcats,$suppcats_ori);
193
+				$suppcats = array_merge($suppcats, $suppcats_ori);
194 194
 				$object->setCategories($suppcats, 'supplier');
195 195
 
196 196
 				// If thirdparty has a new code that is same than origin, we clean origin code to avoid duplicate key from database unique keys.
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 				}
214 214
 
215 215
 				// Move links
216
-				if (! $error)
216
+				if (!$error)
217 217
 				{
218 218
 					$objects = array(
219 219
 						'Adherent' => '/adherents/class/adherent.class.php',
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 				}
254 254
 
255 255
 				// External modules should update their ones too
256
-				if (! $error)
256
+				if (!$error)
257 257
 				{
258 258
 					$reshook = $hookmanager->executeHooks('replaceThirdparty', array(
259 259
 						'soc_origin' => $soc_origin->id,
@@ -268,12 +268,12 @@  discard block
 block discarded – undo
268 268
 				}
269 269
 
270 270
 
271
-				if (! $error)
271
+				if (!$error)
272 272
 				{
273
-					$object->context=array('merge'=>1, 'mergefromid'=>$soc_origin->id);
273
+					$object->context = array('merge'=>1, 'mergefromid'=>$soc_origin->id);
274 274
 
275 275
 					// Call trigger
276
-					$result=$object->call_trigger('COMPANY_MODIFY',$user);
276
+					$result = $object->call_trigger('COMPANY_MODIFY', $user);
277 277
 					if ($result < 0)
278 278
 					{
279 279
 						setEventMessages($object->error, $object->errors, 'errors');
@@ -309,28 +309,28 @@  discard block
 block discarded – undo
309 309
     if (GETPOST('getcustomercode'))
310 310
     {
311 311
         // We defined value code_client
312
-        $_POST["customer_code"]="Acompleter";
312
+        $_POST["customer_code"] = "Acompleter";
313 313
     }
314 314
 
315 315
     if (GETPOST('getsuppliercode'))
316 316
     {
317 317
         // We defined value code_fournisseur
318
-        $_POST["supplier_code"]="Acompleter";
318
+        $_POST["supplier_code"] = "Acompleter";
319 319
     }
320 320
 
321
-    if($action=='set_localtax1')
321
+    if ($action == 'set_localtax1')
322 322
     {
323 323
     	//obtidre selected del combobox
324
-    	$value=GETPOST('lt1');
324
+    	$value = GETPOST('lt1');
325 325
     	$object->fetch($socid);
326
-    	$res=$object->setValueFrom('localtax1_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
326
+    	$res = $object->setValueFrom('localtax1_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
327 327
     }
328
-    if($action=='set_localtax2')
328
+    if ($action == 'set_localtax2')
329 329
     {
330 330
     	//obtidre selected del combobox
331
-    	$value=GETPOST('lt2');
331
+    	$value = GETPOST('lt2');
332 332
     	$object->fetch($socid);
333
-    	$res=$object->setValueFrom('localtax2_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
333
+    	$res = $object->setValueFrom('localtax2_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
334 334
     }
335 335
 
336 336
     if ($action == 'update_extras') {
@@ -340,10 +340,10 @@  discard block
 block discarded – undo
340 340
 
341 341
         // Fill array 'array_options' with data from update form
342 342
         $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
343
-        $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute','none'));
343
+        $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute', 'none'));
344 344
         if ($ret < 0) $error++;
345 345
 
346
-        if (! $error)
346
+        if (!$error)
347 347
         {
348 348
         	$result = $object->insertExtraFields('COMPANY_MODIFY');
349 349
         	if ($result < 0)
@@ -357,12 +357,12 @@  discard block
 block discarded – undo
357 357
     }
358 358
 
359 359
     // Add new or update third party
360
-    if ((! GETPOST('getcustomercode') && ! GETPOST('getsuppliercode'))
360
+    if ((!GETPOST('getcustomercode') && !GETPOST('getsuppliercode'))
361 361
     && ($action == 'add' || $action == 'update') && $user->rights->societe->creer)
362 362
     {
363 363
         require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
364 364
 
365
-        if (! GETPOST('name'))
365
+        if (!GETPOST('name'))
366 366
         {
367 367
             setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdPartyName")), null, 'errors');
368 368
             $error++;
@@ -378,41 +378,41 @@  discard block
 block discarded – undo
378 378
             $error++;
379 379
         }
380 380
 
381
-        if (! $error)
381
+        if (!$error)
382 382
         {
383 383
         	if ($action == 'update')
384 384
 	        {
385
-	        	$ret=$object->fetch($socid);
385
+	        	$ret = $object->fetch($socid);
386 386
 				$object->oldcopy = clone $object;
387 387
 	        }
388
-			else $object->canvas=$canvas;
388
+			else $object->canvas = $canvas;
389 389
 
390 390
 	        if (GETPOST("private") == 1)	// Ask to create a contact
391 391
 	        {
392 392
 	            $object->particulier		= GETPOST("private");
393 393
 
394
-	            $object->name				= dolGetFirstLastname(GETPOST('firstname','alpha'),GETPOST('name','alpha'));
395
-	            $object->civility_id		= GETPOST('civility_id');	// Note: civility id is a code, not an int
394
+	            $object->name = dolGetFirstLastname(GETPOST('firstname', 'alpha'), GETPOST('name', 'alpha'));
395
+	            $object->civility_id		= GETPOST('civility_id'); // Note: civility id is a code, not an int
396 396
 	            // Add non official properties
397
-	            $object->name_bis			= GETPOST('name','alpha');
398
-	            $object->firstname			= GETPOST('firstname','alpha');
397
+	            $object->name_bis = GETPOST('name', 'alpha');
398
+	            $object->firstname = GETPOST('firstname', 'alpha');
399 399
 	        }
400 400
 	        else
401 401
 	        {
402
-	            $object->name				= GETPOST('name', 'alpha');
402
+	            $object->name = GETPOST('name', 'alpha');
403 403
 	        }
404
-	        $object->entity					= (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity);
405
-	        $object->name_alias				= GETPOST('name_alias');
404
+	        $object->entity					= (GETPOSTISSET('entity') ?GETPOST('entity', 'int') : $conf->entity);
405
+	        $object->name_alias = GETPOST('name_alias');
406 406
 	        $object->address				= GETPOST('address');
407
-	        $object->zip					= GETPOST('zipcode', 'alpha');
408
-	        $object->town					= GETPOST('town', 'alpha');
409
-	        $object->country_id				= GETPOST('country_id', 'int');
407
+	        $object->zip = GETPOST('zipcode', 'alpha');
408
+	        $object->town = GETPOST('town', 'alpha');
409
+	        $object->country_id = GETPOST('country_id', 'int');
410 410
 	        $object->state_id				= GETPOST('state_id', 'int');
411 411
 	        $object->skype					= GETPOST('skype', 'alpha');
412
-	        $object->twitter				= GETPOST('twitter', 'alpha');
412
+	        $object->twitter = GETPOST('twitter', 'alpha');
413 413
 	        $object->facebook				= GETPOST('facebook', 'alpha');
414 414
 	        $object->phone					= GETPOST('phone', 'alpha');
415
-	        $object->fax					= GETPOST('fax','alpha');
415
+	        $object->fax					= GETPOST('fax', 'alpha');
416 416
 	        $object->email					= trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL));
417 417
 	        $object->url					= trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL));
418 418
 	        $object->idprof1				= trim(GETPOST('idprof1', 'alpha'));
@@ -422,14 +422,14 @@  discard block
 block discarded – undo
422 422
 	        $object->idprof5				= trim(GETPOST('idprof5', 'alpha'));
423 423
 	        $object->idprof6				= trim(GETPOST('idprof6', 'alpha'));
424 424
 	        $object->prefix_comm			= GETPOST('prefix_comm', 'alpha');
425
-	        $object->code_client			= GETPOSTISSET('customer_code')?GETPOST('customer_code', 'alpha'):GETPOST('code_client', 'alpha');
426
-	        $object->code_fournisseur		= GETPOSTISSET('supplier_code')?GETPOST('supplier_code', 'alpha'):GETPOST('code_fournisseur', 'alpha');
425
+	        $object->code_client			= GETPOSTISSET('customer_code') ?GETPOST('customer_code', 'alpha') : GETPOST('code_client', 'alpha');
426
+	        $object->code_fournisseur = GETPOSTISSET('supplier_code') ?GETPOST('supplier_code', 'alpha') : GETPOST('code_fournisseur', 'alpha');
427 427
 	        $object->capital				= GETPOST('capital', 'alpha');
428 428
 	        $object->barcode				= GETPOST('barcode', 'alpha');
429 429
 
430 430
 	        $object->tva_intra				= GETPOST('tva_intra', 'alpha');
431 431
 	        $object->tva_assuj				= GETPOST('assujtva_value', 'alpha');
432
-	        $object->status					= GETPOST('status', 'alpha');
432
+	        $object->status = GETPOST('status', 'alpha');
433 433
 
434 434
 	        // Local Taxes
435 435
 	        $object->localtax1_assuj		= GETPOST('localtax1assuj_value', 'alpha');
@@ -438,17 +438,17 @@  discard block
 block discarded – undo
438 438
 	        $object->localtax1_value		= GETPOST('lt1', 'alpha');
439 439
 	        $object->localtax2_value		= GETPOST('lt2', 'alpha');
440 440
 
441
-	        $object->forme_juridique_code	= GETPOST('forme_juridique_code', 'int');
441
+	        $object->forme_juridique_code = GETPOST('forme_juridique_code', 'int');
442 442
 	        $object->effectif_id			= GETPOST('effectif_id', 'int');
443
-	        $object->typent_id				= GETPOST('typent_id','int');
443
+	        $object->typent_id = GETPOST('typent_id', 'int');
444 444
 
445
-	        $object->typent_code			= dol_getIdFromCode($db, $object->typent_id, 'c_typent', 'id', 'code');	// Force typent_code too so check in verify() will be done on new type
445
+	        $object->typent_code			= dol_getIdFromCode($db, $object->typent_id, 'c_typent', 'id', 'code'); // Force typent_code too so check in verify() will be done on new type
446 446
 
447
-	        $object->client					= GETPOST('client', 'int');
447
+	        $object->client = GETPOST('client', 'int');
448 448
 	        $object->fournisseur			= GETPOST('fournisseur', 'int');
449 449
 
450
-	        $object->commercial_id			= GETPOST('commercial_id', 'int');
451
-	        $object->default_lang			= GETPOST('default_lang');
450
+	        $object->commercial_id = GETPOST('commercial_id', 'int');
451
+	        $object->default_lang = GETPOST('default_lang');
452 452
 
453 453
 	        // Webservices url/key
454 454
 	        $object->webservices_url		= GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
@@ -457,8 +457,8 @@  discard block
 block discarded – undo
457 457
 			// Incoterms
458 458
 			if (!empty($conf->incoterm->enabled))
459 459
 			{
460
-				$object->fk_incoterms		= GETPOST('incoterm_id', 'int');
461
-				$object->location_incoterms	= GETPOST('location_incoterms', 'alpha');
460
+				$object->fk_incoterms = GETPOST('incoterm_id', 'int');
461
+				$object->location_incoterms = GETPOST('location_incoterms', 'alpha');
462 462
 			}
463 463
 
464 464
 			// Multicurrency
@@ -468,53 +468,53 @@  discard block
 block discarded – undo
468 468
 			}
469 469
 
470 470
 	        // Fill array 'array_options' with data from add form
471
-	        $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
471
+	        $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
472 472
 			if ($ret < 0)
473 473
 			{
474 474
 				 $error++;
475 475
 			}
476 476
 
477 477
 	        if (GETPOST('deletephoto')) $object->logo = '';
478
-	        else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
478
+	        else if (!empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
479 479
 
480 480
 	        // Check parameters
481
-	        if (! GETPOST('cancel','alpha'))
481
+	        if (!GETPOST('cancel', 'alpha'))
482 482
 	        {
483
-	            if (! empty($object->email) && ! isValidEMail($object->email))
483
+	            if (!empty($object->email) && !isValidEMail($object->email))
484 484
 	            {
485 485
 	                $langs->load("errors");
486 486
 	                $error++;
487
-	                setEventMessages('', $langs->trans("ErrorBadEMail",$object->email), 'errors');
487
+	                setEventMessages('', $langs->trans("ErrorBadEMail", $object->email), 'errors');
488 488
 	            }
489
-	            if (! empty($object->url) && ! isValidUrl($object->url))
489
+	            if (!empty($object->url) && !isValidUrl($object->url))
490 490
 	            {
491 491
 	                $langs->load("errors");
492
-	                setEventMessages('', $langs->trans("ErrorBadUrl",$object->url), 'errors');
492
+	                setEventMessages('', $langs->trans("ErrorBadUrl", $object->url), 'errors');
493 493
 	            }
494
-	            if (! empty($object->webservices_url)) {
494
+	            if (!empty($object->webservices_url)) {
495 495
 	                //Check if has transport, without any the soap client will give error
496 496
 	                if (strpos($object->webservices_url, "http") === false)
497 497
 	                {
498 498
 	                    $object->webservices_url = "http://".$object->webservices_url;
499 499
 	                }
500
-	                if (! isValidUrl($object->webservices_url)) {
500
+	                if (!isValidUrl($object->webservices_url)) {
501 501
 	                    $langs->load("errors");
502
-	                    $error++; $errors[] = $langs->trans("ErrorBadUrl",$object->webservices_url);
502
+	                    $error++; $errors[] = $langs->trans("ErrorBadUrl", $object->webservices_url);
503 503
 	                }
504 504
 	            }
505 505
 
506 506
 	            // We set country_id, country_code and country for the selected country
507
-	            $object->country_id=GETPOST('country_id')!=''?GETPOST('country_id'):$mysoc->country_id;
507
+	            $object->country_id = GETPOST('country_id') != '' ?GETPOST('country_id') : $mysoc->country_id;
508 508
 	            if ($object->country_id)
509 509
 	            {
510
-	            	$tmparray=getCountry($object->country_id,'all');
511
-	            	$object->country_code=$tmparray['code'];
512
-	            	$object->country=$tmparray['label'];
510
+	            	$tmparray = getCountry($object->country_id, 'all');
511
+	            	$object->country_code = $tmparray['code'];
512
+	            	$object->country = $tmparray['label'];
513 513
 	            }
514 514
 	        }
515 515
         }
516 516
 
517
-        if (! $error)
517
+        if (!$error)
518 518
         {
519 519
             if ($action == 'add')
520 520
             {
@@ -522,8 +522,8 @@  discard block
 block discarded – undo
522 522
 
523 523
                 $db->begin();
524 524
 
525
-                if (empty($object->client))      $object->code_client='';
526
-                if (empty($object->fournisseur)) $object->code_fournisseur='';
525
+                if (empty($object->client))      $object->code_client = '';
526
+                if (empty($object->fournisseur)) $object->code_fournisseur = '';
527 527
 
528 528
                 $result = $object->create($user);
529 529
 
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
 					if ($object->particulier)
533 533
 					{
534 534
 						dol_syslog("We ask to create a contact/address too", LOG_DEBUG);
535
-						$result=$object->create_individual($user);
535
+						$result = $object->create_individual($user);
536 536
 						if ($result < 0)
537 537
 						{
538 538
 							setEventMessages($object->error, $object->errors, 'errors');
@@ -578,10 +578,10 @@  discard block
 block discarded – undo
578 578
 
579 579
                             if (@is_dir($dir))
580 580
                             {
581
-                                $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
581
+                                $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
582 582
                                 $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
583 583
 
584
-                                if (! $result > 0)
584
+                                if (!$result > 0)
585 585
                                 {
586 586
                                     $errors[] = "ErrorFailedToSaveFile";
587 587
                                 }
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
                     }
596 596
                     else
597 597
 					{
598
-						switch($_FILES['photo']['error'])
598
+						switch ($_FILES['photo']['error'])
599 599
 						{
600 600
 						    case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
601 601
 						    case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
@@ -621,21 +621,21 @@  discard block
 block discarded – undo
621 621
                    	$error++;
622 622
                 }
623 623
 
624
-                if ($result >= 0 && ! $error)
624
+                if ($result >= 0 && !$error)
625 625
                 {
626 626
                     $db->commit();
627 627
 
628
-                	if (! empty($backtopage))
628
+                	if (!empty($backtopage))
629 629
                 	{
630
-                	    if (preg_match('/\?/', $backtopage)) $backtopage.='&socid='.$object->id;
630
+                	    if (preg_match('/\?/', $backtopage)) $backtopage .= '&socid='.$object->id;
631 631
                		    header("Location: ".$backtopage);
632 632
                     	exit;
633 633
                 	}
634 634
                 	else
635 635
                 	{
636
-                    	$url=$_SERVER["PHP_SELF"]."?socid=".$object->id;
637
-                    	if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $url=DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
638
-                    	else if ($object->fournisseur == 1) $url=DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
636
+                    	$url = $_SERVER["PHP_SELF"]."?socid=".$object->id;
637
+                    	if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $url = DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
638
+                    	else if ($object->fournisseur == 1) $url = DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
639 639
 
640 640
                 		header("Location: ".$url);
641 641
                     	exit;
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
                 else
645 645
                 {
646 646
                     $db->rollback();
647
-                    $action='create';
647
+                    $action = 'create';
648 648
                 }
649 649
             }
650 650
 
@@ -652,9 +652,9 @@  discard block
 block discarded – undo
652 652
             {
653 653
             	$error = 0;
654 654
 
655
-                if (GETPOST('cancel','alpha'))
655
+                if (GETPOST('cancel', 'alpha'))
656 656
                 {
657
-                	if (! empty($backtopage))
657
+                	if (!empty($backtopage))
658 658
                 	{
659 659
                		    header("Location: ".$backtopage);
660 660
                     	exit;
@@ -667,12 +667,12 @@  discard block
 block discarded – undo
667 667
                 }
668 668
 
669 669
                 // To not set code if third party is not concerned. But if it had values, we keep them.
670
-                if (empty($object->client) && empty($object->oldcopy->code_client))          $object->code_client='';
671
-                if (empty($object->fournisseur)&& empty($object->oldcopy->code_fournisseur)) $object->code_fournisseur='';
670
+                if (empty($object->client) && empty($object->oldcopy->code_client))          $object->code_client = '';
671
+                if (empty($object->fournisseur) && empty($object->oldcopy->code_fournisseur)) $object->code_fournisseur = '';
672 672
                 //var_dump($object);exit;
673 673
 
674 674
                 $result = $object->update($socid, $user, 1, $object->oldcopy->codeclient_modifiable(), $object->oldcopy->codefournisseur_modifiable(), 'update', 0);
675
-                if ($result <=  0)
675
+                if ($result <= 0)
676 676
                 {
677 677
                     setEventMessages($object->error, $object->errors, 'errors');
678 678
                     $error++;
@@ -688,10 +688,10 @@  discard block
 block discarded – undo
688 688
 				}
689 689
 
690 690
 				// Prevent thirdparty's emptying if a user hasn't rights $user->rights->categorie->lire (in such a case, post of 'custcats' is not defined)
691
-				if (! $error && !empty($user->rights->categorie->lire))
691
+				if (!$error && !empty($user->rights->categorie->lire))
692 692
 				{
693 693
 					// Customer categories association
694
-					$categories = GETPOST( 'custcats', 'array' );
694
+					$categories = GETPOST('custcats', 'array');
695 695
 					$result = $object->setCategories($categories, 'customer');
696 696
 					if ($result < 0)
697 697
 					{
@@ -714,8 +714,8 @@  discard block
 block discarded – undo
714 714
                 $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
715 715
                 if (GETPOST('deletephoto') && $object->logo)
716 716
                 {
717
-                    $fileimg=$dir.'/'.$object->logo;
718
-                    $dirthumbs=$dir.'/thumbs';
717
+                    $fileimg = $dir.'/'.$object->logo;
718
+                    $dirthumbs = $dir.'/thumbs';
719 719
                     dol_delete_file($fileimg);
720 720
                     dol_delete_dir_recursive($dirthumbs);
721 721
                 }
@@ -727,10 +727,10 @@  discard block
 block discarded – undo
727 727
 
728 728
                         if (@is_dir($dir))
729 729
                         {
730
-                            $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
730
+                            $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
731 731
                             $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
732 732
 
733
-                            if (! $result > 0)
733
+                            if (!$result > 0)
734 734
                             {
735 735
                                 $errors[] = "ErrorFailedToSaveFile";
736 736
                             }
@@ -740,9 +740,9 @@  discard block
 block discarded – undo
740 740
                             	$object->addThumbs($newfile);
741 741
 
742 742
                                 // Index file in database
743
-                                if (! empty($conf->global->THIRDPARTY_LOGO_ALLOW_EXTERNAL_DOWNLOAD))
743
+                                if (!empty($conf->global->THIRDPARTY_LOGO_ALLOW_EXTERNAL_DOWNLOAD))
744 744
                                 {
745
-                                	require_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php';
745
+                                	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
746 746
                                 	// the dir dirname($newfile) is directory of logo, so we should have only one file at once into index, so we delete indexes for the dir
747 747
                                 	deleteFilesIntoDatabaseIndex(dirname($newfile), '', '', 'uploaded', 1);
748 748
                                 	// now we index the uploaded logo file
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
                 }
759 759
                 else
760 760
                 {
761
-					switch($_FILES['photo']['error'])
761
+					switch ($_FILES['photo']['error'])
762 762
 					{
763 763
 					    case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
764 764
 					    case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
@@ -773,12 +773,12 @@  discard block
 block discarded – undo
773 773
 
774 774
 
775 775
                 // Update linked member
776
-                if (! $error && $object->fk_soc > 0)
776
+                if (!$error && $object->fk_soc > 0)
777 777
                 {
778 778
 
779 779
                 	$sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
780
-                	$sql.= " SET fk_soc = NULL WHERE fk_soc = " . $id;
781
-                	if (! $object->db->query($sql))
780
+                	$sql .= " SET fk_soc = NULL WHERE fk_soc = ".$id;
781
+                	if (!$object->db->query($sql))
782 782
                 	{
783 783
                 		$error++;
784 784
                 		$object->error .= $object->db->lasterror();
@@ -786,9 +786,9 @@  discard block
 block discarded – undo
786 786
                 	}
787 787
                 }
788 788
 
789
-                if (! $error && ! count($errors))
789
+                if (!$error && !count($errors))
790 790
                 {
791
-                	if (! empty($backtopage))
791
+                	if (!empty($backtopage))
792 792
                 	{
793 793
                		    header("Location: ".$backtopage);
794 794
                     	exit;
@@ -802,13 +802,13 @@  discard block
 block discarded – undo
802 802
                 else
803 803
                 {
804 804
                     $object->id = $socid;
805
-                    $action= "edit";
805
+                    $action = "edit";
806 806
                 }
807 807
             }
808 808
         }
809 809
         else
810 810
         {
811
-        	$action = ($action=='add'?'create':'edit');
811
+        	$action = ($action == 'add' ? 'create' : 'edit');
812 812
         }
813 813
     }
814 814
 
@@ -828,7 +828,7 @@  discard block
 block discarded – undo
828 828
             $langs->load("errors");
829 829
            	setEventMessages($object->error, $object->errors, 'errors');
830 830
            	$error++;
831
-            $action='';
831
+            $action = '';
832 832
         }
833 833
     }
834 834
 
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
     if ($action == 'set_thirdparty' && $user->rights->societe->creer)
837 837
     {
838 838
     	$object->fetch($socid);
839
-    	$result = $object->set_parent(GETPOST('editparentcompany','int'));
839
+    	$result = $object->set_parent(GETPOST('editparentcompany', 'int'));
840 840
     }
841 841
 
842 842
     // Set incoterm
@@ -846,20 +846,20 @@  discard block
 block discarded – undo
846 846
     	$result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
847 847
     }
848 848
 
849
-    $id=$socid;
849
+    $id = $socid;
850 850
     $object->fetch($socid);
851 851
 
852 852
     // Actions to send emails
853
-    $trigger_name='COMPANY_SENTBYMAIL';
854
-    $paramname='socid';
855
-    $mode='emailfromthirdparty';
856
-    $trackid='thi'.$object->id;
853
+    $trigger_name = 'COMPANY_SENTBYMAIL';
854
+    $paramname = 'socid';
855
+    $mode = 'emailfromthirdparty';
856
+    $trackid = 'thi'.$object->id;
857 857
     include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
858 858
 
859 859
     // Actions to build doc
860 860
     $id = $socid;
861 861
     $upload_dir = $conf->societe->dir_output;
862
-    $permissioncreate=$user->rights->societe->creer;
862
+    $permissioncreate = $user->rights->societe->creer;
863 863
     include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
864 864
 }
865 865
 
@@ -875,24 +875,24 @@  discard block
 block discarded – undo
875 875
 
876 876
 if ($socid > 0 && empty($object->id))
877 877
 {
878
-    $result=$object->fetch($socid);
879
-	if ($result <= 0) dol_print_error('',$object->error);
878
+    $result = $object->fetch($socid);
879
+	if ($result <= 0) dol_print_error('', $object->error);
880 880
 }
881 881
 
882
-$title=$langs->trans("ThirdParty");
883
-if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$langs->trans('Card');
884
-$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
885
-llxHeader('',$title,$help_url);
882
+$title = $langs->trans("ThirdParty");
883
+if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->name." - ".$langs->trans('Card');
884
+$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
885
+llxHeader('', $title, $help_url);
886 886
 
887
-$countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
887
+$countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
888 888
 
889 889
 if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
890 890
 {
891 891
     // -----------------------------------------
892 892
     // When used with CANVAS
893 893
     // -----------------------------------------
894
-   	$objcanvas->assign_values($action, $object->id, $object->ref);	// Set value for templates
895
-    $objcanvas->display_canvas($action);							// Show template
894
+   	$objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
895
+    $objcanvas->display_canvas($action); // Show template
896 896
 }
897 897
 else
898 898
 {
@@ -904,68 +904,68 @@  discard block
 block discarded – undo
904 904
         /*
905 905
          *  Creation
906 906
          */
907
-		$private=GETPOST("private","int");
908
-		if (! empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT) && ! isset($_GET['private']) && ! isset($_POST['private'])) $private=1;
909
-    	if (empty($private)) $private=0;
907
+		$private = GETPOST("private", "int");
908
+		if (!empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT) && !isset($_GET['private']) && !isset($_POST['private'])) $private = 1;
909
+    	if (empty($private)) $private = 0;
910 910
 
911 911
         // Load object modCodeTiers
912
-        $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
912
+        $module = (!empty($conf->global->SOCIETE_CODECLIENT_ADDON) ? $conf->global->SOCIETE_CODECLIENT_ADDON : 'mod_codeclient_leopard');
913 913
         if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
914 914
         {
915
-            $module = substr($module, 0, dol_strlen($module)-4);
915
+            $module = substr($module, 0, dol_strlen($module) - 4);
916 916
         }
917
-        $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
917
+        $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
918 918
         foreach ($dirsociete as $dirroot)
919 919
         {
920
-            $res=dol_include_once($dirroot.$module.'.php');
920
+            $res = dol_include_once($dirroot.$module.'.php');
921 921
             if ($res) break;
922 922
         }
923 923
         $modCodeClient = new $module;
924 924
         // Load object modCodeFournisseur
925
-        $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
925
+        $module = (!empty($conf->global->SOCIETE_CODECLIENT_ADDON) ? $conf->global->SOCIETE_CODECLIENT_ADDON : 'mod_codeclient_leopard');
926 926
         if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
927 927
         {
928
-            $module = substr($module, 0, dol_strlen($module)-4);
928
+            $module = substr($module, 0, dol_strlen($module) - 4);
929 929
         }
930
-        $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
930
+        $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
931 931
         foreach ($dirsociete as $dirroot)
932 932
         {
933
-            $res=dol_include_once($dirroot.$module.'.php');
933
+            $res = dol_include_once($dirroot.$module.'.php');
934 934
             if ($res) break;
935 935
         }
936 936
         $modCodeFournisseur = new $module;
937 937
 
938 938
         // Define if customer/prospect or supplier status is set or not
939
-        if (GETPOST("type")!='f')
939
+        if (GETPOST("type") != 'f')
940 940
         {
941
-            $object->client=-1;
942
-            if (! empty($conf->global->THIRDPARTY_CUSTOMERPROSPECT_BY_DEFAULT))  { $object->client=3; }
941
+            $object->client = -1;
942
+            if (!empty($conf->global->THIRDPARTY_CUSTOMERPROSPECT_BY_DEFAULT)) { $object->client = 3; }
943 943
         }
944
-        if (GETPOST("type")=='c')  { $object->client=3; }   // Prospect / Customer
945
-        if (GETPOST("type")=='p')  { $object->client=2; }
946
-        if (! empty($conf->fournisseur->enabled) && (GETPOST("type")=='f' || (GETPOST("type")=='' && ! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT))))  { $object->fournisseur=1; }
944
+        if (GETPOST("type") == 'c') { $object->client = 3; }   // Prospect / Customer
945
+        if (GETPOST("type") == 'p') { $object->client = 2; }
946
+        if (!empty($conf->fournisseur->enabled) && (GETPOST("type") == 'f' || (GETPOST("type") == '' && !empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)))) { $object->fournisseur = 1; }
947 947
 
948
-        $object->name				= GETPOST('name', 'alpha');
949
-        $object->firstname			= GETPOST('firstname', 'alpha');
948
+        $object->name = GETPOST('name', 'alpha');
949
+        $object->firstname = GETPOST('firstname', 'alpha');
950 950
         $object->particulier		= $private;
951 951
         $object->prefix_comm		= GETPOST('prefix_comm');
952
-        $object->client				= GETPOST('client')?GETPOST('client'):$object->client;
952
+        $object->client = GETPOST('client') ?GETPOST('client') : $object->client;
953 953
 
954
-        if(empty($duplicate_code_error)) {
954
+        if (empty($duplicate_code_error)) {
955 955
 	        $object->code_client		= GETPOST('customer_code', 'alpha');
956
-	        $object->fournisseur		= GETPOST('fournisseur')?GETPOST('fournisseur'):$object->fournisseur;
956
+	        $object->fournisseur		= GETPOST('fournisseur') ?GETPOST('fournisseur') : $object->fournisseur;
957 957
         }
958 958
 		else {
959
-			setEventMessages($langs->trans('NewCustomerSupplierCodeProposed'),'', 'warnings');
959
+			setEventMessages($langs->trans('NewCustomerSupplierCodeProposed'), '', 'warnings');
960 960
 		}
961 961
 
962
-        $object->code_fournisseur	= GETPOST('supplier_code', 'alpha');
963
-        $object->address			= GETPOST('address', 'alpha');
964
-        $object->zip				= GETPOST('zipcode', 'alpha');
965
-        $object->town				= GETPOST('town', 'alpha');
962
+        $object->code_fournisseur = GETPOST('supplier_code', 'alpha');
963
+        $object->address = GETPOST('address', 'alpha');
964
+        $object->zip = GETPOST('zipcode', 'alpha');
965
+        $object->town = GETPOST('town', 'alpha');
966 966
         $object->state_id			= GETPOST('state_id', 'int');
967 967
         $object->skype				= GETPOST('skype', 'alpha');
968
-        $object->twitter			= GETPOST('twitter', 'alpha');
968
+        $object->twitter = GETPOST('twitter', 'alpha');
969 969
         $object->facebook			= GETPOST('facebook', 'alpha');
970 970
         $object->phone				= GETPOST('phone', 'alpha');
971 971
         $object->fax				= GETPOST('fax', 'alpha');
@@ -979,30 +979,30 @@  discard block
 block discarded – undo
979 979
         $object->idprof4			= GETPOST('idprof4', 'alpha');
980 980
         $object->idprof5			= GETPOST('idprof5', 'alpha');
981 981
         $object->idprof6			= GETPOST('idprof6', 'alpha');
982
-        $object->typent_id			= GETPOST('typent_id', 'int');
982
+        $object->typent_id = GETPOST('typent_id', 'int');
983 983
         $object->effectif_id		= GETPOST('effectif_id', 'int');
984 984
         $object->civility_id		= GETPOST('civility_id', 'int');
985 985
 
986
-        $object->tva_assuj			= GETPOST('assujtva_value', 'int');
987
-        $object->status				= GETPOST('status', 'int');
986
+        $object->tva_assuj = GETPOST('assujtva_value', 'int');
987
+        $object->status = GETPOST('status', 'int');
988 988
 
989 989
         //Local Taxes
990 990
         $object->localtax1_assuj	= GETPOST('localtax1assuj_value', 'int');
991 991
         $object->localtax2_assuj	= GETPOST('localtax2assuj_value', 'int');
992 992
 
993
-        $object->localtax1_value	=GETPOST('lt1', 'int');
994
-        $object->localtax2_value	=GETPOST('lt2', 'int');
993
+        $object->localtax1_value	= GETPOST('lt1', 'int');
994
+        $object->localtax2_value	= GETPOST('lt2', 'int');
995 995
 
996
-        $object->tva_intra			= GETPOST('tva_intra', 'alpha');
996
+        $object->tva_intra = GETPOST('tva_intra', 'alpha');
997 997
 
998
-        $object->commercial_id		= GETPOST('commercial_id', 'int');
999
-        $object->default_lang		= GETPOST('default_lang');
998
+        $object->commercial_id = GETPOST('commercial_id', 'int');
999
+        $object->default_lang = GETPOST('default_lang');
1000 1000
 
1001
-        $object->logo = (isset($_FILES['photo'])?dol_sanitizeFileName($_FILES['photo']['name']):'');
1001
+        $object->logo = (isset($_FILES['photo']) ?dol_sanitizeFileName($_FILES['photo']['name']) : '');
1002 1002
 
1003 1003
         // Gestion du logo de la société
1004 1004
         $dir     = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos";
1005
-        $file_OK = (isset($_FILES['photo'])?is_uploaded_file($_FILES['photo']['tmp_name']):false);
1005
+        $file_OK = (isset($_FILES['photo']) ?is_uploaded_file($_FILES['photo']['tmp_name']) : false);
1006 1006
         if ($file_OK)
1007 1007
         {
1008 1008
             if (image_format_supported($_FILES['photo']['name']))
@@ -1011,10 +1011,10 @@  discard block
 block discarded – undo
1011 1011
 
1012 1012
                 if (@is_dir($dir))
1013 1013
                 {
1014
-                    $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
1014
+                    $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
1015 1015
                     $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
1016 1016
 
1017
-                    if (! $result > 0)
1017
+                    if (!$result > 0)
1018 1018
                     {
1019 1019
                         $errors[] = "ErrorFailedToSaveFile";
1020 1020
                     }
@@ -1028,20 +1028,20 @@  discard block
 block discarded – undo
1028 1028
         }
1029 1029
 
1030 1030
         // We set country_id, country_code and country for the selected country
1031
-        $object->country_id=GETPOST('country_id')?GETPOST('country_id'):$mysoc->country_id;
1031
+        $object->country_id = GETPOST('country_id') ?GETPOST('country_id') : $mysoc->country_id;
1032 1032
         if ($object->country_id)
1033 1033
         {
1034
-            $tmparray=getCountry($object->country_id,'all');
1035
-            $object->country_code=$tmparray['code'];
1036
-            $object->country=$tmparray['label'];
1034
+            $tmparray = getCountry($object->country_id, 'all');
1035
+            $object->country_code = $tmparray['code'];
1036
+            $object->country = $tmparray['label'];
1037 1037
         }
1038
-        $object->forme_juridique_code=GETPOST('forme_juridique_code');
1038
+        $object->forme_juridique_code = GETPOST('forme_juridique_code');
1039 1039
         /* Show create form */
1040 1040
 
1041
-        $linkback="";
1042
-        print load_fiche_titre($langs->trans("NewThirdParty"),$linkback,'title_companies.png');
1041
+        $linkback = "";
1042
+        print load_fiche_titre($langs->trans("NewThirdParty"), $linkback, 'title_companies.png');
1043 1043
 
1044
-        if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION))
1044
+        if (!empty($conf->use_javascript_ajax) && !empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION))
1045 1045
         {
1046 1046
             print "\n".'<script type="text/javascript">';
1047 1047
             print '$(document).ready(function () {
@@ -1074,7 +1074,7 @@  discard block
 block discarded – undo
1074 1074
 						});
1075 1075
 						function init_customer_categ() {
1076 1076
 								console.log("is customer or prospect = "+jQuery("#customerprospect").val());
1077
-								if (jQuery("#customerprospect").val() == 0 && (jQuery("#fournisseur").val() == 0 || '.(empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER)?'1':'0').'))
1077
+								if (jQuery("#customerprospect").val() == 0 && (jQuery("#fournisseur").val() == 0 || '.(empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER) ? '1' : '0').'))
1078 1078
 								{
1079 1079
 									jQuery(".visibleifcustomer").hide();
1080 1080
 								}
@@ -1112,31 +1112,31 @@  discard block
 block discarded – undo
1112 1112
             print $langs->trans("ThirdPartyType").': &nbsp; &nbsp; ';
1113 1113
             print '</div>';
1114 1114
 	        print '<label for="radiocompany" class="radiocompany">';
1115
-            print '<input type="radio" id="radiocompany" class="flat" name="private"  value="0"'.($private?'':' checked').'>';
1115
+            print '<input type="radio" id="radiocompany" class="flat" name="private"  value="0"'.($private ? '' : ' checked').'>';
1116 1116
 	        print '&nbsp;';
1117 1117
             print $langs->trans("CreateThirdPartyOnly");
1118 1118
 	        print '</label>';
1119 1119
             print ' &nbsp; &nbsp; ';
1120 1120
 	        print '<label for="radioprivate" class="radioprivate">';
1121
-            $text ='<input type="radio" id="radioprivate" class="flat" name="private" value="1"'.($private?' checked':'').'>';
1122
-	        $text.='&nbsp;';
1123
-	        $text.= $langs->trans("CreateThirdPartyAndContact");
1124
-	        $htmltext=$langs->trans("ToCreateContactWithSameName");
1121
+            $text = '<input type="radio" id="radioprivate" class="flat" name="private" value="1"'.($private ? ' checked' : '').'>';
1122
+	        $text .= '&nbsp;';
1123
+	        $text .= $langs->trans("CreateThirdPartyAndContact");
1124
+	        $htmltext = $langs->trans("ToCreateContactWithSameName");
1125 1125
 	        print $form->textwithpicto($text, $htmltext, 1, 'help', '', 0, 3);
1126 1126
             print '</label>';
1127 1127
             print '</div>';
1128 1128
             print "<br>\n";
1129 1129
         }
1130 1130
 
1131
-        dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error');
1131
+        dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
1132 1132
 
1133
-        print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc" autocomplete="off">';		// Chrome ignor autocomplete
1133
+        print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc" autocomplete="off">'; // Chrome ignor autocomplete
1134 1134
 
1135 1135
         print '<input type="hidden" name="action" value="add">';
1136 1136
         print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1137 1137
         print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1138 1138
         print '<input type="hidden" name="private" value='.$object->particulier.'>';
1139
-        print '<input type="hidden" name="type" value='.GETPOST("type",'alpha').'>';
1139
+        print '<input type="hidden" name="type" value='.GETPOST("type", 'alpha').'>';
1140 1140
         print '<input type="hidden" name="LastName" value="'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName').'">';
1141 1141
         print '<input type="hidden" name="ThirdPartyName" value="'.$langs->trans('ThirdPartyName').'">';
1142 1142
         if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) print '<input type="hidden" name="code_auto" value="1">';
@@ -1149,15 +1149,15 @@  discard block
 block discarded – undo
1149 1149
 	    print '<tr><td class="titlefieldcreate">';
1150 1150
         if ($object->particulier || $private)
1151 1151
         {
1152
-	        print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName','name').'</span>';
1152
+	        print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName', 'name').'</span>';
1153 1153
         }
1154 1154
         else
1155 1155
 		{
1156 1156
 			print '<span id="TypeName" class="fieldrequired">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0).'</span>';
1157 1157
         }
1158
-	    print '</td><td'.(empty($conf->global->SOCIETE_USEPREFIX)?' colspan="3"':'').'>';
1158
+	    print '</td><td'.(empty($conf->global->SOCIETE_USEPREFIX) ? ' colspan="3"' : '').'>';
1159 1159
 	    print '<input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.$object->name.'" autofocus="autofocus"></td>';
1160
-	    if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1160
+	    if (!empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1161 1161
 	    {
1162 1162
 		    print '<td>'.$langs->trans('Prefix').'</td><td><input type="text" size="5" maxlength="5" name="prefix_comm" value="'.$object->prefix_comm.'"></td>';
1163 1163
 	    }
@@ -1182,51 +1182,51 @@  discard block
 block discarded – undo
1182 1182
         // Prospect/Customer
1183 1183
         print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).'</td>';
1184 1184
 	    print '<td class="maxwidthonsmartphone">';
1185
-	    $selected=GETPOST('client','int')!=''?GETPOST('client','int'):$object->client;
1185
+	    $selected = GETPOST('client', 'int') != '' ?GETPOST('client', 'int') : $object->client;
1186 1186
         print '<select class="flat" name="client" id="customerprospect">';
1187 1187
         if (GETPOST("type") == '') print '<option value="-1">&nbsp;</option>';
1188
-        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($selected==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1189
-        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) print '<option value="3"'.($selected==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1190
-        if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($selected==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1191
-        print '<option value="0"'.((string) $selected == '0'?' selected':'').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1188
+        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($selected == 2 ? ' selected' : '').'>'.$langs->trans('Prospect').'</option>';
1189
+        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) print '<option value="3"'.($selected == 3 ? ' selected' : '').'>'.$langs->trans('ProspectCustomer').'</option>';
1190
+        if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($selected == 1 ? ' selected' : '').'>'.$langs->trans('Customer').'</option>';
1191
+        print '<option value="0"'.((string) $selected == '0' ? ' selected' : '').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1192 1192
         print '</select></td>';
1193 1193
 
1194 1194
         print '<td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
1195 1195
         print '<table class="nobordernopadding"><tr><td>';
1196
-		$tmpcode=$object->code_client;
1197
-        if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object,0);
1196
+		$tmpcode = $object->code_client;
1197
+        if (empty($tmpcode) && !empty($modCodeClient->code_auto)) $tmpcode = $modCodeClient->getNextValue($object, 0);
1198 1198
         print '<input type="text" name="customer_code" id="customer_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1199 1199
         print '</td><td>';
1200
-        $s=$modCodeClient->getToolTip($langs,$object,0);
1201
-        print $form->textwithpicto('',$s,1);
1200
+        $s = $modCodeClient->getToolTip($langs, $object, 0);
1201
+        print $form->textwithpicto('', $s, 1);
1202 1202
         print '</td></tr></table>';
1203 1203
         print '</td></tr>';
1204 1204
 
1205
-        if ((! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1206
-        	|| (! empty($conf->supplier_proposal->enabled) && ! empty($user->rights->supplier_proposal->lire)))
1205
+        if ((!empty($conf->fournisseur->enabled) && !empty($user->rights->fournisseur->lire))
1206
+        	|| (!empty($conf->supplier_proposal->enabled) && !empty($user->rights->supplier_proposal->lire)))
1207 1207
         {
1208 1208
             // Supplier
1209 1209
             print '<tr>';
1210 1210
             print '<td>'.$form->editfieldkey('Supplier', 'fournisseur', '', $object, 0, 'string', '', 1).'</td><td>';
1211 1211
             $default = -1;
1212
-            if (! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)) $default=1;
1213
-            print $form->selectyesno("fournisseur", (GETPOST('fournisseur','int')!=''?GETPOST('fournisseur','int'):(GETPOST("type",'alpha') == '' ? $default : $object->fournisseur)), 1, 0, (GETPOST("type",'alpha') == '' ? 1 : 0));
1212
+            if (!empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)) $default = 1;
1213
+            print $form->selectyesno("fournisseur", (GETPOST('fournisseur', 'int') != '' ?GETPOST('fournisseur', 'int') : (GETPOST("type", 'alpha') == '' ? $default : $object->fournisseur)), 1, 0, (GETPOST("type", 'alpha') == '' ? 1 : 0));
1214 1214
             print '</td>';
1215 1215
             print '<td>';
1216
-            if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1216
+            if (!empty($conf->fournisseur->enabled) && !empty($user->rights->fournisseur->lire))
1217 1217
             {
1218 1218
             	print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0);
1219 1219
             }
1220 1220
             print '</td><td>';
1221
-            if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1221
+            if (!empty($conf->fournisseur->enabled) && !empty($user->rights->fournisseur->lire))
1222 1222
             {
1223 1223
 	            print '<table class="nobordernopadding"><tr><td>';
1224
-	            $tmpcode=$object->code_fournisseur;
1225
-	            if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1224
+	            $tmpcode = $object->code_fournisseur;
1225
+	            if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) $tmpcode = $modCodeFournisseur->getNextValue($object, 1);
1226 1226
 	            print '<input type="text" name="supplier_code" id="supplier_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1227 1227
 	            print '</td><td>';
1228
-	            $s=$modCodeFournisseur->getToolTip($langs,$object,1);
1229
-	            print $form->textwithpicto('',$s,1);
1228
+	            $s = $modCodeFournisseur->getToolTip($langs, $object, 1);
1229
+	            print $form->textwithpicto('', $s, 1);
1230 1230
 	            print '</td></tr></table>';
1231 1231
             }
1232 1232
             print '</td></tr>';
@@ -1234,11 +1234,11 @@  discard block
 block discarded – undo
1234 1234
 
1235 1235
         // Status
1236 1236
         print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0).'</td><td colspan="3">';
1237
-        print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'),'1'=>$langs->trans('InActivity')),1);
1237
+        print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), 1);
1238 1238
         print '</td></tr>';
1239 1239
 
1240 1240
         // Barcode
1241
-        if (! empty($conf->barcode->enabled))
1241
+        if (!empty($conf->barcode->enabled))
1242 1242
         {
1243 1243
             print '<tr><td>'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).'</td>';
1244 1244
 	        print '<td colspan="3"><input type="text" name="barcode" id="barcode" value="'.$object->barcode.'">';
@@ -1253,21 +1253,21 @@  discard block
 block discarded – undo
1253 1253
 
1254 1254
         // Zip / Town
1255 1255
         print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td>';
1256
-        print $formcompany->select_ziptown($object->zip,'zipcode',array('town','selectcountry_id','state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent');
1256
+        print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent');
1257 1257
         print '</td><td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td>';
1258
-        print $formcompany->select_ziptown($object->town,'town',array('zipcode','selectcountry_id','state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent');
1258
+        print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent');
1259 1259
         print '</td></tr>';
1260 1260
 
1261 1261
         // Country
1262 1262
         print '<tr><td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1263
-        print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id));
1264
-        if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1263
+        print $form->select_country((GETPOST('country_id') != '' ?GETPOST('country_id') : $object->country_id));
1264
+        if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1265 1265
         print '</td></tr>';
1266 1266
 
1267 1267
         // State
1268 1268
         if (empty($conf->global->SOCIETE_DISABLE_STATE))
1269 1269
         {
1270
-            if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1270
+            if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1271 1271
             {
1272 1272
                 print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1273 1273
             }
@@ -1276,7 +1276,7 @@  discard block
 block discarded – undo
1276 1276
                 print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1277 1277
             }
1278 1278
 
1279
-            if ($object->country_id) print $formcompany->select_state($object->state_id,$object->country_code);
1279
+            if ($object->country_id) print $formcompany->select_state($object->state_id, $object->country_code);
1280 1280
             else print $countrynotdefined;
1281 1281
             print '</td></tr>';
1282 1282
         }
@@ -1287,30 +1287,30 @@  discard block
 block discarded – undo
1287 1287
         print '<tr><td>'.$form->editfieldkey('Web', 'url', '', $object, 0).'</td>';
1288 1288
 	    print '<td colspan="3"><input type="text" name="url" id="url" value="'.$object->url.'"></td></tr>';
1289 1289
 
1290
-        if (! empty($conf->socialnetworks->enabled))
1290
+        if (!empty($conf->socialnetworks->enabled))
1291 1291
         {
1292 1292
         	// Skype
1293
-        	if (! empty($conf->global->SOCIALNETWORKS_SKYPE))
1293
+        	if (!empty($conf->global->SOCIALNETWORKS_SKYPE))
1294 1294
         	{
1295 1295
         		print '<tr><td>'.$form->editfieldkey('Skype', 'skype', '', $object, 0).'</td>';
1296 1296
 				print '<td colspan="3">';
1297
-				print '<input type="text" name="skype" class="minwidth100" maxlength="80" id="skype" value="'.dol_escape_htmltag(GETPOSTISSET("skype")?GETPOST("skype",'alpha'):$object->skype).'">';
1297
+				print '<input type="text" name="skype" class="minwidth100" maxlength="80" id="skype" value="'.dol_escape_htmltag(GETPOSTISSET("skype") ?GETPOST("skype", 'alpha') : $object->skype).'">';
1298 1298
 				print '</td></tr>';
1299 1299
         	}
1300 1300
         	// Twitter
1301
-        	if (! empty($conf->global->SOCIALNETWORKS_TWITTER))
1301
+        	if (!empty($conf->global->SOCIALNETWORKS_TWITTER))
1302 1302
         	{
1303 1303
         		print '<tr><td>'.$form->editfieldkey('Twitter', 'twitter', '', $object, 0).'</td>';
1304 1304
 				print '<td colspan="3">';
1305
-				print '<input type="text" name="twitter" class="minwidth100" maxlength="80" id="twitter" value="'.dol_escape_htmltag(GETPOSTISSET("twitter")?GETPOST("twitter",'alpha'):$object->twitter).'">';
1305
+				print '<input type="text" name="twitter" class="minwidth100" maxlength="80" id="twitter" value="'.dol_escape_htmltag(GETPOSTISSET("twitter") ?GETPOST("twitter", 'alpha') : $object->twitter).'">';
1306 1306
 				print '</td></tr>';
1307 1307
         	}
1308 1308
         	// Facebook
1309
-        	if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK))
1309
+        	if (!empty($conf->global->SOCIALNETWORKS_FACEBOOK))
1310 1310
         	{
1311 1311
 	        	print '<tr><td>'.$form->editfieldkey('Facebook', 'facebook', '', $object, 0).'</td>';
1312 1312
 				print '<td colspan="3">';
1313
-				print '<input type="text" name="facebook" class="minwidth100" maxlength="80" id="facebook" value="'.dol_escape_htmltag(GETPOSTISSET("facebook")?GETPOST("facebook",'alpha'):$object->facebook).'">';
1313
+				print '<input type="text" name="facebook" class="minwidth100" maxlength="80" id="facebook" value="'.dol_escape_htmltag(GETPOSTISSET("facebook") ?GETPOST("facebook", 'alpha') : $object->facebook).'">';
1314 1314
 				print '</td></tr>';
1315 1315
         	}
1316 1316
         }
@@ -1322,18 +1322,18 @@  discard block
 block discarded – undo
1322 1322
 	    print '<td><input type="text" name="fax" id="fax" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->fax.'"></td></tr>';
1323 1323
 
1324 1324
         // Prof ids
1325
-        $i=1; $j=0;
1325
+        $i = 1; $j = 0;
1326 1326
         while ($i <= 6)
1327 1327
         {
1328
-            $idprof=$langs->transcountry('ProfId'.$i,$object->country_code);
1329
-            if ($idprof!='-')
1328
+            $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
1329
+            if ($idprof != '-')
1330 1330
             {
1331
-	            $key='idprof'.$i;
1331
+	            $key = 'idprof'.$i;
1332 1332
 
1333 1333
                 if (($j % 2) == 0) print '<tr>';
1334 1334
 
1335
-                $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
1336
-                print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', (empty($conf->global->$idprof_mandatory)?0:1)).'</td><td>';
1335
+                $idprof_mandatory = 'SOCIETE_IDPROF'.($i).'_MANDATORY';
1336
+                print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', (empty($conf->global->$idprof_mandatory) ? 0 : 1)).'</td><td>';
1337 1337
 
1338 1338
                 print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
1339 1339
                 print '</td>';
@@ -1347,7 +1347,7 @@  discard block
 block discarded – undo
1347 1347
         // Vat is used
1348 1348
         print '<tr><td>'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).'</td>';
1349 1349
         print '<td>';
1350
-        print $form->selectyesno('assujtva_value', GETPOSTISSET('assujtva_value')?GETPOST('assujtva_value','int'):1, 1);     // Assujeti par defaut en creation
1350
+        print $form->selectyesno('assujtva_value', GETPOSTISSET('assujtva_value') ?GETPOST('assujtva_value', 'int') : 1, 1); // Assujeti par defaut en creation
1351 1351
         print '</td>';
1352 1352
         print '<td class="nowrap">'.$form->editfieldkey('VATIntra', 'intra_vat', '', $object, 0).'</td>';
1353 1353
         print '<td class="nowrap">';
@@ -1355,9 +1355,9 @@  discard block
 block discarded – undo
1355 1355
 
1356 1356
         if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object))
1357 1357
         {
1358
-            $s.=' ';
1358
+            $s .= ' ';
1359 1359
 
1360
-            if (! empty($conf->use_javascript_ajax))
1360
+            if (!empty($conf->use_javascript_ajax))
1361 1361
             {
1362 1362
                 print "\n";
1363 1363
                 print '<script language="JavaScript" type="text/javascript">';
@@ -1366,12 +1366,12 @@  discard block
 block discarded – undo
1366 1366
                 print "}\n";
1367 1367
                 print '</script>';
1368 1368
                 print "\n";
1369
-                $s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
1370
-                $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
1369
+                $s .= '<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
1370
+                $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->trans("VATIntraCheck")), 1);
1371 1371
             }
1372 1372
             else
1373 1373
             {
1374
-                $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
1374
+                $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", $object->country_id).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
1375 1375
             }
1376 1376
         }
1377 1377
         print $s;
@@ -1380,36 +1380,36 @@  discard block
 block discarded – undo
1380 1380
 
1381 1381
         // Local Taxes
1382 1382
         //TODO: Place into a function to control showing by country or study better option
1383
-        if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
1383
+        if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1")
1384 1384
         {
1385
-            print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
1386
-            print $form->selectyesno('localtax1assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1:0),1);
1387
-            print '</td><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
1388
-            print $form->selectyesno('localtax2assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0),1);
1385
+            print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
1386
+            print $form->selectyesno('localtax1assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1 : 0), 1);
1387
+            print '</td><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
1388
+            print $form->selectyesno('localtax2assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2 : 0), 1);
1389 1389
             print '</td></tr>';
1390 1390
         }
1391
-        elseif($mysoc->localtax1_assuj=="1")
1391
+        elseif ($mysoc->localtax1_assuj == "1")
1392 1392
         {
1393
-            print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td colspan="3">';
1394
-            print $form->selectyesno('localtax1assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1:0),1);
1393
+            print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td colspan="3">';
1394
+            print $form->selectyesno('localtax1assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1 : 0), 1);
1395 1395
             print '</td></tr>';
1396 1396
         }
1397
-        elseif($mysoc->localtax2_assuj=="1")
1397
+        elseif ($mysoc->localtax2_assuj == "1")
1398 1398
         {
1399
-            print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td colspan="3">';
1400
-            print $form->selectyesno('localtax2assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0),1);
1399
+            print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td colspan="3">';
1400
+            print $form->selectyesno('localtax2assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2 : 0), 1);
1401 1401
             print '</td></tr>';
1402 1402
         }
1403 1403
 
1404 1404
         // Type - Size
1405 1405
         print '<tr><td>'.$form->editfieldkey('ThirdPartyType', 'typent_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">'."\n";
1406
-        $sortparam=(empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT); // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on label.
1406
+        $sortparam = (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT); // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on label.
1407 1407
         print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, $sortparam);
1408
-        if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1408
+        if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1409 1409
         print '</td>';
1410 1410
         print '<td>'.$form->editfieldkey('Staff', 'effectif_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
1411 1411
         print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id);
1412
-        if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1412
+        if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1413 1413
         print '</td></tr>';
1414 1414
 
1415 1415
         // Legal Form
@@ -1430,10 +1430,10 @@  discard block
 block discarded – undo
1430 1430
 	    print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="'.$object->capital.'"> ';
1431 1431
         print '<span class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
1432 1432
 
1433
-        if (! empty($conf->global->MAIN_MULTILANGS))
1433
+        if (!empty($conf->global->MAIN_MULTILANGS))
1434 1434
         {
1435 1435
             print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
1436
-            print $formadmin->select_language(($object->default_lang?$object->default_lang:$conf->global->MAIN_LANG_DEFAULT),'default_lang',0,0,1,0,0,'maxwidth200onsmartphone');
1436
+            print $formadmin->select_language(($object->default_lang ? $object->default_lang : $conf->global->MAIN_LANG_DEFAULT), 'default_lang', 0, 0, 1, 0, 0, 'maxwidth200onsmartphone');
1437 1437
             print '</td>';
1438 1438
             print '</tr>';
1439 1439
         }
@@ -1444,18 +1444,18 @@  discard block
 block discarded – undo
1444 1444
 			print '<tr>';
1445 1445
 			print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
1446 1446
 	        print '<td colspan="3" class="maxwidthonsmartphone">';
1447
-	        print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
1447
+	        print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
1448 1448
 			print '</td></tr>';
1449 1449
 		}
1450 1450
 
1451 1451
 		// Categories
1452
-		if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
1452
+		if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire))
1453 1453
 		{
1454 1454
 			$langs->load('categories');
1455 1455
 
1456 1456
 			// Customer
1457 1457
 			//if ($object->prospect || $object->client || (! $object->fournisseur && ! empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER))) {
1458
-			print '<tr class="visibleifcustomer"><td class="toptd">' . $form->editfieldkey('CustomersProspectsCategoriesShort', 'custcats', '', $object, 0) . '</td><td colspan="3">';
1458
+			print '<tr class="visibleifcustomer"><td class="toptd">'.$form->editfieldkey('CustomersProspectsCategoriesShort', 'custcats', '', $object, 0).'</td><td colspan="3">';
1459 1459
 			$cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, 'parent', null, null, 1);
1460 1460
 			print $form->multiselectarray('custcats', $cate_arbo, GETPOST('custcats', 'array'), null, null, null, null, "90%");
1461 1461
 			print "</td></tr>";
@@ -1463,7 +1463,7 @@  discard block
 block discarded – undo
1463 1463
 
1464 1464
 			// Supplier
1465 1465
 			//if ($object->fournisseur) {
1466
-			print '<tr class="visibleifsupplier"><td class="toptd">' . $form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0) . '</td><td colspan="3">';
1466
+			print '<tr class="visibleifsupplier"><td class="toptd">'.$form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0).'</td><td colspan="3">';
1467 1467
 			$cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, 'parent', null, null, 1);
1468 1468
 			print $form->multiselectarray('suppcats', $cate_arbo, GETPOST('suppcats', 'array'), null, null, null, null, "90%");
1469 1469
 			print "</td></tr>";
@@ -1471,7 +1471,7 @@  discard block
 block discarded – undo
1471 1471
 		}
1472 1472
 
1473 1473
 		// Multicurrency
1474
-		if (! empty($conf->multicurrency->enabled))
1474
+		if (!empty($conf->multicurrency->enabled))
1475 1475
 		{
1476 1476
 			print '<tr>';
1477 1477
 			print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
@@ -1481,12 +1481,12 @@  discard block
 block discarded – undo
1481 1481
 		}
1482 1482
 
1483 1483
         // Other attributes
1484
-        $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
1485
-        $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
1484
+        $parameters = array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
1485
+        $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1486 1486
         print $hookmanager->resPrint;
1487 1487
         if (empty($reshook))
1488 1488
         {
1489
-        	print $object->showOptionals($extrafields,'edit');
1489
+        	print $object->showOptionals($extrafields, 'edit');
1490 1490
         }
1491 1491
 
1492 1492
 		// Assign a sale representative
@@ -1495,7 +1495,7 @@  discard block
 block discarded – undo
1495 1495
 		print '<td colspan="3" class="maxwidthonsmartphone">';
1496 1496
 		$userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, '', 0, '', '', 0, 1);
1497 1497
 		// Note: If user has no right to "see all thirdparties", we for selection of sale representative to him, so after creation he can see the record.
1498
-		print $form->multiselectarray('commercial', $userlist, (count(GETPOST('commercial', 'array')) > 0?GETPOST('commercial', 'array'):(empty($user->rights->societe->client->voir)?array($user->id):array())), null, null, null, null, "90%");
1498
+		print $form->multiselectarray('commercial', $userlist, (count(GETPOST('commercial', 'array')) > 0 ?GETPOST('commercial', 'array') : (empty($user->rights->societe->client->voir) ? array($user->id) : array())), null, null, null, null, "90%");
1499 1499
 		print '</td></tr>';
1500 1500
 
1501 1501
         // Ajout du logo
@@ -1512,7 +1512,7 @@  discard block
 block discarded – undo
1512 1512
 
1513 1513
         print '<div class="center">';
1514 1514
         print '<input type="submit" class="button" name="create" value="'.$langs->trans('AddThirdParty').'">';
1515
-        if (! empty($backtopage))
1515
+        if (!empty($backtopage))
1516 1516
         {
1517 1517
             print ' &nbsp; &nbsp; ';
1518 1518
             print '<input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'">';
@@ -1520,7 +1520,7 @@  discard block
 block discarded – undo
1520 1520
         else
1521 1521
         {
1522 1522
             print ' &nbsp; &nbsp; ';
1523
-            print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
1523
+            print '<input type="button" class="button" value="'.$langs->trans("Cancel").'" onClick="javascript:history.go(-1)">';
1524 1524
         }
1525 1525
         print '</div>'."\n";
1526 1526
 
@@ -1532,21 +1532,21 @@  discard block
 block discarded – undo
1532 1532
 
1533 1533
         if ($socid)
1534 1534
         {
1535
-        	$res=$object->fetch_optionals();
1535
+        	$res = $object->fetch_optionals();
1536 1536
             //if ($res < 0) { dol_print_error($db); exit; }
1537 1537
 
1538 1538
 	        $head = societe_prepare_head($object);
1539 1539
 
1540 1540
             // Load object modCodeTiers
1541
-            $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
1541
+            $module = (!empty($conf->global->SOCIETE_CODECLIENT_ADDON) ? $conf->global->SOCIETE_CODECLIENT_ADDON : 'mod_codeclient_leopard');
1542 1542
             if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
1543 1543
             {
1544
-                $module = substr($module, 0, dol_strlen($module)-4);
1544
+                $module = substr($module, 0, dol_strlen($module) - 4);
1545 1545
             }
1546
-            $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
1546
+            $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
1547 1547
             foreach ($dirsociete as $dirroot)
1548 1548
             {
1549
-                $res=dol_include_once($dirroot.$module.'.php');
1549
+                $res = dol_include_once($dirroot.$module.'.php');
1550 1550
                 if ($res) break;
1551 1551
             }
1552 1552
             $modCodeClient = new $module($db);
@@ -1555,15 +1555,15 @@  discard block
 block discarded – undo
1555 1555
             {
1556 1556
                 $prefixCustomerIsUsed = $modCodeClient->verif_prefixIsUsed();
1557 1557
             }
1558
-            $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
1558
+            $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
1559 1559
             if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
1560 1560
             {
1561
-                $module = substr($module, 0, dol_strlen($module)-4);
1561
+                $module = substr($module, 0, dol_strlen($module) - 4);
1562 1562
             }
1563
-            $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
1563
+            $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
1564 1564
             foreach ($dirsociete as $dirroot)
1565 1565
             {
1566
-                $res=dol_include_once($dirroot.$module.'.php');
1566
+                $res = dol_include_once($dirroot.$module.'.php');
1567 1567
                 if ($res) break;
1568 1568
             }
1569 1569
             $modCodeFournisseur = new $module($db);
@@ -1578,19 +1578,19 @@  discard block
 block discarded – undo
1578 1578
             if (GETPOSTISSET('name'))
1579 1579
             {
1580 1580
                 // We overwrite with values if posted
1581
-                $object->name					= GETPOST('name', 'alpha');
1581
+                $object->name = GETPOST('name', 'alpha');
1582 1582
                 $object->prefix_comm			= GETPOST('prefix_comm', 'alpha');
1583
-                $object->client					= GETPOST('client', 'int');
1583
+                $object->client = GETPOST('client', 'int');
1584 1584
                 $object->code_client			= GETPOST('customer_code', 'alpha');
1585 1585
                 $object->fournisseur			= GETPOST('fournisseur', 'int');
1586
-                $object->code_fournisseur		= GETPOST('supplier_code', 'alpha');
1587
-                $object->address				= GETPOST('address', 'alpha');
1588
-                $object->zip					= GETPOST('zipcode', 'alpha');
1589
-                $object->town					= GETPOST('town', 'alpha');
1590
-                $object->country_id				= GETPOST('country_id')?GETPOST('country_id', 'int'):$mysoc->country_id;
1586
+                $object->code_fournisseur = GETPOST('supplier_code', 'alpha');
1587
+                $object->address = GETPOST('address', 'alpha');
1588
+                $object->zip = GETPOST('zipcode', 'alpha');
1589
+                $object->town = GETPOST('town', 'alpha');
1590
+                $object->country_id = GETPOST('country_id') ?GETPOST('country_id', 'int') : $mysoc->country_id;
1591 1591
                 $object->state_id				= GETPOST('state_id', 'int');
1592 1592
                 $object->skype					= GETPOST('skype', 'alpha');
1593
-                $object->twitter				= GETPOST('twitter', 'alpha');
1593
+                $object->twitter = GETPOST('twitter', 'alpha');
1594 1594
                 $object->facebook				= GETPOST('facebook', 'alpha');
1595 1595
                 $object->phone					= GETPOST('phone', 'alpha');
1596 1596
                 $object->fax					= GETPOST('fax', 'alpha');
@@ -1603,15 +1603,15 @@  discard block
 block discarded – undo
1603 1603
                 $object->idprof4				= GETPOST('idprof4', 'alpha');
1604 1604
                 $object->idprof5				= GETPOST('idprof5', 'alpha');
1605 1605
                 $object->idprof6				= GETPOST('idprof6', 'alpha');
1606
-                $object->typent_id				= GETPOST('typent_id', 'int');
1607
-                $object->effectif_id			= GETPOST('effectif_id', 'int');
1606
+                $object->typent_id = GETPOST('typent_id', 'int');
1607
+                $object->effectif_id = GETPOST('effectif_id', 'int');
1608 1608
                 $object->barcode				= GETPOST('barcode', 'alpha');
1609
-                $object->forme_juridique_code	= GETPOST('forme_juridique_code', 'int');
1610
-                $object->default_lang			= GETPOST('default_lang', 'alpha');
1609
+                $object->forme_juridique_code = GETPOST('forme_juridique_code', 'int');
1610
+                $object->default_lang = GETPOST('default_lang', 'alpha');
1611 1611
 
1612 1612
                 $object->tva_assuj				= GETPOST('assujtva_value', 'int');
1613 1613
                 $object->tva_intra				= GETPOST('tva_intra', 'alpha');
1614
-                $object->status					= GETPOST('status', 'int');
1614
+                $object->status = GETPOST('status', 'int');
1615 1615
 
1616 1616
                 // Webservices url/key
1617 1617
                 $object->webservices_url        = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
@@ -1620,32 +1620,32 @@  discard block
 block discarded – undo
1620 1620
 				//Incoterms
1621 1621
 				if (!empty($conf->incoterm->enabled))
1622 1622
 				{
1623
-					$object->fk_incoterms			= GETPOST('incoterm_id', 'int');
1624
-					$object->location_incoterms		= GETPOST('lcoation_incoterms', 'alpha');
1623
+					$object->fk_incoterms = GETPOST('incoterm_id', 'int');
1624
+					$object->location_incoterms = GETPOST('lcoation_incoterms', 'alpha');
1625 1625
 				}
1626 1626
 
1627 1627
                 //Local Taxes
1628 1628
                 $object->localtax1_assuj		= GETPOST('localtax1assuj_value');
1629 1629
                 $object->localtax2_assuj		= GETPOST('localtax2assuj_value');
1630 1630
 
1631
-                $object->localtax1_value		=GETPOST('lt1');
1632
-                $object->localtax2_value		=GETPOST('lt2');
1631
+                $object->localtax1_value		= GETPOST('lt1');
1632
+                $object->localtax2_value		= GETPOST('lt2');
1633 1633
 
1634 1634
                 // We set country_id, and country_code label of the chosen country
1635 1635
                 if ($object->country_id > 0)
1636 1636
                 {
1637
-                	$tmparray=getCountry($object->country_id,'all');
1638
-                    $object->country_code	= $tmparray['code'];
1639
-                    $object->country		= $tmparray['label'];
1637
+                	$tmparray = getCountry($object->country_id, 'all');
1638
+                    $object->country_code = $tmparray['code'];
1639
+                    $object->country = $tmparray['label'];
1640 1640
                 }
1641 1641
             }
1642 1642
 
1643
-            if($object->localtax1_assuj==0){
1644
-            	$sub=0;
1645
-            }else{$sub=1;}
1646
-            if($object->localtax2_assuj==0){
1647
-            	$sub2=0;
1648
-            }else{$sub2=1;}
1643
+            if ($object->localtax1_assuj == 0) {
1644
+            	$sub = 0;
1645
+            } else {$sub = 1; }
1646
+            if ($object->localtax2_assuj == 0) {
1647
+            	$sub2 = 0;
1648
+            } else {$sub2 = 1; }
1649 1649
 
1650 1650
             if ($conf->use_javascript_ajax)
1651 1651
             {
@@ -1690,7 +1690,7 @@  discard block
 block discarded – undo
1690 1690
 				});
1691 1691
        			function init_customer_categ() {
1692 1692
 					console.log("is customer or prospect = "+jQuery("#customerprospect").val());
1693
-					if (jQuery("#customerprospect").val() == 0 && (jQuery("#fournisseur").val() == 0 || '.(empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER)?'1':'0').'))
1693
+					if (jQuery("#customerprospect").val() == 0 && (jQuery("#fournisseur").val() == 0 || '.(empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER) ? '1' : '0').'))
1694 1694
 					{
1695 1695
 						jQuery(".visibleifcustomer").hide();
1696 1696
 					}
@@ -1739,7 +1739,7 @@  discard block
 block discarded – undo
1739 1739
             print '<table class="border" width="100%">';
1740 1740
 
1741 1741
             // Ref/ID
1742
-			if (! empty($conf->global->MAIN_SHOW_TECHNICAL_ID))
1742
+			if (!empty($conf->global->MAIN_SHOW_TECHNICAL_ID))
1743 1743
 			{
1744 1744
 		        print '<tr><td class="titlefieldcreate">'.$langs->trans("ID").'</td><td colspan="3">';
1745 1745
             	print $object->ref;
@@ -1755,7 +1755,7 @@  discard block
 block discarded – undo
1755 1755
 	        print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.dol_escape_htmltag($object->name_alias).'"></td></tr>';
1756 1756
 
1757 1757
             // Prefix
1758
-            if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1758
+            if (!empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1759 1759
             {
1760 1760
                 print '<tr><td>'.$form->editfieldkey('Prefix', 'prefix', '', $object, 0).'</td><td colspan="3">';
1761 1761
                 // It does not change the prefix mode using the auto numbering prefix
@@ -1774,19 +1774,19 @@  discard block
 block discarded – undo
1774 1774
             // Prospect/Customer
1775 1775
             print '<tr><td>'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).'</td>';
1776 1776
 	        print '<td class="maxwidthonsmartphone"><select class="flat" name="client" id="customerprospect">';
1777
-            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($object->client==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1778
-            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="3"'.($object->client==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1779
-            if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($object->client==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1780
-            print '<option value="0"'.($object->client==0?' selected':'').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1777
+            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($object->client == 2 ? ' selected' : '').'>'.$langs->trans('Prospect').'</option>';
1778
+            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="3"'.($object->client == 3 ? ' selected' : '').'>'.$langs->trans('ProspectCustomer').'</option>';
1779
+            if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($object->client == 1 ? ' selected' : '').'>'.$langs->trans('Customer').'</option>';
1780
+            print '<option value="0"'.($object->client == 0 ? ' selected' : '').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1781 1781
             print '</select></td>';
1782 1782
             print '<td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
1783 1783
 
1784 1784
             print '<table class="nobordernopadding"><tr><td>';
1785 1785
             if ((!$object->code_client || $object->code_client == -1) && $modCodeClient->code_auto)
1786 1786
             {
1787
-                $tmpcode=$object->code_client;
1788
-                if (empty($tmpcode) && ! empty($object->oldcopy->code_client)) $tmpcode=$object->oldcopy->code_client; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1789
-                if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object,0);
1787
+                $tmpcode = $object->code_client;
1788
+                if (empty($tmpcode) && !empty($object->oldcopy->code_client)) $tmpcode = $object->oldcopy->code_client; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1789
+                if (empty($tmpcode) && !empty($modCodeClient->code_auto)) $tmpcode = $modCodeClient->getNextValue($object, 0);
1790 1790
                 print '<input type="text" name="customer_code" id="customer_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1791 1791
             }
1792 1792
             else if ($object->codeclient_modifiable())
@@ -1799,34 +1799,34 @@  discard block
 block discarded – undo
1799 1799
                 print '<input type="hidden" name="customer_code" value="'.dol_escape_htmltag($object->code_client).'">';
1800 1800
             }
1801 1801
             print '</td><td>';
1802
-            $s=$modCodeClient->getToolTip($langs,$object,0);
1803
-            print $form->textwithpicto('',$s,1);
1802
+            $s = $modCodeClient->getToolTip($langs, $object, 0);
1803
+            print $form->textwithpicto('', $s, 1);
1804 1804
             print '</td></tr></table>';
1805 1805
 
1806 1806
             print '</td></tr>';
1807 1807
 
1808 1808
             // Supplier
1809
-            if ((! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1810
-            	|| (! empty($conf->supplier_proposal->enabled) && ! empty($user->rights->supplier_proposal->lire)))
1809
+            if ((!empty($conf->fournisseur->enabled) && !empty($user->rights->fournisseur->lire))
1810
+            	|| (!empty($conf->supplier_proposal->enabled) && !empty($user->rights->supplier_proposal->lire)))
1811 1811
             {
1812 1812
                 print '<tr>';
1813 1813
                 print '<td>'.$form->editfieldkey('Supplier', 'fournisseur', '', $object, 0, 'string', '', 1).'</td><td class="maxwidthonsmartphone">';
1814
-                print $form->selectyesno("fournisseur",$object->fournisseur,1);
1814
+                print $form->selectyesno("fournisseur", $object->fournisseur, 1);
1815 1815
                 print '</td>';
1816 1816
                 print '<td>';
1817
-                if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1817
+                if (!empty($conf->fournisseur->enabled) && !empty($user->rights->fournisseur->lire))
1818 1818
                 {
1819 1819
                 	print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0);
1820 1820
                 }
1821 1821
                 print '</td><td>';
1822
-                if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1822
+                if (!empty($conf->fournisseur->enabled) && !empty($user->rights->fournisseur->lire))
1823 1823
                 {
1824 1824
 	                print '<table class="nobordernopadding"><tr><td>';
1825 1825
 	                if ((!$object->code_fournisseur || $object->code_fournisseur == -1) && $modCodeFournisseur->code_auto)
1826 1826
 	                {
1827
-	                    $tmpcode=$object->code_fournisseur;
1828
-	                    if (empty($tmpcode) && ! empty($object->oldcopy->code_fournisseur)) $tmpcode=$object->oldcopy->code_fournisseur; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1829
-	                    if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1827
+	                    $tmpcode = $object->code_fournisseur;
1828
+	                    if (empty($tmpcode) && !empty($object->oldcopy->code_fournisseur)) $tmpcode = $object->oldcopy->code_fournisseur; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1829
+	                    if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) $tmpcode = $modCodeFournisseur->getNextValue($object, 1);
1830 1830
 	                    print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1831 1831
 	                }
1832 1832
 	                else if ($object->codefournisseur_modifiable())
@@ -1839,15 +1839,15 @@  discard block
 block discarded – undo
1839 1839
 	                    print '<input type="hidden" name="supplier_code" value="'.$object->code_fournisseur.'">';
1840 1840
 	                }
1841 1841
 	                print '</td><td>';
1842
-	                $s=$modCodeFournisseur->getToolTip($langs,$object,1);
1843
-	                print $form->textwithpicto('',$s,1);
1842
+	                $s = $modCodeFournisseur->getToolTip($langs, $object, 1);
1843
+	                print $form->textwithpicto('', $s, 1);
1844 1844
 	                print '</td></tr></table>';
1845 1845
                 }
1846 1846
                 print '</td></tr>';
1847 1847
             }
1848 1848
 
1849 1849
             // Barcode
1850
-            if (! empty($conf->barcode->enabled))
1850
+            if (!empty($conf->barcode->enabled))
1851 1851
             {
1852 1852
                 print '<tr><td class="tdtop">'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).'</td>';
1853 1853
 	            print '<td colspan="3"><input type="text" name="barcode" id="barcode" value="'.$object->barcode.'">';
@@ -1856,7 +1856,7 @@  discard block
 block discarded – undo
1856 1856
 
1857 1857
             // Status
1858 1858
             print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0).'</td><td colspan="3">';
1859
-            print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'),'1'=>$langs->trans('InActivity')),$object->status);
1859
+            print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), $object->status);
1860 1860
             print '</td></tr>';
1861 1861
 
1862 1862
             // Address
@@ -1874,14 +1874,14 @@  discard block
 block discarded – undo
1874 1874
 
1875 1875
             // Country
1876 1876
             print '<tr><td>'.$form->editfieldkey('Country', 'selectcounty_id', '', $object, 0).'</td><td colspan="3">';
1877
-            print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id),'country_id');
1878
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1877
+            print $form->select_country((GETPOST('country_id') != '' ?GETPOST('country_id') : $object->country_id), 'country_id');
1878
+            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1879 1879
             print '</td></tr>';
1880 1880
 
1881 1881
             // State
1882 1882
             if (empty($conf->global->SOCIETE_DISABLE_STATE))
1883 1883
             {
1884
-                if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1884
+                if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1885 1885
                 {
1886 1886
                     print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td colspan="3">';
1887 1887
                 }
@@ -1890,32 +1890,32 @@  discard block
 block discarded – undo
1890 1890
                     print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td colspan="3">';
1891 1891
                 }
1892 1892
 
1893
-                print $formcompany->select_state($object->state_id,$object->country_code);
1893
+                print $formcompany->select_state($object->state_id, $object->country_code);
1894 1894
                 print '</td></tr>';
1895 1895
             }
1896 1896
 
1897 1897
             // EMail / Web
1898
-            print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', (! empty($conf->global->SOCIETE_EMAIL_MANDATORY))).'</td>';
1898
+            print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', (!empty($conf->global->SOCIETE_EMAIL_MANDATORY))).'</td>';
1899 1899
 	        print '<td colspan="3"><input type="text" name="email" id="email" size="32" value="'.$object->email.'"></td></tr>';
1900 1900
             print '<tr><td>'.$form->editfieldkey('Web', 'url', '', $object, 0).'</td>';
1901 1901
 	        print '<td colspan="3"><input type="text" name="url" id="url" size="32" value="'.$object->url.'"></td></tr>';
1902 1902
 
1903
-	        if (! empty($conf->socialnetworks->enabled))
1903
+	        if (!empty($conf->socialnetworks->enabled))
1904 1904
 	        {
1905 1905
 	        	// Skype
1906
-	        	if (! empty($conf->global->SOCIALNETWORKS_SKYPE))
1906
+	        	if (!empty($conf->global->SOCIALNETWORKS_SKYPE))
1907 1907
 	        	{
1908 1908
 	        		print '<tr><td>'.$form->editfieldkey('Skype', 'skype', '', $object, 0).'</td>';
1909 1909
 	        		print '<td colspan="3"><input type="text" name="skype" id="skype" value="'.$object->skype.'"></td></tr>';
1910 1910
 	        	}
1911 1911
 	        	// Twitter
1912
-	        	if (! empty($conf->global->SOCIALNETWORKS_TWITTER))
1912
+	        	if (!empty($conf->global->SOCIALNETWORKS_TWITTER))
1913 1913
 	        	{
1914 1914
 	        		print '<tr><td>'.$form->editfieldkey('Twitter', 'twitter', '', $object, 0).'</td>';
1915 1915
 	        		print '<td colspan="3"><input type="text" name="twitter" id="twitter" value="'.$object->twitter.'"></td></tr>';
1916 1916
 	        	}
1917 1917
 	        	// Facebook
1918
-	        	if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK))
1918
+	        	if (!empty($conf->global->SOCIALNETWORKS_FACEBOOK))
1919 1919
 	        	{
1920 1920
 	        		print '<tr><td>'.$form->editfieldkey('Facebook', 'facebook', '', $object, 0).'</td>';
1921 1921
 	        		print '<td colspan="3"><input type="text" name="facebook" id="facebook" value="'.$object->facebook.'"></td></tr>';
@@ -1929,18 +1929,18 @@  discard block
 block discarded – undo
1929 1929
 	        print '<td><input type="text" name="fax" id="fax" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->fax.'"></td></tr>';
1930 1930
 
1931 1931
             // Prof ids
1932
-            $i=1; $j=0;
1932
+            $i = 1; $j = 0;
1933 1933
             while ($i <= 6)
1934 1934
             {
1935
-                $idprof=$langs->transcountry('ProfId'.$i,$object->country_code);
1936
-                if ($idprof!='-')
1935
+                $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
1936
+                if ($idprof != '-')
1937 1937
                 {
1938
-	                $key='idprof'.$i;
1938
+	                $key = 'idprof'.$i;
1939 1939
 
1940 1940
 	                if (($j % 2) == 0) print '<tr>';
1941 1941
 
1942
-	                $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
1943
-	                print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', ! (empty($conf->global->$idprof_mandatory) || ! $object->isACompany())).'</td><td>';
1942
+	                $idprof_mandatory = 'SOCIETE_IDPROF'.($i).'_MANDATORY';
1943
+	                print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', !(empty($conf->global->$idprof_mandatory) || !$object->isACompany())).'</td><td>';
1944 1944
 	                print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
1945 1945
                     print '</td>';
1946 1946
                     if (($j % 2) == 1) print '</tr>';
@@ -1952,53 +1952,53 @@  discard block
 block discarded – undo
1952 1952
 
1953 1953
             // VAT is used
1954 1954
             print '<tr><td>'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).'</td><td colspan="3">';
1955
-            print $form->selectyesno('assujtva_value',$object->tva_assuj,1);
1955
+            print $form->selectyesno('assujtva_value', $object->tva_assuj, 1);
1956 1956
             print '</td></tr>';
1957 1957
 
1958 1958
             // Local Taxes
1959 1959
             //TODO: Place into a function to control showing by country or study better option
1960
-            if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
1960
+            if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1")
1961 1961
             {
1962
-                print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed",$mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td>';
1963
-                print $form->selectyesno('localtax1assuj_value',$object->localtax1_assuj,1);
1964
-                if(! isOnlyOneLocalTax(1))
1962
+                print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td>';
1963
+                print $form->selectyesno('localtax1assuj_value', $object->localtax1_assuj, 1);
1964
+                if (!isOnlyOneLocalTax(1))
1965 1965
                 {
1966
-                    print '<span class="cblt1">     '.$langs->transcountry("Type",$mysoc->country_code).': ';
1967
-                    $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
1966
+                    print '<span class="cblt1">     '.$langs->transcountry("Type", $mysoc->country_code).': ';
1967
+                    $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
1968 1968
                     print '</span>';
1969 1969
                 }
1970 1970
                 print '</td>';
1971 1971
 
1972
-                print '<td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed",$mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td>';
1973
-                print $form->selectyesno('localtax2assuj_value',$object->localtax2_assuj,1);
1974
-                if  (! isOnlyOneLocalTax(2))
1972
+                print '<td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td>';
1973
+                print $form->selectyesno('localtax2assuj_value', $object->localtax2_assuj, 1);
1974
+                if (!isOnlyOneLocalTax(2))
1975 1975
                 {
1976
-                    print '<span class="cblt2">     '.$langs->transcountry("Type",$mysoc->country_code).': ';
1977
-                    $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
1976
+                    print '<span class="cblt2">     '.$langs->transcountry("Type", $mysoc->country_code).': ';
1977
+                    $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
1978 1978
                     print '</span>';
1979 1979
                 }
1980 1980
                 print '</td></tr>';
1981 1981
             }
1982
-            elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
1982
+            elseif ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj != "1")
1983 1983
             {
1984
-                print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed",$mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td colspan="3">';
1985
-                print $form->selectyesno('localtax1assuj_value',$object->localtax1_assuj,1);
1986
-                if(! isOnlyOneLocalTax(1))
1984
+                print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td colspan="3">';
1985
+                print $form->selectyesno('localtax1assuj_value', $object->localtax1_assuj, 1);
1986
+                if (!isOnlyOneLocalTax(1))
1987 1987
                 {
1988
-                    print '<span class="cblt1">     '.$langs->transcountry("Type",$mysoc->country_code).': ';
1989
-                    $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
1988
+                    print '<span class="cblt1">     '.$langs->transcountry("Type", $mysoc->country_code).': ';
1989
+                    $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
1990 1990
                     print '</span>';
1991 1991
                 }
1992 1992
                 print '</td></tr>';
1993 1993
             }
1994
-            elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
1994
+            elseif ($mysoc->localtax2_assuj == "1" && $mysoc->localtax1_assuj != "1")
1995 1995
             {
1996
-                print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed",$mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td colspan="3">';
1997
-                print $form->selectyesno('localtax2assuj_value',$object->localtax2_assuj,1);
1998
-                if(! isOnlyOneLocalTax(2))
1996
+                print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td colspan="3">';
1997
+                print $form->selectyesno('localtax2assuj_value', $object->localtax2_assuj, 1);
1998
+                if (!isOnlyOneLocalTax(2))
1999 1999
                 {
2000
-                    print '<span class="cblt2">     '.$langs->transcountry("Type",$mysoc->country_code).': ';
2001
-                    $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2000
+                    print '<span class="cblt2">     '.$langs->transcountry("Type", $mysoc->country_code).': ';
2001
+                    $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
2002 2002
                     print '</span>';
2003 2003
                 }
2004 2004
                 print '</td></tr>';
@@ -2007,11 +2007,11 @@  discard block
 block discarded – undo
2007 2007
             // VAT Code
2008 2008
             print '<tr><td>'.$form->editfieldkey('VATIntra', 'intra_vat', '', $object, 0).'</td>';
2009 2009
             print '<td colspan="3">';
2010
-            $s ='<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
2010
+            $s = '<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
2011 2011
 
2012 2012
             if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object))
2013 2013
             {
2014
-                $s.=' &nbsp; ';
2014
+                $s .= ' &nbsp; ';
2015 2015
 
2016 2016
                 if ($conf->use_javascript_ajax)
2017 2017
                 {
@@ -2022,12 +2022,12 @@  discard block
 block discarded – undo
2022 2022
                     print "}\n";
2023 2023
                     print '</script>';
2024 2024
                     print "\n";
2025
-                    $s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
2026
-                    $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
2025
+                    $s .= '<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
2026
+                    $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->trans("VATIntraCheck")), 1);
2027 2027
                 }
2028 2028
                 else
2029 2029
                 {
2030
-                    $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
2030
+                    $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", $object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
2031 2031
                 }
2032 2032
             }
2033 2033
             print $s;
@@ -2036,12 +2036,12 @@  discard block
 block discarded – undo
2036 2036
 
2037 2037
             // Type - Size
2038 2038
             print '<tr><td>'.$form->editfieldkey('ThirdPartyType', 'typent_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
2039
-            print $form->selectarray("typent_id",$formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
2040
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
2039
+            print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT));
2040
+            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
2041 2041
             print '</td>';
2042 2042
             print '<td>'.$form->editfieldkey('Staff', 'effectif_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
2043
-            print $form->selectarray("effectif_id",$formcompany->effectif_array(0), $object->effectif_id);
2044
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
2043
+            print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id);
2044
+            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
2045 2045
             print '</td></tr>';
2046 2046
 
2047 2047
             // Juridical type
@@ -2056,10 +2056,10 @@  discard block
 block discarded – undo
2056 2056
 	        print '"> <font class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</font></td></tr>';
2057 2057
 
2058 2058
             // Default language
2059
-            if (! empty($conf->global->MAIN_MULTILANGS))
2059
+            if (!empty($conf->global->MAIN_MULTILANGS))
2060 2060
             {
2061 2061
                 print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3">'."\n";
2062
-                print $formadmin->select_language($object->default_lang,'default_lang',0,0,1);
2062
+                print $formadmin->select_language($object->default_lang, 'default_lang', 0, 0, 1);
2063 2063
                 print '</td>';
2064 2064
                 print '</tr>';
2065 2065
             }
@@ -2070,20 +2070,20 @@  discard block
 block discarded – undo
2070 2070
             	print '<tr>';
2071 2071
       				print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
2072 2072
             	print '<td colspan="3" class="maxwidthonsmartphone">';
2073
-            	print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
2073
+            	print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
2074 2074
             	print '</td></tr>';
2075 2075
             }
2076 2076
 
2077 2077
 			// Categories
2078
-			if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
2078
+			if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire))
2079 2079
 			{
2080 2080
 				// Customer
2081
-				print '<tr class="visibleifcustomer"><td>' . $form->editfieldkey('CustomersCategoriesShort', 'custcats', '', $object, 0) . '</td>';
2081
+				print '<tr class="visibleifcustomer"><td>'.$form->editfieldkey('CustomersCategoriesShort', 'custcats', '', $object, 0).'</td>';
2082 2082
 				print '<td colspan="3">';
2083 2083
 				$cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, null, null, null, 1);
2084 2084
 				$c = new Categorie($db);
2085 2085
 				$cats = $c->containing($object->id, Categorie::TYPE_CUSTOMER);
2086
-				$arrayselected=array();
2086
+				$arrayselected = array();
2087 2087
 				foreach ($cats as $cat) {
2088 2088
 					$arrayselected[] = $cat->id;
2089 2089
 				}
@@ -2091,12 +2091,12 @@  discard block
 block discarded – undo
2091 2091
 				print "</td></tr>";
2092 2092
 
2093 2093
 				// Supplier
2094
-				print '<tr class="visibleifsupplier"><td>' . $form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0) . '</td>';
2094
+				print '<tr class="visibleifsupplier"><td>'.$form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0).'</td>';
2095 2095
 				print '<td colspan="3">';
2096 2096
 				$cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, null, null, null, 1);
2097 2097
 				$c = new Categorie($db);
2098 2098
 				$cats = $c->containing($object->id, Categorie::TYPE_SUPPLIER);
2099
-				$arrayselected=array();
2099
+				$arrayselected = array();
2100 2100
 				foreach ($cats as $cat) {
2101 2101
 					$arrayselected[] = $cat->id;
2102 2102
 				}
@@ -2105,7 +2105,7 @@  discard block
 block discarded – undo
2105 2105
 			}
2106 2106
 
2107 2107
 			// Multicurrency
2108
-			if (! empty($conf->multicurrency->enabled))
2108
+			if (!empty($conf->multicurrency->enabled))
2109 2109
 			{
2110 2110
 				print '<tr>';
2111 2111
 				print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
@@ -2115,12 +2115,12 @@  discard block
 block discarded – undo
2115 2115
 			}
2116 2116
 
2117 2117
             // Other attributes
2118
-            $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
2119
-            $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
2118
+            $parameters = array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
2119
+            $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2120 2120
             print $hookmanager->resPrint;
2121 2121
             if (empty($reshook))
2122 2122
             {
2123
-            	print $object->showOptionals($extrafields,'edit');
2123
+            	print $object->showOptionals($extrafields, 'edit');
2124 2124
             }
2125 2125
 
2126 2126
             // Webservices url/key
@@ -2135,8 +2135,8 @@  discard block
 block discarded – undo
2135 2135
             print '<tr class="hideonsmartphone">';
2136 2136
             print '<td>'.$form->editfieldkey('Logo', 'photoinput', '', $object, 0).'</td>';
2137 2137
             print '<td colspan="3">';
2138
-            if ($object->logo) print $form->showphoto('societe',$object);
2139
-            $caneditfield=1;
2138
+            if ($object->logo) print $form->showphoto('societe', $object);
2139
+            $caneditfield = 1;
2140 2140
             if ($caneditfield)
2141 2141
             {
2142 2142
                 if ($object->logo) print "<br>\n";
@@ -2179,7 +2179,7 @@  discard block
 block discarded – undo
2179 2179
          * View
2180 2180
          */
2181 2181
 
2182
-        if (!empty($object->id)) $res=$object->fetch_optionals();
2182
+        if (!empty($object->id)) $res = $object->fetch_optionals();
2183 2183
         //if ($res < 0) { dol_print_error($db); exit; }
2184 2184
 
2185 2185
 
@@ -2207,11 +2207,11 @@  discard block
 block discarded – undo
2207 2207
 		    print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("MergeThirdparties"), $langs->trans("ConfirmMergeThirdparties"), "confirm_merge", $formquestion, 'no', 1, 250);
2208 2208
 	    }
2209 2209
 
2210
-        dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error');
2210
+        dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
2211 2211
 
2212 2212
         $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
2213 2213
 
2214
-        dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
2214
+        dol_banner_tab($object, 'socid', $linkback, ($user->societe_id ? 0 : 1), 'rowid', 'nom');
2215 2215
 
2216 2216
 
2217 2217
         print '<div class="fichecenter">';
@@ -2226,7 +2226,7 @@  discard block
 block discarded – undo
2226 2226
     	print '</td></tr>';
2227 2227
 
2228 2228
     	// Supplier
2229
-   		if (! empty($conf->fournisseur->enabled) || ! empty($conf->supplier_proposal->enabled))
2229
+   		if (!empty($conf->fournisseur->enabled) || !empty($conf->supplier_proposal->enabled))
2230 2230
     	{
2231 2231
     		print '<tr><td>'.$langs->trans('Supplier').'</td><td>';
2232 2232
     		print yn($object->fournisseur);
@@ -2234,10 +2234,10 @@  discard block
 block discarded – undo
2234 2234
     	}
2235 2235
 
2236 2236
     	// Prefix
2237
-        if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
2237
+        if (!empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
2238 2238
         {
2239 2239
             print '<tr><td>'.$langs->trans('Prefix').'</td><td>'.$object->prefix_comm.'</td>';
2240
-            print $htmllogobar; $htmllogobar='';
2240
+            print $htmllogobar; $htmllogobar = '';
2241 2241
             print '</tr>';
2242 2242
         }
2243 2243
 
@@ -2249,49 +2249,49 @@  discard block
 block discarded – undo
2249 2249
             print $object->code_client;
2250 2250
             if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
2251 2251
             print '</td>';
2252
-            print $htmllogobar; $htmllogobar='';
2252
+            print $htmllogobar; $htmllogobar = '';
2253 2253
             print '</tr>';
2254 2254
         }
2255 2255
 
2256 2256
         // Supplier code
2257
-        if (! empty($conf->fournisseur->enabled) && $object->fournisseur && ! empty($user->rights->fournisseur->lire))
2257
+        if (!empty($conf->fournisseur->enabled) && $object->fournisseur && !empty($user->rights->fournisseur->lire))
2258 2258
         {
2259 2259
             print '<tr><td>';
2260 2260
             print $langs->trans('SupplierCode').'</td><td>';
2261 2261
             print $object->code_fournisseur;
2262 2262
             if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
2263 2263
             print '</td>';
2264
-            print $htmllogobar; $htmllogobar='';
2264
+            print $htmllogobar; $htmllogobar = '';
2265 2265
             print '</tr>';
2266 2266
         }
2267 2267
 
2268 2268
         // Barcode
2269
-        if (! empty($conf->barcode->enabled))
2269
+        if (!empty($conf->barcode->enabled))
2270 2270
         {
2271 2271
             print '<tr><td>';
2272 2272
             print $langs->trans('Gencod').'</td><td>'.$object->barcode;
2273 2273
             print '</td>';
2274
-			if ($htmllogobar) $htmllogobar.=$form->showbarcode($object);
2274
+			if ($htmllogobar) $htmllogobar .= $form->showbarcode($object);
2275 2275
             print $htmllogobar;
2276
-			$htmllogobar='';
2276
+			$htmllogobar = '';
2277 2277
             print '</tr>';
2278 2278
         }
2279 2279
 
2280 2280
         // Prof ids
2281
-        $i=1; $j=0;
2281
+        $i = 1; $j = 0;
2282 2282
         while ($i <= 6)
2283 2283
         {
2284
-            $idprof=$langs->transcountry('ProfId'.$i,$object->country_code);
2285
-            if ($idprof!='-')
2284
+            $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
2285
+            if ($idprof != '-')
2286 2286
             {
2287 2287
                 //if (($j % 2) == 0) print '<tr>';
2288 2288
                 print '<tr>';
2289 2289
             	print '<td>'.$idprof.'</td><td>';
2290
-                $key='idprof'.$i;
2290
+                $key = 'idprof'.$i;
2291 2291
                 print $object->$key;
2292 2292
                 if ($object->$key)
2293 2293
                 {
2294
-                    if ($object->id_prof_check($i,$object) > 0) print ' &nbsp; '.$object->id_prof_url($i,$object);
2294
+                    if ($object->id_prof_check($i, $object) > 0) print ' &nbsp; '.$object->id_prof_url($i, $object);
2295 2295
                     else print ' <font class="error">('.$langs->trans("ErrorWrongValue").')</font>';
2296 2296
                 }
2297 2297
                 print '</td>';
@@ -2312,7 +2312,7 @@  discard block
 block discarded – undo
2312 2312
         {
2313 2313
 	        // VAT is used
2314 2314
 	        print '<tr><td>';
2315
-	        print $form->textwithpicto($langs->trans('VATIsUsed'),$langs->trans('VATIsUsedWhenSelling'));
2315
+	        print $form->textwithpicto($langs->trans('VATIsUsed'), $langs->trans('VATIsUsedWhenSelling'));
2316 2316
 	        print '</td><td>';
2317 2317
 	        print yn($object->tva_assuj);
2318 2318
 	        print '</td>';
@@ -2320,26 +2320,26 @@  discard block
 block discarded – undo
2320 2320
         }
2321 2321
 
2322 2322
 		// Local Taxes
2323
-        if ($object->fournisseur || $mysoc->country_code=='ES')
2323
+        if ($object->fournisseur || $mysoc->country_code == 'ES')
2324 2324
         {
2325
-        	if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
2325
+        	if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1")
2326 2326
 			{
2327
-			    print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
2327
+			    print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
2328 2328
 			    print yn($object->localtax1_assuj);
2329
-			    print '</td></tr><tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
2329
+			    print '</td></tr><tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
2330 2330
 			    print yn($object->localtax2_assuj);
2331 2331
 			    print '</td></tr>';
2332 2332
 
2333
-			    if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1)))
2333
+			    if ($object->localtax1_assuj == "1" && (!isOnlyOneLocalTax(1)))
2334 2334
 			    {
2335 2335
 			        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2336 2336
 			        print '<input type="hidden" name="action" value="set_localtax1">';
2337 2337
 			        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2338
-			        print '<tr><td>'.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2339
-			        if($action == 'editRE')
2338
+			        print '<tr><td>'.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</td>';
2339
+			        if ($action == 'editRE')
2340 2340
 			        {
2341 2341
 			            print '<td align="left">';
2342
-			            $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2342
+			            $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
2343 2343
 			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2344 2344
 			        }
2345 2345
 			        else
@@ -2348,60 +2348,60 @@  discard block
 block discarded – undo
2348 2348
 			        }
2349 2349
 			        print '</tr></form>';
2350 2350
 			    }
2351
-			    if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2)))
2351
+			    if ($object->localtax2_assuj == "1" && (!isOnlyOneLocalTax(2)))
2352 2352
 			    {
2353 2353
 			        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2354 2354
 			        print '<input type="hidden" name="action" value="set_localtax2">';
2355 2355
 			        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2356
-			        print '<tr><td>'.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2357
-			        if($action == 'editIRPF'){
2356
+			        print '<tr><td>'.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</td>';
2357
+			        if ($action == 'editIRPF') {
2358 2358
 			            print '<td align="left">';
2359
-			            $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2359
+			            $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
2360 2360
 			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2361
-			        }else{
2361
+			        } else {
2362 2362
 			            print '<td>'.$object->localtax2_value.'</td>';
2363 2363
 			        }
2364 2364
 			        print '</tr></form>';
2365 2365
 			    }
2366 2366
 			}
2367
-			elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
2367
+			elseif ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj != "1")
2368 2368
 			{
2369
-			    print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
2369
+			    print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
2370 2370
 			    print yn($object->localtax1_assuj);
2371 2371
 			    print '</td></tr>';
2372
-			    if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1)))
2372
+			    if ($object->localtax1_assuj == "1" && (!isOnlyOneLocalTax(1)))
2373 2373
 			    {
2374 2374
 			        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2375 2375
 			        print '<input type="hidden" name="action" value="set_localtax1">';
2376 2376
 			        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2377
-			        print '<tr><td> '.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2378
-			        if($action == 'editRE'){
2377
+			        print '<tr><td> '.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</td>';
2378
+			        if ($action == 'editRE') {
2379 2379
 			            print '<td align="left">';
2380
-			            $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2380
+			            $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
2381 2381
 			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2382
-			        }else{
2382
+			        } else {
2383 2383
 			            print '<td>'.$object->localtax1_value.'</td>';
2384 2384
 			        }
2385 2385
 			        print '</tr></form>';
2386 2386
 			    }
2387 2387
 			}
2388
-			elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
2388
+			elseif ($mysoc->localtax2_assuj == "1" && $mysoc->localtax1_assuj != "1")
2389 2389
 			{
2390
-			    print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
2390
+			    print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
2391 2391
 			    print yn($object->localtax2_assuj);
2392 2392
 			    print '</td></tr>';
2393
-			    if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2)))
2393
+			    if ($object->localtax2_assuj == "1" && (!isOnlyOneLocalTax(2)))
2394 2394
 			    {
2395 2395
 
2396 2396
 			        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2397 2397
 			        print '<input type="hidden" name="action" value="set_localtax2">';
2398 2398
 			        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2399
-			        print '<tr><td> '.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2400
-			        if($action == 'editIRPF'){
2399
+			        print '<tr><td> '.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</td>';
2400
+			        if ($action == 'editIRPF') {
2401 2401
 			            print '<td align="left">';
2402
-			            $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2402
+			            $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
2403 2403
 			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2404
-			        }else{
2404
+			        } else {
2405 2405
 			            print '<td>'.$object->localtax2_value.'</td>';
2406 2406
 			        }
2407 2407
 			        print '</tr></form>';
@@ -2414,13 +2414,13 @@  discard block
 block discarded – undo
2414 2414
 		print '<td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
2415 2415
         if ($object->tva_intra)
2416 2416
         {
2417
-            $s='';
2418
-            $s.=$object->tva_intra;
2419
-            $s.='<input type="hidden" id="tva_intra" name="tva_intra" maxlength="20" value="'.$object->tva_intra.'">';
2417
+            $s = '';
2418
+            $s .= $object->tva_intra;
2419
+            $s .= '<input type="hidden" id="tva_intra" name="tva_intra" maxlength="20" value="'.$object->tva_intra.'">';
2420 2420
 
2421 2421
             if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object))
2422 2422
             {
2423
-                $s.=' &nbsp; ';
2423
+                $s .= ' &nbsp; ';
2424 2424
 
2425 2425
                 if ($conf->use_javascript_ajax)
2426 2426
                 {
@@ -2431,12 +2431,12 @@  discard block
 block discarded – undo
2431 2431
                     print "}\n";
2432 2432
                     print '</script>';
2433 2433
                     print "\n";
2434
-                    $s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT( $(\'#tva_intra\').val() );">'.$langs->trans("VATIntraCheck").'</a>';
2435
-                    $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
2434
+                    $s .= '<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT( $(\'#tva_intra\').val() );">'.$langs->trans("VATIntraCheck").'</a>';
2435
+                    $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->trans("VATIntraCheck")), 1);
2436 2436
                 }
2437 2437
                 else
2438 2438
                 {
2439
-                    $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
2439
+                    $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", $object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
2440 2440
                 }
2441 2441
             }
2442 2442
             print $s;
@@ -2450,7 +2450,7 @@  discard block
 block discarded – undo
2450 2450
 
2451 2451
         // Type + Staff
2452 2452
         $arr = $formcompany->typent_array(1);
2453
-        $object->typent= $arr[$object->typent_code];
2453
+        $object->typent = $arr[$object->typent_code];
2454 2454
         print '<tr><td>'.$langs->trans("ThirdPartyType").'</td><td>'.$object->typent.'</td>';
2455 2455
         print '<tr><td>'.$langs->trans("Staff").'</td><td>'.$object->effectif.'</td></tr>';
2456 2456
 
@@ -2463,11 +2463,11 @@  discard block
 block discarded – undo
2463 2463
         print '<table class="border tableforfield" width="100%">';
2464 2464
 
2465 2465
     	// Tags / categories
2466
-		if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
2466
+		if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire))
2467 2467
 		{
2468 2468
 			// Customer
2469
-			if ($object->prospect || $object->client || (! $object->fournisseur && ! empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER))) {
2470
-				print '<tr><td>' . $langs->trans("CustomersCategoriesShort") . '</td>';
2469
+			if ($object->prospect || $object->client || (!$object->fournisseur && !empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER))) {
2470
+				print '<tr><td>'.$langs->trans("CustomersCategoriesShort").'</td>';
2471 2471
 				print '<td>';
2472 2472
 				print $form->showCategories($object->id, 'customer', 1);
2473 2473
 				print "</td></tr>";
@@ -2475,7 +2475,7 @@  discard block
 block discarded – undo
2475 2475
 
2476 2476
 			// Supplier
2477 2477
 			if ($object->fournisseur) {
2478
-				print '<tr><td>' . $langs->trans("SuppliersCategoriesShort") . '</td>';
2478
+				print '<tr><td>'.$langs->trans("SuppliersCategoriesShort").'</td>';
2479 2479
 				print '<td>';
2480 2480
 				print $form->showCategories($object->id, 'supplier', 1);
2481 2481
 				print "</td></tr>";
@@ -2487,19 +2487,19 @@  discard block
 block discarded – undo
2487 2487
 
2488 2488
         // Capital
2489 2489
         print '<tr><td>'.$langs->trans('Capital').'</td><td>';
2490
-        if ($object->capital) print price($object->capital,'',$langs,0,-1,-1, $conf->currency);
2490
+        if ($object->capital) print price($object->capital, '', $langs, 0, -1, -1, $conf->currency);
2491 2491
         else print '&nbsp;';
2492 2492
         print '</td></tr>';
2493 2493
 
2494 2494
         // Default language
2495
-        if (! empty($conf->global->MAIN_MULTILANGS))
2495
+        if (!empty($conf->global->MAIN_MULTILANGS))
2496 2496
         {
2497 2497
             require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2498 2498
             print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
2499 2499
             //$s=picto_from_langcode($object->default_lang);
2500 2500
             //print ($s?$s.' ':'');
2501 2501
             $langs->load("languages");
2502
-            $labellang = ($object->default_lang?$langs->trans('Language_'.$object->default_lang):'');
2502
+            $labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
2503 2503
             print $labellang;
2504 2504
             print '</td></tr>';
2505 2505
         }
@@ -2511,7 +2511,7 @@  discard block
 block discarded – undo
2511 2511
         	print '<table width="100%" class="nobordernopadding"><tr><td>';
2512 2512
         	print $langs->trans('IncotermLabel');
2513 2513
         	print '<td><td align="right">';
2514
-        	if ($user->rights->societe->creer) print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$object->id.'&action=editincoterm">'.img_edit('',1).'</a>';
2514
+        	if ($user->rights->societe->creer) print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$object->id.'&action=editincoterm">'.img_edit('', 1).'</a>';
2515 2515
         	else print '&nbsp;';
2516 2516
         	print '</td></tr></table>';
2517 2517
         	print '</td>';
@@ -2522,24 +2522,24 @@  discard block
 block discarded – undo
2522 2522
         	}
2523 2523
         	else
2524 2524
         	{
2525
-        		print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?socid='.$object->id);
2525
+        		print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?socid='.$object->id);
2526 2526
         	}
2527 2527
         	print '</td></tr>';
2528 2528
         }
2529 2529
 
2530 2530
 		// Multicurrency
2531
-		if (! empty($conf->multicurrency->enabled))
2531
+		if (!empty($conf->multicurrency->enabled))
2532 2532
 		{
2533 2533
 			print '<tr>';
2534 2534
 			print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
2535 2535
 	        print '<td>';
2536
-	        print !empty($object->multicurrency_code) ? currency_name($object->multicurrency_code,1) : '';
2536
+	        print !empty($object->multicurrency_code) ? currency_name($object->multicurrency_code, 1) : '';
2537 2537
 			print '</td></tr>';
2538 2538
 		}
2539 2539
 
2540 2540
 		// Other attributes
2541
-		$parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
2542
-		include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
2541
+		$parameters = array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
2542
+		include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
2543 2543
 
2544 2544
         // Parent company
2545 2545
         if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY))
@@ -2549,16 +2549,16 @@  discard block
 block discarded – undo
2549 2549
         	print '<table class="nobordernopadding" width="100%"><tr><td>';
2550 2550
         	print $langs->trans('ParentCompany');
2551 2551
         	print '</td>';
2552
-        	if ($action != 'editparentcompany') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</a></td>';
2552
+        	if ($action != 'editparentcompany') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a></td>';
2553 2553
         	print '</tr></table>';
2554 2554
         	print '</td><td colspan="3">';
2555 2555
         	if ($action == 'editparentcompany')
2556 2556
         	{
2557
-        		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'editparentcompany','s.rowid <> '.$object->id,1);
2557
+        		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->parent, 'editparentcompany', 's.rowid <> '.$object->id, 1);
2558 2558
         	}
2559 2559
         	else
2560 2560
         	{
2561
-        		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'none','s.rowid <> '.$object->id,1);
2561
+        		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->parent, 'none', 's.rowid <> '.$object->id, 1);
2562 2562
         	}
2563 2563
         	print '</td>';
2564 2564
         	print '</tr>';
@@ -2568,16 +2568,16 @@  discard block
 block discarded – undo
2568 2568
         include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php';
2569 2569
 
2570 2570
         // Module Adherent
2571
-        if (! empty($conf->adherent->enabled))
2571
+        if (!empty($conf->adherent->enabled))
2572 2572
         {
2573 2573
             $langs->load("members");
2574 2574
             print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
2575 2575
             print '<td colspan="3">';
2576
-            $adh=new Adherent($db);
2577
-            $result=$adh->fetch('','',$object->id);
2576
+            $adh = new Adherent($db);
2577
+            $result = $adh->fetch('', '', $object->id);
2578 2578
             if ($result > 0)
2579 2579
             {
2580
-                $adh->ref=$adh->getFullName($langs);
2580
+                $adh->ref = $adh->getFullName($langs);
2581 2581
                 print $adh->getNomUrl(1);
2582 2582
             }
2583 2583
             else
@@ -2610,8 +2610,8 @@  discard block
 block discarded – undo
2610 2610
         {
2611 2611
 	        print '<div class="tabsAction">'."\n";
2612 2612
 
2613
-			$parameters=array();
2614
-			$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
2613
+			$parameters = array();
2614
+			$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2615 2615
 			if (empty($reshook))
2616 2616
 			{
2617 2617
 				$at_least_one_email_contact = false;
@@ -2625,7 +2625,7 @@  discard block
 block discarded – undo
2625 2625
 					}
2626 2626
 				}
2627 2627
 
2628
-		        if (! empty($object->email) || $at_least_one_email_contact)
2628
+		        if (!empty($object->email) || $at_least_one_email_contact)
2629 2629
 		        {
2630 2630
 		        	$langs->load("mails");
2631 2631
 		        	print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'&amp;action=presend&amp;mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';
@@ -2678,10 +2678,10 @@  discard block
 block discarded – undo
2678 2678
 	            /*
2679 2679
 	             * Documents generes
2680 2680
 	             */
2681
-	            $filedir=$conf->societe->multidir_output[$object->entity].'/'.$object->id;
2682
-	            $urlsource=$_SERVER["PHP_SELF"]."?socid=".$object->id;
2683
-	            $genallowed=$user->rights->societe->lire;
2684
-	            $delallowed=$user->rights->societe->creer;
2681
+	            $filedir = $conf->societe->multidir_output[$object->entity].'/'.$object->id;
2682
+	            $urlsource = $_SERVER["PHP_SELF"]."?socid=".$object->id;
2683
+	            $genallowed = $user->rights->societe->lire;
2684
+	            $delallowed = $user->rights->societe->creer;
2685 2685
 
2686 2686
 	            print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang);
2687 2687
 	        }
@@ -2689,7 +2689,7 @@  discard block
 block discarded – undo
2689 2689
 			// Subsidiaries list
2690 2690
 			if (empty($conf->global->SOCIETE_DISABLE_SUBSIDIARIES))
2691 2691
 			{
2692
-				$result=show_subsidiaries($conf,$langs,$db,$object);
2692
+				$result = show_subsidiaries($conf, $langs, $db, $object);
2693 2693
 			}
2694 2694
 
2695 2695
 			print '</div><div class="fichehalfright"><div class="ficheaddleft">';
@@ -2697,35 +2697,35 @@  discard block
 block discarded – undo
2697 2697
 			$MAXEVENT = 10;
2698 2698
 
2699 2699
 			$morehtmlright = '<a href="'.DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id.'">';
2700
-			$morehtmlright.= $langs->trans("SeeAll");
2701
-			$morehtmlright.= '</a>';
2700
+			$morehtmlright .= $langs->trans("SeeAll");
2701
+			$morehtmlright .= '</a>';
2702 2702
 
2703 2703
 			// List of actions on element
2704
-			include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
2704
+			include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
2705 2705
 			$formactions = new FormActions($db);
2706
-			$somethingshown = $formactions->showactions($object, '', $socid, 1, '', $MAXEVENT, '', $morehtmlright);		// Show all action for thirdparty
2706
+			$somethingshown = $formactions->showactions($object, '', $socid, 1, '', $MAXEVENT, '', $morehtmlright); // Show all action for thirdparty
2707 2707
 
2708 2708
 			print '</div></div></div>';
2709 2709
 
2710
-			if (! empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD))
2710
+			if (!empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD))
2711 2711
 			{
2712 2712
 				// Contacts list
2713 2713
 				if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
2714 2714
 				{
2715
-					$result=show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
2715
+					$result = show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
2716 2716
 				}
2717 2717
 
2718 2718
 				// Addresses list
2719
-				if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))
2719
+				if (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))
2720 2720
 				{
2721
-					$result=show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
2721
+					$result = show_addresses($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
2722 2722
 				}
2723 2723
 			}
2724 2724
 		}
2725 2725
 
2726 2726
 		// Presend form
2727
-		$modelmail='thirdparty';
2728
-		$defaulttopic='Information';
2727
+		$modelmail = 'thirdparty';
2728
+		$defaulttopic = 'Information';
2729 2729
 		$diroutput = $conf->societe->dir_output;
2730 2730
 		$trackid = 'thi'.$object->id;
2731 2731
 
Please login to merge, or discard this patch.
dolibarr/htdocs/societe/ajaxcompanies.php 3 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -52,18 +52,18 @@  discard block
 block discarded – undo
52 52
 // Generation liste des societes
53 53
 if (GETPOST('newcompany') || GETPOST('socid','int') || GETPOST('id_fourn'))
54 54
 {
55
-	$return_arr = array();
56
-
57
-	// Define filter on text typed
58
-	$socid = $_GET['newcompany']?$_GET['newcompany']:'';
59
-	if (! $socid) $socid = $_GET['socid']?$_GET['socid']:'';
60
-	if (! $socid) $socid = $_GET['id_fourn']?$_GET['id_fourn']:'';
61
-
62
-	$sql = "SELECT rowid, nom";
63
-	$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
64
-	$sql.= " WHERE s.entity IN (".getEntity('societe').")";
65
-	if ($socid)
66
-	{
55
+    $return_arr = array();
56
+
57
+    // Define filter on text typed
58
+    $socid = $_GET['newcompany']?$_GET['newcompany']:'';
59
+    if (! $socid) $socid = $_GET['socid']?$_GET['socid']:'';
60
+    if (! $socid) $socid = $_GET['id_fourn']?$_GET['id_fourn']:'';
61
+
62
+    $sql = "SELECT rowid, nom";
63
+    $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
64
+    $sql.= " WHERE s.entity IN (".getEntity('societe').")";
65
+    if ($socid)
66
+    {
67 67
         $sql.=" AND (";
68 68
         // Add criteria on name/code
69 69
         if (! empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE))   // Can use index
@@ -74,37 +74,37 @@  discard block
 block discarded – undo
74 74
         }
75 75
         else
76 76
         {
77
-    		$sql.="nom LIKE '%" . $db->escape($socid) . "%'";
78
-    		$sql.=" OR code_client LIKE '%" . $db->escape($socid) . "%'";
79
-    		$sql.=" OR code_fournisseur LIKE '%" . $db->escape($socid) . "%'";
77
+            $sql.="nom LIKE '%" . $db->escape($socid) . "%'";
78
+            $sql.=" OR code_client LIKE '%" . $db->escape($socid) . "%'";
79
+            $sql.=" OR code_fournisseur LIKE '%" . $db->escape($socid) . "%'";
80 80
         }
81
-		if (! empty($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID)) $sql.=" OR rowid = '" . $db->escape($socid) . "'";
82
-		$sql.=")";
83
-	}
84
-	if (GETPOST("filter")) $sql.= " AND ".GETPOST("filter","alpha"); // Add other filters
85
-	$sql.= " ORDER BY nom ASC";
86
-
87
-	//dol_syslog("ajaxcompanies", LOG_DEBUG);
88
-	$resql=$db->query($sql);
89
-	if ($resql)
90
-	{
91
-		while ($row = $db->fetch_array($resql))
92
-		{
93
-		    $label=$row['nom'];
94
-		    if ($socid) $label=preg_replace('/('.preg_quote($socid,'/').')/i','<strong>$1</strong>',$label,1);
95
-			$row_array['label'] = $label;
96
-			$row_array['value'] = $row['nom'];
97
-	        $row_array['key'] = $row['rowid'];
98
-
99
-	        array_push($return_arr,$row_array);
100
-	    }
101
-
102
-	    echo json_encode($return_arr);
103
-	}
104
-	else
105
-	{
106
-	    echo json_encode(array('nom'=>'Error','label'=>'Error','key'=>'Error','value'=>'Error'));
107
-	}
81
+        if (! empty($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID)) $sql.=" OR rowid = '" . $db->escape($socid) . "'";
82
+        $sql.=")";
83
+    }
84
+    if (GETPOST("filter")) $sql.= " AND ".GETPOST("filter","alpha"); // Add other filters
85
+    $sql.= " ORDER BY nom ASC";
86
+
87
+    //dol_syslog("ajaxcompanies", LOG_DEBUG);
88
+    $resql=$db->query($sql);
89
+    if ($resql)
90
+    {
91
+        while ($row = $db->fetch_array($resql))
92
+        {
93
+            $label=$row['nom'];
94
+            if ($socid) $label=preg_replace('/('.preg_quote($socid,'/').')/i','<strong>$1</strong>',$label,1);
95
+            $row_array['label'] = $label;
96
+            $row_array['value'] = $row['nom'];
97
+            $row_array['key'] = $row['rowid'];
98
+
99
+            array_push($return_arr,$row_array);
100
+        }
101
+
102
+        echo json_encode($return_arr);
103
+    }
104
+    else
105
+    {
106
+        echo json_encode(array('nom'=>'Error','label'=>'Error','key'=>'Error','value'=>'Error'));
107
+    }
108 108
 }
109 109
 else
110 110
 {
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -23,17 +23,17 @@  discard block
 block discarded – undo
23 23
  *       \brief      File to return Ajax response on third parties request
24 24
  */
25 25
 
26
-if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal
27
-if (! defined('NOREQUIREMENU'))  define('NOREQUIREMENU','1');
28
-if (! defined('NOREQUIREHTML'))  define('NOREQUIREHTML','1');
29
-if (! defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX','1');
30
-if (! defined('NOREQUIRESOC'))   define('NOREQUIRESOC','1');
31
-if (! defined('NOCSRFCHECK'))    define('NOCSRFCHECK','1');
26
+if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); // Disables token renewal
27
+if (!defined('NOREQUIREMENU'))  define('NOREQUIREMENU', '1');
28
+if (!defined('NOREQUIREHTML'))  define('NOREQUIREHTML', '1');
29
+if (!defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX', '1');
30
+if (!defined('NOREQUIRESOC'))   define('NOREQUIRESOC', '1');
31
+if (!defined('NOCSRFCHECK'))    define('NOCSRFCHECK', '1');
32 32
 
33 33
 
34 34
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
35 35
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
36
-require DOL_BASE_PATH . 'main.inc.php';
36
+require DOL_BASE_PATH.'main.inc.php';
37 37
 
38 38
 
39 39
 
@@ -50,67 +50,67 @@  discard block
 block discarded – undo
50 50
 
51 51
 //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
52 52
 
53
-dol_syslog(join(',',$_GET));
53
+dol_syslog(join(',', $_GET));
54 54
 
55 55
 
56 56
 // Generation liste des societes
57
-if (GETPOST('newcompany') || GETPOST('socid','int') || GETPOST('id_fourn'))
57
+if (GETPOST('newcompany') || GETPOST('socid', 'int') || GETPOST('id_fourn'))
58 58
 {
59 59
 	$return_arr = array();
60 60
 
61 61
 	// Define filter on text typed
62
-	$socid = $_GET['newcompany']?$_GET['newcompany']:'';
63
-	if (! $socid) $socid = $_GET['socid']?$_GET['socid']:'';
64
-	if (! $socid) $socid = $_GET['id_fourn']?$_GET['id_fourn']:'';
62
+	$socid = $_GET['newcompany'] ? $_GET['newcompany'] : '';
63
+	if (!$socid) $socid = $_GET['socid'] ? $_GET['socid'] : '';
64
+	if (!$socid) $socid = $_GET['id_fourn'] ? $_GET['id_fourn'] : '';
65 65
 
66 66
 	$sql = "SELECT rowid, nom";
67
-	$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
68
-	$sql.= " WHERE s.entity IN (".getEntity('societe').")";
67
+	$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
68
+	$sql .= " WHERE s.entity IN (".getEntity('societe').")";
69 69
 	if ($socid)
70 70
 	{
71
-        $sql.=" AND (";
71
+        $sql .= " AND (";
72 72
         // Add criteria on name/code
73
-        if (! empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE))   // Can use index
73
+        if (!empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE))   // Can use index
74 74
         {
75
-            $sql.="nom LIKE '" . $db->escape($socid) . "%'";
76
-            $sql.=" OR code_client LIKE '" . $db->escape($socid) . "%'";
77
-            $sql.=" OR code_fournisseur LIKE '" . $db->escape($socid) . "%'";
75
+            $sql .= "nom LIKE '".$db->escape($socid)."%'";
76
+            $sql .= " OR code_client LIKE '".$db->escape($socid)."%'";
77
+            $sql .= " OR code_fournisseur LIKE '".$db->escape($socid)."%'";
78 78
         }
79 79
         else
80 80
         {
81
-    		$sql.="nom LIKE '%" . $db->escape($socid) . "%'";
82
-    		$sql.=" OR code_client LIKE '%" . $db->escape($socid) . "%'";
83
-    		$sql.=" OR code_fournisseur LIKE '%" . $db->escape($socid) . "%'";
81
+    		$sql .= "nom LIKE '%".$db->escape($socid)."%'";
82
+    		$sql .= " OR code_client LIKE '%".$db->escape($socid)."%'";
83
+    		$sql .= " OR code_fournisseur LIKE '%".$db->escape($socid)."%'";
84 84
         }
85
-		if (! empty($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID)) $sql.=" OR rowid = '" . $db->escape($socid) . "'";
86
-		$sql.=")";
85
+		if (!empty($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID)) $sql .= " OR rowid = '".$db->escape($socid)."'";
86
+		$sql .= ")";
87 87
 	}
88
-	if (GETPOST("filter")) $sql.= " AND ".GETPOST("filter","alpha"); // Add other filters
89
-	$sql.= " ORDER BY nom ASC";
88
+	if (GETPOST("filter")) $sql .= " AND ".GETPOST("filter", "alpha"); // Add other filters
89
+	$sql .= " ORDER BY nom ASC";
90 90
 
91 91
 	//dol_syslog("ajaxcompanies", LOG_DEBUG);
92
-	$resql=$db->query($sql);
92
+	$resql = $db->query($sql);
93 93
 	if ($resql)
94 94
 	{
95 95
 		while ($row = $db->fetch_array($resql))
96 96
 		{
97
-		    $label=$row['nom'];
98
-		    if ($socid) $label=preg_replace('/('.preg_quote($socid,'/').')/i','<strong>$1</strong>',$label,1);
97
+		    $label = $row['nom'];
98
+		    if ($socid) $label = preg_replace('/('.preg_quote($socid, '/').')/i', '<strong>$1</strong>', $label, 1);
99 99
 			$row_array['label'] = $label;
100 100
 			$row_array['value'] = $row['nom'];
101 101
 	        $row_array['key'] = $row['rowid'];
102 102
 
103
-	        array_push($return_arr,$row_array);
103
+	        array_push($return_arr, $row_array);
104 104
 	    }
105 105
 
106 106
 	    echo json_encode($return_arr);
107 107
 	}
108 108
 	else
109 109
 	{
110
-	    echo json_encode(array('nom'=>'Error','label'=>'Error','key'=>'Error','value'=>'Error'));
110
+	    echo json_encode(array('nom'=>'Error', 'label'=>'Error', 'key'=>'Error', 'value'=>'Error'));
111 111
 	}
112 112
 }
113 113
 else
114 114
 {
115
-    echo json_encode(array('nom'=>'ErrorBadParameter','label'=>'ErrorBadParameter','key'=>'ErrorBadParameter','value'=>'ErrorBadParameter'));
115
+    echo json_encode(array('nom'=>'ErrorBadParameter', 'label'=>'ErrorBadParameter', 'key'=>'ErrorBadParameter', 'value'=>'ErrorBadParameter'));
116 116
 }
Please login to merge, or discard this patch.
Braces   +41 added lines, -18 removed lines patch added patch discarded remove patch
@@ -23,12 +23,25 @@  discard block
 block discarded – undo
23 23
  *       \brief      File to return Ajax response on third parties request
24 24
  */
25 25
 
26
-if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal
27
-if (! defined('NOREQUIREMENU'))  define('NOREQUIREMENU','1');
28
-if (! defined('NOREQUIREHTML'))  define('NOREQUIREHTML','1');
29
-if (! defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX','1');
30
-if (! defined('NOREQUIRESOC'))   define('NOREQUIRESOC','1');
31
-if (! defined('NOCSRFCHECK'))    define('NOCSRFCHECK','1');
26
+if (! defined('NOTOKENRENEWAL')) {
27
+    define('NOTOKENRENEWAL',1);
28
+}
29
+// Disables token renewal
30
+if (! defined('NOREQUIREMENU')) {
31
+    define('NOREQUIREMENU','1');
32
+}
33
+if (! defined('NOREQUIREHTML')) {
34
+    define('NOREQUIREHTML','1');
35
+}
36
+if (! defined('NOREQUIREAJAX')) {
37
+    define('NOREQUIREAJAX','1');
38
+}
39
+if (! defined('NOREQUIRESOC')) {
40
+    define('NOREQUIRESOC','1');
41
+}
42
+if (! defined('NOCSRFCHECK')) {
43
+    define('NOCSRFCHECK','1');
44
+}
32 45
 
33 46
 
34 47
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
@@ -60,8 +73,12 @@  discard block
 block discarded – undo
60 73
 
61 74
 	// Define filter on text typed
62 75
 	$socid = $_GET['newcompany']?$_GET['newcompany']:'';
63
-	if (! $socid) $socid = $_GET['socid']?$_GET['socid']:'';
64
-	if (! $socid) $socid = $_GET['id_fourn']?$_GET['id_fourn']:'';
76
+	if (! $socid) {
77
+	    $socid = $_GET['socid']?$_GET['socid']:'';
78
+	}
79
+	if (! $socid) {
80
+	    $socid = $_GET['id_fourn']?$_GET['id_fourn']:'';
81
+	}
65 82
 
66 83
 	$sql = "SELECT rowid, nom";
67 84
 	$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
@@ -70,22 +87,28 @@  discard block
 block discarded – undo
70 87
 	{
71 88
         $sql.=" AND (";
72 89
         // Add criteria on name/code
73
-        if (! empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE))   // Can use index
90
+        if (! empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE)) {
91
+            // Can use index
74 92
         {
75 93
             $sql.="nom LIKE '" . $db->escape($socid) . "%'";
94
+        }
76 95
             $sql.=" OR code_client LIKE '" . $db->escape($socid) . "%'";
77 96
             $sql.=" OR code_fournisseur LIKE '" . $db->escape($socid) . "%'";
78
-        }
79
-        else
97
+        } else
80 98
         {
81 99
     		$sql.="nom LIKE '%" . $db->escape($socid) . "%'";
82 100
     		$sql.=" OR code_client LIKE '%" . $db->escape($socid) . "%'";
83 101
     		$sql.=" OR code_fournisseur LIKE '%" . $db->escape($socid) . "%'";
84 102
         }
85
-		if (! empty($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID)) $sql.=" OR rowid = '" . $db->escape($socid) . "'";
103
+		if (! empty($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID)) {
104
+		    $sql.=" OR rowid = '" . $db->escape($socid) . "'";
105
+		}
86 106
 		$sql.=")";
87 107
 	}
88
-	if (GETPOST("filter")) $sql.= " AND ".GETPOST("filter","alpha"); // Add other filters
108
+	if (GETPOST("filter")) {
109
+	    $sql.= " AND ".GETPOST("filter","alpha");
110
+	}
111
+	// Add other filters
89 112
 	$sql.= " ORDER BY nom ASC";
90 113
 
91 114
 	//dol_syslog("ajaxcompanies", LOG_DEBUG);
@@ -95,7 +118,9 @@  discard block
 block discarded – undo
95 118
 		while ($row = $db->fetch_array($resql))
96 119
 		{
97 120
 		    $label=$row['nom'];
98
-		    if ($socid) $label=preg_replace('/('.preg_quote($socid,'/').')/i','<strong>$1</strong>',$label,1);
121
+		    if ($socid) {
122
+		        $label=preg_replace('/('.preg_quote($socid,'/').')/i','<strong>$1</strong>',$label,1);
123
+		    }
99 124
 			$row_array['label'] = $label;
100 125
 			$row_array['value'] = $row['nom'];
101 126
 	        $row_array['key'] = $row['rowid'];
@@ -104,13 +129,11 @@  discard block
 block discarded – undo
104 129
 	    }
105 130
 
106 131
 	    echo json_encode($return_arr);
107
-	}
108
-	else
132
+	} else
109 133
 	{
110 134
 	    echo json_encode(array('nom'=>'Error','label'=>'Error','key'=>'Error','value'=>'Error'));
111 135
 	}
112
-}
113
-else
136
+} else
114 137
 {
115 138
     echo json_encode(array('nom'=>'ErrorBadParameter','label'=>'ErrorBadParameter','key'=>'ErrorBadParameter','value'=>'ErrorBadParameter'));
116 139
 }
Please login to merge, or discard this patch.