Passed
Branch develop (e2dd44)
by
unknown
106:32
created

showSocialNetwork()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 38
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 7
eloc 18
nc 5
nop 0
dl 0
loc 38
rs 8.8333
c 2
b 0
f 0
1
<?php
2
/* Copyright (C) 2001-2007  Rodolphe Quiedeville    <[email protected]>
3
 * Copyright (C) 2003       Brian Fraval            <[email protected]>
4
 * Copyright (C) 2004-2015  Laurent Destailleur     <[email protected]>
5
 * Copyright (C) 2005       Eric Seigne             <[email protected]>
6
 * Copyright (C) 2005-2017  Regis Houssin           <[email protected]>
7
 * Copyright (C) 2008       Patrick Raguin          <[email protected]>
8
 * Copyright (C) 2010-2020  Juanjo Menent           <[email protected]>
9
 * Copyright (C) 2011-2022  Alexandre Spangaro      <[email protected]>
10
 * Copyright (C) 2015       Jean-François Ferry     <[email protected]>
11
 * Copyright (C) 2015       Marcos García           <[email protected]>
12
 * Copyright (C) 2015       Raphaël Doursenaud      <[email protected]>
13
 * Copyright (C) 2018       Nicolas ZABOURI	        <[email protected]>
14
 * Copyright (C) 2018       Ferran Marcet		    <[email protected]>
15
 * Copyright (C) 2018-2022  Frédéric France         <[email protected]>
16
 *
17
 * This program is free software; you can redistribute it and/or modify
18
 * it under the terms of the GNU General Public License as published by
19
 * the Free Software Foundation; either version 3 of the License, or
20
 * (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU General Public License
28
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
29
 */
30
31
/**
32
 *  \file       htdocs/societe/card.php
33
 *  \ingroup    societe
34
 *  \brief      Third party card page
35
 */
36
37
38
// Load Dolibarr environment
39
require '../main.inc.php';
40
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
41
require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
42
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
43
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
44
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
45
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
46
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
47
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
48
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
49
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
50
if (isModEnabled('adherent')) {
51
	require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
52
}
53
if (isModEnabled('accounting')) {
54
	require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
55
}
56
if (isModEnabled('accounting')) {
57
	require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
58
}
59
if (isModEnabled('accounting')) {
60
	require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
61
}
62
if (isModEnabled('eventorganization')) {
63
	require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorboothattendee.class.php';
64
}
65
66
67
// Load translation files required by the page
68
69
$langs->loadLangs(array("companies", "commercial", "bills", "banks", "users"));
70
71
if (isModEnabled('adherent')) {
72
	$langs->load("members");
73
}
74
if (isModEnabled('categorie')) {
75
	$langs->load("categories");
76
}
77
if (isModEnabled('incoterm')) {
78
	$langs->load("incoterm");
79
}
80
if (isModEnabled('notification')) {
81
	$langs->load("mails");
82
}
83
if (isModEnabled('accounting')) {
84
	$langs->load("products");
85
}
86
87
$error = 0; $errors = array();
88
89
90
// Get parameters
91
$action		= (GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view');
92
$cancel		= GETPOST('cancel', 'alpha');
93
$backtopage = GETPOST('backtopage', 'alpha');
94
$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
95
$backtopagejsfields = GETPOST('backtopagejsfields', 'alpha');
96
$confirm 	= GETPOST('confirm', 'alpha');
97
98
$dol_openinpopup = '';
99
if (!empty($backtopagejsfields)) {
100
	$tmpbacktopagejsfields = explode(':', $backtopagejsfields);
101
	$dol_openinpopup = $tmpbacktopagejsfields[0];
102
}
103
104
$socid = GETPOST('socid', 'int') ?GETPOST('socid', 'int') : GETPOST('id', 'int');
105
if ($user->socid) {
106
	$socid = $user->socid;
107
}
108
if (empty($socid) && $action == 'view') {
109
	$action = 'create';
110
}
111
112
$id = $socid;
113
114
$object = new Societe($db);
115
$extrafields = new ExtraFields($db);
116
117
// fetch optionals attributes and labels
118
$extrafields->fetch_name_optionals_label($object->table_element);
119
120
$socialnetworks = getArrayOfSocialNetworks();
121
122
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
123
$hookmanager->initHooks(array('thirdpartycard', 'globalcard'));
124
125
if ($socid > 0) {
126
	$object->fetch($socid);
127
}
128
129
if (!($object->id > 0) && $action == 'view') {
130
	$langs->load("errors");
131
	print($langs->trans('ErrorRecordNotFound'));
132
	exit;
133
}
134
135
// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
136
$canvas = $object->canvas ? $object->canvas : GETPOST("canvas");
137
$objcanvas = null;
138
if (!empty($canvas)) {
139
	require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
140
	$objcanvas = new Canvas($db, $action);
141
	$objcanvas->getCanvas('thirdparty', 'card', $canvas);
142
}
143
144
// Permissions
145
$permissiontoread 	= $user->hasRight('societe', 'lire');
146
$permissiontoadd 	= $user->hasRight('societe', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
147
$permissiontodelete = $user->hasRight('societe', 'supprimer') || ($permissiontoadd && isset($object->status) && $object->status == 0);
148
$permissionnote 	= $user->hasRight('societe', 'creer'); // Used by the include of actions_setnotes.inc.php
149
$permissiondellink 	= $user->hasRight('societe', 'creer'); // Used by the include of actions_dellink.inc.php
150
$upload_dir 		= $conf->societe->multidir_output[isset($object->entity) ? $object->entity : 1];
151
152
// Security check
153
$result = restrictedArea($user, 'societe', $socid, '&societe', '', 'fk_soc', 'rowid', 0);
154
155
156
157
/*
158
 * Actions
159
 */
160
161
$parameters = array('id'=>$socid, 'objcanvas'=>$objcanvas);
162
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
163
if ($reshook < 0) {
164
	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
165
}
166
167
if (empty($reshook)) {
168
	$backurlforlist = DOL_URL_ROOT.'/societe/list.php';
169
170
	if (empty($backtopage) || ($cancel && empty($id))) {
171
		if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
172
			if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
173
				$backtopage = $backurlforlist;
174
			} else {
175
				$backtopage = DOL_URL_ROOT.'/societe/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
176
			}
177
		}
178
	}
179
180
	if ($cancel) {
181
		if (!empty($backtopageforcancel)) {
182
			header("Location: ".$backtopageforcancel);
183
			exit;
184
		} elseif (!empty($backtopage)) {
185
			header("Location: ".$backtopage);
186
			exit;
187
		}
188
		$action = '';
189
	}
190
191
	if ($action == 'confirm_merge' && $confirm == 'yes' && $user->rights->societe->creer) {
192
		$error = 0;
193
		$soc_origin_id = GETPOST('soc_origin', 'int');
194
		$soc_origin = new Societe($db);
195
196
		if ($soc_origin_id <= 0) {
197
			$langs->load('errors');
198
			setEventMessages($langs->trans('ErrorThirdPartyIdIsMandatory', $langs->transnoentitiesnoconv('MergeOriginThirdparty')), null, 'errors');
199
		} else {
200
			if (!$error && $soc_origin->fetch($soc_origin_id) < 1) {
201
				setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
202
				$error++;
203
			}
204
205
			if (!$error) {
206
				// TODO Move the merge function into class of object.
207
208
				$db->begin();
209
210
				// Recopy some data
211
				$object->client = $object->client | $soc_origin->client;
212
				$object->fournisseur = $object->fournisseur | $soc_origin->fournisseur;
213
				$listofproperties = array(
214
					'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'socialnetworks', 'url', 'barcode',
215
					'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6',
216
					'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'remise_supplier_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis',
217
					'stcomm_id', 'outstanding_limit', 'price_level', 'parent', 'default_lang', 'ref', 'ref_ext', 'import_key', 'fk_incoterms', 'fk_multicurrency',
218
					'code_client', 'code_fournisseur', 'code_compta', 'code_compta_fournisseur',
219
					'model_pdf', 'fk_projet'
220
				);
221
				foreach ($listofproperties as $property) {
222
					if (empty($object->$property)) {
223
						$object->$property = $soc_origin->$property;
224
					}
225
				}
226
227
				// Concat some data
228
				$listofproperties = array(
229
					'note_public', 'note_private'
230
				);
231
				foreach ($listofproperties as $property) {
232
					$object->$property = dol_concatdesc($object->$property, $soc_origin->$property);
233
				}
234
235
				// Merge extrafields
236
				if (is_array($soc_origin->array_options)) {
237
					foreach ($soc_origin->array_options as $key => $val) {
238
						if (empty($object->array_options[$key])) {
239
							$object->array_options[$key] = $val;
240
						}
241
					}
242
				}
243
244
				// Merge categories
245
				$static_cat = new Categorie($db);
246
247
				$custcats_ori = $static_cat->containing($soc_origin->id, 'customer', 'id');
248
				$custcats = $static_cat->containing($object->id, 'customer', 'id');
249
				$custcats = array_merge($custcats, $custcats_ori);
250
				$object->setCategories($custcats, 'customer');
251
252
				$suppcats_ori = $static_cat->containing($soc_origin->id, 'supplier', 'id');
253
				$suppcats = $static_cat->containing($object->id, 'supplier', 'id');
254
				$suppcats = array_merge($suppcats, $suppcats_ori);
255
				$object->setCategories($suppcats, 'supplier');
256
257
				// If thirdparty has a new code that is same than origin, we clean origin code to avoid duplicate key from database unique keys.
258
				if ($soc_origin->code_client == $object->code_client
259
					|| $soc_origin->code_fournisseur == $object->code_fournisseur
260
					|| $soc_origin->barcode == $object->barcode) {
261
					dol_syslog("We clean customer and supplier code so we will be able to make the update of target");
262
					$soc_origin->code_client = '';
263
					$soc_origin->code_fournisseur = '';
264
					$soc_origin->barcode = '';
265
					$soc_origin->update($soc_origin->id, $user, 0, 1, 1, 'merge');
266
				}
267
268
				// Update
269
				$result = $object->update($object->id, $user, 0, 1, 1, 'merge');
270
271
				if ($result < 0) {
272
					setEventMessages($object->error, $object->errors, 'errors');
273
					$error++;
274
				}
275
276
				// Move links
277
				if (!$error) {
278
					// This list is also into the api_thirdparties.class.php
279
					// TODO Mutualise the list into object societe.class.php
280
					$objects = array(
281
						'Adherent' => '/adherents/class/adherent.class.php',
282
						'Don' => '/don/class/don.class.php',
283
						'Societe' => '/societe/class/societe.class.php',
284
						//'Categorie' => '/categories/class/categorie.class.php',
285
						'ActionComm' => '/comm/action/class/actioncomm.class.php',
286
						'Propal' => '/comm/propal/class/propal.class.php',
287
						'Commande' => '/commande/class/commande.class.php',
288
						'Facture' => '/compta/facture/class/facture.class.php',
289
						'FactureRec' => '/compta/facture/class/facture-rec.class.php',
290
						'LignePrelevement' => '/compta/prelevement/class/ligneprelevement.class.php',
291
						'Mo' => '/mrp/class/mo.class.php',
292
						'Contact' => '/contact/class/contact.class.php',
293
						'Contrat' => '/contrat/class/contrat.class.php',
294
						'Expedition' => '/expedition/class/expedition.class.php',
295
						'Fichinter' => '/fichinter/class/fichinter.class.php',
296
						'CommandeFournisseur' => '/fourn/class/fournisseur.commande.class.php',
297
						'FactureFournisseur' => '/fourn/class/fournisseur.facture.class.php',
298
						'SupplierProposal' => '/supplier_proposal/class/supplier_proposal.class.php',
299
						'ProductFournisseur' => '/fourn/class/fournisseur.product.class.php',
300
						'Delivery' => '/delivery/class/delivery.class.php',
301
						'Product' => '/product/class/product.class.php',
302
						'Project' => '/projet/class/project.class.php',
303
						'Ticket' => '/ticket/class/ticket.class.php',
304
						'User' => '/user/class/user.class.php',
305
						'Account' => '/compta/bank/class/account.class.php',
306
						'ConferenceOrBoothAttendee' => '/eventorganization/class/conferenceorboothattendee.class.php'
307
					);
308
309
					//First, all core objects must update their tables
310
					foreach ($objects as $object_name => $object_file) {
311
						require_once DOL_DOCUMENT_ROOT.$object_file;
312
313
						if (!$error && !$object_name::replaceThirdparty($db, $soc_origin->id, $object->id)) {
314
							$error++;
315
							setEventMessages($db->lasterror(), null, 'errors');
316
							break;
317
						}
318
					}
319
				}
320
321
				// External modules should update their ones too
322
				if (!$error) {
323
					$reshook = $hookmanager->executeHooks('replaceThirdparty', array(
324
						'soc_origin' => $soc_origin->id,
325
						'soc_dest' => $object->id
326
					), $object, $action);
327
328
					if ($reshook < 0) {
329
						setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
330
						$error++;
331
					}
332
				}
333
334
335
				if (!$error) {
336
					$object->context = array('merge'=>1, 'mergefromid'=>$soc_origin->id);
337
338
					// Call trigger
339
					$result = $object->call_trigger('COMPANY_MODIFY', $user);
340
					if ($result < 0) {
341
						setEventMessages($object->error, $object->errors, 'errors');
342
						$error++;
343
					}
344
					// End call triggers
345
				}
346
347
				if (!$error) {
348
					//We finally remove the old thirdparty
349
					if ($soc_origin->delete($soc_origin->id, $user) < 1) {
350
						setEventMessages($soc_origin->error, $soc_origin->errors, 'errors');
351
						$error++;
352
					}
353
				}
354
355
				if (!$error) {
356
					setEventMessages($langs->trans('ThirdpartiesMergeSuccess'), null, 'mesgs');
357
					$db->commit();
358
				} else {
359
					$langs->load("errors");
360
					setEventMessages($langs->trans('ErrorsThirdpartyMerge'), null, 'errors');
361
					$db->rollback();
362
				}
363
			}
364
		}
365
	}
366
367
	if (GETPOST('getcustomercode')) {
368
		// We defined value code_client
369
		$_POST["customer_code"] = "Acompleter";
370
	}
371
372
	if (GETPOST('getsuppliercode')) {
373
		// We defined value code_fournisseur
374
		$_POST["supplier_code"] = "Acompleter";
375
	}
376
377
	if ($action == 'set_localtax1') {
378
		//obtidre selected del combobox
379
		$value = GETPOST('lt1');
380
		$object->fetch($socid);
381
		$res = $object->setValueFrom('localtax1_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
382
	}
383
	if ($action == 'set_localtax2') {
384
		//obtidre selected del combobox
385
		$value = GETPOST('lt2');
386
		$object->fetch($socid);
387
		$res = $object->setValueFrom('localtax2_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
388
	}
389
390
	if ($action == 'update_extras') {
391
		$object->fetch($socid);
392
393
		$object->oldcopy = dol_clone($object);
394
395
		// Fill array 'array_options' with data from update form
396
		$extrafields->fetch_name_optionals_label($object->table_element);
397
398
		$ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
399
		if ($ret < 0) {
400
			$error++;
401
		}
402
403
		if (!$error) {
404
			$result = $object->insertExtraFields('COMPANY_MODIFY');
405
			if ($result < 0) {
406
				setEventMessages($object->error, $object->errors, 'errors');
407
				$error++;
408
			}
409
		}
410
411
		if ($error) {
412
			$action = 'edit_extras';
413
		}
414
	}
415
416
	// Add new or update third party
417
	if ((!GETPOST('getcustomercode') && !GETPOST('getsuppliercode'))
418
	&& ($action == 'add' || $action == 'update') && $user->rights->societe->creer) {
419
		require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
420
421
		if (!GETPOST('name')) {
422
			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdPartyName")), null, 'errors');
423
			$error++;
424
		}
425
		if (GETPOST('client', 'int') && GETPOST('client', 'int') < 0) {
426
			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProspectCustomer")), null, 'errors');
427
			$error++;
428
		}
429
		if (GETPOSTISSET('fournisseur') && GETPOST('fournisseur', 'int') < 0) {
430
			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Supplier")), null, 'errors');
431
			$error++;
432
		}
433
434
		if (isModEnabled('mailing') && !empty($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS) && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2 && GETPOST('contact_no_email', 'int')==-1 && !empty(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL))) {
435
			$error++;
436
			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("No_Email")), null, 'errors');
437
		}
438
439
		if (isModEnabled('mailing') && GETPOST("private", 'int') == 1 && !empty($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS) && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2 && GETPOST('contact_no_email', 'int')==-1 && !empty(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL))) {
440
			$error++;
441
			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("No_Email")), null, 'errors');
442
		}
443
444
		if (!$error) {
445
			if ($action == 'update') {
446
				$ret = $object->fetch($socid);
447
				$object->oldcopy = clone $object;
448
			} else {
449
				$object->canvas = $canvas;
450
			}
451
452
			if (GETPOST("private", 'int') == 1) {	// Ask to create a contact
453
				$object->particulier		= GETPOST("private", 'int');
454
455
				$object->name = dolGetFirstLastname(GETPOST('firstname', 'alphanohtml'), GETPOST('name', 'alphanohtml'));
456
				$object->civility_id		= GETPOST('civility_id', 'alphanohtml'); // Note: civility id is a code, not an int
457
				// Add non official properties
458
				$object->name_bis			= GETPOST('name', 'alphanohtml');
459
				$object->firstname			= GETPOST('firstname', 'alphanohtml');
460
			} else {
461
				$object->name				= GETPOST('name', 'alphanohtml');
462
			}
463
			$object->entity					= (GETPOSTISSET('entity') ? GETPOST('entity', 'int') : $conf->entity);
464
			$object->name_alias				= GETPOST('name_alias', 'alphanohtml');
465
			$object->parent					= GETPOST('parent_company_id', 'int');
466
			$object->address				= GETPOST('address', 'alphanohtml');
467
			$object->zip					= GETPOST('zipcode', 'alphanohtml');
468
			$object->town					= GETPOST('town', 'alphanohtml');
469
			$object->country_id				= GETPOST('country_id', 'int');
470
			$object->state_id				= GETPOST('state_id', 'int');
471
472
			$object->socialnetworks = array();
473
			if (isModEnabled('socialnetworks')) {
474
				foreach ($socialnetworks as $key => $value) {
475
					if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
476
						$object->socialnetworks[$key] = GETPOST($key, 'alphanohtml');
477
					}
478
				}
479
			}
