Passed
Push — master ( 284492...2c3033 )
by Alxarafe
27:10
created
dolibarr/htdocs/core/class/commonobject.class.php 1 patch
Indentation   +6971 added lines, -6971 removed lines patch added patch discarded remove patch
@@ -169,7258 +169,7258 @@
 block discarded – undo
169 169
     public $user;
170 170
 
171 171
     /**
172
-	 * @var int 	The id of originating object
173
-	 * @see fetch_origin()
174
-	 */
175
-	public $origin_id;
176
-
177
-	/**
178
-	 * @var string The object's reference
179
-	 */
180
-	public $ref;
181
-
182
-	/**
183
-	 * @var string The object's previous reference
184
-	 */
185
-	public $ref_previous;
186
-
187
-	/**
188
-	 * @var string The object's next reference
189
-	 */
190
-	public $ref_next;
191
-
192
-	/**
193
-	 * @var string An external reference for the object
194
-	 */
195
-	public $ref_ext;
196
-
197
-	/**
198
-	 * @var int The object's status
199
-	 * @see setStatut()
200
-	 */
201
-	public $statut;
202
-
203
-	/**
204
-	 * @var string
205
-	 * @see getFullAddress()
206
-	 */
207
-	public $country;
208
-
209
-	/**
210
-	 * @var int
211
-	 * @see getFullAddress(), country
212
-	 */
213
-	public $country_id;
214
-
215
-	/**
216
-	 * @var string
217
-	 * @see getFullAddress(), isInEEC(), country
218
-	 */
219
-    public $country_code;
172
+     * @var int 	The id of originating object
173
+     * @see fetch_origin()
174
+     */
175
+    public $origin_id;
220 176
 
221 177
     /**
222
-	 * @var string
223
-	 * @see getFullAddress()
224
-	 */
225
-	public $state;
178
+     * @var string The object's reference
179
+     */
180
+    public $ref;
226 181
 
227
-	/**
228
-	 * @var int
229
-	 * @see getFullAddress(), state
230
-	 */
231
-	public $state_id;
182
+    /**
183
+     * @var string The object's previous reference
184
+     */
185
+    public $ref_previous;
232 186
 
233
-	/**
234
-	 * @var string
235
-	 * @see getFullAddress(), state
236
-	 */
237
-    public $state_code;
187
+    /**
188
+     * @var string The object's next reference
189
+     */
190
+    public $ref_next;
238 191
 
239 192
     /**
240
-	 * @var string
241
-	 * @see getFullAddress(), region
242
-	 */
243
-	public $region;
193
+     * @var string An external reference for the object
194
+     */
195
+    public $ref_ext;
244 196
 
245
-	/**
246
-	 * @var string
247
-	 * @see getFullAddress(), region
248
-	 */
249
-    public $region_code;
197
+    /**
198
+     * @var int The object's status
199
+     * @see setStatut()
200
+     */
201
+    public $statut;
250 202
 
