dolibarr 24.0.0-beta
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2003 Brian Fraval <brian@fraval.org>
4 * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
6 * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
7 * Copyright (C) 2008 Patrick Raguin <patrick.raguin@auguria.net>
8 * Copyright (C) 2010-2020 Juanjo Menent <jmenent@2byte.es>
9 * Copyright (C) 2011-2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
10 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
11 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
12 * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
13 * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
14 * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es.com>
15 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
16 * Copyright (C) 2022-2023 George Gkantinas <info@geowv.eu>
17 * Copyright (C) 2023 Nick Fragoulis
18 * Copyright (C) 2023 Alexandre Janniaux <alexandre.janniaux@gmail.com>
19 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
20 * Copyright (C) 2024 Charlene Benke <charlene@patas-monkey.com>
21 *
22 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation; either version 3 of the License, or
25 * (at your option) any later version.
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program. If not, see <https://www.gnu.org/licenses/>.
34 */
35
43// Load Dolibarr environment
44require '../main.inc.php';
53require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
54require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
55require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
56require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
57require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
58require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
59require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
60require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
61require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
62require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
63if (isModEnabled('member')) {
64 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
65}
66if (isModEnabled('accounting')) {
67 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
68}
69if (isModEnabled('accounting')) {
70 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
71}
72if (isModEnabled('accounting')) {
73 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
74}
75if (isModEnabled('eventorganization')) {
76 require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorboothattendee.class.php';
77}
78
79$u = '';
80$p = '';
81$myafm = '';
82
83if ($mysoc->country_code == 'GR') {
84 $u = getDolGlobalString('AADE_WEBSERVICE_USER');
85 $p = getDolGlobalString('AADE_WEBSERVICE_KEY');
86 $myafm = preg_replace('/\D/', '', getDolGlobalString('MAIN_INFO_TVAINTRA'));
87}
88
89
90// Load translation files required by the page
91
92$langs->loadLangs(array("companies", "commercial", "bills", "banks", "users"));
93
94if (isModEnabled('member')) {
95 $langs->load("members");
96}
97if (isModEnabled('category')) {
98 $langs->load("categories");
99}
100if (isModEnabled('incoterm')) {
101 $langs->load("incoterm");
102}
103if (isModEnabled('notification')) {
104 $langs->load("mails");
105}
106if (isModEnabled('accounting')) {
107 $langs->load("products");
108}
109
110$error = 0;
111$errors = array();
112
113$refalreadyexists = 0;
114
115// Get parameters
116$action = (GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view');
117$cancel = GETPOST('cancel', 'alpha');
118$backtopage = GETPOST('backtopage', 'alpha');
119$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
120$confirm = GETPOST('confirm', 'alpha');
121$canvas = GETPOST('canvas', 'alpha');
122
123$dol_openinpopup = '';
124
125$socid = GETPOSTINT('socid') ? GETPOSTINT('socid') : GETPOSTINT('id');
126if ($user->socid) {
127 if (in_array($action, ['add', 'create', 'merge', 'confirm_merge', 'delete', 'confirm_delete'])) {
129 }
130
131 $socid = $user->socid;
132}
133if (empty($socid) && $action == 'view') {
134 $action = 'create';
135}
136
137$id = $socid;
138
139$object = new Societe($db);
140$extrafields = new ExtraFields($db);
141
142// fetch optionals attributes and labels
143$extrafields->fetch_name_optionals_label($object->table_element);
144
145$socialnetworks = getArrayOfSocialNetworks();
146
147// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
148$hookmanager->initHooks(array('thirdpartycard', 'globalcard'));
149
150if ($socid > 0) {
151 $object->fetch($socid);
152}
153
154// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
155$canvas = $object->canvas ? $object->canvas : GETPOST("canvas");
156$objcanvas = null;
157if (!empty($canvas)) {
158 require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
159 $objcanvas = new Canvas($db, $action);
160 $objcanvas->getCanvas('thirdparty', 'card', $canvas);
161}
162
163// Permissions
164$permissiontoread = $user->hasRight('societe', 'lire');
165$permissiontoadd = $user->hasRight('societe', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
166$permissiontodelete = $user->hasRight('societe', 'supprimer') || ($permissiontoadd && isset($object->status) && $object->status == 0);
167$permissionnote = $user->hasRight('societe', 'creer'); // Used by the include of actions_setnotes.inc.php
168$permissiondellink = $user->hasRight('societe', 'creer'); // Used by the include of actions_dellink.inc.php
169$permissiontoeditextra = $permissiontoadd;
170if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
171 // For action 'update_extras', is there a specific permission set for the attribute to update
172 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
173}
174
175$upload_dir = $conf->societe->multidir_output[isset($object->entity) ? $object->entity : 1];
176
177// Security check
178$result = restrictedArea($user, 'societe', $object->id, '&societe', '', 'fk_soc', 'rowid', 0);
179
180if (!($object->id > 0) && $action == 'view') {
181 recordNotFound();
182}
183
184
185/*
186 * Actions
187 */
188
189$parameters = array('id' => $socid, 'objcanvas' => $objcanvas);
190$current_logo = '';
191$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
192if ($reshook < 0) {
193 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
194}
195
196if (empty($reshook)) {
197 $backurlforlist = DOL_URL_ROOT.'/societe/list.php';
198
199 if (empty($backtopage) || ($cancel && empty($id))) {
200 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
201 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
202 $backtopage = $backurlforlist;
203 } else {
204 $backtopage = DOL_URL_ROOT.'/societe/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__') . (!empty($canvas) ? "&canvas=" . $canvas : "");
205 }
206 }
207 }
208
209 if ($cancel) {
210 if (!empty($backtopageforcancel)) {
211 header("Location: ".$backtopageforcancel);
212 exit;
213 } elseif (!empty($backtopage)) {
214 header("Location: ".$backtopage);
215 exit;
216 }
217 $action = '';
218 }
219
220 if ($action == 'confirm_merge' && $confirm == 'yes' && $permissiontoadd) {
221 $soc_origin_id = GETPOSTINT('soc_origin');
222 $soc_origin = new Societe($db); // The thirdparty that we will delete
223
224 if ($soc_origin_id <= 0) {
225 $langs->load('errors');
226 setEventMessages($langs->trans('ErrorThirdPartyIdIsMandatory', $langs->transnoentitiesnoconv('MergeOriginThirdparty')), null, 'errors');
227 } else {
228 if (!$error && $soc_origin->fetch($soc_origin_id) < 1) {
229 setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
230 $error++;
231 }
232 if (!$error) {
233 $result = $object->mergeCompany($soc_origin_id);
234 if ($result < 0) {
235 $error++;
236 setEventMessages($object->error, $object->errors, 'errors');
237 } else {
238 setEventMessages($langs->trans('ThirdpartiesMergeSuccess'), null, 'mesgs');
239 }
240 }
241 }
242 }
243
244 if (GETPOST('getcustomercode')) {
245 // We defined value code_client
246 $_POST["customer_code"] = "Acompleter";
247 }
248
249 if (GETPOST('getsuppliercode')) {
250 // We defined value code_fournisseur
251 $_POST["supplier_code"] = "Acompleter";
252 }
253
254 if ($action == 'set_localtax1' && $permissiontoadd) {
255 //get selected from combobox
256 $value = GETPOST('lt1');
257 $object->fetch($socid);
258 $res = $object->setValueFrom('localtax1_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
259 }
260 if ($action == 'set_localtax2' && $permissiontoadd) {
261 //get selected from combobox
262 $value = GETPOST('lt2');
263 $object->fetch($socid);
264 $res = $object->setValueFrom('localtax2_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
265 }
266
267 if ($action == 'update_extras' && $permissiontoeditextra) {
268 $object->fetch($socid);
269
270 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
271
272 $attribute_name = GETPOST('attribute', 'aZ09');
273
274 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
275 if ($ret < 0) {
276 $error++;
277 }
278
279 if (!$error) {
280 $result = $object->updateExtraField($attribute_name, 'COMPANY_MODIFY');
281 if ($result < 0) {
282 setEventMessages($object->error, $object->errors, 'errors');
283 $error++;
284 }
285 }
286
287 if ($error) {
288 $action = 'edit_extras';
289 }
290 }
291
292 // Add new or update third party
293 if ((!GETPOST('getcustomercode') && !GETPOST('getsuppliercode')) && ($action == 'add' || $action == 'update') && $permissiontoadd) {
294 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
295
296 if (!GETPOST('name')) {
297 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdPartyName")), null, 'errors');
298 $error++;
299 }
300 if (GETPOSTINT('customer') && GETPOSTINT('customer') < 0) {
301 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Customer")), null, 'errors');
302 $error++;
303 }
304 if (GETPOSTINT('prospect') && GETPOSTINT('prospect') < 0) {
305 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Prospect")), null, 'errors');
306 $error++;
307 }
308 if (GETPOSTISSET('supplier') && GETPOSTINT('supplier') < 0) {
309 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Supplier")), null, 'errors');
310 $error++;
311 }
312
313 if (isModEnabled('mailing') && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2 && GETPOSTINT('contact_no_email') == -1 && !empty(GETPOST('email', 'email'))) {
314 $error++;
315 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("No_Email")), null, 'errors');
316 }
317
318 if (isModEnabled('mailing') && GETPOSTINT("private") == 1 && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2 && GETPOSTINT('contact_no_email') == -1 && !empty(GETPOST('email', 'email'))) {
319 $error++;
320 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("No_Email")), null, 'errors');
321 }
322
323 if (!$error) {
324 if ($action == 'update') { // Test on permission not required here
325 $ret = $object->fetch($socid);
326 $object->oldcopy = clone $object; // @phan-suppress-current-line PhanTypeMismatchProperty
327 } else {
328 $object->canvas = $canvas;
329 }
330
331 if (GETPOSTINT("private") == 1) { // Ask to create a contact
332 $object->particulier = GETPOSTINT("private");
333
334 $object->name = dolGetFirstLastname(GETPOST('firstname', 'alphanohtml'), GETPOST('name', 'alphanohtml'));
335 $object->civility_id = GETPOST('civility_id', 'alphanohtml'); // Note: civility id is a code, not an int
336 $object->civility_code = GETPOST('civility_id', 'alphanohtml'); // Note: civility id is a code, not an int
337 // Add non official properties
338 $object->name_bis = GETPOST('name', 'alphanohtml');
339 $object->firstname = GETPOST('firstname', 'alphanohtml');
340 } else {
341 $object->name = GETPOST('name', 'alphanohtml');
342 }
343 $object->entity = ((GETPOSTISSET('entity') && GETPOST('entity') != '') ? GETPOSTINT('entity') : $conf->entity);
344 $object->name_alias = GETPOST('name_alias', 'alphanohtml');
345 $object->parent = GETPOSTISSET('parent_company_id') ? GETPOSTINT('parent_company_id') : $object->parent;
346 $object->address = GETPOST('address', 'alphanohtml');
347 $object->zip = GETPOST('zipcode', 'alphanohtml');
348 $object->town = GETPOST('town', 'alphanohtml');
349 $object->country_id = GETPOSTINT('country_id');
350 $object->state_id = GETPOSTINT('state_id');
351
352 $object->socialnetworks = array();
353 if (isModEnabled('socialnetworks')) {
354 foreach ($socialnetworks as $key => $value) {
355 if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
356 $object->socialnetworks[$key] = GETPOST($key, 'alphanohtml');
357 }
358 }
359 }
360
361 $object->phone = GETPOST('phone', 'alpha');
362 $object->phone_mobile = (string) GETPOST("phone_mobile", 'alpha');
363 $object->fax = GETPOST('fax', 'alpha');
364 $object->email = trim(GETPOST('email', 'email'));
365 $object->no_email = GETPOSTINT("no_email");
366 $object->url = trim(GETPOST('url', 'url'));
367 $object->idprof1 = trim(GETPOST('idprof1', 'alphanohtml'));
368 $object->idprof2 = trim(GETPOST('idprof2', 'alphanohtml'));
369 $object->idprof3 = trim(GETPOST('idprof3', 'alphanohtml'));
370 $object->idprof4 = trim(GETPOST('idprof4', 'alphanohtml'));
371 $object->idprof5 = trim(GETPOST('idprof5', 'alphanohtml'));
372 $object->idprof6 = trim(GETPOST('idprof6', 'alphanohtml'));
373 $object->prefix_comm = GETPOST('prefix_comm', 'alphanohtml');
374 $object->code_client = GETPOSTISSET('customer_code') ? GETPOST('customer_code', 'alpha') : GETPOST('code_client', 'alpha');
375 $object->code_fournisseur = GETPOSTISSET('supplier_code') ? GETPOST('supplier_code', 'alpha') : GETPOST('code_fournisseur', 'alpha');
376 $object->capital = GETPOST('capital'); // Can be null or 0 or a float value
377 $object->barcode = GETPOST('barcode', 'alphanohtml');
378 $object->fk_account = GETPOSTINT('fk_account') > 0 ? GETPOSTINT('fk_account') : 0;
379
380 $object->euid = GETPOST('euid', 'alphanohtml');
381 $object->tva_intra = GETPOST('tva_intra', 'alphanohtml');
382 $object->tva_assuj = GETPOSTINT('assujtva_value');
383 $object->vat_reverse_charge = GETPOST('vat_reverse_charge') == 'on' ? 1 : 0;
384 $object->status = GETPOSTINT('status');
385
386 // Local Taxes
387 $object->localtax1_assuj = GETPOSTINT('localtax1assuj_value');
388 $object->localtax2_assuj = GETPOSTINT('localtax2assuj_value');
389
390 $object->localtax1_value = GETPOST('lt1', 'alpha');
391 $object->localtax2_value = GETPOST('lt2', 'alpha');
392
393 $object->forme_juridique_code = GETPOSTINT('forme_juridique_code');
394 $object->birth = dol_mktime(0, 0, 0, GETPOSTINT('birthmonth'), GETPOSTINT('birthday'), GETPOSTINT('birthyear'));
395
396 $object->effectif_id = GETPOSTINT('effectif_id');
397 $object->typent_id = GETPOSTINT('typent_id');
398
399 $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
400
401 // Calculate the type of the thirdparty
402 $customer = (GETPOSTINT('customer') > 0 ? 1 : 0);
403 $prospect = (GETPOSTINT('prospect') > 0 ? 2 : 0);
404 $prospectcustomer = $customer + $prospect;
405
406 $object->client = $prospectcustomer;
407 $object->fournisseur = (GETPOSTINT('supplier') > 0 ? 1 : 0);
408
409 if ($action == 'add') { // Test on permission already done
410 // for prospect, customer or supplier
411 if ($object->client > 0 || $object->fournisseur > 0) {
412 $form = new Form($db);
413 $form->load_cache_types_paiements();
414
415 $paymentTermId = GETPOSTINT('cond_reglement_id');
416 $paymentTypeId = GETPOSTINT('mode_reglement_id');
417 if ($object->client > 0) {
418 $object->cond_reglement_id = $paymentTermId;
419
420 $filterPaymentTypeIdArr = array(0, 2, 3); // allow payment type for customer (filter is "CRDT" in "Form::select_types_paiements()" method)
421 if (!empty($form->cache_types_paiements[$paymentTypeId]) && isset($form->cache_types_paiements[$paymentTypeId]['type']) && in_array($form->cache_types_paiements[$paymentTypeId]['type'], $filterPaymentTypeIdArr)) {
422 $object->mode_reglement_id = $paymentTypeId;
423 }
424 }
425
426 if ($object->fournisseur > 0) {
427 $object->cond_reglement_supplier_id = $paymentTermId;
428
429 $filterPaymentTypeIdArr = array(1, 2, 3); // allow payment type for supplier (filter is "DBIT" in "Form::select_types_paiements()" method)
430 if (!empty($form->cache_types_paiements[$paymentTypeId]) && isset($form->cache_types_paiements[$paymentTypeId]['type']) && in_array($form->cache_types_paiements[$paymentTypeId]['type'], $filterPaymentTypeIdArr)) {
431 $object->mode_reglement_supplier_id = $paymentTypeId;
432 }
433 }
434 }
435 }
436
437 $object->commercial_id = GETPOSTINT('commercial_id');
438 $object->default_lang = GETPOST('default_lang');
439
440 // Webservices url/key
441 $object->webservices_url = GETPOST('webservices_url', 'url');
442 $object->webservices_key = GETPOST('webservices_key', 'password');
443
444 if (GETPOSTISSET('accountancy_code_sell')) {
445 $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
446
447 if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') {
448 $object->accountancy_code_sell = '';
449 } else {
450 $object->accountancy_code_sell = $accountancy_code_sell;
451 }
452 }
453 if (GETPOSTISSET('accountancy_code_buy')) {
454 $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
455
456 if (empty($accountancy_code_buy) || $accountancy_code_buy == '-1') {
457 $object->accountancy_code_buy = '';
458 } else {
459 $object->accountancy_code_buy = $accountancy_code_buy;
460 }
461 }
462
463 // Incoterms
464 if (isModEnabled('incoterm')) {
465 $object->fk_incoterms = GETPOSTINT('incoterm_id');
466 $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
467 }
468
469 // Multicurrency
470 if (isModEnabled("multicurrency")) {
471 $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
472 }
473
474 // Fill array 'array_options' with data from add form
475 $ret = $extrafields->setOptionalsFromPost(null, $object);
476 if ($ret < 0) {
477 $error++;
478 }
479
480 // Fill array 'array_languages' with data from add form
481 $ret = $object->setValuesForExtraLanguages();
482 if ($ret < 0) {
483 $error++;
484 }
485 //var_dump($object->array_languages);exit;
486
487 if (!empty($_FILES['photo']['name'])) {
488 $current_logo = $object->logo;
489 $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
490 }
491 if (GETPOST('deletephoto')) {
492 $current_logo = $object->logo;
493 $object->logo = '';
494 }
495
496
497 // Check parameters
498 if (!GETPOST('cancel', 'alpha')) {
499 if (!empty($object->email) && !isValidEmail($object->email)) {
500 $langs->load("errors");
501 $error++;
502 setEventMessages($langs->trans("ErrorBadEMail", $object->email), null, 'errors');
503 }
504 if (!empty($object->url) && !isValidUrl($object->url)) {
505 $langs->load("errors");
506 setEventMessages($langs->trans("ErrorBadUrl", $object->url), null, 'errors');
507 }
508 if (!empty($object->webservices_url)) {
509 //Check if has transport, without any the soap client will give error
510 if (strpos($object->webservices_url, "http") === false) {
511 $object->webservices_url = "http://".$object->webservices_url;
512 }
513 if (!isValidUrl($object->webservices_url)) {
514 $langs->load("errors");
515 $error++;
516 $errors[] = $langs->trans("ErrorBadUrl", $object->webservices_url);
517 }
518 }
519
520 // We set country_id, country_code and country for the selected country
521 $object->country_id = GETPOSTINT('country_id') != '' ? GETPOSTINT('country_id') : $mysoc->country_id;
522 if ($object->country_id) {
523 $tmparray = getCountry($object->country_id, 'all');
524 $object->country_code = $tmparray['code'];
525 $object->country = $tmparray['label'];
526 }
527 }
528 }
529
530 if (!$error) {
531 if ($action == 'add' && $permissiontoadd) {
532 $error = 0;
533
534 $db->begin();
535
536 if (empty($object->client)) {
537 $object->code_client = '';
538 }
539 if (empty($object->fournisseur)) {
540 $object->code_fournisseur = '';
541 }
542
543 $result = $object->create($user);
544
545 if ($result >= 0 && isModEnabled('mailing') && !empty($object->email) && $object->no_email == 1) {
546 // Add mass emailing flag into table mailing_unsubscribe
547 $resultnoemail = $object->setNoEmail($object->no_email);
548 if ($resultnoemail < 0) {
549 $error++;
550 $errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
551 $action = 'create';
552 }
553 }
554
555 if ($result >= 0) {
556 if ($object->particulier) {
557 dol_syslog("We ask to create a contact/address too", LOG_DEBUG);
558 $contcats = GETPOST('contcats', 'array');
559 $no_email = GETPOSTINT('contact_no_email');
560 $result = $object->create_individual($user, $no_email, $contcats);
561 if ($result < 0) {
562 setEventMessages($object->error, $object->errors, 'errors');
563 $error++;
564 }
565 }
566
567 // Links with users
568 $salesreps = GETPOST('commercial', 'array');
569 $result = $object->setSalesRep($salesreps, true);
570 if ($result < 0) {
571 $error++;
572 setEventMessages($object->error, $object->errors, 'errors');
573 }
574
575 // Customer categories association
576 $custcats = GETPOST('custcats', 'array');
577 $result = $object->setCategories($custcats, 'customer');
578 if ($result < 0) {
579 $error++;
580 setEventMessages($object->error, $object->errors, 'errors');
581 }
582
583 // Supplier categories association
584 $suppcats = GETPOST('suppcats', 'array');
585 $result = $object->setCategories($suppcats, 'supplier');
586 if ($result < 0) {
587 $error++;
588 setEventMessages($object->error, $object->errors, 'errors');
589 }
590
591 // Logo/Photo save
592 $dir = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos/";
593 $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
594 if ($file_OK) {
595 if (image_format_supported($_FILES['photo']['name'])) {
596 dol_mkdir($dir);
597
598 if (@is_dir($dir)) {
599 $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
600 $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
601
602 if (!($result > 0)) {
603 $errors[] = "ErrorFailedToSaveFile";
604 } else {
605 // Create thumbs
606 $object->addThumbs($newfile);
607
608 // Index file in database
609 if (getDolGlobalString('THIRDPARTY_LOGO_ALLOW_EXTERNAL_DOWNLOAD')) {
610 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
611 // 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
612 deleteFilesIntoDatabaseIndex(dirname($newfile), '', '', $object);
613 // now we index the uploaded logo file
614 addFileIntoDatabaseIndex(dirname($newfile), basename($newfile), '', 'uploaded', 1, $object);
615 }
616 }
617 }
618 }
619 } else {
620 switch ($_FILES['photo']['error']) {
621 case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
622 case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
623 $errors[] = "ErrorFileSizeTooLarge";
624 break;
625 case 3: //uploaded file was only partially uploaded
626 $errors[] = "ErrorFilePartiallyUploaded";
627 break;
628 }
629 }
630 } else {
631 if ($result == -3 && in_array('ErrorCustomerCodeAlreadyUsed', $object->errors)) {
632 $duplicate_code_error = true;
633 $object->code_client = '';
634 }
635
636 if ($result == -3 && in_array('ErrorSupplierCodeAlreadyUsed', $object->errors)) {
637 $duplicate_code_error = true;
638 $object->code_fournisseur = '';
639 }
640
641 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
642 $duplicate_code_error = true;
643 }
644
645 setEventMessages($object->error, $object->errors, 'errors');
646 $error++;
647 }
648
649 if ($result >= 0 && !$error) {
650 $db->commit();
651
652 if (!empty($backtopage)) {
653 $backtopage = preg_replace('/--IDFORBACKTOPAGE--/', (string) $object->id, $backtopage); // New method to autoselect project after a New on another form object creation
654 if (preg_match('/\?/', $backtopage)) {
655 $backtopage .= '&socid='.$object->id; // Old method
656 }
657 header("Location: ".$backtopage);
658 exit;
659 } else {
660 $url = $_SERVER["PHP_SELF"]."?socid=".$object->id; // Old method
661 if (($object->client == 1 || $object->client == 3) && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS')) {
662 $url = DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
663 } elseif ($object->fournisseur == 1) {
664 $url = DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
665 }
666
667 header("Location: ".$url);
668 exit;
669 }
670 } else {
671 $db->rollback();
672 $action = 'create';
673 }
674 }
675
676 if ($action == 'update' && $permissiontoadd) {
677 $error = 0;
678
679 if (GETPOST('cancel', 'alpha')) {
680 if (!empty($backtopage)) {
681 header("Location: ".$backtopage);
682 exit;
683 } else {
684 header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
685 exit;
686 }
687 }
688
689 // To not set code if third party is not concerned. But if it had values, we keep them.
690 if (empty($object->client) && empty($object->oldcopy->code_client)) {
691 $object->code_client = '';
692 }
693 if (empty($object->fournisseur) && empty($object->oldcopy->code_fournisseur)) {
694 $object->code_fournisseur = '';
695 }
696 //var_dump($object);exit;
697
698 $nosyncmember = getDolGlobalInt('SOCIETE_NO_SYNC_LINKED_MEMBER');
699
700 $result = $object->update($socid, $user, 1, $object->oldcopy->codeclient_modifiable(), $object->oldcopy->codefournisseur_modifiable(), 'update', $nosyncmember);
701
702 if ($result > 0) {
703 // Update mass emailing flag into table mailing_unsubscribe
704 if (GETPOSTISSET('no_email') && $object->email) {
705 $no_email = GETPOSTINT('no_email');
706 $result = $object->setNoEmail($no_email);
707 if ($result < 0) {
708 setEventMessages($object->error, $object->errors, 'errors');
709 $action = 'edit';
710 }
711 }
712
713 $action = 'view';
714 } else {
715 setEventMessages($object->error, $object->errors, 'errors');
716 $action = 'edit';
717 }
718
719 if ($result <= 0) {
720 setEventMessages($object->error, $object->errors, 'errors');
721 $error++;
722 }
723
724 // Links with users
725 $salesreps = GETPOST('commercial', 'array');
726 $result = $object->setSalesRep($salesreps);
727 if ($result < 0) {
728 $error++;
729 setEventMessages($object->error, $object->errors, 'errors');
730 }
731
732 // Prevent thirdparty's emptying if a user hasn't rights $user->rights->categorie->lire (in such a case, post of 'custcats' is not defined)
733 if (!$error && $user->hasRight('categorie', 'lire')) {
734 // Customer categories association
735 $categories = GETPOST('custcats', 'array');
736 $result = $object->setCategories($categories, 'customer');
737 if ($result < 0) {
738 $error++;
739 setEventMessages($object->error, $object->errors, 'errors');
740 }
741
742 // Supplier categories association
743 $categories = GETPOST('suppcats', 'array');
744 $result = $object->setCategories($categories, 'supplier');
745 if ($result < 0) {
746 $error++;
747 setEventMessages($object->error, $object->errors, 'errors');
748 }
749 }
750
751 // Logo/Photo save
752 $dir = $conf->societe->multidir_output[$object->entity ?? $conf->entity]."/".$object->id."/logos";
753 $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
754 if (GETPOST('deletephoto') && $current_logo) {
755 $fileimg = $dir.'/'.$current_logo;
756 $dirthumbs = $dir.'/thumbs';
757 dol_delete_file($fileimg);
758 dol_delete_dir_recursive($dirthumbs);
759 }
760 if ($file_OK) {
761 if (image_format_supported($_FILES['photo']['name']) > 0) {
762 if ($current_logo != $object->logo) {
763 $fileimg = $dir.'/'.$current_logo;
764 $dirthumbs = $dir.'/thumbs';
765 dol_delete_file($fileimg);
766 dol_delete_dir_recursive($dirthumbs);
767 }
768
769 dol_mkdir($dir);
770
771 if (@is_dir($dir)) {
772 $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
773 $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
774
775 if (!($result > 0)) {
776 $errors[] = "ErrorFailedToSaveFile";
777 } else {
778 // Create thumbs
779 $object->addThumbs($newfile);
780
781 // Index file in database
782 if (getDolGlobalString('THIRDPARTY_LOGO_ALLOW_EXTERNAL_DOWNLOAD')) {
783 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
784 // 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
785 deleteFilesIntoDatabaseIndex(dirname($newfile), '', '', $object);
786 // now we index the uploaded logo file
787 addFileIntoDatabaseIndex(dirname($newfile), basename($newfile), '', 'uploaded', 1, $object);
788 }
789 }
790 }
791 } else {
792 $errors[] = "ErrorBadImageFormat";
793 }
794 } else {
795 switch ($_FILES['photo']['error']) {
796 case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
797 case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
798 $errors[] = "ErrorFileSizeTooLarge";
799 break;
800 case 3: //uploaded file was only partially uploaded
801 $errors[] = "ErrorFilePartiallyUploaded";
802 break;
803 }
804 }
805 // Company logo management
806
807
808 // Update linked member
809 if (!$error && isset($object->fk_soc) && $object->fk_soc > 0) {
810 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
811 $sql .= " SET fk_soc = NULL WHERE fk_soc = ".((int) $socid);
812 if (!$object->db->query($sql)) {
813 $error++;
814 $object->error .= $object->db->lasterror();
815 setEventMessages($object->error, $object->errors, 'errors');
816 }
817 }
818
819 if (!$error && !count($errors)) {
820 if (!empty($backtopage)) {
821 header("Location: ".$backtopage);
822 exit;
823 } else {
824 header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
825 exit;
826 }
827 } else {
828 $object->id = $socid;
829 $action = "edit";
830 }
831 }
832 } else {
833 $action = ($action == 'add' ? 'create' : 'edit');
834 }
835 }
836
837 // Delete third party
838 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('societe', 'supprimer')) {
839 $object->fetch($socid);
840 $object->oldcopy = clone $object; // @phan-suppress-current-line PhanTypeMismatchProperty
841 $result = $object->delete($socid, $user);
842
843 if ($result > 0) {
844 header("Location: ".DOL_URL_ROOT."/societe/list.php?restore_lastsearch_values=1&delsoc=".urlencode($object->name));
845 exit;
846 } else {
847 $langs->load("errors");
848 setEventMessages($object->error, $object->errors, 'errors');
849 $error++;
850 $action = '';
851 }
852 }
853
854 // Set third-party type
855 if ($action == 'set_thirdpartytype' && $permissiontoadd) {
856 $object->fetch($socid);
857 $result = $object->setThirdpartyType(GETPOSTINT('typent_id'));
858 }
859
860 // Set incoterm
861 if ($action == 'set_incoterms' && $permissiontoadd && isModEnabled('incoterm')) {
862 $object->fetch($socid);
863 $result = $object->setIncoterms(GETPOSTINT('incoterm_id'), GETPOST('location_incoterms'));
864 }
865
866 // Set parent company
867 if ($action == 'set_thirdparty' && $permissiontoadd) {
868 $object->fetch($socid);
869 $result = $object->setParent(GETPOSTINT('parent_id'));
870 }
871
872 // Set sales representatives
873 if ($action == 'set_salesrepresentatives' && $permissiontoadd) {
874 $object->fetch($socid);
875 $result = $object->setSalesRep(GETPOST('commercial', 'array'));
876 }
877
878 // warehouse
879 if ($action == 'setwarehouse' && $permissiontoadd) {
880 $result = $object->setWarehouse(GETPOSTINT('fk_warehouse'));
881 }
882
883 if ($action == 'confirm_clone' && $confirm != 'yes') { // Test on permission not required here
884 $action = '';
885 }
886 //clone company essential info
887 if ($action == 'confirm_clone' && $confirm == 'yes' && $user->hasRight('societe', 'creer')) {
888 if ($object->id > 0) {
889 $error = 0;
890
891 $clone = dol_clone($object, 1);
892
893 if (!empty(GETPOST('clone_name'))) {
894 $clone->id = 0;
895 $clone->name = GETPOST('clone_name', 'alphanohtml');
896 $clone->status = 1;
897 $clone->fournisseur = 0;
898 $clone->client = 0;
899
900 $db->begin();
901
902 $clone->context['createfromclone'] = 'createfromclone';
903 $id = $clone->create($user);
904 if ($id > 0) {
905 $clone->id = $id;
906 } else {
907 setEventMessages($clone->error, $clone->errors, 'errors');
908 $error++;
909 }
910
911 unset($clone->context['createfromclone']);
912
913 if ($error) {
914 $db->rollback();
915 } else {
916 $db->commit();
917 $db->close();
918 header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
919 exit;
920 }
921 } else {
922 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NewRefForClone")), null, 'errors');
923 }
924 } else {
925 dol_print_error($db, $object->error, $object->errors);
926 }
927 $action = 'clone';
928 }
929
930 $id = $socid;
931 $object->fetch($socid);
932
933 // Selection of new fields
934 if (getDolGlobalString('MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD') && (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS') || getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT'))) {
935 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
936 }
937
938 // Actions to send emails
939 $triggersendname = 'COMPANY_SENTBYMAIL';
940 $paramname = 'socid';
941 $mode = 'emailfromthirdparty';
942 $trackid = 'thi'.$object->id;
943 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
944
945 // Actions to build doc
946 $id = $socid;
947 $upload_dir = !empty($conf->societe->multidir_output[$object->entity ?? $conf->entity]) ? $conf->societe->multidir_output[$object->entity ?? $conf->entity] : $conf->societe->dir_output;
948 $permissiontoadd = $user->hasRight('societe', 'creer');
949 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
950
951 // Actions when printing a doc from card
952 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
953}
954
955
956/*
957 * View
958 */
959
960$form = new Form($db);
961$formfile = new FormFile($db);
962$formadmin = new FormAdmin($db);
963$formcompany = new FormCompany($db);
964$formaccounting = null;
965if (isModEnabled('accounting')) {
966 $formaccounting = new FormAccounting($db);
967}
968
969if ($socid > 0 && empty($object->id)) {
970 $result = $object->fetch($socid);
971 if ($result <= 0) {
972 dol_print_error(null, $object->error);
973 exit(1);
974 }
975}
976
977$title = $langs->trans("ThirdParty");
978if ($action == 'create') {
979 $title = $langs->trans("NewThirdParty");
980}
981if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/thirdpartynameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->name) {
982 $title = $object->name." - ".$langs->trans('Card');
983}
984$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas|DE:Modul_Geschäftspartner';
985
986llxHeader('', $title, $help_url);
987
988$countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
989
990$canvasdisplayaction = $action;
991if (in_array($canvasdisplayaction, array('merge', 'confirm_merge'))) {
992 $canvasdisplayaction = 'view';
993}
994
995if (is_object($objcanvas) && $objcanvas->displayCanvasExists($canvasdisplayaction)) {
996 // -----------------------------------------
997 // When used with CANVAS
998 // -----------------------------------------
999 $objcanvas->assign_values($canvasdisplayaction, $object->id, $object->ref); // Set value for templates
1000 $objcanvas->display_canvas($canvasdisplayaction); // Show template
1001} else {
1002 // -----------------------------------------
1003 // When used in standard mode
1004 // -----------------------------------------
1005 if ($action == 'create') {
1006 /*
1007 * Creation
1008 */
1009 $private = GETPOSTINT("private");
1010 if (getDolGlobalString('THIRDPARTY_DEFAULT_CREATE_CONTACT') && !GETPOSTISSET('private') && GETPOST("type", 'aZ') != 'f') {
1011 $private = 1;
1012 }
1013 if (empty($private)) {
1014 $private = 0;
1015 }
1016
1017 // Load object modCodeClient
1018 $module = getDolGlobalString('SOCIETE_CODECLIENT_ADDON', 'mod_codeclient_leopard');
1019 if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
1020 $module = substr($module, 0, dol_strlen($module) - 4);
1021 }
1022 $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
1023 foreach ($dirsociete as $dirroot) {
1024 $res = dol_include_once($dirroot.$module.'.php');
1025 if ($res) {
1026 break;
1027 }
1028 }
1029 $modCodeClient = new $module($db);
1030 '@phan-var-force ModeleThirdPartyCode $modCodeClient';
1031
1032 // Load object modCodeFournisseur
1033 $module = getDolGlobalString('SOCIETE_CODECLIENT_ADDON', 'mod_codeclient_leopard');
1034 if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
1035 $module = substr($module, 0, dol_strlen($module) - 4);
1036 }
1037 $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
1038 foreach ($dirsociete as $dirroot) {
1039 $res = dol_include_once($dirroot.$module.'.php');
1040 if ($res) {
1041 break;
1042 }
1043 }
1044 $modCodeFournisseur = new $module($db);
1045 '@phan-var-force ModeleThirdPartyCode $modCodeFournisseur';
1046
1047 // Define if customer/prospect or supplier status is set or not
1048 if (GETPOST("type", 'aZ') != 'f') {
1049 $object->client = -1;
1050 if (getDolGlobalString('THIRDPARTY_CUSTOMERPROSPECT_BY_DEFAULT')) {
1051 $object->client = 3;
1052 }
1053 }
1054 // Prospect / Customer
1055 if (GETPOST("type", 'aZ') == 'c') {
1056 if (getDolGlobalInt('THIRDPARTY_CUSTOMERTYPE_BY_DEFAULT')) {
1057 $object->client = getDolGlobalInt('THIRDPARTY_CUSTOMERTYPE_BY_DEFAULT');
1058 } else {
1059 $object->client = 3;
1060 }
1061 }
1062 if (GETPOST("type", 'aZ') == 'p') {
1063 $object->client = 2;
1064 }
1065
1066 if (getDolGlobalString('SOCIETE_DISABLE_PROSPECTSCUSTOMERS') && $object->client == 3) {
1067 $object->client = 1;
1068 }
1069
1070 if ((isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && (GETPOST("type") == 'f' || (GETPOST("type") == '' && getDolGlobalString('THIRDPARTY_SUPPLIER_BY_DEFAULT')))) {
1071 $object->fournisseur = 1;
1072 }
1073
1074 $object->name = GETPOST('name', 'alphanohtml');
1075 $object->name_alias = GETPOST('name_alias', 'alphanohtml');
1076 $object->firstname = GETPOST('firstname', 'alphanohtml');
1077 $object->particulier = $private;
1078 $object->prefix_comm = GETPOST('prefix_comm', 'alphanohtml');
1079 //$object->client = GETPOSTINT('client') ? GETPOSTINT('client') : $object->client;
1080
1081 if (empty($duplicate_code_error)) {
1082 $object->code_client = GETPOST('customer_code', 'alpha');
1083 $object->fournisseur = GETPOST('fournisseur') ? GETPOSTINT('fournisseur') : $object->fournisseur;
1084 $object->code_fournisseur = GETPOST('supplier_code', 'alpha');
1085 } else {
1086 setEventMessages($langs->trans('NewCustomerSupplierCodeProposed'), null, 'warnings');
1087 }
1088
1089 $object->address = GETPOST('address', 'alphanohtml');
1090 $object->zip = GETPOST('zipcode', 'alphanohtml');
1091 $object->town = GETPOST('town', 'alphanohtml');
1092 $object->state_id = GETPOSTINT('state_id');
1093
1094 $object->socialnetworks = array();
1095 if (isModEnabled('socialnetworks')) {
1096 foreach ($socialnetworks as $key => $value) {
1097 if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
1098 $object->socialnetworks[$key] = GETPOST($key, 'alphanohtml');
1099 }
1100 }
1101 }
1102
1103 $object->phone = GETPOST('phone', 'alpha');
1104 $object->phone_mobile = (string) GETPOST("phone_mobile", 'alpha');
1105 $object->fax = GETPOST('fax', 'alpha');
1106 $object->email = GETPOST('email', 'email');
1107 $object->url = GETPOST('url', 'url');
1108 $object->capital = GETPOST('capital'); // can be null or 0 or a float value
1109 $paymentTermId = GETPOSTINT('cond_reglement_id'); // can be set by default values on create page and not already in get or post variables
1110 if (empty($paymentTermId) && !GETPOSTISSET('cond_reglement_id')) {
1111 $paymentTermId = getDolGlobalString('MAIN_DEFAULT_PAYMENT_TERM_ID');
1112 }
1113 $object->cond_reglement_id = $paymentTermId;
1114 $paymentTypeId = GETPOSTINT('mode_reglement_id'); // can be set by default values on create page and not already in get or post variables
1115 if (empty($paymentTypeId) && !GETPOSTISSET('mode_reglement_id')) {
1116 $paymentTypeId = getDolGlobalString('MAIN_DEFAULT_PAYMENT_TYPE_ID');
1117 }
1118 $object->mode_reglement_id = $paymentTypeId;
1119 $object->barcode = GETPOST('barcode', 'alphanohtml');
1120 $object->idprof1 = GETPOST('idprof1', 'alphanohtml');
1121 $object->idprof2 = GETPOST('idprof2', 'alphanohtml');
1122 $object->idprof3 = GETPOST('idprof3', 'alphanohtml');
1123 $object->idprof4 = GETPOST('idprof4', 'alphanohtml');
1124 $object->idprof5 = GETPOST('idprof5', 'alphanohtml');
1125 $object->idprof6 = GETPOST('idprof6', 'alphanohtml');
1126 $object->typent_id = GETPOSTINT('typent_id');
1127 $object->effectif_id = GETPOSTINT('effectif_id');
1128 $object->civility_id = GETPOST('civility_id', 'alpha');
1129
1130 $object->tva_assuj = GETPOSTINT('assujtva_value');
1131 $object->vat_reverse_charge = GETPOST('vat_reverse_charge') == 'on' ? 1 : 0;
1132 $object->status = GETPOSTINT('status');
1133
1134 //Local Taxes
1135 $object->localtax1_assuj = GETPOSTINT('localtax1assuj_value');
1136 $object->localtax2_assuj = GETPOSTINT('localtax2assuj_value');
1137
1138 $object->localtax1_value = GETPOST('lt1', 'alpha');
1139 $object->localtax2_value = GETPOST('lt2', 'alpha');
1140
1141 $object->euid = GETPOST('euid', 'alphanohtml');
1142 $object->tva_intra = GETPOST('tva_intra', 'alphanohtml');
1143
1144 $object->commercial_id = GETPOSTINT('commercial_id');
1145 $object->default_lang = GETPOST('default_lang');
1146
1147 if (GETPOSTISSET('accountancy_code_sell')) {
1148 $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
1149
1150 if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') {
1151 $object->accountancy_code_sell = '';
1152 } else {
1153 $object->accountancy_code_sell = $accountancy_code_sell;
1154 }
1155 }
1156 if (GETPOSTISSET('accountancy_code_buy')) {
1157 $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
1158
1159 if (empty($accountancy_code_buy) || $accountancy_code_buy == '-1') {
1160 $object->accountancy_code_buy = '';
1161 } else {
1162 $object->accountancy_code_buy = $accountancy_code_buy;
1163 }
1164 }
1165
1166 $object->logo = (isset($_FILES['photo']) ? dol_sanitizeFileName($_FILES['photo']['name']) : '');
1167
1168 // Company logo management
1169 $dir = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos";
1170 $file_OK = (isset($_FILES['photo']) ? is_uploaded_file($_FILES['photo']['tmp_name']) : false);
1171 if ($file_OK) {
1172 if (image_format_supported($_FILES['photo']['name'])) {
1173 dol_mkdir($dir);
1174
1175 if (@is_dir($dir)) {
1176 $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
1177 $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
1178
1179 if (!($result > 0)) {
1180 $errors[] = "ErrorFailedToSaveFile";
1181 } else {
1182 // Create thumbs
1183 $object->addThumbs($newfile);
1184 }
1185 }
1186 }
1187 }
1188
1189 // We set country_id, country_code and country for the selected country
1190 $object->country_id = GETPOST('country_id') ? GETPOST('country_id') : $mysoc->country_id;
1191 if ($object->country_id) {
1192 $tmparray = getCountry($object->country_id, 'all');
1193 $object->country_code = $tmparray['code'];
1194 $object->country = $tmparray['label'];
1195 }
1196 $object->forme_juridique_code = GETPOSTINT('forme_juridique_code');
1197
1198 // We set multicurrency_code if enabled
1199 if (isModEnabled("multicurrency")) {
1200 $object->multicurrency_code = GETPOST('multicurrency_code') ? GETPOST('multicurrency_code') : $conf->currency;
1201 }
1202 /* Show create form */
1203
1204 $linkback = "";
1205 print load_fiche_titre($langs->trans("NewThirdParty"), $linkback, 'building');
1206
1207 if (!empty($conf->use_javascript_ajax)) {
1208 // If option to also create a contact
1209 if (getDolGlobalString('THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION')) {
1210 print "\n".'<script type="text/javascript">';
1211 print '$(document).ready(function () {
1212 id_te_private=8;
1213 id_ef15=1;
1214 is_private=' . $private.';
1215 if (is_private) {
1216 $(".individualline").show();
1217 $(".professionalline").hide();
1218 } else {
1219 $(".individualline").hide();
1220 $(".professionalline").show();
1221 }
1222 $("#radiocompany").click(function() {
1223 $(".individualline").hide();
1224 $(".professionalline").show();
1225 $("#typent_id").val(0);
1226 $("#typent_id").change();
1227 $("#effectif_id").val(0);
1228 $("#effectif_id").change();
1229 $("#TypeName").html(document.formsoc.ThirdPartyName.value);
1230 document.formsoc.private.value=0;
1231 });
1232 $("#radioprivate").click(function() {
1233 $(".individualline").show();
1234 $(".professionalline").hide();
1235 $("#typent_id").val(id_te_private);
1236 $("#typent_id").change();
1237 $("#effectif_id").val(id_ef15);
1238 $("#effectif_id").change();
1239 /* Force to recompute the width of a select2 field when it was hidden and then shown programmatically */
1240 if ($("#civility_id").data("select2")) {
1241 $("#civility_id").select2({width: "resolve"});
1242 }
1243 $("#TypeName").html(document.formsoc.LastName.value);
1244 document.formsoc.private.value=1;
1245 });';
1246
1247 if (getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2) {
1248 print '
1249 function init_check_no_email(input) {
1250 if (input.val()!="") {
1251 $(".noemail").addClass("fieldrequired");
1252 } else {
1253 $(".noemail").removeClass("fieldrequired");
1254 }
1255 }
1256 $("#email").keyup(function() {
1257 init_check_no_email($(this));
1258 });
1259 init_check_no_email($("#email"));';
1260 }
1261 print '});';
1262 print '</script>'."\n";
1263
1264 print '<div id="selectthirdpartytype">';
1265 print '<div class="hideonsmartphone float">';
1266 print $langs->trans("ThirdPartyType").': &nbsp; &nbsp; ';
1267 print '</div>';
1268 print '<label for="radiocompany" class="radiocompany">';
1269 print '<input type="radio" id="radiocompany" class="flat" name="private" value="0"'.($private ? '' : ' checked').'>';
1270 print '&nbsp;';
1271 print $langs->trans("CreateThirdPartyOnly");
1272 print '</label>';
1273 print ' &nbsp; &nbsp; ';
1274 print '<label for="radioprivate" class="radioprivate">';
1275 $text = '<input type="radio" id="radioprivate" class="flat" name="private" value="1"'.($private ? ' checked' : '').'>';
1276 $text .= '&nbsp;';
1277 $text .= $langs->trans("CreateThirdPartyAndContact");
1278 $htmltext = $langs->trans("ToCreateContactWithSameName");
1279 print $form->textwithpicto($text, $htmltext, 1, 'help', '', 0, 3);
1280 print '</label>';
1281 print '</div>';
1282 print "<br>\n";
1283 }
1284
1285 print '<script type="text/javascript">';
1286 print '$(document).ready(function () {
1287 var canHaveCustomerCategoryIfNotCustomerProspectSupplier = ' . (!getDolGlobalString('THIRDPARTY_CAN_HAVE_CUSTOMER_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT') ? '0' : '1') . ';
1288
1289 init_customer_categ();
1290 $("#prospectinput, #customerinput").change(function() {
1291 init_customer_categ();
1292 });
1293 function init_customer_categ() {
1294 var iscustomerorprospect = jQuery("#prospectinput").is(":checked") + jQuery("#customerinput").is(":checked");
1295 console.log("is customer or prospect = "+iscustomerorprospect);
1296 if (iscustomerorprospect == 0 && !canHaveCustomerCategoryIfNotCustomerProspectSupplier) {
1297 jQuery(".visibleifcustomer").hide();
1298 } else {
1299 jQuery(".visibleifcustomer").show();
1300 }
1301 }
1302
1303 init_supplier_categ();
1304 $("#supplierinput").change(function() {
1305 init_supplier_categ();
1306 });
1307 function init_supplier_categ() {
1308 var issupplier = jQuery("#supplierinput").is(":checked");
1309 console.log("is supplier = "+issupplier);
1310 if (issupplier == 0) {
1311 jQuery(".visibleifsupplier").hide();
1312 } else {
1313 jQuery(".visibleifsupplier").show();
1314 }
1315 }
1316
1317 $("#selectcountry_id").change(function() {
1318 console.log("selectcountry_id change");
1319 document.formsoc.action.value="create";
1320 document.formsoc.submit();
1321 });
1322 });';
1323 print '</script>'."\n";
1324 }
1325
1326 dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
1327
1328 print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc" autocomplete="off" spellcheck="false">'; // Chrome ignores autocomplete
1329
1330 print '<input type="hidden" name="action" value="add">';
1331 print '<input type="hidden" name="token" value="'.newToken().'">';
1332 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1333 print '<input type="hidden" name="dol_openinpopup" value="'.$dol_openinpopup.'">';
1334 print '<input type="hidden" name="private" value='.$object->particulier.'>';
1335 print '<input type="hidden" name="type" value='.GETPOST("type", 'alpha').'>';
1336 print '<input type="hidden" name="LastName" value="'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName').'">';
1337 print '<input type="hidden" name="ThirdPartyName" value="'.$langs->trans('ThirdPartyName').'">';
1338 if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) {
1339 print '<input type="hidden" name="code_auto" value="1">';
1340 }
1341
1342 print dol_get_fiche_head(array(), 'card', '', 0, '');
1343
1344 // Call Hook tabContentCreateThirdparty
1345 $parameters = array();
1346 // Note that $action and $object may be modified by hook
1347 $reshook = $hookmanager->executeHooks('tabContentCreateThirdparty', $parameters, $object, $action);
1348 if (empty($reshook)) {
1349 print '<table class="border centpercent">';
1350
1351 // Name, firstname
1352 print '<tr class="tr-field-thirdparty-name"><td class="titlefieldcreate">';
1353 if ($object->particulier || $private) {
1354 print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName', 'name').'</span>';
1355 } else {
1356 print '<span id="TypeName" class="fieldrequired">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0).'</span>';
1357 }
1358 print '</td><td colspan="3">';
1359
1360 print '<input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.dolPrintHTMLForAttribute($object->name).'" autofocus="autofocus" spellcheck="false">';
1361 print $form->widgetForTranslation("name", $object, $permissiontoadd, 'string', 'alphanohtml', 'minwidth300'); // For some countries that need the company name in 2 languages
1362 // This implementation of the feature to search already existing company has been disabled. It must be implemented by keeping the "input text" and we must call the search ajax societe/ajax/ajaxcompanies.php
1363 // on a keydown of the input. We should show data about a duplicate found if we found less than 5 answers into a div under the input.
1364 /*
1365 print '<select class="name" name="name" id="name" style="min-width:500px"></select>';
1366 print "\n".'<script type="text/javascript">';
1367 print '$(document).ready(function () {
1368 $("#name").select2({
1369 ajax: {
1370 url: "' . DOL_URL_ROOT . '/core/ajax/ajaxcompanies.php",
1371 dataType: "json",
1372 delay: 250,
1373 data: function (params) {
1374 return {
1375 newcompany: params.term // search term
1376 }
1377 },
1378 processResults: function (data, params) {
1379 return {
1380 results: data
1381 }
1382 },
1383 cache: true
1384 },
1385
1386 placeholder: "' . $langs->trans('Name of the new third party. In the meantime we check if it already exists...') . '",
1387 allowClear: true,
1388 minimumInputLength: 3,
1389 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage,
1390 containerCssClass: ":all:",
1391 selectionCssClass: ":all:",
1392 tags: true,
1393 templateResult: formatCustomer,
1394 templateSelection: formatCustomerSelection
1395 });
1396
1397 function formatCustomer (Customer) {
1398 if(Customer.label === undefined) {
1399 return Customer.text;
1400 }
1401
1402 if(Customer.logo !== null ) {
1403 logo = \'<img src="\';
1404 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";
1405 logo += \'" /></div>\';
1406 } else {
1407 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>\';
1408 }
1409
1410 var $container = $("<div class=\'select2-result-repository clearfix\'>" +
1411 "<div class=\'select2-result-repository__avatar floatleft inline-block valigntop\'>" + logo +
1412 "<div class=\'select2-result-repository__meta floatleft inline-block valigntop\'>" +
1413 "<div class=\'select2-result-repository__title\'></div>" +
1414 "<div class=\'select2-result-repository__name_alias\'></div>" +
1415 "<div class=\'select2-result-repository__code_client\'></div>" +
1416 "<div class=\'select2-result-repository__code_fournisseur\'></div>" +
1417 "<div class=\'select2-result-repository__companies_info\'>" +
1418 "<div class=\'select2-result-repository__email\'><i class=\'fa fa-at\'></i> </div>" +
1419 "<div class=\'select2-result-repository__address\'><i class=\'fa fa-flag\'></i> </div>" +
1420 "<div class=\'select2-result-repository__zip\'><i class=\'fa fa-circle-o\'></i> </div>" +
1421 "<div class=\'select2-result-repository__country\'><i class=\'fa fa-globe-americas\'></i> </div>" +
1422 "<div class=\'select2-result-repository__departement\'><i class=\'fa fa-circle-o\'></i> </div>" +
1423 "<div class=\'select2-result-repository__town\'><i class=\'fa fa-circle-o\'></i> </div>" +
1424 "<div class=\'select2-result-repository__siren\'><i class=\'fa fa-circle-o\'></i> </div>" +
1425 "<div class=\'select2-result-repository__datec\'><i class=\'fa fa-calendar\'></i> </div>" +
1426 "</div>" +
1427 "</div>" +
1428 "</div>"
1429 );
1430
1431 $container.find(".select2-result-repository__title").text(Customer.label);
1432 $container.find(".select2-result-repository__name_alias").text(Customer.name_alias ? Customer.name_alias : "");
1433 $container.find(".select2-result-repository__code_client").text(Customer.code_client ? Customer.code_client : "");
1434 $container.find(".select2-result-repository__code_fournisseur").text((Customer.code_fournisseur!==null) ? Customer.code_fournisseur : "");
1435 $container.find(".select2-result-repository__email").append("' . $langs->trans('EMail') . ': " + (Customer.email !== null ? Customer.email : ""));
1436 $container.find(".select2-result-repository__address").append("' . $langs->trans('Address') . ': " + (Customer.address !== null ? Customer.address : ""));
1437 $container.find(".select2-result-repository__country").append("' . $langs->trans('Country') . ': " + (Customer.country !== null ? Customer.country : ""));
1438 $container.find(".select2-result-repository__departement").append("' . $langs->trans('Region-State') . ': " + (Customer.departement !== null ? Customer.departement : ""));
1439 $container.find(".select2-result-repository__zip").append("' . $langs->trans('Zip') . ': " + (Customer.zip !== null ? Customer.zip : ""));
1440 $container.find(".select2-result-repository__town").append("' . $langs->trans('Town') . ': " + (Customer.town !== null ? Customer.town : ""));
1441 $container.find(".select2-result-repository__siren").append("' . $langs->trans('Siren') . ': " + (Customer.siren !== null ? Customer.siren : ""));
1442 $container.find(".select2-result-repository__datec").append("' . $langs->trans('Created') . ': " + (Customer.datec !== null ? Customer.datec : ""));
1443
1444 return $container;
1445 }
1446
1447 function formatCustomerSelection (selection) {
1448 return selection.label || selection.text;
1449 }
1450 });
1451 </script>
1452 ';
1453 */
1454 print '</td>';
1455 print '</tr>';
1456
1457 // If javascript on, we show option individual
1458 if ($conf->use_javascript_ajax) {
1459 if (getDolGlobalString('THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION')) {
1460 // Firstname
1461 print '<tr class="individualline"><td>'.$form->editfieldkey('FirstName', 'firstname', '', $object, 0).'</td>';
1462 print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="firstname" id="firstname" value="'.dolPrintHTMLForAttribute($object->firstname).'" spellcheck="false"></td>';
1463 print '</tr>';
1464
1465 // Title
1466 print '<tr class="individualline"><td>'.$form->editfieldkey('UserTitle', 'civility_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1467 print $formcompany->select_civility($object->civility_code, 'civility_id', 'maxwidth100').'</td>';
1468 print '</tr>';
1469 }
1470 }
1471
1472 // Alias names (commercial, trademark or alias names)
1473 print '<tr id="name_alias"><td>';
1474 print '<input type="hidden" name="status" value="1">';
1475 print '</td>';
1476 print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.dolPrintHTMLForAttribute($object->name_alias).'" spellcheck="false" placeholder="'.dolPrintHTMLForAttribute($langs->trans('AliasNames')).'"></td></tr>';
1477
1478 // Prospect/Customer/Supplier
1479 $selected = $object->client;
1480 $selectedcustomer = ((getDolGlobalInt('THIRDPARTY_CUSTOMERTYPE_BY_DEFAULT')==1 && GETPOST("type", 'aZ') != 'p' && GETPOST("type", 'aZ') != 'f') || (getDolGlobalInt('THIRDPARTY_CUSTOMERTYPE_BY_DEFAULT')==3 && GETPOST("type", 'aZ') != 'p' && GETPOST("type", 'aZ') != 'f') ? 1 : 0);
1481 $selectedprospect = ((getDolGlobalInt('THIRDPARTY_CUSTOMERTYPE_BY_DEFAULT')==2 && GETPOST("type", 'aZ') != 'c' && GETPOST("type", 'aZ') != 'f') || (getDolGlobalInt('THIRDPARTY_CUSTOMERTYPE_BY_DEFAULT')==3 && GETPOST("type", 'aZ') != 'c' && GETPOST("type", 'aZ') != 'f') ? 1 : 0);
1482 switch ($selected) {
1483 case 1:
1484 $selectedcustomer = 1;
1485 break;
1486 case 2:
1487 $selectedprospect = 1;
1488 break;
1489 case 3:
1490 $selectedprospect = 1;
1491 $selectedcustomer = 1;
1492 break;
1493 default:
1494 break;
1495 }
1496
1497 $selectedprospect = ((GETPOSTISSET('prospect') && $action == 'create') ? GETPOSTINT('prospect') : $selectedprospect);
1498 $selectedcustomer = ((GETPOSTISSET('customer') && $action == 'create') ? GETPOSTINT('customer') : $selectedcustomer);
1499 $selectedsupplier = ((GETPOSTISSET('supplier') && $action == 'create') ? GETPOSTINT('supplier') : $object->fournisseur);
1500
1501 if ($selectedprospect && $selectedcustomer && getDolGlobalString("SOCIETE_DISABLE_PROSPECTSCUSTOMERS")) {
1502 // If both are not allowed, we reset $selectedcustomer
1503 $selectedcustomer = 0;
1504 }
1505
1506 print '<tr class="marginbottomlarge height50">';
1507 if ($conf->browser->layout != 'phone') {
1508 print '<td class="titlefieldcreate">'.$form->editfieldkey('', 'customerprospect', '', $object, 0, 'string', '', 0).'</td>';
1509 }
1510 print '<td class="maxwidthonsmartphone"'.($conf->browser->layout != 'phone' ? 'colspan="3"' : 'colspan="2"').'>';
1511
1512 if (!getDolGlobalString('SOCIETE_DISABLE_PROSPECTS')) {
1513 print '<span id="spannature1" class="spannature prospect-back paddinglarge marginrightonly"><label for="prospectinput" class="spanlabel">'.$langs->trans("Prospect").'</label><input id="prospectinput" class="flat checkforselect marginleftonly valignmiddle" type="checkbox" name="prospect" value="2"'.($selectedprospect ? ' checked="checked"' : '').'></span>';
1514 }
1515
1516 if (!getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS')) {
1517 print '<span id="spannature2" class="spannature customer-back paddinglarge marginrightonly"><label for="customerinput" class="spanlabel">'.$langs->trans("Customer").'</label><input id="customerinput" class="flat checkforselect marginleftonly valignmiddle" type="checkbox" name="customer" value="1"'.($selectedcustomer ? ' checked="checked"' : '').'></span>';
1518 }
1519
1520 if ((isModEnabled("fournisseur") && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))
1521 || (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire'))) {
1522 // Supplier
1523 print '<span id="spannature3" class="spannature vendor-back paddinglarge marginrightonly"><label for="supplierinput" class="spanlabel">'.$langs->trans("Vendor").'</label><input id="supplierinput" class="flat checkforselect marginleftonly valignmiddle" type="checkbox" name="supplier" value="1"'.($selectedsupplier ? ' checked="checked"' : '').'></span>';
1524 }
1525 // Add js to manage the background of nature
1526 if ($conf->use_javascript_ajax) {
1527 print '<script>
1528 function refreshNatureCss() {
1529 jQuery(".spannature").each(function( index ) {
1530 id = $(this).attr("id").split("spannature")[1];
1531 console.log(jQuery("#spannature"+(id)+" .checkforselect").is(":checked"));
1532 if (jQuery("#spannature"+(id)+" .checkforselect").is(":checked")) {
1533 if (id == 1) {
1534 jQuery("#spannature"+(id)).addClass("prospect-back").removeClass("nonature-back");
1535 }
1536 if (id == 2) {
1537 jQuery("#spannature"+(id)).addClass("customer-back").removeClass("nonature-back");
1538 }
1539 if (id == 3) {
1540 jQuery("#spannature"+(id)).addClass("vendor-back").removeClass("nonature-back");
1541 }
1542 } else {
1543 jQuery("#spannature"+(id)).removeClass("prospect-back").removeClass("customer-back").removeClass("vendor-back").addClass("nonature-back");
1544 }
1545 });
1546 }
1547
1548 function manageprospectcustomer(element) {
1549 console.log("We uncheck unwanted values on a nature");
1550 id = $(element).attr("id").split("spannature")[1];
1551 if ( id == 1){
1552 $("#spannature2 .checkforselect").prop("checked", false);
1553 }
1554 if ( id == 2){
1555 $("#spannature1 .checkforselect").prop("checked", false);
1556 }
1557 }
1558
1559 jQuery(".spannature").click(function(){
1560 console.log("We click on a nature");
1561 '.(getDolGlobalString('SOCIETE_DISABLE_PROSPECTSCUSTOMERS') ? 'manageprospectcustomer($(this));' : '').'
1562 refreshNatureCss();
1563 });
1564 refreshNatureCss();
1565 </script>';
1566 }
1567 print '</td>';
1568 print '</tr>';
1569
1570 // Customer code
1571 print '<tr>';
1572 print '<td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
1573 print '<table class="nobordernopadding"><tr><td>';
1574 $tmpcode = $object->code_client ?? '';
1575 if (empty($tmpcode) && !empty($modCodeClient->code_auto)) {
1576 $tmpcode = $modCodeClient->getNextValue($object, 0);
1577 }
1578 print '<input type="text" name="customer_code" id="customer_code" class="maxwidthonsmartphone" value="'.dolPrintHTMLForAttribute($tmpcode).'" maxlength="24" spellcheck="false">';
1579 print '</td><td>';
1580 $s = $modCodeClient->getToolTip($langs, $object, 0);
1581 print $form->textwithpicto('', $s, 1);
1582 print '</td></tr></table>';
1583 print '</td>';
1584
1585 if ((isModEnabled("fournisseur") && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))
1586 || (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire'))) {
1587 if ($conf->browser->layout == 'phone') {
1588 print '<td colspan="2"></td>';
1589 print '</tr><tr>';
1590 }
1591 print '<td>'.$form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0).'</td><td>';
1592 print '<table class="nobordernopadding"><tr><td>';
1593 $tmpcode = $object->code_fournisseur ?? '';
1594 if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) {
1595 $tmpcode = $modCodeFournisseur->getNextValue($object, 1);
1596 }
1597 print '<input type="text" name="supplier_code" id="supplier_code" class="maxwidthonsmartphone" value="'.dolPrintHTMLForAttribute($tmpcode).'" maxlength="24">';
1598 print '</td><td>';
1599 $s = $modCodeFournisseur->getToolTip($langs, $object, 1);
1600 print $form->textwithpicto('', $s, 1);
1601 print '</td></tr></table>';
1602 print '</td>';
1603 } else {
1604 print '<td colspan="2"></td>';
1605 }
1606 print '</tr>';
1607
1608 // Status
1609 /* Useless at creation
1610 print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0).'</td><td colspan="3">';
1611 print $form->selectarray('status', array('1' => $langs->trans('InActivity'), '0' => $langs->trans('ActivityCeased')), 1, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
1612 print '</td></tr>';
1613 */
1614
1615 // Default bank account
1616 if (isModEnabled('bank') && getDolGlobalString('THIRDPARTY_SUGGEST_ALSO_BANK_ACCOUNT')) {
1617 print '<tr><td>';
1618 print $langs->trans('DefaultBankAccount');
1619 print '</td>';
1620 print '<td>';
1621 $form->select_comptes(GETPOST('fk_account'), 'fk_account', 0, '', 1);
1622 print "</td>";
1623 print '</tr>';
1624 }
1625
1626 // Barcode
1627 if (isModEnabled('barcode') && getDolGlobalString('BARCODE_USE_ON_THIRDPARTY')) {
1628 print '<tr><td>'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).'</td>';
1629 print '<td colspan="3">';
1630 print img_picto('', 'barcode', 'class="pictofixedwidth"');
1631 print '<input type="text" class="minwidth200 maxwidth300 widthcentpercentminusx" name="barcode" id="barcode" value="'.dolPrintHTMLForAttribute($object->barcode).'">';
1632 print '</td></tr>';
1633 }
1634
1635 print '<tr class="tdsmallheight"><td colspan="4"></td></tr>';
1636
1637 // Address
1638 print '<tr><td class="tdtop">';
1639 print $form->editfieldkey('Address', 'address', '', $object, 0);
1640 print '</td>';
1641 print '<td colspan="3">';
1642 print '<textarea name="address" id="address" class="quatrevingtpercent" rows="'.ROWS_2.'" wrap="soft">';
1643 print dolPrintHTMLForTextArea($object->address);
1644 print '</textarea>';
1645 print $form->widgetForTranslation("address", $object, $permissiontoadd, 'textarea', 'alphanohtml', 'quatrevingtpercent');
1646 print '</td></tr>';
1647
1648 // Zip / Town
1649 print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td>';
1650 print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100');
1651 print '</td>';
1652 if ($conf->browser->layout == 'phone') {
1653 print '</tr><tr>';
1654 }
1655 print '<td class="tdtop">'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td>';
1656 print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth150 quatrevingtpercent');
1657 print $form->widgetForTranslation("town", $object, $permissiontoadd, 'string', 'alphanohtml', 'maxwidth100 quatrevingtpercent');
1658 print '</td></tr>';
1659
1660 // Country
1661 print '<tr><td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1662 print img_picto('', 'country', 'class="pictofixedwidth"');
1663 print $form->select_country((GETPOSTISSET('country_id') ? GETPOST('country_id') : $object->country_id), 'country_id', '', 0, 'minwidth200 maxwidth300 widthcentpercentminusx');
1664 if ($user->admin) {
1665 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1666 }
1667 print '</td></tr>';
1668
1669 // State
1670 if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
1671 if ((getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 || getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 2)) {
1672 print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1673 } else {
1674 print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1675 }
1676
1677 if ($object->country_id) {
1678 print img_picto('', 'state', 'class="pictofixedwidth"');
1679 print $formcompany->select_state($object->state_id, $object->country_code, 'state_id', 'minwidth200 maxwidth300 widthcentpercentminusx');
1680 } else {
1681 print $countrynotdefined;
1682 }
1683 print '</td></tr>';
1684 }
1685
1686 // Phone / Fax
1687 print '<tr><td>'.$form->editfieldkey('Phone', 'phone', '', $object, 0).'</td>';
1688 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).'" spellcheck="false"></td>';
1689
1690 if ($conf->browser->layout == 'phone') {
1691 print '</tr><tr>';
1692 }
1693
1694 // Phone mobile
1695 print '<td>'.$form->editfieldkey('PhoneMobile', 'phone_mobile', '', $object, 0).'</td>';
1696 print '<td'.($conf->browser->layout == 'phone' ? ' colspan="3"' : '').'>'.img_picto('', 'object_phoning_mobile', 'class="pictofixedwidth"').'<input type="text" name="phone_mobile" id="phone_mobile" class="maxwidth200 widthcentpercentminusx" value="'.(GETPOSTISSET('phone_mobile') ? GETPOST('phone_mobile', 'alpha') : $object->phone_mobile).'" spellcheck="false"></td></tr>';
1697
1698 // Fax
1699 print '<tr>';
1700 print '<td>'.$form->editfieldkey('Fax', 'fax', '', $object, 0).'</td>';
1701 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).'" spellcheck="false"></td></tr>';
1702
1703 // URL
1704 print '<tr><td>'.$form->editfieldkey('Web', 'url', '', $object, 0).'</td>';
1705 print '<td colspan="3">'.img_picto('', 'globe', 'class="pictofixedwidth"').'<input type="text" class="maxwidth500 widthcentpercentminusx" name="url" id="url" value="'.$object->url.'" spellcheck="false"></td></tr>';
1706
1707 // Email
1708 print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', getDolGlobalInt('SOCIETE_EMAIL_MANDATORY')).'</td>';
1709 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.'" spellcheck="false"></td>';
1710
1711 // Unsubscribe
1712 if (isModEnabled('mailing')) {
1713 if ($conf->browser->layout == 'phone') {
1714 print '</tr><tr>';
1715 }
1716 if ($conf->use_javascript_ajax && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2) {
1717 print "\n".'<script type="text/javascript">'."\n";
1718 print '$(document).ready(function () {
1719 $("#email").keyup(function() {
1720 console.log("We change email content");
1721 if ($(this).val()!="") {
1722 $(".noemail").addClass("fieldrequired");
1723 } else {
1724 $(".noemail").removeClass("fieldrequired");
1725 }
1726 });
1727 })'."\n";
1728 print '</script>'."\n";
1729 }
1730 if (!GETPOSTISSET("no_email") && !empty($object->email)) {
1731 $result = $object->getNoEmail();
1732 if ($result < 0) {
1733 setEventMessages($object->error, $object->errors, 'errors');
1734 }
1735 }
1736 print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
1737 print '<td>';
1738 print $form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOSTINT("no_email") : getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS')), 1, false, (getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2 ? 1 : 0), 1);
1739 print '</td>';
1740 }
1741 print '</tr>';
1742
1743 // Refuse emailing of all contacts
1744 if (isModEnabled('mailing') && getDolGlobalString('THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION')) {
1745 print '<tr>';
1746 if ($conf->browser->layout != 'phone') {
1747 print '<td></td>';
1748 print '<td></td>';
1749 }
1750 print '<td class="individualline noemail">'.$form->editfieldkey($langs->trans('No_Email') .' ('.$langs->trans('Contact').')', 'contact_no_email', '', $object, 0).'</td>';
1751 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>';
1752 print '</tr>';
1753 }
1754
1755 $colspan = ($conf->browser->layout == 'phone' ? 2 : 4);
1756
1757 // Social networks
1758 if (isModEnabled('socialnetworks')) {
1759 $object->showSocialNetwork($socialnetworks, $colspan);
1760
1761 print '<tr><td colspan="'.$colspan.'"><hr></td></tr>';
1762 }
1763
1764 // Prof ids
1765 $i = 1;
1766 $j = 0;
1767 $NBCOLS = ($conf->browser->layout == 'phone' ? 1 : 2);
1768 $NBPROFIDMIN = getDolGlobalInt('THIRDPARTY_MIN_NB_PROF_ID', 2);
1769 $NBPROFIDMAX = getDolGlobalInt('THIRDPARTY_MAX_NB_PROF_ID', 6);
1770 while ($i <= $NBPROFIDMAX) {
1771 $idprof = $langs->transcountry('ProfId'.$i, (string) $object->country_code);
1772 if ($idprof != '-' && ($i <= $NBPROFIDMIN || !empty($langs->tab_translate['ProfId'.$i.$object->country_code]))) {
1773 $key = 'idprof'.$i;
1774
1775 if (($j % $NBCOLS) == 0) {
1776 print '<tr class="professionalline">';
1777 }
1778
1779 $idprof_mandatory = 'SOCIETE_IDPROF'.($i).'_MANDATORY';
1780 print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', (getDolGlobalString($idprof_mandatory) ? 1 : 0)).'</td><td>';
1781
1782 print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
1783 print '</td>';
1784 if (($j % $NBCOLS) == ($NBCOLS - 1)) {
1785 print '</tr>';
1786 }
1787 $j++;
1788 }
1789 $i++;
1790 }
1791 if ($NBCOLS > 1 && ($j % 2 == 1)) {
1792 print '<td colspan="2"></td></tr>';
1793 }
1794
1795 // Vat is used
1796 print '<tr><td><label for="assujtva_value">'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).'</label></td>';
1797 print '<td>';
1798 print '<input id="assujtva_value" name="assujtva_value" type="checkbox" ' . (GETPOSTISSET('assujtva_value') ? (GETPOST('assujtva_value', 'alpha') != '' ? ' checked="checked"' : '') : 'checked="checked"') . ' value="1">'; // Assujeti par default en creation
1799 print '</td>';
1800 if ($conf->browser->layout == 'phone') {
1801 print '</tr><tr>';
1802 }
1803 print '<td class="nowrap">'.$form->editfieldkey('VATIntra', 'intra_vat', '', $object, 0).'</td>';
1804 print '<td class="nowrap">';
1805 $s = '<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
1806
1807 if (!getDolGlobalString('MAIN_DISABLEVATCHECK') && isInEEC($object)) {
1808 $s .= ' ';
1809
1810 if (!empty($conf->use_javascript_ajax)) {
1811 $widthpopup = 600;
1812 if (!empty($conf->dol_use_jmobile)) {
1813 $widthpopup = 350;
1814 }
1815 $heightpopup = 400;
1816 print "\n";
1817 print '<script type="text/javascript">';
1818 print "function CheckVAT(a) {\n";
1819 if ($mysoc->country_code == 'GR' && $object->country_code == 'GR' && !empty($u)) {
1820 print "GRVAT(a,'{$u}','{$p}','{$myafm}');\n";
1821 } else {
1822 print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a, '".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
1823 }
1824 print "}\n";
1825 print '</script>';
1826 print "\n";
1827 $s .= '<a href="#" class="hideonsmartphone" onclick="CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
1828 $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1);
1829 } else {
1830 $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", (string) $object->country_id).'" target="_blank" rel="noopener noreferrer">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
1831 }
1832 }
1833 print $s;
1834 print '</td>';
1835 print '</tr>';
1836
1837 // VAT reverse charge by default
1838 if (getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) {
1839 print '<tr><td><label for="vat_reverse_charge">' . $form->editfieldkey('VATReverseChargeByDefault', 'vat_reverse_charge', '', $object, 0) . '</label></td><td colspan="3">';
1840 print '<input type="checkbox" name="vat_reverse_charge" id="vat_reverse_charge" '.($object->vat_reverse_charge == '1' ? ' checked' : '').'>';
1841 print '</td></tr>';
1842 }
1843
1844 print '<td class="nowrap">'.$form->editfieldkey('EUIDShort', 'euid', '', $object, 0).'</td>';
1845 print '<td class="nowrap">';
1846 print '<input type="text" class="flat maxwidthonsmartphone" name="euid" id="euid" maxlength="20" value="'.$object->euid.'">';
1847 print '</td>';
1848 print '</tr>';
1849
1850 // Local Taxes
1851 // TODO: Place into a function to control showing by country or study better option
1852 if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
1853 print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
1854 print '<input id="localtax1assuj_value" name="localtax1assuj_value" type="checkbox" ' . (getDolGlobalString('THIRDPARTY_DEFAULT_USELOCALTAX1') ? 'checked="checked"' : '') . ' value="1">';
1855 print '</td>';
1856 if ($conf->browser->layout == 'phone') {
1857 print '</tr><tr>';
1858 }
1859 print '<td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
1860 print '<input id="localtax2assuj_value" name="localtax2assuj_value" type="checkbox" ' . (getDolGlobalString('THIRDPARTY_DEFAULT_USELOCALTAX2') ? 'checked="checked"' : '') . ' value="1">';
1861 print '</td></tr>';
1862 } elseif ($mysoc->localtax1_assuj == "1") {
1863 print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td colspan="3">';
1864 print '<input id="localtax1assuj_value" name="localtax1assuj_value" type="checkbox" ' . (getDolGlobalString('THIRDPARTY_DEFAULT_USELOCALTAX1') ? 'checked="checked"' : '') . ' value="1">';
1865 print '</td></tr>';
1866 } elseif ($mysoc->localtax2_assuj == "1") {
1867 print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td colspan="3">';
1868 print '<input id="localtax2assuj_value" name="localtax2assuj_value" type="checkbox" ' . (getDolGlobalString('THIRDPARTY_DEFAULT_USELOCALTAX2') ? 'checked="checked"' : '') . ' value="1">';
1869 print '</td></tr>';
1870 }
1871
1872
1873 print '<tr><td colspan="'.$colspan.'"><hr></td></tr>';
1874
1875 // Categories
1876 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1877 $langs->load('categories');
1878
1879 // Customer
1880 print '<tr class="visibleifcustomer"><td class="toptd">'.$form->editfieldkey('CustomersProspectsCategoriesShort', 'custcats', '', $object, 0).'</td><td colspan="3">';
1881 print $form->selectCategories(Categorie::TYPE_CUSTOMER, 'custcats', $object);
1882 print "</td></tr>";
1883
1884 if (getDolGlobalString('THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION')) {
1885 print '<tr class="individualline"><td class="toptd">'.$form->editfieldkey('ContactCategoriesShort', 'contcats', '', $object, 0).'</td><td colspan="3">';
1886 print $form->selectCategories(Categorie::TYPE_CONTACT, 'contcats', $object);
1887 print "</td></tr>";
1888 }
1889
1890 // Supplier
1891 if (isModEnabled("supplier_proposal") || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
1892 print '<tr class="visibleifsupplier"><td class="toptd">'.$form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0).'</td><td colspan="3">';
1893 print $form->selectCategories(Categorie::TYPE_SUPPLIER, 'suppcats', $object);
1894 print "</td></tr>";
1895 }
1896 }
1897
1898 print '<tr><td colspan="'.$colspan.'"><a class="paddingtop paddingbottom morefieldslnk onreposition" id="morefieldslnk" href="#">'.$langs->trans("More").'';
1899 $nbactive = '...';
1900 print '<span class="badge badge-secondary socialnetworklnk marginleftonly">'.$nbactive.'</span></a>';
1901 print '</td>';
1902 print '</tr>';
1903
1904 // Type - Workforce/Staff
1905 print '<tr class="morefields"><td>'.$form->editfieldkey('ThirdPartyType', 'typent_id', '', $object, 0).'</td><td class="maxwidthonsmartphone"'.(($conf->browser->layout == 'phone' || getDolGlobalString('SOCIETE_DISABLE_WORKFORCE')) ? ' colspan="3"' : '').'>'."\n";
1906 $sortparam = getDolGlobalString('SOCIETE_SORT_ON_TYPEENT', 'ASC'); // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on label.
1907 print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 1, 0, 0, '', 0, 0, 0, $sortparam, '', 1);
1908 if ($user->admin) {
1909 print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1910 }
1911 if (!getDolGlobalString('SOCIETE_DISABLE_WORKFORCE')) {
1912 print '</td>';
1913 if ($conf->browser->layout == 'phone') {
1914 print '</tr><tr class="morefields">';
1915 }
1916 print '<td>'.$form->editfieldkey('Workforce', 'effectif_id', '', $object, 0).'</td><td class="maxwidthonsmartphone"'.($conf->browser->layout == 'phone' ? ' colspan="3"' : '').'>';
1917 print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id, 0, 0, 0, '', 0, 0, 0, '', '', 1);
1918 if ($user->admin) {
1919 print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1920 }
1921 } else {
1922 print '<input type="hidden" name="effectif_id" id="effectif_id" value="'.$object->effectif_id.'">';
1923 }
1924 print '</td></tr>';
1925
1926 // Legal Form
1927 print '<tr class="morefields"><td>'.$form->editfieldkey('JuridicalStatus', 'forme_juridique_code', '', $object, 0).'</td>';
1928 print '<td colspan="3" class="maxwidthonsmartphone">';
1929 if ($object->country_id) {
1930 print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code');
1931 } else {
1932 print $countrynotdefined;
1933 }
1934 print '</td></tr>';
1935
1936 // Date birth
1937 print '<tr class="morefields"><td>'.$form->editfieldkey('CompanyBirthDate', 'birth', '', $object, 0).'</td>';
1938 print '<td colspan="3" class="maxwidthonsmartphone">';
1939 print $form->selectDate($object->birth, 'birth', 0, 0, 1, "", 1);
1940 print '</td></tr>';
1941
1942 // Capital
1943 print '<tr class="morefields"><td>'.$form->editfieldkey('Capital', 'capital', '', $object, 0).'</td>';
1944 print '<td colspan="3"><input type="text" name="capital" id="capital" class="maxwidth100" value="'.((string) $object->capital).'"> ';
1945 if (isModEnabled("multicurrency")) {
1946 print '<span class="hideonsmartphone">';
1947 //print $langs->trans("Currency".$object->multicurrency_code);
1948 print $langs->getCurrencySymbol($object->multicurrency_code);
1949 print '</span></td></tr>';
1950 } else {
1951 print '<span class="hideonsmartphone">';
1952 print $langs->getCurrencySymbol($conf->currency);
1953 //print $langs->trans("Currency".$conf->currency);
1954 print '</span></td></tr>';
1955 }
1956 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1957 print '<tr class="morefields"><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
1958 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, array(), 1, 0, 0, 'maxwidth200onsmartphone');
1959 print '</td>';
1960 print '</tr>';
1961 }
1962
1963 // Payment terms of the settlement
1964 print '<tr class="morefields">';
1965 print '<td>'.$form->editfieldkey('PaymentConditions', 'cond_reglement_id', '', $object, 0).'</td>';
1966 print '<td colspan="3" class="maxwidthonsmartphone">';
1967 print $form->getSelectConditionsPaiements((int) $object->cond_reglement_id, 'cond_reglement_id', 1, 1, 1, '', (float) $object->deposit_percent);
1968 print '</td></tr>';
1969
1970 // Payment mode
1971 print '<tr class="morefields">';
1972 print '<td>'.$form->editfieldkey('PaymentMode', 'mode_reglement_id', '', $object, 0).'</td>';
1973 print '<td colspan="3" class="maxwidthonsmartphone">';
1974 print $form->select_types_paiements((string) $object->mode_reglement_id, 'mode_reglement_id', '', 0, 1, 1, 0, 1);
1975 print '</td></tr>';
1976
1977 // Incoterms
1978 if (isModEnabled('incoterm')) {
1979 print '<tr class="morefields">';
1980 print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
1981 print '<td colspan="3" class="maxwidthonsmartphone">';
1982 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
1983 print '</td></tr>';
1984 }
1985
1986 // Multicurrency
1987 if (isModEnabled("multicurrency")) {
1988 print '<tr class="morefields">';
1989 print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
1990 print '<td colspan="3" class="maxwidthonsmartphone">';
1991 print img_picto('', 'currency', 'class="pictofixedwidth"');
1992 print $form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code') : ($object->multicurrency_code ? $object->multicurrency_code : $conf->currency)), 'multicurrency_code', 1, '', false, 'maxwidth150 widthcentpercentminusx');
1993 print '</td></tr>';
1994 }
1995
1996 // Other attributes
1997 $parameters = array('socid' => $socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
1998 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
1999
2000 // Parent company
2001 if (!getDolGlobalString('SOCIETE_DISABLE_PARENTCOMPANY')) {
2002 print '<tr class="morefields">';
2003 print '<td>'.$langs->trans('ParentCompany').'</td>';
2004 print '<td colspan="3" class="maxwidthonsmartphone">';
2005 print img_picto('', 'company', 'class="paddingrightonly"');
2006 print $form->select_company(GETPOST('parent_company_id'), 'parent_company_id', '', 'SelectThirdParty', 0, 0, array(), 0, 'minwidth300 maxwidth500 widthcentpercentminusxx');
2007 print '</td></tr>';
2008 }
2009
2010 // Assign a sale representative
2011 print '<tr class="morefields">';
2012 print '<td>'.$form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0).'</td>';
2013 print '<td colspan="3" class="maxwidthonsmartphone">';
2014 // TODO Use select_doluser in multiselect mode
2015 $userlist = $form->select_dolusers($selected, '', 0, null, 0, '', '', '0', 0, 0, 'u.statut:=:1', 0, '', '', 0, 2);
2016 // 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.
2017 $selected = (GETPOSTISARRAY('commercial') ? GETPOST('commercial', 'array:int') : (GETPOSTINT('commercial') > 0 ? array(GETPOSTINT('commercial')) : array($user->id)));
2018 print img_picto('', 'user').$form->multiselectarray('commercial', $userlist, $selected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
2019 print '</td></tr>';
2020
2021 // Add logo
2022 print '<tr class="hideonsmartphone morefields"">';
2023 print '<td>'.$form->editfieldkey('Logo', 'photoinput', '', $object, 0).'</td>';
2024 print '<td colspan="3">';
2025 print '<input class="flat" type="file" name="photo" id="photoinput" />';
2026 print '</td>';
2027 print '</tr>';
2028
2029 print '</table>'."\n";
2030
2031 print '<script nonce="'.getNonce().'" type="text/javascript">
2032 $("document").ready(function() { toogleMoreFields(false); });
2033
2034 jQuery(".morefieldslnk").click(function() {
2035 console.log("Click on link .morefieldslnk (create)");
2036 toogleMoreFields(true);
2037 return false;
2038 });
2039
2040 function toogleMoreFields(chgCookieState) {
2041 const lnk = $("#morefieldslnk");
2042 const items = $(".morefields, .trextrafields:not(.trextrafieldsgroup)");
2043 var cookieState = document.cookie.split(";").some((item) => item.trim().startsWith("DOLUSER_MOREFIELDS_SHOW=true")) == true;
2044
2045 if (!chgCookieState) cookieState = !cookieState ;
2046
2047 if (cookieState) {
2048 items.hide();
2049 if (chgCookieState) { document.cookie = "DOLUSER_MOREFIELDS_SHOW=false; SameSite=Strict"};
2050 } else {
2051 items.show();
2052 if (chgCookieState) { document.cookie = "DOLUSER_MOREFIELDS_SHOW=true; SameSite=Strict";}
2053 }
2054 }
2055 </script>
2056 ';
2057
2058 // Accountancy codes
2059 if (getDolGlobalString('ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY')) {
2060 print '<table class="border centpercent">';
2061
2062 if (isModEnabled('accounting')) {
2064 // Accountancy_code_sell
2065 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
2066 print '<td>';
2067 $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
2068 print $formaccounting->select_account($accountancy_code_sell, 'accountancy_code_sell', 1, array(), 1, 1, '');
2069 print '</td></tr>';
2070
2071 // Accountancy_code_buy
2072 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyCode").'</td>';
2073 print '<td>';
2074 $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
2075 print $formaccounting->select_account($accountancy_code_buy, 'accountancy_code_buy', 1, array(), 1, 1, '');
2076 print '</td></tr>';
2077 } else { // For external software
2078 // Accountancy_code_sell
2079 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
2080 print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code_sell" value="'.$object->accountancy_code_sell.'">';
2081 print '</td></tr>';
2082
2083 // Accountancy_code_buy
2084 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyCode").'</td>';
2085 print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code_buy" value="'.$object->accountancy_code_buy.'">';
2086 print '</td></tr>';
2087 }
2088
2089 print '</table>';
2090 }
2091 }
2092
2093 print dol_get_fiche_end();
2094
2095 print $form->buttonsSaveCancel('AddThirdParty', 'Cancel', array(), 0, '', $dol_openinpopup);
2096
2097 print '</form>'."\n";
2098 } elseif ($action == 'edit') {
2099 //print load_fiche_titre($langs->trans("EditCompany"));
2100
2101 if ($socid) {
2102 $res = $object->fetch_optionals();
2103 //if ($res < 0) { dol_print_error($db); exit; }
2104
2105 $head = societe_prepare_head($object);
2106
2107 // Load object modCodeTiers
2108 $module = getDolGlobalString('SOCIETE_CODECLIENT_ADDON', 'mod_codeclient_leopard');
2109 if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
2110 $module = substr($module, 0, dol_strlen($module) - 4);
2111 }
2112 $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2113 foreach ($dirsociete as $dirroot) {
2114 $res = dol_include_once($dirroot.$module.'.php');
2115 if ($res) {
2116 break;
2117 }
2118 }
2119 $modCodeClient = new $module($db);
2120 '@phan-var-force ModeleThirdPartyCode $modCodeClient';
2121 // We check if the prefix tag is used
2122 if ($modCodeClient->code_auto) {
2123 $prefixCustomerIsUsed = $modCodeClient->verif_prefixIsUsed();
2124 } else {
2125 $prefixCustomerIsUsed = false;
2126 }
2127 $module = getDolGlobalString('SOCIETE_CODECLIENT_ADDON');
2128 if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
2129 $module = substr($module, 0, dol_strlen($module) - 4);
2130 }
2131 $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2132 foreach ($dirsociete as $dirroot) {
2133 $res = dol_include_once($dirroot.$module.'.php');
2134 if ($res) {
2135 break;
2136 }
2137 }
2138 $modCodeFournisseur = new $module($db);
2139 '@phan-var-force ModeleThirdPartyCode $modCodeFournisseur';
2140 // We check if the prefix tag is used
2141 if ($modCodeFournisseur->code_auto) {
2142 $prefixSupplierIsUsed = $modCodeFournisseur->verif_prefixIsUsed();
2143 } else {
2144 $prefixSupplierIsUsed = false;
2145 }
2146
2147 $object->oldcopy = clone $object; // @phan-suppress-current-line PhanTypeMismatchProperty
2148
2149 if (GETPOSTISSET('name')) {
2150 // We overwrite with values if posted
2151 $object->name = GETPOST('name', 'alphanohtml');
2152 $object->name_alias = GETPOST('name_alias', 'alphanohtml');
2153 $object->prefix_comm = GETPOST('prefix_comm', 'alphanohtml');
2154 $object->client = GETPOSTINT('client');
2155 $object->code_client = GETPOST('customer_code', 'alpha');
2156 $object->fournisseur = GETPOSTINT('fournisseur');
2157 $object->code_fournisseur = GETPOST('supplier_code', 'alpha');
2158 $object->address = GETPOST('address', 'alphanohtml');
2159 $object->zip = GETPOST('zipcode', 'alphanohtml');
2160 $object->town = GETPOST('town', 'alphanohtml');
2161 $object->country_id = GETPOST('country_id') ? GETPOSTINT('country_id') : $mysoc->country_id;
2162 $object->state_id = GETPOSTINT('state_id');
2163 $object->parent = GETPOSTINT('parent_company_id');
2164
2165 $object->socialnetworks = array();
2166 if (isModEnabled('socialnetworks')) {
2167 foreach ($socialnetworks as $key => $value) {
2168 if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
2169 $object->socialnetworks[$key] = GETPOST($key, 'alphanohtml');
2170 }
2171 }
2172 }
2173
2174 $object->phone = GETPOST('phone', 'alpha');
2175 $object->phone_mobile = (string) GETPOST('phone_mobile', 'alpha');
2176 $object->fax = GETPOST('fax', 'alpha');
2177 $object->email = GETPOST('email', 'email');
2178 $object->no_email = GETPOSTINT("no_email");
2179 $object->url = GETPOST('url', 'url');
2180 $object->capital = GETPOST('capital'); // Can be null or 0 or a float value
2181 $object->idprof1 = GETPOST('idprof1', 'alphanohtml');
2182 $object->idprof2 = GETPOST('idprof2', 'alphanohtml');
2183 $object->idprof3 = GETPOST('idprof3', 'alphanohtml');
2184 $object->idprof4 = GETPOST('idprof4', 'alphanohtml');
2185 $object->idprof5 = GETPOST('idprof5', 'alphanohtml');
2186 $object->idprof6 = GETPOST('idprof6', 'alphanohtml');
2187 $object->typent_id = GETPOSTINT('typent_id');
2188 $object->effectif_id = GETPOSTINT('effectif_id');
2189 $object->barcode = GETPOST('barcode', 'alphanohtml');
2190 $object->forme_juridique_code = GETPOSTINT('forme_juridique_code');
2191 $object->default_lang = GETPOST('default_lang', 'alpha');
2192
2193 $object->tva_assuj = GETPOSTINT('assujtva_value');
2194 $object->vat_reverse_charge = GETPOST('vat_reverse_charge') == 'on' ? 1 : 0;
2195 $object->euid = GETPOST('euid', 'alphanohtml');
2196 $object->tva_intra = GETPOST('tva_intra', 'alphanohtml');
2197 $object->status = GETPOSTINT('status');
2198
2199 // Webservices url/key
2200 $object->webservices_url = GETPOST('webservices_url', 'url');
2201 $object->webservices_key = GETPOST('webservices_key', 'password');
2202
2203 if (GETPOSTISSET('accountancy_code_sell')) {
2204 $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
2205
2206 if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') {
2207 $object->accountancy_code_sell = '';
2208 } else {
2209 $object->accountancy_code_sell = $accountancy_code_sell;
2210 }
2211 }
2212 if (GETPOSTISSET('accountancy_code_buy')) {
2213 $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
2214
2215 if (empty($accountancy_code_buy) || $accountancy_code_buy == '-1') {
2216 $object->accountancy_code_buy = '';
2217 } else {
2218 $object->accountancy_code_buy = $accountancy_code_buy;
2219 }
2220 }
2221
2222 //Incoterms
2223 if (isModEnabled('incoterm')) {
2224 $object->fk_incoterms = GETPOSTINT('incoterm_id');
2225 $object->location_incoterms = GETPOST('lcoation_incoterms', 'alpha');
2226 }
2227
2228 //Local Taxes
2229 $object->localtax1_assuj = GETPOSTINT('localtax1assuj_value');
2230 $object->localtax2_assuj = GETPOSTINT('localtax2assuj_value');
2231
2232 $object->localtax1_value = GETPOST('lt1');
2233 $object->localtax2_value = GETPOST('lt2');
2234
2235 // We set country_id, and country_code label of the chosen country
2236 if ($object->country_id > 0) {
2237 $tmparray = getCountry($object->country_id, 'all');
2238 $object->country_code = $tmparray['code'];
2239 $object->country = $tmparray['label'];
2240 }
2241
2242 // We set multicurrency_code if enabled
2243 if (isModEnabled("multicurrency")) {
2244 $object->multicurrency_code = GETPOST('multicurrency_code') ? GETPOST('multicurrency_code') : $object->multicurrency_code;
2245 }
2246 }
2247
2248 if ($object->localtax1_assuj == 0) {
2249 $sub = 0;
2250 } else {
2251 $sub = 1;
2252 }
2253 if ($object->localtax2_assuj == 0) {
2254 $sub2 = 0;
2255 } else {
2256 $sub2 = 1;
2257 }
2258
2259 if (!empty($conf->use_javascript_ajax)) {
2260 print "\n".'<script type="text/javascript">';
2261 print '$(document).ready(function () {
2262 var val='.$sub.';
2263 var val2='.$sub2.';
2264 if("#localtax1assuj_value".value==undefined){
2265 if(val==1){
2266 $(".cblt1").show();
2267 }else{
2268 $(".cblt1").hide();
2269 }
2270 }
2271 if("#localtax2assuj_value".value==undefined){
2272 if(val2==1){
2273 $(".cblt2").show();
2274 }else{
2275 $(".cblt2").hide();
2276 }
2277 }
2278 $("#localtax1assuj_value").change(function() {
2279 var value=document.getElementById("localtax1assuj_value").value;
2280 if(value==1){
2281 $(".cblt1").show();
2282 }else{
2283 $(".cblt1").hide();
2284 }
2285 });
2286 $("#localtax2assuj_value").change(function() {
2287 var value=document.getElementById("localtax2assuj_value").value;
2288 if(value==1){
2289 $(".cblt2").show();
2290 }else{
2291 $(".cblt2").hide();
2292 }
2293 });
2294
2295 var canHaveCustomerCategoryIfNotCustomerProspect = ' . (getDolGlobalInt('THIRDPARTY_CAN_HAVE_CUSTOMER_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT') ? '1' : '0') . ';
2296
2297 init_customer_categ();
2298 $("#prospectinput, #customerinput").change(function() {
2299 init_customer_categ();
2300 });
2301 function init_customer_categ() {
2302 var iscustomerorprospect = jQuery("#prospectinput").is(":checked") + jQuery("#customerinput").is(":checked");
2303 console.log("is customer or prospect = "+iscustomerorprospect);
2304 if (iscustomerorprospect == 0 && !canHaveCustomerCategoryIfNotCustomerProspect) {
2305 jQuery(".visibleifcustomer").hide();
2306 } else {
2307 jQuery(".visibleifcustomer").show();
2308 }
2309 }
2310
2311 init_supplier_categ();
2312 $("#supplierinput").change(function() {
2313 init_supplier_categ();
2314 });
2315 function init_supplier_categ() {
2316 var issupplier = jQuery("#supplierinput").is(":checked");
2317 console.log("is supplier = "+issupplier);
2318 if (issupplier == 0) {
2319 jQuery(".visibleifsupplier").hide();
2320 } else {
2321 jQuery(".visibleifsupplier").show();
2322 }
2323 }
2324
2325 $("#selectcountry_id").change(function() {
2326 console.log("selectcountry_id change");
2327 document.formsoc.action.value="edit";
2328 document.formsoc.submit();
2329 });
2330
2331 })';
2332 print '</script>'."\n";
2333 }
2334
2335 print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="post" name="formsoc">';
2336 print '<input type="hidden" name="action" value="update">';
2337 print '<input type="hidden" name="token" value="'.newToken().'">';
2338 print '<input type="hidden" name="socid" value="'.$object->id.'">';
2339 print '<input type="hidden" name="entity" value="'.$object->entity.'">';
2340 if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) {
2341 print '<input type="hidden" name="code_auto" value="1">';
2342 }
2343
2344
2345 print dol_get_fiche_head($head, 'card', $langs->trans("ThirdParty"), 0, 'company');
2346
2347 print '<div class="fichecenter2">';
2348
2349 // Call Hook tabContentEditThirdparty
2350 $parameters = array();
2351 // Note that $action and $object may be modified by hook
2352 $reshook = $hookmanager->executeHooks('tabContentEditThirdparty', $parameters, $object, $action);
2353 if (empty($reshook)) {
2354 print '<table class="border centpercent">';
2355
2356 // Ref/ID
2357 if (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
2358 print '<tr><td class="titlefieldcreate">'.$langs->trans("ID").'</td><td colspan="3">';
2359 print $object->id;
2360 print '</td></tr>';
2361 }
2362
2363 // Name
2364 print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0, 'string', '', 1).'</td>';
2365 print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.dolPrintHTMLForAttribute($object->name).'" autofocus="autofocus" spellcheck="false">';
2366 print $form->widgetForTranslation("name", $object, (int) $permissiontoadd, 'string', 'alphanohtml', 'minwidth300');
2367 print '</td></tr>';
2368
2369 // Alias names (commercial, trademark or alias names)
2370 print '<tr id="name_alias"><td>';
2371 //print '<label for="name_alias_input">'.$langs->trans('AliasNames').'</label>';
2372 print '</td>';
2373 print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.dolPrintHTMLForAttribute($object->name_alias).'" placeholder="'.dolPrintHTMLForAttribute($langs->trans('AliasNames')).'" spellcheck="false"></td></tr>';
2374
2375 // Prospect/Customer/Supplier
2376 $selected = $object->client;
2377 $selectedcustomer = 0;
2378 $selectedprospect = 0;
2379 switch ($selected) {
2380 case 1:
2381 $selectedcustomer = 1;
2382 break;
2383 case 2:
2384 $selectedprospect = 1;
2385 break;
2386 case 3:
2387 $selectedprospect = 1;
2388 $selectedcustomer = 1;
2389 break;
2390 default:
2391 break;
2392 }
2393
2394 // Nature of thirdparty
2395 $selectedprospect = (GETPOSTISSET('prospect') ? GETPOSTINT('prospect') : $selectedprospect);
2396 $selectedcustomer = (GETPOSTISSET('customer') ? GETPOSTINT('customer') : $selectedcustomer);
2397 print '<tr class="marginbottomlarge height50">';
2398 if ($conf->browser->layout != 'phone') {
2399 print '<td class="titlefieldcreate">'.$form->editfieldkey('', 'customerprospect', '', $object, 0, 'string', '', 0).'</td>';
2400 }
2401 print '<td class="maxwidthonsmartphone"'.($conf->browser->layout != 'phone' ? 'colspan="3"' : 'colspan="2"').'>';
2402
2403 if (!getDolGlobalString('SOCIETE_DISABLE_PROSPECTS')) {
2404 print '<span id="spannature1" class="spannature prospect-back paddinglarge marginrightonly"><label for="prospectinput" class="">'.$langs->trans("Prospect").'<input id="prospectinput" class="flat checkforselect marginleftonly valignmiddle" type="checkbox" name="prospect" value="2"'.($selectedprospect ? ' checked="checked"' : '').'></label></span>';
2405 }
2406
2407 if (!getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS')) {
2408 print '<span id="spannature2" class="spannature customer-back paddinglarge marginrightonly"><label for="customerinput" class="">'.$langs->trans("Customer").'<input id="customerinput" class="flat checkforselect marginleftonly valignmiddle" type="checkbox" name="customer" value="1"'.($selectedcustomer ? ' checked="checked"' : '').'></label></span>';
2409 }
2410 if ((isModEnabled("fournisseur") && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))
2411 || (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire'))) {
2412 // Supplier
2413 $selected = (GETPOSTISSET('supplier') ? GETPOSTINT('supplier') : $object->fournisseur);
2414 print '<span id="spannature3" class="spannature vendor-back paddinglarge marginrightonly"><label for="supplierinput" class="">'.$langs->trans("Vendor").'<input id="supplierinput" class="flat checkforselect marginleftonly valignmiddle" type="checkbox" name="supplier" value="1"'.($selected ? ' checked="checked"' : '').'></label></span>';
2415 }
2416
2417 // Add js to manage the background of nature
2418 if ($conf->use_javascript_ajax) {
2419 print '<script>
2420 function refreshNatureCss() {
2421 jQuery(".spannature").each(function( index ) {
2422 id = $(this).attr("id").split("spannature")[1];
2423 console.log("id="+id+" "+jQuery("#spannature"+(id)+" .checkforselect").is(":checked"));
2424 if (jQuery("#spannature"+(id)+" .checkforselect").is(":checked")) {
2425 if (id == 1) {
2426 jQuery("#spannature"+(id)).addClass("prospect-back").removeClass("nonature-back");
2427 }
2428 if (id == 2) {
2429 jQuery("#spannature"+(id)).addClass("customer-back").removeClass("nonature-back");
2430 }
2431 if (id == 3) {
2432 jQuery("#spannature"+(id)).addClass("vendor-back").removeClass("nonature-back");
2433 }
2434 } else {
2435 jQuery("#spannature"+(id)).removeClass("prospect-back").removeClass("customer-back").removeClass("vendor-back").addClass("nonature-back");
2436 }
2437 })
2438 }
2439
2440 function manageprospectcustomer(element) {
2441 console.log("We uncheck unwanted values on a nature");
2442 id = $(element).attr("id").split("spannature")[1];
2443 if ( id == 1){
2444 $("#spannature2 .checkforselect").prop("checked", false);
2445 }
2446 if ( id == 2){
2447 $("#spannature1 .checkforselect").prop("checked", false);
2448 }
2449 }
2450
2451 jQuery(".spannature").click(function(){
2452 console.log("We click on a nature");
2453 '.(getDolGlobalString('SOCIETE_DISABLE_PROSPECTSCUSTOMERS') ? 'manageprospectcustomer($(this));' : '').'
2454 refreshNatureCss();
2455 });
2456 refreshNatureCss();
2457 </script>';
2458 }
2459 print '</td>';
2460 print '</tr>';
2461
2462 $colspan = 0;
2463 if ($conf->browser->layout == 'phone') {
2464 $colspan = 3;
2465 }
2466
2467 print '<tr><td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td'.($colspan ? ' colspan="'.$colspan.'"': '').'>';
2468 print '<table class="nobordernopadding"><tr><td>';
2469 $tmpcode = $object->code_client ?? '';
2470 if (empty($tmpcode) && !empty($modCodeClient->code_auto)) {
2471 $tmpcode = $modCodeClient->getNextValue($object, 0);
2472 }
2473 print '<input type="text" name="customer_code" id="customer_code" class="maxwidthonsmartphone" value="'.dolPrintHTMLForAttribute($tmpcode).'" maxlength="24">';
2474 print '</td><td>';
2475 $s = $modCodeClient->getToolTip($langs, $object, 0);
2476 print $form->textwithpicto('', $s, 1);
2477 print '</td></tr></table>';
2478 print '</td>';
2479
2480 if ($conf->browser->layout == 'phone') {
2481 print '</tr><tr>';
2482 }
2483
2484 print '<td>'.$form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0).'</td><td'.($colspan ? ' colspan="'.$colspan.'"': '').'>';
2485
2486 if ((isModEnabled("fournisseur") && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))) {
2487 print '<table class="nobordernopadding"><tr><td>';
2488 $tmpcode = $object->code_fournisseur ?? '';
2489 if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) {
2490 $tmpcode = $modCodeFournisseur->getNextValue($object, 1);
2491 }
2492 print '<input type="text" name="supplier_code" id="supplier_code" class="maxwidthonsmartphone" value="'.dolPrintHTMLForAttribute($tmpcode).'" maxlength="24">';
2493 print '</td><td>';
2494 $s = $modCodeFournisseur->getToolTip($langs, $object, 1);
2495 print $form->textwithpicto('', $s, 1);
2496 print '</td></tr></table>';
2497 }
2498 print '</td></tr>';
2499
2500 if (isModEnabled('bank') && getDolGlobalString('THIRDPARTY_SUGGEST_ALSO_BANK_ACCOUNT')) {
2501 // TODO
2502 // Allow to edit field default bank account like we can in creation mode
2503 }
2504
2505 // Barcode
2506 if (isModEnabled('barcode') && getDolGlobalString('BARCODE_USE_ON_THIRDPARTY')) {
2507 print '<tr><td class="tdtop">'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).'</td>';
2508 print '<td colspan="3">';
2509 print img_picto('', 'barcode', 'class="pictofixedwidth"');
2510 print '<input type="text" class="minwidth100 maxwidth200 widthcentpercentminusx" name="barcode" id="barcode" value="'.dolPrintHTMLForAttribute($object->barcode).'" spellcheck="false">';
2511 print '</td></tr>';
2512 }
2513
2514 // Status
2515 print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0).'</td><td'.($conf->browser->layout == 'phone' ? '' : ' colspan="3"').'>';
2516 print $form->selectarray('status', array('0' => $langs->trans('ActivityCeased'), '1' => $langs->trans('InActivity')), $object->status, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
2517 print '</td></tr>';
2518
2519 //$colspan = ($conf->browser->layout == 'phone' ? 2 : 4);
2520 $colspan = 4;
2521 print '<tr class="tdsmallheight"><td colspan="'.$colspan.'"></td></tr>';
2522
2523 // Address
2524 print '<tr><td class="tdtop">'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
2525 print '<td colspan="3"><textarea name="address" id="address" class="quatrevingtpercent" rows="3" wrap="soft" spellcheck="false">';
2526 print dolPrintHTMLForTextArea($object->address);
2527 print '</textarea>';
2528 print $form->widgetForTranslation("address", $object, (int) $permissiontoadd, 'textarea', 'alphanohtml', 'quatrevingtpercent');
2529 print '</td></tr>';
2530
2531 // Zip / Town
2532 print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td'.($conf->browser->layout == 'phone' ? ' colspan="3"' : '').'>';
2533 print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100');
2534 print '</td>';
2535 if ($conf->browser->layout == 'phone') {
2536 print '</tr><tr>';
2537 }
2538 print '<td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td'.($conf->browser->layout == 'phone' ? ' colspan="3"' : '').'>';
2539 print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
2540 print $form->widgetForTranslation("town", $object, (int) $permissiontoadd, 'string', 'alphanohtml', 'maxwidth100 quatrevingtpercent');
2541 print '</td></tr>';
2542
2543 // Country
2544 print '<tr><td>'.$form->editfieldkey('Country', 'selectcounty_id', '', $object, 0).'</td><td colspan="3">';
2545 print img_picto('', 'globe-americas', 'class="pictofixedwidth"');
2546 print $form->select_country((GETPOSTISSET('country_id') ? GETPOST('country_id') : $object->country_id), 'country_id', '', 0, 'minwidth200 maxwidth400 widthcentpercentminusx');
2547 if ($user->admin) {
2548 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
2549 }
2550 print '</td></tr>';
2551
2552 // State
2553 if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
2554 if ((getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 || getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 2)) {
2555 print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td colspan="3">';
2556 } else {
2557 print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td colspan="3">';
2558 }
2559
2560 print img_picto('', 'state', 'class="pictofixedwidth"');
2561 print $formcompany->select_state($object->state_id, $object->country_code, 'state_id', 'minwidth200 maxwidth400 widthcentpercentminusx');
2562 print '</td></tr>';
2563 }
2564
2565 // Phone / Fax
2566 print '<tr><td>'.$form->editfieldkey('Phone', 'phone', GETPOST('phone', 'alpha'), $object, 0).'</td>';
2567 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).'" spellcheck="false"></td>';
2568 if ($conf->browser->layout == 'phone') {
2569 print '</tr><tr>';
2570 }
2571 print '<td>'.$form->editfieldkey('PhoneMobile', 'phone_mobile', GETPOST('phone_mobile', 'alpha'), $object, 0).'</td>';
2572 print '<td'.($conf->browser->layout == 'phone' ? ' colspan="3"' : '').'>'.img_picto('', 'object_phoning_mobile', 'class="pictofixedwidth"').'<input type="text" name="phone_mobile" id="phone_mobile" class="maxwidth200 widthcentpercentminusx" value="'.(GETPOSTISSET('phone_mobile') ? GETPOST('phone_mobile', 'alpha') : $object->phone_mobile).'" spellcheck="false"></td></tr>';
2573
2574 print '<td>'.$form->editfieldkey('Fax', 'fax', GETPOST('fax', 'alpha'), $object, 0).'</td>';
2575 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).'" spellcheck="false"></td>';
2576 print '</tr>';
2577
2578 // Web
2579 print '<tr><td>'.$form->editfieldkey('Web', 'url', GETPOST('url', 'alpha'), $object, 0).'</td>';
2580 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).'" spellcheck="false"></td></tr>';
2581
2582 // EMail
2583 print '<tr><td>'.$form->editfieldkey('EMail', 'email', GETPOST('email', 'alpha'), $object, 0, 'string', '', (getDolGlobalInt('SOCIETE_EMAIL_MANDATORY'))).'</td>';
2584 print '<td'.(($conf->browser->layout == 'phone') || !isModEnabled('mailing') ? ' colspan="3"' : '').'>';
2585 print img_picto('', 'object_email', 'class="pictofixedwidth"');
2586 print '<input type="text" name="email" id="email" class="maxwidth500 widthcentpercentminusx" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alpha') : $object->email).'" spellcheck="false">';
2587 print '</td>';
2588
2589 // Unsubscribe
2590 if (isModEnabled('mailing')) {
2591 if ($conf->browser->layout == 'phone') {
2592 print '</tr><tr>';
2593 }
2594 if ($conf->use_javascript_ajax && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2) {
2595 print "\n".'<script type="text/javascript">'."\n";
2596
2597 print '
2598 jQuery(document).ready(function () {
2599 function init_check_no_email(input) {
2600 if (input.val()!="") {
2601 $(".noemail").addClass("fieldrequired");
2602 } else {
2603 $(".noemail").removeClass("fieldrequired");
2604 }
2605 }
2606 $("#email").keyup(function() {
2607 init_check_no_email($(this));
2608 });
2609 init_check_no_email($("#email"));
2610 })'."\n";
2611 print '</script>'."\n";
2612 }
2613 if (!GETPOSTISSET("no_email") && !empty($object->email)) {
2614 $result = $object->getNoEmail();
2615 if ($result < 0) {
2616 setEventMessages($object->error, $object->errors, 'errors');
2617 }
2618 }
2619 print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
2620 print '<td>';
2621 $useempty = (int) (getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2);
2622 print $form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOSTINT("no_email") : $object->no_email), 1, 0, $useempty);
2623 print '</td>';
2624 }
2625 print '</tr>';
2626
2627 // Social network
2628 if (isModEnabled('socialnetworks')) {
2629 //$colspan = ($conf->browser->layout == 'phone' ? 2 : 4);
2630 $colspan = 4;
2631
2632 $object->showSocialNetwork($socialnetworks, $colspan);
2633
2634 print '<tr><td colspan="'.$colspan.'"><hr></td></tr>';
2635 }
2636
2637 // Prof ids
2638 $i = 1;
2639 $j = 0;
2640 $NBCOLS = ($conf->browser->layout == 'phone' ? 1 : 2);
2641 $NBPROFIDMIN = getDolGlobalInt('THIRDPARTY_MIN_NB_PROF_ID', 2);
2642 $NBPROFIDMAX = getDolGlobalInt('THIRDPARTY_MAX_NB_PROF_ID', 6);
2643 while ($i <= $NBPROFIDMAX) {
2644 $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
2645 if ($idprof != '-' && ($i <= $NBPROFIDMIN || !empty($langs->tab_translate['ProfId'.$i.$object->country_code]))) {
2646 $key = 'idprof'.$i;
2647
2648 if (($j % $NBCOLS) == 0) {
2649 print '<tr>';
2650 }
2651
2652 $idprof_mandatory = 'SOCIETE_IDPROF'.($i).'_MANDATORY';
2653 print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', (int) (getDolGlobalString($idprof_mandatory) && $object->isACompany())).'</td><td>';
2654 print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
2655 print '</td>';
2656 if (($j % $NBCOLS) == ($NBCOLS - 1)) {
2657 print '</tr>';
2658 }
2659 $j++;
2660 }
2661 $i++;
2662 }
2663 if ($NBCOLS > 0 && ($j % 2) == 1) {
2664 print '<td colspan="2"></td></tr>';
2665 }
2666
2667 // VAT is used
2668 print '<tr><td>'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).'</td><td colspan="3">';
2669 print '<input id="assujtva_value" name="assujtva_value" type="checkbox" ' . ($object->tva_assuj ? 'checked="checked"' : '') . ' value="1">';
2670 print '</td></tr>';
2671
2672 // Local Taxes
2673 //TODO: Place into a function to control showing by country or study better option
2674 if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
2675 print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td>';
2676 print '<input id="localtax1assuj_value" name="localtax1assuj_value" type="checkbox" ' . ($object->localtax1_assuj ? 'checked="checked"' : '') . ' value="1">';
2677 if (!isOnlyOneLocalTax(1)) {
2678 print '<span class="cblt1"> '.$langs->transcountry("Type", $mysoc->country_code).': ';
2679 $formcompany->select_localtax(1, (float) $object->localtax1_value, "lt1");
2680 print '</span>';
2681 }
2682 print '</td>';
2683 print '</tr><tr>';
2684 print '<td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td>';
2685 print '<input id="localtax2assuj_value" name="localtax2assuj_value" type="checkbox" ' . ($object->localtax2_assuj ? 'checked="checked"' : '') . ' value="1"></td></tr>';
2686 if (!isOnlyOneLocalTax(2)) {
2687 print '<span class="cblt2"> '.$langs->transcountry("Type", $mysoc->country_code).': ';
2688 $formcompany->select_localtax(2, (float) $object->localtax2_value, "lt2");
2689 print '</span>';
2690 }
2691 print '</td></tr>';
2692 } elseif ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj != "1") {
2693 print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td colspan="3">';
2694 print '<input id="localtax1assuj_value" name="localtax1assuj_value" type="checkbox" ' . ($object->localtax1_assuj ? 'checked="checked"' : '') . ' value="1">';
2695 if (!isOnlyOneLocalTax(1)) {
2696 print '<span class="cblt1"> '.$langs->transcountry("Type", $mysoc->country_code).': ';
2697 $formcompany->select_localtax(1, (float) $object->localtax1_value, "lt1");
2698 print '</span>';
2699 }
2700 print '</td></tr>';
2701 } elseif ($mysoc->localtax2_assuj == "1" && $mysoc->localtax1_assuj != "1") {
2702 print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td colspan="3">';
2703 print '<input id="localtax2assuj_value" name="localtax2assuj_value" type="checkbox" ' . ($object->localtax2_assuj ? 'checked="checked"' : '') . ' value="1">';
2704 if (!isOnlyOneLocalTax(2)) {
2705 print '<span class="cblt2"> '.$langs->transcountry("Type", $mysoc->country_code).': ';
2706 $formcompany->select_localtax(2, (float) $object->localtax2_value, "lt2");
2707 print '</span>';
2708 }
2709 print '</td></tr>';
2710 }
2711
2712 // VAT reverse charge by default
2713 if (getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) {
2714 print '<tr><td>' . $form->editfieldkey('VATReverseChargeByDefault', 'vat_reverse_charge', '', $object, 0) . '</td><td colspan="3">';
2715 print '<input type="checkbox" name="vat_reverse_charge" '.($object->vat_reverse_charge == '1' ? ' checked' : '').'>';
2716 print '</td></tr>';
2717 }
2718
2719 // VAT Code
2720 print '<tr><td>'.$form->editfieldkey('VATIntra', 'intra_vat', '', $object, 0).'</td>';
2721 print '<td colspan="3">';
2722 $s = '<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
2723
2724 if (!getDolGlobalString('MAIN_DISABLEVATCHECK') && isInEEC($object)) {
2725 $s .= ' &nbsp; ';
2726
2727 if ($conf->use_javascript_ajax) {
2728 $widthpopup = 600;
2729 if (!empty($conf->dol_use_jmobile)) {
2730 $widthpopup = 350;
2731 }
2732 $heightpopup = 400;
2733 print "\n";
2734 print '<script type="text/javascript">';
2735 print "function CheckVAT(a) {\n";
2736 if ($mysoc->country_code == 'GR' && $object->country_code == 'GR' && !empty($u)) {
2737 print "GRVAT(a,'{$u}','{$p}','{$myafm}');\n";
2738 } else {
2739 print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a, '".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
2740 }
2741 print "}\n";
2742 print '</script>';
2743 print "\n";
2744 $s .= '<a href="#" class="hideonsmartphone" onclick="CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
2745 $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1);
2746 } else {
2747 $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", (string) $object->country_id).'" class="hideonsmartphone" target="_blank" rel="noopener noreferrer">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
2748 }
2749 }
2750 print $s;
2751 print '</td>';
2752 print '</tr>';
2753
2754 print '<tr><td>'.$form->editfieldkey('EUIDShort', 'euid', '', $object, 0).'</td>';
2755 print '<td colspan="3">';
2756 print '<input type="text" class="flat maxwidthonsmartphone" name="euid" id="euid" maxlength="20" value="'.$object->euid.'">';
2757 print '</td>';
2758 print '</tr>';
2759
2760
2761 $colspan = 4;
2762
2763 print '<tr><td colspan="'.$colspan.'"><hr></td></tr>';
2764
2765 // Categories
2766 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
2767 // Customer
2768 print '<tr class="visibleifcustomer"><td>'.$form->editfieldkey('CustomersCategoriesShort', 'custcats', '', $object, 0).'</td>';
2769 print '<td colspan="3">';
2770 print $form->selectCategories(Categorie::TYPE_CUSTOMER, 'custcats', $object);
2771 print "</td></tr>";
2772
2773 // Supplier
2774 if ((isModEnabled("fournisseur") && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))) {
2775 print '<tr class="visibleifsupplier"><td>'.$form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0).'</td>';
2776 print '<td colspan="3">';
2777 print $form->selectCategories(Categorie::TYPE_SUPPLIER, 'suppcats', $object);
2778 print "</td></tr>";
2779 }
2780 }
2781
2782 print '<tr><td colspan="'.$colspan.'"><br><a class="paddingtop paddingbottom morefieldslnk onreposition" id="morefieldslnk" href="#">'.$langs->trans("More").'';
2783 $nbactive = '...';
2784 print '<span class="badge badge-secondary socialnetworklnk marginleftonly">'.$nbactive.'</span></a>';
2785 print '</td>';
2786 print '</tr>';
2787
2788 // Type - Workforce/Staff
2789 print '<tr class="morefields"><td>'.$form->editfieldkey('ThirdPartyType', 'typent_id', '', $object, 0).'</td><td class="maxwidthonsmartphone"'.(($conf->browser->layout == 'phone' || getDolGlobalString('SOCIETE_DISABLE_WORKFORCE')) ? ' colspan="3"' : '').'>';
2790 print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 1, 0, 0, '', 0, 0, 0, getDolGlobalString('SOCIETE_SORT_ON_TYPEENT', 'ASC'), '', 1);
2791 if ($user->admin) {
2792 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
2793 }
2794 if (!getDolGlobalString('SOCIETE_DISABLE_WORKFORCE')) {
2795 print '</td>';
2796 if ($conf->browser->layout == 'phone') {
2797 print '</tr><tr class="morefields">';
2798 }
2799 print '<td>'.$form->editfieldkey('Workforce', 'effectif_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
2800 print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id, 0, 0, 0, '', 0, 0, 0, '', '', 1);
2801 if ($user->admin) {
2802 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
2803 }
2804 } else {
2805 print '<input type="hidden" name="effectif_id" id="effectif_id" value="'.$object->effectif_id.'">';
2806 }
2807 print '</td></tr>';
2808
2809 // Juridical type
2810 print '<tr class="morefields"><td>'.$form->editfieldkey('JuridicalStatus', 'forme_juridique_code', '', $object, 0).'</td>';
2811 print '<td class="maxwidthonsmartphone" colspan="3">';
2812 print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code');
2813 print '</td></tr>';
2814
2815 // Date birth
2816 print '<tr class="morefields"><td>'.$form->editfieldkey('CompanyBirthDate', 'birth', '', $object, 0).'</td>';
2817 print '<td class="maxwidthonsmartphone" colspan="3">';
2818 print $form->selectDate($object->birth, 'birth', 0, 0, 1, "", 1);
2819 print '</td></tr>';
2820
2821 // Capital
2822 print '<tr class="morefields"><td>'.$form->editfieldkey('Capital', 'capital', '', $object, 0).'</td>';
2823 print '<td colspan="3"><input type="text" name="capital" id="capital" class="width75" value="';
2824 print ($object->capital !== null ? dolPrintHTMLForAttribute(price($object->capital)) : '');
2825 if (isModEnabled("multicurrency")) {
2826 print '"> <span class="hideonsmartphone">'.$langs->trans("Currency".$object->multicurrency_code).'</span></td></tr>';
2827 } else {
2828 print '"> <span class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
2829 }
2830
2831 // Default language
2832 if (getDolGlobalInt('MAIN_MULTILANGS')) {
2833 print '<tr class="morefields"><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3">'."\n";
2834 print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language($object->default_lang, 'default_lang', 0, array(), '1', 0, 0, 'maxwidth300 widthcentpercentminusx');
2835 print '</td>';
2836 print '</tr>';
2837 }
2838
2839 // Incoterms
2840 if (isModEnabled('incoterm')) {
2841 print '<tr class="morefields">';
2842 print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
2843 print '<td colspan="3" class="maxwidthonsmartphone">';
2844 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
2845 print '</td></tr>';
2846 }
2847
2848 // Multicurrency
2849 if (isModEnabled("multicurrency")) {
2850 print '<tr class="morefields">';
2851 print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
2852 print '<td colspan="3" class="maxwidthonsmartphone">';
2853 print img_picto('', 'currency', 'class="pictofixedwidth"');
2854 print $form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code') : ($object->multicurrency_code ? $object->multicurrency_code : $conf->currency)), 'multicurrency_code', 1, '', false, 'maxwidth150 widthcentpercentminusx');
2855 print '</td></tr>';
2856 }
2857
2858 // Other attributes
2859 $parameters = array('socid' => $socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
2860 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
2861
2862 print '<tr class="morefieldsbis tdsmallheight"><td colspan="4"></td></tr>';
2863
2864 // Parent company
2865 if (!getDolGlobalString('SOCIETE_DISABLE_PARENTCOMPANY')) {
2866 print '<tr class="morefieldsbis">';
2867 print '<td>'.$langs->trans('ParentCompany').'</td>';
2868 print '<td colspan="3" class="maxwidthonsmartphone">';
2869 print img_picto('', 'company', 'class="pictofixedwidth"');
2870 print $form->select_company(GETPOST('parent_company_id') ? GETPOST('parent_company_id') : $object->parent, 'parent_company_id', '', 'SelectThirdParty', 0, 0, array(), 0, 'minwidth300 maxwidth500 widthcentpercentminusxx');
2871 print '</td></tr>';
2872 }
2873
2874 // Assign sale representative
2875 print '<tr class="morefieldsbis">';
2876 print '<td>'.$form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0).'</td>';
2877 print '<td colspan="3" class="maxwidthonsmartphone">';
2878 $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', '0', 0, 0, 'u.statut:=:1', 0, '', '', 0, 1);
2879 $arrayselected = GETPOST('commercial', 'array');
2880 if (empty($arrayselected)) {
2881 $arrayselected = $object->getSalesRepresentatives($user, 1);
2882 }
2883 print img_picto('', 'user', 'class="pictofixedwidth"').$form->multiselectarray('commercial', $userlist, $arrayselected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0, '', '', '', 1);
2884 print '</td></tr>';
2885
2886 // Logo
2887 print '<tr class="hideonsmartphone morefieldsbis">';
2888 print '<td>'.$form->editfieldkey('Logo', 'photoinput', '', $object, 0).'</td>';
2889 print '<td colspan="3">';
2890 if ($object->logo) {
2891 print $form->showphoto('societe', $object, 100, 0, 0, 'inline-block');
2892 }
2893 $caneditfield = 1;
2894 if ($caneditfield) {
2895 if ($object->logo) {
2896 print "<br>\n";
2897 }
2898 print '<table class="nobordernopadding">';
2899 if ($object->logo) {
2900 print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">'.$langs->trans("Delete").'</photo><br></td></tr>';
2901 }
2902 //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
2903 print '<tr><td>';
2904 $maxfilesizearray = getMaxFileSizeArray();
2905 $maxmin = $maxfilesizearray['maxmin'];
2906 if ($maxmin > 0) {
2907 print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
2908 }
2909 print '<input type="file" class="flat" name="photo" id="photoinput">';
2910 print '</td></tr>';
2911 print '</table>';
2912 }
2913 print '</td>';
2914 print '</tr>';
2915
2916 print '</table>'."\n";
2917
2918 print '<script nonce="'.getNonce().'" type="text/javascript">
2919 $("document").ready(function() { toogleMoreFields(false); });
2920
2921 jQuery(".morefieldslnk").click(function() {
2922 console.log("Click on link .morefieldslnk (edit)");
2923 toogleMoreFields(true);
2924 return false;
2925 });
2926
2927 function toogleMoreFields(chgCookieState) {
2928 const lnk = $("#morefieldslnk");
2929 const items = $(".morefields, .trextrafields:not(.trextrafieldsgroup)");
2930 var cookieState = document.cookie.split(";").some((item) => item.trim().startsWith("DOLUSER_MOREFIELDS_SHOW=true")) == true;
2931
2932 if (!chgCookieState) cookieState = !cookieState ;
2933
2934 if (cookieState) {
2935 items.hide();
2936 if (chgCookieState) { document.cookie = "DOLUSER_MOREFIELDS_SHOW=false; SameSite=Strict"};
2937 } else {
2938 items.show();
2939 if (chgCookieState) { document.cookie = "DOLUSER_MOREFIELDS_SHOW=true; SameSite=Strict";}
2940 }
2941 }
2942 </script>
2943 ';
2944
2945 if (getDolGlobalString('ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY')) {
2946 print '<br>';
2947 print '<table class="border centpercent">';
2948
2949 if (isModEnabled('accounting')) {
2951 // Accountancy_code_sell
2952 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
2953 print '<td>';
2954 print $formaccounting->select_account($object->accountancy_code_sell, 'accountancy_code_sell', 1, array(), 1, 1);
2955 print '</td></tr>';
2956
2957 // Accountancy_code_buy
2958 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyCode").'</td>';
2959 print '<td>';
2960 print $formaccounting->select_account($object->accountancy_code_buy, 'accountancy_code_buy', 1, array(), 1, 1);
2961 print '</td></tr>';
2962 } else { // For external software
2963 // Accountancy_code_sell
2964 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
2965 print '<td><input name="accountancy_code_sell" class="maxwidth200" value="'.$object->accountancy_code_sell.'">';
2966 print '</td></tr>';
2967
2968 // Accountancy_code_buy
2969 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyCode").'</td>';
2970 print '<td><input name="accountancy_code_buy" class="maxwidth200" value="'.$object->accountancy_code_buy.'">';
2971 print '</td></tr>';
2972 }
2973 print '</table>';
2974 }
2975 }
2976
2977 print '</div>';
2978
2979 print dol_get_fiche_end();
2980
2981 print $form->buttonsSaveCancel();
2982
2983 print '</form>';
2984 }
2985 } else {
2986 // View
2987 if (!empty($object->id)) {
2988 $res = $object->fetch_optionals();
2989 }
2990
2991 $head = societe_prepare_head($object);
2992
2993 print dol_get_fiche_head($head, 'card', $langs->trans("ThirdParty"), -1, 'company', 0, '', '', 0, '', 1);
2994
2995 $formconfirm = '';
2996
2997 // Confirm delete third party
2998 if ($action == 'delete' || ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))) {
2999 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("DeleteACompany"), $langs->trans("ConfirmDeleteCompany"), "confirm_delete", '', 0, "action-delete");
3000 }
3001
3002 if ($action == 'merge') {
3003 $formquestion = array(
3004 array(
3005 'name' => 'soc_origin',
3006 'label' => $langs->trans('MergeOriginThirdparty'),
3007 'type' => 'other',
3008 'value' => $form->select_company('', 'soc_origin', '', 'SelectThirdParty', 1, 0, array(), 0, 'minwidth200', '', '', 1, array(), false, array($object->id))
3009 )
3010 );
3011
3012 $formconfirm .= $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("MergeThirdparties"), $langs->trans("ConfirmMergeThirdparties"), "confirm_merge", $formquestion, 'no', 1, 300);
3013 }
3014
3015 // Clone confirmation
3016 if (($action == 'clone' && (empty($conf->use_javascript_ajax) || !empty($conf->dol_use_jmobile))) // Output when action = clone if jmobile or no js
3017 || (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) { // Always output when not jmobile nor js
3018 // Define confirmation messages
3019 $formquestionclone = array(
3020 'text' => $langs->trans("ConfirmClone"),
3021 0 => array('type' => 'text', 'name' => 'clone_name', 'label' => $langs->trans("NewSocNameForClone"), 'value' => empty($tmpcode) ? $langs->trans("CopyOf").' '.$object->nom : $tmpcode, 'morecss' => 'width250'),
3022 );
3023 $formconfirm .= $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneThirdparties', $object->name), 'confirm_clone', $formquestionclone, 'yes', 'action-clone', 350, 600);
3024 }
3025
3026 // Call Hook formConfirm
3027 $parameters = array('formConfirm' => $formconfirm);
3028 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3029 if (empty($reshook)) {
3030 $formconfirm .= $hookmanager->resPrint;
3031 } elseif ($reshook > 0) {
3032 $formconfirm = $hookmanager->resPrint;
3033 }
3034
3035 // Print form confirm
3036 print $formconfirm;
3037
3038 dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
3039
3040 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
3041
3042 $morehtmlref = '<a href="'.DOL_URL_ROOT.'/societe/vcard.php?id='.$object->id.'" class="refid">';
3043 $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard', 'class="valignmiddle marginleftonly paddingrightonly"');
3044 $morehtmlref .= '</a>';
3045
3046 dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom', $morehtmlref);
3047
3048 // Call Hook tabContentViewThirdparty
3049 $parameters = array();
3050 // Note that $action and $object may be modified by hook
3051 $reshook = $hookmanager->executeHooks('tabContentViewThirdparty', $parameters, $object, $action);
3052 if (empty($reshook)) {
3053 print '<div class="fichecenter">';
3054 print '<div class="fichehalfleft">';
3055
3056 print '<div class="underbanner clearboth"></div>';
3057 print '<table class="border tableforfield centpercent">';
3058
3059 // Type Prospect/Customer/Supplier
3060 print '<tr><td class="titlefieldmiddle">'.$langs->trans('NatureOfThirdParty').'</td><td>';
3061 print $object->getTypeUrl(1);
3062 print '</td></tr>';
3063
3064 // Customer code
3065 if ($object->client) {
3066 print '<tr><td>';
3067 print $langs->trans('CustomerCode');
3068 print '</td>';
3069 print '<td>';
3070 print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_client));
3071 $tmpcheck = $object->check_codeclient();
3072 if ($tmpcheck != 0 && $tmpcheck != -5) {
3073 print img_warning($langs->trans("WrongCustomerCode"));
3074 }
3075 print '</td>';
3076 print '</tr>';
3077 }
3078
3079 // Supplier code
3080 if (((isModEnabled("fournisseur") && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))) && $object->fournisseur) {
3081 print '<tr><td>';
3082 print $langs->trans('SupplierCode').'</td><td>';
3083 print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_fournisseur));
3084 $tmpcheck = $object->check_codefournisseur();
3085 if ($tmpcheck != 0 && $tmpcheck != -5) {
3086 print img_warning($langs->trans("WrongSupplierCode"));
3087 }
3088 print '</td>';
3089 print '</tr>';
3090 }
3091
3092 // Barcode
3093 if (isModEnabled('barcode') && getDolGlobalString('BARCODE_USE_ON_THIRDPARTY')) {
3094 print '<tr><td>';
3095 print $langs->trans('Gencod').'</td><td>'.showValueWithClipboardCPButton(dol_escape_htmltag($object->barcode));
3096 print '</td>';
3097 print '</tr>';
3098 }
3099
3100 // Prof ids
3101 $i = 1;
3102 $j = 0;
3103 $NBPROFIDMIN = getDolGlobalInt('THIRDPARTY_MIN_NB_PROF_ID', 2);
3104 $NBPROFIDMAX = getDolGlobalInt('THIRDPARTY_MAX_NB_PROF_ID', 6);
3105 while ($i <= $NBPROFIDMAX) {
3106 $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
3107 if (!empty($conf->dol_optimize_smallscreen)) {
3108 $idprof = $langs->transcountry('ProfId'.$i.'Short', $object->country_code);
3109 }
3110 if ($idprof != '-' && ($i <= $NBPROFIDMIN || !empty($langs->tab_translate['ProfId'.$i.$object->country_code]))) {
3111 print '<tr>';
3112 print '<td>'.$idprof.'</td><td>';
3113 $key = 'idprof'.$i;
3114 print dol_print_profids($object->$key, 'ProfId'.$i, $object->country_code, 1);
3115 if (!empty($object->$key)) {
3116 if ($object->id_prof_check($i) > 0) {
3117 $profidurl = $object->id_prof_url($i, $object);
3118 if (!empty($profidurl)) {
3119 print ' &nbsp; '.$profidurl;
3120 }
3121 } else {
3122 print img_warning($langs->trans("ErrorWrongValue"));
3123 }
3124 }
3125 print '</td>';
3126 print '</tr>';
3127 $j++;
3128 }
3129 $i++;
3130 }
3131
3132
3133 // 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.
3134 // We don't need them into customer profile.
3135 // Except for spain and localtax where localtax depends on buyer and not seller
3136
3137 if ($object->fournisseur) {
3138 // VAT is used
3139 print '<tr><td>';
3140 print $form->textwithpicto($langs->trans('VATIsUsed'), $langs->trans('VATIsUsedWhenSelling'));
3141 print '</td><td>';
3142 print yn($object->tva_assuj);
3143 print '</td>';
3144 print '</tr>';
3145
3146 if (getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) {
3147 // VAT reverse charge by default
3148 print '<tr><td>';
3149 print $form->textwithpicto($langs->trans('VATReverseChargeByDefault'), $langs->trans('VATReverseChargeByDefaultDesc'));
3150 print '</td><td>';
3151 print '<input type="checkbox" name="vat_reverse_charge" ' . ($object->vat_reverse_charge == '1' ? ' checked' : '') . ' disabled>';
3152 print '</td>';
3153 print '</tr>';
3154 }
3155 }
3156
3157 // Local Taxes
3158 if ($object->fournisseur || $mysoc->country_code == 'ES') {
3159 if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
3160 print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
3161 print yn($object->localtax1_assuj);
3162 print '</td></tr><tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
3163 print yn($object->localtax2_assuj);
3164 print '</td></tr>';
3165
3166 if ($object->localtax1_assuj == "1" && (!isOnlyOneLocalTax(1))) {
3167 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
3168 print '<input type="hidden" name="action" value="set_localtax1">';
3169 print '<input type="hidden" name="token" value="'.newToken().'">';
3170 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>';
3171 if ($action == 'editRE') {
3172 print '<td class="left">';
3173 $formcompany->select_localtax(1, (float) $object->localtax1_value, "lt1");
3174 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
3175 } else {
3176 print '<td>'.$object->localtax1_value.'</td>';
3177 }
3178 print '</tr></form>';
3179 }
3180 if ($object->localtax2_assuj == "1" && (!isOnlyOneLocalTax(2))) {
3181 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
3182 print '<input type="hidden" name="action" value="set_localtax2">';
3183 print '<input type="hidden" name="token" value="'.newToken().'">';
3184 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>';
3185 if ($action == 'editIRPF') {
3186 print '<td class="left">';
3187 $formcompany->select_localtax(2, (float) $object->localtax2_value, "lt2");
3188 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
3189 } else {
3190 print '<td>'.$object->localtax2_value.'</td>';
3191 }
3192 print '</tr></form>';
3193 }
3194 } elseif ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj != "1") {
3195 print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
3196 print yn($object->localtax1_assuj);
3197 print '</td></tr>';
3198 if ($object->localtax1_assuj == "1" && (!isOnlyOneLocalTax(1))) {
3199 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
3200 print '<input type="hidden" name="action" value="set_localtax1">';
3201 print '<input type="hidden" name="token" value="'.newToken().'">';
3202 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>';
3203 if ($action == 'editRE') {
3204 print '<td class="left">';
3205 $formcompany->select_localtax(1, (float) $object->localtax1_value, "lt1");
3206 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
3207 } else {
3208 print '<td>'.$object->localtax1_value.'</td>';
3209 }
3210 print '</tr></form>';
3211 }
3212 } elseif ($mysoc->localtax2_assuj == "1" && $mysoc->localtax1_assuj != "1") {
3213 print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
3214 print yn($object->localtax2_assuj);
3215 print '</td></tr>';
3216 if ($object->localtax2_assuj == "1" && (!isOnlyOneLocalTax(2))) {
3217 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
3218 print '<input type="hidden" name="action" value="set_localtax2">';
3219 print '<input type="hidden" name="token" value="'.newToken().'">';
3220 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>';
3221 if ($action == 'editIRPF') {
3222 print '<td class="left">';
3223 $formcompany->select_localtax(2, (float) $object->localtax2_value, "lt2");
3224 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
3225 } else {
3226 print '<td>'.$object->localtax2_value.'</td>';
3227 }
3228 print '</tr></form>';
3229 }
3230 }
3231 }
3232
3233 // Sale tax code (VAT code)
3234 print '<tr>';
3235 print '<td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
3236 if ($object->tva_intra) {
3237 $s = '';
3238 $s .= dol_print_profids($object->tva_intra, 'VAT', $object->country_code, 1);
3239 $s .= '<input type="hidden" id="tva_intra" name="tva_intra" maxlength="20" value="'.$object->tva_intra.'">';
3240
3241 if (!getDolGlobalString('MAIN_DISABLEVATCHECK') && isInEEC($object)) {
3242 $s .= ' &nbsp; ';
3243
3244 if ($conf->use_javascript_ajax) {
3245 $widthpopup = 600;
3246 if (!empty($conf->dol_use_jmobile)) {
3247 $widthpopup = 350;
3248 }
3249 $heightpopup = 400;
3250 print "\n";
3251 print '<script type="text/javascript">';
3252 print "function CheckVAT(a) {\n";
3253 if ($mysoc->country_code == 'GR' && $object->country_code == 'GR' && !empty($u)) {
3254 print "GRVAT(a,'{$u}','{$p}','{$myafm}');\n";
3255 } else {
3256 print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a, '".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
3257 }
3258 print "}\n";
3259 print '</script>';
3260 print "\n";
3261 $s .= '<a href="#" class="hideonsmartphone" onclick="CheckVAT(jQuery(\'#tva_intra\').val());">'.$langs->trans("VATIntraCheck").'</a>';
3262 $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1);
3263 } else {
3264 $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", (string) $object->country_id).'" class="hideonsmartphone" target="_blank" rel="noopener noreferrer">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
3265 }
3266 }
3267 print $s;
3268 } else {
3269 print '&nbsp;';
3270 }
3271 print '</td></tr>';
3272
3273 // EUID
3274 print '<tr>';
3275 print '<td class="nowrap">'.$langs->trans('EUIDShort').'</td><td>';
3276 if ($object->euid) {
3277 print dol_print_profids($object->euid, 'EUID', $object->country_code, 1);
3278 } else {
3279 print '&nbsp;';
3280 }
3281 print '</td></tr>';
3282
3283 // Warehouse
3284 if (isModEnabled('stock') && getDolGlobalString('SOCIETE_ASK_FOR_WAREHOUSE')) {
3285 $langs->load('stocks');
3286 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
3287 $formproduct = new FormProduct($db);
3288 print '<tr class="nowrap">';
3289 print '<td>';
3290 print $form->editfieldkey("Warehouse", 'warehouse', '', $object, $user->hasRight('societe', 'creer'));
3291 print '</td><td>';
3292 if ($action == 'editwarehouse') {
3293 $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, (int) $object->fk_warehouse, 'fk_warehouse', 1);
3294 } else {
3295 if ($object->fk_warehouse > 0) {
3296 print img_picto('', 'stock', 'class="paddingrightonly"');
3297 }
3298 $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, (int) $object->fk_warehouse, 'none');
3299 }
3300 print '</td>';
3301 print '</tr>';
3302 }
3303
3304 print '</table>';
3305 print '</div>';
3306
3307 print '<div class="fichehalfright">';
3308
3309 print '<div class="underbanner clearboth"></div>';
3310 print '<table class="border tableforfield centpercent">';
3311
3312 // Tags / categories
3313 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
3314 // Customer
3315 if ($object->prospect || $object->client || getDolGlobalString('THIRDPARTY_CAN_HAVE_CUSTOMER_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT')) {
3316 print '<tr><td class="titlefieldmiddle">'.$langs->trans("CustomersCategoriesShort").'</td>';
3317 print '<td>';
3318 print $form->showCategories($object->id, Categorie::TYPE_CUSTOMER, 1);
3319 print "</td></tr>";
3320 }
3321
3322 // Supplier
3323 if (((isModEnabled("fournisseur") && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))) && $object->fournisseur) {
3324 print '<tr><td class="titlefieldmiddle">'.$langs->trans("SuppliersCategoriesShort").'</td>';
3325 print '<td>';
3326 print $form->showCategories($object->id, Categorie::TYPE_SUPPLIER, 1);
3327 print "</td></tr>";
3328 }
3329 }
3330
3331
3332 // Third-Party Type
3333 print '<tr><td class="titlefieldmiddle">';
3334 print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans('ThirdPartyType').'</td>';
3335 if ($action != 'editthirdpartytype' && $user->hasRight('societe', 'creer')) {
3336 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>';
3337 }
3338 print '</tr></table>';
3339 print '</td><td>';
3340 $html_name = ($action == 'editthirdpartytype') ? 'typent_id' : 'none';
3341 $formcompany->formThirdpartyType($_SERVER['PHP_SELF'].'?socid='.$object->id, (string) $object->typent_id, $html_name, '');
3342 print '</td></tr>';
3343
3344 // Workforce/Staff
3345 if (!getDolGlobalString('SOCIETE_DISABLE_WORKFORCE')) {
3346 print '<tr><td>'.$langs->trans("Workforce").'</td><td>'.$object->effectif.'</td></tr>';
3347 }
3348
3349 // Legal
3350 print '<tr><td>'.$langs->trans('JuridicalStatus').'</td><td>'.dolPrintHTML($object->forme_juridique).'</td></tr>';
3351
3352 // Date birth
3353 print '<tr><td>'.$langs->trans('CompanyBirthDate').'</td><td>'.dol_print_date($object->birth).'</td></tr>';
3354
3355 // Capital
3356 print '<tr><td>'.$langs->trans('Capital').'</td><td>';
3357 if ($object->capital !== null) {
3358 if (isModEnabled("multicurrency") && !empty($object->multicurrency_code)) {
3359 print price($object->capital, 0, $langs, 0, -1, -1, $object->multicurrency_code);
3360 } else {
3361 print price($object->capital, 0, $langs, 0, -1, -1, $conf->currency);
3362 }
3363 }
3364 print '</td></tr>';
3365
3366 // Unsubscribe opt-out
3367 if (isModEnabled('mailing')) {
3368 $result = $object->getNoEmail();
3369 if ($result < 0) {
3370 setEventMessages($object->error, $object->errors, 'errors');
3371 }
3372 print '<tr><td>'.$langs->trans("No_Email").'</td><td>';
3373 if ($object->email) {
3374 print yn($object->no_email);
3375 } else {
3376 $langs->load("mails");
3377 print '<span class="opacitymedium">'.$langs->trans("EMailNotDefined").'</span>';
3378 }
3379
3380 $langs->load("mails");
3381 print ' &nbsp; <span class="badge badge-secondary" title="'.dolPrintHTMLForAttribute($langs->trans("NbOfEMailingsSend")).'">'.$object->getNbOfEMailings().'</span>';
3382
3383 print '</td></tr>';
3384 }
3385
3386 // Default language
3387 if (getDolGlobalInt('MAIN_MULTILANGS')) {
3388 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
3389 print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
3390 //$s=picto_from_langcode($object->default_lang);
3391 //print ($s?$s.' ':'');
3392 $langs->load("languages");
3393 $labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
3394 print picto_from_langcode($object->default_lang, 'class="paddingrightonly saturatemedium opacitylow"');
3395 print $labellang;
3396 print '</td></tr>';
3397 }
3398
3399 // Incoterms
3400 if (isModEnabled('incoterm')) {
3401 print '<tr><td>';
3402 print '<table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans('IncotermLabel').'</td>';
3403 if ($action != 'editincoterm' && $user->hasRight('societe', 'creer')) {
3404 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=editincoterm&token='.newToken().'">'.img_edit('', 1).'</a></td>';
3405 }
3406 print '</tr></table>';
3407 print '</td><td colspan="3">';
3408 if ($action != 'editincoterm') {
3409 print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
3410 } else {
3411 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?socid='.$object->id);
3412 }
3413 print '</td></tr>';
3414 }
3415
3416 // Multicurrency
3417 if (isModEnabled("multicurrency")) {
3418 print '<tr>';
3419 print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
3420 print '<td>';
3421 print !empty($object->multicurrency_code) ? currency_name($object->multicurrency_code, 1) : '';
3422 print '</td></tr>';
3423 }
3424
3425 if (getDolGlobalString('ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY')) {
3426 // Accountancy sell code
3427 print '<tr><td class="nowrap">';
3428 print $langs->trans("ProductAccountancySellCode");
3429 print '</td><td colspan="2">';
3430 if (isModEnabled('accounting')) {
3431 if (!empty($object->accountancy_code_sell)) {
3432 $accountingaccount = new AccountingAccount($db);
3433 $accountingaccount->fetch(0, $object->accountancy_code_sell, 1);
3434
3435 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
3436 }
3437 } else {
3438 print $object->accountancy_code_sell;
3439 }
3440 print '</td></tr>';
3441
3442 // Accountancy buy code
3443 print '<tr><td class="nowrap">';
3444 print $langs->trans("ProductAccountancyBuyCode");
3445 print '</td><td colspan="2">';
3446 if (isModEnabled('accounting')) {
3447 if (!empty($object->accountancy_code_buy)) {
3448 $accountingaccount2 = new AccountingAccount($db);
3449 $accountingaccount2->fetch(0, $object->accountancy_code_buy, 1);
3450
3451 print $accountingaccount2->getNomUrl(0, 1, 1, '', 1);
3452 }
3453 } else {
3454 print $object->accountancy_code_buy;
3455 }
3456 print '</td></tr>';
3457 }
3458
3459 // Other attributes
3460 $parameters = array('socid' => $socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
3461 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
3462
3463 // Parent company
3464 if (!getDolGlobalString('SOCIETE_DISABLE_PARENTCOMPANY')) {
3465 print '<tr><td>';
3466 print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans('ParentCompany').'</td>';
3467 if ($action != 'editparentcompany' && $user->hasRight('societe', 'creer')) {
3468 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>';
3469 }
3470 print '</tr></table>';
3471 print '</td><td>';
3472 $html_name = ($action == 'editparentcompany') ? 'parent_id' : 'none';
3473 $form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id, (string) $object->parent, $html_name, '', 1, 0, 0, array(), 0, array($object->id));
3474 print '</td></tr>';
3475 }
3476
3477 // Sales representative
3478 include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php';
3479
3480 // Module Adherent
3481 if (isModEnabled('member')) {
3482 $langs->load("members");
3483 print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
3484 print '<td>';
3485 $adh = new Adherent($db);
3486 $result = $adh->fetch(0, '', $object->id);
3487 if ($result > 0) {
3488 $adh->ref = $adh->getFullName($langs);
3489 print $adh->getNomUrl(-1);
3490 print ' &mdash; '.$adh->getLibStatut(0);
3491 } else {
3492 print '<span class="opacitymedium">'.$langs->trans("ThirdpartyNotLinkedToMember").'</span>';
3493 }
3494 print "</td></tr>\n";
3495 }
3496
3497 // Link user (you must create a contact to get a user)
3498 /*
3499 print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td colspan="3">';
3500 if ($object->user_id) {
3501 $dolibarr_user = new User($db);
3502 $result = $dolibarr_user->fetch($object->user_id);
3503 print $dolibarr_user->getLoginUrl(-1);
3504 } else {
3505 //print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
3506 if (!$object->user_id && $user->hasRight('user', 'user', 'creer')) {
3507 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>';
3508 }
3509 }
3510 print '</td></tr>';
3511 */
3512
3513 print '</table>';
3514 print '</div>';
3515
3516 print '</div>';
3517 print '<div class="clearboth"></div>';
3518 }
3519
3520 print dol_get_fiche_end();
3521
3522
3523 /*
3524 * Actions
3525 */
3526 if ($action != 'presend') {
3527 print '<div class="tabsAction">'."\n";
3528
3529 $parameters = array();
3530 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3531 if (empty($reshook)) {
3532 $at_least_one_email_contact = false;
3533 $TContact = $object->contact_array_objects();
3534 foreach ($TContact as &$contact) {
3535 if (!empty($contact->email)) {
3536 $at_least_one_email_contact = true;
3537 break;
3538 }
3539 }
3540
3541 if (empty($user->socid)) {
3542 $langs->load("mails");
3543 $title = '';
3544 if (empty($object->email) && !$at_least_one_email_contact) {
3545 $title = $langs->trans('NoEMail');
3546 }
3547 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) ? 1 : -1);
3548 }
3549
3550 print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=edit&token='.newToken(), '', $permissiontoadd);
3551
3552 if (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile)) {
3553 $cloneSocietetUrl = '';
3554 $cloneButtonId = 'action-clone';
3555 } else {
3556 $cloneSocietetUrl = '';
3557 $cloneButtonId = '';
3558 }
3559 print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $cloneSocietetUrl, $cloneButtonId, $user->hasRight('societe', 'creer'));
3560
3561 if (isModEnabled('member')) {
3562 $adh = new Adherent($db);
3563 $result = $adh->fetch(0, '', $object->id);
3564 if ($result == 0 && ($object->client == 1 || $object->client == 3) && getDolGlobalString('MEMBER_CAN_CONVERT_CUSTOMERS_TO_MEMBERS')) {
3565 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";
3566 }
3567 }
3568
3569 print dolGetButtonAction($langs->trans('MergeThirdparties'), $langs->trans('Merge'), 'danger', $_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=merge&token='.newToken(), '', $permissiontodelete);
3570
3571 $deleteUrl = $_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=delete&token='.newToken();
3572 $buttonId = 'action-delete-no-ajax';
3573 if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)) { // We can't use preloaded confirm form with jmobile
3574 $deleteUrl = '';
3575 $buttonId = 'action-delete';
3576 }
3577 print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $deleteUrl, $buttonId, $permissiontodelete);
3578 }
3579
3580 print '</div>'."\n";
3581 }
3582
3583 //Select mail models is same action as presend
3584 if (GETPOST('modelselected')) {
3585 $action = 'presend';
3586 }
3587
3588 if ($action != 'presend') {
3589 print '<div class="fichecenter"><div class="fichehalfleft">';
3590
3591 if (!getDolGlobalString('SOCIETE_DISABLE_BUILDDOC')) {
3592 print '<a name="builddoc"></a>'; // ancre
3593
3594 /*
3595 * Generated documents
3596 */
3597 $filedir = $conf->societe->multidir_output[$object->entity ?? $conf->entity].'/'.$object->id;
3598 $urlsource = $_SERVER["PHP_SELF"]."?socid=".$object->id;
3599 $genallowed = $user->hasRight('societe', 'lire');
3600 $delallowed = $user->hasRight('societe', 'creer');
3601
3602 print $formfile->showdocuments('company', (string) $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, '', '', $object->default_lang);
3603 }
3604
3605 // Subsidiaries list
3606 if (!getDolGlobalString('SOCIETE_DISABLE_PARENTCOMPANY') && !getDolGlobalString('SOCIETE_DISABLE_SHOW_SUBSIDIARIES')) {
3607 print '<br>';
3608 $result = show_subsidiaries($conf, $langs, $db, $object);
3609 }
3610
3611 print '</div><div class="fichehalfright">';
3612
3613 $MAXEVENT = 10;
3614
3615 $morehtmlcenter = '<div class="nowraponall">';
3616 $morehtmlcenter .= dolGetButtonTitle($langs->trans('FullConversation'), '', 'fa fa-comments imgforviewmode', DOL_URL_ROOT.'/societe/messaging.php?socid='.$object->id);
3617 $morehtmlcenter .= dolGetButtonTitle($langs->trans('FullList'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id);
3618 $morehtmlcenter .= '</div>';
3619
3620 // List of actions on element
3621 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
3622 $formactions = new FormActions($db);
3623 $somethingshown = $formactions->showactions($object, '', $socid, 1, '', $MAXEVENT, '', $morehtmlcenter); // Show all action for thirdparty
3624
3625 print '</div></div>';
3626
3627 if (getDolGlobalString('MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD')) {
3628 // Contacts list
3629 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
3630 $result = show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
3631 }
3632 }
3633 }
3634
3635 // Presend form
3636 $modelmail = 'thirdparty';
3637 $defaulttopic = 'Information';
3638 $diroutput = $conf->societe->multidir_output[$object->entity ?? $conf->entity];
3639 $trackid = 'thi'.$object->id;
3640
3641 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
3642 }
3643}
3644
3645
3646// End of page
3647llxFooter();
3648$db->close();
3649
3650?>
3651
3652<script>
3653// Function to retrieve VAT details from the Greek Ministry of Finance GSIS SOAP web service
3654function GRVAT(a, u, p, myafm) {
3655 var afm = a.replace(/\D/g, ""); // Remove non-digit characters from 'a'
3656
3657 $.ajax({
3658 type: "GET",
3659 url: '<?php echo DOL_URL_ROOT ?>/societe/checkvat/checkVatGr.php',
3660 data: { afm }, // Set request parameters
3661 success: function(data) {
3662 var obj = data; // Parse response data as JSON
3663
3664 // Update form fields based on retrieved data
3665 if (obj.RgWsPublicBasicRt_out.afm === null) {
3666 alert(obj.pErrorRec_out.errorDescr); // Display error message if AFM is null
3667 } else {
3668 $("#name").val(obj.RgWsPublicBasicRt_out.onomasia); // Set 'name' field value
3669 $("#address").val(obj.RgWsPublicBasicRt_out.postalAddress + " " + obj.RgWsPublicBasicRt_out.postalAddressNo); // Set 'address' field value
3670 $("#zipcode").val(obj.RgWsPublicBasicRt_out.postalZipCode); // Set 'zipcode' field value
3671 $("#town").val(obj.RgWsPublicBasicRt_out.postalAreaDescription); // Set 'town' field value
3672 $("#idprof2").val(obj.RgWsPublicBasicRt_out.doyDescr); // Set 'idprof2' field value
3673 $("#name_alias_input").val(obj.RgWsPublicBasicRt_out.commerTitle); // Set 'name_alias' field value
3674
3675 if (obj.arrayOfRgWsPublicFirmActRt_out.RgWsPublicFirmActRtUser) {
3676 var firmActUser = obj.arrayOfRgWsPublicFirmActRt_out.RgWsPublicFirmActRtUser;
3677
3678 if (Array.isArray(firmActUser)) {
3679 var primaryFirmAct = firmActUser.find(item => item.firmActKindDescr === "ΚΥΡΙΑ"); // Find primary client activity
3680 if (primaryFirmAct) {
3681 $("#idprof1").val(primaryFirmAct.firmActDescr); // Set 'idprof1' field value
3682 }
3683 } else {
3684 $("#idprof1").val(firmActUser.firmActDescr); // Set 'idprof1' field value
3685 }
3686 }
3687 }
3688 }
3689 });
3690}
3691
3692</script>
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage accounting accounts.
Class to manage members of a foundation.
Class to manage canvas.
Class to manage standard extra fields.
Class to manage generation of HTML components for accounting management.
Class to manage building of HTML components.
Class to generate html code for admin pages.
Class to build HTML component for third parties management Only common components are here.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class with static methods for building HTML components related to products Only components common to ...
Class to manage third parties objects (customers, suppliers, prospects...)
show_contacts($conf, $langs, $db, $object, $backtopage='', $showuserlogin=0)
Show html area for list of contacts.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
currency_name($code_iso, $withcode=0, $outputlangs=null)
Return label of currency or code+label.
show_subsidiaries($conf, $langs, $db, $object)
Show html area for list of subsidiaries.
societe_prepare_head(Societe $object, $subtabs='')
Return array of tabs to used on pages for third parties cards.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
global $mysoc
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
addFileIntoDatabaseIndex($dir, $file, $fullpathorig='', $mode='uploaded', $setsharekey=0, $object=null, $forceFullTextIndexation='')
Add a file into database index.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $keyforsourcefile='addedfile', $upload_dir='', $mode=0)
Check validity of a file upload from an GUI page, and move it to its final destination.
deleteFilesIntoDatabaseIndex($dir, $file, $mode='uploaded', $object=null)
Delete files into database index using search criteria.
isValidUrl($url, $http=0, $pass=0, $port=0, $path=0, $query=0, $anchor=0)
Url string validation <http[s]> :// [user[:pass]@] hostname [port] [/path] [?getquery] [anchor].
isOnlyOneLocalTax($local)
Return true if LocalTax (1 or 2) is unique.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='')
Show information in HTML for admin users or standard users.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolPrintHTML($s, $allowiframe=0, $moreallowedtags=array())
Return a string (that can be on several lines) ready to be output on a HTML page.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dolPrintHTMLForTextArea($s, $allowiframe=0)
Return a string ready to be output on input textarea.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
getArrayOfSocialNetworks()
Get array of social network dictionary.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_profids($profID, $profIDtype, $countrycode='', $addcpButton=1)
Format professional IDs according to their country.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formatted messages to output (Used to show messages on html output).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:130
getMaxFileSizeArray()
Return the max allowed for file upload.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.