480
481
			$object->phone					= GETPOST('phone', 'alpha');
482
			$object->fax					= GETPOST('fax', 'alpha');
483
			$object->email					= trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL));
484
			$object->no_email 				= GETPOST("no_email", "int");
485
			$object->url					= trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL));
486
			$object->idprof1				= trim(GETPOST('idprof1', 'alphanohtml'));
487
			$object->idprof2				= trim(GETPOST('idprof2', 'alphanohtml'));
488
			$object->idprof3				= trim(GETPOST('idprof3', 'alphanohtml'));
489
			$object->idprof4				= trim(GETPOST('idprof4', 'alphanohtml'));
490
			$object->idprof5				= trim(GETPOST('idprof5', 'alphanohtml'));
491
			$object->idprof6				= trim(GETPOST('idprof6', 'alphanohtml'));
492
			$object->prefix_comm			= GETPOST('prefix_comm', 'alphanohtml');
493
			$object->code_client			= GETPOSTISSET('customer_code') ?GETPOST('customer_code', 'alpha') : GETPOST('code_client', 'alpha');
494
			$object->code_fournisseur		= GETPOSTISSET('supplier_code') ?GETPOST('supplier_code', 'alpha') : GETPOST('code_fournisseur', 'alpha');
495
			$object->capital				= GETPOST('capital', 'alphanohtml');
496
			$object->barcode				= GETPOST('barcode', 'alphanohtml');
497
498
			$object->tva_intra				= GETPOST('tva_intra', 'alphanohtml');
499
			$object->tva_assuj				= GETPOST('assujtva_value', 'alpha');
500
			$object->status = GETPOST('status', 'alpha');
501
502
			// Local Taxes
503
			$object->localtax1_assuj		= GETPOST('localtax1assuj_value', 'alpha');
504
			$object->localtax2_assuj		= GETPOST('localtax2assuj_value', 'alpha');
505
506
			$object->localtax1_value		= GETPOST('lt1', 'alpha');
507
			$object->localtax2_value		= GETPOST('lt2', 'alpha');
508
509
			$object->forme_juridique_code	= GETPOST('forme_juridique_code', 'int');
510
			$object->effectif_id			= GETPOST('effectif_id', 'int');
511
			$object->typent_id				= GETPOST('typent_id', 'int');
512
513
			$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
514
515
			$object->client					= GETPOST('client', 'int');
516
			$object->fournisseur			= GETPOST('fournisseur', 'int');
517
518
			$object->commercial_id			= GETPOST('commercial_id', 'int');
519
			$object->default_lang			= GETPOST('default_lang');
520
521
			// Webservices url/key
522
			$object->webservices_url		= GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
523
			$object->webservices_key		= GETPOST('webservices_key', 'san_alpha');
524
525
			if (GETPOSTISSET('accountancy_code_sell')) {
526
				$accountancy_code_sell		= GETPOST('accountancy_code_sell', 'alpha');
527
528
				if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') {
529
					$object->accountancy_code_sell = '';
530
				} else {
531
					$object->accountancy_code_sell = $accountancy_code_sell;
532
				}
533
			}
534
			if (GETPOSTISSET('accountancy_code_buy')) {
535
				$accountancy_code_buy		= GETPOST('accountancy_code_buy', 'alpha');
536
537
				if (empty($accountancy_code_buy) || $accountancy_code_buy == '-1') {
538
					$object->accountancy_code_buy = '';
539
				} else {
540
					$object->accountancy_code_buy = $accountancy_code_buy;
541
				}
542
			}
543
544
			// Incoterms
545
			if (isModEnabled('incoterm')) {
546
				$object->fk_incoterms = GETPOST('incoterm_id', 'int');
547
				$object->location_incoterms = GETPOST('location_incoterms', 'alpha');
548
			}
549
550
			// Multicurrency
551
			if (isModEnabled("multicurrency")) {
552
				$object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
553
			}
554
555
			// Fill array 'array_options' with data from add form
556
			$ret = $extrafields->setOptionalsFromPost(null, $object);
557
			if ($ret < 0) {
558
				 $error++;
559
			}
560
561
			// Fill array 'array_languages' with data from add form
562
			$ret = $object->setValuesForExtraLanguages();
563
			if ($ret < 0) {
564
				$error++;
565
			}
566
			//var_dump($object->array_languages);exit;
567
568
			if (!empty($_FILES['photo']['name'])) {
569
				$current_logo = $object->logo;
570
				$object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
571
			}
572
573
			// Check parameters
574
			if (!GETPOST('cancel', 'alpha')) {
575
				if (!empty($object->email) && !isValidEMail($object->email)) {
576
					$langs->load("errors");
577
					$error++;
578
					setEventMessages($langs->trans("ErrorBadEMail", $object->email), null, 'errors');
579
				}
580
				if (!empty($object->url) && !isValidUrl($object->url)) {
581
					$langs->load("errors");
582
					setEventMessages($langs->trans("ErrorBadUrl", $object->url), null, 'errors');
583
				}
584
				if (!empty($object->webservices_url)) {
585
					//Check if has transport, without any the soap client will give error
586
					if (strpos($object->webservices_url, "http") === false) {
587
						$object->webservices_url = "http://".$object->webservices_url;
588
					}
589
					if (!isValidUrl($object->webservices_url)) {
590
						$langs->load("errors");
591
						$error++; $errors[] = $langs->trans("ErrorBadUrl", $object->webservices_url);
592
					}
593
				}
594
595
				// We set country_id, country_code and country for the selected country
596
				$object->country_id = GETPOST('country_id', 'int') != '' ? GETPOST('country_id', 'int') : $mysoc->country_id;
597
				if ($object->country_id) {
598
					$tmparray = getCountry($object->country_id, 'all');
599
					$object->country_code = $tmparray['code'];
600
					$object->country = $tmparray['label'];
601
				}
602
			}
603
		}
604
605
		if (!$error) {
606
			if ($action == 'add') {
607
				$error = 0;
608
609
				$db->begin();
610
611
				if (empty($object->client)) {
612
					$object->code_client = '';
613
				}
614
				if (empty($object->fournisseur)) {
615
					$object->code_fournisseur = '';
616
				}
617
618
				$result = $object->create($user);
619
620
				if (empty($error) && !empty($conf->mailing->enabled) && !empty($object->email) && $object->no_email == 1) {
621
					// Add mass emailing flag into table mailing_unsubscribe
622
					$result = $object->setNoEmail($object->no_email);
623
					if ($result < 0) {
624
						$error++;
625
						$errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
626
						$action = 'create';
627
					}
628
				}
629
630
				if ($result >= 0) {
631
					if ($object->particulier) {
632
						dol_syslog("We ask to create a contact/address too", LOG_DEBUG);
633
						$contcats = GETPOST('contcats', 'array');
634
						$no_email = GETPOST('contact_no_email', 'int');
635
						$result = $object->create_individual($user, $no_email, $contcats);
636
						if ($result < 0) {
637
							setEventMessages($object->error, $object->errors, 'errors');
638
							$error++;
639
						}
640
					}
641
642
					// Links with users
643
					$salesreps = GETPOST('commercial', 'array');
644
					$result = $object->setSalesRep($salesreps, true);
645
					if ($result < 0) {
646
						$error++;
647
						setEventMessages($object->error, $object->errors, 'errors');
648
					}
649
650
					// Customer categories association
651
					$custcats = GETPOST('custcats', 'array');
652
					$result = $object->setCategories($custcats, 'customer');
653
					if ($result < 0) {
654
						$error++;
655
						setEventMessages($object->error, $object->errors, 'errors');
656
					}
657
658
					// Supplier categories association
659
					$suppcats = GETPOST('suppcats', 'array');
660
					$result = $object->setCategories($suppcats, 'supplier');
661
					if ($result < 0) {
662
						$error++;
663
						setEventMessages($object->error, $object->errors, 'errors');
664
					}
665
666
					// Logo/Photo save
667
					$dir = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos/";
668
					$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
669
					if ($file_OK) {
670
						if (image_format_supported($_FILES['photo']['name'])) {
671
							dol_mkdir($dir);
672
673
							if (@is_dir($dir)) {
674
								$newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
675
								$result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
676
677
								if (!($result > 0)) {
678
									$errors[] = "ErrorFailedToSaveFile";
679
								} else {
680
									// Create thumbs
681
									$object->addThumbs($newfile);
682
								}
683
							}
684
						}
685
					} else {
686
						switch ($_FILES['photo']['error']) {
687
							case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
688
							case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
689
								$errors[] = "ErrorFileSizeTooLarge";
690
								break;
691
							case 3: //uploaded file was only partially uploaded
692
								$errors[] = "ErrorFilePartiallyUploaded";
693
								break;
694
						}
695
					}
696
				} else {
697
					if ($result == -3 && in_array('ErrorCustomerCodeAlreadyUsed', $object->errors)) {
698
						$duplicate_code_error = true;
699
						$object->code_client = null;
700
					}
701
702
					if ($result == -3 && in_array('ErrorSupplierCodeAlreadyUsed', $object->errors)) {
703
						$duplicate_code_error = true;
704
						$object->code_fournisseur = null;
705
					}
706
707
					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
708
						$duplicate_code_error = true;
709
					}
710
711
					setEventMessages($object->error, $object->errors, 'errors');
712
					$error++;
713
				}
714
715
				if ($result >= 0 && !$error) {
716
					$db->commit();
717
718
					if ($backtopagejsfields) {
719
						llxHeader('', '', '');
720
721
						$retstring = '<script>';
722
						$retstring .= 'jQuery(document).ready(function() {
723
												console.log(\'We execute action to create. We save id and go back - '.$dol_openinpopup.'\');
724
												console.log(\'id = '.$object->id.'\');
725
												$(\'#varforreturndialogid'.$dol_openinpopup.'\', window.parent.document).text(\''.$object->id.'\');
726
												$(\'#varforreturndialoglabel'.$dol_openinpopup.'\', window.parent.document).text(\''.$object->name.'\');
727
												window.parent.jQuery(\'#idfordialog'.$dol_openinpopup.'\').dialog(\'close\');
728
				 							});';
729
						$retstring .= '</script>';
730
						print $retstring;
731
732
						llxFooter();
733
						exit;
734
					}
735
736
					if (!empty($backtopage)) {
737
						$backtopage = preg_replace('/--IDFORBACKTOPAGE--/', $object->id, $backtopage); // New method to autoselect project after a New on another form object creation
738
						if (preg_match('/\?/', $backtopage)) {
739
							$backtopage .= '&socid='.$object->id; // Old method
740
						}
741
						header("Location: ".$backtopage);
742
						exit;
743
					} else {
744
						$url = $_SERVER["PHP_SELF"]."?socid=".$object->id; // Old method
745
						if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
746
							$url = DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
747
						} elseif ($object->fournisseur == 1) {
748
							$url = DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
749
						}
750
751
						header("Location: ".$url);
752
						exit;
753
					}
754
				} else {
755
					$db->rollback();
756
					$action = 'create';
757
				}
758
			}
759
760
			if ($action == 'update') {
761
				$error = 0;
762
763
				if (GETPOST('cancel', 'alpha')) {
764
					if (!empty($backtopage)) {
765
						header("Location: ".$backtopage);
766
						exit;
767
					} else {
768
						header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
769
						exit;
770
					}
771
				}
772
773
				// To not set code if third party is not concerned. But if it had values, we keep them.
774
				if (empty($object->client) && empty($object->oldcopy->code_client)) {
775
					$object->code_client = '';
776
				}
777
				if (empty($object->fournisseur) && empty($object->oldcopy->code_fournisseur)) {
778
					$object->code_fournisseur = '';
779
				}
780
				//var_dump($object);exit;
781
782
				$result = $object->update($socid, $user, 1, $object->oldcopy->codeclient_modifiable(), $object->oldcopy->codefournisseur_modifiable(), 'update', 0);
783
784
				if ($result > 0) {
785
					// Update mass emailing flag into table mailing_unsubscribe
786
					if (GETPOSTISSET('no_email') && $object->email) {
787
						$no_email = GETPOST('no_email', 'int');
788
						$result = $object->setNoEmail($no_email);
789
						if ($result < 0) {
790
							setEventMessages($object->error, $object->errors, 'errors');
791
							$action = 'edit';
792
						}
793
					}
794
795
					$action = 'view';
796
				} else {
797
					setEventMessages($object->error, $object->errors, 'errors');
798
					$action = 'edit';
799
				}
800
801
				if ($result <= 0) {
802
					setEventMessages($object->error, $object->errors, 'errors');
803
					$error++;
804
				}
805
806
				// Links with users
807
				$salesreps = GETPOST('commercial', 'array');
808
				$result = $object->setSalesRep($salesreps);
809
				if ($result < 0) {
810
					$error++;
811
					setEventMessages($object->error, $object->errors, 'errors');
812
				}
813
814
				// Prevent thirdparty's emptying if a user hasn't rights $user->rights->categorie->lire (in such a case, post of 'custcats' is not defined)
815
				if (!$error && !empty($user->rights->categorie->lire)) {
816
					// Customer categories association
817
					$categories = GETPOST('custcats', 'array');
818
					$result = $object->setCategories($categories, 'customer');
819
					if ($result < 0) {
820
						$error++;
821
						setEventMessages($object->error, $object->errors, 'errors');
822
					}
823
824
					// Supplier categories association
825
					$categories = GETPOST('suppcats', 'array');
826
					$result = $object->setCategories($categories, 'supplier');
827
					if ($result < 0) {
828
						$error++;
829
						setEventMessages($object->error, $object->errors, 'errors');
830
					}
831
				}
832
833
				// Logo/Photo save
834
				$dir     = $conf->societe->multidir_output[$object->entity]."/".$object->id."/logos";
835
				$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
836
				if (GETPOST('deletephoto') && $object->logo) {
837
					$fileimg = $dir.'/'.$object->logo;
838
					$dirthumbs = $dir.'/thumbs';
839
					dol_delete_file($fileimg);
840
					dol_delete_dir_recursive($dirthumbs);
841
				}
842
				if ($file_OK) {
843
					if (image_format_supported($_FILES['photo']['name']) > 0) {
844
						if ($current_logo != $object->logo) {
845
							$fileimg = $dir.'/'.$current_logo;
846
							$dirthumbs = $dir.'/thumbs';
847
							dol_delete_file($fileimg);
848
							dol_delete_dir_recursive($dirthumbs);
849
						}
850
851
						dol_mkdir($dir);
852
853
						if (@is_dir($dir)) {
854
							$newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
855
							$result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
856
857
							if (!($result > 0)) {
858
								$errors[] = "ErrorFailedToSaveFile";
859
							} else {
860
								// Create thumbs
861
								$object->addThumbs($newfile);
862
863
								// Index file in database
864
								if (!empty($conf->global->THIRDPARTY_LOGO_ALLOW_EXTERNAL_DOWNLOAD)) {
865
									require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
866
									// 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
867
									deleteFilesIntoDatabaseIndex(dirname($newfile), '', '');
868
									// now we index the uploaded logo file
869
									addFileIntoDatabaseIndex(dirname($newfile), basename($newfile), '', 'uploaded', 1);
870
								}
871
							}
872
						}
873
					} else {
874
						$errors[] = "ErrorBadImageFormat";
875
					}
876
				} else {
877
					switch ($_FILES['photo']['error']) {
878
						case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
879
						case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
880
							$errors[] = "ErrorFileSizeTooLarge";
881
							break;
882
						case 3: //uploaded file was only partially uploaded
883
							$errors[] = "ErrorFilePartiallyUploaded";
884
							break;
885
					}
886
				}
887
				// Gestion du logo de la société
888
889
890
				// Update linked member
891
				if (!$error && $object->fk_soc > 0) {
892
					$sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
893
					$sql .= " SET fk_soc = NULL WHERE fk_soc = ".((int) $socid);
894
					if (!$object->db->query($sql)) {
895
						$error++;
896
						$object->error .= $object->db->lasterror();
897
						setEventMessages($object->error, $object->errors, 'errors');
898
					}
899
				}
900
901
				if (!$error && !count($errors)) {
902
					if (!empty($backtopage)) {
903
						header("Location: ".$backtopage);
904
						exit;
905
					} else {
906
						header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
907
						exit;
908
					}
909
				} else {
910
					$object->id = $socid;
911
					$action = "edit";
912
				}
913
			}
914
		} else {
915
			$action = ($action == 'add' ? 'create' : 'edit');
916
		}
917
	}
918
919
	// Delete third party
920
	if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('societe', 'supprimer')) {
921
		$object->fetch($socid);
922
		$object->oldcopy = clone $object;
923
		$result = $object->delete($socid, $user);
924
925
		if ($result > 0) {
926
			header("Location: ".DOL_URL_ROOT."/societe/list.php?restore_lastsearch_values=1&delsoc=".urlencode($object->name));
927
			exit;
928
		} else {
929
			$langs->load("errors");
930
			setEventMessages($object->error, $object->errors, 'errors');
931
			$error++;
932
			$action = '';
933
		}
934
	}
935
936
	// Set third-party type
937
	if ($action == 'set_thirdpartytype' && $user->rights->societe->creer) {
938
		$object->fetch($socid);
939
		$result = $object->setThirdpartyType(GETPOST('typent_id', 'int'));
940
	}
941
942
	// Set incoterm
943
	if ($action == 'set_incoterms' && $user->rights->societe->creer && isModEnabled('incoterm')) {
944
		$object->fetch($socid);
945
		$result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
946
	}
947
948
	// Set parent company
949
	if ($action == 'set_thirdparty' && $user->rights->societe->creer) {
950
		$object->fetch($socid);
951
		$result = $object->setParent(GETPOST('parent_id', 'int'));
952
	}
953
954
	// Set sales representatives