251
-	/**
252
-	 * @var int
253
-	 * @see fetch_barcode()
254
-	 */
255
-	public $barcode_type;
256
-
257
-	/**
258
-	 * @var string
259
-	 * @see fetch_barcode(), barcode_type
260
-	 */
261
-	public $barcode_type_code;
262
-
263
-	/**
264
-	 * @var string
265
-	 * @see fetch_barcode(), barcode_type
266
-	 */
267
-	public $barcode_type_label;
268
-
269
-	/**
270
-	 * @var string
271
-	 * @see fetch_barcode(), barcode_type
272
-	 */
273
-	public $barcode_type_coder;
274
-
275
-	/**
276
-	 * @var int Payment method ID (cheque, cash, ...)
277
-	 * @see setPaymentMethods()
278
-	 */
279
-	public $mode_reglement_id;
280
-
281
-	/**
282
-	 * @var int Payment terms ID
283
-	 * @see setPaymentTerms()
284
-	 */
285
-	public $cond_reglement_id;
286
-
287
-	/**
288
-	 * @var int Payment terms ID
289
-	 * @deprecated Kept for compatibility
290
-	 * @see cond_reglement_id;
291
-	 */
292
-	public $cond_reglement;
293
-
294
-	/**
295
-	 * @var int Delivery address ID
296
-	 * @deprecated
297
-	 * @see setDeliveryAddress()
298
-	 */
299
-	public $fk_delivery_address;
300
-
301
-	/**
302
-	 * @var int Shipping method ID
303
-	 * @see setShippingMethod()
304
-	 */
305
-	public $shipping_method_id;
306
-
307
-	/**
308
-	 * @var string
309
-	 * @see SetDocModel()
310
-	 */
311
-	public $modelpdf;
312
-
313
-	/**
314
-	 * @var int Bank account ID
315
-	 * @see SetBankAccount()
316
-	 */
317
-	public $fk_account;
318
-
319
-	/**
320
-	 * @var string Public note
321
-	 * @see update_note()
322
-	 */
323
-	public $note_public;
324
-
325
-	/**
326
-	 * @var string Private note
327
-	 * @see update_note()
328
-	 */
329
-	public $note_private;
330
-
331
-	/**
332
-	 * @deprecated
333
-	 * @see note_public
334
-	 */
335
-	public $note;
336
-
337
-	/**
338
-	 * @var float Total amount before taxes
339
-	 * @see update_price()
340
-	 */
341
-	public $total_ht;
342
-
343
-	/**
344
-	 * @var float Total VAT amount
345
-	 * @see update_price()
346
-	 */
347
-	public $total_tva;
348
-
349
-	/**
350
-	 * @var float Total local tax 1 amount
351
-	 * @see update_price()
352
-	 */
353
-	public $total_localtax1;
354
-
355
-	/**
356
-	 * @var float Total local tax 2 amount
357
-	 * @see update_price()
358
-	 */
359
-	public $total_localtax2;
360
-
361
-	/**
362
-	 * @var float Total amount with taxes
363
-	 * @see update_price()
364
-	 */
365
-	public $total_ttc;
366
-
367
-	/**
368
-	 * @var CommonObjectLine[]
369
-	 */
370
-	public $lines;
371
-
372
-	/**
373
-	 * @var mixed		Contains comments
374
-	 * @see fetchComments()
375
-	 */
376
-	public $comments=array();
377
-
378
-	/**
379
-	 * @var int
380
-	 * @see setIncoterms()
381
-	 */
382
-	public $fk_incoterms;
383
-
384
-	/**
385
-	 * @var string
386
-	 * @see SetIncoterms()
387
-	 */
388
-	public $libelle_incoterms;
389
-
390
-	/**
391
-	 * @var string
392
-	 * @see display_incoterms()
393
-	 */
394
-	public $location_incoterms;
395
-
396
-	public $name;
397
-	public $lastname;
398
-	public $firstname;
399
-	public $civility_id;
400
-
401
-	// Dates
402
-	public $date_creation;			// Date creation
403
-	public $date_validation;		// Date validation
404
-	public $date_modification;		// Date last change (tms field)
405
-
406
-
407
-
408
-	// No constructor as it is an abstract class
409
-
410
-	/**
411
-	 * Check an object id/ref exists
412
-	 * If you don't need/want to instantiate object and just need to know if object exists, use this method instead of fetch
413
-	 *
414
-	 *  @param	string	$element   	String of element ('product', 'facture', ...)
415
-	 *  @param	int		$id      	Id of object
416
-	 *  @param  string	$ref     	Ref of object to check
417
-	 *  @param	string	$ref_ext	Ref ext of object to check
418
-	 *  @return int     			<0 if KO, 0 if OK but not found, >0 if OK and exists
419
-	 */
420
-	static function isExistingObject($element, $id, $ref='', $ref_ext='')
421
-	{
422
-		global $db,$conf;
423
-
424
-		$sql = "SELECT rowid, ref, ref_ext";
425
-		$sql.= " FROM ".MAIN_DB_PREFIX.$element;
426
-		$sql.= " WHERE entity IN (".getEntity($element).")" ;
427
-
428
-		if ($id > 0) $sql.= " AND rowid = ".$db->escape($id);
429
-		else if ($ref) $sql.= " AND ref = '".$db->escape($ref)."'";
430
-		else if ($ref_ext) $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'";
431
-		else {
432
-			$error='ErrorWrongParameters';
433
-			dol_print_error(get_class()."::isExistingObject ".$error, LOG_ERR);
434
-			return -1;
435
-		}
436
-		if ($ref || $ref_ext) $sql.= " AND entity = ".$conf->entity;
437
-
438
-		dol_syslog(get_class()."::isExistingObject", LOG_DEBUG);
439
-		$resql = $db->query($sql);
440
-		if ($resql)
441
-		{
442
-			$num=$db->num_rows($resql);
443
-			if ($num > 0) return 1;
444
-			else return 0;
445
-		}
446
-		return -1;
447
-	}
448
-
449
-	/**
450
-	 * Method to output saved errors
451
-	 *
452
-	 * @return	string		String with errors
453
-	 */
454
-	function errorsToString()
455
-	{
456
-		return $this->error.(is_array($this->errors)?(($this->error!=''?', ':'').join(', ',$this->errors)):'');
457
-	}
458
-
459
-	/**
460
-	 *	Return full name (civility+' '+name+' '+lastname)
461
-	 *
462
-	 *	@param	Translate	$langs			Language object for translation of civility (used only if option is 1)
463
-	 *	@param	int			$option			0=No option, 1=Add civility
464
-	 * 	@param	int			$nameorder		-1=Auto, 0=Lastname+Firstname, 1=Firstname+Lastname, 2=Firstname
465
-	 * 	@param	int			$maxlen			Maximum length
466
-	 * 	@return	string						String with full name
467
-	 */
468
-	function getFullName($langs,$option=0,$nameorder=-1,$maxlen=0)
469
-	{
470
-		//print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n";
471
-		$lastname=$this->lastname;
472
-		$firstname=$this->firstname;
473
-		if (empty($lastname))  $lastname=(isset($this->lastname)?$this->lastname:(isset($this->name)?$this->name:(isset($this->nom)?$this->nom:(isset($this->societe)?$this->societe:(isset($this->company)?$this->company:'')))));
474
-
475
-		$ret='';
476
-		if ($option && $this->civility_id)
477
-		{
478
-			if ($langs->transnoentitiesnoconv("Civility".$this->civility_id)!="Civility".$this->civility_id) $ret.=$langs->transnoentitiesnoconv("Civility".$this->civility_id).' ';
479
-			else $ret.=$this->civility_id.' ';
480
-		}
481
-
482
-		$ret.=dolGetFirstLastname($firstname, $lastname, $nameorder);
483
-
484
-		return dol_trunc($ret,$maxlen);
485
-	}
486
-
487
-	/**
488
-	 * 	Return full address of contact
489
-	 *
490
-	 * 	@param		int			$withcountry		1=Add country into address string
491
-	 *  @param		string		$sep				Separator to use to build string
492
-	 *  @param		int		    $withregion			1=Add region into address string
493
-	 *	@return		string							Full address string
494
-	 */
495
-	function getFullAddress($withcountry=0, $sep="\n", $withregion=0)
496
-	{
497
-		if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country)))
498
-		{
499
-			require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php';
500
-			$tmparray=getCountry($this->country_id,'all');
501
-			$this->country_code=$tmparray['code'];
502
-			$this->country     =$tmparray['label'];
503
-		}
203
+    /**
204
+     * @var string
205
+     * @see getFullAddress()
206
+     */
207
+    public $country;
504 208
 
