Test Failed
Push — master ( d56fde...b8c830 )
by Alxarafe
37:54
created
dolibarr/htdocs/expedition/stats/index.php 1 patch
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -28,11 +28,11 @@  discard block
 block discarded – undo
28 28
 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionstats.class.php';
29 29
 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
30 30
 
31
-$WIDTH=DolGraph::getDefaultGraphSizeForStats('width');
32
-$HEIGHT=DolGraph::getDefaultGraphSizeForStats('height');
31
+$WIDTH = DolGraph::getDefaultGraphSizeForStats('width');
32
+$HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
33 33
 
34
-$userid=GETPOST('userid','int');
35
-$socid=GETPOST('socid','int');
34
+$userid = GETPOST('userid', 'int');
35
+$socid = GETPOST('socid', 'int');
36 36
 // Security check
37 37
 if ($user->societe_id > 0)
38 38
 {
@@ -40,11 +40,11 @@  discard block
 block discarded – undo
40 40
     $socid = $user->societe_id;
41 41
 }
42 42
 
43
-$nowyear=strftime("%Y", dol_now());
44
-$year = GETPOST('year')>0?GETPOST('year'):$nowyear;
43
+$nowyear = strftime("%Y", dol_now());
44
+$year = GETPOST('year') > 0 ?GETPOST('year') : $nowyear;
45 45
 //$startyear=$year-2;
46
-$startyear=$year-1;
47
-$endyear=$year;
46
+$startyear = $year - 1;
47
+$endyear = $year;
48 48
 
49 49
 // Load translation files required by the page
50 50
 $langs->loadLangs(array('sendings', 'other', 'companies'));
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
  * View
55 55
  */
56 56
 
57
-$form=new Form($db);
57
+$form = new Form($db);
58 58
 
59 59
 llxHeader();
60 60
 
@@ -63,10 +63,10 @@  discard block
 block discarded – undo
63 63
 
64 64
 dol_mkdir($dir);
65 65
 
66
-$stats = new ExpeditionStats($db, $socid, $mode, ($userid>0?$userid:0));
66
+$stats = new ExpeditionStats($db, $socid, $mode, ($userid > 0 ? $userid : 0));
67 67
 
68 68
 // Build graphic number of object
69
-$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
69
+$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
70 70
 //var_dump($data);exit;
71 71
 // $data = array(array('Lib',val1,val2,val3),...)
72 72
 
@@ -86,29 +86,29 @@  discard block
 block discarded – undo
86 86
 
87 87
 $px1 = new DolGraph();
88 88
 $mesg = $px1->isGraphKo();
89
-if (! $mesg)
89
+if (!$mesg)
90 90
 {
91 91
     $px1->SetData($data);
92 92
     $px1->SetPrecisionY(0);
93
-    $i=$startyear;$legend=array();
93
+    $i = $startyear; $legend = array();
94 94
     while ($i <= $endyear)
95 95
     {
96
-        $legend[]=$i;
96
+        $legend[] = $i;
97 97
         $i++;
98 98
     }
99 99
     $px1->SetLegend($legend);
100 100
     $px1->SetMaxValue($px1->GetCeilMaxValue());
101
-    $px1->SetMinValue(min(0,$px1->GetFloorMinValue()));
101
+    $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
102 102
     $px1->SetWidth($WIDTH);
103 103
     $px1->SetHeight($HEIGHT);
104 104
     $px1->SetYLabel($langs->trans("NbOfSendings"));
105 105
     $px1->SetShading(3);
106 106
     $px1->SetHorizTickIncrement(1);
107 107
     $px1->SetPrecisionY(0);
108
-    $px1->mode='depth';
108
+    $px1->mode = 'depth';
109 109
     $px1->SetTitle($langs->trans("NumberOfShipmentsByMonth"));
110 110
 
111
-    $px1->draw($filenamenb,$fileurlnb);
111
+    $px1->draw($filenamenb, $fileurlnb);
112 112
 }
113 113
 
114 114
 // Build graphic amount of object
@@ -203,24 +203,24 @@  discard block
 block discarded – undo
203 203
 
204 204
 // Show array
205 205
 $data = $stats->getAllByYear();
206
-$arrayyears=array();
207
-foreach($data as $val) {
208
-	if (! empty($val['year'])) {
209
-		$arrayyears[$val['year']]=$val['year'];
206
+$arrayyears = array();
207
+foreach ($data as $val) {
208
+	if (!empty($val['year'])) {
209
+		$arrayyears[$val['year']] = $val['year'];
210 210
 	}
211 211
 }
212
-if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear;
212
+if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear;
213 213
 
214
-$h=0;
214
+$h = 0;
215 215
 $head = array();
216
-$head[$h][0] = DOL_URL_ROOT . '/expedition/stats/index.php?mode='.$mode;
216
+$head[$h][0] = DOL_URL_ROOT.'/expedition/stats/index.php?mode='.$mode;
217 217
 $head[$h][1] = $langs->trans("ByMonthYear");
218 218
 $head[$h][2] = 'byyear';
219 219
 $h++;
220 220
 
221
-$type='shipment_stats';
221
+$type = 'shipment_stats';
222 222
 
223
-complete_head_from_modules($conf,$langs,null,$head,$h,$type);
223
+complete_head_from_modules($conf, $langs, null, $head, $h, $type);
224 224
 
225 225
 dol_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
226 226
 
@@ -238,9 +238,9 @@  discard block
 block discarded – undo
238 238
 	print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
239 239
 	// Company
240 240
 	print '<tr><td align="left">'.$langs->trans("ThirdParty").'</td><td align="left">';
241
-	if ($mode == 'customer') $filter='s.client in (1,2,3)';
242
-	if ($mode == 'supplier') $filter='s.fournisseur = 1';
243
-	print $form->select_company($socid,'socid',$filter,1,0,0,array(),0,'','style="width: 95%"');
241
+	if ($mode == 'customer') $filter = 's.client in (1,2,3)';
242
+	if ($mode == 'supplier') $filter = 's.fournisseur = 1';
243
+	print $form->select_company($socid, 'socid', $filter, 1, 0, 0, array(), 0, '', 'style="width: 95%"');
244 244
 	print '</td></tr>';
245 245
 	// User
246 246
 	print '<tr><td align="left">'.$langs->trans("CreatedBy").'</td><td align="left">';
@@ -248,10 +248,10 @@  discard block
 block discarded – undo
248 248
 	print '</td></tr>';
249 249
 	// Year
250 250
 	print '<tr><td align="left">'.$langs->trans("Year").'</td><td align="left">';
251
-	if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
252
-	if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear;
251
+	if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year;
252
+	if (!in_array($nowyear, $arrayyears)) $arrayyears[$nowyear] = $nowyear;
253 253
 	arsort($arrayyears);
254
-	print $form->selectarray('year',$arrayyears,$year,0);
254
+	print $form->selectarray('year', $arrayyears, $year, 0);
255 255
 	print '</td></tr>';
256 256
 	print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
257 257
 	print '</table>';
@@ -269,11 +269,11 @@  discard block
 block discarded – undo
269 269
 print '<td align="center">'.$langs->trans("AmountAverage").'</td>';*/
270 270
 print '</tr>';
271 271
 
272
-$oldyear=0;
272
+$oldyear = 0;
273 273
 foreach ($data as $val)
274 274
 {
275 275
 	$year = $val['year'];
276
-	while (! empty($year) && $oldyear > $year+1)
276
+	while (!empty($year) && $oldyear > $year + 1)
277 277
 	{ // If we have empty year
278 278
 		$oldyear--;
279 279
 
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 	/*print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
297 297
 	print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';*/
298 298
 	print '</tr>';
299
-	$oldyear=$year;
299
+	$oldyear = $year;
300 300
 }
301 301
 
302 302
 print '</table>';
Please login to merge, or discard this patch.
dolibarr/htdocs/societe/class/societe.class.php 3 patches
Indentation   +3920 added lines, -3920 removed lines patch added patch discarded remove patch
@@ -42,313 +42,313 @@  discard block
 block discarded – undo
42 42
  */
43 43
 class Societe extends CommonObject
44 44
 {
45
-	/**
46
-	 * @var string ID to identify managed object
47
-	 */
48
-	public $element='societe';
49
-
50
-	/**
51
-	 * @var string Name of table without prefix where object is stored
52
-	 */
53
-	public $table_element = 'societe';
54
-
55
-	/**
56
-	 * @var int Field with ID of parent key if this field has a parent
57
-	 */
58
-	public $fk_element='fk_soc';
59
-
60
-	public $fieldsforcombobox='nom,name_alias';
61
-	protected $childtables=array("supplier_proposal"=>'SupplierProposal',"propal"=>'Proposal',"commande"=>'Order',"facture"=>'Invoice',"facture_rec"=>'RecurringInvoiceTemplate',"contrat"=>'Contract',"fichinter"=>'Fichinter',"facture_fourn"=>'SupplierInvoice',"commande_fournisseur"=>'SupplierOrder',"projet"=>'Project',"expedition"=>'Shipment',"prelevement_lignes"=>'DirectDebitRecord');    // To test if we can delete object
62
-	protected $childtablesoncascade=array("societe_prices", "societe_log", "societe_address", "product_fournisseur_price", "product_customer_price_log", "product_customer_price", "socpeople", "adherent", "societe_rib", "societe_remise", "societe_remise_except", "societe_commerciaux", "categorie", "notify", "notify_def", "actioncomm");
63
-	public $picto = 'company';
64
-
65
-	/**
66
-	 * 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
67
-	 * @var int
68
-	 */
69
-	public $ismultientitymanaged = 1;
70
-
71
-	/**
72
-	 * 0=Default, 1=View may be restricted to sales representative only if no permission to see all or to company of external user if external user
73
-	 * @var integer
74
-	 */
75
-	public $restrictiononfksoc = 1;
76
-
77
-
78
-	// BEGIN MODULEBUILDER PROPERTIES
79
-	/**
80
-	 * @var array  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
81
-	 */
82
-	public $fields=array(
83
-		'rowid'         =>array('type'=>'integer',      'label'=>'TechnicalID',      'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'index'=>1, 'position'=>1, 'comment'=>'Id'),
84
-		'nom'           =>array('type'=>'varchar(128)', 'label'=>'Name',             'enabled'=>1, 'visible'=>1,  'notnull'=>1,  'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
85
-		'name_alias'    =>array('type'=>'varchar(128)', 'label'=>'Name',             'enabled'=>1, 'visible'=>1,  'notnull'=>1,  'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
86
-		'entity'        =>array('type'=>'integer',      'label'=>'Entity',           'enabled'=>1, 'visible'=>0,  'default'=>1,  'notnull'=>1,  'index'=>1, 'position'=>20),
87
-		'note_public'   =>array('type'=>'text',			'label'=>'NotePublic',		 'enabled'=>1, 'visible'=>0,  'position'=>60),
88
-		'note_private'  =>array('type'=>'text',			'label'=>'NotePrivate',		 'enabled'=>1, 'visible'=>0,  'position'=>61),
89
-		'datec'			=>array('type'=>'datetime',     'label'=>'DateCreation',     'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'position'=>500),
90
-		'tms'           =>array('type'=>'timestamp',    'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'position'=>501),
91
-		//'date_valid'    =>array('type'=>'datetime',     'label'=>'DateCreation',     'enabled'=>1, 'visible'=>-2, 'position'=>502),
92
-		'fk_user_creat' =>array('type'=>'integer',      'label'=>'UserAuthor',       'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'position'=>510),
93
-		'fk_user_modif' =>array('type'=>'integer',      'label'=>'UserModif',        'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511),
94
-		//'fk_user_valid' =>array('type'=>'integer',      'label'=>'UserValidation',        'enabled'=>1, 'visible'=>-1, 'position'=>512),
95
-		'import_key'    =>array('type'=>'varchar(14)',  'label'=>'ImportId',         'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>1,  'position'=>1000),
96
-	);
97
-
98
-
99
-	/**
100
-	 * @var int Entity
101
-	 */
102
-	public $entity;
103
-
104
-	/**
105
-	 * Thirdparty name
106
-	 * @var string
107
-	 * @deprecated Use $name instead
108
-	 * @see $name
109
-	 */
110
-	public $nom;
111
-
112
-	/**
113
-	 * @var string name
114
-	 */
115
-	public $name;
116
-
117
-	/**
118
-	 * Alias names (commercial, trademark or alias names)
119
-	 * @var string
120
-	 */
121
-	public $name_alias;
122
-
123
-	public $particulier;
124
-
125
-	/**
126
-	 * @var string Address
127
-	 */
128
-	public $address;
129
-
130
-	public $zip;
131
-	public $town;
132
-
133
-	/**
134
-	 * Thirdparty status : 0=activity ceased, 1= in activity
135
-	 * @var int
136
-	 */
137
-	public $status=1;
138
-
139
-	/**
140
-	 * Id of department
141
-	 * @var int
142
-	 */
143
-	public $state_id;
144
-	public $state_code;
145
-	public $state;
146
-
147
-	/**
148
-	 * Id of region
149
-	 * @var int
150
-	 */
151
-	public $region_code;
152
-	public $region;
153
-
154
-	/**
155
-	 * State code
156
-	 * @var string
157
-	 * @deprecated Use state_code instead
158
-	 * @see $state_code
159
-	 */
160
-	public $departement_code;
161
-
162
-	/**
163
-	 * @var string
164
-	 * @deprecated Use state instead
165
-	 * @see $state
166
-	 */
167
-	public $departement;
168
-
169
-	/**
170
-	 * @var string
171
-	 * @deprecated Use country instead
172
-	 * @see $country
173
-	 */
174
-	public $pays;
175
-
176
-	/**
177
-	 * Phone number
178
-	 * @var string
179
-	 */
180
-	public $phone;
181
-	/**
182
-	 * Fax number
183
-	 * @var string
184
-	 */
185
-	public $fax;
186
-	/**
187
-	 * Email
188
-	 * @var string
189
-	 */
190
-	public $email;
191
-	/**
192
-	 * Skype username
193
-	 * @var string
194
-	 */
195
-	public $skype;
196
-	/**
197
-	 * Twitter username
198
-	 * @var string
199
-	 */
200
-	public $twitter;
201
-	/**
202
-	 * Facebook username
203
-	 * @var string
204
-	 */
205
-	public $facebook;
206
-	/**
207
-	 * Webpage
208
-	 * @var string
209
-	 */
210
-	public $url;
211
-
212
-	//! barcode
213
-	/**
214
-	 * Barcode value
215
-	 * @var string
216
-	 */
217
-	public $barcode;
218
-
219
-	// 6 professional id (usage depends on country)
220
-
221
-	/**
222
-	 * Professional ID 1 (Ex: Siren in France)
223
-	 * @var string
224
-	 */
225
-	public $idprof1;
226
-
227
-	/**
228
-	 * Professional ID 2 (Ex: Siret in France)
229
-	 * @var string
230
-	 */
231
-	public $idprof2;
232
-
233
-	/**
234
-	 * Professional ID 3 (Ex: Ape in France)
235
-	 * @var string
236
-	 */
237
-	public $idprof3;
238
-
239
-	/**
240
-	 * Professional ID 4 (Ex: RCS in France)
241
-	 * @var string
242
-	 */
243
-	public $idprof4;
244
-
245
-	/**
246
-	 * Professional ID 5
247
-	 * @var string
248
-	 */
249
-	public $idprof5;
250
-
251
-	/**
252
-	 * Professional ID 6
253
-	 * @var string
254
-	 */
255
-	public $idprof6;
256
-
257
-	public $prefix_comm;
258
-
259
-	public $tva_assuj=1;
260
-	/**
261
-	 * Intracommunitary VAT ID
262
-	 * @var string
263
-	 */
264
-	public $tva_intra;
265
-
266
-	// Local taxes
267
-	public $localtax1_assuj;
268
-	public $localtax1_value;
269
-	public $localtax2_assuj;
270
-	public $localtax2_value;
271
-
272
-	public $managers;
273
-	public $capital;
274
-	public $typent_id=0;
275
-	public $typent_code;
276
-	public $effectif;
277
-	public $effectif_id=0;
278
-	public $forme_juridique_code;
279
-	public $forme_juridique=0;
280
-
281
-	public $remise_percent;
282
-	public $remise_supplier_percent;
283
-	public $mode_reglement_supplier_id;
284
-	public $cond_reglement_supplier_id;
285
-
286
-	/**
45
+    /**
46
+     * @var string ID to identify managed object
47
+     */
48
+    public $element='societe';
49
+
50
+    /**
51
+     * @var string Name of table without prefix where object is stored
52
+     */
53
+    public $table_element = 'societe';
54
+
55
+    /**
56
+     * @var int Field with ID of parent key if this field has a parent
57
+     */
58
+    public $fk_element='fk_soc';
59
+
60
+    public $fieldsforcombobox='nom,name_alias';
61
+    protected $childtables=array("supplier_proposal"=>'SupplierProposal',"propal"=>'Proposal',"commande"=>'Order',"facture"=>'Invoice',"facture_rec"=>'RecurringInvoiceTemplate',"contrat"=>'Contract',"fichinter"=>'Fichinter',"facture_fourn"=>'SupplierInvoice',"commande_fournisseur"=>'SupplierOrder',"projet"=>'Project',"expedition"=>'Shipment',"prelevement_lignes"=>'DirectDebitRecord');    // To test if we can delete object
62
+    protected $childtablesoncascade=array("societe_prices", "societe_log", "societe_address", "product_fournisseur_price", "product_customer_price_log", "product_customer_price", "socpeople", "adherent", "societe_rib", "societe_remise", "societe_remise_except", "societe_commerciaux", "categorie", "notify", "notify_def", "actioncomm");
63
+    public $picto = 'company';
64
+
65
+    /**
66
+     * 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
67
+     * @var int
68
+     */
69
+    public $ismultientitymanaged = 1;
70
+
71
+    /**
72
+     * 0=Default, 1=View may be restricted to sales representative only if no permission to see all or to company of external user if external user
73
+     * @var integer
74
+     */
75
+    public $restrictiononfksoc = 1;
76
+
77
+
78
+    // BEGIN MODULEBUILDER PROPERTIES
79
+    /**
80
+     * @var array  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
81
+     */
82
+    public $fields=array(
83
+        'rowid'         =>array('type'=>'integer',      'label'=>'TechnicalID',      'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'index'=>1, 'position'=>1, 'comment'=>'Id'),
84
+        'nom'           =>array('type'=>'varchar(128)', 'label'=>'Name',             'enabled'=>1, 'visible'=>1,  'notnull'=>1,  'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
85
+        'name_alias'    =>array('type'=>'varchar(128)', 'label'=>'Name',             'enabled'=>1, 'visible'=>1,  'notnull'=>1,  'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
86
+        'entity'        =>array('type'=>'integer',      'label'=>'Entity',           'enabled'=>1, 'visible'=>0,  'default'=>1,  'notnull'=>1,  'index'=>1, 'position'=>20),
87
+        'note_public'   =>array('type'=>'text',			'label'=>'NotePublic',		 'enabled'=>1, 'visible'=>0,  'position'=>60),
88
+        'note_private'  =>array('type'=>'text',			'label'=>'NotePrivate',		 'enabled'=>1, 'visible'=>0,  'position'=>61),
89
+        'datec'			=>array('type'=>'datetime',     'label'=>'DateCreation',     'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'position'=>500),
90
+        'tms'           =>array('type'=>'timestamp',    'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'position'=>501),
91
+        //'date_valid'    =>array('type'=>'datetime',     'label'=>'DateCreation',     'enabled'=>1, 'visible'=>-2, 'position'=>502),
92
+        'fk_user_creat' =>array('type'=>'integer',      'label'=>'UserAuthor',       'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'position'=>510),
93
+        'fk_user_modif' =>array('type'=>'integer',      'label'=>'UserModif',        'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511),
94
+        //'fk_user_valid' =>array('type'=>'integer',      'label'=>'UserValidation',        'enabled'=>1, 'visible'=>-1, 'position'=>512),
95
+        'import_key'    =>array('type'=>'varchar(14)',  'label'=>'ImportId',         'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>1,  'position'=>1000),
96
+    );
97
+
98
+
99
+    /**
100
+     * @var int Entity
101
+     */
102
+    public $entity;
103
+
104
+    /**
105
+     * Thirdparty name
106
+     * @var string
107
+     * @deprecated Use $name instead
108
+     * @see $name
109
+     */
110
+    public $nom;
111
+
112
+    /**
113
+     * @var string name
114
+     */
115
+    public $name;
116
+
117
+    /**
118
+     * Alias names (commercial, trademark or alias names)
119
+     * @var string
120
+     */
121
+    public $name_alias;
122
+
123
+    public $particulier;
124
+
125
+    /**
126
+     * @var string Address
127
+     */
128
+    public $address;
129
+
130
+    public $zip;
131
+    public $town;
132
+
133
+    /**
134
+     * Thirdparty status : 0=activity ceased, 1= in activity
135
+     * @var int
136
+     */
137
+    public $status=1;
138
+
139
+    /**
140
+     * Id of department
141
+     * @var int
142
+     */
143
+    public $state_id;
144
+    public $state_code;
145
+    public $state;
146
+
147
+    /**
148
+     * Id of region
149
+     * @var int
150
+     */
151
+    public $region_code;
152
+    public $region;
153
+
154
+    /**
155
+     * State code
156
+     * @var string
157
+     * @deprecated Use state_code instead
158
+     * @see $state_code
159
+     */
160
+    public $departement_code;
161
+
162
+    /**
163
+     * @var string
164
+     * @deprecated Use state instead
165
+     * @see $state
166
+     */
167
+    public $departement;
168
+
169
+    /**
170
+     * @var string
171
+     * @deprecated Use country instead
172
+     * @see $country
173
+     */
174
+    public $pays;
175
+
176
+    /**
177
+     * Phone number
178
+     * @var string
179
+     */
180
+    public $phone;
181
+    /**
182
+     * Fax number
183
+     * @var string
184
+     */
185
+    public $fax;
186
+    /**
187
+     * Email
188
+     * @var string
189
+     */
190
+    public $email;
191
+    /**
192
+     * Skype username
193
+     * @var string
194
+     */
195
+    public $skype;
196
+    /**
197
+     * Twitter username
198
+     * @var string
199
+     */
200
+    public $twitter;
201
+    /**
202
+     * Facebook username
203
+     * @var string
204
+     */
205
+    public $facebook;
206
+    /**
207
+     * Webpage
208
+     * @var string
209
+     */
210
+    public $url;
211
+
212
+    //! barcode
213
+    /**
214
+     * Barcode value
215
+     * @var string
216
+     */
217
+    public $barcode;
218
+
219
+    // 6 professional id (usage depends on country)
220
+
221
+    /**
222
+     * Professional ID 1 (Ex: Siren in France)
223
+     * @var string
224
+     */
225
+    public $idprof1;
226
+
227
+    /**
228
+     * Professional ID 2 (Ex: Siret in France)
229
+     * @var string
230
+     */
231
+    public $idprof2;
232
+
233
+    /**
234
+     * Professional ID 3 (Ex: Ape in France)
235
+     * @var string
236
+     */
237
+    public $idprof3;
238
+
239
+    /**
240
+     * Professional ID 4 (Ex: RCS in France)
241
+     * @var string
242
+     */
243
+    public $idprof4;
244
+
245
+    /**
246
+     * Professional ID 5
247
+     * @var string
248
+     */
249
+    public $idprof5;
250
+
251
+    /**
252
+     * Professional ID 6
253
+     * @var string
254
+     */
255
+    public $idprof6;
256
+
257
+    public $prefix_comm;
258
+
259
+    public $tva_assuj=1;
260
+    /**
261
+     * Intracommunitary VAT ID
262
+     * @var string
263
+     */
264
+    public $tva_intra;
265
+
266
+    // Local taxes
267
+    public $localtax1_assuj;
268
+    public $localtax1_value;
269
+    public $localtax2_assuj;
270
+    public $localtax2_value;
271
+
272
+    public $managers;
273
+    public $capital;
274
+    public $typent_id=0;
275
+    public $typent_code;
276
+    public $effectif;
277
+    public $effectif_id=0;
278
+    public $forme_juridique_code;
279
+    public $forme_juridique=0;
280
+
281
+    public $remise_percent;
282
+    public $remise_supplier_percent;
283
+    public $mode_reglement_supplier_id;
284
+    public $cond_reglement_supplier_id;
285
+
286
+    /**
287 287
      * @var int ID
288 288
      */
289
-	public $fk_prospectlevel;
290
-
291
-	public $name_bis;
292
-
293
-	//Log data
294
-
295
-	/**
296
-	 * Date of last update
297
-	 * @var string
298
-	 */
299
-	public $date_modification;
300
-	/**
301
-	 * User that made last update
302
-	 * @var string
303
-	 */
304
-	public $user_modification;
305
-	/**
306
-	 * Date of creation
307
-	 * @var string
308
-	 */
309
-	public $date_creation;
310
-	/**
311
-	 * User that created the thirdparty
312
-	 * @var User
313
-	 */
314
-	public $user_creation;
315
-
316
-
317
-	public $specimen;
318
-
319
-	/**
320
-	 * 0=no customer, 1=customer, 2=prospect, 3=customer and prospect
321
-	 * @var int
322
-	 */
323
-	public $client=0;
324
-	/**
325
-	 * 0=no prospect, 1=prospect
326
-	 * @var int
327
-	 */
328
-	public $prospect=0;
329
-	/**
330
-	 * 0=no supplier, 1=supplier
331
-	 * @var int
332
-	 */
333
-	public $fournisseur;
334
-
335
-	/**
336
-	 * Client code. E.g: CU2014-003
337
-	 * @var string
338
-	 */
339
-	public $code_client;
340
-
341
-	/**
342
-	 * Supplier code. E.g: SU2014-003
343
-	 * @var string
344
-	 */
345
-	public $code_fournisseur;
346
-
347
-	/**
348
-	 * Accounting code for client
349
-	 * @var string
350
-	 */
351
-	public $code_compta;
289
+    public $fk_prospectlevel;
290
+
291
+    public $name_bis;
292
+
293
+    //Log data
294
+
295
+    /**
296
+     * Date of last update
297
+     * @var string
298
+     */
299
+    public $date_modification;
300
+    /**
301
+     * User that made last update
302
+     * @var string
303
+     */
304
+    public $user_modification;
305
+    /**
306
+     * Date of creation
307
+     * @var string
308
+     */
309
+    public $date_creation;
310
+    /**
311
+     * User that created the thirdparty
312
+     * @var User
313
+     */
314
+    public $user_creation;
315
+
316
+
317
+    public $specimen;
318
+
319
+    /**
320
+     * 0=no customer, 1=customer, 2=prospect, 3=customer and prospect
321
+     * @var int
322
+     */
323
+    public $client=0;
324
+    /**
325
+     * 0=no prospect, 1=prospect
326
+     * @var int
327
+     */
328
+    public $prospect=0;
329
+    /**
330
+     * 0=no supplier, 1=supplier
331
+     * @var int
332
+     */
333
+    public $fournisseur;
334
+
335
+    /**
336
+     * Client code. E.g: CU2014-003
337
+     * @var string
338
+     */
339
+    public $code_client;
340
+
341
+    /**
342
+     * Supplier code. E.g: SU2014-003
343
+     * @var string
344
+     */
345
+    public $code_fournisseur;
346
+
347
+    /**
348
+     * Accounting code for client
349
+     * @var string
350
+     */
351
+    public $code_compta;
352 352
 
353 353
     /**
354 354
      * Accounting code for client
@@ -356,3795 +356,3795 @@  discard block
 block discarded – undo
356 356
      */
357 357
     public $code_compta_client;
358 358
 
359
-	/**
360
-	 * Accounting code for suppliers
361
-	 * @var string
362
-	 */
363
-	public $code_compta_fournisseur;
364
-
365
-	/**
366
-	 * @var string
367
-	 * @deprecated Note is split in public and private notes
368
-	 * @see $note_public, $note_private
369
-	 */
370
-	public $note;
371
-
372
-	/**
373
-	 * Private note
374
-	 * @var string
375
-	 */
376
-	public $note_private;
377
-
378
-	/**
379
-	 * Public note
380
-	 * @var string
381
-	 */
382
-	public $note_public;
383
-
384
-	//! code statut prospect
385
-	public $stcomm_id;
386
-	public $statut_commercial;
387
-
388
-	/**
389
-	 * Assigned price level
390
-	 * @var int
391
-	 */
392
-	public $price_level;
393
-	public $outstanding_limit;
394
-
395
-	/**
396
-	 * Min order amounts
397
-	 */
398
-	public $order_min_amount;
399
-	public $supplier_order_min_amount;
400
-
401
-	/**
402
-	 * Id of sales representative to link (used for thirdparty creation). Not filled by a fetch, because we can have several sales representatives.
403
-	 * @var int
404
-	 */
405
-	public $commercial_id;
406
-	/**
407
-	 * Id of parent thirdparty (if one)
408
-	 * @var int
409
-	 */
410
-	public $parent;
411
-	/**
412
-	 * Default language code of thirdparty (en_US, ...)
413
-	 * @var string
414
-	 */
415
-	public $default_lang;
416
-
417
-	/**
418
-	 * @var string Ref
419
-	 */
420
-	public $ref;
421
-
422
-	public $ref_int;
423
-	/**
424
-	 * External user reference.
425
-	 * This is to allow external systems to store their id and make self-developed synchronizing functions easier to
426
-	 * build.
427
-	 * @var string
428
-	 */
429
-	public $ref_ext;
430
-
431
-	/**
432
-	 * Import key.
433
-	 * Set when the thirdparty has been created through an import process. This is to relate those created thirdparties
434
-	 * to an import process
435
-	 * @var string
436
-	 */
437
-	public $import_key;
438
-
439
-	/**
440
-	 * Supplier WebServices URL
441
-	 * @var string
442
-	 */
443
-	public $webservices_url;
444
-
445
-	/**
446
-	 * Supplier WebServices Key
447
-	 * @var string
448
-	 */
449
-	public $webservices_key;
450
-
451
-	public $logo;
452
-	public $logo_small;
453
-	public $logo_mini;
454
-
455
-	public $array_options;
456
-
457
-	// Incoterms
458
-	/**
359
+    /**
360
+     * Accounting code for suppliers
361
+     * @var string
362
+     */
363
+    public $code_compta_fournisseur;
364
+
365
+    /**
366
+     * @var string
367
+     * @deprecated Note is split in public and private notes
368
+     * @see $note_public, $note_private
369
+     */
370
+    public $note;
371
+
372
+    /**
373
+     * Private note
374
+     * @var string
375
+     */
376
+    public $note_private;
377
+
378
+    /**
379
+     * Public note
380
+     * @var string
381
+     */
382
+    public $note_public;
383
+
384
+    //! code statut prospect
385
+    public $stcomm_id;
386
+    public $statut_commercial;
387
+
388
+    /**
389
+     * Assigned price level
390
+     * @var int
391
+     */
392
+    public $price_level;
393
+    public $outstanding_limit;
394
+
395
+    /**
396
+     * Min order amounts
397
+     */
398
+    public $order_min_amount;
399
+    public $supplier_order_min_amount;
400
+
401
+    /**
402
+     * Id of sales representative to link (used for thirdparty creation). Not filled by a fetch, because we can have several sales representatives.
403
+     * @var int
404
+     */
405
+    public $commercial_id;
406
+    /**
407
+     * Id of parent thirdparty (if one)
408
+     * @var int
409
+     */
410
+    public $parent;
411
+    /**
412
+     * Default language code of thirdparty (en_US, ...)
413
+     * @var string
414
+     */
415
+    public $default_lang;
416
+
417
+    /**
418
+     * @var string Ref
419
+     */
420
+    public $ref;
421
+
422
+    public $ref_int;
423
+    /**
424
+     * External user reference.
425
+     * This is to allow external systems to store their id and make self-developed synchronizing functions easier to
426
+     * build.
427
+     * @var string
428
+     */
429
+    public $ref_ext;
430
+
431
+    /**
432
+     * Import key.
433
+     * Set when the thirdparty has been created through an import process. This is to relate those created thirdparties
434
+     * to an import process
435
+     * @var string
436
+     */
437
+    public $import_key;
438
+
439
+    /**
440
+     * Supplier WebServices URL
441
+     * @var string
442
+     */
443
+    public $webservices_url;
444
+
445
+    /**
446
+     * Supplier WebServices Key
447
+     * @var string
448
+     */
449
+    public $webservices_key;
450
+
451
+    public $logo;
452
+    public $logo_small;
453
+    public $logo_mini;
454
+
455
+    public $array_options;
456
+
457
+    // Incoterms
458
+    /**
459 459
      * @var int ID
460 460
      */
461
-	public $fk_incoterms;
461
+    public $fk_incoterms;
462 462
 
463
-	public $location_incoterms;
464
-	public $libelle_incoterms;  //Used into tooltip
463
+    public $location_incoterms;
464
+    public $libelle_incoterms;  //Used into tooltip
465 465
 
466
-	// Multicurrency
467
-	/**
466
+    // Multicurrency
467
+    /**
468 468
      * @var int ID
469 469
      */
470
-	public $fk_multicurrency;
471
-
472
-	public $multicurrency_code;
473
-
474
-
475
-	// END MODULEBUILDER PROPERTIES
476
-
477
-
478
-	/**
479
-	 *    Constructor
480
-	 *
481
-	 *    @param	DoliDB		$db		Database handler
482
-	 */
483
-	public function __construct($db)
484
-	{
485
-		$this->db = $db;
486
-
487
-		$this->client = 0;
488
-		$this->prospect = 0;
489
-		$this->fournisseur = 0;
490
-		$this->typent_id  = 0;
491
-		$this->effectif_id  = 0;
492
-		$this->forme_juridique_code  = 0;
493
-		$this->tva_assuj = 1;
494
-		$this->status = 1;
495
-	}
496
-
497
-
498
-	/**
499
-	 *    Create third party in database.
500
-	 *    $this->code_client = -1 and $this->code_fournisseur = -1 means automatic assignement.
501
-	 *
502
-	 *    @param	User	$user       Object of user that ask creation
503
-	 *    @return   int         		>= 0 if OK, < 0 if KO
504
-	 */
505
-	function create(User $user)
506
-	{
507
-		global $langs,$conf,$mysoc;
508
-
509
-		$error=0;
510
-
511
-		// Clean parameters
512
-		if (empty($this->status)) $this->status=0;
513
-		$this->name=$this->name?trim($this->name):trim($this->nom);
514
-		if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name=ucwords($this->name);
515
-		$this->nom=$this->name; // For backward compatibility
516
-		if (empty($this->client))      $this->client=0;
517
-		if (empty($this->fournisseur)) $this->fournisseur=0;
518
-		$this->import_key = trim($this->import_key);
519
-
520
-		if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
521
-		if (empty($this->fk_multicurrency))
522
-		{
523
-			$this->multicurrency_code = '';
524
-			$this->fk_multicurrency = 0;
525
-		}
526
-
527
-		dol_syslog(get_class($this)."::create ".$this->name);
528
-
529
-		$now=dol_now();
530
-
531
-		$this->db->begin();
532
-
533
-		// For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
534
-		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this,0);
535
-		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1);
536
-
537
-		// Check more parameters (including mandatory setup
538
-		// If error, this->errors[] is filled
539
-		$result = $this->verify();
540
-
541
-		if ($result >= 0)
542
-		{
543
-			$this->entity = ((isset($this->entity) && is_numeric($this->entity))?$this->entity:$conf->entity);
544
-
545
-			$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, name_alias, entity, datec, fk_user_creat, canvas, status, ref_int, ref_ext, fk_stcomm, fk_incoterms, location_incoterms ,import_key, fk_multicurrency, multicurrency_code)";
546
-			$sql.= " VALUES ('".$this->db->escape($this->name)."', '".$this->db->escape($this->name_alias)."', ".$this->db->escape($this->entity).", '".$this->db->idate($now)."'";
547
-			$sql.= ", ".(! empty($user->id) ? "'".$user->id."'":"null");
548
-			$sql.= ", ".(! empty($this->canvas) ? "'".$this->db->escape($this->canvas)."'":"null");
549
-			$sql.= ", ".$this->status;
550
-			$sql.= ", ".(! empty($this->ref_int) ? "'".$this->db->escape($this->ref_int)."'":"null");
551
-			$sql.= ", ".(! empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'":"null");
552
-			$sql.= ", 0";
553
-			$sql.= ", ".(int) $this->fk_incoterms;
554
-			$sql.= ", '".$this->db->escape($this->location_incoterms)."'";
555
-			$sql.= ", ".(! empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'":"null");
556
-			$sql.= ", ".(int) $this->fk_multicurrency;
557
-			$sql.= ", '".$this->db->escape($this->multicurrency_code)."')";
558
-
559
-			dol_syslog(get_class($this)."::create", LOG_DEBUG);
560
-			$result=$this->db->query($sql);
561
-			if ($result)
562
-			{
563
-				$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe");
564
-
565
-				$ret = $this->update($this->id,$user,0,1,1,'add');
566
-
567
-				// Ajout du commercial affecte
568
-				if ($this->commercial_id != '' && $this->commercial_id != -1)
569
-				{
570
-					$this->add_commercial($user, $this->commercial_id);
571
-				}
572
-				// si un commercial cree un client il lui est affecte automatiquement
573
-				elseif (empty($user->rights->societe->client->voir))
574
-				{
575
-					$this->add_commercial($user, $user->id);
576
-				}
577
-
578
-				if ($ret >= 0)
579
-				{
580
-					// Call trigger
581
-					$result=$this->call_trigger('COMPANY_CREATE',$user);
582
-					if ($result < 0) $error++;
583
-					// End call triggers
584
-				}
585
-				else $error++;
586
-
587
-				if (! $error)
588
-				{
589
-					dol_syslog(get_class($this)."::Create success id=".$this->id);
590
-					$this->db->commit();
591
-					return $this->id;
592
-				}
593
-				else
594
-				{
595
-					dol_syslog(get_class($this)."::Create echec update ".$this->error." ".join(',',$this->errors), LOG_ERR);
596
-					$this->db->rollback();
597
-					return -4;
598
-				}
599
-			}
600
-			else
601
-			{
602
-				if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
603
-				{
604
-					$this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->name);    // duplicate on a field (code or profid or ...)
605
-					$result=-1;
606
-				}
607
-				else
608
-				{
609
-					$this->error=$this->db->lasterror();
610
-					$result=-2;
611
-				}
612
-				$this->db->rollback();
613
-				return $result;
614
-			}
615
-		}
616
-		else
617
-		{
618
-			$this->db->rollback();
619
-			dol_syslog(get_class($this)."::Create fails verify ".join(',',$this->errors), LOG_WARNING);
620
-			return -3;
621
-		}
622
-	}
470
+    public $fk_multicurrency;
471
+
472
+    public $multicurrency_code;
473
+
474
+
475
+    // END MODULEBUILDER PROPERTIES
476
+
477
+
478
+    /**
479
+     *    Constructor
480
+     *
481
+     *    @param	DoliDB		$db		Database handler
482
+     */
483
+    public function __construct($db)
484
+    {
485
+        $this->db = $db;
486
+
487
+        $this->client = 0;
488
+        $this->prospect = 0;
489
+        $this->fournisseur = 0;
490
+        $this->typent_id  = 0;
491
+        $this->effectif_id  = 0;
492
+        $this->forme_juridique_code  = 0;
493
+        $this->tva_assuj = 1;
494
+        $this->status = 1;
495
+    }
496
+
497
+
498
+    /**
499
+     *    Create third party in database.
500
+     *    $this->code_client = -1 and $this->code_fournisseur = -1 means automatic assignement.
501
+     *
502
+     *    @param	User	$user       Object of user that ask creation
503
+     *    @return   int         		>= 0 if OK, < 0 if KO
504
+     */
505
+    function create(User $user)
506
+    {
507
+        global $langs,$conf,$mysoc;
508
+
509
+        $error=0;
510
+
511
+        // Clean parameters
512
+        if (empty($this->status)) $this->status=0;
513
+        $this->name=$this->name?trim($this->name):trim($this->nom);
514
+        if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name=ucwords($this->name);
515
+        $this->nom=$this->name; // For backward compatibility
516
+        if (empty($this->client))      $this->client=0;
517
+        if (empty($this->fournisseur)) $this->fournisseur=0;
518
+        $this->import_key = trim($this->import_key);
519
+
520
+        if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
521
+        if (empty($this->fk_multicurrency))
522
+        {
523
+            $this->multicurrency_code = '';
524
+            $this->fk_multicurrency = 0;
525
+        }
526
+
527
+        dol_syslog(get_class($this)."::create ".$this->name);
528
+
529
+        $now=dol_now();
530
+
531
+        $this->db->begin();
532
+
533
+        // For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
534
+        if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this,0);
535
+        if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1);
536
+
537
+        // Check more parameters (including mandatory setup
538
+        // If error, this->errors[] is filled
539
+        $result = $this->verify();
540
+
541
+        if ($result >= 0)
542
+        {
543
+            $this->entity = ((isset($this->entity) && is_numeric($this->entity))?$this->entity:$conf->entity);
544
+
545
+            $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, name_alias, entity, datec, fk_user_creat, canvas, status, ref_int, ref_ext, fk_stcomm, fk_incoterms, location_incoterms ,import_key, fk_multicurrency, multicurrency_code)";
546
+            $sql.= " VALUES ('".$this->db->escape($this->name)."', '".$this->db->escape($this->name_alias)."', ".$this->db->escape($this->entity).", '".$this->db->idate($now)."'";
547
+            $sql.= ", ".(! empty($user->id) ? "'".$user->id."'":"null");
548
+            $sql.= ", ".(! empty($this->canvas) ? "'".$this->db->escape($this->canvas)."'":"null");
549
+            $sql.= ", ".$this->status;
550
+            $sql.= ", ".(! empty($this->ref_int) ? "'".$this->db->escape($this->ref_int)."'":"null");
551
+            $sql.= ", ".(! empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'":"null");
552
+            $sql.= ", 0";
553
+            $sql.= ", ".(int) $this->fk_incoterms;
554
+            $sql.= ", '".$this->db->escape($this->location_incoterms)."'";
555
+            $sql.= ", ".(! empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'":"null");
556
+            $sql.= ", ".(int) $this->fk_multicurrency;
557
+            $sql.= ", '".$this->db->escape($this->multicurrency_code)."')";
558
+
559
+            dol_syslog(get_class($this)."::create", LOG_DEBUG);
560
+            $result=$this->db->query($sql);
561
+            if ($result)
562
+            {
563
+                $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe");
564
+
565
+                $ret = $this->update($this->id,$user,0,1,1,'add');
566
+
567
+                // Ajout du commercial affecte
568
+                if ($this->commercial_id != '' && $this->commercial_id != -1)
569
+                {
570
+                    $this->add_commercial($user, $this->commercial_id);
571
+                }
572
+                // si un commercial cree un client il lui est affecte automatiquement
573
+                elseif (empty($user->rights->societe->client->voir))
574
+                {
575
+                    $this->add_commercial($user, $user->id);
576
+                }
577
+
578
+                if ($ret >= 0)
579
+                {
580
+                    // Call trigger
581
+                    $result=$this->call_trigger('COMPANY_CREATE',$user);
582
+                    if ($result < 0) $error++;
583
+                    // End call triggers
584
+                }
585
+                else $error++;
586
+
587
+                if (! $error)
588
+                {
589
+                    dol_syslog(get_class($this)."::Create success id=".$this->id);
590
+                    $this->db->commit();
591
+                    return $this->id;
592
+                }
593
+                else
594
+                {
595
+                    dol_syslog(get_class($this)."::Create echec update ".$this->error." ".join(',',$this->errors), LOG_ERR);
596
+                    $this->db->rollback();
597
+                    return -4;
598
+                }
599
+            }
600
+            else
601
+            {
602
+                if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
603
+                {
604
+                    $this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->name);    // duplicate on a field (code or profid or ...)
605
+                    $result=-1;
606
+                }
607
+                else
608
+                {
609
+                    $this->error=$this->db->lasterror();
610
+                    $result=-2;
611
+                }
612
+                $this->db->rollback();
613
+                return $result;
614
+            }
615
+        }
616
+        else
617
+        {
618
+            $this->db->rollback();
619
+            dol_syslog(get_class($this)."::Create fails verify ".join(',',$this->errors), LOG_WARNING);
620
+            return -3;
621
+        }
622
+    }
623 623
 
624 624
 
625 625
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
626
-	/**
627
-	 * Create a contact/address from thirdparty
628
-	 *
629
-	 * @param 	User	$user		Object user
630
-	 * @return 	int					<0 if KO, >0 if OK
631
-	 */
632
-	function create_individual(User $user)
633
-	{
626
+    /**
627
+     * Create a contact/address from thirdparty
628
+     *
629
+     * @param 	User	$user		Object user
630
+     * @return 	int					<0 if KO, >0 if OK
631
+     */
632
+    function create_individual(User $user)
633
+    {
634 634
         // phpcs:enable
635
-		require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
636
-		$contact=new Contact($this->db);
637
-
638
-		$contact->name              = $this->name_bis;
639
-		$contact->firstname         = $this->firstname;
640
-		$contact->civility_id       = $this->civility_id;
641
-		$contact->socid             = $this->id;	// fk_soc
642
-		$contact->statut            = 1;
643
-		$contact->priv              = 0;
644
-		$contact->country_id        = $this->country_id;
645
-		$contact->state_id          = $this->state_id;
646
-		$contact->address           = $this->address;
647
-		$contact->email             = $this->email;
648
-		$contact->zip               = $this->zip;
649
-		$contact->town              = $this->town;
650
-		$contact->phone_pro         = $this->phone;
651
-
652
-		$result = $contact->create($user);
653
-		if ($result < 0)
654
-		{
655
-			$this->error = $contact->error;
656
-			$this->errors = $contact->errors;
657
-			dol_syslog(get_class($this)."::create_individual ERROR:" . $this->error, LOG_ERR);
658
-		}
659
-
660
-		return $result;
661
-	}
662
-
663
-	/**
664
-	 *    Check properties of third party are ok (like name, third party codes, ...)
665
-	 *    Used before an add or update.
666
-	 *
667
-	 *    @return     int		0 if OK, <0 if KO
668
-	 */
669
-	function verify()
670
-	{
671
-		global $conf, $langs, $mysoc;
672
-
673
-		$error = 0;
674
-		$this->errors=array();
675
-
676
-		$result = 0;
677
-		$this->name	= trim($this->name);
678
-		$this->nom=$this->name; // For backward compatibility
679
-
680
-		if (! $this->name)
681
-		{
682
-			$this->errors[] = 'ErrorBadThirdPartyName';
683
-			$result = -2;
684
-		}
685
-
686
-		if ($this->client)
687
-		{
688
-			$rescode = $this->check_codeclient();
689
-			if ($rescode <> 0)
690
-			{
691
-				if ($rescode == -1)
692
-				{
693
-					$this->errors[] = 'ErrorBadCustomerCodeSyntax';
694
-				}
695
-				elseif ($rescode == -2)
696
-				{
697
-					$this->errors[] = 'ErrorCustomerCodeRequired';
698
-				}
699
-				elseif ($rescode == -3)
700
-				{
701
-					$this->errors[] = 'ErrorCustomerCodeAlreadyUsed';
702
-				}
703
-				elseif ($rescode == -4)
704
-				{
705
-					$this->errors[] = 'ErrorPrefixRequired';
706
-				}
707
-				$result = -3;
708
-			}
709
-		}
710
-
711
-		if ($this->fournisseur)
712
-		{
713
-			$rescode = $this->check_codefournisseur();
714
-			if ($rescode <> 0)
715
-			{
716
-				if ($rescode == -1)
717
-				{
718
-					$this->errors[] = 'ErrorBadSupplierCodeSyntax';
719
-				}
720
-				elseif ($rescode == -2)
721
-				{
722
-					$this->errors[] = 'ErrorSupplierCodeRequired';
723
-				}
724
-				elseif ($rescode == -3)
725
-				{
726
-					$this->errors[] = 'ErrorSupplierCodeAlreadyUsed';
727
-				}
728
-				elseif ($rescode == -5)
729
-				{
730
-					$this->errors[] = 'ErrorprefixRequired';
731
-				}
732
-				$result = -3;
733
-			}
734
-		}
735
-
736
-		// Check for duplicate or mandatory fields defined into setup
737
-		$array_to_check=array('IDPROF1','IDPROF2','IDPROF3','IDPROF4','IDPROF5','IDPROF6','EMAIL');
738
-		foreach($array_to_check as $key)
739
-		{
740
-			$keymin=strtolower($key);
741
-			$i=(int) preg_replace('/[^0-9]/','',$key);
742
-			$vallabel=$this->$keymin;
743
-
744
-			if ($i > 0)
745
-			{
746
-				if ($this->isACompany())
747
-				{
748
-					// Check for unicity
749
-					if ($vallabel && $this->id_prof_verifiable($i))
750
-					{
751
-						if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0)))
752
-						{
753
-							$langs->load("errors");
754
-							$error++; $this->errors[] = $langs->transcountry('ProfId'.$i, $this->country_code)." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')';
755
-						}
756
-					}
757
-
758
-					// Check for mandatory prof id (but only if country is other than ours)
759
-					if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id)
760
-					{
761
-						$idprof_mandatory ='SOCIETE_'.$key.'_MANDATORY';
762
-						if (! $vallabel && ! empty($conf->global->$idprof_mandatory))
763
-						{
764
-							$langs->load("errors");
765
-							$error++;
766
-							$this->errors[] = $langs->trans("ErrorProdIdIsMandatory", $langs->transcountry('ProfId'.$i, $this->country_code)).' ('.$langs->trans("ForbiddenBySetupRules").')';
767
-						}
768
-					}
769
-				}
770
-			}
771
-			else
772
-			{
773
-				//var_dump($conf->global->SOCIETE_EMAIL_UNIQUE);
774
-				//var_dump($conf->global->SOCIETE_EMAIL_MANDATORY);
775
-				if ($key == 'EMAIL')
776
-				{
777
-					// Check for unicity
778
-					if ($vallabel && ! empty($conf->global->SOCIETE_EMAIL_UNIQUE))
779
-					{
780
-						if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0)))
781
-						{
782
-							$langs->load("errors");
783
-							$error++; $this->errors[] = $langs->trans('Email')." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')';
784
-						}
785
-					}
786
-
787
-					// Check for mandatory
788
-					if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY) && ! isValidEMail($this->email))
789
-					{
790
-						$langs->load("errors");
791
-						$error++;
792
-						$this->errors[] = $langs->trans("ErrorBadEMail", $this->email).' ('.$langs->trans("ForbiddenBySetupRules").')';
793
-					}
794
-				}
795
-			}
796
-		}
797
-
798
-		if ($error) $result = -4;
799
-
800
-		return $result;
801
-	}
802
-
803
-	/**
804
-	 *      Update parameters of third party
805
-	 *
806
-	 *      @param	int		$id              			Id of company (deprecated, use 0 here and call update on an object loaded by a fetch)
807
-	 *      @param  User	$user            			Utilisateur qui demande la mise a jour
808
-	 *      @param  int		$call_trigger    			0=no, 1=yes
809
-	 *		@param	int		$allowmodcodeclient			Inclut modif code client et code compta
810
-	 *		@param	int		$allowmodcodefournisseur	Inclut modif code fournisseur et code compta fournisseur
811
-	 *		@param	string	$action						'add' or 'update' or 'merge'
812
-	 *		@param	int		$nosyncmember				Do not synchronize info of linked member
813
-	 *      @return int  			           			<0 if KO, >=0 if OK
814
-	 */
815
-	function update($id, $user='', $call_trigger=1, $allowmodcodeclient=0, $allowmodcodefournisseur=0, $action='update', $nosyncmember=1)
816
-	{
817
-		global $langs,$conf,$hookmanager;
818
-
819
-		require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
820
-
821
-		if (empty($id)) $id = $this->id;
822
-
823
-		$error=0;
824
-
825
-		dol_syslog(get_class($this)."::Update id=".$id." call_trigger=".$call_trigger." allowmodcodeclient=".$allowmodcodeclient." allowmodcodefournisseur=".$allowmodcodefournisseur);
826
-
827
-		$now=dol_now();
828
-
829
-		// Clean parameters
830
-		$this->id			= $id;
831
-		$this->entity		= ((isset($this->entity) && is_numeric($this->entity))?$this->entity:$conf->entity);
832
-		$this->name			= $this->name?trim($this->name):trim($this->nom);
833
-		$this->nom			= $this->name;	// For backward compatibility
834
-		$this->name_alias	= trim($this->name_alias);
835
-		$this->ref_ext		= trim($this->ref_ext);
836
-		$this->address		= $this->address?trim($this->address):trim($this->address);
837
-		$this->zip			= $this->zip?trim($this->zip):trim($this->zip);
838
-		$this->town			= $this->town?trim($this->town):trim($this->town);
839
-		$this->state_id		= trim($this->state_id);
840
-		$this->country_id	= ($this->country_id > 0)?$this->country_id:0;
841
-		$this->phone		= trim($this->phone);
842
-		$this->phone		= preg_replace("/\s/","",$this->phone);
843
-		$this->phone		= preg_replace("/\./","",$this->phone);
844
-		$this->fax			= trim($this->fax);
845
-		$this->fax			= preg_replace("/\s/","",$this->fax);
846
-		$this->fax			= preg_replace("/\./","",$this->fax);
847
-		$this->email		= trim($this->email);
848
-		$this->skype		= trim($this->skype);
849
-		$this->twitter		= trim($this->twitter);
850
-		$this->facebook		= trim($this->facebook);
851
-		$this->url			= $this->url?clean_url($this->url,0):'';
852
-		$this->note_private = trim($this->note_private);
853
-		$this->note_public  = trim($this->note_public);
854
-		$this->idprof1		= trim($this->idprof1);
855
-		$this->idprof2		= trim($this->idprof2);
856
-		$this->idprof3		= trim($this->idprof3);
857
-		$this->idprof4		= trim($this->idprof4);
858
-		$this->idprof5		= (! empty($this->idprof5)?trim($this->idprof5):'');
859
-		$this->idprof6		= (! empty($this->idprof6)?trim($this->idprof6):'');
860
-		$this->prefix_comm	= trim($this->prefix_comm);
861
-		$this->outstanding_limit = price2num($this->outstanding_limit);
862
-		$this->order_min_amount = price2num($this->order_min_amount);
863
-		$this->supplier_order_min_amount = price2num($this->supplier_order_min_amount);
864
-
865
-		$this->tva_assuj	= trim($this->tva_assuj);
866
-		$this->tva_intra	= dol_sanitizeFileName($this->tva_intra,'');
867
-		if (empty($this->status)) $this->status = 0;
868
-
869
-		if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
870
-		if (empty($this->fk_multicurrency))
871
-		{
872
-			$this->multicurrency_code = '';
873
-			$this->fk_multicurrency = 0;
874
-		}
875
-
876
-		// Local taxes
877
-		$this->localtax1_assuj=trim($this->localtax1_assuj);
878
-		$this->localtax2_assuj=trim($this->localtax2_assuj);
879
-
880
-		$this->localtax1_value=trim($this->localtax1_value);
881
-		$this->localtax2_value=trim($this->localtax2_value);
882
-
883
-		if ($this->capital != '') $this->capital=price2num(trim($this->capital));
884
-		if (! is_numeric($this->capital)) $this->capital = '';     // '' = undef
885
-
886
-		$this->effectif_id=trim($this->effectif_id);
887
-		$this->forme_juridique_code=trim($this->forme_juridique_code);
888
-
889
-		//Gencod
890
-		$this->barcode=trim($this->barcode);
891
-
892
-		// For automatic creation
893
-		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this,0);
894
-		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1);
895
-
896
-		$this->code_compta=trim($this->code_compta);
897
-		$this->code_compta_fournisseur=trim($this->code_compta_fournisseur);
898
-
899
-		// Check parameters. More tests are done later in the ->verify()
900
-		if (! is_numeric($this->client) && ! is_numeric($this->fournisseur))
901
-		{
902
-			$langs->load("errors");
903
-			$this->error = $langs->trans("BadValueForParameterClientOrSupplier");
904
-			return -1;
905
-		}
906
-
907
-		$customer=false;
908
-		if (! empty($allowmodcodeclient) && ! empty($this->client))
909
-		{
910
-			// Attention get_codecompta peut modifier le code suivant le module utilise
911
-			if (empty($this->code_compta))
912
-			{
913
-				$ret=$this->get_codecompta('customer');
914
-				if ($ret < 0) return -1;
915
-			}
916
-
917
-			$customer=true;
918
-		}
919
-
920
-		$supplier=false;
921
-		if (! empty($allowmodcodefournisseur) && ! empty($this->fournisseur))
922
-		{
923
-			// Attention get_codecompta peut modifier le code suivant le module utilise
924
-			if (empty($this->code_compta_fournisseur))
925
-			{
926
-				$ret=$this->get_codecompta('supplier');
927
-				if ($ret < 0) return -1;
928
-			}
929
-
930
-			$supplier=true;
931
-		}
932
-
933
-		//Web services
934
-		$this->webservices_url = $this->webservices_url?clean_url($this->webservices_url,0):'';
935
-		$this->webservices_key = trim($this->webservices_key);
936
-
937
-		//Incoterms
938
-		$this->fk_incoterms = (int) $this->fk_incoterms;
939
-		$this->location_incoterms = trim($this->location_incoterms);
940
-
941
-		$this->db->begin();
942
-
943
-		// Check name is required and codes are ok or unique.
944
-		// If error, this->errors[] is filled
945
-		$result = 0;
946
-		if ($action != 'add' && $action != 'merge')
947
-		{
948
-			// We don't check when update called during a create because verify was already done.
949
-			// For a merge, we suppose source data is clean and a customer code of a deleted thirdparty must be accepted into a target thirdparty with empty code without duplicate error
950
-			$result = $this->verify();
951
-
952
-			// If there is only one error and error is ErrorBadCustomerCodeSyntax and we don't change customer code, we allow the update
953
-			// So we can update record that were using and old numbering rule.
954
-			if (is_array($this->errors))
955
-			{
956
-				if (in_array('ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client)
957
-				{
958
-					if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]);	// Remove error message
959
-				}
960
-				if (in_array('ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur)
961
-				{
962
-					if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]);	// Remove error message
963
-				}
964
-				if (empty($this->errors))	// If there is no more error, we can make like if there is no error at all
965
-				{
966
-					$result = 0;
967
-				}
968
-			}
969
-		}
970
-
971
-		if ($result >= 0)
972
-		{
973
-			dol_syslog(get_class($this)."::update verify ok or not done");
974
-
975
-			$sql  = "UPDATE ".MAIN_DB_PREFIX."societe SET ";
976
-			$sql .= "entity = " . $this->db->escape($this->entity);
977
-			$sql .= ",nom = '" . $this->db->escape($this->name) ."'"; // Required
978
-			$sql .= ",name_alias = '" . $this->db->escape($this->name_alias) ."'";
979
-			$sql .= ",ref_ext = " .(! empty($this->ref_ext)?"'".$this->db->escape($this->ref_ext) ."'":"null");
980
-			$sql .= ",address = '" . $this->db->escape($this->address) ."'";
981
-
982
-			$sql .= ",zip = ".(! empty($this->zip)?"'".$this->db->escape($this->zip)."'":"null");
983
-			$sql .= ",town = ".(! empty($this->town)?"'".$this->db->escape($this->town)."'":"null");
984
-
985
-			$sql .= ",fk_departement = '" . (! empty($this->state_id)?$this->state_id:'0') ."'";
986
-			$sql .= ",fk_pays = '" . (! empty($this->country_id)?$this->country_id:'0') ."'";
987
-
988
-			$sql .= ",phone = ".(! empty($this->phone)?"'".$this->db->escape($this->phone)."'":"null");
989
-			$sql .= ",fax = ".(! empty($this->fax)?"'".$this->db->escape($this->fax)."'":"null");
990
-			$sql .= ",email = ".(! empty($this->email)?"'".$this->db->escape($this->email)."'":"null");
991
-			$sql .= ",skype = ".(! empty($this->skype)?"'".$this->db->escape($this->skype)."'":"null");
992
-			$sql .= ",twitter = ".(! empty($this->twitter)?"'".$this->db->escape($this->twitter)."'":"null");
993
-			$sql .= ",facebook = ".(! empty($this->facebook)?"'".$this->db->escape($this->facebook)."'":"null");
994
-			$sql .= ",url = ".(! empty($this->url)?"'".$this->db->escape($this->url)."'":"null");
995
-
996
-			$sql .= ",parent = " . ($this->parent > 0 ? $this->parent : "null");
997
-
998
-			$sql .= ",note_private = ".(! empty($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null");
999
-			$sql .= ",note_public = ".(! empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null");
1000
-
1001
-			$sql .= ",siren   = '". $this->db->escape($this->idprof1) ."'";
1002
-			$sql .= ",siret   = '". $this->db->escape($this->idprof2) ."'";
1003
-			$sql .= ",ape     = '". $this->db->escape($this->idprof3) ."'";
1004
-			$sql .= ",idprof4 = '". $this->db->escape($this->idprof4) ."'";
1005
-			$sql .= ",idprof5 = '". $this->db->escape($this->idprof5) ."'";
1006
-			$sql .= ",idprof6 = '". $this->db->escape($this->idprof6) ."'";
1007
-
1008
-			$sql .= ",tva_assuj = ".($this->tva_assuj!=''?"'".$this->db->escape($this->tva_assuj)."'":"null");
1009
-			$sql .= ",tva_intra = '" . $this->db->escape($this->tva_intra) ."'";
1010
-			$sql .= ",status = " .$this->status;
1011
-
1012
-			// Local taxes
1013
-			$sql .= ",localtax1_assuj = ".($this->localtax1_assuj!=''?"'".$this->db->escape($this->localtax1_assuj)."'":"null");
1014
-			$sql .= ",localtax2_assuj = ".($this->localtax2_assuj!=''?"'".$this->db->escape($this->localtax2_assuj)."'":"null");
1015
-			if($this->localtax1_assuj==1)
1016
-			{
1017
-				if($this->localtax1_value!='')
1018
-				{
1019
-					$sql .=",localtax1_value =".$this->localtax1_value;
1020
-				}
1021
-				else $sql .=",localtax1_value =0.000";
1022
-			}
1023
-			else $sql .=",localtax1_value =0.000";
1024
-
1025
-			if($this->localtax2_assuj==1)
1026
-			{
1027
-				if($this->localtax2_value!='')
1028
-				{
1029
-					$sql .=",localtax2_value =".$this->localtax2_value;
1030
-				}
1031
-				else $sql .=",localtax2_value =0.000";
1032
-			}
1033
-			else $sql .=",localtax2_value =0.000";
1034
-
1035
-			$sql .= ",capital = ".($this->capital == '' ? "null" : $this->capital);
1036
-
1037
-			$sql .= ",prefix_comm = ".(! empty($this->prefix_comm)?"'".$this->db->escape($this->prefix_comm)."'":"null");
1038
-
1039
-			$sql .= ",fk_effectif = ".(! empty($this->effectif_id)?"'".$this->db->escape($this->effectif_id)."'":"null");
1040
-			if (isset($this->stcomm_id))
1041
-			{
1042
-				$sql .= ",fk_stcomm=".(!empty($this->stcomm_id)  ? $this->stcomm_id : "0");
1043
-			}
1044
-			$sql .= ",fk_typent = ".(! empty($this->typent_id)?"'".$this->db->escape($this->typent_id)."'":"0");
1045
-
1046
-			$sql .= ",fk_forme_juridique = ".(! empty($this->forme_juridique_code)?"'".$this->db->escape($this->forme_juridique_code)."'":"null");
1047
-
1048
-			$sql .= ",mode_reglement = ".(! empty($this->mode_reglement_id)?"'".$this->db->escape($this->mode_reglement_id)."'":"null");
1049
-			$sql .= ",cond_reglement = ".(! empty($this->cond_reglement_id)?"'".$this->db->escape($this->cond_reglement_id)."'":"null");
1050
-			$sql .= ",mode_reglement_supplier = ".(! empty($this->mode_reglement_supplier_id)?"'".$this->db->escape($this->mode_reglement_supplier_id)."'":"null");
1051
-			$sql .= ",cond_reglement_supplier = ".(! empty($this->cond_reglement_supplier_id)?"'".$this->db->escape($this->cond_reglement_supplier_id)."'":"null");
1052
-			$sql .= ",fk_shipping_method = ".(! empty($this->shipping_method_id)?"'".$this->db->escape($this->shipping_method_id)."'":"null");
1053
-
1054
-			$sql .= ",client = " . (! empty($this->client)?$this->client:0);
1055
-			$sql .= ",fournisseur = " . (! empty($this->fournisseur)?$this->fournisseur:0);
1056
-			$sql .= ",barcode = ".(! empty($this->barcode)?"'".$this->db->escape($this->barcode)."'":"null");
1057
-			$sql .= ",default_lang = ".(! empty($this->default_lang)?"'".$this->db->escape($this->default_lang)."'":"null");
1058
-			$sql .= ",logo = ".(! empty($this->logo)?"'".$this->db->escape($this->logo)."'":"null");
1059
-			$sql .= ",outstanding_limit= ".($this->outstanding_limit!=''?$this->outstanding_limit:'null');
1060
-			$sql .= ",order_min_amount= ".($this->order_min_amount!=''?$this->order_min_amount:'null');
1061
-			$sql .= ",supplier_order_min_amount= ".($this->supplier_order_min_amount!=''?$this->supplier_order_min_amount:'null');
1062
-			$sql .= ",fk_prospectlevel='".$this->db->escape($this->fk_prospectlevel)."'";
1063
-
1064
-			$sql .= ",webservices_url = ".(! empty($this->webservices_url)?"'".$this->db->escape($this->webservices_url)."'":"null");
1065
-			$sql .= ",webservices_key = ".(! empty($this->webservices_key)?"'".$this->db->escape($this->webservices_key)."'":"null");
1066
-
1067
-			//Incoterms
1068
-			$sql.= ", fk_incoterms = ".$this->fk_incoterms;
1069
-			$sql.= ", location_incoterms = ".(! empty($this->location_incoterms)?"'".$this->db->escape($this->location_incoterms)."'":"null");
1070
-
1071
-			if ($customer)
1072
-			{
1073
-				$sql .= ", code_client = ".(! empty($this->code_client)?"'".$this->db->escape($this->code_client)."'":"null");
1074
-				$sql .= ", code_compta = ".(! empty($this->code_compta)?"'".$this->db->escape($this->code_compta)."'":"null");
1075
-			}
1076
-
1077
-			if ($supplier)
1078
-			{
1079
-				$sql .= ", code_fournisseur = ".(! empty($this->code_fournisseur)?"'".$this->db->escape($this->code_fournisseur)."'":"null");
1080
-				$sql .= ", code_compta_fournisseur = ".(! empty($this->code_compta_fournisseur)?"'".$this->db->escape($this->code_compta_fournisseur)."'":"null");
1081
-			}
1082
-			$sql .= ", fk_user_modif = ".($user->id > 0 ? $user->id:"null");
1083
-			$sql .= ", fk_multicurrency = ".(int) $this->fk_multicurrency;
1084
-			$sql .= ", multicurrency_code = '".$this->db->escape($this->multicurrency_code)."'";
1085
-			$sql .= " WHERE rowid = " . (int) $id;
1086
-
1087
-			$resql=$this->db->query($sql);
1088
-			if ($resql)
1089
-			{
1090
-				if (is_object($this->oldcopy))	// If we have information on old values
1091
-				{
1092
-					if ($this->oldcopy->country_id != $this->country_id)
1093
-					{
1094
-						unset($this->country_code);
1095
-						unset($this->country);
1096
-					}
1097
-					if ($this->oldcopy->state_id != $this->state_id)
1098
-					{
1099
-						unset($this->state_code);
1100
-						unset($this->state);
1101
-					}
1102
-				}
1103
-				else
1104
-				{
1105
-					unset($this->country_code);	// We clean this, in the doubt, because it may have been changed after an update of country_id
1106
-					unset($this->country);
1107
-					unset($this->state_code);
1108
-					unset($this->state);
1109
-				}
1110
-
1111
-				$nbrowsaffected = $this->db->affected_rows($resql);
1112
-
1113
-				if (! $error && $nbrowsaffected)
1114
-				{
1115
-					// Update information on linked member if it is an update
1116
-					if (! $nosyncmember && ! empty($conf->adherent->enabled))
1117
-					{
1118
-						require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
1119
-
1120
-						dol_syslog(get_class($this)."::update update linked member");
1121
-
1122
-						$lmember=new Adherent($this->db);
1123
-						$result=$lmember->fetch(0, 0, $this->id);
1124
-
1125
-						if ($result > 0)
1126
-						{
1127
-							$lmember->societe=$this->name;
1128
-							//$lmember->firstname=$this->firstname?$this->firstname:$lmember->firstname;	// We keep firstname and lastname of member unchanged
1129
-							//$lmember->lastname=$this->lastname?$this->lastname:$lmember->lastname;		// We keep firstname and lastname of member unchanged
1130
-							$lmember->address=$this->address;
1131
-							$lmember->email=$this->email;
1132
-							$lmember->skype=$this->skype;
1133
-							$lmember->twitter=$this->twitter;
1134
-							$lmember->facebook=$this->facebook;
1135
-							$lmember->phone=$this->phone;
1136
-
1137
-							$result=$lmember->update($user,0,1,1,1);	// Use nosync to 1 to avoid cyclic updates
1138
-							if ($result < 0)
1139
-							{
1140
-								$this->error=$lmember->error;
1141
-								dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
1142
-								$error++;
1143
-							}
1144
-						}
1145
-						elseif ($result < 0)
1146
-						{
1147
-							$this->error=$lmember->error;
1148
-							$error++;
1149
-						}
1150
-					}
1151
-				}
1152
-
1153
-				$action='update';
1154
-
1155
-				// Actions on extra fields
1156
-				if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1157
-				{
1158
-					$result=$this->insertExtraFields();
1159
-					if ($result < 0)
1160
-					{
1161
-						$error++;
1162
-					}
1163
-				}
1164
-
1165
-				if (! $error && $call_trigger)
1166
-				{
1167
-					// Call trigger
1168
-					$result=$this->call_trigger('COMPANY_MODIFY',$user);
1169
-					if ($result < 0) $error++;
1170
-					// End call triggers
1171
-				}
1172
-
1173
-				if (! $error)
1174
-				{
1175
-					dol_syslog(get_class($this)."::Update success");
1176
-					$this->db->commit();
1177
-					return 1;
1178
-				}
1179
-				else
1180
-				{
1181
-					$this->db->rollback();
1182
-					return -1;
1183
-				}
1184
-			}
1185
-			else
1186
-			{
1187
-				if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
1188
-				{
1189
-					// Doublon
1190
-					$this->error = $langs->trans("ErrorDuplicateField");
1191
-					$result = -1;
1192
-				}
1193
-				else
1194
-				{
1195
-					$this->error = $this->db->lasterror();
1196
-					$result = -2;
1197
-				}
1198
-				$this->db->rollback();
1199
-				return $result;
1200
-			}
1201
-		}
1202
-		else
1203
-	   {
1204
-			$this->db->rollback();
1205
-			dol_syslog(get_class($this)."::Update fails verify ".join(',',$this->errors), LOG_WARNING);
1206
-			return -3;
1207
-		}
1208
-	}
1209
-
1210
-	/**
1211
-	 *    Load a third party from database into memory
1212
-	 *
1213
-	 *    @param	int		$rowid			Id of third party to load
1214
-	 *    @param    string	$ref			Reference of third party, name (Warning, this can return several records)
1215
-	 *    @param    string	$ref_ext       	External reference of third party (Warning, this information is a free field not provided by Dolibarr)
1216
-	 *    @param    string	$ref_int       	Internal reference of third party (not used by dolibarr)
1217
-	 *    @param    string	$idprof1		Prof id 1 of third party (Warning, this can return several records)
1218
-	 *    @param    string	$idprof2		Prof id 2 of third party (Warning, this can return several records)
1219
-	 *    @param    string	$idprof3		Prof id 3 of third party (Warning, this can return several records)
1220
-	 *    @param    string	$idprof4		Prof id 4 of third party (Warning, this can return several records)
1221
-	 *    @param    string	$idprof5		Prof id 5 of third party (Warning, this can return several records)
1222
-	 *    @param    string	$idprof6		Prof id 6 of third party (Warning, this can return several records)
1223
-	 *    @param    string	$email   		Email of third party (Warning, this can return several records)
1224
-	 *    @param    string	$ref_alias 		Name_alias of third party (Warning, this can return several records)
1225
-	 *    @return   int						>0 if OK, <0 if KO or if two records found for same ref or idprof, 0 if not found.
1226
-	 */
1227
-	function fetch($rowid, $ref='', $ref_ext='', $ref_int='', $idprof1='',$idprof2='',$idprof3='',$idprof4='',$idprof5='',$idprof6='', $email='', $ref_alias='')
1228
-	{
1229
-		global $langs;
1230
-		global $conf;
1231
-
1232
-		if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($ref_int) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) return -1;
1233
-
1234
-		$sql = 'SELECT s.rowid, s.nom as name, s.name_alias, s.entity, s.ref_ext, s.ref_int, s.address, s.datec as date_creation, s.prefix_comm';
1235
-		$sql .= ', s.status';
1236
-		$sql .= ', s.price_level';
1237
-		$sql .= ', s.tms as date_modification, s.fk_user_creat, s.fk_user_modif';
1238
-		$sql .= ', s.phone, s.fax, s.email, s.skype, s.twitter, s.facebook, s.url, s.zip, s.town, s.note_private, s.note_public, s.model_pdf, s.client, s.fournisseur';
1239
-		$sql .= ', s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6';
1240
-		$sql .= ', s.capital, s.tva_intra';
1241
-		$sql .= ', s.fk_typent as typent_id';
1242
-		$sql .= ', s.fk_effectif as effectif_id';
1243
-		$sql .= ', s.fk_forme_juridique as forme_juridique_code';
1244
-		$sql .= ', s.webservices_url, s.webservices_key';
1245
-		$sql .= ', s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur, s.parent, s.barcode';
1246
-		$sql .= ', s.fk_departement, s.fk_pays as country_id, s.fk_stcomm, s.remise_client, s.remise_supplier, s.mode_reglement, s.cond_reglement, s.fk_account, s.tva_assuj';
1247
-		$sql .= ', s.mode_reglement_supplier, s.cond_reglement_supplier, s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo';
1248
-		$sql .= ', s.fk_shipping_method';
1249
-		$sql .= ', s.outstanding_limit, s.import_key, s.canvas, s.fk_incoterms, s.location_incoterms';
1250
-		$sql .= ', s.order_min_amount, s.supplier_order_min_amount';
1251
-		$sql .= ', s.fk_multicurrency, s.multicurrency_code';
1252
-		$sql .= ', fj.libelle as forme_juridique';
1253
-		$sql .= ', e.libelle as effectif';
1254
-		$sql .= ', c.code as country_code, c.label as country';
1255
-		$sql .= ', d.code_departement as state_code, d.nom as state';
1256
-		$sql .= ', st.libelle as stcomm';
1257
-		$sql .= ', te.code as typent_code';
1258
-		$sql .= ', i.libelle as libelle_incoterms';
1259
-		$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
1260
-		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as e ON s.fk_effectif = e.id';
1261
-		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
1262
-		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id';
1263
-		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code';
1264
-		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
1265
-		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as te ON s.fk_typent = te.id';
1266
-		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON s.fk_incoterms = i.rowid';
1267
-
1268
-		$sql .= ' WHERE s.entity IN ('.getEntity($this->element).')';
1269
-		if ($rowid)     $sql .= ' AND s.rowid = '.$rowid;
1270
-		if ($ref)       $sql .= " AND s.nom = '".$this->db->escape($ref)."'";
1271
-		if ($ref_alias) $sql .= " AND s.nom_alias = '".$this->db->escape($ref_alias)."'";
1272
-		if ($ref_ext)   $sql .= " AND s.ref_ext = '".$this->db->escape($ref_ext)."'";
1273
-		if ($ref_int)   $sql .= " AND s.ref_int = '".$this->db->escape($ref_int)."'";
1274
-		if ($idprof1)   $sql .= " AND s.siren = '".$this->db->escape($idprof1)."'";
1275
-		if ($idprof2)   $sql .= " AND s.siret = '".$this->db->escape($idprof2)."'";
1276
-		if ($idprof3)   $sql .= " AND s.ape = '".$this->db->escape($idprof3)."'";
1277
-		if ($idprof4)   $sql .= " AND s.idprof4 = '".$this->db->escape($idprof4)."'";
1278
-		if ($idprof5)   $sql .= " AND s.idprof5 = '".$this->db->escape($idprof5)."'";
1279
-		if ($idprof6)   $sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'";
1280
-		if ($email)     $sql .= " AND s.email = '".$this->db->escape($email)."'";
1281
-
1282
-		$resql=$this->db->query($sql);
1283
-		if ($resql)
1284
-		{
1285
-			$num=$this->db->num_rows($resql);
1286
-			if ($num > 1)
1287
-			{
1288
-				$this->error='Fetch found several records. Rename one of tirdparties to avoid duplicate.';
1289
-				dol_syslog($this->error, LOG_ERR);
1290
-				$result = -2;
1291
-			}
1292
-			elseif ($num)   // $num = 1
1293
-			{
1294
-				$obj = $this->db->fetch_object($resql);
1295
-
1296
-				$this->id           = $obj->rowid;
1297
-				$this->entity       = $obj->entity;
1298
-				$this->canvas		= $obj->canvas;
1299
-
1300
-				$this->ref          = $obj->rowid;
1301
-				$this->name 		= $obj->name;
1302
-				$this->nom          = $obj->name;		// deprecated
1303
-				$this->name_alias = $obj->name_alias;
1304
-				$this->ref_ext      = $obj->ref_ext;
1305
-				$this->ref_int      = $obj->ref_int;
1306
-
1307
-				$this->date_creation     = $this->db->jdate($obj->date_creation);
1308
-				$this->date_modification = $this->db->jdate($obj->date_modification);
1309
-				$this->user_creation     = $obj->fk_user_creat;
1310
-				$this->user_modification = $obj->fk_user_modif;
1311
-
1312
-				$this->address 		= $obj->address;
1313
-				$this->zip 			= $obj->zip;
1314
-				$this->town 		= $obj->town;
1315
-
1316
-				$this->country_id   = $obj->country_id;
1317
-				$this->country_code = $obj->country_id?$obj->country_code:'';
1318
-				$this->country 		= $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->transnoentities('Country'.$obj->country_code):$obj->country):'';
1319
-
1320
-				$this->state_id     = $obj->fk_departement;
1321
-				$this->state_code   = $obj->state_code;
1322
-				$this->state        = ($obj->state!='-'?$obj->state:'');
1323
-
1324
-				$transcode=$langs->trans('StatusProspect'.$obj->fk_stcomm);
1325
-				$libelle=($transcode!='StatusProspect'.$obj->fk_stcomm?$transcode:$obj->stcomm);
1326
-				$this->stcomm_id = $obj->fk_stcomm;     // id statut commercial
1327
-				$this->statut_commercial = $libelle;    // libelle statut commercial
1328
-
1329
-				$this->email = $obj->email;
1330
-				$this->skype = $obj->skype;
1331
-				$this->twitter = $obj->twitter;
1332
-				$this->facebook = $obj->facebook;
1333
-				$this->url = $obj->url;
1334
-				$this->phone = $obj->phone;
1335
-				$this->fax = $obj->fax;
1336
-
1337
-				$this->parent    = $obj->parent;
1338
-
1339
-				$this->idprof1		= $obj->idprof1;
1340
-				$this->idprof2		= $obj->idprof2;
1341
-				$this->idprof3		= $obj->idprof3;
1342
-				$this->idprof4		= $obj->idprof4;
1343
-				$this->idprof5		= $obj->idprof5;
1344
-				$this->idprof6		= $obj->idprof6;
1345
-
1346
-				$this->capital   = $obj->capital;
1347
-
1348
-				$this->code_client = $obj->code_client;
1349
-				$this->code_fournisseur = $obj->code_fournisseur;
1350
-
1351
-				$this->code_compta = $obj->code_compta;
1352
-				$this->code_compta_fournisseur = $obj->code_compta_fournisseur;
1353
-
1354
-				$this->barcode = $obj->barcode;
1355
-
1356
-				$this->tva_assuj      = $obj->tva_assuj;
1357
-				$this->tva_intra      = $obj->tva_intra;
1358
-				$this->status = $obj->status;
1359
-
1360
-				// Local Taxes
1361
-				$this->localtax1_assuj      = $obj->localtax1_assuj;
1362
-				$this->localtax2_assuj      = $obj->localtax2_assuj;
1363
-
1364
-				$this->localtax1_value		= $obj->localtax1_value;
1365
-				$this->localtax2_value		= $obj->localtax2_value;
1366
-
1367
-				$this->typent_id      = $obj->typent_id;
1368
-				$this->typent_code    = $obj->typent_code;
1369
-
1370
-				$this->effectif_id    = $obj->effectif_id;
1371
-				$this->effectif       = $obj->effectif_id?$obj->effectif:'';
1372
-
1373
-				$this->forme_juridique_code= $obj->forme_juridique_code;
1374
-				$this->forme_juridique     = $obj->forme_juridique_code?$obj->forme_juridique:'';
1375
-
1376
-				$this->fk_prospectlevel = $obj->fk_prospectlevel;
1377
-
1378
-				$this->prefix_comm = $obj->prefix_comm;
1379
-
1380
-				$this->remise_percent		= $obj->remise_client;
1381
-				$this->remise_supplier_percent		= $obj->remise_supplier;
1382
-				$this->mode_reglement_id 	= $obj->mode_reglement;
1383
-				$this->cond_reglement_id 	= $obj->cond_reglement;
1384
-				$this->mode_reglement_supplier_id 	= $obj->mode_reglement_supplier;
1385
-				$this->cond_reglement_supplier_id 	= $obj->cond_reglement_supplier;
1386
-				$this->shipping_method_id   = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null;
1387
-				$this->fk_account			= $obj->fk_account;
1388
-
1389
-				$this->client      = $obj->client;
1390
-				$this->fournisseur = $obj->fournisseur;
1391
-
1392
-				$this->note = $obj->note_private; // TODO Deprecated for backward comtability
1393
-				$this->note_private = $obj->note_private;
1394
-				$this->note_public = $obj->note_public;
1395
-				$this->modelpdf = $obj->model_pdf;
1396
-				$this->default_lang = $obj->default_lang;
1397
-				$this->logo = $obj->logo;
1398
-
1399
-				$this->webservices_url = $obj->webservices_url;
1400
-				$this->webservices_key = $obj->webservices_key;
1401
-
1402
-				$this->outstanding_limit		= $obj->outstanding_limit;
1403
-				$this->order_min_amount			= $obj->order_min_amount;
1404
-				$this->supplier_order_min_amount	= $obj->supplier_order_min_amount;
1405
-
1406
-				// multiprix
1407
-				$this->price_level = $obj->price_level;
1408
-
1409
-				$this->import_key = $obj->import_key;
1410
-
1411
-				//Incoterms
1412
-				$this->fk_incoterms = $obj->fk_incoterms;
1413
-				$this->location_incoterms = $obj->location_incoterms;
1414
-				$this->libelle_incoterms = $obj->libelle_incoterms;
1415
-
1416
-				// multicurrency
1417
-				$this->fk_multicurrency = $obj->fk_multicurrency;
1418
-				$this->multicurrency_code = $obj->multicurrency_code;
1419
-
1420
-				$result = 1;
1421
-
1422
-				// fetch optionals attributes and labels
1423
-				$this->fetch_optionals();
1424
-			}
1425
-			else
1426
-			{
1427
-				$result = 0;
1428
-			}
1429
-
1430
-			$this->db->free($resql);
1431
-		}
1432
-		else
1433
-		{
1434
-			$this->error=$this->db->lasterror();
1435
-			$result = -3;
1436
-		}
1437
-
1438
-		// Use first price level if level not defined for third party
1439
-		if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->price_level)) $this->price_level=1;
1440
-
1441
-		return $result;
1442
-	}
1443
-
1444
-	/**
1445
-	 *    Delete a third party from database and all its dependencies (contacts, rib...)
1446
-	 *
1447
-	 *    @param	int		$id             Id of third party to delete
1448
-	 *    @param    User    $fuser          User who ask to delete thirparty
1449
-	 *    @param    int		$call_trigger   0=No, 1=yes
1450
-	 *    @return	int						<0 if KO, 0 if nothing done, >0 if OK
1451
-	 */
1452
-	function delete($id, User $fuser=null, $call_trigger=1)
1453
-	{
1454
-		global $langs, $conf, $user;
1455
-
1456
-		if (empty($fuser)) $fuser=$user;
1457
-
1458
-		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1459
-
1460
-		$entity=isset($this->entity)?$this->entity:$conf->entity;
1461
-
1462
-		dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1463
-		$error = 0;
1464
-
1465
-		// Test if child exists
1466
-		$objectisused = $this->isObjectUsed($id);
1467
-		if (empty($objectisused))
1468
-		{
1469
-			$this->db->begin();
1470
-
1471
-			// User is mandatory for trigger call
1472
-			if (! $error && $call_trigger)
1473
-			{
1474
-				// Call trigger
1475
-				$result=$this->call_trigger('COMPANY_DELETE',$fuser);
1476
-				if ($result < 0) $error++;
1477
-				// End call triggers
1478
-			}
1479
-
1480
-			if (! $error)
1481
-			{
1482
-				require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1483
-				$static_cat = new Categorie($this->db);
1484
-				$toute_categs = array();
1485
-
1486
-				// Fill $toute_categs array with an array of (type => array of ("Categorie" instance))
1487
-				if ($this->client || $this->prospect)
1488
-				{
1489
-					$toute_categs['customer'] = $static_cat->containing($this->id,Categorie::TYPE_CUSTOMER);
1490
-				}
1491
-				if ($this->fournisseur)
1492
-				{
1493
-					$toute_categs['supplier'] = $static_cat->containing($this->id,Categorie::TYPE_SUPPLIER);
1494
-				}
1495
-
1496
-				// Remove each "Categorie"
1497
-				foreach ($toute_categs as $type => $categs_type)
1498
-				{
1499
-					foreach ($categs_type as $cat)
1500
-					{
1501
-						$cat->del_type($this, $type);
1502
-					}
1503
-				}
1504
-			}
1505
-
1506
-			foreach ($this->childtablesoncascade as $tabletodelete)
1507
-			{
1508
-				if (! $error)
1509
-				{
1510
-					$sql = "DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete;
1511
-					$sql.= " WHERE fk_soc = " . $id;
1512
-					if (! $this->db->query($sql))
1513
-					{
1514
-						$error++;
1515
-						$this->errors[] = $this->db->lasterror();
1516
-					}
1517
-				}
1518
-			}
1519
-
1520
-			// Removed extrafields
1521
-			if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
1522
-			{
1523
-				$result=$this->deleteExtraFields();
1524
-				if ($result < 0)
1525
-				{
1526
-					$error++;
1527
-					dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR);
1528
-				}
1529
-			}
1530
-
1531
-			// Remove links to subsidiaries companies
1532
-			if (! $error)
1533
-			{
1534
-				$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
1535
-				$sql.= " SET parent = NULL";
1536
-				$sql.= " WHERE parent = " . $id;
1537
-				if (! $this->db->query($sql))
1538
-				{
1539
-					$error++;
1540
-					$this->errors[] = $this->db->lasterror();
1541
-				}
1542
-			}
1543
-
1544
-			// Remove third party
1545
-			if (! $error)
1546
-			{
1547
-				$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe";
1548
-				$sql.= " WHERE rowid = " . $id;
1549
-				if (! $this->db->query($sql))
1550
-				{
1551
-					$error++;
1552
-					$this->errors[] = $this->db->lasterror();
1553
-				}
1554
-			}
1555
-
1556
-			if (! $error)
1557
-			{
1558
-				$this->db->commit();
1559
-
1560
-				// Delete directory
1561
-				if (! empty($conf->societe->multidir_output[$entity]))
1562
-				{
1563
-					$docdir = $conf->societe->multidir_output[$entity] . "/" . $id;
1564
-					if (dol_is_dir($docdir))
1565
-					{
1566
-						dol_delete_dir_recursive($docdir);
1567
-					}
1568
-				}
1569
-
1570
-				return 1;
1571
-			}
1572
-			else
1573
-			{
1574
-				dol_syslog($this->error, LOG_ERR);
1575
-				$this->db->rollback();
1576
-				return -1;
1577
-			}
1578
-		}
1579
-		else dol_syslog("Can't remove thirdparty with id ".$id.". There is ".$objectisused." childs", LOG_WARNING);
1580
-		return 0;
1581
-	}
635
+        require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
636
+        $contact=new Contact($this->db);
637
+
638
+        $contact->name              = $this->name_bis;
639
+        $contact->firstname         = $this->firstname;
640
+        $contact->civility_id       = $this->civility_id;
641
+        $contact->socid             = $this->id;	// fk_soc
642
+        $contact->statut            = 1;
643
+        $contact->priv              = 0;
644
+        $contact->country_id        = $this->country_id;
645
+        $contact->state_id          = $this->state_id;
646
+        $contact->address           = $this->address;
647
+        $contact->email             = $this->email;
648
+        $contact->zip               = $this->zip;
649
+        $contact->town              = $this->town;
650
+        $contact->phone_pro         = $this->phone;
651
+
652
+        $result = $contact->create($user);
653
+        if ($result < 0)
654
+        {
655
+            $this->error = $contact->error;
656
+            $this->errors = $contact->errors;
657
+            dol_syslog(get_class($this)."::create_individual ERROR:" . $this->error, LOG_ERR);
658
+        }
659
+
660
+        return $result;
661
+    }
662
+
663
+    /**
664
+     *    Check properties of third party are ok (like name, third party codes, ...)
665
+     *    Used before an add or update.
666
+     *
667
+     *    @return     int		0 if OK, <0 if KO
668
+     */
669
+    function verify()
670
+    {
671
+        global $conf, $langs, $mysoc;
672
+
673
+        $error = 0;
674
+        $this->errors=array();
675
+
676
+        $result = 0;
677
+        $this->name	= trim($this->name);
678
+        $this->nom=$this->name; // For backward compatibility
679
+
680
+        if (! $this->name)
681
+        {
682
+            $this->errors[] = 'ErrorBadThirdPartyName';
683
+            $result = -2;
684
+        }
685
+
686
+        if ($this->client)
687
+        {
688
+            $rescode = $this->check_codeclient();
689
+            if ($rescode <> 0)
690
+            {
691
+                if ($rescode == -1)
692
+                {
693
+                    $this->errors[] = 'ErrorBadCustomerCodeSyntax';
694
+                }
695
+                elseif ($rescode == -2)
696
+                {
697
+                    $this->errors[] = 'ErrorCustomerCodeRequired';
698
+                }
699
+                elseif ($rescode == -3)
700
+                {
701
+                    $this->errors[] = 'ErrorCustomerCodeAlreadyUsed';
702
+                }
703
+                elseif ($rescode == -4)
704
+                {
705
+                    $this->errors[] = 'ErrorPrefixRequired';
706
+                }
707
+                $result = -3;
708
+            }
709
+        }
710
+
711
+        if ($this->fournisseur)
712
+        {
713
+            $rescode = $this->check_codefournisseur();
714
+            if ($rescode <> 0)
715
+            {
716
+                if ($rescode == -1)
717
+                {
718
+                    $this->errors[] = 'ErrorBadSupplierCodeSyntax';
719
+                }
720
+                elseif ($rescode == -2)
721
+                {
722
+                    $this->errors[] = 'ErrorSupplierCodeRequired';
723
+                }
724
+                elseif ($rescode == -3)
725
+                {
726
+                    $this->errors[] = 'ErrorSupplierCodeAlreadyUsed';
727
+                }
728
+                elseif ($rescode == -5)
729
+                {
730
+                    $this->errors[] = 'ErrorprefixRequired';
731
+                }
732
+                $result = -3;
733
+            }
734
+        }
735
+
736
+        // Check for duplicate or mandatory fields defined into setup
737
+        $array_to_check=array('IDPROF1','IDPROF2','IDPROF3','IDPROF4','IDPROF5','IDPROF6','EMAIL');
738
+        foreach($array_to_check as $key)
739
+        {
740
+            $keymin=strtolower($key);
741
+            $i=(int) preg_replace('/[^0-9]/','',$key);
742
+            $vallabel=$this->$keymin;
743
+
744
+            if ($i > 0)
745
+            {
746
+                if ($this->isACompany())
747
+                {
748
+                    // Check for unicity
749
+                    if ($vallabel && $this->id_prof_verifiable($i))
750
+                    {
751
+                        if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0)))
752
+                        {
753
+                            $langs->load("errors");
754
+                            $error++; $this->errors[] = $langs->transcountry('ProfId'.$i, $this->country_code)." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')';
755
+                        }
756
+                    }
757
+
758
+                    // Check for mandatory prof id (but only if country is other than ours)
759
+                    if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id)
760
+                    {
761
+                        $idprof_mandatory ='SOCIETE_'.$key.'_MANDATORY';
762
+                        if (! $vallabel && ! empty($conf->global->$idprof_mandatory))
763
+                        {
764
+                            $langs->load("errors");
765
+                            $error++;
766
+                            $this->errors[] = $langs->trans("ErrorProdIdIsMandatory", $langs->transcountry('ProfId'.$i, $this->country_code)).' ('.$langs->trans("ForbiddenBySetupRules").')';
767
+                        }
768
+                    }
769
+                }
770
+            }
771
+            else
772
+            {
773
+                //var_dump($conf->global->SOCIETE_EMAIL_UNIQUE);
774
+                //var_dump($conf->global->SOCIETE_EMAIL_MANDATORY);
775
+                if ($key == 'EMAIL')
776
+                {
777
+                    // Check for unicity
778
+                    if ($vallabel && ! empty($conf->global->SOCIETE_EMAIL_UNIQUE))
779
+                    {
780
+                        if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0)))
781
+                        {
782
+                            $langs->load("errors");
783
+                            $error++; $this->errors[] = $langs->trans('Email')." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')';
784
+                        }
785
+                    }
786
+
787
+                    // Check for mandatory
788
+                    if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY) && ! isValidEMail($this->email))
789
+                    {
790
+                        $langs->load("errors");
791
+                        $error++;
792
+                        $this->errors[] = $langs->trans("ErrorBadEMail", $this->email).' ('.$langs->trans("ForbiddenBySetupRules").')';
793
+                    }
794
+                }
795
+            }
796
+        }
797
+
798
+        if ($error) $result = -4;
799
+
800
+        return $result;
801
+    }
802
+
803
+    /**
804
+     *      Update parameters of third party
805
+     *
806
+     *      @param	int		$id              			Id of company (deprecated, use 0 here and call update on an object loaded by a fetch)
807
+     *      @param  User	$user            			Utilisateur qui demande la mise a jour
808
+     *      @param  int		$call_trigger    			0=no, 1=yes
809
+     *		@param	int		$allowmodcodeclient			Inclut modif code client et code compta
810
+     *		@param	int		$allowmodcodefournisseur	Inclut modif code fournisseur et code compta fournisseur
811
+     *		@param	string	$action						'add' or 'update' or 'merge'
812
+     *		@param	int		$nosyncmember				Do not synchronize info of linked member
813
+     *      @return int  			           			<0 if KO, >=0 if OK
814
+     */
815
+    function update($id, $user='', $call_trigger=1, $allowmodcodeclient=0, $allowmodcodefournisseur=0, $action='update', $nosyncmember=1)
816
+    {
817
+        global $langs,$conf,$hookmanager;
818
+
819
+        require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
820
+
821
+        if (empty($id)) $id = $this->id;
822
+
823
+        $error=0;
824
+
825
+        dol_syslog(get_class($this)."::Update id=".$id." call_trigger=".$call_trigger." allowmodcodeclient=".$allowmodcodeclient." allowmodcodefournisseur=".$allowmodcodefournisseur);
826
+
827
+        $now=dol_now();
828
+
829
+        // Clean parameters
830
+        $this->id			= $id;
831
+        $this->entity		= ((isset($this->entity) && is_numeric($this->entity))?$this->entity:$conf->entity);
832
+        $this->name			= $this->name?trim($this->name):trim($this->nom);
833
+        $this->nom			= $this->name;	// For backward compatibility
834
+        $this->name_alias	= trim($this->name_alias);
835
+        $this->ref_ext		= trim($this->ref_ext);
836
+        $this->address		= $this->address?trim($this->address):trim($this->address);
837
+        $this->zip			= $this->zip?trim($this->zip):trim($this->zip);
838
+        $this->town			= $this->town?trim($this->town):trim($this->town);
839
+        $this->state_id		= trim($this->state_id);
840
+        $this->country_id	= ($this->country_id > 0)?$this->country_id:0;
841
+        $this->phone		= trim($this->phone);
842
+        $this->phone		= preg_replace("/\s/","",$this->phone);
843
+        $this->phone		= preg_replace("/\./","",$this->phone);
844
+        $this->fax			= trim($this->fax);
845
+        $this->fax			= preg_replace("/\s/","",$this->fax);
846
+        $this->fax			= preg_replace("/\./","",$this->fax);
847
+        $this->email		= trim($this->email);
848
+        $this->skype		= trim($this->skype);
849
+        $this->twitter		= trim($this->twitter);
850
+        $this->facebook		= trim($this->facebook);
851
+        $this->url			= $this->url?clean_url($this->url,0):'';
852
+        $this->note_private = trim($this->note_private);
853
+        $this->note_public  = trim($this->note_public);
854
+        $this->idprof1		= trim($this->idprof1);
855
+        $this->idprof2		= trim($this->idprof2);
856
+        $this->idprof3		= trim($this->idprof3);
857
+        $this->idprof4		= trim($this->idprof4);
858
+        $this->idprof5		= (! empty($this->idprof5)?trim($this->idprof5):'');
859
+        $this->idprof6		= (! empty($this->idprof6)?trim($this->idprof6):'');
860
+        $this->prefix_comm	= trim($this->prefix_comm);
861
+        $this->outstanding_limit = price2num($this->outstanding_limit);
862
+        $this->order_min_amount = price2num($this->order_min_amount);
863
+        $this->supplier_order_min_amount = price2num($this->supplier_order_min_amount);
864
+
865
+        $this->tva_assuj	= trim($this->tva_assuj);
866
+        $this->tva_intra	= dol_sanitizeFileName($this->tva_intra,'');
867
+        if (empty($this->status)) $this->status = 0;
868
+
869
+        if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
870
+        if (empty($this->fk_multicurrency))
871
+        {
872
+            $this->multicurrency_code = '';
873
+            $this->fk_multicurrency = 0;
874
+        }
875
+
876
+        // Local taxes
877
+        $this->localtax1_assuj=trim($this->localtax1_assuj);
878
+        $this->localtax2_assuj=trim($this->localtax2_assuj);
879
+
880
+        $this->localtax1_value=trim($this->localtax1_value);
881
+        $this->localtax2_value=trim($this->localtax2_value);
882
+
883
+        if ($this->capital != '') $this->capital=price2num(trim($this->capital));
884
+        if (! is_numeric($this->capital)) $this->capital = '';     // '' = undef
885
+
886
+        $this->effectif_id=trim($this->effectif_id);
887
+        $this->forme_juridique_code=trim($this->forme_juridique_code);
888
+
889
+        //Gencod
890
+        $this->barcode=trim($this->barcode);
891
+
892
+        // For automatic creation
893
+        if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this,0);
894
+        if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1);
895
+
896
+        $this->code_compta=trim($this->code_compta);
897
+        $this->code_compta_fournisseur=trim($this->code_compta_fournisseur);
898
+
899
+        // Check parameters. More tests are done later in the ->verify()
900
+        if (! is_numeric($this->client) && ! is_numeric($this->fournisseur))
901
+        {
902
+            $langs->load("errors");
903
+            $this->error = $langs->trans("BadValueForParameterClientOrSupplier");
904
+            return -1;
905
+        }
906
+
907
+        $customer=false;
908
+        if (! empty($allowmodcodeclient) && ! empty($this->client))
909
+        {
910
+            // Attention get_codecompta peut modifier le code suivant le module utilise
911
+            if (empty($this->code_compta))
912
+            {
913
+                $ret=$this->get_codecompta('customer');
914
+                if ($ret < 0) return -1;
915
+            }
916
+
917
+            $customer=true;
918
+        }
919
+
920
+        $supplier=false;
921
+        if (! empty($allowmodcodefournisseur) && ! empty($this->fournisseur))
922
+        {
923
+            // Attention get_codecompta peut modifier le code suivant le module utilise
924
+            if (empty($this->code_compta_fournisseur))
925
+            {
926
+                $ret=$this->get_codecompta('supplier');
927
+                if ($ret < 0) return -1;
928
+            }
929
+
930
+            $supplier=true;
931
+        }
932
+
933
+        //Web services
934
+        $this->webservices_url = $this->webservices_url?clean_url($this->webservices_url,0):'';
935
+        $this->webservices_key = trim($this->webservices_key);
936
+
937
+        //Incoterms
938
+        $this->fk_incoterms = (int) $this->fk_incoterms;
939
+        $this->location_incoterms = trim($this->location_incoterms);
940
+
941
+        $this->db->begin();
942
+
943
+        // Check name is required and codes are ok or unique.
944
+        // If error, this->errors[] is filled
945
+        $result = 0;
946
+        if ($action != 'add' && $action != 'merge')
947
+        {
948
+            // We don't check when update called during a create because verify was already done.
949
+            // For a merge, we suppose source data is clean and a customer code of a deleted thirdparty must be accepted into a target thirdparty with empty code without duplicate error
950
+            $result = $this->verify();
951
+
952
+            // If there is only one error and error is ErrorBadCustomerCodeSyntax and we don't change customer code, we allow the update
953
+            // So we can update record that were using and old numbering rule.
954
+            if (is_array($this->errors))
955
+            {
956
+                if (in_array('ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client)
957
+                {
958
+                    if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]);	// Remove error message
959
+                }
960
+                if (in_array('ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur)
961
+                {
962
+                    if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]);	// Remove error message
963
+                }
964
+                if (empty($this->errors))	// If there is no more error, we can make like if there is no error at all
965
+                {
966
+                    $result = 0;
967
+                }
968
+            }
969
+        }
970
+
971
+        if ($result >= 0)
972
+        {
973
+            dol_syslog(get_class($this)."::update verify ok or not done");
974
+
975
+            $sql  = "UPDATE ".MAIN_DB_PREFIX."societe SET ";
976
+            $sql .= "entity = " . $this->db->escape($this->entity);
977
+            $sql .= ",nom = '" . $this->db->escape($this->name) ."'"; // Required
978
+            $sql .= ",name_alias = '" . $this->db->escape($this->name_alias) ."'";
979
+            $sql .= ",ref_ext = " .(! empty($this->ref_ext)?"'".$this->db->escape($this->ref_ext) ."'":"null");
980
+            $sql .= ",address = '" . $this->db->escape($this->address) ."'";
981
+
982
+            $sql .= ",zip = ".(! empty($this->zip)?"'".$this->db->escape($this->zip)."'":"null");
983
+            $sql .= ",town = ".(! empty($this->town)?"'".$this->db->escape($this->town)."'":"null");
984
+
985
+            $sql .= ",fk_departement = '" . (! empty($this->state_id)?$this->state_id:'0') ."'";
986
+            $sql .= ",fk_pays = '" . (! empty($this->country_id)?$this->country_id:'0') ."'";
987
+
988
+            $sql .= ",phone = ".(! empty($this->phone)?"'".$this->db->escape($this->phone)."'":"null");
989
+            $sql .= ",fax = ".(! empty($this->fax)?"'".$this->db->escape($this->fax)."'":"null");
990
+            $sql .= ",email = ".(! empty($this->email)?"'".$this->db->escape($this->email)."'":"null");
991
+            $sql .= ",skype = ".(! empty($this->skype)?"'".$this->db->escape($this->skype)."'":"null");
992
+            $sql .= ",twitter = ".(! empty($this->twitter)?"'".$this->db->escape($this->twitter)."'":"null");
993
+            $sql .= ",facebook = ".(! empty($this->facebook)?"'".$this->db->escape($this->facebook)."'":"null");
994
+            $sql .= ",url = ".(! empty($this->url)?"'".$this->db->escape($this->url)."'":"null");
995
+
996
+            $sql .= ",parent = " . ($this->parent > 0 ? $this->parent : "null");
997
+
998
+            $sql .= ",note_private = ".(! empty($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null");
999
+            $sql .= ",note_public = ".(! empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null");
1000
+
1001
+            $sql .= ",siren   = '". $this->db->escape($this->idprof1) ."'";
1002
+            $sql .= ",siret   = '". $this->db->escape($this->idprof2) ."'";
1003
+            $sql .= ",ape     = '". $this->db->escape($this->idprof3) ."'";
1004
+            $sql .= ",idprof4 = '". $this->db->escape($this->idprof4) ."'";
1005
+            $sql .= ",idprof5 = '". $this->db->escape($this->idprof5) ."'";
1006
+            $sql .= ",idprof6 = '". $this->db->escape($this->idprof6) ."'";
1007
+
1008
+            $sql .= ",tva_assuj = ".($this->tva_assuj!=''?"'".$this->db->escape($this->tva_assuj)."'":"null");
1009
+            $sql .= ",tva_intra = '" . $this->db->escape($this->tva_intra) ."'";
1010
+            $sql .= ",status = " .$this->status;
1011
+
1012
+            // Local taxes
1013
+            $sql .= ",localtax1_assuj = ".($this->localtax1_assuj!=''?"'".$this->db->escape($this->localtax1_assuj)."'":"null");
1014
+            $sql .= ",localtax2_assuj = ".($this->localtax2_assuj!=''?"'".$this->db->escape($this->localtax2_assuj)."'":"null");
1015
+            if($this->localtax1_assuj==1)
1016
+            {
1017
+                if($this->localtax1_value!='')
1018
+                {
1019
+                    $sql .=",localtax1_value =".$this->localtax1_value;
1020
+                }
1021
+                else $sql .=",localtax1_value =0.000";
1022
+            }
1023
+            else $sql .=",localtax1_value =0.000";
1024
+
1025
+            if($this->localtax2_assuj==1)
1026
+            {
1027
+                if($this->localtax2_value!='')
1028
+                {
1029
+                    $sql .=",localtax2_value =".$this->localtax2_value;
1030
+                }
1031
+                else $sql .=",localtax2_value =0.000";
1032
+            }
1033
+            else $sql .=",localtax2_value =0.000";
1034
+
1035
+            $sql .= ",capital = ".($this->capital == '' ? "null" : $this->capital);
1036
+
1037
+            $sql .= ",prefix_comm = ".(! empty($this->prefix_comm)?"'".$this->db->escape($this->prefix_comm)."'":"null");
1038
+
1039
+            $sql .= ",fk_effectif = ".(! empty($this->effectif_id)?"'".$this->db->escape($this->effectif_id)."'":"null");
1040
+            if (isset($this->stcomm_id))
1041
+            {
1042
+                $sql .= ",fk_stcomm=".(!empty($this->stcomm_id)  ? $this->stcomm_id : "0");
1043
+            }
1044
+            $sql .= ",fk_typent = ".(! empty($this->typent_id)?"'".$this->db->escape($this->typent_id)."'":"0");
1045
+
1046
+            $sql .= ",fk_forme_juridique = ".(! empty($this->forme_juridique_code)?"'".$this->db->escape($this->forme_juridique_code)."'":"null");
1047
+
1048
+            $sql .= ",mode_reglement = ".(! empty($this->mode_reglement_id)?"'".$this->db->escape($this->mode_reglement_id)."'":"null");
1049
+            $sql .= ",cond_reglement = ".(! empty($this->cond_reglement_id)?"'".$this->db->escape($this->cond_reglement_id)."'":"null");
1050
+            $sql .= ",mode_reglement_supplier = ".(! empty($this->mode_reglement_supplier_id)?"'".$this->db->escape($this->mode_reglement_supplier_id)."'":"null");
1051
+            $sql .= ",cond_reglement_supplier = ".(! empty($this->cond_reglement_supplier_id)?"'".$this->db->escape($this->cond_reglement_supplier_id)."'":"null");
1052
+            $sql .= ",fk_shipping_method = ".(! empty($this->shipping_method_id)?"'".$this->db->escape($this->shipping_method_id)."'":"null");
1053
+
1054
+            $sql .= ",client = " . (! empty($this->client)?$this->client:0);
1055
+            $sql .= ",fournisseur = " . (! empty($this->fournisseur)?$this->fournisseur:0);
1056
+            $sql .= ",barcode = ".(! empty($this->barcode)?"'".$this->db->escape($this->barcode)."'":"null");
1057
+            $sql .= ",default_lang = ".(! empty($this->default_lang)?"'".$this->db->escape($this->default_lang)."'":"null");
1058
+            $sql .= ",logo = ".(! empty($this->logo)?"'".$this->db->escape($this->logo)."'":"null");
1059
+            $sql .= ",outstanding_limit= ".($this->outstanding_limit!=''?$this->outstanding_limit:'null');
1060
+            $sql .= ",order_min_amount= ".($this->order_min_amount!=''?$this->order_min_amount:'null');
1061
+            $sql .= ",supplier_order_min_amount= ".($this->supplier_order_min_amount!=''?$this->supplier_order_min_amount:'null');
1062
+            $sql .= ",fk_prospectlevel='".$this->db->escape($this->fk_prospectlevel)."'";
1063
+
1064
+            $sql .= ",webservices_url = ".(! empty($this->webservices_url)?"'".$this->db->escape($this->webservices_url)."'":"null");
1065
+            $sql .= ",webservices_key = ".(! empty($this->webservices_key)?"'".$this->db->escape($this->webservices_key)."'":"null");
1066
+
1067
+            //Incoterms
1068
+            $sql.= ", fk_incoterms = ".$this->fk_incoterms;
1069
+            $sql.= ", location_incoterms = ".(! empty($this->location_incoterms)?"'".$this->db->escape($this->location_incoterms)."'":"null");
1070
+
1071
+            if ($customer)
1072
+            {
1073
+                $sql .= ", code_client = ".(! empty($this->code_client)?"'".$this->db->escape($this->code_client)."'":"null");
1074
+                $sql .= ", code_compta = ".(! empty($this->code_compta)?"'".$this->db->escape($this->code_compta)."'":"null");
1075
+            }
1076
+
1077
+            if ($supplier)
1078
+            {
1079
+                $sql .= ", code_fournisseur = ".(! empty($this->code_fournisseur)?"'".$this->db->escape($this->code_fournisseur)."'":"null");
1080
+                $sql .= ", code_compta_fournisseur = ".(! empty($this->code_compta_fournisseur)?"'".$this->db->escape($this->code_compta_fournisseur)."'":"null");
1081
+            }
1082
+            $sql .= ", fk_user_modif = ".($user->id > 0 ? $user->id:"null");
1083
+            $sql .= ", fk_multicurrency = ".(int) $this->fk_multicurrency;
1084
+            $sql .= ", multicurrency_code = '".$this->db->escape($this->multicurrency_code)."'";
1085
+            $sql .= " WHERE rowid = " . (int) $id;
1086
+
1087
+            $resql=$this->db->query($sql);
1088
+            if ($resql)
1089
+            {
1090
+                if (is_object($this->oldcopy))	// If we have information on old values
1091
+                {
1092
+                    if ($this->oldcopy->country_id != $this->country_id)
1093
+                    {
1094
+                        unset($this->country_code);
1095
+                        unset($this->country);
1096
+                    }
1097
+                    if ($this->oldcopy->state_id != $this->state_id)
1098
+                    {
1099
+                        unset($this->state_code);
1100
+                        unset($this->state);
1101
+                    }
1102
+                }
1103
+                else
1104
+                {
1105
+                    unset($this->country_code);	// We clean this, in the doubt, because it may have been changed after an update of country_id
1106
+                    unset($this->country);
1107
+                    unset($this->state_code);
1108
+                    unset($this->state);
1109
+                }
1110
+
1111
+                $nbrowsaffected = $this->db->affected_rows($resql);
1112
+
1113
+                if (! $error && $nbrowsaffected)
1114
+                {
1115
+                    // Update information on linked member if it is an update
1116
+                    if (! $nosyncmember && ! empty($conf->adherent->enabled))
1117
+                    {
1118
+                        require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
1119
+
1120
+                        dol_syslog(get_class($this)."::update update linked member");
1121
+
1122
+                        $lmember=new Adherent($this->db);
1123
+                        $result=$lmember->fetch(0, 0, $this->id);
1124
+
1125
+                        if ($result > 0)
1126
+                        {
1127
+                            $lmember->societe=$this->name;
1128
+                            //$lmember->firstname=$this->firstname?$this->firstname:$lmember->firstname;	// We keep firstname and lastname of member unchanged
1129
+                            //$lmember->lastname=$this->lastname?$this->lastname:$lmember->lastname;		// We keep firstname and lastname of member unchanged
1130
+                            $lmember->address=$this->address;
1131
+                            $lmember->email=$this->email;
1132
+                            $lmember->skype=$this->skype;
1133
+                            $lmember->twitter=$this->twitter;
1134
+                            $lmember->facebook=$this->facebook;
1135
+                            $lmember->phone=$this->phone;
1136
+
1137
+                            $result=$lmember->update($user,0,1,1,1);	// Use nosync to 1 to avoid cyclic updates
1138
+                            if ($result < 0)
1139
+                            {
1140
+                                $this->error=$lmember->error;
1141
+                                dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
1142
+                                $error++;
1143
+                            }
1144
+                        }
1145
+                        elseif ($result < 0)
1146
+                        {
1147
+                            $this->error=$lmember->error;
1148
+                            $error++;
1149
+                        }
1150
+                    }
1151
+                }
1152
+
1153
+                $action='update';
1154
+
1155
+                // Actions on extra fields
1156
+                if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1157
+                {
1158
+                    $result=$this->insertExtraFields();
1159
+                    if ($result < 0)
1160
+                    {
1161
+                        $error++;
1162
+                    }
1163
+                }
1164
+
1165
+                if (! $error && $call_trigger)
1166
+                {
1167
+                    // Call trigger
1168
+                    $result=$this->call_trigger('COMPANY_MODIFY',$user);
1169
+                    if ($result < 0) $error++;
1170
+                    // End call triggers
1171
+                }
1172
+
1173
+                if (! $error)
1174
+                {
1175
+                    dol_syslog(get_class($this)."::Update success");
1176
+                    $this->db->commit();
1177
+                    return 1;
1178
+                }
1179
+                else
1180
+                {
1181
+                    $this->db->rollback();
1182
+                    return -1;
1183
+                }
1184
+            }
1185
+            else
1186
+            {
1187
+                if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
1188
+                {
1189
+                    // Doublon
1190
+                    $this->error = $langs->trans("ErrorDuplicateField");
1191
+                    $result = -1;
1192
+                }
1193
+                else
1194
+                {
1195
+                    $this->error = $this->db->lasterror();
1196
+                    $result = -2;
1197
+                }
1198
+                $this->db->rollback();
1199
+                return $result;
1200
+            }
1201
+        }
1202
+        else
1203
+        {
1204
+            $this->db->rollback();
1205
+            dol_syslog(get_class($this)."::Update fails verify ".join(',',$this->errors), LOG_WARNING);
1206
+            return -3;
1207
+        }
1208
+    }
1209
+
1210
+    /**
1211
+     *    Load a third party from database into memory
1212
+     *
1213
+     *    @param	int		$rowid			Id of third party to load
1214
+     *    @param    string	$ref			Reference of third party, name (Warning, this can return several records)
1215
+     *    @param    string	$ref_ext       	External reference of third party (Warning, this information is a free field not provided by Dolibarr)
1216
+     *    @param    string	$ref_int       	Internal reference of third party (not used by dolibarr)
1217
+     *    @param    string	$idprof1		Prof id 1 of third party (Warning, this can return several records)
1218
+     *    @param    string	$idprof2		Prof id 2 of third party (Warning, this can return several records)
1219
+     *    @param    string	$idprof3		Prof id 3 of third party (Warning, this can return several records)
1220
+     *    @param    string	$idprof4		Prof id 4 of third party (Warning, this can return several records)
1221
+     *    @param    string	$idprof5		Prof id 5 of third party (Warning, this can return several records)
1222
+     *    @param    string	$idprof6		Prof id 6 of third party (Warning, this can return several records)
1223
+     *    @param    string	$email   		Email of third party (Warning, this can return several records)
1224
+     *    @param    string	$ref_alias 		Name_alias of third party (Warning, this can return several records)
1225
+     *    @return   int						>0 if OK, <0 if KO or if two records found for same ref or idprof, 0 if not found.
1226
+     */
1227
+    function fetch($rowid, $ref='', $ref_ext='', $ref_int='', $idprof1='',$idprof2='',$idprof3='',$idprof4='',$idprof5='',$idprof6='', $email='', $ref_alias='')
1228
+    {
1229
+        global $langs;
1230
+        global $conf;
1231
+
1232
+        if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($ref_int) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) return -1;
1233
+
1234
+        $sql = 'SELECT s.rowid, s.nom as name, s.name_alias, s.entity, s.ref_ext, s.ref_int, s.address, s.datec as date_creation, s.prefix_comm';
1235
+        $sql .= ', s.status';
1236
+        $sql .= ', s.price_level';
1237
+        $sql .= ', s.tms as date_modification, s.fk_user_creat, s.fk_user_modif';
1238
+        $sql .= ', s.phone, s.fax, s.email, s.skype, s.twitter, s.facebook, s.url, s.zip, s.town, s.note_private, s.note_public, s.model_pdf, s.client, s.fournisseur';
1239
+        $sql .= ', s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6';
1240
+        $sql .= ', s.capital, s.tva_intra';
1241
+        $sql .= ', s.fk_typent as typent_id';
1242
+        $sql .= ', s.fk_effectif as effectif_id';
1243
+        $sql .= ', s.fk_forme_juridique as forme_juridique_code';
1244
+        $sql .= ', s.webservices_url, s.webservices_key';
1245
+        $sql .= ', s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur, s.parent, s.barcode';
1246
+        $sql .= ', s.fk_departement, s.fk_pays as country_id, s.fk_stcomm, s.remise_client, s.remise_supplier, s.mode_reglement, s.cond_reglement, s.fk_account, s.tva_assuj';
1247
+        $sql .= ', s.mode_reglement_supplier, s.cond_reglement_supplier, s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo';
1248
+        $sql .= ', s.fk_shipping_method';
1249
+        $sql .= ', s.outstanding_limit, s.import_key, s.canvas, s.fk_incoterms, s.location_incoterms';
1250
+        $sql .= ', s.order_min_amount, s.supplier_order_min_amount';
1251
+        $sql .= ', s.fk_multicurrency, s.multicurrency_code';
1252
+        $sql .= ', fj.libelle as forme_juridique';
1253
+        $sql .= ', e.libelle as effectif';
1254
+        $sql .= ', c.code as country_code, c.label as country';
1255
+        $sql .= ', d.code_departement as state_code, d.nom as state';
1256
+        $sql .= ', st.libelle as stcomm';
1257
+        $sql .= ', te.code as typent_code';
1258
+        $sql .= ', i.libelle as libelle_incoterms';
1259
+        $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
1260
+        $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as e ON s.fk_effectif = e.id';
1261
+        $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
1262
+        $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id';
1263
+        $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code';
1264
+        $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
1265
+        $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as te ON s.fk_typent = te.id';
1266
+        $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON s.fk_incoterms = i.rowid';
1267
+
1268
+        $sql .= ' WHERE s.entity IN ('.getEntity($this->element).')';
1269
+        if ($rowid)     $sql .= ' AND s.rowid = '.$rowid;
1270
+        if ($ref)       $sql .= " AND s.nom = '".$this->db->escape($ref)."'";
1271
+        if ($ref_alias) $sql .= " AND s.nom_alias = '".$this->db->escape($ref_alias)."'";
1272
+        if ($ref_ext)   $sql .= " AND s.ref_ext = '".$this->db->escape($ref_ext)."'";
1273
+        if ($ref_int)   $sql .= " AND s.ref_int = '".$this->db->escape($ref_int)."'";
1274
+        if ($idprof1)   $sql .= " AND s.siren = '".$this->db->escape($idprof1)."'";
1275
+        if ($idprof2)   $sql .= " AND s.siret = '".$this->db->escape($idprof2)."'";
1276
+        if ($idprof3)   $sql .= " AND s.ape = '".$this->db->escape($idprof3)."'";
1277
+        if ($idprof4)   $sql .= " AND s.idprof4 = '".$this->db->escape($idprof4)."'";
1278
+        if ($idprof5)   $sql .= " AND s.idprof5 = '".$this->db->escape($idprof5)."'";
1279
+        if ($idprof6)   $sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'";
1280
+        if ($email)     $sql .= " AND s.email = '".$this->db->escape($email)."'";
1281
+
1282
+        $resql=$this->db->query($sql);
1283
+        if ($resql)
1284
+        {
1285
+            $num=$this->db->num_rows($resql);
1286
+            if ($num > 1)
1287
+            {
1288
+                $this->error='Fetch found several records. Rename one of tirdparties to avoid duplicate.';
1289
+                dol_syslog($this->error, LOG_ERR);
1290
+                $result = -2;
1291
+            }
1292
+            elseif ($num)   // $num = 1
1293
+            {
1294
+                $obj = $this->db->fetch_object($resql);
1295
+
1296
+                $this->id           = $obj->rowid;
1297
+                $this->entity       = $obj->entity;
1298
+                $this->canvas		= $obj->canvas;
1299
+
1300
+                $this->ref          = $obj->rowid;
1301
+                $this->name 		= $obj->name;
1302
+                $this->nom          = $obj->name;		// deprecated
1303
+                $this->name_alias = $obj->name_alias;
1304
+                $this->ref_ext      = $obj->ref_ext;
1305
+                $this->ref_int      = $obj->ref_int;
1306
+
1307
+                $this->date_creation     = $this->db->jdate($obj->date_creation);
1308
+                $this->date_modification = $this->db->jdate($obj->date_modification);
1309
+                $this->user_creation     = $obj->fk_user_creat;
1310
+                $this->user_modification = $obj->fk_user_modif;
1311
+
1312
+                $this->address 		= $obj->address;
1313
+                $this->zip 			= $obj->zip;
1314
+                $this->town 		= $obj->town;
1315
+
1316
+                $this->country_id   = $obj->country_id;
1317
+                $this->country_code = $obj->country_id?$obj->country_code:'';
1318
+                $this->country 		= $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->transnoentities('Country'.$obj->country_code):$obj->country):'';
1319
+
1320
+                $this->state_id     = $obj->fk_departement;
1321
+                $this->state_code   = $obj->state_code;
1322
+                $this->state        = ($obj->state!='-'?$obj->state:'');
1323
+
1324
+                $transcode=$langs->trans('StatusProspect'.$obj->fk_stcomm);
1325
+                $libelle=($transcode!='StatusProspect'.$obj->fk_stcomm?$transcode:$obj->stcomm);
1326
+                $this->stcomm_id = $obj->fk_stcomm;     // id statut commercial
1327
+                $this->statut_commercial = $libelle;    // libelle statut commercial
1328
+
1329
+                $this->email = $obj->email;
1330
+                $this->skype = $obj->skype;
1331
+                $this->twitter = $obj->twitter;
1332
+                $this->facebook = $obj->facebook;
1333
+                $this->url = $obj->url;
1334
+                $this->phone = $obj->phone;
1335
+                $this->fax = $obj->fax;
1336
+
1337
+                $this->parent    = $obj->parent;
1338
+
1339
+                $this->idprof1		= $obj->idprof1;
1340
+                $this->idprof2		= $obj->idprof2;
1341
+                $this->idprof3		= $obj->idprof3;
1342
+                $this->idprof4		= $obj->idprof4;
1343
+                $this->idprof5		= $obj->idprof5;
1344
+                $this->idprof6		= $obj->idprof6;
1345
+
1346
+                $this->capital   = $obj->capital;
1347
+
1348
+                $this->code_client = $obj->code_client;
1349
+                $this->code_fournisseur = $obj->code_fournisseur;
1350
+
1351
+                $this->code_compta = $obj->code_compta;
1352
+                $this->code_compta_fournisseur = $obj->code_compta_fournisseur;
1353
+
1354
+                $this->barcode = $obj->barcode;
1355
+
1356
+                $this->tva_assuj      = $obj->tva_assuj;
1357
+                $this->tva_intra      = $obj->tva_intra;
1358
+                $this->status = $obj->status;
1359
+
1360
+                // Local Taxes
1361
+                $this->localtax1_assuj      = $obj->localtax1_assuj;
1362
+                $this->localtax2_assuj      = $obj->localtax2_assuj;
1363
+
1364
+                $this->localtax1_value		= $obj->localtax1_value;
1365
+                $this->localtax2_value		= $obj->localtax2_value;
1366
+
1367
+                $this->typent_id      = $obj->typent_id;
1368
+                $this->typent_code    = $obj->typent_code;
1369
+
1370
+                $this->effectif_id    = $obj->effectif_id;
1371
+                $this->effectif       = $obj->effectif_id?$obj->effectif:'';
1372
+
1373
+                $this->forme_juridique_code= $obj->forme_juridique_code;
1374
+                $this->forme_juridique     = $obj->forme_juridique_code?$obj->forme_juridique:'';
1375
+
1376
+                $this->fk_prospectlevel = $obj->fk_prospectlevel;
1377
+
1378
+                $this->prefix_comm = $obj->prefix_comm;
1379
+
1380
+                $this->remise_percent		= $obj->remise_client;
1381
+                $this->remise_supplier_percent		= $obj->remise_supplier;
1382
+                $this->mode_reglement_id 	= $obj->mode_reglement;
1383
+                $this->cond_reglement_id 	= $obj->cond_reglement;
1384
+                $this->mode_reglement_supplier_id 	= $obj->mode_reglement_supplier;
1385
+                $this->cond_reglement_supplier_id 	= $obj->cond_reglement_supplier;
1386
+                $this->shipping_method_id   = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null;
1387
+                $this->fk_account			= $obj->fk_account;
1388
+
1389
+                $this->client      = $obj->client;
1390
+                $this->fournisseur = $obj->fournisseur;
1391
+
1392
+                $this->note = $obj->note_private; // TODO Deprecated for backward comtability
1393
+                $this->note_private = $obj->note_private;
1394
+                $this->note_public = $obj->note_public;
1395
+                $this->modelpdf = $obj->model_pdf;
1396
+                $this->default_lang = $obj->default_lang;
1397
+                $this->logo = $obj->logo;
1398
+
1399
+                $this->webservices_url = $obj->webservices_url;
1400
+                $this->webservices_key = $obj->webservices_key;
1401
+
1402
+                $this->outstanding_limit		= $obj->outstanding_limit;
1403
+                $this->order_min_amount			= $obj->order_min_amount;
1404
+                $this->supplier_order_min_amount	= $obj->supplier_order_min_amount;
1405
+
1406
+                // multiprix
1407
+                $this->price_level = $obj->price_level;
1408
+
1409
+                $this->import_key = $obj->import_key;
1410
+
1411
+                //Incoterms
1412
+                $this->fk_incoterms = $obj->fk_incoterms;
1413
+                $this->location_incoterms = $obj->location_incoterms;
1414
+                $this->libelle_incoterms = $obj->libelle_incoterms;
1415
+
1416
+                // multicurrency
1417
+                $this->fk_multicurrency = $obj->fk_multicurrency;
1418
+                $this->multicurrency_code = $obj->multicurrency_code;
1419
+
1420
+                $result = 1;
1421
+
1422
+                // fetch optionals attributes and labels
1423
+                $this->fetch_optionals();
1424
+            }
1425
+            else
1426
+            {
1427
+                $result = 0;
1428
+            }
1429
+
1430
+            $this->db->free($resql);
1431
+        }
1432
+        else
1433
+        {
1434
+            $this->error=$this->db->lasterror();
1435
+            $result = -3;
1436
+        }
1437
+
1438
+        // Use first price level if level not defined for third party
1439
+        if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->price_level)) $this->price_level=1;
1440
+
1441
+        return $result;
1442
+    }
1443
+
1444
+    /**
1445
+     *    Delete a third party from database and all its dependencies (contacts, rib...)
1446
+     *
1447
+     *    @param	int		$id             Id of third party to delete
1448
+     *    @param    User    $fuser          User who ask to delete thirparty
1449
+     *    @param    int		$call_trigger   0=No, 1=yes
1450
+     *    @return	int						<0 if KO, 0 if nothing done, >0 if OK
1451
+     */
1452
+    function delete($id, User $fuser=null, $call_trigger=1)
1453
+    {
1454
+        global $langs, $conf, $user;
1455
+
1456
+        if (empty($fuser)) $fuser=$user;
1457
+
1458
+        require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1459
+
1460
+        $entity=isset($this->entity)?$this->entity:$conf->entity;
1461
+
1462
+        dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1463
+        $error = 0;
1464
+
1465
+        // Test if child exists
1466
+        $objectisused = $this->isObjectUsed($id);
1467
+        if (empty($objectisused))
1468
+        {
1469
+            $this->db->begin();
1470
+
1471
+            // User is mandatory for trigger call
1472
+            if (! $error && $call_trigger)
1473
+            {
1474
+                // Call trigger
1475
+                $result=$this->call_trigger('COMPANY_DELETE',$fuser);
1476
+                if ($result < 0) $error++;
1477
+                // End call triggers
1478
+            }
1479
+
1480
+            if (! $error)
1481
+            {
1482
+                require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1483
+                $static_cat = new Categorie($this->db);
1484
+                $toute_categs = array();
1485
+
1486
+                // Fill $toute_categs array with an array of (type => array of ("Categorie" instance))
1487
+                if ($this->client || $this->prospect)
1488
+                {
1489
+                    $toute_categs['customer'] = $static_cat->containing($this->id,Categorie::TYPE_CUSTOMER);
1490
+                }
1491
+                if ($this->fournisseur)
1492
+                {
1493
+                    $toute_categs['supplier'] = $static_cat->containing($this->id,Categorie::TYPE_SUPPLIER);
1494
+                }
1495
+
1496
+                // Remove each "Categorie"
1497
+                foreach ($toute_categs as $type => $categs_type)
1498
+                {
1499
+                    foreach ($categs_type as $cat)
1500
+                    {
1501
+                        $cat->del_type($this, $type);
1502
+                    }
1503
+                }
1504
+            }
1505
+
1506
+            foreach ($this->childtablesoncascade as $tabletodelete)
1507
+            {
1508
+                if (! $error)
1509
+                {
1510
+                    $sql = "DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete;
1511
+                    $sql.= " WHERE fk_soc = " . $id;
1512
+                    if (! $this->db->query($sql))
1513
+                    {
1514
+                        $error++;
1515
+                        $this->errors[] = $this->db->lasterror();
1516
+                    }
1517
+                }
1518
+            }
1519
+
1520
+            // Removed extrafields
1521
+            if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
1522
+            {
1523
+                $result=$this->deleteExtraFields();
1524
+                if ($result < 0)
1525
+                {
1526
+                    $error++;
1527
+                    dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR);
1528
+                }
1529
+            }
1530
+
1531
+            // Remove links to subsidiaries companies
1532
+            if (! $error)
1533
+            {
1534
+                $sql = "UPDATE ".MAIN_DB_PREFIX."societe";
1535
+                $sql.= " SET parent = NULL";
1536
+                $sql.= " WHERE parent = " . $id;
1537
+                if (! $this->db->query($sql))
1538
+                {
1539
+                    $error++;
1540
+                    $this->errors[] = $this->db->lasterror();
1541
+                }
1542
+            }
1543
+
1544
+            // Remove third party
1545
+            if (! $error)
1546
+            {
1547
+                $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe";
1548
+                $sql.= " WHERE rowid = " . $id;
1549
+                if (! $this->db->query($sql))
1550
+                {
1551
+                    $error++;
1552
+                    $this->errors[] = $this->db->lasterror();
1553
+                }
1554
+            }
1555
+
1556
+            if (! $error)
1557
+            {
1558
+                $this->db->commit();
1559
+
1560
+                // Delete directory
1561
+                if (! empty($conf->societe->multidir_output[$entity]))
1562
+                {
1563
+                    $docdir = $conf->societe->multidir_output[$entity] . "/" . $id;
1564
+                    if (dol_is_dir($docdir))
1565
+                    {
1566
+                        dol_delete_dir_recursive($docdir);
1567
+                    }
1568
+                }
1569
+
1570
+                return 1;
1571
+            }
1572
+            else
1573
+            {
1574
+                dol_syslog($this->error, LOG_ERR);
1575
+                $this->db->rollback();
1576
+                return -1;
1577
+            }
1578
+        }
1579
+        else dol_syslog("Can't remove thirdparty with id ".$id.". There is ".$objectisused." childs", LOG_WARNING);
1580
+        return 0;
1581
+    }
1582 1582
 
1583 1583
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1584
-	/**
1585
-	 *  Define third party as a customer
1586
-	 *
1587
-	 *	@return		int		<0 if KO, >0 if OK
1588
-	 */
1589
-	function set_as_client()
1590
-	{
1584
+    /**
1585
+     *  Define third party as a customer
1586
+     *
1587
+     *	@return		int		<0 if KO, >0 if OK
1588
+     */
1589
+    function set_as_client()
1590
+    {
1591 1591
         // phpcs:enable
1592
-		if ($this->id)
1593
-		{
1594
-			$newclient=1;
1595
-			if ($this->client == 2 || $this->client == 3) $newclient=3;	//If prospect, we keep prospect tag
1596
-			$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
1597
-			$sql.= " SET client = ".$newclient;
1598
-			$sql.= " WHERE rowid = " . $this->id;
1599
-
1600
-			$resql=$this->db->query($sql);
1601
-			if ($resql)
1602
-			{
1603
-				$this->client = $newclient;
1604
-				return 1;
1605
-			}
1606
-			else return -1;
1607
-		}
1608
-		return 0;
1609
-	}
1592
+        if ($this->id)
1593
+        {
1594
+            $newclient=1;
1595
+            if ($this->client == 2 || $this->client == 3) $newclient=3;	//If prospect, we keep prospect tag
1596
+            $sql = "UPDATE ".MAIN_DB_PREFIX."societe";
1597
+            $sql.= " SET client = ".$newclient;
1598
+            $sql.= " WHERE rowid = " . $this->id;
1599
+
1600
+            $resql=$this->db->query($sql);
1601
+            if ($resql)
1602
+            {
1603
+                $this->client = $newclient;
1604
+                return 1;
1605
+            }
1606
+            else return -1;
1607
+        }
1608
+        return 0;
1609
+    }
1610 1610
 
1611 1611
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1612
-	/**
1613
-	 *  Definit la societe comme un client
1614
-	 *
1615
-	 *  @param	float	$remise		Valeur en % de la remise
1616
-	 *  @param  string	$note		Note/Motif de modification de la remise
1617
-	 *  @param  User	$user		Utilisateur qui definie la remise
1618
-	 *	@return	int					<0 if KO, >0 if OK
1619
-	 */
1620
-	function set_remise_client($remise, $note, User $user)
1621
-	{
1612
+    /**
1613
+     *  Definit la societe comme un client
1614
+     *
1615
+     *  @param	float	$remise		Valeur en % de la remise
1616
+     *  @param  string	$note		Note/Motif de modification de la remise
1617
+     *  @param  User	$user		Utilisateur qui definie la remise
1618
+     *	@return	int					<0 if KO, >0 if OK
1619
+     */
1620
+    function set_remise_client($remise, $note, User $user)
1621
+    {
1622 1622
         // phpcs:enable
1623
-		global $conf, $langs;
1624
-
1625
-		// Nettoyage parametres
1626
-		$note=trim($note);
1627
-		if (! $note)
1628
-		{
1629
-			$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("NoteReason"));
1630
-			return -2;
1631
-		}
1632
-
1633
-		dol_syslog(get_class($this)."::set_remise_client ".$remise.", ".$note.", ".$user->id);
1634
-
1635
-		if ($this->id)
1636
-		{
1637
-			$this->db->begin();
1638
-
1639
-			$now=dol_now();
1640
-
1641
-			// Positionne remise courante
1642
-			$sql = "UPDATE ".MAIN_DB_PREFIX."societe ";
1643
-			$sql.= " SET remise_client = '".$this->db->escape($remise)."'";
1644
-			$sql.= " WHERE rowid = " . $this->id;
1645
-			$resql=$this->db->query($sql);
1646
-			if (! $resql)
1647
-			{
1648
-				$this->db->rollback();
1649
-				$this->error=$this->db->error();
1650
-				return -1;
1651
-			}
1652
-
1653
-			// Ecrit trace dans historique des remises
1654
-			$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise";
1655
-			$sql.= " (entity, datec, fk_soc, remise_client, note, fk_user_author)";
1656
-			$sql.= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',";
1657
-			$sql.= " '".$this->db->escape($note)."',";
1658
-			$sql.= " ".$user->id;
1659
-			$sql.= ")";
1660
-
1661
-			$resql=$this->db->query($sql);
1662
-			if (! $resql)
1663
-			{
1664
-				$this->db->rollback();
1665
-				$this->error=$this->db->lasterror();
1666
-				return -1;
1667
-			}
1668
-
1669
-			$this->db->commit();
1670
-			return 1;
1671
-		}
1672
-	}
1623
+        global $conf, $langs;
1624
+
1625
+        // Nettoyage parametres
1626
+        $note=trim($note);
1627
+        if (! $note)
1628
+        {
1629
+            $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("NoteReason"));
1630
+            return -2;
1631
+        }
1632
+
1633
+        dol_syslog(get_class($this)."::set_remise_client ".$remise.", ".$note.", ".$user->id);
1634
+
1635
+        if ($this->id)
1636
+        {
1637
+            $this->db->begin();
1638
+
1639
+            $now=dol_now();
1640
+
1641
+            // Positionne remise courante
1642
+            $sql = "UPDATE ".MAIN_DB_PREFIX."societe ";
1643
+            $sql.= " SET remise_client = '".$this->db->escape($remise)."'";
1644
+            $sql.= " WHERE rowid = " . $this->id;
1645
+            $resql=$this->db->query($sql);
1646
+            if (! $resql)
1647
+            {
1648
+                $this->db->rollback();
1649
+                $this->error=$this->db->error();
1650
+                return -1;
1651
+            }
1652
+
1653
+            // Ecrit trace dans historique des remises
1654
+            $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise";
1655
+            $sql.= " (entity, datec, fk_soc, remise_client, note, fk_user_author)";
1656
+            $sql.= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',";
1657
+            $sql.= " '".$this->db->escape($note)."',";
1658
+            $sql.= " ".$user->id;
1659
+            $sql.= ")";
1660
+
1661
+            $resql=$this->db->query($sql);
1662
+            if (! $resql)
1663
+            {
1664
+                $this->db->rollback();
1665
+                $this->error=$this->db->lasterror();
1666
+                return -1;
1667
+            }
1668
+
1669
+            $this->db->commit();
1670
+            return 1;
1671
+        }
1672
+    }
1673 1673
 
1674 1674
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1675
-	/**
1676
-	 *  Definit la societe comme un client
1677
-	 *
1678
-	 *  @param	float	$remise		Valeur en % de la remise
1679
-	 *  @param  string	$note		Note/Motif de modification de la remise
1680
-	 *  @param  User	$user		Utilisateur qui definie la remise
1681
-	 *	@return	int					<0 if KO, >0 if OK
1682
-	 */
1683
-	function set_remise_supplier($remise, $note, User $user)
1684
-	{
1675
+    /**
1676
+     *  Definit la societe comme un client
1677
+     *
1678
+     *  @param	float	$remise		Valeur en % de la remise
1679
+     *  @param  string	$note		Note/Motif de modification de la remise
1680
+     *  @param  User	$user		Utilisateur qui definie la remise
1681
+     *	@return	int					<0 if KO, >0 if OK
1682
+     */
1683
+    function set_remise_supplier($remise, $note, User $user)
1684
+    {
1685 1685
         // phpcs:enable
1686
-		global $conf, $langs;
1687
-
1688
-		// Nettoyage parametres
1689
-		$note=trim($note);
1690
-		if (! $note)
1691
-		{
1692
-			$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("NoteReason"));
1693
-			return -2;
1694
-		}
1695
-
1696
-		dol_syslog(get_class($this)."::set_remise_supplier ".$remise.", ".$note.", ".$user->id);
1697
-
1698
-		if ($this->id)
1699
-		{
1700
-			$this->db->begin();
1701
-
1702
-			$now=dol_now();
1703
-
1704
-			// Positionne remise courante
1705
-			$sql = "UPDATE ".MAIN_DB_PREFIX."societe ";
1706
-			$sql.= " SET remise_supplier = '".$this->db->escape($remise)."'";
1707
-			$sql.= " WHERE rowid = " . $this->id;
1708
-			$resql=$this->db->query($sql);
1709
-			if (! $resql)
1710
-			{
1711
-				$this->db->rollback();
1712
-				$this->error=$this->db->error();
1713
-				return -1;
1714
-			}
1715
-
1716
-			// Ecrit trace dans historique des remises
1717
-			$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_supplier";
1718
-			$sql.= " (entity, datec, fk_soc, remise_supplier, note, fk_user_author)";
1719
-			$sql.= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',";
1720
-			$sql.= " '".$this->db->escape($note)."',";
1721
-			$sql.= " ".$user->id;
1722
-			$sql.= ")";
1723
-
1724
-			$resql=$this->db->query($sql);
1725
-			if (! $resql)
1726
-			{
1727
-				$this->db->rollback();
1728
-				$this->error=$this->db->lasterror();
1729
-				return -1;
1730
-			}
1731
-
1732
-			$this->db->commit();
1733
-			return 1;
1734
-		}
1735
-	}
1686
+        global $conf, $langs;
1687
+
1688
+        // Nettoyage parametres
1689
+        $note=trim($note);
1690
+        if (! $note)
1691
+        {
1692
+            $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("NoteReason"));
1693
+            return -2;
1694
+        }
1695
+
1696
+        dol_syslog(get_class($this)."::set_remise_supplier ".$remise.", ".$note.", ".$user->id);
1697
+
1698
+        if ($this->id)
1699
+        {
1700
+            $this->db->begin();
1701
+
1702
+            $now=dol_now();
1703
+
1704
+            // Positionne remise courante
1705
+            $sql = "UPDATE ".MAIN_DB_PREFIX."societe ";
1706
+            $sql.= " SET remise_supplier = '".$this->db->escape($remise)."'";
1707
+            $sql.= " WHERE rowid = " . $this->id;
1708
+            $resql=$this->db->query($sql);
1709
+            if (! $resql)
1710
+            {
1711
+                $this->db->rollback();
1712
+                $this->error=$this->db->error();
1713
+                return -1;
1714
+            }
1715
+
1716
+            // Ecrit trace dans historique des remises
1717
+            $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_supplier";
1718
+            $sql.= " (entity, datec, fk_soc, remise_supplier, note, fk_user_author)";
1719
+            $sql.= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',";
1720
+            $sql.= " '".$this->db->escape($note)."',";
1721
+            $sql.= " ".$user->id;
1722
+            $sql.= ")";
1723
+
1724
+            $resql=$this->db->query($sql);
1725
+            if (! $resql)
1726
+            {
1727
+                $this->db->rollback();
1728
+                $this->error=$this->db->lasterror();
1729
+                return -1;
1730
+            }
1731
+
1732
+            $this->db->commit();
1733
+            return 1;
1734
+        }
1735
+    }
1736 1736
 
1737 1737
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1738
-	/**
1739
-	 *    	Add a discount for third party
1740
-	 *
1741
-	 *    	@param	float	$remise     	Amount of discount
1742
-	 *    	@param  User	$user       	User adding discount
1743
-	 *    	@param  string	$desc			Reason of discount
1744
-	 *      @param  float	$tva_tx     	VAT rate
1745
-	 *      @param	int		$discount_type	0 => customer discount, 1 => supplier discount
1746
-	 *		@return	int					<0 if KO, id of discount record if OK
1747
-	 */
1748
-	function set_remise_except($remise, User $user, $desc, $tva_tx=0, $discount_type=0)
1749
-	{
1738
+    /**
1739
+     *    	Add a discount for third party
1740
+     *
1741
+     *    	@param	float	$remise     	Amount of discount
1742
+     *    	@param  User	$user       	User adding discount
1743
+     *    	@param  string	$desc			Reason of discount
1744
+     *      @param  float	$tva_tx     	VAT rate
1745
+     *      @param	int		$discount_type	0 => customer discount, 1 => supplier discount
1746
+     *		@return	int					<0 if KO, id of discount record if OK
1747
+     */
1748
+    function set_remise_except($remise, User $user, $desc, $tva_tx=0, $discount_type=0)
1749
+    {
1750 1750
         // phpcs:enable
1751
-		global $langs;
1752
-
1753
-		// Clean parameters
1754
-		$remise = price2num($remise);
1755
-		$desc = trim($desc);
1756
-
1757
-		// Check parameters
1758
-		if (! $remise > 0)
1759
-		{
1760
-			$this->error=$langs->trans("ErrorWrongValueForParameter","1");
1761
-			return -1;
1762
-		}
1763
-		if (! $desc)
1764
-		{
1765
-			$this->error=$langs->trans("ErrorWrongValueForParameter","3");
1766
-			return -2;
1767
-		}
1768
-
1769
-		if ($this->id)
1770
-		{
1771
-			require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
1772
-
1773
-			$discount = new DiscountAbsolute($this->db);
1774
-			$discount->fk_soc=$this->id;
1775
-
1776
-			$discount->discount_type=$discount_type;
1777
-
1778
-			$discount->amount_ht=$discount->multicurrency_amount_ht=price2num($remise,'MT');
1779
-			$discount->amount_tva=$discount->multicurrency_amount_tva=price2num($remise*$tva_tx/100,'MT');
1780
-			$discount->amount_ttc=$discount->multicurrency_amount_ttc=price2num($discount->amount_ht+$discount->amount_tva,'MT');
1781
-
1782
-			$discount->tva_tx=price2num($tva_tx,'MT');
1783
-			$discount->description=$desc;
1784
-
1785
-			$result=$discount->create($user);
1786
-			if ($result > 0)
1787
-			{
1788
-				return $result;
1789
-			}
1790
-			else
1791
-			{
1792
-				$this->error=$discount->error;
1793
-				return -3;
1794
-			}
1795
-		}
1796
-		else return 0;
1797
-	}
1798
-
1799
-	/**
1800
-	 *  Renvoie montant TTC des reductions/avoirs en cours disponibles de la societe
1801
-	 *
1802
-	 *	@param	User	$user			Filtre sur un user auteur des remises
1803
-	 * 	@param	string	$filter			Filtre autre
1804
-	 * 	@param	integer	$maxvalue		Filter on max value for discount
1805
-	 * 	@param	int		$discount_type	0 => customer discount, 1 => supplier discount
1806
-	 *	@return	int					<0 if KO, Credit note amount otherwise
1807
-	 */
1808
-	function getAvailableDiscounts($user='',$filter='',$maxvalue=0,$discount_type=0)
1809
-	{
1810
-		require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
1811
-
1812
-		$discountstatic=new DiscountAbsolute($this->db);
1813
-		$result=$discountstatic->getAvailableDiscounts($this,$user,$filter,$maxvalue,$discount_type);
1814
-		if ($result >= 0)
1815
-		{
1816
-			return $result;
1817
-		}
1818
-		else
1819
-		{
1820
-			$this->error=$discountstatic->error;
1821
-			return -1;
1822
-		}
1823
-	}
1824
-
1825
-	/**
1826
-	 *  Return array of sales representatives
1827
-	 *
1828
-	 *  @param	User	$user		Object user
1829
-	 *  @param	int		$mode		0=Array with properties, 1=Array of id.
1830
-	 *  @return array       		Array of sales representatives of third party
1831
-	 */
1832
-	function getSalesRepresentatives(User $user, $mode=0)
1833
-	{
1834
-		global $conf;
1835
-
1836
-		$reparray=array();
1837
-
1838
-		$sql = "SELECT DISTINCT u.rowid, u.login, u.lastname, u.firstname, u.email, u.statut, u.entity, u.photo";
1839
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."user as u";
1840
-		if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
1841
-		{
1842
-			$sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1843
-			$sql.= " WHERE ((ug.fk_user = sc.fk_user";
1844
-			$sql.= " AND ug.entity = ".$conf->entity.")";
1845
-			$sql.= " OR u.admin = 1)";
1846
-		}
1847
-		else
1848
-			$sql.= " WHERE entity in (0, ".$conf->entity.")";
1849
-
1850
-		$sql.= " AND u.rowid = sc.fk_user AND sc.fk_soc = ".$this->id;
1851
-
1852
-		$resql = $this->db->query($sql);
1853
-		if ($resql)
1854
-		{
1855
-			$num = $this->db->num_rows($resql);
1856
-			$i=0;
1857
-			while ($i < $num)
1858
-			{
1859
-				$obj = $this->db->fetch_object($resql);
1860
-
1861
-				if (empty($mode))
1862
-				{
1863
-					$reparray[$i]['id']=$obj->rowid;
1864
-					$reparray[$i]['lastname']=$obj->lastname;
1865
-					$reparray[$i]['firstname']=$obj->firstname;
1866
-					$reparray[$i]['email']=$obj->email;
1867
-					$reparray[$i]['statut']=$obj->statut;
1868
-					$reparray[$i]['entity']=$obj->entity;
1869
-					$reparray[$i]['login']=$obj->login;
1870
-					$reparray[$i]['photo']=$obj->photo;
1871
-				}
1872
-				else
1873
-				{
1874
-					$reparray[]=$obj->rowid;
1875
-				}
1876
-				$i++;
1877
-			}
1878
-			return $reparray;
1879
-		}
1880
-		else {
1881
-			dol_print_error($this->db);
1882
-			return -1;
1883
-		}
1884
-	}
1751
+        global $langs;
1752
+
1753
+        // Clean parameters
1754
+        $remise = price2num($remise);
1755
+        $desc = trim($desc);
1756
+
1757
+        // Check parameters
1758
+        if (! $remise > 0)
1759
+        {
1760
+            $this->error=$langs->trans("ErrorWrongValueForParameter","1");
1761
+            return -1;
1762
+        }
1763
+        if (! $desc)
1764
+        {
1765
+            $this->error=$langs->trans("ErrorWrongValueForParameter","3");
1766
+            return -2;
1767
+        }
1768
+
1769
+        if ($this->id)
1770
+        {
1771
+            require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
1772
+
1773
+            $discount = new DiscountAbsolute($this->db);
1774
+            $discount->fk_soc=$this->id;
1775
+
1776
+            $discount->discount_type=$discount_type;
1777
+
1778
+            $discount->amount_ht=$discount->multicurrency_amount_ht=price2num($remise,'MT');
1779
+            $discount->amount_tva=$discount->multicurrency_amount_tva=price2num($remise*$tva_tx/100,'MT');
1780
+            $discount->amount_ttc=$discount->multicurrency_amount_ttc=price2num($discount->amount_ht+$discount->amount_tva,'MT');
1781
+
1782
+            $discount->tva_tx=price2num($tva_tx,'MT');
1783
+            $discount->description=$desc;
1784
+
1785
+            $result=$discount->create($user);
1786
+            if ($result > 0)
1787
+            {
1788
+                return $result;
1789
+            }
1790
+            else
1791
+            {
1792
+                $this->error=$discount->error;
1793
+                return -3;
1794
+            }
1795
+        }
1796
+        else return 0;
1797
+    }
1798
+
1799
+    /**
1800
+     *  Renvoie montant TTC des reductions/avoirs en cours disponibles de la societe
1801
+     *
1802
+     *	@param	User	$user			Filtre sur un user auteur des remises
1803
+     * 	@param	string	$filter			Filtre autre
1804
+     * 	@param	integer	$maxvalue		Filter on max value for discount
1805
+     * 	@param	int		$discount_type	0 => customer discount, 1 => supplier discount
1806
+     *	@return	int					<0 if KO, Credit note amount otherwise
1807
+     */
1808
+    function getAvailableDiscounts($user='',$filter='',$maxvalue=0,$discount_type=0)
1809
+    {
1810
+        require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
1811
+
1812
+        $discountstatic=new DiscountAbsolute($this->db);
1813
+        $result=$discountstatic->getAvailableDiscounts($this,$user,$filter,$maxvalue,$discount_type);
1814
+        if ($result >= 0)
1815
+        {
1816
+            return $result;
1817
+        }
1818
+        else
1819
+        {
1820
+            $this->error=$discountstatic->error;
1821
+            return -1;
1822
+        }
1823
+    }
1824
+
1825
+    /**
1826
+     *  Return array of sales representatives
1827
+     *
1828
+     *  @param	User	$user		Object user
1829
+     *  @param	int		$mode		0=Array with properties, 1=Array of id.
1830
+     *  @return array       		Array of sales representatives of third party
1831
+     */
1832
+    function getSalesRepresentatives(User $user, $mode=0)
1833
+    {
1834
+        global $conf;
1835
+
1836
+        $reparray=array();
1837
+
1838
+        $sql = "SELECT DISTINCT u.rowid, u.login, u.lastname, u.firstname, u.email, u.statut, u.entity, u.photo";
1839
+        $sql.= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."user as u";
1840
+        if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
1841
+        {
1842
+            $sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1843
+            $sql.= " WHERE ((ug.fk_user = sc.fk_user";
1844
+            $sql.= " AND ug.entity = ".$conf->entity.")";
1845
+            $sql.= " OR u.admin = 1)";
1846
+        }
1847
+        else
1848
+            $sql.= " WHERE entity in (0, ".$conf->entity.")";
1849
+
1850
+        $sql.= " AND u.rowid = sc.fk_user AND sc.fk_soc = ".$this->id;
1851
+
1852
+        $resql = $this->db->query($sql);
1853
+        if ($resql)
1854
+        {
1855
+            $num = $this->db->num_rows($resql);
1856
+            $i=0;
1857
+            while ($i < $num)
1858
+            {
1859
+                $obj = $this->db->fetch_object($resql);
1860
+
1861
+                if (empty($mode))
1862
+                {
1863
+                    $reparray[$i]['id']=$obj->rowid;
1864
+                    $reparray[$i]['lastname']=$obj->lastname;
1865
+                    $reparray[$i]['firstname']=$obj->firstname;
1866
+                    $reparray[$i]['email']=$obj->email;
1867
+                    $reparray[$i]['statut']=$obj->statut;
1868
+                    $reparray[$i]['entity']=$obj->entity;
1869
+                    $reparray[$i]['login']=$obj->login;
1870
+                    $reparray[$i]['photo']=$obj->photo;
1871
+                }
1872
+                else
1873
+                {
1874
+                    $reparray[]=$obj->rowid;
1875
+                }
1876
+                $i++;
1877
+            }
1878
+            return $reparray;
1879
+        }
1880
+        else {
1881
+            dol_print_error($this->db);
1882
+            return -1;
1883
+        }
1884
+    }
1885 1885
 
1886 1886
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1887
-	/**
1888
-	 * Set the price level
1889
-	 *
1890
-	 * @param 	int		$price_level	Level of price
1891
-	 * @param 	User	$user			Use making change
1892
-	 * @return	int						<0 if KO, >0 if OK
1893
-	 */
1894
-	function set_price_level($price_level, User $user)
1895
-	{
1887
+    /**
1888
+     * Set the price level
1889
+     *
1890
+     * @param 	int		$price_level	Level of price
1891
+     * @param 	User	$user			Use making change
1892
+     * @return	int						<0 if KO, >0 if OK
1893
+     */
1894
+    function set_price_level($price_level, User $user)
1895
+    {
1896 1896
         // phpcs:enable
1897
-		if ($this->id)
1898
-		{
1899
-			$now=dol_now();
1900
-
1901
-			$sql  = "UPDATE ".MAIN_DB_PREFIX."societe";
1902
-			$sql .= " SET price_level = '".$this->db->escape($price_level)."'";
1903
-			$sql .= " WHERE rowid = " . $this->id;
1904
-
1905
-			if (! $this->db->query($sql))
1906
-			{
1907
-				dol_print_error($this->db);
1908
-				return -1;
1909
-			}
1910
-
1911
-			$sql  = "INSERT INTO ".MAIN_DB_PREFIX."societe_prices";
1912
-			$sql .= " (datec, fk_soc, price_level, fk_user_author)";
1913
-			$sql .= " VALUES ('".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($price_level)."', ".$user->id.")";
1914
-
1915
-			if (! $this->db->query($sql))
1916
-			{
1917
-				dol_print_error($this->db);
1918
-				return -1;
1919
-			}
1920
-			return 1;
1921
-		}
1922
-		return -1;
1923
-	}
1897
+        if ($this->id)
1898
+        {
1899
+            $now=dol_now();
1900
+
1901
+            $sql  = "UPDATE ".MAIN_DB_PREFIX."societe";
1902
+            $sql .= " SET price_level = '".$this->db->escape($price_level)."'";
1903
+            $sql .= " WHERE rowid = " . $this->id;
1904
+
1905
+            if (! $this->db->query($sql))
1906
+            {
1907
+                dol_print_error($this->db);
1908
+                return -1;
1909
+            }
1910
+
1911
+            $sql  = "INSERT INTO ".MAIN_DB_PREFIX."societe_prices";
1912
+            $sql .= " (datec, fk_soc, price_level, fk_user_author)";
1913
+            $sql .= " VALUES ('".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($price_level)."', ".$user->id.")";
1914
+
1915
+            if (! $this->db->query($sql))
1916
+            {
1917
+                dol_print_error($this->db);
1918
+                return -1;
1919
+            }
1920
+            return 1;
1921
+        }
1922
+        return -1;
1923
+    }
1924 1924
 
1925 1925
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1926
-	/**
1927
-	 *	Add link to sales representative
1928
-	 *
1929
-	 *	@param	User	$user		Object user
1930
-	 *	@param	int		$commid		Id of user
1931
-	 *	@return	void
1932
-	 */
1933
-	function add_commercial(User $user, $commid)
1934
-	{
1926
+    /**
1927
+     *	Add link to sales representative
1928
+     *
1929
+     *	@param	User	$user		Object user
1930
+     *	@param	int		$commid		Id of user
1931
+     *	@return	void
1932
+     */
1933
+    function add_commercial(User $user, $commid)
1934
+    {
1935 1935
         // phpcs:enable
1936
-		$error=0;
1936
+        $error=0;
1937 1937
 
1938 1938
 
1939
-		if ($this->id > 0 && $commid > 0)
1940
-		{
1941
-			$sql = "DELETE FROM  ".MAIN_DB_PREFIX."societe_commerciaux";
1942
-			$sql.= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid;
1939
+        if ($this->id > 0 && $commid > 0)
1940
+        {
1941
+            $sql = "DELETE FROM  ".MAIN_DB_PREFIX."societe_commerciaux";
1942
+            $sql.= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid;
1943 1943
 
1944
-			$this->db->query($sql);
1944
+            $this->db->query($sql);
1945 1945
 
1946
-			$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_commerciaux";
1947
-			$sql.= " ( fk_soc, fk_user )";
1948
-			$sql.= " VALUES (".$this->id.",".$commid.")";
1946
+            $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_commerciaux";
1947
+            $sql.= " ( fk_soc, fk_user )";
1948
+            $sql.= " VALUES (".$this->id.",".$commid.")";
1949 1949
 
1950
-			if (! $this->db->query($sql) )
1951
-			{
1952
-				dol_syslog(get_class($this)."::add_commercial Erreur");
1953
-			}
1954
-			else {
1955
-				$this->context=array('commercial_modified'=>$commid);
1950
+            if (! $this->db->query($sql) )
1951
+            {
1952
+                dol_syslog(get_class($this)."::add_commercial Erreur");
1953
+            }
1954
+            else {
1955
+                $this->context=array('commercial_modified'=>$commid);
1956 1956
 
1957
-				$result=$this->call_trigger('COMPANY_LINK_SALE_REPRESENTATIVE',$user);
1957
+                $result=$this->call_trigger('COMPANY_LINK_SALE_REPRESENTATIVE',$user);
1958 1958
                 if ($result < 0) $error++;
1959
-			}
1960
-		}
1961
-	}
1959
+            }
1960
+        }
1961
+    }
1962 1962
 
1963 1963
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1964
-	/**
1965
-	 *	Add link to sales representative
1966
-	 *
1967
-	 *	@param	User	$user		Object user
1968
-	 *	@param	int		$commid		Id of user
1969
-	 *	@return	void
1970
-	 */
1971
-	function del_commercial(User $user, $commid)
1972
-	{
1964
+    /**
1965
+     *	Add link to sales representative
1966
+     *
1967
+     *	@param	User	$user		Object user
1968
+     *	@param	int		$commid		Id of user
1969
+     *	@return	void
1970
+     */
1971
+    function del_commercial(User $user, $commid)
1972
+    {
1973 1973
         // phpcs:enable
1974
-		$error=0;
1975
-		$this->context=array('commercial_modified'=>$commid);
1974
+        $error=0;
1975
+        $this->context=array('commercial_modified'=>$commid);
1976 1976
 
1977
-		$result=$this->call_trigger('COMPANY_UNLINK_SALE_REPRESENTATIVE',$user);
1977
+        $result=$this->call_trigger('COMPANY_UNLINK_SALE_REPRESENTATIVE',$user);
1978 1978
         if ($result < 0) $error++;
1979 1979
 
1980
-		if ($this->id > 0 && $commid > 0)
1981
-		{
1982
-			$sql  = "DELETE FROM  ".MAIN_DB_PREFIX."societe_commerciaux ";
1983
-			$sql .= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid;
1984
-
1985
-			if (! $this->db->query($sql) )
1986
-			{
1987
-				dol_syslog(get_class($this)."::del_commercial Erreur");
1988
-			}
1989
-		}
1990
-	}
1991
-
1992
-
1993
-	/**
1994
-	 *    	Return a link on thirdparty (with picto)
1995
-	 *
1996
-	 *		@param	int		$withpicto		          Add picto into link (0=No picto, 1=Include picto with link, 2=Picto only)
1997
-	 *		@param	string	$option			          Target of link ('', 'customer', 'prospect', 'supplier', 'project')
1998
-	 *		@param	int		$maxlen			          Max length of name
1999
-	 *      @param	int  	$notooltip		          1=Disable tooltip
2000
-	 *      @param  int     $save_lastsearch_value    -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
2001
-	 *		@return	string					          String with URL
2002
-	 */
2003
-	function getNomUrl($withpicto=0, $option='', $maxlen=0, $notooltip=0, $save_lastsearch_value=-1)
2004
-	{
2005
-		global $conf, $langs, $hookmanager;
2006
-
2007
-		if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
2008
-
2009
-		$name=$this->name?$this->name:$this->nom;
2010
-
2011
-		if(!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)){
2012
-
2013
-             if(empty($option) && $this->client > 0) $option = 'customer';
2014
-             if(empty($option) && $this->fournisseur > 0) $option = 'supplier';
2015
-         }
2016
-
2017
-
2018
-		if (! empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto)))
2019
-		{
2020
-			$code = '';
2021
-			if (($this->client) && (! empty ( $this->code_client ))
2022
-				&& ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1
2023
-				|| $conf->global->SOCIETE_ADD_REF_IN_LIST == 2
2024
-				)
2025
-			)
2026
-			{
2027
-				$code = $this->code_client . ' - ';
2028
-			}
2029
-
2030
-			if (($this->fournisseur) && (! empty ( $this->code_fournisseur ))
2031
-				&& ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1
2032
-				|| $conf->global->SOCIETE_ADD_REF_IN_LIST == 3
2033
-				)
2034
-			)
2035
-			{
2036
-				$code .= $this->code_fournisseur . ' - ';
2037
-			}
2038
-
2039
-			if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1)
2040
-			{
2041
-				$name =$code.' '.$name;
2042
-			}
2043
-			else
2044
-			{
2045
-				$name =$code;
2046
-			}
2047
-		}
2048
-
2049
-		if (!empty($this->name_alias)) $name .= ' ('.$this->name_alias.')';
2050
-
2051
-		$result=''; $label='';
2052
-		$linkstart=''; $linkend='';
2053
-
2054
-		if (! empty($this->logo) && class_exists('Form'))
2055
-		{
2056
-			$label.= '<div class="photointooltip">';
2057
-			$label.= Form::showphoto('societe', $this, 0, 40, 0, 'photowithmargin', 'mini', 0);	// Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
2058
-			$label.= '</div><div style="clear: both;"></div>';
2059
-		}
2060
-
2061
-		$label.= '<div class="centpercent">';
2062
-
2063
-		if ($option == 'customer' || $option == 'compta' || $option == 'category' || $option == 'category_supplier')
2064
-		{
2065
-		   $label.= '<u>' . $langs->trans("ShowCustomer") . '</u>';
2066
-		   $linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id;
2067
-		}
2068
-		elseif ($option == 'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
2069
-		{
2070
-			$label.= '<u>' . $langs->trans("ShowProspect") . '</u>';
2071
-			$linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id;
2072
-		}
2073
-		elseif ($option == 'supplier')
2074
-		{
2075
-			$label.= '<u>' . $langs->trans("ShowSupplier") . '</u>';
2076
-			$linkstart = '<a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$this->id;
2077
-		}
2078
-		elseif ($option == 'agenda')
2079
-		{
2080
-			$label.= '<u>' . $langs->trans("ShowAgenda") . '</u>';
2081
-			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/agenda.php?socid='.$this->id;
2082
-		}
2083
-		elseif ($option == 'project')
2084
-		{
2085
-			$label.= '<u>' . $langs->trans("ShowProject") . '</u>';
2086
-			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/project.php?socid='.$this->id;
2087
-		}
2088
-		elseif ($option == 'margin')
2089
-		{
2090
-			$label.= '<u>' . $langs->trans("ShowMargin") . '</u>';
2091
-			$linkstart = '<a href="'.DOL_URL_ROOT.'/margin/tabs/thirdpartyMargins.php?socid='.$this->id.'&type=1';
2092
-		}
2093
-		elseif ($option == 'contact')
2094
-		{
2095
-			$label.= '<u>' . $langs->trans("ShowContacts") . '</u>';
2096
-			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/contact.php?socid='.$this->id;
2097
-		}
2098
-		elseif ($option == 'ban')
2099
-		{
2100
-			$label.= '<u>' . $langs->trans("ShowBan") . '</u>';
2101
-			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$this->id;
2102
-		}
2103
-
2104
-		// By default
2105
-		if (empty($linkstart))
2106
-		{
2107
-			$label.= '<u>' . $langs->trans("ShowCompany") . '</u>';
2108
-			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$this->id;
2109
-		}
2110
-
2111
-		if (! empty($this->name))
2112
-		{
2113
-			$label.= '<br><b>' . $langs->trans('Name') . ':</b> '. $this->name;
2114
-			if (! empty($this->name_alias)) $label.=' ('.$this->name_alias.')';
2115
-			$label.= '<br><b>' . $langs->trans('Email') . ':</b> '. $this->email;
2116
-		}
2117
-		if (! empty($this->country_code))
2118
-			$label.= '<br><b>' . $langs->trans('Country') . ':</b> '. $this->country_code;
2119
-		if (! empty($this->tva_intra) || (! empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'vatnumber') !== false))
2120
-			$label.= '<br><b>' . $langs->trans('VATIntra') . ':</b> '. $this->tva_intra;
2121
-		if (! empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP))
2122
-		{
2123
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid1') !== false) $label.= '<br><b>' . $langs->trans('ProfId1'.$this->country_code) . ':</b> '. $this->idprof1;
2124
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid2') !== false) $label.= '<br><b>' . $langs->trans('ProfId2'.$this->country_code) . ':</b> '. $this->idprof2;
2125
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid3') !== false) $label.= '<br><b>' . $langs->trans('ProfId3'.$this->country_code) . ':</b> '. $this->idprof3;
2126
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid4') !== false) $label.= '<br><b>' . $langs->trans('ProfId4'.$this->country_code) . ':</b> '. $this->idprof4;
2127
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid5') !== false) $label.= '<br><b>' . $langs->trans('ProfId5'.$this->country_code) . ':</b> '. $this->idprof5;
2128
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid6') !== false) $label.= '<br><b>' . $langs->trans('ProfId6'.$this->country_code) . ':</b> '. $this->idprof6;
2129
-		}
2130
-		if (! empty($this->code_client) && ($this->client == 1 || $this->client == 3))
2131
-			$label.= '<br><b>' . $langs->trans('CustomerCode') . ':</b> '. $this->code_client;
2132
-		if (! empty($this->code_fournisseur) && $this->fournisseur)
2133
-			$label.= '<br><b>' . $langs->trans('SupplierCode') . ':</b> '. $this->code_fournisseur;
2134
-		if (! empty($conf->accounting->enabled) && ($this->client == 1 || $this->client == 3))
2135
-			$label.= '<br><b>' . $langs->trans('CustomerAccountancyCode') . ':</b> '. ($this->code_compta ? $this->code_compta : $this->code_compta_client);
2136
-		if (! empty($conf->accounting->enabled) && $this->fournisseur)
2137
-			$label.= '<br><b>' . $langs->trans('SupplierAccountancyCode') . ':</b> '. $this->code_compta_fournisseur;
2138
-
2139
-		$label.= '</div>';
2140
-
2141
-		// Add type of canvas
2142
-		$linkstart.=(!empty($this->canvas)?'&canvas='.$this->canvas:'');
2143
-		// Add param to save lastsearch_values or not
2144
-		$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
2145
-		if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
2146
-		if ($add_save_lastsearch_values) $linkstart.='&save_lastsearch_values=1';
2147
-		$linkstart.='"';
2148
-
2149
-		$linkclose='';
2150
-		if (empty($notooltip))
2151
-		{
2152
-			if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
2153
-			{
2154
-				$label=$langs->trans("ShowCompany");
2155
-				$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
2156
-			}
2157
-			$linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
2158
-			$linkclose.=' class="classfortooltip refurl"';
2159
-
2160
-		 	/*
1980
+        if ($this->id > 0 && $commid > 0)
1981
+        {
1982
+            $sql  = "DELETE FROM  ".MAIN_DB_PREFIX."societe_commerciaux ";
1983
+            $sql .= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid;
1984
+
1985
+            if (! $this->db->query($sql) )
1986
+            {
1987
+                dol_syslog(get_class($this)."::del_commercial Erreur");
1988
+            }
1989
+        }
1990
+    }
1991
+
1992
+
1993
+    /**
1994
+     *    	Return a link on thirdparty (with picto)
1995
+     *
1996
+     *		@param	int		$withpicto		          Add picto into link (0=No picto, 1=Include picto with link, 2=Picto only)
1997
+     *		@param	string	$option			          Target of link ('', 'customer', 'prospect', 'supplier', 'project')
1998
+     *		@param	int		$maxlen			          Max length of name
1999
+     *      @param	int  	$notooltip		          1=Disable tooltip
2000
+     *      @param  int     $save_lastsearch_value    -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
2001
+     *		@return	string					          String with URL
2002
+     */
2003
+    function getNomUrl($withpicto=0, $option='', $maxlen=0, $notooltip=0, $save_lastsearch_value=-1)
2004
+    {
2005
+        global $conf, $langs, $hookmanager;
2006
+
2007
+        if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
2008
+
2009
+        $name=$this->name?$this->name:$this->nom;
2010
+
2011
+        if(!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)){
2012
+
2013
+                if(empty($option) && $this->client > 0) $option = 'customer';
2014
+                if(empty($option) && $this->fournisseur > 0) $option = 'supplier';
2015
+            }
2016
+
2017
+
2018
+        if (! empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto)))
2019
+        {
2020
+            $code = '';
2021
+            if (($this->client) && (! empty ( $this->code_client ))
2022
+                && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1
2023
+                || $conf->global->SOCIETE_ADD_REF_IN_LIST == 2
2024
+                )
2025
+            )
2026
+            {
2027
+                $code = $this->code_client . ' - ';
2028
+            }
2029
+
2030
+            if (($this->fournisseur) && (! empty ( $this->code_fournisseur ))
2031
+                && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1
2032
+                || $conf->global->SOCIETE_ADD_REF_IN_LIST == 3
2033
+                )
2034
+            )
2035
+            {
2036
+                $code .= $this->code_fournisseur . ' - ';
2037
+            }
2038
+
2039
+            if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1)
2040
+            {
2041
+                $name =$code.' '.$name;
2042
+            }
2043
+            else
2044
+            {
2045
+                $name =$code;
2046
+            }
2047
+        }
2048
+
2049
+        if (!empty($this->name_alias)) $name .= ' ('.$this->name_alias.')';
2050
+
2051
+        $result=''; $label='';
2052
+        $linkstart=''; $linkend='';
2053
+
2054
+        if (! empty($this->logo) && class_exists('Form'))
2055
+        {
2056
+            $label.= '<div class="photointooltip">';
2057
+            $label.= Form::showphoto('societe', $this, 0, 40, 0, 'photowithmargin', 'mini', 0);	// Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
2058
+            $label.= '</div><div style="clear: both;"></div>';
2059
+        }
2060
+
2061
+        $label.= '<div class="centpercent">';
2062
+
2063
+        if ($option == 'customer' || $option == 'compta' || $option == 'category' || $option == 'category_supplier')
2064
+        {
2065
+            $label.= '<u>' . $langs->trans("ShowCustomer") . '</u>';
2066
+            $linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id;
2067
+        }
2068
+        elseif ($option == 'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
2069
+        {
2070
+            $label.= '<u>' . $langs->trans("ShowProspect") . '</u>';
2071
+            $linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id;
2072
+        }
2073
+        elseif ($option == 'supplier')
2074
+        {
2075
+            $label.= '<u>' . $langs->trans("ShowSupplier") . '</u>';
2076
+            $linkstart = '<a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$this->id;
2077
+        }
2078
+        elseif ($option == 'agenda')
2079
+        {
2080
+            $label.= '<u>' . $langs->trans("ShowAgenda") . '</u>';
2081
+            $linkstart = '<a href="'.DOL_URL_ROOT.'/societe/agenda.php?socid='.$this->id;
2082
+        }
2083
+        elseif ($option == 'project')
2084
+        {
2085
+            $label.= '<u>' . $langs->trans("ShowProject") . '</u>';
2086
+            $linkstart = '<a href="'.DOL_URL_ROOT.'/societe/project.php?socid='.$this->id;
2087
+        }
2088
+        elseif ($option == 'margin')
2089
+        {
2090
+            $label.= '<u>' . $langs->trans("ShowMargin") . '</u>';
2091
+            $linkstart = '<a href="'.DOL_URL_ROOT.'/margin/tabs/thirdpartyMargins.php?socid='.$this->id.'&type=1';
2092
+        }
2093
+        elseif ($option == 'contact')
2094
+        {
2095
+            $label.= '<u>' . $langs->trans("ShowContacts") . '</u>';
2096
+            $linkstart = '<a href="'.DOL_URL_ROOT.'/societe/contact.php?socid='.$this->id;
2097
+        }
2098
+        elseif ($option == 'ban')
2099
+        {
2100
+            $label.= '<u>' . $langs->trans("ShowBan") . '</u>';
2101
+            $linkstart = '<a href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$this->id;
2102
+        }
2103
+
2104
+        // By default
2105
+        if (empty($linkstart))
2106
+        {
2107
+            $label.= '<u>' . $langs->trans("ShowCompany") . '</u>';
2108
+            $linkstart = '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$this->id;
2109
+        }
2110
+
2111
+        if (! empty($this->name))
2112
+        {
2113
+            $label.= '<br><b>' . $langs->trans('Name') . ':</b> '. $this->name;
2114
+            if (! empty($this->name_alias)) $label.=' ('.$this->name_alias.')';
2115
+            $label.= '<br><b>' . $langs->trans('Email') . ':</b> '. $this->email;
2116
+        }
2117
+        if (! empty($this->country_code))
2118
+            $label.= '<br><b>' . $langs->trans('Country') . ':</b> '. $this->country_code;
2119
+        if (! empty($this->tva_intra) || (! empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'vatnumber') !== false))
2120
+            $label.= '<br><b>' . $langs->trans('VATIntra') . ':</b> '. $this->tva_intra;
2121
+        if (! empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP))
2122
+        {
2123
+            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid1') !== false) $label.= '<br><b>' . $langs->trans('ProfId1'.$this->country_code) . ':</b> '. $this->idprof1;
2124
+            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid2') !== false) $label.= '<br><b>' . $langs->trans('ProfId2'.$this->country_code) . ':</b> '. $this->idprof2;
2125
+            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid3') !== false) $label.= '<br><b>' . $langs->trans('ProfId3'.$this->country_code) . ':</b> '. $this->idprof3;
2126
+            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid4') !== false) $label.= '<br><b>' . $langs->trans('ProfId4'.$this->country_code) . ':</b> '. $this->idprof4;
2127
+            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid5') !== false) $label.= '<br><b>' . $langs->trans('ProfId5'.$this->country_code) . ':</b> '. $this->idprof5;
2128
+            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid6') !== false) $label.= '<br><b>' . $langs->trans('ProfId6'.$this->country_code) . ':</b> '. $this->idprof6;
2129
+        }
2130
+        if (! empty($this->code_client) && ($this->client == 1 || $this->client == 3))
2131
+            $label.= '<br><b>' . $langs->trans('CustomerCode') . ':</b> '. $this->code_client;
2132
+        if (! empty($this->code_fournisseur) && $this->fournisseur)
2133
+            $label.= '<br><b>' . $langs->trans('SupplierCode') . ':</b> '. $this->code_fournisseur;
2134
+        if (! empty($conf->accounting->enabled) && ($this->client == 1 || $this->client == 3))
2135
+            $label.= '<br><b>' . $langs->trans('CustomerAccountancyCode') . ':</b> '. ($this->code_compta ? $this->code_compta : $this->code_compta_client);
2136
+        if (! empty($conf->accounting->enabled) && $this->fournisseur)
2137
+            $label.= '<br><b>' . $langs->trans('SupplierAccountancyCode') . ':</b> '. $this->code_compta_fournisseur;
2138
+
2139
+        $label.= '</div>';
2140
+
2141
+        // Add type of canvas
2142
+        $linkstart.=(!empty($this->canvas)?'&canvas='.$this->canvas:'');
2143
+        // Add param to save lastsearch_values or not
2144
+        $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
2145
+        if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
2146
+        if ($add_save_lastsearch_values) $linkstart.='&save_lastsearch_values=1';
2147
+        $linkstart.='"';
2148
+
2149
+        $linkclose='';
2150
+        if (empty($notooltip))
2151
+        {
2152
+            if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
2153
+            {
2154
+                $label=$langs->trans("ShowCompany");
2155
+                $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
2156
+            }
2157
+            $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
2158
+            $linkclose.=' class="classfortooltip refurl"';
2159
+
2160
+                /*
2161 2161
 			$hookmanager->initHooks(array('thirdpartydao'));
2162 2162
 			$parameters=array('id'=>$this->id);
2163 2163
 			$reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
2164 2164
 			if ($reshook > 0) $linkclose = $hookmanager->resPrint;
2165 2165
 			*/
2166
-		}
2167
-		$linkstart.=$linkclose.'>';
2168
-		$linkend='</a>';
2169
-
2170
-		global $user;
2171
-		if (! $user->rights->societe->client->voir && $user->societe_id > 0 && $this->id != $user->societe_id)
2172
-		{
2173
-			$linkstart='';
2174
-			$linkend='';
2175
-		}
2176
-
2177
-		$result.=$linkstart;
2178
-		if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip valigntextbottom"'), 0, 0, $notooltip?0:1);
2179
-		if ($withpicto != 2) $result.=($maxlen?dol_trunc($name,$maxlen):$name);
2180
-		$result.=$linkend;
2181
-
2182
-		global $action;
2183
-		$hookmanager->initHooks(array('thirdpartydao'));
2184
-		$parameters=array('id'=>$this->id, 'getnomurl'=>$result);
2185
-		$reshook=$hookmanager->executeHooks('getNomUrl',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
2186
-		if ($reshook > 0) $result = $hookmanager->resPrint;
2187
-		else $result .= $hookmanager->resPrint;
2188
-
2189
-		return $result;
2190
-	}
2191
-
2192
-	/**
2193
-	 *    Return label of status (activity, closed)
2194
-	 *
2195
-	 *    @param	int		$mode       0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
2196
-	 *    @return   string        		Libelle
2197
-	 */
2198
-	function getLibStatut($mode=0)
2199
-	{
2200
-		return $this->LibStatut($this->status,$mode);
2201
-	}
2166
+        }
2167
+        $linkstart.=$linkclose.'>';
2168
+        $linkend='</a>';
2169
+
2170
+        global $user;
2171
+        if (! $user->rights->societe->client->voir && $user->societe_id > 0 && $this->id != $user->societe_id)
2172
+        {
2173
+            $linkstart='';
2174
+            $linkend='';
2175
+        }
2176
+
2177
+        $result.=$linkstart;
2178
+        if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip valigntextbottom"'), 0, 0, $notooltip?0:1);
2179
+        if ($withpicto != 2) $result.=($maxlen?dol_trunc($name,$maxlen):$name);
2180
+        $result.=$linkend;
2181
+
2182
+        global $action;
2183
+        $hookmanager->initHooks(array('thirdpartydao'));
2184
+        $parameters=array('id'=>$this->id, 'getnomurl'=>$result);
2185
+        $reshook=$hookmanager->executeHooks('getNomUrl',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
2186
+        if ($reshook > 0) $result = $hookmanager->resPrint;
2187
+        else $result .= $hookmanager->resPrint;
2188
+
2189
+        return $result;
2190
+    }
2191
+
2192
+    /**
2193
+     *    Return label of status (activity, closed)
2194
+     *
2195
+     *    @param	int		$mode       0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
2196
+     *    @return   string        		Libelle
2197
+     */
2198
+    function getLibStatut($mode=0)
2199
+    {
2200
+        return $this->LibStatut($this->status,$mode);
2201
+    }
2202 2202
 
2203 2203
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2204
-	/**
2205
-	 *  Renvoi le libelle d'un statut donne
2206
-	 *
2207
-	 *  @param	int		$statut         Id statut
2208
-	 *  @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
2209
-	 *  @return	string          		Libelle du statut
2210
-	 */
2211
-	function LibStatut($statut,$mode=0)
2212
-	{
2204
+    /**
2205
+     *  Renvoi le libelle d'un statut donne
2206
+     *
2207
+     *  @param	int		$statut         Id statut
2208
+     *  @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
2209
+     *  @return	string          		Libelle du statut
2210
+     */
2211
+    function LibStatut($statut,$mode=0)
2212
+    {
2213 2213
         // phpcs:enable
2214
-		global $langs;
2215
-		$langs->load('companies');
2216
-
2217
-		if ($mode == 0)
2218
-		{
2219
-			if ($statut==0) return $langs->trans("ActivityCeased");
2220
-			elseif ($statut==1) return $langs->trans("InActivity");
2221
-		}
2222
-		elseif ($mode == 1)
2223
-		{
2224
-			if ($statut==0) return $langs->trans("ActivityCeased");
2225
-			elseif ($statut==1) return $langs->trans("InActivity");
2226
-		}
2227
-		elseif ($mode == 2)
2228
-		{
2229
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2230
-			elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2231
-		}
2232
-		elseif ($mode == 3)
2233
-		{
2234
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2235
-			elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2236
-		}
2237
-		elseif ($mode == 4)
2238
-		{
2239
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2240
-			elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2241
-		}
2242
-		elseif ($mode == 5)
2243
-		{
2244
-			if ($statut==0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2245
-			elseif ($statut==1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2246
-		}
2247
-		elseif ($mode == 6)
2248
-		{
2249
-			if ($statut==0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2250
-			elseif ($statut==1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2251
-		}
2252
-	}
2214
+        global $langs;
2215
+        $langs->load('companies');
2216
+
2217
+        if ($mode == 0)
2218
+        {
2219
+            if ($statut==0) return $langs->trans("ActivityCeased");
2220
+            elseif ($statut==1) return $langs->trans("InActivity");
2221
+        }
2222
+        elseif ($mode == 1)
2223
+        {
2224
+            if ($statut==0) return $langs->trans("ActivityCeased");
2225
+            elseif ($statut==1) return $langs->trans("InActivity");
2226
+        }
2227
+        elseif ($mode == 2)
2228
+        {
2229
+            if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2230
+            elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2231
+        }
2232
+        elseif ($mode == 3)
2233
+        {
2234
+            if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2235
+            elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2236
+        }
2237
+        elseif ($mode == 4)
2238
+        {
2239
+            if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2240
+            elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2241
+        }
2242
+        elseif ($mode == 5)
2243
+        {
2244
+            if ($statut==0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2245
+            elseif ($statut==1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2246
+        }
2247
+        elseif ($mode == 6)
2248
+        {
2249
+            if ($statut==0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2250
+            elseif ($statut==1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2251
+        }
2252
+    }
2253 2253
 
2254 2254
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2255
-	/**
2256
-	 *    Return list of contacts emails existing for third party
2257
-	 *
2258
-	 *	  @param	  int		$addthirdparty		1=Add also a record for thirdparty email
2259
-	 *    @return     array       					Array of contacts emails
2260
-	 */
2261
-	function thirdparty_and_contact_email_array($addthirdparty=0)
2262
-	{
2255
+    /**
2256
+     *    Return list of contacts emails existing for third party
2257
+     *
2258
+     *	  @param	  int		$addthirdparty		1=Add also a record for thirdparty email
2259
+     *    @return     array       					Array of contacts emails
2260
+     */
2261
+    function thirdparty_and_contact_email_array($addthirdparty=0)
2262
+    {
2263 2263
         // phpcs:enable
2264
-		global $langs;
2265
-
2266
-		$contact_emails = $this->contact_property_array('email',1);
2267
-		if ($this->email && $addthirdparty)
2268
-		{
2269
-			if (empty($this->name)) $this->name=$this->nom;
2270
-			$contact_emails['thirdparty']=$langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->email.">";
2271
-		}
2272
-		//var_dump($contact_emails)
2273
-		return $contact_emails;
2274
-	}
2264
+        global $langs;
2265
+
2266
+        $contact_emails = $this->contact_property_array('email',1);
2267
+        if ($this->email && $addthirdparty)
2268
+        {
2269
+            if (empty($this->name)) $this->name=$this->nom;
2270
+            $contact_emails['thirdparty']=$langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->email.">";
2271
+        }
2272
+        //var_dump($contact_emails)
2273
+        return $contact_emails;
2274
+    }
2275 2275
 
2276 2276
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2277
-	/**
2278
-	 *    Return list of contacts mobile phone existing for third party
2279
-	 *
2280
-	 *    @return     array       Array of contacts emails
2281
-	 */
2282
-	function thirdparty_and_contact_phone_array()
2283
-	{
2277
+    /**
2278
+     *    Return list of contacts mobile phone existing for third party
2279
+     *
2280
+     *    @return     array       Array of contacts emails
2281
+     */
2282
+    function thirdparty_and_contact_phone_array()
2283
+    {
2284 2284
         // phpcs:enable
2285
-		global $langs;
2285
+        global $langs;
2286 2286
 
2287
-		$contact_phone = $this->contact_property_array('mobile');
2287
+        $contact_phone = $this->contact_property_array('mobile');
2288 2288
 
2289
-		if (! empty($this->phone))	// If a phone of thirdparty is defined, we add it ot mobile of contacts
2290
-		{
2291
-			if (empty($this->name)) $this->name=$this->nom;
2292
-			// TODO: Tester si tel non deja present dans tableau contact
2293
-			$contact_phone['thirdparty']=$langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->phone.">";
2294
-		}
2295
-		return $contact_phone;
2296
-	}
2289
+        if (! empty($this->phone))	// If a phone of thirdparty is defined, we add it ot mobile of contacts
2290
+        {
2291
+            if (empty($this->name)) $this->name=$this->nom;
2292
+            // TODO: Tester si tel non deja present dans tableau contact
2293
+            $contact_phone['thirdparty']=$langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->phone.">";
2294
+        }
2295
+        return $contact_phone;
2296
+    }
2297 2297
 
2298 2298
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2299
-	/**
2300
-	 *  Return list of contacts emails or mobile existing for third party
2301
-	 *
2302
-	 *  @param	string	$mode       		'email' or 'mobile'
2303
-	 * 	@param	int		$hidedisabled		1=Hide contact if disabled
2304
-	 *  @return array       				Array of contacts emails or mobile. Example: array(id=>'Name <email>')
2305
-	 */
2306
-	function contact_property_array($mode='email', $hidedisabled=0)
2307
-	{
2299
+    /**
2300
+     *  Return list of contacts emails or mobile existing for third party
2301
+     *
2302
+     *  @param	string	$mode       		'email' or 'mobile'
2303
+     * 	@param	int		$hidedisabled		1=Hide contact if disabled
2304
+     *  @return array       				Array of contacts emails or mobile. Example: array(id=>'Name <email>')
2305
+     */
2306
+    function contact_property_array($mode='email', $hidedisabled=0)
2307
+    {
2308 2308
         // phpcs:enable
2309
-		global $langs;
2310
-
2311
-		$contact_property = array();
2312
-
2313
-
2314
-		$sql = "SELECT rowid, email, statut, phone_mobile, lastname, poste, firstname";
2315
-		$sql.= " FROM ".MAIN_DB_PREFIX."socpeople";
2316
-		$sql.= " WHERE fk_soc = ".$this->id;
2317
-
2318
-		$resql=$this->db->query($sql);
2319
-		if ($resql)
2320
-		{
2321
-			$nump = $this->db->num_rows($resql);
2322
-			if ($nump)
2323
-			{
2324
-				$sepa="("; $sepb=")";
2325
-				if ($mode == 'email')
2326
-				{
2327
-					//$sepa="&lt;"; $sepb="&gt;";
2328
-					$sepa="<"; $sepb=">";
2329
-				}
2330
-				$i = 0;
2331
-				while ($i < $nump)
2332
-				{
2333
-					$obj = $this->db->fetch_object($resql);
2334
-					if ($mode == 'email') $property=$obj->email;
2335
-					else if ($mode == 'mobile') $property=$obj->phone_mobile;
2336
-					else $property=$obj->$mode;
2337
-
2338
-					// Show all contact. If hidedisabled is 1, showonly contacts with status = 1
2339
-					if ($obj->statut == 1 || empty($hidedisabled))
2340
-					{
2341
-						if (empty($property))
2342
-						{
2343
-							if ($mode == 'email') $property=$langs->transnoentitiesnoconv("NoEMail");
2344
-							else if ($mode == 'mobile') $property=$langs->transnoentitiesnoconv("NoMobilePhone");
2345
-						}
2346
-
2347
-						if (!empty($obj->poste))
2348
-						{
2349
-							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname,$obj->lastname)).($obj->poste?" - ".$obj->poste:"").(($mode != 'poste' && $property)?" ".$sepa.$property.$sepb:'');
2350
-						}
2351
-						else
2352
-						{
2353
-							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname,$obj->lastname)).(($mode != 'poste' && $property)?" ".$sepa.$property.$sepb:'');
2354
-						}
2355
-					}
2356
-					$i++;
2357
-				}
2358
-			}
2359
-		}
2360
-		else
2361
-		{
2362
-			dol_print_error($this->db);
2363
-		}
2364
-		return $contact_property;
2365
-	}
2309
+        global $langs;
2310
+
2311
+        $contact_property = array();
2312
+
2313
+
2314
+        $sql = "SELECT rowid, email, statut, phone_mobile, lastname, poste, firstname";
2315
+        $sql.= " FROM ".MAIN_DB_PREFIX."socpeople";
2316
+        $sql.= " WHERE fk_soc = ".$this->id;
2317
+
2318
+        $resql=$this->db->query($sql);
2319
+        if ($resql)
2320
+        {
2321
+            $nump = $this->db->num_rows($resql);
2322
+            if ($nump)
2323
+            {
2324
+                $sepa="("; $sepb=")";
2325
+                if ($mode == 'email')
2326
+                {
2327
+                    //$sepa="&lt;"; $sepb="&gt;";
2328
+                    $sepa="<"; $sepb=">";
2329
+                }
2330
+                $i = 0;
2331
+                while ($i < $nump)
2332
+                {
2333
+                    $obj = $this->db->fetch_object($resql);
2334
+                    if ($mode == 'email') $property=$obj->email;
2335
+                    else if ($mode == 'mobile') $property=$obj->phone_mobile;
2336
+                    else $property=$obj->$mode;
2337
+
2338
+                    // Show all contact. If hidedisabled is 1, showonly contacts with status = 1
2339
+                    if ($obj->statut == 1 || empty($hidedisabled))
2340
+                    {
2341
+                        if (empty($property))
2342
+                        {
2343
+                            if ($mode == 'email') $property=$langs->transnoentitiesnoconv("NoEMail");
2344
+                            else if ($mode == 'mobile') $property=$langs->transnoentitiesnoconv("NoMobilePhone");
2345
+                        }
2346
+
2347
+                        if (!empty($obj->poste))
2348
+                        {
2349
+                            $contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname,$obj->lastname)).($obj->poste?" - ".$obj->poste:"").(($mode != 'poste' && $property)?" ".$sepa.$property.$sepb:'');
2350
+                        }
2351
+                        else
2352
+                        {
2353
+                            $contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname,$obj->lastname)).(($mode != 'poste' && $property)?" ".$sepa.$property.$sepb:'');
2354
+                        }
2355
+                    }
2356
+                    $i++;
2357
+                }
2358
+            }
2359
+        }
2360
+        else
2361
+        {
2362
+            dol_print_error($this->db);
2363
+        }
2364
+        return $contact_property;
2365
+    }
2366 2366
 
2367 2367
 
2368 2368
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2369
-	/**
2370
-	 *    Renvoie la liste des contacts de cette societe
2371
-	 *
2372
-	 *    @return     array      tableau des contacts
2373
-	 */
2374
-	function contact_array()
2375
-	{
2369
+    /**
2370
+     *    Renvoie la liste des contacts de cette societe
2371
+     *
2372
+     *    @return     array      tableau des contacts
2373
+     */
2374
+    function contact_array()
2375
+    {
2376 2376
         // phpcs:enable
2377
-		$contacts = array();
2378
-
2379
-		$sql = "SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id;
2380
-		$resql=$this->db->query($sql);
2381
-		if ($resql)
2382
-		{
2383
-			$nump = $this->db->num_rows($resql);
2384
-			if ($nump)
2385
-			{
2386
-				$i = 0;
2387
-				while ($i < $nump)
2388
-				{
2389
-					$obj = $this->db->fetch_object($resql);
2390
-					$contacts[$obj->rowid] = dolGetFirstLastname($obj->firstname,$obj->lastname);
2391
-					$i++;
2392
-				}
2393
-			}
2394
-		}
2395
-		else
2396
-		{
2397
-			dol_print_error($this->db);
2398
-		}
2399
-		return $contacts;
2400
-	}
2377
+        $contacts = array();
2378
+
2379
+        $sql = "SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id;
2380
+        $resql=$this->db->query($sql);
2381
+        if ($resql)
2382
+        {
2383
+            $nump = $this->db->num_rows($resql);
2384
+            if ($nump)
2385
+            {
2386
+                $i = 0;
2387
+                while ($i < $nump)
2388
+                {
2389
+                    $obj = $this->db->fetch_object($resql);
2390
+                    $contacts[$obj->rowid] = dolGetFirstLastname($obj->firstname,$obj->lastname);
2391
+                    $i++;
2392
+                }
2393
+            }
2394
+        }
2395
+        else
2396
+        {
2397
+            dol_print_error($this->db);
2398
+        }
2399
+        return $contacts;
2400
+    }
2401 2401
 
2402 2402
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2403
-	/**
2404
-	 *    Renvoie la liste des contacts de cette societe
2405
-	 *
2406
-	 *    @return    array    $contacts    tableau des contacts
2407
-	 */
2408
-	function contact_array_objects()
2409
-	{
2403
+    /**
2404
+     *    Renvoie la liste des contacts de cette societe
2405
+     *
2406
+     *    @return    array    $contacts    tableau des contacts
2407
+     */
2408
+    function contact_array_objects()
2409
+    {
2410 2410
         // phpcs:enable
2411
-		require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
2412
-		$contacts = array();
2413
-
2414
-		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id;
2415
-		$resql=$this->db->query($sql);
2416
-		if ($resql)
2417
-		{
2418
-			$nump = $this->db->num_rows($resql);
2419
-			if ($nump)
2420
-			{
2421
-				$i = 0;
2422
-				while ($i < $nump)
2423
-				{
2424
-					$obj = $this->db->fetch_object($resql);
2425
-					$contact = new Contact($this->db);
2426
-					$contact->fetch($obj->rowid);
2427
-					$contacts[] = $contact;
2428
-					$i++;
2429
-				}
2430
-			}
2431
-		}
2432
-		else
2433
-		{
2434
-			dol_print_error($this->db);
2435
-		}
2436
-		return $contacts;
2437
-	}
2411
+        require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
2412
+        $contacts = array();
2413
+
2414
+        $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id;
2415
+        $resql=$this->db->query($sql);
2416
+        if ($resql)
2417
+        {
2418
+            $nump = $this->db->num_rows($resql);
2419
+            if ($nump)
2420
+            {
2421
+                $i = 0;
2422
+                while ($i < $nump)
2423
+                {
2424
+                    $obj = $this->db->fetch_object($resql);
2425
+                    $contact = new Contact($this->db);
2426
+                    $contact->fetch($obj->rowid);
2427
+                    $contacts[] = $contact;
2428
+                    $i++;
2429
+                }
2430
+            }
2431
+        }
2432
+        else
2433
+        {
2434
+            dol_print_error($this->db);
2435
+        }
2436
+        return $contacts;
2437
+    }
2438 2438
 
2439 2439
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2440
-	/**
2441
-	 *  Return property of contact from its id
2442
-	 *
2443
-	 *  @param	int		$rowid      id of contact
2444
-	 *  @param  string	$mode       'email' or 'mobile'
2445
-	 *  @return string  			Email of contact with format: "Full name <email>"
2446
-	 */
2447
-	function contact_get_property($rowid,$mode)
2448
-	{
2440
+    /**
2441
+     *  Return property of contact from its id
2442
+     *
2443
+     *  @param	int		$rowid      id of contact
2444
+     *  @param  string	$mode       'email' or 'mobile'
2445
+     *  @return string  			Email of contact with format: "Full name <email>"
2446
+     */
2447
+    function contact_get_property($rowid,$mode)
2448
+    {
2449 2449
         // phpcs:enable
2450
-		$contact_property='';
2450
+        $contact_property='';
2451 2451
 
2452
-		if (empty($rowid)) return '';
2452
+        if (empty($rowid)) return '';
2453 2453
 
2454
-		$sql = "SELECT rowid, email, phone_mobile, lastname, firstname";
2455
-		$sql.= " FROM ".MAIN_DB_PREFIX."socpeople";
2456
-		$sql.= " WHERE rowid = '".$rowid."'";
2454
+        $sql = "SELECT rowid, email, phone_mobile, lastname, firstname";
2455
+        $sql.= " FROM ".MAIN_DB_PREFIX."socpeople";
2456
+        $sql.= " WHERE rowid = '".$rowid."'";
2457 2457
 
2458
-		$resql=$this->db->query($sql);
2459
-		if ($resql)
2460
-		{
2461
-			$nump = $this->db->num_rows($resql);
2458
+        $resql=$this->db->query($sql);
2459
+        if ($resql)
2460
+        {
2461
+            $nump = $this->db->num_rows($resql);
2462 2462
 
2463
-			if ($nump)
2464
-			{
2465
-				$obj = $this->db->fetch_object($resql);
2463
+            if ($nump)
2464
+            {
2465
+                $obj = $this->db->fetch_object($resql);
2466 2466
 
2467
-				if ($mode == 'email') $contact_property = dol_string_nospecial(dolGetFirstLastname($obj->firstname, $obj->lastname), ' ', array(","))." <".$obj->email.">";
2468
-				else if ($mode == 'mobile') $contact_property = $obj->phone_mobile;
2469
-			}
2470
-			return $contact_property;
2471
-		}
2472
-		else
2473
-		{
2474
-			dol_print_error($this->db);
2475
-		}
2476
-	}
2467
+                if ($mode == 'email') $contact_property = dol_string_nospecial(dolGetFirstLastname($obj->firstname, $obj->lastname), ' ', array(","))." <".$obj->email.">";
2468
+                else if ($mode == 'mobile') $contact_property = $obj->phone_mobile;
2469
+            }
2470
+            return $contact_property;
2471
+        }
2472
+        else
2473
+        {
2474
+            dol_print_error($this->db);
2475
+        }
2476
+    }
2477 2477
 
2478 2478
 
2479 2479
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2480
-	/**
2481
-	 *  Return bank number property of thirdparty (label or rum)
2482
-	 *
2483
-	 *	@param	string	$mode	'label' or 'rum' or 'format'
2484
-	 *  @return	string			Bank number
2485
-	 */
2486
-	function display_rib($mode='label')
2487
-	{
2480
+    /**
2481
+     *  Return bank number property of thirdparty (label or rum)
2482
+     *
2483
+     *	@param	string	$mode	'label' or 'rum' or 'format'
2484
+     *  @return	string			Bank number
2485
+     */
2486
+    function display_rib($mode='label')
2487
+    {
2488 2488
         // phpcs:enable
2489
-		require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
2490
-
2491
-		$bac = new CompanyBankAccount($this->db);
2492
-		$bac->fetch(0,$this->id);
2493
-
2494
-		if ($mode == 'label')
2495
-		{
2496
-			return $bac->getRibLabel(true);
2497
-		}
2498
-		elseif ($mode == 'rum')
2499
-		{
2500
-			if (empty($bac->rum))
2501
-			{
2502
-				require_once DOL_DOCUMENT_ROOT . '/compta/prelevement/class/bonprelevement.class.php';
2503
-				$prelevement = new BonPrelevement($this->db);
2504
-				$bac->fetch_thirdparty();
2505
-				$bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id);
2506
-			}
2507
-			return $bac->rum;
2508
-		}
2509
-		elseif ($mode == 'format')
2510
-		{
2511
-			return $bac->frstrecur;
2512
-		}
2513
-
2514
-		return 'BadParameterToFunctionDisplayRib';
2515
-	}
2489
+        require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
2490
+
2491
+        $bac = new CompanyBankAccount($this->db);
2492
+        $bac->fetch(0,$this->id);
2493
+
2494
+        if ($mode == 'label')
2495
+        {
2496
+            return $bac->getRibLabel(true);
2497
+        }
2498
+        elseif ($mode == 'rum')
2499
+        {
2500
+            if (empty($bac->rum))
2501
+            {
2502
+                require_once DOL_DOCUMENT_ROOT . '/compta/prelevement/class/bonprelevement.class.php';
2503
+                $prelevement = new BonPrelevement($this->db);
2504
+                $bac->fetch_thirdparty();
2505
+                $bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id);
2506
+            }
2507
+            return $bac->rum;
2508
+        }
2509
+        elseif ($mode == 'format')
2510
+        {
2511
+            return $bac->frstrecur;
2512
+        }
2513
+
2514
+        return 'BadParameterToFunctionDisplayRib';
2515
+    }
2516 2516
 
2517 2517
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2518
-	/**
2519
-	 * Return Array of RIB
2520
-	 *
2521
-	 * @return     array|int        0 if KO, Array of CompanyBanckAccount if OK
2522
-	 */
2523
-	function get_all_rib()
2524
-	{
2518
+    /**
2519
+     * Return Array of RIB
2520
+     *
2521
+     * @return     array|int        0 if KO, Array of CompanyBanckAccount if OK
2522
+     */
2523
+    function get_all_rib()
2524
+    {
2525 2525
         // phpcs:enable
2526
-		require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
2527
-		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_rib WHERE type='ban' AND fk_soc = ".$this->id;
2528
-		$result = $this->db->query($sql);
2529
-		if (!$result) {
2530
-			$this->error++;
2531
-			$this->errors[] = $this->db->lasterror;
2532
-			return 0;
2533
-		} else {
2534
-			$num_rows = $this->db->num_rows($result);
2535
-			$rib_array = array();
2536
-			if ($num_rows) {
2537
-				while ($obj = $this->db->fetch_object($result)) {
2538
-					$rib = new CompanyBankAccount($this->db);
2539
-					$rib->fetch($obj->rowid);
2540
-					$rib_array[] = $rib;
2541
-				}
2542
-			}
2543
-			return $rib_array;
2544
-		}
2545
-	}
2526
+        require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
2527
+        $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_rib WHERE type='ban' AND fk_soc = ".$this->id;
2528
+        $result = $this->db->query($sql);
2529
+        if (!$result) {
2530
+            $this->error++;
2531
+            $this->errors[] = $this->db->lasterror;
2532
+            return 0;
2533
+        } else {
2534
+            $num_rows = $this->db->num_rows($result);
2535
+            $rib_array = array();
2536
+            if ($num_rows) {
2537
+                while ($obj = $this->db->fetch_object($result)) {
2538
+                    $rib = new CompanyBankAccount($this->db);
2539
+                    $rib->fetch($obj->rowid);
2540
+                    $rib_array[] = $rib;
2541
+                }
2542
+            }
2543
+            return $rib_array;
2544
+        }
2545
+    }
2546 2546
 
2547 2547
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2548
-	/**
2549
-	 *  Attribut un code client a partir du module de controle des codes.
2550
-	 *  Return value is stored into this->code_client
2551
-	 *
2552
-	 *	@param	Societe		$objsoc		Object thirdparty
2553
-	 *	@param	int			$type		Should be 0 to say customer
2554
-	 *  @return void
2555
-	 */
2556
-	function get_codeclient($objsoc=0,$type=0)
2557
-	{
2548
+    /**
2549
+     *  Attribut un code client a partir du module de controle des codes.
2550
+     *  Return value is stored into this->code_client
2551
+     *
2552
+     *	@param	Societe		$objsoc		Object thirdparty
2553
+     *	@param	int			$type		Should be 0 to say customer
2554
+     *  @return void
2555
+     */
2556
+    function get_codeclient($objsoc=0,$type=0)
2557
+    {
2558 2558
         // phpcs:enable
2559
-		global $conf;
2560
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2561
-		{
2562
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2563
-
2564
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2565
-			foreach ($dirsociete as $dirroot)
2566
-			{
2567
-				$res=dol_include_once($dirroot.$module.'.php');
2568
-				if ($res) break;
2569
-			}
2570
-			$mod = new $module();
2571
-
2572
-			$this->code_client = $mod->getNextValue($objsoc,$type);
2573
-			$this->prefixCustomerIsRequired = $mod->prefixIsRequired;
2574
-
2575
-			dol_syslog(get_class($this)."::get_codeclient code_client=".$this->code_client." module=".$module);
2576
-		}
2577
-	}
2559
+        global $conf;
2560
+        if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2561
+        {
2562
+            $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2563
+
2564
+            $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2565
+            foreach ($dirsociete as $dirroot)
2566
+            {
2567
+                $res=dol_include_once($dirroot.$module.'.php');
2568
+                if ($res) break;
2569
+            }
2570
+            $mod = new $module();
2571
+
2572
+            $this->code_client = $mod->getNextValue($objsoc,$type);
2573
+            $this->prefixCustomerIsRequired = $mod->prefixIsRequired;
2574
+
2575
+            dol_syslog(get_class($this)."::get_codeclient code_client=".$this->code_client." module=".$module);
2576
+        }
2577
+    }
2578 2578
 
2579 2579
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2580
-	/**
2581
-	 *  Attribut un code fournisseur a partir du module de controle des codes.
2582
-	 *  Return value is stored into this->code_fournisseur
2583
-	 *
2584
-	 *	@param	Societe		$objsoc		Object thirdparty
2585
-	 *	@param	int			$type		Should be 1 to say supplier
2586
-	 *  @return void
2587
-	 */
2588
-	function get_codefournisseur($objsoc=0,$type=1)
2589
-	{
2580
+    /**
2581
+     *  Attribut un code fournisseur a partir du module de controle des codes.
2582
+     *  Return value is stored into this->code_fournisseur
2583
+     *
2584
+     *	@param	Societe		$objsoc		Object thirdparty
2585
+     *	@param	int			$type		Should be 1 to say supplier
2586
+     *  @return void
2587
+     */
2588
+    function get_codefournisseur($objsoc=0,$type=1)
2589
+    {
2590 2590
         // phpcs:enable
2591
-		global $conf;
2592
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2593
-		{
2594
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2591
+        global $conf;
2592
+        if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2593
+        {
2594
+            $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2595 2595
 
2596
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2597
-			foreach ($dirsociete as $dirroot)
2598
-			{
2599
-				$res=dol_include_once($dirroot.$module.'.php');
2600
-				if ($res) break;
2601
-			}
2602
-			$mod = new $module();
2596
+            $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2597
+            foreach ($dirsociete as $dirroot)
2598
+            {
2599
+                $res=dol_include_once($dirroot.$module.'.php');
2600
+                if ($res) break;
2601
+            }
2602
+            $mod = new $module();
2603 2603
 
2604
-			$this->code_fournisseur = $mod->getNextValue($objsoc,$type);
2604
+            $this->code_fournisseur = $mod->getNextValue($objsoc,$type);
2605 2605
 
2606
-			dol_syslog(get_class($this)."::get_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$module);
2607
-		}
2608
-	}
2606
+            dol_syslog(get_class($this)."::get_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$module);
2607
+        }
2608
+    }
2609 2609
 
2610 2610
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2611
-	/**
2612
-	 *    Verifie si un code client est modifiable en fonction des parametres
2613
-	 *    du module de controle des codes.
2614
-	 *
2615
-	 *    @return     int		0=No, 1=Yes
2616
-	 */
2617
-	function codeclient_modifiable()
2618
-	{
2611
+    /**
2612
+     *    Verifie si un code client est modifiable en fonction des parametres
2613
+     *    du module de controle des codes.
2614
+     *
2615
+     *    @return     int		0=No, 1=Yes
2616
+     */
2617
+    function codeclient_modifiable()
2618
+    {
2619 2619
         // phpcs:enable
2620
-		global $conf;
2621
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2622
-		{
2623
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2624
-
2625
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2626
-			foreach ($dirsociete as $dirroot)
2627
-			{
2628
-				$res=dol_include_once($dirroot.$module.'.php');
2629
-				if ($res) break;
2630
-			}
2631
-
2632
-			$mod = new $module();
2633
-
2634
-			dol_syslog(get_class($this)."::codeclient_modifiable code_client=".$this->code_client." module=".$module);
2635
-			if ($mod->code_modifiable_null && ! $this->code_client) return 1;
2636
-			if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) return 1;
2637
-			if ($mod->code_modifiable) return 1;	// A mettre en dernier
2638
-			return 0;
2639
-		}
2640
-		else
2641
-		{
2642
-			return 0;
2643
-		}
2644
-	}
2620
+        global $conf;
2621
+        if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2622
+        {
2623
+            $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2624
+
2625
+            $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2626
+            foreach ($dirsociete as $dirroot)
2627
+            {
2628
+                $res=dol_include_once($dirroot.$module.'.php');
2629
+                if ($res) break;
2630
+            }
2631
+
2632
+            $mod = new $module();
2633
+
2634
+            dol_syslog(get_class($this)."::codeclient_modifiable code_client=".$this->code_client." module=".$module);
2635
+            if ($mod->code_modifiable_null && ! $this->code_client) return 1;
2636
+            if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) return 1;
2637
+            if ($mod->code_modifiable) return 1;	// A mettre en dernier
2638
+            return 0;
2639
+        }
2640
+        else
2641
+        {
2642
+            return 0;
2643
+        }
2644
+    }
2645 2645
 
2646 2646
 
2647 2647
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2648
-	/**
2649
-	 *    Verifie si un code fournisseur est modifiable dans configuration du module de controle des codes
2650
-	 *
2651
-	 *    @return     int		0=No, 1=Yes
2652
-	 */
2653
-	function codefournisseur_modifiable()
2654
-	{
2648
+    /**
2649
+     *    Verifie si un code fournisseur est modifiable dans configuration du module de controle des codes
2650
+     *
2651
+     *    @return     int		0=No, 1=Yes
2652
+     */
2653
+    function codefournisseur_modifiable()
2654
+    {
2655 2655
         // phpcs:enable
2656
-		global $conf;
2657
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2658
-		{
2659
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2660
-
2661
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2662
-			foreach ($dirsociete as $dirroot)
2663
-			{
2664
-				$res=dol_include_once($dirroot.$module.'.php');
2665
-				if ($res) break;
2666
-			}
2667
-
2668
-			$mod = new $module();
2669
-
2670
-			dol_syslog(get_class($this)."::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur." module=".$module);
2671
-			if ($mod->code_modifiable_null && ! $this->code_fournisseur) return 1;
2672
-			if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) return 1;
2673
-			if ($mod->code_modifiable) return 1;	// A mettre en dernier
2674
-			return 0;
2675
-		}
2676
-		else
2677
-		{
2678
-			return 0;
2679
-		}
2680
-	}
2656
+        global $conf;
2657
+        if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2658
+        {
2659
+            $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2660
+
2661
+            $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2662
+            foreach ($dirsociete as $dirroot)
2663
+            {
2664
+                $res=dol_include_once($dirroot.$module.'.php');
2665
+                if ($res) break;
2666
+            }
2667
+
2668
+            $mod = new $module();
2669
+
2670
+            dol_syslog(get_class($this)."::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur." module=".$module);
2671
+            if ($mod->code_modifiable_null && ! $this->code_fournisseur) return 1;
2672
+            if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) return 1;
2673
+            if ($mod->code_modifiable) return 1;	// A mettre en dernier
2674
+            return 0;
2675
+        }
2676
+        else
2677
+        {
2678
+            return 0;
2679
+        }
2680
+    }
2681 2681
 
2682 2682
 
2683 2683
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2684
-	/**
2685
-	 *  Check customer code
2686
-	 *
2687
-	 *  @return     int				0 if OK
2688
-	 * 								-1 ErrorBadCustomerCodeSyntax
2689
-	 * 								-2 ErrorCustomerCodeRequired
2690
-	 * 								-3 ErrorCustomerCodeAlreadyUsed
2691
-	 * 								-4 ErrorPrefixRequired
2692
-	 */
2693
-	function check_codeclient()
2694
-	{
2684
+    /**
2685
+     *  Check customer code
2686
+     *
2687
+     *  @return     int				0 if OK
2688
+     * 								-1 ErrorBadCustomerCodeSyntax
2689
+     * 								-2 ErrorCustomerCodeRequired
2690
+     * 								-3 ErrorCustomerCodeAlreadyUsed
2691
+     * 								-4 ErrorPrefixRequired
2692
+     */
2693
+    function check_codeclient()
2694
+    {
2695 2695
         // phpcs:enable
2696
-		global $conf;
2697
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2698
-		{
2699
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2700
-
2701
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2702
-			foreach ($dirsociete as $dirroot)
2703
-			{
2704
-				$res=dol_include_once($dirroot.$module.'.php');
2705
-				if ($res) break;
2706
-			}
2707
-
2708
-			$mod = new $module();
2709
-
2710
-		   	dol_syslog(get_class($this)."::check_codeclient code_client=".$this->code_client." module=".$module);
2711
-		   	$result = $mod->verif($this->db, $this->code_client, $this, 0);
2712
-			return $result;
2713
-		}
2714
-		else
2715
-		{
2716
-			return 0;
2717
-		}
2718
-	}
2696
+        global $conf;
2697
+        if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2698
+        {
2699
+            $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2700
+
2701
+            $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2702
+            foreach ($dirsociete as $dirroot)
2703
+            {
2704
+                $res=dol_include_once($dirroot.$module.'.php');
2705
+                if ($res) break;
2706
+            }
2707
+
2708
+            $mod = new $module();
2709
+
2710
+                dol_syslog(get_class($this)."::check_codeclient code_client=".$this->code_client." module=".$module);
2711
+                $result = $mod->verif($this->db, $this->code_client, $this, 0);
2712
+            return $result;
2713
+        }
2714
+        else
2715
+        {
2716
+            return 0;
2717
+        }
2718
+    }
2719 2719
 
2720 2720
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2721
-	/**
2722
-	 *    Check supplier code
2723
-	 *
2724
-	 *    @return     int		0 if OK
2725
-	 * 							-1 ErrorBadCustomerCodeSyntax
2726
-	 * 							-2 ErrorCustomerCodeRequired
2727
-	 * 							-3 ErrorCustomerCodeAlreadyUsed
2728
-	 * 							-4 ErrorPrefixRequired
2729
-	 */
2730
-	function check_codefournisseur()
2731
-	{
2721
+    /**
2722
+     *    Check supplier code
2723
+     *
2724
+     *    @return     int		0 if OK
2725
+     * 							-1 ErrorBadCustomerCodeSyntax
2726
+     * 							-2 ErrorCustomerCodeRequired
2727
+     * 							-3 ErrorCustomerCodeAlreadyUsed
2728
+     * 							-4 ErrorPrefixRequired
2729
+     */
2730
+    function check_codefournisseur()
2731
+    {
2732 2732
         // phpcs:enable
2733
-		global $conf;
2734
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2735
-		{
2736
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2737
-
2738
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2739
-			foreach ($dirsociete as $dirroot)
2740
-			{
2741
-				$res=dol_include_once($dirroot.$module.'.php');
2742
-				if ($res) break;
2743
-			}
2744
-
2745
-			$mod = new $module();
2746
-
2747
-			dol_syslog(get_class($this)."::check_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$module);
2748
-			$result = $mod->verif($this->db, $this->code_fournisseur, $this, 1);
2749
-			return $result;
2750
-		}
2751
-		else
2752
-		{
2753
-			return 0;
2754
-		}
2755
-	}
2733
+        global $conf;
2734
+        if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2735
+        {
2736
+            $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2737
+
2738
+            $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2739
+            foreach ($dirsociete as $dirroot)
2740
+            {
2741
+                $res=dol_include_once($dirroot.$module.'.php');
2742
+                if ($res) break;
2743
+            }
2744
+
2745
+            $mod = new $module();
2746
+
2747
+            dol_syslog(get_class($this)."::check_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$module);
2748
+            $result = $mod->verif($this->db, $this->code_fournisseur, $this, 1);
2749
+            return $result;
2750
+        }
2751
+        else
2752
+        {
2753
+            return 0;
2754
+        }
2755
+    }
2756 2756
 
2757 2757
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2758
-	/**
2759
-	 *    	Renvoie un code compta, suivant le module de code compta.
2760
-	 *      Peut etre identique a celui saisit ou genere automatiquement.
2761
-	 *      A ce jour seule la generation automatique est implementee
2762
-	 *
2763
-	 *    	@param	string	$type		Type of thirdparty ('customer' or 'supplier')
2764
-	 *		@return	string				Code compta si ok, 0 si aucun, <0 si ko
2765
-	 */
2766
-	function get_codecompta($type)
2767
-	{
2758
+    /**
2759
+     *    	Renvoie un code compta, suivant le module de code compta.
2760
+     *      Peut etre identique a celui saisit ou genere automatiquement.
2761
+     *      A ce jour seule la generation automatique est implementee
2762
+     *
2763
+     *    	@param	string	$type		Type of thirdparty ('customer' or 'supplier')
2764
+     *		@return	string				Code compta si ok, 0 si aucun, <0 si ko
2765
+     */
2766
+    function get_codecompta($type)
2767
+    {
2768 2768
         // phpcs:enable
2769
-		global $conf;
2770
-
2771
-		if (! empty($conf->global->SOCIETE_CODECOMPTA_ADDON))
2772
-		{
2773
-			$res=false;
2774
-			$dirsociete=array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2775
-			foreach ($dirsociete as $dirroot)
2776
-			{
2777
-				$res=dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.'.php');
2778
-				if ($res) break;
2779
-			}
2780
-
2781
-			if ($res)
2782
-			{
2783
-				$classname = $conf->global->SOCIETE_CODECOMPTA_ADDON;
2784
-				$mod = new $classname;
2785
-
2786
-				// Defini code compta dans $mod->code
2787
-				$result = $mod->get_code($this->db, $this, $type);
2788
-
2789
-				if ($type == 'customer') $this->code_compta = $mod->code;
2790
-				else if ($type == 'supplier') $this->code_compta_fournisseur = $mod->code;
2791
-
2792
-				return $result;
2793
-			}
2794
-			else
2795
-			{
2796
-				$this->error = 'ErrorAccountancyCodeNotDefined';
2797
-				return -1;
2798
-			}
2799
-		}
2800
-		else
2801
-		{
2802
-			if ($type == 'customer') $this->code_compta = '';
2803
-			else if ($type == 'supplier') $this->code_compta_fournisseur = '';
2804
-
2805
-			return 0;
2806
-		}
2807
-	}
2769
+        global $conf;
2770
+
2771
+        if (! empty($conf->global->SOCIETE_CODECOMPTA_ADDON))
2772
+        {
2773
+            $res=false;
2774
+            $dirsociete=array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2775
+            foreach ($dirsociete as $dirroot)
2776
+            {
2777
+                $res=dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.'.php');
2778
+                if ($res) break;
2779
+            }
2780
+
2781
+            if ($res)
2782
+            {
2783
+                $classname = $conf->global->SOCIETE_CODECOMPTA_ADDON;
2784
+                $mod = new $classname;
2785
+
2786
+                // Defini code compta dans $mod->code
2787
+                $result = $mod->get_code($this->db, $this, $type);
2788
+
2789
+                if ($type == 'customer') $this->code_compta = $mod->code;
2790
+                else if ($type == 'supplier') $this->code_compta_fournisseur = $mod->code;
2791
+
2792
+                return $result;
2793
+            }
2794
+            else
2795
+            {
2796
+                $this->error = 'ErrorAccountancyCodeNotDefined';
2797
+                return -1;
2798
+            }
2799
+        }
2800
+        else
2801
+        {
2802
+            if ($type == 'customer') $this->code_compta = '';
2803
+            else if ($type == 'supplier') $this->code_compta_fournisseur = '';
2804
+
2805
+            return 0;
2806
+        }
2807
+    }
2808 2808
 
2809 2809
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2810
-	/**
2811
-	 *    Define parent commany of current company
2812
-	 *
2813
-	 *    @param	int		$id     Id of thirdparty to set or '' to remove
2814
-	 *    @return	int     		<0 if KO, >0 if OK
2815
-	 */
2816
-	function set_parent($id)
2817
-	{
2810
+    /**
2811
+     *    Define parent commany of current company
2812
+     *
2813
+     *    @param	int		$id     Id of thirdparty to set or '' to remove
2814
+     *    @return	int     		<0 if KO, >0 if OK
2815
+     */
2816
+    function set_parent($id)
2817
+    {
2818 2818
         // phpcs:enable
2819
-		if ($this->id)
2820
-		{
2821
-			$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
2822
-			$sql.= " SET parent = ".($id > 0 ? $id : "null");
2823
-			$sql.= " WHERE rowid = " . $this->id;
2824
-			dol_syslog(get_class($this).'::set_parent', LOG_DEBUG);
2825
-			$resql=$this->db->query($sql);
2826
-			if ($resql)
2827
-			{
2828
-				$this->parent = $id;
2829
-				return 1;
2830
-			}
2831
-			else
2832
-			{
2833
-				return -1;
2834
-			}
2835
-		}
2836
-		else return -1;
2837
-	}
2819
+        if ($this->id)
2820
+        {
2821
+            $sql = "UPDATE ".MAIN_DB_PREFIX."societe";
2822
+            $sql.= " SET parent = ".($id > 0 ? $id : "null");
2823
+            $sql.= " WHERE rowid = " . $this->id;
2824
+            dol_syslog(get_class($this).'::set_parent', LOG_DEBUG);
2825
+            $resql=$this->db->query($sql);
2826
+            if ($resql)
2827
+            {
2828
+                $this->parent = $id;
2829
+                return 1;
2830
+            }
2831
+            else
2832
+            {
2833
+                return -1;
2834
+            }
2835
+        }
2836
+        else return -1;
2837
+    }
2838 2838
 
2839 2839
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2840
-	/**
2841
-	 *  Returns if a profid sould be verified
2842
-	 *
2843
-	 *  @param	int		$idprof		1,2,3,4,5,6 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm,5=idprof5,6=idprof6)
2844
-	 *  @return boolean         	true , false
2845
-	 */
2846
-	function id_prof_verifiable($idprof)
2847
-	{
2840
+    /**
2841
+     *  Returns if a profid sould be verified
2842
+     *
2843
+     *  @param	int		$idprof		1,2,3,4,5,6 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm,5=idprof5,6=idprof6)
2844
+     *  @return boolean         	true , false
2845
+     */
2846
+    function id_prof_verifiable($idprof)
2847
+    {
2848 2848
         // phpcs:enable
2849
-		global $conf;
2850
-
2851
-	 	switch($idprof)
2852
-		{
2853
-			case 1:
2854
-				$ret=(!$conf->global->SOCIETE_IDPROF1_UNIQUE?false:true);
2855
-				break;
2856
-			case 2:
2857
-				$ret=(!$conf->global->SOCIETE_IDPROF2_UNIQUE?false:true);
2858
-				break;
2859
-			case 3:
2860
-				$ret=(!$conf->global->SOCIETE_IDPROF3_UNIQUE?false:true);
2861
-				break;
2862
-			case 4:
2863
-				$ret=(!$conf->global->SOCIETE_IDPROF4_UNIQUE?false:true);
2864
-				break;
2865
-			case 5:
2866
-				$ret=(!$conf->global->SOCIETE_IDPROF5_UNIQUE?false:true);
2867
-				break;
2868
-			case 6:
2869
-				$ret=(!$conf->global->SOCIETE_IDPROF6_UNIQUE?false:true);
2870
-				break;
2871
-			default:
2872
-				$ret=false;
2873
-		}
2874
-
2875
-		return $ret;
2876
-	}
2849
+        global $conf;
2850
+
2851
+            switch($idprof)
2852
+        {
2853
+            case 1:
2854
+                $ret=(!$conf->global->SOCIETE_IDPROF1_UNIQUE?false:true);
2855
+                break;
2856
+            case 2:
2857
+                $ret=(!$conf->global->SOCIETE_IDPROF2_UNIQUE?false:true);
2858
+                break;
2859
+            case 3:
2860
+                $ret=(!$conf->global->SOCIETE_IDPROF3_UNIQUE?false:true);
2861
+                break;
2862
+            case 4:
2863
+                $ret=(!$conf->global->SOCIETE_IDPROF4_UNIQUE?false:true);
2864
+                break;
2865
+            case 5:
2866
+                $ret=(!$conf->global->SOCIETE_IDPROF5_UNIQUE?false:true);
2867
+                break;
2868
+            case 6:
2869
+                $ret=(!$conf->global->SOCIETE_IDPROF6_UNIQUE?false:true);
2870
+                break;
2871
+            default:
2872
+                $ret=false;
2873
+        }
2874
+
2875
+        return $ret;
2876
+    }
2877 2877
 
2878 2878
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2879
-	/**
2880
-	 *    Verify if a profid exists into database for others thirds
2881
-	 *
2882
-	 *    @param	string	$idprof		'idprof1','idprof2','idprof3','idprof4','idprof5','idprof6','email' (Example: idprof1=siren, idprof2=siret, idprof3=naf, idprof4=rcs/rm)
2883
-	 *    @param	string	$value		Value of profid
2884
-	 *    @param	int		$socid		Id of thirdparty to exclude (if update)
2885
-	 *    @return   boolean				True if exists, False if not
2886
-	 */
2887
-	function id_prof_exists($idprof, $value, $socid=0)
2888
-	{
2879
+    /**
2880
+     *    Verify if a profid exists into database for others thirds
2881
+     *
2882
+     *    @param	string	$idprof		'idprof1','idprof2','idprof3','idprof4','idprof5','idprof6','email' (Example: idprof1=siren, idprof2=siret, idprof3=naf, idprof4=rcs/rm)
2883
+     *    @param	string	$value		Value of profid
2884
+     *    @param	int		$socid		Id of thirdparty to exclude (if update)
2885
+     *    @return   boolean				True if exists, False if not
2886
+     */
2887
+    function id_prof_exists($idprof, $value, $socid=0)
2888
+    {
2889 2889
         // phpcs:enable
2890
-		$field = $idprof;
2891
-
2892
-	 	switch($idprof)	// For backward compatibility
2893
-		{
2894
-			case '1':
2895
-			case 'idprof1':
2896
-				$field="siren";
2897
-				break;
2898
-			case '2':
2899
-			case 'idprof2':
2900
-				$field="siret";
2901
-				break;
2902
-			case '3':
2903
-			case 'idprof3':
2904
-				$field="ape";
2905
-				break;
2906
-			case '4':
2907
-			case 'idprof4':
2908
-				$field="idprof4";
2909
-				break;
2910
-			case '5':
2911
-				$field="idprof5";
2912
-				break;
2913
-			case '6':
2914
-				$field="idprof6";
2915
-				break;
2916
-	 	}
2917
-
2918
-		 //Verify duplicate entries
2919
-		$sql  = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$value."' AND entity IN (".getEntity('societe').")";
2920
-		if($socid) $sql .= " AND rowid <> ".$socid;
2921
-		$resql = $this->db->query($sql);
2922
-		if ($resql)
2923
-		{
2924
-			$obj = $this->db->fetch_object($resql);
2925
-			$count = $obj->idprof;
2926
-		}
2927
-		else
2928
-		{
2929
-			$count = 0;
2930
-			print $this->db->error();
2931
-		}
2932
-		$this->db->free($resql);
2933
-
2934
-		if ($count > 0) return true;
2935
-		else return false;
2936
-	}
2890
+        $field = $idprof;
2891
+
2892
+            switch($idprof)	// For backward compatibility
2893
+        {
2894
+            case '1':
2895
+            case 'idprof1':
2896
+                $field="siren";
2897
+                break;
2898
+            case '2':
2899
+            case 'idprof2':
2900
+                $field="siret";
2901
+                break;
2902
+            case '3':
2903
+            case 'idprof3':
2904
+                $field="ape";
2905
+                break;
2906
+            case '4':
2907
+            case 'idprof4':
2908
+                $field="idprof4";
2909
+                break;
2910
+            case '5':
2911
+                $field="idprof5";
2912
+                break;
2913
+            case '6':
2914
+                $field="idprof6";
2915
+                break;
2916
+            }
2917
+
2918
+            //Verify duplicate entries
2919
+        $sql  = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$value."' AND entity IN (".getEntity('societe').")";
2920
+        if($socid) $sql .= " AND rowid <> ".$socid;
2921
+        $resql = $this->db->query($sql);
2922
+        if ($resql)
2923
+        {
2924
+            $obj = $this->db->fetch_object($resql);
2925
+            $count = $obj->idprof;
2926
+        }
2927
+        else
2928
+        {
2929
+            $count = 0;
2930
+            print $this->db->error();
2931
+        }
2932
+        $this->db->free($resql);
2933
+
2934
+        if ($count > 0) return true;
2935
+        else return false;
2936
+    }
2937 2937
 
2938 2938
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2939
-	/**
2940
-	 *  Verifie la validite d'un identifiant professionnel en fonction du pays de la societe (siren, siret, ...)
2941
-	 *
2942
-	 *  @param	int			$idprof         1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm)
2943
-	 *  @param  Societe		$soc            Objet societe
2944
-	 *  @return int             			<=0 if KO, >0 if OK
2945
-	 *  TODO better to have this in a lib than into a business class
2946
-	 */
2947
-	function id_prof_check($idprof,$soc)
2948
-	{
2939
+    /**
2940
+     *  Verifie la validite d'un identifiant professionnel en fonction du pays de la societe (siren, siret, ...)
2941
+     *
2942
+     *  @param	int			$idprof         1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm)
2943
+     *  @param  Societe		$soc            Objet societe
2944
+     *  @return int             			<=0 if KO, >0 if OK
2945
+     *  TODO better to have this in a lib than into a business class
2946
+     */
2947
+    function id_prof_check($idprof,$soc)
2948
+    {
2949 2949
         // phpcs:enable
2950
-		global $conf;
2951
-
2952
-		$ok=1;
2953
-
2954
-		if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) return 1;
2955
-
2956
-		// Verifie SIREN si pays FR
2957
-		if ($idprof == 1 && $soc->country_code == 'FR')
2958
-		{
2959
-			$chaine=trim($this->idprof1);
2960
-			$chaine=preg_replace('/(\s)/','',$chaine);
2961
-
2962
-			if (!is_numeric($chaine)) return -1;
2963
-			if (dol_strlen($chaine) != 9) return -1;
2964
-
2965
-			// on prend chaque chiffre un par un
2966
-			// si son index (position dans la chaîne en commence à 0 au premier caractère) est impair
2967
-			// on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9
2968
-			// on ajoute cette valeur à la somme totale
2969
-
2970
-			for ($index = 0; $index < 9; $index ++)
2971
-			{
2972
-				$number = (int) $siren[$index];
2973
-				if (($index % 2) != 0) { if (($number *= 2) > 9) $number -= 9; }
2974
-				$sum += $number;
2975
-			}
2976
-
2977
-			// le numéro est valide si la somme des chiffres est multiple de 10
2978
-			if (($sum % 10) != 0) return -1;
2979
-		}
2980
-
2981
-		// Verifie SIRET si pays FR
2982
-		if ($idprof == 2 && $soc->country_code == 'FR')
2983
-		{
2984
-			$chaine=trim($this->idprof2);
2985
-			$chaine=preg_replace('/(\s)/','',$chaine);
2986
-
2987
-			if (!is_numeric($chaine)) return -1;
2988
-			if (dol_strlen($chaine) != 14) return -1;
2989
-
2990
-			// on prend chaque chiffre un par un
2991
-			// si son index (position dans la chaîne en commence à 0 au premier caractère) est pair
2992
-			// on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9
2993
-			// on ajoute cette valeur à la somme totale
2994
-
2995
-			for ($index = 0; $index < 14; $index ++)
2996
-			{
2997
-				$number = (int) $chaine[$index];
2998
-				if (($index % 2) == 0) { if (($number *= 2) > 9) $number -= 9; }
2999
-				$sum += $number;
3000
-			}
3001
-
3002
-			// le numéro est valide si la somme des chiffres est multiple de 10
3003
-			if (($sum % 10) != 0) return -1;
3004
-		}
3005
-
3006
-		//Verify CIF/NIF/NIE if pays ES
3007
-		//Returns: 1 if NIF ok, 2 if CIF ok, 3 if NIE ok, -1 if NIF bad, -2 if CIF bad, -3 if NIE bad, 0 if unexpected bad
3008
-		if ($idprof == 1 && $soc->country_code == 'ES')
3009
-		{
3010
-			$string=trim($this->idprof1);
3011
-			$string=preg_replace('/(\s)/','',$string);
3012
-			$string = strtoupper($string);
3013
-
3014
-			for ($i = 0; $i < 9; $i ++)
3015
-			$num[$i] = substr($string, $i, 1);
3016
-
3017
-			//Check format
3018
-			if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string))
3019
-			return 0;
3020
-
3021
-			//Check NIF
3022
-			if (preg_match('/(^[0-9]{8}[A-Z]{1}$)/', $string))
3023
-				if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1))
3024
-				return 1;
3025
-				else
3026
-				return -1;
3027
-
3028
-			//algorithm checking type code CIF
3029
-			$sum = $num[2] + $num[4] + $num[6];
3030
-			for ($i = 1; $i < 8; $i += 2)
3031
-			$sum += intval(substr((2 * $num[$i]),0,1)) + intval(substr((2 * $num[$i]),1,1));
3032
-			$n = 10 - substr($sum, strlen($sum) - 1, 1);
3033
-
3034
-			//Chek special NIF
3035
-			if (preg_match('/^[KLM]{1}/', $string))
3036
-				if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1))
3037
-				return 1;
3038
-				else
3039
-				return -1;
3040
-
3041
-			//Check CIF
3042
-			if (preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $string))
3043
-				if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1))
3044
-				return 2;
3045
-				else
3046
-				return -2;
3047
-
3048
-			//Check NIE T
3049
-			if (preg_match('/^[T]{1}/', $string))
3050
-				if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string))
3051
-				return 3;
3052
-				else
3053
-				return -3;
3054
-
3055
-			//Check NIE XYZ
3056
-			if (preg_match('/^[XYZ]{1}/', $string))
3057
-				if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X','Y','Z'), array('0','1','2'), $string), 0, 8) % 23, 1))
3058
-				return 3;
3059
-				else
3060
-				return -3;
3061
-
3062
-			//Can not be verified
3063
-			return -4;
3064
-		}
3065
-
3066
-		//Verify NIF if country is PT
3067
-		//Returns: 1 if NIF ok, -1 if NIF bad, 0 if unexpected bad
3068
-		if ($idprof == 1 && $soc->country_code == 'PT')
3069
-		{
3070
-			$string=trim($this->idprof1);
3071
-			$string=preg_replace('/(\s)/','',$string);
3072
-
3073
-			for ($i = 0; $i < 9; $i ++) {
3074
-				$num[$i] = substr($string, $i, 1);
3075
-			}
3076
-
3077
-			//Check NIF
3078
-			if (preg_match('/(^[0-9]{9}$)/', $string)) {
3079
-				return 1;
3080
-			}
3081
-			else {
3082
-				return -1;
3083
-			}
3084
-		}
3085
-
3086
-		return $ok;
3087
-	}
2950
+        global $conf;
2951
+
2952
+        $ok=1;
2953
+
2954
+        if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) return 1;
2955
+
2956
+        // Verifie SIREN si pays FR
2957
+        if ($idprof == 1 && $soc->country_code == 'FR')
2958
+        {
2959
+            $chaine=trim($this->idprof1);
2960
+            $chaine=preg_replace('/(\s)/','',$chaine);
2961
+
2962
+            if (!is_numeric($chaine)) return -1;
2963
+            if (dol_strlen($chaine) != 9) return -1;
2964
+
2965
+            // on prend chaque chiffre un par un
2966
+            // si son index (position dans la chaîne en commence à 0 au premier caractère) est impair
2967
+            // on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9
2968
+            // on ajoute cette valeur à la somme totale
2969
+
2970
+            for ($index = 0; $index < 9; $index ++)
2971
+            {
2972
+                $number = (int) $siren[$index];
2973
+                if (($index % 2) != 0) { if (($number *= 2) > 9) $number -= 9; }
2974
+                $sum += $number;
2975
+            }
2976
+
2977
+            // le numéro est valide si la somme des chiffres est multiple de 10
2978
+            if (($sum % 10) != 0) return -1;
2979
+        }
2980
+
2981
+        // Verifie SIRET si pays FR
2982
+        if ($idprof == 2 && $soc->country_code == 'FR')
2983
+        {
2984
+            $chaine=trim($this->idprof2);
2985
+            $chaine=preg_replace('/(\s)/','',$chaine);
2986
+
2987
+            if (!is_numeric($chaine)) return -1;
2988
+            if (dol_strlen($chaine) != 14) return -1;
2989
+
2990
+            // on prend chaque chiffre un par un
2991
+            // si son index (position dans la chaîne en commence à 0 au premier caractère) est pair
2992
+            // on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9
2993
+            // on ajoute cette valeur à la somme totale
2994
+
2995
+            for ($index = 0; $index < 14; $index ++)
2996
+            {
2997
+                $number = (int) $chaine[$index];
2998
+                if (($index % 2) == 0) { if (($number *= 2) > 9) $number -= 9; }
2999
+                $sum += $number;
3000
+            }
3001
+
3002
+            // le numéro est valide si la somme des chiffres est multiple de 10
3003
+            if (($sum % 10) != 0) return -1;
3004
+        }
3005
+
3006
+        //Verify CIF/NIF/NIE if pays ES
3007
+        //Returns: 1 if NIF ok, 2 if CIF ok, 3 if NIE ok, -1 if NIF bad, -2 if CIF bad, -3 if NIE bad, 0 if unexpected bad
3008
+        if ($idprof == 1 && $soc->country_code == 'ES')
3009
+        {
3010
+            $string=trim($this->idprof1);
3011
+            $string=preg_replace('/(\s)/','',$string);
3012
+            $string = strtoupper($string);
3013
+
3014
+            for ($i = 0; $i < 9; $i ++)
3015
+            $num[$i] = substr($string, $i, 1);
3016
+
3017
+            //Check format
3018
+            if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string))
3019
+            return 0;
3020
+
3021
+            //Check NIF
3022
+            if (preg_match('/(^[0-9]{8}[A-Z]{1}$)/', $string))
3023
+                if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1))
3024
+                return 1;
3025
+                else
3026
+                return -1;
3027
+
3028
+            //algorithm checking type code CIF
3029
+            $sum = $num[2] + $num[4] + $num[6];
3030
+            for ($i = 1; $i < 8; $i += 2)
3031
+            $sum += intval(substr((2 * $num[$i]),0,1)) + intval(substr((2 * $num[$i]),1,1));
3032
+            $n = 10 - substr($sum, strlen($sum) - 1, 1);
3033
+
3034
+            //Chek special NIF
3035
+            if (preg_match('/^[KLM]{1}/', $string))
3036
+                if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1))
3037
+                return 1;
3038
+                else
3039
+                return -1;
3040
+
3041
+            //Check CIF
3042
+            if (preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $string))
3043
+                if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1))
3044
+                return 2;
3045
+                else
3046
+                return -2;
3047
+
3048
+            //Check NIE T
3049
+            if (preg_match('/^[T]{1}/', $string))
3050
+                if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string))
3051
+                return 3;
3052
+                else
3053
+                return -3;
3054
+
3055
+            //Check NIE XYZ
3056
+            if (preg_match('/^[XYZ]{1}/', $string))
3057
+                if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X','Y','Z'), array('0','1','2'), $string), 0, 8) % 23, 1))
3058
+                return 3;
3059
+                else
3060
+                return -3;
3061
+
3062
+            //Can not be verified
3063
+            return -4;
3064
+        }
3065
+
3066
+        //Verify NIF if country is PT
3067
+        //Returns: 1 if NIF ok, -1 if NIF bad, 0 if unexpected bad
3068
+        if ($idprof == 1 && $soc->country_code == 'PT')
3069
+        {
3070
+            $string=trim($this->idprof1);
3071
+            $string=preg_replace('/(\s)/','',$string);
3072
+
3073
+            for ($i = 0; $i < 9; $i ++) {
3074
+                $num[$i] = substr($string, $i, 1);
3075
+            }
3076
+
3077
+            //Check NIF
3078
+            if (preg_match('/(^[0-9]{9}$)/', $string)) {
3079
+                return 1;
3080
+            }
3081
+            else {
3082
+                return -1;
3083
+            }
3084
+        }
3085
+
3086
+        return $ok;
3087
+    }
3088 3088
 
3089 3089
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3090
-	/**
3091
-	 *   Return an url to check online a professional id or empty string
3092
-	 *
3093
-	 *   @param		int		$idprof         1,2,3,4 (Example: 1=siren,2=siret,3=naf,4=rcs/rm)
3094
-	 *   @param 	Societe	$thirdparty     Object thirdparty
3095
-	 *   @return	string          		Url or empty string if no URL known
3096
-	 *   TODO better in a lib than into business class
3097
-	 */
3098
-	function id_prof_url($idprof,$thirdparty)
3099
-	{
3090
+    /**
3091
+     *   Return an url to check online a professional id or empty string
3092
+     *
3093
+     *   @param		int		$idprof         1,2,3,4 (Example: 1=siren,2=siret,3=naf,4=rcs/rm)
3094
+     *   @param 	Societe	$thirdparty     Object thirdparty
3095
+     *   @return	string          		Url or empty string if no URL known
3096
+     *   TODO better in a lib than into business class
3097
+     */
3098
+    function id_prof_url($idprof,$thirdparty)
3099
+    {
3100 3100
         // phpcs:enable
3101
-		global $conf,$langs,$hookmanager;
3101
+        global $conf,$langs,$hookmanager;
3102 3102
 
3103
-		$url='';
3104
-		$action = '';
3103
+        $url='';
3104
+        $action = '';
3105 3105
 
3106
-		$hookmanager->initHooks(array('idprofurl'));
3107
-		$parameters=array('idprof'=>$idprof, 'company'=>$thirdparty);
3108
-		$reshook=$hookmanager->executeHooks('getIdProfUrl',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
3109
-		if (empty($reshook)) {
3110
-			if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
3111
-				return '';
3112
-			}
3106
+        $hookmanager->initHooks(array('idprofurl'));
3107
+        $parameters=array('idprof'=>$idprof, 'company'=>$thirdparty);
3108
+        $reshook=$hookmanager->executeHooks('getIdProfUrl',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
3109
+        if (empty($reshook)) {
3110
+            if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
3111
+                return '';
3112
+            }
3113 3113
 
3114
-			// TODO Move links to validate professional ID into a dictionary table "country" + "link"
3114
+            // TODO Move links to validate professional ID into a dictionary table "country" + "link"
3115 3115
             $strippedIdProf1 = str_replace(' ', '', $thirdparty->idprof1);
3116
-			if ($idprof == 1 && $thirdparty->country_code == 'FR') {
3117
-				$url='http://www.societe.com/cgi-bin/search?champs='.$strippedIdProf1;    // See also http://avis-situation-sirene.insee.fr/
3118
-			}
3119
-			if ($idprof == 1 && ($thirdparty->country_code == 'GB' || $thirdparty->country_code == 'UK')) {
3120
-				$url='https://beta.companieshouse.gov.uk/company/'.$strippedIdProf1;
3121
-			}
3122
-			if ($idprof == 1 && $thirdparty->country_code == 'ES') {
3123
-				$url='http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$strippedIdProf1;
3124
-			}
3125
-			if ($idprof == 1 && $thirdparty->country_code == 'IN') {
3126
-				$url='http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$strippedIdProf1.';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
3127
-			}
3128
-			if ($idprof == 1 && $thirdparty->country_code == 'PT') {
3129
-				$url='http://www.nif.pt/'.$strippedIdProf1;
3130
-			}
3131
-
3132
-			if ($url) {
3133
-				return '<a target="_blank" href="'.$url.'">'.$langs->trans("Check").'</a>';
3134
-			}
3135
-		}
3136
-		else {
3137
-			return $hookmanager->resPrint;
3138
-		}
3139
-
3140
-		return '';
3141
-	}
3116
+            if ($idprof == 1 && $thirdparty->country_code == 'FR') {
3117
+                $url='http://www.societe.com/cgi-bin/search?champs='.$strippedIdProf1;    // See also http://avis-situation-sirene.insee.fr/
3118
+            }
3119
+            if ($idprof == 1 && ($thirdparty->country_code == 'GB' || $thirdparty->country_code == 'UK')) {
3120
+                $url='https://beta.companieshouse.gov.uk/company/'.$strippedIdProf1;
3121
+            }
3122
+            if ($idprof == 1 && $thirdparty->country_code == 'ES') {
3123
+                $url='http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$strippedIdProf1;
3124
+            }
3125
+            if ($idprof == 1 && $thirdparty->country_code == 'IN') {
3126
+                $url='http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$strippedIdProf1.';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
3127
+            }
3128
+            if ($idprof == 1 && $thirdparty->country_code == 'PT') {
3129
+                $url='http://www.nif.pt/'.$strippedIdProf1;
3130
+            }
3131
+
3132
+            if ($url) {
3133
+                return '<a target="_blank" href="'.$url.'">'.$langs->trans("Check").'</a>';
3134
+            }
3135
+        }
3136
+        else {
3137
+            return $hookmanager->resPrint;
3138
+        }
3139
+
3140
+        return '';
3141
+    }
3142 3142
 
3143 3143
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3144
-	/**
3145
-	 *   Indique si la societe a des projets
3146
-	 *
3147
-	 *   @return     bool	   true si la societe a des projets, false sinon
3148
-	 */
3149
-	function has_projects()
3150
-	{
3144
+    /**
3145
+     *   Indique si la societe a des projets
3146
+     *
3147
+     *   @return     bool	   true si la societe a des projets, false sinon
3148
+     */
3149
+    function has_projects()
3150
+    {
3151 3151
         // phpcs:enable
3152
-		$sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = ' . $this->id;
3153
-		$resql = $this->db->query($sql);
3154
-		if ($resql)
3155
-		{
3156
-			$obj = $this->db->fetch_object($resql);
3157
-			$count = $obj->numproj;
3158
-		}
3159
-		else
3160
-		{
3161
-			$count = 0;
3162
-			print $this->db->error();
3163
-		}
3164
-		$this->db->free($resql);
3165
-		return ($count > 0);
3166
-	}
3167
-
3168
-
3169
-	/**
3170
-	 *  Load information for tab info
3171
-	 *
3172
-	 *  @param  int		$id     Id of thirdparty to load
3173
-	 *  @return	void
3174
-	 */
3175
-	function info($id)
3176
-	{
3177
-		$sql = "SELECT s.rowid, s.nom as name, s.datec as date_creation, tms as date_modification,";
3178
-		$sql.= " fk_user_creat, fk_user_modif";
3179
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
3180
-		$sql.= " WHERE s.rowid = ".$id;
3181
-
3182
-		$result=$this->db->query($sql);
3183
-		if ($result)
3184
-		{
3185
-			if ($this->db->num_rows($result))
3186
-			{
3187
-				$obj = $this->db->fetch_object($result);
3188
-
3189
-				$this->id = $obj->rowid;
3190
-
3191
-				if ($obj->fk_user_creat) {
3192
-					$cuser = new User($this->db);
3193
-					$cuser->fetch($obj->fk_user_creat);
3194
-					$this->user_creation     = $cuser;
3195
-				}
3196
-
3197
-				if ($obj->fk_user_modif) {
3198
-					$muser = new User($this->db);
3199
-					$muser->fetch($obj->fk_user_modif);
3200
-					$this->user_modification = $muser;
3201
-				}
3202
-
3203
-				$this->ref			     = $obj->name;
3204
-				$this->date_creation     = $this->db->jdate($obj->date_creation);
3205
-				$this->date_modification = $this->db->jdate($obj->date_modification);
3206
-			}
3207
-
3208
-			$this->db->free($result);
3209
-		}
3210
-		else
3211
-		{
3212
-			dol_print_error($this->db);
3213
-		}
3214
-	}
3215
-
3216
-	/**
3217
-	 *  Return if third party is a company (Business) or an end user (Consumer)
3218
-	 *
3219
-	 *  @return    boolean     true=is a company, false=a and user
3220
-	 */
3221
-	function isACompany()
3222
-	{
3223
-		global $conf;
3224
-
3225
-		// Define if third party is treated as company (or not) when nature is unknown
3226
-		$isacompany=empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES)?0:1; // 0 by default
3227
-		if (! empty($this->tva_intra)) $isacompany=1;
3228
-		else if (! empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN')
3229
-		{
3230
-			// TODO Add a field is_a_company into dictionary
3231
-			if (preg_match('/^TE_PRIVATE/', $this->typent_code)) $isacompany=0;
3232
-			else $isacompany=1;
3233
-		}
3234
-
3235
-		return $isacompany;
3236
-	}
3237
-
3238
-	/**
3239
-	 *  Return if a company is inside the EEC (European Economic Community)
3240
-	 *
3241
-	 *  @return     boolean		true = country inside EEC, false = country outside EEC
3242
-	 */
3243
-	function isInEEC()
3244
-	{
3245
-		require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
3246
-		return isInEEC($this);
3247
-	}
3152
+        $sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = ' . $this->id;
3153
+        $resql = $this->db->query($sql);
3154
+        if ($resql)
3155
+        {
3156
+            $obj = $this->db->fetch_object($resql);
3157
+            $count = $obj->numproj;
3158
+        }
3159
+        else
3160
+        {
3161
+            $count = 0;
3162
+            print $this->db->error();
3163
+        }
3164
+        $this->db->free($resql);
3165
+        return ($count > 0);
3166
+    }
3167
+
3168
+
3169
+    /**
3170
+     *  Load information for tab info
3171
+     *
3172
+     *  @param  int		$id     Id of thirdparty to load
3173
+     *  @return	void
3174
+     */
3175
+    function info($id)
3176
+    {
3177
+        $sql = "SELECT s.rowid, s.nom as name, s.datec as date_creation, tms as date_modification,";
3178
+        $sql.= " fk_user_creat, fk_user_modif";
3179
+        $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
3180
+        $sql.= " WHERE s.rowid = ".$id;
3181
+
3182
+        $result=$this->db->query($sql);
3183
+        if ($result)
3184
+        {
3185
+            if ($this->db->num_rows($result))
3186
+            {
3187
+                $obj = $this->db->fetch_object($result);
3188
+
3189
+                $this->id = $obj->rowid;
3190
+
3191
+                if ($obj->fk_user_creat) {
3192
+                    $cuser = new User($this->db);
3193
+                    $cuser->fetch($obj->fk_user_creat);
3194
+                    $this->user_creation     = $cuser;
3195
+                }
3196
+
3197
+                if ($obj->fk_user_modif) {
3198
+                    $muser = new User($this->db);
3199
+                    $muser->fetch($obj->fk_user_modif);
3200
+                    $this->user_modification = $muser;
3201
+                }
3202
+
3203
+                $this->ref			     = $obj->name;
3204
+                $this->date_creation     = $this->db->jdate($obj->date_creation);
3205
+                $this->date_modification = $this->db->jdate($obj->date_modification);
3206
+            }
3207
+
3208
+            $this->db->free($result);
3209
+        }
3210
+        else
3211
+        {
3212
+            dol_print_error($this->db);
3213
+        }
3214
+    }
3215
+
3216
+    /**
3217
+     *  Return if third party is a company (Business) or an end user (Consumer)
3218
+     *
3219
+     *  @return    boolean     true=is a company, false=a and user
3220
+     */
3221
+    function isACompany()
3222
+    {
3223
+        global $conf;
3224
+
3225
+        // Define if third party is treated as company (or not) when nature is unknown
3226
+        $isacompany=empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES)?0:1; // 0 by default
3227
+        if (! empty($this->tva_intra)) $isacompany=1;
3228
+        else if (! empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN')
3229
+        {
3230
+            // TODO Add a field is_a_company into dictionary
3231
+            if (preg_match('/^TE_PRIVATE/', $this->typent_code)) $isacompany=0;
3232
+            else $isacompany=1;
3233
+        }
3234
+
3235
+        return $isacompany;
3236
+    }
3237
+
3238
+    /**
3239
+     *  Return if a company is inside the EEC (European Economic Community)
3240
+     *
3241
+     *  @return     boolean		true = country inside EEC, false = country outside EEC
3242
+     */
3243
+    function isInEEC()
3244
+    {
3245
+        require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
3246
+        return isInEEC($this);
3247
+    }
3248 3248
 
3249 3249
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3250
-	/**
3251
-	 *  Charge la liste des categories fournisseurs
3252
-	 *
3253
-	 *  @return    int      0 if success, <> 0 if error
3254
-	 */
3255
-	function LoadSupplierCateg()
3256
-	{
3250
+    /**
3251
+     *  Charge la liste des categories fournisseurs
3252
+     *
3253
+     *  @return    int      0 if success, <> 0 if error
3254
+     */
3255
+    function LoadSupplierCateg()
3256
+    {
3257 3257
         // phpcs:enable
3258
-		$this->SupplierCategories = array();
3259
-		$sql = "SELECT rowid, label";
3260
-		$sql.= " FROM ".MAIN_DB_PREFIX."categorie";
3261
-		$sql.= " WHERE type = ".Categorie::TYPE_SUPPLIER;
3262
-
3263
-		$resql=$this->db->query($sql);
3264
-		if ($resql)
3265
-		{
3266
-			while ($obj = $this->db->fetch_object($resql) )
3267
-			{
3268
-				$this->SupplierCategories[$obj->rowid] = $obj->label;
3269
-			}
3270
-			return 0;
3271
-		}
3272
-		else
3273
-		{
3274
-			return -1;
3275
-		}
3276
-	}
3258
+        $this->SupplierCategories = array();
3259
+        $sql = "SELECT rowid, label";
3260
+        $sql.= " FROM ".MAIN_DB_PREFIX."categorie";
3261
+        $sql.= " WHERE type = ".Categorie::TYPE_SUPPLIER;
3262
+
3263
+        $resql=$this->db->query($sql);
3264
+        if ($resql)
3265
+        {
3266
+            while ($obj = $this->db->fetch_object($resql) )
3267
+            {
3268
+                $this->SupplierCategories[$obj->rowid] = $obj->label;
3269
+            }
3270
+            return 0;
3271
+        }
3272
+        else
3273
+        {
3274
+            return -1;
3275
+        }
3276
+    }
3277 3277
 
3278 3278
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3279
-	/**
3280
-	 *  Insert link supplier - category
3281
-	 *
3282
-	 *	@param	int		$categorie_id		Id of category
3283
-	 *  @return int      					0 if success, <> 0 if error
3284
-	 */
3285
-	function AddFournisseurInCategory($categorie_id)
3286
-	{
3279
+    /**
3280
+     *  Insert link supplier - category
3281
+     *
3282
+     *	@param	int		$categorie_id		Id of category
3283
+     *  @return int      					0 if success, <> 0 if error
3284
+     */
3285
+    function AddFournisseurInCategory($categorie_id)
3286
+    {
3287 3287
         // phpcs:enable
3288
-		if ($categorie_id > 0 && $this->id > 0)
3289
-		{
3290
-			$sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_fournisseur (fk_categorie, fk_soc) ";
3291
-			$sql.= " VALUES (".$categorie_id.", ".$this->id.")";
3288
+        if ($categorie_id > 0 && $this->id > 0)
3289
+        {
3290
+            $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_fournisseur (fk_categorie, fk_soc) ";
3291
+            $sql.= " VALUES (".$categorie_id.", ".$this->id.")";
3292 3292
 
3293
-			if ($resql=$this->db->query($sql)) return 0;
3294
-		}
3295
-		else
3296
-		{
3297
-			return 0;
3298
-		}
3299
-		return -1;
3300
-	}
3293
+            if ($resql=$this->db->query($sql)) return 0;
3294
+        }
3295
+        else
3296
+        {
3297
+            return 0;
3298
+        }
3299
+        return -1;
3300
+    }
3301 3301
 
3302 3302
 
3303 3303
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3304
-	/**
3305
-	 *  Create a third party into database from a member object
3306
-	 *
3307
-	 *  @param	Adherent	$member			Object member
3308
-	 * 	@param	string		$socname		Name of third party to force
3309
-	 *	@param	string		$socalias		Alias name of third party to force
3310
-	 *  @param	string		$customercode	Customer code
3311
-	 *  @return int							<0 if KO, id of created account if OK
3312
-	 */
3313
-	function create_from_member(Adherent $member, $socname='', $socalias='', $customercode='')
3314
-	{
3304
+    /**
3305
+     *  Create a third party into database from a member object
3306
+     *
3307
+     *  @param	Adherent	$member			Object member
3308
+     * 	@param	string		$socname		Name of third party to force
3309
+     *	@param	string		$socalias		Alias name of third party to force
3310
+     *  @param	string		$customercode	Customer code
3311
+     *  @return int							<0 if KO, id of created account if OK
3312
+     */
3313
+    function create_from_member(Adherent $member, $socname='', $socalias='', $customercode='')
3314
+    {
3315 3315
         // phpcs:enable
3316
-		global $user,$langs;
3317
-
3318
-		dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG);
3319
-
3320
-		$name = $socname?$socname:$member->societe;
3321
-		if (empty($name)) $name=$member->getFullName($langs);
3322
-
3323
-		$alias = $socalias?$socalias:'';
3324
-
3325
-		// Positionne parametres
3326
-		$this->nom=$name;				// TODO deprecated
3327
-		$this->name=$name;
3328
-		$this->name_alias=$alias;
3329
-		$this->address=$member->address;
3330
-		$this->zip=$member->zip;
3331
-		$this->town=$member->town;
3332
-		$this->country_code=$member->country_code;
3333
-		$this->country_id=$member->country_id;
3334
-		$this->phone=$member->phone;       // Prof phone
3335
-		$this->email=$member->email;
3336
-		$this->skype=$member->skype;
3337
-		$this->twitter=$member->twitter;
3338
-		$this->facebook=$member->facebook;
3339
-
3340
-		$this->client = 1;				// A member is a customer by default
3341
-		$this->code_client = ($customercode?$customercode:-1);
3342
-		$this->code_fournisseur = -1;
3343
-
3344
-		$this->db->begin();
3345
-
3346
-		// Cree et positionne $this->id
3347
-		$result=$this->create($user);
3348
-		if ($result >= 0)
3349
-		{
3350
-			$sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
3351
-			$sql.= " SET fk_soc=".$this->id;
3352
-			$sql.= " WHERE rowid=".$member->id;
3353
-
3354
-			$resql=$this->db->query($sql);
3355
-			if ($resql)
3356
-			{
3357
-				$this->db->commit();
3358
-				return $this->id;
3359
-			}
3360
-			else
3361
-			{
3362
-				$this->error=$this->db->error();
3363
-
3364
-				$this->db->rollback();
3365
-				return -1;
3366
-			}
3367
-		}
3368
-		else
3369
-		{
3370
-			// $this->error deja positionne
3371
-			dol_syslog(get_class($this)."::create_from_member - 2 - ".$this->error." - ".join(',',$this->errors), LOG_ERR);
3372
-
3373
-			$this->db->rollback();
3374
-			return $result;
3375
-		}
3376
-	}
3377
-
3378
-	/**
3379
-	 * 	Set properties with value into $conf
3380
-	 *
3381
-	 * 	@param	Conf	$conf		Conf object (possibility to use another entity)
3382
-	 * 	@return	void
3383
-	 */
3384
-	function setMysoc(Conf $conf)
3385
-	{
3386
-		global $langs;
3387
-
3388
-		$this->id=0;
3389
-		$this->name=empty($conf->global->MAIN_INFO_SOCIETE_NOM)?'':$conf->global->MAIN_INFO_SOCIETE_NOM;
3390
-		$this->address=empty($conf->global->MAIN_INFO_SOCIETE_ADDRESS)?'':$conf->global->MAIN_INFO_SOCIETE_ADDRESS;
3391
-		$this->zip=empty($conf->global->MAIN_INFO_SOCIETE_ZIP)?'':$conf->global->MAIN_INFO_SOCIETE_ZIP;
3392
-		$this->town=empty($conf->global->MAIN_INFO_SOCIETE_TOWN)?'':$conf->global->MAIN_INFO_SOCIETE_TOWN;
3393
-		$this->state_id=empty($conf->global->MAIN_INFO_SOCIETE_STATE)?'':$conf->global->MAIN_INFO_SOCIETE_STATE;
3394
-		$this->region_code=empty($conf->global->MAIN_INFO_SOCIETE_REGION)?'':$conf->global->MAIN_INFO_SOCIETE_REGION;
3395
-		$this->object=empty($conf->global->MAIN_INFO_SOCIETE_OBJECT)?'':$conf->global->MAIN_INFO_SOCIETE_OBJECT;
3396
-
3397
-		$this->note_private=empty($conf->global->MAIN_INFO_SOCIETE_NOTE)?'':$conf->global->MAIN_INFO_SOCIETE_NOTE;
3398
-
3399
-		$this->nom=$this->name; 									// deprecated
3400
-
3401
-		// We define country_id, country_code and country
3402
-		$country_id=$country_code=$country_label='';
3403
-		if (! empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY))
3404
-		{
3405
-			$tmp=explode(':',$conf->global->MAIN_INFO_SOCIETE_COUNTRY);
3406
-			$country_id=$tmp[0];
3407
-			if (! empty($tmp[1]))   // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label"
3408
-			{
3409
-				$country_code=$tmp[1];
3410
-				$country_label=$tmp[2];
3411
-			}
3412
-			else                    // For backward compatibility
3413
-			{
3414
-				dol_syslog("Your country setup use an old syntax. Reedit it using setup area.", LOG_ERR);
3415
-				include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
3416
-				$country_code=getCountry($country_id,2,$this->db);  // This need a SQL request, but it's the old feature that should not be used anymore
3417
-				$country_label=getCountry($country_id,0,$this->db);  // This need a SQL request, but it's the old feature that should not be used anymore
3418
-			}
3419
-		}
3420
-		$this->country_id=$country_id;
3421
-		$this->country_code=$country_code;
3422
-		$this->country=$country_label;
3423
-		if (is_object($langs)) $this->country=($langs->trans('Country'.$country_code)!='Country'.$country_code)?$langs->trans('Country'.$country_code):$country_label;
3424
-
3425
-		$this->phone=empty($conf->global->MAIN_INFO_SOCIETE_TEL)?'':$conf->global->MAIN_INFO_SOCIETE_TEL;
3426
-		$this->fax=empty($conf->global->MAIN_INFO_SOCIETE_FAX)?'':$conf->global->MAIN_INFO_SOCIETE_FAX;
3427
-		$this->url=empty($conf->global->MAIN_INFO_SOCIETE_WEB)?'':$conf->global->MAIN_INFO_SOCIETE_WEB;
3428
-		// Id prof generiques
3429
-		$this->idprof1=empty($conf->global->MAIN_INFO_SIREN)?'':$conf->global->MAIN_INFO_SIREN;
3430
-		$this->idprof2=empty($conf->global->MAIN_INFO_SIRET)?'':$conf->global->MAIN_INFO_SIRET;
3431
-		$this->idprof3=empty($conf->global->MAIN_INFO_APE)?'':$conf->global->MAIN_INFO_APE;
3432
-		$this->idprof4=empty($conf->global->MAIN_INFO_RCS)?'':$conf->global->MAIN_INFO_RCS;
3433
-		$this->idprof5=empty($conf->global->MAIN_INFO_PROFID5)?'':$conf->global->MAIN_INFO_PROFID5;
3434
-		$this->idprof6=empty($conf->global->MAIN_INFO_PROFID6)?'':$conf->global->MAIN_INFO_PROFID6;
3435
-		$this->tva_intra=empty($conf->global->MAIN_INFO_TVAINTRA)?'':$conf->global->MAIN_INFO_TVAINTRA;	// VAT number, not necessarly INTRA.
3436
-		$this->managers=empty($conf->global->MAIN_INFO_SOCIETE_MANAGERS)?'':$conf->global->MAIN_INFO_SOCIETE_MANAGERS;
3437
-		$this->capital=empty($conf->global->MAIN_INFO_CAPITAL)?'':$conf->global->MAIN_INFO_CAPITAL;
3438
-		$this->forme_juridique_code=empty($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE)?'':$conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE;
3439
-		$this->email=empty($conf->global->MAIN_INFO_SOCIETE_MAIL)?'':$conf->global->MAIN_INFO_SOCIETE_MAIL;
3440
-		$this->logo=empty($conf->global->MAIN_INFO_SOCIETE_LOGO)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO;
3441
-		$this->logo_small=empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL;
3442
-		$this->logo_mini=empty($conf->global->MAIN_INFO_SOCIETE_LOGO_MINI)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
3443
-
3444
-		// Define if company use vat or not
3445
-		$this->tva_assuj=$conf->global->FACTURE_TVAOPTION;
3446
-
3447
-		// Define if company use local taxes
3448
-		$this->localtax1_assuj=((isset($conf->global->FACTURE_LOCAL_TAX1_OPTION) && ($conf->global->FACTURE_LOCAL_TAX1_OPTION=='1' || $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on'))?1:0);
3449
-		$this->localtax2_assuj=((isset($conf->global->FACTURE_LOCAL_TAX2_OPTION) && ($conf->global->FACTURE_LOCAL_TAX2_OPTION=='1' || $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on'))?1:0);
3450
-	}
3451
-
3452
-	/**
3453
-	 *  Initialise an instance with random values.
3454
-	 *  Used to build previews or test instances.
3455
-	 *	id must be 0 if object instance is a specimen.
3456
-	 *
3457
-	 *  @return	void
3458
-	 */
3459
-	function initAsSpecimen()
3460
-	{
3461
-		$now=dol_now();
3462
-
3463
-		// Initialize parameters
3464
-		$this->id=0;
3465
-		$this->name = 'THIRDPARTY SPECIMEN '.dol_print_date($now,'dayhourlog');
3466
-		$this->nom = $this->name;   // For backward compatibility
3467
-		$this->ref_ext = 'Ref ext';
3468
-		$this->specimen=1;
3469
-		$this->address='21 jump street';
3470
-		$this->zip='99999';
3471
-		$this->town='MyTown';
3472
-		$this->state_id=1;
3473
-		$this->state_code='AA';
3474
-		$this->state='MyState';
3475
-		$this->country_id=1;
3476
-		$this->country_code='FR';
3477
-		$this->email='[email protected]';
3478
-		$this->skype='tom.hanson';
3479
-		$this->twitter='tomhanson';
3480
-		$this->facebook='tomhanson';
3481
-		$this->url='http://www.specimen.com';
3482
-
3483
-		$this->phone='0909090901';
3484
-		$this->fax='0909090909';
3485
-
3486
-		$this->code_client='CC-'.dol_print_date($now,'dayhourlog');
3487
-		$this->code_fournisseur='SC-'.dol_print_date($now,'dayhourlog');
3488
-		$this->capital=10000;
3489
-		$this->client=1;
3490
-		$this->prospect=1;
3491
-		$this->fournisseur=1;
3492
-		$this->tva_assuj=1;
3493
-		$this->tva_intra='EU1234567';
3494
-		$this->note_public='This is a comment (public)';
3495
-		$this->note_private='This is a comment (private)';
3496
-
3497
-		$this->idprof1='idprof1';
3498
-		$this->idprof2='idprof2';
3499
-		$this->idprof3='idprof3';
3500
-		$this->idprof4='idprof4';
3501
-		$this->idprof5='idprof5';
3502
-		$this->idprof6='idprof6';
3503
-	}
3504
-
3505
-	/**
3506
-	 *  Check if we must use localtax feature or not according to country (country of $mysoc in most cases).
3507
-	 *
3508
-	 *	@param		int		$localTaxNum	To get info for only localtax1 or localtax2
3509
-	 *  @return		boolean					true or false
3510
-	 */
3511
-	function useLocalTax($localTaxNum=0)
3512
-	{
3513
-		$sql  = "SELECT t.localtax1, t.localtax2";
3514
-		$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
3515
-		$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'";
3516
-		$sql .= " AND t.active = 1";
3517
-		if (empty($localTaxNum))   $sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
3518
-		elseif ($localTaxNum == 1) $sql .= " AND t.localtax1_type <> '0'";
3519
-		elseif ($localTaxNum == 2) $sql .= " AND t.localtax2_type <> '0'";
3520
-
3521
-		dol_syslog("useLocalTax", LOG_DEBUG);
3522
-		$resql=$this->db->query($sql);
3523
-		if ($resql)
3524
-		{
3525
-   			return ($this->db->num_rows($resql) > 0);
3526
-		}
3527
-		else return false;
3528
-	}
3529
-
3530
-	/**
3531
-	 *  Check if we must use NPR Vat (french stupid rule) or not according to country (country of $mysoc in most cases).
3532
-	 *
3533
-	 *  @return		boolean					true or false
3534
-	 */
3535
-	function useNPR()
3536
-	{
3537
-		$sql  = "SELECT t.rowid";
3538
-		$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
3539
-		$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'";
3540
-		$sql .= " AND t.active = 1 AND t.recuperableonly = 1";
3541
-
3542
-		dol_syslog("useNPR", LOG_DEBUG);
3543
-		$resql=$this->db->query($sql);
3544
-		if ($resql)
3545
-		{
3546
-			return ($this->db->num_rows($resql) > 0);
3547
-		}
3548
-		else return false;
3549
-	}
3550
-
3551
-	/**
3552
-	 *  Check if we must use revenue stamps feature or not according to country (country of $mysocin most cases).
3553
-	 *
3554
-	 *  @return		boolean			true or false
3555
-	 */
3556
-	function useRevenueStamp()
3557
-	{
3558
-		$sql  = "SELECT COUNT(*) as nb";
3559
-		$sql .= " FROM ".MAIN_DB_PREFIX."c_revenuestamp as r, ".MAIN_DB_PREFIX."c_country as c";
3560
-		$sql .= " WHERE r.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'";
3561
-		$sql .= " AND r.active = 1";
3562
-
3563
-		dol_syslog("useRevenueStamp", LOG_DEBUG);
3564
-		$resql=$this->db->query($sql);
3565
-		if ($resql)
3566
-		{
3567
-			$obj=$this->db->fetch_object($resql);
3568
-   			return (($obj->nb > 0)?true:false);
3569
-		}
3570
-		else
3571
-		{
3572
-			$this->error=$this->db->lasterror();
3573
-			return false;
3574
-		}
3575
-	}
3576
-
3577
-	/**
3578
-	 *	Return prostect level
3579
-	 *
3580
-	 *  @return     string        Libelle
3581
-	 */
3582
-	function getLibProspLevel()
3583
-	{
3584
-		return $this->LibProspLevel($this->fk_prospectlevel);
3585
-	}
3316
+        global $user,$langs;
3317
+
3318
+        dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG);
3319
+
3320
+        $name = $socname?$socname:$member->societe;
3321
+        if (empty($name)) $name=$member->getFullName($langs);
3322
+
3323
+        $alias = $socalias?$socalias:'';
3324
+
3325
+        // Positionne parametres
3326
+        $this->nom=$name;				// TODO deprecated
3327
+        $this->name=$name;
3328
+        $this->name_alias=$alias;
3329
+        $this->address=$member->address;
3330
+        $this->zip=$member->zip;
3331
+        $this->town=$member->town;
3332
+        $this->country_code=$member->country_code;
3333
+        $this->country_id=$member->country_id;
3334
+        $this->phone=$member->phone;       // Prof phone
3335
+        $this->email=$member->email;
3336
+        $this->skype=$member->skype;
3337
+        $this->twitter=$member->twitter;
3338
+        $this->facebook=$member->facebook;
3339
+
3340
+        $this->client = 1;				// A member is a customer by default
3341
+        $this->code_client = ($customercode?$customercode:-1);
3342
+        $this->code_fournisseur = -1;
3343
+
3344
+        $this->db->begin();
3345
+
3346
+        // Cree et positionne $this->id
3347
+        $result=$this->create($user);
3348
+        if ($result >= 0)
3349
+        {
3350
+            $sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
3351
+            $sql.= " SET fk_soc=".$this->id;
3352
+            $sql.= " WHERE rowid=".$member->id;
3353
+
3354
+            $resql=$this->db->query($sql);
3355
+            if ($resql)
3356
+            {
3357
+                $this->db->commit();
3358
+                return $this->id;
3359
+            }
3360
+            else
3361
+            {
3362
+                $this->error=$this->db->error();
3363
+
3364
+                $this->db->rollback();
3365
+                return -1;
3366
+            }
3367
+        }
3368
+        else
3369
+        {
3370
+            // $this->error deja positionne
3371
+            dol_syslog(get_class($this)."::create_from_member - 2 - ".$this->error." - ".join(',',$this->errors), LOG_ERR);
3372
+
3373
+            $this->db->rollback();
3374
+            return $result;
3375
+        }
3376
+    }
3377
+
3378
+    /**
3379
+     * 	Set properties with value into $conf
3380
+     *
3381
+     * 	@param	Conf	$conf		Conf object (possibility to use another entity)
3382
+     * 	@return	void
3383
+     */
3384
+    function setMysoc(Conf $conf)
3385
+    {
3386
+        global $langs;
3387
+
3388
+        $this->id=0;
3389
+        $this->name=empty($conf->global->MAIN_INFO_SOCIETE_NOM)?'':$conf->global->MAIN_INFO_SOCIETE_NOM;
3390
+        $this->address=empty($conf->global->MAIN_INFO_SOCIETE_ADDRESS)?'':$conf->global->MAIN_INFO_SOCIETE_ADDRESS;
3391
+        $this->zip=empty($conf->global->MAIN_INFO_SOCIETE_ZIP)?'':$conf->global->MAIN_INFO_SOCIETE_ZIP;
3392
+        $this->town=empty($conf->global->MAIN_INFO_SOCIETE_TOWN)?'':$conf->global->MAIN_INFO_SOCIETE_TOWN;
3393
+        $this->state_id=empty($conf->global->MAIN_INFO_SOCIETE_STATE)?'':$conf->global->MAIN_INFO_SOCIETE_STATE;
3394
+        $this->region_code=empty($conf->global->MAIN_INFO_SOCIETE_REGION)?'':$conf->global->MAIN_INFO_SOCIETE_REGION;
3395
+        $this->object=empty($conf->global->MAIN_INFO_SOCIETE_OBJECT)?'':$conf->global->MAIN_INFO_SOCIETE_OBJECT;
3396
+
3397
+        $this->note_private=empty($conf->global->MAIN_INFO_SOCIETE_NOTE)?'':$conf->global->MAIN_INFO_SOCIETE_NOTE;
3398
+
3399
+        $this->nom=$this->name; 									// deprecated
3400
+
3401
+        // We define country_id, country_code and country
3402
+        $country_id=$country_code=$country_label='';
3403
+        if (! empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY))
3404
+        {
3405
+            $tmp=explode(':',$conf->global->MAIN_INFO_SOCIETE_COUNTRY);
3406
+            $country_id=$tmp[0];
3407
+            if (! empty($tmp[1]))   // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label"
3408
+            {
3409
+                $country_code=$tmp[1];
3410
+                $country_label=$tmp[2];
3411
+            }
3412
+            else                    // For backward compatibility
3413
+            {
3414
+                dol_syslog("Your country setup use an old syntax. Reedit it using setup area.", LOG_ERR);
3415
+                include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
3416
+                $country_code=getCountry($country_id,2,$this->db);  // This need a SQL request, but it's the old feature that should not be used anymore
3417
+                $country_label=getCountry($country_id,0,$this->db);  // This need a SQL request, but it's the old feature that should not be used anymore
3418
+            }
3419
+        }
3420
+        $this->country_id=$country_id;
3421
+        $this->country_code=$country_code;
3422
+        $this->country=$country_label;
3423
+        if (is_object($langs)) $this->country=($langs->trans('Country'.$country_code)!='Country'.$country_code)?$langs->trans('Country'.$country_code):$country_label;
3424
+
3425
+        $this->phone=empty($conf->global->MAIN_INFO_SOCIETE_TEL)?'':$conf->global->MAIN_INFO_SOCIETE_TEL;
3426
+        $this->fax=empty($conf->global->MAIN_INFO_SOCIETE_FAX)?'':$conf->global->MAIN_INFO_SOCIETE_FAX;
3427
+        $this->url=empty($conf->global->MAIN_INFO_SOCIETE_WEB)?'':$conf->global->MAIN_INFO_SOCIETE_WEB;
3428
+        // Id prof generiques
3429
+        $this->idprof1=empty($conf->global->MAIN_INFO_SIREN)?'':$conf->global->MAIN_INFO_SIREN;
3430
+        $this->idprof2=empty($conf->global->MAIN_INFO_SIRET)?'':$conf->global->MAIN_INFO_SIRET;
3431
+        $this->idprof3=empty($conf->global->MAIN_INFO_APE)?'':$conf->global->MAIN_INFO_APE;
3432
+        $this->idprof4=empty($conf->global->MAIN_INFO_RCS)?'':$conf->global->MAIN_INFO_RCS;
3433
+        $this->idprof5=empty($conf->global->MAIN_INFO_PROFID5)?'':$conf->global->MAIN_INFO_PROFID5;
3434
+        $this->idprof6=empty($conf->global->MAIN_INFO_PROFID6)?'':$conf->global->MAIN_INFO_PROFID6;
3435
+        $this->tva_intra=empty($conf->global->MAIN_INFO_TVAINTRA)?'':$conf->global->MAIN_INFO_TVAINTRA;	// VAT number, not necessarly INTRA.
3436
+        $this->managers=empty($conf->global->MAIN_INFO_SOCIETE_MANAGERS)?'':$conf->global->MAIN_INFO_SOCIETE_MANAGERS;
3437
+        $this->capital=empty($conf->global->MAIN_INFO_CAPITAL)?'':$conf->global->MAIN_INFO_CAPITAL;
3438
+        $this->forme_juridique_code=empty($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE)?'':$conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE;
3439
+        $this->email=empty($conf->global->MAIN_INFO_SOCIETE_MAIL)?'':$conf->global->MAIN_INFO_SOCIETE_MAIL;
3440
+        $this->logo=empty($conf->global->MAIN_INFO_SOCIETE_LOGO)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO;
3441
+        $this->logo_small=empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL;
3442
+        $this->logo_mini=empty($conf->global->MAIN_INFO_SOCIETE_LOGO_MINI)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
3443
+
3444
+        // Define if company use vat or not
3445
+        $this->tva_assuj=$conf->global->FACTURE_TVAOPTION;
3446
+
3447
+        // Define if company use local taxes
3448
+        $this->localtax1_assuj=((isset($conf->global->FACTURE_LOCAL_TAX1_OPTION) && ($conf->global->FACTURE_LOCAL_TAX1_OPTION=='1' || $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on'))?1:0);
3449
+        $this->localtax2_assuj=((isset($conf->global->FACTURE_LOCAL_TAX2_OPTION) && ($conf->global->FACTURE_LOCAL_TAX2_OPTION=='1' || $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on'))?1:0);
3450
+    }
3451
+
3452
+    /**
3453
+     *  Initialise an instance with random values.
3454
+     *  Used to build previews or test instances.
3455
+     *	id must be 0 if object instance is a specimen.
3456
+     *
3457
+     *  @return	void
3458
+     */
3459
+    function initAsSpecimen()
3460
+    {
3461
+        $now=dol_now();
3462
+
3463
+        // Initialize parameters
3464
+        $this->id=0;
3465
+        $this->name = 'THIRDPARTY SPECIMEN '.dol_print_date($now,'dayhourlog');
3466
+        $this->nom = $this->name;   // For backward compatibility
3467
+        $this->ref_ext = 'Ref ext';
3468
+        $this->specimen=1;
3469
+        $this->address='21 jump street';
3470
+        $this->zip='99999';
3471
+        $this->town='MyTown';
3472
+        $this->state_id=1;
3473
+        $this->state_code='AA';
3474
+        $this->state='MyState';
3475
+        $this->country_id=1;
3476
+        $this->country_code='FR';
3477
+        $this->email='[email protected]';
3478
+        $this->skype='tom.hanson';
3479
+        $this->twitter='tomhanson';
3480
+        $this->facebook='tomhanson';
3481
+        $this->url='http://www.specimen.com';
3482
+
3483
+        $this->phone='0909090901';
3484
+        $this->fax='0909090909';
3485
+
3486
+        $this->code_client='CC-'.dol_print_date($now,'dayhourlog');
3487
+        $this->code_fournisseur='SC-'.dol_print_date($now,'dayhourlog');
3488
+        $this->capital=10000;
3489
+        $this->client=1;
3490
+        $this->prospect=1;
3491
+        $this->fournisseur=1;
3492
+        $this->tva_assuj=1;
3493
+        $this->tva_intra='EU1234567';
3494
+        $this->note_public='This is a comment (public)';
3495
+        $this->note_private='This is a comment (private)';
3496
+
3497
+        $this->idprof1='idprof1';
3498
+        $this->idprof2='idprof2';
3499
+        $this->idprof3='idprof3';
3500
+        $this->idprof4='idprof4';
3501
+        $this->idprof5='idprof5';
3502
+        $this->idprof6='idprof6';
3503
+    }
3504
+
3505
+    /**
3506
+     *  Check if we must use localtax feature or not according to country (country of $mysoc in most cases).
3507
+     *
3508
+     *	@param		int		$localTaxNum	To get info for only localtax1 or localtax2
3509
+     *  @return		boolean					true or false
3510
+     */
3511
+    function useLocalTax($localTaxNum=0)
3512
+    {
3513
+        $sql  = "SELECT t.localtax1, t.localtax2";
3514
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
3515
+        $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'";
3516
+        $sql .= " AND t.active = 1";
3517
+        if (empty($localTaxNum))   $sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
3518
+        elseif ($localTaxNum == 1) $sql .= " AND t.localtax1_type <> '0'";
3519
+        elseif ($localTaxNum == 2) $sql .= " AND t.localtax2_type <> '0'";
3520
+
3521
+        dol_syslog("useLocalTax", LOG_DEBUG);
3522
+        $resql=$this->db->query($sql);
3523
+        if ($resql)
3524
+        {
3525
+                return ($this->db->num_rows($resql) > 0);
3526
+        }
3527
+        else return false;
3528
+    }
3529
+
3530
+    /**
3531
+     *  Check if we must use NPR Vat (french stupid rule) or not according to country (country of $mysoc in most cases).
3532
+     *
3533
+     *  @return		boolean					true or false
3534
+     */
3535
+    function useNPR()
3536
+    {
3537
+        $sql  = "SELECT t.rowid";
3538
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
3539
+        $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'";
3540
+        $sql .= " AND t.active = 1 AND t.recuperableonly = 1";
3541
+
3542
+        dol_syslog("useNPR", LOG_DEBUG);
3543
+        $resql=$this->db->query($sql);
3544
+        if ($resql)
3545
+        {
3546
+            return ($this->db->num_rows($resql) > 0);
3547
+        }
3548
+        else return false;
3549
+    }
3550
+
3551
+    /**
3552
+     *  Check if we must use revenue stamps feature or not according to country (country of $mysocin most cases).
3553
+     *
3554
+     *  @return		boolean			true or false
3555
+     */
3556
+    function useRevenueStamp()
3557
+    {
3558
+        $sql  = "SELECT COUNT(*) as nb";
3559
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_revenuestamp as r, ".MAIN_DB_PREFIX."c_country as c";
3560
+        $sql .= " WHERE r.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'";
3561
+        $sql .= " AND r.active = 1";
3562
+
3563
+        dol_syslog("useRevenueStamp", LOG_DEBUG);
3564
+        $resql=$this->db->query($sql);
3565
+        if ($resql)
3566
+        {
3567
+            $obj=$this->db->fetch_object($resql);
3568
+                return (($obj->nb > 0)?true:false);
3569
+        }
3570
+        else
3571
+        {
3572
+            $this->error=$this->db->lasterror();
3573
+            return false;
3574
+        }
3575
+    }
3576
+
3577
+    /**
3578
+     *	Return prostect level
3579
+     *
3580
+     *  @return     string        Libelle
3581
+     */
3582
+    function getLibProspLevel()
3583
+    {
3584
+        return $this->LibProspLevel($this->fk_prospectlevel);
3585
+    }
3586 3586
 
3587 3587
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3588
-	/**
3589
-	 *  Return label of prospect level
3590
-	 *
3591
-	 *  @param	int		$fk_prospectlevel   	Prospect level
3592
-	 *  @return string        					label of level
3593
-	 */
3594
-	function LibProspLevel($fk_prospectlevel)
3595
-	{
3588
+    /**
3589
+     *  Return label of prospect level
3590
+     *
3591
+     *  @param	int		$fk_prospectlevel   	Prospect level
3592
+     *  @return string        					label of level
3593
+     */
3594
+    function LibProspLevel($fk_prospectlevel)
3595
+    {
3596 3596
         // phpcs:enable
3597
-		global $langs;
3597
+        global $langs;
3598 3598
 
3599
-		$lib=$langs->trans("ProspectLevel".$fk_prospectlevel);
3600
-		// If lib not found in language file, we get label from cache/databse
3601
-		if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel))
3602
-		{
3603
-			$lib=$langs->getLabelFromKey($this->db,$fk_prospectlevel,'c_prospectlevel','code','label');
3604
-		}
3605
-		return $lib;
3606
-	}
3599
+        $lib=$langs->trans("ProspectLevel".$fk_prospectlevel);
3600
+        // If lib not found in language file, we get label from cache/databse
3601
+        if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel))
3602
+        {
3603
+            $lib=$langs->getLabelFromKey($this->db,$fk_prospectlevel,'c_prospectlevel','code','label');
3604
+        }
3605
+        return $lib;
3606
+    }
3607 3607
 
3608 3608
 
3609 3609
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3610
-	/**
3611
-	 *  Set prospect level
3612
-	 *
3613
-	 *  @param  User	$user		Utilisateur qui definie la remise
3614
-	 *	@return	int					<0 if KO, >0 if OK
3615
-	 * @deprecated Use update function instead
3616
-	 */
3617
-	function set_prospect_level(User $user)
3618
-	{
3610
+    /**
3611
+     *  Set prospect level
3612
+     *
3613
+     *  @param  User	$user		Utilisateur qui definie la remise
3614
+     *	@return	int					<0 if KO, >0 if OK
3615
+     * @deprecated Use update function instead
3616
+     */
3617
+    function set_prospect_level(User $user)
3618
+    {
3619 3619
         // phpcs:enable
3620
-		return $this->update($this->id, $user);
3621
-	}
3622
-
3623
-	/**
3624
-	 *  Return status of prospect
3625
-	 *
3626
-	 *  @param	int		$mode       0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long
3627
-	 *  @param	string	$label		Label to use for status for added status
3628
-	 *  @return string        		Libelle
3629
-	 */
3630
-	function getLibProspCommStatut($mode=0, $label='')
3631
-	{
3632
-		return $this->LibProspCommStatut($this->stcomm_id, $mode, $label);
3633
-	}
3620
+        return $this->update($this->id, $user);
3621
+    }
3622
+
3623
+    /**
3624
+     *  Return status of prospect
3625
+     *
3626
+     *  @param	int		$mode       0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long
3627
+     *  @param	string	$label		Label to use for status for added status
3628
+     *  @return string        		Libelle
3629
+     */
3630
+    function getLibProspCommStatut($mode=0, $label='')
3631
+    {
3632
+        return $this->LibProspCommStatut($this->stcomm_id, $mode, $label);
3633
+    }
3634 3634
 
3635 3635
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3636
-	/**
3637
-	 *  Return label of a given status
3638
-	 *
3639
-	 *  @param	int|string	$statut        	Id or code for prospection status
3640
-	 *  @param  int			$mode          	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
3641
-	 *  @param	string		$label			Label to use for status for added status
3642
-	 *  @return string       	 			Libelle du statut
3643
-	 */
3644
-	function LibProspCommStatut($statut, $mode=0, $label='')
3645
-	{
3636
+    /**
3637
+     *  Return label of a given status
3638
+     *
3639
+     *  @param	int|string	$statut        	Id or code for prospection status
3640
+     *  @param  int			$mode          	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
3641
+     *  @param	string		$label			Label to use for status for added status
3642
+     *  @return string       	 			Libelle du statut
3643
+     */
3644
+    function LibProspCommStatut($statut, $mode=0, $label='')
3645
+    {
3646 3646
         // phpcs:enable
3647
-		global $langs;
3648
-		$langs->load('customers');
3649
-
3650
-		if ($mode == 2)
3651
-		{
3652
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3653
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3654
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3655
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3656
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3657
-			else
3658
-			{
3659
-				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
3660
-			}
3661
-		}
3662
-		if ($mode == 3)
3663
-		{
3664
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1);
3665
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0);
3666
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1);
3667
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2);
3668
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3);
3669
-			else
3670
-			{
3671
-				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0);
3672
-			}
3673
-		}
3674
-		if ($mode == 4)
3675
-		{
3676
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3677
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3678
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3679
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3680
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3681
-			else
3682
-			{
3683
-				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
3684
-			}
3685
-		}
3686
-
3687
-		return "Error, mode/status not found";
3688
-	}
3647
+        global $langs;
3648
+        $langs->load('customers');
3649
+
3650
+        if ($mode == 2)
3651
+        {
3652
+            if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3653
+            elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3654
+            elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3655
+            elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3656
+            elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3657
+            else
3658
+            {
3659
+                return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
3660
+            }
3661
+        }
3662
+        if ($mode == 3)
3663
+        {
3664
+            if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1);
3665
+            elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0);
3666
+            elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1);
3667
+            elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2);
3668
+            elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3);
3669
+            else
3670
+            {
3671
+                return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0);
3672
+            }
3673
+        }
3674
+        if ($mode == 4)
3675
+        {
3676
+            if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3677
+            elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3678
+            elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3679
+            elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3680
+            elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3681
+            else
3682
+            {
3683
+                return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
3684
+            }
3685
+        }
3686
+
3687
+        return "Error, mode/status not found";
3688
+    }
3689 3689
 
3690 3690
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3691
-	/**
3692
-	 *  Set outstanding value
3693
-	 *
3694
-	 *  @param  User	$user		User making change
3695
-	 *	@return	int					<0 if KO, >0 if OK
3696
-	 * @deprecated Use update function instead
3697
-	 */
3698
-	function set_OutstandingBill(User $user)
3699
-	{
3691
+    /**
3692
+     *  Set outstanding value
3693
+     *
3694
+     *  @param  User	$user		User making change
3695
+     *	@return	int					<0 if KO, >0 if OK
3696
+     * @deprecated Use update function instead
3697
+     */
3698
+    function set_OutstandingBill(User $user)
3699
+    {
3700 3700
         // phpcs:enable
3701
-		return $this->update($this->id, $user);
3702
-	}
3703
-
3704
-	/**
3705
-	 *  Return amount of order not paid and total
3706
-	 *
3707
-	 *  @param     string      $mode    'customer' or 'supplier'
3708
-	 *  @return    array				array('opened'=>Amount, 'total'=>Total amount)
3709
-	 */
3710
-	function getOutstandingProposals($mode='customer')
3711
-	{
3712
-		$table='propal';
3713
-		if ($mode == 'supplier') $table = 'supplier_proposal';
3714
-
3715
-		$sql  = "SELECT rowid, total_ht, total as total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
3716
-		$sql .= " WHERE fk_soc = ". $this->id;
3717
-		if ($mode == 'supplier') {
3718
-			$sql .= " AND entity IN (".getEntity('supplier_proposal').")";
3719
-		} else {
3720
-			$sql .= " AND entity IN (".getEntity('propal').")";
3721
-		}
3722
-
3723
-		dol_syslog("getOutstandingProposals", LOG_DEBUG);
3724
-		$resql=$this->db->query($sql);
3725
-		if ($resql)
3726
-		{
3727
-			$outstandingOpened = 0;
3728
-			$outstandingTotal = 0;
3729
-			$outstandingTotalIncTax = 0;
3730
-			while($obj=$this->db->fetch_object($resql)) {
3731
-				$outstandingTotal+= $obj->total_ht;
3732
-				$outstandingTotalIncTax+= $obj->total_ttc;
3733
-				if ($obj->fk_statut != 0)    // Not a draft
3734
-				{
3735
-					$outstandingOpened+=$obj->total_ttc;
3736
-				}
3737
-			}
3738
-			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3739
-		}
3740
-		else
3741
-			return array();
3742
-	}
3743
-
3744
-	/**
3745
-	 *  Return amount of order not paid and total
3746
-	 *
3747
-	 *  @param     string      $mode    'customer' or 'supplier'
3748
-	 *  @return		array				array('opened'=>Amount, 'total'=>Total amount)
3749
-	 */
3750
-	function getOutstandingOrders($mode='customer')
3751
-	{
3752
-		$table='commande';
3753
-		if ($mode == 'supplier') $table = 'commande_fournisseur';
3754
-
3755
-		$sql  = "SELECT rowid, total_ht, total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
3756
-		$sql .= " WHERE fk_soc = ". $this->id;
3757
-		if ($mode == 'supplier') {
3758
-			$sql .= " AND entity IN (".getEntity('supplier_order').")";
3759
-		} else {
3760
-			$sql .= " AND entity IN (".getEntity('commande').")";
3761
-		}
3762
-
3763
-		dol_syslog("getOutstandingOrders", LOG_DEBUG);
3764
-		$resql=$this->db->query($sql);
3765
-		if ($resql)
3766
-		{
3767
-			$outstandingOpened = 0;
3768
-			$outstandingTotal = 0;
3769
-			$outstandingTotalIncTax = 0;
3770
-			while($obj=$this->db->fetch_object($resql)) {
3771
-				$outstandingTotal+= $obj->total_ht;
3772
-				$outstandingTotalIncTax+= $obj->total_ttc;
3773
-				if ($obj->fk_statut != 0)    // Not a draft
3774
-				{
3775
-					$outstandingOpened+=$obj->total_ttc;
3776
-				}
3777
-			}
3778
-			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3779
-		}
3780
-		else
3781
-			return array();
3782
-	}
3783
-
3784
-	/**
3785
-	 *  Return amount of bill not paid and total
3786
-	 *
3787
-	 *  @param     string      $mode    'customer' or 'supplier'
3788
-	 *  @return		array				array('opened'=>Amount, 'total'=>Total amount)
3789
-	 */
3790
-	function getOutstandingBills($mode='customer')
3791
-	{
3792
-		$table='facture';
3793
-		if ($mode == 'supplier') $table = 'facture_fourn';
3794
-
3795
-		/* Accurate value of remain to pay is to sum remaintopay for each invoice
3701
+        return $this->update($this->id, $user);
3702
+    }
3703
+
3704
+    /**
3705
+     *  Return amount of order not paid and total
3706
+     *
3707
+     *  @param     string      $mode    'customer' or 'supplier'
3708
+     *  @return    array				array('opened'=>Amount, 'total'=>Total amount)
3709
+     */
3710
+    function getOutstandingProposals($mode='customer')
3711
+    {
3712
+        $table='propal';
3713
+        if ($mode == 'supplier') $table = 'supplier_proposal';
3714
+
3715
+        $sql  = "SELECT rowid, total_ht, total as total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
3716
+        $sql .= " WHERE fk_soc = ". $this->id;
3717
+        if ($mode == 'supplier') {
3718
+            $sql .= " AND entity IN (".getEntity('supplier_proposal').")";
3719
+        } else {
3720
+            $sql .= " AND entity IN (".getEntity('propal').")";
3721
+        }
3722
+
3723
+        dol_syslog("getOutstandingProposals", LOG_DEBUG);
3724
+        $resql=$this->db->query($sql);
3725
+        if ($resql)
3726
+        {
3727
+            $outstandingOpened = 0;
3728
+            $outstandingTotal = 0;
3729
+            $outstandingTotalIncTax = 0;
3730
+            while($obj=$this->db->fetch_object($resql)) {
3731
+                $outstandingTotal+= $obj->total_ht;
3732
+                $outstandingTotalIncTax+= $obj->total_ttc;
3733
+                if ($obj->fk_statut != 0)    // Not a draft
3734
+                {
3735
+                    $outstandingOpened+=$obj->total_ttc;
3736
+                }
3737
+            }
3738
+            return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3739
+        }
3740
+        else
3741
+            return array();
3742
+    }
3743
+
3744
+    /**
3745
+     *  Return amount of order not paid and total
3746
+     *
3747
+     *  @param     string      $mode    'customer' or 'supplier'
3748
+     *  @return		array				array('opened'=>Amount, 'total'=>Total amount)
3749
+     */
3750
+    function getOutstandingOrders($mode='customer')
3751
+    {
3752
+        $table='commande';
3753
+        if ($mode == 'supplier') $table = 'commande_fournisseur';
3754
+
3755
+        $sql  = "SELECT rowid, total_ht, total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
3756
+        $sql .= " WHERE fk_soc = ". $this->id;
3757
+        if ($mode == 'supplier') {
3758
+            $sql .= " AND entity IN (".getEntity('supplier_order').")";
3759
+        } else {
3760
+            $sql .= " AND entity IN (".getEntity('commande').")";
3761
+        }
3762
+
3763
+        dol_syslog("getOutstandingOrders", LOG_DEBUG);
3764
+        $resql=$this->db->query($sql);
3765
+        if ($resql)
3766
+        {
3767
+            $outstandingOpened = 0;
3768
+            $outstandingTotal = 0;
3769
+            $outstandingTotalIncTax = 0;
3770
+            while($obj=$this->db->fetch_object($resql)) {
3771
+                $outstandingTotal+= $obj->total_ht;
3772
+                $outstandingTotalIncTax+= $obj->total_ttc;
3773
+                if ($obj->fk_statut != 0)    // Not a draft
3774
+                {
3775
+                    $outstandingOpened+=$obj->total_ttc;
3776
+                }
3777
+            }
3778
+            return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3779
+        }
3780
+        else
3781
+            return array();
3782
+    }
3783
+
3784
+    /**
3785
+     *  Return amount of bill not paid and total
3786
+     *
3787
+     *  @param     string      $mode    'customer' or 'supplier'
3788
+     *  @return		array				array('opened'=>Amount, 'total'=>Total amount)
3789
+     */
3790
+    function getOutstandingBills($mode='customer')
3791
+    {
3792
+        $table='facture';
3793
+        if ($mode == 'supplier') $table = 'facture_fourn';
3794
+
3795
+        /* Accurate value of remain to pay is to sum remaintopay for each invoice
3796 3796
 		 $paiement = $invoice->getSommePaiement();
3797 3797
 		 $creditnotes=$invoice->getSumCreditNotesUsed();
3798 3798
 		 $deposits=$invoice->getSumDepositsUsed();
3799 3799
 		 $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
3800 3800
 		 $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
3801 3801
 		 */
3802
-		if ($mode == 'supplier') $sql  = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3803
-		else $sql  = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3804
-		$sql .= " WHERE fk_soc = ". $this->id;
3805
-		if ($mode == 'supplier') {
3806
-			$sql .= " AND entity IN (".getEntity('facture_fourn').")";
3807
-		} else {
3808
-			$sql .= " AND entity IN (".getEntity('invoice').")";
3809
-		}
3810
-
3811
-		dol_syslog("getOutstandingBills", LOG_DEBUG);
3812
-		$resql=$this->db->query($sql);
3813
-		if ($resql)
3814
-		{
3815
-			$outstandingOpened = 0;
3816
-			$outstandingTotal = 0;
3817
-			$outstandingTotalIncTax = 0;
3818
-			if ($mode == 'supplier')
3819
-			{
3820
-				require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
3821
-				$tmpobject=new FactureFournisseur($this->db);
3822
-			}
3823
-			else
3824
-			{
3825
-				require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
3826
-				$tmpobject=new Facture($this->db);
3827
-			}
3828
-			while($obj=$this->db->fetch_object($resql)) {
3829
-				$tmpobject->id=$obj->rowid;
3830
-				if ($obj->fk_statut != 0                                           // Not a draft
3831
-					&& ! ($obj->fk_statut == 3 && $obj->close_code == 'replaced')  // Not a replaced invoice
3832
-					)
3833
-				{
3834
-					$outstandingTotal+= $obj->total_ht;
3835
-					$outstandingTotalIncTax+= $obj->total_ttc;
3836
-				}
3837
-				if ($obj->paye == 0
3838
-					&& $obj->fk_statut != 0    // Not a draft
3839
-					&& $obj->fk_statut != 3	   // Not abandonned
3840
-					&& $obj->fk_statut != 2)   // Not classified as paid
3841
-				//$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')";		// Not abandonned for undefined reason
3842
-				{
3843
-					$paiement = $tmpobject->getSommePaiement();
3844
-					$creditnotes = $tmpobject->getSumCreditNotesUsed();
3845
-					$deposits = $tmpobject->getSumDepositsUsed();
3846
-					$outstandingOpened+=$obj->total_ttc - $paiement - $creditnotes - $deposits;
3847
-				}
3848
-			}
3849
-			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3850
-		}
3851
-		else
3852
-		{
3853
-			return array();
3854
-		}
3855
-	}
3802
+        if ($mode == 'supplier') $sql  = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3803
+        else $sql  = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3804
+        $sql .= " WHERE fk_soc = ". $this->id;
3805
+        if ($mode == 'supplier') {
3806
+            $sql .= " AND entity IN (".getEntity('facture_fourn').")";
3807
+        } else {
3808
+            $sql .= " AND entity IN (".getEntity('invoice').")";
3809
+        }
3810
+
3811
+        dol_syslog("getOutstandingBills", LOG_DEBUG);
3812
+        $resql=$this->db->query($sql);
3813
+        if ($resql)
3814
+        {
3815
+            $outstandingOpened = 0;
3816
+            $outstandingTotal = 0;
3817
+            $outstandingTotalIncTax = 0;
3818
+            if ($mode == 'supplier')
3819
+            {
3820
+                require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
3821
+                $tmpobject=new FactureFournisseur($this->db);
3822
+            }
3823
+            else
3824
+            {
3825
+                require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
3826
+                $tmpobject=new Facture($this->db);
3827
+            }
3828
+            while($obj=$this->db->fetch_object($resql)) {
3829
+                $tmpobject->id=$obj->rowid;
3830
+                if ($obj->fk_statut != 0                                           // Not a draft
3831
+                    && ! ($obj->fk_statut == 3 && $obj->close_code == 'replaced')  // Not a replaced invoice
3832
+                    )
3833
+                {
3834
+                    $outstandingTotal+= $obj->total_ht;
3835
+                    $outstandingTotalIncTax+= $obj->total_ttc;
3836
+                }
3837
+                if ($obj->paye == 0
3838
+                    && $obj->fk_statut != 0    // Not a draft
3839
+                    && $obj->fk_statut != 3	   // Not abandonned
3840
+                    && $obj->fk_statut != 2)   // Not classified as paid
3841
+                //$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')";		// Not abandonned for undefined reason
3842
+                {
3843
+                    $paiement = $tmpobject->getSommePaiement();
3844
+                    $creditnotes = $tmpobject->getSumCreditNotesUsed();
3845
+                    $deposits = $tmpobject->getSumDepositsUsed();
3846
+                    $outstandingOpened+=$obj->total_ttc - $paiement - $creditnotes - $deposits;
3847
+                }
3848
+            }
3849
+            return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3850
+        }
3851
+        else
3852
+        {
3853
+            return array();
3854
+        }
3855
+    }
3856 3856
 
3857 3857
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3858
-	/**
3859
-	 *  Return amount of bill not paid
3860
-	 *
3861
-	 *  @return		int				Amount in debt for thirdparty
3862
-	 *  @deprecated
3863
-	 *  @see getOutstandingBills()
3864
-	 */
3865
-	function get_OutstandingBill()
3866
-	{
3858
+    /**
3859
+     *  Return amount of bill not paid
3860
+     *
3861
+     *  @return		int				Amount in debt for thirdparty
3862
+     *  @deprecated
3863
+     *  @see getOutstandingBills()
3864
+     */
3865
+    function get_OutstandingBill()
3866
+    {
3867 3867
         // phpcs:enable
3868
-		/* Accurate value of remain to pay is to sum remaintopay for each invoice
3868
+        /* Accurate value of remain to pay is to sum remaintopay for each invoice
3869 3869
 	     $paiement = $invoice->getSommePaiement();
3870 3870
 	     $creditnotes=$invoice->getSumCreditNotesUsed();
3871 3871
 	     $deposits=$invoice->getSumDepositsUsed();
3872 3872
 	     $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
3873 3873
 	     $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
3874 3874
 	     */
3875
-		$sql  = "SELECT rowid, total_ttc FROM ".MAIN_DB_PREFIX."facture as f";
3876
-		$sql .= " WHERE fk_soc = ". $this->id;
3877
-		$sql .= " AND paye = 0";
3878
-		$sql .= " AND fk_statut <> 0";	// Not a draft
3879
-		//$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')";		// Not abandonned for undefined reason
3880
-		$sql .= " AND fk_statut <> 3";		// Not abandonned
3881
-		$sql .= " AND fk_statut <> 2";		// Not clasified as paid
3882
-
3883
-		dol_syslog("get_OutstandingBill", LOG_DEBUG);
3884
-		$resql=$this->db->query($sql);
3885
-		if ($resql)
3886
-		{
3887
-			$outstandingAmount = 0;
3888
-			require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
3889
-			$tmpobject=new Facture($this->db);
3890
-			while($obj=$this->db->fetch_object($resql)) {
3891
-				$tmpobject->id=$obj->rowid;
3892
-				$paiement = $tmpobject->getSommePaiement();
3893
-				$creditnotes = $tmpobject->getSumCreditNotesUsed();
3894
-				$deposits = $tmpobject->getSumDepositsUsed();
3895
-				$outstandingAmount+= $obj->total_ttc - $paiement - $creditnotes - $deposits;
3896
-			}
3897
-			return $outstandingAmount;
3898
-		}
3899
-		else
3900
-			return 0;
3901
-	}
3902
-
3903
-	/**
3904
-	 * Return label of status customer is prospect/customer
3905
-	 *
3906
-	 * @return   string        	Label
3907
-	 */
3908
-	function getLibCustProspStatut()
3909
-	{
3910
-		return $this->LibCustProspStatut($this->client);
3911
-	}
3875
+        $sql  = "SELECT rowid, total_ttc FROM ".MAIN_DB_PREFIX."facture as f";
3876
+        $sql .= " WHERE fk_soc = ". $this->id;
3877
+        $sql .= " AND paye = 0";
3878
+        $sql .= " AND fk_statut <> 0";	// Not a draft
3879
+        //$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')";		// Not abandonned for undefined reason
3880
+        $sql .= " AND fk_statut <> 3";		// Not abandonned
3881
+        $sql .= " AND fk_statut <> 2";		// Not clasified as paid
3882
+
3883
+        dol_syslog("get_OutstandingBill", LOG_DEBUG);
3884
+        $resql=$this->db->query($sql);
3885
+        if ($resql)
3886
+        {
3887
+            $outstandingAmount = 0;
3888
+            require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
3889
+            $tmpobject=new Facture($this->db);
3890
+            while($obj=$this->db->fetch_object($resql)) {
3891
+                $tmpobject->id=$obj->rowid;
3892
+                $paiement = $tmpobject->getSommePaiement();
3893
+                $creditnotes = $tmpobject->getSumCreditNotesUsed();
3894
+                $deposits = $tmpobject->getSumDepositsUsed();
3895
+                $outstandingAmount+= $obj->total_ttc - $paiement - $creditnotes - $deposits;
3896
+            }
3897
+            return $outstandingAmount;
3898
+        }
3899
+        else
3900
+            return 0;
3901
+    }
3902
+
3903
+    /**
3904
+     * Return label of status customer is prospect/customer
3905
+     *
3906
+     * @return   string        	Label
3907
+     */
3908
+    function getLibCustProspStatut()
3909
+    {
3910
+        return $this->LibCustProspStatut($this->client);
3911
+    }
3912 3912
 
3913 3913
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3914
-	/**
3915
-	 *  Renvoi le libelle d'un statut donne
3916
-	 *
3917
-	 *  @param	int		$statut         Id statut
3918
-	 *  @return	string          		Libelle du statut
3919
-	 */
3920
-	function LibCustProspStatut($statut)
3921
-	{
3914
+    /**
3915
+     *  Renvoi le libelle d'un statut donne
3916
+     *
3917
+     *  @param	int		$statut         Id statut
3918
+     *  @return	string          		Libelle du statut
3919
+     */
3920
+    function LibCustProspStatut($statut)
3921
+    {
3922 3922
         // phpcs:enable
3923
-		global $langs;
3924
-		$langs->load('companies');
3925
-
3926
-		if ($statut==0) return $langs->trans("NorProspectNorCustomer");
3927
-		if ($statut==1) return $langs->trans("Customer");
3928
-		if ($statut==2) return $langs->trans("Prospect");
3929
-		if ($statut==3) return $langs->trans("ProspectCustomer");
3930
-	}
3931
-
3932
-
3933
-	/**
3934
-	 *  Create a document onto disk according to template module.
3935
-	 *
3936
-	 *	@param	string		$modele			Generator to use. Caller must set it to obj->modelpdf or GETPOST('modelpdf') for example.
3937
-	 *	@param	Translate	$outputlangs	objet lang a utiliser pour traduction
3938
-	 *  @param  int			$hidedetails    Hide details of lines
3939
-	 *  @param  int			$hidedesc       Hide description
3940
-	 *  @param  int			$hideref        Hide ref
3941
-	 *  @param  null|array  $moreparams     Array to provide more information
3942
-	 *	@return int        					<0 if KO, >0 if OK
3943
-	 */
3944
-	public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
3945
-	{
3946
-		global $conf,$user,$langs;
3947
-
3948
-		if (! empty($moreparams) && ! empty($moreparams['use_companybankid']))
3949
-		{
3950
-			$modelpath = "core/modules/bank/doc/";
3951
-
3952
-			include_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
3953
-			$companybankaccount = new CompanyBankAccount($this->db);
3954
-			$result = $companybankaccount->fetch($moreparams['use_companybankid']);
3955
-			if (! $result) dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
3956
-			$result=$companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3957
-		}
3958
-		else
3959
-		{
3960
-			// Positionne le modele sur le nom du modele a utiliser
3961
-			if (! dol_strlen($modele))
3962
-			{
3963
-				if (! empty($conf->global->COMPANY_ADDON_PDF))
3964
-				{
3965
-					$modele = $conf->global->COMPANY_ADDON_PDF;
3966
-				}
3967
-				else
3968
-				{
3969
-					print $langs->trans("Error")." ".$langs->trans("Error_COMPANY_ADDON_PDF_NotDefined");
3970
-					return 0;
3971
-				}
3972
-			}
3973
-
3974
-			$modelpath = "core/modules/societe/doc/";
3975
-
3976
-			$result=$this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3977
-		}
3978
-
3979
-		return $result;
3980
-	}
3981
-
3982
-
3983
-	/**
3984
-	 * Sets object to supplied categories.
3985
-	 *
3986
-	 * Deletes object from existing categories not supplied.
3987
-	 * Adds it to non existing supplied categories.
3988
-	 * Existing categories are left untouch.
3989
-	 *
3990
-	 * @param 	int[]|int 	$categories 	Category ID or array of Categories IDs
3991
-	 * @param 	string 		$type 			Category type ('customer' or 'supplier')
3992
-	 * @return	int							<0 if KO, >0 if OK
3993
-	 */
3994
-	public function setCategories($categories, $type)
3995
-	{
3996
-		require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
3997
-
3998
-		// Decode type
3999
-		if ($type == 'customer') {
4000
-			$type_id = Categorie::TYPE_CUSTOMER;
4001
-			$type_text = 'customer';
4002
-		} elseif ($type == 'supplier') {
4003
-			$type_id = Categorie::TYPE_SUPPLIER;
4004
-			$type_text = 'supplier';
4005
-		} else {
4006
-			dol_syslog(__METHOD__ . ': Type ' . $type .  'is an unknown company category type. Done nothing.', LOG_ERR);
4007
-			return -1;
4008
-		}
4009
-
4010
-		// Handle single category
4011
-		if (!is_array($categories)) {
4012
-			$categories = array($categories);
4013
-		}
4014
-
4015
-		// Get current categories
4016
-		$c = new Categorie($this->db);
4017
-		$existing = $c->containing($this->id, $type_id, 'id');
4018
-
4019
-		// Diff
4020
-		if (is_array($existing)) {
4021
-			$to_del = array_diff($existing, $categories);
4022
-			$to_add = array_diff($categories, $existing);
4023
-		} else {
4024
-			$to_del = array(); // Nothing to delete
4025
-			$to_add = $categories;
4026
-		}
4027
-
4028
-		$error = 0;
4029
-
4030
-		// Process
4031
-		foreach ($to_del as $del) {
4032
-			if ($c->fetch($del) > 0) {
4033
-				$c->del_type($this, $type_text);
4034
-			}
4035
-		}
4036
-		foreach ($to_add as $add) {
4037
-			if ($c->fetch($add) > 0)
4038
-			{
4039
-				$result = $c->add_type($this, $type_text);
4040
-				if ($result < 0)
4041
-				{
4042
-					$error++;
4043
-					$this->error = $c->error;
4044
-					$this->errors = $c->errors;
4045
-					break;
4046
-				}
4047
-			}
4048
-		}
4049
-
4050
-		return $error ? -1 : 1;
4051
-	}
4052
-
4053
-	/**
4054
-	 * Sets sales representatives of the thirdparty
4055
-	 *
4056
-	 * @param 	int[]|int 	$salesrep	 	User ID or array of user IDs
4057
-	 * @return	int							<0 if KO, >0 if OK
4058
-	 */
4059
-	public function setSalesRep($salesrep)
4060
-	{
4061
-		global $user;
4062
-
4063
-		// Handle single user
4064
-		if (!is_array($salesrep)) {
4065
-			$salesrep = array($salesrep);
4066
-		}
4067
-
4068
-		// Get current users
4069
-		$existing = $this->getSalesRepresentatives($user, 1);
4070
-
4071
-		// Diff
4072
-		if (is_array($existing)) {
4073
-			$to_del = array_diff($existing, $salesrep);
4074
-			$to_add = array_diff($salesrep, $existing);
4075
-		} else {
4076
-			$to_del = array(); // Nothing to delete
4077
-			$to_add = $salesrep;
4078
-		}
4079
-
4080
-		$error = 0;
4081
-
4082
-		// Process
4083
-		foreach ($to_del as $del) {
4084
-			$this->del_commercial($user, $del);
4085
-		}
4086
-		foreach ($to_add as $add) {
4087
-			$result = $this->add_commercial($user, $add);
4088
-			if ($result < 0)
4089
-			{
4090
-				$error++;
4091
-				$this->error = $c->error;
4092
-				$this->errors = $c->errors;
4093
-				break;
4094
-			}
4095
-		}
4096
-
4097
-		return $error ? -1 : 1;
4098
-	}
4099
-
4100
-
4101
-	/**
4102
-	 * Function used to replace a thirdparty id with another one.
4103
-	 * It must be used within a transaction to avoid trouble
4104
-	 *
4105
-	 * @param 	DoliDB 	$db 		Database handler
4106
-	 * @param 	int 	$origin_id 	Old thirdparty id (will be removed)
4107
-	 * @param 	int 	$dest_id 	New thirdparty id
4108
-	 * @return 	bool				True if success, False if error
4109
-	 */
4110
-	public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
4111
-	{
4112
-		if ($origin_id == $dest_id)
4113
-		{
4114
-			dol_syslog('Error: Try to merge a thirdparty into itself');
4115
-			return false;
4116
-		}
4117
-
4118
-		/**
4119
-		 * Thirdparty commercials cannot be the same in both thirdparties so we look for them and remove some to avoid duplicate.
4120
-		 * Because this function is meant to be executed within a transaction, we won't take care of begin/commit.
4121
-		 */
4122
-		$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'societe_commerciaux ';
4123
-		$sql .= ' WHERE fk_soc = '.(int) $dest_id.' AND fk_user IN ( ';
4124
-		$sql .= ' SELECT fk_user ';
4125
-		$sql .= ' FROM '.MAIN_DB_PREFIX.'societe_commerciaux ';
4126
-		$sql .= ' WHERE fk_soc = '.(int) $origin_id.') ';
3923
+        global $langs;
3924
+        $langs->load('companies');
4127 3925
 
4128
-		$query = $db->query($sql);
3926
+        if ($statut==0) return $langs->trans("NorProspectNorCustomer");
3927
+        if ($statut==1) return $langs->trans("Customer");
3928
+        if ($statut==2) return $langs->trans("Prospect");
3929
+        if ($statut==3) return $langs->trans("ProspectCustomer");
3930
+    }
4129 3931
 
4130
-		while ($result = $db->fetch_object($query)) {
4131
-			$db->query('DELETE FROM '.MAIN_DB_PREFIX.'societe_commerciaux WHERE rowid = '.$result->rowid);
4132
-		}
4133 3932
 
4134
-		/**
4135
-		 * llx_societe_extrafields table must not be here because we don't care about the old thirdparty data
4136
-		 * Do not include llx_societe because it will be replaced later
4137
-		 */
4138
-		$tables = array(
4139
-			'societe_address',
4140
-			'societe_commerciaux',
4141
-			'societe_log',
4142
-			'societe_prices',
4143
-			'societe_remise',
4144
-			'societe_remise_except',
4145
-			'societe_rib'
4146
-		);
4147
-
4148
-		return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
4149
-	}
3933
+    /**
3934
+     *  Create a document onto disk according to template module.
3935
+     *
3936
+     *	@param	string		$modele			Generator to use. Caller must set it to obj->modelpdf or GETPOST('modelpdf') for example.
3937
+     *	@param	Translate	$outputlangs	objet lang a utiliser pour traduction
3938
+     *  @param  int			$hidedetails    Hide details of lines
3939
+     *  @param  int			$hidedesc       Hide description
3940
+     *  @param  int			$hideref        Hide ref
3941
+     *  @param  null|array  $moreparams     Array to provide more information
3942
+     *	@return int        					<0 if KO, >0 if OK
3943
+     */
3944
+    public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
3945
+    {
3946
+        global $conf,$user,$langs;
3947
+
3948
+        if (! empty($moreparams) && ! empty($moreparams['use_companybankid']))
3949
+        {
3950
+            $modelpath = "core/modules/bank/doc/";
3951
+
3952
+            include_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
3953
+            $companybankaccount = new CompanyBankAccount($this->db);
3954
+            $result = $companybankaccount->fetch($moreparams['use_companybankid']);
3955
+            if (! $result) dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
3956
+            $result=$companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3957
+        }
3958
+        else
3959
+        {
3960
+            // Positionne le modele sur le nom du modele a utiliser
3961
+            if (! dol_strlen($modele))
3962
+            {
3963
+                if (! empty($conf->global->COMPANY_ADDON_PDF))
3964
+                {
3965
+                    $modele = $conf->global->COMPANY_ADDON_PDF;
3966
+                }
3967
+                else
3968
+                {
3969
+                    print $langs->trans("Error")." ".$langs->trans("Error_COMPANY_ADDON_PDF_NotDefined");
3970
+                    return 0;
3971
+                }
3972
+            }
3973
+
3974
+            $modelpath = "core/modules/societe/doc/";
3975
+
3976
+            $result=$this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3977
+        }
3978
+
3979
+        return $result;
3980
+    }
3981
+
3982
+
3983
+    /**
3984
+     * Sets object to supplied categories.
3985
+     *
3986
+     * Deletes object from existing categories not supplied.
3987
+     * Adds it to non existing supplied categories.
3988
+     * Existing categories are left untouch.
3989
+     *
3990
+     * @param 	int[]|int 	$categories 	Category ID or array of Categories IDs
3991
+     * @param 	string 		$type 			Category type ('customer' or 'supplier')
3992
+     * @return	int							<0 if KO, >0 if OK
3993
+     */
3994
+    public function setCategories($categories, $type)
3995
+    {
3996
+        require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
3997
+
3998
+        // Decode type
3999
+        if ($type == 'customer') {
4000
+            $type_id = Categorie::TYPE_CUSTOMER;
4001
+            $type_text = 'customer';
4002
+        } elseif ($type == 'supplier') {
4003
+            $type_id = Categorie::TYPE_SUPPLIER;
4004
+            $type_text = 'supplier';
4005
+        } else {
4006
+            dol_syslog(__METHOD__ . ': Type ' . $type .  'is an unknown company category type. Done nothing.', LOG_ERR);
4007
+            return -1;
4008
+        }
4009
+
4010
+        // Handle single category
4011
+        if (!is_array($categories)) {
4012
+            $categories = array($categories);
4013
+        }
4014
+
4015
+        // Get current categories
4016
+        $c = new Categorie($this->db);
4017
+        $existing = $c->containing($this->id, $type_id, 'id');
4018
+
4019
+        // Diff
4020
+        if (is_array($existing)) {
4021
+            $to_del = array_diff($existing, $categories);
4022
+            $to_add = array_diff($categories, $existing);
4023
+        } else {
4024
+            $to_del = array(); // Nothing to delete
4025
+            $to_add = $categories;
4026
+        }
4027
+
4028
+        $error = 0;
4029
+
4030
+        // Process
4031
+        foreach ($to_del as $del) {
4032
+            if ($c->fetch($del) > 0) {
4033
+                $c->del_type($this, $type_text);
4034
+            }
4035
+        }
4036
+        foreach ($to_add as $add) {
4037
+            if ($c->fetch($add) > 0)
4038
+            {
4039
+                $result = $c->add_type($this, $type_text);
4040
+                if ($result < 0)
4041
+                {
4042
+                    $error++;
4043
+                    $this->error = $c->error;
4044
+                    $this->errors = $c->errors;
4045
+                    break;
4046
+                }
4047
+            }
4048
+        }
4049
+
4050
+        return $error ? -1 : 1;
4051
+    }
4052
+
4053
+    /**
4054
+     * Sets sales representatives of the thirdparty
4055
+     *
4056
+     * @param 	int[]|int 	$salesrep	 	User ID or array of user IDs
4057
+     * @return	int							<0 if KO, >0 if OK
4058
+     */
4059
+    public function setSalesRep($salesrep)
4060
+    {
4061
+        global $user;
4062
+
4063
+        // Handle single user
4064
+        if (!is_array($salesrep)) {
4065
+            $salesrep = array($salesrep);
4066
+        }
4067
+
4068
+        // Get current users
4069
+        $existing = $this->getSalesRepresentatives($user, 1);
4070
+
4071
+        // Diff
4072
+        if (is_array($existing)) {
4073
+            $to_del = array_diff($existing, $salesrep);
4074
+            $to_add = array_diff($salesrep, $existing);
4075
+        } else {
4076
+            $to_del = array(); // Nothing to delete
4077
+            $to_add = $salesrep;
4078
+        }
4079
+
4080
+        $error = 0;
4081
+
4082
+        // Process
4083
+        foreach ($to_del as $del) {
4084
+            $this->del_commercial($user, $del);
4085
+        }
4086
+        foreach ($to_add as $add) {
4087
+            $result = $this->add_commercial($user, $add);
4088
+            if ($result < 0)
4089
+            {
4090
+                $error++;
4091
+                $this->error = $c->error;
4092
+                $this->errors = $c->errors;
4093
+                break;
4094
+            }
4095
+        }
4096
+
4097
+        return $error ? -1 : 1;
4098
+    }
4099
+
4100
+
4101
+    /**
4102
+     * Function used to replace a thirdparty id with another one.
4103
+     * It must be used within a transaction to avoid trouble
4104
+     *
4105
+     * @param 	DoliDB 	$db 		Database handler
4106
+     * @param 	int 	$origin_id 	Old thirdparty id (will be removed)
4107
+     * @param 	int 	$dest_id 	New thirdparty id
4108
+     * @return 	bool				True if success, False if error
4109
+     */
4110
+    public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
4111
+    {
4112
+        if ($origin_id == $dest_id)
4113
+        {
4114
+            dol_syslog('Error: Try to merge a thirdparty into itself');
4115
+            return false;
4116
+        }
4117
+
4118
+        /**
4119
+         * Thirdparty commercials cannot be the same in both thirdparties so we look for them and remove some to avoid duplicate.
4120
+         * Because this function is meant to be executed within a transaction, we won't take care of begin/commit.
4121
+         */
4122
+        $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'societe_commerciaux ';
4123
+        $sql .= ' WHERE fk_soc = '.(int) $dest_id.' AND fk_user IN ( ';
4124
+        $sql .= ' SELECT fk_user ';
4125
+        $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_commerciaux ';
4126
+        $sql .= ' WHERE fk_soc = '.(int) $origin_id.') ';
4127
+
4128
+        $query = $db->query($sql);
4129
+
4130
+        while ($result = $db->fetch_object($query)) {
4131
+            $db->query('DELETE FROM '.MAIN_DB_PREFIX.'societe_commerciaux WHERE rowid = '.$result->rowid);
4132
+        }
4133
+
4134
+        /**
4135
+         * llx_societe_extrafields table must not be here because we don't care about the old thirdparty data
4136
+         * Do not include llx_societe because it will be replaced later
4137
+         */
4138
+        $tables = array(
4139
+            'societe_address',
4140
+            'societe_commerciaux',
4141
+            'societe_log',
4142
+            'societe_prices',
4143
+            'societe_remise',
4144
+            'societe_remise_except',
4145
+            'societe_rib'
4146
+        );
4147
+
4148
+        return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
4149
+    }
4150 4150
 }
Please login to merge, or discard this patch.
Spacing   +798 added lines, -798 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	/**
46 46
 	 * @var string ID to identify managed object
47 47
 	 */
48
-	public $element='societe';
48
+	public $element = 'societe';
49 49
 
50 50
 	/**
51 51
 	 * @var string Name of table without prefix where object is stored
@@ -55,11 +55,11 @@  discard block
 block discarded – undo
55 55
 	/**
56 56
 	 * @var int Field with ID of parent key if this field has a parent
57 57
 	 */
58
-	public $fk_element='fk_soc';
58
+	public $fk_element = 'fk_soc';
59 59
 
60
-	public $fieldsforcombobox='nom,name_alias';
61
-	protected $childtables=array("supplier_proposal"=>'SupplierProposal',"propal"=>'Proposal',"commande"=>'Order',"facture"=>'Invoice',"facture_rec"=>'RecurringInvoiceTemplate',"contrat"=>'Contract',"fichinter"=>'Fichinter',"facture_fourn"=>'SupplierInvoice',"commande_fournisseur"=>'SupplierOrder',"projet"=>'Project',"expedition"=>'Shipment',"prelevement_lignes"=>'DirectDebitRecord');    // To test if we can delete object
62
-	protected $childtablesoncascade=array("societe_prices", "societe_log", "societe_address", "product_fournisseur_price", "product_customer_price_log", "product_customer_price", "socpeople", "adherent", "societe_rib", "societe_remise", "societe_remise_except", "societe_commerciaux", "categorie", "notify", "notify_def", "actioncomm");
60
+	public $fieldsforcombobox = 'nom,name_alias';
61
+	protected $childtables = array("supplier_proposal"=>'SupplierProposal', "propal"=>'Proposal', "commande"=>'Order', "facture"=>'Invoice', "facture_rec"=>'RecurringInvoiceTemplate', "contrat"=>'Contract', "fichinter"=>'Fichinter', "facture_fourn"=>'SupplierInvoice', "commande_fournisseur"=>'SupplierOrder', "projet"=>'Project', "expedition"=>'Shipment', "prelevement_lignes"=>'DirectDebitRecord'); // To test if we can delete object
62
+	protected $childtablesoncascade = array("societe_prices", "societe_log", "societe_address", "product_fournisseur_price", "product_customer_price_log", "product_customer_price", "socpeople", "adherent", "societe_rib", "societe_remise", "societe_remise_except", "societe_commerciaux", "categorie", "notify", "notify_def", "actioncomm");
63 63
 	public $picto = 'company';
64 64
 
65 65
 	/**
@@ -79,20 +79,20 @@  discard block
 block discarded – undo
79 79
 	/**
80 80
 	 * @var array  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
81 81
 	 */
82
-	public $fields=array(
83
-		'rowid'         =>array('type'=>'integer',      'label'=>'TechnicalID',      'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'index'=>1, 'position'=>1, 'comment'=>'Id'),
84
-		'nom'           =>array('type'=>'varchar(128)', 'label'=>'Name',             'enabled'=>1, 'visible'=>1,  'notnull'=>1,  'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
85
-		'name_alias'    =>array('type'=>'varchar(128)', 'label'=>'Name',             'enabled'=>1, 'visible'=>1,  'notnull'=>1,  'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
86
-		'entity'        =>array('type'=>'integer',      'label'=>'Entity',           'enabled'=>1, 'visible'=>0,  'default'=>1,  'notnull'=>1,  'index'=>1, 'position'=>20),
87
-		'note_public'   =>array('type'=>'text',			'label'=>'NotePublic',		 'enabled'=>1, 'visible'=>0,  'position'=>60),
88
-		'note_private'  =>array('type'=>'text',			'label'=>'NotePrivate',		 'enabled'=>1, 'visible'=>0,  'position'=>61),
89
-		'datec'			=>array('type'=>'datetime',     'label'=>'DateCreation',     'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'position'=>500),
90
-		'tms'           =>array('type'=>'timestamp',    'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'position'=>501),
82
+	public $fields = array(
83
+		'rowid'         =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
84
+		'nom'           =>array('type'=>'varchar(128)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
85
+		'name_alias'    =>array('type'=>'varchar(128)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
86
+		'entity'        =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20),
87
+		'note_public'   =>array('type'=>'text', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>60),
88
+		'note_private'  =>array('type'=>'text', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>61),
89
+		'datec'			=>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500),
90
+		'tms'           =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501),
91 91
 		//'date_valid'    =>array('type'=>'datetime',     'label'=>'DateCreation',     'enabled'=>1, 'visible'=>-2, 'position'=>502),
92
-		'fk_user_creat' =>array('type'=>'integer',      'label'=>'UserAuthor',       'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'position'=>510),
93
-		'fk_user_modif' =>array('type'=>'integer',      'label'=>'UserModif',        'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511),
92
+		'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>510),
93
+		'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511),
94 94
 		//'fk_user_valid' =>array('type'=>'integer',      'label'=>'UserValidation',        'enabled'=>1, 'visible'=>-1, 'position'=>512),
95
-		'import_key'    =>array('type'=>'varchar(14)',  'label'=>'ImportId',         'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>1,  'position'=>1000),
95
+		'import_key'    =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>1, 'position'=>1000),
96 96
 	);
97 97
 
98 98
 
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 	 * Thirdparty status : 0=activity ceased, 1= in activity
135 135
 	 * @var int
136 136
 	 */
137
-	public $status=1;
137
+	public $status = 1;
138 138
 
139 139
 	/**
140 140
 	 * Id of department
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 
257 257
 	public $prefix_comm;
258 258
 
259
-	public $tva_assuj=1;
259
+	public $tva_assuj = 1;
260 260
 	/**
261 261
 	 * Intracommunitary VAT ID
262 262
 	 * @var string
@@ -271,12 +271,12 @@  discard block
 block discarded – undo
271 271
 
272 272
 	public $managers;
273 273
 	public $capital;
274
-	public $typent_id=0;
274
+	public $typent_id = 0;
275 275
 	public $typent_code;
276 276
 	public $effectif;
277
-	public $effectif_id=0;
277
+	public $effectif_id = 0;
278 278
 	public $forme_juridique_code;
279
-	public $forme_juridique=0;
279
+	public $forme_juridique = 0;
280 280
 
281 281
 	public $remise_percent;
282 282
 	public $remise_supplier_percent;
@@ -320,12 +320,12 @@  discard block
 block discarded – undo
320 320
 	 * 0=no customer, 1=customer, 2=prospect, 3=customer and prospect
321 321
 	 * @var int
322 322
 	 */
323
-	public $client=0;
323
+	public $client = 0;
324 324
 	/**
325 325
 	 * 0=no prospect, 1=prospect
326 326
 	 * @var int
327 327
 	 */
328
-	public $prospect=0;
328
+	public $prospect = 0;
329 329
 	/**
330 330
 	 * 0=no supplier, 1=supplier
331 331
 	 * @var int
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 	public $fk_incoterms;
462 462
 
463 463
 	public $location_incoterms;
464
-	public $libelle_incoterms;  //Used into tooltip
464
+	public $libelle_incoterms; //Used into tooltip
465 465
 
466 466
 	// Multicurrency
467 467
 	/**
@@ -487,9 +487,9 @@  discard block
 block discarded – undo
487 487
 		$this->client = 0;
488 488
 		$this->prospect = 0;
489 489
 		$this->fournisseur = 0;
490
-		$this->typent_id  = 0;
491
-		$this->effectif_id  = 0;
492
-		$this->forme_juridique_code  = 0;
490
+		$this->typent_id = 0;
491
+		$this->effectif_id = 0;
492
+		$this->forme_juridique_code = 0;
493 493
 		$this->tva_assuj = 1;
494 494
 		$this->status = 1;
495 495
 	}
@@ -504,17 +504,17 @@  discard block
 block discarded – undo
504 504
 	 */
505 505
 	function create(User $user)
506 506
 	{
507
-		global $langs,$conf,$mysoc;
507
+		global $langs, $conf, $mysoc;
508 508
 
509
-		$error=0;
509
+		$error = 0;
510 510
 
511 511
 		// Clean parameters
512
-		if (empty($this->status)) $this->status=0;
513
-		$this->name=$this->name?trim($this->name):trim($this->nom);
514
-		if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name=ucwords($this->name);
515
-		$this->nom=$this->name; // For backward compatibility
516
-		if (empty($this->client))      $this->client=0;
517
-		if (empty($this->fournisseur)) $this->fournisseur=0;
512
+		if (empty($this->status)) $this->status = 0;
513
+		$this->name = $this->name ?trim($this->name) : trim($this->nom);
514
+		if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name = ucwords($this->name);
515
+		$this->nom = $this->name; // For backward compatibility
516
+		if (empty($this->client))      $this->client = 0;
517
+		if (empty($this->fournisseur)) $this->fournisseur = 0;
518 518
 		$this->import_key = trim($this->import_key);
519 519
 
520 520
 		if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
@@ -526,13 +526,13 @@  discard block
 block discarded – undo
526 526
 
527 527
 		dol_syslog(get_class($this)."::create ".$this->name);
528 528
 
529
-		$now=dol_now();
529
+		$now = dol_now();
530 530
 
531 531
 		$this->db->begin();
532 532
 
533 533
 		// For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
534
-		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this,0);
535
-		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1);
534
+		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this, 0);
535
+		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this, 1);
536 536
 
537 537
 		// Check more parameters (including mandatory setup
538 538
 		// If error, this->errors[] is filled
@@ -540,29 +540,29 @@  discard block
 block discarded – undo
540 540
 
541 541
 		if ($result >= 0)
542 542
 		{
543
-			$this->entity = ((isset($this->entity) && is_numeric($this->entity))?$this->entity:$conf->entity);
543
+			$this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
544 544
 
545 545
 			$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, name_alias, entity, datec, fk_user_creat, canvas, status, ref_int, ref_ext, fk_stcomm, fk_incoterms, location_incoterms ,import_key, fk_multicurrency, multicurrency_code)";
546
-			$sql.= " VALUES ('".$this->db->escape($this->name)."', '".$this->db->escape($this->name_alias)."', ".$this->db->escape($this->entity).", '".$this->db->idate($now)."'";
547
-			$sql.= ", ".(! empty($user->id) ? "'".$user->id."'":"null");
548
-			$sql.= ", ".(! empty($this->canvas) ? "'".$this->db->escape($this->canvas)."'":"null");
549
-			$sql.= ", ".$this->status;
550
-			$sql.= ", ".(! empty($this->ref_int) ? "'".$this->db->escape($this->ref_int)."'":"null");
551
-			$sql.= ", ".(! empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'":"null");
552
-			$sql.= ", 0";
553
-			$sql.= ", ".(int) $this->fk_incoterms;
554
-			$sql.= ", '".$this->db->escape($this->location_incoterms)."'";
555
-			$sql.= ", ".(! empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'":"null");
556
-			$sql.= ", ".(int) $this->fk_multicurrency;
557
-			$sql.= ", '".$this->db->escape($this->multicurrency_code)."')";
546
+			$sql .= " VALUES ('".$this->db->escape($this->name)."', '".$this->db->escape($this->name_alias)."', ".$this->db->escape($this->entity).", '".$this->db->idate($now)."'";
547
+			$sql .= ", ".(!empty($user->id) ? "'".$user->id."'" : "null");
548
+			$sql .= ", ".(!empty($this->canvas) ? "'".$this->db->escape($this->canvas)."'" : "null");
549
+			$sql .= ", ".$this->status;
550
+			$sql .= ", ".(!empty($this->ref_int) ? "'".$this->db->escape($this->ref_int)."'" : "null");
551
+			$sql .= ", ".(!empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null");
552
+			$sql .= ", 0";
553
+			$sql .= ", ".(int) $this->fk_incoterms;
554
+			$sql .= ", '".$this->db->escape($this->location_incoterms)."'";
555
+			$sql .= ", ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null");
556
+			$sql .= ", ".(int) $this->fk_multicurrency;
557
+			$sql .= ", '".$this->db->escape($this->multicurrency_code)."')";
558 558
 
559 559
 			dol_syslog(get_class($this)."::create", LOG_DEBUG);
560
-			$result=$this->db->query($sql);
560
+			$result = $this->db->query($sql);
561 561
 			if ($result)
562 562
 			{
563 563
 				$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe");
564 564
 
565
-				$ret = $this->update($this->id,$user,0,1,1,'add');
565
+				$ret = $this->update($this->id, $user, 0, 1, 1, 'add');
566 566
 
567 567
 				// Ajout du commercial affecte
568 568
 				if ($this->commercial_id != '' && $this->commercial_id != -1)
@@ -578,13 +578,13 @@  discard block
 block discarded – undo
578 578
 				if ($ret >= 0)
579 579
 				{
580 580
 					// Call trigger
581
-					$result=$this->call_trigger('COMPANY_CREATE',$user);
581
+					$result = $this->call_trigger('COMPANY_CREATE', $user);
582 582
 					if ($result < 0) $error++;
583 583
 					// End call triggers
584 584
 				}
585 585
 				else $error++;
586 586
 
587
-				if (! $error)
587
+				if (!$error)
588 588
 				{
589 589
 					dol_syslog(get_class($this)."::Create success id=".$this->id);
590 590
 					$this->db->commit();
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
 				}
593 593
 				else
594 594
 				{
595
-					dol_syslog(get_class($this)."::Create echec update ".$this->error." ".join(',',$this->errors), LOG_ERR);
595
+					dol_syslog(get_class($this)."::Create echec update ".$this->error." ".join(',', $this->errors), LOG_ERR);
596 596
 					$this->db->rollback();
597 597
 					return -4;
598 598
 				}
@@ -601,13 +601,13 @@  discard block
 block discarded – undo
601 601
 			{
602 602
 				if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
603 603
 				{
604
-					$this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->name);    // duplicate on a field (code or profid or ...)
605
-					$result=-1;
604
+					$this->error = $langs->trans("ErrorCompanyNameAlreadyExists", $this->name); // duplicate on a field (code or profid or ...)
605
+					$result = -1;
606 606
 				}
607 607
 				else
608 608
 				{
609
-					$this->error=$this->db->lasterror();
610
-					$result=-2;
609
+					$this->error = $this->db->lasterror();
610
+					$result = -2;
611 611
 				}
612 612
 				$this->db->rollback();
613 613
 				return $result;
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
 		else
617 617
 		{
618 618
 			$this->db->rollback();
619
-			dol_syslog(get_class($this)."::Create fails verify ".join(',',$this->errors), LOG_WARNING);
619
+			dol_syslog(get_class($this)."::Create fails verify ".join(',', $this->errors), LOG_WARNING);
620 620
 			return -3;
621 621
 		}
622 622
 	}
@@ -633,12 +633,12 @@  discard block
 block discarded – undo
633 633
 	{
634 634
         // phpcs:enable
635 635
 		require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
636
-		$contact=new Contact($this->db);
636
+		$contact = new Contact($this->db);
637 637
 
638 638
 		$contact->name              = $this->name_bis;
639 639
 		$contact->firstname         = $this->firstname;
640 640
 		$contact->civility_id       = $this->civility_id;
641
-		$contact->socid             = $this->id;	// fk_soc
641
+		$contact->socid             = $this->id; // fk_soc
642 642
 		$contact->statut            = 1;
643 643
 		$contact->priv              = 0;
644 644
 		$contact->country_id        = $this->country_id;
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 		{
655 655
 			$this->error = $contact->error;
656 656
 			$this->errors = $contact->errors;
657
-			dol_syslog(get_class($this)."::create_individual ERROR:" . $this->error, LOG_ERR);
657
+			dol_syslog(get_class($this)."::create_individual ERROR:".$this->error, LOG_ERR);
658 658
 		}
659 659
 
660 660
 		return $result;
@@ -671,13 +671,13 @@  discard block
 block discarded – undo
671 671
 		global $conf, $langs, $mysoc;
672 672
 
673 673
 		$error = 0;
674
-		$this->errors=array();
674
+		$this->errors = array();
675 675
 
676 676
 		$result = 0;
677
-		$this->name	= trim($this->name);
678
-		$this->nom=$this->name; // For backward compatibility
677
+		$this->name = trim($this->name);
678
+		$this->nom = $this->name; // For backward compatibility
679 679
 
680
-		if (! $this->name)
680
+		if (!$this->name)
681 681
 		{
682 682
 			$this->errors[] = 'ErrorBadThirdPartyName';
683 683
 			$result = -2;
@@ -734,12 +734,12 @@  discard block
 block discarded – undo
734 734
 		}
735 735
 
736 736
 		// Check for duplicate or mandatory fields defined into setup
737
-		$array_to_check=array('IDPROF1','IDPROF2','IDPROF3','IDPROF4','IDPROF5','IDPROF6','EMAIL');
738
-		foreach($array_to_check as $key)
737
+		$array_to_check = array('IDPROF1', 'IDPROF2', 'IDPROF3', 'IDPROF4', 'IDPROF5', 'IDPROF6', 'EMAIL');
738
+		foreach ($array_to_check as $key)
739 739
 		{
740
-			$keymin=strtolower($key);
741
-			$i=(int) preg_replace('/[^0-9]/','',$key);
742
-			$vallabel=$this->$keymin;
740
+			$keymin = strtolower($key);
741
+			$i = (int) preg_replace('/[^0-9]/', '', $key);
742
+			$vallabel = $this->$keymin;
743 743
 
744 744
 			if ($i > 0)
745 745
 			{
@@ -758,8 +758,8 @@  discard block
 block discarded – undo
758 758
 					// Check for mandatory prof id (but only if country is other than ours)
759 759
 					if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id)
760 760
 					{
761
-						$idprof_mandatory ='SOCIETE_'.$key.'_MANDATORY';
762
-						if (! $vallabel && ! empty($conf->global->$idprof_mandatory))
761
+						$idprof_mandatory = 'SOCIETE_'.$key.'_MANDATORY';
762
+						if (!$vallabel && !empty($conf->global->$idprof_mandatory))
763 763
 						{
764 764
 							$langs->load("errors");
765 765
 							$error++;
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
 				if ($key == 'EMAIL')
776 776
 				{
777 777
 					// Check for unicity
778
-					if ($vallabel && ! empty($conf->global->SOCIETE_EMAIL_UNIQUE))
778
+					if ($vallabel && !empty($conf->global->SOCIETE_EMAIL_UNIQUE))
779 779
 					{
780 780
 						if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0)))
781 781
 						{
@@ -785,7 +785,7 @@  discard block
 block discarded – undo
785 785
 					}
786 786
 
787 787
 					// Check for mandatory
788
-					if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY) && ! isValidEMail($this->email))
788
+					if (!empty($conf->global->SOCIETE_EMAIL_MANDATORY) && !isValidEMail($this->email))
789 789
 					{
790 790
 						$langs->load("errors");
791 791
 						$error++;
@@ -812,58 +812,58 @@  discard block
 block discarded – undo
812 812
 	 *		@param	int		$nosyncmember				Do not synchronize info of linked member
813 813
 	 *      @return int  			           			<0 if KO, >=0 if OK
814 814
 	 */
815
-	function update($id, $user='', $call_trigger=1, $allowmodcodeclient=0, $allowmodcodefournisseur=0, $action='update', $nosyncmember=1)
815
+	function update($id, $user = '', $call_trigger = 1, $allowmodcodeclient = 0, $allowmodcodefournisseur = 0, $action = 'update', $nosyncmember = 1)
816 816
 	{
817
-		global $langs,$conf,$hookmanager;
817
+		global $langs, $conf, $hookmanager;
818 818
 
819 819
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
820 820
 
821 821
 		if (empty($id)) $id = $this->id;
822 822
 
823
-		$error=0;
823
+		$error = 0;
824 824
 
825 825
 		dol_syslog(get_class($this)."::Update id=".$id." call_trigger=".$call_trigger." allowmodcodeclient=".$allowmodcodeclient." allowmodcodefournisseur=".$allowmodcodefournisseur);
826 826
 
827
-		$now=dol_now();
827
+		$now = dol_now();
828 828
 
829 829
 		// Clean parameters
830
-		$this->id			= $id;
831
-		$this->entity		= ((isset($this->entity) && is_numeric($this->entity))?$this->entity:$conf->entity);
832
-		$this->name			= $this->name?trim($this->name):trim($this->nom);
833
-		$this->nom			= $this->name;	// For backward compatibility
834
-		$this->name_alias	= trim($this->name_alias);
830
+		$this->id = $id;
831
+		$this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
832
+		$this->name = $this->name ?trim($this->name) : trim($this->nom);
833
+		$this->nom = $this->name; // For backward compatibility
834
+		$this->name_alias = trim($this->name_alias);
835 835
 		$this->ref_ext		= trim($this->ref_ext);
836
-		$this->address		= $this->address?trim($this->address):trim($this->address);
837
-		$this->zip			= $this->zip?trim($this->zip):trim($this->zip);
838
-		$this->town			= $this->town?trim($this->town):trim($this->town);
839
-		$this->state_id		= trim($this->state_id);
840
-		$this->country_id	= ($this->country_id > 0)?$this->country_id:0;
836
+		$this->address		= $this->address ?trim($this->address) : trim($this->address);
837
+		$this->zip = $this->zip ?trim($this->zip) : trim($this->zip);
838
+		$this->town			= $this->town ?trim($this->town) : trim($this->town);
839
+		$this->state_id = trim($this->state_id);
840
+		$this->country_id = ($this->country_id > 0) ? $this->country_id : 0;
841 841
 		$this->phone		= trim($this->phone);
842
-		$this->phone		= preg_replace("/\s/","",$this->phone);
843
-		$this->phone		= preg_replace("/\./","",$this->phone);
842
+		$this->phone		= preg_replace("/\s/", "", $this->phone);
843
+		$this->phone		= preg_replace("/\./", "", $this->phone);
844 844
 		$this->fax			= trim($this->fax);
845
-		$this->fax			= preg_replace("/\s/","",$this->fax);
846
-		$this->fax			= preg_replace("/\./","",$this->fax);
845
+		$this->fax			= preg_replace("/\s/", "", $this->fax);
846
+		$this->fax			= preg_replace("/\./", "", $this->fax);
847 847
 		$this->email		= trim($this->email);
848 848
 		$this->skype		= trim($this->skype);
849
-		$this->twitter		= trim($this->twitter);
850
-		$this->facebook		= trim($this->facebook);
851
-		$this->url			= $this->url?clean_url($this->url,0):'';
849
+		$this->twitter = trim($this->twitter);
850
+		$this->facebook = trim($this->facebook);
851
+		$this->url = $this->url ?clean_url($this->url, 0) : '';
852 852
 		$this->note_private = trim($this->note_private);
853 853
 		$this->note_public  = trim($this->note_public);
854 854
 		$this->idprof1		= trim($this->idprof1);
855 855
 		$this->idprof2		= trim($this->idprof2);
856 856
 		$this->idprof3		= trim($this->idprof3);
857 857
 		$this->idprof4		= trim($this->idprof4);
858
-		$this->idprof5		= (! empty($this->idprof5)?trim($this->idprof5):'');
859
-		$this->idprof6		= (! empty($this->idprof6)?trim($this->idprof6):'');
860
-		$this->prefix_comm	= trim($this->prefix_comm);
858
+		$this->idprof5		= (!empty($this->idprof5) ?trim($this->idprof5) : '');
859
+		$this->idprof6		= (!empty($this->idprof6) ?trim($this->idprof6) : '');
860
+		$this->prefix_comm = trim($this->prefix_comm);
861 861
 		$this->outstanding_limit = price2num($this->outstanding_limit);
862 862
 		$this->order_min_amount = price2num($this->order_min_amount);
863 863
 		$this->supplier_order_min_amount = price2num($this->supplier_order_min_amount);
864 864
 
865 865
 		$this->tva_assuj	= trim($this->tva_assuj);
866
-		$this->tva_intra	= dol_sanitizeFileName($this->tva_intra,'');
866
+		$this->tva_intra	= dol_sanitizeFileName($this->tva_intra, '');
867 867
 		if (empty($this->status)) $this->status = 0;
868 868
 
869 869
 		if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
@@ -874,64 +874,64 @@  discard block
 block discarded – undo
874 874
 		}
875 875
 
876 876
 		// Local taxes
877
-		$this->localtax1_assuj=trim($this->localtax1_assuj);
878
-		$this->localtax2_assuj=trim($this->localtax2_assuj);
877
+		$this->localtax1_assuj = trim($this->localtax1_assuj);
878
+		$this->localtax2_assuj = trim($this->localtax2_assuj);
879 879
 
880
-		$this->localtax1_value=trim($this->localtax1_value);
881
-		$this->localtax2_value=trim($this->localtax2_value);
880
+		$this->localtax1_value = trim($this->localtax1_value);
881
+		$this->localtax2_value = trim($this->localtax2_value);
882 882
 
883
-		if ($this->capital != '') $this->capital=price2num(trim($this->capital));
884
-		if (! is_numeric($this->capital)) $this->capital = '';     // '' = undef
883
+		if ($this->capital != '') $this->capital = price2num(trim($this->capital));
884
+		if (!is_numeric($this->capital)) $this->capital = ''; // '' = undef
885 885
 
886
-		$this->effectif_id=trim($this->effectif_id);
887
-		$this->forme_juridique_code=trim($this->forme_juridique_code);
886
+		$this->effectif_id = trim($this->effectif_id);
887
+		$this->forme_juridique_code = trim($this->forme_juridique_code);
888 888
 
889 889
 		//Gencod
890
-		$this->barcode=trim($this->barcode);
890
+		$this->barcode = trim($this->barcode);
891 891
 
892 892
 		// For automatic creation
893
-		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this,0);
894
-		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1);
893
+		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this, 0);
894
+		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this, 1);
895 895
 
896
-		$this->code_compta=trim($this->code_compta);
897
-		$this->code_compta_fournisseur=trim($this->code_compta_fournisseur);
896
+		$this->code_compta = trim($this->code_compta);
897
+		$this->code_compta_fournisseur = trim($this->code_compta_fournisseur);
898 898
 
899 899
 		// Check parameters. More tests are done later in the ->verify()
900
-		if (! is_numeric($this->client) && ! is_numeric($this->fournisseur))
900
+		if (!is_numeric($this->client) && !is_numeric($this->fournisseur))
901 901
 		{
902 902
 			$langs->load("errors");
903 903
 			$this->error = $langs->trans("BadValueForParameterClientOrSupplier");
904 904
 			return -1;
905 905
 		}
906 906
 
907
-		$customer=false;
908
-		if (! empty($allowmodcodeclient) && ! empty($this->client))
907
+		$customer = false;
908
+		if (!empty($allowmodcodeclient) && !empty($this->client))
909 909
 		{
910 910
 			// Attention get_codecompta peut modifier le code suivant le module utilise
911 911
 			if (empty($this->code_compta))
912 912
 			{
913
-				$ret=$this->get_codecompta('customer');
913
+				$ret = $this->get_codecompta('customer');
914 914
 				if ($ret < 0) return -1;
915 915
 			}
916 916
 
917
-			$customer=true;
917
+			$customer = true;
918 918
 		}
919 919
 
920
-		$supplier=false;
921
-		if (! empty($allowmodcodefournisseur) && ! empty($this->fournisseur))
920
+		$supplier = false;
921
+		if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur))
922 922
 		{
923 923
 			// Attention get_codecompta peut modifier le code suivant le module utilise
924 924
 			if (empty($this->code_compta_fournisseur))
925 925
 			{
926
-				$ret=$this->get_codecompta('supplier');
926
+				$ret = $this->get_codecompta('supplier');
927 927
 				if ($ret < 0) return -1;
928 928
 			}
929 929
 
930
-			$supplier=true;
930
+			$supplier = true;
931 931
 		}
932 932
 
933 933
 		//Web services
934
-		$this->webservices_url = $this->webservices_url?clean_url($this->webservices_url,0):'';
934
+		$this->webservices_url = $this->webservices_url ?clean_url($this->webservices_url, 0) : '';
935 935
 		$this->webservices_key = trim($this->webservices_key);
936 936
 
937 937
 		//Incoterms
@@ -955,11 +955,11 @@  discard block
 block discarded – undo
955 955
 			{
956 956
 				if (in_array('ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client)
957 957
 				{
958
-					if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]);	// Remove error message
958
+					if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]); // Remove error message
959 959
 				}
960 960
 				if (in_array('ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur)
961 961
 				{
962
-					if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]);	// Remove error message
962
+					if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]); // Remove error message
963 963
 				}
964 964
 				if (empty($this->errors))	// If there is no more error, we can make like if there is no error at all
965 965
 				{
@@ -973,118 +973,118 @@  discard block
 block discarded – undo
973 973
 			dol_syslog(get_class($this)."::update verify ok or not done");
974 974
 
975 975
 			$sql  = "UPDATE ".MAIN_DB_PREFIX."societe SET ";
976
-			$sql .= "entity = " . $this->db->escape($this->entity);
977
-			$sql .= ",nom = '" . $this->db->escape($this->name) ."'"; // Required
978
-			$sql .= ",name_alias = '" . $this->db->escape($this->name_alias) ."'";
979
-			$sql .= ",ref_ext = " .(! empty($this->ref_ext)?"'".$this->db->escape($this->ref_ext) ."'":"null");
980
-			$sql .= ",address = '" . $this->db->escape($this->address) ."'";
981
-
982
-			$sql .= ",zip = ".(! empty($this->zip)?"'".$this->db->escape($this->zip)."'":"null");
983
-			$sql .= ",town = ".(! empty($this->town)?"'".$this->db->escape($this->town)."'":"null");
984
-
985
-			$sql .= ",fk_departement = '" . (! empty($this->state_id)?$this->state_id:'0') ."'";
986
-			$sql .= ",fk_pays = '" . (! empty($this->country_id)?$this->country_id:'0') ."'";
987
-
988
-			$sql .= ",phone = ".(! empty($this->phone)?"'".$this->db->escape($this->phone)."'":"null");
989
-			$sql .= ",fax = ".(! empty($this->fax)?"'".$this->db->escape($this->fax)."'":"null");
990
-			$sql .= ",email = ".(! empty($this->email)?"'".$this->db->escape($this->email)."'":"null");
991
-			$sql .= ",skype = ".(! empty($this->skype)?"'".$this->db->escape($this->skype)."'":"null");
992
-			$sql .= ",twitter = ".(! empty($this->twitter)?"'".$this->db->escape($this->twitter)."'":"null");
993
-			$sql .= ",facebook = ".(! empty($this->facebook)?"'".$this->db->escape($this->facebook)."'":"null");
994
-			$sql .= ",url = ".(! empty($this->url)?"'".$this->db->escape($this->url)."'":"null");
995
-
996
-			$sql .= ",parent = " . ($this->parent > 0 ? $this->parent : "null");
997
-
998
-			$sql .= ",note_private = ".(! empty($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null");
999
-			$sql .= ",note_public = ".(! empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null");
1000
-
1001
-			$sql .= ",siren   = '". $this->db->escape($this->idprof1) ."'";
1002
-			$sql .= ",siret   = '". $this->db->escape($this->idprof2) ."'";
1003
-			$sql .= ",ape     = '". $this->db->escape($this->idprof3) ."'";
1004
-			$sql .= ",idprof4 = '". $this->db->escape($this->idprof4) ."'";
1005
-			$sql .= ",idprof5 = '". $this->db->escape($this->idprof5) ."'";
1006
-			$sql .= ",idprof6 = '". $this->db->escape($this->idprof6) ."'";
1007
-
1008
-			$sql .= ",tva_assuj = ".($this->tva_assuj!=''?"'".$this->db->escape($this->tva_assuj)."'":"null");
1009
-			$sql .= ",tva_intra = '" . $this->db->escape($this->tva_intra) ."'";
1010
-			$sql .= ",status = " .$this->status;
976
+			$sql .= "entity = ".$this->db->escape($this->entity);
977
+			$sql .= ",nom = '".$this->db->escape($this->name)."'"; // Required
978
+			$sql .= ",name_alias = '".$this->db->escape($this->name_alias)."'";
979
+			$sql .= ",ref_ext = ".(!empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null");
980
+			$sql .= ",address = '".$this->db->escape($this->address)."'";
981
+
982
+			$sql .= ",zip = ".(!empty($this->zip) ? "'".$this->db->escape($this->zip)."'" : "null");
983
+			$sql .= ",town = ".(!empty($this->town) ? "'".$this->db->escape($this->town)."'" : "null");
984
+
985
+			$sql .= ",fk_departement = '".(!empty($this->state_id) ? $this->state_id : '0')."'";
986
+			$sql .= ",fk_pays = '".(!empty($this->country_id) ? $this->country_id : '0')."'";
987
+
988
+			$sql .= ",phone = ".(!empty($this->phone) ? "'".$this->db->escape($this->phone)."'" : "null");
989
+			$sql .= ",fax = ".(!empty($this->fax) ? "'".$this->db->escape($this->fax)."'" : "null");
990
+			$sql .= ",email = ".(!empty($this->email) ? "'".$this->db->escape($this->email)."'" : "null");
991
+			$sql .= ",skype = ".(!empty($this->skype) ? "'".$this->db->escape($this->skype)."'" : "null");
992
+			$sql .= ",twitter = ".(!empty($this->twitter) ? "'".$this->db->escape($this->twitter)."'" : "null");
993
+			$sql .= ",facebook = ".(!empty($this->facebook) ? "'".$this->db->escape($this->facebook)."'" : "null");
994
+			$sql .= ",url = ".(!empty($this->url) ? "'".$this->db->escape($this->url)."'" : "null");
995
+
996
+			$sql .= ",parent = ".($this->parent > 0 ? $this->parent : "null");
997
+
998
+			$sql .= ",note_private = ".(!empty($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null");
999
+			$sql .= ",note_public = ".(!empty($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null");
1000
+
1001
+			$sql .= ",siren   = '".$this->db->escape($this->idprof1)."'";
1002
+			$sql .= ",siret   = '".$this->db->escape($this->idprof2)."'";
1003
+			$sql .= ",ape     = '".$this->db->escape($this->idprof3)."'";
1004
+			$sql .= ",idprof4 = '".$this->db->escape($this->idprof4)."'";
1005
+			$sql .= ",idprof5 = '".$this->db->escape($this->idprof5)."'";
1006
+			$sql .= ",idprof6 = '".$this->db->escape($this->idprof6)."'";
1007
+
1008
+			$sql .= ",tva_assuj = ".($this->tva_assuj != '' ? "'".$this->db->escape($this->tva_assuj)."'" : "null");
1009
+			$sql .= ",tva_intra = '".$this->db->escape($this->tva_intra)."'";
1010
+			$sql .= ",status = ".$this->status;
1011 1011
 
1012 1012
 			// Local taxes
1013
-			$sql .= ",localtax1_assuj = ".($this->localtax1_assuj!=''?"'".$this->db->escape($this->localtax1_assuj)."'":"null");
1014
-			$sql .= ",localtax2_assuj = ".($this->localtax2_assuj!=''?"'".$this->db->escape($this->localtax2_assuj)."'":"null");
1015
-			if($this->localtax1_assuj==1)
1013
+			$sql .= ",localtax1_assuj = ".($this->localtax1_assuj != '' ? "'".$this->db->escape($this->localtax1_assuj)."'" : "null");
1014
+			$sql .= ",localtax2_assuj = ".($this->localtax2_assuj != '' ? "'".$this->db->escape($this->localtax2_assuj)."'" : "null");
1015
+			if ($this->localtax1_assuj == 1)
1016 1016
 			{
1017
-				if($this->localtax1_value!='')
1017
+				if ($this->localtax1_value != '')
1018 1018
 				{
1019
-					$sql .=",localtax1_value =".$this->localtax1_value;
1019
+					$sql .= ",localtax1_value =".$this->localtax1_value;
1020 1020
 				}
1021
-				else $sql .=",localtax1_value =0.000";
1021
+				else $sql .= ",localtax1_value =0.000";
1022 1022
 			}
1023
-			else $sql .=",localtax1_value =0.000";
1023
+			else $sql .= ",localtax1_value =0.000";
1024 1024
 
1025
-			if($this->localtax2_assuj==1)
1025
+			if ($this->localtax2_assuj == 1)
1026 1026
 			{
1027
-				if($this->localtax2_value!='')
1027
+				if ($this->localtax2_value != '')
1028 1028
 				{
1029
-					$sql .=",localtax2_value =".$this->localtax2_value;
1029
+					$sql .= ",localtax2_value =".$this->localtax2_value;
1030 1030
 				}
1031
-				else $sql .=",localtax2_value =0.000";
1031
+				else $sql .= ",localtax2_value =0.000";
1032 1032
 			}
1033
-			else $sql .=",localtax2_value =0.000";
1033
+			else $sql .= ",localtax2_value =0.000";
1034 1034
 
1035 1035
 			$sql .= ",capital = ".($this->capital == '' ? "null" : $this->capital);
1036 1036
 
1037
-			$sql .= ",prefix_comm = ".(! empty($this->prefix_comm)?"'".$this->db->escape($this->prefix_comm)."'":"null");
1037
+			$sql .= ",prefix_comm = ".(!empty($this->prefix_comm) ? "'".$this->db->escape($this->prefix_comm)."'" : "null");
1038 1038
 
1039
-			$sql .= ",fk_effectif = ".(! empty($this->effectif_id)?"'".$this->db->escape($this->effectif_id)."'":"null");
1039
+			$sql .= ",fk_effectif = ".(!empty($this->effectif_id) ? "'".$this->db->escape($this->effectif_id)."'" : "null");
1040 1040
 			if (isset($this->stcomm_id))
1041 1041
 			{
1042
-				$sql .= ",fk_stcomm=".(!empty($this->stcomm_id)  ? $this->stcomm_id : "0");
1042
+				$sql .= ",fk_stcomm=".(!empty($this->stcomm_id) ? $this->stcomm_id : "0");
1043 1043
 			}
1044
-			$sql .= ",fk_typent = ".(! empty($this->typent_id)?"'".$this->db->escape($this->typent_id)."'":"0");
1045
-
1046
-			$sql .= ",fk_forme_juridique = ".(! empty($this->forme_juridique_code)?"'".$this->db->escape($this->forme_juridique_code)."'":"null");
1047
-
1048
-			$sql .= ",mode_reglement = ".(! empty($this->mode_reglement_id)?"'".$this->db->escape($this->mode_reglement_id)."'":"null");
1049
-			$sql .= ",cond_reglement = ".(! empty($this->cond_reglement_id)?"'".$this->db->escape($this->cond_reglement_id)."'":"null");
1050
-			$sql .= ",mode_reglement_supplier = ".(! empty($this->mode_reglement_supplier_id)?"'".$this->db->escape($this->mode_reglement_supplier_id)."'":"null");
1051
-			$sql .= ",cond_reglement_supplier = ".(! empty($this->cond_reglement_supplier_id)?"'".$this->db->escape($this->cond_reglement_supplier_id)."'":"null");
1052
-			$sql .= ",fk_shipping_method = ".(! empty($this->shipping_method_id)?"'".$this->db->escape($this->shipping_method_id)."'":"null");
1053
-
1054
-			$sql .= ",client = " . (! empty($this->client)?$this->client:0);
1055
-			$sql .= ",fournisseur = " . (! empty($this->fournisseur)?$this->fournisseur:0);
1056
-			$sql .= ",barcode = ".(! empty($this->barcode)?"'".$this->db->escape($this->barcode)."'":"null");
1057
-			$sql .= ",default_lang = ".(! empty($this->default_lang)?"'".$this->db->escape($this->default_lang)."'":"null");
1058
-			$sql .= ",logo = ".(! empty($this->logo)?"'".$this->db->escape($this->logo)."'":"null");
1059
-			$sql .= ",outstanding_limit= ".($this->outstanding_limit!=''?$this->outstanding_limit:'null');
1060
-			$sql .= ",order_min_amount= ".($this->order_min_amount!=''?$this->order_min_amount:'null');
1061
-			$sql .= ",supplier_order_min_amount= ".($this->supplier_order_min_amount!=''?$this->supplier_order_min_amount:'null');
1044
+			$sql .= ",fk_typent = ".(!empty($this->typent_id) ? "'".$this->db->escape($this->typent_id)."'" : "0");
1045
+
1046
+			$sql .= ",fk_forme_juridique = ".(!empty($this->forme_juridique_code) ? "'".$this->db->escape($this->forme_juridique_code)."'" : "null");
1047
+
1048
+			$sql .= ",mode_reglement = ".(!empty($this->mode_reglement_id) ? "'".$this->db->escape($this->mode_reglement_id)."'" : "null");
1049
+			$sql .= ",cond_reglement = ".(!empty($this->cond_reglement_id) ? "'".$this->db->escape($this->cond_reglement_id)."'" : "null");
1050
+			$sql .= ",mode_reglement_supplier = ".(!empty($this->mode_reglement_supplier_id) ? "'".$this->db->escape($this->mode_reglement_supplier_id)."'" : "null");
1051
+			$sql .= ",cond_reglement_supplier = ".(!empty($this->cond_reglement_supplier_id) ? "'".$this->db->escape($this->cond_reglement_supplier_id)."'" : "null");
1052
+			$sql .= ",fk_shipping_method = ".(!empty($this->shipping_method_id) ? "'".$this->db->escape($this->shipping_method_id)."'" : "null");
1053
+
1054
+			$sql .= ",client = ".(!empty($this->client) ? $this->client : 0);
1055
+			$sql .= ",fournisseur = ".(!empty($this->fournisseur) ? $this->fournisseur : 0);
1056
+			$sql .= ",barcode = ".(!empty($this->barcode) ? "'".$this->db->escape($this->barcode)."'" : "null");
1057
+			$sql .= ",default_lang = ".(!empty($this->default_lang) ? "'".$this->db->escape($this->default_lang)."'" : "null");
1058
+			$sql .= ",logo = ".(!empty($this->logo) ? "'".$this->db->escape($this->logo)."'" : "null");
1059
+			$sql .= ",outstanding_limit= ".($this->outstanding_limit != '' ? $this->outstanding_limit : 'null');
1060
+			$sql .= ",order_min_amount= ".($this->order_min_amount != '' ? $this->order_min_amount : 'null');
1061
+			$sql .= ",supplier_order_min_amount= ".($this->supplier_order_min_amount != '' ? $this->supplier_order_min_amount : 'null');
1062 1062
 			$sql .= ",fk_prospectlevel='".$this->db->escape($this->fk_prospectlevel)."'";
1063 1063
 
1064
-			$sql .= ",webservices_url = ".(! empty($this->webservices_url)?"'".$this->db->escape($this->webservices_url)."'":"null");
1065
-			$sql .= ",webservices_key = ".(! empty($this->webservices_key)?"'".$this->db->escape($this->webservices_key)."'":"null");
1064
+			$sql .= ",webservices_url = ".(!empty($this->webservices_url) ? "'".$this->db->escape($this->webservices_url)."'" : "null");
1065
+			$sql .= ",webservices_key = ".(!empty($this->webservices_key) ? "'".$this->db->escape($this->webservices_key)."'" : "null");
1066 1066
 
1067 1067
 			//Incoterms
1068
-			$sql.= ", fk_incoterms = ".$this->fk_incoterms;
1069
-			$sql.= ", location_incoterms = ".(! empty($this->location_incoterms)?"'".$this->db->escape($this->location_incoterms)."'":"null");
1068
+			$sql .= ", fk_incoterms = ".$this->fk_incoterms;
1069
+			$sql .= ", location_incoterms = ".(!empty($this->location_incoterms) ? "'".$this->db->escape($this->location_incoterms)."'" : "null");
1070 1070
 
1071 1071
 			if ($customer)
1072 1072
 			{
1073
-				$sql .= ", code_client = ".(! empty($this->code_client)?"'".$this->db->escape($this->code_client)."'":"null");
1074
-				$sql .= ", code_compta = ".(! empty($this->code_compta)?"'".$this->db->escape($this->code_compta)."'":"null");
1073
+				$sql .= ", code_client = ".(!empty($this->code_client) ? "'".$this->db->escape($this->code_client)."'" : "null");
1074
+				$sql .= ", code_compta = ".(!empty($this->code_compta) ? "'".$this->db->escape($this->code_compta)."'" : "null");
1075 1075
 			}
1076 1076
 
1077 1077
 			if ($supplier)
1078 1078
 			{
1079
-				$sql .= ", code_fournisseur = ".(! empty($this->code_fournisseur)?"'".$this->db->escape($this->code_fournisseur)."'":"null");
1080
-				$sql .= ", code_compta_fournisseur = ".(! empty($this->code_compta_fournisseur)?"'".$this->db->escape($this->code_compta_fournisseur)."'":"null");
1079
+				$sql .= ", code_fournisseur = ".(!empty($this->code_fournisseur) ? "'".$this->db->escape($this->code_fournisseur)."'" : "null");
1080
+				$sql .= ", code_compta_fournisseur = ".(!empty($this->code_compta_fournisseur) ? "'".$this->db->escape($this->code_compta_fournisseur)."'" : "null");
1081 1081
 			}
1082
-			$sql .= ", fk_user_modif = ".($user->id > 0 ? $user->id:"null");
1082
+			$sql .= ", fk_user_modif = ".($user->id > 0 ? $user->id : "null");
1083 1083
 			$sql .= ", fk_multicurrency = ".(int) $this->fk_multicurrency;
1084 1084
 			$sql .= ", multicurrency_code = '".$this->db->escape($this->multicurrency_code)."'";
1085
-			$sql .= " WHERE rowid = " . (int) $id;
1085
+			$sql .= " WHERE rowid = ".(int) $id;
1086 1086
 
1087
-			$resql=$this->db->query($sql);
1087
+			$resql = $this->db->query($sql);
1088 1088
 			if ($resql)
1089 1089
 			{
1090 1090
 				if (is_object($this->oldcopy))	// If we have information on old values
@@ -1102,7 +1102,7 @@  discard block
 block discarded – undo
1102 1102
 				}
1103 1103
 				else
1104 1104
 				{
1105
-					unset($this->country_code);	// We clean this, in the doubt, because it may have been changed after an update of country_id
1105
+					unset($this->country_code); // We clean this, in the doubt, because it may have been changed after an update of country_id
1106 1106
 					unset($this->country);
1107 1107
 					unset($this->state_code);
1108 1108
 					unset($this->state);
@@ -1110,67 +1110,67 @@  discard block
 block discarded – undo
1110 1110
 
1111 1111
 				$nbrowsaffected = $this->db->affected_rows($resql);
1112 1112
 
1113
-				if (! $error && $nbrowsaffected)
1113
+				if (!$error && $nbrowsaffected)
1114 1114
 				{
1115 1115
 					// Update information on linked member if it is an update
1116
-					if (! $nosyncmember && ! empty($conf->adherent->enabled))
1116
+					if (!$nosyncmember && !empty($conf->adherent->enabled))
1117 1117
 					{
1118 1118
 						require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
1119 1119
 
1120 1120
 						dol_syslog(get_class($this)."::update update linked member");
1121 1121
 
1122
-						$lmember=new Adherent($this->db);
1123
-						$result=$lmember->fetch(0, 0, $this->id);
1122
+						$lmember = new Adherent($this->db);
1123
+						$result = $lmember->fetch(0, 0, $this->id);
1124 1124
 
1125 1125
 						if ($result > 0)
1126 1126
 						{
1127
-							$lmember->societe=$this->name;
1127
+							$lmember->societe = $this->name;
1128 1128
 							//$lmember->firstname=$this->firstname?$this->firstname:$lmember->firstname;	// We keep firstname and lastname of member unchanged
1129 1129
 							//$lmember->lastname=$this->lastname?$this->lastname:$lmember->lastname;		// We keep firstname and lastname of member unchanged
1130
-							$lmember->address=$this->address;
1131
-							$lmember->email=$this->email;
1132
-							$lmember->skype=$this->skype;
1133
-							$lmember->twitter=$this->twitter;
1134
-							$lmember->facebook=$this->facebook;
1135
-							$lmember->phone=$this->phone;
1136
-
1137
-							$result=$lmember->update($user,0,1,1,1);	// Use nosync to 1 to avoid cyclic updates
1130
+							$lmember->address = $this->address;
1131
+							$lmember->email = $this->email;
1132
+							$lmember->skype = $this->skype;
1133
+							$lmember->twitter = $this->twitter;
1134
+							$lmember->facebook = $this->facebook;
1135
+							$lmember->phone = $this->phone;
1136
+
1137
+							$result = $lmember->update($user, 0, 1, 1, 1); // Use nosync to 1 to avoid cyclic updates
1138 1138
 							if ($result < 0)
1139 1139
 							{
1140
-								$this->error=$lmember->error;
1141
-								dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
1140
+								$this->error = $lmember->error;
1141
+								dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
1142 1142
 								$error++;
1143 1143
 							}
1144 1144
 						}
1145 1145
 						elseif ($result < 0)
1146 1146
 						{
1147
-							$this->error=$lmember->error;
1147
+							$this->error = $lmember->error;
1148 1148
 							$error++;
1149 1149
 						}
1150 1150
 					}
1151 1151
 				}
1152 1152
 
1153
-				$action='update';
1153
+				$action = 'update';
1154 1154
 
1155 1155
 				// Actions on extra fields
1156
-				if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1156
+				if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1157 1157
 				{
1158
-					$result=$this->insertExtraFields();
1158
+					$result = $this->insertExtraFields();
1159 1159
 					if ($result < 0)
1160 1160
 					{
1161 1161
 						$error++;
1162 1162
 					}
1163 1163
 				}
1164 1164
 
1165
-				if (! $error && $call_trigger)
1165
+				if (!$error && $call_trigger)
1166 1166
 				{
1167 1167
 					// Call trigger
1168
-					$result=$this->call_trigger('COMPANY_MODIFY',$user);
1168
+					$result = $this->call_trigger('COMPANY_MODIFY', $user);
1169 1169
 					if ($result < 0) $error++;
1170 1170
 					// End call triggers
1171 1171
 				}
1172 1172
 
1173
-				if (! $error)
1173
+				if (!$error)
1174 1174
 				{
1175 1175
 					dol_syslog(get_class($this)."::Update success");
1176 1176
 					$this->db->commit();
@@ -1202,7 +1202,7 @@  discard block
 block discarded – undo
1202 1202
 		else
1203 1203
 	   {
1204 1204
 			$this->db->rollback();
1205
-			dol_syslog(get_class($this)."::Update fails verify ".join(',',$this->errors), LOG_WARNING);
1205
+			dol_syslog(get_class($this)."::Update fails verify ".join(',', $this->errors), LOG_WARNING);
1206 1206
 			return -3;
1207 1207
 		}
1208 1208
 	}
@@ -1224,7 +1224,7 @@  discard block
 block discarded – undo
1224 1224
 	 *    @param    string	$ref_alias 		Name_alias of third party (Warning, this can return several records)
1225 1225
 	 *    @return   int						>0 if OK, <0 if KO or if two records found for same ref or idprof, 0 if not found.
1226 1226
 	 */
1227
-	function fetch($rowid, $ref='', $ref_ext='', $ref_int='', $idprof1='',$idprof2='',$idprof3='',$idprof4='',$idprof5='',$idprof6='', $email='', $ref_alias='')
1227
+	function fetch($rowid, $ref = '', $ref_ext = '', $ref_int = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '')
1228 1228
 	{
1229 1229
 		global $langs;
1230 1230
 		global $conf;
@@ -1279,13 +1279,13 @@  discard block
 block discarded – undo
1279 1279
 		if ($idprof6)   $sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'";
1280 1280
 		if ($email)     $sql .= " AND s.email = '".$this->db->escape($email)."'";
1281 1281
 
1282
-		$resql=$this->db->query($sql);
1282
+		$resql = $this->db->query($sql);
1283 1283
 		if ($resql)
1284 1284
 		{
1285
-			$num=$this->db->num_rows($resql);
1285
+			$num = $this->db->num_rows($resql);
1286 1286
 			if ($num > 1)
1287 1287
 			{
1288
-				$this->error='Fetch found several records. Rename one of tirdparties to avoid duplicate.';
1288
+				$this->error = 'Fetch found several records. Rename one of tirdparties to avoid duplicate.';
1289 1289
 				dol_syslog($this->error, LOG_ERR);
1290 1290
 				$result = -2;
1291 1291
 			}
@@ -1295,11 +1295,11 @@  discard block
 block discarded – undo
1295 1295
 
1296 1296
 				$this->id           = $obj->rowid;
1297 1297
 				$this->entity       = $obj->entity;
1298
-				$this->canvas		= $obj->canvas;
1298
+				$this->canvas = $obj->canvas;
1299 1299
 
1300 1300
 				$this->ref          = $obj->rowid;
1301
-				$this->name 		= $obj->name;
1302
-				$this->nom          = $obj->name;		// deprecated
1301
+				$this->name = $obj->name;
1302
+				$this->nom          = $obj->name; // deprecated
1303 1303
 				$this->name_alias = $obj->name_alias;
1304 1304
 				$this->ref_ext      = $obj->ref_ext;
1305 1305
 				$this->ref_int      = $obj->ref_int;
@@ -1309,22 +1309,22 @@  discard block
 block discarded – undo
1309 1309
 				$this->user_creation     = $obj->fk_user_creat;
1310 1310
 				$this->user_modification = $obj->fk_user_modif;
1311 1311
 
1312
-				$this->address 		= $obj->address;
1312
+				$this->address = $obj->address;
1313 1313
 				$this->zip 			= $obj->zip;
1314 1314
 				$this->town 		= $obj->town;
1315 1315
 
1316 1316
 				$this->country_id   = $obj->country_id;
1317
-				$this->country_code = $obj->country_id?$obj->country_code:'';
1318
-				$this->country 		= $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->transnoentities('Country'.$obj->country_code):$obj->country):'';
1317
+				$this->country_code = $obj->country_id ? $obj->country_code : '';
1318
+				$this->country = $obj->country_id ? ($langs->trans('Country'.$obj->country_code) != 'Country'.$obj->country_code ? $langs->transnoentities('Country'.$obj->country_code) : $obj->country) : '';
1319 1319
 
1320 1320
 				$this->state_id     = $obj->fk_departement;
1321 1321
 				$this->state_code   = $obj->state_code;
1322
-				$this->state        = ($obj->state!='-'?$obj->state:'');
1322
+				$this->state        = ($obj->state != '-' ? $obj->state : '');
1323 1323
 
1324
-				$transcode=$langs->trans('StatusProspect'.$obj->fk_stcomm);
1325
-				$libelle=($transcode!='StatusProspect'.$obj->fk_stcomm?$transcode:$obj->stcomm);
1326
-				$this->stcomm_id = $obj->fk_stcomm;     // id statut commercial
1327
-				$this->statut_commercial = $libelle;    // libelle statut commercial
1324
+				$transcode = $langs->trans('StatusProspect'.$obj->fk_stcomm);
1325
+				$libelle = ($transcode != 'StatusProspect'.$obj->fk_stcomm ? $transcode : $obj->stcomm);
1326
+				$this->stcomm_id = $obj->fk_stcomm; // id statut commercial
1327
+				$this->statut_commercial = $libelle; // libelle statut commercial
1328 1328
 
1329 1329
 				$this->email = $obj->email;
1330 1330
 				$this->skype = $obj->skype;
@@ -1334,7 +1334,7 @@  discard block
 block discarded – undo
1334 1334
 				$this->phone = $obj->phone;
1335 1335
 				$this->fax = $obj->fax;
1336 1336
 
1337
-				$this->parent    = $obj->parent;
1337
+				$this->parent = $obj->parent;
1338 1338
 
1339 1339
 				$this->idprof1		= $obj->idprof1;
1340 1340
 				$this->idprof2		= $obj->idprof2;
@@ -1343,7 +1343,7 @@  discard block
 block discarded – undo
1343 1343
 				$this->idprof5		= $obj->idprof5;
1344 1344
 				$this->idprof6		= $obj->idprof6;
1345 1345
 
1346
-				$this->capital   = $obj->capital;
1346
+				$this->capital = $obj->capital;
1347 1347
 
1348 1348
 				$this->code_client = $obj->code_client;
1349 1349
 				$this->code_fournisseur = $obj->code_fournisseur;
@@ -1368,23 +1368,23 @@  discard block
 block discarded – undo
1368 1368
 				$this->typent_code    = $obj->typent_code;
1369 1369
 
1370 1370
 				$this->effectif_id    = $obj->effectif_id;
1371
-				$this->effectif       = $obj->effectif_id?$obj->effectif:'';
1371
+				$this->effectif       = $obj->effectif_id ? $obj->effectif : '';
1372 1372
 
1373
-				$this->forme_juridique_code= $obj->forme_juridique_code;
1374
-				$this->forme_juridique     = $obj->forme_juridique_code?$obj->forme_juridique:'';
1373
+				$this->forme_juridique_code = $obj->forme_juridique_code;
1374
+				$this->forme_juridique     = $obj->forme_juridique_code ? $obj->forme_juridique : '';
1375 1375
 
1376 1376
 				$this->fk_prospectlevel = $obj->fk_prospectlevel;
1377 1377
 
1378 1378
 				$this->prefix_comm = $obj->prefix_comm;
1379 1379
 
1380
-				$this->remise_percent		= $obj->remise_client;
1381
-				$this->remise_supplier_percent		= $obj->remise_supplier;
1380
+				$this->remise_percent = $obj->remise_client;
1381
+				$this->remise_supplier_percent = $obj->remise_supplier;
1382 1382
 				$this->mode_reglement_id 	= $obj->mode_reglement;
1383 1383
 				$this->cond_reglement_id 	= $obj->cond_reglement;
1384 1384
 				$this->mode_reglement_supplier_id 	= $obj->mode_reglement_supplier;
1385 1385
 				$this->cond_reglement_supplier_id 	= $obj->cond_reglement_supplier;
1386
-				$this->shipping_method_id   = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null;
1387
-				$this->fk_account			= $obj->fk_account;
1386
+				$this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method : null;
1387
+				$this->fk_account = $obj->fk_account;
1388 1388
 
1389 1389
 				$this->client      = $obj->client;
1390 1390
 				$this->fournisseur = $obj->fournisseur;
@@ -1401,7 +1401,7 @@  discard block
 block discarded – undo
1401 1401
 
1402 1402
 				$this->outstanding_limit		= $obj->outstanding_limit;
1403 1403
 				$this->order_min_amount			= $obj->order_min_amount;
1404
-				$this->supplier_order_min_amount	= $obj->supplier_order_min_amount;
1404
+				$this->supplier_order_min_amount = $obj->supplier_order_min_amount;
1405 1405
 
1406 1406
 				// multiprix
1407 1407
 				$this->price_level = $obj->price_level;
@@ -1431,12 +1431,12 @@  discard block
 block discarded – undo
1431 1431
 		}
1432 1432
 		else
1433 1433
 		{
1434
-			$this->error=$this->db->lasterror();
1434
+			$this->error = $this->db->lasterror();
1435 1435
 			$result = -3;
1436 1436
 		}
1437 1437
 
1438 1438
 		// Use first price level if level not defined for third party
1439
-		if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->price_level)) $this->price_level=1;
1439
+		if (!empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->price_level)) $this->price_level = 1;
1440 1440
 
1441 1441
 		return $result;
1442 1442
 	}
@@ -1449,15 +1449,15 @@  discard block
 block discarded – undo
1449 1449
 	 *    @param    int		$call_trigger   0=No, 1=yes
1450 1450
 	 *    @return	int						<0 if KO, 0 if nothing done, >0 if OK
1451 1451
 	 */
1452
-	function delete($id, User $fuser=null, $call_trigger=1)
1452
+	function delete($id, User $fuser = null, $call_trigger = 1)
1453 1453
 	{
1454 1454
 		global $langs, $conf, $user;
1455 1455
 
1456
-		if (empty($fuser)) $fuser=$user;
1456
+		if (empty($fuser)) $fuser = $user;
1457 1457
 
1458 1458
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1459 1459
 
1460
-		$entity=isset($this->entity)?$this->entity:$conf->entity;
1460
+		$entity = isset($this->entity) ? $this->entity : $conf->entity;
1461 1461
 
1462 1462
 		dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1463 1463
 		$error = 0;
@@ -1469,15 +1469,15 @@  discard block
 block discarded – undo
1469 1469
 			$this->db->begin();
1470 1470
 
1471 1471
 			// User is mandatory for trigger call
1472
-			if (! $error && $call_trigger)
1472
+			if (!$error && $call_trigger)
1473 1473
 			{
1474 1474
 				// Call trigger
1475
-				$result=$this->call_trigger('COMPANY_DELETE',$fuser);
1475
+				$result = $this->call_trigger('COMPANY_DELETE', $fuser);
1476 1476
 				if ($result < 0) $error++;
1477 1477
 				// End call triggers
1478 1478
 			}
1479 1479
 
1480
-			if (! $error)
1480
+			if (!$error)
1481 1481
 			{
1482 1482
 				require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1483 1483
 				$static_cat = new Categorie($this->db);
@@ -1486,11 +1486,11 @@  discard block
 block discarded – undo
1486 1486
 				// Fill $toute_categs array with an array of (type => array of ("Categorie" instance))
1487 1487
 				if ($this->client || $this->prospect)
1488 1488
 				{
1489
-					$toute_categs['customer'] = $static_cat->containing($this->id,Categorie::TYPE_CUSTOMER);
1489
+					$toute_categs['customer'] = $static_cat->containing($this->id, Categorie::TYPE_CUSTOMER);
1490 1490
 				}
1491 1491
 				if ($this->fournisseur)
1492 1492
 				{
1493
-					$toute_categs['supplier'] = $static_cat->containing($this->id,Categorie::TYPE_SUPPLIER);
1493
+					$toute_categs['supplier'] = $static_cat->containing($this->id, Categorie::TYPE_SUPPLIER);
1494 1494
 				}
1495 1495
 
1496 1496
 				// Remove each "Categorie"
@@ -1505,11 +1505,11 @@  discard block
 block discarded – undo
1505 1505
 
1506 1506
 			foreach ($this->childtablesoncascade as $tabletodelete)
1507 1507
 			{
1508
-				if (! $error)
1508
+				if (!$error)
1509 1509
 				{
1510 1510
 					$sql = "DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete;
1511
-					$sql.= " WHERE fk_soc = " . $id;
1512
-					if (! $this->db->query($sql))
1511
+					$sql .= " WHERE fk_soc = ".$id;
1512
+					if (!$this->db->query($sql))
1513 1513
 					{
1514 1514
 						$error++;
1515 1515
 						$this->errors[] = $this->db->lasterror();
@@ -1518,9 +1518,9 @@  discard block
 block discarded – undo
1518 1518
 			}
1519 1519
 
1520 1520
 			// Removed extrafields
1521
-			if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
1521
+			if ((!$error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
1522 1522
 			{
1523
-				$result=$this->deleteExtraFields();
1523
+				$result = $this->deleteExtraFields();
1524 1524
 				if ($result < 0)
1525 1525
 				{
1526 1526
 					$error++;
@@ -1529,12 +1529,12 @@  discard block
 block discarded – undo
1529 1529
 			}
1530 1530
 
1531 1531
 			// Remove links to subsidiaries companies
1532
-			if (! $error)
1532
+			if (!$error)
1533 1533
 			{
1534 1534
 				$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
1535
-				$sql.= " SET parent = NULL";
1536
-				$sql.= " WHERE parent = " . $id;
1537
-				if (! $this->db->query($sql))
1535
+				$sql .= " SET parent = NULL";
1536
+				$sql .= " WHERE parent = ".$id;
1537
+				if (!$this->db->query($sql))
1538 1538
 				{
1539 1539
 					$error++;
1540 1540
 					$this->errors[] = $this->db->lasterror();
@@ -1542,25 +1542,25 @@  discard block
 block discarded – undo
1542 1542
 			}
1543 1543
 
1544 1544
 			// Remove third party
1545
-			if (! $error)
1545
+			if (!$error)
1546 1546
 			{
1547 1547
 				$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe";
1548
-				$sql.= " WHERE rowid = " . $id;
1549
-				if (! $this->db->query($sql))
1548
+				$sql .= " WHERE rowid = ".$id;
1549
+				if (!$this->db->query($sql))
1550 1550
 				{
1551 1551
 					$error++;
1552 1552
 					$this->errors[] = $this->db->lasterror();
1553 1553
 				}
1554 1554
 			}
1555 1555
 
1556
-			if (! $error)
1556
+			if (!$error)
1557 1557
 			{
1558 1558
 				$this->db->commit();
1559 1559
 
1560 1560
 				// Delete directory
1561
-				if (! empty($conf->societe->multidir_output[$entity]))
1561
+				if (!empty($conf->societe->multidir_output[$entity]))
1562 1562
 				{
1563
-					$docdir = $conf->societe->multidir_output[$entity] . "/" . $id;
1563
+					$docdir = $conf->societe->multidir_output[$entity]."/".$id;
1564 1564
 					if (dol_is_dir($docdir))
1565 1565
 					{
1566 1566
 						dol_delete_dir_recursive($docdir);
@@ -1591,13 +1591,13 @@  discard block
 block discarded – undo
1591 1591
         // phpcs:enable
1592 1592
 		if ($this->id)
1593 1593
 		{
1594
-			$newclient=1;
1595
-			if ($this->client == 2 || $this->client == 3) $newclient=3;	//If prospect, we keep prospect tag
1594
+			$newclient = 1;
1595
+			if ($this->client == 2 || $this->client == 3) $newclient = 3; //If prospect, we keep prospect tag
1596 1596
 			$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
1597
-			$sql.= " SET client = ".$newclient;
1598
-			$sql.= " WHERE rowid = " . $this->id;
1597
+			$sql .= " SET client = ".$newclient;
1598
+			$sql .= " WHERE rowid = ".$this->id;
1599 1599
 
1600
-			$resql=$this->db->query($sql);
1600
+			$resql = $this->db->query($sql);
1601 1601
 			if ($resql)
1602 1602
 			{
1603 1603
 				$this->client = $newclient;
@@ -1623,10 +1623,10 @@  discard block
 block discarded – undo
1623 1623
 		global $conf, $langs;
1624 1624
 
1625 1625
 		// Nettoyage parametres
1626
-		$note=trim($note);
1627
-		if (! $note)
1626
+		$note = trim($note);
1627
+		if (!$note)
1628 1628
 		{
1629
-			$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("NoteReason"));
1629
+			$this->error = $langs->trans("ErrorFieldRequired", $langs->trans("NoteReason"));
1630 1630
 			return -2;
1631 1631
 		}
1632 1632
 
@@ -1636,33 +1636,33 @@  discard block
 block discarded – undo
1636 1636
 		{
1637 1637
 			$this->db->begin();
1638 1638
 
1639
-			$now=dol_now();
1639
+			$now = dol_now();
1640 1640
 
1641 1641
 			// Positionne remise courante
1642 1642
 			$sql = "UPDATE ".MAIN_DB_PREFIX."societe ";
1643
-			$sql.= " SET remise_client = '".$this->db->escape($remise)."'";
1644
-			$sql.= " WHERE rowid = " . $this->id;
1645
-			$resql=$this->db->query($sql);
1646
-			if (! $resql)
1643
+			$sql .= " SET remise_client = '".$this->db->escape($remise)."'";
1644
+			$sql .= " WHERE rowid = ".$this->id;
1645
+			$resql = $this->db->query($sql);
1646
+			if (!$resql)
1647 1647
 			{
1648 1648
 				$this->db->rollback();
1649
-				$this->error=$this->db->error();
1649
+				$this->error = $this->db->error();
1650 1650
 				return -1;
1651 1651
 			}
1652 1652
 
1653 1653
 			// Ecrit trace dans historique des remises
1654 1654
 			$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise";
1655
-			$sql.= " (entity, datec, fk_soc, remise_client, note, fk_user_author)";
1656
-			$sql.= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',";
1657
-			$sql.= " '".$this->db->escape($note)."',";
1658
-			$sql.= " ".$user->id;
1659
-			$sql.= ")";
1660
-
1661
-			$resql=$this->db->query($sql);
1662
-			if (! $resql)
1655
+			$sql .= " (entity, datec, fk_soc, remise_client, note, fk_user_author)";
1656
+			$sql .= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',";
1657
+			$sql .= " '".$this->db->escape($note)."',";
1658
+			$sql .= " ".$user->id;
1659
+			$sql .= ")";
1660
+
1661
+			$resql = $this->db->query($sql);
1662
+			if (!$resql)
1663 1663
 			{
1664 1664
 				$this->db->rollback();
1665
-				$this->error=$this->db->lasterror();
1665
+				$this->error = $this->db->lasterror();
1666 1666
 				return -1;
1667 1667
 			}
1668 1668
 
@@ -1686,10 +1686,10 @@  discard block
 block discarded – undo
1686 1686
 		global $conf, $langs;
1687 1687
 
1688 1688
 		// Nettoyage parametres
1689
-		$note=trim($note);
1690
-		if (! $note)
1689
+		$note = trim($note);
1690
+		if (!$note)
1691 1691
 		{
1692
-			$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("NoteReason"));
1692
+			$this->error = $langs->trans("ErrorFieldRequired", $langs->trans("NoteReason"));
1693 1693
 			return -2;
1694 1694
 		}
1695 1695
 
@@ -1699,33 +1699,33 @@  discard block
 block discarded – undo
1699 1699
 		{
1700 1700
 			$this->db->begin();
1701 1701
 
1702
-			$now=dol_now();
1702
+			$now = dol_now();
1703 1703
 
1704 1704
 			// Positionne remise courante
1705 1705
 			$sql = "UPDATE ".MAIN_DB_PREFIX."societe ";
1706
-			$sql.= " SET remise_supplier = '".$this->db->escape($remise)."'";
1707
-			$sql.= " WHERE rowid = " . $this->id;
1708
-			$resql=$this->db->query($sql);
1709
-			if (! $resql)
1706
+			$sql .= " SET remise_supplier = '".$this->db->escape($remise)."'";
1707
+			$sql .= " WHERE rowid = ".$this->id;
1708
+			$resql = $this->db->query($sql);
1709
+			if (!$resql)
1710 1710
 			{
1711 1711
 				$this->db->rollback();
1712
-				$this->error=$this->db->error();
1712
+				$this->error = $this->db->error();
1713 1713
 				return -1;
1714 1714
 			}
1715 1715
 
1716 1716
 			// Ecrit trace dans historique des remises
1717 1717
 			$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_supplier";
1718
-			$sql.= " (entity, datec, fk_soc, remise_supplier, note, fk_user_author)";
1719
-			$sql.= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',";
1720
-			$sql.= " '".$this->db->escape($note)."',";
1721
-			$sql.= " ".$user->id;
1722
-			$sql.= ")";
1723
-
1724
-			$resql=$this->db->query($sql);
1725
-			if (! $resql)
1718
+			$sql .= " (entity, datec, fk_soc, remise_supplier, note, fk_user_author)";
1719
+			$sql .= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',";
1720
+			$sql .= " '".$this->db->escape($note)."',";
1721
+			$sql .= " ".$user->id;
1722
+			$sql .= ")";
1723
+
1724
+			$resql = $this->db->query($sql);
1725
+			if (!$resql)
1726 1726
 			{
1727 1727
 				$this->db->rollback();
1728
-				$this->error=$this->db->lasterror();
1728
+				$this->error = $this->db->lasterror();
1729 1729
 				return -1;
1730 1730
 			}
1731 1731
 
@@ -1745,7 +1745,7 @@  discard block
 block discarded – undo
1745 1745
 	 *      @param	int		$discount_type	0 => customer discount, 1 => supplier discount
1746 1746
 	 *		@return	int					<0 if KO, id of discount record if OK
1747 1747
 	 */
1748
-	function set_remise_except($remise, User $user, $desc, $tva_tx=0, $discount_type=0)
1748
+	function set_remise_except($remise, User $user, $desc, $tva_tx = 0, $discount_type = 0)
1749 1749
 	{
1750 1750
         // phpcs:enable
1751 1751
 		global $langs;
@@ -1755,14 +1755,14 @@  discard block
 block discarded – undo
1755 1755
 		$desc = trim($desc);
1756 1756
 
1757 1757
 		// Check parameters
1758
-		if (! $remise > 0)
1758
+		if (!$remise > 0)
1759 1759
 		{
1760
-			$this->error=$langs->trans("ErrorWrongValueForParameter","1");
1760
+			$this->error = $langs->trans("ErrorWrongValueForParameter", "1");
1761 1761
 			return -1;
1762 1762
 		}
1763
-		if (! $desc)
1763
+		if (!$desc)
1764 1764
 		{
1765
-			$this->error=$langs->trans("ErrorWrongValueForParameter","3");
1765
+			$this->error = $langs->trans("ErrorWrongValueForParameter", "3");
1766 1766
 			return -2;
1767 1767
 		}
1768 1768
 
@@ -1771,25 +1771,25 @@  discard block
 block discarded – undo
1771 1771
 			require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
1772 1772
 
1773 1773
 			$discount = new DiscountAbsolute($this->db);
1774
-			$discount->fk_soc=$this->id;
1774
+			$discount->fk_soc = $this->id;
1775 1775
 
1776
-			$discount->discount_type=$discount_type;
1776
+			$discount->discount_type = $discount_type;
1777 1777
 
1778
-			$discount->amount_ht=$discount->multicurrency_amount_ht=price2num($remise,'MT');
1779
-			$discount->amount_tva=$discount->multicurrency_amount_tva=price2num($remise*$tva_tx/100,'MT');
1780
-			$discount->amount_ttc=$discount->multicurrency_amount_ttc=price2num($discount->amount_ht+$discount->amount_tva,'MT');
1778
+			$discount->amount_ht = $discount->multicurrency_amount_ht = price2num($remise, 'MT');
1779
+			$discount->amount_tva = $discount->multicurrency_amount_tva = price2num($remise * $tva_tx / 100, 'MT');
1780
+			$discount->amount_ttc = $discount->multicurrency_amount_ttc = price2num($discount->amount_ht + $discount->amount_tva, 'MT');
1781 1781
 
1782
-			$discount->tva_tx=price2num($tva_tx,'MT');
1783
-			$discount->description=$desc;
1782
+			$discount->tva_tx = price2num($tva_tx, 'MT');
1783
+			$discount->description = $desc;
1784 1784
 
1785
-			$result=$discount->create($user);
1785
+			$result = $discount->create($user);
1786 1786
 			if ($result > 0)
1787 1787
 			{
1788 1788
 				return $result;
1789 1789
 			}
1790 1790
 			else
1791 1791
 			{
1792
-				$this->error=$discount->error;
1792
+				$this->error = $discount->error;
1793 1793
 				return -3;
1794 1794
 			}
1795 1795
 		}
@@ -1805,19 +1805,19 @@  discard block
 block discarded – undo
1805 1805
 	 * 	@param	int		$discount_type	0 => customer discount, 1 => supplier discount
1806 1806
 	 *	@return	int					<0 if KO, Credit note amount otherwise
1807 1807
 	 */
1808
-	function getAvailableDiscounts($user='',$filter='',$maxvalue=0,$discount_type=0)
1808
+	function getAvailableDiscounts($user = '', $filter = '', $maxvalue = 0, $discount_type = 0)
1809 1809
 	{
1810 1810
 		require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
1811 1811
 
1812
-		$discountstatic=new DiscountAbsolute($this->db);
1813
-		$result=$discountstatic->getAvailableDiscounts($this,$user,$filter,$maxvalue,$discount_type);
1812
+		$discountstatic = new DiscountAbsolute($this->db);
1813
+		$result = $discountstatic->getAvailableDiscounts($this, $user, $filter, $maxvalue, $discount_type);
1814 1814
 		if ($result >= 0)
1815 1815
 		{
1816 1816
 			return $result;
1817 1817
 		}
1818 1818
 		else
1819 1819
 		{
1820
-			$this->error=$discountstatic->error;
1820
+			$this->error = $discountstatic->error;
1821 1821
 			return -1;
1822 1822
 		}
1823 1823
 	}
@@ -1829,49 +1829,49 @@  discard block
 block discarded – undo
1829 1829
 	 *  @param	int		$mode		0=Array with properties, 1=Array of id.
1830 1830
 	 *  @return array       		Array of sales representatives of third party
1831 1831
 	 */
1832
-	function getSalesRepresentatives(User $user, $mode=0)
1832
+	function getSalesRepresentatives(User $user, $mode = 0)
1833 1833
 	{
1834 1834
 		global $conf;
1835 1835
 
1836
-		$reparray=array();
1836
+		$reparray = array();
1837 1837
 
1838 1838
 		$sql = "SELECT DISTINCT u.rowid, u.login, u.lastname, u.firstname, u.email, u.statut, u.entity, u.photo";
1839
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."user as u";
1840
-		if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
1839
+		$sql .= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."user as u";
1840
+		if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
1841 1841
 		{
1842
-			$sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1843
-			$sql.= " WHERE ((ug.fk_user = sc.fk_user";
1844
-			$sql.= " AND ug.entity = ".$conf->entity.")";
1845
-			$sql.= " OR u.admin = 1)";
1842
+			$sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1843
+			$sql .= " WHERE ((ug.fk_user = sc.fk_user";
1844
+			$sql .= " AND ug.entity = ".$conf->entity.")";
1845
+			$sql .= " OR u.admin = 1)";
1846 1846
 		}
1847 1847
 		else
1848
-			$sql.= " WHERE entity in (0, ".$conf->entity.")";
1848
+			$sql .= " WHERE entity in (0, ".$conf->entity.")";
1849 1849
 
1850
-		$sql.= " AND u.rowid = sc.fk_user AND sc.fk_soc = ".$this->id;
1850
+		$sql .= " AND u.rowid = sc.fk_user AND sc.fk_soc = ".$this->id;
1851 1851
 
1852 1852
 		$resql = $this->db->query($sql);
1853 1853
 		if ($resql)
1854 1854
 		{
1855 1855
 			$num = $this->db->num_rows($resql);
1856
-			$i=0;
1856
+			$i = 0;
1857 1857
 			while ($i < $num)
1858 1858
 			{
1859 1859
 				$obj = $this->db->fetch_object($resql);
1860 1860
 
1861 1861
 				if (empty($mode))
1862 1862
 				{
1863
-					$reparray[$i]['id']=$obj->rowid;
1864
-					$reparray[$i]['lastname']=$obj->lastname;
1865
-					$reparray[$i]['firstname']=$obj->firstname;
1866
-					$reparray[$i]['email']=$obj->email;
1867
-					$reparray[$i]['statut']=$obj->statut;
1868
-					$reparray[$i]['entity']=$obj->entity;
1869
-					$reparray[$i]['login']=$obj->login;
1870
-					$reparray[$i]['photo']=$obj->photo;
1863
+					$reparray[$i]['id'] = $obj->rowid;
1864
+					$reparray[$i]['lastname'] = $obj->lastname;
1865
+					$reparray[$i]['firstname'] = $obj->firstname;
1866
+					$reparray[$i]['email'] = $obj->email;
1867
+					$reparray[$i]['statut'] = $obj->statut;
1868
+					$reparray[$i]['entity'] = $obj->entity;
1869
+					$reparray[$i]['login'] = $obj->login;
1870
+					$reparray[$i]['photo'] = $obj->photo;
1871 1871
 				}
1872 1872
 				else
1873 1873
 				{
1874
-					$reparray[]=$obj->rowid;
1874
+					$reparray[] = $obj->rowid;
1875 1875
 				}
1876 1876
 				$i++;
1877 1877
 			}
@@ -1896,13 +1896,13 @@  discard block
 block discarded – undo
1896 1896
         // phpcs:enable
1897 1897
 		if ($this->id)
1898 1898
 		{
1899
-			$now=dol_now();
1899
+			$now = dol_now();
1900 1900
 
1901 1901
 			$sql  = "UPDATE ".MAIN_DB_PREFIX."societe";
1902 1902
 			$sql .= " SET price_level = '".$this->db->escape($price_level)."'";
1903
-			$sql .= " WHERE rowid = " . $this->id;
1903
+			$sql .= " WHERE rowid = ".$this->id;
1904 1904
 
1905
-			if (! $this->db->query($sql))
1905
+			if (!$this->db->query($sql))
1906 1906
 			{
1907 1907
 				dol_print_error($this->db);
1908 1908
 				return -1;
@@ -1912,7 +1912,7 @@  discard block
 block discarded – undo
1912 1912
 			$sql .= " (datec, fk_soc, price_level, fk_user_author)";
1913 1913
 			$sql .= " VALUES ('".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($price_level)."', ".$user->id.")";
1914 1914
 
1915
-			if (! $this->db->query($sql))
1915
+			if (!$this->db->query($sql))
1916 1916
 			{
1917 1917
 				dol_print_error($this->db);
1918 1918
 				return -1;
@@ -1933,28 +1933,28 @@  discard block
 block discarded – undo
1933 1933
 	function add_commercial(User $user, $commid)
1934 1934
 	{
1935 1935
         // phpcs:enable
1936
-		$error=0;
1936
+		$error = 0;
1937 1937
 
1938 1938
 
1939 1939
 		if ($this->id > 0 && $commid > 0)
1940 1940
 		{
1941 1941
 			$sql = "DELETE FROM  ".MAIN_DB_PREFIX."societe_commerciaux";
1942
-			$sql.= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid;
1942
+			$sql .= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid;
1943 1943
 
1944 1944
 			$this->db->query($sql);
1945 1945
 
1946 1946
 			$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_commerciaux";
1947
-			$sql.= " ( fk_soc, fk_user )";
1948
-			$sql.= " VALUES (".$this->id.",".$commid.")";
1947
+			$sql .= " ( fk_soc, fk_user )";
1948
+			$sql .= " VALUES (".$this->id.",".$commid.")";
1949 1949
 
1950
-			if (! $this->db->query($sql) )
1950
+			if (!$this->db->query($sql))
1951 1951
 			{
1952 1952
 				dol_syslog(get_class($this)."::add_commercial Erreur");
1953 1953
 			}
1954 1954
 			else {
1955
-				$this->context=array('commercial_modified'=>$commid);
1955
+				$this->context = array('commercial_modified'=>$commid);
1956 1956
 
1957
-				$result=$this->call_trigger('COMPANY_LINK_SALE_REPRESENTATIVE',$user);
1957
+				$result = $this->call_trigger('COMPANY_LINK_SALE_REPRESENTATIVE', $user);
1958 1958
                 if ($result < 0) $error++;
1959 1959
 			}
1960 1960
 		}
@@ -1971,10 +1971,10 @@  discard block
 block discarded – undo
1971 1971
 	function del_commercial(User $user, $commid)
1972 1972
 	{
1973 1973
         // phpcs:enable
1974
-		$error=0;
1975
-		$this->context=array('commercial_modified'=>$commid);
1974
+		$error = 0;
1975
+		$this->context = array('commercial_modified'=>$commid);
1976 1976
 
1977
-		$result=$this->call_trigger('COMPANY_UNLINK_SALE_REPRESENTATIVE',$user);
1977
+		$result = $this->call_trigger('COMPANY_UNLINK_SALE_REPRESENTATIVE', $user);
1978 1978
         if ($result < 0) $error++;
1979 1979
 
1980 1980
 		if ($this->id > 0 && $commid > 0)
@@ -1982,7 +1982,7 @@  discard block
 block discarded – undo
1982 1982
 			$sql  = "DELETE FROM  ".MAIN_DB_PREFIX."societe_commerciaux ";
1983 1983
 			$sql .= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid;
1984 1984
 
1985
-			if (! $this->db->query($sql) )
1985
+			if (!$this->db->query($sql))
1986 1986
 			{
1987 1987
 				dol_syslog(get_class($this)."::del_commercial Erreur");
1988 1988
 			}
@@ -2000,162 +2000,162 @@  discard block
 block discarded – undo
2000 2000
 	 *      @param  int     $save_lastsearch_value    -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
2001 2001
 	 *		@return	string					          String with URL
2002 2002
 	 */
2003
-	function getNomUrl($withpicto=0, $option='', $maxlen=0, $notooltip=0, $save_lastsearch_value=-1)
2003
+	function getNomUrl($withpicto = 0, $option = '', $maxlen = 0, $notooltip = 0, $save_lastsearch_value = -1)
2004 2004
 	{
2005 2005
 		global $conf, $langs, $hookmanager;
2006 2006
 
2007
-		if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
2007
+		if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
2008 2008
 
2009
-		$name=$this->name?$this->name:$this->nom;
2009
+		$name = $this->name ? $this->name : $this->nom;
2010 2010
 
2011
-		if(!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)){
2011
+		if (!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)) {
2012 2012
 
2013
-             if(empty($option) && $this->client > 0) $option = 'customer';
2014
-             if(empty($option) && $this->fournisseur > 0) $option = 'supplier';
2013
+             if (empty($option) && $this->client > 0) $option = 'customer';
2014
+             if (empty($option) && $this->fournisseur > 0) $option = 'supplier';
2015 2015
          }
2016 2016
 
2017 2017
 
2018
-		if (! empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto)))
2018
+		if (!empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto)))
2019 2019
 		{
2020 2020
 			$code = '';
2021
-			if (($this->client) && (! empty ( $this->code_client ))
2021
+			if (($this->client) && (!empty ($this->code_client))
2022 2022
 				&& ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1
2023 2023
 				|| $conf->global->SOCIETE_ADD_REF_IN_LIST == 2
2024 2024
 				)
2025 2025
 			)
2026 2026
 			{
2027
-				$code = $this->code_client . ' - ';
2027
+				$code = $this->code_client.' - ';
2028 2028
 			}
2029 2029
 
2030
-			if (($this->fournisseur) && (! empty ( $this->code_fournisseur ))
2030
+			if (($this->fournisseur) && (!empty ($this->code_fournisseur))
2031 2031
 				&& ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1
2032 2032
 				|| $conf->global->SOCIETE_ADD_REF_IN_LIST == 3
2033 2033
 				)
2034 2034
 			)
2035 2035
 			{
2036
-				$code .= $this->code_fournisseur . ' - ';
2036
+				$code .= $this->code_fournisseur.' - ';
2037 2037
 			}
2038 2038
 
2039 2039
 			if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1)
2040 2040
 			{
2041
-				$name =$code.' '.$name;
2041
+				$name = $code.' '.$name;
2042 2042
 			}
2043 2043
 			else
2044 2044
 			{
2045
-				$name =$code;
2045
+				$name = $code;
2046 2046
 			}
2047 2047
 		}
2048 2048
 
2049 2049
 		if (!empty($this->name_alias)) $name .= ' ('.$this->name_alias.')';
2050 2050
 
2051
-		$result=''; $label='';
2052
-		$linkstart=''; $linkend='';
2051
+		$result = ''; $label = '';
2052
+		$linkstart = ''; $linkend = '';
2053 2053
 
2054
-		if (! empty($this->logo) && class_exists('Form'))
2054
+		if (!empty($this->logo) && class_exists('Form'))
2055 2055
 		{
2056
-			$label.= '<div class="photointooltip">';
2057
-			$label.= Form::showphoto('societe', $this, 0, 40, 0, 'photowithmargin', 'mini', 0);	// Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
2058
-			$label.= '</div><div style="clear: both;"></div>';
2056
+			$label .= '<div class="photointooltip">';
2057
+			$label .= Form::showphoto('societe', $this, 0, 40, 0, 'photowithmargin', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
2058
+			$label .= '</div><div style="clear: both;"></div>';
2059 2059
 		}
2060 2060
 
2061
-		$label.= '<div class="centpercent">';
2061
+		$label .= '<div class="centpercent">';
2062 2062
 
2063 2063
 		if ($option == 'customer' || $option == 'compta' || $option == 'category' || $option == 'category_supplier')
2064 2064
 		{
2065
-		   $label.= '<u>' . $langs->trans("ShowCustomer") . '</u>';
2065
+		   $label .= '<u>'.$langs->trans("ShowCustomer").'</u>';
2066 2066
 		   $linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id;
2067 2067
 		}
2068 2068
 		elseif ($option == 'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
2069 2069
 		{
2070
-			$label.= '<u>' . $langs->trans("ShowProspect") . '</u>';
2070
+			$label .= '<u>'.$langs->trans("ShowProspect").'</u>';
2071 2071
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id;
2072 2072
 		}
2073 2073
 		elseif ($option == 'supplier')
2074 2074
 		{
2075
-			$label.= '<u>' . $langs->trans("ShowSupplier") . '</u>';
2075
+			$label .= '<u>'.$langs->trans("ShowSupplier").'</u>';
2076 2076
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$this->id;
2077 2077
 		}
2078 2078
 		elseif ($option == 'agenda')
2079 2079
 		{
2080
-			$label.= '<u>' . $langs->trans("ShowAgenda") . '</u>';
2080
+			$label .= '<u>'.$langs->trans("ShowAgenda").'</u>';
2081 2081
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/agenda.php?socid='.$this->id;
2082 2082
 		}
2083 2083
 		elseif ($option == 'project')
2084 2084
 		{
2085
-			$label.= '<u>' . $langs->trans("ShowProject") . '</u>';
2085
+			$label .= '<u>'.$langs->trans("ShowProject").'</u>';
2086 2086
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/project.php?socid='.$this->id;
2087 2087
 		}
2088 2088
 		elseif ($option == 'margin')
2089 2089
 		{
2090
-			$label.= '<u>' . $langs->trans("ShowMargin") . '</u>';
2090
+			$label .= '<u>'.$langs->trans("ShowMargin").'</u>';
2091 2091
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/margin/tabs/thirdpartyMargins.php?socid='.$this->id.'&type=1';
2092 2092
 		}
2093 2093
 		elseif ($option == 'contact')
2094 2094
 		{
2095
-			$label.= '<u>' . $langs->trans("ShowContacts") . '</u>';
2095
+			$label .= '<u>'.$langs->trans("ShowContacts").'</u>';
2096 2096
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/contact.php?socid='.$this->id;
2097 2097
 		}
2098 2098
 		elseif ($option == 'ban')
2099 2099
 		{
2100
-			$label.= '<u>' . $langs->trans("ShowBan") . '</u>';
2100
+			$label .= '<u>'.$langs->trans("ShowBan").'</u>';
2101 2101
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$this->id;
2102 2102
 		}
2103 2103
 
2104 2104
 		// By default
2105 2105
 		if (empty($linkstart))
2106 2106
 		{
2107
-			$label.= '<u>' . $langs->trans("ShowCompany") . '</u>';
2107
+			$label .= '<u>'.$langs->trans("ShowCompany").'</u>';
2108 2108
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$this->id;
2109 2109
 		}
2110 2110
 
2111
-		if (! empty($this->name))
2111
+		if (!empty($this->name))
2112 2112
 		{
2113
-			$label.= '<br><b>' . $langs->trans('Name') . ':</b> '. $this->name;
2114
-			if (! empty($this->name_alias)) $label.=' ('.$this->name_alias.')';
2115
-			$label.= '<br><b>' . $langs->trans('Email') . ':</b> '. $this->email;
2116
-		}
2117
-		if (! empty($this->country_code))
2118
-			$label.= '<br><b>' . $langs->trans('Country') . ':</b> '. $this->country_code;
2119
-		if (! empty($this->tva_intra) || (! empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'vatnumber') !== false))
2120
-			$label.= '<br><b>' . $langs->trans('VATIntra') . ':</b> '. $this->tva_intra;
2121
-		if (! empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP))
2113
+			$label .= '<br><b>'.$langs->trans('Name').':</b> '.$this->name;
2114
+			if (!empty($this->name_alias)) $label .= ' ('.$this->name_alias.')';
2115
+			$label .= '<br><b>'.$langs->trans('Email').':</b> '.$this->email;
2116
+		}
2117
+		if (!empty($this->country_code))
2118
+			$label .= '<br><b>'.$langs->trans('Country').':</b> '.$this->country_code;
2119
+		if (!empty($this->tva_intra) || (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'vatnumber') !== false))
2120
+			$label .= '<br><b>'.$langs->trans('VATIntra').':</b> '.$this->tva_intra;
2121
+		if (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP))
2122 2122
 		{
2123
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid1') !== false) $label.= '<br><b>' . $langs->trans('ProfId1'.$this->country_code) . ':</b> '. $this->idprof1;
2124
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid2') !== false) $label.= '<br><b>' . $langs->trans('ProfId2'.$this->country_code) . ':</b> '. $this->idprof2;
2125
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid3') !== false) $label.= '<br><b>' . $langs->trans('ProfId3'.$this->country_code) . ':</b> '. $this->idprof3;
2126
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid4') !== false) $label.= '<br><b>' . $langs->trans('ProfId4'.$this->country_code) . ':</b> '. $this->idprof4;
2127
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid5') !== false) $label.= '<br><b>' . $langs->trans('ProfId5'.$this->country_code) . ':</b> '. $this->idprof5;
2128
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid6') !== false) $label.= '<br><b>' . $langs->trans('ProfId6'.$this->country_code) . ':</b> '. $this->idprof6;
2129
-		}
2130
-		if (! empty($this->code_client) && ($this->client == 1 || $this->client == 3))
2131
-			$label.= '<br><b>' . $langs->trans('CustomerCode') . ':</b> '. $this->code_client;
2132
-		if (! empty($this->code_fournisseur) && $this->fournisseur)
2133
-			$label.= '<br><b>' . $langs->trans('SupplierCode') . ':</b> '. $this->code_fournisseur;
2134
-		if (! empty($conf->accounting->enabled) && ($this->client == 1 || $this->client == 3))
2135
-			$label.= '<br><b>' . $langs->trans('CustomerAccountancyCode') . ':</b> '. ($this->code_compta ? $this->code_compta : $this->code_compta_client);
2136
-		if (! empty($conf->accounting->enabled) && $this->fournisseur)
2137
-			$label.= '<br><b>' . $langs->trans('SupplierAccountancyCode') . ':</b> '. $this->code_compta_fournisseur;
2138
-
2139
-		$label.= '</div>';
2123
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid1') !== false) $label .= '<br><b>'.$langs->trans('ProfId1'.$this->country_code).':</b> '.$this->idprof1;
2124
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid2') !== false) $label .= '<br><b>'.$langs->trans('ProfId2'.$this->country_code).':</b> '.$this->idprof2;
2125
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid3') !== false) $label .= '<br><b>'.$langs->trans('ProfId3'.$this->country_code).':</b> '.$this->idprof3;
2126
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid4') !== false) $label .= '<br><b>'.$langs->trans('ProfId4'.$this->country_code).':</b> '.$this->idprof4;
2127
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid5') !== false) $label .= '<br><b>'.$langs->trans('ProfId5'.$this->country_code).':</b> '.$this->idprof5;
2128
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid6') !== false) $label .= '<br><b>'.$langs->trans('ProfId6'.$this->country_code).':</b> '.$this->idprof6;
2129
+		}
2130
+		if (!empty($this->code_client) && ($this->client == 1 || $this->client == 3))
2131
+			$label .= '<br><b>'.$langs->trans('CustomerCode').':</b> '.$this->code_client;
2132
+		if (!empty($this->code_fournisseur) && $this->fournisseur)
2133
+			$label .= '<br><b>'.$langs->trans('SupplierCode').':</b> '.$this->code_fournisseur;
2134
+		if (!empty($conf->accounting->enabled) && ($this->client == 1 || $this->client == 3))
2135
+			$label .= '<br><b>'.$langs->trans('CustomerAccountancyCode').':</b> '.($this->code_compta ? $this->code_compta : $this->code_compta_client);
2136
+		if (!empty($conf->accounting->enabled) && $this->fournisseur)
2137
+			$label .= '<br><b>'.$langs->trans('SupplierAccountancyCode').':</b> '.$this->code_compta_fournisseur;
2138
+
2139
+		$label .= '</div>';
2140 2140
 
2141 2141
 		// Add type of canvas
2142
-		$linkstart.=(!empty($this->canvas)?'&canvas='.$this->canvas:'');
2142
+		$linkstart .= (!empty($this->canvas) ? '&canvas='.$this->canvas : '');
2143 2143
 		// Add param to save lastsearch_values or not
2144
-		$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
2145
-		if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
2146
-		if ($add_save_lastsearch_values) $linkstart.='&save_lastsearch_values=1';
2147
-		$linkstart.='"';
2144
+		$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2145
+		if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
2146
+		if ($add_save_lastsearch_values) $linkstart .= '&save_lastsearch_values=1';
2147
+		$linkstart .= '"';
2148 2148
 
2149
-		$linkclose='';
2149
+		$linkclose = '';
2150 2150
 		if (empty($notooltip))
2151 2151
 		{
2152
-			if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
2152
+			if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
2153 2153
 			{
2154
-				$label=$langs->trans("ShowCompany");
2155
-				$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
2154
+				$label = $langs->trans("ShowCompany");
2155
+				$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
2156 2156
 			}
2157
-			$linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
2158
-			$linkclose.=' class="classfortooltip refurl"';
2157
+			$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
2158
+			$linkclose .= ' class="classfortooltip refurl"';
2159 2159
 
2160 2160
 		 	/*
2161 2161
 			$hookmanager->initHooks(array('thirdpartydao'));
@@ -2164,25 +2164,25 @@  discard block
 block discarded – undo
2164 2164
 			if ($reshook > 0) $linkclose = $hookmanager->resPrint;
2165 2165
 			*/
2166 2166
 		}
2167
-		$linkstart.=$linkclose.'>';
2168
-		$linkend='</a>';
2167
+		$linkstart .= $linkclose.'>';
2168
+		$linkend = '</a>';
2169 2169
 
2170 2170
 		global $user;
2171
-		if (! $user->rights->societe->client->voir && $user->societe_id > 0 && $this->id != $user->societe_id)
2171
+		if (!$user->rights->societe->client->voir && $user->societe_id > 0 && $this->id != $user->societe_id)
2172 2172
 		{
2173
-			$linkstart='';
2174
-			$linkend='';
2173
+			$linkstart = '';
2174
+			$linkend = '';
2175 2175
 		}
2176 2176
 
2177
-		$result.=$linkstart;
2178
-		if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip valigntextbottom"'), 0, 0, $notooltip?0:1);
2179
-		if ($withpicto != 2) $result.=($maxlen?dol_trunc($name,$maxlen):$name);
2180
-		$result.=$linkend;
2177
+		$result .= $linkstart;
2178
+		if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip valigntextbottom"'), 0, 0, $notooltip ? 0 : 1);
2179
+		if ($withpicto != 2) $result .= ($maxlen ?dol_trunc($name, $maxlen) : $name);
2180
+		$result .= $linkend;
2181 2181
 
2182 2182
 		global $action;
2183 2183
 		$hookmanager->initHooks(array('thirdpartydao'));
2184
-		$parameters=array('id'=>$this->id, 'getnomurl'=>$result);
2185
-		$reshook=$hookmanager->executeHooks('getNomUrl',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
2184
+		$parameters = array('id'=>$this->id, 'getnomurl'=>$result);
2185
+		$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
2186 2186
 		if ($reshook > 0) $result = $hookmanager->resPrint;
2187 2187
 		else $result .= $hookmanager->resPrint;
2188 2188
 
@@ -2195,9 +2195,9 @@  discard block
 block discarded – undo
2195 2195
 	 *    @param	int		$mode       0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
2196 2196
 	 *    @return   string        		Libelle
2197 2197
 	 */
2198
-	function getLibStatut($mode=0)
2198
+	function getLibStatut($mode = 0)
2199 2199
 	{
2200
-		return $this->LibStatut($this->status,$mode);
2200
+		return $this->LibStatut($this->status, $mode);
2201 2201
 	}
2202 2202
 
2203 2203
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -2208,7 +2208,7 @@  discard block
 block discarded – undo
2208 2208
 	 *  @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
2209 2209
 	 *  @return	string          		Libelle du statut
2210 2210
 	 */
2211
-	function LibStatut($statut,$mode=0)
2211
+	function LibStatut($statut, $mode = 0)
2212 2212
 	{
2213 2213
         // phpcs:enable
2214 2214
 		global $langs;
@@ -2216,38 +2216,38 @@  discard block
 block discarded – undo
2216 2216
 
2217 2217
 		if ($mode == 0)
2218 2218
 		{
2219
-			if ($statut==0) return $langs->trans("ActivityCeased");
2220
-			elseif ($statut==1) return $langs->trans("InActivity");
2219
+			if ($statut == 0) return $langs->trans("ActivityCeased");
2220
+			elseif ($statut == 1) return $langs->trans("InActivity");
2221 2221
 		}
2222 2222
 		elseif ($mode == 1)
2223 2223
 		{
2224
-			if ($statut==0) return $langs->trans("ActivityCeased");
2225
-			elseif ($statut==1) return $langs->trans("InActivity");
2224
+			if ($statut == 0) return $langs->trans("ActivityCeased");
2225
+			elseif ($statut == 1) return $langs->trans("InActivity");
2226 2226
 		}
2227 2227
 		elseif ($mode == 2)
2228 2228
 		{
2229
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2230
-			elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2229
+			if ($statut == 0) return img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2230
+			elseif ($statut == 1) return img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2231 2231
 		}
2232 2232
 		elseif ($mode == 3)
2233 2233
 		{
2234
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2235
-			elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2234
+			if ($statut == 0) return img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"');
2235
+			elseif ($statut == 1) return img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"');
2236 2236
 		}
2237 2237
 		elseif ($mode == 4)
2238 2238
 		{
2239
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2240
-			elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2239
+			if ($statut == 0) return img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2240
+			elseif ($statut == 1) return img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2241 2241
 		}
2242 2242
 		elseif ($mode == 5)
2243 2243
 		{
2244
-			if ($statut==0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2245
-			elseif ($statut==1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2244
+			if ($statut == 0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"');
2245
+			elseif ($statut == 1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"');
2246 2246
 		}
2247 2247
 		elseif ($mode == 6)
2248 2248
 		{
2249
-			if ($statut==0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2250
-			elseif ($statut==1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2249
+			if ($statut == 0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"');
2250
+			elseif ($statut == 1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"');
2251 2251
 		}
2252 2252
 	}
2253 2253
 
@@ -2258,16 +2258,16 @@  discard block
 block discarded – undo
2258 2258
 	 *	  @param	  int		$addthirdparty		1=Add also a record for thirdparty email
2259 2259
 	 *    @return     array       					Array of contacts emails
2260 2260
 	 */
2261
-	function thirdparty_and_contact_email_array($addthirdparty=0)
2261
+	function thirdparty_and_contact_email_array($addthirdparty = 0)
2262 2262
 	{
2263 2263
         // phpcs:enable
2264 2264
 		global $langs;
2265 2265
 
2266
-		$contact_emails = $this->contact_property_array('email',1);
2266
+		$contact_emails = $this->contact_property_array('email', 1);
2267 2267
 		if ($this->email && $addthirdparty)
2268 2268
 		{
2269
-			if (empty($this->name)) $this->name=$this->nom;
2270
-			$contact_emails['thirdparty']=$langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->email.">";
2269
+			if (empty($this->name)) $this->name = $this->nom;
2270
+			$contact_emails['thirdparty'] = $langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name, 16)." <".$this->email.">";
2271 2271
 		}
2272 2272
 		//var_dump($contact_emails)
2273 2273
 		return $contact_emails;
@@ -2286,11 +2286,11 @@  discard block
 block discarded – undo
2286 2286
 
2287 2287
 		$contact_phone = $this->contact_property_array('mobile');
2288 2288
 
2289
-		if (! empty($this->phone))	// If a phone of thirdparty is defined, we add it ot mobile of contacts
2289
+		if (!empty($this->phone))	// If a phone of thirdparty is defined, we add it ot mobile of contacts
2290 2290
 		{
2291
-			if (empty($this->name)) $this->name=$this->nom;
2291
+			if (empty($this->name)) $this->name = $this->nom;
2292 2292
 			// TODO: Tester si tel non deja present dans tableau contact
2293
-			$contact_phone['thirdparty']=$langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->phone.">";
2293
+			$contact_phone['thirdparty'] = $langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name, 16)." <".$this->phone.">";
2294 2294
 		}
2295 2295
 		return $contact_phone;
2296 2296
 	}
@@ -2303,7 +2303,7 @@  discard block
 block discarded – undo
2303 2303
 	 * 	@param	int		$hidedisabled		1=Hide contact if disabled
2304 2304
 	 *  @return array       				Array of contacts emails or mobile. Example: array(id=>'Name <email>')
2305 2305
 	 */
2306
-	function contact_property_array($mode='email', $hidedisabled=0)
2306
+	function contact_property_array($mode = 'email', $hidedisabled = 0)
2307 2307
 	{
2308 2308
         // phpcs:enable
2309 2309
 		global $langs;
@@ -2312,45 +2312,45 @@  discard block
 block discarded – undo
2312 2312
 
2313 2313
 
2314 2314
 		$sql = "SELECT rowid, email, statut, phone_mobile, lastname, poste, firstname";
2315
-		$sql.= " FROM ".MAIN_DB_PREFIX."socpeople";
2316
-		$sql.= " WHERE fk_soc = ".$this->id;
2315
+		$sql .= " FROM ".MAIN_DB_PREFIX."socpeople";
2316
+		$sql .= " WHERE fk_soc = ".$this->id;
2317 2317
 
2318
-		$resql=$this->db->query($sql);
2318
+		$resql = $this->db->query($sql);
2319 2319
 		if ($resql)
2320 2320
 		{
2321 2321
 			$nump = $this->db->num_rows($resql);
2322 2322
 			if ($nump)
2323 2323
 			{
2324
-				$sepa="("; $sepb=")";
2324
+				$sepa = "("; $sepb = ")";
2325 2325
 				if ($mode == 'email')
2326 2326
 				{
2327 2327
 					//$sepa="&lt;"; $sepb="&gt;";
2328
-					$sepa="<"; $sepb=">";
2328
+					$sepa = "<"; $sepb = ">";
2329 2329
 				}
2330 2330
 				$i = 0;
2331 2331
 				while ($i < $nump)
2332 2332
 				{
2333 2333
 					$obj = $this->db->fetch_object($resql);
2334
-					if ($mode == 'email') $property=$obj->email;
2335
-					else if ($mode == 'mobile') $property=$obj->phone_mobile;
2336
-					else $property=$obj->$mode;
2334
+					if ($mode == 'email') $property = $obj->email;
2335
+					else if ($mode == 'mobile') $property = $obj->phone_mobile;
2336
+					else $property = $obj->$mode;
2337 2337
 
2338 2338
 					// Show all contact. If hidedisabled is 1, showonly contacts with status = 1
2339 2339
 					if ($obj->statut == 1 || empty($hidedisabled))
2340 2340
 					{
2341 2341
 						if (empty($property))
2342 2342
 						{
2343
-							if ($mode == 'email') $property=$langs->transnoentitiesnoconv("NoEMail");
2344
-							else if ($mode == 'mobile') $property=$langs->transnoentitiesnoconv("NoMobilePhone");
2343
+							if ($mode == 'email') $property = $langs->transnoentitiesnoconv("NoEMail");
2344
+							else if ($mode == 'mobile') $property = $langs->transnoentitiesnoconv("NoMobilePhone");
2345 2345
 						}
2346 2346
 
2347 2347
 						if (!empty($obj->poste))
2348 2348
 						{
2349
-							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname,$obj->lastname)).($obj->poste?" - ".$obj->poste:"").(($mode != 'poste' && $property)?" ".$sepa.$property.$sepb:'');
2349
+							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname, $obj->lastname)).($obj->poste ? " - ".$obj->poste : "").(($mode != 'poste' && $property) ? " ".$sepa.$property.$sepb : '');
2350 2350
 						}
2351 2351
 						else
2352 2352
 						{
2353
-							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname,$obj->lastname)).(($mode != 'poste' && $property)?" ".$sepa.$property.$sepb:'');
2353
+							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname, $obj->lastname)).(($mode != 'poste' && $property) ? " ".$sepa.$property.$sepb : '');
2354 2354
 						}
2355 2355
 					}
2356 2356
 					$i++;
@@ -2377,7 +2377,7 @@  discard block
 block discarded – undo
2377 2377
 		$contacts = array();
2378 2378
 
2379 2379
 		$sql = "SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id;
2380
-		$resql=$this->db->query($sql);
2380
+		$resql = $this->db->query($sql);
2381 2381
 		if ($resql)
2382 2382
 		{
2383 2383
 			$nump = $this->db->num_rows($resql);
@@ -2387,7 +2387,7 @@  discard block
 block discarded – undo
2387 2387
 				while ($i < $nump)
2388 2388
 				{
2389 2389
 					$obj = $this->db->fetch_object($resql);
2390
-					$contacts[$obj->rowid] = dolGetFirstLastname($obj->firstname,$obj->lastname);
2390
+					$contacts[$obj->rowid] = dolGetFirstLastname($obj->firstname, $obj->lastname);
2391 2391
 					$i++;
2392 2392
 				}
2393 2393
 			}
@@ -2408,11 +2408,11 @@  discard block
 block discarded – undo
2408 2408
 	function contact_array_objects()
2409 2409
 	{
2410 2410
         // phpcs:enable
2411
-		require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
2411
+		require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
2412 2412
 		$contacts = array();
2413 2413
 
2414 2414
 		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id;
2415
-		$resql=$this->db->query($sql);
2415
+		$resql = $this->db->query($sql);
2416 2416
 		if ($resql)
2417 2417
 		{
2418 2418
 			$nump = $this->db->num_rows($resql);
@@ -2444,18 +2444,18 @@  discard block
 block discarded – undo
2444 2444
 	 *  @param  string	$mode       'email' or 'mobile'
2445 2445
 	 *  @return string  			Email of contact with format: "Full name <email>"
2446 2446
 	 */
2447
-	function contact_get_property($rowid,$mode)
2447
+	function contact_get_property($rowid, $mode)
2448 2448
 	{
2449 2449
         // phpcs:enable
2450
-		$contact_property='';
2450
+		$contact_property = '';
2451 2451
 
2452 2452
 		if (empty($rowid)) return '';
2453 2453
 
2454 2454
 		$sql = "SELECT rowid, email, phone_mobile, lastname, firstname";
2455
-		$sql.= " FROM ".MAIN_DB_PREFIX."socpeople";
2456
-		$sql.= " WHERE rowid = '".$rowid."'";
2455
+		$sql .= " FROM ".MAIN_DB_PREFIX."socpeople";
2456
+		$sql .= " WHERE rowid = '".$rowid."'";
2457 2457
 
2458
-		$resql=$this->db->query($sql);
2458
+		$resql = $this->db->query($sql);
2459 2459
 		if ($resql)
2460 2460
 		{
2461 2461
 			$nump = $this->db->num_rows($resql);
@@ -2483,13 +2483,13 @@  discard block
 block discarded – undo
2483 2483
 	 *	@param	string	$mode	'label' or 'rum' or 'format'
2484 2484
 	 *  @return	string			Bank number
2485 2485
 	 */
2486
-	function display_rib($mode='label')
2486
+	function display_rib($mode = 'label')
2487 2487
 	{
2488 2488
         // phpcs:enable
2489
-		require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
2489
+		require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
2490 2490
 
2491 2491
 		$bac = new CompanyBankAccount($this->db);
2492
-		$bac->fetch(0,$this->id);
2492
+		$bac->fetch(0, $this->id);
2493 2493
 
2494 2494
 		if ($mode == 'label')
2495 2495
 		{
@@ -2499,7 +2499,7 @@  discard block
 block discarded – undo
2499 2499
 		{
2500 2500
 			if (empty($bac->rum))
2501 2501
 			{
2502
-				require_once DOL_DOCUMENT_ROOT . '/compta/prelevement/class/bonprelevement.class.php';
2502
+				require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
2503 2503
 				$prelevement = new BonPrelevement($this->db);
2504 2504
 				$bac->fetch_thirdparty();
2505 2505
 				$bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id);
@@ -2523,7 +2523,7 @@  discard block
 block discarded – undo
2523 2523
 	function get_all_rib()
2524 2524
 	{
2525 2525
         // phpcs:enable
2526
-		require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
2526
+		require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
2527 2527
 		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_rib WHERE type='ban' AND fk_soc = ".$this->id;
2528 2528
 		$result = $this->db->query($sql);
2529 2529
 		if (!$result) {
@@ -2553,23 +2553,23 @@  discard block
 block discarded – undo
2553 2553
 	 *	@param	int			$type		Should be 0 to say customer
2554 2554
 	 *  @return void
2555 2555
 	 */
2556
-	function get_codeclient($objsoc=0,$type=0)
2556
+	function get_codeclient($objsoc = 0, $type = 0)
2557 2557
 	{
2558 2558
         // phpcs:enable
2559 2559
 		global $conf;
2560
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2560
+		if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2561 2561
 		{
2562
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2562
+			$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2563 2563
 
2564
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2564
+			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2565 2565
 			foreach ($dirsociete as $dirroot)
2566 2566
 			{
2567
-				$res=dol_include_once($dirroot.$module.'.php');
2567
+				$res = dol_include_once($dirroot.$module.'.php');
2568 2568
 				if ($res) break;
2569 2569
 			}
2570 2570
 			$mod = new $module();
2571 2571
 
2572
-			$this->code_client = $mod->getNextValue($objsoc,$type);
2572
+			$this->code_client = $mod->getNextValue($objsoc, $type);
2573 2573
 			$this->prefixCustomerIsRequired = $mod->prefixIsRequired;
2574 2574
 
2575 2575
 			dol_syslog(get_class($this)."::get_codeclient code_client=".$this->code_client." module=".$module);
@@ -2585,23 +2585,23 @@  discard block
 block discarded – undo
2585 2585
 	 *	@param	int			$type		Should be 1 to say supplier
2586 2586
 	 *  @return void
2587 2587
 	 */
2588
-	function get_codefournisseur($objsoc=0,$type=1)
2588
+	function get_codefournisseur($objsoc = 0, $type = 1)
2589 2589
 	{
2590 2590
         // phpcs:enable
2591 2591
 		global $conf;
2592
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2592
+		if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2593 2593
 		{
2594
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2594
+			$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2595 2595
 
2596
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2596
+			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2597 2597
 			foreach ($dirsociete as $dirroot)
2598 2598
 			{
2599
-				$res=dol_include_once($dirroot.$module.'.php');
2599
+				$res = dol_include_once($dirroot.$module.'.php');
2600 2600
 				if ($res) break;
2601 2601
 			}
2602 2602
 			$mod = new $module();
2603 2603
 
2604
-			$this->code_fournisseur = $mod->getNextValue($objsoc,$type);
2604
+			$this->code_fournisseur = $mod->getNextValue($objsoc, $type);
2605 2605
 
2606 2606
 			dol_syslog(get_class($this)."::get_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$module);
2607 2607
 		}
@@ -2618,23 +2618,23 @@  discard block
 block discarded – undo
2618 2618
 	{
2619 2619
         // phpcs:enable
2620 2620
 		global $conf;
2621
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2621
+		if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2622 2622
 		{
2623
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2623
+			$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2624 2624
 
2625
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2625
+			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2626 2626
 			foreach ($dirsociete as $dirroot)
2627 2627
 			{
2628
-				$res=dol_include_once($dirroot.$module.'.php');
2628
+				$res = dol_include_once($dirroot.$module.'.php');
2629 2629
 				if ($res) break;
2630 2630
 			}
2631 2631
 
2632 2632
 			$mod = new $module();
2633 2633
 
2634 2634
 			dol_syslog(get_class($this)."::codeclient_modifiable code_client=".$this->code_client." module=".$module);
2635
-			if ($mod->code_modifiable_null && ! $this->code_client) return 1;
2635
+			if ($mod->code_modifiable_null && !$this->code_client) return 1;
2636 2636
 			if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) return 1;
2637
-			if ($mod->code_modifiable) return 1;	// A mettre en dernier
2637
+			if ($mod->code_modifiable) return 1; // A mettre en dernier
2638 2638
 			return 0;
2639 2639
 		}
2640 2640
 		else
@@ -2654,23 +2654,23 @@  discard block
 block discarded – undo
2654 2654
 	{
2655 2655
         // phpcs:enable
2656 2656
 		global $conf;
2657
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2657
+		if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2658 2658
 		{
2659
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2659
+			$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2660 2660
 
2661
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2661
+			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2662 2662
 			foreach ($dirsociete as $dirroot)
2663 2663
 			{
2664
-				$res=dol_include_once($dirroot.$module.'.php');
2664
+				$res = dol_include_once($dirroot.$module.'.php');
2665 2665
 				if ($res) break;
2666 2666
 			}
2667 2667
 
2668 2668
 			$mod = new $module();
2669 2669
 
2670 2670
 			dol_syslog(get_class($this)."::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur." module=".$module);
2671
-			if ($mod->code_modifiable_null && ! $this->code_fournisseur) return 1;
2671
+			if ($mod->code_modifiable_null && !$this->code_fournisseur) return 1;
2672 2672
 			if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) return 1;
2673
-			if ($mod->code_modifiable) return 1;	// A mettre en dernier
2673
+			if ($mod->code_modifiable) return 1; // A mettre en dernier
2674 2674
 			return 0;
2675 2675
 		}
2676 2676
 		else
@@ -2694,14 +2694,14 @@  discard block
 block discarded – undo
2694 2694
 	{
2695 2695
         // phpcs:enable
2696 2696
 		global $conf;
2697
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2697
+		if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2698 2698
 		{
2699
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2699
+			$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2700 2700
 
2701
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2701
+			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2702 2702
 			foreach ($dirsociete as $dirroot)
2703 2703
 			{
2704
-				$res=dol_include_once($dirroot.$module.'.php');
2704
+				$res = dol_include_once($dirroot.$module.'.php');
2705 2705
 				if ($res) break;
2706 2706
 			}
2707 2707
 
@@ -2731,14 +2731,14 @@  discard block
 block discarded – undo
2731 2731
 	{
2732 2732
         // phpcs:enable
2733 2733
 		global $conf;
2734
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2734
+		if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2735 2735
 		{
2736
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2736
+			$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2737 2737
 
2738
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2738
+			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2739 2739
 			foreach ($dirsociete as $dirroot)
2740 2740
 			{
2741
-				$res=dol_include_once($dirroot.$module.'.php');
2741
+				$res = dol_include_once($dirroot.$module.'.php');
2742 2742
 				if ($res) break;
2743 2743
 			}
2744 2744
 
@@ -2768,13 +2768,13 @@  discard block
 block discarded – undo
2768 2768
         // phpcs:enable
2769 2769
 		global $conf;
2770 2770
 
2771
-		if (! empty($conf->global->SOCIETE_CODECOMPTA_ADDON))
2771
+		if (!empty($conf->global->SOCIETE_CODECOMPTA_ADDON))
2772 2772
 		{
2773
-			$res=false;
2774
-			$dirsociete=array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2773
+			$res = false;
2774
+			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2775 2775
 			foreach ($dirsociete as $dirroot)
2776 2776
 			{
2777
-				$res=dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.'.php');
2777
+				$res = dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.'.php');
2778 2778
 				if ($res) break;
2779 2779
 			}
2780 2780
 
@@ -2819,10 +2819,10 @@  discard block
 block discarded – undo
2819 2819
 		if ($this->id)
2820 2820
 		{
2821 2821
 			$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
2822
-			$sql.= " SET parent = ".($id > 0 ? $id : "null");
2823
-			$sql.= " WHERE rowid = " . $this->id;
2822
+			$sql .= " SET parent = ".($id > 0 ? $id : "null");
2823
+			$sql .= " WHERE rowid = ".$this->id;
2824 2824
 			dol_syslog(get_class($this).'::set_parent', LOG_DEBUG);
2825
-			$resql=$this->db->query($sql);
2825
+			$resql = $this->db->query($sql);
2826 2826
 			if ($resql)
2827 2827
 			{
2828 2828
 				$this->parent = $id;
@@ -2848,28 +2848,28 @@  discard block
 block discarded – undo
2848 2848
         // phpcs:enable
2849 2849
 		global $conf;
2850 2850
 
2851
-	 	switch($idprof)
2851
+	 	switch ($idprof)
2852 2852
 		{
2853 2853
 			case 1:
2854
-				$ret=(!$conf->global->SOCIETE_IDPROF1_UNIQUE?false:true);
2854
+				$ret = (!$conf->global->SOCIETE_IDPROF1_UNIQUE ?false:true);
2855 2855
 				break;
2856 2856
 			case 2:
2857
-				$ret=(!$conf->global->SOCIETE_IDPROF2_UNIQUE?false:true);
2857
+				$ret = (!$conf->global->SOCIETE_IDPROF2_UNIQUE ?false:true);
2858 2858
 				break;
2859 2859
 			case 3:
2860
-				$ret=(!$conf->global->SOCIETE_IDPROF3_UNIQUE?false:true);
2860
+				$ret = (!$conf->global->SOCIETE_IDPROF3_UNIQUE ?false:true);
2861 2861
 				break;
2862 2862
 			case 4:
2863
-				$ret=(!$conf->global->SOCIETE_IDPROF4_UNIQUE?false:true);
2863
+				$ret = (!$conf->global->SOCIETE_IDPROF4_UNIQUE ?false:true);
2864 2864
 				break;
2865 2865
 			case 5:
2866
-				$ret=(!$conf->global->SOCIETE_IDPROF5_UNIQUE?false:true);
2866
+				$ret = (!$conf->global->SOCIETE_IDPROF5_UNIQUE ?false:true);
2867 2867
 				break;
2868 2868
 			case 6:
2869
-				$ret=(!$conf->global->SOCIETE_IDPROF6_UNIQUE?false:true);
2869
+				$ret = (!$conf->global->SOCIETE_IDPROF6_UNIQUE ?false:true);
2870 2870
 				break;
2871 2871
 			default:
2872
-				$ret=false;
2872
+				$ret = false;
2873 2873
 		}
2874 2874
 
2875 2875
 		return $ret;
@@ -2884,40 +2884,40 @@  discard block
 block discarded – undo
2884 2884
 	 *    @param	int		$socid		Id of thirdparty to exclude (if update)
2885 2885
 	 *    @return   boolean				True if exists, False if not
2886 2886
 	 */
2887
-	function id_prof_exists($idprof, $value, $socid=0)
2887
+	function id_prof_exists($idprof, $value, $socid = 0)
2888 2888
 	{
2889 2889
         // phpcs:enable
2890 2890
 		$field = $idprof;
2891 2891
 
2892
-	 	switch($idprof)	// For backward compatibility
2892
+	 	switch ($idprof)	// For backward compatibility
2893 2893
 		{
2894 2894
 			case '1':
2895 2895
 			case 'idprof1':
2896
-				$field="siren";
2896
+				$field = "siren";
2897 2897
 				break;
2898 2898
 			case '2':
2899 2899
 			case 'idprof2':
2900
-				$field="siret";
2900
+				$field = "siret";
2901 2901
 				break;
2902 2902
 			case '3':
2903 2903
 			case 'idprof3':
2904
-				$field="ape";
2904
+				$field = "ape";
2905 2905
 				break;
2906 2906
 			case '4':
2907 2907
 			case 'idprof4':
2908
-				$field="idprof4";
2908
+				$field = "idprof4";
2909 2909
 				break;
2910 2910
 			case '5':
2911
-				$field="idprof5";
2911
+				$field = "idprof5";
2912 2912
 				break;
2913 2913
 			case '6':
2914
-				$field="idprof6";
2914
+				$field = "idprof6";
2915 2915
 				break;
2916 2916
 	 	}
2917 2917
 
2918 2918
 		 //Verify duplicate entries
2919
-		$sql  = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$value."' AND entity IN (".getEntity('societe').")";
2920
-		if($socid) $sql .= " AND rowid <> ".$socid;
2919
+		$sql = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$value."' AND entity IN (".getEntity('societe').")";
2920
+		if ($socid) $sql .= " AND rowid <> ".$socid;
2921 2921
 		$resql = $this->db->query($sql);
2922 2922
 		if ($resql)
2923 2923
 		{
@@ -2944,20 +2944,20 @@  discard block
 block discarded – undo
2944 2944
 	 *  @return int             			<=0 if KO, >0 if OK
2945 2945
 	 *  TODO better to have this in a lib than into a business class
2946 2946
 	 */
2947
-	function id_prof_check($idprof,$soc)
2947
+	function id_prof_check($idprof, $soc)
2948 2948
 	{
2949 2949
         // phpcs:enable
2950 2950
 		global $conf;
2951 2951
 
2952
-		$ok=1;
2952
+		$ok = 1;
2953 2953
 
2954
-		if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) return 1;
2954
+		if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) return 1;
2955 2955
 
2956 2956
 		// Verifie SIREN si pays FR
2957 2957
 		if ($idprof == 1 && $soc->country_code == 'FR')
2958 2958
 		{
2959
-			$chaine=trim($this->idprof1);
2960
-			$chaine=preg_replace('/(\s)/','',$chaine);
2959
+			$chaine = trim($this->idprof1);
2960
+			$chaine = preg_replace('/(\s)/', '', $chaine);
2961 2961
 
2962 2962
 			if (!is_numeric($chaine)) return -1;
2963 2963
 			if (dol_strlen($chaine) != 9) return -1;
@@ -2967,7 +2967,7 @@  discard block
 block discarded – undo
2967 2967
 			// on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9
2968 2968
 			// on ajoute cette valeur à la somme totale
2969 2969
 
2970
-			for ($index = 0; $index < 9; $index ++)
2970
+			for ($index = 0; $index < 9; $index++)
2971 2971
 			{
2972 2972
 				$number = (int) $siren[$index];
2973 2973
 				if (($index % 2) != 0) { if (($number *= 2) > 9) $number -= 9; }
@@ -2981,8 +2981,8 @@  discard block
 block discarded – undo
2981 2981
 		// Verifie SIRET si pays FR
2982 2982
 		if ($idprof == 2 && $soc->country_code == 'FR')
2983 2983
 		{
2984
-			$chaine=trim($this->idprof2);
2985
-			$chaine=preg_replace('/(\s)/','',$chaine);
2984
+			$chaine = trim($this->idprof2);
2985
+			$chaine = preg_replace('/(\s)/', '', $chaine);
2986 2986
 
2987 2987
 			if (!is_numeric($chaine)) return -1;
2988 2988
 			if (dol_strlen($chaine) != 14) return -1;
@@ -2992,7 +2992,7 @@  discard block
 block discarded – undo
2992 2992
 			// on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9
2993 2993
 			// on ajoute cette valeur à la somme totale
2994 2994
 
2995
-			for ($index = 0; $index < 14; $index ++)
2995
+			for ($index = 0; $index < 14; $index++)
2996 2996
 			{
2997 2997
 				$number = (int) $chaine[$index];
2998 2998
 				if (($index % 2) == 0) { if (($number *= 2) > 9) $number -= 9; }
@@ -3007,11 +3007,11 @@  discard block
 block discarded – undo
3007 3007
 		//Returns: 1 if NIF ok, 2 if CIF ok, 3 if NIE ok, -1 if NIF bad, -2 if CIF bad, -3 if NIE bad, 0 if unexpected bad
3008 3008
 		if ($idprof == 1 && $soc->country_code == 'ES')
3009 3009
 		{
3010
-			$string=trim($this->idprof1);
3011
-			$string=preg_replace('/(\s)/','',$string);
3010
+			$string = trim($this->idprof1);
3011
+			$string = preg_replace('/(\s)/', '', $string);
3012 3012
 			$string = strtoupper($string);
3013 3013
 
3014
-			for ($i = 0; $i < 9; $i ++)
3014
+			for ($i = 0; $i < 9; $i++)
3015 3015
 			$num[$i] = substr($string, $i, 1);
3016 3016
 
3017 3017
 			//Check format
@@ -3028,7 +3028,7 @@  discard block
 block discarded – undo
3028 3028
 			//algorithm checking type code CIF
3029 3029
 			$sum = $num[2] + $num[4] + $num[6];
3030 3030
 			for ($i = 1; $i < 8; $i += 2)
3031
-			$sum += intval(substr((2 * $num[$i]),0,1)) + intval(substr((2 * $num[$i]),1,1));
3031
+			$sum += intval(substr((2 * $num[$i]), 0, 1)) + intval(substr((2 * $num[$i]), 1, 1));
3032 3032
 			$n = 10 - substr($sum, strlen($sum) - 1, 1);
3033 3033
 
3034 3034
 			//Chek special NIF
@@ -3054,7 +3054,7 @@  discard block
 block discarded – undo
3054 3054
 
3055 3055
 			//Check NIE XYZ
3056 3056
 			if (preg_match('/^[XYZ]{1}/', $string))
3057
-				if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X','Y','Z'), array('0','1','2'), $string), 0, 8) % 23, 1))
3057
+				if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X', 'Y', 'Z'), array('0', '1', '2'), $string), 0, 8) % 23, 1))
3058 3058
 				return 3;
3059 3059
 				else
3060 3060
 				return -3;
@@ -3067,10 +3067,10 @@  discard block
 block discarded – undo
3067 3067
 		//Returns: 1 if NIF ok, -1 if NIF bad, 0 if unexpected bad
3068 3068
 		if ($idprof == 1 && $soc->country_code == 'PT')
3069 3069
 		{
3070
-			$string=trim($this->idprof1);
3071
-			$string=preg_replace('/(\s)/','',$string);
3070
+			$string = trim($this->idprof1);
3071
+			$string = preg_replace('/(\s)/', '', $string);
3072 3072
 
3073
-			for ($i = 0; $i < 9; $i ++) {
3073
+			for ($i = 0; $i < 9; $i++) {
3074 3074
 				$num[$i] = substr($string, $i, 1);
3075 3075
 			}
3076 3076
 
@@ -3095,38 +3095,38 @@  discard block
 block discarded – undo
3095 3095
 	 *   @return	string          		Url or empty string if no URL known
3096 3096
 	 *   TODO better in a lib than into business class
3097 3097
 	 */
3098
-	function id_prof_url($idprof,$thirdparty)
3098
+	function id_prof_url($idprof, $thirdparty)
3099 3099
 	{
3100 3100
         // phpcs:enable
3101
-		global $conf,$langs,$hookmanager;
3101
+		global $conf, $langs, $hookmanager;
3102 3102
 
3103
-		$url='';
3103
+		$url = '';
3104 3104
 		$action = '';
3105 3105
 
3106 3106
 		$hookmanager->initHooks(array('idprofurl'));
3107
-		$parameters=array('idprof'=>$idprof, 'company'=>$thirdparty);
3108
-		$reshook=$hookmanager->executeHooks('getIdProfUrl',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
3107
+		$parameters = array('idprof'=>$idprof, 'company'=>$thirdparty);
3108
+		$reshook = $hookmanager->executeHooks('getIdProfUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
3109 3109
 		if (empty($reshook)) {
3110
-			if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
3110
+			if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
3111 3111
 				return '';
3112 3112
 			}
3113 3113
 
3114 3114
 			// TODO Move links to validate professional ID into a dictionary table "country" + "link"
3115 3115
             $strippedIdProf1 = str_replace(' ', '', $thirdparty->idprof1);
3116 3116
 			if ($idprof == 1 && $thirdparty->country_code == 'FR') {
3117
-				$url='http://www.societe.com/cgi-bin/search?champs='.$strippedIdProf1;    // See also http://avis-situation-sirene.insee.fr/
3117
+				$url = 'http://www.societe.com/cgi-bin/search?champs='.$strippedIdProf1; // See also http://avis-situation-sirene.insee.fr/
3118 3118
 			}
3119 3119
 			if ($idprof == 1 && ($thirdparty->country_code == 'GB' || $thirdparty->country_code == 'UK')) {
3120
-				$url='https://beta.companieshouse.gov.uk/company/'.$strippedIdProf1;
3120
+				$url = 'https://beta.companieshouse.gov.uk/company/'.$strippedIdProf1;
3121 3121
 			}
3122 3122
 			if ($idprof == 1 && $thirdparty->country_code == 'ES') {
3123
-				$url='http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$strippedIdProf1;
3123
+				$url = 'http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$strippedIdProf1;
3124 3124
 			}
3125 3125
 			if ($idprof == 1 && $thirdparty->country_code == 'IN') {
3126
-				$url='http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$strippedIdProf1.';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
3126
+				$url = 'http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$strippedIdProf1.';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
3127 3127
 			}
3128 3128
 			if ($idprof == 1 && $thirdparty->country_code == 'PT') {
3129
-				$url='http://www.nif.pt/'.$strippedIdProf1;
3129
+				$url = 'http://www.nif.pt/'.$strippedIdProf1;
3130 3130
 			}
3131 3131
 
3132 3132
 			if ($url) {
@@ -3149,7 +3149,7 @@  discard block
 block discarded – undo
3149 3149
 	function has_projects()
3150 3150
 	{
3151 3151
         // phpcs:enable
3152
-		$sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = ' . $this->id;
3152
+		$sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = '.$this->id;
3153 3153
 		$resql = $this->db->query($sql);
3154 3154
 		if ($resql)
3155 3155
 		{
@@ -3175,11 +3175,11 @@  discard block
 block discarded – undo
3175 3175
 	function info($id)
3176 3176
 	{
3177 3177
 		$sql = "SELECT s.rowid, s.nom as name, s.datec as date_creation, tms as date_modification,";
3178
-		$sql.= " fk_user_creat, fk_user_modif";
3179
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
3180
-		$sql.= " WHERE s.rowid = ".$id;
3178
+		$sql .= " fk_user_creat, fk_user_modif";
3179
+		$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
3180
+		$sql .= " WHERE s.rowid = ".$id;
3181 3181
 
3182
-		$result=$this->db->query($sql);
3182
+		$result = $this->db->query($sql);
3183 3183
 		if ($result)
3184 3184
 		{
3185 3185
 			if ($this->db->num_rows($result))
@@ -3191,7 +3191,7 @@  discard block
 block discarded – undo
3191 3191
 				if ($obj->fk_user_creat) {
3192 3192
 					$cuser = new User($this->db);
3193 3193
 					$cuser->fetch($obj->fk_user_creat);
3194
-					$this->user_creation     = $cuser;
3194
+					$this->user_creation = $cuser;
3195 3195
 				}
3196 3196
 
3197 3197
 				if ($obj->fk_user_modif) {
@@ -3200,7 +3200,7 @@  discard block
 block discarded – undo
3200 3200
 					$this->user_modification = $muser;
3201 3201
 				}
3202 3202
 
3203
-				$this->ref			     = $obj->name;
3203
+				$this->ref = $obj->name;
3204 3204
 				$this->date_creation     = $this->db->jdate($obj->date_creation);
3205 3205
 				$this->date_modification = $this->db->jdate($obj->date_modification);
3206 3206
 			}
@@ -3223,13 +3223,13 @@  discard block
 block discarded – undo
3223 3223
 		global $conf;
3224 3224
 
3225 3225
 		// Define if third party is treated as company (or not) when nature is unknown
3226
-		$isacompany=empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES)?0:1; // 0 by default
3227
-		if (! empty($this->tva_intra)) $isacompany=1;
3228
-		else if (! empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN')
3226
+		$isacompany = empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES) ? 0 : 1; // 0 by default
3227
+		if (!empty($this->tva_intra)) $isacompany = 1;
3228
+		else if (!empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN')
3229 3229
 		{
3230 3230
 			// TODO Add a field is_a_company into dictionary
3231
-			if (preg_match('/^TE_PRIVATE/', $this->typent_code)) $isacompany=0;
3232
-			else $isacompany=1;
3231
+			if (preg_match('/^TE_PRIVATE/', $this->typent_code)) $isacompany = 0;
3232
+			else $isacompany = 1;
3233 3233
 		}
3234 3234
 
3235 3235
 		return $isacompany;
@@ -3257,13 +3257,13 @@  discard block
 block discarded – undo
3257 3257
         // phpcs:enable
3258 3258
 		$this->SupplierCategories = array();
3259 3259
 		$sql = "SELECT rowid, label";
3260
-		$sql.= " FROM ".MAIN_DB_PREFIX."categorie";
3261
-		$sql.= " WHERE type = ".Categorie::TYPE_SUPPLIER;
3260
+		$sql .= " FROM ".MAIN_DB_PREFIX."categorie";
3261
+		$sql .= " WHERE type = ".Categorie::TYPE_SUPPLIER;
3262 3262
 
3263
-		$resql=$this->db->query($sql);
3263
+		$resql = $this->db->query($sql);
3264 3264
 		if ($resql)
3265 3265
 		{
3266
-			while ($obj = $this->db->fetch_object($resql) )
3266
+			while ($obj = $this->db->fetch_object($resql))
3267 3267
 			{
3268 3268
 				$this->SupplierCategories[$obj->rowid] = $obj->label;
3269 3269
 			}
@@ -3288,9 +3288,9 @@  discard block
 block discarded – undo
3288 3288
 		if ($categorie_id > 0 && $this->id > 0)
3289 3289
 		{
3290 3290
 			$sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_fournisseur (fk_categorie, fk_soc) ";
3291
-			$sql.= " VALUES (".$categorie_id.", ".$this->id.")";
3291
+			$sql .= " VALUES (".$categorie_id.", ".$this->id.")";
3292 3292
 
3293
-			if ($resql=$this->db->query($sql)) return 0;
3293
+			if ($resql = $this->db->query($sql)) return 0;
3294 3294
 		}
3295 3295
 		else
3296 3296
 		{
@@ -3310,48 +3310,48 @@  discard block
 block discarded – undo
3310 3310
 	 *  @param	string		$customercode	Customer code
3311 3311
 	 *  @return int							<0 if KO, id of created account if OK
3312 3312
 	 */
3313
-	function create_from_member(Adherent $member, $socname='', $socalias='', $customercode='')
3313
+	function create_from_member(Adherent $member, $socname = '', $socalias = '', $customercode = '')
3314 3314
 	{
3315 3315
         // phpcs:enable
3316
-		global $user,$langs;
3316
+		global $user, $langs;
3317 3317
 
3318 3318
 		dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG);
3319 3319
 
3320
-		$name = $socname?$socname:$member->societe;
3321
-		if (empty($name)) $name=$member->getFullName($langs);
3320
+		$name = $socname ? $socname : $member->societe;
3321
+		if (empty($name)) $name = $member->getFullName($langs);
3322 3322
 
3323
-		$alias = $socalias?$socalias:'';
3323
+		$alias = $socalias ? $socalias : '';
3324 3324
 
3325 3325
 		// Positionne parametres
3326
-		$this->nom=$name;				// TODO deprecated
3327
-		$this->name=$name;
3328
-		$this->name_alias=$alias;
3329
-		$this->address=$member->address;
3330
-		$this->zip=$member->zip;
3331
-		$this->town=$member->town;
3332
-		$this->country_code=$member->country_code;
3333
-		$this->country_id=$member->country_id;
3334
-		$this->phone=$member->phone;       // Prof phone
3335
-		$this->email=$member->email;
3336
-		$this->skype=$member->skype;
3337
-		$this->twitter=$member->twitter;
3338
-		$this->facebook=$member->facebook;
3339
-
3340
-		$this->client = 1;				// A member is a customer by default
3341
-		$this->code_client = ($customercode?$customercode:-1);
3326
+		$this->nom = $name; // TODO deprecated
3327
+		$this->name = $name;
3328
+		$this->name_alias = $alias;
3329
+		$this->address = $member->address;
3330
+		$this->zip = $member->zip;
3331
+		$this->town = $member->town;
3332
+		$this->country_code = $member->country_code;
3333
+		$this->country_id = $member->country_id;
3334
+		$this->phone = $member->phone; // Prof phone
3335
+		$this->email = $member->email;
3336
+		$this->skype = $member->skype;
3337
+		$this->twitter = $member->twitter;
3338
+		$this->facebook = $member->facebook;
3339
+
3340
+		$this->client = 1; // A member is a customer by default
3341
+		$this->code_client = ($customercode ? $customercode : -1);
3342 3342
 		$this->code_fournisseur = -1;
3343 3343
 
3344 3344
 		$this->db->begin();
3345 3345
 
3346 3346
 		// Cree et positionne $this->id
3347
-		$result=$this->create($user);
3347
+		$result = $this->create($user);
3348 3348
 		if ($result >= 0)
3349 3349
 		{
3350 3350
 			$sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
3351
-			$sql.= " SET fk_soc=".$this->id;
3352
-			$sql.= " WHERE rowid=".$member->id;
3351
+			$sql .= " SET fk_soc=".$this->id;
3352
+			$sql .= " WHERE rowid=".$member->id;
3353 3353
 
3354
-			$resql=$this->db->query($sql);
3354
+			$resql = $this->db->query($sql);
3355 3355
 			if ($resql)
3356 3356
 			{
3357 3357
 				$this->db->commit();
@@ -3359,7 +3359,7 @@  discard block
 block discarded – undo
3359 3359
 			}
3360 3360
 			else
3361 3361
 			{
3362
-				$this->error=$this->db->error();
3362
+				$this->error = $this->db->error();
3363 3363
 
3364 3364
 				$this->db->rollback();
3365 3365
 				return -1;
@@ -3368,7 +3368,7 @@  discard block
 block discarded – undo
3368 3368
 		else
3369 3369
 		{
3370 3370
 			// $this->error deja positionne
3371
-			dol_syslog(get_class($this)."::create_from_member - 2 - ".$this->error." - ".join(',',$this->errors), LOG_ERR);
3371
+			dol_syslog(get_class($this)."::create_from_member - 2 - ".$this->error." - ".join(',', $this->errors), LOG_ERR);
3372 3372
 
3373 3373
 			$this->db->rollback();
3374 3374
 			return $result;
@@ -3385,68 +3385,68 @@  discard block
 block discarded – undo
3385 3385
 	{
3386 3386
 		global $langs;
3387 3387
 
3388
-		$this->id=0;
3389
-		$this->name=empty($conf->global->MAIN_INFO_SOCIETE_NOM)?'':$conf->global->MAIN_INFO_SOCIETE_NOM;
3390
-		$this->address=empty($conf->global->MAIN_INFO_SOCIETE_ADDRESS)?'':$conf->global->MAIN_INFO_SOCIETE_ADDRESS;
3391
-		$this->zip=empty($conf->global->MAIN_INFO_SOCIETE_ZIP)?'':$conf->global->MAIN_INFO_SOCIETE_ZIP;
3392
-		$this->town=empty($conf->global->MAIN_INFO_SOCIETE_TOWN)?'':$conf->global->MAIN_INFO_SOCIETE_TOWN;
3393
-		$this->state_id=empty($conf->global->MAIN_INFO_SOCIETE_STATE)?'':$conf->global->MAIN_INFO_SOCIETE_STATE;
3394
-		$this->region_code=empty($conf->global->MAIN_INFO_SOCIETE_REGION)?'':$conf->global->MAIN_INFO_SOCIETE_REGION;
3395
-		$this->object=empty($conf->global->MAIN_INFO_SOCIETE_OBJECT)?'':$conf->global->MAIN_INFO_SOCIETE_OBJECT;
3388
+		$this->id = 0;
3389
+		$this->name = empty($conf->global->MAIN_INFO_SOCIETE_NOM) ? '' : $conf->global->MAIN_INFO_SOCIETE_NOM;
3390
+		$this->address = empty($conf->global->MAIN_INFO_SOCIETE_ADDRESS) ? '' : $conf->global->MAIN_INFO_SOCIETE_ADDRESS;
3391
+		$this->zip = empty($conf->global->MAIN_INFO_SOCIETE_ZIP) ? '' : $conf->global->MAIN_INFO_SOCIETE_ZIP;
3392
+		$this->town = empty($conf->global->MAIN_INFO_SOCIETE_TOWN) ? '' : $conf->global->MAIN_INFO_SOCIETE_TOWN;
3393
+		$this->state_id = empty($conf->global->MAIN_INFO_SOCIETE_STATE) ? '' : $conf->global->MAIN_INFO_SOCIETE_STATE;
3394
+		$this->region_code = empty($conf->global->MAIN_INFO_SOCIETE_REGION) ? '' : $conf->global->MAIN_INFO_SOCIETE_REGION;
3395
+		$this->object = empty($conf->global->MAIN_INFO_SOCIETE_OBJECT) ? '' : $conf->global->MAIN_INFO_SOCIETE_OBJECT;
3396 3396
 
3397
-		$this->note_private=empty($conf->global->MAIN_INFO_SOCIETE_NOTE)?'':$conf->global->MAIN_INFO_SOCIETE_NOTE;
3397
+		$this->note_private = empty($conf->global->MAIN_INFO_SOCIETE_NOTE) ? '' : $conf->global->MAIN_INFO_SOCIETE_NOTE;
3398 3398
 
3399
-		$this->nom=$this->name; 									// deprecated
3399
+		$this->nom = $this->name; // deprecated
3400 3400
 
3401 3401
 		// We define country_id, country_code and country
3402
-		$country_id=$country_code=$country_label='';
3403
-		if (! empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY))
3402
+		$country_id = $country_code = $country_label = '';
3403
+		if (!empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY))
3404 3404
 		{
3405
-			$tmp=explode(':',$conf->global->MAIN_INFO_SOCIETE_COUNTRY);
3406
-			$country_id=$tmp[0];
3407
-			if (! empty($tmp[1]))   // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label"
3405
+			$tmp = explode(':', $conf->global->MAIN_INFO_SOCIETE_COUNTRY);
3406
+			$country_id = $tmp[0];
3407
+			if (!empty($tmp[1]))   // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label"
3408 3408
 			{
3409
-				$country_code=$tmp[1];
3410
-				$country_label=$tmp[2];
3409
+				$country_code = $tmp[1];
3410
+				$country_label = $tmp[2];
3411 3411
 			}
3412 3412
 			else                    // For backward compatibility
3413 3413
 			{
3414 3414
 				dol_syslog("Your country setup use an old syntax. Reedit it using setup area.", LOG_ERR);
3415 3415
 				include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
3416
-				$country_code=getCountry($country_id,2,$this->db);  // This need a SQL request, but it's the old feature that should not be used anymore
3417
-				$country_label=getCountry($country_id,0,$this->db);  // This need a SQL request, but it's the old feature that should not be used anymore
3416
+				$country_code = getCountry($country_id, 2, $this->db); // This need a SQL request, but it's the old feature that should not be used anymore
3417
+				$country_label = getCountry($country_id, 0, $this->db); // This need a SQL request, but it's the old feature that should not be used anymore
3418 3418
 			}
3419 3419
 		}
3420
-		$this->country_id=$country_id;
3421
-		$this->country_code=$country_code;
3422
-		$this->country=$country_label;
3423
-		if (is_object($langs)) $this->country=($langs->trans('Country'.$country_code)!='Country'.$country_code)?$langs->trans('Country'.$country_code):$country_label;
3420
+		$this->country_id = $country_id;
3421
+		$this->country_code = $country_code;
3422
+		$this->country = $country_label;
3423
+		if (is_object($langs)) $this->country = ($langs->trans('Country'.$country_code) != 'Country'.$country_code) ? $langs->trans('Country'.$country_code) : $country_label;
3424 3424
 
3425
-		$this->phone=empty($conf->global->MAIN_INFO_SOCIETE_TEL)?'':$conf->global->MAIN_INFO_SOCIETE_TEL;
3426
-		$this->fax=empty($conf->global->MAIN_INFO_SOCIETE_FAX)?'':$conf->global->MAIN_INFO_SOCIETE_FAX;
3427
-		$this->url=empty($conf->global->MAIN_INFO_SOCIETE_WEB)?'':$conf->global->MAIN_INFO_SOCIETE_WEB;
3425
+		$this->phone = empty($conf->global->MAIN_INFO_SOCIETE_TEL) ? '' : $conf->global->MAIN_INFO_SOCIETE_TEL;
3426
+		$this->fax = empty($conf->global->MAIN_INFO_SOCIETE_FAX) ? '' : $conf->global->MAIN_INFO_SOCIETE_FAX;
3427
+		$this->url = empty($conf->global->MAIN_INFO_SOCIETE_WEB) ? '' : $conf->global->MAIN_INFO_SOCIETE_WEB;
3428 3428
 		// Id prof generiques
3429
-		$this->idprof1=empty($conf->global->MAIN_INFO_SIREN)?'':$conf->global->MAIN_INFO_SIREN;
3430
-		$this->idprof2=empty($conf->global->MAIN_INFO_SIRET)?'':$conf->global->MAIN_INFO_SIRET;
3431
-		$this->idprof3=empty($conf->global->MAIN_INFO_APE)?'':$conf->global->MAIN_INFO_APE;
3432
-		$this->idprof4=empty($conf->global->MAIN_INFO_RCS)?'':$conf->global->MAIN_INFO_RCS;
3433
-		$this->idprof5=empty($conf->global->MAIN_INFO_PROFID5)?'':$conf->global->MAIN_INFO_PROFID5;
3434
-		$this->idprof6=empty($conf->global->MAIN_INFO_PROFID6)?'':$conf->global->MAIN_INFO_PROFID6;
3435
-		$this->tva_intra=empty($conf->global->MAIN_INFO_TVAINTRA)?'':$conf->global->MAIN_INFO_TVAINTRA;	// VAT number, not necessarly INTRA.
3436
-		$this->managers=empty($conf->global->MAIN_INFO_SOCIETE_MANAGERS)?'':$conf->global->MAIN_INFO_SOCIETE_MANAGERS;
3437
-		$this->capital=empty($conf->global->MAIN_INFO_CAPITAL)?'':$conf->global->MAIN_INFO_CAPITAL;
3438
-		$this->forme_juridique_code=empty($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE)?'':$conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE;
3439
-		$this->email=empty($conf->global->MAIN_INFO_SOCIETE_MAIL)?'':$conf->global->MAIN_INFO_SOCIETE_MAIL;
3440
-		$this->logo=empty($conf->global->MAIN_INFO_SOCIETE_LOGO)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO;
3441
-		$this->logo_small=empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL;
3442
-		$this->logo_mini=empty($conf->global->MAIN_INFO_SOCIETE_LOGO_MINI)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
3429
+		$this->idprof1 = empty($conf->global->MAIN_INFO_SIREN) ? '' : $conf->global->MAIN_INFO_SIREN;
3430
+		$this->idprof2 = empty($conf->global->MAIN_INFO_SIRET) ? '' : $conf->global->MAIN_INFO_SIRET;
3431
+		$this->idprof3 = empty($conf->global->MAIN_INFO_APE) ? '' : $conf->global->MAIN_INFO_APE;
3432
+		$this->idprof4 = empty($conf->global->MAIN_INFO_RCS) ? '' : $conf->global->MAIN_INFO_RCS;
3433
+		$this->idprof5 = empty($conf->global->MAIN_INFO_PROFID5) ? '' : $conf->global->MAIN_INFO_PROFID5;
3434
+		$this->idprof6 = empty($conf->global->MAIN_INFO_PROFID6) ? '' : $conf->global->MAIN_INFO_PROFID6;
3435
+		$this->tva_intra = empty($conf->global->MAIN_INFO_TVAINTRA) ? '' : $conf->global->MAIN_INFO_TVAINTRA; // VAT number, not necessarly INTRA.
3436
+		$this->managers = empty($conf->global->MAIN_INFO_SOCIETE_MANAGERS) ? '' : $conf->global->MAIN_INFO_SOCIETE_MANAGERS;
3437
+		$this->capital = empty($conf->global->MAIN_INFO_CAPITAL) ? '' : $conf->global->MAIN_INFO_CAPITAL;
3438
+		$this->forme_juridique_code = empty($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE) ? '' : $conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE;
3439
+		$this->email = empty($conf->global->MAIN_INFO_SOCIETE_MAIL) ? '' : $conf->global->MAIN_INFO_SOCIETE_MAIL;
3440
+		$this->logo = empty($conf->global->MAIN_INFO_SOCIETE_LOGO) ? '' : $conf->global->MAIN_INFO_SOCIETE_LOGO;
3441
+		$this->logo_small = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL) ? '' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL;
3442
+		$this->logo_mini = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_MINI) ? '' : $conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
3443 3443
 
3444 3444
 		// Define if company use vat or not
3445
-		$this->tva_assuj=$conf->global->FACTURE_TVAOPTION;
3445
+		$this->tva_assuj = $conf->global->FACTURE_TVAOPTION;
3446 3446
 
3447 3447
 		// Define if company use local taxes
3448
-		$this->localtax1_assuj=((isset($conf->global->FACTURE_LOCAL_TAX1_OPTION) && ($conf->global->FACTURE_LOCAL_TAX1_OPTION=='1' || $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on'))?1:0);
3449
-		$this->localtax2_assuj=((isset($conf->global->FACTURE_LOCAL_TAX2_OPTION) && ($conf->global->FACTURE_LOCAL_TAX2_OPTION=='1' || $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on'))?1:0);
3448
+		$this->localtax1_assuj = ((isset($conf->global->FACTURE_LOCAL_TAX1_OPTION) && ($conf->global->FACTURE_LOCAL_TAX1_OPTION == '1' || $conf->global->FACTURE_LOCAL_TAX1_OPTION == 'localtax1on')) ? 1 : 0);
3449
+		$this->localtax2_assuj = ((isset($conf->global->FACTURE_LOCAL_TAX2_OPTION) && ($conf->global->FACTURE_LOCAL_TAX2_OPTION == '1' || $conf->global->FACTURE_LOCAL_TAX2_OPTION == 'localtax2on')) ? 1 : 0);
3450 3450
 	}
3451 3451
 
3452 3452
 	/**
@@ -3458,48 +3458,48 @@  discard block
 block discarded – undo
3458 3458
 	 */
3459 3459
 	function initAsSpecimen()
3460 3460
 	{
3461
-		$now=dol_now();
3461
+		$now = dol_now();
3462 3462
 
3463 3463
 		// Initialize parameters
3464
-		$this->id=0;
3465
-		$this->name = 'THIRDPARTY SPECIMEN '.dol_print_date($now,'dayhourlog');
3466
-		$this->nom = $this->name;   // For backward compatibility
3464
+		$this->id = 0;
3465
+		$this->name = 'THIRDPARTY SPECIMEN '.dol_print_date($now, 'dayhourlog');
3466
+		$this->nom = $this->name; // For backward compatibility
3467 3467
 		$this->ref_ext = 'Ref ext';
3468
-		$this->specimen=1;
3469
-		$this->address='21 jump street';
3470
-		$this->zip='99999';
3471
-		$this->town='MyTown';
3472
-		$this->state_id=1;
3473
-		$this->state_code='AA';
3474
-		$this->state='MyState';
3475
-		$this->country_id=1;
3476
-		$this->country_code='FR';
3477
-		$this->email='[email protected]';
3478
-		$this->skype='tom.hanson';
3479
-		$this->twitter='tomhanson';
3480
-		$this->facebook='tomhanson';
3481
-		$this->url='http://www.specimen.com';
3482
-
3483
-		$this->phone='0909090901';
3484
-		$this->fax='0909090909';
3485
-
3486
-		$this->code_client='CC-'.dol_print_date($now,'dayhourlog');
3487
-		$this->code_fournisseur='SC-'.dol_print_date($now,'dayhourlog');
3488
-		$this->capital=10000;
3489
-		$this->client=1;
3490
-		$this->prospect=1;
3491
-		$this->fournisseur=1;
3492
-		$this->tva_assuj=1;
3493
-		$this->tva_intra='EU1234567';
3494
-		$this->note_public='This is a comment (public)';
3495
-		$this->note_private='This is a comment (private)';
3496
-
3497
-		$this->idprof1='idprof1';
3498
-		$this->idprof2='idprof2';
3499
-		$this->idprof3='idprof3';
3500
-		$this->idprof4='idprof4';
3501
-		$this->idprof5='idprof5';
3502
-		$this->idprof6='idprof6';
3468
+		$this->specimen = 1;
3469
+		$this->address = '21 jump street';
3470
+		$this->zip = '99999';
3471
+		$this->town = 'MyTown';
3472
+		$this->state_id = 1;
3473
+		$this->state_code = 'AA';
3474
+		$this->state = 'MyState';
3475
+		$this->country_id = 1;
3476
+		$this->country_code = 'FR';
3477
+		$this->email = '[email protected]';
3478
+		$this->skype = 'tom.hanson';
3479
+		$this->twitter = 'tomhanson';
3480
+		$this->facebook = 'tomhanson';
3481
+		$this->url = 'http://www.specimen.com';
3482
+
3483
+		$this->phone = '0909090901';
3484
+		$this->fax = '0909090909';
3485
+
3486
+		$this->code_client = 'CC-'.dol_print_date($now, 'dayhourlog');
3487
+		$this->code_fournisseur = 'SC-'.dol_print_date($now, 'dayhourlog');
3488
+		$this->capital = 10000;
3489
+		$this->client = 1;
3490
+		$this->prospect = 1;
3491
+		$this->fournisseur = 1;
3492
+		$this->tva_assuj = 1;
3493
+		$this->tva_intra = 'EU1234567';
3494
+		$this->note_public = 'This is a comment (public)';
3495
+		$this->note_private = 'This is a comment (private)';
3496
+
3497
+		$this->idprof1 = 'idprof1';
3498
+		$this->idprof2 = 'idprof2';
3499
+		$this->idprof3 = 'idprof3';
3500
+		$this->idprof4 = 'idprof4';
3501
+		$this->idprof5 = 'idprof5';
3502
+		$this->idprof6 = 'idprof6';
3503 3503
 	}
3504 3504
 
3505 3505
 	/**
@@ -3508,7 +3508,7 @@  discard block
 block discarded – undo
3508 3508
 	 *	@param		int		$localTaxNum	To get info for only localtax1 or localtax2
3509 3509
 	 *  @return		boolean					true or false
3510 3510
 	 */
3511
-	function useLocalTax($localTaxNum=0)
3511
+	function useLocalTax($localTaxNum = 0)
3512 3512
 	{
3513 3513
 		$sql  = "SELECT t.localtax1, t.localtax2";
3514 3514
 		$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
@@ -3519,7 +3519,7 @@  discard block
 block discarded – undo
3519 3519
 		elseif ($localTaxNum == 2) $sql .= " AND t.localtax2_type <> '0'";
3520 3520
 
3521 3521
 		dol_syslog("useLocalTax", LOG_DEBUG);
3522
-		$resql=$this->db->query($sql);
3522
+		$resql = $this->db->query($sql);
3523 3523
 		if ($resql)
3524 3524
 		{
3525 3525
    			return ($this->db->num_rows($resql) > 0);
@@ -3540,7 +3540,7 @@  discard block
 block discarded – undo
3540 3540
 		$sql .= " AND t.active = 1 AND t.recuperableonly = 1";
3541 3541
 
3542 3542
 		dol_syslog("useNPR", LOG_DEBUG);
3543
-		$resql=$this->db->query($sql);
3543
+		$resql = $this->db->query($sql);
3544 3544
 		if ($resql)
3545 3545
 		{
3546 3546
 			return ($this->db->num_rows($resql) > 0);
@@ -3561,15 +3561,15 @@  discard block
 block discarded – undo
3561 3561
 		$sql .= " AND r.active = 1";
3562 3562
 
3563 3563
 		dol_syslog("useRevenueStamp", LOG_DEBUG);
3564
-		$resql=$this->db->query($sql);
3564
+		$resql = $this->db->query($sql);
3565 3565
 		if ($resql)
3566 3566
 		{
3567
-			$obj=$this->db->fetch_object($resql);
3568
-   			return (($obj->nb > 0)?true:false);
3567
+			$obj = $this->db->fetch_object($resql);
3568
+   			return (($obj->nb > 0) ?true:false);
3569 3569
 		}
3570 3570
 		else
3571 3571
 		{
3572
-			$this->error=$this->db->lasterror();
3572
+			$this->error = $this->db->lasterror();
3573 3573
 			return false;
3574 3574
 		}
3575 3575
 	}
@@ -3596,11 +3596,11 @@  discard block
 block discarded – undo
3596 3596
         // phpcs:enable
3597 3597
 		global $langs;
3598 3598
 
3599
-		$lib=$langs->trans("ProspectLevel".$fk_prospectlevel);
3599
+		$lib = $langs->trans("ProspectLevel".$fk_prospectlevel);
3600 3600
 		// If lib not found in language file, we get label from cache/databse
3601 3601
 		if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel))
3602 3602
 		{
3603
-			$lib=$langs->getLabelFromKey($this->db,$fk_prospectlevel,'c_prospectlevel','code','label');
3603
+			$lib = $langs->getLabelFromKey($this->db, $fk_prospectlevel, 'c_prospectlevel', 'code', 'label');
3604 3604
 		}
3605 3605
 		return $lib;
3606 3606
 	}
@@ -3627,7 +3627,7 @@  discard block
 block discarded – undo
3627 3627
 	 *  @param	string	$label		Label to use for status for added status
3628 3628
 	 *  @return string        		Libelle
3629 3629
 	 */
3630
-	function getLibProspCommStatut($mode=0, $label='')
3630
+	function getLibProspCommStatut($mode = 0, $label = '')
3631 3631
 	{
3632 3632
 		return $this->LibProspCommStatut($this->stcomm_id, $mode, $label);
3633 3633
 	}
@@ -3641,7 +3641,7 @@  discard block
 block discarded – undo
3641 3641
 	 *  @param	string		$label			Label to use for status for added status
3642 3642
 	 *  @return string       	 			Libelle du statut
3643 3643
 	 */
3644
-	function LibProspCommStatut($statut, $mode=0, $label='')
3644
+	function LibProspCommStatut($statut, $mode = 0, $label = '')
3645 3645
 	{
3646 3646
         // phpcs:enable
3647 3647
 		global $langs;
@@ -3649,11 +3649,11 @@  discard block
 block discarded – undo
3649 3649
 
3650 3650
 		if ($mode == 2)
3651 3651
 		{
3652
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3653
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3654
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3655
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3656
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3652
+			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"), -1).' '.$langs->trans("StatusProspect-1");
3653
+			elseif ($statut == '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3654
+			elseif ($statut == '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3655
+			elseif ($statut == '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3656
+			elseif ($statut == '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3657 3657
 			else
3658 3658
 			{
3659 3659
 				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
@@ -3661,11 +3661,11 @@  discard block
 block discarded – undo
3661 3661
 		}
3662 3662
 		if ($mode == 3)
3663 3663
 		{
3664
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1);
3665
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0);
3666
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1);
3667
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2);
3668
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3);
3664
+			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"), -1);
3665
+			elseif ($statut == '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0);
3666
+			elseif ($statut == '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1);
3667
+			elseif ($statut == '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2);
3668
+			elseif ($statut == '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3);
3669 3669
 			else
3670 3670
 			{
3671 3671
 				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0);
@@ -3673,11 +3673,11 @@  discard block
 block discarded – undo
3673 3673
 		}
3674 3674
 		if ($mode == 4)
3675 3675
 		{
3676
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3677
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3678
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3679
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3680
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3676
+			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"), -1).' '.$langs->trans("StatusProspect-1");
3677
+			elseif ($statut == '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3678
+			elseif ($statut == '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3679
+			elseif ($statut == '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3680
+			elseif ($statut == '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3681 3681
 			else
3682 3682
 			{
3683 3683
 				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
@@ -3707,13 +3707,13 @@  discard block
 block discarded – undo
3707 3707
 	 *  @param     string      $mode    'customer' or 'supplier'
3708 3708
 	 *  @return    array				array('opened'=>Amount, 'total'=>Total amount)
3709 3709
 	 */
3710
-	function getOutstandingProposals($mode='customer')
3710
+	function getOutstandingProposals($mode = 'customer')
3711 3711
 	{
3712
-		$table='propal';
3712
+		$table = 'propal';
3713 3713
 		if ($mode == 'supplier') $table = 'supplier_proposal';
3714 3714
 
3715 3715
 		$sql  = "SELECT rowid, total_ht, total as total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
3716
-		$sql .= " WHERE fk_soc = ". $this->id;
3716
+		$sql .= " WHERE fk_soc = ".$this->id;
3717 3717
 		if ($mode == 'supplier') {
3718 3718
 			$sql .= " AND entity IN (".getEntity('supplier_proposal').")";
3719 3719
 		} else {
@@ -3721,21 +3721,21 @@  discard block
 block discarded – undo
3721 3721
 		}
3722 3722
 
3723 3723
 		dol_syslog("getOutstandingProposals", LOG_DEBUG);
3724
-		$resql=$this->db->query($sql);
3724
+		$resql = $this->db->query($sql);
3725 3725
 		if ($resql)
3726 3726
 		{
3727 3727
 			$outstandingOpened = 0;
3728 3728
 			$outstandingTotal = 0;
3729 3729
 			$outstandingTotalIncTax = 0;
3730
-			while($obj=$this->db->fetch_object($resql)) {
3731
-				$outstandingTotal+= $obj->total_ht;
3732
-				$outstandingTotalIncTax+= $obj->total_ttc;
3730
+			while ($obj = $this->db->fetch_object($resql)) {
3731
+				$outstandingTotal += $obj->total_ht;
3732
+				$outstandingTotalIncTax += $obj->total_ttc;
3733 3733
 				if ($obj->fk_statut != 0)    // Not a draft
3734 3734
 				{
3735
-					$outstandingOpened+=$obj->total_ttc;
3735
+					$outstandingOpened += $obj->total_ttc;
3736 3736
 				}
3737 3737
 			}
3738
-			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3738
+			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes'
3739 3739
 		}
3740 3740
 		else
3741 3741
 			return array();
@@ -3747,13 +3747,13 @@  discard block
 block discarded – undo
3747 3747
 	 *  @param     string      $mode    'customer' or 'supplier'
3748 3748
 	 *  @return		array				array('opened'=>Amount, 'total'=>Total amount)
3749 3749
 	 */
3750
-	function getOutstandingOrders($mode='customer')
3750
+	function getOutstandingOrders($mode = 'customer')
3751 3751
 	{
3752
-		$table='commande';
3752
+		$table = 'commande';
3753 3753
 		if ($mode == 'supplier') $table = 'commande_fournisseur';
3754 3754
 
3755 3755
 		$sql  = "SELECT rowid, total_ht, total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
3756
-		$sql .= " WHERE fk_soc = ". $this->id;
3756
+		$sql .= " WHERE fk_soc = ".$this->id;
3757 3757
 		if ($mode == 'supplier') {
3758 3758
 			$sql .= " AND entity IN (".getEntity('supplier_order').")";
3759 3759
 		} else {
@@ -3761,21 +3761,21 @@  discard block
 block discarded – undo
3761 3761
 		}
3762 3762
 
3763 3763
 		dol_syslog("getOutstandingOrders", LOG_DEBUG);
3764
-		$resql=$this->db->query($sql);
3764
+		$resql = $this->db->query($sql);
3765 3765
 		if ($resql)
3766 3766
 		{
3767 3767
 			$outstandingOpened = 0;
3768 3768
 			$outstandingTotal = 0;
3769 3769
 			$outstandingTotalIncTax = 0;
3770
-			while($obj=$this->db->fetch_object($resql)) {
3771
-				$outstandingTotal+= $obj->total_ht;
3772
-				$outstandingTotalIncTax+= $obj->total_ttc;
3770
+			while ($obj = $this->db->fetch_object($resql)) {
3771
+				$outstandingTotal += $obj->total_ht;
3772
+				$outstandingTotalIncTax += $obj->total_ttc;
3773 3773
 				if ($obj->fk_statut != 0)    // Not a draft
3774 3774
 				{
3775
-					$outstandingOpened+=$obj->total_ttc;
3775
+					$outstandingOpened += $obj->total_ttc;
3776 3776
 				}
3777 3777
 			}
3778
-			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3778
+			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes'
3779 3779
 		}
3780 3780
 		else
3781 3781
 			return array();
@@ -3787,9 +3787,9 @@  discard block
 block discarded – undo
3787 3787
 	 *  @param     string      $mode    'customer' or 'supplier'
3788 3788
 	 *  @return		array				array('opened'=>Amount, 'total'=>Total amount)
3789 3789
 	 */
3790
-	function getOutstandingBills($mode='customer')
3790
+	function getOutstandingBills($mode = 'customer')
3791 3791
 	{
3792
-		$table='facture';
3792
+		$table = 'facture';
3793 3793
 		if ($mode == 'supplier') $table = 'facture_fourn';
3794 3794
 
3795 3795
 		/* Accurate value of remain to pay is to sum remaintopay for each invoice
@@ -3799,9 +3799,9 @@  discard block
 block discarded – undo
3799 3799
 		 $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
3800 3800
 		 $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
3801 3801
 		 */
3802
-		if ($mode == 'supplier') $sql  = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3803
-		else $sql  = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3804
-		$sql .= " WHERE fk_soc = ". $this->id;
3802
+		if ($mode == 'supplier') $sql = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3803
+		else $sql = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3804
+		$sql .= " WHERE fk_soc = ".$this->id;
3805 3805
 		if ($mode == 'supplier') {
3806 3806
 			$sql .= " AND entity IN (".getEntity('facture_fourn').")";
3807 3807
 		} else {
@@ -3809,7 +3809,7 @@  discard block
 block discarded – undo
3809 3809
 		}
3810 3810
 
3811 3811
 		dol_syslog("getOutstandingBills", LOG_DEBUG);
3812
-		$resql=$this->db->query($sql);
3812
+		$resql = $this->db->query($sql);
3813 3813
 		if ($resql)
3814 3814
 		{
3815 3815
 			$outstandingOpened = 0;
@@ -3818,21 +3818,21 @@  discard block
 block discarded – undo
3818 3818
 			if ($mode == 'supplier')
3819 3819
 			{
3820 3820
 				require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
3821
-				$tmpobject=new FactureFournisseur($this->db);
3821
+				$tmpobject = new FactureFournisseur($this->db);
3822 3822
 			}
3823 3823
 			else
3824 3824
 			{
3825 3825
 				require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
3826
-				$tmpobject=new Facture($this->db);
3826
+				$tmpobject = new Facture($this->db);
3827 3827
 			}
3828
-			while($obj=$this->db->fetch_object($resql)) {
3829
-				$tmpobject->id=$obj->rowid;
3828
+			while ($obj = $this->db->fetch_object($resql)) {
3829
+				$tmpobject->id = $obj->rowid;
3830 3830
 				if ($obj->fk_statut != 0                                           // Not a draft
3831
-					&& ! ($obj->fk_statut == 3 && $obj->close_code == 'replaced')  // Not a replaced invoice
3831
+					&& !($obj->fk_statut == 3 && $obj->close_code == 'replaced')  // Not a replaced invoice
3832 3832
 					)
3833 3833
 				{
3834
-					$outstandingTotal+= $obj->total_ht;
3835
-					$outstandingTotalIncTax+= $obj->total_ttc;
3834
+					$outstandingTotal += $obj->total_ht;
3835
+					$outstandingTotalIncTax += $obj->total_ttc;
3836 3836
 				}
3837 3837
 				if ($obj->paye == 0
3838 3838
 					&& $obj->fk_statut != 0    // Not a draft
@@ -3843,10 +3843,10 @@  discard block
 block discarded – undo
3843 3843
 					$paiement = $tmpobject->getSommePaiement();
3844 3844
 					$creditnotes = $tmpobject->getSumCreditNotesUsed();
3845 3845
 					$deposits = $tmpobject->getSumDepositsUsed();
3846
-					$outstandingOpened+=$obj->total_ttc - $paiement - $creditnotes - $deposits;
3846
+					$outstandingOpened += $obj->total_ttc - $paiement - $creditnotes - $deposits;
3847 3847
 				}
3848 3848
 			}
3849
-			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3849
+			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes'
3850 3850
 		}
3851 3851
 		else
3852 3852
 		{
@@ -3873,26 +3873,26 @@  discard block
 block discarded – undo
3873 3873
 	     $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
3874 3874
 	     */
3875 3875
 		$sql  = "SELECT rowid, total_ttc FROM ".MAIN_DB_PREFIX."facture as f";
3876
-		$sql .= " WHERE fk_soc = ". $this->id;
3876
+		$sql .= " WHERE fk_soc = ".$this->id;
3877 3877
 		$sql .= " AND paye = 0";
3878
-		$sql .= " AND fk_statut <> 0";	// Not a draft
3878
+		$sql .= " AND fk_statut <> 0"; // Not a draft
3879 3879
 		//$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')";		// Not abandonned for undefined reason
3880
-		$sql .= " AND fk_statut <> 3";		// Not abandonned
3881
-		$sql .= " AND fk_statut <> 2";		// Not clasified as paid
3880
+		$sql .= " AND fk_statut <> 3"; // Not abandonned
3881
+		$sql .= " AND fk_statut <> 2"; // Not clasified as paid
3882 3882
 
3883 3883
 		dol_syslog("get_OutstandingBill", LOG_DEBUG);
3884
-		$resql=$this->db->query($sql);
3884
+		$resql = $this->db->query($sql);
3885 3885
 		if ($resql)
3886 3886
 		{
3887 3887
 			$outstandingAmount = 0;
3888 3888
 			require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
3889
-			$tmpobject=new Facture($this->db);
3890
-			while($obj=$this->db->fetch_object($resql)) {
3891
-				$tmpobject->id=$obj->rowid;
3889
+			$tmpobject = new Facture($this->db);
3890
+			while ($obj = $this->db->fetch_object($resql)) {
3891
+				$tmpobject->id = $obj->rowid;
3892 3892
 				$paiement = $tmpobject->getSommePaiement();
3893 3893
 				$creditnotes = $tmpobject->getSumCreditNotesUsed();
3894 3894
 				$deposits = $tmpobject->getSumDepositsUsed();
3895
-				$outstandingAmount+= $obj->total_ttc - $paiement - $creditnotes - $deposits;
3895
+				$outstandingAmount += $obj->total_ttc - $paiement - $creditnotes - $deposits;
3896 3896
 			}
3897 3897
 			return $outstandingAmount;
3898 3898
 		}
@@ -3923,10 +3923,10 @@  discard block
 block discarded – undo
3923 3923
 		global $langs;
3924 3924
 		$langs->load('companies');
3925 3925
 
3926
-		if ($statut==0) return $langs->trans("NorProspectNorCustomer");
3927
-		if ($statut==1) return $langs->trans("Customer");
3928
-		if ($statut==2) return $langs->trans("Prospect");
3929
-		if ($statut==3) return $langs->trans("ProspectCustomer");
3926
+		if ($statut == 0) return $langs->trans("NorProspectNorCustomer");
3927
+		if ($statut == 1) return $langs->trans("Customer");
3928
+		if ($statut == 2) return $langs->trans("Prospect");
3929
+		if ($statut == 3) return $langs->trans("ProspectCustomer");
3930 3930
 	}
3931 3931
 
3932 3932
 
@@ -3941,26 +3941,26 @@  discard block
 block discarded – undo
3941 3941
 	 *  @param  null|array  $moreparams     Array to provide more information
3942 3942
 	 *	@return int        					<0 if KO, >0 if OK
3943 3943
 	 */
3944
-	public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
3944
+	public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
3945 3945
 	{
3946
-		global $conf,$user,$langs;
3946
+		global $conf, $user, $langs;
3947 3947
 
3948
-		if (! empty($moreparams) && ! empty($moreparams['use_companybankid']))
3948
+		if (!empty($moreparams) && !empty($moreparams['use_companybankid']))
3949 3949
 		{
3950 3950
 			$modelpath = "core/modules/bank/doc/";
3951 3951
 
3952 3952
 			include_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
3953 3953
 			$companybankaccount = new CompanyBankAccount($this->db);
3954 3954
 			$result = $companybankaccount->fetch($moreparams['use_companybankid']);
3955
-			if (! $result) dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
3956
-			$result=$companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3955
+			if (!$result) dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
3956
+			$result = $companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3957 3957
 		}
3958 3958
 		else
3959 3959
 		{
3960 3960
 			// Positionne le modele sur le nom du modele a utiliser
3961
-			if (! dol_strlen($modele))
3961
+			if (!dol_strlen($modele))
3962 3962
 			{
3963
-				if (! empty($conf->global->COMPANY_ADDON_PDF))
3963
+				if (!empty($conf->global->COMPANY_ADDON_PDF))
3964 3964
 				{
3965 3965
 					$modele = $conf->global->COMPANY_ADDON_PDF;
3966 3966
 				}
@@ -3973,7 +3973,7 @@  discard block
 block discarded – undo
3973 3973
 
3974 3974
 			$modelpath = "core/modules/societe/doc/";
3975 3975
 
3976
-			$result=$this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3976
+			$result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3977 3977
 		}
3978 3978
 
3979 3979
 		return $result;
@@ -3993,7 +3993,7 @@  discard block
 block discarded – undo
3993 3993
 	 */
3994 3994
 	public function setCategories($categories, $type)
3995 3995
 	{
3996
-		require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
3996
+		require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
3997 3997
 
3998 3998
 		// Decode type
3999 3999
 		if ($type == 'customer') {
@@ -4003,7 +4003,7 @@  discard block
 block discarded – undo
4003 4003
 			$type_id = Categorie::TYPE_SUPPLIER;
4004 4004
 			$type_text = 'supplier';
4005 4005
 		} else {
4006
-			dol_syslog(__METHOD__ . ': Type ' . $type .  'is an unknown company category type. Done nothing.', LOG_ERR);
4006
+			dol_syslog(__METHOD__.': Type '.$type.'is an unknown company category type. Done nothing.', LOG_ERR);
4007 4007
 			return -1;
4008 4008
 		}
4009 4009
 
Please login to merge, or discard this patch.
Braces   +588 added lines, -352 removed lines patch added patch discarded remove patch
@@ -509,15 +509,25 @@  discard block
 block discarded – undo
509 509
 		$error=0;
510 510
 
511 511
 		// Clean parameters
512
-		if (empty($this->status)) $this->status=0;
512
+		if (empty($this->status)) {
513
+		    $this->status=0;
514
+		}
513 515
 		$this->name=$this->name?trim($this->name):trim($this->nom);
514
-		if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name=ucwords($this->name);
516
+		if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) {
517
+		    $this->name=ucwords($this->name);
518
+		}
515 519
 		$this->nom=$this->name; // For backward compatibility
516
-		if (empty($this->client))      $this->client=0;
517
-		if (empty($this->fournisseur)) $this->fournisseur=0;
520
+		if (empty($this->client)) {
521
+		    $this->client=0;
522
+		}
523
+		if (empty($this->fournisseur)) {
524
+		    $this->fournisseur=0;
525
+		}
518 526
 		$this->import_key = trim($this->import_key);
519 527
 
520
-		if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
528
+		if (!empty($this->multicurrency_code)) {
529
+		    $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
530
+		}
521 531
 		if (empty($this->fk_multicurrency))
522 532
 		{
523 533
 			$this->multicurrency_code = '';
@@ -531,8 +541,12 @@  discard block
 block discarded – undo
531 541
 		$this->db->begin();
532 542
 
533 543
 		// For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
534
-		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this,0);
535
-		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1);
544
+		if ($this->code_client == -1 || $this->code_client === 'auto') {
545
+		    $this->get_codeclient($this,0);
546
+		}
547
+		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') {
548
+		    $this->get_codefournisseur($this,1);
549
+		}
536 550
 
537 551
 		// Check more parameters (including mandatory setup
538 552
 		// If error, this->errors[] is filled
@@ -579,32 +593,32 @@  discard block
 block discarded – undo
579 593
 				{
580 594
 					// Call trigger
581 595
 					$result=$this->call_trigger('COMPANY_CREATE',$user);
582
-					if ($result < 0) $error++;
596
+					if ($result < 0) {
597
+					    $error++;
598
+					}
583 599
 					// End call triggers
600
+				} else {
601
+				    $error++;
584 602
 				}
585
-				else $error++;
586 603
 
587 604
 				if (! $error)
588 605
 				{
589 606
 					dol_syslog(get_class($this)."::Create success id=".$this->id);
590 607
 					$this->db->commit();
591 608
 					return $this->id;
592
-				}
593
-				else
609
+				} else
594 610
 				{
595 611
 					dol_syslog(get_class($this)."::Create echec update ".$this->error." ".join(',',$this->errors), LOG_ERR);
596 612
 					$this->db->rollback();
597 613
 					return -4;
598 614
 				}
599
-			}
600
-			else
615
+			} else
601 616
 			{
602 617
 				if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
603 618
 				{
604 619
 					$this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->name);    // duplicate on a field (code or profid or ...)
605 620
 					$result=-1;
606
-				}
607
-				else
621
+				} else
608 622
 				{
609 623
 					$this->error=$this->db->lasterror();
610 624
 					$result=-2;
@@ -612,8 +626,7 @@  discard block
 block discarded – undo
612 626
 				$this->db->rollback();
613 627
 				return $result;
614 628
 			}
615
-		}
616
-		else
629
+		} else
617 630
 		{
618 631
 			$this->db->rollback();
619 632
 			dol_syslog(get_class($this)."::Create fails verify ".join(',',$this->errors), LOG_WARNING);
@@ -691,16 +704,13 @@  discard block
 block discarded – undo
691 704
 				if ($rescode == -1)
692 705
 				{
693 706
 					$this->errors[] = 'ErrorBadCustomerCodeSyntax';
694
-				}
695
-				elseif ($rescode == -2)
707
+				} elseif ($rescode == -2)
696 708
 				{
697 709
 					$this->errors[] = 'ErrorCustomerCodeRequired';
698
-				}
699
-				elseif ($rescode == -3)
710
+				} elseif ($rescode == -3)
700 711
 				{
701 712
 					$this->errors[] = 'ErrorCustomerCodeAlreadyUsed';
702
-				}
703
-				elseif ($rescode == -4)
713
+				} elseif ($rescode == -4)
704 714
 				{
705 715
 					$this->errors[] = 'ErrorPrefixRequired';
706 716
 				}
@@ -716,16 +726,13 @@  discard block
 block discarded – undo
716 726
 				if ($rescode == -1)
717 727
 				{
718 728
 					$this->errors[] = 'ErrorBadSupplierCodeSyntax';
719
-				}
720
-				elseif ($rescode == -2)
729
+				} elseif ($rescode == -2)
721 730
 				{
722 731
 					$this->errors[] = 'ErrorSupplierCodeRequired';
723
-				}
724
-				elseif ($rescode == -3)
732
+				} elseif ($rescode == -3)
725 733
 				{
726 734
 					$this->errors[] = 'ErrorSupplierCodeAlreadyUsed';
727
-				}
728
-				elseif ($rescode == -5)
735
+				} elseif ($rescode == -5)
729 736
 				{
730 737
 					$this->errors[] = 'ErrorprefixRequired';
731 738
 				}
@@ -767,8 +774,7 @@  discard block
 block discarded – undo
767 774
 						}
768 775
 					}
769 776
 				}
770
-			}
771
-			else
777
+			} else
772 778
 			{
773 779
 				//var_dump($conf->global->SOCIETE_EMAIL_UNIQUE);
774 780
 				//var_dump($conf->global->SOCIETE_EMAIL_MANDATORY);
@@ -795,7 +801,9 @@  discard block
 block discarded – undo
795 801
 			}
796 802
 		}
797 803
 
798
-		if ($error) $result = -4;
804
+		if ($error) {
805
+		    $result = -4;
806
+		}
799 807
 
800 808
 		return $result;
801 809
 	}
@@ -818,7 +826,9 @@  discard block
 block discarded – undo
818 826
 
819 827
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
820 828
 
821
-		if (empty($id)) $id = $this->id;
829
+		if (empty($id)) {
830
+		    $id = $this->id;
831
+		}
822 832
 
823 833
 		$error=0;
824 834
 
@@ -864,9 +874,13 @@  discard block
 block discarded – undo
864 874
 
865 875
 		$this->tva_assuj	= trim($this->tva_assuj);
866 876
 		$this->tva_intra	= dol_sanitizeFileName($this->tva_intra,'');
867
-		if (empty($this->status)) $this->status = 0;
877
+		if (empty($this->status)) {
878
+		    $this->status = 0;
879
+		}
868 880
 
869
-		if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
881
+		if (!empty($this->multicurrency_code)) {
882
+		    $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
883
+		}
870 884
 		if (empty($this->fk_multicurrency))
871 885
 		{
872 886
 			$this->multicurrency_code = '';
@@ -880,8 +894,13 @@  discard block
 block discarded – undo
880 894
 		$this->localtax1_value=trim($this->localtax1_value);
881 895
 		$this->localtax2_value=trim($this->localtax2_value);
882 896
 
883
-		if ($this->capital != '') $this->capital=price2num(trim($this->capital));
884
-		if (! is_numeric($this->capital)) $this->capital = '';     // '' = undef
897
+		if ($this->capital != '') {
898
+		    $this->capital=price2num(trim($this->capital));
899
+		}
900
+		if (! is_numeric($this->capital)) {
901
+		    $this->capital = '';
902
+		}
903
+		// '' = undef
885 904
 
886 905
 		$this->effectif_id=trim($this->effectif_id);
887 906
 		$this->forme_juridique_code=trim($this->forme_juridique_code);
@@ -890,8 +909,12 @@  discard block
 block discarded – undo
890 909
 		$this->barcode=trim($this->barcode);
891 910
 
892 911
 		// For automatic creation
893
-		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this,0);
894
-		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1);
912
+		if ($this->code_client == -1 || $this->code_client === 'auto') {
913
+		    $this->get_codeclient($this,0);
914
+		}
915
+		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') {
916
+		    $this->get_codefournisseur($this,1);
917
+		}
895 918
 
896 919
 		$this->code_compta=trim($this->code_compta);
897 920
 		$this->code_compta_fournisseur=trim($this->code_compta_fournisseur);
@@ -911,7 +934,9 @@  discard block
 block discarded – undo
911 934
 			if (empty($this->code_compta))
912 935
 			{
913 936
 				$ret=$this->get_codecompta('customer');
914
-				if ($ret < 0) return -1;
937
+				if ($ret < 0) {
938
+				    return -1;
939
+				}
915 940
 			}
916 941
 
917 942
 			$customer=true;
@@ -924,7 +949,9 @@  discard block
 block discarded – undo
924 949
 			if (empty($this->code_compta_fournisseur))
925 950
 			{
926 951
 				$ret=$this->get_codecompta('supplier');
927
-				if ($ret < 0) return -1;
952
+				if ($ret < 0) {
953
+				    return -1;
954
+				}
928 955
 			}
929 956
 
930 957
 			$supplier=true;
@@ -955,16 +982,24 @@  discard block
 block discarded – undo
955 982
 			{
956 983
 				if (in_array('ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client)
957 984
 				{
958
-					if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]);	// Remove error message
985
+					if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false) {
986
+					    unset($this->errors[$key]);
987
+					}
988
+					// Remove error message
959 989
 				}
960 990
 				if (in_array('ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur)
961 991
 				{
962
-					if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]);	// Remove error message
992
+					if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false) {
993
+					    unset($this->errors[$key]);
994
+					}
995
+					// Remove error message
963 996
 				}
964
-				if (empty($this->errors))	// If there is no more error, we can make like if there is no error at all
997
+				if (empty($this->errors)) {
998
+				    // If there is no more error, we can make like if there is no error at all
965 999
 				{
966 1000
 					$result = 0;
967 1001
 				}
1002
+				}
968 1003
 			}
969 1004
 		}
970 1005
 
@@ -1017,20 +1052,24 @@  discard block
 block discarded – undo
1017 1052
 				if($this->localtax1_value!='')
1018 1053
 				{
1019 1054
 					$sql .=",localtax1_value =".$this->localtax1_value;
1055
+				} else {
1056
+				    $sql .=",localtax1_value =0.000";
1020 1057
 				}
1021
-				else $sql .=",localtax1_value =0.000";
1058
+			} else {
1059
+			    $sql .=",localtax1_value =0.000";
1022 1060
 			}
1023
-			else $sql .=",localtax1_value =0.000";
1024 1061
 
1025 1062
 			if($this->localtax2_assuj==1)
1026 1063
 			{
1027 1064
 				if($this->localtax2_value!='')
1028 1065
 				{
1029 1066
 					$sql .=",localtax2_value =".$this->localtax2_value;
1067
+				} else {
1068
+				    $sql .=",localtax2_value =0.000";
1030 1069
 				}
1031
-				else $sql .=",localtax2_value =0.000";
1070
+			} else {
1071
+			    $sql .=",localtax2_value =0.000";
1032 1072
 			}
1033
-			else $sql .=",localtax2_value =0.000";
1034 1073
 
1035 1074
 			$sql .= ",capital = ".($this->capital == '' ? "null" : $this->capital);
1036 1075
 
@@ -1087,11 +1126,13 @@  discard block
 block discarded – undo
1087 1126
 			$resql=$this->db->query($sql);
1088 1127
 			if ($resql)
1089 1128
 			{
1090
-				if (is_object($this->oldcopy))	// If we have information on old values
1129
+				if (is_object($this->oldcopy)) {
1130
+				    // If we have information on old values
1091 1131
 				{
1092 1132
 					if ($this->oldcopy->country_id != $this->country_id)
1093 1133
 					{
1094 1134
 						unset($this->country_code);
1135
+				}
1095 1136
 						unset($this->country);
1096 1137
 					}
1097 1138
 					if ($this->oldcopy->state_id != $this->state_id)
@@ -1099,8 +1140,7 @@  discard block
 block discarded – undo
1099 1140
 						unset($this->state_code);
1100 1141
 						unset($this->state);
1101 1142
 					}
1102
-				}
1103
-				else
1143
+				} else
1104 1144
 				{
1105 1145
 					unset($this->country_code);	// We clean this, in the doubt, because it may have been changed after an update of country_id
1106 1146
 					unset($this->country);
@@ -1141,8 +1181,7 @@  discard block
 block discarded – undo
1141 1181
 								dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
1142 1182
 								$error++;
1143 1183
 							}
1144
-						}
1145
-						elseif ($result < 0)
1184
+						} elseif ($result < 0)
1146 1185
 						{
1147 1186
 							$this->error=$lmember->error;
1148 1187
 							$error++;
@@ -1153,9 +1192,11 @@  discard block
 block discarded – undo
1153 1192
 				$action='update';
1154 1193
 
1155 1194
 				// Actions on extra fields
1156
-				if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1195
+				if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
1196
+				    // For avoid conflicts if trigger used
1157 1197
 				{
1158 1198
 					$result=$this->insertExtraFields();
1199
+				}
1159 1200
 					if ($result < 0)
1160 1201
 					{
1161 1202
 						$error++;
@@ -1166,7 +1207,9 @@  discard block
 block discarded – undo
1166 1207
 				{
1167 1208
 					// Call trigger
1168 1209
 					$result=$this->call_trigger('COMPANY_MODIFY',$user);
1169
-					if ($result < 0) $error++;
1210
+					if ($result < 0) {
1211
+					    $error++;
1212
+					}
1170 1213
 					// End call triggers
1171 1214
 				}
1172 1215
 
@@ -1175,22 +1218,19 @@  discard block
 block discarded – undo
1175 1218
 					dol_syslog(get_class($this)."::Update success");
1176 1219
 					$this->db->commit();
1177 1220
 					return 1;
1178
-				}
1179
-				else
1221
+				} else
1180 1222
 				{
1181 1223
 					$this->db->rollback();
1182 1224
 					return -1;
1183 1225
 				}
1184
-			}
1185
-			else
1226
+			} else
1186 1227
 			{
1187 1228
 				if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
1188 1229
 				{
1189 1230
 					// Doublon
1190 1231
 					$this->error = $langs->trans("ErrorDuplicateField");
1191 1232
 					$result = -1;
1192
-				}
1193
-				else
1233
+				} else
1194 1234
 				{
1195 1235
 					$this->error = $this->db->lasterror();
1196 1236
 					$result = -2;
@@ -1198,8 +1238,7 @@  discard block
 block discarded – undo
1198 1238
 				$this->db->rollback();
1199 1239
 				return $result;
1200 1240
 			}
1201
-		}
1202
-		else
1241
+		} else
1203 1242
 	   {
1204 1243
 			$this->db->rollback();
1205 1244
 			dol_syslog(get_class($this)."::Update fails verify ".join(',',$this->errors), LOG_WARNING);
@@ -1229,7 +1268,9 @@  discard block
 block discarded – undo
1229 1268
 		global $langs;
1230 1269
 		global $conf;
1231 1270
 
1232
-		if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($ref_int) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) return -1;
1271
+		if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($ref_int) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) {
1272
+		    return -1;
1273
+		}
1233 1274
 
1234 1275
 		$sql = 'SELECT s.rowid, s.nom as name, s.name_alias, s.entity, s.ref_ext, s.ref_int, s.address, s.datec as date_creation, s.prefix_comm';
1235 1276
 		$sql .= ', s.status';
@@ -1266,18 +1307,42 @@  discard block
 block discarded – undo
1266 1307
 		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON s.fk_incoterms = i.rowid';
1267 1308
 
1268 1309
 		$sql .= ' WHERE s.entity IN ('.getEntity($this->element).')';
1269
-		if ($rowid)     $sql .= ' AND s.rowid = '.$rowid;
1270
-		if ($ref)       $sql .= " AND s.nom = '".$this->db->escape($ref)."'";
1271
-		if ($ref_alias) $sql .= " AND s.nom_alias = '".$this->db->escape($ref_alias)."'";
1272
-		if ($ref_ext)   $sql .= " AND s.ref_ext = '".$this->db->escape($ref_ext)."'";
1273
-		if ($ref_int)   $sql .= " AND s.ref_int = '".$this->db->escape($ref_int)."'";
1274
-		if ($idprof1)   $sql .= " AND s.siren = '".$this->db->escape($idprof1)."'";
1275
-		if ($idprof2)   $sql .= " AND s.siret = '".$this->db->escape($idprof2)."'";
1276
-		if ($idprof3)   $sql .= " AND s.ape = '".$this->db->escape($idprof3)."'";
1277
-		if ($idprof4)   $sql .= " AND s.idprof4 = '".$this->db->escape($idprof4)."'";
1278
-		if ($idprof5)   $sql .= " AND s.idprof5 = '".$this->db->escape($idprof5)."'";
1279
-		if ($idprof6)   $sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'";
1280
-		if ($email)     $sql .= " AND s.email = '".$this->db->escape($email)."'";
1310
+		if ($rowid) {
1311
+		    $sql .= ' AND s.rowid = '.$rowid;
1312
+		}
1313
+		if ($ref) {
1314
+		    $sql .= " AND s.nom = '".$this->db->escape($ref)."'";
1315
+		}
1316
+		if ($ref_alias) {
1317
+		    $sql .= " AND s.nom_alias = '".$this->db->escape($ref_alias)."'";
1318
+		}
1319
+		if ($ref_ext) {
1320
+		    $sql .= " AND s.ref_ext = '".$this->db->escape($ref_ext)."'";
1321
+		}
1322
+		if ($ref_int) {
1323
+		    $sql .= " AND s.ref_int = '".$this->db->escape($ref_int)."'";
1324
+		}
1325
+		if ($idprof1) {
1326
+		    $sql .= " AND s.siren = '".$this->db->escape($idprof1)."'";
1327
+		}
1328
+		if ($idprof2) {
1329
+		    $sql .= " AND s.siret = '".$this->db->escape($idprof2)."'";
1330
+		}
1331
+		if ($idprof3) {
1332
+		    $sql .= " AND s.ape = '".$this->db->escape($idprof3)."'";
1333
+		}
1334
+		if ($idprof4) {
1335
+		    $sql .= " AND s.idprof4 = '".$this->db->escape($idprof4)."'";
1336
+		}
1337
+		if ($idprof5) {
1338
+		    $sql .= " AND s.idprof5 = '".$this->db->escape($idprof5)."'";
1339
+		}
1340
+		if ($idprof6) {
1341
+		    $sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'";
1342
+		}
1343
+		if ($email) {
1344
+		    $sql .= " AND s.email = '".$this->db->escape($email)."'";
1345
+		}
1281 1346
 
1282 1347
 		$resql=$this->db->query($sql);
1283 1348
 		if ($resql)
@@ -1288,10 +1353,11 @@  discard block
 block discarded – undo
1288 1353
 				$this->error='Fetch found several records. Rename one of tirdparties to avoid duplicate.';
1289 1354
 				dol_syslog($this->error, LOG_ERR);
1290 1355
 				$result = -2;
1291
-			}
1292
-			elseif ($num)   // $num = 1
1356
+			} elseif ($num) {
1357
+			    // $num = 1
1293 1358
 			{
1294 1359
 				$obj = $this->db->fetch_object($resql);
1360
+			}
1295 1361
 
1296 1362
 				$this->id           = $obj->rowid;
1297 1363
 				$this->entity       = $obj->entity;
@@ -1421,22 +1487,22 @@  discard block
 block discarded – undo
1421 1487
 
1422 1488
 				// fetch optionals attributes and labels
1423 1489
 				$this->fetch_optionals();
1424
-			}
1425
-			else
1490
+			} else
1426 1491
 			{
1427 1492
 				$result = 0;
1428 1493
 			}
1429 1494
 
1430 1495
 			$this->db->free($resql);
1431
-		}
1432
-		else
1496
+		} else
1433 1497
 		{
1434 1498
 			$this->error=$this->db->lasterror();
1435 1499
 			$result = -3;
1436 1500
 		}
1437 1501
 
1438 1502
 		// Use first price level if level not defined for third party
1439
-		if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->price_level)) $this->price_level=1;
1503
+		if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->price_level)) {
1504
+		    $this->price_level=1;
1505
+		}
1440 1506
 
1441 1507
 		return $result;
1442 1508
 	}
@@ -1453,7 +1519,9 @@  discard block
 block discarded – undo
1453 1519
 	{
1454 1520
 		global $langs, $conf, $user;
1455 1521
 
1456
-		if (empty($fuser)) $fuser=$user;
1522
+		if (empty($fuser)) {
1523
+		    $fuser=$user;
1524
+		}
1457 1525
 
1458 1526
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1459 1527
 
@@ -1473,7 +1541,9 @@  discard block
 block discarded – undo
1473 1541
 			{
1474 1542
 				// Call trigger
1475 1543
 				$result=$this->call_trigger('COMPANY_DELETE',$fuser);
1476
-				if ($result < 0) $error++;
1544
+				if ($result < 0) {
1545
+				    $error++;
1546
+				}
1477 1547
 				// End call triggers
1478 1548
 			}
1479 1549
 
@@ -1518,9 +1588,11 @@  discard block
 block discarded – undo
1518 1588
 			}
1519 1589
 
1520 1590
 			// Removed extrafields
1521
-			if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
1591
+			if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) {
1592
+			    // For avoid conflicts if trigger used
1522 1593
 			{
1523 1594
 				$result=$this->deleteExtraFields();
1595
+			}
1524 1596
 				if ($result < 0)
1525 1597
 				{
1526 1598
 					$error++;
@@ -1568,15 +1640,15 @@  discard block
 block discarded – undo
1568 1640
 				}
1569 1641
 
1570 1642
 				return 1;
1571
-			}
1572
-			else
1643
+			} else
1573 1644
 			{
1574 1645
 				dol_syslog($this->error, LOG_ERR);
1575 1646
 				$this->db->rollback();
1576 1647
 				return -1;
1577 1648
 			}
1649
+		} else {
1650
+		    dol_syslog("Can't remove thirdparty with id ".$id.". There is ".$objectisused." childs", LOG_WARNING);
1578 1651
 		}
1579
-		else dol_syslog("Can't remove thirdparty with id ".$id.". There is ".$objectisused." childs", LOG_WARNING);
1580 1652
 		return 0;
1581 1653
 	}
1582 1654
 
@@ -1592,7 +1664,10 @@  discard block
 block discarded – undo
1592 1664
 		if ($this->id)
1593 1665
 		{
1594 1666
 			$newclient=1;
1595
-			if ($this->client == 2 || $this->client == 3) $newclient=3;	//If prospect, we keep prospect tag
1667
+			if ($this->client == 2 || $this->client == 3) {
1668
+			    $newclient=3;
1669
+			}
1670
+			//If prospect, we keep prospect tag
1596 1671
 			$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
1597 1672
 			$sql.= " SET client = ".$newclient;
1598 1673
 			$sql.= " WHERE rowid = " . $this->id;
@@ -1602,8 +1677,9 @@  discard block
 block discarded – undo
1602 1677
 			{
1603 1678
 				$this->client = $newclient;
1604 1679
 				return 1;
1680
+			} else {
1681
+			    return -1;
1605 1682
 			}
1606
-			else return -1;
1607 1683
 		}
1608 1684
 		return 0;
1609 1685
 	}
@@ -1786,14 +1862,14 @@  discard block
 block discarded – undo
1786 1862
 			if ($result > 0)
1787 1863
 			{
1788 1864
 				return $result;
1789
-			}
1790
-			else
1865
+			} else
1791 1866
 			{
1792 1867
 				$this->error=$discount->error;
1793 1868
 				return -3;
1794 1869
 			}
1870
+		} else {
1871
+		    return 0;
1795 1872
 		}
1796
-		else return 0;
1797 1873
 	}
1798 1874
 
1799 1875
 	/**
@@ -1814,8 +1890,7 @@  discard block
 block discarded – undo
1814 1890
 		if ($result >= 0)
1815 1891
 		{
1816 1892
 			return $result;
1817
-		}
1818
-		else
1893
+		} else
1819 1894
 		{
1820 1895
 			$this->error=$discountstatic->error;
1821 1896
 			return -1;
@@ -1843,9 +1918,9 @@  discard block
 block discarded – undo
1843 1918
 			$sql.= " WHERE ((ug.fk_user = sc.fk_user";
1844 1919
 			$sql.= " AND ug.entity = ".$conf->entity.")";
1845 1920
 			$sql.= " OR u.admin = 1)";
1921
+		} else {
1922
+					$sql.= " WHERE entity in (0, ".$conf->entity.")";
1846 1923
 		}
1847
-		else
1848
-			$sql.= " WHERE entity in (0, ".$conf->entity.")";
1849 1924
 
1850 1925
 		$sql.= " AND u.rowid = sc.fk_user AND sc.fk_soc = ".$this->id;
1851 1926
 
@@ -1868,16 +1943,14 @@  discard block
 block discarded – undo
1868 1943
 					$reparray[$i]['entity']=$obj->entity;
1869 1944
 					$reparray[$i]['login']=$obj->login;
1870 1945
 					$reparray[$i]['photo']=$obj->photo;
1871
-				}
1872
-				else
1946
+				} else
1873 1947
 				{
1874 1948
 					$reparray[]=$obj->rowid;
1875 1949
 				}
1876 1950
 				$i++;
1877 1951
 			}
1878 1952
 			return $reparray;
1879
-		}
1880
-		else {
1953
+		} else {
1881 1954
 			dol_print_error($this->db);
1882 1955
 			return -1;
1883 1956
 		}
@@ -1950,12 +2023,13 @@  discard block
 block discarded – undo
1950 2023
 			if (! $this->db->query($sql) )
1951 2024
 			{
1952 2025
 				dol_syslog(get_class($this)."::add_commercial Erreur");
1953
-			}
1954
-			else {
2026
+			} else {
1955 2027
 				$this->context=array('commercial_modified'=>$commid);
1956 2028
 
1957 2029
 				$result=$this->call_trigger('COMPANY_LINK_SALE_REPRESENTATIVE',$user);
1958
-                if ($result < 0) $error++;
2030
+                if ($result < 0) {
2031
+                    $error++;
2032
+                }
1959 2033
 			}
1960 2034
 		}
1961 2035
 	}
@@ -1975,7 +2049,9 @@  discard block
 block discarded – undo
1975 2049
 		$this->context=array('commercial_modified'=>$commid);
1976 2050
 
1977 2051
 		$result=$this->call_trigger('COMPANY_UNLINK_SALE_REPRESENTATIVE',$user);
1978
-        if ($result < 0) $error++;
2052
+        if ($result < 0) {
2053
+            $error++;
2054
+        }
1979 2055
 
1980 2056
 		if ($this->id > 0 && $commid > 0)
1981 2057
 		{
@@ -2004,14 +2080,21 @@  discard block
 block discarded – undo
2004 2080
 	{
2005 2081
 		global $conf, $langs, $hookmanager;
2006 2082
 
2007
-		if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
2083
+		if (! empty($conf->dol_no_mouse_hover)) {
2084
+		    $notooltip=1;
2085
+		}
2086
+		// Force disable tooltips
2008 2087
 
2009 2088
 		$name=$this->name?$this->name:$this->nom;
2010 2089
 
2011 2090
 		if(!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)){
2012 2091
 
2013
-             if(empty($option) && $this->client > 0) $option = 'customer';
2014
-             if(empty($option) && $this->fournisseur > 0) $option = 'supplier';
2092
+             if(empty($option) && $this->client > 0) {
2093
+                 $option = 'customer';
2094
+             }
2095
+             if(empty($option) && $this->fournisseur > 0) {
2096
+                 $option = 'supplier';
2097
+             }
2015 2098
          }
2016 2099
 
2017 2100
 
@@ -2039,14 +2122,15 @@  discard block
 block discarded – undo
2039 2122
 			if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1)
2040 2123
 			{
2041 2124
 				$name =$code.' '.$name;
2042
-			}
2043
-			else
2125
+			} else
2044 2126
 			{
2045 2127
 				$name =$code;
2046 2128
 			}
2047 2129
 		}
2048 2130
 
2049
-		if (!empty($this->name_alias)) $name .= ' ('.$this->name_alias.')';
2131
+		if (!empty($this->name_alias)) {
2132
+		    $name .= ' ('.$this->name_alias.')';
2133
+		}
2050 2134
 
2051 2135
 		$result=''; $label='';
2052 2136
 		$linkstart=''; $linkend='';
@@ -2064,38 +2148,31 @@  discard block
 block discarded – undo
2064 2148
 		{
2065 2149
 		   $label.= '<u>' . $langs->trans("ShowCustomer") . '</u>';
2066 2150
 		   $linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id;
2067
-		}
2068
-		elseif ($option == 'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
2151
+		} elseif ($option == 'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
2069 2152
 		{
2070 2153
 			$label.= '<u>' . $langs->trans("ShowProspect") . '</u>';
2071 2154
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id;
2072
-		}
2073
-		elseif ($option == 'supplier')
2155
+		} elseif ($option == 'supplier')
2074 2156
 		{
2075 2157
 			$label.= '<u>' . $langs->trans("ShowSupplier") . '</u>';
2076 2158
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$this->id;
2077
-		}
2078
-		elseif ($option == 'agenda')
2159
+		} elseif ($option == 'agenda')
2079 2160
 		{
2080 2161
 			$label.= '<u>' . $langs->trans("ShowAgenda") . '</u>';
2081 2162
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/agenda.php?socid='.$this->id;
2082
-		}
2083
-		elseif ($option == 'project')
2163
+		} elseif ($option == 'project')
2084 2164
 		{
2085 2165
 			$label.= '<u>' . $langs->trans("ShowProject") . '</u>';
2086 2166
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/project.php?socid='.$this->id;
2087
-		}
2088
-		elseif ($option == 'margin')
2167
+		} elseif ($option == 'margin')
2089 2168
 		{
2090 2169
 			$label.= '<u>' . $langs->trans("ShowMargin") . '</u>';
2091 2170
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/margin/tabs/thirdpartyMargins.php?socid='.$this->id.'&type=1';
2092
-		}
2093
-		elseif ($option == 'contact')
2171
+		} elseif ($option == 'contact')
2094 2172
 		{
2095 2173
 			$label.= '<u>' . $langs->trans("ShowContacts") . '</u>';
2096 2174
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/contact.php?socid='.$this->id;
2097
-		}
2098
-		elseif ($option == 'ban')
2175
+		} elseif ($option == 'ban')
2099 2176
 		{
2100 2177
 			$label.= '<u>' . $langs->trans("ShowBan") . '</u>';
2101 2178
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$this->id;
@@ -2111,30 +2188,50 @@  discard block
 block discarded – undo
2111 2188
 		if (! empty($this->name))
2112 2189
 		{
2113 2190
 			$label.= '<br><b>' . $langs->trans('Name') . ':</b> '. $this->name;
2114
-			if (! empty($this->name_alias)) $label.=' ('.$this->name_alias.')';
2191
+			if (! empty($this->name_alias)) {
2192
+			    $label.=' ('.$this->name_alias.')';
2193
+			}
2115 2194
 			$label.= '<br><b>' . $langs->trans('Email') . ':</b> '. $this->email;
2116 2195
 		}
2117
-		if (! empty($this->country_code))
2118
-			$label.= '<br><b>' . $langs->trans('Country') . ':</b> '. $this->country_code;
2119
-		if (! empty($this->tva_intra) || (! empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'vatnumber') !== false))
2120
-			$label.= '<br><b>' . $langs->trans('VATIntra') . ':</b> '. $this->tva_intra;
2196
+		if (! empty($this->country_code)) {
2197
+					$label.= '<br><b>' . $langs->trans('Country') . ':</b> '. $this->country_code;
2198
+		}
2199
+		if (! empty($this->tva_intra) || (! empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'vatnumber') !== false)) {
2200
+					$label.= '<br><b>' . $langs->trans('VATIntra') . ':</b> '. $this->tva_intra;
2201
+		}
2121 2202
 		if (! empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP))
2122 2203
 		{
2123
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid1') !== false) $label.= '<br><b>' . $langs->trans('ProfId1'.$this->country_code) . ':</b> '. $this->idprof1;
2124
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid2') !== false) $label.= '<br><b>' . $langs->trans('ProfId2'.$this->country_code) . ':</b> '. $this->idprof2;
2125
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid3') !== false) $label.= '<br><b>' . $langs->trans('ProfId3'.$this->country_code) . ':</b> '. $this->idprof3;
2126
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid4') !== false) $label.= '<br><b>' . $langs->trans('ProfId4'.$this->country_code) . ':</b> '. $this->idprof4;
2127
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid5') !== false) $label.= '<br><b>' . $langs->trans('ProfId5'.$this->country_code) . ':</b> '. $this->idprof5;
2128
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid6') !== false) $label.= '<br><b>' . $langs->trans('ProfId6'.$this->country_code) . ':</b> '. $this->idprof6;
2129
-		}
2130
-		if (! empty($this->code_client) && ($this->client == 1 || $this->client == 3))
2131
-			$label.= '<br><b>' . $langs->trans('CustomerCode') . ':</b> '. $this->code_client;
2132
-		if (! empty($this->code_fournisseur) && $this->fournisseur)
2133
-			$label.= '<br><b>' . $langs->trans('SupplierCode') . ':</b> '. $this->code_fournisseur;
2134
-		if (! empty($conf->accounting->enabled) && ($this->client == 1 || $this->client == 3))
2135
-			$label.= '<br><b>' . $langs->trans('CustomerAccountancyCode') . ':</b> '. ($this->code_compta ? $this->code_compta : $this->code_compta_client);
2136
-		if (! empty($conf->accounting->enabled) && $this->fournisseur)
2137
-			$label.= '<br><b>' . $langs->trans('SupplierAccountancyCode') . ':</b> '. $this->code_compta_fournisseur;
2204
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid1') !== false) {
2205
+			    $label.= '<br><b>' . $langs->trans('ProfId1'.$this->country_code) . ':</b> '. $this->idprof1;
2206
+			}
2207
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid2') !== false) {
2208
+			    $label.= '<br><b>' . $langs->trans('ProfId2'.$this->country_code) . ':</b> '. $this->idprof2;
2209
+			}
2210
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid3') !== false) {
2211
+			    $label.= '<br><b>' . $langs->trans('ProfId3'.$this->country_code) . ':</b> '. $this->idprof3;
2212
+			}
2213
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid4') !== false) {
2214
+			    $label.= '<br><b>' . $langs->trans('ProfId4'.$this->country_code) . ':</b> '. $this->idprof4;
2215
+			}
2216
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid5') !== false) {
2217
+			    $label.= '<br><b>' . $langs->trans('ProfId5'.$this->country_code) . ':</b> '. $this->idprof5;
2218
+			}
2219
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid6') !== false) {
2220
+			    $label.= '<br><b>' . $langs->trans('ProfId6'.$this->country_code) . ':</b> '. $this->idprof6;
2221
+			}
2222
+		}
2223
+		if (! empty($this->code_client) && ($this->client == 1 || $this->client == 3)) {
2224
+					$label.= '<br><b>' . $langs->trans('CustomerCode') . ':</b> '. $this->code_client;
2225
+		}
2226
+		if (! empty($this->code_fournisseur) && $this->fournisseur) {
2227
+					$label.= '<br><b>' . $langs->trans('SupplierCode') . ':</b> '. $this->code_fournisseur;
2228
+		}
2229
+		if (! empty($conf->accounting->enabled) && ($this->client == 1 || $this->client == 3)) {
2230
+					$label.= '<br><b>' . $langs->trans('CustomerAccountancyCode') . ':</b> '. ($this->code_compta ? $this->code_compta : $this->code_compta_client);
2231
+		}
2232
+		if (! empty($conf->accounting->enabled) && $this->fournisseur) {
2233
+					$label.= '<br><b>' . $langs->trans('SupplierAccountancyCode') . ':</b> '. $this->code_compta_fournisseur;
2234
+		}
2138 2235
 
2139 2236
 		$label.= '</div>';
2140 2237
 
@@ -2142,8 +2239,12 @@  discard block
 block discarded – undo
2142 2239
 		$linkstart.=(!empty($this->canvas)?'&canvas='.$this->canvas:'');
2143 2240
 		// Add param to save lastsearch_values or not
2144 2241
 		$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
2145
-		if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
2146
-		if ($add_save_lastsearch_values) $linkstart.='&save_lastsearch_values=1';
2242
+		if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) {
2243
+		    $add_save_lastsearch_values=1;
2244
+		}
2245
+		if ($add_save_lastsearch_values) {
2246
+		    $linkstart.='&save_lastsearch_values=1';
2247
+		}
2147 2248
 		$linkstart.='"';
2148 2249
 
2149 2250
 		$linkclose='';
@@ -2175,16 +2276,23 @@  discard block
 block discarded – undo
2175 2276
 		}
2176 2277
 
2177 2278
 		$result.=$linkstart;
2178
-		if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip valigntextbottom"'), 0, 0, $notooltip?0:1);
2179
-		if ($withpicto != 2) $result.=($maxlen?dol_trunc($name,$maxlen):$name);
2279
+		if ($withpicto) {
2280
+		    $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip valigntextbottom"'), 0, 0, $notooltip?0:1);
2281
+		}
2282
+		if ($withpicto != 2) {
2283
+		    $result.=($maxlen?dol_trunc($name,$maxlen):$name);
2284
+		}
2180 2285
 		$result.=$linkend;
2181 2286
 
2182 2287
 		global $action;
2183 2288
 		$hookmanager->initHooks(array('thirdpartydao'));
2184 2289
 		$parameters=array('id'=>$this->id, 'getnomurl'=>$result);
2185 2290
 		$reshook=$hookmanager->executeHooks('getNomUrl',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
2186
-		if ($reshook > 0) $result = $hookmanager->resPrint;
2187
-		else $result .= $hookmanager->resPrint;
2291
+		if ($reshook > 0) {
2292
+		    $result = $hookmanager->resPrint;
2293
+		} else {
2294
+		    $result .= $hookmanager->resPrint;
2295
+		}
2188 2296
 
2189 2297
 		return $result;
2190 2298
 	}
@@ -2216,38 +2324,53 @@  discard block
 block discarded – undo
2216 2324
 
2217 2325
 		if ($mode == 0)
2218 2326
 		{
2219
-			if ($statut==0) return $langs->trans("ActivityCeased");
2220
-			elseif ($statut==1) return $langs->trans("InActivity");
2221
-		}
2222
-		elseif ($mode == 1)
2327
+			if ($statut==0) {
2328
+			    return $langs->trans("ActivityCeased");
2329
+			} elseif ($statut==1) {
2330
+			    return $langs->trans("InActivity");
2331
+			}
2332
+		} elseif ($mode == 1)
2223 2333
 		{
2224
-			if ($statut==0) return $langs->trans("ActivityCeased");
2225
-			elseif ($statut==1) return $langs->trans("InActivity");
2226
-		}
2227
-		elseif ($mode == 2)
2334
+			if ($statut==0) {
2335
+			    return $langs->trans("ActivityCeased");
2336
+			} elseif ($statut==1) {
2337
+			    return $langs->trans("InActivity");
2338
+			}
2339
+		} elseif ($mode == 2)
2228 2340
 		{
2229
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2230
-			elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2231
-		}
2232
-		elseif ($mode == 3)
2341
+			if ($statut==0) {
2342
+			    return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2343
+			} elseif ($statut==1) {
2344
+			    return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2345
+			}
2346
+		} elseif ($mode == 3)
2233 2347
 		{
2234
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2235
-			elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2236
-		}
2237
-		elseif ($mode == 4)
2348
+			if ($statut==0) {
2349
+			    return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2350
+			} elseif ($statut==1) {
2351
+			    return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2352
+			}
2353
+		} elseif ($mode == 4)
2238 2354
 		{
2239
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2240
-			elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2241
-		}
2242
-		elseif ($mode == 5)
2355
+			if ($statut==0) {
2356
+			    return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2357
+			} elseif ($statut==1) {
2358
+			    return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2359
+			}
2360
+		} elseif ($mode == 5)
2243 2361
 		{
2244
-			if ($statut==0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2245
-			elseif ($statut==1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2246
-		}
2247
-		elseif ($mode == 6)
2362
+			if ($statut==0) {
2363
+			    return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2364
+			} elseif ($statut==1) {
2365
+			    return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2366
+			}
2367
+		} elseif ($mode == 6)
2248 2368
 		{
2249
-			if ($statut==0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2250
-			elseif ($statut==1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2369
+			if ($statut==0) {
2370
+			    return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2371
+			} elseif ($statut==1) {
2372
+			    return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2373
+			}
2251 2374
 		}
2252 2375
 	}
2253 2376
 
@@ -2266,7 +2389,9 @@  discard block
 block discarded – undo
2266 2389
 		$contact_emails = $this->contact_property_array('email',1);
2267 2390
 		if ($this->email && $addthirdparty)
2268 2391
 		{
2269
-			if (empty($this->name)) $this->name=$this->nom;
2392
+			if (empty($this->name)) {
2393
+			    $this->name=$this->nom;
2394
+			}
2270 2395
 			$contact_emails['thirdparty']=$langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->email.">";
2271 2396
 		}
2272 2397
 		//var_dump($contact_emails)
@@ -2286,9 +2411,11 @@  discard block
 block discarded – undo
2286 2411
 
2287 2412
 		$contact_phone = $this->contact_property_array('mobile');
2288 2413
 
2289
-		if (! empty($this->phone))	// If a phone of thirdparty is defined, we add it ot mobile of contacts
2414
+		if (! empty($this->phone)) {
2415
+		    // If a phone of thirdparty is defined, we add it ot mobile of contacts
2290 2416
 		{
2291 2417
 			if (empty($this->name)) $this->name=$this->nom;
2418
+		}
2292 2419
 			// TODO: Tester si tel non deja present dans tableau contact
2293 2420
 			$contact_phone['thirdparty']=$langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->phone.">";
2294 2421
 		}
@@ -2331,24 +2458,30 @@  discard block
 block discarded – undo
2331 2458
 				while ($i < $nump)
2332 2459
 				{
2333 2460
 					$obj = $this->db->fetch_object($resql);
2334
-					if ($mode == 'email') $property=$obj->email;
2335
-					else if ($mode == 'mobile') $property=$obj->phone_mobile;
2336
-					else $property=$obj->$mode;
2461
+					if ($mode == 'email') {
2462
+					    $property=$obj->email;
2463
+					} else if ($mode == 'mobile') {
2464
+					    $property=$obj->phone_mobile;
2465
+					} else {
2466
+					    $property=$obj->$mode;
2467
+					}
2337 2468
 
2338 2469
 					// Show all contact. If hidedisabled is 1, showonly contacts with status = 1
2339 2470
 					if ($obj->statut == 1 || empty($hidedisabled))
2340 2471
 					{
2341 2472
 						if (empty($property))
2342 2473
 						{
2343
-							if ($mode == 'email') $property=$langs->transnoentitiesnoconv("NoEMail");
2344
-							else if ($mode == 'mobile') $property=$langs->transnoentitiesnoconv("NoMobilePhone");
2474
+							if ($mode == 'email') {
2475
+							    $property=$langs->transnoentitiesnoconv("NoEMail");
2476
+							} else if ($mode == 'mobile') {
2477
+							    $property=$langs->transnoentitiesnoconv("NoMobilePhone");
2478
+							}
2345 2479
 						}
2346 2480
 
2347 2481
 						if (!empty($obj->poste))
2348 2482
 						{
2349 2483
 							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname,$obj->lastname)).($obj->poste?" - ".$obj->poste:"").(($mode != 'poste' && $property)?" ".$sepa.$property.$sepb:'');
2350
-						}
2351
-						else
2484
+						} else
2352 2485
 						{
2353 2486
 							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname,$obj->lastname)).(($mode != 'poste' && $property)?" ".$sepa.$property.$sepb:'');
2354 2487
 						}
@@ -2356,8 +2489,7 @@  discard block
 block discarded – undo
2356 2489
 					$i++;
2357 2490
 				}
2358 2491
 			}
2359
-		}
2360
-		else
2492
+		} else
2361 2493
 		{
2362 2494
 			dol_print_error($this->db);
2363 2495
 		}
@@ -2391,8 +2523,7 @@  discard block
 block discarded – undo
2391 2523
 					$i++;
2392 2524
 				}
2393 2525
 			}
2394
-		}
2395
-		else
2526
+		} else
2396 2527
 		{
2397 2528
 			dol_print_error($this->db);
2398 2529
 		}
@@ -2428,8 +2559,7 @@  discard block
 block discarded – undo
2428 2559
 					$i++;
2429 2560
 				}
2430 2561
 			}
2431
-		}
2432
-		else
2562
+		} else
2433 2563
 		{
2434 2564
 			dol_print_error($this->db);
2435 2565
 		}
@@ -2449,7 +2579,9 @@  discard block
 block discarded – undo
2449 2579
         // phpcs:enable
2450 2580
 		$contact_property='';
2451 2581
 
2452
-		if (empty($rowid)) return '';
2582
+		if (empty($rowid)) {
2583
+		    return '';
2584
+		}
2453 2585
 
2454 2586
 		$sql = "SELECT rowid, email, phone_mobile, lastname, firstname";
2455 2587
 		$sql.= " FROM ".MAIN_DB_PREFIX."socpeople";
@@ -2464,12 +2596,14 @@  discard block
 block discarded – undo
2464 2596
 			{
2465 2597
 				$obj = $this->db->fetch_object($resql);
2466 2598
 
2467
-				if ($mode == 'email') $contact_property = dol_string_nospecial(dolGetFirstLastname($obj->firstname, $obj->lastname), ' ', array(","))." <".$obj->email.">";
2468
-				else if ($mode == 'mobile') $contact_property = $obj->phone_mobile;
2599
+				if ($mode == 'email') {
2600
+				    $contact_property = dol_string_nospecial(dolGetFirstLastname($obj->firstname, $obj->lastname), ' ', array(","))." <".$obj->email.">";
2601
+				} else if ($mode == 'mobile') {
2602
+				    $contact_property = $obj->phone_mobile;
2603
+				}
2469 2604
 			}
2470 2605
 			return $contact_property;
2471
-		}
2472
-		else
2606
+		} else
2473 2607
 		{
2474 2608
 			dol_print_error($this->db);
2475 2609
 		}
@@ -2494,8 +2628,7 @@  discard block
 block discarded – undo
2494 2628
 		if ($mode == 'label')
2495 2629
 		{
2496 2630
 			return $bac->getRibLabel(true);
2497
-		}
2498
-		elseif ($mode == 'rum')
2631
+		} elseif ($mode == 'rum')
2499 2632
 		{
2500 2633
 			if (empty($bac->rum))
2501 2634
 			{
@@ -2505,8 +2638,7 @@  discard block
 block discarded – undo
2505 2638
 				$bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id);
2506 2639
 			}
2507 2640
 			return $bac->rum;
2508
-		}
2509
-		elseif ($mode == 'format')
2641
+		} elseif ($mode == 'format')
2510 2642
 		{
2511 2643
 			return $bac->frstrecur;
2512 2644
 		}
@@ -2565,7 +2697,9 @@  discard block
 block discarded – undo
2565 2697
 			foreach ($dirsociete as $dirroot)
2566 2698
 			{
2567 2699
 				$res=dol_include_once($dirroot.$module.'.php');
2568
-				if ($res) break;
2700
+				if ($res) {
2701
+				    break;
2702
+				}
2569 2703
 			}
2570 2704
 			$mod = new $module();
2571 2705
 
@@ -2597,7 +2731,9 @@  discard block
 block discarded – undo
2597 2731
 			foreach ($dirsociete as $dirroot)
2598 2732
 			{
2599 2733
 				$res=dol_include_once($dirroot.$module.'.php');
2600
-				if ($res) break;
2734
+				if ($res) {
2735
+				    break;
2736
+				}
2601 2737
 			}
2602 2738
 			$mod = new $module();
2603 2739
 
@@ -2626,18 +2762,26 @@  discard block
 block discarded – undo
2626 2762
 			foreach ($dirsociete as $dirroot)
2627 2763
 			{
2628 2764
 				$res=dol_include_once($dirroot.$module.'.php');
2629
-				if ($res) break;
2765
+				if ($res) {
2766
+				    break;
2767
+				}
2630 2768
 			}
2631 2769
 
2632 2770
 			$mod = new $module();
2633 2771
 
2634 2772
 			dol_syslog(get_class($this)."::codeclient_modifiable code_client=".$this->code_client." module=".$module);
2635
-			if ($mod->code_modifiable_null && ! $this->code_client) return 1;
2636
-			if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) return 1;
2637
-			if ($mod->code_modifiable) return 1;	// A mettre en dernier
2773
+			if ($mod->code_modifiable_null && ! $this->code_client) {
2774
+			    return 1;
2775
+			}
2776
+			if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) {
2777
+			    return 1;
2778
+			}
2779
+			if ($mod->code_modifiable) {
2780
+			    return 1;
2781
+			}
2782
+			// A mettre en dernier
2638 2783
 			return 0;
2639
-		}
2640
-		else
2784
+		} else
2641 2785
 		{
2642 2786
 			return 0;
2643 2787
 		}
@@ -2662,18 +2806,26 @@  discard block
 block discarded – undo
2662 2806
 			foreach ($dirsociete as $dirroot)
2663 2807
 			{
2664 2808
 				$res=dol_include_once($dirroot.$module.'.php');
2665
-				if ($res) break;
2809
+				if ($res) {
2810
+				    break;
2811
+				}
2666 2812
 			}
2667 2813
 
2668 2814
 			$mod = new $module();
2669 2815
 
2670 2816
 			dol_syslog(get_class($this)."::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur." module=".$module);
2671
-			if ($mod->code_modifiable_null && ! $this->code_fournisseur) return 1;
2672
-			if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) return 1;
2673
-			if ($mod->code_modifiable) return 1;	// A mettre en dernier
2817
+			if ($mod->code_modifiable_null && ! $this->code_fournisseur) {
2818
+			    return 1;
2819
+			}
2820
+			if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) {
2821
+			    return 1;
2822
+			}
2823
+			if ($mod->code_modifiable) {
2824
+			    return 1;
2825
+			}
2826
+			// A mettre en dernier
2674 2827
 			return 0;
2675
-		}
2676
-		else
2828
+		} else
2677 2829
 		{
2678 2830
 			return 0;
2679 2831
 		}
@@ -2702,7 +2854,9 @@  discard block
 block discarded – undo
2702 2854
 			foreach ($dirsociete as $dirroot)
2703 2855
 			{
2704 2856
 				$res=dol_include_once($dirroot.$module.'.php');
2705
-				if ($res) break;
2857
+				if ($res) {
2858
+				    break;
2859
+				}
2706 2860
 			}
2707 2861
 
2708 2862
 			$mod = new $module();
@@ -2710,8 +2864,7 @@  discard block
 block discarded – undo
2710 2864
 		   	dol_syslog(get_class($this)."::check_codeclient code_client=".$this->code_client." module=".$module);
2711 2865
 		   	$result = $mod->verif($this->db, $this->code_client, $this, 0);
2712 2866
 			return $result;
2713
-		}
2714
-		else
2867
+		} else
2715 2868
 		{
2716 2869
 			return 0;
2717 2870
 		}
@@ -2739,7 +2892,9 @@  discard block
 block discarded – undo
2739 2892
 			foreach ($dirsociete as $dirroot)
2740 2893
 			{
2741 2894
 				$res=dol_include_once($dirroot.$module.'.php');
2742
-				if ($res) break;
2895
+				if ($res) {
2896
+				    break;
2897
+				}
2743 2898
 			}
2744 2899
 
2745 2900
 			$mod = new $module();
@@ -2747,8 +2902,7 @@  discard block
 block discarded – undo
2747 2902
 			dol_syslog(get_class($this)."::check_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$module);
2748 2903
 			$result = $mod->verif($this->db, $this->code_fournisseur, $this, 1);
2749 2904
 			return $result;
2750
-		}
2751
-		else
2905
+		} else
2752 2906
 		{
2753 2907
 			return 0;
2754 2908
 		}
@@ -2775,7 +2929,9 @@  discard block
 block discarded – undo
2775 2929
 			foreach ($dirsociete as $dirroot)
2776 2930
 			{
2777 2931
 				$res=dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.'.php');
2778
-				if ($res) break;
2932
+				if ($res) {
2933
+				    break;
2934
+				}
2779 2935
 			}
2780 2936
 
2781 2937
 			if ($res)
@@ -2786,21 +2942,25 @@  discard block
 block discarded – undo
2786 2942
 				// Defini code compta dans $mod->code
2787 2943
 				$result = $mod->get_code($this->db, $this, $type);
2788 2944
 
2789
-				if ($type == 'customer') $this->code_compta = $mod->code;
2790
-				else if ($type == 'supplier') $this->code_compta_fournisseur = $mod->code;
2945
+				if ($type == 'customer') {
2946
+				    $this->code_compta = $mod->code;
2947
+				} else if ($type == 'supplier') {
2948
+				    $this->code_compta_fournisseur = $mod->code;
2949
+				}
2791 2950
 
2792 2951
 				return $result;
2793
-			}
2794
-			else
2952
+			} else
2795 2953
 			{
2796 2954
 				$this->error = 'ErrorAccountancyCodeNotDefined';
2797 2955
 				return -1;
2798 2956
 			}
2799
-		}
2800
-		else
2957
+		} else
2801 2958
 		{
2802
-			if ($type == 'customer') $this->code_compta = '';
2803
-			else if ($type == 'supplier') $this->code_compta_fournisseur = '';
2959
+			if ($type == 'customer') {
2960
+			    $this->code_compta = '';
2961
+			} else if ($type == 'supplier') {
2962
+			    $this->code_compta_fournisseur = '';
2963
+			}
2804 2964
 
2805 2965
 			return 0;
2806 2966
 		}
@@ -2827,13 +2987,13 @@  discard block
 block discarded – undo
2827 2987
 			{
2828 2988
 				$this->parent = $id;
2829 2989
 				return 1;
2830
-			}
2831
-			else
2990
+			} else
2832 2991
 			{
2833 2992
 				return -1;
2834 2993
 			}
2994
+		} else {
2995
+		    return -1;
2835 2996
 		}
2836
-		else return -1;
2837 2997
 	}
2838 2998
 
2839 2999
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -2917,22 +3077,26 @@  discard block
 block discarded – undo
2917 3077
 
2918 3078
 		 //Verify duplicate entries
2919 3079
 		$sql  = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$value."' AND entity IN (".getEntity('societe').")";
2920
-		if($socid) $sql .= " AND rowid <> ".$socid;
3080
+		if($socid) {
3081
+		    $sql .= " AND rowid <> ".$socid;
3082
+		}
2921 3083
 		$resql = $this->db->query($sql);
2922 3084
 		if ($resql)
2923 3085
 		{
2924 3086
 			$obj = $this->db->fetch_object($resql);
2925 3087
 			$count = $obj->idprof;
2926
-		}
2927
-		else
3088
+		} else
2928 3089
 		{
2929 3090
 			$count = 0;
2930 3091
 			print $this->db->error();
2931 3092
 		}
2932 3093
 		$this->db->free($resql);
2933 3094
 
2934
-		if ($count > 0) return true;
2935
-		else return false;
3095
+		if ($count > 0) {
3096
+		    return true;
3097
+		} else {
3098
+		    return false;
3099
+		}
2936 3100
 	}
2937 3101
 
2938 3102
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -2951,7 +3115,9 @@  discard block
 block discarded – undo
2951 3115
 
2952 3116
 		$ok=1;
2953 3117
 
2954
-		if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) return 1;
3118
+		if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
3119
+		    return 1;
3120
+		}
2955 3121
 
2956 3122
 		// Verifie SIREN si pays FR
2957 3123
 		if ($idprof == 1 && $soc->country_code == 'FR')
@@ -2959,8 +3125,12 @@  discard block
 block discarded – undo
2959 3125
 			$chaine=trim($this->idprof1);
2960 3126
 			$chaine=preg_replace('/(\s)/','',$chaine);
2961 3127
 
2962
-			if (!is_numeric($chaine)) return -1;
2963
-			if (dol_strlen($chaine) != 9) return -1;
3128
+			if (!is_numeric($chaine)) {
3129
+			    return -1;
3130
+			}
3131
+			if (dol_strlen($chaine) != 9) {
3132
+			    return -1;
3133
+			}
2964 3134
 
2965 3135
 			// on prend chaque chiffre un par un
2966 3136
 			// si son index (position dans la chaîne en commence à 0 au premier caractère) est impair
@@ -2970,12 +3140,17 @@  discard block
 block discarded – undo
2970 3140
 			for ($index = 0; $index < 9; $index ++)
2971 3141
 			{
2972 3142
 				$number = (int) $siren[$index];
2973
-				if (($index % 2) != 0) { if (($number *= 2) > 9) $number -= 9; }
3143
+				if (($index % 2) != 0) { if (($number *= 2) > 9) {
3144
+				    $number -= 9;
3145
+				}
3146
+				}
2974 3147
 				$sum += $number;
2975 3148
 			}
2976 3149
 
2977 3150
 			// le numéro est valide si la somme des chiffres est multiple de 10
2978
-			if (($sum % 10) != 0) return -1;
3151
+			if (($sum % 10) != 0) {
3152
+			    return -1;
3153
+			}
2979 3154
 		}
2980 3155
 
2981 3156
 		// Verifie SIRET si pays FR
@@ -2984,8 +3159,12 @@  discard block
 block discarded – undo
2984 3159
 			$chaine=trim($this->idprof2);
2985 3160
 			$chaine=preg_replace('/(\s)/','',$chaine);
2986 3161
 
2987
-			if (!is_numeric($chaine)) return -1;
2988
-			if (dol_strlen($chaine) != 14) return -1;
3162
+			if (!is_numeric($chaine)) {
3163
+			    return -1;
3164
+			}
3165
+			if (dol_strlen($chaine) != 14) {
3166
+			    return -1;
3167
+			}
2989 3168
 
2990 3169
 			// on prend chaque chiffre un par un
2991 3170
 			// si son index (position dans la chaîne en commence à 0 au premier caractère) est pair
@@ -2995,12 +3174,17 @@  discard block
 block discarded – undo
2995 3174
 			for ($index = 0; $index < 14; $index ++)
2996 3175
 			{
2997 3176
 				$number = (int) $chaine[$index];
2998
-				if (($index % 2) == 0) { if (($number *= 2) > 9) $number -= 9; }
3177
+				if (($index % 2) == 0) { if (($number *= 2) > 9) {
3178
+				    $number -= 9;
3179
+				}
3180
+				}
2999 3181
 				$sum += $number;
3000 3182
 			}
3001 3183
 
3002 3184
 			// le numéro est valide si la somme des chiffres est multiple de 10
3003
-			if (($sum % 10) != 0) return -1;
3185
+			if (($sum % 10) != 0) {
3186
+			    return -1;
3187
+			}
3004 3188
 		}
3005 3189
 
3006 3190
 		//Verify CIF/NIF/NIE if pays ES
@@ -3011,53 +3195,61 @@  discard block
 block discarded – undo
3011 3195
 			$string=preg_replace('/(\s)/','',$string);
3012 3196
 			$string = strtoupper($string);
3013 3197
 
3014
-			for ($i = 0; $i < 9; $i ++)
3015
-			$num[$i] = substr($string, $i, 1);
3198
+			for ($i = 0; $i < 9; $i ++) {
3199
+						$num[$i] = substr($string, $i, 1);
3200
+			}
3016 3201
 
3017 3202
 			//Check format
3018
-			if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string))
3019
-			return 0;
3203
+			if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string)) {
3204
+						return 0;
3205
+			}
3020 3206
 
3021 3207
 			//Check NIF
3022
-			if (preg_match('/(^[0-9]{8}[A-Z]{1}$)/', $string))
3023
-				if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1))
3208
+			if (preg_match('/(^[0-9]{8}[A-Z]{1}$)/', $string)) {
3209
+							if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1))
3024 3210
 				return 1;
3025
-				else
3026
-				return -1;
3211
+			} else {
3212
+								return -1;
3213
+				}
3027 3214
 
3028 3215
 			//algorithm checking type code CIF
3029 3216
 			$sum = $num[2] + $num[4] + $num[6];
3030
-			for ($i = 1; $i < 8; $i += 2)
3031
-			$sum += intval(substr((2 * $num[$i]),0,1)) + intval(substr((2 * $num[$i]),1,1));
3217
+			for ($i = 1; $i < 8; $i += 2) {
3218
+						$sum += intval(substr((2 * $num[$i]),0,1)) + intval(substr((2 * $num[$i]),1,1));
3219
+			}
3032 3220
 			$n = 10 - substr($sum, strlen($sum) - 1, 1);
3033 3221
 
3034 3222
 			//Chek special NIF
3035
-			if (preg_match('/^[KLM]{1}/', $string))
3036
-				if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1))
3223
+			if (preg_match('/^[KLM]{1}/', $string)) {
3224
+							if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1))
3037 3225
 				return 1;
3038
-				else
3039
-				return -1;
3226
+			} else {
3227
+								return -1;
3228
+				}
3040 3229
 
3041 3230
 			//Check CIF
3042
-			if (preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $string))
3043
-				if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1))
3231
+			if (preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $string)) {
3232
+							if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1))
3044 3233
 				return 2;
3045
-				else
3046
-				return -2;
3234
+			} else {
3235
+								return -2;
3236
+				}
3047 3237
 
3048 3238
 			//Check NIE T
3049
-			if (preg_match('/^[T]{1}/', $string))
3050
-				if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string))
3239
+			if (preg_match('/^[T]{1}/', $string)) {
3240
+							if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string))
3051 3241
 				return 3;
3052
-				else
3053
-				return -3;
3242
+			} else {
3243
+								return -3;
3244
+				}
3054 3245
 
3055 3246
 			//Check NIE XYZ
3056
-			if (preg_match('/^[XYZ]{1}/', $string))
3057
-				if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X','Y','Z'), array('0','1','2'), $string), 0, 8) % 23, 1))
3247
+			if (preg_match('/^[XYZ]{1}/', $string)) {
3248
+							if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X','Y','Z'), array('0','1','2'), $string), 0, 8) % 23, 1))
3058 3249
 				return 3;
3059
-				else
3060
-				return -3;
3250
+			} else {
3251
+								return -3;
3252
+				}
3061 3253
 
3062 3254
 			//Can not be verified
3063 3255
 			return -4;
@@ -3077,8 +3269,7 @@  discard block
 block discarded – undo
3077 3269
 			//Check NIF
3078 3270
 			if (preg_match('/(^[0-9]{9}$)/', $string)) {
3079 3271
 				return 1;
3080
-			}
3081
-			else {
3272
+			} else {
3082 3273
 				return -1;
3083 3274
 			}
3084 3275
 		}
@@ -3132,8 +3323,7 @@  discard block
 block discarded – undo
3132 3323
 			if ($url) {
3133 3324
 				return '<a target="_blank" href="'.$url.'">'.$langs->trans("Check").'</a>';
3134 3325
 			}
3135
-		}
3136
-		else {
3326
+		} else {
3137 3327
 			return $hookmanager->resPrint;
3138 3328
 		}
3139 3329
 
@@ -3155,8 +3345,7 @@  discard block
 block discarded – undo
3155 3345
 		{
3156 3346
 			$obj = $this->db->fetch_object($resql);
3157 3347
 			$count = $obj->numproj;
3158
-		}
3159
-		else
3348
+		} else
3160 3349
 		{
3161 3350
 			$count = 0;
3162 3351
 			print $this->db->error();
@@ -3206,8 +3395,7 @@  discard block
 block discarded – undo
3206 3395
 			}
3207 3396
 
3208 3397
 			$this->db->free($result);
3209
-		}
3210
-		else
3398
+		} else
3211 3399
 		{
3212 3400
 			dol_print_error($this->db);
3213 3401
 		}
@@ -3224,12 +3412,16 @@  discard block
 block discarded – undo
3224 3412
 
3225 3413
 		// Define if third party is treated as company (or not) when nature is unknown
3226 3414
 		$isacompany=empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES)?0:1; // 0 by default
3227
-		if (! empty($this->tva_intra)) $isacompany=1;
3228
-		else if (! empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN')
3415
+		if (! empty($this->tva_intra)) {
3416
+		    $isacompany=1;
3417
+		} else if (! empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN')
3229 3418
 		{
3230 3419
 			// TODO Add a field is_a_company into dictionary
3231
-			if (preg_match('/^TE_PRIVATE/', $this->typent_code)) $isacompany=0;
3232
-			else $isacompany=1;
3420
+			if (preg_match('/^TE_PRIVATE/', $this->typent_code)) {
3421
+			    $isacompany=0;
3422
+			} else {
3423
+			    $isacompany=1;
3424
+			}
3233 3425
 		}
3234 3426
 
3235 3427
 		return $isacompany;
@@ -3268,8 +3460,7 @@  discard block
 block discarded – undo
3268 3460
 				$this->SupplierCategories[$obj->rowid] = $obj->label;
3269 3461
 			}
3270 3462
 			return 0;
3271
-		}
3272
-		else
3463
+		} else
3273 3464
 		{
3274 3465
 			return -1;
3275 3466
 		}
@@ -3290,9 +3481,10 @@  discard block
 block discarded – undo
3290 3481
 			$sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_fournisseur (fk_categorie, fk_soc) ";
3291 3482
 			$sql.= " VALUES (".$categorie_id.", ".$this->id.")";
3292 3483
 
3293
-			if ($resql=$this->db->query($sql)) return 0;
3294
-		}
3295
-		else
3484
+			if ($resql=$this->db->query($sql)) {
3485
+			    return 0;
3486
+			}
3487
+		} else
3296 3488
 		{
3297 3489
 			return 0;
3298 3490
 		}
@@ -3318,7 +3510,9 @@  discard block
 block discarded – undo
3318 3510
 		dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG);
3319 3511
 
3320 3512
 		$name = $socname?$socname:$member->societe;
3321
-		if (empty($name)) $name=$member->getFullName($langs);
3513
+		if (empty($name)) {
3514
+		    $name=$member->getFullName($langs);
3515
+		}
3322 3516
 
3323 3517
 		$alias = $socalias?$socalias:'';
3324 3518
 
@@ -3356,16 +3550,14 @@  discard block
 block discarded – undo
3356 3550
 			{
3357 3551
 				$this->db->commit();
3358 3552
 				return $this->id;
3359
-			}
3360
-			else
3553
+			} else
3361 3554
 			{
3362 3555
 				$this->error=$this->db->error();
3363 3556
 
3364 3557
 				$this->db->rollback();
3365 3558
 				return -1;
3366 3559
 			}
3367
-		}
3368
-		else
3560
+		} else
3369 3561
 		{
3370 3562
 			// $this->error deja positionne
3371 3563
 			dol_syslog(get_class($this)."::create_from_member - 2 - ".$this->error." - ".join(',',$this->errors), LOG_ERR);
@@ -3404,12 +3596,13 @@  discard block
 block discarded – undo
3404 3596
 		{
3405 3597
 			$tmp=explode(':',$conf->global->MAIN_INFO_SOCIETE_COUNTRY);
3406 3598
 			$country_id=$tmp[0];
3407
-			if (! empty($tmp[1]))   // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label"
3599
+			if (! empty($tmp[1])) {
3600
+			    // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label"
3408 3601
 			{
3409 3602
 				$country_code=$tmp[1];
3410
-				$country_label=$tmp[2];
3411 3603
 			}
3412
-			else                    // For backward compatibility
3604
+				$country_label=$tmp[2];
3605
+			} else                    // For backward compatibility
3413 3606
 			{
3414 3607
 				dol_syslog("Your country setup use an old syntax. Reedit it using setup area.", LOG_ERR);
3415 3608
 				include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
@@ -3420,7 +3613,9 @@  discard block
 block discarded – undo
3420 3613
 		$this->country_id=$country_id;
3421 3614
 		$this->country_code=$country_code;
3422 3615
 		$this->country=$country_label;
3423
-		if (is_object($langs)) $this->country=($langs->trans('Country'.$country_code)!='Country'.$country_code)?$langs->trans('Country'.$country_code):$country_label;
3616
+		if (is_object($langs)) {
3617
+		    $this->country=($langs->trans('Country'.$country_code)!='Country'.$country_code)?$langs->trans('Country'.$country_code):$country_label;
3618
+		}
3424 3619
 
3425 3620
 		$this->phone=empty($conf->global->MAIN_INFO_SOCIETE_TEL)?'':$conf->global->MAIN_INFO_SOCIETE_TEL;
3426 3621
 		$this->fax=empty($conf->global->MAIN_INFO_SOCIETE_FAX)?'':$conf->global->MAIN_INFO_SOCIETE_FAX;
@@ -3514,17 +3709,22 @@  discard block
 block discarded – undo
3514 3709
 		$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
3515 3710
 		$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'";
3516 3711
 		$sql .= " AND t.active = 1";
3517
-		if (empty($localTaxNum))   $sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
3518
-		elseif ($localTaxNum == 1) $sql .= " AND t.localtax1_type <> '0'";
3519
-		elseif ($localTaxNum == 2) $sql .= " AND t.localtax2_type <> '0'";
3712
+		if (empty($localTaxNum)) {
3713
+		    $sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
3714
+		} elseif ($localTaxNum == 1) {
3715
+		    $sql .= " AND t.localtax1_type <> '0'";
3716
+		} elseif ($localTaxNum == 2) {
3717
+		    $sql .= " AND t.localtax2_type <> '0'";
3718
+		}
3520 3719
 
3521 3720
 		dol_syslog("useLocalTax", LOG_DEBUG);
3522 3721
 		$resql=$this->db->query($sql);
3523 3722
 		if ($resql)
3524 3723
 		{
3525 3724
    			return ($this->db->num_rows($resql) > 0);
3725
+		} else {
3726
+		    return false;
3526 3727
 		}
3527
-		else return false;
3528 3728
 	}
3529 3729
 
3530 3730
 	/**
@@ -3544,8 +3744,9 @@  discard block
 block discarded – undo
3544 3744
 		if ($resql)
3545 3745
 		{
3546 3746
 			return ($this->db->num_rows($resql) > 0);
3747
+		} else {
3748
+		    return false;
3547 3749
 		}
3548
-		else return false;
3549 3750
 	}
3550 3751
 
3551 3752
 	/**
@@ -3566,8 +3767,7 @@  discard block
 block discarded – undo
3566 3767
 		{
3567 3768
 			$obj=$this->db->fetch_object($resql);
3568 3769
    			return (($obj->nb > 0)?true:false);
3569
-		}
3570
-		else
3770
+		} else
3571 3771
 		{
3572 3772
 			$this->error=$this->db->lasterror();
3573 3773
 			return false;
@@ -3649,36 +3849,51 @@  discard block
 block discarded – undo
3649 3849
 
3650 3850
 		if ($mode == 2)
3651 3851
 		{
3652
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3653
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3654
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3655
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3656
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3657
-			else
3852
+			if ($statut == '-1' || $statut == 'ST_NO') {
3853
+			    return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3854
+			} elseif ($statut ==  '0' || $statut == 'ST_NEVER') {
3855
+			    return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3856
+			} elseif ($statut ==  '1' || $statut == 'ST_TODO') {
3857
+			    return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3858
+			} elseif ($statut ==  '2' || $statut == 'ST_PEND') {
3859
+			    return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3860
+			} elseif ($statut ==  '3' || $statut == 'ST_DONE') {
3861
+			    return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3862
+			} else
3658 3863
 			{
3659 3864
 				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
3660 3865
 			}
3661 3866
 		}
3662 3867
 		if ($mode == 3)
3663 3868
 		{
3664
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1);
3665
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0);
3666
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1);
3667
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2);
3668
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3);
3669
-			else
3869
+			if ($statut == '-1' || $statut == 'ST_NO') {
3870
+			    return img_action($langs->trans("StatusProspect-1"),-1);
3871
+			} elseif ($statut ==  '0' || $statut == 'ST_NEVER') {
3872
+			    return img_action($langs->trans("StatusProspect0"), 0);
3873
+			} elseif ($statut ==  '1' || $statut == 'ST_TODO') {
3874
+			    return img_action($langs->trans("StatusProspect1"), 1);
3875
+			} elseif ($statut ==  '2' || $statut == 'ST_PEND') {
3876
+			    return img_action($langs->trans("StatusProspect2"), 2);
3877
+			} elseif ($statut ==  '3' || $statut == 'ST_DONE') {
3878
+			    return img_action($langs->trans("StatusProspect3"), 3);
3879
+			} else
3670 3880
 			{
3671 3881
 				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0);
3672 3882
 			}
3673 3883
 		}
3674 3884
 		if ($mode == 4)
3675 3885
 		{
3676
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3677
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3678
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3679
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3680
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3681
-			else
3886
+			if ($statut == '-1' || $statut == 'ST_NO') {
3887
+			    return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3888
+			} elseif ($statut ==  '0' || $statut == 'ST_NEVER') {
3889
+			    return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3890
+			} elseif ($statut ==  '1' || $statut == 'ST_TODO') {
3891
+			    return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3892
+			} elseif ($statut ==  '2' || $statut == 'ST_PEND') {
3893
+			    return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3894
+			} elseif ($statut ==  '3' || $statut == 'ST_DONE') {
3895
+			    return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3896
+			} else
3682 3897
 			{
3683 3898
 				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
3684 3899
 			}
@@ -3710,7 +3925,9 @@  discard block
 block discarded – undo
3710 3925
 	function getOutstandingProposals($mode='customer')
3711 3926
 	{
3712 3927
 		$table='propal';
3713
-		if ($mode == 'supplier') $table = 'supplier_proposal';
3928
+		if ($mode == 'supplier') {
3929
+		    $table = 'supplier_proposal';
3930
+		}
3714 3931
 
3715 3932
 		$sql  = "SELECT rowid, total_ht, total as total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
3716 3933
 		$sql .= " WHERE fk_soc = ". $this->id;
@@ -3730,15 +3947,17 @@  discard block
 block discarded – undo
3730 3947
 			while($obj=$this->db->fetch_object($resql)) {
3731 3948
 				$outstandingTotal+= $obj->total_ht;
3732 3949
 				$outstandingTotalIncTax+= $obj->total_ttc;
3733
-				if ($obj->fk_statut != 0)    // Not a draft
3950
+				if ($obj->fk_statut != 0) {
3951
+				    // Not a draft
3734 3952
 				{
3735 3953
 					$outstandingOpened+=$obj->total_ttc;
3736 3954
 				}
3955
+				}
3737 3956
 			}
3738 3957
 			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3958
+		} else {
3959
+					return array();
3739 3960
 		}
3740
-		else
3741
-			return array();
3742 3961
 	}
3743 3962
 
3744 3963
 	/**
@@ -3750,7 +3969,9 @@  discard block
 block discarded – undo
3750 3969
 	function getOutstandingOrders($mode='customer')
3751 3970
 	{
3752 3971
 		$table='commande';
3753
-		if ($mode == 'supplier') $table = 'commande_fournisseur';
3972
+		if ($mode == 'supplier') {
3973
+		    $table = 'commande_fournisseur';
3974
+		}
3754 3975
 
3755 3976
 		$sql  = "SELECT rowid, total_ht, total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
3756 3977
 		$sql .= " WHERE fk_soc = ". $this->id;
@@ -3770,15 +3991,17 @@  discard block
 block discarded – undo
3770 3991
 			while($obj=$this->db->fetch_object($resql)) {
3771 3992
 				$outstandingTotal+= $obj->total_ht;
3772 3993
 				$outstandingTotalIncTax+= $obj->total_ttc;
3773
-				if ($obj->fk_statut != 0)    // Not a draft
3994
+				if ($obj->fk_statut != 0) {
3995
+				    // Not a draft
3774 3996
 				{
3775 3997
 					$outstandingOpened+=$obj->total_ttc;
3776 3998
 				}
3999
+				}
3777 4000
 			}
3778 4001
 			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
4002
+		} else {
4003
+					return array();
3779 4004
 		}
3780
-		else
3781
-			return array();
3782 4005
 	}
3783 4006
 
3784 4007
 	/**
@@ -3790,7 +4013,9 @@  discard block
 block discarded – undo
3790 4013
 	function getOutstandingBills($mode='customer')
3791 4014
 	{
3792 4015
 		$table='facture';
3793
-		if ($mode == 'supplier') $table = 'facture_fourn';
4016
+		if ($mode == 'supplier') {
4017
+		    $table = 'facture_fourn';
4018
+		}
3794 4019
 
3795 4020
 		/* Accurate value of remain to pay is to sum remaintopay for each invoice
3796 4021
 		 $paiement = $invoice->getSommePaiement();
@@ -3799,8 +4024,11 @@  discard block
 block discarded – undo
3799 4024
 		 $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
3800 4025
 		 $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
3801 4026
 		 */
3802
-		if ($mode == 'supplier') $sql  = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3803
-		else $sql  = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
4027
+		if ($mode == 'supplier') {
4028
+		    $sql  = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
4029
+		} else {
4030
+		    $sql  = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
4031
+		}
3804 4032
 		$sql .= " WHERE fk_soc = ". $this->id;
3805 4033
 		if ($mode == 'supplier') {
3806 4034
 			$sql .= " AND entity IN (".getEntity('facture_fourn').")";
@@ -3819,8 +4047,7 @@  discard block
 block discarded – undo
3819 4047
 			{
3820 4048
 				require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
3821 4049
 				$tmpobject=new FactureFournisseur($this->db);
3822
-			}
3823
-			else
4050
+			} else
3824 4051
 			{
3825 4052
 				require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
3826 4053
 				$tmpobject=new Facture($this->db);
@@ -3837,18 +4064,19 @@  discard block
 block discarded – undo
3837 4064
 				if ($obj->paye == 0
3838 4065
 					&& $obj->fk_statut != 0    // Not a draft
3839 4066
 					&& $obj->fk_statut != 3	   // Not abandonned
3840
-					&& $obj->fk_statut != 2)   // Not classified as paid
4067
+					&& $obj->fk_statut != 2) {
4068
+				    // Not classified as paid
3841 4069
 				//$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')";		// Not abandonned for undefined reason
3842 4070
 				{
3843 4071
 					$paiement = $tmpobject->getSommePaiement();
4072
+				}
3844 4073
 					$creditnotes = $tmpobject->getSumCreditNotesUsed();
3845 4074
 					$deposits = $tmpobject->getSumDepositsUsed();
3846 4075
 					$outstandingOpened+=$obj->total_ttc - $paiement - $creditnotes - $deposits;
3847 4076
 				}
3848 4077
 			}
3849 4078
 			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3850
-		}
3851
-		else
4079
+		} else
3852 4080
 		{
3853 4081
 			return array();
3854 4082
 		}
@@ -3895,9 +4123,9 @@  discard block
 block discarded – undo
3895 4123
 				$outstandingAmount+= $obj->total_ttc - $paiement - $creditnotes - $deposits;
3896 4124
 			}
3897 4125
 			return $outstandingAmount;
4126
+		} else {
4127
+					return 0;
3898 4128
 		}
3899
-		else
3900
-			return 0;
3901 4129
 	}
3902 4130
 
3903 4131
 	/**
@@ -3923,10 +4151,18 @@  discard block
 block discarded – undo
3923 4151
 		global $langs;
3924 4152
 		$langs->load('companies');
3925 4153
 
3926
-		if ($statut==0) return $langs->trans("NorProspectNorCustomer");
3927
-		if ($statut==1) return $langs->trans("Customer");
3928
-		if ($statut==2) return $langs->trans("Prospect");
3929
-		if ($statut==3) return $langs->trans("ProspectCustomer");
4154
+		if ($statut==0) {
4155
+		    return $langs->trans("NorProspectNorCustomer");
4156
+		}
4157
+		if ($statut==1) {
4158
+		    return $langs->trans("Customer");
4159
+		}
4160
+		if ($statut==2) {
4161
+		    return $langs->trans("Prospect");
4162
+		}
4163
+		if ($statut==3) {
4164
+		    return $langs->trans("ProspectCustomer");
4165
+		}
3930 4166
 	}
3931 4167
 
3932 4168
 
@@ -3952,10 +4188,11 @@  discard block
 block discarded – undo
3952 4188
 			include_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
3953 4189
 			$companybankaccount = new CompanyBankAccount($this->db);
3954 4190
 			$result = $companybankaccount->fetch($moreparams['use_companybankid']);
3955
-			if (! $result) dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
4191
+			if (! $result) {
4192
+			    dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
4193
+			}
3956 4194
 			$result=$companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3957
-		}
3958
-		else
4195
+		} else
3959 4196
 		{
3960 4197
 			// Positionne le modele sur le nom du modele a utiliser
3961 4198
 			if (! dol_strlen($modele))
@@ -3963,8 +4200,7 @@  discard block
 block discarded – undo
3963 4200
 				if (! empty($conf->global->COMPANY_ADDON_PDF))
3964 4201
 				{
3965 4202
 					$modele = $conf->global->COMPANY_ADDON_PDF;
3966
-				}
3967
-				else
4203
+				} else
3968 4204
 				{
3969 4205
 					print $langs->trans("Error")." ".$langs->trans("Error_COMPANY_ADDON_PDF_NotDefined");
3970 4206
 					return 0;
Please login to merge, or discard this patch.
dolibarr/htdocs/societe/societecontact.php 1 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.
dolibarr/htdocs/societe/project.php 1 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.
dolibarr/htdocs/societe/notify/card.php 1 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.
dolibarr/htdocs/societe/notify/index.php 1 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.
dolibarr/htdocs/societe/card.php 3 patches
Indentation   +1029 added lines, -1029 removed lines patch added patch discarded remove patch
@@ -76,9 +76,9 @@  discard block
 block discarded – undo
76 76
 
77 77
 if (! ($object->id > 0) && $action == 'view')
78 78
 {
79
-	$langs->load("errors");
80
-	print($langs->trans('ErrorRecordNotFound'));
81
-	exit;
79
+    $langs->load("errors");
80
+    print($langs->trans('ErrorRecordNotFound'));
81
+    exit;
82 82
 }
83 83
 
84 84
 // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
@@ -116,191 +116,191 @@  discard block
 block discarded – undo
116 116
         }
117 117
     }
118 118
 
119
-	if ($action == 'confirm_merge' && $confirm == 'yes' && $user->rights->societe->creer)
120
-	{
121
-		$error = 0;
122
-		$soc_origin_id = GETPOST('soc_origin', 'int');
123
-		$soc_origin = new Societe($db);
124
-
125
-		if ($soc_origin_id <= 0)
126
-		{
127
-			$langs->load('errors');
128
-			$langs->load('companies');
129
-			setEventMessages($langs->trans('ErrorThirdPartyIdIsMandatory', $langs->trans('MergeOriginThirdparty')), null, 'errors');
130
-		}
131
-		else
132
-		{
133
-			if (!$error && $soc_origin->fetch($soc_origin_id) < 1)
134
-			{
135
-				setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
136
-				$error++;
137
-			}
138
-
139
-			if (!$error)
140
-			{
141
-			    // TODO Move the merge function into class of object.
142
-
143
-				$db->begin();
144
-
145
-				// Recopy some data
146
-				$object->client = $object->client | $soc_origin->client;
147
-				$object->fournisseur = $object->fournisseur | $soc_origin->fournisseur;
148
-				$listofproperties=array(
149
-					'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'skype', 'twitter', 'facebook', 'url', 'barcode',
150
-					'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6',
151
-					'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'remise_supplier_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis',
152
-					'stcomm_id', 'outstanding_limit', 'price_level', 'parent', 'default_lang', 'ref', 'ref_ext', 'import_key', 'fk_incoterms', 'fk_multicurrency',
153
-					'code_client', 'code_fournisseur', 'code_compta', 'code_compta_fournisseur',
154
-					'model_pdf', 'fk_projet'
155
-				);
156
-				foreach ($listofproperties as $property)
157
-				{
158
-					if (empty($object->$property)) $object->$property = $soc_origin->$property;
159
-				}
119
+    if ($action == 'confirm_merge' && $confirm == 'yes' && $user->rights->societe->creer)
120
+    {
121
+        $error = 0;
122
+        $soc_origin_id = GETPOST('soc_origin', 'int');
123
+        $soc_origin = new Societe($db);
160 124
 
161
-				// Concat some data
162
-				$listofproperties=array(
163
-				    'note_public', 'note_private'
164
-				);
165
-				foreach ($listofproperties as $property)
166
-				{
167
-				    $object->$property = dol_concatdesc($object->$property, $soc_origin->$property);
168
-				}
125
+        if ($soc_origin_id <= 0)
126
+        {
127
+            $langs->load('errors');
128
+            $langs->load('companies');
129
+            setEventMessages($langs->trans('ErrorThirdPartyIdIsMandatory', $langs->trans('MergeOriginThirdparty')), null, 'errors');
130
+        }
131
+        else
132
+        {
133
+            if (!$error && $soc_origin->fetch($soc_origin_id) < 1)
134
+            {
135
+                setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
136
+                $error++;
137
+            }
169 138
 
170
-				// Merge extrafields
171
-				if (is_array($soc_origin->array_options))
172
-				{
173
-					foreach ($soc_origin->array_options as $key => $val)
174
-					{
175
-					    if (empty($object->array_options[$key])) $object->array_options[$key] = $val;
176
-					}
177
-				}
139
+            if (!$error)
140
+            {
141
+                // TODO Move the merge function into class of object.
178 142
 
179
-				// Merge categories
180
-				$static_cat = new Categorie($db);
181
-
182
-				$custcats_ori = $static_cat->containing($soc_origin->id, 'customer', 'id');
183
-				$custcats = $static_cat->containing($object->id, 'customer', 'id');
184
-				$custcats = array_merge($custcats,$custcats_ori);
185
-				$object->setCategories($custcats, 'customer');
186
-
187
-				$suppcats_ori = $static_cat->containing($soc_origin->id, 'supplier', 'id');
188
-				$suppcats = $static_cat->containing($object->id, 'supplier', 'id');
189
-				$suppcats = array_merge($suppcats,$suppcats_ori);
190
-				$object->setCategories($suppcats, 'supplier');
191
-
192
-				// If thirdparty has a new code that is same than origin, we clean origin code to avoid duplicate key from database unique keys.
193
-				if ($soc_origin->code_client == $object->code_client
194
-					|| $soc_origin->code_fournisseur == $object->code_fournisseur
195
-					|| $soc_origin->barcode == $object->barcode)
196
-				{
197
-					dol_syslog("We clean customer and supplier code so we will be able to make the update of target");
198
-					$soc_origin->code_client = '';
199
-					$soc_origin->code_fournisseur = '';
200
-					$soc_origin->barcode = '';
201
-					$soc_origin->update($soc_origin->id, $user, 0, 1, 1, 'merge');
202
-				}
143
+                $db->begin();
203 144
 
204
-				// Update
205
-				$object->update($object->id, $user, 0, 1, 1, 'merge');
206
-				if ($result < 0)
207
-				{
208
-					$error++;
209
-				}
145
+                // Recopy some data
146
+                $object->client = $object->client | $soc_origin->client;
147
+                $object->fournisseur = $object->fournisseur | $soc_origin->fournisseur;
148
+                $listofproperties=array(
149
+                    'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'skype', 'twitter', 'facebook', 'url', 'barcode',
150
+                    'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6',
151
+                    'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'remise_supplier_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis',
152
+                    'stcomm_id', 'outstanding_limit', 'price_level', 'parent', 'default_lang', 'ref', 'ref_ext', 'import_key', 'fk_incoterms', 'fk_multicurrency',
153
+                    'code_client', 'code_fournisseur', 'code_compta', 'code_compta_fournisseur',
154
+                    'model_pdf', 'fk_projet'
155
+                );
156
+                foreach ($listofproperties as $property)
157
+                {
158
+                    if (empty($object->$property)) $object->$property = $soc_origin->$property;
159
+                }
210 160
 
211
-				// Move links
212
-				if (! $error)
213
-				{
214
-					$objects = array(
215
-						'Adherent' => '/adherents/class/adherent.class.php',
216
-						'Societe' => '/societe/class/societe.class.php',
217
-						//'Categorie' => '/categories/class/categorie.class.php',
218
-						'ActionComm' => '/comm/action/class/actioncomm.class.php',
219
-						'Propal' => '/comm/propal/class/propal.class.php',
220
-						'Commande' => '/commande/class/commande.class.php',
221
-						'Facture' => '/compta/facture/class/facture.class.php',
222
-						'FactureRec' => '/compta/facture/class/facture-rec.class.php',
223
-						'LignePrelevement' => '/compta/prelevement/class/ligneprelevement.class.php',
224
-						'Contact' => '/contact/class/contact.class.php',
225
-						'Contrat' => '/contrat/class/contrat.class.php',
226
-						'Expedition' => '/expedition/class/expedition.class.php',
227
-						'Fichinter' => '/fichinter/class/fichinter.class.php',
228
-						'CommandeFournisseur' => '/fourn/class/fournisseur.commande.class.php',
229
-						'FactureFournisseur' => '/fourn/class/fournisseur.facture.class.php',
230
-						'SupplierProposal' => '/supplier_proposal/class/supplier_proposal.class.php',
231
-						'ProductFournisseur' => '/fourn/class/fournisseur.product.class.php',
232
-						'Livraison' => '/livraison/class/livraison.class.php',
233
-						'Product' => '/product/class/product.class.php',
234
-						'Project' => '/projet/class/project.class.php',
235
-						'User' => '/user/class/user.class.php',
236
-					);
237
-
238
-					//First, all core objects must update their tables
239
-					foreach ($objects as $object_name => $object_file)
240
-					{
241
-						require_once DOL_DOCUMENT_ROOT.$object_file;
161
+                // Concat some data
162
+                $listofproperties=array(
163
+                    'note_public', 'note_private'
164
+                );
165
+                foreach ($listofproperties as $property)
166
+                {
167
+                    $object->$property = dol_concatdesc($object->$property, $soc_origin->$property);
168
+                }
242 169
 
243
-						if (!$error && !$object_name::replaceThirdparty($db, $soc_origin->id, $object->id))
244
-						{
245
-							$error++;
246
-							setEventMessages($db->lasterror(), null, 'errors');
247
-						}
248
-					}
249
-				}
170
+                // Merge extrafields
171
+                if (is_array($soc_origin->array_options))
172
+                {
173
+                    foreach ($soc_origin->array_options as $key => $val)
174
+                    {
175
+                        if (empty($object->array_options[$key])) $object->array_options[$key] = $val;
176
+                    }
177
+                }
250 178
 
251
-				// External modules should update their ones too
252
-				if (! $error)
253
-				{
254
-					$reshook = $hookmanager->executeHooks('replaceThirdparty', array(
255
-						'soc_origin' => $soc_origin->id,
256
-						'soc_dest' => $object->id
257
-					), $soc_dest, $action);
179
+                // Merge categories
180
+                $static_cat = new Categorie($db);
258 181
 
259
-					if ($reshook < 0)
260
-					{
261
-						setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
262
-						$error++;
263
-					}
264
-				}
182
+                $custcats_ori = $static_cat->containing($soc_origin->id, 'customer', 'id');
183
+                $custcats = $static_cat->containing($object->id, 'customer', 'id');
184
+                $custcats = array_merge($custcats,$custcats_ori);
185
+                $object->setCategories($custcats, 'customer');
265 186
 
187
+                $suppcats_ori = $static_cat->containing($soc_origin->id, 'supplier', 'id');
188
+                $suppcats = $static_cat->containing($object->id, 'supplier', 'id');
189
+                $suppcats = array_merge($suppcats,$suppcats_ori);
190
+                $object->setCategories($suppcats, 'supplier');
266 191
 
267
-				if (! $error)
268
-				{
269
-					$object->context=array('merge'=>1, 'mergefromid'=>$soc_origin->id);
192
+                // If thirdparty has a new code that is same than origin, we clean origin code to avoid duplicate key from database unique keys.
193
+                if ($soc_origin->code_client == $object->code_client
194
+                    || $soc_origin->code_fournisseur == $object->code_fournisseur
195
+                    || $soc_origin->barcode == $object->barcode)
196
+                {
197
+                    dol_syslog("We clean customer and supplier code so we will be able to make the update of target");
198
+                    $soc_origin->code_client = '';
199
+                    $soc_origin->code_fournisseur = '';
200
+                    $soc_origin->barcode = '';
201
+                    $soc_origin->update($soc_origin->id, $user, 0, 1, 1, 'merge');
202
+                }
270 203
 
271
-					// Call trigger
272
-					$result=$object->call_trigger('COMPANY_MODIFY',$user);
273
-					if ($result < 0)
274
-					{
275
-						setEventMessages($object->error, $object->errors, 'errors');
276
-						$error++;
277
-					}
278
-					// End call triggers
279
-				}
204
+                // Update
205
+                $object->update($object->id, $user, 0, 1, 1, 'merge');
206
+                if ($result < 0)
207
+                {
208
+                    $error++;
209
+                }
280 210
 
281
-				if (!$error)
282
-				{
283
-					//We finally remove the old thirdparty
284
-					if ($soc_origin->delete($soc_origin->id, $user) < 1)
285
-					{
286
-						$error++;
287
-					}
288
-				}
211
+                // Move links
212
+                if (! $error)
213
+                {
214
+                    $objects = array(
215
+                        'Adherent' => '/adherents/class/adherent.class.php',
216
+                        'Societe' => '/societe/class/societe.class.php',
217
+                        //'Categorie' => '/categories/class/categorie.class.php',
218
+                        'ActionComm' => '/comm/action/class/actioncomm.class.php',
219
+                        'Propal' => '/comm/propal/class/propal.class.php',
220
+                        'Commande' => '/commande/class/commande.class.php',
221
+                        'Facture' => '/compta/facture/class/facture.class.php',
222
+                        'FactureRec' => '/compta/facture/class/facture-rec.class.php',
223
+                        'LignePrelevement' => '/compta/prelevement/class/ligneprelevement.class.php',
224
+                        'Contact' => '/contact/class/contact.class.php',
225
+                        'Contrat' => '/contrat/class/contrat.class.php',
226
+                        'Expedition' => '/expedition/class/expedition.class.php',
227
+                        'Fichinter' => '/fichinter/class/fichinter.class.php',
228
+                        'CommandeFournisseur' => '/fourn/class/fournisseur.commande.class.php',
229
+                        'FactureFournisseur' => '/fourn/class/fournisseur.facture.class.php',
230
+                        'SupplierProposal' => '/supplier_proposal/class/supplier_proposal.class.php',
231
+                        'ProductFournisseur' => '/fourn/class/fournisseur.product.class.php',
232
+                        'Livraison' => '/livraison/class/livraison.class.php',
233
+                        'Product' => '/product/class/product.class.php',
234
+                        'Project' => '/projet/class/project.class.php',
235
+                        'User' => '/user/class/user.class.php',
236
+                    );
237
+
238
+                    //First, all core objects must update their tables
239
+                    foreach ($objects as $object_name => $object_file)
240
+                    {
241
+                        require_once DOL_DOCUMENT_ROOT.$object_file;
289 242
 
290
-				if (!$error)
291
-				{
292
-					setEventMessages($langs->trans('ThirdpartiesMergeSuccess'), null, 'mesgs');
293
-					$db->commit();
294
-				}
295
-				else
296
-				{
297
-				    $langs->load("errors");
298
-					setEventMessages($langs->trans('ErrorsThirdpartyMerge'), null, 'errors');
299
-					$db->rollback();
300
-				}
301
-			}
302
-		}
303
-	}
243
+                        if (!$error && !$object_name::replaceThirdparty($db, $soc_origin->id, $object->id))
244
+                        {
245
+                            $error++;
246
+                            setEventMessages($db->lasterror(), null, 'errors');
247
+                        }
248
+                    }
249
+                }
250
+
251
+                // External modules should update their ones too
252
+                if (! $error)
253
+                {
254
+                    $reshook = $hookmanager->executeHooks('replaceThirdparty', array(
255
+                        'soc_origin' => $soc_origin->id,
256
+                        'soc_dest' => $object->id
257
+                    ), $soc_dest, $action);
258
+
259
+                    if ($reshook < 0)
260
+                    {
261
+                        setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
262
+                        $error++;
263
+                    }
264
+                }
265
+
266
+
267
+                if (! $error)
268
+                {
269
+                    $object->context=array('merge'=>1, 'mergefromid'=>$soc_origin->id);
270
+
271
+                    // Call trigger
272
+                    $result=$object->call_trigger('COMPANY_MODIFY',$user);
273
+                    if ($result < 0)
274
+                    {
275
+                        setEventMessages($object->error, $object->errors, 'errors');
276
+                        $error++;
277
+                    }
278
+                    // End call triggers
279
+                }
280
+
281
+                if (!$error)
282
+                {
283
+                    //We finally remove the old thirdparty
284
+                    if ($soc_origin->delete($soc_origin->id, $user) < 1)
285
+                    {
286
+                        $error++;
287
+                    }
288
+                }
289
+
290
+                if (!$error)
291
+                {
292
+                    setEventMessages($langs->trans('ThirdpartiesMergeSuccess'), null, 'mesgs');
293
+                    $db->commit();
294
+                }
295
+                else
296
+                {
297
+                    $langs->load("errors");
298
+                    setEventMessages($langs->trans('ErrorsThirdpartyMerge'), null, 'errors');
299
+                    $db->rollback();
300
+                }
301
+            }
302
+        }
303
+    }
304 304
 
305 305
     if (GETPOST('getcustomercode'))
306 306
     {
@@ -316,17 +316,17 @@  discard block
 block discarded – undo
316 316
 
317 317
     if($action=='set_localtax1')
318 318
     {
319
-    	//obtidre selected del combobox
320
-    	$value=GETPOST('lt1');
321
-    	$object->fetch($socid);
322
-    	$res=$object->setValueFrom('localtax1_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
319
+        //obtidre selected del combobox
320
+        $value=GETPOST('lt1');
321
+        $object->fetch($socid);
322
+        $res=$object->setValueFrom('localtax1_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
323 323
     }
324 324
     if($action=='set_localtax2')
325 325
     {
326
-    	//obtidre selected del combobox
327
-    	$value=GETPOST('lt2');
328
-    	$object->fetch($socid);
329
-    	$res=$object->setValueFrom('localtax2_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
326
+        //obtidre selected del combobox
327
+        $value=GETPOST('lt2');
328
+        $object->fetch($socid);
329
+        $res=$object->setValueFrom('localtax2_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
330 330
     }
331 331
 
332 332
     if ($action == 'update_extras') {
@@ -341,12 +341,12 @@  discard block
 block discarded – undo
341 341
 
342 342
         if (! $error)
343 343
         {
344
-        	$result = $object->insertExtraFields('COMPANY_MODIFY');
345
-        	if ($result < 0)
346
-        	{
347
-        		setEventMessages($object->error, $object->errors, 'errors');
348
-        		$error++;
349
-        	}
344
+            $result = $object->insertExtraFields('COMPANY_MODIFY');
345
+            if ($result < 0)
346
+            {
347
+                setEventMessages($object->error, $object->errors, 'errors');
348
+                $error++;
349
+            }
350 350
         }
351 351
 
352 352
         if ($error) $action = 'edit_extras';
@@ -376,145 +376,145 @@  discard block
 block discarded – undo
376 376
 
377 377
         if (! $error)
378 378
         {
379
-        	if ($action == 'update')
380
-	        {
381
-	        	$ret=$object->fetch($socid);
382
-				$object->oldcopy = clone $object;
383
-	        }
384
-			else $object->canvas=$canvas;
385
-
386
-	        if (GETPOST("private") == 1)	// Ask to create a contact
387
-	        {
388
-	            $object->particulier		= GETPOST("private");
389
-
390
-	            $object->name				= dolGetFirstLastname(GETPOST('firstname','alpha'),GETPOST('name','alpha'));
391
-	            $object->civility_id		= GETPOST('civility_id');	// Note: civility id is a code, not an int
392
-	            // Add non official properties
393
-	            $object->name_bis			= GETPOST('name','alpha');
394
-	            $object->firstname			= GETPOST('firstname','alpha');
395
-	        }
396
-	        else
397
-	        {
398
-	            $object->name				= GETPOST('name', 'alpha');
399
-	        }
400
-	        $object->entity					= (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity);
401
-	        $object->name_alias				= GETPOST('name_alias');
402
-	        $object->address				= GETPOST('address');
403
-	        $object->zip					= GETPOST('zipcode', 'alpha');
404
-	        $object->town					= GETPOST('town', 'alpha');
405
-	        $object->country_id				= GETPOST('country_id', 'int');
406
-	        $object->state_id				= GETPOST('state_id', 'int');
407
-	        $object->skype					= GETPOST('skype', 'alpha');
408
-	        $object->twitter				= GETPOST('twitter', 'alpha');
409
-	        $object->facebook				= GETPOST('facebook', 'alpha');
410
-	        $object->phone					= GETPOST('phone', 'alpha');
411
-	        $object->fax					= GETPOST('fax','alpha');
412
-	        $object->email					= trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL));
413
-	        $object->url					= trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL));
414
-	        $object->idprof1				= trim(GETPOST('idprof1', 'alpha'));
415
-	        $object->idprof2				= trim(GETPOST('idprof2', 'alpha'));
416
-	        $object->idprof3				= trim(GETPOST('idprof3', 'alpha'));
417
-	        $object->idprof4				= trim(GETPOST('idprof4', 'alpha'));
418
-	        $object->idprof5				= trim(GETPOST('idprof5', 'alpha'));
419
-	        $object->idprof6				= trim(GETPOST('idprof6', 'alpha'));
420
-	        $object->prefix_comm			= GETPOST('prefix_comm', 'alpha');
421
-	        $object->code_client			= GETPOSTISSET('customer_code')?GETPOST('customer_code', 'alpha'):GETPOST('code_client', 'alpha');
422
-	        $object->code_fournisseur		= GETPOSTISSET('supplier_code')?GETPOST('supplier_code', 'alpha'):GETPOST('code_fournisseur', 'alpha');
423
-	        $object->capital				= GETPOST('capital', 'alpha');
424
-	        $object->barcode				= GETPOST('barcode', 'alpha');
425
-
426
-	        $object->tva_intra				= GETPOST('tva_intra', 'alpha');
427
-	        $object->tva_assuj				= GETPOST('assujtva_value', 'alpha');
428
-	        $object->status					= GETPOST('status', 'alpha');
429
-
430
-	        // Local Taxes
431
-	        $object->localtax1_assuj		= GETPOST('localtax1assuj_value', 'alpha');
432
-	        $object->localtax2_assuj		= GETPOST('localtax2assuj_value', 'alpha');
433
-
434
-	        $object->localtax1_value		= GETPOST('lt1', 'alpha');
435
-	        $object->localtax2_value		= GETPOST('lt2', 'alpha');
436
-
437
-	        $object->forme_juridique_code	= GETPOST('forme_juridique_code', 'int');
438
-	        $object->effectif_id			= GETPOST('effectif_id', 'int');
439
-	        $object->typent_id				= GETPOST('typent_id','int');
440
-
441
-	        $object->typent_code			= dol_getIdFromCode($db, $object->typent_id, 'c_typent', 'id', 'code');	// Force typent_code too so check in verify() will be done on new type
442
-
443
-	        $object->client					= GETPOST('client', 'int');
444
-	        $object->fournisseur			= GETPOST('fournisseur', 'int');
445
-
446
-	        $object->commercial_id			= GETPOST('commercial_id', 'int');
447
-	        $object->default_lang			= GETPOST('default_lang');
448
-
449
-	        // Webservices url/key
450
-	        $object->webservices_url		= GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
451
-	        $object->webservices_key		= GETPOST('webservices_key', 'san_alpha');
452
-
453
-			// Incoterms
454
-			if (!empty($conf->incoterm->enabled))
455
-			{
456
-				$object->fk_incoterms		= GETPOST('incoterm_id', 'int');
457
-				$object->location_incoterms	= GETPOST('location_incoterms', 'alpha');
458
-			}
459
-
460
-			// Multicurrency
461
-			if (!empty($conf->multicurrency->enabled))
462
-			{
463
-				$object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
464
-			}
465
-
466
-	        // Fill array 'array_options' with data from add form
467
-	        $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
468
-			if ($ret < 0)
469
-			{
470
-				 $error++;
471
-			}
472
-
473
-	        if (GETPOST('deletephoto')) $object->logo = '';
474
-	        else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
475
-
476
-	        // Check parameters
477
-	        if (! GETPOST('cancel','alpha'))
478
-	        {
479
-	            if (! empty($object->email) && ! isValidEMail($object->email))
480
-	            {
481
-	                $langs->load("errors");
482
-	                $error++;
483
-	                setEventMessages('', $langs->trans("ErrorBadEMail",$object->email), 'errors');
484
-	            }
485
-	            if (! empty($object->url) && ! isValidUrl($object->url))
486
-	            {
487
-	                $langs->load("errors");
488
-	                setEventMessages('', $langs->trans("ErrorBadUrl",$object->url), 'errors');
489
-	            }
490
-	            if (! empty($object->webservices_url)) {
491
-	                //Check if has transport, without any the soap client will give error
492
-	                if (strpos($object->webservices_url, "http") === false)
493
-	                {
494
-	                    $object->webservices_url = "http://".$object->webservices_url;
495
-	                }
496
-	                if (! isValidUrl($object->webservices_url)) {
497
-	                    $langs->load("errors");
498
-	                    $error++; $errors[] = $langs->trans("ErrorBadUrl",$object->webservices_url);
499
-	                }
500
-	            }
501
-
502
-	            // We set country_id, country_code and country for the selected country
503
-	            $object->country_id=GETPOST('country_id')!=''?GETPOST('country_id'):$mysoc->country_id;
504
-	            if ($object->country_id)
505
-	            {
506
-	            	$tmparray=getCountry($object->country_id,'all');
507
-	            	$object->country_code=$tmparray['code'];
508
-	            	$object->country=$tmparray['label'];
509
-	            }
510
-	        }
379
+            if ($action == 'update')
380
+            {
381
+                $ret=$object->fetch($socid);
382
+                $object->oldcopy = clone $object;
383
+            }
384
+            else $object->canvas=$canvas;
385
+
386
+            if (GETPOST("private") == 1)	// Ask to create a contact
387
+            {
388
+                $object->particulier		= GETPOST("private");
389
+
390
+                $object->name				= dolGetFirstLastname(GETPOST('firstname','alpha'),GETPOST('name','alpha'));
391
+                $object->civility_id		= GETPOST('civility_id');	// Note: civility id is a code, not an int
392
+                // Add non official properties
393
+                $object->name_bis			= GETPOST('name','alpha');
394
+                $object->firstname			= GETPOST('firstname','alpha');
395
+            }
396
+            else
397
+            {
398
+                $object->name				= GETPOST('name', 'alpha');
399
+            }
400
+            $object->entity					= (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity);
401
+            $object->name_alias				= GETPOST('name_alias');
402
+            $object->address				= GETPOST('address');
403
+            $object->zip					= GETPOST('zipcode', 'alpha');
404
+            $object->town					= GETPOST('town', 'alpha');
405
+            $object->country_id				= GETPOST('country_id', 'int');
406
+            $object->state_id				= GETPOST('state_id', 'int');
407
+            $object->skype					= GETPOST('skype', 'alpha');
408
+            $object->twitter				= GETPOST('twitter', 'alpha');
409
+            $object->facebook				= GETPOST('facebook', 'alpha');
410
+            $object->phone					= GETPOST('phone', 'alpha');
411
+            $object->fax					= GETPOST('fax','alpha');
412
+            $object->email					= trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL));
413
+            $object->url					= trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL));
414
+            $object->idprof1				= trim(GETPOST('idprof1', 'alpha'));
415
+            $object->idprof2				= trim(GETPOST('idprof2', 'alpha'));
416
+            $object->idprof3				= trim(GETPOST('idprof3', 'alpha'));
417
+            $object->idprof4				= trim(GETPOST('idprof4', 'alpha'));
418
+            $object->idprof5				= trim(GETPOST('idprof5', 'alpha'));
419
+            $object->idprof6				= trim(GETPOST('idprof6', 'alpha'));
420
+            $object->prefix_comm			= GETPOST('prefix_comm', 'alpha');
421
+            $object->code_client			= GETPOSTISSET('customer_code')?GETPOST('customer_code', 'alpha'):GETPOST('code_client', 'alpha');
422
+            $object->code_fournisseur		= GETPOSTISSET('supplier_code')?GETPOST('supplier_code', 'alpha'):GETPOST('code_fournisseur', 'alpha');
423
+            $object->capital				= GETPOST('capital', 'alpha');
424
+            $object->barcode				= GETPOST('barcode', 'alpha');
425
+
426
+            $object->tva_intra				= GETPOST('tva_intra', 'alpha');
427
+            $object->tva_assuj				= GETPOST('assujtva_value', 'alpha');
428
+            $object->status					= GETPOST('status', 'alpha');
429
+
430
+            // Local Taxes
431
+            $object->localtax1_assuj		= GETPOST('localtax1assuj_value', 'alpha');
432
+            $object->localtax2_assuj		= GETPOST('localtax2assuj_value', 'alpha');
433
+
434
+            $object->localtax1_value		= GETPOST('lt1', 'alpha');
435
+            $object->localtax2_value		= GETPOST('lt2', 'alpha');
436
+
437
+            $object->forme_juridique_code	= GETPOST('forme_juridique_code', 'int');
438
+            $object->effectif_id			= GETPOST('effectif_id', 'int');
439
+            $object->typent_id				= GETPOST('typent_id','int');
440
+
441
+            $object->typent_code			= dol_getIdFromCode($db, $object->typent_id, 'c_typent', 'id', 'code');	// Force typent_code too so check in verify() will be done on new type
442
+
443
+            $object->client					= GETPOST('client', 'int');
444
+            $object->fournisseur			= GETPOST('fournisseur', 'int');
445
+
446
+            $object->commercial_id			= GETPOST('commercial_id', 'int');
447
+            $object->default_lang			= GETPOST('default_lang');
448
+
449
+            // Webservices url/key
450
+            $object->webservices_url		= GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
451
+            $object->webservices_key		= GETPOST('webservices_key', 'san_alpha');
452
+
453
+            // Incoterms
454
+            if (!empty($conf->incoterm->enabled))
455
+            {
456
+                $object->fk_incoterms		= GETPOST('incoterm_id', 'int');
457
+                $object->location_incoterms	= GETPOST('location_incoterms', 'alpha');
458
+            }
459
+
460
+            // Multicurrency
461
+            if (!empty($conf->multicurrency->enabled))
462
+            {
463
+                $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
464
+            }
465
+
466
+            // Fill array 'array_options' with data from add form
467
+            $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
468
+            if ($ret < 0)
469
+            {
470
+                    $error++;
471
+            }
472
+
473
+            if (GETPOST('deletephoto')) $object->logo = '';
474
+            else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
475
+
476
+            // Check parameters
477
+            if (! GETPOST('cancel','alpha'))
478
+            {
479
+                if (! empty($object->email) && ! isValidEMail($object->email))
480
+                {
481
+                    $langs->load("errors");
482
+                    $error++;
483
+                    setEventMessages('', $langs->trans("ErrorBadEMail",$object->email), 'errors');
484
+                }
485
+                if (! empty($object->url) && ! isValidUrl($object->url))
486
+                {
487
+                    $langs->load("errors");
488
+                    setEventMessages('', $langs->trans("ErrorBadUrl",$object->url), 'errors');
489
+                }
490
+                if (! empty($object->webservices_url)) {
491
+                    //Check if has transport, without any the soap client will give error
492
+                    if (strpos($object->webservices_url, "http") === false)
493
+                    {
494
+                        $object->webservices_url = "http://".$object->webservices_url;
495
+                    }
496
+                    if (! isValidUrl($object->webservices_url)) {
497
+                        $langs->load("errors");
498
+                        $error++; $errors[] = $langs->trans("ErrorBadUrl",$object->webservices_url);
499
+                    }
500
+                }
501
+
502
+                // We set country_id, country_code and country for the selected country
503
+                $object->country_id=GETPOST('country_id')!=''?GETPOST('country_id'):$mysoc->country_id;
504
+                if ($object->country_id)
505
+                {
506
+                    $tmparray=getCountry($object->country_id,'all');
507
+                    $object->country_code=$tmparray['code'];
508
+                    $object->country=$tmparray['label'];
509
+                }
510
+            }
511 511
         }
512 512
 
513 513
         if (! $error)
514 514
         {
515 515
             if ($action == 'add')
516 516
             {
517
-            	$error = 0;
517
+                $error = 0;
518 518
 
519 519
                 $db->begin();
520 520
 
@@ -523,45 +523,45 @@  discard block
 block discarded – undo
523 523
 
524 524
                 $result = $object->create($user);
525 525
 
526
-				if ($result >= 0)
527
-				{
528
-					if ($object->particulier)
529
-					{
530
-						dol_syslog("We ask to create a contact/address too", LOG_DEBUG);
531
-						$result=$object->create_individual($user);
532
-						if ($result < 0)
533
-						{
534
-							setEventMessages($object->error, $object->errors, 'errors');
535
-							$error++;
536
-						}
537
-					}
526
+                if ($result >= 0)
527
+                {
528
+                    if ($object->particulier)
529
+                    {
530
+                        dol_syslog("We ask to create a contact/address too", LOG_DEBUG);
531
+                        $result=$object->create_individual($user);
532
+                        if ($result < 0)
533
+                        {
534
+                            setEventMessages($object->error, $object->errors, 'errors');
535
+                            $error++;
536
+                        }
537
+                    }
538 538
 
539
-					// Links with users
540
-					$salesreps = GETPOST('commercial', 'array');
541
-					$result = $object->setSalesRep($salesreps);
542
-					if ($result < 0)
543
-					{
544
-						$error++;
545
-						setEventMessages($object->error, $object->errors, 'errors');
546
-					}
539
+                    // Links with users
540
+                    $salesreps = GETPOST('commercial', 'array');
541
+                    $result = $object->setSalesRep($salesreps);
542
+                    if ($result < 0)
543
+                    {
544
+                        $error++;
545
+                        setEventMessages($object->error, $object->errors, 'errors');
546
+                    }
547 547
 
548
-					// Customer categories association
549
-					$custcats = GETPOST('custcats', 'array');
550
-					$result = $object->setCategories($custcats, 'customer');
551
-					if ($result < 0)
552
-					{
553
-						$error++;
554
-						setEventMessages($object->error, $object->errors, 'errors');
555
-					}
548
+                    // Customer categories association
549
+                    $custcats = GETPOST('custcats', 'array');
550
+                    $result = $object->setCategories($custcats, 'customer');
551
+                    if ($result < 0)
552
+                    {
553
+                        $error++;
554
+                        setEventMessages($object->error, $object->errors, 'errors');
555
+                    }
556 556
 
557
-					// Supplier categories association
558
-					$suppcats = GETPOST('suppcats', 'array');
559
-					$result = $object->setCategories($suppcats, 'supplier');
560
-					if ($result < 0)
561
-					{
562
-						$error++;
563
-						setEventMessages($object->error, $object->errors, 'errors');
564
-					}
557
+                    // Supplier categories association
558
+                    $suppcats = GETPOST('suppcats', 'array');
559
+                    $result = $object->setCategories($suppcats, 'supplier');
560
+                    if ($result < 0)
561
+                    {
562
+                        $error++;
563
+                        setEventMessages($object->error, $object->errors, 'errors');
564
+                    }
565 565
 
566 566
                     // Logo/Photo save
567 567
                     $dir     = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos/";
@@ -590,52 +590,52 @@  discard block
 block discarded – undo
590 590
                         }
591 591
                     }
592 592
                     else
593
-					{
594
-						switch($_FILES['photo']['error'])
595
-						{
596
-						    case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
597
-						    case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
598
-						      $errors[] = "ErrorFileSizeTooLarge";
599
-						      break;
600
-	      					case 3: //uploaded file was only partially uploaded
601
-						      $errors[] = "ErrorFilePartiallyUploaded";
602
-						      break;
603
-						}
604
-	                }
593
+                    {
594
+                        switch($_FILES['photo']['error'])
595
+                        {
596
+                            case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
597
+                            case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
598
+                              $errors[] = "ErrorFileSizeTooLarge";
599
+                                break;
600
+                                case 3: //uploaded file was only partially uploaded
601
+                              $errors[] = "ErrorFilePartiallyUploaded";
602
+                                break;
603
+                        }
604
+                    }
605 605
                     // Gestion du logo de la société
606 606
                 }
607 607
                 else
608
-				{
609
-				    if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') // TODO Sometime errors on duplicate on profid and not on code, so we must manage this case
610
-					{
611
-						$duplicate_code_error = true;
612
-						$object->code_fournisseur = null;
613
-						$object->code_client = null;
614
-					}
608
+                {
609
+                    if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') // TODO Sometime errors on duplicate on profid and not on code, so we must manage this case
610
+                    {
611
+                        $duplicate_code_error = true;
612
+                        $object->code_fournisseur = null;
613
+                        $object->code_client = null;
614
+                    }
615 615
 
616 616
                     setEventMessages($object->error, $object->errors, 'errors');
617
-                   	$error++;
617
+                        $error++;
618 618
                 }
619 619
 
620 620
                 if ($result >= 0 && ! $error)
621 621
                 {
622 622
                     $db->commit();
623 623
 
624
-                	if (! empty($backtopage))
625
-                	{
626
-                	    if (preg_match('/\?/', $backtopage)) $backtopage.='&socid='.$object->id;
627
-               		    header("Location: ".$backtopage);
628
-                    	exit;
629
-                	}
630
-                	else
631
-                	{
632
-                    	$url=$_SERVER["PHP_SELF"]."?socid=".$object->id;
633
-                    	if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $url=DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
634
-                    	else if ($object->fournisseur == 1) $url=DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
635
-
636
-                		header("Location: ".$url);
637
-                    	exit;
638
-                	}
624
+                    if (! empty($backtopage))
625
+                    {
626
+                        if (preg_match('/\?/', $backtopage)) $backtopage.='&socid='.$object->id;
627
+                            header("Location: ".$backtopage);
628
+                        exit;
629
+                    }
630
+                    else
631
+                    {
632
+                        $url=$_SERVER["PHP_SELF"]."?socid=".$object->id;
633
+                        if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $url=DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
634
+                        else if ($object->fournisseur == 1) $url=DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
635
+
636
+                        header("Location: ".$url);
637
+                        exit;
638
+                    }
639 639
                 }
640 640
                 else
641 641
                 {
@@ -646,20 +646,20 @@  discard block
 block discarded – undo
646 646
 
647 647
             if ($action == 'update')
648 648
             {
649
-            	$error = 0;
649
+                $error = 0;
650 650
 
651 651
                 if (GETPOST('cancel','alpha'))
652 652
                 {
653
-                	if (! empty($backtopage))
654
-                	{
655
-               		    header("Location: ".$backtopage);
656
-                    	exit;
657
-                	}
658
-                	else
659
-                	{
660
-               		    header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
661
-                    	exit;
662
-                	}
653
+                    if (! empty($backtopage))
654
+                    {
655
+                            header("Location: ".$backtopage);
656
+                        exit;
657
+                    }
658
+                    else
659
+                    {
660
+                            header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
661
+                        exit;
662
+                    }
663 663
                 }
664 664
 
665 665
                 // To not set code if third party is not concerned. But if it had values, we keep them.
@@ -674,36 +674,36 @@  discard block
 block discarded – undo
674 674
                     $error++;
675 675
                 }
676 676
 
677
-				// Links with users
678
-				$salesreps = GETPOST('commercial', 'array');
679
-				$result = $object->setSalesRep($salesreps);
680
-				if ($result < 0)
681
-				{
682
-					$error++;
683
-					setEventMessages($object->error, $object->errors, 'errors');
684
-				}
677
+                // Links with users
678
+                $salesreps = GETPOST('commercial', 'array');
679
+                $result = $object->setSalesRep($salesreps);
680
+                if ($result < 0)
681
+                {
682
+                    $error++;
683
+                    setEventMessages($object->error, $object->errors, 'errors');
684
+                }
685 685
 
686
-				// Prevent thirdparty's emptying if a user hasn't rights $user->rights->categorie->lire (in such a case, post of 'custcats' is not defined)
687
-				if (! $error && !empty($user->rights->categorie->lire))
688
-				{
689
-					// Customer categories association
690
-					$categories = GETPOST( 'custcats', 'array' );
691
-					$result = $object->setCategories($categories, 'customer');
692
-					if ($result < 0)
693
-					{
694
-						$error++;
695
-						setEventMessages($object->error, $object->errors, 'errors');
696
-					}
686
+                // Prevent thirdparty's emptying if a user hasn't rights $user->rights->categorie->lire (in such a case, post of 'custcats' is not defined)
687
+                if (! $error && !empty($user->rights->categorie->lire))
688
+                {
689
+                    // Customer categories association
690
+                    $categories = GETPOST( 'custcats', 'array' );
691
+                    $result = $object->setCategories($categories, 'customer');
692
+                    if ($result < 0)
693
+                    {
694
+                        $error++;
695
+                        setEventMessages($object->error, $object->errors, 'errors');
696
+                    }
697 697
 
698
-					// Supplier categories association
699
-					$categories = GETPOST('suppcats', 'array');
700
-					$result = $object->setCategories($categories, 'supplier');
701
-					if ($result < 0)
702
-					{
703
-						$error++;
704
-						setEventMessages($object->error, $object->errors, 'errors');
705
-					}
706
-				}
698
+                    // Supplier categories association
699
+                    $categories = GETPOST('suppcats', 'array');
700
+                    $result = $object->setCategories($categories, 'supplier');
701
+                    if ($result < 0)
702
+                    {
703
+                        $error++;
704
+                        setEventMessages($object->error, $object->errors, 'errors');
705
+                    }
706
+                }
707 707
 
708 708
                 // Logo/Photo save
709 709
                 $dir     = $conf->societe->multidir_output[$object->entity]."/".$object->id."/logos";
@@ -732,38 +732,38 @@  discard block
 block discarded – undo
732 732
                             }
733 733
                             else
734 734
                             {
735
-                            	// Create thumbs
736
-                            	$object->addThumbs($newfile);
735
+                                // Create thumbs
736
+                                $object->addThumbs($newfile);
737 737
 
738 738
                                 // Index file in database
739 739
                                 if (! empty($conf->global->THIRDPARTY_LOGO_ALLOW_EXTERNAL_DOWNLOAD))
740 740
                                 {
741
-                                	require_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php';
742
-                                	// the dir dirname($newfile) is directory of logo, so we should have only one file at once into index, so we delete indexes for the dir
743
-                                	deleteFilesIntoDatabaseIndex(dirname($newfile), '', '', 'uploaded', 1);
744
-                                	// now we index the uploaded logo file
745
-                                	addFileIntoDatabaseIndex(dirname($newfile), basename($newfile), '', 'uploaded', 1);
741
+                                    require_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php';
742
+                                    // the dir dirname($newfile) is directory of logo, so we should have only one file at once into index, so we delete indexes for the dir
743
+                                    deleteFilesIntoDatabaseIndex(dirname($newfile), '', '', 'uploaded', 1);
744
+                                    // now we index the uploaded logo file
745
+                                    addFileIntoDatabaseIndex(dirname($newfile), basename($newfile), '', 'uploaded', 1);
746 746
                                 }
747 747
                             }
748 748
                         }
749 749
                     }
750 750
                     else
751
-					{
751
+                    {
752 752
                         $errors[] = "ErrorBadImageFormat";
753 753
                     }
754 754
                 }
755 755
                 else
756 756
                 {
757
-					switch($_FILES['photo']['error'])
758
-					{
759
-					    case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
760
-					    case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
761
-					      $errors[] = "ErrorFileSizeTooLarge";
762
-					      break;
763
-      					case 3: //uploaded file was only partially uploaded
764
-					      $errors[] = "ErrorFilePartiallyUploaded";
765
-					      break;
766
-					}
757
+                    switch($_FILES['photo']['error'])
758
+                    {
759
+                        case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
760
+                        case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
761
+                          $errors[] = "ErrorFileSizeTooLarge";
762
+                            break;
763
+                            case 3: //uploaded file was only partially uploaded
764
+                          $errors[] = "ErrorFilePartiallyUploaded";
765
+                            break;
766
+                    }
767 767
                 }
768 768
                 // Gestion du logo de la société
769 769
 
@@ -772,28 +772,28 @@  discard block
 block discarded – undo
772 772
                 if (! $error && $object->fk_soc > 0)
773 773
                 {
774 774
 
775
-                	$sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
776
-                	$sql.= " SET fk_soc = NULL WHERE fk_soc = " . $id;
777
-                	if (! $object->db->query($sql))
778
-                	{
779
-                		$error++;
780
-                		$object->error .= $object->db->lasterror();
781
-                		setEventMessages($object->error, $object->errors, 'errors');
782
-                	}
775
+                    $sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
776
+                    $sql.= " SET fk_soc = NULL WHERE fk_soc = " . $id;
777
+                    if (! $object->db->query($sql))
778
+                    {
779
+                        $error++;
780
+                        $object->error .= $object->db->lasterror();
781
+                        setEventMessages($object->error, $object->errors, 'errors');
782
+                    }
783 783
                 }
784 784
 
785 785
                 if (! $error && ! count($errors))
786 786
                 {
787
-                	if (! empty($backtopage))
788
-                	{
789
-               		    header("Location: ".$backtopage);
790
-                    	exit;
791
-                	}
792
-                	else
793
-                	{
794
-               		    header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
795
-                    	exit;
796
-                	}
787
+                    if (! empty($backtopage))
788
+                    {
789
+                            header("Location: ".$backtopage);
790
+                        exit;
791
+                    }
792
+                    else
793
+                    {
794
+                            header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
795
+                        exit;
796
+                    }
797 797
                 }
798 798
                 else
799 799
                 {
@@ -804,7 +804,7 @@  discard block
 block discarded – undo
804 804
         }
805 805
         else
806 806
         {
807
-        	$action = ($action=='add'?'create':'edit');
807
+            $action = ($action=='add'?'create':'edit');
808 808
         }
809 809
     }
810 810
 
@@ -822,8 +822,8 @@  discard block
 block discarded – undo
822 822
         else
823 823
         {
824 824
             $langs->load("errors");
825
-           	setEventMessages($object->error, $object->errors, 'errors');
826
-           	$error++;
825
+                setEventMessages($object->error, $object->errors, 'errors');
826
+                $error++;
827 827
             $action='';
828 828
         }
829 829
     }
@@ -831,15 +831,15 @@  discard block
 block discarded – undo
831 831
     // Set parent company
832 832
     if ($action == 'set_thirdparty' && $user->rights->societe->creer)
833 833
     {
834
-    	$object->fetch($socid);
835
-    	$result = $object->set_parent(GETPOST('editparentcompany','int'));
834
+        $object->fetch($socid);
835
+        $result = $object->set_parent(GETPOST('editparentcompany','int'));
836 836
     }
837 837
 
838 838
     // Set incoterm
839 839
     if ($action == 'set_incoterms' && !empty($conf->incoterm->enabled))
840 840
     {
841
-    	$object->fetch($socid);
842
-    	$result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
841
+        $object->fetch($socid);
842
+        $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
843 843
     }
844 844
 
845 845
     $id=$socid;
@@ -872,7 +872,7 @@  discard block
 block discarded – undo
872 872
 if ($socid > 0 && empty($object->id))
873 873
 {
874 874
     $result=$object->fetch($socid);
875
-	if ($result <= 0) dol_print_error('',$object->error);
875
+    if ($result <= 0) dol_print_error('',$object->error);
876 876
 }
877 877
 
878 878
 $title=$langs->trans("ThirdParty");
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
     // -----------------------------------------
888 888
     // When used with CANVAS
889 889
     // -----------------------------------------
890
-   	$objcanvas->assign_values($action, $object->id, $object->ref);	// Set value for templates
890
+        $objcanvas->assign_values($action, $object->id, $object->ref);	// Set value for templates
891 891
     $objcanvas->display_canvas($action);							// Show template
892 892
 }
893 893
 else
@@ -900,9 +900,9 @@  discard block
 block discarded – undo
900 900
         /*
901 901
          *  Creation
902 902
          */
903
-		$private=GETPOST("private","int");
904
-		if (! empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT) && ! isset($_GET['private']) && ! isset($_POST['private'])) $private=1;
905
-    	if (empty($private)) $private=0;
903
+        $private=GETPOST("private","int");
904
+        if (! empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT) && ! isset($_GET['private']) && ! isset($_POST['private'])) $private=1;
905
+        if (empty($private)) $private=0;
906 906
 
907 907
         // Load object modCodeTiers
908 908
         $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
@@ -948,12 +948,12 @@  discard block
 block discarded – undo
948 948
         $object->client				= GETPOST('client')?GETPOST('client'):$object->client;
949 949
 
950 950
         if(empty($duplicate_code_error)) {
951
-	        $object->code_client		= GETPOST('customer_code', 'alpha');
952
-	        $object->fournisseur		= GETPOST('fournisseur')?GETPOST('fournisseur'):$object->fournisseur;
951
+            $object->code_client		= GETPOST('customer_code', 'alpha');
952
+            $object->fournisseur		= GETPOST('fournisseur')?GETPOST('fournisseur'):$object->fournisseur;
953
+        }
954
+        else {
955
+            setEventMessages($langs->trans('NewCustomerSupplierCodeProposed'),'', 'warnings');
953 956
         }
954
-		else {
955
-			setEventMessages($langs->trans('NewCustomerSupplierCodeProposed'),'', 'warnings');
956
-		}
957 957
 
958 958
         $object->code_fournisseur	= GETPOST('supplier_code', 'alpha');
959 959
         $object->address			= GETPOST('address', 'alpha');
@@ -1107,18 +1107,18 @@  discard block
 block discarded – undo
1107 1107
             print '<div class="hideonsmartphone float">';
1108 1108
             print $langs->trans("ThirdPartyType").': &nbsp; &nbsp; ';
1109 1109
             print '</div>';
1110
-	        print '<label for="radiocompany" class="radiocompany">';
1110
+            print '<label for="radiocompany" class="radiocompany">';
1111 1111
             print '<input type="radio" id="radiocompany" class="flat" name="private"  value="0"'.($private?'':' checked').'>';
1112
-	        print '&nbsp;';
1112
+            print '&nbsp;';
1113 1113
             print $langs->trans("CreateThirdPartyOnly");
1114
-	        print '</label>';
1114
+            print '</label>';
1115 1115
             print ' &nbsp; &nbsp; ';
1116
-	        print '<label for="radioprivate" class="radioprivate">';
1116
+            print '<label for="radioprivate" class="radioprivate">';
1117 1117
             $text ='<input type="radio" id="radioprivate" class="flat" name="private" value="1"'.($private?' checked':'').'>';
1118
-	        $text.='&nbsp;';
1119
-	        $text.= $langs->trans("CreateThirdPartyAndContact");
1120
-	        $htmltext=$langs->trans("ToCreateContactWithSameName");
1121
-	        print $form->textwithpicto($text, $htmltext, 1, 'help', '', 0, 3);
1118
+            $text.='&nbsp;';
1119
+            $text.= $langs->trans("CreateThirdPartyAndContact");
1120
+            $htmltext=$langs->trans("ToCreateContactWithSameName");
1121
+            print $form->textwithpicto($text, $htmltext, 1, 'help', '', 0, 3);
1122 1122
             print '</label>';
1123 1123
             print '</div>';
1124 1124
             print "<br>\n";
@@ -1142,28 +1142,28 @@  discard block
 block discarded – undo
1142 1142
         print '<table class="border" width="100%">';
1143 1143
 
1144 1144
         // Name, firstname
1145
-	    print '<tr><td class="titlefieldcreate">';
1145
+        print '<tr><td class="titlefieldcreate">';
1146 1146
         if ($object->particulier || $private)
1147 1147
         {
1148
-	        print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName','name').'</span>';
1148
+            print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName','name').'</span>';
1149 1149
         }
1150 1150
         else
1151
-		{
1152
-			print '<span id="TypeName" class="fieldrequired">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0).'</span>';
1151
+        {
1152
+            print '<span id="TypeName" class="fieldrequired">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0).'</span>';
1153 1153
         }
1154
-	    print '</td><td'.(empty($conf->global->SOCIETE_USEPREFIX)?' colspan="3"':'').'>';
1155
-	    print '<input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.$object->name.'" autofocus="autofocus"></td>';
1156
-	    if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1157
-	    {
1158
-		    print '<td>'.$langs->trans('Prefix').'</td><td><input type="text" size="5" maxlength="5" name="prefix_comm" value="'.$object->prefix_comm.'"></td>';
1159
-	    }
1160
-	    print '</tr>';
1154
+        print '</td><td'.(empty($conf->global->SOCIETE_USEPREFIX)?' colspan="3"':'').'>';
1155
+        print '<input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.$object->name.'" autofocus="autofocus"></td>';
1156
+        if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1157
+        {
1158
+            print '<td>'.$langs->trans('Prefix').'</td><td><input type="text" size="5" maxlength="5" name="prefix_comm" value="'.$object->prefix_comm.'"></td>';
1159
+        }
1160
+        print '</tr>';
1161 1161
 
1162 1162
         // If javascript on, we show option individual
1163 1163
         if ($conf->use_javascript_ajax)
1164 1164
         {
1165 1165
             print '<tr class="individualline"><td>'.$form->editfieldkey('FirstName', 'firstname', '', $object, 0).'</td>';
1166
-	        print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="firstname" id="firstname" value="'.$object->firstname.'"></td>';
1166
+            print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="firstname" id="firstname" value="'.$object->firstname.'"></td>';
1167 1167
             print '</tr>';
1168 1168
             // Title
1169 1169
             print '<tr class="individualline"><td>'.$form->editfieldkey('UserTitle', 'civility_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
@@ -1173,12 +1173,12 @@  discard block
 block discarded – undo
1173 1173
 
1174 1174
         // Alias names (commercial, trademark or alias names)
1175 1175
         print '<tr id="name_alias"><td><label for="name_alias_input">'.$langs->trans('AliasNames').'</label></td>';
1176
-	    print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.$object->name_alias.'"></td></tr>';
1176
+        print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.$object->name_alias.'"></td></tr>';
1177 1177
 
1178 1178
         // Prospect/Customer
1179 1179
         print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).'</td>';
1180
-	    print '<td class="maxwidthonsmartphone">';
1181
-	    $selected=GETPOST('client','int')!=''?GETPOST('client','int'):$object->client;
1180
+        print '<td class="maxwidthonsmartphone">';
1181
+        $selected=GETPOST('client','int')!=''?GETPOST('client','int'):$object->client;
1182 1182
         print '<select class="flat" name="client" id="customerprospect">';
1183 1183
         if (GETPOST("type") == '') print '<option value="-1">&nbsp;</option>';
1184 1184
         if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($selected==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
@@ -1189,7 +1189,7 @@  discard block
 block discarded – undo
1189 1189
 
1190 1190
         print '<td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
1191 1191
         print '<table class="nobordernopadding"><tr><td>';
1192
-		$tmpcode=$object->code_client;
1192
+        $tmpcode=$object->code_client;
1193 1193
         if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object,0);
1194 1194
         print '<input type="text" name="customer_code" id="customer_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1195 1195
         print '</td><td>';
@@ -1199,7 +1199,7 @@  discard block
 block discarded – undo
1199 1199
         print '</td></tr>';
1200 1200
 
1201 1201
         if ((! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1202
-        	|| (! empty($conf->supplier_proposal->enabled) && ! empty($user->rights->supplier_proposal->lire)))
1202
+            || (! empty($conf->supplier_proposal->enabled) && ! empty($user->rights->supplier_proposal->lire)))
1203 1203
         {
1204 1204
             // Supplier
1205 1205
             print '<tr>';
@@ -1211,19 +1211,19 @@  discard block
 block discarded – undo
1211 1211
             print '<td>';
1212 1212
             if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1213 1213
             {
1214
-            	print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0);
1214
+                print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0);
1215 1215
             }
1216 1216
             print '</td><td>';
1217 1217
             if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1218 1218
             {
1219
-	            print '<table class="nobordernopadding"><tr><td>';
1220
-	            $tmpcode=$object->code_fournisseur;
1221
-	            if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1222
-	            print '<input type="text" name="supplier_code" id="supplier_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1223
-	            print '</td><td>';
1224
-	            $s=$modCodeFournisseur->getToolTip($langs,$object,1);
1225
-	            print $form->textwithpicto('',$s,1);
1226
-	            print '</td></tr></table>';
1219
+                print '<table class="nobordernopadding"><tr><td>';
1220
+                $tmpcode=$object->code_fournisseur;
1221
+                if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1222
+                print '<input type="text" name="supplier_code" id="supplier_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1223
+                print '</td><td>';
1224
+                $s=$modCodeFournisseur->getToolTip($langs,$object,1);
1225
+                print $form->textwithpicto('',$s,1);
1226
+                print '</td></tr></table>';
1227 1227
             }
1228 1228
             print '</td></tr>';
1229 1229
         }
@@ -1237,13 +1237,13 @@  discard block
 block discarded – undo
1237 1237
         if (! empty($conf->barcode->enabled))
1238 1238
         {
1239 1239
             print '<tr><td>'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).'</td>';
1240
-	        print '<td colspan="3"><input type="text" name="barcode" id="barcode" value="'.$object->barcode.'">';
1240
+            print '<td colspan="3"><input type="text" name="barcode" id="barcode" value="'.$object->barcode.'">';
1241 1241
             print '</td></tr>';
1242 1242
         }
1243 1243
 
1244 1244
         // Address
1245 1245
         print '<tr><td class="tdtop">'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
1246
-	    print '<td colspan="3"><textarea name="address" id="address" class="quatrevingtpercent" rows="'.ROWS_2.'" wrap="soft">';
1246
+        print '<td colspan="3"><textarea name="address" id="address" class="quatrevingtpercent" rows="'.ROWS_2.'" wrap="soft">';
1247 1247
         print $object->address;
1248 1248
         print '</textarea></td></tr>';
1249 1249
 
@@ -1279,43 +1279,43 @@  discard block
 block discarded – undo
1279 1279
 
1280 1280
         // Email / Web
1281 1281
         print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', $conf->global->SOCIETE_EMAIL_MANDATORY).'</td>';
1282
-	    print '<td colspan="3"><input type="text" name="email" id="email" value="'.$object->email.'"></td></tr>';
1282
+        print '<td colspan="3"><input type="text" name="email" id="email" value="'.$object->email.'"></td></tr>';
1283 1283
         print '<tr><td>'.$form->editfieldkey('Web', 'url', '', $object, 0).'</td>';
1284
-	    print '<td colspan="3"><input type="text" name="url" id="url" value="'.$object->url.'"></td></tr>';
1284
+        print '<td colspan="3"><input type="text" name="url" id="url" value="'.$object->url.'"></td></tr>';
1285 1285
 
1286 1286
         if (! empty($conf->socialnetworks->enabled))
1287 1287
         {
1288
-        	// Skype
1289
-        	if (! empty($conf->global->SOCIALNETWORKS_SKYPE))
1290
-        	{
1291
-        		print '<tr><td>'.$form->editfieldkey('Skype', 'skype', '', $object, 0).'</td>';
1292
-				print '<td colspan="3">';
1293
-				print '<input type="text" name="skype" class="minwidth100" maxlength="80" id="skype" value="'.dol_escape_htmltag(GETPOSTISSET("skype")?GETPOST("skype",'alpha'):$object->skype).'">';
1294
-				print '</td></tr>';
1295
-        	}
1296
-        	// Twitter
1297
-        	if (! empty($conf->global->SOCIALNETWORKS_TWITTER))
1298
-        	{
1299
-        		print '<tr><td>'.$form->editfieldkey('Twitter', 'twitter', '', $object, 0).'</td>';
1300
-				print '<td colspan="3">';
1301
-				print '<input type="text" name="twitter" class="minwidth100" maxlength="80" id="twitter" value="'.dol_escape_htmltag(GETPOSTISSET("twitter")?GETPOST("twitter",'alpha'):$object->twitter).'">';
1302
-				print '</td></tr>';
1303
-        	}
1304
-        	// Facebook
1305
-        	if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK))
1306
-        	{
1307
-	        	print '<tr><td>'.$form->editfieldkey('Facebook', 'facebook', '', $object, 0).'</td>';
1308
-				print '<td colspan="3">';
1309
-				print '<input type="text" name="facebook" class="minwidth100" maxlength="80" id="facebook" value="'.dol_escape_htmltag(GETPOSTISSET("facebook")?GETPOST("facebook",'alpha'):$object->facebook).'">';
1310
-				print '</td></tr>';
1311
-        	}
1288
+            // Skype
1289
+            if (! empty($conf->global->SOCIALNETWORKS_SKYPE))
1290
+            {
1291
+                print '<tr><td>'.$form->editfieldkey('Skype', 'skype', '', $object, 0).'</td>';
1292
+                print '<td colspan="3">';
1293
+                print '<input type="text" name="skype" class="minwidth100" maxlength="80" id="skype" value="'.dol_escape_htmltag(GETPOSTISSET("skype")?GETPOST("skype",'alpha'):$object->skype).'">';
1294
+                print '</td></tr>';
1295
+            }
1296
+            // Twitter
1297
+            if (! empty($conf->global->SOCIALNETWORKS_TWITTER))
1298
+            {
1299
+                print '<tr><td>'.$form->editfieldkey('Twitter', 'twitter', '', $object, 0).'</td>';
1300
+                print '<td colspan="3">';
1301
+                print '<input type="text" name="twitter" class="minwidth100" maxlength="80" id="twitter" value="'.dol_escape_htmltag(GETPOSTISSET("twitter")?GETPOST("twitter",'alpha'):$object->twitter).'">';
1302
+                print '</td></tr>';
1303
+            }
1304
+            // Facebook
1305
+            if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK))
1306
+            {
1307
+                print '<tr><td>'.$form->editfieldkey('Facebook', 'facebook', '', $object, 0).'</td>';
1308
+                print '<td colspan="3">';
1309
+                print '<input type="text" name="facebook" class="minwidth100" maxlength="80" id="facebook" value="'.dol_escape_htmltag(GETPOSTISSET("facebook")?GETPOST("facebook",'alpha'):$object->facebook).'">';
1310
+                print '</td></tr>';
1311
+            }
1312 1312
         }
1313 1313
 
1314 1314
         // Phone / Fax
1315 1315
         print '<tr><td>'.$form->editfieldkey('Phone', 'phone', '', $object, 0).'</td>';
1316
-	    print '<td><input type="text" name="phone" id="phone" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->phone.'"></td>';
1316
+        print '<td><input type="text" name="phone" id="phone" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->phone.'"></td>';
1317 1317
         print '<td>'.$form->editfieldkey('Fax', 'fax', '', $object, 0).'</td>';
1318
-	    print '<td><input type="text" name="fax" id="fax" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->fax.'"></td></tr>';
1318
+        print '<td><input type="text" name="fax" id="fax" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->fax.'"></td></tr>';
1319 1319
 
1320 1320
         // Prof ids
1321 1321
         $i=1; $j=0;
@@ -1324,7 +1324,7 @@  discard block
 block discarded – undo
1324 1324
             $idprof=$langs->transcountry('ProfId'.$i,$object->country_code);
1325 1325
             if ($idprof!='-')
1326 1326
             {
1327
-	            $key='idprof'.$i;
1327
+                $key='idprof'.$i;
1328 1328
 
1329 1329
                 if (($j % 2) == 0) print '<tr>';
1330 1330
 
@@ -1423,7 +1423,7 @@  discard block
 block discarded – undo
1423 1423
 
1424 1424
         // Capital
1425 1425
         print '<tr><td>'.$form->editfieldkey('Capital', 'capital', '', $object, 0).'</td>';
1426
-	    print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="'.$object->capital.'"> ';
1426
+        print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="'.$object->capital.'"> ';
1427 1427
         print '<span class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
1428 1428
 
1429 1429
         if (! empty($conf->global->MAIN_MULTILANGS))
@@ -1434,47 +1434,47 @@  discard block
 block discarded – undo
1434 1434
             print '</tr>';
1435 1435
         }
1436 1436
 
1437
-		// Incoterms
1438
-		if (!empty($conf->incoterm->enabled))
1439
-		{
1440
-			print '<tr>';
1441
-			print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
1442
-	        print '<td colspan="3" class="maxwidthonsmartphone">';
1443
-	        print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
1444
-			print '</td></tr>';
1445
-		}
1446
-
1447
-		// Categories
1448
-		if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
1449
-		{
1450
-			$langs->load('categories');
1451
-
1452
-			// Customer
1453
-			//if ($object->prospect || $object->client || (! $object->fournisseur && ! empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER))) {
1454
-			print '<tr class="visibleifcustomer"><td class="toptd">' . $form->editfieldkey('CustomersProspectsCategoriesShort', 'custcats', '', $object, 0) . '</td><td colspan="3">';
1455
-			$cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, 'parent', null, null, 1);
1456
-			print $form->multiselectarray('custcats', $cate_arbo, GETPOST('custcats', 'array'), null, null, null, null, "90%");
1457
-			print "</td></tr>";
1458
-			//}
1459
-
1460
-			// Supplier
1461
-			//if ($object->fournisseur) {
1462
-			print '<tr class="visibleifsupplier"><td class="toptd">' . $form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0) . '</td><td colspan="3">';
1463
-			$cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, 'parent', null, null, 1);
1464
-			print $form->multiselectarray('suppcats', $cate_arbo, GETPOST('suppcats', 'array'), null, null, null, null, "90%");
1465
-			print "</td></tr>";
1466
-			//}
1467
-		}
1468
-
1469
-		// Multicurrency
1470
-		if (! empty($conf->multicurrency->enabled))
1471
-		{
1472
-			print '<tr>';
1473
-			print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
1474
-	        print '<td colspan="3" class="maxwidthonsmartphone">';
1475
-	        print $form->selectMultiCurrency(($object->multicurrency_code ? $object->multicurrency_code : $conf->currency), 'multicurrency_code', 1);
1476
-			print '</td></tr>';
1477
-		}
1437
+        // Incoterms
1438
+        if (!empty($conf->incoterm->enabled))
1439
+        {
1440
+            print '<tr>';
1441
+            print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
1442
+            print '<td colspan="3" class="maxwidthonsmartphone">';
1443
+            print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
1444
+            print '</td></tr>';
1445
+        }
1446
+
1447
+        // Categories
1448
+        if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
1449
+        {
1450
+            $langs->load('categories');
1451
+
1452
+            // Customer
1453
+            //if ($object->prospect || $object->client || (! $object->fournisseur && ! empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER))) {
1454
+            print '<tr class="visibleifcustomer"><td class="toptd">' . $form->editfieldkey('CustomersProspectsCategoriesShort', 'custcats', '', $object, 0) . '</td><td colspan="3">';
1455
+            $cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, 'parent', null, null, 1);
1456
+            print $form->multiselectarray('custcats', $cate_arbo, GETPOST('custcats', 'array'), null, null, null, null, "90%");
1457
+            print "</td></tr>";
1458
+            //}
1459
+
1460
+            // Supplier
1461
+            //if ($object->fournisseur) {
1462
+            print '<tr class="visibleifsupplier"><td class="toptd">' . $form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0) . '</td><td colspan="3">';
1463
+            $cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, 'parent', null, null, 1);
1464
+            print $form->multiselectarray('suppcats', $cate_arbo, GETPOST('suppcats', 'array'), null, null, null, null, "90%");
1465
+            print "</td></tr>";
1466
+            //}
1467
+        }
1468
+
1469
+        // Multicurrency
1470
+        if (! empty($conf->multicurrency->enabled))
1471
+        {
1472
+            print '<tr>';
1473
+            print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
1474
+            print '<td colspan="3" class="maxwidthonsmartphone">';
1475
+            print $form->selectMultiCurrency(($object->multicurrency_code ? $object->multicurrency_code : $conf->currency), 'multicurrency_code', 1);
1476
+            print '</td></tr>';
1477
+        }
1478 1478
 
1479 1479
         // Other attributes
1480 1480
         $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
@@ -1482,17 +1482,17 @@  discard block
 block discarded – undo
1482 1482
         print $hookmanager->resPrint;
1483 1483
         if (empty($reshook))
1484 1484
         {
1485
-        	print $object->showOptionals($extrafields,'edit');
1485
+            print $object->showOptionals($extrafields,'edit');
1486 1486
         }
1487 1487
 
1488
-		// Assign a sale representative
1489
-		print '<tr>';
1490
-		print '<td>'.$form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0).'</td>';
1491
-		print '<td colspan="3" class="maxwidthonsmartphone">';
1492
-		$userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, '', 0, '', '', 0, 1);
1493
-		// Note: If user has no right to "see all thirdparties", we for selection of sale representative to him, so after creation he can see the record.
1494
-		print $form->multiselectarray('commercial', $userlist, (count(GETPOST('commercial', 'array')) > 0?GETPOST('commercial', 'array'):(empty($user->rights->societe->client->voir)?array($user->id):array())), null, null, null, null, "90%");
1495
-		print '</td></tr>';
1488
+        // Assign a sale representative
1489
+        print '<tr>';
1490
+        print '<td>'.$form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0).'</td>';
1491
+        print '<td colspan="3" class="maxwidthonsmartphone">';
1492
+        $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, '', 0, '', '', 0, 1);
1493
+        // Note: If user has no right to "see all thirdparties", we for selection of sale representative to him, so after creation he can see the record.
1494
+        print $form->multiselectarray('commercial', $userlist, (count(GETPOST('commercial', 'array')) > 0?GETPOST('commercial', 'array'):(empty($user->rights->societe->client->voir)?array($user->id):array())), null, null, null, null, "90%");
1495
+        print '</td></tr>';
1496 1496
 
1497 1497
         // Ajout du logo
1498 1498
         print '<tr class="hideonsmartphone">';
@@ -1528,10 +1528,10 @@  discard block
 block discarded – undo
1528 1528
 
1529 1529
         if ($socid)
1530 1530
         {
1531
-        	$res=$object->fetch_optionals();
1531
+            $res=$object->fetch_optionals();
1532 1532
             //if ($res < 0) { dol_print_error($db); exit; }
1533 1533
 
1534
-	        $head = societe_prepare_head($object);
1534
+            $head = societe_prepare_head($object);
1535 1535
 
1536 1536
             // Load object modCodeTiers
1537 1537
             $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
@@ -1569,7 +1569,7 @@  discard block
 block discarded – undo
1569 1569
                 $prefixSupplierIsUsed = $modCodeFournisseur->verif_prefixIsUsed();
1570 1570
             }
1571 1571
 
1572
-			$object->oldcopy = clone $object;
1572
+            $object->oldcopy = clone $object;
1573 1573
 
1574 1574
             if (GETPOSTISSET('name'))
1575 1575
             {
@@ -1613,12 +1613,12 @@  discard block
 block discarded – undo
1613 1613
                 $object->webservices_url        = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
1614 1614
                 $object->webservices_key        = GETPOST('webservices_key', 'san_alpha');
1615 1615
 
1616
-				//Incoterms
1617
-				if (!empty($conf->incoterm->enabled))
1618
-				{
1619
-					$object->fk_incoterms			= GETPOST('incoterm_id', 'int');
1620
-					$object->location_incoterms		= GETPOST('lcoation_incoterms', 'alpha');
1621
-				}
1616
+                //Incoterms
1617
+                if (!empty($conf->incoterm->enabled))
1618
+                {
1619
+                    $object->fk_incoterms			= GETPOST('incoterm_id', 'int');
1620
+                    $object->location_incoterms		= GETPOST('lcoation_incoterms', 'alpha');
1621
+                }
1622 1622
 
1623 1623
                 //Local Taxes
1624 1624
                 $object->localtax1_assuj		= GETPOST('localtax1assuj_value');
@@ -1630,23 +1630,23 @@  discard block
 block discarded – undo
1630 1630
                 // We set country_id, and country_code label of the chosen country
1631 1631
                 if ($object->country_id > 0)
1632 1632
                 {
1633
-                	$tmparray=getCountry($object->country_id,'all');
1633
+                    $tmparray=getCountry($object->country_id,'all');
1634 1634
                     $object->country_code	= $tmparray['code'];
1635 1635
                     $object->country		= $tmparray['label'];
1636 1636
                 }
1637 1637
             }
1638 1638
 
1639 1639
             if($object->localtax1_assuj==0){
1640
-            	$sub=0;
1640
+                $sub=0;
1641 1641
             }else{$sub=1;}
1642 1642
             if($object->localtax2_assuj==0){
1643
-            	$sub2=0;
1643
+                $sub2=0;
1644 1644
             }else{$sub2=1;}
1645 1645
 
1646 1646
             if ($conf->use_javascript_ajax)
1647 1647
             {
1648
-            	print "\n".'<script type="text/javascript">';
1649
-            	print '$(document).ready(function () {
1648
+                print "\n".'<script type="text/javascript">';
1649
+                print '$(document).ready(function () {
1650 1650
     			var val='.$sub.';
1651 1651
     			var val2='.$sub2.';
1652 1652
     			if("#localtax1assuj_value".value==undefined){
@@ -1735,20 +1735,20 @@  discard block
 block discarded – undo
1735 1735
             print '<table class="border" width="100%">';
1736 1736
 
1737 1737
             // Ref/ID
1738
-			if (! empty($conf->global->MAIN_SHOW_TECHNICAL_ID))
1739
-			{
1740
-		        print '<tr><td class="titlefieldcreate">'.$langs->trans("ID").'</td><td colspan="3">';
1741
-            	print $object->ref;
1742
-            	print '</td></tr>';
1743
-			}
1738
+            if (! empty($conf->global->MAIN_SHOW_TECHNICAL_ID))
1739
+            {
1740
+                print '<tr><td class="titlefieldcreate">'.$langs->trans("ID").'</td><td colspan="3">';
1741
+                print $object->ref;
1742
+                print '</td></tr>';
1743
+            }
1744 1744
 
1745 1745
             // Name
1746 1746
             print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0, 'string', '', 1).'</td>';
1747
-	        print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.dol_escape_htmltag($object->name).'" autofocus="autofocus"></td></tr>';
1747
+            print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.dol_escape_htmltag($object->name).'" autofocus="autofocus"></td></tr>';
1748 1748
 
1749
-	        // Alias names (commercial, trademark or alias names)
1750
-	        print '<tr id="name_alias"><td><label for="name_alias_input">'.$langs->trans('AliasNames').'</label></td>';
1751
-	        print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.dol_escape_htmltag($object->name_alias).'"></td></tr>';
1749
+            // Alias names (commercial, trademark or alias names)
1750
+            print '<tr id="name_alias"><td><label for="name_alias_input">'.$langs->trans('AliasNames').'</label></td>';
1751
+            print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.dol_escape_htmltag($object->name_alias).'"></td></tr>';
1752 1752
 
1753 1753
             // Prefix
1754 1754
             if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
@@ -1769,7 +1769,7 @@  discard block
 block discarded – undo
1769 1769
 
1770 1770
             // Prospect/Customer
1771 1771
             print '<tr><td>'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).'</td>';
1772
-	        print '<td class="maxwidthonsmartphone"><select class="flat" name="client" id="customerprospect">';
1772
+            print '<td class="maxwidthonsmartphone"><select class="flat" name="client" id="customerprospect">';
1773 1773
             if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($object->client==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1774 1774
             if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="3"'.($object->client==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1775 1775
             if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($object->client==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
@@ -1787,7 +1787,7 @@  discard block
 block discarded – undo
1787 1787
             }
1788 1788
             else if ($object->codeclient_modifiable())
1789 1789
             {
1790
-            	print '<input type="text" name="customer_code" id="customer_code" size="16" value="'.dol_escape_htmltag($object->code_client).'" maxlength="15">';
1790
+                print '<input type="text" name="customer_code" id="customer_code" size="16" value="'.dol_escape_htmltag($object->code_client).'" maxlength="15">';
1791 1791
             }
1792 1792
             else
1793 1793
             {
@@ -1803,7 +1803,7 @@  discard block
 block discarded – undo
1803 1803
 
1804 1804
             // Supplier
1805 1805
             if ((! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1806
-            	|| (! empty($conf->supplier_proposal->enabled) && ! empty($user->rights->supplier_proposal->lire)))
1806
+                || (! empty($conf->supplier_proposal->enabled) && ! empty($user->rights->supplier_proposal->lire)))
1807 1807
             {
1808 1808
                 print '<tr>';
1809 1809
                 print '<td>'.$form->editfieldkey('Supplier', 'fournisseur', '', $object, 0, 'string', '', 1).'</td><td class="maxwidthonsmartphone">';
@@ -1812,32 +1812,32 @@  discard block
 block discarded – undo
1812 1812
                 print '<td>';
1813 1813
                 if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1814 1814
                 {
1815
-                	print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0);
1815
+                    print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0);
1816 1816
                 }
1817 1817
                 print '</td><td>';
1818 1818
                 if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1819 1819
                 {
1820
-	                print '<table class="nobordernopadding"><tr><td>';
1821
-	                if ((!$object->code_fournisseur || $object->code_fournisseur == -1) && $modCodeFournisseur->code_auto)
1822
-	                {
1823
-	                    $tmpcode=$object->code_fournisseur;
1824
-	                    if (empty($tmpcode) && ! empty($object->oldcopy->code_fournisseur)) $tmpcode=$object->oldcopy->code_fournisseur; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1825
-	                    if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1826
-	                    print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1827
-	                }
1828
-	                else if ($object->codefournisseur_modifiable())
1829
-	                {
1830
-	                    print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.$object->code_fournisseur.'" maxlength="15">';
1831
-	                }
1832
-	                else
1833
-	              {
1834
-	                    print $object->code_fournisseur;
1835
-	                    print '<input type="hidden" name="supplier_code" value="'.$object->code_fournisseur.'">';
1836
-	                }
1837
-	                print '</td><td>';
1838
-	                $s=$modCodeFournisseur->getToolTip($langs,$object,1);
1839
-	                print $form->textwithpicto('',$s,1);
1840
-	                print '</td></tr></table>';
1820
+                    print '<table class="nobordernopadding"><tr><td>';
1821
+                    if ((!$object->code_fournisseur || $object->code_fournisseur == -1) && $modCodeFournisseur->code_auto)
1822
+                    {
1823
+                        $tmpcode=$object->code_fournisseur;
1824
+                        if (empty($tmpcode) && ! empty($object->oldcopy->code_fournisseur)) $tmpcode=$object->oldcopy->code_fournisseur; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1825
+                        if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1826
+                        print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1827
+                    }
1828
+                    else if ($object->codefournisseur_modifiable())
1829
+                    {
1830
+                        print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.$object->code_fournisseur.'" maxlength="15">';
1831
+                    }
1832
+                    else
1833
+                    {
1834
+                        print $object->code_fournisseur;
1835
+                        print '<input type="hidden" name="supplier_code" value="'.$object->code_fournisseur.'">';
1836
+                    }
1837
+                    print '</td><td>';
1838
+                    $s=$modCodeFournisseur->getToolTip($langs,$object,1);
1839
+                    print $form->textwithpicto('',$s,1);
1840
+                    print '</td></tr></table>';
1841 1841
                 }
1842 1842
                 print '</td></tr>';
1843 1843
             }
@@ -1846,7 +1846,7 @@  discard block
 block discarded – undo
1846 1846
             if (! empty($conf->barcode->enabled))
1847 1847
             {
1848 1848
                 print '<tr><td class="tdtop">'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).'</td>';
1849
-	            print '<td colspan="3"><input type="text" name="barcode" id="barcode" value="'.$object->barcode.'">';
1849
+                print '<td colspan="3"><input type="text" name="barcode" id="barcode" value="'.$object->barcode.'">';
1850 1850
                 print '</td></tr>';
1851 1851
             }
1852 1852
 
@@ -1857,7 +1857,7 @@  discard block
 block discarded – undo
1857 1857
 
1858 1858
             // Address
1859 1859
             print '<tr><td class="tdtop">'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
1860
-	        print '<td colspan="3"><textarea name="address" id="address" class="quatrevingtpercent" rows="3" wrap="soft">';
1860
+            print '<td colspan="3"><textarea name="address" id="address" class="quatrevingtpercent" rows="3" wrap="soft">';
1861 1861
             print $object->address;
1862 1862
             print '</textarea></td></tr>';
1863 1863
 
@@ -1892,37 +1892,37 @@  discard block
 block discarded – undo
1892 1892
 
1893 1893
             // EMail / Web
1894 1894
             print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', (! empty($conf->global->SOCIETE_EMAIL_MANDATORY))).'</td>';
1895
-	        print '<td colspan="3"><input type="text" name="email" id="email" size="32" value="'.$object->email.'"></td></tr>';
1895
+            print '<td colspan="3"><input type="text" name="email" id="email" size="32" value="'.$object->email.'"></td></tr>';
1896 1896
             print '<tr><td>'.$form->editfieldkey('Web', 'url', '', $object, 0).'</td>';
1897
-	        print '<td colspan="3"><input type="text" name="url" id="url" size="32" value="'.$object->url.'"></td></tr>';
1898
-
1899
-	        if (! empty($conf->socialnetworks->enabled))
1900
-	        {
1901
-	        	// Skype
1902
-	        	if (! empty($conf->global->SOCIALNETWORKS_SKYPE))
1903
-	        	{
1904
-	        		print '<tr><td>'.$form->editfieldkey('Skype', 'skype', '', $object, 0).'</td>';
1905
-	        		print '<td colspan="3"><input type="text" name="skype" id="skype" value="'.$object->skype.'"></td></tr>';
1906
-	        	}
1907
-	        	// Twitter
1908
-	        	if (! empty($conf->global->SOCIALNETWORKS_TWITTER))
1909
-	        	{
1910
-	        		print '<tr><td>'.$form->editfieldkey('Twitter', 'twitter', '', $object, 0).'</td>';
1911
-	        		print '<td colspan="3"><input type="text" name="twitter" id="twitter" value="'.$object->twitter.'"></td></tr>';
1912
-	        	}
1913
-	        	// Facebook
1914
-	        	if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK))
1915
-	        	{
1916
-	        		print '<tr><td>'.$form->editfieldkey('Facebook', 'facebook', '', $object, 0).'</td>';
1917
-	        		print '<td colspan="3"><input type="text" name="facebook" id="facebook" value="'.$object->facebook.'"></td></tr>';
1918
-	        	}
1919
-	        }
1897
+            print '<td colspan="3"><input type="text" name="url" id="url" size="32" value="'.$object->url.'"></td></tr>';
1898
+
1899
+            if (! empty($conf->socialnetworks->enabled))
1900
+            {
1901
+                // Skype
1902
+                if (! empty($conf->global->SOCIALNETWORKS_SKYPE))
1903
+                {
1904
+                    print '<tr><td>'.$form->editfieldkey('Skype', 'skype', '', $object, 0).'</td>';
1905
+                    print '<td colspan="3"><input type="text" name="skype" id="skype" value="'.$object->skype.'"></td></tr>';
1906
+                }
1907
+                // Twitter
1908
+                if (! empty($conf->global->SOCIALNETWORKS_TWITTER))
1909
+                {
1910
+                    print '<tr><td>'.$form->editfieldkey('Twitter', 'twitter', '', $object, 0).'</td>';
1911
+                    print '<td colspan="3"><input type="text" name="twitter" id="twitter" value="'.$object->twitter.'"></td></tr>';
1912
+                }
1913
+                // Facebook
1914
+                if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK))
1915
+                {
1916
+                    print '<tr><td>'.$form->editfieldkey('Facebook', 'facebook', '', $object, 0).'</td>';
1917
+                    print '<td colspan="3"><input type="text" name="facebook" id="facebook" value="'.$object->facebook.'"></td></tr>';
1918
+                }
1919
+            }
1920 1920
 
1921 1921
             // Phone / Fax
1922 1922
             print '<tr><td>'.$form->editfieldkey('Phone', 'phone', '', $object, 0).'</td>';
1923
-	        print '<td><input type="text" name="phone" id="phone" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->phone.'"></td>';
1923
+            print '<td><input type="text" name="phone" id="phone" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->phone.'"></td>';
1924 1924
             print '<td>'.$form->editfieldkey('Fax', 'fax', '', $object, 0).'</td>';
1925
-	        print '<td><input type="text" name="fax" id="fax" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->fax.'"></td></tr>';
1925
+            print '<td><input type="text" name="fax" id="fax" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->fax.'"></td></tr>';
1926 1926
 
1927 1927
             // Prof ids
1928 1928
             $i=1; $j=0;
@@ -1931,13 +1931,13 @@  discard block
 block discarded – undo
1931 1931
                 $idprof=$langs->transcountry('ProfId'.$i,$object->country_code);
1932 1932
                 if ($idprof!='-')
1933 1933
                 {
1934
-	                $key='idprof'.$i;
1934
+                    $key='idprof'.$i;
1935 1935
 
1936
-	                if (($j % 2) == 0) print '<tr>';
1936
+                    if (($j % 2) == 0) print '<tr>';
1937 1937
 
1938
-	                $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
1939
-	                print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', ! (empty($conf->global->$idprof_mandatory) || ! $object->isACompany())).'</td><td>';
1940
-	                print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
1938
+                    $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
1939
+                    print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', ! (empty($conf->global->$idprof_mandatory) || ! $object->isACompany())).'</td><td>';
1940
+                    print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
1941 1941
                     print '</td>';
1942 1942
                     if (($j % 2) == 1) print '</tr>';
1943 1943
                     $j++;
@@ -2047,9 +2047,9 @@  discard block
 block discarded – undo
2047 2047
 
2048 2048
             // Capital
2049 2049
             print '<tr><td>'.$form->editfieldkey('Capital', 'capital', '', $object, 0).'</td>';
2050
-	        print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="';
2051
-	        print $object->capital != '' ? dol_escape_htmltag(price($object->capital)) : '';
2052
-	        print '"> <font class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</font></td></tr>';
2050
+            print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="';
2051
+            print $object->capital != '' ? dol_escape_htmltag(price($object->capital)) : '';
2052
+            print '"> <font class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</font></td></tr>';
2053 2053
 
2054 2054
             // Default language
2055 2055
             if (! empty($conf->global->MAIN_MULTILANGS))
@@ -2063,52 +2063,52 @@  discard block
 block discarded – undo
2063 2063
             // Incoterms
2064 2064
             if (!empty($conf->incoterm->enabled))
2065 2065
             {
2066
-            	print '<tr>';
2067
-      				print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
2068
-            	print '<td colspan="3" class="maxwidthonsmartphone">';
2069
-            	print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
2070
-            	print '</td></tr>';
2071
-            }
2072
-
2073
-			// Categories
2074
-			if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
2075
-			{
2076
-				// Customer
2077
-				print '<tr class="visibleifcustomer"><td>' . $form->editfieldkey('CustomersCategoriesShort', 'custcats', '', $object, 0) . '</td>';
2078
-				print '<td colspan="3">';
2079
-				$cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, null, null, null, 1);
2080
-				$c = new Categorie($db);
2081
-				$cats = $c->containing($object->id, Categorie::TYPE_CUSTOMER);
2082
-				$arrayselected=array();
2083
-				foreach ($cats as $cat) {
2084
-					$arrayselected[] = $cat->id;
2085
-				}
2086
-				print $form->multiselectarray('custcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%');
2087
-				print "</td></tr>";
2088
-
2089
-				// Supplier
2090
-				print '<tr class="visibleifsupplier"><td>' . $form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0) . '</td>';
2091
-				print '<td colspan="3">';
2092
-				$cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, null, null, null, 1);
2093
-				$c = new Categorie($db);
2094
-				$cats = $c->containing($object->id, Categorie::TYPE_SUPPLIER);
2095
-				$arrayselected=array();
2096
-				foreach ($cats as $cat) {
2097
-					$arrayselected[] = $cat->id;
2098
-				}
2099
-				print $form->multiselectarray('suppcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%');
2100
-				print "</td></tr>";
2101
-			}
2102
-
2103
-			// Multicurrency
2104
-			if (! empty($conf->multicurrency->enabled))
2105
-			{
2106
-				print '<tr>';
2107
-				print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
2108
-		        print '<td colspan="3" class="maxwidthonsmartphone">';
2109
-		        print $form->selectMultiCurrency(($object->multicurrency_code ? $object->multicurrency_code : $conf->currency), 'multicurrency_code', 1);
2110
-				print '</td></tr>';
2111
-			}
2066
+                print '<tr>';
2067
+                        print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
2068
+                print '<td colspan="3" class="maxwidthonsmartphone">';
2069
+                print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
2070
+                print '</td></tr>';
2071
+            }
2072
+
2073
+            // Categories
2074
+            if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
2075
+            {
2076
+                // Customer
2077
+                print '<tr class="visibleifcustomer"><td>' . $form->editfieldkey('CustomersCategoriesShort', 'custcats', '', $object, 0) . '</td>';
2078
+                print '<td colspan="3">';
2079
+                $cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, null, null, null, 1);
2080
+                $c = new Categorie($db);
2081
+                $cats = $c->containing($object->id, Categorie::TYPE_CUSTOMER);
2082
+                $arrayselected=array();
2083
+                foreach ($cats as $cat) {
2084
+                    $arrayselected[] = $cat->id;
2085
+                }
2086
+                print $form->multiselectarray('custcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%');
2087
+                print "</td></tr>";
2088
+
2089
+                // Supplier
2090
+                print '<tr class="visibleifsupplier"><td>' . $form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0) . '</td>';
2091
+                print '<td colspan="3">';
2092
+                $cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, null, null, null, 1);
2093
+                $c = new Categorie($db);
2094
+                $cats = $c->containing($object->id, Categorie::TYPE_SUPPLIER);
2095
+                $arrayselected=array();
2096
+                foreach ($cats as $cat) {
2097
+                    $arrayselected[] = $cat->id;
2098
+                }
2099
+                print $form->multiselectarray('suppcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%');
2100
+                print "</td></tr>";
2101
+            }
2102
+
2103
+            // Multicurrency
2104
+            if (! empty($conf->multicurrency->enabled))
2105
+            {
2106
+                print '<tr>';
2107
+                print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
2108
+                print '<td colspan="3" class="maxwidthonsmartphone">';
2109
+                print $form->selectMultiCurrency(($object->multicurrency_code ? $object->multicurrency_code : $conf->currency), 'multicurrency_code', 1);
2110
+                print '</td></tr>';
2111
+            }
2112 2112
 
2113 2113
             // Other attributes
2114 2114
             $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
@@ -2116,7 +2116,7 @@  discard block
 block discarded – undo
2116 2116
             print $hookmanager->resPrint;
2117 2117
             if (empty($reshook))
2118 2118
             {
2119
-            	print $object->showOptionals($extrafields,'edit');
2119
+                print $object->showOptionals($extrafields,'edit');
2120 2120
             }
2121 2121
 
2122 2122
             // Webservices url/key
@@ -2158,7 +2158,7 @@  discard block
 block discarded – undo
2158 2158
             print '</table>';
2159 2159
             print '</div>';
2160 2160
 
2161
-	          dol_fiche_end();
2161
+                dol_fiche_end();
2162 2162
 
2163 2163
             print '<div align="center">';
2164 2164
             print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
@@ -2171,7 +2171,7 @@  discard block
 block discarded – undo
2171 2171
     }
2172 2172
     else
2173 2173
     {
2174
-    	/*
2174
+        /*
2175 2175
          * View
2176 2176
          */
2177 2177
 
@@ -2189,19 +2189,19 @@  discard block
 block discarded – undo
2189 2189
             print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("DeleteACompany"), $langs->trans("ConfirmDeleteCompany"), "confirm_delete", '', 0, "action-delete");
2190 2190
         }
2191 2191
 
2192
-	    if ($action == 'merge')
2193
-	    {
2194
-		    $formquestion = array(
2195
-			    array(
2196
-				    'name' => 'soc_origin',
2197
-			    	'label' => $langs->trans('MergeOriginThirdparty'),
2198
-				    'type' => 'other',
2199
-				    'value' => $form->select_company('', 'soc_origin', 's.rowid != '.$object->id, 'SelectThirdParty', 0, 0, array(), 0, 'minwidth200')
2200
-			    )
2201
-		    );
2202
-
2203
-		    print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("MergeThirdparties"), $langs->trans("ConfirmMergeThirdparties"), "confirm_merge", $formquestion, 'no', 1, 250);
2204
-	    }
2192
+        if ($action == 'merge')
2193
+        {
2194
+            $formquestion = array(
2195
+                array(
2196
+                    'name' => 'soc_origin',
2197
+                    'label' => $langs->trans('MergeOriginThirdparty'),
2198
+                    'type' => 'other',
2199
+                    'value' => $form->select_company('', 'soc_origin', 's.rowid != '.$object->id, 'SelectThirdParty', 0, 0, array(), 0, 'minwidth200')
2200
+                )
2201
+            );
2202
+
2203
+            print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("MergeThirdparties"), $langs->trans("ConfirmMergeThirdparties"), "confirm_merge", $formquestion, 'no', 1, 250);
2204
+        }
2205 2205
 
2206 2206
         dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error');
2207 2207
 
@@ -2216,20 +2216,20 @@  discard block
 block discarded – undo
2216 2216
         print '<div class="underbanner clearboth"></div>';
2217 2217
         print '<table class="border tableforfield" width="100%">';
2218 2218
 
2219
-    	// Prospect/Customer
2220
-    	print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>';
2221
-    	print $object->getLibCustProspStatut();
2222
-    	print '</td></tr>';
2219
+        // Prospect/Customer
2220
+        print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>';
2221
+        print $object->getLibCustProspStatut();
2222
+        print '</td></tr>';
2223 2223
 
2224
-    	// Supplier
2225
-   		if (! empty($conf->fournisseur->enabled) || ! empty($conf->supplier_proposal->enabled))
2226
-    	{
2227
-    		print '<tr><td>'.$langs->trans('Supplier').'</td><td>';
2228
-    		print yn($object->fournisseur);
2229
-    		print '</td></tr>';
2230
-    	}
2224
+        // Supplier
2225
+            if (! empty($conf->fournisseur->enabled) || ! empty($conf->supplier_proposal->enabled))
2226
+        {
2227
+            print '<tr><td>'.$langs->trans('Supplier').'</td><td>';
2228
+            print yn($object->fournisseur);
2229
+            print '</td></tr>';
2230
+        }
2231 2231
 
2232
-    	// Prefix
2232
+        // Prefix
2233 2233
         if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
2234 2234
         {
2235 2235
             print '<tr><td>'.$langs->trans('Prefix').'</td><td>'.$object->prefix_comm.'</td>';
@@ -2267,9 +2267,9 @@  discard block
 block discarded – undo
2267 2267
             print '<tr><td>';
2268 2268
             print $langs->trans('Gencod').'</td><td>'.$object->barcode;
2269 2269
             print '</td>';
2270
-			if ($htmllogobar) $htmllogobar.=$form->showbarcode($object);
2270
+            if ($htmllogobar) $htmllogobar.=$form->showbarcode($object);
2271 2271
             print $htmllogobar;
2272
-			$htmllogobar='';
2272
+            $htmllogobar='';
2273 2273
             print '</tr>';
2274 2274
         }
2275 2275
 
@@ -2282,7 +2282,7 @@  discard block
 block discarded – undo
2282 2282
             {
2283 2283
                 //if (($j % 2) == 0) print '<tr>';
2284 2284
                 print '<tr>';
2285
-            	print '<td>'.$idprof.'</td><td>';
2285
+                print '<td>'.$idprof.'</td><td>';
2286 2286
                 $key='idprof'.$i;
2287 2287
                 print $object->$key;
2288 2288
                 if ($object->$key)
@@ -2306,108 +2306,108 @@  discard block
 block discarded – undo
2306 2306
 
2307 2307
         if ($object->fournisseur)
2308 2308
         {
2309
-	        // VAT is used
2310
-	        print '<tr><td>';
2311
-	        print $form->textwithpicto($langs->trans('VATIsUsed'),$langs->trans('VATIsUsedWhenSelling'));
2312
-	        print '</td><td>';
2313
-	        print yn($object->tva_assuj);
2314
-	        print '</td>';
2315
-			print '</tr>';
2309
+            // VAT is used
2310
+            print '<tr><td>';
2311
+            print $form->textwithpicto($langs->trans('VATIsUsed'),$langs->trans('VATIsUsedWhenSelling'));
2312
+            print '</td><td>';
2313
+            print yn($object->tva_assuj);
2314
+            print '</td>';
2315
+            print '</tr>';
2316 2316
         }
2317 2317
 
2318
-		// Local Taxes
2318
+        // Local Taxes
2319 2319
         if ($object->fournisseur || $mysoc->country_code=='ES')
2320 2320
         {
2321
-        	if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
2322
-			{
2323
-			    print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
2324
-			    print yn($object->localtax1_assuj);
2325
-			    print '</td></tr><tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
2326
-			    print yn($object->localtax2_assuj);
2327
-			    print '</td></tr>';
2328
-
2329
-			    if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1)))
2330
-			    {
2331
-			        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2332
-			        print '<input type="hidden" name="action" value="set_localtax1">';
2333
-			        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2334
-			        print '<tr><td>'.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2335
-			        if($action == 'editRE')
2336
-			        {
2337
-			            print '<td align="left">';
2338
-			            $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2339
-			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2340
-			        }
2341
-			        else
2342
-			        {
2343
-			            print '<td>'.$object->localtax1_value.'</td>';
2344
-			        }
2345
-			        print '</tr></form>';
2346
-			    }
2347
-			    if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2)))
2348
-			    {
2349
-			        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2350
-			        print '<input type="hidden" name="action" value="set_localtax2">';
2351
-			        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2352
-			        print '<tr><td>'.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2353
-			        if($action == 'editIRPF'){
2354
-			            print '<td align="left">';
2355
-			            $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2356
-			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2357
-			        }else{
2358
-			            print '<td>'.$object->localtax2_value.'</td>';
2359
-			        }
2360
-			        print '</tr></form>';
2361
-			    }
2362
-			}
2363
-			elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
2364
-			{
2365
-			    print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
2366
-			    print yn($object->localtax1_assuj);
2367
-			    print '</td></tr>';
2368
-			    if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1)))
2369
-			    {
2370
-			        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2371
-			        print '<input type="hidden" name="action" value="set_localtax1">';
2372
-			        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2373
-			        print '<tr><td> '.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2374
-			        if($action == 'editRE'){
2375
-			            print '<td align="left">';
2376
-			            $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2377
-			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2378
-			        }else{
2379
-			            print '<td>'.$object->localtax1_value.'</td>';
2380
-			        }
2381
-			        print '</tr></form>';
2382
-			    }
2383
-			}
2384
-			elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
2385
-			{
2386
-			    print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
2387
-			    print yn($object->localtax2_assuj);
2388
-			    print '</td></tr>';
2389
-			    if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2)))
2390
-			    {
2391
-
2392
-			        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2393
-			        print '<input type="hidden" name="action" value="set_localtax2">';
2394
-			        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2395
-			        print '<tr><td> '.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2396
-			        if($action == 'editIRPF'){
2397
-			            print '<td align="left">';
2398
-			            $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2399
-			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2400
-			        }else{
2401
-			            print '<td>'.$object->localtax2_value.'</td>';
2402
-			        }
2403
-			        print '</tr></form>';
2404
-			    }
2405
-			}
2321
+            if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
2322
+            {
2323
+                print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
2324
+                print yn($object->localtax1_assuj);
2325
+                print '</td></tr><tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
2326
+                print yn($object->localtax2_assuj);
2327
+                print '</td></tr>';
2328
+
2329
+                if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1)))
2330
+                {
2331
+                    print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2332
+                    print '<input type="hidden" name="action" value="set_localtax1">';
2333
+                    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2334
+                    print '<tr><td>'.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2335
+                    if($action == 'editRE')
2336
+                    {
2337
+                        print '<td align="left">';
2338
+                        $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2339
+                        print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2340
+                    }
2341
+                    else
2342
+                    {
2343
+                        print '<td>'.$object->localtax1_value.'</td>';
2344
+                    }
2345
+                    print '</tr></form>';
2346
+                }
2347
+                if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2)))
2348
+                {
2349
+                    print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2350
+                    print '<input type="hidden" name="action" value="set_localtax2">';
2351
+                    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2352
+                    print '<tr><td>'.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2353
+                    if($action == 'editIRPF'){
2354
+                        print '<td align="left">';
2355
+                        $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2356
+                        print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2357
+                    }else{
2358
+                        print '<td>'.$object->localtax2_value.'</td>';
2359
+                    }
2360
+                    print '</tr></form>';
2361
+                }
2362
+            }
2363
+            elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
2364
+            {
2365
+                print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
2366
+                print yn($object->localtax1_assuj);
2367
+                print '</td></tr>';
2368
+                if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1)))
2369
+                {
2370
+                    print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2371
+                    print '<input type="hidden" name="action" value="set_localtax1">';
2372
+                    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2373
+                    print '<tr><td> '.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2374
+                    if($action == 'editRE'){
2375
+                        print '<td align="left">';
2376
+                        $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2377
+                        print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2378
+                    }else{
2379
+                        print '<td>'.$object->localtax1_value.'</td>';
2380
+                    }
2381
+                    print '</tr></form>';
2382
+                }
2383
+            }
2384
+            elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
2385
+            {
2386
+                print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
2387
+                print yn($object->localtax2_assuj);
2388
+                print '</td></tr>';
2389
+                if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2)))
2390
+                {
2391
+
2392
+                    print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2393
+                    print '<input type="hidden" name="action" value="set_localtax2">';
2394
+                    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2395
+                    print '<tr><td> '.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2396
+                    if($action == 'editIRPF'){
2397
+                        print '<td align="left">';
2398
+                        $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2399
+                        print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2400
+                    }else{
2401
+                        print '<td>'.$object->localtax2_value.'</td>';
2402
+                    }
2403
+                    print '</tr></form>';
2404
+                }
2405
+            }
2406 2406
         }
2407 2407
 
2408 2408
         // Sale tax code (VAT code)
2409 2409
         print '<tr>';
2410
-		print '<td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
2410
+        print '<td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
2411 2411
         if ($object->tva_intra)
2412 2412
         {
2413 2413
             $s='';
@@ -2458,25 +2458,25 @@  discard block
 block discarded – undo
2458 2458
         print '<div class="underbanner clearboth"></div>';
2459 2459
         print '<table class="border tableforfield" width="100%">';
2460 2460
 
2461
-    	// Tags / categories
2462
-		if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
2463
-		{
2464
-			// Customer
2465
-			if ($object->prospect || $object->client || (! $object->fournisseur && ! empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER))) {
2466
-				print '<tr><td>' . $langs->trans("CustomersCategoriesShort") . '</td>';
2467
-				print '<td>';
2468
-				print $form->showCategories($object->id, 'customer', 1);
2469
-				print "</td></tr>";
2470
-			}
2471
-
2472
-			// Supplier
2473
-			if ($object->fournisseur) {
2474
-				print '<tr><td>' . $langs->trans("SuppliersCategoriesShort") . '</td>';
2475
-				print '<td>';
2476
-				print $form->showCategories($object->id, 'supplier', 1);
2477
-				print "</td></tr>";
2478
-			}
2479
-		}
2461
+        // Tags / categories
2462
+        if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
2463
+        {
2464
+            // Customer
2465
+            if ($object->prospect || $object->client || (! $object->fournisseur && ! empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER))) {
2466
+                print '<tr><td>' . $langs->trans("CustomersCategoriesShort") . '</td>';
2467
+                print '<td>';
2468
+                print $form->showCategories($object->id, 'customer', 1);
2469
+                print "</td></tr>";
2470
+            }
2471
+
2472
+            // Supplier
2473
+            if ($object->fournisseur) {
2474
+                print '<tr><td>' . $langs->trans("SuppliersCategoriesShort") . '</td>';
2475
+                print '<td>';
2476
+                print $form->showCategories($object->id, 'supplier', 1);
2477
+                print "</td></tr>";
2478
+            }
2479
+        }
2480 2480
 
2481 2481
         // Legal
2482 2482
         print '<tr><td class="titlefield">'.$langs->trans('JuridicalStatus').'</td><td>'.$object->forme_juridique.'</td></tr>';
@@ -2503,61 +2503,61 @@  discard block
 block discarded – undo
2503 2503
         // Incoterms
2504 2504
         if (!empty($conf->incoterm->enabled))
2505 2505
         {
2506
-        	print '<tr><td>';
2507
-        	print '<table width="100%" class="nobordernopadding"><tr><td>';
2508
-        	print $langs->trans('IncotermLabel');
2509
-        	print '<td><td align="right">';
2510
-        	if ($user->rights->societe->creer) print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$object->id.'&action=editincoterm">'.img_edit('',1).'</a>';
2511
-        	else print '&nbsp;';
2512
-        	print '</td></tr></table>';
2513
-        	print '</td>';
2514
-        	print '<td colspan="3">';
2515
-        	if ($action != 'editincoterm')
2516
-        	{
2517
-        		print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1);
2518
-        	}
2519
-        	else
2520
-        	{
2521
-        		print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?socid='.$object->id);
2522
-        	}
2523
-        	print '</td></tr>';
2524
-        }
2525
-
2526
-		// Multicurrency
2527
-		if (! empty($conf->multicurrency->enabled))
2528
-		{
2529
-			print '<tr>';
2530
-			print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
2531
-	        print '<td>';
2532
-	        print !empty($object->multicurrency_code) ? currency_name($object->multicurrency_code,1) : '';
2533
-			print '</td></tr>';
2534
-		}
2535
-
2536
-		// Other attributes
2537
-		$parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
2538
-		include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
2506
+            print '<tr><td>';
2507
+            print '<table width="100%" class="nobordernopadding"><tr><td>';
2508
+            print $langs->trans('IncotermLabel');
2509
+            print '<td><td align="right">';
2510
+            if ($user->rights->societe->creer) print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$object->id.'&action=editincoterm">'.img_edit('',1).'</a>';
2511
+            else print '&nbsp;';
2512
+            print '</td></tr></table>';
2513
+            print '</td>';
2514
+            print '<td colspan="3">';
2515
+            if ($action != 'editincoterm')
2516
+            {
2517
+                print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1);
2518
+            }
2519
+            else
2520
+            {
2521
+                print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?socid='.$object->id);
2522
+            }
2523
+            print '</td></tr>';
2524
+        }
2525
+
2526
+        // Multicurrency
2527
+        if (! empty($conf->multicurrency->enabled))
2528
+        {
2529
+            print '<tr>';
2530
+            print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
2531
+            print '<td>';
2532
+            print !empty($object->multicurrency_code) ? currency_name($object->multicurrency_code,1) : '';
2533
+            print '</td></tr>';
2534
+        }
2535
+
2536
+        // Other attributes
2537
+        $parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
2538
+        include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
2539 2539
 
2540 2540
         // Parent company
2541 2541
         if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY))
2542 2542
         {
2543
-        	// Payment term
2544
-        	print '<tr><td>';
2545
-        	print '<table class="nobordernopadding" width="100%"><tr><td>';
2546
-        	print $langs->trans('ParentCompany');
2547
-        	print '</td>';
2548
-        	if ($action != 'editparentcompany') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</a></td>';
2549
-        	print '</tr></table>';
2550
-        	print '</td><td colspan="3">';
2551
-        	if ($action == 'editparentcompany')
2552
-        	{
2553
-        		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'editparentcompany','s.rowid <> '.$object->id,1);
2554
-        	}
2555
-        	else
2556
-        	{
2557
-        		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'none','s.rowid <> '.$object->id,1);
2558
-        	}
2559
-        	print '</td>';
2560
-        	print '</tr>';
2543
+            // Payment term
2544
+            print '<tr><td>';
2545
+            print '<table class="nobordernopadding" width="100%"><tr><td>';
2546
+            print $langs->trans('ParentCompany');
2547
+            print '</td>';
2548
+            if ($action != 'editparentcompany') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</a></td>';
2549
+            print '</tr></table>';
2550
+            print '</td><td colspan="3">';
2551
+            if ($action == 'editparentcompany')
2552
+            {
2553
+                $form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'editparentcompany','s.rowid <> '.$object->id,1);
2554
+            }
2555
+            else
2556
+            {
2557
+                $form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'none','s.rowid <> '.$object->id,1);
2558
+            }
2559
+            print '</td>';
2560
+            print '</tr>';
2561 2561
         }
2562 2562
 
2563 2563
         // Sales representative
@@ -2591,7 +2591,7 @@  discard block
 block discarded – undo
2591 2591
         }
2592 2592
 
2593 2593
         print '</table>';
2594
-		print '</div>';
2594
+        print '</div>';
2595 2595
 
2596 2596
         print '</div></div>';
2597 2597
         print '<div style="clear:both"></div>';
@@ -2604,128 +2604,128 @@  discard block
 block discarded – undo
2604 2604
          */
2605 2605
         if ($action != 'presend')
2606 2606
         {
2607
-	        print '<div class="tabsAction">'."\n";
2608
-
2609
-			$parameters=array();
2610
-			$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
2611
-			if (empty($reshook))
2612
-			{
2613
-				$at_least_one_email_contact = false;
2614
-				$TContact = $object->contact_array_objects();
2615
-				foreach ($TContact as &$contact)
2616
-				{
2617
-					if (!empty($contact->email))
2618
-					{
2619
-						$at_least_one_email_contact = true;
2620
-						break;
2621
-					}
2622
-				}
2607
+            print '<div class="tabsAction">'."\n";
2623 2608
 
2624
-		        if (! empty($object->email) || $at_least_one_email_contact)
2625
-		        {
2626
-		        	$langs->load("mails");
2627
-		        	print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'&amp;action=presend&amp;mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';
2628
-		        }
2629
-		        else
2630
-				{
2631
-		        	$langs->load("mails");
2632
-		       		print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans('SendMail').'</a></div>';
2633
-		        }
2634
-
2635
-		        if ($user->rights->societe->creer)
2636
-		        {
2637
-		            print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a></div>'."\n";
2638
-		        }
2639
-
2640
-		        if ($user->rights->societe->supprimer)
2641
-		        {
2642
-		        	print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?action=merge&socid='.$object->id.'" title="'.dol_escape_htmltag($langs->trans("MergeThirdparties")).'">'.$langs->trans('Merge').'</a></div>';
2643
-		        }
2644
-
2645
-		        if ($user->rights->societe->supprimer)
2646
-		        {
2647
-		            if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))	// We can't use preloaded confirm form with jmobile
2648
-		            {
2649
-		                print '<div class="inline-block divButAction"><span id="action-delete" class="butActionDelete">'.$langs->trans('Delete').'</span></div>'."\n";
2650
-		            }
2651
-		            else
2652
-					{
2653
-		                print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a></div>'."\n";
2654
-		            }
2655
-		        }
2656
-			}
2609
+            $parameters=array();
2610
+            $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
2611
+            if (empty($reshook))
2612
+            {
2613
+                $at_least_one_email_contact = false;
2614
+                $TContact = $object->contact_array_objects();
2615
+                foreach ($TContact as &$contact)
2616
+                {
2617
+                    if (!empty($contact->email))
2618
+                    {
2619
+                        $at_least_one_email_contact = true;
2620
+                        break;
2621
+                    }
2622
+                }
2623
+
2624
+                if (! empty($object->email) || $at_least_one_email_contact)
2625
+                {
2626
+                    $langs->load("mails");
2627
+                    print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'&amp;action=presend&amp;mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';
2628
+                }
2629
+                else
2630
+                {
2631
+                    $langs->load("mails");
2632
+                        print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans('SendMail').'</a></div>';
2633
+                }
2634
+
2635
+                if ($user->rights->societe->creer)
2636
+                {
2637
+                    print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a></div>'."\n";
2638
+                }
2639
+
2640
+                if ($user->rights->societe->supprimer)
2641
+                {
2642
+                    print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?action=merge&socid='.$object->id.'" title="'.dol_escape_htmltag($langs->trans("MergeThirdparties")).'">'.$langs->trans('Merge').'</a></div>';
2643
+                }
2657 2644
 
2658
-	        print '</div>'."\n";
2645
+                if ($user->rights->societe->supprimer)
2646
+                {
2647
+                    if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))	// We can't use preloaded confirm form with jmobile
2648
+                    {
2649
+                        print '<div class="inline-block divButAction"><span id="action-delete" class="butActionDelete">'.$langs->trans('Delete').'</span></div>'."\n";
2650
+                    }
2651
+                    else
2652
+                    {
2653
+                        print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a></div>'."\n";
2654
+                    }
2655
+                }
2656
+            }
2657
+
2658
+            print '</div>'."\n";
2659 2659
         }
2660 2660
 
2661 2661
         //Select mail models is same action as presend
2662
-		if (GETPOST('modelselected')) {
2663
-			$action = 'presend';
2664
-		}
2662
+        if (GETPOST('modelselected')) {
2663
+            $action = 'presend';
2664
+        }
2665 2665
 
2666
-		if ($action != 'presend')
2667
-		{
2668
-			print '<div class="fichecenter"><div class="fichehalfleft">';
2666
+        if ($action != 'presend')
2667
+        {
2668
+            print '<div class="fichecenter"><div class="fichehalfleft">';
2669 2669
 
2670
-	        if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC))
2671
-	        {
2672
-				print '<a name="builddoc"></a>'; // ancre
2670
+            if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC))
2671
+            {
2672
+                print '<a name="builddoc"></a>'; // ancre
2673 2673
 
2674
-	            /*
2674
+                /*
2675 2675
 	             * Documents generes
2676 2676
 	             */
2677
-	            $filedir=$conf->societe->multidir_output[$object->entity].'/'.$object->id;
2678
-	            $urlsource=$_SERVER["PHP_SELF"]."?socid=".$object->id;
2679
-	            $genallowed=$user->rights->societe->lire;
2680
-	            $delallowed=$user->rights->societe->creer;
2677
+                $filedir=$conf->societe->multidir_output[$object->entity].'/'.$object->id;
2678
+                $urlsource=$_SERVER["PHP_SELF"]."?socid=".$object->id;
2679
+                $genallowed=$user->rights->societe->lire;
2680
+                $delallowed=$user->rights->societe->creer;
2681 2681
 
2682
-	            print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang);
2683
-	        }
2682
+                print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang);
2683
+            }
2684 2684
 
2685
-			// Subsidiaries list
2686
-			if (empty($conf->global->SOCIETE_DISABLE_SUBSIDIARIES))
2687
-			{
2688
-				$result=show_subsidiaries($conf,$langs,$db,$object);
2689
-			}
2685
+            // Subsidiaries list
2686
+            if (empty($conf->global->SOCIETE_DISABLE_SUBSIDIARIES))
2687
+            {
2688
+                $result=show_subsidiaries($conf,$langs,$db,$object);
2689
+            }
2690 2690
 
2691
-			print '</div><div class="fichehalfright"><div class="ficheaddleft">';
2691
+            print '</div><div class="fichehalfright"><div class="ficheaddleft">';
2692 2692
 
2693
-			$MAXEVENT = 10;
2693
+            $MAXEVENT = 10;
2694 2694
 
2695
-			$morehtmlright = '<a href="'.DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id.'">';
2696
-			$morehtmlright.= $langs->trans("SeeAll");
2697
-			$morehtmlright.= '</a>';
2695
+            $morehtmlright = '<a href="'.DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id.'">';
2696
+            $morehtmlright.= $langs->trans("SeeAll");
2697
+            $morehtmlright.= '</a>';
2698 2698
 
2699
-			// List of actions on element
2700
-			include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
2701
-			$formactions = new FormActions($db);
2702
-			$somethingshown = $formactions->showactions($object, '', $socid, 1, '', $MAXEVENT, '', $morehtmlright);		// Show all action for thirdparty
2699
+            // List of actions on element
2700
+            include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
2701
+            $formactions = new FormActions($db);
2702
+            $somethingshown = $formactions->showactions($object, '', $socid, 1, '', $MAXEVENT, '', $morehtmlright);		// Show all action for thirdparty
2703 2703
 
2704
-			print '</div></div></div>';
2704
+            print '</div></div></div>';
2705 2705
 
2706
-			if (! empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD))
2707
-			{
2708
-				// Contacts list
2709
-				if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
2710
-				{
2711
-					$result=show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
2712
-				}
2706
+            if (! empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD))
2707
+            {
2708
+                // Contacts list
2709
+                if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
2710
+                {
2711
+                    $result=show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
2712
+                }
2713 2713
 
2714
-				// Addresses list
2715
-				if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))
2716
-				{
2717
-					$result=show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
2718
-				}
2719
-			}
2720
-		}
2714
+                // Addresses list
2715
+                if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))
2716
+                {
2717
+                    $result=show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
2718
+                }
2719
+            }
2720
+        }
2721 2721
 
2722
-		// Presend form
2723
-		$modelmail='thirdparty';
2724
-		$defaulttopic='Information';
2725
-		$diroutput = $conf->societe->dir_output;
2726
-		$trackid = 'thi'.$object->id;
2722
+        // Presend form
2723
+        $modelmail='thirdparty';
2724
+        $defaulttopic='Information';
2725
+        $diroutput = $conf->societe->dir_output;
2726
+        $trackid = 'thi'.$object->id;
2727 2727
 
2728
-		include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2728
+        include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2729 2729
     }
2730 2730
 }
2731 2731
 
Please login to merge, or discard this patch.
Spacing   +481 added lines, -481 removed lines patch added patch discarded remove patch
@@ -45,36 +45,36 @@  discard block
 block discarded – undo
45 45
 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
46 46
 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
47 47
 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
48
-if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
48
+if (!empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
49 49
 
50
-$langs->loadLangs(array("companies","commercial","bills","banks","users"));
51
-if (! empty($conf->categorie->enabled)) $langs->load("categories");
52
-if (! empty($conf->incoterm->enabled)) $langs->load("incoterm");
53
-if (! empty($conf->notification->enabled)) $langs->load("mails");
50
+$langs->loadLangs(array("companies", "commercial", "bills", "banks", "users"));
51
+if (!empty($conf->categorie->enabled)) $langs->load("categories");
52
+if (!empty($conf->incoterm->enabled)) $langs->load("incoterm");
53
+if (!empty($conf->notification->enabled)) $langs->load("mails");
54 54
 
55
-$mesg=''; $error=0; $errors=array();
55
+$mesg = ''; $error = 0; $errors = array();
56 56
 
57
-$action		= (GETPOST('action','aZ09') ? GETPOST('action','aZ09') : 'view');
58
-$cancel		= GETPOST('cancel','alpha');
59
-$backtopage	= GETPOST('backtopage','alpha');
60
-$confirm	= GETPOST('confirm','alpha');
57
+$action		= (GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view');
58
+$cancel		= GETPOST('cancel', 'alpha');
59
+$backtopage = GETPOST('backtopage', 'alpha');
60
+$confirm	= GETPOST('confirm', 'alpha');
61 61
 
62
-$socid		= GETPOST('socid','int')?GETPOST('socid','int'):GETPOST('id','int');
63
-if ($user->societe_id) $socid=$user->societe_id;
64
-if (empty($socid) && $action == 'view') $action='create';
62
+$socid = GETPOST('socid', 'int') ?GETPOST('socid', 'int') : GETPOST('id', 'int');
63
+if ($user->societe_id) $socid = $user->societe_id;
64
+if (empty($socid) && $action == 'view') $action = 'create';
65 65
 
66 66
 $object = new Societe($db);
67 67
 $extrafields = new ExtraFields($db);
68 68
 
69 69
 // fetch optionals attributes and labels
70
-$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
70
+$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
71 71
 
72 72
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
73
-$hookmanager->initHooks(array('thirdpartycard','globalcard'));
73
+$hookmanager->initHooks(array('thirdpartycard', 'globalcard'));
74 74
 
75 75
 if ($socid > 0) $object->fetch($socid);
76 76
 
77
-if (! ($object->id > 0) && $action == 'view')
77
+if (!($object->id > 0) && $action == 'view')
78 78
 {
79 79
 	$langs->load("errors");
80 80
 	print($langs->trans('ErrorRecordNotFound'));
@@ -83,9 +83,9 @@  discard block
 block discarded – undo
83 83
 
84 84
 // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
85 85
 $object->getCanvas($socid);
86
-$canvas = $object->canvas?$object->canvas:GETPOST("canvas");
87
-$objcanvas=null;
88
-if (! empty($canvas))
86
+$canvas = $object->canvas ? $object->canvas : GETPOST("canvas");
87
+$objcanvas = null;
88
+if (!empty($canvas))
89 89
 {
90 90
     require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
91 91
     $objcanvas = new Canvas($db, $action);
@@ -100,16 +100,16 @@  discard block
 block discarded – undo
100 100
  * Actions
101 101
  */
102 102
 
103
-$parameters=array('id'=>$socid, 'objcanvas'=>$objcanvas);
104
-$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
103
+$parameters = array('id'=>$socid, 'objcanvas'=>$objcanvas);
104
+$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
105 105
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
106 106
 
107 107
 if (empty($reshook))
108 108
 {
109 109
     if ($cancel)
110 110
     {
111
-        $action='';
112
-        if (! empty($backtopage))
111
+        $action = '';
112
+        if (!empty($backtopage))
113 113
         {
114 114
             header("Location: ".$backtopage);
115 115
             exit;
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 				// Recopy some data
146 146
 				$object->client = $object->client | $soc_origin->client;
147 147
 				$object->fournisseur = $object->fournisseur | $soc_origin->fournisseur;
148
-				$listofproperties=array(
148
+				$listofproperties = array(
149 149
 					'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'skype', 'twitter', 'facebook', 'url', 'barcode',
150 150
 					'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6',
151 151
 					'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'remise_supplier_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis',
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 				}
160 160
 
161 161
 				// Concat some data
162
-				$listofproperties=array(
162
+				$listofproperties = array(
163 163
 				    'note_public', 'note_private'
164 164
 				);
165 165
 				foreach ($listofproperties as $property)
@@ -181,12 +181,12 @@  discard block
 block discarded – undo
181 181
 
182 182
 				$custcats_ori = $static_cat->containing($soc_origin->id, 'customer', 'id');
183 183
 				$custcats = $static_cat->containing($object->id, 'customer', 'id');
184
-				$custcats = array_merge($custcats,$custcats_ori);
184
+				$custcats = array_merge($custcats, $custcats_ori);
185 185
 				$object->setCategories($custcats, 'customer');
186 186
 
187 187
 				$suppcats_ori = $static_cat->containing($soc_origin->id, 'supplier', 'id');
188 188
 				$suppcats = $static_cat->containing($object->id, 'supplier', 'id');
189
-				$suppcats = array_merge($suppcats,$suppcats_ori);
189
+				$suppcats = array_merge($suppcats, $suppcats_ori);
190 190
 				$object->setCategories($suppcats, 'supplier');
191 191
 
192 192
 				// If thirdparty has a new code that is same than origin, we clean origin code to avoid duplicate key from database unique keys.
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 				}
210 210
 
211 211
 				// Move links
212
-				if (! $error)
212
+				if (!$error)
213 213
 				{
214 214
 					$objects = array(
215 215
 						'Adherent' => '/adherents/class/adherent.class.php',
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 				}
250 250
 
251 251
 				// External modules should update their ones too
252
-				if (! $error)
252
+				if (!$error)
253 253
 				{
254 254
 					$reshook = $hookmanager->executeHooks('replaceThirdparty', array(
255 255
 						'soc_origin' => $soc_origin->id,
@@ -264,12 +264,12 @@  discard block
 block discarded – undo
264 264
 				}
265 265
 
266 266
 
267
-				if (! $error)
267
+				if (!$error)
268 268
 				{
269
-					$object->context=array('merge'=>1, 'mergefromid'=>$soc_origin->id);
269
+					$object->context = array('merge'=>1, 'mergefromid'=>$soc_origin->id);
270 270
 
271 271
 					// Call trigger
272
-					$result=$object->call_trigger('COMPANY_MODIFY',$user);
272
+					$result = $object->call_trigger('COMPANY_MODIFY', $user);
273 273
 					if ($result < 0)
274 274
 					{
275 275
 						setEventMessages($object->error, $object->errors, 'errors');
@@ -305,28 +305,28 @@  discard block
 block discarded – undo
305 305
     if (GETPOST('getcustomercode'))
306 306
     {
307 307
         // We defined value code_client
308
-        $_POST["customer_code"]="Acompleter";
308
+        $_POST["customer_code"] = "Acompleter";
309 309
     }
310 310
 
311 311
     if (GETPOST('getsuppliercode'))
312 312
     {
313 313
         // We defined value code_fournisseur
314
-        $_POST["supplier_code"]="Acompleter";
314
+        $_POST["supplier_code"] = "Acompleter";
315 315
     }
316 316
 
317
-    if($action=='set_localtax1')
317
+    if ($action == 'set_localtax1')
318 318
     {
319 319
     	//obtidre selected del combobox
320
-    	$value=GETPOST('lt1');
320
+    	$value = GETPOST('lt1');
321 321
     	$object->fetch($socid);
322
-    	$res=$object->setValueFrom('localtax1_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
322
+    	$res = $object->setValueFrom('localtax1_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
323 323
     }
324
-    if($action=='set_localtax2')
324
+    if ($action == 'set_localtax2')
325 325
     {
326 326
     	//obtidre selected del combobox
327
-    	$value=GETPOST('lt2');
327
+    	$value = GETPOST('lt2');
328 328
     	$object->fetch($socid);
329
-    	$res=$object->setValueFrom('localtax2_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
329
+    	$res = $object->setValueFrom('localtax2_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
330 330
     }
331 331
 
332 332
     if ($action == 'update_extras') {
@@ -336,10 +336,10 @@  discard block
 block discarded – undo
336 336
 
337 337
         // Fill array 'array_options' with data from update form
338 338
         $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
339
-        $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute','none'));
339
+        $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute', 'none'));
340 340
         if ($ret < 0) $error++;
341 341
 
342
-        if (! $error)
342
+        if (!$error)
343 343
         {
344 344
         	$result = $object->insertExtraFields('COMPANY_MODIFY');
345 345
         	if ($result < 0)
@@ -353,12 +353,12 @@  discard block
 block discarded – undo
353 353
     }
354 354
 
355 355
     // Add new or update third party
356
-    if ((! GETPOST('getcustomercode') && ! GETPOST('getsuppliercode'))
356
+    if ((!GETPOST('getcustomercode') && !GETPOST('getsuppliercode'))
357 357
     && ($action == 'add' || $action == 'update') && $user->rights->societe->creer)
358 358
     {
359 359
         require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
360 360
 
361
-        if (! GETPOST('name'))
361
+        if (!GETPOST('name'))
362 362
         {
363 363
             setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdPartyName")), null, 'errors');
364 364
             $error++;
@@ -374,41 +374,41 @@  discard block
 block discarded – undo
374 374
             $error++;
375 375
         }
376 376
 
377
-        if (! $error)
377
+        if (!$error)
378 378
         {
379 379
         	if ($action == 'update')
380 380
 	        {
381
-	        	$ret=$object->fetch($socid);
381
+	        	$ret = $object->fetch($socid);
382 382
 				$object->oldcopy = clone $object;
383 383
 	        }
384
-			else $object->canvas=$canvas;
384
+			else $object->canvas = $canvas;
385 385
 
386 386
 	        if (GETPOST("private") == 1)	// Ask to create a contact
387 387
 	        {
388 388
 	            $object->particulier		= GETPOST("private");
389 389
 
390
-	            $object->name				= dolGetFirstLastname(GETPOST('firstname','alpha'),GETPOST('name','alpha'));
391
-	            $object->civility_id		= GETPOST('civility_id');	// Note: civility id is a code, not an int
390
+	            $object->name = dolGetFirstLastname(GETPOST('firstname', 'alpha'), GETPOST('name', 'alpha'));
391
+	            $object->civility_id		= GETPOST('civility_id'); // Note: civility id is a code, not an int
392 392
 	            // Add non official properties
393
-	            $object->name_bis			= GETPOST('name','alpha');
394
-	            $object->firstname			= GETPOST('firstname','alpha');
393
+	            $object->name_bis = GETPOST('name', 'alpha');
394
+	            $object->firstname = GETPOST('firstname', 'alpha');
395 395
 	        }
396 396
 	        else
397 397
 	        {
398
-	            $object->name				= GETPOST('name', 'alpha');
398
+	            $object->name = GETPOST('name', 'alpha');
399 399
 	        }
400
-	        $object->entity					= (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity);
401
-	        $object->name_alias				= GETPOST('name_alias');
400
+	        $object->entity					= (GETPOSTISSET('entity') ?GETPOST('entity', 'int') : $conf->entity);
401
+	        $object->name_alias = GETPOST('name_alias');
402 402
 	        $object->address				= GETPOST('address');
403
-	        $object->zip					= GETPOST('zipcode', 'alpha');
404
-	        $object->town					= GETPOST('town', 'alpha');
405
-	        $object->country_id				= GETPOST('country_id', 'int');
403
+	        $object->zip = GETPOST('zipcode', 'alpha');
404
+	        $object->town = GETPOST('town', 'alpha');
405
+	        $object->country_id = GETPOST('country_id', 'int');
406 406
 	        $object->state_id				= GETPOST('state_id', 'int');
407 407
 	        $object->skype					= GETPOST('skype', 'alpha');
408
-	        $object->twitter				= GETPOST('twitter', 'alpha');
408
+	        $object->twitter = GETPOST('twitter', 'alpha');
409 409
 	        $object->facebook				= GETPOST('facebook', 'alpha');
410 410
 	        $object->phone					= GETPOST('phone', 'alpha');
411
-	        $object->fax					= GETPOST('fax','alpha');
411
+	        $object->fax					= GETPOST('fax', 'alpha');
412 412
 	        $object->email					= trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL));
413 413
 	        $object->url					= trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL));
414 414
 	        $object->idprof1				= trim(GETPOST('idprof1', 'alpha'));
@@ -418,14 +418,14 @@  discard block
 block discarded – undo
418 418
 	        $object->idprof5				= trim(GETPOST('idprof5', 'alpha'));
419 419
 	        $object->idprof6				= trim(GETPOST('idprof6', 'alpha'));
420 420
 	        $object->prefix_comm			= GETPOST('prefix_comm', 'alpha');
421
-	        $object->code_client			= GETPOSTISSET('customer_code')?GETPOST('customer_code', 'alpha'):GETPOST('code_client', 'alpha');
422
-	        $object->code_fournisseur		= GETPOSTISSET('supplier_code')?GETPOST('supplier_code', 'alpha'):GETPOST('code_fournisseur', 'alpha');
421
+	        $object->code_client			= GETPOSTISSET('customer_code') ?GETPOST('customer_code', 'alpha') : GETPOST('code_client', 'alpha');
422
+	        $object->code_fournisseur = GETPOSTISSET('supplier_code') ?GETPOST('supplier_code', 'alpha') : GETPOST('code_fournisseur', 'alpha');
423 423
 	        $object->capital				= GETPOST('capital', 'alpha');
424 424
 	        $object->barcode				= GETPOST('barcode', 'alpha');
425 425
 
426 426
 	        $object->tva_intra				= GETPOST('tva_intra', 'alpha');
427 427
 	        $object->tva_assuj				= GETPOST('assujtva_value', 'alpha');
428
-	        $object->status					= GETPOST('status', 'alpha');
428
+	        $object->status = GETPOST('status', 'alpha');
429 429
 
430 430
 	        // Local Taxes
431 431
 	        $object->localtax1_assuj		= GETPOST('localtax1assuj_value', 'alpha');
@@ -434,17 +434,17 @@  discard block
 block discarded – undo
434 434
 	        $object->localtax1_value		= GETPOST('lt1', 'alpha');
435 435
 	        $object->localtax2_value		= GETPOST('lt2', 'alpha');
436 436
 
437
-	        $object->forme_juridique_code	= GETPOST('forme_juridique_code', 'int');
437
+	        $object->forme_juridique_code = GETPOST('forme_juridique_code', 'int');
438 438
 	        $object->effectif_id			= GETPOST('effectif_id', 'int');
439
-	        $object->typent_id				= GETPOST('typent_id','int');
439
+	        $object->typent_id = GETPOST('typent_id', 'int');
440 440
 
441
-	        $object->typent_code			= dol_getIdFromCode($db, $object->typent_id, 'c_typent', 'id', 'code');	// Force typent_code too so check in verify() will be done on new type
441
+	        $object->typent_code			= dol_getIdFromCode($db, $object->typent_id, 'c_typent', 'id', 'code'); // Force typent_code too so check in verify() will be done on new type
442 442
 
443
-	        $object->client					= GETPOST('client', 'int');
443
+	        $object->client = GETPOST('client', 'int');
444 444
 	        $object->fournisseur			= GETPOST('fournisseur', 'int');
445 445
 
446
-	        $object->commercial_id			= GETPOST('commercial_id', 'int');
447
-	        $object->default_lang			= GETPOST('default_lang');
446
+	        $object->commercial_id = GETPOST('commercial_id', 'int');
447
+	        $object->default_lang = GETPOST('default_lang');
448 448
 
449 449
 	        // Webservices url/key
450 450
 	        $object->webservices_url		= GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
@@ -453,8 +453,8 @@  discard block
 block discarded – undo
453 453
 			// Incoterms
454 454
 			if (!empty($conf->incoterm->enabled))
455 455
 			{
456
-				$object->fk_incoterms		= GETPOST('incoterm_id', 'int');
457
-				$object->location_incoterms	= GETPOST('location_incoterms', 'alpha');
456
+				$object->fk_incoterms = GETPOST('incoterm_id', 'int');
457
+				$object->location_incoterms = GETPOST('location_incoterms', 'alpha');
458 458
 			}
459 459
 
460 460
 			// Multicurrency
@@ -464,53 +464,53 @@  discard block
 block discarded – undo
464 464
 			}
465 465
 
466 466
 	        // Fill array 'array_options' with data from add form
467
-	        $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
467
+	        $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
468 468
 			if ($ret < 0)
469 469
 			{
470 470
 				 $error++;
471 471
 			}
472 472
 
473 473
 	        if (GETPOST('deletephoto')) $object->logo = '';
474
-	        else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
474
+	        else if (!empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
475 475
 
476 476
 	        // Check parameters
477
-	        if (! GETPOST('cancel','alpha'))
477
+	        if (!GETPOST('cancel', 'alpha'))
478 478
 	        {
479
-	            if (! empty($object->email) && ! isValidEMail($object->email))
479
+	            if (!empty($object->email) && !isValidEMail($object->email))
480 480
 	            {
481 481
 	                $langs->load("errors");
482 482
 	                $error++;
483
-	                setEventMessages('', $langs->trans("ErrorBadEMail",$object->email), 'errors');
483
+	                setEventMessages('', $langs->trans("ErrorBadEMail", $object->email), 'errors');
484 484
 	            }
485
-	            if (! empty($object->url) && ! isValidUrl($object->url))
485
+	            if (!empty($object->url) && !isValidUrl($object->url))
486 486
 	            {
487 487
 	                $langs->load("errors");
488
-	                setEventMessages('', $langs->trans("ErrorBadUrl",$object->url), 'errors');
488
+	                setEventMessages('', $langs->trans("ErrorBadUrl", $object->url), 'errors');
489 489
 	            }
490
-	            if (! empty($object->webservices_url)) {
490
+	            if (!empty($object->webservices_url)) {
491 491
 	                //Check if has transport, without any the soap client will give error
492 492
 	                if (strpos($object->webservices_url, "http") === false)
493 493
 	                {
494 494
 	                    $object->webservices_url = "http://".$object->webservices_url;
495 495
 	                }
496
-	                if (! isValidUrl($object->webservices_url)) {
496
+	                if (!isValidUrl($object->webservices_url)) {
497 497
 	                    $langs->load("errors");
498
-	                    $error++; $errors[] = $langs->trans("ErrorBadUrl",$object->webservices_url);
498
+	                    $error++; $errors[] = $langs->trans("ErrorBadUrl", $object->webservices_url);
499 499
 	                }
500 500
 	            }
501 501
 
502 502
 	            // We set country_id, country_code and country for the selected country
503
-	            $object->country_id=GETPOST('country_id')!=''?GETPOST('country_id'):$mysoc->country_id;
503
+	            $object->country_id = GETPOST('country_id') != '' ?GETPOST('country_id') : $mysoc->country_id;
504 504
 	            if ($object->country_id)
505 505
 	            {
506
-	            	$tmparray=getCountry($object->country_id,'all');
507
-	            	$object->country_code=$tmparray['code'];
508
-	            	$object->country=$tmparray['label'];
506
+	            	$tmparray = getCountry($object->country_id, 'all');
507
+	            	$object->country_code = $tmparray['code'];
508
+	            	$object->country = $tmparray['label'];
509 509
 	            }
510 510
 	        }
511 511
         }
512 512
 
513
-        if (! $error)
513
+        if (!$error)
514 514
         {
515 515
             if ($action == 'add')
516 516
             {
@@ -518,8 +518,8 @@  discard block
 block discarded – undo
518 518
 
519 519
                 $db->begin();
520 520
 
521
-                if (empty($object->client))      $object->code_client='';
522
-                if (empty($object->fournisseur)) $object->code_fournisseur='';
521
+                if (empty($object->client))      $object->code_client = '';
522
+                if (empty($object->fournisseur)) $object->code_fournisseur = '';
523 523
 
524 524
                 $result = $object->create($user);
525 525
 
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
 					if ($object->particulier)
529 529
 					{
530 530
 						dol_syslog("We ask to create a contact/address too", LOG_DEBUG);
531
-						$result=$object->create_individual($user);
531
+						$result = $object->create_individual($user);
532 532
 						if ($result < 0)
533 533
 						{
534 534
 							setEventMessages($object->error, $object->errors, 'errors');
@@ -574,10 +574,10 @@  discard block
 block discarded – undo
574 574
 
575 575
                             if (@is_dir($dir))
576 576
                             {
577
-                                $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
577
+                                $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
578 578
                                 $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
579 579
 
580
-                                if (! $result > 0)
580
+                                if (!$result > 0)
581 581
                                 {
582 582
                                     $errors[] = "ErrorFailedToSaveFile";
583 583
                                 }
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
                     }
592 592
                     else
593 593
 					{
594
-						switch($_FILES['photo']['error'])
594
+						switch ($_FILES['photo']['error'])
595 595
 						{
596 596
 						    case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
597 597
 						    case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
@@ -617,21 +617,21 @@  discard block
 block discarded – undo
617 617
                    	$error++;
618 618
                 }
619 619
 
620
-                if ($result >= 0 && ! $error)
620
+                if ($result >= 0 && !$error)
621 621
                 {
622 622
                     $db->commit();
623 623
 
624
-                	if (! empty($backtopage))
624
+                	if (!empty($backtopage))
625 625
                 	{
626
-                	    if (preg_match('/\?/', $backtopage)) $backtopage.='&socid='.$object->id;
626
+                	    if (preg_match('/\?/', $backtopage)) $backtopage .= '&socid='.$object->id;
627 627
                		    header("Location: ".$backtopage);
628 628
                     	exit;
629 629
                 	}
630 630
                 	else
631 631
                 	{
632
-                    	$url=$_SERVER["PHP_SELF"]."?socid=".$object->id;
633
-                    	if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $url=DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
634
-                    	else if ($object->fournisseur == 1) $url=DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
632
+                    	$url = $_SERVER["PHP_SELF"]."?socid=".$object->id;
633
+                    	if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $url = DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
634
+                    	else if ($object->fournisseur == 1) $url = DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
635 635
 
636 636
                 		header("Location: ".$url);
637 637
                     	exit;
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
                 else
641 641
                 {
642 642
                     $db->rollback();
643
-                    $action='create';
643
+                    $action = 'create';
644 644
                 }
645 645
             }
646 646
 
@@ -648,9 +648,9 @@  discard block
 block discarded – undo
648 648
             {
649 649
             	$error = 0;
650 650
 
651
-                if (GETPOST('cancel','alpha'))
651
+                if (GETPOST('cancel', 'alpha'))
652 652
                 {
653
-                	if (! empty($backtopage))
653
+                	if (!empty($backtopage))
654 654
                 	{
655 655
                		    header("Location: ".$backtopage);
656 656
                     	exit;
@@ -663,12 +663,12 @@  discard block
 block discarded – undo
663 663
                 }
664 664
 
665 665
                 // To not set code if third party is not concerned. But if it had values, we keep them.
666
-                if (empty($object->client) && empty($object->oldcopy->code_client))          $object->code_client='';
667
-                if (empty($object->fournisseur)&& empty($object->oldcopy->code_fournisseur)) $object->code_fournisseur='';
666
+                if (empty($object->client) && empty($object->oldcopy->code_client))          $object->code_client = '';
667
+                if (empty($object->fournisseur) && empty($object->oldcopy->code_fournisseur)) $object->code_fournisseur = '';
668 668
                 //var_dump($object);exit;
669 669
 
670 670
                 $result = $object->update($socid, $user, 1, $object->oldcopy->codeclient_modifiable(), $object->oldcopy->codefournisseur_modifiable(), 'update', 0);
671
-                if ($result <=  0)
671
+                if ($result <= 0)
672 672
                 {
673 673
                     setEventMessages($object->error, $object->errors, 'errors');
674 674
                     $error++;
@@ -684,10 +684,10 @@  discard block
 block discarded – undo
684 684
 				}
685 685
 
686 686
 				// Prevent thirdparty's emptying if a user hasn't rights $user->rights->categorie->lire (in such a case, post of 'custcats' is not defined)
687
-				if (! $error && !empty($user->rights->categorie->lire))
687
+				if (!$error && !empty($user->rights->categorie->lire))
688 688
 				{
689 689
 					// Customer categories association
690
-					$categories = GETPOST( 'custcats', 'array' );
690
+					$categories = GETPOST('custcats', 'array');
691 691
 					$result = $object->setCategories($categories, 'customer');
692 692
 					if ($result < 0)
693 693
 					{
@@ -710,8 +710,8 @@  discard block
 block discarded – undo
710 710
                 $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
711 711
                 if (GETPOST('deletephoto') && $object->logo)
712 712
                 {
713
-                    $fileimg=$dir.'/'.$object->logo;
714
-                    $dirthumbs=$dir.'/thumbs';
713
+                    $fileimg = $dir.'/'.$object->logo;
714
+                    $dirthumbs = $dir.'/thumbs';
715 715
                     dol_delete_file($fileimg);
716 716
                     dol_delete_dir_recursive($dirthumbs);
717 717
                 }
@@ -723,10 +723,10 @@  discard block
 block discarded – undo
723 723
 
724 724
                         if (@is_dir($dir))
725 725
                         {
726
-                            $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
726
+                            $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
727 727
                             $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
728 728
 
729
-                            if (! $result > 0)
729
+                            if (!$result > 0)
730 730
                             {
731 731
                                 $errors[] = "ErrorFailedToSaveFile";
732 732
                             }
@@ -736,9 +736,9 @@  discard block
 block discarded – undo
736 736
                             	$object->addThumbs($newfile);
737 737
 
738 738
                                 // Index file in database
739
-                                if (! empty($conf->global->THIRDPARTY_LOGO_ALLOW_EXTERNAL_DOWNLOAD))
739
+                                if (!empty($conf->global->THIRDPARTY_LOGO_ALLOW_EXTERNAL_DOWNLOAD))
740 740
                                 {
741
-                                	require_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php';
741
+                                	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
742 742
                                 	// the dir dirname($newfile) is directory of logo, so we should have only one file at once into index, so we delete indexes for the dir
743 743
                                 	deleteFilesIntoDatabaseIndex(dirname($newfile), '', '', 'uploaded', 1);
744 744
                                 	// now we index the uploaded logo file
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
                 }
755 755
                 else
756 756
                 {
757
-					switch($_FILES['photo']['error'])
757
+					switch ($_FILES['photo']['error'])
758 758
 					{
759 759
 					    case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
760 760
 					    case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
@@ -769,12 +769,12 @@  discard block
 block discarded – undo
769 769
 
770 770
 
771 771
                 // Update linked member
772
-                if (! $error && $object->fk_soc > 0)
772
+                if (!$error && $object->fk_soc > 0)
773 773
                 {
774 774
 
775 775
                 	$sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
776
-                	$sql.= " SET fk_soc = NULL WHERE fk_soc = " . $id;
777
-                	if (! $object->db->query($sql))
776
+                	$sql .= " SET fk_soc = NULL WHERE fk_soc = ".$id;
777
+                	if (!$object->db->query($sql))
778 778
                 	{
779 779
                 		$error++;
780 780
                 		$object->error .= $object->db->lasterror();
@@ -782,9 +782,9 @@  discard block
 block discarded – undo
782 782
                 	}
783 783
                 }
784 784
 
785
-                if (! $error && ! count($errors))
785
+                if (!$error && !count($errors))
786 786
                 {
787
-                	if (! empty($backtopage))
787
+                	if (!empty($backtopage))
788 788
                 	{
789 789
                		    header("Location: ".$backtopage);
790 790
                     	exit;
@@ -798,13 +798,13 @@  discard block
 block discarded – undo
798 798
                 else
799 799
                 {
800 800
                     $object->id = $socid;
801
-                    $action= "edit";
801
+                    $action = "edit";
802 802
                 }
803 803
             }
804 804
         }
805 805
         else
806 806
         {
807
-        	$action = ($action=='add'?'create':'edit');
807
+        	$action = ($action == 'add' ? 'create' : 'edit');
808 808
         }
809 809
     }
810 810
 
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
             $langs->load("errors");
825 825
            	setEventMessages($object->error, $object->errors, 'errors');
826 826
            	$error++;
827
-            $action='';
827
+            $action = '';
828 828
         }
829 829
     }
830 830
 
@@ -832,7 +832,7 @@  discard block
 block discarded – undo
832 832
     if ($action == 'set_thirdparty' && $user->rights->societe->creer)
833 833
     {
834 834
     	$object->fetch($socid);
835
-    	$result = $object->set_parent(GETPOST('editparentcompany','int'));
835
+    	$result = $object->set_parent(GETPOST('editparentcompany', 'int'));
836 836
     }
837 837
 
838 838
     // Set incoterm
@@ -842,20 +842,20 @@  discard block
 block discarded – undo
842 842
     	$result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
843 843
     }
844 844
 
845
-    $id=$socid;
845
+    $id = $socid;
846 846
     $object->fetch($socid);
847 847
 
848 848
     // Actions to send emails
849
-    $trigger_name='COMPANY_SENTBYMAIL';
850
-    $paramname='socid';
851
-    $mode='emailfromthirdparty';
852
-    $trackid='thi'.$object->id;
849
+    $trigger_name = 'COMPANY_SENTBYMAIL';
850
+    $paramname = 'socid';
851
+    $mode = 'emailfromthirdparty';
852
+    $trackid = 'thi'.$object->id;
853 853
     include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
854 854
 
855 855
     // Actions to build doc
856 856
     $id = $socid;
857 857
     $upload_dir = $conf->societe->dir_output;
858
-    $permissioncreate=$user->rights->societe->creer;
858
+    $permissioncreate = $user->rights->societe->creer;
859 859
     include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
860 860
 }
861 861
 
@@ -871,24 +871,24 @@  discard block
 block discarded – undo
871 871
 
872 872
 if ($socid > 0 && empty($object->id))
873 873
 {
874
-    $result=$object->fetch($socid);
875
-	if ($result <= 0) dol_print_error('',$object->error);
874
+    $result = $object->fetch($socid);
875
+	if ($result <= 0) dol_print_error('', $object->error);
876 876
 }
877 877
 
878
-$title=$langs->trans("ThirdParty");
879
-if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$langs->trans('Card');
880
-$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
881
-llxHeader('',$title,$help_url);
878
+$title = $langs->trans("ThirdParty");
879
+if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->name." - ".$langs->trans('Card');
880
+$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
881
+llxHeader('', $title, $help_url);
882 882
 
883
-$countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
883
+$countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
884 884
 
885 885
 if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
886 886
 {
887 887
     // -----------------------------------------
888 888
     // When used with CANVAS
889 889
     // -----------------------------------------
890
-   	$objcanvas->assign_values($action, $object->id, $object->ref);	// Set value for templates
891
-    $objcanvas->display_canvas($action);							// Show template
890
+   	$objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
891
+    $objcanvas->display_canvas($action); // Show template
892 892
 }
893 893
 else
894 894
 {
@@ -900,68 +900,68 @@  discard block
 block discarded – undo
900 900
         /*
901 901
          *  Creation
902 902
          */
903
-		$private=GETPOST("private","int");
904
-		if (! empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT) && ! isset($_GET['private']) && ! isset($_POST['private'])) $private=1;
905
-    	if (empty($private)) $private=0;
903
+		$private = GETPOST("private", "int");
904
+		if (!empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT) && !isset($_GET['private']) && !isset($_POST['private'])) $private = 1;
905
+    	if (empty($private)) $private = 0;
906 906
 
907 907
         // Load object modCodeTiers
908
-        $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
908
+        $module = (!empty($conf->global->SOCIETE_CODECLIENT_ADDON) ? $conf->global->SOCIETE_CODECLIENT_ADDON : 'mod_codeclient_leopard');
909 909
         if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
910 910
         {
911
-            $module = substr($module, 0, dol_strlen($module)-4);
911
+            $module = substr($module, 0, dol_strlen($module) - 4);
912 912
         }
913
-        $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
913
+        $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
914 914
         foreach ($dirsociete as $dirroot)
915 915
         {
916
-            $res=dol_include_once($dirroot.$module.'.php');
916
+            $res = dol_include_once($dirroot.$module.'.php');
917 917
             if ($res) break;
918 918
         }
919 919
         $modCodeClient = new $module;
920 920
         // Load object modCodeFournisseur
921
-        $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
921
+        $module = (!empty($conf->global->SOCIETE_CODECLIENT_ADDON) ? $conf->global->SOCIETE_CODECLIENT_ADDON : 'mod_codeclient_leopard');
922 922
         if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
923 923
         {
924
-            $module = substr($module, 0, dol_strlen($module)-4);
924
+            $module = substr($module, 0, dol_strlen($module) - 4);
925 925
         }
926
-        $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
926
+        $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
927 927
         foreach ($dirsociete as $dirroot)
928 928
         {
929
-            $res=dol_include_once($dirroot.$module.'.php');
929
+            $res = dol_include_once($dirroot.$module.'.php');
930 930
             if ($res) break;
931 931
         }
932 932
         $modCodeFournisseur = new $module;
933 933
 
934 934
         // Define if customer/prospect or supplier status is set or not
935
-        if (GETPOST("type")!='f')
935
+        if (GETPOST("type") != 'f')
936 936
         {
937
-            $object->client=-1;
938
-            if (! empty($conf->global->THIRDPARTY_CUSTOMERPROSPECT_BY_DEFAULT))  { $object->client=3; }
937
+            $object->client = -1;
938
+            if (!empty($conf->global->THIRDPARTY_CUSTOMERPROSPECT_BY_DEFAULT)) { $object->client = 3; }
939 939
         }
940
-        if (GETPOST("type")=='c')  { $object->client=3; }   // Prospect / Customer
941
-        if (GETPOST("type")=='p')  { $object->client=2; }
942
-        if (! empty($conf->fournisseur->enabled) && (GETPOST("type")=='f' || (GETPOST("type")=='' && ! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT))))  { $object->fournisseur=1; }
940
+        if (GETPOST("type") == 'c') { $object->client = 3; }   // Prospect / Customer
941
+        if (GETPOST("type") == 'p') { $object->client = 2; }
942
+        if (!empty($conf->fournisseur->enabled) && (GETPOST("type") == 'f' || (GETPOST("type") == '' && !empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)))) { $object->fournisseur = 1; }
943 943
 
944
-        $object->name				= GETPOST('name', 'alpha');
945
-        $object->firstname			= GETPOST('firstname', 'alpha');
944
+        $object->name = GETPOST('name', 'alpha');
945
+        $object->firstname = GETPOST('firstname', 'alpha');
946 946
         $object->particulier		= $private;
947 947
         $object->prefix_comm		= GETPOST('prefix_comm');
948
-        $object->client				= GETPOST('client')?GETPOST('client'):$object->client;
948
+        $object->client = GETPOST('client') ?GETPOST('client') : $object->client;
949 949
 
950
-        if(empty($duplicate_code_error)) {
950
+        if (empty($duplicate_code_error)) {
951 951
 	        $object->code_client		= GETPOST('customer_code', 'alpha');
952
-	        $object->fournisseur		= GETPOST('fournisseur')?GETPOST('fournisseur'):$object->fournisseur;
952
+	        $object->fournisseur		= GETPOST('fournisseur') ?GETPOST('fournisseur') : $object->fournisseur;
953 953
         }
954 954
 		else {
955
-			setEventMessages($langs->trans('NewCustomerSupplierCodeProposed'),'', 'warnings');
955
+			setEventMessages($langs->trans('NewCustomerSupplierCodeProposed'), '', 'warnings');
956 956
 		}
957 957
 
958
-        $object->code_fournisseur	= GETPOST('supplier_code', 'alpha');
959
-        $object->address			= GETPOST('address', 'alpha');
960
-        $object->zip				= GETPOST('zipcode', 'alpha');
961
-        $object->town				= GETPOST('town', 'alpha');
958
+        $object->code_fournisseur = GETPOST('supplier_code', 'alpha');
959
+        $object->address = GETPOST('address', 'alpha');
960
+        $object->zip = GETPOST('zipcode', 'alpha');
961
+        $object->town = GETPOST('town', 'alpha');
962 962
         $object->state_id			= GETPOST('state_id', 'int');
963 963
         $object->skype				= GETPOST('skype', 'alpha');
964
-        $object->twitter			= GETPOST('twitter', 'alpha');
964
+        $object->twitter = GETPOST('twitter', 'alpha');
965 965
         $object->facebook			= GETPOST('facebook', 'alpha');
966 966
         $object->phone				= GETPOST('phone', 'alpha');
967 967
         $object->fax				= GETPOST('fax', 'alpha');
@@ -975,30 +975,30 @@  discard block
 block discarded – undo
975 975
         $object->idprof4			= GETPOST('idprof4', 'alpha');
976 976
         $object->idprof5			= GETPOST('idprof5', 'alpha');
977 977
         $object->idprof6			= GETPOST('idprof6', 'alpha');
978
-        $object->typent_id			= GETPOST('typent_id', 'int');
978
+        $object->typent_id = GETPOST('typent_id', 'int');
979 979
         $object->effectif_id		= GETPOST('effectif_id', 'int');
980 980
         $object->civility_id		= GETPOST('civility_id', 'int');
981 981
 
982
-        $object->tva_assuj			= GETPOST('assujtva_value', 'int');
983
-        $object->status				= GETPOST('status', 'int');
982
+        $object->tva_assuj = GETPOST('assujtva_value', 'int');
983
+        $object->status = GETPOST('status', 'int');
984 984
 
985 985
         //Local Taxes
986 986
         $object->localtax1_assuj	= GETPOST('localtax1assuj_value', 'int');
987 987
         $object->localtax2_assuj	= GETPOST('localtax2assuj_value', 'int');
988 988
 
989
-        $object->localtax1_value	=GETPOST('lt1', 'int');
990
-        $object->localtax2_value	=GETPOST('lt2', 'int');
989
+        $object->localtax1_value	= GETPOST('lt1', 'int');
990
+        $object->localtax2_value	= GETPOST('lt2', 'int');
991 991
 
992
-        $object->tva_intra			= GETPOST('tva_intra', 'alpha');
992
+        $object->tva_intra = GETPOST('tva_intra', 'alpha');
993 993
 
994
-        $object->commercial_id		= GETPOST('commercial_id', 'int');
995
-        $object->default_lang		= GETPOST('default_lang');
994
+        $object->commercial_id = GETPOST('commercial_id', 'int');
995
+        $object->default_lang = GETPOST('default_lang');
996 996
 
997
-        $object->logo = (isset($_FILES['photo'])?dol_sanitizeFileName($_FILES['photo']['name']):'');
997
+        $object->logo = (isset($_FILES['photo']) ?dol_sanitizeFileName($_FILES['photo']['name']) : '');
998 998
 
999 999
         // Gestion du logo de la société
1000 1000
         $dir     = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos";
1001
-        $file_OK = (isset($_FILES['photo'])?is_uploaded_file($_FILES['photo']['tmp_name']):false);
1001
+        $file_OK = (isset($_FILES['photo']) ?is_uploaded_file($_FILES['photo']['tmp_name']) : false);
1002 1002
         if ($file_OK)
1003 1003
         {
1004 1004
             if (image_format_supported($_FILES['photo']['name']))
@@ -1007,10 +1007,10 @@  discard block
 block discarded – undo
1007 1007
 
1008 1008
                 if (@is_dir($dir))
1009 1009
                 {
1010
-                    $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
1010
+                    $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
1011 1011
                     $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
1012 1012
 
1013
-                    if (! $result > 0)
1013
+                    if (!$result > 0)
1014 1014
                     {
1015 1015
                         $errors[] = "ErrorFailedToSaveFile";
1016 1016
                     }
@@ -1024,20 +1024,20 @@  discard block
 block discarded – undo
1024 1024
         }
1025 1025
 
1026 1026
         // We set country_id, country_code and country for the selected country
1027
-        $object->country_id=GETPOST('country_id')?GETPOST('country_id'):$mysoc->country_id;
1027
+        $object->country_id = GETPOST('country_id') ?GETPOST('country_id') : $mysoc->country_id;
1028 1028
         if ($object->country_id)
1029 1029
         {
1030
-            $tmparray=getCountry($object->country_id,'all');
1031
-            $object->country_code=$tmparray['code'];
1032
-            $object->country=$tmparray['label'];
1030
+            $tmparray = getCountry($object->country_id, 'all');
1031
+            $object->country_code = $tmparray['code'];
1032
+            $object->country = $tmparray['label'];
1033 1033
         }
1034
-        $object->forme_juridique_code=GETPOST('forme_juridique_code');
1034
+        $object->forme_juridique_code = GETPOST('forme_juridique_code');
1035 1035
         /* Show create form */
1036 1036
 
1037
-        $linkback="";
1038
-        print load_fiche_titre($langs->trans("NewThirdParty"),$linkback,'title_companies.png');
1037
+        $linkback = "";
1038
+        print load_fiche_titre($langs->trans("NewThirdParty"), $linkback, 'title_companies.png');
1039 1039
 
1040
-        if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION))
1040
+        if (!empty($conf->use_javascript_ajax) && !empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION))
1041 1041
         {
1042 1042
             print "\n".'<script type="text/javascript">';
1043 1043
             print '$(document).ready(function () {
@@ -1070,7 +1070,7 @@  discard block
 block discarded – undo
1070 1070
 						});
1071 1071
 						function init_customer_categ() {
1072 1072
 								console.log("is customer or prospect = "+jQuery("#customerprospect").val());
1073
-								if (jQuery("#customerprospect").val() == 0 && (jQuery("#fournisseur").val() == 0 || '.(empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER)?'1':'0').'))
1073
+								if (jQuery("#customerprospect").val() == 0 && (jQuery("#fournisseur").val() == 0 || '.(empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER) ? '1' : '0').'))
1074 1074
 								{
1075 1075
 									jQuery(".visibleifcustomer").hide();
1076 1076
 								}
@@ -1108,31 +1108,31 @@  discard block
 block discarded – undo
1108 1108
             print $langs->trans("ThirdPartyType").': &nbsp; &nbsp; ';
1109 1109
             print '</div>';
1110 1110
 	        print '<label for="radiocompany" class="radiocompany">';
1111
-            print '<input type="radio" id="radiocompany" class="flat" name="private"  value="0"'.($private?'':' checked').'>';
1111
+            print '<input type="radio" id="radiocompany" class="flat" name="private"  value="0"'.($private ? '' : ' checked').'>';
1112 1112
 	        print '&nbsp;';
1113 1113
             print $langs->trans("CreateThirdPartyOnly");
1114 1114
 	        print '</label>';
1115 1115
             print ' &nbsp; &nbsp; ';
1116 1116
 	        print '<label for="radioprivate" class="radioprivate">';
1117
-            $text ='<input type="radio" id="radioprivate" class="flat" name="private" value="1"'.($private?' checked':'').'>';
1118
-	        $text.='&nbsp;';
1119
-	        $text.= $langs->trans("CreateThirdPartyAndContact");
1120
-	        $htmltext=$langs->trans("ToCreateContactWithSameName");
1117
+            $text = '<input type="radio" id="radioprivate" class="flat" name="private" value="1"'.($private ? ' checked' : '').'>';
1118
+	        $text .= '&nbsp;';
1119
+	        $text .= $langs->trans("CreateThirdPartyAndContact");
1120
+	        $htmltext = $langs->trans("ToCreateContactWithSameName");
1121 1121
 	        print $form->textwithpicto($text, $htmltext, 1, 'help', '', 0, 3);
1122 1122
             print '</label>';
1123 1123
             print '</div>';
1124 1124
             print "<br>\n";
1125 1125
         }
1126 1126
 
1127
-        dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error');
1127
+        dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
1128 1128
 
1129
-        print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc" autocomplete="off">';		// Chrome ignor autocomplete
1129
+        print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc" autocomplete="off">'; // Chrome ignor autocomplete
1130 1130
 
1131 1131
         print '<input type="hidden" name="action" value="add">';
1132 1132
         print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1133 1133
         print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1134 1134
         print '<input type="hidden" name="private" value='.$object->particulier.'>';
1135
-        print '<input type="hidden" name="type" value='.GETPOST("type",'alpha').'>';
1135
+        print '<input type="hidden" name="type" value='.GETPOST("type", 'alpha').'>';
1136 1136
         print '<input type="hidden" name="LastName" value="'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName').'">';
1137 1137
         print '<input type="hidden" name="ThirdPartyName" value="'.$langs->trans('ThirdPartyName').'">';
1138 1138
         if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) print '<input type="hidden" name="code_auto" value="1">';
@@ -1145,15 +1145,15 @@  discard block
 block discarded – undo
1145 1145
 	    print '<tr><td class="titlefieldcreate">';
1146 1146
         if ($object->particulier || $private)
1147 1147
         {
1148
-	        print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName','name').'</span>';
1148
+	        print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName', 'name').'</span>';
1149 1149
         }
1150 1150
         else
1151 1151
 		{
1152 1152
 			print '<span id="TypeName" class="fieldrequired">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0).'</span>';
1153 1153
         }
1154
-	    print '</td><td'.(empty($conf->global->SOCIETE_USEPREFIX)?' colspan="3"':'').'>';
1154
+	    print '</td><td'.(empty($conf->global->SOCIETE_USEPREFIX) ? ' colspan="3"' : '').'>';
1155 1155
 	    print '<input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.$object->name.'" autofocus="autofocus"></td>';
1156
-	    if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1156
+	    if (!empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1157 1157
 	    {
1158 1158
 		    print '<td>'.$langs->trans('Prefix').'</td><td><input type="text" size="5" maxlength="5" name="prefix_comm" value="'.$object->prefix_comm.'"></td>';
1159 1159
 	    }
@@ -1178,51 +1178,51 @@  discard block
 block discarded – undo
1178 1178
         // Prospect/Customer
1179 1179
         print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).'</td>';
1180 1180
 	    print '<td class="maxwidthonsmartphone">';
1181
-	    $selected=GETPOST('client','int')!=''?GETPOST('client','int'):$object->client;
1181
+	    $selected = GETPOST('client', 'int') != '' ?GETPOST('client', 'int') : $object->client;
1182 1182
         print '<select class="flat" name="client" id="customerprospect">';
1183 1183
         if (GETPOST("type") == '') print '<option value="-1">&nbsp;</option>';
1184
-        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($selected==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1185
-        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) print '<option value="3"'.($selected==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1186
-        if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($selected==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1187
-        print '<option value="0"'.((string) $selected == '0'?' selected':'').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1184
+        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($selected == 2 ? ' selected' : '').'>'.$langs->trans('Prospect').'</option>';
1185
+        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) print '<option value="3"'.($selected == 3 ? ' selected' : '').'>'.$langs->trans('ProspectCustomer').'</option>';
1186
+        if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($selected == 1 ? ' selected' : '').'>'.$langs->trans('Customer').'</option>';
1187
+        print '<option value="0"'.((string) $selected == '0' ? ' selected' : '').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1188 1188
         print '</select></td>';
1189 1189
 
1190 1190
         print '<td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
1191 1191
         print '<table class="nobordernopadding"><tr><td>';
1192
-		$tmpcode=$object->code_client;
1193
-        if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object,0);
1192
+		$tmpcode = $object->code_client;
1193
+        if (empty($tmpcode) && !empty($modCodeClient->code_auto)) $tmpcode = $modCodeClient->getNextValue($object, 0);
1194 1194
         print '<input type="text" name="customer_code" id="customer_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1195 1195
         print '</td><td>';
1196
-        $s=$modCodeClient->getToolTip($langs,$object,0);
1197
-        print $form->textwithpicto('',$s,1);
1196
+        $s = $modCodeClient->getToolTip($langs, $object, 0);
1197
+        print $form->textwithpicto('', $s, 1);
1198 1198
         print '</td></tr></table>';
1199 1199
         print '</td></tr>';
1200 1200
 
1201
-        if ((! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1202
-        	|| (! empty($conf->supplier_proposal->enabled) && ! empty($user->rights->supplier_proposal->lire)))
1201
+        if ((!empty($conf->fournisseur->enabled) && !empty($user->rights->fournisseur->lire))
1202
+        	|| (!empty($conf->supplier_proposal->enabled) && !empty($user->rights->supplier_proposal->lire)))
1203 1203
         {
1204 1204
             // Supplier
1205 1205
             print '<tr>';
1206 1206
             print '<td>'.$form->editfieldkey('Supplier', 'fournisseur', '', $object, 0, 'string', '', 1).'</td><td>';
1207 1207
             $default = -1;
1208
-            if (! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)) $default=1;
1209
-            print $form->selectyesno("fournisseur", (GETPOST('fournisseur','int')!=''?GETPOST('fournisseur','int'):(GETPOST("type",'alpha') == '' ? $default : $object->fournisseur)), 1, 0, (GETPOST("type",'alpha') == '' ? 1 : 0));
1208
+            if (!empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)) $default = 1;
1209
+            print $form->selectyesno("fournisseur", (GETPOST('fournisseur', 'int') != '' ?GETPOST('fournisseur', 'int') : (GETPOST("type", 'alpha') == '' ? $default : $object->fournisseur)), 1, 0, (GETPOST("type", 'alpha') == '' ? 1 : 0));
1210 1210
             print '</td>';
1211 1211
             print '<td>';
1212
-            if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1212
+            if (!empty($conf->fournisseur->enabled) && !empty($user->rights->fournisseur->lire))
1213 1213
             {
1214 1214
             	print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0);
1215 1215
             }
1216 1216
             print '</td><td>';
1217
-            if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1217
+            if (!empty($conf->fournisseur->enabled) && !empty($user->rights->fournisseur->lire))
1218 1218
             {
1219 1219
 	            print '<table class="nobordernopadding"><tr><td>';
1220
-	            $tmpcode=$object->code_fournisseur;
1221
-	            if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1220
+	            $tmpcode = $object->code_fournisseur;
1221
+	            if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) $tmpcode = $modCodeFournisseur->getNextValue($object, 1);
1222 1222
 	            print '<input type="text" name="supplier_code" id="supplier_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1223 1223
 	            print '</td><td>';
1224
-	            $s=$modCodeFournisseur->getToolTip($langs,$object,1);
1225
-	            print $form->textwithpicto('',$s,1);
1224
+	            $s = $modCodeFournisseur->getToolTip($langs, $object, 1);
1225
+	            print $form->textwithpicto('', $s, 1);
1226 1226
 	            print '</td></tr></table>';
1227 1227
             }
1228 1228
             print '</td></tr>';
@@ -1230,11 +1230,11 @@  discard block
 block discarded – undo
1230 1230
 
1231 1231
         // Status
1232 1232
         print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0).'</td><td colspan="3">';
1233
-        print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'),'1'=>$langs->trans('InActivity')),1);
1233
+        print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), 1);
1234 1234
         print '</td></tr>';
1235 1235
 
1236 1236
         // Barcode
1237
-        if (! empty($conf->barcode->enabled))
1237
+        if (!empty($conf->barcode->enabled))
1238 1238
         {
1239 1239
             print '<tr><td>'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).'</td>';
1240 1240
 	        print '<td colspan="3"><input type="text" name="barcode" id="barcode" value="'.$object->barcode.'">';
@@ -1249,21 +1249,21 @@  discard block
 block discarded – undo
1249 1249
 
1250 1250
         // Zip / Town
1251 1251
         print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td>';
1252
-        print $formcompany->select_ziptown($object->zip,'zipcode',array('town','selectcountry_id','state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent');
1252
+        print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent');
1253 1253
         print '</td><td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td>';
1254
-        print $formcompany->select_ziptown($object->town,'town',array('zipcode','selectcountry_id','state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent');
1254
+        print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent');
1255 1255
         print '</td></tr>';
1256 1256
 
1257 1257
         // Country
1258 1258
         print '<tr><td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1259
-        print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id));
1260
-        if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1259
+        print $form->select_country((GETPOST('country_id') != '' ?GETPOST('country_id') : $object->country_id));
1260
+        if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1261 1261
         print '</td></tr>';
1262 1262
 
1263 1263
         // State
1264 1264
         if (empty($conf->global->SOCIETE_DISABLE_STATE))
1265 1265
         {
1266
-            if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1266
+            if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1267 1267
             {
1268 1268
                 print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1269 1269
             }
@@ -1272,7 +1272,7 @@  discard block
 block discarded – undo
1272 1272
                 print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1273 1273
             }
1274 1274
 
1275
-            if ($object->country_id) print $formcompany->select_state($object->state_id,$object->country_code);
1275
+            if ($object->country_id) print $formcompany->select_state($object->state_id, $object->country_code);
1276 1276
             else print $countrynotdefined;
1277 1277
             print '</td></tr>';
1278 1278
         }
@@ -1283,30 +1283,30 @@  discard block
 block discarded – undo
1283 1283
         print '<tr><td>'.$form->editfieldkey('Web', 'url', '', $object, 0).'</td>';
1284 1284
 	    print '<td colspan="3"><input type="text" name="url" id="url" value="'.$object->url.'"></td></tr>';
1285 1285
 
1286
-        if (! empty($conf->socialnetworks->enabled))
1286
+        if (!empty($conf->socialnetworks->enabled))
1287 1287
         {
1288 1288
         	// Skype
1289
-        	if (! empty($conf->global->SOCIALNETWORKS_SKYPE))
1289
+        	if (!empty($conf->global->SOCIALNETWORKS_SKYPE))
1290 1290
         	{
1291 1291
         		print '<tr><td>'.$form->editfieldkey('Skype', 'skype', '', $object, 0).'</td>';
1292 1292
 				print '<td colspan="3">';
1293
-				print '<input type="text" name="skype" class="minwidth100" maxlength="80" id="skype" value="'.dol_escape_htmltag(GETPOSTISSET("skype")?GETPOST("skype",'alpha'):$object->skype).'">';
1293
+				print '<input type="text" name="skype" class="minwidth100" maxlength="80" id="skype" value="'.dol_escape_htmltag(GETPOSTISSET("skype") ?GETPOST("skype", 'alpha') : $object->skype).'">';
1294 1294
 				print '</td></tr>';
1295 1295
         	}
1296 1296
         	// Twitter
1297
-        	if (! empty($conf->global->SOCIALNETWORKS_TWITTER))
1297
+        	if (!empty($conf->global->SOCIALNETWORKS_TWITTER))
1298 1298
         	{
1299 1299
         		print '<tr><td>'.$form->editfieldkey('Twitter', 'twitter', '', $object, 0).'</td>';
1300 1300
 				print '<td colspan="3">';
1301
-				print '<input type="text" name="twitter" class="minwidth100" maxlength="80" id="twitter" value="'.dol_escape_htmltag(GETPOSTISSET("twitter")?GETPOST("twitter",'alpha'):$object->twitter).'">';
1301
+				print '<input type="text" name="twitter" class="minwidth100" maxlength="80" id="twitter" value="'.dol_escape_htmltag(GETPOSTISSET("twitter") ?GETPOST("twitter", 'alpha') : $object->twitter).'">';
1302 1302
 				print '</td></tr>';
1303 1303
         	}
1304 1304
         	// Facebook
1305
-        	if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK))
1305
+        	if (!empty($conf->global->SOCIALNETWORKS_FACEBOOK))
1306 1306
         	{
1307 1307
 	        	print '<tr><td>'.$form->editfieldkey('Facebook', 'facebook', '', $object, 0).'</td>';
1308 1308
 				print '<td colspan="3">';
1309
-				print '<input type="text" name="facebook" class="minwidth100" maxlength="80" id="facebook" value="'.dol_escape_htmltag(GETPOSTISSET("facebook")?GETPOST("facebook",'alpha'):$object->facebook).'">';
1309
+				print '<input type="text" name="facebook" class="minwidth100" maxlength="80" id="facebook" value="'.dol_escape_htmltag(GETPOSTISSET("facebook") ?GETPOST("facebook", 'alpha') : $object->facebook).'">';
1310 1310
 				print '</td></tr>';
1311 1311
         	}
1312 1312
         }
@@ -1318,18 +1318,18 @@  discard block
 block discarded – undo
1318 1318
 	    print '<td><input type="text" name="fax" id="fax" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->fax.'"></td></tr>';
1319 1319
 
1320 1320
         // Prof ids
1321
-        $i=1; $j=0;
1321
+        $i = 1; $j = 0;
1322 1322
         while ($i <= 6)
1323 1323
         {
1324
-            $idprof=$langs->transcountry('ProfId'.$i,$object->country_code);
1325
-            if ($idprof!='-')
1324
+            $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
1325
+            if ($idprof != '-')
1326 1326
             {
1327
-	            $key='idprof'.$i;
1327
+	            $key = 'idprof'.$i;
1328 1328
 
1329 1329
                 if (($j % 2) == 0) print '<tr>';
1330 1330
 
1331
-                $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
1332
-                print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', (empty($conf->global->$idprof_mandatory)?0:1)).'</td><td>';
1331
+                $idprof_mandatory = 'SOCIETE_IDPROF'.($i).'_MANDATORY';
1332
+                print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', (empty($conf->global->$idprof_mandatory) ? 0 : 1)).'</td><td>';
1333 1333
 
1334 1334
                 print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
1335 1335
                 print '</td>';
@@ -1343,7 +1343,7 @@  discard block
 block discarded – undo
1343 1343
         // Vat is used
1344 1344
         print '<tr><td>'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).'</td>';
1345 1345
         print '<td>';
1346
-        print $form->selectyesno('assujtva_value', GETPOSTISSET('assujtva_value')?GETPOST('assujtva_value','int'):1, 1);     // Assujeti par defaut en creation
1346
+        print $form->selectyesno('assujtva_value', GETPOSTISSET('assujtva_value') ?GETPOST('assujtva_value', 'int') : 1, 1); // Assujeti par defaut en creation
1347 1347
         print '</td>';
1348 1348
         print '<td class="nowrap">'.$form->editfieldkey('VATIntra', 'intra_vat', '', $object, 0).'</td>';
1349 1349
         print '<td class="nowrap">';
@@ -1351,9 +1351,9 @@  discard block
 block discarded – undo
1351 1351
 
1352 1352
         if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object))
1353 1353
         {
1354
-            $s.=' ';
1354
+            $s .= ' ';
1355 1355
 
1356
-            if (! empty($conf->use_javascript_ajax))
1356
+            if (!empty($conf->use_javascript_ajax))
1357 1357
             {
1358 1358
                 print "\n";
1359 1359
                 print '<script language="JavaScript" type="text/javascript">';
@@ -1362,12 +1362,12 @@  discard block
 block discarded – undo
1362 1362
                 print "}\n";
1363 1363
                 print '</script>';
1364 1364
                 print "\n";
1365
-                $s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
1366
-                $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
1365
+                $s .= '<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
1366
+                $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->trans("VATIntraCheck")), 1);
1367 1367
             }
1368 1368
             else
1369 1369
             {
1370
-                $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
1370
+                $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", $object->country_id).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
1371 1371
             }
1372 1372
         }
1373 1373
         print $s;
@@ -1376,36 +1376,36 @@  discard block
 block discarded – undo
1376 1376
 
1377 1377
         // Local Taxes
1378 1378
         //TODO: Place into a function to control showing by country or study better option
1379
-        if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
1379
+        if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1")
1380 1380
         {
1381
-            print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
1382
-            print $form->selectyesno('localtax1assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1:0),1);
1383
-            print '</td><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
1384
-            print $form->selectyesno('localtax2assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0),1);
1381
+            print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
1382
+            print $form->selectyesno('localtax1assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1 : 0), 1);
1383
+            print '</td><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
1384
+            print $form->selectyesno('localtax2assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2 : 0), 1);
1385 1385
             print '</td></tr>';
1386 1386
         }
1387
-        elseif($mysoc->localtax1_assuj=="1")
1387
+        elseif ($mysoc->localtax1_assuj == "1")
1388 1388
         {
1389
-            print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td colspan="3">';
1390
-            print $form->selectyesno('localtax1assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1:0),1);
1389
+            print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td colspan="3">';
1390
+            print $form->selectyesno('localtax1assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1 : 0), 1);
1391 1391
             print '</td></tr>';
1392 1392
         }
1393
-        elseif($mysoc->localtax2_assuj=="1")
1393
+        elseif ($mysoc->localtax2_assuj == "1")
1394 1394
         {
1395
-            print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td colspan="3">';
1396
-            print $form->selectyesno('localtax2assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0),1);
1395
+            print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td colspan="3">';
1396
+            print $form->selectyesno('localtax2assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2 : 0), 1);
1397 1397
             print '</td></tr>';
1398 1398
         }
1399 1399
 
1400 1400
         // Type - Size
1401 1401
         print '<tr><td>'.$form->editfieldkey('ThirdPartyType', 'typent_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">'."\n";
1402
-        $sortparam=(empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT); // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on label.
1402
+        $sortparam = (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT); // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on label.
1403 1403
         print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, $sortparam);
1404
-        if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1404
+        if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1405 1405
         print '</td>';
1406 1406
         print '<td>'.$form->editfieldkey('Staff', 'effectif_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
1407 1407
         print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id);
1408
-        if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1408
+        if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1409 1409
         print '</td></tr>';
1410 1410
 
1411 1411
         // Legal Form
@@ -1426,10 +1426,10 @@  discard block
 block discarded – undo
1426 1426
 	    print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="'.$object->capital.'"> ';
1427 1427
         print '<span class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
1428 1428
 
1429
-        if (! empty($conf->global->MAIN_MULTILANGS))
1429
+        if (!empty($conf->global->MAIN_MULTILANGS))
1430 1430
         {
1431 1431
             print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
1432
-            print $formadmin->select_language(($object->default_lang?$object->default_lang:$conf->global->MAIN_LANG_DEFAULT),'default_lang',0,0,1,0,0,'maxwidth200onsmartphone');
1432
+            print $formadmin->select_language(($object->default_lang ? $object->default_lang : $conf->global->MAIN_LANG_DEFAULT), 'default_lang', 0, 0, 1, 0, 0, 'maxwidth200onsmartphone');
1433 1433
             print '</td>';
1434 1434
             print '</tr>';
1435 1435
         }
@@ -1440,18 +1440,18 @@  discard block
 block discarded – undo
1440 1440
 			print '<tr>';
1441 1441
 			print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
1442 1442
 	        print '<td colspan="3" class="maxwidthonsmartphone">';
1443
-	        print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
1443
+	        print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
1444 1444
 			print '</td></tr>';
1445 1445
 		}
1446 1446
 
1447 1447
 		// Categories
1448
-		if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
1448
+		if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire))
1449 1449
 		{
1450 1450
 			$langs->load('categories');
1451 1451
 
1452 1452
 			// Customer
1453 1453
 			//if ($object->prospect || $object->client || (! $object->fournisseur && ! empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER))) {
1454
-			print '<tr class="visibleifcustomer"><td class="toptd">' . $form->editfieldkey('CustomersProspectsCategoriesShort', 'custcats', '', $object, 0) . '</td><td colspan="3">';
1454
+			print '<tr class="visibleifcustomer"><td class="toptd">'.$form->editfieldkey('CustomersProspectsCategoriesShort', 'custcats', '', $object, 0).'</td><td colspan="3">';
1455 1455
 			$cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, 'parent', null, null, 1);
1456 1456
 			print $form->multiselectarray('custcats', $cate_arbo, GETPOST('custcats', 'array'), null, null, null, null, "90%");
1457 1457
 			print "</td></tr>";
@@ -1459,7 +1459,7 @@  discard block
 block discarded – undo
1459 1459
 
1460 1460
 			// Supplier
1461 1461
 			//if ($object->fournisseur) {
1462
-			print '<tr class="visibleifsupplier"><td class="toptd">' . $form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0) . '</td><td colspan="3">';
1462
+			print '<tr class="visibleifsupplier"><td class="toptd">'.$form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0).'</td><td colspan="3">';
1463 1463
 			$cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, 'parent', null, null, 1);
1464 1464
 			print $form->multiselectarray('suppcats', $cate_arbo, GETPOST('suppcats', 'array'), null, null, null, null, "90%");
1465 1465
 			print "</td></tr>";
@@ -1467,7 +1467,7 @@  discard block
 block discarded – undo
1467 1467
 		}
1468 1468
 
1469 1469
 		// Multicurrency
1470
-		if (! empty($conf->multicurrency->enabled))
1470
+		if (!empty($conf->multicurrency->enabled))
1471 1471
 		{
1472 1472
 			print '<tr>';
1473 1473
 			print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
@@ -1477,12 +1477,12 @@  discard block
 block discarded – undo
1477 1477
 		}
1478 1478
 
1479 1479
         // Other attributes
1480
-        $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
1481
-        $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
1480
+        $parameters = array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
1481
+        $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1482 1482
         print $hookmanager->resPrint;
1483 1483
         if (empty($reshook))
1484 1484
         {
1485
-        	print $object->showOptionals($extrafields,'edit');
1485
+        	print $object->showOptionals($extrafields, 'edit');
1486 1486
         }
1487 1487
 
1488 1488
 		// Assign a sale representative
@@ -1491,7 +1491,7 @@  discard block
 block discarded – undo
1491 1491
 		print '<td colspan="3" class="maxwidthonsmartphone">';
1492 1492
 		$userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, '', 0, '', '', 0, 1);
1493 1493
 		// Note: If user has no right to "see all thirdparties", we for selection of sale representative to him, so after creation he can see the record.
1494
-		print $form->multiselectarray('commercial', $userlist, (count(GETPOST('commercial', 'array')) > 0?GETPOST('commercial', 'array'):(empty($user->rights->societe->client->voir)?array($user->id):array())), null, null, null, null, "90%");
1494
+		print $form->multiselectarray('commercial', $userlist, (count(GETPOST('commercial', 'array')) > 0 ?GETPOST('commercial', 'array') : (empty($user->rights->societe->client->voir) ? array($user->id) : array())), null, null, null, null, "90%");
1495 1495
 		print '</td></tr>';
1496 1496
 
1497 1497
         // Ajout du logo
@@ -1508,7 +1508,7 @@  discard block
 block discarded – undo
1508 1508
 
1509 1509
         print '<div class="center">';
1510 1510
         print '<input type="submit" class="button" name="create" value="'.$langs->trans('AddThirdParty').'">';
1511
-        if (! empty($backtopage))
1511
+        if (!empty($backtopage))
1512 1512
         {
1513 1513
             print ' &nbsp; &nbsp; ';
1514 1514
             print '<input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'">';
@@ -1516,7 +1516,7 @@  discard block
 block discarded – undo
1516 1516
         else
1517 1517
         {
1518 1518
             print ' &nbsp; &nbsp; ';
1519
-            print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
1519
+            print '<input type="button" class="button" value="'.$langs->trans("Cancel").'" onClick="javascript:history.go(-1)">';
1520 1520
         }
1521 1521
         print '</div>'."\n";
1522 1522
 
@@ -1528,21 +1528,21 @@  discard block
 block discarded – undo
1528 1528
 
1529 1529
         if ($socid)
1530 1530
         {
1531
-        	$res=$object->fetch_optionals();
1531
+        	$res = $object->fetch_optionals();
1532 1532
             //if ($res < 0) { dol_print_error($db); exit; }
1533 1533
 
1534 1534
 	        $head = societe_prepare_head($object);
1535 1535
 
1536 1536
             // Load object modCodeTiers
1537
-            $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
1537
+            $module = (!empty($conf->global->SOCIETE_CODECLIENT_ADDON) ? $conf->global->SOCIETE_CODECLIENT_ADDON : 'mod_codeclient_leopard');
1538 1538
             if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
1539 1539
             {
1540
-                $module = substr($module, 0, dol_strlen($module)-4);
1540
+                $module = substr($module, 0, dol_strlen($module) - 4);
1541 1541
             }
1542
-            $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
1542
+            $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
1543 1543
             foreach ($dirsociete as $dirroot)
1544 1544
             {
1545
-                $res=dol_include_once($dirroot.$module.'.php');
1545
+                $res = dol_include_once($dirroot.$module.'.php');
1546 1546
                 if ($res) break;
1547 1547
             }
1548 1548
             $modCodeClient = new $module($db);
@@ -1551,15 +1551,15 @@  discard block
 block discarded – undo
1551 1551
             {
1552 1552
                 $prefixCustomerIsUsed = $modCodeClient->verif_prefixIsUsed();
1553 1553
             }
1554
-            $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
1554
+            $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
1555 1555
             if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
1556 1556
             {
1557
-                $module = substr($module, 0, dol_strlen($module)-4);
1557
+                $module = substr($module, 0, dol_strlen($module) - 4);
1558 1558
             }
1559
-            $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
1559
+            $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
1560 1560
             foreach ($dirsociete as $dirroot)
1561 1561
             {
1562
-                $res=dol_include_once($dirroot.$module.'.php');
1562
+                $res = dol_include_once($dirroot.$module.'.php');
1563 1563
                 if ($res) break;
1564 1564
             }
1565 1565
             $modCodeFournisseur = new $module($db);
@@ -1574,19 +1574,19 @@  discard block
 block discarded – undo
1574 1574
             if (GETPOSTISSET('name'))
1575 1575
             {
1576 1576
                 // We overwrite with values if posted
1577
-                $object->name					= GETPOST('name', 'alpha');
1577
+                $object->name = GETPOST('name', 'alpha');
1578 1578
                 $object->prefix_comm			= GETPOST('prefix_comm', 'alpha');
1579
-                $object->client					= GETPOST('client', 'int');
1579
+                $object->client = GETPOST('client', 'int');
1580 1580
                 $object->code_client			= GETPOST('customer_code', 'alpha');
1581 1581
                 $object->fournisseur			= GETPOST('fournisseur', 'int');
1582
-                $object->code_fournisseur		= GETPOST('supplier_code', 'alpha');
1583
-                $object->address				= GETPOST('address', 'alpha');
1584
-                $object->zip					= GETPOST('zipcode', 'alpha');
1585
-                $object->town					= GETPOST('town', 'alpha');
1586
-                $object->country_id				= GETPOST('country_id')?GETPOST('country_id', 'int'):$mysoc->country_id;
1582
+                $object->code_fournisseur = GETPOST('supplier_code', 'alpha');
1583
+                $object->address = GETPOST('address', 'alpha');
1584
+                $object->zip = GETPOST('zipcode', 'alpha');
1585
+                $object->town = GETPOST('town', 'alpha');
1586
+                $object->country_id = GETPOST('country_id') ?GETPOST('country_id', 'int') : $mysoc->country_id;
1587 1587
                 $object->state_id				= GETPOST('state_id', 'int');
1588 1588
                 $object->skype					= GETPOST('skype', 'alpha');
1589
-                $object->twitter				= GETPOST('twitter', 'alpha');
1589
+                $object->twitter = GETPOST('twitter', 'alpha');
1590 1590
                 $object->facebook				= GETPOST('facebook', 'alpha');
1591 1591
                 $object->phone					= GETPOST('phone', 'alpha');
1592 1592
                 $object->fax					= GETPOST('fax', 'alpha');
@@ -1599,15 +1599,15 @@  discard block
 block discarded – undo
1599 1599
                 $object->idprof4				= GETPOST('idprof4', 'alpha');
1600 1600
                 $object->idprof5				= GETPOST('idprof5', 'alpha');
1601 1601
                 $object->idprof6				= GETPOST('idprof6', 'alpha');
1602
-                $object->typent_id				= GETPOST('typent_id', 'int');
1603
-                $object->effectif_id			= GETPOST('effectif_id', 'int');
1602
+                $object->typent_id = GETPOST('typent_id', 'int');
1603
+                $object->effectif_id = GETPOST('effectif_id', 'int');
1604 1604
                 $object->barcode				= GETPOST('barcode', 'alpha');
1605
-                $object->forme_juridique_code	= GETPOST('forme_juridique_code', 'int');
1606
-                $object->default_lang			= GETPOST('default_lang', 'alpha');
1605
+                $object->forme_juridique_code = GETPOST('forme_juridique_code', 'int');
1606
+                $object->default_lang = GETPOST('default_lang', 'alpha');
1607 1607
 
1608 1608
                 $object->tva_assuj				= GETPOST('assujtva_value', 'int');
1609 1609
                 $object->tva_intra				= GETPOST('tva_intra', 'alpha');
1610
-                $object->status					= GETPOST('status', 'int');
1610
+                $object->status = GETPOST('status', 'int');
1611 1611
 
1612 1612
                 // Webservices url/key
1613 1613
                 $object->webservices_url        = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
@@ -1616,32 +1616,32 @@  discard block
 block discarded – undo
1616 1616
 				//Incoterms
1617 1617
 				if (!empty($conf->incoterm->enabled))
1618 1618
 				{
1619
-					$object->fk_incoterms			= GETPOST('incoterm_id', 'int');
1620
-					$object->location_incoterms		= GETPOST('lcoation_incoterms', 'alpha');
1619
+					$object->fk_incoterms = GETPOST('incoterm_id', 'int');
1620
+					$object->location_incoterms = GETPOST('lcoation_incoterms', 'alpha');
1621 1621
 				}
1622 1622
 
1623 1623
                 //Local Taxes
1624 1624
                 $object->localtax1_assuj		= GETPOST('localtax1assuj_value');
1625 1625
                 $object->localtax2_assuj		= GETPOST('localtax2assuj_value');
1626 1626
 
1627
-                $object->localtax1_value		=GETPOST('lt1');
1628
-                $object->localtax2_value		=GETPOST('lt2');
1627
+                $object->localtax1_value		= GETPOST('lt1');
1628
+                $object->localtax2_value		= GETPOST('lt2');
1629 1629
 
1630 1630
                 // We set country_id, and country_code label of the chosen country
1631 1631
                 if ($object->country_id > 0)
1632 1632
                 {
1633
-                	$tmparray=getCountry($object->country_id,'all');
1634
-                    $object->country_code	= $tmparray['code'];
1635
-                    $object->country		= $tmparray['label'];
1633
+                	$tmparray = getCountry($object->country_id, 'all');
1634
+                    $object->country_code = $tmparray['code'];
1635
+                    $object->country = $tmparray['label'];
1636 1636
                 }
1637 1637
             }
1638 1638
 
1639
-            if($object->localtax1_assuj==0){
1640
-            	$sub=0;
1641
-            }else{$sub=1;}
1642
-            if($object->localtax2_assuj==0){
1643
-            	$sub2=0;
1644
-            }else{$sub2=1;}
1639
+            if ($object->localtax1_assuj == 0) {
1640
+            	$sub = 0;
1641
+            } else {$sub = 1; }
1642
+            if ($object->localtax2_assuj == 0) {
1643
+            	$sub2 = 0;
1644
+            } else {$sub2 = 1; }
1645 1645
 
1646 1646
             if ($conf->use_javascript_ajax)
1647 1647
             {
@@ -1686,7 +1686,7 @@  discard block
 block discarded – undo
1686 1686
 				});
1687 1687
        			function init_customer_categ() {
1688 1688
 					console.log("is customer or prospect = "+jQuery("#customerprospect").val());
1689
-					if (jQuery("#customerprospect").val() == 0 && (jQuery("#fournisseur").val() == 0 || '.(empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER)?'1':'0').'))
1689
+					if (jQuery("#customerprospect").val() == 0 && (jQuery("#fournisseur").val() == 0 || '.(empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER) ? '1' : '0').'))
1690 1690
 					{
1691 1691
 						jQuery(".visibleifcustomer").hide();
1692 1692
 					}
@@ -1735,7 +1735,7 @@  discard block
 block discarded – undo
1735 1735
             print '<table class="border" width="100%">';
1736 1736
 
1737 1737
             // Ref/ID
1738
-			if (! empty($conf->global->MAIN_SHOW_TECHNICAL_ID))
1738
+			if (!empty($conf->global->MAIN_SHOW_TECHNICAL_ID))
1739 1739
 			{
1740 1740
 		        print '<tr><td class="titlefieldcreate">'.$langs->trans("ID").'</td><td colspan="3">';
1741 1741
             	print $object->ref;
@@ -1751,7 +1751,7 @@  discard block
 block discarded – undo
1751 1751
 	        print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.dol_escape_htmltag($object->name_alias).'"></td></tr>';
1752 1752
 
1753 1753
             // Prefix
1754
-            if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1754
+            if (!empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1755 1755
             {
1756 1756
                 print '<tr><td>'.$form->editfieldkey('Prefix', 'prefix', '', $object, 0).'</td><td colspan="3">';
1757 1757
                 // It does not change the prefix mode using the auto numbering prefix
@@ -1770,19 +1770,19 @@  discard block
 block discarded – undo
1770 1770
             // Prospect/Customer
1771 1771
             print '<tr><td>'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).'</td>';
1772 1772
 	        print '<td class="maxwidthonsmartphone"><select class="flat" name="client" id="customerprospect">';
1773
-            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($object->client==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1774
-            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="3"'.($object->client==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1775
-            if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($object->client==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1776
-            print '<option value="0"'.($object->client==0?' selected':'').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1773
+            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($object->client == 2 ? ' selected' : '').'>'.$langs->trans('Prospect').'</option>';
1774
+            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="3"'.($object->client == 3 ? ' selected' : '').'>'.$langs->trans('ProspectCustomer').'</option>';
1775
+            if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($object->client == 1 ? ' selected' : '').'>'.$langs->trans('Customer').'</option>';
1776
+            print '<option value="0"'.($object->client == 0 ? ' selected' : '').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1777 1777
             print '</select></td>';
1778 1778
             print '<td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
1779 1779
 
1780 1780
             print '<table class="nobordernopadding"><tr><td>';
1781 1781
             if ((!$object->code_client || $object->code_client == -1) && $modCodeClient->code_auto)
1782 1782
             {
1783
-                $tmpcode=$object->code_client;
1784
-                if (empty($tmpcode) && ! empty($object->oldcopy->code_client)) $tmpcode=$object->oldcopy->code_client; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1785
-                if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object,0);
1783
+                $tmpcode = $object->code_client;
1784
+                if (empty($tmpcode) && !empty($object->oldcopy->code_client)) $tmpcode = $object->oldcopy->code_client; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1785
+                if (empty($tmpcode) && !empty($modCodeClient->code_auto)) $tmpcode = $modCodeClient->getNextValue($object, 0);
1786 1786
                 print '<input type="text" name="customer_code" id="customer_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1787 1787
             }
1788 1788
             else if ($object->codeclient_modifiable())
@@ -1795,34 +1795,34 @@  discard block
 block discarded – undo
1795 1795
                 print '<input type="hidden" name="customer_code" value="'.dol_escape_htmltag($object->code_client).'">';
1796 1796
             }
1797 1797
             print '</td><td>';
1798
-            $s=$modCodeClient->getToolTip($langs,$object,0);
1799
-            print $form->textwithpicto('',$s,1);
1798
+            $s = $modCodeClient->getToolTip($langs, $object, 0);
1799
+            print $form->textwithpicto('', $s, 1);
1800 1800
             print '</td></tr></table>';
1801 1801
 
1802 1802
             print '</td></tr>';
1803 1803
 
1804 1804
             // Supplier
1805
-            if ((! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1806
-            	|| (! empty($conf->supplier_proposal->enabled) && ! empty($user->rights->supplier_proposal->lire)))
1805
+            if ((!empty($conf->fournisseur->enabled) && !empty($user->rights->fournisseur->lire))
1806
+            	|| (!empty($conf->supplier_proposal->enabled) && !empty($user->rights->supplier_proposal->lire)))
1807 1807
             {
1808 1808
                 print '<tr>';
1809 1809
                 print '<td>'.$form->editfieldkey('Supplier', 'fournisseur', '', $object, 0, 'string', '', 1).'</td><td class="maxwidthonsmartphone">';
1810
-                print $form->selectyesno("fournisseur",$object->fournisseur,1);
1810
+                print $form->selectyesno("fournisseur", $object->fournisseur, 1);
1811 1811
                 print '</td>';
1812 1812
                 print '<td>';
1813
-                if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1813
+                if (!empty($conf->fournisseur->enabled) && !empty($user->rights->fournisseur->lire))
1814 1814
                 {
1815 1815
                 	print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0);
1816 1816
                 }
1817 1817
                 print '</td><td>';
1818
-                if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1818
+                if (!empty($conf->fournisseur->enabled) && !empty($user->rights->fournisseur->lire))
1819 1819
                 {
1820 1820
 	                print '<table class="nobordernopadding"><tr><td>';
1821 1821
 	                if ((!$object->code_fournisseur || $object->code_fournisseur == -1) && $modCodeFournisseur->code_auto)
1822 1822
 	                {
1823
-	                    $tmpcode=$object->code_fournisseur;
1824
-	                    if (empty($tmpcode) && ! empty($object->oldcopy->code_fournisseur)) $tmpcode=$object->oldcopy->code_fournisseur; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1825
-	                    if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1823
+	                    $tmpcode = $object->code_fournisseur;
1824
+	                    if (empty($tmpcode) && !empty($object->oldcopy->code_fournisseur)) $tmpcode = $object->oldcopy->code_fournisseur; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1825
+	                    if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) $tmpcode = $modCodeFournisseur->getNextValue($object, 1);
1826 1826
 	                    print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1827 1827
 	                }
1828 1828
 	                else if ($object->codefournisseur_modifiable())
@@ -1835,15 +1835,15 @@  discard block
 block discarded – undo
1835 1835
 	                    print '<input type="hidden" name="supplier_code" value="'.$object->code_fournisseur.'">';
1836 1836
 	                }
1837 1837
 	                print '</td><td>';
1838
-	                $s=$modCodeFournisseur->getToolTip($langs,$object,1);
1839
-	                print $form->textwithpicto('',$s,1);
1838
+	                $s = $modCodeFournisseur->getToolTip($langs, $object, 1);
1839
+	                print $form->textwithpicto('', $s, 1);
1840 1840
 	                print '</td></tr></table>';
1841 1841
                 }
1842 1842
                 print '</td></tr>';
1843 1843
             }
1844 1844
 
1845 1845
             // Barcode
1846
-            if (! empty($conf->barcode->enabled))
1846
+            if (!empty($conf->barcode->enabled))
1847 1847
             {
1848 1848
                 print '<tr><td class="tdtop">'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).'</td>';
1849 1849
 	            print '<td colspan="3"><input type="text" name="barcode" id="barcode" value="'.$object->barcode.'">';
@@ -1852,7 +1852,7 @@  discard block
 block discarded – undo
1852 1852
 
1853 1853
             // Status
1854 1854
             print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0).'</td><td colspan="3">';
1855
-            print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'),'1'=>$langs->trans('InActivity')),$object->status);
1855
+            print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), $object->status);
1856 1856
             print '</td></tr>';
1857 1857
 
1858 1858
             // Address
@@ -1870,14 +1870,14 @@  discard block
 block discarded – undo
1870 1870
 
1871 1871
             // Country
1872 1872
             print '<tr><td>'.$form->editfieldkey('Country', 'selectcounty_id', '', $object, 0).'</td><td colspan="3">';
1873
-            print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id),'country_id');
1874
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1873
+            print $form->select_country((GETPOST('country_id') != '' ?GETPOST('country_id') : $object->country_id), 'country_id');
1874
+            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1875 1875
             print '</td></tr>';
1876 1876
 
1877 1877
             // State
1878 1878
             if (empty($conf->global->SOCIETE_DISABLE_STATE))
1879 1879
             {
1880
-                if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1880
+                if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1881 1881
                 {
1882 1882
                     print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td colspan="3">';
1883 1883
                 }
@@ -1886,32 +1886,32 @@  discard block
 block discarded – undo
1886 1886
                     print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td colspan="3">';
1887 1887
                 }
1888 1888
 
1889
-                print $formcompany->select_state($object->state_id,$object->country_code);
1889
+                print $formcompany->select_state($object->state_id, $object->country_code);
1890 1890
                 print '</td></tr>';
1891 1891
             }
1892 1892
 
1893 1893
             // EMail / Web
1894
-            print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', (! empty($conf->global->SOCIETE_EMAIL_MANDATORY))).'</td>';
1894
+            print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', (!empty($conf->global->SOCIETE_EMAIL_MANDATORY))).'</td>';
1895 1895
 	        print '<td colspan="3"><input type="text" name="email" id="email" size="32" value="'.$object->email.'"></td></tr>';
1896 1896
             print '<tr><td>'.$form->editfieldkey('Web', 'url', '', $object, 0).'</td>';
1897 1897
 	        print '<td colspan="3"><input type="text" name="url" id="url" size="32" value="'.$object->url.'"></td></tr>';
1898 1898
 
1899
-	        if (! empty($conf->socialnetworks->enabled))
1899
+	        if (!empty($conf->socialnetworks->enabled))
1900 1900
 	        {
1901 1901
 	        	// Skype
1902
-	        	if (! empty($conf->global->SOCIALNETWORKS_SKYPE))
1902
+	        	if (!empty($conf->global->SOCIALNETWORKS_SKYPE))
1903 1903
 	        	{
1904 1904
 	        		print '<tr><td>'.$form->editfieldkey('Skype', 'skype', '', $object, 0).'</td>';
1905 1905
 	        		print '<td colspan="3"><input type="text" name="skype" id="skype" value="'.$object->skype.'"></td></tr>';
1906 1906
 	        	}
1907 1907
 	        	// Twitter
1908
-	        	if (! empty($conf->global->SOCIALNETWORKS_TWITTER))
1908
+	        	if (!empty($conf->global->SOCIALNETWORKS_TWITTER))
1909 1909
 	        	{
1910 1910
 	        		print '<tr><td>'.$form->editfieldkey('Twitter', 'twitter', '', $object, 0).'</td>';
1911 1911
 	        		print '<td colspan="3"><input type="text" name="twitter" id="twitter" value="'.$object->twitter.'"></td></tr>';
1912 1912
 	        	}
1913 1913
 	        	// Facebook
1914
-	        	if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK))
1914
+	        	if (!empty($conf->global->SOCIALNETWORKS_FACEBOOK))
1915 1915
 	        	{
1916 1916
 	        		print '<tr><td>'.$form->editfieldkey('Facebook', 'facebook', '', $object, 0).'</td>';
1917 1917
 	        		print '<td colspan="3"><input type="text" name="facebook" id="facebook" value="'.$object->facebook.'"></td></tr>';
@@ -1925,18 +1925,18 @@  discard block
 block discarded – undo
1925 1925
 	        print '<td><input type="text" name="fax" id="fax" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->fax.'"></td></tr>';
1926 1926
 
1927 1927
             // Prof ids
1928
-            $i=1; $j=0;
1928
+            $i = 1; $j = 0;
1929 1929
             while ($i <= 6)
1930 1930
             {
1931
-                $idprof=$langs->transcountry('ProfId'.$i,$object->country_code);
1932
-                if ($idprof!='-')
1931
+                $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
1932
+                if ($idprof != '-')
1933 1933
                 {
1934
-	                $key='idprof'.$i;
1934
+	                $key = 'idprof'.$i;
1935 1935
 
1936 1936
 	                if (($j % 2) == 0) print '<tr>';
1937 1937
 
1938
-	                $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
1939
-	                print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', ! (empty($conf->global->$idprof_mandatory) || ! $object->isACompany())).'</td><td>';
1938
+	                $idprof_mandatory = 'SOCIETE_IDPROF'.($i).'_MANDATORY';
1939
+	                print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', !(empty($conf->global->$idprof_mandatory) || !$object->isACompany())).'</td><td>';
1940 1940
 	                print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
1941 1941
                     print '</td>';
1942 1942
                     if (($j % 2) == 1) print '</tr>';
@@ -1948,53 +1948,53 @@  discard block
 block discarded – undo
1948 1948
 
1949 1949
             // VAT is used
1950 1950
             print '<tr><td>'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).'</td><td colspan="3">';
1951
-            print $form->selectyesno('assujtva_value',$object->tva_assuj,1);
1951
+            print $form->selectyesno('assujtva_value', $object->tva_assuj, 1);
1952 1952
             print '</td></tr>';
1953 1953
 
1954 1954
             // Local Taxes
1955 1955
             //TODO: Place into a function to control showing by country or study better option
1956
-            if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
1956
+            if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1")
1957 1957
             {
1958
-                print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed",$mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td>';
1959
-                print $form->selectyesno('localtax1assuj_value',$object->localtax1_assuj,1);
1960
-                if(! isOnlyOneLocalTax(1))
1958
+                print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td>';
1959
+                print $form->selectyesno('localtax1assuj_value', $object->localtax1_assuj, 1);
1960
+                if (!isOnlyOneLocalTax(1))
1961 1961
                 {
1962
-                    print '<span class="cblt1">     '.$langs->transcountry("Type",$mysoc->country_code).': ';
1963
-                    $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
1962
+                    print '<span class="cblt1">     '.$langs->transcountry("Type", $mysoc->country_code).': ';
1963
+                    $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
1964 1964
                     print '</span>';
1965 1965
                 }
1966 1966
                 print '</td>';
1967 1967
 
1968
-                print '<td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed",$mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td>';
1969
-                print $form->selectyesno('localtax2assuj_value',$object->localtax2_assuj,1);
1970
-                if  (! isOnlyOneLocalTax(2))
1968
+                print '<td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td>';
1969
+                print $form->selectyesno('localtax2assuj_value', $object->localtax2_assuj, 1);
1970
+                if (!isOnlyOneLocalTax(2))
1971 1971
                 {
1972
-                    print '<span class="cblt2">     '.$langs->transcountry("Type",$mysoc->country_code).': ';
1973
-                    $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
1972
+                    print '<span class="cblt2">     '.$langs->transcountry("Type", $mysoc->country_code).': ';
1973
+                    $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
1974 1974
                     print '</span>';
1975 1975
                 }
1976 1976
                 print '</td></tr>';
1977 1977
             }
1978
-            elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
1978
+            elseif ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj != "1")
1979 1979
             {
1980
-                print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed",$mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td colspan="3">';
1981
-                print $form->selectyesno('localtax1assuj_value',$object->localtax1_assuj,1);
1982
-                if(! isOnlyOneLocalTax(1))
1980
+                print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td colspan="3">';
1981
+                print $form->selectyesno('localtax1assuj_value', $object->localtax1_assuj, 1);
1982
+                if (!isOnlyOneLocalTax(1))
1983 1983
                 {
1984
-                    print '<span class="cblt1">     '.$langs->transcountry("Type",$mysoc->country_code).': ';
1985
-                    $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
1984
+                    print '<span class="cblt1">     '.$langs->transcountry("Type", $mysoc->country_code).': ';
1985
+                    $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
1986 1986
                     print '</span>';
1987 1987
                 }
1988 1988
                 print '</td></tr>';
1989 1989
             }
1990
-            elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
1990
+            elseif ($mysoc->localtax2_assuj == "1" && $mysoc->localtax1_assuj != "1")
1991 1991
             {
1992
-                print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed",$mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td colspan="3">';
1993
-                print $form->selectyesno('localtax2assuj_value',$object->localtax2_assuj,1);
1994
-                if(! isOnlyOneLocalTax(2))
1992
+                print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td colspan="3">';
1993
+                print $form->selectyesno('localtax2assuj_value', $object->localtax2_assuj, 1);
1994
+                if (!isOnlyOneLocalTax(2))
1995 1995
                 {
1996
-                    print '<span class="cblt2">     '.$langs->transcountry("Type",$mysoc->country_code).': ';
1997
-                    $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
1996
+                    print '<span class="cblt2">     '.$langs->transcountry("Type", $mysoc->country_code).': ';
1997
+                    $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
1998 1998
                     print '</span>';
1999 1999
                 }
2000 2000
                 print '</td></tr>';
@@ -2003,11 +2003,11 @@  discard block
 block discarded – undo
2003 2003
             // VAT Code
2004 2004
             print '<tr><td>'.$form->editfieldkey('VATIntra', 'intra_vat', '', $object, 0).'</td>';
2005 2005
             print '<td colspan="3">';
2006
-            $s ='<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
2006
+            $s = '<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
2007 2007
 
2008 2008
             if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object))
2009 2009
             {
2010
-                $s.=' &nbsp; ';
2010
+                $s .= ' &nbsp; ';
2011 2011
 
2012 2012
                 if ($conf->use_javascript_ajax)
2013 2013
                 {
@@ -2018,12 +2018,12 @@  discard block
 block discarded – undo
2018 2018
                     print "}\n";
2019 2019
                     print '</script>';
2020 2020
                     print "\n";
2021
-                    $s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
2022
-                    $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
2021
+                    $s .= '<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
2022
+                    $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->trans("VATIntraCheck")), 1);
2023 2023
                 }
2024 2024
                 else
2025 2025
                 {
2026
-                    $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
2026
+                    $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", $object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
2027 2027
                 }
2028 2028
             }
2029 2029
             print $s;
@@ -2032,12 +2032,12 @@  discard block
 block discarded – undo
2032 2032
 
2033 2033
             // Type - Size
2034 2034
             print '<tr><td>'.$form->editfieldkey('ThirdPartyType', 'typent_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
2035
-            print $form->selectarray("typent_id",$formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
2036
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
2035
+            print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT));
2036
+            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
2037 2037
             print '</td>';
2038 2038
             print '<td>'.$form->editfieldkey('Staff', 'effectif_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
2039
-            print $form->selectarray("effectif_id",$formcompany->effectif_array(0), $object->effectif_id);
2040
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
2039
+            print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id);
2040
+            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
2041 2041
             print '</td></tr>';
2042 2042
 
2043 2043
             // Juridical type
@@ -2052,10 +2052,10 @@  discard block
 block discarded – undo
2052 2052
 	        print '"> <font class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</font></td></tr>';
2053 2053
 
2054 2054
             // Default language
2055
-            if (! empty($conf->global->MAIN_MULTILANGS))
2055
+            if (!empty($conf->global->MAIN_MULTILANGS))
2056 2056
             {
2057 2057
                 print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3">'."\n";
2058
-                print $formadmin->select_language($object->default_lang,'default_lang',0,0,1);
2058
+                print $formadmin->select_language($object->default_lang, 'default_lang', 0, 0, 1);
2059 2059
                 print '</td>';
2060 2060
                 print '</tr>';
2061 2061
             }
@@ -2066,20 +2066,20 @@  discard block
 block discarded – undo
2066 2066
             	print '<tr>';
2067 2067
       				print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
2068 2068
             	print '<td colspan="3" class="maxwidthonsmartphone">';
2069
-            	print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
2069
+            	print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
2070 2070
             	print '</td></tr>';
2071 2071
             }
2072 2072
 
2073 2073
 			// Categories
2074
-			if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
2074
+			if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire))
2075 2075
 			{
2076 2076
 				// Customer
2077
-				print '<tr class="visibleifcustomer"><td>' . $form->editfieldkey('CustomersCategoriesShort', 'custcats', '', $object, 0) . '</td>';
2077
+				print '<tr class="visibleifcustomer"><td>'.$form->editfieldkey('CustomersCategoriesShort', 'custcats', '', $object, 0).'</td>';
2078 2078
 				print '<td colspan="3">';
2079 2079
 				$cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, null, null, null, 1);
2080 2080
 				$c = new Categorie($db);
2081 2081
 				$cats = $c->containing($object->id, Categorie::TYPE_CUSTOMER);
2082
-				$arrayselected=array();
2082
+				$arrayselected = array();
2083 2083
 				foreach ($cats as $cat) {
2084 2084
 					$arrayselected[] = $cat->id;
2085 2085
 				}
@@ -2087,12 +2087,12 @@  discard block
 block discarded – undo
2087 2087
 				print "</td></tr>";
2088 2088
 
2089 2089
 				// Supplier
2090
-				print '<tr class="visibleifsupplier"><td>' . $form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0) . '</td>';
2090
+				print '<tr class="visibleifsupplier"><td>'.$form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0).'</td>';
2091 2091
 				print '<td colspan="3">';
2092 2092
 				$cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, null, null, null, 1);
2093 2093
 				$c = new Categorie($db);
2094 2094
 				$cats = $c->containing($object->id, Categorie::TYPE_SUPPLIER);
2095
-				$arrayselected=array();
2095
+				$arrayselected = array();
2096 2096
 				foreach ($cats as $cat) {
2097 2097
 					$arrayselected[] = $cat->id;
2098 2098
 				}
@@ -2101,7 +2101,7 @@  discard block
 block discarded – undo
2101 2101
 			}
2102 2102
 
2103 2103
 			// Multicurrency
2104
-			if (! empty($conf->multicurrency->enabled))
2104
+			if (!empty($conf->multicurrency->enabled))
2105 2105
 			{
2106 2106
 				print '<tr>';
2107 2107
 				print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
@@ -2111,12 +2111,12 @@  discard block
 block discarded – undo
2111 2111
 			}
2112 2112
 
2113 2113
             // Other attributes
2114
-            $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
2115
-            $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
2114
+            $parameters = array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
2115
+            $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2116 2116
             print $hookmanager->resPrint;
2117 2117
             if (empty($reshook))
2118 2118
             {
2119
-            	print $object->showOptionals($extrafields,'edit');
2119
+            	print $object->showOptionals($extrafields, 'edit');
2120 2120
             }
2121 2121
 
2122 2122
             // Webservices url/key
@@ -2131,8 +2131,8 @@  discard block
 block discarded – undo
2131 2131
             print '<tr class="hideonsmartphone">';
2132 2132
             print '<td>'.$form->editfieldkey('Logo', 'photoinput', '', $object, 0).'</td>';
2133 2133
             print '<td colspan="3">';
2134
-            if ($object->logo) print $form->showphoto('societe',$object);
2135
-            $caneditfield=1;
2134
+            if ($object->logo) print $form->showphoto('societe', $object);
2135
+            $caneditfield = 1;
2136 2136
             if ($caneditfield)
2137 2137
             {
2138 2138
                 if ($object->logo) print "<br>\n";
@@ -2175,7 +2175,7 @@  discard block
 block discarded – undo
2175 2175
          * View
2176 2176
          */
2177 2177
 
2178
-        if (!empty($object->id)) $res=$object->fetch_optionals();
2178
+        if (!empty($object->id)) $res = $object->fetch_optionals();
2179 2179
         //if ($res < 0) { dol_print_error($db); exit; }
2180 2180
 
2181 2181
 
@@ -2203,11 +2203,11 @@  discard block
 block discarded – undo
2203 2203
 		    print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("MergeThirdparties"), $langs->trans("ConfirmMergeThirdparties"), "confirm_merge", $formquestion, 'no', 1, 250);
2204 2204
 	    }
2205 2205
 
2206
-        dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error');
2206
+        dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
2207 2207
 
2208 2208
         $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
2209 2209
 
2210
-        dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
2210
+        dol_banner_tab($object, 'socid', $linkback, ($user->societe_id ? 0 : 1), 'rowid', 'nom');
2211 2211
 
2212 2212
 
2213 2213
         print '<div class="fichecenter">';
@@ -2222,7 +2222,7 @@  discard block
 block discarded – undo
2222 2222
     	print '</td></tr>';
2223 2223
 
2224 2224
     	// Supplier
2225
-   		if (! empty($conf->fournisseur->enabled) || ! empty($conf->supplier_proposal->enabled))
2225
+   		if (!empty($conf->fournisseur->enabled) || !empty($conf->supplier_proposal->enabled))
2226 2226
     	{
2227 2227
     		print '<tr><td>'.$langs->trans('Supplier').'</td><td>';
2228 2228
     		print yn($object->fournisseur);
@@ -2230,10 +2230,10 @@  discard block
 block discarded – undo
2230 2230
     	}
2231 2231
 
2232 2232
     	// Prefix
2233
-        if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
2233
+        if (!empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
2234 2234
         {
2235 2235
             print '<tr><td>'.$langs->trans('Prefix').'</td><td>'.$object->prefix_comm.'</td>';
2236
-            print $htmllogobar; $htmllogobar='';
2236
+            print $htmllogobar; $htmllogobar = '';
2237 2237
             print '</tr>';
2238 2238
         }
2239 2239
 
@@ -2245,49 +2245,49 @@  discard block
 block discarded – undo
2245 2245
             print $object->code_client;
2246 2246
             if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
2247 2247
             print '</td>';
2248
-            print $htmllogobar; $htmllogobar='';
2248
+            print $htmllogobar; $htmllogobar = '';
2249 2249
             print '</tr>';
2250 2250
         }
2251 2251
 
2252 2252
         // Supplier code
2253
-        if (! empty($conf->fournisseur->enabled) && $object->fournisseur && ! empty($user->rights->fournisseur->lire))
2253
+        if (!empty($conf->fournisseur->enabled) && $object->fournisseur && !empty($user->rights->fournisseur->lire))
2254 2254
         {
2255 2255
             print '<tr><td>';
2256 2256
             print $langs->trans('SupplierCode').'</td><td>';
2257 2257
             print $object->code_fournisseur;
2258 2258
             if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
2259 2259
             print '</td>';
2260
-            print $htmllogobar; $htmllogobar='';
2260
+            print $htmllogobar; $htmllogobar = '';
2261 2261
             print '</tr>';
2262 2262
         }
2263 2263
 
2264 2264
         // Barcode
2265
-        if (! empty($conf->barcode->enabled))
2265
+        if (!empty($conf->barcode->enabled))
2266 2266
         {
2267 2267
             print '<tr><td>';
2268 2268
             print $langs->trans('Gencod').'</td><td>'.$object->barcode;
2269 2269
             print '</td>';
2270
-			if ($htmllogobar) $htmllogobar.=$form->showbarcode($object);
2270
+			if ($htmllogobar) $htmllogobar .= $form->showbarcode($object);
2271 2271
             print $htmllogobar;
2272
-			$htmllogobar='';
2272
+			$htmllogobar = '';
2273 2273
             print '</tr>';
2274 2274
         }
2275 2275
 
2276 2276
         // Prof ids
2277
-        $i=1; $j=0;
2277
+        $i = 1; $j = 0;
2278 2278
         while ($i <= 6)
2279 2279
         {
2280
-            $idprof=$langs->transcountry('ProfId'.$i,$object->country_code);
2281
-            if ($idprof!='-')
2280
+            $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
2281
+            if ($idprof != '-')
2282 2282
             {
2283 2283
                 //if (($j % 2) == 0) print '<tr>';
2284 2284
                 print '<tr>';
2285 2285
             	print '<td>'.$idprof.'</td><td>';
2286
-                $key='idprof'.$i;
2286
+                $key = 'idprof'.$i;
2287 2287
                 print $object->$key;
2288 2288
                 if ($object->$key)
2289 2289
                 {
2290
-                    if ($object->id_prof_check($i,$object) > 0) print ' &nbsp; '.$object->id_prof_url($i,$object);
2290
+                    if ($object->id_prof_check($i, $object) > 0) print ' &nbsp; '.$object->id_prof_url($i, $object);
2291 2291
                     else print ' <font class="error">('.$langs->trans("ErrorWrongValue").')</font>';
2292 2292
                 }
2293 2293
                 print '</td>';
@@ -2308,7 +2308,7 @@  discard block
 block discarded – undo
2308 2308
         {
2309 2309
 	        // VAT is used
2310 2310
 	        print '<tr><td>';
2311
-	        print $form->textwithpicto($langs->trans('VATIsUsed'),$langs->trans('VATIsUsedWhenSelling'));
2311
+	        print $form->textwithpicto($langs->trans('VATIsUsed'), $langs->trans('VATIsUsedWhenSelling'));
2312 2312
 	        print '</td><td>';
2313 2313
 	        print yn($object->tva_assuj);
2314 2314
 	        print '</td>';
@@ -2316,26 +2316,26 @@  discard block
 block discarded – undo
2316 2316
         }
2317 2317
 
2318 2318
 		// Local Taxes
2319
-        if ($object->fournisseur || $mysoc->country_code=='ES')
2319
+        if ($object->fournisseur || $mysoc->country_code == 'ES')
2320 2320
         {
2321
-        	if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
2321
+        	if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1")
2322 2322
 			{
2323
-			    print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
2323
+			    print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
2324 2324
 			    print yn($object->localtax1_assuj);
2325
-			    print '</td></tr><tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
2325
+			    print '</td></tr><tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
2326 2326
 			    print yn($object->localtax2_assuj);
2327 2327
 			    print '</td></tr>';
2328 2328
 
2329
-			    if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1)))
2329
+			    if ($object->localtax1_assuj == "1" && (!isOnlyOneLocalTax(1)))
2330 2330
 			    {
2331 2331
 			        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2332 2332
 			        print '<input type="hidden" name="action" value="set_localtax1">';
2333 2333
 			        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2334
-			        print '<tr><td>'.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2335
-			        if($action == 'editRE')
2334
+			        print '<tr><td>'.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</td>';
2335
+			        if ($action == 'editRE')
2336 2336
 			        {
2337 2337
 			            print '<td align="left">';
2338
-			            $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2338
+			            $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
2339 2339
 			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2340 2340
 			        }
2341 2341
 			        else
@@ -2344,60 +2344,60 @@  discard block
 block discarded – undo
2344 2344
 			        }
2345 2345
 			        print '</tr></form>';
2346 2346
 			    }
2347
-			    if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2)))
2347
+			    if ($object->localtax2_assuj == "1" && (!isOnlyOneLocalTax(2)))
2348 2348
 			    {
2349 2349
 			        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2350 2350
 			        print '<input type="hidden" name="action" value="set_localtax2">';
2351 2351
 			        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2352
-			        print '<tr><td>'.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2353
-			        if($action == 'editIRPF'){
2352
+			        print '<tr><td>'.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</td>';
2353
+			        if ($action == 'editIRPF') {
2354 2354
 			            print '<td align="left">';
2355
-			            $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2355
+			            $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
2356 2356
 			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2357
-			        }else{
2357
+			        } else {
2358 2358
 			            print '<td>'.$object->localtax2_value.'</td>';
2359 2359
 			        }
2360 2360
 			        print '</tr></form>';
2361 2361
 			    }
2362 2362
 			}
2363
-			elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
2363
+			elseif ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj != "1")
2364 2364
 			{
2365
-			    print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
2365
+			    print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
2366 2366
 			    print yn($object->localtax1_assuj);
2367 2367
 			    print '</td></tr>';
2368
-			    if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1)))
2368
+			    if ($object->localtax1_assuj == "1" && (!isOnlyOneLocalTax(1)))
2369 2369
 			    {
2370 2370
 			        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2371 2371
 			        print '<input type="hidden" name="action" value="set_localtax1">';
2372 2372
 			        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2373
-			        print '<tr><td> '.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2374
-			        if($action == 'editRE'){
2373
+			        print '<tr><td> '.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</td>';
2374
+			        if ($action == 'editRE') {
2375 2375
 			            print '<td align="left">';
2376
-			            $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2376
+			            $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
2377 2377
 			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2378
-			        }else{
2378
+			        } else {
2379 2379
 			            print '<td>'.$object->localtax1_value.'</td>';
2380 2380
 			        }
2381 2381
 			        print '</tr></form>';
2382 2382
 			    }
2383 2383
 			}
2384
-			elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
2384
+			elseif ($mysoc->localtax2_assuj == "1" && $mysoc->localtax1_assuj != "1")
2385 2385
 			{
2386
-			    print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
2386
+			    print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
2387 2387
 			    print yn($object->localtax2_assuj);
2388 2388
 			    print '</td></tr>';
2389
-			    if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2)))
2389
+			    if ($object->localtax2_assuj == "1" && (!isOnlyOneLocalTax(2)))
2390 2390
 			    {
2391 2391
 
2392 2392
 			        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2393 2393
 			        print '<input type="hidden" name="action" value="set_localtax2">';
2394 2394
 			        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2395
-			        print '<tr><td> '.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2396
-			        if($action == 'editIRPF'){
2395
+			        print '<tr><td> '.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</td>';
2396
+			        if ($action == 'editIRPF') {
2397 2397
 			            print '<td align="left">';
2398
-			            $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2398
+			            $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
2399 2399
 			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2400
-			        }else{
2400
+			        } else {
2401 2401
 			            print '<td>'.$object->localtax2_value.'</td>';
2402 2402
 			        }
2403 2403
 			        print '</tr></form>';
@@ -2410,13 +2410,13 @@  discard block
 block discarded – undo
2410 2410
 		print '<td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
2411 2411
         if ($object->tva_intra)
2412 2412
         {
2413
-            $s='';
2414
-            $s.=$object->tva_intra;
2415
-            $s.='<input type="hidden" id="tva_intra" name="tva_intra" maxlength="20" value="'.$object->tva_intra.'">';
2413
+            $s = '';
2414
+            $s .= $object->tva_intra;
2415
+            $s .= '<input type="hidden" id="tva_intra" name="tva_intra" maxlength="20" value="'.$object->tva_intra.'">';
2416 2416
 
2417 2417
             if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object))
2418 2418
             {
2419
-                $s.=' &nbsp; ';
2419
+                $s .= ' &nbsp; ';
2420 2420
 
2421 2421
                 if ($conf->use_javascript_ajax)
2422 2422
                 {
@@ -2427,12 +2427,12 @@  discard block
 block discarded – undo
2427 2427
                     print "}\n";
2428 2428
                     print '</script>';
2429 2429
                     print "\n";
2430
-                    $s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT( $(\'#tva_intra\').val() );">'.$langs->trans("VATIntraCheck").'</a>';
2431
-                    $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
2430
+                    $s .= '<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT( $(\'#tva_intra\').val() );">'.$langs->trans("VATIntraCheck").'</a>';
2431
+                    $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->trans("VATIntraCheck")), 1);
2432 2432
                 }
2433 2433
                 else
2434 2434
                 {
2435
-                    $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
2435
+                    $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", $object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
2436 2436
                 }
2437 2437
             }
2438 2438
             print $s;
@@ -2446,7 +2446,7 @@  discard block
 block discarded – undo
2446 2446
 
2447 2447
         // Type + Staff
2448 2448
         $arr = $formcompany->typent_array(1);
2449
-        $object->typent= $arr[$object->typent_code];
2449
+        $object->typent = $arr[$object->typent_code];
2450 2450
         print '<tr><td>'.$langs->trans("ThirdPartyType").'</td><td>'.$object->typent.'</td>';
2451 2451
         print '<tr><td>'.$langs->trans("Staff").'</td><td>'.$object->effectif.'</td></tr>';
2452 2452
 
@@ -2459,11 +2459,11 @@  discard block
 block discarded – undo
2459 2459
         print '<table class="border tableforfield" width="100%">';
2460 2460
 
2461 2461
     	// Tags / categories
2462
-		if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
2462
+		if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire))
2463 2463
 		{
2464 2464
 			// Customer
2465
-			if ($object->prospect || $object->client || (! $object->fournisseur && ! empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER))) {
2466
-				print '<tr><td>' . $langs->trans("CustomersCategoriesShort") . '</td>';
2465
+			if ($object->prospect || $object->client || (!$object->fournisseur && !empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER))) {
2466
+				print '<tr><td>'.$langs->trans("CustomersCategoriesShort").'</td>';
2467 2467
 				print '<td>';
2468 2468
 				print $form->showCategories($object->id, 'customer', 1);
2469 2469
 				print "</td></tr>";
@@ -2471,7 +2471,7 @@  discard block
 block discarded – undo
2471 2471
 
2472 2472
 			// Supplier
2473 2473
 			if ($object->fournisseur) {
2474
-				print '<tr><td>' . $langs->trans("SuppliersCategoriesShort") . '</td>';
2474
+				print '<tr><td>'.$langs->trans("SuppliersCategoriesShort").'</td>';
2475 2475
 				print '<td>';
2476 2476
 				print $form->showCategories($object->id, 'supplier', 1);
2477 2477
 				print "</td></tr>";
@@ -2483,19 +2483,19 @@  discard block
 block discarded – undo
2483 2483
 
2484 2484
         // Capital
2485 2485
         print '<tr><td>'.$langs->trans('Capital').'</td><td>';
2486
-        if ($object->capital) print price($object->capital,'',$langs,0,-1,-1, $conf->currency);
2486
+        if ($object->capital) print price($object->capital, '', $langs, 0, -1, -1, $conf->currency);
2487 2487
         else print '&nbsp;';
2488 2488
         print '</td></tr>';
2489 2489
 
2490 2490
         // Default language
2491
-        if (! empty($conf->global->MAIN_MULTILANGS))
2491
+        if (!empty($conf->global->MAIN_MULTILANGS))
2492 2492
         {
2493 2493
             require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2494 2494
             print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
2495 2495
             //$s=picto_from_langcode($object->default_lang);
2496 2496
             //print ($s?$s.' ':'');
2497 2497
             $langs->load("languages");
2498
-            $labellang = ($object->default_lang?$langs->trans('Language_'.$object->default_lang):'');
2498
+            $labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
2499 2499
             print $labellang;
2500 2500
             print '</td></tr>';
2501 2501
         }
@@ -2507,7 +2507,7 @@  discard block
 block discarded – undo
2507 2507
         	print '<table width="100%" class="nobordernopadding"><tr><td>';
2508 2508
         	print $langs->trans('IncotermLabel');
2509 2509
         	print '<td><td align="right">';
2510
-        	if ($user->rights->societe->creer) print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$object->id.'&action=editincoterm">'.img_edit('',1).'</a>';
2510
+        	if ($user->rights->societe->creer) print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$object->id.'&action=editincoterm">'.img_edit('', 1).'</a>';
2511 2511
         	else print '&nbsp;';
2512 2512
         	print '</td></tr></table>';
2513 2513
         	print '</td>';
@@ -2518,24 +2518,24 @@  discard block
 block discarded – undo
2518 2518
         	}
2519 2519
         	else
2520 2520
         	{
2521
-        		print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?socid='.$object->id);
2521
+        		print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?socid='.$object->id);
2522 2522
         	}
2523 2523
         	print '</td></tr>';
2524 2524
         }
2525 2525
 
2526 2526
 		// Multicurrency
2527
-		if (! empty($conf->multicurrency->enabled))
2527
+		if (!empty($conf->multicurrency->enabled))
2528 2528
 		{
2529 2529
 			print '<tr>';
2530 2530
 			print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
2531 2531
 	        print '<td>';
2532
-	        print !empty($object->multicurrency_code) ? currency_name($object->multicurrency_code,1) : '';
2532
+	        print !empty($object->multicurrency_code) ? currency_name($object->multicurrency_code, 1) : '';
2533 2533
 			print '</td></tr>';
2534 2534
 		}
2535 2535
 
2536 2536
 		// Other attributes
2537
-		$parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
2538
-		include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
2537
+		$parameters = array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
2538
+		include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
2539 2539
 
2540 2540
         // Parent company
2541 2541
         if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY))
@@ -2545,16 +2545,16 @@  discard block
 block discarded – undo
2545 2545
         	print '<table class="nobordernopadding" width="100%"><tr><td>';
2546 2546
         	print $langs->trans('ParentCompany');
2547 2547
         	print '</td>';
2548
-        	if ($action != 'editparentcompany') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</a></td>';
2548
+        	if ($action != 'editparentcompany') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a></td>';
2549 2549
         	print '</tr></table>';
2550 2550
         	print '</td><td colspan="3">';
2551 2551
         	if ($action == 'editparentcompany')
2552 2552
         	{
2553
-        		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'editparentcompany','s.rowid <> '.$object->id,1);
2553
+        		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->parent, 'editparentcompany', 's.rowid <> '.$object->id, 1);
2554 2554
         	}
2555 2555
         	else
2556 2556
         	{
2557
-        		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'none','s.rowid <> '.$object->id,1);
2557
+        		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->parent, 'none', 's.rowid <> '.$object->id, 1);
2558 2558
         	}
2559 2559
         	print '</td>';
2560 2560
         	print '</tr>';
@@ -2564,16 +2564,16 @@  discard block
 block discarded – undo
2564 2564
         include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php';
2565 2565
 
2566 2566
         // Module Adherent
2567
-        if (! empty($conf->adherent->enabled))
2567
+        if (!empty($conf->adherent->enabled))
2568 2568
         {
2569 2569
             $langs->load("members");
2570 2570
             print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
2571 2571
             print '<td colspan="3">';
2572
-            $adh=new Adherent($db);
2573
-            $result=$adh->fetch('','',$object->id);
2572
+            $adh = new Adherent($db);
2573
+            $result = $adh->fetch('', '', $object->id);
2574 2574
             if ($result > 0)
2575 2575
             {
2576
-                $adh->ref=$adh->getFullName($langs);
2576
+                $adh->ref = $adh->getFullName($langs);
2577 2577
                 print $adh->getNomUrl(1);
2578 2578
             }
2579 2579
             else
@@ -2606,8 +2606,8 @@  discard block
 block discarded – undo
2606 2606
         {
2607 2607
 	        print '<div class="tabsAction">'."\n";
2608 2608
 
2609
-			$parameters=array();
2610
-			$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
2609
+			$parameters = array();
2610
+			$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2611 2611
 			if (empty($reshook))
2612 2612
 			{
2613 2613
 				$at_least_one_email_contact = false;
@@ -2621,7 +2621,7 @@  discard block
 block discarded – undo
2621 2621
 					}
2622 2622
 				}
2623 2623
 
2624
-		        if (! empty($object->email) || $at_least_one_email_contact)
2624
+		        if (!empty($object->email) || $at_least_one_email_contact)
2625 2625
 		        {
2626 2626
 		        	$langs->load("mails");
2627 2627
 		        	print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'&amp;action=presend&amp;mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';
@@ -2674,10 +2674,10 @@  discard block
 block discarded – undo
2674 2674
 	            /*
2675 2675
 	             * Documents generes
2676 2676
 	             */
2677
-	            $filedir=$conf->societe->multidir_output[$object->entity].'/'.$object->id;
2678
-	            $urlsource=$_SERVER["PHP_SELF"]."?socid=".$object->id;
2679
-	            $genallowed=$user->rights->societe->lire;
2680
-	            $delallowed=$user->rights->societe->creer;
2677
+	            $filedir = $conf->societe->multidir_output[$object->entity].'/'.$object->id;
2678
+	            $urlsource = $_SERVER["PHP_SELF"]."?socid=".$object->id;
2679
+	            $genallowed = $user->rights->societe->lire;
2680
+	            $delallowed = $user->rights->societe->creer;
2681 2681
 
2682 2682
 	            print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang);
2683 2683
 	        }
@@ -2685,7 +2685,7 @@  discard block
 block discarded – undo
2685 2685
 			// Subsidiaries list
2686 2686
 			if (empty($conf->global->SOCIETE_DISABLE_SUBSIDIARIES))
2687 2687
 			{
2688
-				$result=show_subsidiaries($conf,$langs,$db,$object);
2688
+				$result = show_subsidiaries($conf, $langs, $db, $object);
2689 2689
 			}
2690 2690
 
2691 2691
 			print '</div><div class="fichehalfright"><div class="ficheaddleft">';
@@ -2693,35 +2693,35 @@  discard block
 block discarded – undo
2693 2693
 			$MAXEVENT = 10;
2694 2694
 
2695 2695
 			$morehtmlright = '<a href="'.DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id.'">';
2696
-			$morehtmlright.= $langs->trans("SeeAll");
2697
-			$morehtmlright.= '</a>';
2696
+			$morehtmlright .= $langs->trans("SeeAll");
2697
+			$morehtmlright .= '</a>';
2698 2698
 
2699 2699
 			// List of actions on element
2700
-			include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
2700
+			include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
2701 2701
 			$formactions = new FormActions($db);
2702
-			$somethingshown = $formactions->showactions($object, '', $socid, 1, '', $MAXEVENT, '', $morehtmlright);		// Show all action for thirdparty
2702
+			$somethingshown = $formactions->showactions($object, '', $socid, 1, '', $MAXEVENT, '', $morehtmlright); // Show all action for thirdparty
2703 2703
 
2704 2704
 			print '</div></div></div>';
2705 2705
 
2706
-			if (! empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD))
2706
+			if (!empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD))
2707 2707
 			{
2708 2708
 				// Contacts list
2709 2709
 				if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
2710 2710
 				{
2711
-					$result=show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
2711
+					$result = show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
2712 2712
 				}
2713 2713
 
2714 2714
 				// Addresses list
2715
-				if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))
2715
+				if (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))
2716 2716
 				{
2717
-					$result=show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
2717
+					$result = show_addresses($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
2718 2718
 				}
2719 2719
 			}
2720 2720
 		}
2721 2721
 
2722 2722
 		// Presend form
2723
-		$modelmail='thirdparty';
2724
-		$defaulttopic='Information';
2723
+		$modelmail = 'thirdparty';
2724
+		$defaulttopic = 'Information';
2725 2725
 		$diroutput = $conf->societe->dir_output;
2726 2726
 		$trackid = 'thi'.$object->id;
2727 2727
 
Please login to merge, or discard this patch.
Braces   +291 added lines, -181 removed lines patch added patch discarded remove patch
@@ -45,12 +45,20 @@  discard block
 block discarded – undo
45 45
 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
46 46
 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
47 47
 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
48
-if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
48
+if (! empty($conf->adherent->enabled)) {
49
+    require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
50
+}
49 51
 
50 52
 $langs->loadLangs(array("companies","commercial","bills","banks","users"));
51
-if (! empty($conf->categorie->enabled)) $langs->load("categories");
52
-if (! empty($conf->incoterm->enabled)) $langs->load("incoterm");
53
-if (! empty($conf->notification->enabled)) $langs->load("mails");
53
+if (! empty($conf->categorie->enabled)) {
54
+    $langs->load("categories");
55
+}
56
+if (! empty($conf->incoterm->enabled)) {
57
+    $langs->load("incoterm");
58
+}
59
+if (! empty($conf->notification->enabled)) {
60
+    $langs->load("mails");
61
+}
54 62
 
55 63
 $mesg=''; $error=0; $errors=array();
56 64
 
@@ -60,8 +68,12 @@  discard block
 block discarded – undo
60 68
 $confirm	= GETPOST('confirm','alpha');
61 69
 
62 70
 $socid		= GETPOST('socid','int')?GETPOST('socid','int'):GETPOST('id','int');
63
-if ($user->societe_id) $socid=$user->societe_id;
64
-if (empty($socid) && $action == 'view') $action='create';
71
+if ($user->societe_id) {
72
+    $socid=$user->societe_id;
73
+}
74
+if (empty($socid) && $action == 'view') {
75
+    $action='create';
76
+}
65 77
 
66 78
 $object = new Societe($db);
67 79
 $extrafields = new ExtraFields($db);
@@ -72,7 +84,9 @@  discard block
 block discarded – undo
72 84
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
73 85
 $hookmanager->initHooks(array('thirdpartycard','globalcard'));
74 86
 
75
-if ($socid > 0) $object->fetch($socid);
87
+if ($socid > 0) {
88
+    $object->fetch($socid);
89
+}
76 90
 
77 91
 if (! ($object->id > 0) && $action == 'view')
78 92
 {
@@ -102,7 +116,9 @@  discard block
 block discarded – undo
102 116
 
103 117
 $parameters=array('id'=>$socid, 'objcanvas'=>$objcanvas);
104 118
 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
105
-if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
119
+if ($reshook < 0) {
120
+    setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
121
+}
106 122
 
107 123
 if (empty($reshook))
108 124
 {
@@ -127,8 +143,7 @@  discard block
 block discarded – undo
127 143
 			$langs->load('errors');
128 144
 			$langs->load('companies');
129 145
 			setEventMessages($langs->trans('ErrorThirdPartyIdIsMandatory', $langs->trans('MergeOriginThirdparty')), null, 'errors');
130
-		}
131
-		else
146
+		} else
132 147
 		{
133 148
 			if (!$error && $soc_origin->fetch($soc_origin_id) < 1)
134 149
 			{
@@ -155,7 +170,9 @@  discard block
 block discarded – undo
155 170
 				);
156 171
 				foreach ($listofproperties as $property)
157 172
 				{
158
-					if (empty($object->$property)) $object->$property = $soc_origin->$property;
173
+					if (empty($object->$property)) {
174
+					    $object->$property = $soc_origin->$property;
175
+					}
159 176
 				}
160 177
 
161 178
 				// Concat some data
@@ -172,7 +189,9 @@  discard block
 block discarded – undo
172 189
 				{
173 190
 					foreach ($soc_origin->array_options as $key => $val)
174 191
 					{
175
-					    if (empty($object->array_options[$key])) $object->array_options[$key] = $val;
192
+					    if (empty($object->array_options[$key])) {
193
+					        $object->array_options[$key] = $val;
194
+					    }
176 195
 					}
177 196
 				}
178 197
 
@@ -291,8 +310,7 @@  discard block
 block discarded – undo
291 310
 				{
292 311
 					setEventMessages($langs->trans('ThirdpartiesMergeSuccess'), null, 'mesgs');
293 312
 					$db->commit();
294
-				}
295
-				else
313
+				} else
296 314
 				{
297 315
 				    $langs->load("errors");
298 316
 					setEventMessages($langs->trans('ErrorsThirdpartyMerge'), null, 'errors');
@@ -337,7 +355,9 @@  discard block
 block discarded – undo
337 355
         // Fill array 'array_options' with data from update form
338 356
         $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
339 357
         $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute','none'));
340
-        if ($ret < 0) $error++;
358
+        if ($ret < 0) {
359
+            $error++;
360
+        }
341 361
 
342 362
         if (! $error)
343 363
         {
@@ -349,7 +369,9 @@  discard block
 block discarded – undo
349 369
         	}
350 370
         }
351 371
 
352
-        if ($error) $action = 'edit_extras';
372
+        if ($error) {
373
+            $action = 'edit_extras';
374
+        }
353 375
     }
354 376
 
355 377
     // Add new or update third party
@@ -380,20 +402,22 @@  discard block
 block discarded – undo
380 402
 	        {
381 403
 	        	$ret=$object->fetch($socid);
382 404
 				$object->oldcopy = clone $object;
383
-	        }
384
-			else $object->canvas=$canvas;
405
+	        } else {
406
+			    $object->canvas=$canvas;
407
+			}
385 408
 
386
-	        if (GETPOST("private") == 1)	// Ask to create a contact
409
+	        if (GETPOST("private") == 1) {
410
+	            // Ask to create a contact
387 411
 	        {
388 412
 	            $object->particulier		= GETPOST("private");
413
+	        }
389 414
 
390 415
 	            $object->name				= dolGetFirstLastname(GETPOST('firstname','alpha'),GETPOST('name','alpha'));
391 416
 	            $object->civility_id		= GETPOST('civility_id');	// Note: civility id is a code, not an int
392 417
 	            // Add non official properties
393 418
 	            $object->name_bis			= GETPOST('name','alpha');
394 419
 	            $object->firstname			= GETPOST('firstname','alpha');
395
-	        }
396
-	        else
420
+	        } else
397 421
 	        {
398 422
 	            $object->name				= GETPOST('name', 'alpha');
399 423
 	        }
@@ -470,8 +494,11 @@  discard block
 block discarded – undo
470 494
 				 $error++;
471 495
 			}
472 496
 
473
-	        if (GETPOST('deletephoto')) $object->logo = '';
474
-	        else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
497
+	        if (GETPOST('deletephoto')) {
498
+	            $object->logo = '';
499
+	        } else if (! empty($_FILES['photo']['name'])) {
500
+	            $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
501
+	        }
475 502
 
476 503
 	        // Check parameters
477 504
 	        if (! GETPOST('cancel','alpha'))
@@ -518,8 +545,12 @@  discard block
 block discarded – undo
518 545
 
519 546
                 $db->begin();
520 547
 
521
-                if (empty($object->client))      $object->code_client='';
522
-                if (empty($object->fournisseur)) $object->code_fournisseur='';
548
+                if (empty($object->client)) {
549
+                    $object->code_client='';
550
+                }
551
+                if (empty($object->fournisseur)) {
552
+                    $object->code_fournisseur='';
553
+                }
523 554
 
524 555
                 $result = $object->create($user);
525 556
 
@@ -580,16 +611,14 @@  discard block
 block discarded – undo
580 611
                                 if (! $result > 0)
581 612
                                 {
582 613
                                     $errors[] = "ErrorFailedToSaveFile";
583
-                                }
584
-                                else
614
+                                } else
585 615
                                 {
586 616
                                     // Create thumbs
587 617
                                     $object->addThumbs($newfile);
588 618
                                 }
589 619
                             }
590 620
                         }
591
-                    }
592
-                    else
621
+                    } else
593 622
 					{
594 623
 						switch($_FILES['photo']['error'])
595 624
 						{
@@ -603,12 +632,13 @@  discard block
 block discarded – undo
603 632
 						}
604 633
 	                }
605 634
                     // Gestion du logo de la société
606
-                }
607
-                else
635
+                } else
608 636
 				{
609
-				    if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') // TODO Sometime errors on duplicate on profid and not on code, so we must manage this case
637
+				    if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
638
+				        // TODO Sometime errors on duplicate on profid and not on code, so we must manage this case
610 639
 					{
611 640
 						$duplicate_code_error = true;
641
+				    }
612 642
 						$object->code_fournisseur = null;
613 643
 						$object->code_client = null;
614 644
 					}
@@ -623,21 +653,24 @@  discard block
 block discarded – undo
623 653
 
624 654
                 	if (! empty($backtopage))
625 655
                 	{
626
-                	    if (preg_match('/\?/', $backtopage)) $backtopage.='&socid='.$object->id;
656
+                	    if (preg_match('/\?/', $backtopage)) {
657
+                	        $backtopage.='&socid='.$object->id;
658
+                	    }
627 659
                		    header("Location: ".$backtopage);
628 660
                     	exit;
629
-                	}
630
-                	else
661
+                	} else
631 662
                 	{
632 663
                     	$url=$_SERVER["PHP_SELF"]."?socid=".$object->id;
633
-                    	if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $url=DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
634
-                    	else if ($object->fournisseur == 1) $url=DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
664
+                    	if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
665
+                    	    $url=DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
666
+                    	} else if ($object->fournisseur == 1) {
667
+                    	    $url=DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
668
+                    	}
635 669
 
636 670
                 		header("Location: ".$url);
637 671
                     	exit;
638 672
                 	}
639
-                }
640
-                else
673
+                } else
641 674
                 {
642 675
                     $db->rollback();
643 676
                     $action='create';
@@ -654,8 +687,7 @@  discard block
 block discarded – undo
654 687
                 	{
655 688
                		    header("Location: ".$backtopage);
656 689
                     	exit;
657
-                	}
658
-                	else
690
+                	} else
659 691
                 	{
660 692
                		    header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
661 693
                     	exit;
@@ -663,8 +695,12 @@  discard block
 block discarded – undo
663 695
                 }
664 696
 
665 697
                 // To not set code if third party is not concerned. But if it had values, we keep them.
666
-                if (empty($object->client) && empty($object->oldcopy->code_client))          $object->code_client='';
667
-                if (empty($object->fournisseur)&& empty($object->oldcopy->code_fournisseur)) $object->code_fournisseur='';
698
+                if (empty($object->client) && empty($object->oldcopy->code_client)) {
699
+                    $object->code_client='';
700
+                }
701
+                if (empty($object->fournisseur)&& empty($object->oldcopy->code_fournisseur)) {
702
+                    $object->code_fournisseur='';
703
+                }
668 704
                 //var_dump($object);exit;
669 705
 
670 706
                 $result = $object->update($socid, $user, 1, $object->oldcopy->codeclient_modifiable(), $object->oldcopy->codefournisseur_modifiable(), 'update', 0);
@@ -729,8 +765,7 @@  discard block
 block discarded – undo
729 765
                             if (! $result > 0)
730 766
                             {
731 767
                                 $errors[] = "ErrorFailedToSaveFile";
732
-                            }
733
-                            else
768
+                            } else
734 769
                             {
735 770
                             	// Create thumbs
736 771
                             	$object->addThumbs($newfile);
@@ -746,13 +781,11 @@  discard block
 block discarded – undo
746 781
                                 }
747 782
                             }
748 783
                         }
749
-                    }
750
-                    else
784
+                    } else
751 785
 					{
752 786
                         $errors[] = "ErrorBadImageFormat";
753 787
                     }
754
-                }
755
-                else
788
+                } else
756 789
                 {
757 790
 					switch($_FILES['photo']['error'])
758 791
 					{
@@ -788,21 +821,18 @@  discard block
 block discarded – undo
788 821
                 	{
789 822
                		    header("Location: ".$backtopage);
790 823
                     	exit;
791
-                	}
792
-                	else
824
+                	} else
793 825
                 	{
794 826
                		    header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
795 827
                     	exit;
796 828
                 	}
797
-                }
798
-                else
829
+                } else
799 830
                 {
800 831
                     $object->id = $socid;
801 832
                     $action= "edit";
802 833
                 }
803 834
             }
804
-        }
805
-        else
835
+        } else
806 836
         {
807 837
         	$action = ($action=='add'?'create':'edit');
808 838
         }
@@ -818,8 +848,7 @@  discard block
 block discarded – undo
818 848
         {
819 849
             header("Location: ".DOL_URL_ROOT."/societe/list.php?restore_lastsearch_values=1&delsoc=".urlencode($object->name));
820 850
             exit;
821
-        }
822
-        else
851
+        } else
823 852
         {
824 853
             $langs->load("errors");
825 854
            	setEventMessages($object->error, $object->errors, 'errors');
@@ -872,11 +901,15 @@  discard block
 block discarded – undo
872 901
 if ($socid > 0 && empty($object->id))
873 902
 {
874 903
     $result=$object->fetch($socid);
875
-	if ($result <= 0) dol_print_error('',$object->error);
876
-}
904
+	if ($result <= 0) {
905
+	    dol_print_error('',$object->error);
906
+	}
907
+	}
877 908
 
878 909
 $title=$langs->trans("ThirdParty");
879
-if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$langs->trans('Card');
910
+if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) {
911
+    $title=$object->name." - ".$langs->trans('Card');
912
+}
880 913
 $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
881 914
 llxHeader('',$title,$help_url);
882 915
 
@@ -889,8 +922,7 @@  discard block
 block discarded – undo
889 922
     // -----------------------------------------
890 923
    	$objcanvas->assign_values($action, $object->id, $object->ref);	// Set value for templates
891 924
     $objcanvas->display_canvas($action);							// Show template
892
-}
893
-else
925
+} else
894 926
 {
895 927
     // -----------------------------------------
896 928
     // When used in standard mode
@@ -901,8 +933,12 @@  discard block
 block discarded – undo
901 933
          *  Creation
902 934
          */
903 935
 		$private=GETPOST("private","int");
904
-		if (! empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT) && ! isset($_GET['private']) && ! isset($_POST['private'])) $private=1;
905
-    	if (empty($private)) $private=0;
936
+		if (! empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT) && ! isset($_GET['private']) && ! isset($_POST['private'])) {
937
+		    $private=1;
938
+		}
939
+    	if (empty($private)) {
940
+    	    $private=0;
941
+    	}
906 942
 
907 943
         // Load object modCodeTiers
908 944
         $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
@@ -914,7 +950,9 @@  discard block
 block discarded – undo
914 950
         foreach ($dirsociete as $dirroot)
915 951
         {
916 952
             $res=dol_include_once($dirroot.$module.'.php');
917
-            if ($res) break;
953
+            if ($res) {
954
+                break;
955
+            }
918 956
         }
919 957
         $modCodeClient = new $module;
920 958
         // Load object modCodeFournisseur
@@ -927,7 +965,9 @@  discard block
 block discarded – undo
927 965
         foreach ($dirsociete as $dirroot)
928 966
         {
929 967
             $res=dol_include_once($dirroot.$module.'.php');
930
-            if ($res) break;
968
+            if ($res) {
969
+                break;
970
+            }
931 971
         }
932 972
         $modCodeFournisseur = new $module;
933 973
 
@@ -950,8 +990,7 @@  discard block
 block discarded – undo
950 990
         if(empty($duplicate_code_error)) {
951 991
 	        $object->code_client		= GETPOST('customer_code', 'alpha');
952 992
 	        $object->fournisseur		= GETPOST('fournisseur')?GETPOST('fournisseur'):$object->fournisseur;
953
-        }
954
-		else {
993
+        } else {
955 994
 			setEventMessages($langs->trans('NewCustomerSupplierCodeProposed'),'', 'warnings');
956 995
 		}
957 996
 
@@ -1013,8 +1052,7 @@  discard block
 block discarded – undo
1013 1052
                     if (! $result > 0)
1014 1053
                     {
1015 1054
                         $errors[] = "ErrorFailedToSaveFile";
1016
-                    }
1017
-                    else
1055
+                    } else
1018 1056
                     {
1019 1057
                         // Create thumbs
1020 1058
                         $object->addThumbs($newfile);
@@ -1135,7 +1173,9 @@  discard block
 block discarded – undo
1135 1173
         print '<input type="hidden" name="type" value='.GETPOST("type",'alpha').'>';
1136 1174
         print '<input type="hidden" name="LastName" value="'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName').'">';
1137 1175
         print '<input type="hidden" name="ThirdPartyName" value="'.$langs->trans('ThirdPartyName').'">';
1138
-        if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) print '<input type="hidden" name="code_auto" value="1">';
1176
+        if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) {
1177
+            print '<input type="hidden" name="code_auto" value="1">';
1178
+        }
1139 1179
 
1140 1180
         dol_fiche_head(null, 'card', '', 0, '');
1141 1181
 
@@ -1146,17 +1186,18 @@  discard block
 block discarded – undo
1146 1186
         if ($object->particulier || $private)
1147 1187
         {
1148 1188
 	        print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName','name').'</span>';
1149
-        }
1150
-        else
1189
+        } else
1151 1190
 		{
1152 1191
 			print '<span id="TypeName" class="fieldrequired">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0).'</span>';
1153 1192
         }
1154 1193
 	    print '</td><td'.(empty($conf->global->SOCIETE_USEPREFIX)?' colspan="3"':'').'>';
1155 1194
 	    print '<input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.$object->name.'" autofocus="autofocus"></td>';
1156
-	    if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1195
+	    if (! empty($conf->global->SOCIETE_USEPREFIX)) {
1196
+	        // Old not used prefix field
1157 1197
 	    {
1158 1198
 		    print '<td>'.$langs->trans('Prefix').'</td><td><input type="text" size="5" maxlength="5" name="prefix_comm" value="'.$object->prefix_comm.'"></td>';
1159 1199
 	    }
1200
+	    }
1160 1201
 	    print '</tr>';
1161 1202
 
1162 1203
         // If javascript on, we show option individual
@@ -1180,17 +1221,27 @@  discard block
 block discarded – undo
1180 1221
 	    print '<td class="maxwidthonsmartphone">';
1181 1222
 	    $selected=GETPOST('client','int')!=''?GETPOST('client','int'):$object->client;
1182 1223
         print '<select class="flat" name="client" id="customerprospect">';
1183
-        if (GETPOST("type") == '') print '<option value="-1">&nbsp;</option>';
1184
-        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($selected==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1185
-        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) print '<option value="3"'.($selected==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1186
-        if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($selected==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1224
+        if (GETPOST("type") == '') {
1225
+            print '<option value="-1">&nbsp;</option>';
1226
+        }
1227
+        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
1228
+            print '<option value="2"'.($selected==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1229
+        }
1230
+        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) {
1231
+            print '<option value="3"'.($selected==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1232
+        }
1233
+        if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
1234
+            print '<option value="1"'.($selected==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1235
+        }
1187 1236
         print '<option value="0"'.((string) $selected == '0'?' selected':'').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1188 1237
         print '</select></td>';
1189 1238
 
1190 1239
         print '<td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
1191 1240
         print '<table class="nobordernopadding"><tr><td>';
1192 1241
 		$tmpcode=$object->code_client;
1193
-        if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object,0);
1242
+        if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) {
1243
+            $tmpcode=$modCodeClient->getNextValue($object,0);
1244
+        }
1194 1245
         print '<input type="text" name="customer_code" id="customer_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1195 1246
         print '</td><td>';
1196 1247
         $s=$modCodeClient->getToolTip($langs,$object,0);
@@ -1205,7 +1256,9 @@  discard block
 block discarded – undo
1205 1256
             print '<tr>';
1206 1257
             print '<td>'.$form->editfieldkey('Supplier', 'fournisseur', '', $object, 0, 'string', '', 1).'</td><td>';
1207 1258
             $default = -1;
1208
-            if (! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)) $default=1;
1259
+            if (! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)) {
1260
+                $default=1;
1261
+            }
1209 1262
             print $form->selectyesno("fournisseur", (GETPOST('fournisseur','int')!=''?GETPOST('fournisseur','int'):(GETPOST("type",'alpha') == '' ? $default : $object->fournisseur)), 1, 0, (GETPOST("type",'alpha') == '' ? 1 : 0));
1210 1263
             print '</td>';
1211 1264
             print '<td>';
@@ -1218,7 +1271,9 @@  discard block
 block discarded – undo
1218 1271
             {
1219 1272
 	            print '<table class="nobordernopadding"><tr><td>';
1220 1273
 	            $tmpcode=$object->code_fournisseur;
1221
-	            if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1274
+	            if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) {
1275
+	                $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1276
+	            }
1222 1277
 	            print '<input type="text" name="supplier_code" id="supplier_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1223 1278
 	            print '</td><td>';
1224 1279
 	            $s=$modCodeFournisseur->getToolTip($langs,$object,1);
@@ -1257,7 +1312,9 @@  discard block
 block discarded – undo
1257 1312
         // Country
1258 1313
         print '<tr><td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1259 1314
         print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id));
1260
-        if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1315
+        if ($user->admin) {
1316
+            print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1317
+        }
1261 1318
         print '</td></tr>';
1262 1319
 
1263 1320
         // State
@@ -1266,14 +1323,16 @@  discard block
 block discarded – undo
1266 1323
             if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1267 1324
             {
1268 1325
                 print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1269
-            }
1270
-            else
1326
+            } else
1271 1327
             {
1272 1328
                 print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1273 1329
             }
1274 1330
 
1275
-            if ($object->country_id) print $formcompany->select_state($object->state_id,$object->country_code);
1276
-            else print $countrynotdefined;
1331
+            if ($object->country_id) {
1332
+                print $formcompany->select_state($object->state_id,$object->country_code);
1333
+            } else {
1334
+                print $countrynotdefined;
1335
+            }
1277 1336
             print '</td></tr>';
1278 1337
         }
1279 1338
 
@@ -1326,19 +1385,25 @@  discard block
 block discarded – undo
1326 1385
             {
1327 1386
 	            $key='idprof'.$i;
1328 1387
 
1329
-                if (($j % 2) == 0) print '<tr>';
1388
+                if (($j % 2) == 0) {
1389
+                    print '<tr>';
1390
+                }
1330 1391
 
1331 1392
                 $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
1332 1393
                 print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', (empty($conf->global->$idprof_mandatory)?0:1)).'</td><td>';
1333 1394
 
1334 1395
                 print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
1335 1396
                 print '</td>';
1336
-                if (($j % 2) == 1) print '</tr>';
1397
+                if (($j % 2) == 1) {
1398
+                    print '</tr>';
1399
+                }
1337 1400
                 $j++;
1338 1401
             }
1339 1402
             $i++;
1340 1403
         }
1341
-        if ($j % 2 == 1) print '<td colspan="2"></td></tr>';
1404
+        if ($j % 2 == 1) {
1405
+            print '<td colspan="2"></td></tr>';
1406
+        }
1342 1407
 
1343 1408
         // Vat is used
1344 1409
         print '<tr><td>'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).'</td>';
@@ -1364,8 +1429,7 @@  discard block
 block discarded – undo
1364 1429
                 print "\n";
1365 1430
                 $s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
1366 1431
                 $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
1367
-            }
1368
-            else
1432
+            } else
1369 1433
             {
1370 1434
                 $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
1371 1435
             }
@@ -1383,14 +1447,12 @@  discard block
 block discarded – undo
1383 1447
             print '</td><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
1384 1448
             print $form->selectyesno('localtax2assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0),1);
1385 1449
             print '</td></tr>';
1386
-        }
1387
-        elseif($mysoc->localtax1_assuj=="1")
1450
+        } elseif($mysoc->localtax1_assuj=="1")
1388 1451
         {
1389 1452
             print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td colspan="3">';
1390 1453
             print $form->selectyesno('localtax1assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1:0),1);
1391 1454
             print '</td></tr>';
1392
-        }
1393
-        elseif($mysoc->localtax2_assuj=="1")
1455
+        } elseif($mysoc->localtax2_assuj=="1")
1394 1456
         {
1395 1457
             print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td colspan="3">';
1396 1458
             print $form->selectyesno('localtax2assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0),1);
@@ -1401,11 +1463,15 @@  discard block
 block discarded – undo
1401 1463
         print '<tr><td>'.$form->editfieldkey('ThirdPartyType', 'typent_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">'."\n";
1402 1464
         $sortparam=(empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT); // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on label.
1403 1465
         print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, $sortparam);
1404
-        if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1466
+        if ($user->admin) {
1467
+            print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1468
+        }
1405 1469
         print '</td>';
1406 1470
         print '<td>'.$form->editfieldkey('Staff', 'effectif_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
1407 1471
         print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id);
1408
-        if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1472
+        if ($user->admin) {
1473
+            print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1474
+        }
1409 1475
         print '</td></tr>';
1410 1476
 
1411 1477
         // Legal Form
@@ -1414,8 +1480,7 @@  discard block
 block discarded – undo
1414 1480
         if ($object->country_id)
1415 1481
         {
1416 1482
             print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code');
1417
-        }
1418
-        else
1483
+        } else
1419 1484
         {
1420 1485
             print $countrynotdefined;
1421 1486
         }
@@ -1512,8 +1577,7 @@  discard block
 block discarded – undo
1512 1577
         {
1513 1578
             print ' &nbsp; &nbsp; ';
1514 1579
             print '<input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'">';
1515
-        }
1516
-        else
1580
+        } else
1517 1581
         {
1518 1582
             print ' &nbsp; &nbsp; ';
1519 1583
             print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
@@ -1521,8 +1585,7 @@  discard block
 block discarded – undo
1521 1585
         print '</div>'."\n";
1522 1586
 
1523 1587
         print '</form>'."\n";
1524
-    }
1525
-    elseif ($action == 'edit')
1588
+    } elseif ($action == 'edit')
1526 1589
     {
1527 1590
         //print load_fiche_titre($langs->trans("EditCompany"));
1528 1591
 
@@ -1543,7 +1606,9 @@  discard block
 block discarded – undo
1543 1606
             foreach ($dirsociete as $dirroot)
1544 1607
             {
1545 1608
                 $res=dol_include_once($dirroot.$module.'.php');
1546
-                if ($res) break;
1609
+                if ($res) {
1610
+                    break;
1611
+                }
1547 1612
             }
1548 1613
             $modCodeClient = new $module($db);
1549 1614
             // We verified if the tag prefix is used
@@ -1560,7 +1625,9 @@  discard block
 block discarded – undo
1560 1625
             foreach ($dirsociete as $dirroot)
1561 1626
             {
1562 1627
                 $res=dol_include_once($dirroot.$module.'.php');
1563
-                if ($res) break;
1628
+                if ($res) {
1629
+                    break;
1630
+                }
1564 1631
             }
1565 1632
             $modCodeFournisseur = new $module($db);
1566 1633
             // On verifie si la balise prefix est utilisee
@@ -1638,10 +1705,10 @@  discard block
 block discarded – undo
1638 1705
 
1639 1706
             if($object->localtax1_assuj==0){
1640 1707
             	$sub=0;
1641
-            }else{$sub=1;}
1708
+            } else{$sub=1;}
1642 1709
             if($object->localtax2_assuj==0){
1643 1710
             	$sub2=0;
1644
-            }else{$sub2=1;}
1711
+            } else{$sub2=1;}
1645 1712
 
1646 1713
             if ($conf->use_javascript_ajax)
1647 1714
             {
@@ -1726,7 +1793,9 @@  discard block
 block discarded – undo
1726 1793
             print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1727 1794
             print '<input type="hidden" name="socid" value="'.$object->id.'">';
1728 1795
             print '<input type="hidden" name="entity" value="'.$object->entity.'">';
1729
-            if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) print '<input type="hidden" name="code_auto" value="1">';
1796
+            if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) {
1797
+                print '<input type="hidden" name="code_auto" value="1">';
1798
+            }
1730 1799
 
1731 1800
 
1732 1801
             dol_fiche_head($head, 'card', $langs->trans("ThirdParty"), 0, 'company');
@@ -1751,16 +1820,17 @@  discard block
 block discarded – undo
1751 1820
 	        print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.dol_escape_htmltag($object->name_alias).'"></td></tr>';
1752 1821
 
1753 1822
             // Prefix
1754
-            if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1823
+            if (! empty($conf->global->SOCIETE_USEPREFIX)) {
1824
+                // Old not used prefix field
1755 1825
             {
1756 1826
                 print '<tr><td>'.$form->editfieldkey('Prefix', 'prefix', '', $object, 0).'</td><td colspan="3">';
1827
+            }
1757 1828
                 // It does not change the prefix mode using the auto numbering prefix
1758 1829
                 if (($prefixCustomerIsUsed || $prefixSupplierIsUsed) && $object->prefix_comm)
1759 1830
                 {
1760 1831
                     print '<input type="hidden" name="prefix_comm" value="'.dol_escape_htmltag($object->prefix_comm).'">';
1761 1832
                     print $object->prefix_comm;
1762
-                }
1763
-                else
1833
+                } else
1764 1834
                 {
1765 1835
                     print '<input type="text" size="5" maxlength="5" name="prefix_comm" id="prefix" value="'.dol_escape_htmltag($object->prefix_comm).'">';
1766 1836
                 }
@@ -1770,9 +1840,15 @@  discard block
 block discarded – undo
1770 1840
             // Prospect/Customer
1771 1841
             print '<tr><td>'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).'</td>';
1772 1842
 	        print '<td class="maxwidthonsmartphone"><select class="flat" name="client" id="customerprospect">';
1773
-            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($object->client==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1774
-            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="3"'.($object->client==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1775
-            if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($object->client==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1843
+            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
1844
+                print '<option value="2"'.($object->client==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1845
+            }
1846
+            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
1847
+                print '<option value="3"'.($object->client==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1848
+            }
1849
+            if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
1850
+                print '<option value="1"'.($object->client==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1851
+            }
1776 1852
             print '<option value="0"'.($object->client==0?' selected':'').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1777 1853
             print '</select></td>';
1778 1854
             print '<td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
@@ -1781,15 +1857,18 @@  discard block
 block discarded – undo
1781 1857
             if ((!$object->code_client || $object->code_client == -1) && $modCodeClient->code_auto)
1782 1858
             {
1783 1859
                 $tmpcode=$object->code_client;
1784
-                if (empty($tmpcode) && ! empty($object->oldcopy->code_client)) $tmpcode=$object->oldcopy->code_client; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1785
-                if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object,0);
1860
+                if (empty($tmpcode) && ! empty($object->oldcopy->code_client)) {
1861
+                    $tmpcode=$object->oldcopy->code_client;
1862
+                }
1863
+                // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1864
+                if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) {
1865
+                    $tmpcode=$modCodeClient->getNextValue($object,0);
1866
+                }
1786 1867
                 print '<input type="text" name="customer_code" id="customer_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1787
-            }
1788
-            else if ($object->codeclient_modifiable())
1868
+            } else if ($object->codeclient_modifiable())
1789 1869
             {
1790 1870
             	print '<input type="text" name="customer_code" id="customer_code" size="16" value="'.dol_escape_htmltag($object->code_client).'" maxlength="15">';
1791
-            }
1792
-            else
1871
+            } else
1793 1872
             {
1794 1873
                 print $object->code_client;
1795 1874
                 print '<input type="hidden" name="customer_code" value="'.dol_escape_htmltag($object->code_client).'">';
@@ -1821,15 +1900,18 @@  discard block
 block discarded – undo
1821 1900
 	                if ((!$object->code_fournisseur || $object->code_fournisseur == -1) && $modCodeFournisseur->code_auto)
1822 1901
 	                {
1823 1902
 	                    $tmpcode=$object->code_fournisseur;
1824
-	                    if (empty($tmpcode) && ! empty($object->oldcopy->code_fournisseur)) $tmpcode=$object->oldcopy->code_fournisseur; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1825
-	                    if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1903
+	                    if (empty($tmpcode) && ! empty($object->oldcopy->code_fournisseur)) {
1904
+	                        $tmpcode=$object->oldcopy->code_fournisseur;
1905
+	                    }
1906
+	                    // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1907
+	                    if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) {
1908
+	                        $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1909
+	                    }
1826 1910
 	                    print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1827
-	                }
1828
-	                else if ($object->codefournisseur_modifiable())
1911
+	                } else if ($object->codefournisseur_modifiable())
1829 1912
 	                {
1830 1913
 	                    print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.$object->code_fournisseur.'" maxlength="15">';
1831
-	                }
1832
-	                else
1914
+	                } else
1833 1915
 	              {
1834 1916
 	                    print $object->code_fournisseur;
1835 1917
 	                    print '<input type="hidden" name="supplier_code" value="'.$object->code_fournisseur.'">';
@@ -1871,7 +1953,9 @@  discard block
 block discarded – undo
1871 1953
             // Country
1872 1954
             print '<tr><td>'.$form->editfieldkey('Country', 'selectcounty_id', '', $object, 0).'</td><td colspan="3">';
1873 1955
             print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id),'country_id');
1874
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1956
+            if ($user->admin) {
1957
+                print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1958
+            }
1875 1959
             print '</td></tr>';
1876 1960
 
1877 1961
             // State
@@ -1880,8 +1964,7 @@  discard block
 block discarded – undo
1880 1964
                 if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1881 1965
                 {
1882 1966
                     print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td colspan="3">';
1883
-                }
1884
-                else
1967
+                } else
1885 1968
                 {
1886 1969
                     print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td colspan="3">';
1887 1970
                 }
@@ -1933,18 +2016,24 @@  discard block
 block discarded – undo
1933 2016
                 {
1934 2017
 	                $key='idprof'.$i;
1935 2018
 
1936
-	                if (($j % 2) == 0) print '<tr>';
2019
+	                if (($j % 2) == 0) {
2020
+	                    print '<tr>';
2021
+	                }
1937 2022
 
1938 2023
 	                $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
1939 2024
 	                print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', ! (empty($conf->global->$idprof_mandatory) || ! $object->isACompany())).'</td><td>';
1940 2025
 	                print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
1941 2026
                     print '</td>';
1942
-                    if (($j % 2) == 1) print '</tr>';
2027
+                    if (($j % 2) == 1) {
2028
+                        print '</tr>';
2029
+                    }
1943 2030
                     $j++;
1944 2031
                 }
1945 2032
                 $i++;
1946 2033
             }
1947
-            if ($j % 2 == 1) print '<td colspan="2"></td></tr>';
2034
+            if ($j % 2 == 1) {
2035
+                print '<td colspan="2"></td></tr>';
2036
+            }
1948 2037
 
1949 2038
             // VAT is used
1950 2039
             print '<tr><td>'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).'</td><td colspan="3">';
@@ -1974,8 +2063,7 @@  discard block
 block discarded – undo
1974 2063
                     print '</span>';
1975 2064
                 }
1976 2065
                 print '</td></tr>';
1977
-            }
1978
-            elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
2066
+            } elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
1979 2067
             {
1980 2068
                 print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed",$mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td colspan="3">';
1981 2069
                 print $form->selectyesno('localtax1assuj_value',$object->localtax1_assuj,1);
@@ -1986,8 +2074,7 @@  discard block
 block discarded – undo
1986 2074
                     print '</span>';
1987 2075
                 }
1988 2076
                 print '</td></tr>';
1989
-            }
1990
-            elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
2077
+            } elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
1991 2078
             {
1992 2079
                 print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed",$mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td colspan="3">';
1993 2080
                 print $form->selectyesno('localtax2assuj_value',$object->localtax2_assuj,1);
@@ -2020,8 +2107,7 @@  discard block
 block discarded – undo
2020 2107
                     print "\n";
2021 2108
                     $s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
2022 2109
                     $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
2023
-                }
2024
-                else
2110
+                } else
2025 2111
                 {
2026 2112
                     $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
2027 2113
                 }
@@ -2033,11 +2119,15 @@  discard block
 block discarded – undo
2033 2119
             // Type - Size
2034 2120
             print '<tr><td>'.$form->editfieldkey('ThirdPartyType', 'typent_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
2035 2121
             print $form->selectarray("typent_id",$formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
2036
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
2122
+            if ($user->admin) {
2123
+                print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
2124
+            }
2037 2125
             print '</td>';
2038 2126
             print '<td>'.$form->editfieldkey('Staff', 'effectif_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
2039 2127
             print $form->selectarray("effectif_id",$formcompany->effectif_array(0), $object->effectif_id);
2040
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
2128
+            if ($user->admin) {
2129
+                print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
2130
+            }
2041 2131
             print '</td></tr>';
2042 2132
 
2043 2133
             // Juridical type
@@ -2131,13 +2221,19 @@  discard block
 block discarded – undo
2131 2221
             print '<tr class="hideonsmartphone">';
2132 2222
             print '<td>'.$form->editfieldkey('Logo', 'photoinput', '', $object, 0).'</td>';
2133 2223
             print '<td colspan="3">';
2134
-            if ($object->logo) print $form->showphoto('societe',$object);
2224
+            if ($object->logo) {
2225
+                print $form->showphoto('societe',$object);
2226
+            }
2135 2227
             $caneditfield=1;
2136 2228
             if ($caneditfield)
2137 2229
             {
2138
-                if ($object->logo) print "<br>\n";
2230
+                if ($object->logo) {
2231
+                    print "<br>\n";
2232
+                }
2139 2233
                 print '<table class="nobordernopadding">';
2140
-                if ($object->logo) print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
2234
+                if ($object->logo) {
2235
+                    print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
2236
+                }
2141 2237
                 //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
2142 2238
                 print '<tr><td><input type="file" class="flat" name="photo" id="photoinput"></td></tr>';
2143 2239
                 print '</table>';
@@ -2151,7 +2247,9 @@  discard block
 block discarded – undo
2151 2247
             print '<td colspan="3" class="maxwidthonsmartphone">';
2152 2248
             $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, '', 0, '', '', 0, 1);
2153 2249
             $arrayselected = GETPOST('commercial', 'array');
2154
-            if (empty($arrayselected)) $arrayselected = $object->getSalesRepresentatives($user, 1);
2250
+            if (empty($arrayselected)) {
2251
+                $arrayselected = $object->getSalesRepresentatives($user, 1);
2252
+            }
2155 2253
             print $form->multiselectarray('commercial', $userlist, $arrayselected, null, null, null, null, "90%");
2156 2254
             print '</td></tr>';
2157 2255
 
@@ -2168,14 +2266,15 @@  discard block
 block discarded – undo
2168 2266
 
2169 2267
             print '</form>';
2170 2268
         }
2171
-    }
2172
-    else
2269
+    } else
2173 2270
     {
2174 2271
     	/*
2175 2272
          * View
2176 2273
          */
2177 2274
 
2178
-        if (!empty($object->id)) $res=$object->fetch_optionals();
2275
+        if (!empty($object->id)) {
2276
+            $res=$object->fetch_optionals();
2277
+        }
2179 2278
         //if ($res < 0) { dol_print_error($db); exit; }
2180 2279
 
2181 2280
 
@@ -2230,9 +2329,11 @@  discard block
 block discarded – undo
2230 2329
     	}
2231 2330
 
2232 2331
     	// Prefix
2233
-        if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
2332
+        if (! empty($conf->global->SOCIETE_USEPREFIX)) {
2333
+            // Old not used prefix field
2234 2334
         {
2235 2335
             print '<tr><td>'.$langs->trans('Prefix').'</td><td>'.$object->prefix_comm.'</td>';
2336
+        }
2236 2337
             print $htmllogobar; $htmllogobar='';
2237 2338
             print '</tr>';
2238 2339
         }
@@ -2243,7 +2344,9 @@  discard block
 block discarded – undo
2243 2344
             print '<tr><td>';
2244 2345
             print $langs->trans('CustomerCode').'</td><td>';
2245 2346
             print $object->code_client;
2246
-            if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
2347
+            if ($object->check_codeclient() <> 0) {
2348
+                print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
2349
+            }
2247 2350
             print '</td>';
2248 2351
             print $htmllogobar; $htmllogobar='';
2249 2352
             print '</tr>';
@@ -2255,7 +2358,9 @@  discard block
 block discarded – undo
2255 2358
             print '<tr><td>';
2256 2359
             print $langs->trans('SupplierCode').'</td><td>';
2257 2360
             print $object->code_fournisseur;
2258
-            if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
2361
+            if ($object->check_codefournisseur() <> 0) {
2362
+                print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
2363
+            }
2259 2364
             print '</td>';
2260 2365
             print $htmllogobar; $htmllogobar='';
2261 2366
             print '</tr>';
@@ -2267,7 +2372,9 @@  discard block
 block discarded – undo
2267 2372
             print '<tr><td>';
2268 2373
             print $langs->trans('Gencod').'</td><td>'.$object->barcode;
2269 2374
             print '</td>';
2270
-			if ($htmllogobar) $htmllogobar.=$form->showbarcode($object);
2375
+			if ($htmllogobar) {
2376
+			    $htmllogobar.=$form->showbarcode($object);
2377
+			}
2271 2378
             print $htmllogobar;
2272 2379
 			$htmllogobar='';
2273 2380
             print '</tr>';
@@ -2287,8 +2394,11 @@  discard block
 block discarded – undo
2287 2394
                 print $object->$key;
2288 2395
                 if ($object->$key)
2289 2396
                 {
2290
-                    if ($object->id_prof_check($i,$object) > 0) print ' &nbsp; '.$object->id_prof_url($i,$object);
2291
-                    else print ' <font class="error">('.$langs->trans("ErrorWrongValue").')</font>';
2397
+                    if ($object->id_prof_check($i,$object) > 0) {
2398
+                        print ' &nbsp; '.$object->id_prof_url($i,$object);
2399
+                    } else {
2400
+                        print ' <font class="error">('.$langs->trans("ErrorWrongValue").')</font>';
2401
+                    }
2292 2402
                 }
2293 2403
                 print '</td>';
2294 2404
                 //if (($j % 2) == 1) print '</tr>';
@@ -2337,8 +2447,7 @@  discard block
 block discarded – undo
2337 2447
 			            print '<td align="left">';
2338 2448
 			            $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2339 2449
 			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2340
-			        }
2341
-			        else
2450
+			        } else
2342 2451
 			        {
2343 2452
 			            print '<td>'.$object->localtax1_value.'</td>';
2344 2453
 			        }
@@ -2354,13 +2463,12 @@  discard block
 block discarded – undo
2354 2463
 			            print '<td align="left">';
2355 2464
 			            $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2356 2465
 			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2357
-			        }else{
2466
+			        } else{
2358 2467
 			            print '<td>'.$object->localtax2_value.'</td>';
2359 2468
 			        }
2360 2469
 			        print '</tr></form>';
2361 2470
 			    }
2362
-			}
2363
-			elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
2471
+			} elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
2364 2472
 			{
2365 2473
 			    print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
2366 2474
 			    print yn($object->localtax1_assuj);
@@ -2375,13 +2483,12 @@  discard block
 block discarded – undo
2375 2483
 			            print '<td align="left">';
2376 2484
 			            $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2377 2485
 			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2378
-			        }else{
2486
+			        } else{
2379 2487
 			            print '<td>'.$object->localtax1_value.'</td>';
2380 2488
 			        }
2381 2489
 			        print '</tr></form>';
2382 2490
 			    }
2383
-			}
2384
-			elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
2491
+			} elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
2385 2492
 			{
2386 2493
 			    print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
2387 2494
 			    print yn($object->localtax2_assuj);
@@ -2397,7 +2504,7 @@  discard block
 block discarded – undo
2397 2504
 			            print '<td align="left">';
2398 2505
 			            $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2399 2506
 			            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2400
-			        }else{
2507
+			        } else{
2401 2508
 			            print '<td>'.$object->localtax2_value.'</td>';
2402 2509
 			        }
2403 2510
 			        print '</tr></form>';
@@ -2429,15 +2536,13 @@  discard block
 block discarded – undo
2429 2536
                     print "\n";
2430 2537
                     $s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT( $(\'#tva_intra\').val() );">'.$langs->trans("VATIntraCheck").'</a>';
2431 2538
                     $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
2432
-                }
2433
-                else
2539
+                } else
2434 2540
                 {
2435 2541
                     $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
2436 2542
                 }
2437 2543
             }
2438 2544
             print $s;
2439
-        }
2440
-        else
2545
+        } else
2441 2546
         {
2442 2547
             print '&nbsp;';
2443 2548
         }
@@ -2483,8 +2588,11 @@  discard block
 block discarded – undo
2483 2588
 
2484 2589
         // Capital
2485 2590
         print '<tr><td>'.$langs->trans('Capital').'</td><td>';
2486
-        if ($object->capital) print price($object->capital,'',$langs,0,-1,-1, $conf->currency);
2487
-        else print '&nbsp;';
2591
+        if ($object->capital) {
2592
+            print price($object->capital,'',$langs,0,-1,-1, $conf->currency);
2593
+        } else {
2594
+            print '&nbsp;';
2595
+        }
2488 2596
         print '</td></tr>';
2489 2597
 
2490 2598
         // Default language
@@ -2507,16 +2615,18 @@  discard block
 block discarded – undo
2507 2615
         	print '<table width="100%" class="nobordernopadding"><tr><td>';
2508 2616
         	print $langs->trans('IncotermLabel');
2509 2617
         	print '<td><td align="right">';
2510
-        	if ($user->rights->societe->creer) print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$object->id.'&action=editincoterm">'.img_edit('',1).'</a>';
2511
-        	else print '&nbsp;';
2618
+        	if ($user->rights->societe->creer) {
2619
+        	    print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$object->id.'&action=editincoterm">'.img_edit('',1).'</a>';
2620
+        	} else {
2621
+        	    print '&nbsp;';
2622
+        	}
2512 2623
         	print '</td></tr></table>';
2513 2624
         	print '</td>';
2514 2625
         	print '<td colspan="3">';
2515 2626
         	if ($action != 'editincoterm')
2516 2627
         	{
2517 2628
         		print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1);
2518
-        	}
2519
-        	else
2629
+        	} else
2520 2630
         	{
2521 2631
         		print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?socid='.$object->id);
2522 2632
         	}
@@ -2545,14 +2655,15 @@  discard block
 block discarded – undo
2545 2655
         	print '<table class="nobordernopadding" width="100%"><tr><td>';
2546 2656
         	print $langs->trans('ParentCompany');
2547 2657
         	print '</td>';
2548
-        	if ($action != 'editparentcompany') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</a></td>';
2658
+        	if ($action != 'editparentcompany') {
2659
+        	    print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</a></td>';
2660
+        	}
2549 2661
         	print '</tr></table>';
2550 2662
         	print '</td><td colspan="3">';
2551 2663
         	if ($action == 'editparentcompany')
2552 2664
         	{
2553 2665
         		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'editparentcompany','s.rowid <> '.$object->id,1);
2554
-        	}
2555
-        	else
2666
+        	} else
2556 2667
         	{
2557 2668
         		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'none','s.rowid <> '.$object->id,1);
2558 2669
         	}
@@ -2575,8 +2686,7 @@  discard block
 block discarded – undo
2575 2686
             {
2576 2687
                 $adh->ref=$adh->getFullName($langs);
2577 2688
                 print $adh->getNomUrl(1);
2578
-            }
2579
-            else
2689
+            } else
2580 2690
             {
2581 2691
                 print '<span class="opacitymedium">'.$langs->trans("ThirdpartyNotLinkedToMember").'</span>';
2582 2692
             }
@@ -2625,8 +2735,7 @@  discard block
 block discarded – undo
2625 2735
 		        {
2626 2736
 		        	$langs->load("mails");
2627 2737
 		        	print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'&amp;action=presend&amp;mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';
2628
-		        }
2629
-		        else
2738
+		        } else
2630 2739
 				{
2631 2740
 		        	$langs->load("mails");
2632 2741
 		       		print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans('SendMail').'</a></div>';
@@ -2644,11 +2753,12 @@  discard block
 block discarded – undo
2644 2753
 
2645 2754
 		        if ($user->rights->societe->supprimer)
2646 2755
 		        {
2647
-		            if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))	// We can't use preloaded confirm form with jmobile
2756
+		            if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)) {
2757
+		                // We can't use preloaded confirm form with jmobile
2648 2758
 		            {
2649 2759
 		                print '<div class="inline-block divButAction"><span id="action-delete" class="butActionDelete">'.$langs->trans('Delete').'</span></div>'."\n";
2650 2760
 		            }
2651
-		            else
2761
+		            } else
2652 2762
 					{
2653 2763
 		                print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a></div>'."\n";
2654 2764
 		            }
Please login to merge, or discard this patch.
dolibarr/htdocs/societe/ajaxcompanies.php 2 patches
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -23,12 +23,12 @@  discard block
 block discarded – undo
23 23
  *       \brief      File to return Ajax response on third parties request
24 24
  */
25 25
 
26
-if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal
27
-if (! defined('NOREQUIREMENU'))  define('NOREQUIREMENU','1');
28
-if (! defined('NOREQUIREHTML'))  define('NOREQUIREHTML','1');
29
-if (! defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX','1');
30
-if (! defined('NOREQUIRESOC'))   define('NOREQUIRESOC','1');
31
-if (! defined('NOCSRFCHECK'))    define('NOCSRFCHECK','1');
26
+if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); // Disables token renewal
27
+if (!defined('NOREQUIREMENU'))  define('NOREQUIREMENU', '1');
28
+if (!defined('NOREQUIREHTML'))  define('NOREQUIREHTML', '1');
29
+if (!defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX', '1');
30
+if (!defined('NOREQUIRESOC'))   define('NOREQUIRESOC', '1');
31
+if (!defined('NOCSRFCHECK'))    define('NOCSRFCHECK', '1');
32 32
 
33 33
 require '../main.inc.php';
34 34
 
@@ -46,67 +46,67 @@  discard block
 block discarded – undo
46 46
 
47 47
 //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
48 48
 
49
-dol_syslog(join(',',$_GET));
49
+dol_syslog(join(',', $_GET));
50 50
 
51 51
 
52 52
 // Generation liste des societes
53
-if (GETPOST('newcompany') || GETPOST('socid','int') || GETPOST('id_fourn'))
53
+if (GETPOST('newcompany') || GETPOST('socid', 'int') || GETPOST('id_fourn'))
54 54
 {
55 55
 	$return_arr = array();
56 56
 
57 57
 	// Define filter on text typed
58
-	$socid = $_GET['newcompany']?$_GET['newcompany']:'';
59
-	if (! $socid) $socid = $_GET['socid']?$_GET['socid']:'';
60
-	if (! $socid) $socid = $_GET['id_fourn']?$_GET['id_fourn']:'';
58
+	$socid = $_GET['newcompany'] ? $_GET['newcompany'] : '';
59
+	if (!$socid) $socid = $_GET['socid'] ? $_GET['socid'] : '';
60
+	if (!$socid) $socid = $_GET['id_fourn'] ? $_GET['id_fourn'] : '';
61 61
 
62 62
 	$sql = "SELECT rowid, nom";
63
-	$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
64
-	$sql.= " WHERE s.entity IN (".getEntity('societe').")";
63
+	$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
64
+	$sql .= " WHERE s.entity IN (".getEntity('societe').")";
65 65
 	if ($socid)
66 66
 	{
67
-        $sql.=" AND (";
67
+        $sql .= " AND (";
68 68
         // Add criteria on name/code
69
-        if (! empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE))   // Can use index
69
+        if (!empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE))   // Can use index
70 70
         {
71
-            $sql.="nom LIKE '" . $db->escape($socid) . "%'";
72
-            $sql.=" OR code_client LIKE '" . $db->escape($socid) . "%'";
73
-            $sql.=" OR code_fournisseur LIKE '" . $db->escape($socid) . "%'";
71
+            $sql .= "nom LIKE '".$db->escape($socid)."%'";
72
+            $sql .= " OR code_client LIKE '".$db->escape($socid)."%'";
73
+            $sql .= " OR code_fournisseur LIKE '".$db->escape($socid)."%'";
74 74
         }
75 75
         else
76 76
         {
77
-    		$sql.="nom LIKE '%" . $db->escape($socid) . "%'";
78
-    		$sql.=" OR code_client LIKE '%" . $db->escape($socid) . "%'";
79
-    		$sql.=" OR code_fournisseur LIKE '%" . $db->escape($socid) . "%'";
77
+    		$sql .= "nom LIKE '%".$db->escape($socid)."%'";
78
+    		$sql .= " OR code_client LIKE '%".$db->escape($socid)."%'";
79
+    		$sql .= " OR code_fournisseur LIKE '%".$db->escape($socid)."%'";
80 80
         }
81
-		if (! empty($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID)) $sql.=" OR rowid = '" . $db->escape($socid) . "'";
82
-		$sql.=")";
81
+		if (!empty($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID)) $sql .= " OR rowid = '".$db->escape($socid)."'";
82
+		$sql .= ")";
83 83
 	}
84
-	if (GETPOST("filter")) $sql.= " AND ".GETPOST("filter","alpha"); // Add other filters
85
-	$sql.= " ORDER BY nom ASC";
84
+	if (GETPOST("filter")) $sql .= " AND ".GETPOST("filter", "alpha"); // Add other filters
85
+	$sql .= " ORDER BY nom ASC";
86 86
 
87 87
 	//dol_syslog("ajaxcompanies", LOG_DEBUG);
88
-	$resql=$db->query($sql);
88
+	$resql = $db->query($sql);
89 89
 	if ($resql)
90 90
 	{
91 91
 		while ($row = $db->fetch_array($resql))
92 92
 		{
93
-		    $label=$row['nom'];
94
-		    if ($socid) $label=preg_replace('/('.preg_quote($socid,'/').')/i','<strong>$1</strong>',$label,1);
93
+		    $label = $row['nom'];
94
+		    if ($socid) $label = preg_replace('/('.preg_quote($socid, '/').')/i', '<strong>$1</strong>', $label, 1);
95 95
 			$row_array['label'] = $label;
96 96
 			$row_array['value'] = $row['nom'];
97 97
 	        $row_array['key'] = $row['rowid'];
98 98
 
99
-	        array_push($return_arr,$row_array);
99
+	        array_push($return_arr, $row_array);
100 100
 	    }
101 101
 
102 102
 	    echo json_encode($return_arr);
103 103
 	}
104 104
 	else
105 105
 	{
106
-	    echo json_encode(array('nom'=>'Error','label'=>'Error','key'=>'Error','value'=>'Error'));
106
+	    echo json_encode(array('nom'=>'Error', 'label'=>'Error', 'key'=>'Error', 'value'=>'Error'));
107 107
 	}
108 108
 }
109 109
 else
110 110
 {
111
-    echo json_encode(array('nom'=>'ErrorBadParameter','label'=>'ErrorBadParameter','key'=>'ErrorBadParameter','value'=>'ErrorBadParameter'));
111
+    echo json_encode(array('nom'=>'ErrorBadParameter', 'label'=>'ErrorBadParameter', 'key'=>'ErrorBadParameter', 'value'=>'ErrorBadParameter'));
112 112
 }
Please login to merge, or discard this patch.
Braces   +41 added lines, -18 removed lines patch added patch discarded remove patch
@@ -23,12 +23,25 @@  discard block
 block discarded – undo
23 23
  *       \brief      File to return Ajax response on third parties request
24 24
  */
25 25
 
26
-if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal
27
-if (! defined('NOREQUIREMENU'))  define('NOREQUIREMENU','1');
28
-if (! defined('NOREQUIREHTML'))  define('NOREQUIREHTML','1');
29
-if (! defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX','1');
30
-if (! defined('NOREQUIRESOC'))   define('NOREQUIRESOC','1');
31
-if (! defined('NOCSRFCHECK'))    define('NOCSRFCHECK','1');
26
+if (! defined('NOTOKENRENEWAL')) {
27
+    define('NOTOKENRENEWAL',1);
28
+}
29
+// Disables token renewal
30
+if (! defined('NOREQUIREMENU')) {
31
+    define('NOREQUIREMENU','1');
32
+}
33
+if (! defined('NOREQUIREHTML')) {
34
+    define('NOREQUIREHTML','1');
35
+}
36
+if (! defined('NOREQUIREAJAX')) {
37
+    define('NOREQUIREAJAX','1');
38
+}
39
+if (! defined('NOREQUIRESOC')) {
40
+    define('NOREQUIRESOC','1');
41
+}
42
+if (! defined('NOCSRFCHECK')) {
43
+    define('NOCSRFCHECK','1');
44
+}
32 45
 
33 46
 require '../main.inc.php';
34 47
 
@@ -56,8 +69,12 @@  discard block
 block discarded – undo
56 69
 
57 70
 	// Define filter on text typed
58 71
 	$socid = $_GET['newcompany']?$_GET['newcompany']:'';
59
-	if (! $socid) $socid = $_GET['socid']?$_GET['socid']:'';
60
-	if (! $socid) $socid = $_GET['id_fourn']?$_GET['id_fourn']:'';
72
+	if (! $socid) {
73
+	    $socid = $_GET['socid']?$_GET['socid']:'';
74
+	}
75
+	if (! $socid) {
76
+	    $socid = $_GET['id_fourn']?$_GET['id_fourn']:'';
77
+	}
61 78
 
62 79
 	$sql = "SELECT rowid, nom";
63 80
 	$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
@@ -66,22 +83,28 @@  discard block
 block discarded – undo
66 83
 	{
67 84
         $sql.=" AND (";
68 85
         // Add criteria on name/code
69
-        if (! empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE))   // Can use index
86
+        if (! empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE)) {
87
+            // Can use index
70 88
         {
71 89
             $sql.="nom LIKE '" . $db->escape($socid) . "%'";
90
+        }
72 91
             $sql.=" OR code_client LIKE '" . $db->escape($socid) . "%'";
73 92
             $sql.=" OR code_fournisseur LIKE '" . $db->escape($socid) . "%'";
74
-        }
75
-        else
93
+        } else
76 94
         {
77 95
     		$sql.="nom LIKE '%" . $db->escape($socid) . "%'";
78 96
     		$sql.=" OR code_client LIKE '%" . $db->escape($socid) . "%'";
79 97
     		$sql.=" OR code_fournisseur LIKE '%" . $db->escape($socid) . "%'";
80 98
         }
81
-		if (! empty($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID)) $sql.=" OR rowid = '" . $db->escape($socid) . "'";
99
+		if (! empty($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID)) {
100
+		    $sql.=" OR rowid = '" . $db->escape($socid) . "'";
101
+		}
82 102
 		$sql.=")";
83 103
 	}
84
-	if (GETPOST("filter")) $sql.= " AND ".GETPOST("filter","alpha"); // Add other filters
104
+	if (GETPOST("filter")) {
105
+	    $sql.= " AND ".GETPOST("filter","alpha");
106
+	}
107
+	// Add other filters
85 108
 	$sql.= " ORDER BY nom ASC";
86 109
 
87 110
 	//dol_syslog("ajaxcompanies", LOG_DEBUG);
@@ -91,7 +114,9 @@  discard block
 block discarded – undo
91 114
 		while ($row = $db->fetch_array($resql))
92 115
 		{
93 116
 		    $label=$row['nom'];
94
-		    if ($socid) $label=preg_replace('/('.preg_quote($socid,'/').')/i','<strong>$1</strong>',$label,1);
117
+		    if ($socid) {
118
+		        $label=preg_replace('/('.preg_quote($socid,'/').')/i','<strong>$1</strong>',$label,1);
119
+		    }
95 120
 			$row_array['label'] = $label;
96 121
 			$row_array['value'] = $row['nom'];
97 122
 	        $row_array['key'] = $row['rowid'];
@@ -100,13 +125,11 @@  discard block
 block discarded – undo
100 125
 	    }
101 126
 
102 127
 	    echo json_encode($return_arr);
103
-	}
104
-	else
128
+	} else
105 129
 	{
106 130
 	    echo json_encode(array('nom'=>'Error','label'=>'Error','key'=>'Error','value'=>'Error'));
107 131
 	}
108
-}
109
-else
132
+} else
110 133
 {
111 134
     echo json_encode(array('nom'=>'ErrorBadParameter','label'=>'ErrorBadParameter','key'=>'ErrorBadParameter','value'=>'ErrorBadParameter'));
112 135
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/societe/document.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -34,9 +34,9 @@  discard block
 block discarded – undo
34 34
 
35 35
 $langs->loadLangs(array("companies", "other"));
36 36
 
37
-$action=GETPOST('action','aZ09');
38
-$confirm=GETPOST('confirm');
39
-$id=(GETPOST('socid','int') ? GETPOST('socid','int') : GETPOST('id','int'));
37
+$action = GETPOST('action', 'aZ09');
38
+$confirm = GETPOST('confirm');
39
+$id = (GETPOST('socid', 'int') ? GETPOST('socid', 'int') : GETPOST('id', 'int'));
40 40
 $ref = GETPOST('ref', 'alpha');
41 41
 
42 42
 // Security check
@@ -48,27 +48,27 @@  discard block
 block discarded – undo
48 48
 $result = restrictedArea($user, 'societe', $id, '&societe');
49 49
 
50 50
 // Get parameters
51
-$sortfield = GETPOST("sortfield",'alpha');
52
-$sortorder = GETPOST("sortorder",'alpha');
53
-$page = GETPOST("page",'int');
51
+$sortfield = GETPOST("sortfield", 'alpha');
52
+$sortorder = GETPOST("sortorder", 'alpha');
53
+$page = GETPOST("page", 'int');
54 54
 if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
55 55
 $offset = $conf->liste_limit * $page;
56 56
 $pageprev = $page - 1;
57 57
 $pagenext = $page + 1;
58
-if (! $sortorder) $sortorder="ASC";
59
-if (! $sortfield) $sortfield="position_name";
58
+if (!$sortorder) $sortorder = "ASC";
59
+if (!$sortfield) $sortfield = "position_name";
60 60
 
61 61
 $object = new Societe($db);
62
-if ($id > 0 || ! empty($ref))
62
+if ($id > 0 || !empty($ref))
63 63
 {
64 64
 	$result = $object->fetch($id, $ref);
65 65
 
66
-	$upload_dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->id ;
67
-	$courrier_dir = $conf->societe->multidir_output[$object->entity] . "/courrier/" . get_exdir($object->id,0,0,0,$object,'thirdparty');
66
+	$upload_dir = $conf->societe->multidir_output[$object->entity]."/".$object->id;
67
+	$courrier_dir = $conf->societe->multidir_output[$object->entity]."/courrier/".get_exdir($object->id, 0, 0, 0, $object, 'thirdparty');
68 68
 }
69 69
 
70 70
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
71
-$hookmanager->initHooks(array('thirdpartydocument','globalcard'));
71
+$hookmanager->initHooks(array('thirdpartydocument', 'globalcard'));
72 72
 
73 73
 
74 74
 
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
  * Actions
77 77
  */
78 78
 
79
-include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
79
+include_once DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
80 80
 
81 81
 
82 82
 /*
@@ -85,35 +85,35 @@  discard block
 block discarded – undo
85 85
 
86 86
 $form = new Form($db);
87 87
 
88
-$title=$langs->trans("ThirdParty").' - '.$langs->trans("Files");
89
-if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name.' - '.$langs->trans("Files");
90
-$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
91
-llxHeader('',$title,$help_url);
88
+$title = $langs->trans("ThirdParty").' - '.$langs->trans("Files");
89
+if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->name.' - '.$langs->trans("Files");
90
+$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
91
+llxHeader('', $title, $help_url);
92 92
 
93 93
 if ($object->id)
94 94
 {
95 95
 	/*
96 96
 	 * Show tabs
97 97
 	 */
98
-	if (! empty($conf->notification->enabled)) $langs->load("mails");
98
+	if (!empty($conf->notification->enabled)) $langs->load("mails");
99 99
 	$head = societe_prepare_head($object);
100 100
 
101
-	$form=new Form($db);
101
+	$form = new Form($db);
102 102
 
103 103
 	dol_fiche_head($head, 'document', $langs->trans("ThirdParty"), -1, 'company');
104 104
 
105 105
 
106 106
 	// Build file list
107
-	$filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
108
-	$totalsize=0;
109
-	foreach($filearray as $key => $file)
107
+	$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
108
+	$totalsize = 0;
109
+	foreach ($filearray as $key => $file)
110 110
 	{
111
-		$totalsize+=$file['size'];
111
+		$totalsize += $file['size'];
112 112
 	}
113 113
 
114 114
     $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
115 115
 
116
-    dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
116
+    dol_banner_tab($object, 'socid', $linkback, ($user->societe_id ? 0 : 1), 'rowid', 'nom');
117 117
 
118 118
     print '<div class="fichecenter">';
119 119
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	print '<table class="border centpercent">';
122 122
 
123 123
 	// Prefix
124
-	if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
124
+	if (!empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
125 125
 	{
126 126
 		print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
127 127
 	}
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 	print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
149 149
 
150 150
 	// Total size
151
-	print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize,1,1).'</td></tr>';
151
+	print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
152 152
 
153 153
 	print '</table>';
154 154
 
@@ -159,12 +159,12 @@  discard block
 block discarded – undo
159 159
 	$modulepart = 'societe';
160 160
 	$permission = $user->rights->societe->creer;
161 161
 	$permtoedit = $user->rights->societe->creer;
162
-	$param = '&id=' . $object->id;
163
-	include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
162
+	$param = '&id='.$object->id;
163
+	include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
164 164
 }
165 165
 else
166 166
 {
167
-	accessforbidden('',0,0);
167
+	accessforbidden('', 0, 0);
168 168
 }
169 169
 
170 170
 // End of page
Please login to merge, or discard this patch.