955
	if ($action == 'set_salesrepresentatives' && $user->rights->societe->creer) {
956
		$object->fetch($socid);
957
		$result = $object->setSalesRep(GETPOST('commercial', 'array'));
958
	}
959
960
	// warehouse
961
	if ($action == 'setwarehouse' && $user->rights->societe->creer) {
962
		$result = $object->setWarehouse(GETPOST('fk_warehouse', 'int'));
963
	}
964
965
	$id = $socid;
966
	$object->fetch($socid);
967
968
	// Selection of new fields
969
	if (!empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD) && (empty($conf->global->SOCIETE_DISABLE_CONTACTS) || !empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))) {
970
		include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
971
	}
972
973
	// Actions to send emails
974
	$triggersendname = 'COMPANY_SENTBYMAIL';
975
	$paramname = 'socid';
976
	$mode = 'emailfromthirdparty';
977
	$trackid = 'thi'.$object->id;
978
	include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
979
980
	// Actions to build doc
981
	$id = $socid;
982
	$upload_dir = !empty($conf->societe->multidir_output[$object->entity])?$conf->societe->multidir_output[$object->entity]:$conf->societe->dir_output;
983
	$permissiontoadd = $user->hasRight('societe', 'creer');
984
	include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
985
}
986
987
988
/*
989
 *  View
990
 */
991
992
$form = new Form($db);
993
$formfile = new FormFile($db);
994
$formadmin = new FormAdmin($db);
995
$formcompany = new FormCompany($db);
996
if (isModEnabled('accounting')) {
997
	$formaccounting = new FormAccounting($db);
998
}
999
1000
if ($socid > 0 && empty($object->id)) {
1001
	$result = $object->fetch($socid);
1002
	if ($result <= 0) {
1003
		dol_print_error('', $object->error);
1004
		exit(-1);
1005
	}
1006
}
1007
1008
$title = $langs->trans("ThirdParty");
1009
if ($action == 'create') {
1010
	$title = $langs->trans("NewThirdParty");
1011
}
1012
if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
1013
	$title = $object->name." - ".$langs->trans('Card');
1014
}
1015
$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas|DE:Modul_Geschäftspartner';
1016
1017
llxHeader('', $title, $help_url);
1018
1019
$countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
1020
1021
if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
1022
	// -----------------------------------------
1023
	// When used with CANVAS
1024
	// -----------------------------------------
1025
	$objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
1026
	$objcanvas->display_canvas($action); // Show template
1027
} else {
1028
	// -----------------------------------------
1029
	// When used in standard mode
1030
	// -----------------------------------------
1031
	if ($action == 'create') {
1032
		/*
1033
		 *  Creation
1034
		 */
1035
		$private = GETPOST("private", "int");
1036
		if (!empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT) && !GETPOSTISSET('private')) {
1037
			$private = 1;
1038
		}
1039
		if (empty($private)) {
1040
			$private = 0;
1041
		}
1042
1043
		// Load object modCodeTiers
1044
		$module = (!empty($conf->global->SOCIETE_CODECLIENT_ADDON) ? $conf->global->SOCIETE_CODECLIENT_ADDON : 'mod_codeclient_leopard');
1045
		if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
1046
			$module = substr($module, 0, dol_strlen($module) - 4);
1047
		}
1048
		$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
1049
		foreach ($dirsociete as $dirroot) {
1050
			$res = dol_include_once($dirroot.$module.'.php');
1051
			if ($res) {
1052
				break;
1053
			}
1054
		}
1055
		$modCodeClient = new $module;
1056
		// Load object modCodeFournisseur
1057
		$module = (!empty($conf->global->SOCIETE_CODECLIENT_ADDON) ? $conf->global->SOCIETE_CODECLIENT_ADDON : 'mod_codeclient_leopard');
1058
		if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
1059
			$module = substr($module, 0, dol_strlen($module) - 4);
1060
		}
1061
		$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
1062
		foreach ($dirsociete as $dirroot) {
1063
			$res = dol_include_once($dirroot.$module.'.php');
1064
			if ($res) {
1065
				break;
1066
			}
1067
		}
1068
		$modCodeFournisseur = new $module;
1069
1070
		// Define if customer/prospect or supplier status is set or not
1071
		if (GETPOST("type", 'aZ') != 'f') {
1072
			$object->client = -1;
1073
			if (!empty($conf->global->THIRDPARTY_CUSTOMERPROSPECT_BY_DEFAULT)) {
1074
				$object->client = 3;
1075
			}
1076
		}
1077
		// Prospect / Customer
1078
		if (GETPOST("type", 'aZ') == 'c') {
1079
			if (!empty($conf->global->THIRDPARTY_CUSTOMERTYPE_BY_DEFAULT)) {
1080
				$object->client = $conf->global->THIRDPARTY_CUSTOMERTYPE_BY_DEFAULT;
1081
			} else {
1082
				$object->client = 3;
1083
			}
1084
		}
1085
		if (GETPOST("type", 'aZ') == 'p') {
1086
			$object->client = 2;
1087
		}
1088
1089
		if (!empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS) && $object->client == 3) {
1090
			$object->client = 1;
1091
		}
1092
1093
		if (((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && (GETPOST("type") == 'f' || (GETPOST("type") == '' && !empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)))) {
1094
			$object->fournisseur = 1;
1095
		}
1096
1097
		$object->name = GETPOST('name', 'alphanohtml');
1098
		$object->name_alias = GETPOST('name_alias', 'alphanohtml');
1099
		$object->firstname = GETPOST('firstname', 'alphanohtml');
1100
		$object->particulier		= $private;
1101
		$object->prefix_comm		= GETPOST('prefix_comm', 'alphanohtml');
1102
		$object->client = GETPOST('client', 'int') ?GETPOST('client', 'int') : $object->client;
1103
1104
		if (empty($duplicate_code_error)) {
1105
			$object->code_client		= GETPOST('customer_code', 'alpha');
1106
			$object->fournisseur		= GETPOST('fournisseur') ? GETPOST('fournisseur', 'int') : $object->fournisseur;
1107
			$object->code_fournisseur = GETPOST('supplier_code', 'alpha');
1108
		} else {
1109
			setEventMessages($langs->trans('NewCustomerSupplierCodeProposed'), null, 'warnings');
1110
		}
1111
1112
		$object->address = GETPOST('address', 'alphanohtml');
1113
		$object->zip = GETPOST('zipcode', 'alphanohtml');
1114
		$object->town = GETPOST('town', 'alphanohtml');
1115
		$object->state_id = GETPOST('state_id', 'int');
1116
1117
		$object->socialnetworks = array();
1118
		if (isModEnabled('socialnetworks')) {
1119
			foreach ($socialnetworks as $key => $value) {
1120
				if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
1121
					$object->socialnetworks[$key] = GETPOST($key, 'alphanohtml');
1122
				}
1123
			}
1124
		}
1125
1126
		$object->phone				= GETPOST('phone', 'alpha');
1127
		$object->fax				= GETPOST('fax', 'alpha');
1128
		$object->email				= GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL);
1129
		$object->url				= GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL);
1130
		$object->capital			= GETPOST('capital', 'alphanohtml');
1131
		$object->barcode			= GETPOST('barcode', 'alphanohtml');
1132
		$object->idprof1			= GETPOST('idprof1', 'alphanohtml');
1133
		$object->idprof2			= GETPOST('idprof2', 'alphanohtml');
1134
		$object->idprof3			= GETPOST('idprof3', 'alphanohtml');
1135
		$object->idprof4			= GETPOST('idprof4', 'alphanohtml');
1136
		$object->idprof5			= GETPOST('idprof5', 'alphanohtml');
1137
		$object->idprof6			= GETPOST('idprof6', 'alphanohtml');
1138
		$object->typent_id = GETPOST('typent_id', 'int');
1139
		$object->effectif_id		= GETPOST('effectif_id', 'int');
1140
		$object->civility_id		= GETPOST('civility_id', 'alpha');
1141
1142
		$object->tva_assuj = GETPOST('assujtva_value', 'int');
1143
		$object->status = GETPOST('status', 'int');
1144
1145
		//Local Taxes
1146
		$object->localtax1_assuj	= GETPOST('localtax1assuj_value', 'int');
1147
		$object->localtax2_assuj	= GETPOST('localtax2assuj_value', 'int');
1148
1149
		$object->localtax1_value	= GETPOST('lt1', 'int');
1150
		$object->localtax2_value	= GETPOST('lt2', 'int');
1151
1152
		$object->tva_intra = GETPOST('tva_intra', 'alphanohtml');
1153
1154
		$object->commercial_id = GETPOST('commercial_id', 'int');
1155
		$object->default_lang = GETPOST('default_lang');
1156
1157
		if (GETPOSTISSET('accountancy_code_sell')) {
1158
			$accountancy_code_sell  = GETPOST('accountancy_code_sell', 'alpha');
1159
1160
			if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') {
1161
				$object->accountancy_code_sell = '';
1162
			} else {
1163
				$object->accountancy_code_sell = $accountancy_code_sell;
1164
			}
1165
		}
1166
		if (GETPOSTISSET('accountancy_code_buy')) {
1167
			$accountancy_code_buy   = GETPOST('accountancy_code_buy', 'alpha');
1168
1169
			if (empty($accountancy_code_buy) || $accountancy_code_buy == '-1') {
1170
				$object->accountancy_code_buy = '';
1171
			} else {
1172
				$object->accountancy_code_buy = $accountancy_code_buy;
1173
			}
1174
		}
1175
1176
		$object->logo = (isset($_FILES['photo']) ?dol_sanitizeFileName($_FILES['photo']['name']) : '');
1177
1178
		// Gestion du logo de la société
1179
		$dir     = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos";
1180
		$file_OK = (isset($_FILES['photo']) ?is_uploaded_file($_FILES['photo']['tmp_name']) : false);
1181
		if ($file_OK) {
1182
			if (image_format_supported($_FILES['photo']['name'])) {
1183
				dol_mkdir($dir);
1184
1185
				if (@is_dir($dir)) {
1186
					$newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
1187
					$result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
1188
1189
					if (!($result > 0)) {
1190
						$errors[] = "ErrorFailedToSaveFile";
1191
					} else {
1192
						// Create thumbs
1193
						$object->addThumbs($newfile);
1194
					}
1195
				}
1196
			}
1197
		}
1198
1199
		// We set country_id, country_code and country for the selected country
1200
		$object->country_id = GETPOST('country_id') ?GETPOST('country_id') : $mysoc->country_id;
1201
		if ($object->country_id) {
1202
			$tmparray = getCountry($object->country_id, 'all');
1203
			$object->country_code = $tmparray['code'];
1204
			$object->country = $tmparray['label'];
1205
		}
1206
		$object->forme_juridique_code = GETPOST('forme_juridique_code');
1207
1208
		// We set multicurrency_code if enabled
1209
		if (isModEnabled("multicurrency")) {
1210
			$object->multicurrency_code = GETPOST('multicurrency_code') ? GETPOST('multicurrency_code') : $conf->currency;
1211
		}
1212
		/* Show create form */
1213
1214
		$linkback = "";
1215
		print load_fiche_titre($langs->trans("NewThirdParty"), $linkback, 'building');
1216
1217
		if (!empty($conf->use_javascript_ajax)) {
1218
			if (!empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION)) {
1219
				print "\n".'<script type="text/javascript">';
1220
				print '$(document).ready(function () {
1221
						id_te_private=8;
1222
                        id_ef15=1;
1223
                        is_private=' . $private.';
1224
						if (is_private) {
1225
							$(".individualline").show();
1226
						} else {
1227
							$(".individualline").hide();
1228
						}
1229
                        $("#radiocompany").click(function() {
1230
                        	$(".individualline").hide();
1231
                        	$("#typent_id").val(0);
1232
                        	$("#typent_id").change();
1233
                        	$("#effectif_id").val(0);
1234
                        	$("#effectif_id").change();
1235
                        	$("#TypeName").html(document.formsoc.ThirdPartyName.value);
1236
                        	document.formsoc.private.value=0;
1237
                        });
1238
                        $("#radioprivate").click(function() {
1239
                        	$(".individualline").show();
1240
                        	$("#typent_id").val(id_te_private);
1241
                        	$("#typent_id").change();
1242
                        	$("#effectif_id").val(id_ef15);
1243
                        	$("#effectif_id").change();
1244
							/* Force to recompute the width of a select2 field when it was hidden and then shown programatically */
1245
							if ($("#civility_id").data("select2")) {
1246
								$("#civility_id").select2({width: "resolve"});
1247
							}
1248
                        	$("#TypeName").html(document.formsoc.LastName.value);
1249
                        	document.formsoc.private.value=1;
1250
                        });
1251
1252
						var canHaveCategoryIfNotCustomerProspectSupplier = ' . (empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT) ? '0' : '1') . ';
1253
1254
						init_customer_categ();
1255
			  			$("#customerprospect").change(function() {
1256
								init_customer_categ();
1257
						});
1258
						function init_customer_categ() {
1259
								console.log("is customer or prospect = "+jQuery("#customerprospect").val());
1260
								if (jQuery("#customerprospect").val() == 0 && !canHaveCategoryIfNotCustomerProspectSupplier)
1261
								{
1262
									jQuery(".visibleifcustomer").hide();
1263
								}
1264
								else
1265
								{
1266
									jQuery(".visibleifcustomer").show();
1267
								}
1268
						}
1269
1270
						init_supplier_categ();
1271
			       		$("#fournisseur").change(function() {
1272
							init_supplier_categ();
1273
						});
1274
						function init_supplier_categ() {
1275
								console.log("is supplier = "+jQuery("#fournisseur").val());
1276
								if (jQuery("#fournisseur").val() == 0)
1277
								{
1278
									jQuery(".visibleifsupplier").hide();
1279
								}
1280
								else
1281
								{
1282
									jQuery(".visibleifsupplier").show();
1283
								}
1284
						}
1285
1286
                        $("#selectcountry_id").change(function() {
1287
                        	document.formsoc.action.value="create";
1288
                        	document.formsoc.submit();
1289
                        });';
1290
				if ($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2) {
1291
					print '
1292
						function init_check_no_email(input) {
1293
							if (input.val()!="") {
1294
								$(".noemail").addClass("fieldrequired");
1295
							} else {
1296
								$(".noemail").removeClass("fieldrequired");
1297
							}
1298
						}
1299
						$("#email").keyup(function() {
1300
							init_check_no_email($(this));
1301
						});
1302
						init_check_no_email($("#email"));';
1303
				}
1304
				print '});';
1305
				print '</script>'."\n";
1306
1307
				print '<div id="selectthirdpartytype">';
1308
				print '<div class="hideonsmartphone float">';
1309
				print $langs->trans("ThirdPartyType").': &nbsp; &nbsp; ';
1310
				print '</div>';
1311
				print '<label for="radiocompany" class="radiocompany">';
1312
				print '<input type="radio" id="radiocompany" class="flat" name="private"  value="0"'.($private ? '' : ' checked').'>';
1313
				print '&nbsp;';
1314
				print $langs->trans("CreateThirdPartyOnly");
1315
				print '</label>';
1316
				print ' &nbsp; &nbsp; ';
1317
				print '<label for="radioprivate" class="radioprivate">';
1318
				$text = '<input type="radio" id="radioprivate" class="flat" name="private" value="1"'.($private ? ' checked' : '').'>';
1319
				$text .= '&nbsp;';
1320
				$text .= $langs->trans("CreateThirdPartyAndContact");
1321
				$htmltext = $langs->trans("ToCreateContactWithSameName");
1322
				print $form->textwithpicto($text, $htmltext, 1, 'help', '', 0, 3);
1323
				print '</label>';
1324
				print '</div>';
1325
				print "<br>\n";
1326
			} else {
1327
				print '<script type="text/javascript">';
1328
				print '$(document).ready(function () {
1329
                        $("#selectcountry_id").change(function() {
1330
                        	document.formsoc.action.value="create";
1331
                        	document.formsoc.submit();
1332
                        });
1333
                     });';
1334
				print '</script>'."\n";
1335
			}
1336
		}
1337
1338
		dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
1339
1340
		print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc" autocomplete="off">'; // Chrome ignor autocomplete
1341
1342
		print '<input type="hidden" name="action" value="add">';
1343
		print '<input type="hidden" name="token" value="'.newToken().'">';
1344
		print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1345
		print '<input type="hidden" name="backtopagejsfields" value="'.$backtopagejsfields.'">';
1346
		print '<input type="hidden" name="dol_openinpopup" value="'.$dol_openinpopup.'">';
1347
		print '<input type="hidden" name="private" value='.$object->particulier.'>';
1348
		print '<input type="hidden" name="type" value='.GETPOST("type", 'alpha').'>';
1349
		print '<input type="hidden" name="LastName" value="'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName').'">';
1350
		print '<input type="hidden" name="ThirdPartyName" value="'.$langs->trans('ThirdPartyName').'">';
1351
		if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) {
1352
			print '<input type="hidden" name="code_auto" value="1">';
1353
		}
1354
1355
		print dol_get_fiche_head(null, 'card', '', 0, '');
1356
1357
		print '<table class="border centpercent">';
1358
1359
		// Name, firstname
1360
		print '<tr class="tr-field-thirdparty-name"><td class="titlefieldcreate">';
1361
		if ($object->particulier || $private) {
1362
			print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName', 'name').'</span>';
1363
		} else {
1364
			print '<span id="TypeName" class="fieldrequired">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0).'</span>';
1365
		}
1366
		print '</td><td'.(empty($conf->global->SOCIETE_USEPREFIX) ? ' colspan="3"' : '').'>';
1367
1368
		print '<input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.dol_escape_htmltag($object->name).'" autofocus="autofocus">';
1369
		print $form->widgetForTranslation("name", $object, $permissiontoadd, 'string', 'alpahnohtml', 'minwidth300');
1370
		/* Disabled. Must be implenteted by keeping the input text but calling ajax on a keydown of the input and output
1371
		   data of duplicate into a div under the input. We need to keep the widgetForTranslation also for some countries.
1372
		 */