505
-        if ($withregion && $this->state_id && (empty($this->state_code) || empty($this->state) || empty($this->region) || empty($this->region_cpde)))
506
-    	{
507
-    		require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php';
508
-    		$tmparray=getState($this->state_id,'all',0,1);
509
-			$this->state_code   =$tmparray['code'];
510
-			$this->state        =$tmparray['label'];
511
-			$this->region_code  =$tmparray['region_code'];
512
-			$this->region       =$tmparray['region'];
513
-        }
514
-
515
-		return dol_format_address($this, $withcountry, $sep);
516
-	}
517
-
518
-
519
-	/**
520
-	 * 	Return full address for banner
521
-	 *
522
-	 * 	@param		string		$htmlkey            HTML id to make banner content unique
523
-	 *  @param      Object      $object				Object (thirdparty, thirdparty of contact for contact, null for a member)
524
-	 *	@return		string							Full address string
525
-	 */
526
-	function getBannerAddress($htmlkey, $object)
527
-	{
528
-		global $conf, $langs;
529
-
530
-		$countriesusingstate=array('AU','US','IN','GB','ES','UK','TR');    // See also option MAIN_FORCE_STATE_INTO_ADDRESS
531
-
532
-		$contactid=0;
533
-		$thirdpartyid=0;
534
-		if ($this->element == 'societe')
535
-		{
536
-			$thirdpartyid=$this->id;
537
-		}
538
-		if ($this->element == 'contact')
539
-		{
540
-			$contactid=$this->id;
541
-			$thirdpartyid=$object->fk_soc;
542
-		}
543
-		if ($this->element == 'user')
544
-		{
545
-			$contactid=$this->contact_id;
546
-			$thirdpartyid=$object->fk_soc;
547
-		}
548
-
549
-		$out='<!-- BEGIN part to show address block -->';
550
-
551
-		$outdone=0;
552
-		$coords = $this->getFullAddress(1,', ',$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT);
553
-		if ($coords)
554
-		{
555
-			if (! empty($conf->use_javascript_ajax))
556
-			{
557
-				$namecoords = $this->getFullName($langs,1).'<br>'.$coords;
558
-				// hideonsmatphone because copyToClipboard call jquery dialog that does not work with jmobile
559
-				$out.='<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($namecoords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">';
560
-				$out.=img_picto($langs->trans("Address"), 'object_address.png');
561
-				$out.='</a> ';
562
-			}
563
-			$out.=dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', '); $outdone++;
564
-			$outdone++;
565
-		}
566
-
567
-		if (! in_array($this->country_code,$countriesusingstate) && empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS)   // If MAIN_FORCE_STATE_INTO_ADDRESS is on, state is already returned previously with getFullAddress
568
-				&& empty($conf->global->SOCIETE_DISABLE_STATE) && $this->state)
569
-		{
570
-            if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 && $this->region) {
571
-                $out.=($outdone?' - ':'').$this->region.' - '.$this->state;
572
-            }
573
-            else {
574
-                $out.=($outdone?' - ':'').$this->state;
575
-            }
576
-			$outdone++;
577
-		}
578
-
579
-		if (! empty($this->phone) || ! empty($this->phone_pro) || ! empty($this->phone_mobile) || ! empty($this->phone_perso) || ! empty($this->fax) || ! empty($this->office_phone) || ! empty($this->user_mobile) || ! empty($this->office_fax)) $out.=($outdone?'<br>':'');
580
-		if (! empty($this->phone) && empty($this->phone_pro)) {		// For objects that store pro phone into ->phone
581
-			$out.=dol_print_phone($this->phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL','&nbsp;','phone',$langs->trans("PhonePro")); $outdone++;
582
-		}
583
-		if (! empty($this->phone_pro)) {
584
-			$out.=dol_print_phone($this->phone_pro,$this->country_code,$contactid,$thirdpartyid,'AC_TEL','&nbsp;','phone',$langs->trans("PhonePro")); $outdone++;
585
-		}
586
-		if (! empty($this->phone_mobile)) {
587
-			$out.=dol_print_phone($this->phone_mobile,$this->country_code,$contactid,$thirdpartyid,'AC_TEL','&nbsp;','mobile',$langs->trans("PhoneMobile")); $outdone++;
588
-		}
589
-		if (! empty($this->phone_perso)) {
590
-			$out.=dol_print_phone($this->phone_perso,$this->country_code,$contactid,$thirdpartyid,'AC_TEL','&nbsp;','phone',$langs->trans("PhonePerso")); $outdone++;
591
-		}
592
-		if (! empty($this->office_phone)) {
593
-			$out.=dol_print_phone($this->office_phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL','&nbsp;','phone',$langs->trans("PhonePro")); $outdone++;
594
-		}
595
-		if (! empty($this->user_mobile)) {
596
-			$out.=dol_print_phone($this->user_mobile,$this->country_code,$contactid,$thirdpartyid,'AC_TEL','&nbsp;','mobile',$langs->trans("PhoneMobile")); $outdone++;
597
-		}
598
-		if (! empty($this->fax)) {
599
-			$out.=dol_print_phone($this->fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX','&nbsp;','fax',$langs->trans("Fax")); $outdone++;
600
-		}
601
-		if (! empty($this->office_fax)) {
602
-			$out.=dol_print_phone($this->office_fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX','&nbsp;','fax',$langs->trans("Fax")); $outdone++;
603
-		}
604
-
605
-		$out.='<div style="clear: both;"></div>';
606
-		$outdone=0;
607
-		if (! empty($this->email))
608
-		{
609
-			$out.=dol_print_email($this->email,$this->id,$object->id,'AC_EMAIL',0,0,1);
610
-			$outdone++;
611
-		}
612
-		if (! empty($this->url))
613
-		{
614
-			$out.=dol_print_url($this->url,'_goout',0,1);
615
-			$outdone++;
616
-		}
617
-		$out.='<div style="clear: both;">';
618
-		if (! empty($conf->socialnetworks->enabled))
619
-		{
620
-			if ($this->skype) $out.=dol_print_socialnetworks($this->skype,$this->id,$object->id,'skype');
621
-			$outdone++;
622
-			if ($this->jabberid) $out.=dol_print_socialnetworks($this->jabberid,$this->id,$object->id,'jabber');
623
-			$outdone++;
624
-			if ($this->twitter) $out.=dol_print_socialnetworks($this->twitter,$this->id,$object->id,'twitter');
625
-			$outdone++;
626
-			if ($this->facebook) $out.=dol_print_socialnetworks($this->facebook,$this->id,$object->id,'facebook');
627
-			$outdone++;
628
-		}
629
-		$out.='</div>';
630
-
631
-		$out.='<!-- END Part to show address block -->';
632
-
633
-		return $out;
634
-	}
635
-
636
-	/**
637
-	 * Return the link of last main doc file for direct public download.
638
-	 *
639
-	 * @param	string	$modulepart			Module related to document
640
-	 * @param	int		$initsharekey		Init the share key if it was not yet defined
641
-	 * @param	int		$relativelink		0=Return full external link, 1=Return link relative to root of file
642
-	 * @return	string						Link or empty string if there is no download link
643
-	 */
644
-	function getLastMainDocLink($modulepart, $initsharekey=0, $relativelink=0)
645
-	{
646
-		global $user, $dolibarr_main_url_root;
647
-
648
-		if (empty($this->last_main_doc))
649
-		{
650
-			return '';		// No way to known which document name to use
651
-		}
652
-
653
-		include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
654
-		$ecmfile=new EcmFiles($this->db);
655
-		$result = $ecmfile->fetch(0, '', $this->last_main_doc);
656
-		if ($result < 0)
657
-		{
658
-			$this->error = $ecmfile->error;
659
-			$this->errors = $ecmfile->errors;
660
-			return -1;
661
-		}
662
-
663
-		if (empty($ecmfile->id))
664
-		{
665
-			// Add entry into index
666
-			if ($initsharekey)
667
-			{
668
-				require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
669
-				// TODO We can't, we dont' have full path of file, only last_main_doc adn ->element, so we must rebuild full path first
670
-				/*
671
-				$ecmfile->filepath = $rel_dir;
672
-				$ecmfile->filename = $filename;
673
-				$ecmfile->label = md5_file(dol_osencode($destfull));	// hash of file content
674
-				$ecmfile->fullpath_orig = '';
675
-				$ecmfile->gen_or_uploaded = 'generated';
676
-				$ecmfile->description = '';    // indexed content
677
-				$ecmfile->keyword = '';        // keyword content
678
-				$ecmfile->share = getRandomPassword(true);
679
-				$result = $ecmfile->create($user);
680
-				if ($result < 0)
681
-				{
682
-					$this->error = $ecmfile->error;
683
-					$this->errors = $ecmfile->errors;
684
-				}
685
-				*/
686
-			}
687
-			else return '';
688
-		}
689
-		elseif (empty($ecmfile->share))
690
-		{
691
-			// Add entry into index
692
-			if ($initsharekey)
693
-			{
694
-				require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
695
-				$ecmfile->share = getRandomPassword(true);
696
-				$ecmfile->update($user);
697
-			}
698
-			else return '';
699
-		}
700
-
701
-		// Define $urlwithroot
702
-		$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
703
-		$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
704
-		//$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
705
-
706
-		$forcedownload=0;
707
-
708
-		$paramlink='';
709
-		//if (! empty($modulepart)) $paramlink.=($paramlink?'&':'').'modulepart='.$modulepart;		// For sharing with hash (so public files), modulepart is not required.
710
-		//if (! empty($ecmfile->entity)) $paramlink.='&entity='.$ecmfile->entity; 					// For sharing with hash (so public files), entity is not required.
711
-		//$paramlink.=($paramlink?'&':'').'file='.urlencode($filepath);								// No need of name of file for public link, we will use the hash
712
-		if (! empty($ecmfile->share)) $paramlink.=($paramlink?'&':'').'hashp='.$ecmfile->share;			// Hash for public share
713
-		if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1';
714
-
715
-		if ($relativelink)
716
-		{
717
-			$linktoreturn='document.php'.($paramlink?'?'.$paramlink:'');
718
-		}
719
-		else
720
-		{
721
-			$linktoreturn=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:'');
722
-		}
723
-
724
-		// Here $ecmfile->share is defined
725
-		return $linktoreturn;
726
-	}
209
+    /**
210
+     * @var int
211
+     * @see getFullAddress(), country
212
+     */
213
+    public $country_id;
727 214
 
215
+    /**
216
+     * @var string
217
+     * @see getFullAddress(), isInEEC(), country
218
+     */
219
+    public $country_code;
728 220
 
729
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
730
-	/**
731
-	 *  Add a link between element $this->element and a contact
732
-	 *
733
-	 *  @param	int		$fk_socpeople       Id of thirdparty contact (if source = 'external') or id of user (if souce = 'internal') to link
734
-	 *  @param 	int		$type_contact 		Type of contact (code or id). Must be id or code found into table llx_c_type_contact. For example: SALESREPFOLL
735
-	 *  @param  string	$source             external=Contact extern (llx_socpeople), internal=Contact intern (llx_user)
736
-	 *  @param  int		$notrigger			Disable all triggers
737
-	 *  @return int                 		<0 if KO, >0 if OK
738
-	 */
739
-	function add_contact($fk_socpeople, $type_contact, $source='external',$notrigger=0)
740
-	{
741
-        // phpcs:enable
742
-		global $user,$langs;
743
-
744
-
745
-		dol_syslog(get_class($this)."::add_contact $fk_socpeople, $type_contact, $source, $notrigger");
746
-
747
-		// Check parameters
748
-		if ($fk_socpeople <= 0)
749
-		{
750
-			$langs->load("errors");
751
-			$this->error=$langs->trans("ErrorWrongValueForParameterX","1");
752
-			dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR);
753
-			return -1;
754
-		}
755
-		if (! $type_contact)
756
-		{
757
-			$langs->load("errors");
758
-			$this->error=$langs->trans("ErrorWrongValueForParameterX","2");
759
-			dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR);
760
-			return -2;
761
-		}
762
-
763
-		$id_type_contact=0;
764
-		if (is_numeric($type_contact))
765
-		{
766
-			$id_type_contact=$type_contact;
767
-		}
768
-		else
769
-		{
770
-			// We look for id type_contact
771
-			$sql = "SELECT tc.rowid";
772
-			$sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc";
773
-			$sql.= " WHERE tc.element='".$this->db->escape($this->element)."'";
774
-			$sql.= " AND tc.source='".$this->db->escape($source)."'";
775
-			$sql.= " AND tc.code='".$this->db->escape($type_contact)."' AND tc.active=1";
776
-			//print $sql;
777
-			$resql=$this->db->query($sql);
778
-			if ($resql)
779
-			{
780
-				$obj = $this->db->fetch_object($resql);
781
-				if ($obj) $id_type_contact=$obj->rowid;
782
-			}
783
-		}
784
-
785
-		if ($id_type_contact == 0)
786
-		{
787
-			$this->error='CODE_NOT_VALID_FOR_THIS_ELEMENT';
788
-			dol_syslog("CODE_NOT_VALID_FOR_THIS_ELEMENT: Code type of contact '".$type_contact."' does not exists or is not active for element ".$this->element.", we can ignore it");
789
-			return -3;
790
-		}
791
-
792
-		$datecreate = dol_now();
793
-
794
-		// Socpeople must have already been added by some trigger, then we have to check it to avoid DB_ERROR_RECORD_ALREADY_EXISTS error
795
-		$TListeContacts=$this->liste_contact(-1, $source);
796
-		$already_added=false;
797
-		if(!empty($TListeContacts)) {
798
-			foreach($TListeContacts as $array_contact) {
799
-				if($array_contact['status'] == 4 && $array_contact['id'] == $fk_socpeople && $array_contact['fk_c_type_contact'] == $id_type_contact) {
800
-					$already_added=true;
801
-					break;
802
-				}
803
-			}
804
-		}
221
+    /**
222
+     * @var string
223
+     * @see getFullAddress()
224
+     */
225
+    public $state;
805 226
 
806
-		if(!$already_added) {
227
+    /**
228
+     * @var int
229
+     * @see getFullAddress(), state
230
+     */
231
+    public $state_id;
807 232
 
808
-			$this->db->begin();
233
+    /**
234
+     * @var string
235
+     * @see getFullAddress(), state
236
+     */
237
+    public $state_code;
809 238
 
810
-			// Insert into database
811
-			$sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact";
812
-			$sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) ";
813
-			$sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ;
814
-			$sql.= "'".$this->db->idate($datecreate)."'";
815
-			$sql.= ", 4, ". $id_type_contact;
816
-			$sql.= ")";
239
+    /**
240
+     * @var string
241
+     * @see getFullAddress(), region
242
+     */
243
+    public $region;
817 244
 
818
-			$resql=$this->db->query($sql);
819
-			if ($resql)
820
-			{
821
-				if (! $notrigger)
822
-				{
823
-					$result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user);
824
-					if ($result < 0)
825
-					{
826
-						$this->db->rollback();
827
-						return -1;
828
-					}
829
-				}
245
+    /**
246
+     * @var string
247
+     * @see getFullAddress(), region
248
+     */
249
+    public $region_code;
830 250
 
831
-				$this->db->commit();
832
-				return 1;
833
-			}
834
-			else
835
-			{
836
-				if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
837
-				{
838
-					$this->error=$this->db->errno();
839
-					$this->db->rollback();
840
-					echo 'err rollback';
841
-					return -2;
842
-				}
843
-				else
844
-				{
845
-					$this->error=$this->db->error();
846
-					$this->db->rollback();
847
-					return -1;
848
-				}
849
-			}
850
-		} else return 0;
851
-	}
251
+    /**
252
+     * @var int
253
+     * @see fetch_barcode()
254
+     */
255
+    public $barcode_type;
852 256
 
