Test Failed
Push — master ( e0c20c...b8c830 )
by Alxarafe
39:29
created
dolibarr/htdocs/societe/class/companybankaccount.class.php 3 patches
Indentation   +381 added lines, -381 removed lines patch added patch discarded remove patch
@@ -33,386 +33,386 @@
 block discarded – undo
33 33
  */
34 34
 class CompanyBankAccount extends Account
35 35
 {
36
-	var $socid;
37
-
38
-	var $default_rib;
39
-	var $frstrecur;
40
-	var $rum;
41
-	var $date_rum;
42
-
43
-	var $datec;
44
-	var $datem;
45
-
46
-
47
-	/**
48
-	 *  Constructor
49
-	 *
50
-	 *  @param      DoliDB		$db      Database handler
51
-	 */
52
-	public function __construct(DoliDB $db)
53
-	{
54
-		$this->db = $db;
55
-
56
-		$this->socid = 0;
57
-		$this->solde = 0;
58
-		$this->error_number = 0;
59
-		$this->default_rib = 0;
60
-	}
61
-
62
-
63
-	/**
64
-	 * Create bank information record
65
-	 *
66
-	 * @param   User   $user		User
67
-	 * @param   int    $notrigger   1=Disable triggers
68
-	 * @return	int					<0 if KO, >= 0 if OK
69
-	 */
70
-	function create(User $user = null, $notrigger=0)
71
-	{
72
-		$now	= dol_now();
73
-		$error	= 0;
74
-		// Correct default_rib to be sure to have always one default
75
-		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_rib where fk_soc = ".$this->socid." AND default_rib = 1 AND type = 'ban'";
76
-   		$result = $this->db->query($sql);
77
-		if ($result)
78
-		{
79
-			$numrows=$this->db->num_rows($result);
80
-			if ($this->default_rib && $numrows > 0) $this->default_rib = 0;
81
-			if (empty($this->default_rib) && $numrows == 0) $this->default_rib = 1;
82
-		}
83
-
84
-		$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_rib (fk_soc, type, datec)";
85
-		$sql.= " VALUES (".$this->socid.", 'ban', '".$this->db->idate($now)."')";
86
-		$resql=$this->db->query($sql);
87
-		if ($resql)
88
-		{
89
-			if ($this->db->affected_rows($resql))
90
-			{
91
-				$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_rib");
92
-
93
-				if (! $notrigger)
94
-				{
95
-				   	// Call trigger
96
-					$result=$this->call_trigger('COMPANY_RIB_CREATE',$user);
97
-					if ($result < 0) $error++;
98
-					// End call triggers
99
-
100
-					if (! $error)
101
-					{
102
-						return 1;
103
-					}
104
-					else
105
-					{
106
-						return 0;
107
-					}
108
-				}
109
-				else
110
-				{
111
-					return 1;
112
-				}
113
-			}
114
-		}
115
-		else
116
-		{
117
-			print $this->db->error();
118
-			return 0;
119
-		}
120
-	}
121
-
122
-	/**
123
-	 *	Update bank account
124
-	 *
125
-	 *	@param	User	$user	     Object user
126
-	 *  @param  int     $notrigger   1=Disable triggers
127
-	 *	@return	int				     <=0 if KO, >0 if OK
128
-	 */
129
-	function update(User $user = null, $notrigger = 0)
130
-	{
131
-		global $conf;
132
-		$error = 0;
133
-
134
-		if (! $this->id) return -1;
135
-
136
-		if (dol_strlen($this->domiciliation) > 255) $this->domiciliation = dol_trunc($this->domiciliation, 254, 'right', 'UTF-8', 1);
137
-		if (dol_strlen($this->owner_address) > 255) $this->owner_address = dol_trunc($this->owner_address, 254, 'right', 'UTF-8', 1);
138
-
139
-		$sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET";
140
-		$sql.= " bank = '" .$this->db->escape($this->bank)."'";
141
-		$sql.= ",code_banque='".$this->db->escape($this->code_banque)."'";
142
-		$sql.= ",code_guichet='".$this->db->escape($this->code_guichet)."'";
143
-		$sql.= ",number='".$this->db->escape($this->number)."'";
144
-		$sql.= ",cle_rib='".$this->db->escape($this->cle_rib)."'";
145
-		$sql.= ",bic='".$this->db->escape($this->bic)."'";
146
-		$sql.= ",iban_prefix = '".$this->db->escape($this->iban)."'";
147
-		$sql.= ",domiciliation='".$this->db->escape($this->domiciliation)."'";
148
-		$sql.= ",proprio = '".$this->db->escape($this->proprio)."'";
149
-		$sql.= ",owner_address = '".$this->db->escape($this->owner_address)."'";
150
-		$sql.= ",default_rib = ".$this->default_rib;
151
-		if ($conf->prelevement->enabled)
152
-		{
153
-			$sql.= ",frstrecur = '".$this->db->escape($this->frstrecur)."'";
154
-			$sql.= ",rum = '".$this->db->escape($this->rum)."'";
155
-			$sql.= ",date_rum = ".($this->date_rum ? "'".$this->db->idate($this->date_rum)."'" : "null");
156
-		}
157
-		if (trim($this->label) != '')
158
-			$sql.= ",label = '".$this->db->escape($this->label)."'";
159
-		else
160
-			$sql.= ",label = NULL";
161
-		$sql.= " WHERE rowid = ".$this->id;
162
-
163
-		$result = $this->db->query($sql);
164
-		if ($result)
165
-		{
166
-
167
-
168
-		if (! $notrigger)
169
-		{
170
-			// Call trigger
171
-			$result=$this->call_trigger('COMPANY_RIB_MODIFY',$user);
172
-			if ($result < 0) $error++;
173
-			// End call triggers
174
-			if(! $error )
175
-			{
176
-				return 1;
177
-			}
178
-			else
179
-			{
180
-				return -1;
181
-			}
182
-		}
183
-		else
184
-		{
185
-			return 1;
186
-		}
187
-		}
188
-		else
189
-		{
190
-			dol_print_error($this->db);
191
-			return -1;
192
-		}
193
-	}
194
-
195
-	/**
196
-	 * 	Load record from database
197
-	 *
198
-	 *	@param	int		$id			Id of record
199
-	 * 	@param	int		$socid		Id of company. If this is filled, function will return the first entry found (matching $default and $type)
200
-	 *  @param	int		$default	If id of company filled, we say if we want first record among all (-1), default record (1) or non default record (0)
201
-	 *  @param	int		$type		If id of company filled, we say if we want record of this type only
202
-	 * 	@return	int					<0 if KO, >0 if OK
203
-	 */
204
-	function fetch($id, $socid=0, $default=1, $type='ban')
205
-	{
206
-		if (empty($id) && empty($socid)) return -1;
207
-
208
-		$sql = "SELECT rowid, type, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,";
209
-		$sql.= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur";
210
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe_rib";
211
-		if ($id)    $sql.= " WHERE rowid = ".$id;
212
-		if ($socid)
213
-		{
214
-			$sql.= " WHERE fk_soc  = ".$socid;
215
-			if ($default > -1) $sql.=" AND default_rib = ".$this->db->escape($default);
216
-			if ($type) $sql.= " AND type ='".$this->db->escape($type)."'";
217
-		}
218
-
219
-		$resql = $this->db->query($sql);
220
-		if ($resql)
221
-		{
222
-			if ($this->db->num_rows($resql))
223
-			{
224
-				$obj = $this->db->fetch_object($resql);
225
-
226
-				$this->ref             = $obj->fk_soc.'-'.$obj->label;      // Generate an artificial ref
227
-
228
-				$this->id			   = $obj->rowid;
229
-				$this->type			   = $obj->type;
230
-				$this->socid           = $obj->fk_soc;
231
-				$this->bank            = $obj->bank;
232
-				$this->code_banque     = $obj->code_banque;
233
-				$this->code_guichet    = $obj->code_guichet;
234
-				$this->number          = $obj->number;
235
-				$this->cle_rib         = $obj->cle_rib;
236
-				$this->bic             = $obj->bic;
237
-				$this->iban		       = $obj->iban;
238
-				$this->domiciliation   = $obj->domiciliation;
239
-				$this->proprio         = $obj->proprio;
240
-				$this->owner_address   = $obj->owner_address;
241
-				$this->label           = $obj->label;
242
-				$this->default_rib     = $obj->default_rib;
243
-				$this->datec           = $this->db->jdate($obj->datec);
244
-				$this->datem           = $this->db->jdate($obj->datem);
245
-				$this->rum             = $obj->rum;
246
-				$this->frstrecur       = $obj->frstrecur;
247
-			}
248
-			$this->db->free($resql);
249
-
250
-			return 1;
251
-		}
252
-		else
253
-		{
254
-			dol_print_error($this->db);
255
-			return -1;
256
-		}
257
-	}
258
-
259
-	/**
260
-	 *  Delete a rib from database
261
-	 *
262
-	 *	@param		User	$user		User deleting
263
-	 *	@param  	int		$notrigger	1=Disable triggers
264
-	 *  @return		int		            <0 if KO, >0 if OK
265
-	 */
266
-	function delete(User $user = null, $notrigger=0)
267
-	{
268
-		global $conf;
269
-
270
-		$error = 0;
271
-
272
-		dol_syslog(get_class($this) . "::delete ".$this->id, LOG_DEBUG);
273
-
274
-		$this->db->begin();
275
-
276
-		if (! $error && ! $notrigger)
277
-		{
278
-			// Call trigger
279
-			$result=$this->call_trigger('COMPANY_RIB_DELETE',$user);
280
-			if ($result < 0) $error++;
281
-			// End call triggers
282
-		}
283
-
284
-		if (! $error)
285
-		{
286
-			$sql = "DELETE FROM " . MAIN_DB_PREFIX . "societe_rib";
287
-			$sql .= " WHERE rowid  = " . $this->id;
288
-
289
-			if (! $this->db->query($sql))
290
-			{
291
-				$error++;
292
-				$this->errors[]=$this->db->lasterror();
293
-			}
294
-		}
295
-
296
-		if (! $error)
297
-		{
298
-			$this->db->commit();
299
-			return 1;
300
-		}
301
-		else
302
-		{
303
-			$this->db->rollback();
304
-			return -1*$error;
305
-		}
306
-	}
307
-
308
-	/**
309
-	 * Return RIB
310
-	 *
311
-	 * @param   boolean     $displayriblabel     Prepend or Hide Label
312
-	 * @return	string		RIB
313
-	 */
314
-	public function getRibLabel($displayriblabel = true)
315
-	{
316
-		$rib = '';
317
-
318
-		if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib || $this->iban || $this->bic ) {
319
-
320
-			if ($this->label && $displayriblabel) {
321
-				$rib = $this->label." : ";
322
-			}
323
-
324
-			$rib .= (string) $this;
325
-		}
326
-
327
-		return $rib;
328
-	}
329
-
330
-	/**
331
-	 * Set a BAN as Default
332
-	 *
333
-	 * @param   int     $rib    RIB id
334
-	 * @return  int             0 if KO, 1 if OK
335
-	 */
336
-	function setAsDefault($rib=0)
337
-	{
338
-		$sql1 = "SELECT rowid as id, fk_soc  FROM ".MAIN_DB_PREFIX."societe_rib";
339
-		$sql1.= " WHERE rowid = ".($rib?$rib:$this->id);
340
-
341
-		dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
342
-		$result1 = $this->db->query($sql1);
343
-		if ($result1)
344
-		{
345
-			if ($this->db->num_rows($result1) == 0)
346
-			{
347
-				return 0;
348
-			}
349
-			else
350
-			{
351
-				$obj = $this->db->fetch_object($result1);
352
-
353
-				$this->db->begin();
354
-
355
-				$sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0";
356
-				$sql2.= " WHERE type = 'ban' AND fk_soc = ".$obj->fk_soc;
357
-				dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
358
-				$result2 = $this->db->query($sql2);
359
-
360
-				$sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1";
361
-				$sql3.= " WHERE rowid = ".$obj->id;
362
-				dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
363
-				$result3 = $this->db->query($sql3);
364
-
365
-				if (!$result2 || !$result3)
366
-				{
367
-					dol_print_error($this->db);
368
-					$this->db->rollback();
369
-					return -1;
370
-				}
371
-				else
372
-				{
373
-					$this->db->commit();
374
-					return 1;
375
-				}
376
-			}
377
-		}
378
-		else
379
-		{
380
-			dol_print_error($this->db);
381
-			return -1;
382
-		}
383
-	}
384
-
385
-	/**
386
-	 *  Initialise an instance with random values.
387
-	 *  Used to build previews or test instances.
388
-	 *	id must be 0 if object instance is a specimen.
389
-	 *
390
-	 *  @return	void
391
-	 */
392
-	function initAsSpecimen()
393
-	{
394
-		$this->specimen        = 1;
395
-		$this->ref             = 'CBA';
396
-		$this->label           = 'CustomerCorp Bank account';
397
-		$this->bank            = 'CustomerCorp Bank';
398
-		$this->courant         = Account::TYPE_CURRENT;
399
-		$this->clos            = Account::STATUS_OPEN;
400
-		$this->code_banque     = '123';
401
-		$this->code_guichet    = '456';
402
-		$this->number          = 'CUST12345';
403
-		$this->cle_rib         = 50;
404
-		$this->bic             = 'CC12';
405
-		$this->iban            = 'FR999999999';
406
-		$this->domiciliation   = 'Bank address of customer corp';
407
-		$this->proprio         = 'Owner';
408
-		$this->owner_address   = 'Owner address';
409
-		$this->country_id      = 1;
410
-
411
-		$this->rum             = 'UMR-CU1212-0007-5-1475405262';
412
-		$this->date_rum        =dol_now() - 10000;
413
-		$this->frstrecur       = 'FRST';
414
-
415
-		$this->socid = 0;
416
-	}
36
+    var $socid;
37
+
38
+    var $default_rib;
39
+    var $frstrecur;
40
+    var $rum;
41
+    var $date_rum;
42
+
43
+    var $datec;
44
+    var $datem;
45
+
46
+
47
+    /**
48
+     *  Constructor
49
+     *
50
+     *  @param      DoliDB		$db      Database handler
51
+     */
52
+    public function __construct(DoliDB $db)
53
+    {
54
+        $this->db = $db;
55
+
56
+        $this->socid = 0;
57
+        $this->solde = 0;
58
+        $this->error_number = 0;
59
+        $this->default_rib = 0;
60
+    }
61
+
62
+
63
+    /**
64
+     * Create bank information record
65
+     *
66
+     * @param   User   $user		User
67
+     * @param   int    $notrigger   1=Disable triggers
68
+     * @return	int					<0 if KO, >= 0 if OK
69
+     */
70
+    function create(User $user = null, $notrigger=0)
71
+    {
72
+        $now	= dol_now();
73
+        $error	= 0;
74
+        // Correct default_rib to be sure to have always one default
75
+        $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_rib where fk_soc = ".$this->socid." AND default_rib = 1 AND type = 'ban'";
76
+            $result = $this->db->query($sql);
77
+        if ($result)
78
+        {
79
+            $numrows=$this->db->num_rows($result);
80
+            if ($this->default_rib && $numrows > 0) $this->default_rib = 0;
81
+            if (empty($this->default_rib) && $numrows == 0) $this->default_rib = 1;
82
+        }
83
+
84
+        $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_rib (fk_soc, type, datec)";
85
+        $sql.= " VALUES (".$this->socid.", 'ban', '".$this->db->idate($now)."')";
86
+        $resql=$this->db->query($sql);
87
+        if ($resql)
88
+        {
89
+            if ($this->db->affected_rows($resql))
90
+            {
91
+                $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_rib");
92
+
93
+                if (! $notrigger)
94
+                {
95
+                        // Call trigger
96
+                    $result=$this->call_trigger('COMPANY_RIB_CREATE',$user);
97
+                    if ($result < 0) $error++;
98
+                    // End call triggers
99
+
100
+                    if (! $error)
101
+                    {
102
+                        return 1;
103
+                    }
104
+                    else
105
+                    {
106
+                        return 0;
107
+                    }
108
+                }
109
+                else
110
+                {
111
+                    return 1;
112
+                }
113
+            }
114
+        }
115
+        else
116
+        {
117
+            print $this->db->error();
118
+            return 0;
119
+        }
120
+    }
121
+
122
+    /**
123
+     *	Update bank account
124
+     *
125
+     *	@param	User	$user	     Object user
126
+     *  @param  int     $notrigger   1=Disable triggers
127
+     *	@return	int				     <=0 if KO, >0 if OK
128
+     */
129
+    function update(User $user = null, $notrigger = 0)
130
+    {
131
+        global $conf;
132
+        $error = 0;
133
+
134
+        if (! $this->id) return -1;
135
+
136
+        if (dol_strlen($this->domiciliation) > 255) $this->domiciliation = dol_trunc($this->domiciliation, 254, 'right', 'UTF-8', 1);
137
+        if (dol_strlen($this->owner_address) > 255) $this->owner_address = dol_trunc($this->owner_address, 254, 'right', 'UTF-8', 1);
138
+
139
+        $sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET";
140
+        $sql.= " bank = '" .$this->db->escape($this->bank)."'";
141
+        $sql.= ",code_banque='".$this->db->escape($this->code_banque)."'";
142
+        $sql.= ",code_guichet='".$this->db->escape($this->code_guichet)."'";
143
+        $sql.= ",number='".$this->db->escape($this->number)."'";
144
+        $sql.= ",cle_rib='".$this->db->escape($this->cle_rib)."'";
145
+        $sql.= ",bic='".$this->db->escape($this->bic)."'";
146
+        $sql.= ",iban_prefix = '".$this->db->escape($this->iban)."'";
147
+        $sql.= ",domiciliation='".$this->db->escape($this->domiciliation)."'";
148
+        $sql.= ",proprio = '".$this->db->escape($this->proprio)."'";
149
+        $sql.= ",owner_address = '".$this->db->escape($this->owner_address)."'";
150
+        $sql.= ",default_rib = ".$this->default_rib;
151
+        if ($conf->prelevement->enabled)
152
+        {
153
+            $sql.= ",frstrecur = '".$this->db->escape($this->frstrecur)."'";
154
+            $sql.= ",rum = '".$this->db->escape($this->rum)."'";
155
+            $sql.= ",date_rum = ".($this->date_rum ? "'".$this->db->idate($this->date_rum)."'" : "null");
156
+        }
157
+        if (trim($this->label) != '')
158
+            $sql.= ",label = '".$this->db->escape($this->label)."'";
159
+        else
160
+            $sql.= ",label = NULL";
161
+        $sql.= " WHERE rowid = ".$this->id;
162
+
163
+        $result = $this->db->query($sql);
164
+        if ($result)
165
+        {
166
+
167
+
168
+        if (! $notrigger)
169
+        {
170
+            // Call trigger
171
+            $result=$this->call_trigger('COMPANY_RIB_MODIFY',$user);
172
+            if ($result < 0) $error++;
173
+            // End call triggers
174
+            if(! $error )
175
+            {
176
+                return 1;
177
+            }
178
+            else
179
+            {
180
+                return -1;
181
+            }
182
+        }
183
+        else
184
+        {
185
+            return 1;
186
+        }
187
+        }
188
+        else
189
+        {
190
+            dol_print_error($this->db);
191
+            return -1;
192
+        }
193
+    }
194
+
195
+    /**
196
+     * 	Load record from database
197
+     *
198
+     *	@param	int		$id			Id of record
199
+     * 	@param	int		$socid		Id of company. If this is filled, function will return the first entry found (matching $default and $type)
200
+     *  @param	int		$default	If id of company filled, we say if we want first record among all (-1), default record (1) or non default record (0)
201
+     *  @param	int		$type		If id of company filled, we say if we want record of this type only
202
+     * 	@return	int					<0 if KO, >0 if OK
203
+     */
204
+    function fetch($id, $socid=0, $default=1, $type='ban')
205
+    {
206
+        if (empty($id) && empty($socid)) return -1;
207
+
208
+        $sql = "SELECT rowid, type, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,";
209
+        $sql.= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur";
210
+        $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib";
211
+        if ($id)    $sql.= " WHERE rowid = ".$id;
212
+        if ($socid)
213
+        {
214
+            $sql.= " WHERE fk_soc  = ".$socid;
215
+            if ($default > -1) $sql.=" AND default_rib = ".$this->db->escape($default);
216
+            if ($type) $sql.= " AND type ='".$this->db->escape($type)."'";
217
+        }
218
+
219
+        $resql = $this->db->query($sql);
220
+        if ($resql)
221
+        {
222
+            if ($this->db->num_rows($resql))
223
+            {
224
+                $obj = $this->db->fetch_object($resql);
225
+
226
+                $this->ref             = $obj->fk_soc.'-'.$obj->label;      // Generate an artificial ref
227
+
228
+                $this->id			   = $obj->rowid;
229
+                $this->type			   = $obj->type;
230
+                $this->socid           = $obj->fk_soc;
231
+                $this->bank            = $obj->bank;
232
+                $this->code_banque     = $obj->code_banque;
233
+                $this->code_guichet    = $obj->code_guichet;
234
+                $this->number          = $obj->number;
235
+                $this->cle_rib         = $obj->cle_rib;
236
+                $this->bic             = $obj->bic;
237
+                $this->iban		       = $obj->iban;
238
+                $this->domiciliation   = $obj->domiciliation;
239
+                $this->proprio         = $obj->proprio;
240
+                $this->owner_address   = $obj->owner_address;
241
+                $this->label           = $obj->label;
242
+                $this->default_rib     = $obj->default_rib;
243
+                $this->datec           = $this->db->jdate($obj->datec);
244
+                $this->datem           = $this->db->jdate($obj->datem);
245
+                $this->rum             = $obj->rum;
246
+                $this->frstrecur       = $obj->frstrecur;
247
+            }
248
+            $this->db->free($resql);
249
+
250
+            return 1;
251
+        }
252
+        else
253
+        {
254
+            dol_print_error($this->db);
255
+            return -1;
256
+        }
257
+    }
258
+
259
+    /**
260
+     *  Delete a rib from database
261
+     *
262
+     *	@param		User	$user		User deleting
263
+     *	@param  	int		$notrigger	1=Disable triggers
264
+     *  @return		int		            <0 if KO, >0 if OK
265
+     */
266
+    function delete(User $user = null, $notrigger=0)
267
+    {
268
+        global $conf;
269
+
270
+        $error = 0;
271
+
272
+        dol_syslog(get_class($this) . "::delete ".$this->id, LOG_DEBUG);
273
+
274
+        $this->db->begin();
275
+
276
+        if (! $error && ! $notrigger)
277
+        {
278
+            // Call trigger
279
+            $result=$this->call_trigger('COMPANY_RIB_DELETE',$user);
280
+            if ($result < 0) $error++;
281
+            // End call triggers
282
+        }
283
+
284
+        if (! $error)
285
+        {
286
+            $sql = "DELETE FROM " . MAIN_DB_PREFIX . "societe_rib";
287
+            $sql .= " WHERE rowid  = " . $this->id;
288
+
289
+            if (! $this->db->query($sql))
290
+            {
291
+                $error++;
292
+                $this->errors[]=$this->db->lasterror();
293
+            }
294
+        }
295
+
296
+        if (! $error)
297
+        {
298
+            $this->db->commit();
299
+            return 1;
300
+        }
301
+        else
302
+        {
303
+            $this->db->rollback();
304
+            return -1*$error;
305
+        }
306
+    }
307
+
308
+    /**
309
+     * Return RIB
310
+     *
311
+     * @param   boolean     $displayriblabel     Prepend or Hide Label
312
+     * @return	string		RIB
313
+     */
314
+    public function getRibLabel($displayriblabel = true)
315
+    {
316
+        $rib = '';
317
+
318
+        if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib || $this->iban || $this->bic ) {
319
+
320
+            if ($this->label && $displayriblabel) {
321
+                $rib = $this->label." : ";
322
+            }
323
+
324
+            $rib .= (string) $this;
325
+        }
326
+
327
+        return $rib;
328
+    }
329
+
330
+    /**
331
+     * Set a BAN as Default
332
+     *
333
+     * @param   int     $rib    RIB id
334
+     * @return  int             0 if KO, 1 if OK
335
+     */
336
+    function setAsDefault($rib=0)
337
+    {
338
+        $sql1 = "SELECT rowid as id, fk_soc  FROM ".MAIN_DB_PREFIX."societe_rib";
339
+        $sql1.= " WHERE rowid = ".($rib?$rib:$this->id);
340
+
341
+        dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
342
+        $result1 = $this->db->query($sql1);
343
+        if ($result1)
344
+        {
345
+            if ($this->db->num_rows($result1) == 0)
346
+            {
347
+                return 0;
348
+            }
349
+            else
350
+            {
351
+                $obj = $this->db->fetch_object($result1);
352
+
353
+                $this->db->begin();
354
+
355
+                $sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0";
356
+                $sql2.= " WHERE type = 'ban' AND fk_soc = ".$obj->fk_soc;
357
+                dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
358
+                $result2 = $this->db->query($sql2);
359
+
360
+                $sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1";
361
+                $sql3.= " WHERE rowid = ".$obj->id;
362
+                dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
363
+                $result3 = $this->db->query($sql3);
364
+
365
+                if (!$result2 || !$result3)
366
+                {
367
+                    dol_print_error($this->db);
368
+                    $this->db->rollback();
369
+                    return -1;
370
+                }
371
+                else
372
+                {
373
+                    $this->db->commit();
374
+                    return 1;
375
+                }
376
+            }
377
+        }
378
+        else
379
+        {
380
+            dol_print_error($this->db);
381
+            return -1;
382
+        }
383
+    }
384
+
385
+    /**
386
+     *  Initialise an instance with random values.
387
+     *  Used to build previews or test instances.
388
+     *	id must be 0 if object instance is a specimen.
389
+     *
390
+     *  @return	void
391
+     */
392
+    function initAsSpecimen()
393
+    {
394
+        $this->specimen        = 1;
395
+        $this->ref             = 'CBA';
396
+        $this->label           = 'CustomerCorp Bank account';
397
+        $this->bank            = 'CustomerCorp Bank';
398
+        $this->courant         = Account::TYPE_CURRENT;
399
+        $this->clos            = Account::STATUS_OPEN;
400
+        $this->code_banque     = '123';
401
+        $this->code_guichet    = '456';
402
+        $this->number          = 'CUST12345';
403
+        $this->cle_rib         = 50;
404
+        $this->bic             = 'CC12';
405
+        $this->iban            = 'FR999999999';
406
+        $this->domiciliation   = 'Bank address of customer corp';
407
+        $this->proprio         = 'Owner';
408
+        $this->owner_address   = 'Owner address';
409
+        $this->country_id      = 1;
410
+
411
+        $this->rum             = 'UMR-CU1212-0007-5-1475405262';
412
+        $this->date_rum        =dol_now() - 10000;
413
+        $this->frstrecur       = 'FRST';
414
+
415
+        $this->socid = 0;
416
+    }
417 417
 }