1373
		/*
1374
		print '<select class="name" name="name" id="name" style="min-width:500px"></select>';
1375
		print "\n".'<script type="text/javascript">';
1376
		print '$(document).ready(function () {
1377
			$("#name").select2({
1378
				ajax: {
1379
				  url: "' . DOL_URL_ROOT . '/core/ajax/ajaxcompanies.php",
1380
				  dataType: "json",
1381
				  delay: 250,
1382
				  data: function (params) {
1383
						return {
1384
							newcompany: params.term // search term
1385
						}
1386
				  },
1387
				  processResults: function (data, params) {
1388
					  return {
1389
						results: data
1390
					  }
1391
				  },
1392
				  cache: true
1393
				},
1394
1395
				placeholder: "' . $langs->trans('Name of the new third party. In the meantime we check if it already exists...') . '",
1396
				allowClear: true,
1397
				minimumInputLength: 3,
1398
				language: select2arrayoflanguage,
1399
				containerCssClass: ":all:",
1400
				selectionCssClass: ":all:",
1401
				tags: true,
1402
				templateResult: formatCustomer,
1403
				templateSelection: formatCustomerSelection
1404
			});
1405
1406
			function formatCustomer (Customer) {
1407
				if(Customer.label === undefined) {
1408
					return Customer.text;
1409
				}
1410
1411
				if(Customer.logo !== null ) {
1412
					logo = \'<img src="\';
1413
					logo += \'' . DOL_URL_ROOT . '/viewimage.php?modulepart=societe&amp;entity=1&amp;file=\' + Customer.key + "%2Flogos%2Fthumbs%2F" + Customer.logo.replace(".", "_mini.") + "&amp;cache=0";
1414
					logo += \'" /></div>\';
1415
				} else {
1416
					logo = \'<div class="floatleft inline-block valigntop photowithmargin" style="padding:0 10px"><div class="photosociete photoref" alt="No photo"><span class="fas fa-building" style="color: #6c6aa8;"></span></div></div>\';
1417
				}
1418
1419
				var $container = $("<div class=\'select2-result-repository clearfix\'>" +
1420
					 "<div class=\'select2-result-repository__avatar floatleft inline-block valigntop\'>" + logo +
1421
					  "<div class=\'select2-result-repository__meta floatleft inline-block valigntop\'>" +
1422
						"<div class=\'select2-result-repository__title\'></div>" +
1423
						"<div class=\'select2-result-repository__name_alias\'></div>" +
1424
						"<div class=\'select2-result-repository__code_client\'></div>" +
1425
						"<div class=\'select2-result-repository__code_fournisseur\'></div>" +
1426
						"<div class=\'select2-result-repository__companies_info\'>" +
1427
						  "<div class=\'select2-result-repository__email\'><i class=\'fa fa-at\'></i> </div>" +
1428
						  "<div class=\'select2-result-repository__address\'><i class=\'fa fa-flag\'></i> </div>" +
1429
						  "<div class=\'select2-result-repository__zip\'><i class=\'fa fa-circle-o\'></i> </div>" +
1430
						  "<div class=\'select2-result-repository__country\'><i class=\'fa fa-globe-americas\'></i> </div>" +
1431
						  "<div class=\'select2-result-repository__departement\'><i class=\'fa fa-circle-o\'></i> </div>" +
1432
						  "<div class=\'select2-result-repository__town\'><i class=\'fa fa-circle-o\'></i> </div>" +
1433
						  "<div class=\'select2-result-repository__siren\'><i class=\'fa fa-circle-o\'></i> </div>" +
1434
						  "<div class=\'select2-result-repository__datec\'><i class=\'fa fa-calendar\'></i> </div>" +
1435
						"</div>" +
1436
					  "</div>" +
1437
					"</div>"
1438
				);
1439
1440
				$container.find(".select2-result-repository__title").text(Customer.label);
1441
				$container.find(".select2-result-repository__name_alias").text(Customer.name_alias ? Customer.name_alias : "");
1442
				$container.find(".select2-result-repository__code_client").text(Customer.code_client ? Customer.code_client  : "");
1443
				$container.find(".select2-result-repository__code_fournisseur").text((Customer.code_fournisseur!==null) ? Customer.code_fournisseur : "");
1444
				$container.find(".select2-result-repository__email").append("' . $langs->trans('EMail') . ': " + (Customer.email !== null ? Customer.email : ""));
1445
				$container.find(".select2-result-repository__address").append("' . $langs->trans('Address') . ': " + (Customer.address !== null ? Customer.address : ""));
1446
				$container.find(".select2-result-repository__country").append("' . $langs->trans('Country') . ': " + (Customer.country !== null ? Customer.country : ""));
1447
				$container.find(".select2-result-repository__departement").append("' . $langs->trans('Region-State') . ': " + (Customer.departement !== null ? Customer.departement : ""));
1448
				$container.find(".select2-result-repository__zip").append("' . $langs->trans('Zip') . ': " + (Customer.zip !== null ? Customer.zip : ""));
1449
				$container.find(".select2-result-repository__town").append("' . $langs->trans('Town') . ': " + (Customer.town !== null ? Customer.town : ""));
1450
				$container.find(".select2-result-repository__siren").append("' . $langs->trans('Siren') . ': " + (Customer.siren !== null ? Customer.siren : ""));
1451
				$container.find(".select2-result-repository__datec").append("' . $langs->trans('Created') . ': " + (Customer.datec !== null ? Customer.datec : ""));
1452
1453
				return $container;
1454
			}
1455
1456
			function formatCustomerSelection (selection) {
1457
				return selection.label || selection.text;
1458
			}
1459
		});
1460
		</script>
1461
		';
1462
		*/
1463
		print '</td>';
1464
		if (!empty($conf->global->SOCIETE_USEPREFIX)) {  // Old not used prefix field
1465
			print '<td>'.$langs->trans('Prefix').'</td><td><input type="text" size="5" maxlength="5" name="prefix_comm" value="'.dol_escape_htmltag($object->prefix_comm).'"></td>';
1466
		}
1467
		print '</tr>';
1468
1469
		// If javascript on, we show option individual
1470
		if ($conf->use_javascript_ajax) {
1471
			if (!empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION)) {
1472
				// Firstname
1473
				print '<tr class="individualline"><td>'.$form->editfieldkey('FirstName', 'firstname', '', $object, 0).'</td>';
1474
				print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="firstname" id="firstname" value="'.dol_escape_htmltag($object->firstname).'"></td>';
1475
				print '</tr>';
1476
1477
				// Title
1478
				print '<tr class="individualline"><td>'.$form->editfieldkey('UserTitle', 'civility_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1479
				print $formcompany->select_civility($object->civility_id, 'civility_id', 'maxwidth100').'</td>';
1480
				print '</tr>';
1481
			}
1482
		}
1483
1484
		// Alias names (commercial, trademark or alias names)
1485
		print '<tr id="name_alias"><td><label for="name_alias_input">'.$langs->trans('AliasNames').'</label></td>';
1486
		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>';
1487
1488
		// Prospect/Customer
1489
		print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).'</td>';
1490
		print '<td class="maxwidthonsmartphone">';
1491
		$selected = (GETPOSTISSET('client') ?GETPOST('client', 'int') : $object->client);
1492
		print $formcompany->selectProspectCustomerType($selected);
1493
		print '</td>';
1494
1495
		if ($conf->browser->layout == 'phone') {
1496
			print '</tr><tr>';
1497
		}
1498
1499
		print '<td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
1500
		print '<table class="nobordernopadding"><tr><td>';
1501
		$tmpcode = $object->code_client;
1502
		if (empty($tmpcode) && !empty($modCodeClient->code_auto)) {
1503
			$tmpcode = $modCodeClient->getNextValue($object, 0);
1504
		}
1505
		print '<input type="text" name="customer_code" id="customer_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="24">';
1506
		print '</td><td>';
1507
		$s = $modCodeClient->getToolTip($langs, $object, 0);
1508
		print $form->textwithpicto('', $s, 1);
1509
		print '</td></tr></table>';
1510
		print '</td></tr>';
1511
1512
		if ((isModEnabled("fournisseur") && !empty($user->rights->fournisseur->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled("supplier_order") && !empty($user->rights->supplier_order->lire)) || (isModEnabled("supplier_invoice") && !empty($user->rights->supplier_invoice->lire))
1513
			|| (isModEnabled('supplier_proposal') && !empty($user->rights->supplier_proposal->lire))) {
1514
			// Supplier
1515
			print '<tr>';
1516
			print '<td>'.$form->editfieldkey('Vendor', 'fournisseur', '', $object, 0, 'string', '', 1).'</td><td>';
1517
			$default = -1;
1518
			if (!empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)) {
1519
				$default = 1;
1520
			}
1521
			print $form->selectyesno("fournisseur", (GETPOST('fournisseur', 'int') != '' ? GETPOST('fournisseur', 'int') : (GETPOST("type", 'alpha') == '' ? $default : $object->fournisseur)), 1, 0, (GETPOST("type", 'alpha') == '' ? 1 : 0), 1);
1522
			print '</td>';
1523
1524
1525
			if ($conf->browser->layout == 'phone') {
1526
				print '</tr><tr>';
1527
			}
1528
1529
			print '<td>';
1530
			if ((isModEnabled("fournisseur") && !empty($user->rights->fournisseur->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled("supplier_order") && !empty($user->rights->supplier_order->lire)) || (isModEnabled("supplier_invoice") && !empty($user->rights->supplier_invoice->lire))) {
1531
				print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0);
1532
			}
1533
			print '</td><td>';
1534
			if ((isModEnabled("fournisseur") && !empty($user->rights->fournisseur->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled("supplier_order") && !empty($user->rights->supplier_order->lire)) || (isModEnabled("supplier_invoice") && !empty($user->rights->supplier_invoice->lire))) {
1535
				print '<table class="nobordernopadding"><tr><td>';
1536
				$tmpcode = $object->code_fournisseur;
1537
				if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) {
1538
					$tmpcode = $modCodeFournisseur->getNextValue($object, 1);
1539
				}
1540
				print '<input type="text" name="supplier_code" id="supplier_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="24">';
1541
				print '</td><td>';
1542
				$s = $modCodeFournisseur->getToolTip($langs, $object, 1);
1543
				print $form->textwithpicto('', $s, 1);
1544
				print '</td></tr></table>';
1545
			}
1546
			print '</td></tr>';
1547
		}
1548
1549
		// Status
1550
		print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0).'</td><td colspan="3">';
1551
		print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), 1, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
1552
		print '</td></tr>';
1553
1554
		// Barcode
1555
		if (isModEnabled('barcode')) {
1556
			print '<tr><td>'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).'</td>';
1557
			print '<td colspan="3">';
1558
			print img_picto('', 'barcode', 'class="pictofixedwidth"');
1559
			print '<input type="text" name="barcode" id="barcode" value="'.dol_escape_htmltag($object->barcode).'">';
1560
			print '</td></tr>';
1561
		}
1562
1563
		// Address
1564
		print '<tr><td class="tdtop">';
1565
		print $form->editfieldkey('Address', 'address', '', $object, 0);
1566
		print '</td>';
1567
		print '<td colspan="3">';
1568
		print '<textarea name="address" id="address" class="quatrevingtpercent" rows="'.ROWS_2.'" wrap="soft">';
1569
		print dol_escape_htmltag($object->address, 0, 1);
1570
		print '</textarea>';
1571
		print $form->widgetForTranslation("address", $object, $permissiontoadd, 'textarea', 'alphanohtml', 'quatrevingtpercent');
1572
		print '</td></tr>';
1573
1574
		// Zip / Town
1575
		print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td>';
1576
		print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100');
1577
		print '</td>';
1578
		if ($conf->browser->layout == 'phone') {
1579
			print '</tr><tr>';
1580
		}
1581
		print '<td class="tdtop">'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td>';
1582
		print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth150 quatrevingtpercent');
1583
		print $form->widgetForTranslation("town", $object, $permissiontoadd, 'string', 'alphanohtml', 'maxwidth100 quatrevingtpercent');
1584
		print '</td></tr>';
1585
1586
		// Country
1587
		print '<tr><td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1588
		print img_picto('', 'country', 'class="pictofixedwidth"');
1589
		print $form->select_country((GETPOSTISSET('country_id') ? GETPOST('country_id') : $object->country_id), 'country_id', '', 0, 'minwidth300 maxwidth500 widthcentpercentminusx');
1590
		if ($user->admin) {
1591
			print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1592
		}
1593
		print '</td></tr>';
1594
1595
		// State
1596
		if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
1597
			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)) {
1598
				print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1599
			} else {
1600
				print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1601
			}
1602
1603
			if ($object->country_id) {
1604
				print img_picto('', 'state', 'class="pictofixedwidth"');
1605
				print $formcompany->select_state($object->state_id, $object->country_code);
1606
			} else {
1607
				print $countrynotdefined;
1608
			}
1609
			print '</td></tr>';
1610
		}
1611
1612
		// Phone / Fax
1613
		print '<tr><td>'.$form->editfieldkey('Phone', 'phone', '', $object, 0).'</td>';
1614
		print '<td'.($conf->browser->layout == 'phone' ? ' colspan="3"' : '').'>'.img_picto('', 'object_phoning', 'class="pictofixedwidth"').' <input type="text" name="phone" id="phone" class="maxwidth200 widthcentpercentminusx" value="'.(GETPOSTISSET('phone') ?GETPOST('phone', 'alpha') : $object->phone).'"></td>';
1615
		if ($conf->browser->layout == 'phone') {
1616
			print '</tr><tr>';
1617
		}
1618
		print '<td>'.$form->editfieldkey('Fax', 'fax', '', $object, 0).'</td>';
1619
		print '<td'.($conf->browser->layout == 'phone' ? ' colspan="3"' : '').'>'.img_picto('', 'object_phoning_fax', 'class="pictofixedwidth"').' <input type="text" name="fax" id="fax" class="maxwidth200 widthcentpercentminusx" value="'.(GETPOSTISSET('fax') ?GETPOST('fax', 'alpha') : $object->fax).'"></td></tr>';
1620
1621
		// Email / Web
1622
		print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', empty($conf->global->SOCIETE_EMAIL_MANDATORY) ? '' : $conf->global->SOCIETE_EMAIL_MANDATORY).'</td>';
1623
		print '<td'.(($conf->browser->layout == 'phone') || !isModEnabled('mailing') ? ' colspan="3"' : '').'>'.img_picto('', 'object_email', 'class="pictofixedwidth"').' <input type="text" class="maxwidth200 widthcentpercentminusx" name="email" id="email" value="'.$object->email.'"></td>';
1624
		if (isModEnabled('mailing') && !empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION)) {
1625
			if ($conf->browser->layout == 'phone') {
1626
				print '</tr><tr>';
1627
			}
1628
			print '<td class="individualline noemail">'.$form->editfieldkey($langs->trans('No_Email') .' ('.$langs->trans('Contact').')', 'contact_no_email', '', $object, 0).'</td>';
1629
			print '<td class="individualline" '.(($conf->browser->layout == 'phone') || !isModEnabled('mailing') ? ' colspan="3"' : '').'>'.$form->selectyesno('contact_no_email', (GETPOSTISSET("contact_no_email") ? GETPOST("contact_no_email", 'alpha') : (empty($object->no_email) ? 0 : 1)), 1, false, 1).'</td>';
1630
		}
1631
		print '</tr>';
1632
		print '<tr><td>'.$form->editfieldkey('Web', 'url', '', $object, 0).'</td>';
1633
		print '<td colspan="3">'.img_picto('', 'globe', 'class="pictofixedwidth"').' <input type="text" class="maxwidth500 widthcentpercentminusx" name="url" id="url" value="'.$object->url.'"></td></tr>';
1634
1635
			// Unsubscribe
1636
		if (!empty($conf->mailing->enabled)) {
1637
			if ($conf->use_javascript_ajax && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2) {
1638
				print "\n".'<script type="text/javascript">'."\n";
1639
				print '$(document).ready(function () {
1640
							$("#email").keyup(function() {
1641
								if ($(this).val()!="") {
1642
									$(".noemail").addClass("fieldrequired");
1643
								} else {
1644
									$(".noemail").removeClass("fieldrequired");
1645
								}
1646
							});
1647
						})'."\n";
1648
				print '</script>'."\n";
1649
			}
1650
			if (!GETPOSTISSET("no_email") && !empty($object->email)) {
1651
				$result = $object->getNoEmail();
1652
				if ($result < 0) {
1653
					setEventMessages($object->error, $object->errors, 'errors');
1654
				}
1655
			}
1656
			print '<tr>';
1657
			print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
1658
			print '<td>';
1659
			print $form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOST("no_email", 'int') : $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS), 1, false, ($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2));
1660
			print '</td>';
1661
			print '</tr>';
1662
		}
1663
1664
		// Social networks
1665
		if (isModEnabled('socialnetworks')) {
1666
			$object->showSocialNetwork($socialnetworks, ($conf->browser->layout == 'phone' ? 2 : 4));
1667
		}
1668
1669
		// Prof ids
1670
		$i = 1; $j = 0; $NBCOLS = ($conf->browser->layout == 'phone' ? 1 : 2);
1671
		while ($i <= 6) {
1672
			$idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
1673
			if ($idprof != '-')	{
1674
				$key = 'idprof'.$i;
1675
1676
				if (($j % $NBCOLS) == 0) {
1677
					print '<tr>';
1678
				}
1679
1680
				$idprof_mandatory = 'SOCIETE_IDPROF'.($i).'_MANDATORY';
1681
				print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', (empty($conf->global->$idprof_mandatory) ? 0 : 1)).'</td><td>';
1682
1683
				print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
1684
				print '</td>';
1685
				if (($j % $NBCOLS) == ($NBCOLS - 1)) {
1686
					print '</tr>';
1687
				}
1688
				$j++;
1689
			}
1690
			$i++;
1691
		}
1692
		if ($NBCOLS > 1 && ($j % 2 == 1)) {
1693
			print '<td colspan="2"></td></tr>';
1694
		}
1695
1696
		// Vat is used
1697
		print '<tr><td>'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).'</td>';
1698
		print '<td>';
1699
		print $form->selectyesno('assujtva_value', GETPOSTISSET('assujtva_value') ?GETPOST('assujtva_value', 'int') : 1, 1); // Assujeti par defaut en creation