853
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
854
-	/**
855
-	 *    Copy contact from one element to current
856
-	 *
857
-	 *    @param    CommonObject    $objFrom    Source element
858
-	 *    @param    string          $source     Nature of contact ('internal' or 'external')
859
-	 *    @return   int                         >0 if OK, <0 if KO
860
-	 */
861
-	function copy_linked_contact($objFrom, $source='internal')
862
-	{
863
-        // phpcs:enable
864
-		$contacts = $objFrom->liste_contact(-1, $source);
865
-		foreach($contacts as $contact)
866
-		{
867
-			if ($this->add_contact($contact['id'], $contact['fk_c_type_contact'], $contact['source']) < 0)
868
-			{
869
-				$this->error=$this->db->lasterror();
870
-				return -1;
871
-			}
872
-		}
873
-		return 1;
874
-	}
257
+    /**
258
+     * @var string
259
+     * @see fetch_barcode(), barcode_type
260
+     */
261
+    public $barcode_type_code;
875 262
 
876
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
877
-	/**
878
-	 *      Update a link to contact line
879
-	 *
880
-	 *      @param	int		$rowid              Id of line contact-element
881
-	 * 		@param	int		$statut	            New status of link
882
-	 *      @param  int		$type_contact_id    Id of contact type (not modified if 0)
883
-	 *      @param  int		$fk_socpeople	    Id of soc_people to update (not modified if 0)
884
-	 *      @return int                 		<0 if KO, >= 0 if OK
885
-	 */
886
-	function update_contact($rowid, $statut, $type_contact_id=0, $fk_socpeople=0)
887
-	{
888
-        // phpcs:enable
889
-		// Insert into database
890
-		$sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set";
891
-		$sql.= " statut = ".$statut;
892
-		if ($type_contact_id) $sql.= ", fk_c_type_contact = '".$type_contact_id ."'";
893
-		if ($fk_socpeople) $sql.= ", fk_socpeople = '".$fk_socpeople ."'";
894
-		$sql.= " where rowid = ".$rowid;
895
-		$resql=$this->db->query($sql);
896
-		if ($resql)
897
-		{
898
-			return 0;
899
-		}
900
-		else
901
-		{
902
-			$this->error=$this->db->lasterror();
903
-			return -1;
904
-		}
905
-	}
263
+    /**
264
+     * @var string
265
+     * @see fetch_barcode(), barcode_type
266
+     */
267
+    public $barcode_type_label;
906 268
 