418 418
 
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  *		\brief      File of class to manage bank accounts description of third parties
26 26
  */
27 27
 
28
-require_once DOL_DOCUMENT_ROOT .'/compta/bank/class/account.class.php';
28
+require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
29 29
 
30 30
 
31 31
 /**
@@ -67,37 +67,37 @@  discard block
 block discarded – undo
67 67
 	 * @param   int    $notrigger   1=Disable triggers
68 68
 	 * @return	int					<0 if KO, >= 0 if OK
69 69
 	 */
70
-	function create(User $user = null, $notrigger=0)
70
+	function create(User $user = null, $notrigger = 0)
71 71
 	{
72 72
 		$now	= dol_now();
73
-		$error	= 0;
73
+		$error = 0;
74 74
 		// Correct default_rib to be sure to have always one default
75 75
 		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_rib where fk_soc = ".$this->socid." AND default_rib = 1 AND type = 'ban'";
76 76
    		$result = $this->db->query($sql);
77 77
 		if ($result)
78 78
 		{
79
-			$numrows=$this->db->num_rows($result);
79
+			$numrows = $this->db->num_rows($result);
80 80
 			if ($this->default_rib && $numrows > 0) $this->default_rib = 0;
81 81
 			if (empty($this->default_rib) && $numrows == 0) $this->default_rib = 1;
82 82
 		}
83 83
 
84 84
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_rib (fk_soc, type, datec)";
85
-		$sql.= " VALUES (".$this->socid.", 'ban', '".$this->db->idate($now)."')";
86
-		$resql=$this->db->query($sql);
85
+		$sql .= " VALUES (".$this->socid.", 'ban', '".$this->db->idate($now)."')";
86
+		$resql = $this->db->query($sql);
87 87
 		if ($resql)
88 88
 		{
89 89
 			if ($this->db->affected_rows($resql))
90 90
 			{
91 91
 				$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_rib");
92 92
 
93
-				if (! $notrigger)
93
+				if (!$notrigger)
94 94
 				{
95 95
 				   	// Call trigger
96
-					$result=$this->call_trigger('COMPANY_RIB_CREATE',$user);
96
+					$result = $this->call_trigger('COMPANY_RIB_CREATE', $user);
97 97
 					if ($result < 0) $error++;
98 98
 					// End call triggers
99 99
 
100
-					if (! $error)
100
+					if (!$error)
101 101
 					{
102 102
 						return 1;
103 103
 					}
@@ -131,47 +131,47 @@  discard block
 block discarded – undo
131 131
 		global $conf;
132 132
 		$error = 0;
133 133
 
134
-		if (! $this->id) return -1;
134
+		if (!$this->id) return -1;
135 135
 
136 136
 		if (dol_strlen($this->domiciliation) > 255) $this->domiciliation = dol_trunc($this->domiciliation, 254, 'right', 'UTF-8', 1);
137 137
 		if (dol_strlen($this->owner_address) > 255) $this->owner_address = dol_trunc($this->owner_address, 254, 'right', 'UTF-8', 1);
138 138
 
139 139
 		$sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET";
140
-		$sql.= " bank = '" .$this->db->escape($this->bank)."'";
141
-		$sql.= ",code_banque='".$this->db->escape($this->code_banque)."'";
142
-		$sql.= ",code_guichet='".$this->db->escape($this->code_guichet)."'";
143
-		$sql.= ",number='".$this->db->escape($this->number)."'";
144
-		$sql.= ",cle_rib='".$this->db->escape($this->cle_rib)."'";
145
-		$sql.= ",bic='".$this->db->escape($this->bic)."'";
146
-		$sql.= ",iban_prefix = '".$this->db->escape($this->iban)."'";
147
-		$sql.= ",domiciliation='".$this->db->escape($this->domiciliation)."'";
148
-		$sql.= ",proprio = '".$this->db->escape($this->proprio)."'";
149
-		$sql.= ",owner_address = '".$this->db->escape($this->owner_address)."'";
150
-		$sql.= ",default_rib = ".$this->default_rib;
140
+		$sql .= " bank = '".$this->db->escape($this->bank)."'";
141
+		$sql .= ",code_banque='".$this->db->escape($this->code_banque)."'";
142
+		$sql .= ",code_guichet='".$this->db->escape($this->code_guichet)."'";
143
+		$sql .= ",number='".$this->db->escape($this->number)."'";
144
+		$sql .= ",cle_rib='".$this->db->escape($this->cle_rib)."'";
145
+		$sql .= ",bic='".$this->db->escape($this->bic)."'";
146
+		$sql .= ",iban_prefix = '".$this->db->escape($this->iban)."'";
147
+		$sql .= ",domiciliation='".$this->db->escape($this->domiciliation)."'";
148
+		$sql .= ",proprio = '".$this->db->escape($this->proprio)."'";
149
+		$sql .= ",owner_address = '".$this->db->escape($this->owner_address)."'";
150
+		$sql .= ",default_rib = ".$this->default_rib;
151 151
 		if ($conf->prelevement->enabled)
152 152
 		{
153
-			$sql.= ",frstrecur = '".$this->db->escape($this->frstrecur)."'";
154
-			$sql.= ",rum = '".$this->db->escape($this->rum)."'";
155
-			$sql.= ",date_rum = ".($this->date_rum ? "'".$this->db->idate($this->date_rum)."'" : "null");
153
+			$sql .= ",frstrecur = '".$this->db->escape($this->frstrecur)."'";
154
+			$sql .= ",rum = '".$this->db->escape($this->rum)."'";
155
+			$sql .= ",date_rum = ".($this->date_rum ? "'".$this->db->idate($this->date_rum)."'" : "null");
156 156
 		}
157 157
 		if (trim($this->label) != '')
158
-			$sql.= ",label = '".$this->db->escape($this->label)."'";
158
+			$sql .= ",label = '".$this->db->escape($this->label)."'";
159 159
 		else
160
-			$sql.= ",label = NULL";
161
-		$sql.= " WHERE rowid = ".$this->id;
160
+			$sql .= ",label = NULL";
161
+		$sql .= " WHERE rowid = ".$this->id;
162 162
 
163 163
 		$result = $this->db->query($sql);
164 164
 		if ($result)
165 165
 		{
166 166
 
167 167
 
168
-		if (! $notrigger)
168
+		if (!$notrigger)
169 169
 		{
170 170
 			// Call trigger
171
-			$result=$this->call_trigger('COMPANY_RIB_MODIFY',$user);
171
+			$result = $this->call_trigger('COMPANY_RIB_MODIFY', $user);
172 172
 			if ($result < 0) $error++;
173 173
 			// End call triggers
174
-			if(! $error )
174
+			if (!$error)
175 175
 			{
176 176
 				return 1;
177 177
 			}
@@ -201,19 +201,19 @@  discard block
 block discarded – undo
201 201
 	 *  @param	int		$type		If id of company filled, we say if we want record of this type only
202 202
 	 * 	@return	int					<0 if KO, >0 if OK
203 203
 	 */
204
-	function fetch($id, $socid=0, $default=1, $type='ban')
204
+	function fetch($id, $socid = 0, $default = 1, $type = 'ban')
205 205
 	{
206 206
 		if (empty($id) && empty($socid)) return -1;
207 207
 
208 208
 		$sql = "SELECT rowid, type, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,";
209
-		$sql.= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur";
210
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe_rib";
211
-		if ($id)    $sql.= " WHERE rowid = ".$id;
209
+		$sql .= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur";
210
+		$sql .= " FROM ".MAIN_DB_PREFIX."societe_rib";
211
+		if ($id)    $sql .= " WHERE rowid = ".$id;
212 212
 		if ($socid)
213 213
 		{
214
-			$sql.= " WHERE fk_soc  = ".$socid;
215
-			if ($default > -1) $sql.=" AND default_rib = ".$this->db->escape($default);
216
-			if ($type) $sql.= " AND type ='".$this->db->escape($type)."'";
214
+			$sql .= " WHERE fk_soc  = ".$socid;
215
+			if ($default > -1) $sql .= " AND default_rib = ".$this->db->escape($default);
216
+			if ($type) $sql .= " AND type ='".$this->db->escape($type)."'";
217 217
 		}
218 218
 
219 219
 		$resql = $this->db->query($sql);
@@ -223,10 +223,10 @@  discard block
 block discarded – undo
223 223
 			{
224 224
 				$obj = $this->db->fetch_object($resql);
225 225
 
226
-				$this->ref             = $obj->fk_soc.'-'.$obj->label;      // Generate an artificial ref
226
+				$this->ref = $obj->fk_soc.'-'.$obj->label; // Generate an artificial ref
227 227
 
228
-				$this->id			   = $obj->rowid;
229
-				$this->type			   = $obj->type;
228
+				$this->id = $obj->rowid;
229
+				$this->type = $obj->type;
230 230
 				$this->socid           = $obj->fk_soc;
231 231
 				$this->bank            = $obj->bank;
232 232
 				$this->code_banque     = $obj->code_banque;
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 				$this->number          = $obj->number;
235 235
 				$this->cle_rib         = $obj->cle_rib;
236 236
 				$this->bic             = $obj->bic;
237
-				$this->iban		       = $obj->iban;
237
+				$this->iban = $obj->iban;
238 238
 				$this->domiciliation   = $obj->domiciliation;
239 239
 				$this->proprio         = $obj->proprio;
240 240
 				$this->owner_address   = $obj->owner_address;
@@ -263,37 +263,37 @@  discard block
 block discarded – undo
263 263
 	 *	@param  	int		$notrigger	1=Disable triggers
264 264
 	 *  @return		int		            <0 if KO, >0 if OK
265 265
 	 */
266
-	function delete(User $user = null, $notrigger=0)
266
+	function delete(User $user = null, $notrigger = 0)
267 267
 	{
268 268
 		global $conf;
269 269
 
270 270
 		$error = 0;
271 271
 
272
-		dol_syslog(get_class($this) . "::delete ".$this->id, LOG_DEBUG);
272
+		dol_syslog(get_class($this)."::delete ".$this->id, LOG_DEBUG);
273 273
 
274 274
 		$this->db->begin();
275 275
 
276
-		if (! $error && ! $notrigger)
276
+		if (!$error && !$notrigger)
277 277
 		{
278 278
 			// Call trigger
279
-			$result=$this->call_trigger('COMPANY_RIB_DELETE',$user);
279
+			$result = $this->call_trigger('COMPANY_RIB_DELETE', $user);
280 280
 			if ($result < 0) $error++;
281 281
 			// End call triggers
282 282
 		}
283 283
 
284
-		if (! $error)
284
+		if (!$error)
285 285
 		{
286
-			$sql = "DELETE FROM " . MAIN_DB_PREFIX . "societe_rib";
287
-			$sql .= " WHERE rowid  = " . $this->id;
286
+			$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_rib";
287
+			$sql .= " WHERE rowid  = ".$this->id;
288 288
 
289
-			if (! $this->db->query($sql))
289
+			if (!$this->db->query($sql))
290 290
 			{
291 291
 				$error++;
292
-				$this->errors[]=$this->db->lasterror();
292
+				$this->errors[] = $this->db->lasterror();
293 293
 			}
294 294
 		}
295 295
 
296
-		if (! $error)
296
+		if (!$error)
297 297
 		{
298 298
 			$this->db->commit();
299 299
 			return 1;
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 		else
302 302
 		{
303 303
 			$this->db->rollback();
304
-			return -1*$error;
304
+			return -1 * $error;
305 305
 		}
306 306
 	}
307 307
 
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 	{
316 316
 		$rib = '';
317 317
 
318
-		if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib || $this->iban || $this->bic ) {
318
+		if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib || $this->iban || $this->bic) {
319 319
 
320 320
 			if ($this->label && $displayriblabel) {
321 321
 				$rib = $this->label." : ";
@@ -333,10 +333,10 @@  discard block
 block discarded – undo
333 333
 	 * @param   int     $rib    RIB id
334 334
 	 * @return  int             0 if KO, 1 if OK
335 335
 	 */
336
-	function setAsDefault($rib=0)
336
+	function setAsDefault($rib = 0)
337 337
 	{
338 338
 		$sql1 = "SELECT rowid as id, fk_soc  FROM ".MAIN_DB_PREFIX."societe_rib";
339
-		$sql1.= " WHERE rowid = ".($rib?$rib:$this->id);
339
+		$sql1 .= " WHERE rowid = ".($rib ? $rib : $this->id);
340 340
 
341 341
 		dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
342 342
 		$result1 = $this->db->query($sql1);
@@ -353,12 +353,12 @@  discard block
 block discarded – undo
353 353
 				$this->db->begin();
354 354
 
355 355
 				$sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0";
356
-				$sql2.= " WHERE type = 'ban' AND fk_soc = ".$obj->fk_soc;
356
+				$sql2 .= " WHERE type = 'ban' AND fk_soc = ".$obj->fk_soc;
357 357
 				dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
358 358
 				$result2 = $this->db->query($sql2);
359 359
 
360 360
 				$sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1";
361
-				$sql3.= " WHERE rowid = ".$obj->id;
361
+				$sql3 .= " WHERE rowid = ".$obj->id;
362 362
 				dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
363 363
 				$result3 = $this->db->query($sql3);
364 364
 
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
 		$this->country_id      = 1;
410 410
 
411 411
 		$this->rum             = 'UMR-CU1212-0007-5-1475405262';
412
-		$this->date_rum        =dol_now() - 10000;
412
+		$this->date_rum        = dol_now() - 10000;
413 413
 		$this->frstrecur       = 'FRST';
414 414
 
415 415
 		$this->socid = 0;
Please login to merge, or discard this patch.
Braces   +52 added lines, -38 removed lines patch added patch discarded remove patch
@@ -77,8 +77,12 @@  discard block
 block discarded – undo
77 77
 		if ($result)
78 78
 		{
79 79
 			$numrows=$this->db->num_rows($result);
80
-			if ($this->default_rib && $numrows > 0) $this->default_rib = 0;
81
-			if (empty($this->default_rib) && $numrows == 0) $this->default_rib = 1;
80
+			if ($this->default_rib && $numrows > 0) {
81
+			    $this->default_rib = 0;
82
+			}
83
+			if (empty($this->default_rib) && $numrows == 0) {
84
+			    $this->default_rib = 1;
85
+			}
82 86
 		}
83 87
 
84 88
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_rib (fk_soc, type, datec)";
@@ -94,25 +98,24 @@  discard block
 block discarded – undo
94 98
 				{
95 99
 				   	// Call trigger
96 100
 					$result=$this->call_trigger('COMPANY_RIB_CREATE',$user);
97
-					if ($result < 0) $error++;
101
+					if ($result < 0) {
102
+					    $error++;
103
+					}
98 104
 					// End call triggers
99 105
 
100 106
 					if (! $error)
101 107
 					{
102 108
 						return 1;
103
-					}
104
-					else
109
+					} else
105 110
 					{
106 111
 						return 0;
107 112
 					}
108
-				}
109
-				else
113
+				} else
110 114
 				{
111 115
 					return 1;
112 116
 				}
113 117
 			}
114
-		}
115
-		else
118
+		} else
116 119
 		{
117 120
 			print $this->db->error();
118 121
 			return 0;
@@ -131,10 +134,16 @@  discard block
 block discarded – undo
131 134
 		global $conf;
132 135
 		$error = 0;
133 136
 
134
-		if (! $this->id) return -1;
137
+		if (! $this->id) {
138
+		    return -1;
139
+		}
135 140
 
136
-		if (dol_strlen($this->domiciliation) > 255) $this->domiciliation = dol_trunc($this->domiciliation, 254, 'right', 'UTF-8', 1);
137
-		if (dol_strlen($this->owner_address) > 255) $this->owner_address = dol_trunc($this->owner_address, 254, 'right', 'UTF-8', 1);
141
+		if (dol_strlen($this->domiciliation) > 255) {
142
+		    $this->domiciliation = dol_trunc($this->domiciliation, 254, 'right', 'UTF-8', 1);
143
+		}
144
+		if (dol_strlen($this->owner_address) > 255) {
145
+		    $this->owner_address = dol_trunc($this->owner_address, 254, 'right', 'UTF-8', 1);
146
+		}
138 147
 
139 148
 		$sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET";
140 149
 		$sql.= " bank = '" .$this->db->escape($this->bank)."'";
@@ -154,10 +163,11 @@  discard block
 block discarded – undo
154 163
 			$sql.= ",rum = '".$this->db->escape($this->rum)."'";
155 164
 			$sql.= ",date_rum = ".($this->date_rum ? "'".$this->db->idate($this->date_rum)."'" : "null");
156 165
 		}
157
-		if (trim($this->label) != '')
158
-			$sql.= ",label = '".$this->db->escape($this->label)."'";
159
-		else
160
-			$sql.= ",label = NULL";
166
+		if (trim($this->label) != '') {
167
+					$sql.= ",label = '".$this->db->escape($this->label)."'";
168
+		} else {
169
+					$sql.= ",label = NULL";
170
+		}
161 171
 		$sql.= " WHERE rowid = ".$this->id;
162 172
 
163 173
 		$result = $this->db->query($sql);
@@ -169,23 +179,22 @@  discard block
 block discarded – undo
169 179
 		{
170 180
 			// Call trigger
171 181
 			$result=$this->call_trigger('COMPANY_RIB_MODIFY',$user);
172
-			if ($result < 0) $error++;
182
+			if ($result < 0) {
183
+			    $error++;
184
+			}
173 185
 			// End call triggers
174 186
 			if(! $error )
175 187
 			{
176 188
 				return 1;
177
-			}
178
-			else
189
+			} else
179 190
 			{
180 191
 				return -1;
181 192
 			}
182
-		}
183
-		else
193
+		} else
184 194
 		{
185 195
 			return 1;
186 196
 		}
187
-		}
188
-		else
197
+		} else
189 198
 		{
190 199
 			dol_print_error($this->db);
191 200
 			return -1;
@@ -203,17 +212,25 @@  discard block
 block discarded – undo
203 212
 	 */
204 213
 	function fetch($id, $socid=0, $default=1, $type='ban')
205 214
 	{
206
-		if (empty($id) && empty($socid)) return -1;
215
+		if (empty($id) && empty($socid)) {
216
+		    return -1;
217
+		}
207 218
 
208 219
 		$sql = "SELECT rowid, type, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,";
209 220
 		$sql.= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur";
210 221
 		$sql.= " FROM ".MAIN_DB_PREFIX."societe_rib";
211
-		if ($id)    $sql.= " WHERE rowid = ".$id;
222
+		if ($id) {
223
+		    $sql.= " WHERE rowid = ".$id;
224
+		}
212 225
 		if ($socid)
213 226
 		{
214 227
 			$sql.= " WHERE fk_soc  = ".$socid;
215
-			if ($default > -1) $sql.=" AND default_rib = ".$this->db->escape($default);
216
-			if ($type) $sql.= " AND type ='".$this->db->escape($type)."'";
228
+			if ($default > -1) {
229
+			    $sql.=" AND default_rib = ".$this->db->escape($default);
230
+			}
231
+			if ($type) {
232
+			    $sql.= " AND type ='".$this->db->escape($type)."'";
233
+			}
217 234
 		}
218 235
 
219 236
 		$resql = $this->db->query($sql);
@@ -248,8 +265,7 @@  discard block
 block discarded – undo
248 265
 			$this->db->free($resql);
249 266
 
250 267
 			return 1;
251
-		}
252
-		else
268
+		} else
253 269
 		{
254 270
 			dol_print_error($this->db);
255 271
 			return -1;
@@ -277,7 +293,9 @@  discard block
 block discarded – undo
277 293
 		{
278 294
 			// Call trigger
279 295
 			$result=$this->call_trigger('COMPANY_RIB_DELETE',$user);
280
-			if ($result < 0) $error++;
296
+			if ($result < 0) {
297
+			    $error++;
298
+			}
281 299
 			// End call triggers
282 300
 		}
283 301
 
@@ -297,8 +315,7 @@  discard block
 block discarded – undo
297 315
 		{
298 316
 			$this->db->commit();
299 317
 			return 1;
300
-		}
301
-		else
318
+		} else
302 319
 		{
303 320
 			$this->db->rollback();
304 321
 			return -1*$error;
@@ -345,8 +362,7 @@  discard block
 block discarded – undo
345 362
 			if ($this->db->num_rows($result1) == 0)
346 363
 			{
347 364
 				return 0;
348
-			}
349
-			else
365
+			} else
350 366
 			{
351 367
 				$obj = $this->db->fetch_object($result1);
352 368
 
@@ -367,15 +383,13 @@  discard block
 block discarded – undo
367 383
 					dol_print_error($this->db);
368 384
 					$this->db->rollback();
369 385
 					return -1;
370
-				}
371
-				else
386
+				} else
372 387
 				{
373 388
 					$this->db->commit();
374 389
 					return 1;
375 390
 				}
376 391
 			}
377
-		}
378
-		else
392
+		} else
379 393
 		{
380 394
 			dol_print_error($this->db);
381 395
 			return -1;
Please login to merge, or discard this patch.
dolibarr/htdocs/societe/class/api_contacts.class.php 3 patches
Indentation   +308 added lines, -308 removed lines patch added patch discarded remove patch
@@ -29,305 +29,305 @@  discard block
 block discarded – undo
29 29
  */
30 30
 class Contacts extends DolibarrApi
31 31
 {
32
-	/**
33
-	 *
34
-	 * @var array   $FIELDS     Mandatory fields, checked when create and update object
35
-	 */
36
-	static $FIELDS = array(
37
-		'lastname',
38
-	);
39
-
40
-	/**
41
-	 * @var Contact $contact {@type Contact}
42
-	 */
43
-	public $contact;
44
-
45
-	/**
46
-	 * Constructor
47
-	 */
48
-	function __construct()
49
-	{
50
-		global $db, $conf;
51
-		$this->db = $db;
52
-
53
-		require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
54
-		require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
55
-
56
-		$this->contact = new Contact($this->db);
57
-	}
58
-
59
-	/**
60
-	 * Get properties of a contact object
61
-	 *
62
-	 * Return an array with contact informations
63
-	 *
64
-	 * @param 	int 	$id ID of contact
65
-	 * @return 	array|mixed data without useless information
66
-	 *
67
-	 * @throws 	RestException
68
-	 */
69
-	function get($id)
70
-	{
71
-		if (!DolibarrApiAccess::$user->rights->societe->contact->lire)
72
-		{
73
-			throw new RestException(401, 'No permission to read contacts');
74
-		}
75
-
76
-		$result = $this->contact->fetch($id);
77
-		if (!$result)
78
-		{
79
-			throw new RestException(404, 'Contact not found');
80
-		}
81
-
82
-		if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe'))
83
-		{
84
-			throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
85
-		}
86
-
87
-		return $this->_cleanObjectDatas($this->contact);
88
-	}
89
-
90
-	/**
91
-	 * List contacts
92
-	 *
93
-	 * Get a list of contacts
94
-	 *
95
-	 * @param string	$sortfield	        Sort field
96
-	 * @param string	$sortorder	        Sort order
97
-	 * @param int		$limit		        Limit for list
98
-	 * @param int		$page		        Page number
32
+    /**
33
+     *
34
+     * @var array   $FIELDS     Mandatory fields, checked when create and update object
35
+     */
36
+    static $FIELDS = array(
37
+        'lastname',
38
+    );
39
+
40
+    /**
41
+     * @var Contact $contact {@type Contact}
42
+     */
43
+    public $contact;
44
+
45
+    /**
46
+     * Constructor
47
+     */
48
+    function __construct()
49
+    {
50
+        global $db, $conf;
51
+        $this->db = $db;
52
+
53
+        require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
54
+        require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
55
+
56
+        $this->contact = new Contact($this->db);
57
+    }
58
+
59
+    /**
60
+     * Get properties of a contact object
61
+     *
62
+     * Return an array with contact informations
63
+     *
64
+     * @param 	int 	$id ID of contact
65
+     * @return 	array|mixed data without useless information
66
+     *
67
+     * @throws 	RestException
68
+     */
69
+    function get($id)
70
+    {
71
+        if (!DolibarrApiAccess::$user->rights->societe->contact->lire)
72
+        {
73
+            throw new RestException(401, 'No permission to read contacts');
74
+        }
75
+
76
+        $result = $this->contact->fetch($id);
77
+        if (!$result)
78
+        {
79
+            throw new RestException(404, 'Contact not found');
80
+        }
81
+
82
+        if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe'))
83
+        {
84
+            throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
85
+        }
86
+
87
+        return $this->_cleanObjectDatas($this->contact);
88
+    }
89
+
90
+    /**
91
+     * List contacts
92
+     *
93
+     * Get a list of contacts
94
+     *
95
+     * @param string	$sortfield	        Sort field
96
+     * @param string	$sortorder	        Sort order
97
+     * @param int		$limit		        Limit for list
98
+     * @param int		$page		        Page number
99 99
      * @param string   	$thirdparty_ids	    Thirdparty ids to filter contacts of. {@example '1' or '1,2,3'} {@pattern /^[0-9,]*$/i}
100 100
      * @param string    $sqlfilters         Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
101
-	 * @return array                        Array of contact objects
101
+     * @return array                        Array of contact objects
102 102
      *
103
-	 * @throws RestException
103
+     * @throws RestException
104 104
      */
105 105
     function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '')
106 106
     {
107
-		global $db, $conf;
107
+        global $db, $conf;
108 108
 
109
-		$obj_ret = array();
109
+        $obj_ret = array();
110 110
 
111
-		if (!DolibarrApiAccess::$user->rights->societe->contact->lire)
112
-		{
113
-		    throw new RestException(401, 'No permission to read contacts');
114
-		}
111
+        if (!DolibarrApiAccess::$user->rights->societe->contact->lire)
112
+        {
113
+            throw new RestException(401, 'No permission to read contacts');
114
+        }
115 115
 
116 116
         // case of external user, $thirdparty_ids param is ignored and replaced by user's socid
117
-		$socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids;
118
-
119
-		// If the internal user must only see his customers, force searching by him
120
-		$search_sale = 0;
121
-		if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids)
122
-			$search_sale = DolibarrApiAccess::$user->id;
123
-
124
-		$sql = "SELECT t.rowid";
125
-		$sql.= " FROM " . MAIN_DB_PREFIX . "socpeople as t";
126
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX . "socpeople_extrafields as te ON te.fk_object = t.rowid";
127
-		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
128
-			// We need this table joined to the select in order to filter by sale
129
-			$sql.= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
130
-		}
131
-		$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON t.fk_soc = s.rowid";
132
-		$sql.= ' WHERE t.entity IN (' . getEntity('socpeople') . ')';
133
-		if ($socids) $sql.= " AND t.fk_soc IN (" . $socids . ")";
134
-
135
-		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0)
136
-			$sql.= " AND t.fk_soc = sc.fk_soc";
137
-		if ($search_sale > 0)
138
-			$sql.= " AND s.rowid = sc.fk_soc";  // Join for the needed table to filter by sale
139
-		// Insert sale filter
140
-		if ($search_sale > 0)
141
-		{
142
-			$sql .= " AND sc.fk_user = " . $search_sale;
143
-		}
144
-	    // Add sql filters
117
+        $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids;
118
+
119
+        // If the internal user must only see his customers, force searching by him
120
+        $search_sale = 0;
121
+        if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids)
122
+            $search_sale = DolibarrApiAccess::$user->id;
123
+
124
+        $sql = "SELECT t.rowid";
125
+        $sql.= " FROM " . MAIN_DB_PREFIX . "socpeople as t";
126
+        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX . "socpeople_extrafields as te ON te.fk_object = t.rowid";
127
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
128
+            // We need this table joined to the select in order to filter by sale
129
+            $sql.= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
130
+        }
131
+        $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON t.fk_soc = s.rowid";
132
+        $sql.= ' WHERE t.entity IN (' . getEntity('socpeople') . ')';
133
+        if ($socids) $sql.= " AND t.fk_soc IN (" . $socids . ")";
134
+
135
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0)
136
+            $sql.= " AND t.fk_soc = sc.fk_soc";
137
+        if ($search_sale > 0)
138
+            $sql.= " AND s.rowid = sc.fk_soc";  // Join for the needed table to filter by sale
139
+        // Insert sale filter
140
+        if ($search_sale > 0)
141
+        {
142
+            $sql .= " AND sc.fk_user = " . $search_sale;
143
+        }
144
+        // Add sql filters
145 145
         if ($sqlfilters)