1700
		print '</td>';
1701
		if ($conf->browser->layout == 'phone') {
1702
			print '</tr><tr>';
1703
		}
1704
		print '<td class="nowrap">'.$form->editfieldkey('VATIntra', 'intra_vat', '', $object, 0).'</td>';
1705
		print '<td class="nowrap">';
1706
		$s = '<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
1707
1708
		if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object)) {
1709
			$s .= ' ';
1710
1711
			if (!empty($conf->use_javascript_ajax))	{
1712
				$widthpopup = 600;
1713
				if (!empty($conf->dol_use_jmobile)) {
1714
					$widthpopup = 350;
1715
				}
1716
				$heightpopup = 400;
1717
				print "\n";
1718
				print '<script type="text/javascript">';
1719
				print "function CheckVAT(a) {\n";
1720
				print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a, '".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
1721
				print "}\n";
1722
				print '</script>';
1723
				print "\n";
1724
				$s .= '<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
1725
				$s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1);
1726
			} else {
1727
				$s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", $object->country_id).'" target="_blank" rel="noopener noreferrer">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
1728
			}
1729
		}
1730
		print $s;
1731
		print '</td>';
1732
		print '</tr>';
1733
1734
		// Local Taxes
1735
		//TODO: Place into a function to control showing by country or study better option
1736
		if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
1737
			print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
1738
			print $form->selectyesno('localtax1assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1 : 0), 1);
1739
			print '</td>';
1740
			if ($conf->browser->layout == 'phone') {
1741
				print '</tr><tr>';
1742
			}
1743
			print '<td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
1744
			print $form->selectyesno('localtax2assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2 : 0), 1);
1745
			print '</td></tr>';
1746
		} elseif ($mysoc->localtax1_assuj == "1") {
1747
			print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td colspan="3">';
1748
			print $form->selectyesno('localtax1assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1 : 0), 1);
1749
			print '</td></tr>';
1750
		} elseif ($mysoc->localtax2_assuj == "1") {
1751
			print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td colspan="3">';
1752
			print $form->selectyesno('localtax2assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2 : 0), 1);
1753
			print '</td></tr>';
1754
		}
1755
1756
		// Type - Workforce/Staff
1757
		print '<tr><td>'.$form->editfieldkey('ThirdPartyType', 'typent_id', '', $object, 0).'</td><td class="maxwidthonsmartphone"'.( ($conf->browser->layout == 'phone' || !empty($conf->global->SOCIETE_DISABLE_WORKFORCE)) ? ' colspan="3"' : '').'>'."\n";
1758
		$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.
1759
		print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 1, 0, 0, '', 0, 0, 0, $sortparam, '', 1);
1760
		if ($user->admin) {
1761
			print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1762
		}
1763
		if (empty($conf->global->SOCIETE_DISABLE_WORKFORCE)) {
1764
			print '</td>';
1765
			if ($conf->browser->layout == 'phone') {
1766
				print '</tr><tr>';
1767
			}
1768
			print '<td>'.$form->editfieldkey('Workforce', 'effectif_id', '', $object, 0).'</td><td class="maxwidthonsmartphone"'.($conf->browser->layout == 'phone' ? ' colspan="3"' : '').'>';
1769
			print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id, 0, 0, 0, '', 0, 0, 0, '', '', 1);
1770
			if ($user->admin) {
1771
				print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1772
			}
1773
		} else {
1774
			print '<input type="hidden" name="effectif_id" id="effectif_id" value="'.$object->effectif_id.'">';
1775
		}
1776
		print '</td></tr>';
1777
1778
		// Legal Form
1779
		print '<tr><td>'.$form->editfieldkey('JuridicalStatus', 'forme_juridique_code', '', $object, 0).'</td>';
1780
		print '<td colspan="3" class="maxwidthonsmartphone">';
1781
		if ($object->country_id) {
1782
			print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code');
1783
		} else {
1784
			print $countrynotdefined;
1785
		}
1786
		print '</td></tr>';
1787
1788
		// Capital
1789
		print '<tr><td>'.$form->editfieldkey('Capital', 'capital', '', $object, 0).'</td>';
1790
		print '<td colspan="3"><input type="text" name="capital" id="capital" class="maxwidth100" value="'.$object->capital.'"> ';
1791
		if (isModEnabled("multicurrency")) {
1792
			print '<span class="hideonsmartphone">'.$langs->trans("Currency".$object->multicurrency_code).'</span></td></tr>';
1793
		} else {
1794
			print '<span class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
1795
		}
1796
		if (getDolGlobalInt('MAIN_MULTILANGS')) {
1797
			print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
1798
			print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language(GETPOST('default_lang', 'alpha') ? GETPOST('default_lang', 'alpha') : ($object->default_lang ? $object->default_lang : ''), 'default_lang', 0, 0, 1, 0, 0, 'maxwidth200onsmartphone');
1799
			print '</td>';
1800
			print '</tr>';
1801
		}
1802
1803
		// Incoterms
1804
		if (isModEnabled('incoterm')) {
1805
			print '<tr>';
1806
			print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
1807
			print '<td colspan="3" class="maxwidthonsmartphone">';
1808
			print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
1809
			print '</td></tr>';
1810
		}
1811
1812
		// Categories
1813
		if (isModEnabled('categorie') && !empty($user->rights->categorie->lire)) {
1814
			$langs->load('categories');
1815
1816
			// Customer
1817
			print '<tr class="visibleifcustomer"><td class="toptd">'.$form->editfieldkey('CustomersProspectsCategoriesShort', 'custcats', '', $object, 0).'</td><td colspan="3">';
1818
			$cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, 'parent', null, null, 1);
1819
			print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('custcats', $cate_arbo, GETPOST('custcats', 'array'), null, null, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
1820
			print "</td></tr>";
1821
1822
			if (!empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION)) {
1823
				print '<tr class="individualline"><td class="toptd">'.$form->editfieldkey('ContactCategoriesShort', 'contcats', '', $object, 0).'</td><td colspan="3">';
1824
				$cate_arbo = $form->select_all_categories(Categorie::TYPE_CONTACT, null, 'parent', null, null, 1);
1825
				print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('contcats', $cate_arbo, GETPOST('contcats', 'array'), null, null, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
1826
				print "</td></tr>";
1827
			}
1828
1829
			// Supplier
1830
			if ((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
1831
				print '<tr class="visibleifsupplier"><td class="toptd">'.$form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0).'</td><td colspan="3">';
1832
				$cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, 'parent', null, null, 1);
1833
				print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('suppcats', $cate_arbo, GETPOST('suppcats', 'array'), null, null, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
1834
				print "</td></tr>";
1835
			}
1836
		}
1837
1838
		// Multicurrency
1839
		if (isModEnabled("multicurrency")) {
1840
			print '<tr>';
1841
			print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
1842
			print '<td colspan="3" class="maxwidthonsmartphone">';
1843
			print img_picto('', 'currency', 'class="pictofixedwidth"');
1844
			print $form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code') : ($object->multicurrency_code ? $object->multicurrency_code : $conf->currency)), 'multicurrency_code', 1, '', false, 'maxwidth150 widthcentpercentminusx');
1845
			print '</td></tr>';
1846
		}
1847
1848
		// Other attributes
1849
		$parameters = array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
1850
		include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
1851
1852
		// Parent company
1853
		if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY)) {
1854
			print '<tr>';
1855
			print '<td>'.$langs->trans('ParentCompany').'</td>';
1856
			print '<td colspan="3" class="maxwidthonsmartphone">';
1857
			print img_picto('', 'company', 'class="paddingrightonly"');
1858
			print $form->select_company(GETPOST('parent_company_id'), 'parent_company_id', '', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300 maxwidth500 widthcentpercentminusxx');
1859
			print '</td></tr>';
1860
		}
1861
1862
		// Assign a sale representative
1863
		print '<tr>';
1864
		print '<td>'.$form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0).'</td>';
1865
		print '<td colspan="3" class="maxwidthonsmartphone">';
1866
		$userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, 'AND u.statut = 1', 0, '', '', 0, 1);
1867
		// Note: If user has no right to "see all thirdparties", we force selection of sale representative to him, so after creation he can see the record.
1868
		$selected = (count(GETPOST('commercial', 'array')) > 0 ? GETPOST('commercial', 'array') : (GETPOST('commercial', 'int') > 0 ? array(GETPOST('commercial', 'int')) : (empty($user->rights->societe->client->voir) ? array($user->id) : array())));
1869
		print img_picto('', 'user').$form->multiselectarray('commercial', $userlist, $selected, null, null, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
1870
		print '</td></tr>';
1871
1872
		// Add logo
1873
		print '<tr class="hideonsmartphone">';
1874
		print '<td>'.$form->editfieldkey('Logo', 'photoinput', '', $object, 0).'</td>';
1875
		print '<td colspan="3">';
1876
		print '<input class="flat" type="file" name="photo" id="photoinput" />';
1877
		print '</td>';
1878
		print '</tr>';
1879
1880
		print '</table>'."\n";
1881
1882
		// Accountancy codes
1883
		if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
1884
			print '<table class="border centpercent">';
1885
1886
			if (isModEnabled('accounting')) {
1887
				// Accountancy_code_sell
1888
				print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
1889
				print '<td>';
1890
				$accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
1891
				print $formaccounting->select_account($accountancy_code_sell, 'accountancy_code_sell', 1, null, 1, 1, '');
1892
				print '</td></tr>';
1893
1894
				// Accountancy_code_buy
1895
				print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyCode").'</td>';
1896
				print '<td>';
1897
				$accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
1898
				print $formaccounting->select_account($accountancy_code_buy, 'accountancy_code_buy', 1, null, 1, 1, '');
1899
				print '</td></tr>';
1900
			} else { // For external software
1901
				// Accountancy_code_sell
1902
				print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
1903
				print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code_sell" value="'.$object->accountancy_code_sell.'">';
1904
				print '</td></tr>';
1905
1906
				// Accountancy_code_buy
1907
				print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyCode").'</td>';
1908
				print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code_buy" value="'.$object->accountancy_code_buy.'">';
1909
				print '</td></tr>';
1910
			}
1911
1912
			print '</table>';
1913
		}
1914
1915
		print dol_get_fiche_end();
1916
1917
		print $form->buttonsSaveCancel("AddThirdParty", 'Cancel', null, 0, '', $dol_openinpopup);
1918
1919
		print '</form>'."\n";
1920
	} elseif ($action == 'edit') {
1921
		//print load_fiche_titre($langs->trans("EditCompany"));
1922
1923
		if ($socid) {
1924
			$res = $object->fetch_optionals();
1925
			//if ($res < 0) { dol_print_error($db); exit; }
1926
1927
			$head = societe_prepare_head($object);
1928
1929
			// Load object modCodeTiers
1930
			$module = (!empty($conf->global->SOCIETE_CODECLIENT_ADDON) ? $conf->global->SOCIETE_CODECLIENT_ADDON : 'mod_codeclient_leopard');
1931
			if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
1932
				$module = substr($module, 0, dol_strlen($module) - 4);
1933
			}
1934
			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
1935
			foreach ($dirsociete as $dirroot) {
1936
				$res = dol_include_once($dirroot.$module.'.php');
1937
				if ($res) {
1938
					break;
1939
				}
1940
			}
1941
			$modCodeClient = new $module($db);
1942
			// We verified if the tag prefix is used
1943
			if ($modCodeClient->code_auto) {
1944
				$prefixCustomerIsUsed = $modCodeClient->verif_prefixIsUsed();
1945
			}
1946
			$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
1947
			if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
1948
				$module = substr($module, 0, dol_strlen($module) - 4);
1949
			}
1950
			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
1951
			foreach ($dirsociete as $dirroot) {
1952
				$res = dol_include_once($dirroot.$module.'.php');
1953
				if ($res) {
1954
					break;
1955
				}
1956
			}
1957
			$modCodeFournisseur = new $module($db);
1958
			// On verifie si la balise prefix est utilisee
1959
			if ($modCodeFournisseur->code_auto) {
1960
				$prefixSupplierIsUsed = $modCodeFournisseur->verif_prefixIsUsed();
1961
			}
1962
1963
			$object->oldcopy = clone $object;
1964
1965
			if (GETPOSTISSET('name')) {
1966
				// We overwrite with values if posted
1967
				$object->name = GETPOST('name', 'alphanohtml');
1968
				$object->name_alias = GETPOST('name_alias', 'alphanohtml');
1969
				$object->prefix_comm = GETPOST('prefix_comm', 'alphanohtml');
1970
				$object->client = GETPOST('client', 'int');
1971
				$object->code_client = GETPOST('customer_code', 'alpha');
1972
				$object->fournisseur = GETPOST('fournisseur', 'int');
1973
				$object->code_fournisseur = GETPOST('supplier_code', 'alpha');
1974
				$object->address = GETPOST('address', 'alphanohtml');
1975
				$object->zip = GETPOST('zipcode', 'alphanohtml');
1976
				$object->town = GETPOST('town', 'alphanohtml');
1977
				$object->country_id = GETPOST('country_id') ?GETPOST('country_id', 'int') : $mysoc->country_id;
1978
				$object->state_id = GETPOST('state_id', 'int');
1979
				$object->parent = GETPOST('parent_company_id', 'int');
1980
1981
				$object->socialnetworks = array();
1982
				if (isModEnabled('socialnetworks')) {
1983
					foreach ($socialnetworks as $key => $value) {
1984
						if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
1985
							$object->socialnetworks[$key] = GETPOST($key, 'alphanohtml');
1986
						}
1987
					}
1988
				}
1989
1990
				$object->phone					= GETPOST('phone', 'alpha');
1991
				$object->fax					= GETPOST('fax', 'alpha');
1992
				$object->email					= GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL);
1993
				$object->no_email				= GETPOST("no_email", "int");
1994
				$object->url					= GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL);
1995
				$object->capital				= GETPOST('capital', 'alphanohtml');
1996
				$object->idprof1				= GETPOST('idprof1', 'alphanohtml');
1997
				$object->idprof2				= GETPOST('idprof2', 'alphanohtml');
1998
				$object->idprof3				= GETPOST('idprof3', 'alphanohtml');
1999
				$object->idprof4				= GETPOST('idprof4', 'alphanohtml');
2000
				$object->idprof5				= GETPOST('idprof5', 'alphanohtml');
2001
				$object->idprof6				= GETPOST('idprof6', 'alphanohtml');
2002
				$object->typent_id = GETPOST('typent_id', 'int');
2003
				$object->effectif_id = GETPOST('effectif_id', 'int');
2004
				$object->barcode				= GETPOST('barcode', 'alphanohtml');
2005
				$object->forme_juridique_code = GETPOST('forme_juridique_code', 'int');
2006
				$object->default_lang = GETPOST('default_lang', 'alpha');
2007
2008
				$object->tva_assuj				= GETPOST('assujtva_value', 'int');
2009
				$object->tva_intra				= GETPOST('tva_intra', 'alphanohtml');
2010
				$object->status = GETPOST('status', 'int');
2011
2012
				// Webservices url/key
2013
				$object->webservices_url        = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
2014
				$object->webservices_key        = GETPOST('webservices_key', 'san_alpha');
2015
2016
				if (GETPOSTISSET('accountancy_code_sell')) {
2017
					$accountancy_code_sell  = GETPOST('accountancy_code_sell', 'alpha');
2018
2019
					if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') {
2020
						$object->accountancy_code_sell = '';
2021
					} else {
2022
						$object->accountancy_code_sell = $accountancy_code_sell;
2023
					}
2024
				}
2025
				if (GETPOSTISSET('accountancy_code_buy')) {
2026
					$accountancy_code_buy   = GETPOST('accountancy_code_buy', 'alpha');
2027
2028
					if (empty($accountancy_code_buy) || $accountancy_code_buy == '-1') {
2029
						$object->accountancy_code_buy = '';
2030
					} else {
2031
						$object->accountancy_code_buy = $accountancy_code_buy;
2032
					}
2033
				}
2034
2035
				//Incoterms
2036
				if (isModEnabled('incoterm')) {
2037
					$object->fk_incoterms = GETPOST('incoterm_id', 'int');
2038
					$object->location_incoterms = GETPOST('lcoation_incoterms', 'alpha');
2039
				}
2040
2041
				//Local Taxes
2042
				$object->localtax1_assuj		= GETPOST('localtax1assuj_value');
2043
				$object->localtax2_assuj		= GETPOST('localtax2assuj_value');
2044
2045
				$object->localtax1_value		= GETPOST('lt1');
2046
				$object->localtax2_value		= GETPOST('lt2');
2047
2048
				// We set country_id, and country_code label of the chosen country
2049
				if ($object->country_id > 0) {
2050
					$tmparray = getCountry($object->country_id, 'all');
2051
					$object->country_code = $tmparray['code'];
2052
					$object->country = $tmparray['label'];
2053
				}
2054
2055
				// We set multicurrency_code if enabled
2056
				if (isModEnabled("multicurrency")) {
2057
					$object->multicurrency_code = GETPOST('multicurrency_code') ? GETPOST('multicurrency_code') : $object->multicurrency_code;
2058
				}
2059
			}
2060
2061
			if ($object->localtax1_assuj == 0) {
2062
				$sub = 0;
2063
			} else {
2064
				$sub = 1;
2065
			}
2066
			if ($object->localtax2_assuj == 0) {
2067
				$sub2 = 0;
2068
			} else {
2069
				$sub2 = 1;
2070
			}