907
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
908
-	/**
909
-	 *    Delete a link to contact line
910
-	 *
911
-	 *    @param	int		$rowid			Id of contact link line to delete
912
-	 *    @param	int		$notrigger		Disable all triggers
913
-	 *    @return   int						>0 if OK, <0 if KO
914
-	 */
915
-	function delete_contact($rowid, $notrigger=0)
916
-	{
917
-        // phpcs:enable
918
-		global $user;
269
+    /**
270
+     * @var string
271
+     * @see fetch_barcode(), barcode_type
272
+     */
273
+    public $barcode_type_coder;
919 274
 
275
+    /**
276
+     * @var int Payment method ID (cheque, cash, ...)
277
+     * @see setPaymentMethods()
278
+     */
279
+    public $mode_reglement_id;
920 280
 
921
-		$this->db->begin();
281
+    /**
282
+     * @var int Payment terms ID
283
+     * @see setPaymentTerms()
284
+     */
285
+    public $cond_reglement_id;
922 286
 
923
-		$sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact";
924
-		$sql.= " WHERE rowid =".$rowid;
287
+    /**
288
+     * @var int Payment terms ID
289
+     * @deprecated Kept for compatibility
290
+     * @see cond_reglement_id;
291
+     */
292
+    public $cond_reglement;
925 293
 
926
-		dol_syslog(get_class($this)."::delete_contact", LOG_DEBUG);
927
-		if ($this->db->query($sql))
928
-		{
929
-			if (! $notrigger)
930
-			{
931
-				$result=$this->call_trigger(strtoupper($this->element).'_DELETE_CONTACT', $user);
932
-				if ($result < 0) { $this->db->rollback(); return -1; }
933
-			}
934
-
935
-			$this->db->commit();
936
-			return 1;
937
-		}
938
-		else
939
-		{
940
-			$this->error=$this->db->lasterror();
941
-			$this->db->rollback();
942
-			return -1;
943
-		}
944
-	}
294
+    /**
295
+     * @var int Delivery address ID
296
+     * @deprecated
297
+     * @see setDeliveryAddress()
298
+     */
299
+    public $fk_delivery_address;
945 300
 