146 146
         {
147 147
             if (! DolibarrApi::_checkFilters($sqlfilters))
148 148
             {
149 149
                 throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
150 150
             }
151
-	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
151
+            $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
152 152
             $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
153 153
         }
154 154
 
155
-		$sql.= $db->order($sortfield, $sortorder);
156
-
157
-		if ($limit)
158
-		{
159
-			if ($page < 0)
160
-			{
161
-				$page = 0;
162
-			}
163
-			$offset = $limit * $page;
164
-
165
-			$sql.= $db->plimit($limit + 1, $offset);
166
-		}
167
-		$result = $db->query($sql);
168
-		if ($result)
169
-		{
170
-			$num = $db->num_rows($result);
171
-			$min = min($num, ($limit <= 0 ? $num : $limit));
172
-			while ($i < $min)
173
-			{
174
-				$obj = $db->fetch_object($result);
175
-				$contact_static = new Contact($db);
176
-				if ($contact_static->fetch($obj->rowid))
177
-				{
178
-					$obj_ret[] = $this->_cleanObjectDatas($contact_static);
179
-				}
180
-				$i++;
181
-			}
182
-		}
183
-		else {
184
-			throw new RestException(503, 'Error when retrieve contacts : ' . $sql);
185
-		}
186
-		if (!count($obj_ret))
187
-		{
188
-			throw new RestException(404, 'Contacts not found');
189
-		}
190
-		return $obj_ret;
191
-	}
192
-
193
-	/**
194
-	 * Create contact object
195
-	 *
196
-	 * @param   array   $request_data   Request datas
197
-	 * @return  int     ID of contact
198
-	 */
155
+        $sql.= $db->order($sortfield, $sortorder);
156
+
157
+        if ($limit)
158
+        {
159
+            if ($page < 0)
160
+            {
161
+                $page = 0;
162
+            }
163
+            $offset = $limit * $page;
164
+
165
+            $sql.= $db->plimit($limit + 1, $offset);
166
+        }
167
+        $result = $db->query($sql);
168
+        if ($result)
169
+        {
170
+            $num = $db->num_rows($result);
171
+            $min = min($num, ($limit <= 0 ? $num : $limit));
172
+            while ($i < $min)
173
+            {
174
+                $obj = $db->fetch_object($result);
175
+                $contact_static = new Contact($db);
176
+                if ($contact_static->fetch($obj->rowid))
177
+                {
178
+                    $obj_ret[] = $this->_cleanObjectDatas($contact_static);
179
+                }
180
+                $i++;
181
+            }
182
+        }
183
+        else {
184
+            throw new RestException(503, 'Error when retrieve contacts : ' . $sql);
185
+        }
186
+        if (!count($obj_ret))
187
+        {
188
+            throw new RestException(404, 'Contacts not found');
189
+        }
190
+        return $obj_ret;
191
+    }
192
+
193
+    /**
194
+     * Create contact object
195
+     *
196
+     * @param   array   $request_data   Request datas
197
+     * @return  int     ID of contact
198
+     */
199 199
     function post($request_data = null)