2071
2072
			if (!empty($conf->use_javascript_ajax)) {
2073
				print "\n".'<script type="text/javascript">';
2074
				print '$(document).ready(function () {
2075
    			var val='.$sub.';
2076
    			var val2='.$sub2.';
2077
    			if("#localtax1assuj_value".value==undefined){
2078
    				if(val==1){
2079
    					$(".cblt1").show();
2080
    				}else{
2081
    					$(".cblt1").hide();
2082
    				}
2083
    			}
2084
    			if("#localtax2assuj_value".value==undefined){
2085
    				if(val2==1){
2086
    					$(".cblt2").show();
2087
    				}else{
2088
    					$(".cblt2").hide();
2089
    				}
2090
    			}
2091
    			$("#localtax1assuj_value").change(function() {
2092
               		var value=document.getElementById("localtax1assuj_value").value;
2093
    				if(value==1){
2094
    					$(".cblt1").show();
2095
    				}else{
2096
    					$(".cblt1").hide();
2097
    				}
2098
    			});
2099
    			$("#localtax2assuj_value").change(function() {
2100
    				var value=document.getElementById("localtax2assuj_value").value;
2101
    				if(value==1){
2102
    					$(".cblt2").show();
2103
    				}else{
2104
    					$(".cblt2").hide();
2105
    				}
2106
    			});
2107
2108
				var canHaveCategoryIfNotCustomerProspectSupplier = ' . (empty($conf->global->THIRDPARTY_CAN_HAVE_CUSTOMER_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT) ? '0' : '1') . ';
2109
2110
				init_customer_categ();
2111
	  			$("#customerprospect").change(function() {
2112
					init_customer_categ();
2113
				});
2114
       			function init_customer_categ() {
2115
					console.log("is customer or prospect = "+jQuery("#customerprospect").val());
2116
					if (jQuery("#customerprospect").val() == 0 && !canHaveCategoryIfNotCustomerProspectSupplier)
2117
					{
2118
						jQuery(".visibleifcustomer").hide();
2119
					}
2120
					else
2121
					{
2122
						jQuery(".visibleifcustomer").show();
2123
					}
2124
				}
2125
2126
				init_supplier_categ();
2127
	  			$("#fournisseur").change(function() {
2128
					init_supplier_categ();
2129
				});
2130
       			function init_supplier_categ() {
2131
					console.log("is supplier = "+jQuery("#fournisseur").val());
2132
					if (jQuery("#fournisseur").val() == 0)
2133
					{
2134
						jQuery(".visibleifsupplier").hide();
2135
					}
2136
					else
2137
					{
2138
						jQuery(".visibleifsupplier").show();
2139
					}
2140
				}
2141
2142
       			$("#selectcountry_id").change(function() {
2143
       				document.formsoc.action.value="edit";
2144
      				document.formsoc.submit();
2145
        			});
2146
2147
                })';
2148
				print '</script>'."\n";
2149
			}
2150
2151
			print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="post" name="formsoc">';
2152
			print '<input type="hidden" name="action" value="update">';
2153
			print '<input type="hidden" name="token" value="'.newToken().'">';
2154
			print '<input type="hidden" name="socid" value="'.$object->id.'">';
2155
			print '<input type="hidden" name="entity" value="'.$object->entity.'">';
2156
			if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) {
2157
				print '<input type="hidden" name="code_auto" value="1">';
2158
			}
2159
2160
2161
			print dol_get_fiche_head($head, 'card', $langs->trans("ThirdParty"), 0, 'company');
2162
2163
			print '<div class="fichecenter2">';
2164
			print '<table class="border centpercent">';
2165
2166
			// Ref/ID
2167
			if (!empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
2168
				print '<tr><td class="titlefieldcreate">'.$langs->trans("ID").'</td><td colspan="3">';
2169
				print $object->ref;
2170
				print '</td></tr>';
2171
			}
2172
2173
			// Name
2174
			print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0, 'string', '', 1).'</td>';
2175
			print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.dol_escape_htmltag($object->name).'" autofocus="autofocus">';
2176
			print $form->widgetForTranslation("name", $object, $permissiontoadd, 'string', 'alpahnohtml', 'minwidth300');
2177
			print '</td></tr>';
2178
2179
			// Alias names (commercial, trademark or alias names)
2180
			print '<tr id="name_alias"><td><label for="name_alias_input">'.$langs->trans('AliasNames').'</label></td>';
2181
			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>';
2182
2183
			// Prefix
2184
			if (!empty($conf->global->SOCIETE_USEPREFIX)) {  // Old not used prefix field
2185
				print '<tr><td>'.$form->editfieldkey('Prefix', 'prefix', '', $object, 0).'</td><td colspan="3">';
2186
				// It does not change the prefix mode using the auto numbering prefix
2187
				if (($prefixCustomerIsUsed || $prefixSupplierIsUsed) && $object->prefix_comm) {
2188
					print '<input type="hidden" name="prefix_comm" value="'.dol_escape_htmltag($object->prefix_comm).'">';
2189
					print $object->prefix_comm;
2190
				} else {
2191
					print '<input type="text" size="5" maxlength="5" name="prefix_comm" id="prefix" value="'.dol_escape_htmltag($object->prefix_comm).'">';
2192
				}
2193
				print '</td>';
2194
			}
2195
2196
			// Prospect/Customer
2197
			print '<tr><td>'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).'</td>';
2198
			print '<td class="maxwidthonsmartphone">';
2199
			print $formcompany->selectProspectCustomerType($object->client);
2200
			print '</td>';
2201
			if ($conf->browser->layout == 'phone') {
2202
				print '</tr><tr>';
2203
			}
2204
			print '<td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
2205
2206
			print '<table class="nobordernopadding"><tr><td>';
2207
			if ((!$object->code_client || $object->code_client == -1) && $modCodeClient->code_auto) {
2208
				$tmpcode = $object->code_client;
2209
				if (empty($tmpcode) && !empty($object->oldcopy->code_client)) {
2210
					$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.
2211
				}
2212
				if (empty($tmpcode) && !empty($modCodeClient->code_auto)) {
2213
					$tmpcode = $modCodeClient->getNextValue($object, 0);
2214
				}
2215
				print '<input type="text" name="customer_code" id="customer_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="24">';
2216
			} elseif ($object->codeclient_modifiable()) {
2217
				print '<input type="text" name="customer_code" id="customer_code" size="16" value="'.dol_escape_htmltag($object->code_client).'" maxlength="24">';
2218
			} else {
2219
				print $object->code_client;
2220
				print '<input type="hidden" name="customer_code" value="'.dol_escape_htmltag($object->code_client).'">';
2221
			}
2222
			print '</td><td>';
2223
			$s = $modCodeClient->getToolTip($langs, $object, 0);
2224
			print $form->textwithpicto('', $s, 1);
2225
			print '</td></tr></table>';
2226
2227
			print '</td></tr>';
2228
2229
			// Supplier
2230
			if (((isModEnabled("fournisseur") && !empty($user->rights->fournisseur->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled("supplier_order") && !empty($user->rights->supplier_order->lire)) || (isModEnabled("supplier_invoice") && !empty($user->rights->supplier_invoice->lire)))
2231
				|| (isModEnabled('supplier_proposal') && !empty($user->rights->supplier_proposal->lire))) {
2232
				print '<tr>';
2233
				print '<td>'.$form->editfieldkey('Supplier', 'fournisseur', '', $object, 0, 'string', '', 1).'</td>';
2234
				print '<td class="maxwidthonsmartphone">';
2235
				print $form->selectyesno("fournisseur", $object->fournisseur, 1, false, 0, 1);
2236
				print '</td>';
2237
				if ($conf->browser->layout == 'phone') {
2238
					print '</tr><tr>';
2239
				}
2240
				print '<td>';
2241
				if ((isModEnabled("fournisseur") && !empty($user->rights->fournisseur->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled("supplier_order") && !empty($user->rights->supplier_order->lire)) || (isModEnabled("supplier_invoice") && !empty($user->rights->supplier_invoice->lire))) {
2242
					print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0);
2243
				}
2244
				print '</td>';
2245
				print '<td>';
2246
				print '<table class="nobordernopadding"><tr><td>';
2247
				if ((!$object->code_fournisseur || $object->code_fournisseur == -1) && $modCodeFournisseur->code_auto) {
2248
					$tmpcode = $object->code_fournisseur;
2249
					if (empty($tmpcode) && !empty($object->oldcopy->code_fournisseur)) {
2250
						$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.
2251
					}
2252
					if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) {
2253
						$tmpcode = $modCodeFournisseur->getNextValue($object, 1);
2254
					}
2255
					print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="24">';
2256
				} elseif ($object->codefournisseur_modifiable()) {
2257
					print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.dol_escape_htmltag($object->code_fournisseur).'" maxlength="24">';
2258
				} else {
2259
					print $object->code_fournisseur;
2260
					print '<input type="hidden" name="supplier_code" value="'.$object->code_fournisseur.'">';
2261
				}
2262
				print '</td><td>';
2263
				$s = $modCodeFournisseur->getToolTip($langs, $object, 1);
2264
				print $form->textwithpicto('', $s, 1);
2265
				print '</td></tr></table>';
2266
				print '</td></tr>';
2267
			}
2268
2269
			// Barcode
2270
			if (isModEnabled('barcode')) {
2271
				print '<tr><td class="tdtop">'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).'</td>';
2272
				print '<td colspan="3">';
2273
				print img_picto('', 'barcode');
2274
				print '<input type="text" name="barcode" id="barcode" value="'.dol_escape_htmltag($object->barcode).'">';
2275
				print '</td></tr>';
2276
			}
2277
2278
			// Status
2279
			print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0).'</td><td colspan="3">';
2280
			print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), $object->status, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
2281
			print '</td></tr>';
2282
2283
			// Address
2284
			print '<tr><td class="tdtop">'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
2285
			print '<td colspan="3"><textarea name="address" id="address" class="quatrevingtpercent" rows="3" wrap="soft">';
2286
			print dol_escape_htmltag($object->address, 0, 1);
2287
			print '</textarea>';
2288
			print $form->widgetForTranslation("address", $object, $permissiontoadd, 'textarea', 'alphanohtml', 'quatrevingtpercent');
2289
			print '</td></tr>';
2290
2291
			// Zip / Town
2292
			print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td'.($conf->browser->layout == 'phone' ? ' colspan="3"': '').'>';
2293
			print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100');
2294
			print '</td>';
2295
			if ($conf->browser->layout == 'phone') {
2296
				print '</tr><tr>';
2297
			}
2298
			print '<td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td'.($conf->browser->layout == 'phone' ? ' colspan="3"': '').'>';
2299
			print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
2300
			print $form->widgetForTranslation("town", $object, $permissiontoadd, 'string', 'alphanohtml', 'maxwidth100 quatrevingtpercent');
2301
			print '</td></tr>';
2302
2303
			// Country
2304
			print '<tr><td>'.$form->editfieldkey('Country', 'selectcounty_id', '', $object, 0).'</td><td colspan="3">';
2305
			print img_picto('', 'globe-americas', 'class="paddingrightonly"');
2306
			print $form->select_country((GETPOSTISSET('country_id') ? GETPOST('country_id') : $object->country_id), 'country_id', '', 0, 'minwidth300 maxwidth500 widthcentpercentminusx');
2307
			if ($user->admin) {
2308
				print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
2309
			}
2310
			print '</td></tr>';
2311
2312
			// State
2313
			if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
2314
				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)) {
2315
					print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td colspan="3">';
2316
				} else {
2317
					print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td colspan="3">';
2318
				}
2319
2320
				print img_picto('', 'state', 'class="pictofixedwidth"');
2321
				print $formcompany->select_state($object->state_id, $object->country_code);
2322
				print '</td></tr>';
2323
			}
2324
2325
			// Phone / Fax
2326
			print '<tr><td>'.$form->editfieldkey('Phone', 'phone', GETPOST('phone', 'alpha'), $object, 0).'</td>';
2327
			print '<td'.($conf->browser->layout == 'phone' ? ' colspan="3"': '').'>'.img_picto('', 'object_phoning', 'class="pictofixedwidth"').' <input type="text" name="phone" id="phone" class="maxwidth200 widthcentpercentminusx" value="'.(GETPOSTISSET('phone') ? GETPOST('phone', 'alpha') : $object->phone).'"></td>';
2328
			if ($conf->browser->layout == 'phone') {
2329
				print '</tr><tr>';
2330
			}
2331
			print '<td>'.$form->editfieldkey('Fax', 'fax', GETPOST('fax', 'alpha'), $object, 0).'</td>';
2332
			print '<td'.($conf->browser->layout == 'phone' ? ' colspan="3"': '').'>'.img_picto('', 'object_phoning_fax', 'class="pictofixedwidth"').' <input type="text" name="fax" id="fax" class="maxwidth200 widthcentpercentminusx" value="'.(GETPOSTISSET('fax') ? GETPOST('fax', 'alpha') : $object->fax).'"></td>';
2333
			print '</tr>';
2334
2335
			// Web
2336
			print '<tr><td>'.$form->editfieldkey('Web', 'url', GETPOST('url', 'alpha'), $object, 0).'</td>';
2337
			print '<td colspan="3">'.img_picto('', 'globe', 'class="pictofixedwidth"').' <input type="text" name="url" id="url" class="maxwidth200onsmartphone maxwidth300 widthcentpercentminusx " value="'.(GETPOSTISSET('url') ?GETPOST('url', 'alpha') : $object->url).'"></td></tr>';
2338
2339
			// EMail
2340
			print '<tr><td>'.$form->editfieldkey('EMail', 'email', GETPOST('email', 'alpha'), $object, 0, 'string', '', (!empty($conf->global->SOCIETE_EMAIL_MANDATORY))).'</td>';
2341
			print '<td colspan="3">';
2342
			print img_picto('', 'object_email', 'class="pictofixedwidth"');
2343
			print '<input type="text" name="email" id="email" class="maxwidth500 widthcentpercentminusx" value="'.(GETPOSTISSET('email') ?GETPOST('email', 'alpha') : $object->email).'">';
2344
			print '</td></tr>';
2345
2346
			// Unsubscribe
2347
			if (!empty($conf->mailing->enabled)) {
2348
				if ($conf->use_javascript_ajax && isset($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS) && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2) {
2349
					print "\n".'<script type="text/javascript">'."\n";
2350
2351
					print '
2352
					jQuery(document).ready(function () {
2353
						function init_check_no_email(input) {
2354
							if (input.val()!="") {
2355
								$(".noemail").addClass("fieldrequired");
2356
							} else {
2357
								$(".noemail").removeClass("fieldrequired");
2358
							}
2359
						}
2360
						$("#email").keyup(function() {
2361
							init_check_no_email($(this));
2362
						});
2363
						init_check_no_email($("#email"));
2364
					})'."\n";
2365
					print '</script>'."\n";
2366
				}
2367
				if (!GETPOSTISSET("no_email") && !empty($object->email)) {
2368
					$result = $object->getNoEmail();
2369
					if ($result < 0) {
2370
						setEventMessages($object->error, $object->errors, 'errors');
2371
					}
2372
				}
2373
				print '<tr>';
2374
				print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
2375
				print '<td>';
2376
				$useempty = (isset($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS) && ($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2));
2377
				print $form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOST("no_email", 'int') : $object->no_email), 1, false, $useempty);
2378
				print '</td>';
2379
				print '</tr>';
2380
			}
2381
2382
			// Social network
2383
			if (isModEnabled('socialnetworks')) {
2384
				$object->showSocialNetwork($socialnetworks, ($conf->browser->layout == 'phone' ? 2 : 4));
2385
			}
2386
2387
			// Prof ids
2388
			$i = 1;
2389
			$j = 0;
2390
			$NBCOLS = ($conf->browser->layout == 'phone' ? 1 : 2);
2391
			while ($i <= 6) {
2392
				$idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
2393
				if ($idprof != '-') {
2394
					$key = 'idprof'.$i;
2395
2396
					if (($j % $NBCOLS) == 0) {
2397
						print '<tr>';
2398
					}
2399
2400
					$idprof_mandatory = 'SOCIETE_IDPROF'.($i).'_MANDATORY';
2401
					print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', !(empty($conf->global->$idprof_mandatory) || !$object->isACompany())).'</td><td>';
2402
					print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
2403
					print '</td>';
2404
					if (($j % $NBCOLS) == ($NBCOLS - 1)) {
2405
						print '</tr>';
2406
					}
2407
					$j++;
2408
				}
2409
				$i++;
2410
			}
2411
			if ($NBCOLS > 0 && $j % 2 == 1) {
2412
				print '<td colspan="2"></td></tr>';
2413
			}
2414
2415
			// VAT is used
2416
			print '<tr><td>'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).'</td><td colspan="3">';
2417
			print $form->selectyesno('assujtva_value', $object->tva_assuj, 1);
2418
			print '</td></tr>';
2419
2420
			// Local Taxes
2421
			//TODO: Place into a function to control showing by country or study better option
2422
			if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
2423
				print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td>';
2424
				print $form->selectyesno('localtax1assuj_value', $object->localtax1_assuj, 1);
2425
				if (!isOnlyOneLocalTax(1)) {
2426
					print '<span class="cblt1">     '.$langs->transcountry("Type", $mysoc->country_code).': ';
2427
					$formcompany->select_localtax(1, $object->localtax1_value, "lt1");
2428
					print '</span>';
2429
				}
2430
				print '</td>';
2431
				print '</tr><tr>';
2432
				print '<td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td>';
2433
				print $form->selectyesno('localtax2assuj_value', $object->localtax2_assuj, 1);
2434
				if (!isOnlyOneLocalTax(2)) {
2435
					print '<span class="cblt2">     '.$langs->transcountry("Type", $mysoc->country_code).': ';
2436
					$formcompany->select_localtax(2, $object->localtax2_value, "lt2");
2437
					print '</span>';
2438
				}
2439
				print '</td></tr>';
2440
			} elseif ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj != "1") {
2441
				print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td colspan="3">';
2442
				print $form->selectyesno('localtax1assuj_value', $object->localtax1_assuj, 1);
2443
				if (!isOnlyOneLocalTax(1)) {
2444
					print '<span class="cblt1">     '.$langs->transcountry("Type", $mysoc->country_code).': ';
2445
					$formcompany->select_localtax(1, $object->localtax1_value, "lt1");
2446
					print '</span>';
2447
				}
2448
				print '</td></tr>';
2449
			} elseif ($mysoc->localtax2_assuj == "1" && $mysoc->localtax1_assuj != "1") {
2450
				print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td colspan="3">';
2451
				print $form->selectyesno('localtax2assuj_value', $object->localtax2_assuj, 1);
2452
				if (!isOnlyOneLocalTax(2)) {
2453
					print '<span class="cblt2">     '.$langs->transcountry("Type", $mysoc->country_code).': ';
2454
					$formcompany->select_localtax(2, $object->localtax2_value, "lt2");
2455
					print '</span>';
2456
				}
2457
				print '</td></tr>';
2458
			}