946
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
947
-	/**
948
-	 *    Delete all links between an object $this and all its contacts
949
-	 *
950
-	 *	  @param	string	$source		'' or 'internal' or 'external'
951
-	 *	  @param	string	$code		Type of contact (code or id)
952
-	 *    @return   int					>0 if OK, <0 if KO
953
-	 */
954
-	function delete_linked_contact($source='',$code='')
955
-	{
956
-        // phpcs:enable
957
-		$temp = array();
958
-		$typeContact = $this->liste_type_contact($source,'',0,0,$code);
959
-
960
-		foreach($typeContact as $key => $value)
961
-		{
962
-			array_push($temp,$key);
963
-		}
964
-		$listId = implode(",", $temp);
965
-
966
-		$sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact";
967
-		$sql.= " WHERE element_id = ".$this->id;
968
-		if ($listId)
969
-			$sql.= " AND fk_c_type_contact IN (".$listId.")";
970
-
971
-		dol_syslog(get_class($this)."::delete_linked_contact", LOG_DEBUG);
972
-		if ($this->db->query($sql))
973
-		{
974
-			return 1;
975
-		}
976
-		else
977
-		{
978
-			$this->error=$this->db->lasterror();
979
-			return -1;
980
-		}
981
-	}
301
+    /**
302
+     * @var int Shipping method ID
303
+     * @see setShippingMethod()
304
+     */
305
+    public $shipping_method_id;
982 306
 
983
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
984
-	/**
985
-	 *    Get array of all contacts for an object
986
-	 *
987
-	 *    @param	int			$statut		Status of links to get (-1=all)
988
-	 *    @param	string		$source		Source of contact: external or thirdparty (llx_socpeople) or internal (llx_user)
989
-	 *    @param	int         $list       0:Return array contains all properties, 1:Return array contains just id
990
-	 *    @param    string      $code       Filter on this code of contact type ('SHIPPING', 'BILLING', ...)
991
-	 *    @return	array|int		        Array of contacts, -1 if error
992
-	 */
993
-	function liste_contact($statut=-1,$source='external',$list=0,$code='')
994
-	{
995
-        // phpcs:enable
996