200 200
     {
201
-		if (!DolibarrApiAccess::$user->rights->societe->contact->creer)
202
-		{
203
-			throw new RestException(401, 'No permission to create/update contacts');
204
-		}
205
-		// Check mandatory fields
206
-		$result = $this->_validate($request_data);
207
-
208
-		foreach ($request_data as $field => $value)
209
-		{
210
-			$this->contact->$field = $value;
211
-		}
212
-		if ($this->contact->create(DolibarrApiAccess::$user) < 0) {
213
-		    throw new RestException(500, "Error creating contact", array_merge(array($this->contact->error), $this->contact->errors));
214
-		}
215
-		return $this->contact->id;
216
-	}
217
-
218
-	/**
219
-	 * Update contact
220
-	 *
221
-	 * @param int   $id             Id of contact to update
222
-	 * @param array $request_data   Datas
223
-	 * @return int
224
-	 */
201
+        if (!DolibarrApiAccess::$user->rights->societe->contact->creer)
202
+        {
203
+            throw new RestException(401, 'No permission to create/update contacts');
204
+        }
205
+        // Check mandatory fields
206
+        $result = $this->_validate($request_data);
207
+
208
+        foreach ($request_data as $field => $value)
209
+        {
210
+            $this->contact->$field = $value;
211
+        }
212
+        if ($this->contact->create(DolibarrApiAccess::$user) < 0) {
213
+            throw new RestException(500, "Error creating contact", array_merge(array($this->contact->error), $this->contact->errors));
214
+        }
215
+        return $this->contact->id;
216
+    }
217
+
218
+    /**
219
+     * Update contact
220
+     *
221
+     * @param int   $id             Id of contact to update
222
+     * @param array $request_data   Datas
223
+     * @return int
224
+     */
225 225
     function put($id, $request_data = null)