2459
2460
			// VAT Code
2461
			print '<tr><td>'.$form->editfieldkey('VATIntra', 'intra_vat', '', $object, 0).'</td>';
2462
			print '<td colspan="3">';
2463
			$s = '<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
2464
2465
			if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object)) {
2466
				$s .= ' &nbsp; ';
2467
2468
				if ($conf->use_javascript_ajax) {
2469
					$widthpopup = 600;
2470
					if (!empty($conf->dol_use_jmobile)) {
2471
						$widthpopup = 350;
2472
					}
2473
					$heightpopup = 400;
2474
					print "\n";
2475
					print '<script type="text/javascript">';
2476
					print "function CheckVAT(a) {\n";
2477
					print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a,'".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
2478
					print "}\n";
2479
					print '</script>';
2480
					print "\n";
2481
					$s .= '<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
2482
					$s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1);
2483
				} else {
2484
					$s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", $object->country_id).'" class="hideonsmartphone" target="_blank" rel="noopener noreferrer">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
2485
				}
2486
			}
2487
			print $s;
2488
			print '</td>';
2489
			print '</tr>';
2490
2491
			// Type - Workforce/Staff
2492
			print '<tr><td>'.$form->editfieldkey('ThirdPartyType', 'typent_id', '', $object, 0).'</td><td class="maxwidthonsmartphone"'.( ($conf->browser->layout == 'phone' || !empty($conf->global->SOCIETE_DISABLE_WORKFORCE)) ? ' colspan="3"' : '').'>';
2493
			print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 1, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);
2494
			if ($user->admin) {
2495
				print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
2496
			}
2497
			if (empty($conf->global->SOCIETE_DISABLE_WORKFORCE)) {
2498
				print '</td>';
2499
				if ($conf->browser->layout == 'phone') {
2500
					print '</tr><tr>';
2501
				}
2502
				print '<td>'.$form->editfieldkey('Workforce', 'effectif_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
2503
				print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id, 0, 0, 0, '', 0, 0, 0, '', '', 1);
2504
				if ($user->admin) {
2505
					print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
2506
				}
2507
			} else {
2508
				print '<input type="hidden" name="effectif_id" id="effectif_id" value="'.$object->effectif_id.'">';
2509
			}
2510
			print '</td></tr>';
2511
2512
			// Juridical type
2513
			print '<tr><td>'.$form->editfieldkey('JuridicalStatus', 'forme_juridique_code', '', $object, 0).'</td><td class="maxwidthonsmartphone" colspan="3">';
2514
			print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code');
2515
			print '</td></tr>';
2516
2517
			// Capital
2518
			print '<tr><td>'.$form->editfieldkey('Capital', 'capital', '', $object, 0).'</td>';
2519
			print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="';
2520
			print $object->capital != '' ? dol_escape_htmltag(price($object->capital)) : '';
2521
			if (isModEnabled("multicurrency")) {
2522
				print '"> <span class="hideonsmartphone">'.$langs->trans("Currency".$object->multicurrency_code).'</span></td></tr>';
2523
			} else {
2524
				print '"> <span class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
2525
			}
2526
2527
			// Default language
2528
			if (getDolGlobalInt('MAIN_MULTILANGS')) {
2529
				print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3">'."\n";
2530
				print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language($object->default_lang, 'default_lang', 0, null, '1', 0, 0, 'maxwidth300 widthcentpercentminusx');
2531
				print '</td>';
2532
				print '</tr>';
2533
			}
2534
2535
			// Incoterms
2536
			if (isModEnabled('incoterm')) {
2537
				print '<tr>';
2538
					print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
2539
				print '<td colspan="3" class="maxwidthonsmartphone">';
2540
				print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
2541
				print '</td></tr>';
2542
			}
2543
2544
			// Categories
2545
			if (isModEnabled('categorie') && !empty($user->rights->categorie->lire)) {
2546
				// Customer
2547
				print '<tr class="visibleifcustomer"><td>'.$form->editfieldkey('CustomersCategoriesShort', 'custcats', '', $object, 0).'</td>';
2548
				print '<td colspan="3">';
2549
				$cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, null, null, null, 1);
2550
				$c = new Categorie($db);
2551
				$cats = $c->containing($object->id, Categorie::TYPE_CUSTOMER);
2552
				$arrayselected = array();
2553
				foreach ($cats as $cat) {
2554
					$arrayselected[] = $cat->id;
2555
				}
2556
				print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('custcats', $cate_arbo, $arrayselected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
2557
				print "</td></tr>";
2558
2559
				// Supplier
2560
				if ((isModEnabled("fournisseur") && !empty($user->rights->fournisseur->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled("supplier_order") && !empty($user->rights->supplier_order->lire)) || (isModEnabled("supplier_invoice") && !empty($user->rights->supplier_invoice->lire))) {
2561
					print '<tr class="visibleifsupplier"><td>'.$form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0).'</td>';
2562
					print '<td colspan="3">';
2563
					$cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, null, null, null, 1);
2564
					$c = new Categorie($db);
2565
					$cats = $c->containing($object->id, Categorie::TYPE_SUPPLIER);
2566
					$arrayselected = array();
2567
					foreach ($cats as $cat) {
2568
						$arrayselected[] = $cat->id;
2569
					}
2570
					print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('suppcats', $cate_arbo, $arrayselected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
2571
					print "</td></tr>";
2572
				}
2573
			}
2574
2575
			// Multicurrency
2576
			if (isModEnabled("multicurrency")) {
2577
				print '<tr>';
2578
				print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
2579
				print '<td colspan="3" class="maxwidthonsmartphone">';
2580
				print img_picto('', 'currency', 'class="pictofixedwidth"');
2581
				print $form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code') : ($object->multicurrency_code ? $object->multicurrency_code : $conf->currency)), 'multicurrency_code', 1, '', false, 'maxwidth150 widthcentpercentminusx');
2582
				print '</td></tr>';
2583
			}
2584
2585
			// Other attributes
2586
			$parameters = array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
2587
			include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
2588
2589
			// Parent company
2590
			if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY)) {
2591
				print '<tr>';
2592
				print '<td>'.$langs->trans('ParentCompany').'</td>';
2593
				print '<td colspan="3" class="maxwidthonsmartphone">';
2594
				print img_picto('', 'company', 'class="pictofixedwidth"');
2595
				print $form->select_company(GETPOST('parent_company_id') ? GETPOST('parent_company_id') : $object->parent, 'parent_company_id', '', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300 maxwidth500 widthcentpercentminusxx');
2596
				print '</td></tr>';
2597
			}
2598
2599
			// Webservices url/key
2600
			if (!empty($conf->syncsupplierwebservices->enabled)) {
2601
				print '<tr><td>'.$form->editfieldkey('WebServiceURL', 'webservices_url', '', $object, 0).'</td>';
2602
				print '<td><input type="text" name="webservices_url" id="webservices_url" size="32" value="'.$object->webservices_url.'"></td>';
2603
				print '<td>'.$form->editfieldkey('WebServiceKey', 'webservices_key', '', $object, 0).'</td>';
2604
				print '<td><input type="text" name="webservices_key" id="webservices_key" size="32" value="'.$object->webservices_key.'"></td></tr>';
2605
			}
2606
2607
			// Logo
2608
			print '<tr class="hideonsmartphone">';
2609
			print '<td>'.$form->editfieldkey('Logo', 'photoinput', '', $object, 0).'</td>';
2610
			print '<td colspan="3">';
2611
			if ($object->logo) {
2612
				print $form->showphoto('societe', $object);
2613
			}
2614
			$caneditfield = 1;
2615
			if ($caneditfield) {
2616
				if ($object->logo) {
2617
					print "<br>\n";
2618
				}
2619
				print '<table class="nobordernopadding">';
2620
				if ($object->logo) {
2621
					print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
2622
				}
2623
				//print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
2624
				print '<tr><td>';
2625
				$maxfilesizearray = getMaxFileSizeArray();
2626
				$maxmin = $maxfilesizearray['maxmin'];
2627
				if ($maxmin > 0) {
2628
					print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">';	// MAX_FILE_SIZE must precede the field type=file
2629
				}
2630
				print '<input type="file" class="flat" name="photo" id="photoinput">';
2631
				print '</td></tr>';
2632
				print '</table>';
2633
			}
2634
			print '</td>';
2635
			print '</tr>';
2636
2637
			// Assign sale representative
2638
			print '<tr>';
2639
			print '<td>'.$form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0).'</td>';
2640
			print '<td colspan="3" class="maxwidthonsmartphone">';
2641
			$userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, 'AND u.statut = 1', 0, '', '', 0, 1);
2642
			$arrayselected = GETPOST('commercial', 'array');
2643
			if (empty($arrayselected)) {
2644
				$arrayselected = $object->getSalesRepresentatives($user, 1);
2645
			}
2646
			print img_picto('', 'user', 'class="pictofixedwidth"').$form->multiselectarray('commercial', $userlist, $arrayselected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0, '', '', '', 1);
2647
			print '</td></tr>';
2648
2649
			print '</table>';
2650
2651
			if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
2652
				print '<br>';
2653
				print '<table class="border centpercent">';
2654
2655
				if (isModEnabled('accounting')) {
2656
					// Accountancy_code_sell
2657
					print '<tr><td class="titlefield">'.$langs->trans("ProductAccountancySellCode").'</td>';
2658
					print '<td>';
2659
					print $formaccounting->select_account($object->accountancy_code_sell, 'accountancy_code_sell', 1, '', 1, 1);
2660
					print '</td></tr>';
2661
2662
					// Accountancy_code_buy
2663
					print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
2664
					print '<td>';
2665
					print $formaccounting->select_account($object->accountancy_code_buy, 'accountancy_code_buy', 1, '', 1, 1);
2666
					print '</td></tr>';
2667
				} else { // For external software
2668
					// Accountancy_code_sell
2669
					print '<tr><td class="titlefield">'.$langs->trans("ProductAccountancySellCode").'</td>';
2670
					print '<td><input name="accountancy_code_sell" class="maxwidth200" value="'.$object->accountancy_code_sell.'">';
2671
					print '</td></tr>';
2672
2673
					// Accountancy_code_buy
2674
					print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
2675
					print '<td><input name="accountancy_code_buy" class="maxwidth200" value="'.$object->accountancy_code_buy.'">';
2676
					print '</td></tr>';
2677
				}
2678
				print '</table>';
2679
			}
2680
2681
			print '</div>';
2682
2683
			print dol_get_fiche_end();
2684
2685
			print $form->buttonsSaveCancel();
2686
2687
			print '</form>';
2688
		}
2689
	} else {
2690
		/*
2691
		 * View
2692
		 */
2693
2694
		if (!empty($object->id)) {
2695
			$res = $object->fetch_optionals();
2696
		}
2697
		//if ($res < 0) { dol_print_error($db); exit; }
2698
2699
2700
		$head = societe_prepare_head($object);
2701
2702
		print dol_get_fiche_head($head, 'card', $langs->trans("ThirdParty"), -1, 'company');
2703
2704
		$formconfirm = '';
2705
2706
		// Confirm delete third party
2707
		if ($action == 'delete' || ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))) {
2708
			$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("DeleteACompany"), $langs->trans("ConfirmDeleteCompany"), "confirm_delete", '', 0, "action-delete");
2709
		}
2710
2711
		if ($action == 'merge') {
2712
			$formquestion = array(
2713
				array(
2714
					'name' => 'soc_origin',
2715
					'label' => $langs->trans('MergeOriginThirdparty'),
2716
					'type' => 'other',
2717
					'value' => $form->select_company('', 'soc_origin', '', 'SelectThirdParty', 0, 0, array(), 0, 'minwidth200', '', '', 1, null, false, array($object->id))
2718
				)
2719
			);
2720
2721
			$formconfirm .= $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("MergeThirdparties"), $langs->trans("ConfirmMergeThirdparties"), "confirm_merge", $formquestion, 'no', 1, 250);
2722
		}
2723
2724
		// Call Hook formConfirm
2725
		$parameters = array('formConfirm' => $formconfirm);
2726
		$reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2727
		if (empty($reshook)) {
2728
			$formconfirm .= $hookmanager->resPrint;
2729
		} elseif ($reshook > 0) {
2730
			$formconfirm = $hookmanager->resPrint;
2731
		}
2732
2733
		// Print form confirm
2734
		print $formconfirm;
2735
2736
		dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
2737
2738
		$linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
2739
2740
		dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
2741
2742
2743
		print '<div class="fichecenter">';
2744
		print '<div class="fichehalfleft">';
2745
2746
		print '<div class="underbanner clearboth"></div>';
2747
		print '<table class="border tableforfield centpercent">';
2748
2749
		// Type Prospect/Customer/Supplier
2750
		print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
2751
		print $object->getTypeUrl(1);
2752
		print '</td></tr>';
2753
2754
		// Prefix
2755
		if (!empty($conf->global->SOCIETE_USEPREFIX)) {  // Old not used prefix field
2756
			print '<tr><td>'.$langs->trans('Prefix').'</td><td>'.dol_escape_htmltag($object->prefix_comm).'</td>';
2757
			print '</tr>';
2758
		}
2759
2760
		// Customer code
2761
		if ($object->client) {
2762
			print '<tr><td>';
2763
			print $langs->trans('CustomerCode');
2764
			print '</td>';
2765
			print '<td>';
2766
			print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_client));
2767
			$tmpcheck = $object->check_codeclient();
2768
			if ($tmpcheck != 0 && $tmpcheck != -5) {
2769
				print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
2770
			}
2771
			print '</td>';
2772
			print '</tr>';
2773
		}
2774
2775
		// Supplier code
2776
		if (((isModEnabled("fournisseur") && !empty($user->rights->fournisseur->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled("supplier_order") && !empty($user->rights->supplier_order->lire)) || (isModEnabled("supplier_invoice") && !empty($user->rights->supplier_invoice->lire))) && $object->fournisseur) {
2777
			print '<tr><td>';
2778
			print $langs->trans('SupplierCode').'</td><td>';
2779
			print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_fournisseur));
2780
			$tmpcheck = $object->check_codefournisseur();
2781
			if ($tmpcheck != 0 && $tmpcheck != -5) {
2782
				print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
2783
			}
2784
			print '</td>';
2785
			print '</tr>';
2786
		}
2787
2788
		// Barcode
2789
		if (isModEnabled('barcode')) {
2790
			print '<tr><td>';
2791
			print $langs->trans('Gencod').'</td><td>'.showValueWithClipboardCPButton(dol_escape_htmltag($object->barcode));
2792
			print '</td>';
2793
			print '</tr>';
2794
		}
2795
2796
		// Prof ids
2797
		$i = 1; $j = 0;
2798
		while ($i <= 6) {
2799
			$idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
2800
			if ($idprof != '-') {
2801
				//if (($j % 2) == 0) print '<tr>';
2802
				print '<tr>';
2803
				print '<td>'.$idprof.'</td><td>';
2804
				$key = 'idprof'.$i;
2805
				print dol_print_profids($object->$key, 'ProfId'.$i, $object->country_code, 1);
2806
				if ($object->$key) {
2807
					if ($object->id_prof_check($i, $object) > 0) {
2808
						if (!empty($object->id_prof_url($i, $object))) {
2809
							print ' &nbsp; '.$object->id_prof_url($i, $object);
2810
						}
2811
					} else {
2812
						print ' <span class="error">('.$langs->trans("ErrorWrongValue").')</span>';
2813
					}
2814
				}
2815
				print '</td>';
2816
				//if (($j % 2) == 1) print '</tr>';
2817
				print '</tr>';
2818
				$j++;
2819
			}
2820
			$i++;
2821
		}
2822
		//if ($j % 2 == 1)  print '<td colspan="2"></td></tr>';
2823
2824
2825
		// This fields are used to know VAT to include in an invoice when the thirdparty is making a sale, so when it is a supplier.
2826
		// We don't need them into customer profile.
2827
		// Except for spain and localtax where localtax depends on buyer and not seller
2828
2829
		if ($object->fournisseur) {
2830
			// VAT is used
2831
			print '<tr><td>';
2832
			print $form->textwithpicto($langs->trans('VATIsUsed'), $langs->trans('VATIsUsedWhenSelling'));
2833
			print '</td><td>';
2834
			print yn($object->tva_assuj);
2835
			print '</td>';
2836
			print '</tr>';
2837
		}
2838
2839
		// Local Taxes