226 226
     {
227
-		if (!DolibarrApiAccess::$user->rights->societe->contact->creer)
228
-		{
229
-			throw new RestException(401, 'No permission to create/update contacts');
230
-		}
231
-
232
-		$result = $this->contact->fetch($id);
233
-		if (!$result)
234
-		{
235
-			throw new RestException(404, 'Contact not found');
236
-		}
237
-
238
-		if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe'))
239
-		{
240
-			throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
241
-		}
242
-
243
-		foreach ($request_data as $field => $value)
244
-		{
227
+        if (!DolibarrApiAccess::$user->rights->societe->contact->creer)
228
+        {
229
+            throw new RestException(401, 'No permission to create/update contacts');
230
+        }
231
+
232
+        $result = $this->contact->fetch($id);
233
+        if (!$result)
234
+        {
235
+            throw new RestException(404, 'Contact not found');
236
+        }
237
+
238
+        if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe'))
239
+        {
240
+            throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
241
+        }
242
+
243
+        foreach ($request_data as $field => $value)
244
+        {
245 245
             if ($field == 'id') continue;
246
-		    $this->contact->$field = $value;
247
-		}
246
+            $this->contact->$field = $value;
247
+        }
248 248
 
249
-		if ($this->contact->update($id, DolibarrApiAccess::$user, 1, '', '', 'update'))
250
-			return $this->get($id);
249
+        if ($this->contact->update($id, DolibarrApiAccess::$user, 1, '', '', 'update'))
250
+            return $this->get($id);
251 251
 
252
-		return false;
253
-	}
252
+        return false;
253
+    }
254 254
 
255
-	/**
256
-	 * Delete contact
257
-	 *
258
-	 * @param   int     $id Contact ID
259
-	 * @return  integer
260
-	 */
255
+    /**
256
+     * Delete contact
257
+     *
258
+     * @param   int     $id Contact ID
259
+     * @return  integer
260
+     */
261 261
     function delete($id)
262 262
     {
263
-		if (!DolibarrApiAccess::$user->rights->societe->contact->supprimer)
264
-		{
265
-			throw new RestException(401, 'No permission to delete contacts');
266
-		}
267
-		$result = $this->contact->fetch($id);
268
-		if (!$result)
269
-		{
270
-			throw new RestException(404, 'Contact not found');
271
-		}
272
-
273
-		if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe'))
274
-		{
275
-			throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
276
-		}
277
-
278
-		return $this->contact->delete($id);
279
-	}
280
-
281
-	/**
282
-	 * Create an user account object from contact (external user)
283
-	 *
284
-	 * @param   int   	$id   Id of contact
285
-	 * @param   array   $request_data   Request datas
286
-	 * @return  int     ID of user
287
-	 *
288
-	 * @url	POST {id}/createUser
289
-	 */
263
+        if (!DolibarrApiAccess::$user->rights->societe->contact->supprimer)
264
+        {
265
+            throw new RestException(401, 'No permission to delete contacts');
266
+        }
267
+        $result = $this->contact->fetch($id);
268
+        if (!$result)
269
+        {
270
+            throw new RestException(404, 'Contact not found');
271
+        }
272
+
273
+        if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe'))
274
+        {
275
+            throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
276
+        }
277
+
278
+        return $this->contact->delete($id);
279
+    }
280
+
281
+    /**
282
+     * Create an user account object from contact (external user)
283
+     *
284
+     * @param   int   	$id   Id of contact
285
+     * @param   array   $request_data   Request datas
286
+     * @return  int     ID of user
287
+     *
288
+     * @url	POST {id}/createUser
289
+     */
290 290
     function createUser($id, $request_data = null)
291 291
     {
292
-	    //if (!DolibarrApiAccess::$user->rights->user->user->creer) {
293
-	    //throw new RestException(401);
294
-	    //}
295
-
296
-	    if (!isset($request_data["login"]))
297
-	    				throw new RestException(400, "login field missing");
298
-	    if (!isset($request_data["password"]))
299
-	    				throw new RestException(400, "password field missing");
300
-
301
-	    if (!DolibarrApiAccess::$user->rights->societe->contact->lire) {
302
-	        throw new RestException(401, 'No permission to read contacts');
303
-	    }
304
-	    if (!DolibarrApiAccess::$user->rights->user->user->creer) {
305
-	        throw new RestException(401, 'No permission to create user');
306
-	    }
307
-
308
-	    $contact = new Contact($this->db);
309
-	    $contact->fetch($id);
310
-	    if ($contact->id <= 0) {
311
-	        throw new RestException(404, 'Contact not found');
312
-	    }
313
-
314
-	    if (!DolibarrApi::_checkAccessToResource('contact', $contact->id, 'socpeople&societe')) {
315
-	        throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
316
-	    }
317
-
318
-	    // Check mandatory fields
319
-	    $login = $request_data["login"];
320
-	    $password = $request_data["password"];
321
-	    $useraccount = new User($this->db);
322
-	    $result = $useraccount->create_from_contact($contact,$login,$password);
323
-	    if ($result <= 0) {
324
-	        throw new RestException(500, "User not created");
325
-	    }
326
-	    // password parameter not used in create_from_contact
327
-	    $useraccount->setPassword($useraccount,$password);
328
-
329
-	    return $result;
330
-	}
292
+        //if (!DolibarrApiAccess::$user->rights->user->user->creer) {
293
+        //throw new RestException(401);
294
+        //}
295
+
296
+        if (!isset($request_data["login"]))
297
+                        throw new RestException(400, "login field missing");
298
+        if (!isset($request_data["password"]))
299
+                        throw new RestException(400, "password field missing");
300
+
301
+        if (!DolibarrApiAccess::$user->rights->societe->contact->lire) {
302
+            throw new RestException(401, 'No permission to read contacts');
303
+        }
304
+        if (!DolibarrApiAccess::$user->rights->user->user->creer) {
305
+            throw new RestException(401, 'No permission to create user');
306
+        }
307
+
308
+        $contact = new Contact($this->db);
309
+        $contact->fetch($id);
310
+        if ($contact->id <= 0) {
311
+            throw new RestException(404, 'Contact not found');
312
+        }
313
+
314
+        if (!DolibarrApi::_checkAccessToResource('contact', $contact->id, 'socpeople&societe')) {
315
+            throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
316
+        }
317
+
318
+        // Check mandatory fields
319
+        $login = $request_data["login"];
320
+        $password = $request_data["password"];
321
+        $useraccount = new User($this->db);
322
+        $result = $useraccount->create_from_contact($contact,$login,$password);
323
+        if ($result <= 0) {
324
+            throw new RestException(500, "User not created");
325
+        }
326
+        // password parameter not used in create_from_contact
327
+        $useraccount->setPassword($useraccount,$password);
328
+
329
+        return $result;
330
+    }
331 331
 
332 332
     /**
333 333
      * Get categories for a contact
@@ -342,25 +342,25 @@  discard block
 block discarded – undo
342 342
      *
343 343
      * @url GET {id}/categories
344 344
      */
345
-	function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
346
-	{
347
-		if (! DolibarrApiAccess::$user->rights->categorie->lire) {
348
-			throw new RestException(401);
349
-		}
345
+    function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
346
+    {
347
+        if (! DolibarrApiAccess::$user->rights->categorie->lire) {
348
+            throw new RestException(401);
349
+        }
350 350
 
351
-		$categories = new Categorie($this->db);
351
+        $categories = new Categorie($this->db);
352 352
 
353
-		$result = $categories->getListForItem($id, 'contact', $sortfield, $sortorder, $limit, $page);
353
+        $result = $categories->getListForItem($id, 'contact', $sortfield, $sortorder, $limit, $page);
354 354
 
355
-		if (empty($result)) {
356
-			throw new RestException(404, 'No category found');
357
-		}
355
+        if (empty($result)) {
356
+            throw new RestException(404, 'No category found');
357
+        }
358 358
 
359
-		if ($result < 0) {
360
-			throw new RestException(503, 'Error when retrieve category list : '.$categories->error);
361
-		}
359
+        if ($result < 0) {
360
+            throw new RestException(503, 'Error when retrieve category list : '.$categories->error);
361
+        }
362 362
 
363
-		return $result;
363
+        return $result;
364 364
     }
365 365
 
366 366
 
@@ -373,38 +373,38 @@  discard block
 block discarded – undo
373 373
     function _cleanObjectDatas($object)
374 374
     {
375 375
 
376
-    	$object = parent::_cleanObjectDatas($object);
376
+        $object = parent::_cleanObjectDatas($object);
377 377
 
378
-    	unset($object->total_ht);
379
-    	unset($object->total_tva);
380
-    	unset($object->total_localtax1);
381
-    	unset($object->total_localtax2);
382
-    	unset($object->total_ttc);
378
+        unset($object->total_ht);
379
+        unset($object->total_tva);
380
+        unset($object->total_localtax1);
381
+        unset($object->total_localtax2);
382
+        unset($object->total_ttc);
383 383
 
384
-    	unset($object->note);
385
-    	unset($object->lines);
386
-    	unset($object->thirdparty);
384
+        unset($object->note);
385
+        unset($object->lines);
386
+        unset($object->thirdparty);
387 387
 
388
-    	return $object;
388
+        return $object;
389 389
     }
390 390
 
391
-	/**
392
-	 * Validate fields before create or update object
391
+    /**
392
+     * Validate fields before create or update object
393 393
      *
394
-	 * @param   array|null     $data   Data to validate
395
-	 * @return  array
396
-	 * @throws RestException
397
-	 */
394
+     * @param   array|null     $data   Data to validate
395
+     * @return  array
396
+     * @throws RestException
397
+     */
398 398
     function _validate($data)
399 399
     {
400
-		$contact = array();
401
-		foreach (Contacts::$FIELDS as $field)
402
-		{
403
-			if (!isset($data[$field]))
404
-				throw new RestException(400, "$field field missing");
405
-			$contact[$field] = $data[$field];
406
-		}
407
-
408
-		return $contact;
409
-	}
400
+        $contact = array();
401
+        foreach (Contacts::$FIELDS as $field)
402
+        {
403
+            if (!isset($data[$field]))
404
+                throw new RestException(400, "$field field missing");
405
+            $contact[$field] = $data[$field];
406
+        }
407
+
408
+        return $contact;
409
+    }
410 410
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 
82 82
 		if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe'))
83 83
 		{
84
-			throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
84
+			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
85 85
 		}
86 86
 
87 87
 		return $this->_cleanObjectDatas($this->contact);
@@ -122,37 +122,37 @@  discard block
 block discarded – undo
122 122
 			$search_sale = DolibarrApiAccess::$user->id;
123 123
 
124 124
 		$sql = "SELECT t.rowid";
125
-		$sql.= " FROM " . MAIN_DB_PREFIX . "socpeople as t";
126
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX . "socpeople_extrafields as te ON te.fk_object = t.rowid";
125
+		$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as t";
126
+		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as te ON te.fk_object = t.rowid";
127 127
 		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
128 128
 			// We need this table joined to the select in order to filter by sale
129
-			$sql.= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
129
+			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
130 130
 		}
131
-		$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON t.fk_soc = s.rowid";
132
-		$sql.= ' WHERE t.entity IN (' . getEntity('socpeople') . ')';
133
-		if ($socids) $sql.= " AND t.fk_soc IN (" . $socids . ")";
131
+		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON t.fk_soc = s.rowid";
132
+		$sql .= ' WHERE t.entity IN ('.getEntity('socpeople').')';
133
+		if ($socids) $sql .= " AND t.fk_soc IN (".$socids.")";
134 134
 
135 135
 		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0)
136
-			$sql.= " AND t.fk_soc = sc.fk_soc";
136
+			$sql .= " AND t.fk_soc = sc.fk_soc";
137 137
 		if ($search_sale > 0)
138
-			$sql.= " AND s.rowid = sc.fk_soc";  // Join for the needed table to filter by sale
138
+			$sql .= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
139 139
 		// Insert sale filter
140 140
 		if ($search_sale > 0)
141 141
 		{
142
-			$sql .= " AND sc.fk_user = " . $search_sale;
142
+			$sql .= " AND sc.fk_user = ".$search_sale;
143 143
 		}
144 144
 	    // Add sql filters
145 145
         if ($sqlfilters)
146 146
         {
147
-            if (! DolibarrApi::_checkFilters($sqlfilters))
147
+            if (!DolibarrApi::_checkFilters($sqlfilters))
148 148
             {
149 149
                 throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
150 150
             }
151
-	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
152
-            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
151
+	        $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
152
+            $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
153 153
         }
154 154
 
155
-		$sql.= $db->order($sortfield, $sortorder);
155
+		$sql .= $db->order($sortfield, $sortorder);
156 156
 
157 157
 		if ($limit)
158 158
 		{
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 			}
163 163
 			$offset = $limit * $page;
164 164
 
165
-			$sql.= $db->plimit($limit + 1, $offset);
165
+			$sql .= $db->plimit($limit + 1, $offset);
166 166
 		}
167 167
 		$result = $db->query($sql);
168 168
 		if ($result)
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 			}
182 182
 		}
183 183
 		else {
184
-			throw new RestException(503, 'Error when retrieve contacts : ' . $sql);
184
+			throw new RestException(503, 'Error when retrieve contacts : '.$sql);
185 185
 		}
186 186
 		if (!count($obj_ret))
187 187
 		{
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 
238 238
 		if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe'))
239 239
 		{
240
-			throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
240
+			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
241 241
 		}
242 242
 
243 243
 		foreach ($request_data as $field => $value)
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 
273 273
 		if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe'))
274 274
 		{
275
-			throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
275
+			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
276 276
 		}
277 277
 
278 278
 		return $this->contact->delete($id);
@@ -312,19 +312,19 @@  discard block
 block discarded – undo
312 312
 	    }
313 313
 
314 314
 	    if (!DolibarrApi::_checkAccessToResource('contact', $contact->id, 'socpeople&societe')) {
315
-	        throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
315
+	        throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
316 316
 	    }
317 317
 
318 318
 	    // Check mandatory fields
319 319
 	    $login = $request_data["login"];
320 320
 	    $password = $request_data["password"];
321 321
 	    $useraccount = new User($this->db);
322
-	    $result = $useraccount->create_from_contact($contact,$login,$password);
322
+	    $result = $useraccount->create_from_contact($contact, $login, $password);
323 323
 	    if ($result <= 0) {
324 324
 	        throw new RestException(500, "User not created");
325 325
 	    }
326 326
 	    // password parameter not used in create_from_contact
327
-	    $useraccount->setPassword($useraccount,$password);
327
+	    $useraccount->setPassword($useraccount, $password);
328 328
 
329 329
 	    return $result;
330 330
 	}
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
      */
345 345
 	function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
346 346
 	{
347
-		if (! DolibarrApiAccess::$user->rights->categorie->lire) {
347
+		if (!DolibarrApiAccess::$user->rights->categorie->lire) {
348 348
 			throw new RestException(401);
349 349
 		}
350 350
 
Please login to merge, or discard this patch.
Braces   +29 added lines, -18 removed lines patch added patch discarded remove patch
@@ -118,8 +118,9 @@  discard block
 block discarded – undo
118 118
 
119 119
 		// If the internal user must only see his customers, force searching by him
120 120
 		$search_sale = 0;
121
-		if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids)
122
-			$search_sale = DolibarrApiAccess::$user->id;
121
+		if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) {
122
+					$search_sale = DolibarrApiAccess::$user->id;
123
+		}
123 124
 
124 125
 		$sql = "SELECT t.rowid";
125 126
 		$sql.= " FROM " . MAIN_DB_PREFIX . "socpeople as t";
@@ -130,12 +131,17 @@  discard block
 block discarded – undo
130 131
 		}
131 132
 		$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON t.fk_soc = s.rowid";
132 133
 		$sql.= ' WHERE t.entity IN (' . getEntity('socpeople') . ')';
133
-		if ($socids) $sql.= " AND t.fk_soc IN (" . $socids . ")";
134
+		if ($socids) {
135
+		    $sql.= " AND t.fk_soc IN (" . $socids . ")";
136
+		}
134 137
 
135
-		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0)
136
-			$sql.= " AND t.fk_soc = sc.fk_soc";
137
-		if ($search_sale > 0)
138
-			$sql.= " AND s.rowid = sc.fk_soc";  // Join for the needed table to filter by sale
138
+		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
139
+					$sql.= " AND t.fk_soc = sc.fk_soc";
140
+		}
141
+		if ($search_sale > 0) {
142
+					$sql.= " AND s.rowid = sc.fk_soc";
143
+		}
144
+		// Join for the needed table to filter by sale
139 145
 		// Insert sale filter
140 146
 		if ($search_sale > 0)
141 147
 		{
@@ -179,8 +185,7 @@  discard block
 block discarded – undo
179 185
 				}
180 186
 				$i++;
181 187
 			}
182
-		}
183
-		else {
188
+		} else {
184 189
 			throw new RestException(503, 'Error when retrieve contacts : ' . $sql);
185 190
 		}
186 191
 		if (!count($obj_ret))
@@ -242,12 +247,15 @@  discard block
 block discarded – undo
242 247
 
243 248
 		foreach ($request_data as $field => $value)
244 249
 		{
245
-            if ($field == 'id') continue;
250
+            if ($field == 'id') {
251
+                continue;
252
+            }
246 253
 		    $this->contact->$field = $value;
247 254
 		}
248 255
 
249
-		if ($this->contact->update($id, DolibarrApiAccess::$user, 1, '', '', 'update'))
250
-			return $this->get($id);
256
+		if ($this->contact->update($id, DolibarrApiAccess::$user, 1, '', '', 'update')) {
257
+					return $this->get($id);
258
+		}
251 259
 
252 260
 		return false;
253 261
 	}
@@ -293,10 +301,12 @@  discard block
 block discarded – undo
293 301
 	    //throw new RestException(401);
294 302
 	    //}
295 303
 
296
-	    if (!isset($request_data["login"]))
297
-	    				throw new RestException(400, "login field missing");
298
-	    if (!isset($request_data["password"]))
299
-	    				throw new RestException(400, "password field missing");
304
+	    if (!isset($request_data["login"])) {
305
+	    	    				throw new RestException(400, "login field missing");
306
+	    }
307
+	    if (!isset($request_data["password"])) {
308
+	    	    				throw new RestException(400, "password field missing");
309
+	    }
300 310
 