2840
		if ($object->fournisseur || $mysoc->country_code == 'ES') {
2841
			if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
2842
				print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
2843
				print yn($object->localtax1_assuj);
2844
				print '</td></tr><tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
2845
				print yn($object->localtax2_assuj);
2846
				print '</td></tr>';
2847
2848
				if ($object->localtax1_assuj == "1" && (!isOnlyOneLocalTax(1))) {
2849
					print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2850
					print '<input type="hidden" name="action" value="set_localtax1">';
2851
					print '<input type="hidden" name="token" value="'.newToken().'">';
2852
					print '<tr><td>'.$langs->transcountry("Localtax1", $mysoc->country_code).' <a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editRE&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</td>';
2853
					if ($action == 'editRE') {
2854
						print '<td class="left">';
2855
						$formcompany->select_localtax(1, $object->localtax1_value, "lt1");
2856
						print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
2857
					} else {
2858
						print '<td>'.$object->localtax1_value.'</td>';
2859
					}
2860
					print '</tr></form>';
2861
				}
2862
				if ($object->localtax2_assuj == "1" && (!isOnlyOneLocalTax(2))) {
2863
					print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2864
					print '<input type="hidden" name="action" value="set_localtax2">';
2865
					print '<input type="hidden" name="token" value="'.newToken().'">';
2866
					print '<tr><td>'.$langs->transcountry("Localtax2", $mysoc->country_code).'<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</td>';
2867
					if ($action == 'editIRPF') {
2868
						print '<td class="left">';
2869
						$formcompany->select_localtax(2, $object->localtax2_value, "lt2");
2870
						print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
2871
					} else {
2872
						print '<td>'.$object->localtax2_value.'</td>';
2873
					}
2874
					print '</tr></form>';
2875
				}
2876
			} elseif ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj != "1") {
2877
				print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
2878
				print yn($object->localtax1_assuj);
2879
				print '</td></tr>';
2880
				if ($object->localtax1_assuj == "1" && (!isOnlyOneLocalTax(1))) {
2881
					print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2882
					print '<input type="hidden" name="action" value="set_localtax1">';
2883
					print '<input type="hidden" name="token" value="'.newToken().'">';
2884
					print '<tr><td> '.$langs->transcountry("Localtax1", $mysoc->country_code).'<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editRE&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</td>';
2885
					if ($action == 'editRE') {
2886
						print '<td class="left">';
2887
						$formcompany->select_localtax(1, $object->localtax1_value, "lt1");
2888
						print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
2889
					} else {
2890
						print '<td>'.$object->localtax1_value.'</td>';
2891
					}
2892
					print '</tr></form>';
2893
				}
2894
			} elseif ($mysoc->localtax2_assuj == "1" && $mysoc->localtax1_assuj != "1") {
2895
				print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
2896
				print yn($object->localtax2_assuj);
2897
				print '</td></tr>';
2898
				if ($object->localtax2_assuj == "1" && (!isOnlyOneLocalTax(2))) {
2899
					print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2900
					print '<input type="hidden" name="action" value="set_localtax2">';
2901
					print '<input type="hidden" name="token" value="'.newToken().'">';
2902
					print '<tr><td> '.$langs->transcountry("Localtax2", $mysoc->country_code).' <a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</td>';
2903
					if ($action == 'editIRPF') {
2904
						print '<td class="left">';
2905
						$formcompany->select_localtax(2, $object->localtax2_value, "lt2");
2906
						print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
2907
					} else {
2908
						print '<td>'.$object->localtax2_value.'</td>';
2909
					}
2910
					print '</tr></form>';
2911
				}
2912
			}
2913
		}
2914
2915
		// Sale tax code (VAT code)
2916
		print '<tr>';
2917
		print '<td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
2918
		if ($object->tva_intra) {
2919
			$s = '';
2920
			$s .= dol_print_profids($object->tva_intra, 'VAT', $object->country_code, 1);
2921
			$s .= '<input type="hidden" id="tva_intra" name="tva_intra" maxlength="20" value="'.$object->tva_intra.'">';
2922
2923
			if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object)) {
2924
				$s .= ' &nbsp; ';
2925
2926
				if ($conf->use_javascript_ajax) {
2927
					$widthpopup = 600;
2928
					if (!empty($conf->dol_use_jmobile)) {
2929
						$widthpopup = 350;
2930
					}
2931
					$heightpopup = 400;
2932
					print "\n";
2933
					print '<script type="text/javascript">';
2934
					print "function CheckVAT(a) {\n";
2935
					print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a, '".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
2936
					print "}\n";
2937
					print '</script>';
2938
					print "\n";
2939
					$s .= '<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT( $(\'#tva_intra\').val() );">'.$langs->trans("VATIntraCheck").'</a>';
2940
					$s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1);
2941
				} else {
2942
					$s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", $object->country_id).'" class="hideonsmartphone" target="_blank" rel="noopener noreferrer">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
2943
				}
2944
			}
2945
			print $s;
2946
		} else {
2947
			print '&nbsp;';
2948
		}
2949
		print '</td></tr>';
2950
2951
		// Warehouse
2952
		if (isModEnabled('stock') && !empty($conf->global->SOCIETE_ASK_FOR_WAREHOUSE)) {
2953
			$langs->load('stocks');
2954
			require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
2955
			$formproduct = new FormProduct($db);
2956
			print '<tr class="nowrap">';
2957
			print '<td>';
2958
			print $form->editfieldkey("Warehouse", 'warehouse', '', $object, $user->rights->societe->creer);
2959
			print '</td><td>';
2960
			if ($action == 'editwarehouse') {
2961
				$formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_warehouse, 'fk_warehouse', 1);
2962
			} else {
2963
				if ($object->fk_warehouse > 0) {
2964
					print img_picto('', 'stock', 'class="paddingrightonly"');
2965
				}
2966
				$formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_warehouse, 'none');
2967
			}
2968
			print '</td>';
2969
			print '</tr>';
2970
		}
2971
2972
		print '</table>';
2973
		print '</div>';
2974
2975
		print '<div class="fichehalfright">';
2976
2977
		print '<div class="underbanner clearboth"></div>';
2978
		print '<table class="border tableforfield centpercent">';
2979
2980
		// Tags / categories
2981
		if (isModEnabled('categorie') && !empty($user->rights->categorie->lire)) {
2982
			// Customer
2983
			if ($object->prospect || $object->client || !empty($conf->global->THIRDPARTY_CAN_HAVE_CUSTOMER_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT)) {
2984
				print '<tr><td>'.$langs->trans("CustomersCategoriesShort").'</td>';
2985
				print '<td>';
2986
				print $form->showCategories($object->id, Categorie::TYPE_CUSTOMER, 1);
2987
				print "</td></tr>";
2988
			}
2989
2990
			// Supplier
2991
			if (((isModEnabled("fournisseur") && !empty($user->rights->fournisseur->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled("supplier_order") && !empty($user->rights->supplier_order->lire)) || (isModEnabled("supplier_invoice") && !empty($user->rights->supplier_invoice->lire))) && $object->fournisseur) {
2992
				print '<tr><td>'.$langs->trans("SuppliersCategoriesShort").'</td>';
2993
				print '<td>';
2994
				print $form->showCategories($object->id, Categorie::TYPE_SUPPLIER, 1);
2995
				print "</td></tr>";
2996
			}
2997
		}
2998
2999
3000
		// Third-Party Type
3001
		print '<tr><td>';
3002
		print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans('ThirdPartyType').'</td>';
3003
		if ($action != 'editthirdpartytype' && $user->hasRight('societe', 'creer')) {
3004
			print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editthirdpartytype&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a></td>';
3005
		}
3006
		print '</tr></table>';
3007
		print '</td><td>';
3008
		$html_name = ($action == 'editthirdpartytype') ? 'typent_id' : 'none';
3009
		$formcompany->formThirdpartyType($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->typent_id, $html_name, '');
3010
		print '</td></tr>';
3011
3012
		// Workforce/Staff
3013
		if (empty($conf->global->SOCIETE_DISABLE_WORKFORCE)) {
3014
			print '<tr><td>'.$langs->trans("Workforce").'</td><td>'.$object->effectif.'</td></tr>';
3015
		}
3016
3017
		// Legal
3018
		print '<tr><td class="titlefield">'.$langs->trans('JuridicalStatus').'</td><td>'.$object->forme_juridique.'</td></tr>';
3019
3020
		// Capital
3021
		print '<tr><td>'.$langs->trans('Capital').'</td><td>';
3022
		if ($object->capital) {
3023
			if (isModEnabled("multicurrency") && !empty($object->multicurrency_code)) {
3024
				print price($object->capital, '', $langs, 0, -1, -1, $object->multicurrency_code);
3025
			} else {
3026
				print price($object->capital, '', $langs, 0, -1, -1, $conf->currency);
3027
			}
3028
		} else {
3029
			print '&nbsp;';
3030
		}
3031
		print '</td></tr>';
3032
3033
		// Unsubscribe opt-out
3034
		if (!empty($conf->mailing->enabled)) {
3035
			$result = $object->getNoEmail();
3036
			if ($result < 0) {
3037
				setEventMessages($object->error, $object->errors, 'errors');
3038
			}
3039
			print '<tr><td>'.$langs->trans("No_Email").'</td><td>';
3040
			if ($object->email) {
3041
				print yn($object->no_email);
3042
			} else {
3043
				print '<span class="opacitymedium">'.$langs->trans("EMailNotDefined").'</span>';
3044
			}
3045
3046
			$langs->load("mails");
3047
			print ' &nbsp; <span class="badge badge-secondary" title="'.dol_escape_htmltag($langs->trans("NbOfEMailingsSend")).'">'.$object->getNbOfEMailings().'</span>';
3048
3049
			print '</td></tr>';
3050
		}
3051
3052
		// Default language
3053
		if (getDolGlobalInt('MAIN_MULTILANGS')) {
3054
			require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
3055
			print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
3056
			//$s=picto_from_langcode($object->default_lang);
3057
			//print ($s?$s.' ':'');
3058
			$langs->load("languages");
3059
			$labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
3060
			print picto_from_langcode($object->default_lang, 'class="paddingrightonly saturatemedium opacitylow"');
3061
			print $labellang;
3062
			print '</td></tr>';
3063
		}
3064
3065
		// Incoterms
3066
		if (isModEnabled('incoterm')) {
3067
			print '<tr><td>';
3068
			print '<table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans('IncotermLabel').'</td>';
3069
			if ($action != 'editincoterm' && $user->hasRight('societe', 'creer')) {
3070
				print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=editincoterm&token='.newToken().'">'.img_edit('', 1).'</a></td>';
3071
			}
3072
			print '</tr></table>';
3073
			print '</td><td colspan="3">';
3074
			if ($action != 'editincoterm') {
3075
				print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
3076
			} else {
3077
				print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?socid='.$object->id);
3078
			}
3079
			print '</td></tr>';
3080
		}
3081
3082
		// Multicurrency
3083
		if (isModEnabled("multicurrency")) {
3084
			print '<tr>';
3085
			print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
3086
			print '<td>';
3087
			print !empty($object->multicurrency_code) ? currency_name($object->multicurrency_code, 1) : '';
3088
			print '</td></tr>';
3089
		}
3090
3091
		if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
3092
			// Accountancy sell code
3093
			print '<tr><td class="nowrap">';
3094
			print $langs->trans("ProductAccountancySellCode");
3095
			print '</td><td colspan="2">';
3096
			if (isModEnabled('accounting')) {
3097
				if (!empty($object->accountancy_code_sell)) {
3098
					$accountingaccount = new AccountingAccount($db);
3099
					$accountingaccount->fetch('', $object->accountancy_code_sell, 1);
3100
3101
					print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
3102
				}
3103
			} else {
3104
				print $object->accountancy_code_sell;
3105
			}
3106
			print '</td></tr>';
3107
3108
			// Accountancy buy code
3109
			print '<tr><td class="nowrap">';
3110
			print $langs->trans("ProductAccountancyBuyCode");
3111
			print '</td><td colspan="2">';
3112
			if (isModEnabled('accounting')) {
3113
				if (!empty($object->accountancy_code_buy)) {
3114
					$accountingaccount2 = new AccountingAccount($db);
3115
					$accountingaccount2->fetch('', $object->accountancy_code_buy, 1);
3116
3117
					print $accountingaccount2->getNomUrl(0, 1, 1, '', 1);
3118
				}
3119
			} else {
3120
				print $object->accountancy_code_buy;
3121
			}
3122
			print '</td></tr>';
3123
		}
3124
3125
		// Other attributes
3126
		$parameters = array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
3127
		include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
3128
3129
		// Parent company
3130
		if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY)) {
3131
			print '<tr><td>';
3132
			print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans('ParentCompany').'</td>';
3133
			if ($action != 'editparentcompany' && $user->hasRight('societe', 'creer')) {
3134
				print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a></td>';
3135
			}
3136
			print '</tr></table>';
3137
			print '</td><td>';
3138
			$html_name = ($action == 'editparentcompany') ? 'parent_id' : 'none';
3139
			$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->parent, $html_name, '', 1, 0, 0, null, 0, array($object->id));
3140
			print '</td></tr>';
3141
		}
3142
3143
		// Sales representative
3144
		include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php';
3145
3146
		// Module Adherent
3147
		if (isModEnabled('adherent')) {
3148
			$langs->load("members");
3149
			print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
3150
			print '<td>';
3151
			$adh = new Adherent($db);
3152
			$result = $adh->fetch('', '', $object->id);
3153
			if ($result > 0) {
3154
				$adh->ref = $adh->getFullName($langs);
3155
				print $adh->getNomUrl(-1);
3156
			} else {
3157
				print '<span class="opacitymedium">'.$langs->trans("ThirdpartyNotLinkedToMember").'</span>';
3158
			}
3159
			print "</td></tr>\n";
3160
		}
3161
3162
		// Link user (you must create a contact to get a user)
3163
		/*
3164
		print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td colspan="3">';
3165
		if ($object->user_id) {
3166
			$dolibarr_user = new User($db);
3167
			$result = $dolibarr_user->fetch($object->user_id);
3168
			print $dolibarr_user->getLoginUrl(-1);
3169
		} else {
3170
			//print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
3171
			if (!$object->user_id && $user->rights->user->user->creer) {
3172
				print '<a class="aaa" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=create_user&token='.newToken().'">'.img_picto($langs->trans("CreateDolibarrLogin"), 'add').' '.$langs->trans("CreateDolibarrLogin").'</a>';
3173
			}
3174
		}
3175
		print '</td></tr>';
3176
		*/
3177
3178
		// Webservices url/key
3179
		if (!empty($conf->syncsupplierwebservices->enabled)) {
3180
			print '<tr><td>'.$langs->trans("WebServiceURL").'</td><td>'.dol_print_url($object->webservices_url).'</td>';
3181
			print '<td class="nowrap">'.$langs->trans('WebServiceKey').'</td><td>'.$object->webservices_key.'</td></tr>';
3182
		}
3183
3184
		print '</table>';
3185
		print '</div>';
3186
3187
		print '</div>';
3188
		print '<div style="clear:both"></div>';
3189
3190
		print dol_get_fiche_end();
3191
3192
3193
		/*
3194
		 *  Actions
3195
		 */
3196
		if ($action != 'presend') {
3197
			print '<div class="tabsAction">'."\n";
3198
3199
			$parameters = array();
3200
			$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3201
			if (empty($reshook)) {
3202
				$at_least_one_email_contact = false;
3203
				$TContact = $object->contact_array_objects();
3204
				foreach ($TContact as &$contact) {
3205
					if (!empty($contact->email)) {
3206
						$at_least_one_email_contact = true;
3207
						break;
3208
					}
3209
				}
3210
3211
				if (empty($user->socid)) {
3212
					$langs->load("mails");
3213
					$title = '';
3214
					if (empty($object->email) && !$at_least_one_email_contact) { $title = $langs->trans('NoEMail'); }
3215
					print dolGetButtonAction($title, $langs->trans('SendMail'), 'default', $_SERVER['PHP_SELF'].'?socid='.$object->id.'&action=presend&mode=init#formmailbeforetitle', 'btn-send-mail', !empty($object->email) || $at_least_one_email_contact);
3216
				}
3217
3218
				print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=edit&token='.newToken(), '', $permissiontoadd);
3219
3220
				if (isModEnabled('adherent')) {
3221
					$adh = new Adherent($db);
3222
					$result = $adh->fetch('', '', $object->id);
3223
					if ($result == 0 && ($object->client == 1 || $object->client == 3) && !empty($conf->global->MEMBER_CAN_CONVERT_CUSTOMERS_TO_MEMBERS)) {
3224
						print '<a class="butAction" href="'.DOL_URL_ROOT.'/adherents/card.php?&action=create&socid='.$object->id.'" title="'.dol_escape_htmltag($langs->trans("NewMember")).'">'.$langs->trans("NewMember").'</a>'."\n";
3225
					}
3226
				}
3227
3228
				print dolGetButtonAction($langs->trans('MergeThirdparties'), $langs->trans('Merge'), 'danger', $_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=merge&token='.newToken(), '', $permissiontodelete);
3229
3230
				if ($user->hasRight('societe', 'supprimer')) {
3231
					$deleteUrl = $_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=delete&token='.newToken();
3232
					$buttonId = 'action-delete-no-ajax';
3233
					if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)) {	// We can't use preloaded confirm form with jmobile
3234
						$deleteUrl = '';
3235
						$buttonId = 'action-delete';
3236
					}
3237
					print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $deleteUrl, $buttonId, $permissiontodelete);
3238
				}
3239
			}
3240
3241
			print '</div>'."\n";
3242
		}
3243
3244
		//Select mail models is same action as presend
3245
		if (GETPOST('modelselected')) {
3246
			$action = 'presend';
3247
		}
3248
3249
		if ($action != 'presend') {
3250
			print '<div class="fichecenter"><div class="fichehalfleft">';
3251
3252
			if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC)) {
3253
				print '<a name="builddoc"></a>'; // ancre
3254
3255
				/*
3256
				 * Generated documents
3257
				 */
3258
				$filedir = $conf->societe->multidir_output[$object->entity].'/'.$object->id;
3259
				$urlsource = $_SERVER["PHP_SELF"]."?socid=".$object->id;
3260
				$genallowed = $user->hasRight('societe', 'lire');
3261
				$delallowed = $user->hasRight('societe', 'creer');
3262
3263
				print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang);
3264
			}
3265
3266
			// Subsidiaries list
3267
			if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY) && empty($conf->global->SOCIETE_DISABLE_SHOW_SUBSIDIARIES)) {
3268
				$result = show_subsidiaries($conf, $langs, $db, $object);
3269
			}
3270
3271
			print '</div><div class="fichehalfright">';
3272
3273
			$MAXEVENT = 10;
3274
3275
			$morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id);
3276
3277
			// List of actions on element
3278
			include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
3279
			$formactions = new FormActions($db);
3280
			$somethingshown = $formactions->showactions($object, '', $socid, 1, '', $MAXEVENT, '', $morehtmlcenter); // Show all action for thirdparty
3281
3282
			print '</div></div>';
3283
3284
			if (!empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD)) {
3285
				// Contacts list
3286
				if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
3287
					$result = show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
3288
				}
3289
			}
3290
		}
3291
3292
		// Presend form
3293
		$modelmail = 'thirdparty';
3294
		$defaulttopic = 'Information';
3295
		$diroutput = $conf->societe->multidir_output[$object->entity];
3296
		$trackid = 'thi'.$object->id;
3297
3298
		include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
3299
	}
3300
}
3301
3302
3303
// End of page
3304
llxFooter();
3305
$db->close();
3306