301 311
 	    if (!DolibarrApiAccess::$user->rights->societe->contact->lire) {
302 312
 	        throw new RestException(401, 'No permission to read contacts');
@@ -400,8 +410,9 @@  discard block
 block discarded – undo
400 410
 		$contact = array();
401 411
 		foreach (Contacts::$FIELDS as $field)
402 412
 		{
403
-			if (!isset($data[$field]))
404
-				throw new RestException(400, "$field field missing");
413
+			if (!isset($data[$field])) {
414
+							throw new RestException(400, "$field field missing");
415
+			}
405 416
 			$contact[$field] = $data[$field];
406 417
 		}
407 418
 
Please login to merge, or discard this patch.
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.
Spacing   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -34,18 +34,18 @@  discard block
 block discarded – undo
34 34
 
35 35
 $langs->loadLangs(array("orders", "companies"));
36 36
 
37
-$id=GETPOST('id','int')?GETPOST('id','int'):GETPOST('socid','int');
38
-$ref=GETPOST('ref','alpha');
39
-$action=GETPOST('action','alpha');
37
+$id = GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('socid', 'int');
38
+$ref = GETPOST('ref', 'alpha');
39
+$action = GETPOST('action', 'alpha');
40 40
 
41 41
 // Security check
42
-if ($user->societe_id) $socid=$user->societe_id;
43
-$result = restrictedArea($user, 'societe', $id,'');
42
+if ($user->societe_id) $socid = $user->societe_id;
43
+$result = restrictedArea($user, 'societe', $id, '');
44 44
 
45 45
 $object = new Societe($db);
46 46
 
47 47
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
48
-$hookmanager->initHooks(array('contactthirdparty','globalcard'));
48
+$hookmanager->initHooks(array('contactthirdparty', 'globalcard'));
49 49
 
50 50
 
51 51
 /*
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 
59 59
     if ($result > 0 && $id > 0)
60 60
     {
61
-    	$contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int'));
61
+    	$contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
62 62
   		$result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
63 63
     }
64 64
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 {
87 87
 	if ($object->fetch($id))
88 88
 	{
89
-	    $result=$object->swapContactStatus(GETPOST('ligne'));
89
+	    $result = $object->swapContactStatus(GETPOST('ligne'));
90 90
 	}
91 91
 	else
92 92
 	{
@@ -122,15 +122,15 @@  discard block
 block discarded – undo
122 122
  * View
123 123
  */
124 124
 
125
-$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
126
-llxHeader('',$langs->trans("ThirdParty"),$help_url);
125
+$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
126
+llxHeader('', $langs->trans("ThirdParty"), $help_url);
127 127
 
128 128
 
129 129
 $form = new Form($db);
130 130
 $formcompany = new FormCompany($db);
131 131
 $formother = new FormOther($db);
132
-$contactstatic=new Contact($db);
133
-$userstatic=new User($db);
132
+$contactstatic = new Contact($db);
133
+$userstatic = new User($db);
134 134
 
135 135
 
136 136
 /* *************************************************************************** */
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 /*                                                                             */
140 140
 /* *************************************************************************** */
141 141
 
142
-if ($id > 0 || ! empty($ref))
142
+if ($id > 0 || !empty($ref))
143 143
 {
144 144
 	if ($object->fetch($id, $ref) > 0)
145 145
 	{
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 
155 155
         $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
156 156
 
157
-        dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
157
+        dol_banner_tab($object, 'socid', $linkback, ($user->societe_id ? 0 : 1), 'rowid', 'nom');
158 158
 
159 159
     	print '<div class="fichecenter">';
160 160
 
@@ -171,7 +171,7 @@  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
174
+		if (!empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
175 175
 		{
176 176
 		    print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
177 177
 		}
@@ -201,31 +201,31 @@  discard block
 block discarded – undo
201 201
 		print '<br>';
202 202
 
203 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)
204
+		$dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
205
+		foreach ($dirtpls as $reldir)
206 206
 		{
207
-			$res=@include dol_buildpath($reldir.'/contacts.tpl.php');
207
+			$res = @include dol_buildpath($reldir.'/contacts.tpl.php');
208 208
 			if ($res) break;
209 209
 		}
210 210
 
211 211
 		// additionnal list with adherents of company
212
-		if (! empty($conf->adherent->enabled) && $user->rights->adherent->lire)
212
+		if (!empty($conf->adherent->enabled) && $user->rights->adherent->lire)
213 213
 		{
214 214
 			require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
215 215
 			require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
216 216
 
217
-			$membertypestatic=new AdherentType($db);
218
-			$memberstatic=new Adherent($db);
217
+			$membertypestatic = new AdherentType($db);
218
+			$memberstatic = new Adherent($db);
219 219
 
220 220
 			$langs->load("members");
221 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";
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 229
 
230 230
 			dol_syslog("get list sql=".$sql);
231 231
 			$resql = $db->query($sql);
@@ -233,39 +233,39 @@  discard block
 block discarded – undo
233 233
 			{
234 234
 				$num = $db->num_rows($resql);
235 235
 
236
-				if ($num  > 0 )
236
+				if ($num > 0)
237 237
 				{
238
-					$titre=$langs->trans("MembersListOfTiers");
238
+					$titre = $langs->trans("MembersListOfTiers");
239 239
 					print '<br>';
240 240
 
241
-					print_barre_liste($titre,$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords,'');
241
+					print_barre_liste($titre, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '');
242 242
 
243 243
 					print "<table class=\"noborder\" width=\"100%\">";
244 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);
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 253
 					print "</tr>\n";
254 254
 
255
-					$i=0;
255
+					$i = 0;
256 256
 					while ($i < $num && $i < $conf->liste_limit)
257 257
 					{
258 258
 						$objp = $db->fetch_object($resql);
259 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);
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 267
 
268
-						$companyname=$objp->company;
268
+						$companyname = $objp->company;
269 269
 
270 270
 						print '<tr class="oddeven">';
271 271
 
@@ -276,37 +276,37 @@  discard block
 block discarded – undo
276 276
 
277 277
 						// Lastname
278 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) : '');
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 282
 						print "</a></td>\n";
283 283
 
284 284
 						// Login
285 285
 						print "<td>".$objp->login."</td>\n";
286 286
 
287 287
 						// Type
288
-						$membertypestatic->id=$objp->type_id;
289
-						$membertypestatic->libelle=$objp->type;
288
+						$membertypestatic->id = $objp->type_id;
289
+						$membertypestatic->libelle = $objp->type;
290 290
 						print '<td class="nowrap">';
291
-						print $membertypestatic->getNomUrl(1,32);
291
+						print $membertypestatic->getNomUrl(1, 32);
292 292
 						print '</td>';
293 293
 
294 294
 						// Moral/Physique
295 295
 						print "<td>".$memberstatic->getmorphylib($objp->morphy)."</td>\n";
296 296
 
297 297
 						// EMail
298
-						print "<td>".dol_print_email($objp->email,0,0,1)."</td>\n";
298
+						print "<td>".dol_print_email($objp->email, 0, 0, 1)."</td>\n";
299 299
 
300 300
 						// Statut
301 301
 						print '<td class="nowrap">';
302
-						print $memberstatic->LibStatut($objp->statut,$objp->subscription,$datefin,2);
302
+						print $memberstatic->LibStatut($objp->statut, $objp->subscription, $datefin, 2);
303 303
 						print "</td>";
304 304
 
305 305
 						// End of subscription date
306 306
 						if ($datefin)
307 307
 						{
308 308
 							print '<td align="center" class="nowrap">';
309
-							print dol_print_date($datefin,'day');
309
+							print dol_print_date($datefin, 'day');
310 310
 							if ($memberstatic->hasDelay()) {
311 311
 								print " ".img_warning($langs->trans("SubscriptionLate"));
312 312
 							}
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.
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.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -34,8 +34,8 @@  discard block
 block discarded – undo
34 34
 $langs->loadLangs(array("companies", "projects"));
35 35
 
36 36
 // Security check
37
-$socid = GETPOST('socid','int');
38
-if ($user->societe_id) $socid=$user->societe_id;
37
+$socid = GETPOST('socid', 'int');
38
+if ($user->societe_id) $socid = $user->societe_id;
39 39
 $result = restrictedArea($user, 'societe', $socid, '&societe');
40 40
 
41 41
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
  *	Actions
47 47
  */
48 48
 
49
-$parameters=array('id'=>$socid);
50
-$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
49
+$parameters = array('id'=>$socid);
50
+$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
51 51
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
52 52
 
53 53
 
@@ -71,25 +71,25 @@  discard block
 block discarded – undo
71 71
 	$object = new Societe($db);
72 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");
78
+	if (!empty($conf->notification->enabled)) $langs->load("mails");
79 79
 	$head = societe_prepare_head($object);
80 80
 
81 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
 
85
-    dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
85
+    dol_banner_tab($object, 'socid', $linkback, ($user->societe_id ? 0 : 1), 'rowid', 'nom');
86 86
 
87 87
     print '<div class="fichecenter">';
88 88
 
89 89
     print '<div class="underbanner clearboth"></div>';
90 90
 	print '<table class="border centpercent">';
91 91
 
92
-    if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
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
     }
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 
144 144
 
145 145
 	// Projects list
146
-	$result=show_projects($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id, 1, $addbutton);
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.
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.
Spacing   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -32,32 +32,32 @@  discard block
 block discarded – undo
32 32
 
33 33
 $langs->loadLangs(array("companies", "mails", "admin", "other"));
34 34
 
35
-$socid = GETPOST("socid",'int');
36
-$action = GETPOST('action','aZ09');
37
-$contactid=GETPOST('contactid');    // May be an int or 'thirdparty'
38
-$actionid=GETPOST('actionid');
35
+$socid = GETPOST("socid", 'int');
36
+$action = GETPOST('action', 'aZ09');
37
+$contactid = GETPOST('contactid'); // May be an int or 'thirdparty'
38
+$actionid = GETPOST('actionid');
39 39
 
40 40
 // Security check
41
-if ($user->societe_id) $socid=$user->societe_id;
42
-$result = restrictedArea($user, 'societe','','');
43
-
44
-$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
45
-$sortfield=GETPOST("sortfield",'alpha');
46
-$sortorder=GETPOST("sortorder",'alpha');
47
-$page=GETPOST("page",'int');
48
-if (! $sortorder) $sortorder="DESC";
49
-if (! $sortfield) $sortfield="n.daten";
41
+if ($user->societe_id) $socid = $user->societe_id;
42
+$result = restrictedArea($user, 'societe', '', '');
43
+
44
+$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
45
+$sortfield = GETPOST("sortfield", 'alpha');
46
+$sortorder = GETPOST("sortorder", 'alpha');
47
+$page = GETPOST("page", 'int');
48
+if (!$sortorder) $sortorder = "DESC";
49
+if (!$sortfield) $sortfield = "n.daten";
50 50
 if (empty($page) || $page == -1) { $page = 0; }
51 51
 $offset = $limit * $page;
52 52
 $pageprev = $page - 1;
53 53
 $pagenext = $page + 1;
54 54
 
55
-$now=dol_now();
55
+$now = dol_now();
56 56
 
57 57
 $object = new Societe($db);
58 58
 
59 59
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
60
-$hookmanager->initHooks(array('thirdpartynotification','globalcard'));
60
+$hookmanager->initHooks(array('thirdpartynotification', 'globalcard'));
61 61
 
62 62
 
63 63
 
@@ -65,29 +65,29 @@  discard block
 block discarded – undo
65 65
  * Actions
66 66
  */
67 67
 
68
-$parameters=array('id'=>$socid);
69
-$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
68
+$parameters = array('id'=>$socid);
69
+$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
70 70
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
71 71
 
72 72
 if (empty($reshook))
73 73
 {
74
-    $error=0;
74
+    $error = 0;
75 75
 
76 76
     // Add a notification
77 77
     if ($action == 'add')
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
 
90
-        if (! $error)
90
+        if (!$error)
91 91
         {
92 92
             $db->begin();
93 93
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
                 $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify_def (datec,fk_soc, fk_contact, fk_action)";
99 99
                 $sql .= " VALUES ('".$db->idate($now)."',".$socid.",".$contactid.",".$actionid.")";
100 100
 
101
-                if (! $db->query($sql))
101
+                if (!$db->query($sql))
102 102
                 {
103 103
                     $error++;
104 104
                     dol_print_error($db);
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
                 dol_print_error($db);
110 110
             }
111 111
 
112
-            if (! $error)
112
+            if (!$error)
113 113
             {
114 114
                 $db->commit();
115 115
             }
@@ -137,12 +137,12 @@  discard block
 block discarded – undo
137 137
 $form = new Form($db);
138 138
 
139 139
 $object = new Societe($db);
140
-$result=$object->fetch($socid);
140
+$result = $object->fetch($socid);
141 141
 
142
-$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");
144
-$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
145
-llxHeader('',$title,$help_url);
142
+$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");
144
+$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
145
+llxHeader('', $title, $help_url);
146 146
 
147 147
 
148 148
 if ($result > 0)
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 
156 156
     $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
157 157
 
158
-    dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
158
+    dol_banner_tab($object, 'socid', $linkback, ($user->societe_id ? 0 : 1), 'rowid', 'nom');
159 159
 
160 160
     print '<div class="fichecenter">';
161 161
 
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
     print '<table class="border centpercent">';
164 164
 
165 165
     // Prefix
166
-    if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
166
+    if (!empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
167 167
     {
168 168
         print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
169 169
     }
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
         print '</td></tr>';
178 178
     }
179 179
 
180
-    if (! empty($conf->fournisseur->enabled) && $object->fournisseur && ! empty($user->rights->fournisseur->lire))
180
+    if (!empty($conf->fournisseur->enabled) && $object->fournisseur && !empty($user->rights->fournisseur->lire))
181 181
     {
182 182
         print '<tr><td class="titlefield">';
183 183
         print $langs->trans('SupplierCode').'</td><td colspan="3">';
@@ -218,37 +218,37 @@  discard block
 block discarded – undo
218 218
 
219 219
 
220 220
     // Add notification form
221
-    print load_fiche_titre($langs->trans("AddNewNotification"),'','');
221
+    print load_fiche_titre($langs->trans("AddNewNotification"), '', '');
222 222
 
223 223
     print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$socid.'" method="post">';
224 224
     print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
225 225
     print '<input type="hidden" name="action" value="add">';
226 226
 
227
-    $param="&socid=".$socid;
227
+    $param = "&socid=".$socid;
228 228
 
229 229
     // Line with titles
230 230
     print '<table width="100%" class="noborder">';
231 231
     print '<tr class="liste_titre">';
232
-    print_liste_field_titre("Target",$_SERVER["PHP_SELF"],"c.lastname,c.firstname",'',$param,'"width="45%"',$sortfield,$sortorder);
233
-    print_liste_field_titre("Action",$_SERVER["PHP_SELF"],"",'',$param,'"width="35%"',$sortfield,$sortorder);
234
-    print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"n.type",'',$param,'"width="10%"',$sortfield,$sortorder);
232
+    print_liste_field_titre("Target", $_SERVER["PHP_SELF"], "c.lastname,c.firstname", '', $param, '"width="45%"', $sortfield, $sortorder);
233
+    print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "", '', $param, '"width="35%"', $sortfield, $sortorder);
234
+    print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "n.type", '', $param, '"width="10%"', $sortfield, $sortorder);
235 235
     print_liste_field_titre('');
236 236
 	print "</tr>\n";
237 237
 
238
-    $var=false;
239
-    $listofemails=$object->thirdparty_and_contact_email_array();
238
+    $var = false;
239
+    $listofemails = $object->thirdparty_and_contact_email_array();
240 240
     if (count($listofemails) > 0)
241 241
     {
242
-        $actions=array();
242
+        $actions = array();
243 243
 
244 244
         // Load array of available notifications
245
-        $notificationtrigger=new InterfaceNotification($db);
246
-        $listofmanagedeventfornotification=$notificationtrigger->getListOfManagedEvents();
245
+        $notificationtrigger = new InterfaceNotification($db);
246
+        $listofmanagedeventfornotification = $notificationtrigger->getListOfManagedEvents();
247 247
 
248
-        foreach($listofmanagedeventfornotification as $managedeventfornotification)
248
+        foreach ($listofmanagedeventfornotification as $managedeventfornotification)
249 249
         {
250
- 			$label=($langs->trans("Notify_".$managedeventfornotification['code'])!="Notify_".$managedeventfornotification['code']?$langs->trans("Notify_".$managedeventfornotification['code']):$managedeventfornotification['label']);
251
-            $actions[$managedeventfornotification['rowid']]=$label;
250
+ 			$label = ($langs->trans("Notify_".$managedeventfornotification['code']) != "Notify_".$managedeventfornotification['code'] ? $langs->trans("Notify_".$managedeventfornotification['code']) : $managedeventfornotification['label']);
251
+            $actions[$managedeventfornotification['rowid']] = $label;
252 252
         }
253 253
         print '<tr class="oddeven"><td class="maxwidthonsmartphone">';
254 254
         print $form->selectarray("contactid", $listofemails, '', 0, 0, 0, '', 0, 0, 0, '', 'maxwidthonsmartphone');
@@ -257,8 +257,8 @@  discard block
 block discarded – undo
257 257
         print $form->selectarray("actionid", $actions, '', 1, 0, 0, '', 0, 0, 0, '', 'maxwidthonsmartphone');
258 258
         print '</td>';
259 259
         print '<td>';
260
-        $type=array('email'=>$langs->trans("EMail"));
261
-        print $form->selectarray("typeid",$type);
260
+        $type = array('email'=>$langs->trans("EMail"));
261
+        print $form->selectarray("typeid", $type);
262 262
         print '</td>';
263 263
         print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
264 264
         print '</tr>';
@@ -279,16 +279,16 @@  discard block
 block discarded – undo
279 279
 
280 280
     // List of notifications enabled for contacts
281 281
     $sql = "SELECT n.rowid, n.type,";
282
-    $sql.= " a.code, a.label,";
283
-    $sql.= " c.rowid as contactid, c.lastname, c.firstname, c.email";
284
-    $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,";
285
-    $sql.= " ".MAIN_DB_PREFIX."notify_def as n,";
286
-    $sql.= " ".MAIN_DB_PREFIX."socpeople c";
287
-    $sql.= " WHERE a.rowid = n.fk_action";
288
-    $sql.= " AND c.rowid = n.fk_contact";
289
-    $sql.= " AND c.fk_soc = ".$object->id;
290
-
291
-    $resql=$db->query($sql);
282
+    $sql .= " a.code, a.label,";
283
+    $sql .= " c.rowid as contactid, c.lastname, c.firstname, c.email";
284
+    $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,";
285
+    $sql .= " ".MAIN_DB_PREFIX."notify_def as n,";
286
+    $sql .= " ".MAIN_DB_PREFIX."socpeople c";
287
+    $sql .= " WHERE a.rowid = n.fk_action";
288
+    $sql .= " AND c.rowid = n.fk_contact";
289
+    $sql .= " AND c.fk_soc = ".$object->id;
290
+
291
+    $resql = $db->query($sql);
292 292
     if ($resql)
293 293
     {
294 294
         $num = $db->num_rows($resql);
@@ -299,15 +299,15 @@  discard block
 block discarded – undo
299 299
     }
300 300
 
301 301
     // List of active notifications
302
-    print load_fiche_titre($langs->trans("ListOfActiveNotifications").' ('.$num.')','','');
302
+    print load_fiche_titre($langs->trans("ListOfActiveNotifications").' ('.$num.')', '', '');
303 303
 
304 304
     // Line with titles
305 305
     print '<table width="100%" class="noborder">';
306 306
     print '<tr class="liste_titre">';
307
-    print_liste_field_titre("Target",$_SERVER["PHP_SELF"],"c.lastname,c.firstname",'',$param,'"width="45%"',$sortfield,$sortorder);
308
-    print_liste_field_titre("Action",$_SERVER["PHP_SELF"],"",'',$param,'"width="35%"',$sortfield,$sortorder);
309
-    print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"n.type",'',$param,'"width="10%"',$sortfield,$sortorder);
310
-    print_liste_field_titre('','','');
307
+    print_liste_field_titre("Target", $_SERVER["PHP_SELF"], "c.lastname,c.firstname", '', $param, '"width="45%"', $sortfield, $sortorder);
308
+    print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "", '', $param, '"width="35%"', $sortfield, $sortorder);
309
+    print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "n.type", '', $param, '"width="10%"', $sortfield, $sortorder);
310
+    print_liste_field_titre('', '', '');
311 311
     print '</tr>';
312 312
 
313 313
 	$langs->load("errors");
@@ -317,15 +317,15 @@  discard block
 block discarded – undo
317 317
     {
318 318
         $i = 0;
319 319
 
320
-        $contactstatic=new Contact($db);
320
+        $contactstatic = new Contact($db);
321 321
 
322 322
         while ($i < $num)
323 323
         {
324 324
             $obj = $db->fetch_object($resql);
325 325
 
326
-            $contactstatic->id=$obj->contactid;
327
-            $contactstatic->lastname=$obj->lastname;
328
-            $contactstatic->firstname=$obj->firstname;
326
+            $contactstatic->id = $obj->contactid;
327
+            $contactstatic->lastname = $obj->lastname;
328
+            $contactstatic->firstname = $obj->firstname;
329 329
             print '<tr class="oddeven"><td>'.$contactstatic->getNomUrl(1);
330 330
             if ($obj->type == 'email')
331 331
             {
@@ -336,12 +336,12 @@  discard block
 block discarded – undo
336 336
                 else
337 337
                 {
338 338
                     $langs->load("errors");
339
-                    print ' &nbsp; '.img_warning().' '.$langs->trans("ErrorBadEMail",$obj->email);
339
+                    print ' &nbsp; '.img_warning().' '.$langs->trans("ErrorBadEMail", $obj->email);
340 340
                 }
341 341
             }
342 342
             print '</td>';
343 343
             print '<td>';
344
-            $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
344
+            $label = ($langs->trans("Notify_".$obj->code) != "Notify_".$obj->code ? $langs->trans("Notify_".$obj->code) : $obj->label);
345 345
             print $label;
346 346
             print '</td>';
347 347
             print '<td>';
@@ -414,14 +414,14 @@  discard block
 block discarded – undo
414 414
 
415 415
     // List
416 416
     $sql = "SELECT n.rowid, n.daten, n.email, n.objet_type as object_type, n.objet_id as object_id, n.type,";
417
-    $sql.= " c.rowid as id, c.lastname, c.firstname, c.email as contactemail,";
418
-    $sql.= " a.code, a.label";
419
-    $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,";
420
-    $sql.= " ".MAIN_DB_PREFIX."notify as n ";
421
-    $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as c ON n.fk_contact = c.rowid";
422
-    $sql.= " WHERE a.rowid = n.fk_action";
423
-    $sql.= " AND n.fk_soc = ".$object->id;
424
-    $sql.= $db->order($sortfield, $sortorder);
417
+    $sql .= " c.rowid as id, c.lastname, c.firstname, c.email as contactemail,";
418
+    $sql .= " a.code, a.label";
419
+    $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,";
420
+    $sql .= " ".MAIN_DB_PREFIX."notify as n ";
421
+    $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as c ON n.fk_contact = c.rowid";
422
+    $sql .= " WHERE a.rowid = n.fk_action";
423
+    $sql .= " AND n.fk_soc = ".$object->id;
424
+    $sql .= $db->order($sortfield, $sortorder);
425 425
 
426 426
     // Count total nb of records
427 427
     $nbtotalofrecords = '';
@@ -436,9 +436,9 @@  discard block
 block discarded – undo
436 436
         }
437 437
     }
438 438
 
439
-    $sql.= $db->plimit($limit+1, $offset);
439
+    $sql .= $db->plimit($limit + 1, $offset);
440 440
 
441
-    $resql=$db->query($sql);
441
+    $resql = $db->query($sql);
442 442
     if ($resql)
443 443
     {
444 444
         $num = $db->num_rows($resql);
@@ -448,9 +448,9 @@  discard block
 block discarded – undo
448 448
         dol_print_error($db);
449 449
     }
450 450
 
451
-    $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;
451
+    $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;
454 454
 
455 455
     print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
456 456
     if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
@@ -467,18 +467,18 @@  discard block
 block discarded – undo
467 467
     // Line with titles
468 468
     print '<table width="100%" class="noborder">';
469 469
     print '<tr class="liste_titre">';
470
-    print_liste_field_titre("Target",$_SERVER["PHP_SELF"],"c.lastname,c.firstname",'',$param,'',$sortfield,$sortorder);
471
-    print_liste_field_titre("Action",$_SERVER["PHP_SELF"],"",'',$param,'',$sortfield,$sortorder);
472
-    print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"n.type",'',$param,'',$sortfield,$sortorder);
470
+    print_liste_field_titre("Target", $_SERVER["PHP_SELF"], "c.lastname,c.firstname", '', $param, '', $sortfield, $sortorder);
471
+    print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder);
472
+    print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "n.type", '', $param, '', $sortfield, $sortorder);
473 473
     //print_liste_field_titre("Object",$_SERVER["PHP_SELF"],"",'',$param,'"',$sortfield,$sortorder);
474
-    print_liste_field_titre("Date",$_SERVER["PHP_SELF"],"n.daten",'',$param,'align="right"',$sortfield,$sortorder);
474
+    print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "n.daten", '', $param, 'align="right"', $sortfield, $sortorder);
475 475
     print '</tr>';
476 476
 
477 477
     if ($num > 0)
478 478
     {
479 479
         $i = 0;
480 480
 
481
-        $contactstatic=new Contact($db);
481
+        $contactstatic = new Contact($db);
482 482
 
483 483
         while ($i < $num)
484 484
         {
@@ -487,11 +487,11 @@  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;
490
+	            $contactstatic->id = $obj->id;
491
+	            $contactstatic->lastname = $obj->lastname;
492
+	            $contactstatic->firstname = $obj->firstname;
493 493
 	            print $contactstatic->getNomUrl(1);
494
-	            print $obj->email?' &lt;'.$obj->email.'&gt;':$langs->trans("NoMail");
494
+	            print $obj->email ? ' &lt;'.$obj->email.'&gt;' : $langs->trans("NoMail");
495 495
             }
496 496
             else
497 497
 			{
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
             }
500 500
             print '</td>';
501 501
             print '<td>';
502
-            $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
502
+            $label = ($langs->trans("Notify_".$obj->code) != "Notify_".$obj->code ? $langs->trans("Notify_".$obj->code) : $obj->label);
503 503
             print $label;
504 504
             print '</td>';
505 505
             print '<td>';
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
 
528 528
     print '</form>';
529 529
 }
530
-else dol_print_error('','RecordNotFound');
530
+else dol_print_error('', 'RecordNotFound');
531 531
 
532 532
 // End of page
533 533
 llxFooter();
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.
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.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -34,16 +34,16 @@  discard block
 block discarded – undo
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
-if ($page == -1 || $page == null) { $page = 0 ; }
44
+if ($page == -1 || $page == null) { $page = 0; }
45 45
 
46
-$offset = $conf->liste_limit * $page ;
46
+$offset = $conf->liste_limit * $page;
47 47
 $pageprev = $page - 1;
48 48
 $pagenext = $page + 1;
49 49
 
@@ -56,18 +56,18 @@  discard block
 block discarded – undo
56 56
 llxHeader();
57 57
 
58 58
 $sql = "SELECT s.nom as name, s.rowid as socid, c.lastname, c.firstname, a.label, n.rowid";
59
-$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c,";
60
-$sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
61
-$sql.= " ".MAIN_DB_PREFIX."notify_def as n,";
62
-$sql.= " ".MAIN_DB_PREFIX."societe as s";
63
-$sql.= " WHERE n.fk_contact = c.rowid";
64
-$sql.= " AND a.rowid = n.fk_action";
65
-$sql.= " AND n.fk_soc = s.rowid";
66
-$sql.= " AND s.entity IN (".getEntity('societe').")";
67
-if ($socid > 0)	$sql.= " AND s.rowid = " . $user->societe_id;
68
-
69
-$sql.= $db->order($sortfield,$sortorder);
70
-$sql.= $db->plimit($conf->liste_limit, $offset);
59
+$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c,";
60
+$sql .= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
61
+$sql .= " ".MAIN_DB_PREFIX."notify_def as n,";
62
+$sql .= " ".MAIN_DB_PREFIX."societe as s";
63
+$sql .= " WHERE n.fk_contact = c.rowid";
64
+$sql .= " AND a.rowid = n.fk_action";
65
+$sql .= " AND n.fk_soc = s.rowid";
66
+$sql .= " AND s.entity IN (".getEntity('societe').")";
67
+if ($socid > 0)	$sql .= " AND s.rowid = ".$user->societe_id;
68
+
69
+$sql .= $db->order($sortfield, $sortorder);
70
+$sql .= $db->plimit($conf->liste_limit, $offset);
71 71
 
72 72
 $result = $db->query($sql);
73 73
 if ($result)
@@ -75,14 +75,14 @@  discard block
 block discarded – undo
75 75
 	$num = $db->num_rows($result);
76 76
 	$i = 0;
77 77
 
78
-	$paramlist='';
79
-	print_barre_liste($langs->trans("ListOfNotificationsDone"), $page, $_SERVER["PHP_SELF"], $paramlist, $sortfield,$sortorder,'',$num);
78
+	$paramlist = '';
79
+	print_barre_liste($langs->trans("ListOfNotificationsDone"), $page, $_SERVER["PHP_SELF"], $paramlist, $sortfield, $sortorder, '', $num);
80 80
 
81 81
 	print '<table class="noborder" width="100%">';
82 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);
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 86
 	print "</tr>\n";
87 87
 
88 88
 	while ($i < $num)
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.