dolibarr 24.0.1
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-2026 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') {
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 if (empty($object->tva_intra)) {
528 $object->tva_intra = $object->calculateVATNumberFromProperties($object);
529 }
530 }
531 }
532
533 if (!$error) {
534 if ($action == 'add' && $permissiontoadd) {
535 $error = 0;
536
537 $db->begin();
538
539 if (empty($object->client)) {
540 $object->code_client = '';
541 }
542 if (empty($object->fournisseur)) {
543 $object->code_fournisseur = '';
544 }
545
546 $result = $object->create($user);
547
548 if ($result >= 0 && isModEnabled('mailing') && !empty($object->email) && $object->no_email == 1) {
549 // Add mass emailing flag into table mailing_unsubscribe
550 $resultnoemail = $object->setNoEmail($object->no_email);
551 if ($resultnoemail < 0) {
552 $error++;
553 $errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
554 $action = 'create';
555 }
556 }
557
558 if ($result >= 0) {
559 if ($object->particulier) {
560 dol_syslog("We ask to create a contact/address too", LOG_DEBUG);
561 $contcats = GETPOST('contcats', 'array');
562 $no_email = GETPOSTINT('contact_no_email');
563 $result = $object->create_individual($user, $no_email, $contcats);
564 if ($result < 0) {
565 setEventMessages($object->error, $object->errors, 'errors');
566 $error++;
567 }
568 }
569
570 // Links with users
571 $salesreps = GETPOST('commercial', 'array');
572 $result = $object->setSalesRep($salesreps, true);
573 if ($result < 0) {
574 $error++;
575 setEventMessages($object->error, $object->errors, 'errors');
576 }
577
578 // Customer categories association
579 $custcats = GETPOST('custcats', 'array');
580 $result = $object->setCategories($custcats, 'customer');
581 if ($result < 0) {
582 $error++;
583 setEventMessages($object->error, $object->errors, 'errors');
584 }
585
586 // Supplier categories association
587 $suppcats = GETPOST('suppcats', 'array');
588 $result = $object->setCategories($suppcats, 'supplier');
589 if ($result < 0) {
590 $error++;
591 setEventMessages($object->error, $object->errors, 'errors');
592 }
593
594 // Logo/Photo save
595 $dir = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos/";
596 $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
597 if ($file_OK) {
598 if (image_format_supported($_FILES['photo']['name'])) {
599 dol_mkdir($dir);
600
601 if (@is_dir($dir)) {
602 $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
603 $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
604
605 // Note: $result is a string when the file was refused and, in PHP 8, such a string compares as greater than 0
606 if (!is_numeric($result) || $result <= 0) {
607 $errors[] = "ErrorFailedToSaveFile";
608 } else {
609 // Create thumbs
610 $object->addThumbs($newfile);
611
612 // Index file in database
613 if (getDolGlobalString('THIRDPARTY_LOGO_ALLOW_EXTERNAL_DOWNLOAD')) {
614 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
615 // 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
616 deleteFilesIntoDatabaseIndex(dirname($newfile), '', '', $object);
617 // now we index the uploaded logo file
618 addFileIntoDatabaseIndex(dirname($newfile), basename($newfile), '', 'uploaded', 1, $object);
619 }
620 }
621 }
622 }
623 } else {
624 switch ($_FILES['photo']['error']) {
625 case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
626 case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
627 $errors[] = "ErrorFileSizeTooLarge";
628 break;
629 case 3: //uploaded file was only partially uploaded
630 $errors[] = "ErrorFilePartiallyUploaded";
631 break;
632 }
633 }
634 } else {
635 if ($result == -3 && in_array('ErrorCustomerCodeAlreadyUsed', $object->errors)) {
636 $duplicate_code_error = true;
637 $object->code_client = '';
638 }
639
640 if ($result == -3 && in_array('ErrorSupplierCodeAlreadyUsed', $object->errors)) {
641 $duplicate_code_error = true;
642 $object->code_fournisseur = '';
643 }
644
645 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
646 $duplicate_code_error = true;
647 }
648
649 setEventMessages($object->error, $object->errors, 'errors');
650 $error++;
651 }
652
653 if ($result >= 0 && !$error) {
654 $db->commit();
655
656 if (!empty($backtopage)) {
657 $backtopage = preg_replace('/--IDFORBACKTOPAGE--/', (string) $object->id, $backtopage); // New method to autoselect project after a New on another form object creation
658 if (preg_match('/\?/', $backtopage)) {
659 $backtopage .= '&socid='.$object->id; // Old method
660 }
661 header("Location: ".$backtopage);
662 exit;
663 } else {
664 $url = $_SERVER["PHP_SELF"]."?socid=".$object->id; // Old method
665 if (($object->client == 1 || $object->client == 3) && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS')) {
666 $url = DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
667 } elseif ($object->fournisseur == 1) {
668 $url = DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
669 }
670
671 header("Location: ".$url);
672 exit;
673 }
674 } else {
675 $db->rollback();
676 $action = 'create';
677 }
678 }
679
680 if ($action == 'update' && $permissiontoadd) {
681 $error = 0;
682
683 if (GETPOST('cancel', 'alpha')) {
684 if (!empty($backtopage)) {
685 header("Location: ".$backtopage);
686 exit;
687 } else {
688 header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
689 exit;
690 }
691 }
692
693 // To not set code if third party is not concerned. But if it had values, we keep them.
694 if (empty($object->client) && empty($object->oldcopy->code_client)) {
695 $object->code_client = '';
696 }
697 if (empty($object->fournisseur) && empty($object->oldcopy->code_fournisseur)) {
698 $object->code_fournisseur = '';
699 }
700 //var_dump($object);exit;
701
702 $nosyncmember = getDolGlobalInt('SOCIETE_NO_SYNC_LINKED_MEMBER');
703
704 $result = $object->update($socid, $user, 1, $object->oldcopy->codeclient_modifiable(), $object->oldcopy->codefournisseur_modifiable(), 'update', $nosyncmember);
705
706 if ($result > 0) {
707 // Update mass emailing flag into table mailing_unsubscribe
708 if (GETPOSTISSET('no_email') && $object->email) {
709 $no_email = GETPOSTINT('no_email');
710 $result = $object->setNoEmail($no_email);
711 if ($result < 0) {
712 setEventMessages($object->error, $object->errors, 'errors');
713 $action = 'edit';
714 }
715 }
716
717 $action = 'view';
718 } else {
719 setEventMessages($object->error, $object->errors, 'errors');
720 $action = 'edit';
721 }
722
723 if ($result <= 0) {
724 setEventMessages($object->error, $object->errors, 'errors');
725 $error++;
726 }
727
728 // Links with users
729 $salesreps = GETPOST('commercial', 'array');
730 $result = $object->setSalesRep($salesreps);
731 if ($result < 0) {
732 $error++;
733 setEventMessages($object->error, $object->errors, 'errors');
734 }
735
736 // Prevent thirdparty's emptying if a user hasn't rights $user->rights->categorie->lire (in such a case, post of 'custcats' is not defined)
737 if (!$error && $user->hasRight('categorie', 'lire')) {
738 // Customer categories association
739 $categories = GETPOST('custcats', 'array');
740 $result = $object->setCategories($categories, 'customer');
741 if ($result < 0) {
742 $error++;
743 setEventMessages($object->error, $object->errors, 'errors');
744 }
745
746 // Supplier categories association
747 $categories = GETPOST('suppcats', 'array');
748 $result = $object->setCategories($categories, 'supplier');
749 if ($result < 0) {
750 $error++;
751 setEventMessages($object->error, $object->errors, 'errors');
752 }
753 }
754
755 // Logo/Photo save
756 $dir = $conf->societe->multidir_output[$object->entity ?? $conf->entity]."/".$object->id."/logos";
757 $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
758 if (GETPOST('deletephoto') && $current_logo) {
759 $fileimg = $dir.'/'.$current_logo;
760 $dirthumbs = $dir.'/thumbs';
761 dol_delete_file($fileimg);
762 dol_delete_dir_recursive($dirthumbs);
763 }
764 if ($file_OK) {
765 if (image_format_supported($_FILES['photo']['name']) > 0) {
766 if ($current_logo != $object->logo) {
767 $fileimg = $dir.'/'.$current_logo;
768 $dirthumbs = $dir.'/thumbs';
769 dol_delete_file($fileimg);
770 dol_delete_dir_recursive($dirthumbs);
771 }
772
773 dol_mkdir($dir);
774
775 if (@is_dir($dir)) {
776 $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
777 $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
778
779 // Note: $result is a string when the file was refused and, in PHP 8, such a string compares as greater than 0
780 if (!is_numeric($result) || $result <= 0) {
781 $errors[] = "ErrorFailedToSaveFile";
782 } else {
783 // Create thumbs
784 $object->addThumbs($newfile);
785
786 // Index file in database
787 if (getDolGlobalString('THIRDPARTY_LOGO_ALLOW_EXTERNAL_DOWNLOAD')) {
788 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
789 // 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
790 deleteFilesIntoDatabaseIndex(dirname($newfile), '', '', $object);
791 // now we index the uploaded logo file
792 addFileIntoDatabaseIndex(dirname($newfile), basename($newfile), '', 'uploaded', 1, $object);
793 }
794 }
795 }
796 } else {
797 $errors[] = "ErrorBadImageFormat";
798 }
799 } else {
800 switch ($_FILES['photo']['error']) {
801 case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
802 case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
803 $errors[] = "ErrorFileSizeTooLarge";
804 break;
805 case 3: //uploaded file was only partially uploaded
806 $errors[] = "ErrorFilePartiallyUploaded";
807 break;
808 }
809 }
810 // Company logo management
811
812
813 // Update linked member
814 if (!$error && isset($object->fk_soc) && $object->fk_soc > 0) {
815 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
816 $sql .= " SET fk_soc = NULL WHERE fk_soc = ".((int) $socid);
817 if (!$object->db->query($sql)) {
818 $error++;
819 $object->error .= $object->db->lasterror();
820 setEventMessages($object->error, $object->errors, 'errors');
821 }
822 }
823
824 if (!$error && !count($errors)) {
825 if (!empty($backtopage)) {
826 header("Location: ".$backtopage);
827 exit;
828 } else {
829 header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
830 exit;
831 }
832 } else {
833 $object->id = $socid;
834 $action = "edit";
835 }
836 }
837 } else {
838 $action = ($action == 'add' ? 'create' : 'edit');
839 }
840 }
841
842 // Delete third party
843 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('societe', 'supprimer')) {
844 $object->fetch($socid);
845 $object->oldcopy = clone $object; // @phan-suppress-current-line PhanTypeMismatchProperty
846 $result = $object->delete($socid, $user);
847
848 if ($result > 0) {
849 header("Location: ".DOL_URL_ROOT."/societe/list.php?restore_lastsearch_values=1&delsoc=".urlencode($object->name));
850 exit;
851 } else {
852 $langs->load("errors");
853 setEventMessages($object->error, $object->errors, 'errors');
854 $error++;
855 $action = '';
856 }
857 }
858
859 // Set third-party type
860 if ($action == 'set_thirdpartytype' && $permissiontoadd) {
861 $object->fetch($socid);
862 $result = $object->setThirdpartyType(GETPOSTINT('typent_id'));
863 }
864
865 // Set incoterm
866 if ($action == 'set_incoterms' && $permissiontoadd && isModEnabled('incoterm')) {
867 $object->fetch($socid);
868 $result = $object->setIncoterms(GETPOSTINT('incoterm_id'), GETPOST('location_incoterms'));
869 }
870
871 // Set parent company
872 if ($action == 'set_thirdparty' && $permissiontoadd) {
873 $object->fetch($socid);
874 $result = $object->setParent(GETPOSTINT('parent_id'));
875 }
876
877 // Set sales representatives
878 if ($action == 'set_salesrepresentatives' && $permissiontoadd) {
879 $object->fetch($socid);
880 $result = $object->setSalesRep(GETPOST('commercial', 'array'));
881 }
882
883 // warehouse
884 if ($action == 'setwarehouse' && $permissiontoadd) {
885 $result = $object->setWarehouse(GETPOSTINT('fk_warehouse'));
886 }
887
888 if ($action == 'confirm_clone' && $confirm != 'yes') { // Test on permission not required here
889 $action = '';
890 }
891 //clone company essential info
892 if ($action == 'confirm_clone' && $confirm == 'yes' && $user->hasRight('societe', 'creer')) {
893 if ($object->id > 0) {
894 $error = 0;
895
896 $clone = dol_clone($object, 1);
897
898 if (!empty(GETPOST('clone_name'))) {
899 $clone->id = 0;
900 $clone->name = GETPOST('clone_name', 'alphanohtml');
901 $clone->status = 1;
902 $clone->fournisseur = 0;
903 $clone->client = 0;
904
905 $db->begin();
906
907 $clone->context['createfromclone'] = 'createfromclone';
908 $id = $clone->create($user);
909 if ($id > 0) {
910 $clone->id = $id;
911 } else {
912 setEventMessages($clone->error, $clone->errors, 'errors');
913 $error++;
914 }
915
916 unset($clone->context['createfromclone']);
917
918 if ($error) {
919 $db->rollback();
920 } else {
921 $db->commit();
922 $db->close();
923 header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
924 exit;
925 }
926 } else {
927 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NewRefForClone")), null, 'errors');
928 }
929 } else {
930 dol_print_error($db, $object->error, $object->errors);
931 }
932 $action = 'clone';
933 }
934
935 $id = $socid;
936 $object->fetch($socid);
937
938 // Selection of new fields
939 if (getDolGlobalString('MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD') && (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS') || getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT'))) {
940 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
941 }
942
943 // Actions to send emails
944 $triggersendname = 'COMPANY_SENTBYMAIL';
945 $paramname = 'socid';
946 $mode = 'emailfromthirdparty';
947 $trackid = 'thi'.$object->id;
948 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
949
950 // Actions to build doc
951 $id = $socid;
952 $upload_dir = !empty($conf->societe->multidir_output[$object->entity ?? $conf->entity]) ? $conf->societe->multidir_output[$object->entity ?? $conf->entity] : $conf->societe->dir_output;
953 $permissiontoadd = $user->hasRight('societe', 'creer');
954 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
955
956 // Actions when printing a doc from card
957 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
958}
959
960
961/*
962 * View
963 */
964
965$form = new Form($db);
966$formfile = new FormFile($db);
967$formadmin = new FormAdmin($db);
968$formcompany = new FormCompany($db);
969$formaccounting = null;
970if (isModEnabled('accounting')) {
971 $formaccounting = new FormAccounting($db);
972}
973
974if ($socid > 0 && empty($object->id)) {
975 $result = $object->fetch($socid);
976 if ($result <= 0) {
977 dol_print_error(null, $object->error);
978 exit(1);
979 }
980}
981
982$title = $langs->trans("ThirdParty");
983if ($action == 'create') {
984 $title = $langs->trans("NewThirdParty");
985}
986if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/thirdpartynameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->name) {
987 $title = $object->name." - ".$langs->trans('Card');
988}
989$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas|DE:Modul_Geschäftspartner';
990
991llxHeader('', $title, $help_url);
992
993$countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
994
995$canvasdisplayaction = $action;
996if (in_array($canvasdisplayaction, array('merge', 'confirm_merge'))) {
997 $canvasdisplayaction = 'view';
998}
999
1000if (is_object($objcanvas) && $objcanvas->displayCanvasExists($canvasdisplayaction)) {
1001 // -----------------------------------------
1002 // When used with CANVAS
1003 // -----------------------------------------
1004 $objcanvas->assign_values($canvasdisplayaction, $object->id, $object->ref); // Set value for templates
1005 $objcanvas->display_canvas($canvasdisplayaction); // Show template
1006} else {
1007 // -----------------------------------------
1008 // When used in standard mode
1009 // -----------------------------------------
1010 if ($action == 'create') {
1011 /*
1012 * Creation
1013 */
1014 $private = GETPOSTINT("private");
1015 if (getDolGlobalString('THIRDPARTY_DEFAULT_CREATE_CONTACT') && !GETPOSTISSET('private') && GETPOST("type", 'aZ') != 'f') {
1016 $private = 1;
1017 }
1018 if (empty($private)) {
1019 $private = 0;
1020 }
1021
1022 // Load object modCodeClient
1023 $module = getDolGlobalString('SOCIETE_CODECLIENT_ADDON', 'mod_codeclient_leopard');
1024 if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
1025 $module = substr($module, 0, dol_strlen($module) - 4);
1026 }
1027 $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
1028 foreach ($dirsociete as $dirroot) {
1029 $res = dol_include_once($dirroot.$module.'.php');
1030 if ($res) {
1031 break;
1032 }
1033 }
1034 $modCodeClient = new $module($db);
1035 '@phan-var-force ModeleThirdPartyCode $modCodeClient';
1036
1037 // Load object modCodeFournisseur
1038 $module = getDolGlobalString('SOCIETE_CODECLIENT_ADDON', 'mod_codeclient_leopard');
1039 if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
1040 $module = substr($module, 0, dol_strlen($module) - 4);
1041 }
1042 $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
1043 foreach ($dirsociete as $dirroot) {
1044 $res = dol_include_once($dirroot.$module.'.php');
1045 if ($res) {
1046 break;
1047 }
1048 }
1049 $modCodeFournisseur = new $module($db);
1050 '@phan-var-force ModeleThirdPartyCode $modCodeFournisseur';
1051
1052 // Define if customer/prospect or supplier status is set or not
1053 if (GETPOST("type", 'aZ') != 'f') {
1054 $object->client = 0;
1055 if (getDolGlobalString('THIRDPARTY_CUSTOMERPROSPECT_BY_DEFAULT')) {
1056 $object->client = 3;
1057 }
1058 }
1059 // Prospect / Customer
1060 if (GETPOST("type", 'aZ') == 'c') {
1061 if (getDolGlobalInt('THIRDPARTY_CUSTOMERTYPE_BY_DEFAULT')) {
1062 $object->client = getDolGlobalInt('THIRDPARTY_CUSTOMERTYPE_BY_DEFAULT');
1063 } else {
1064 $object->client = 3;
1065 }
1066 }
1067 if (GETPOST("type", 'aZ') == 'p') {
1068 $object->client = 2;
1069 }
1070
1071 if (getDolGlobalString('SOCIETE_DISABLE_PROSPECTSCUSTOMERS') && $object->client == 3) {
1072 $object->client = 1;
1073 }
1074
1075 if ((isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && (GETPOST("type") == 'f' || (GETPOST("type") == '' && getDolGlobalString('THIRDPARTY_SUPPLIER_BY_DEFAULT')))) {
1076 $object->fournisseur = 1;
1077 }
1078
1079 $object->name = GETPOST('name', 'alphanohtml');
1080 $object->name_alias = GETPOST('name_alias', 'alphanohtml');
1081 $object->firstname = GETPOST('firstname', 'alphanohtml');
1082 $object->particulier = $private;
1083 $object->prefix_comm = GETPOST('prefix_comm', 'alphanohtml');
1084 //$object->client = GETPOSTINT('client') ? GETPOSTINT('client') : $object->client;
1085
1086 if (empty($duplicate_code_error)) {
1087 $object->code_client = GETPOST('customer_code', 'alpha');
1088 $object->fournisseur = GETPOST('fournisseur') ? GETPOSTINT('fournisseur') : $object->fournisseur;
1089 $object->code_fournisseur = GETPOST('supplier_code', 'alpha');
1090 } else {
1091 setEventMessages($langs->trans('NewCustomerSupplierCodeProposed'), null, 'warnings');
1092 }
1093
1094 $object->address = GETPOST('address', 'alphanohtml');
1095 $object->zip = GETPOST('zipcode', 'alphanohtml');
1096 $object->town = GETPOST('town', 'alphanohtml');
1097 $object->state_id = GETPOSTINT('state_id');
1098
1099 $object->socialnetworks = array();
1100 if (isModEnabled('socialnetworks')) {
1101 foreach ($socialnetworks as $key => $value) {
1102 if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
1103 $object->socialnetworks[$key] = GETPOST($key, 'alphanohtml');
1104 }
1105 }
1106 }
1107
1108 $object->phone = GETPOST('phone', 'alpha');
1109 $object->phone_mobile = (string) GETPOST("phone_mobile", 'alpha');
1110 $object->fax = GETPOST('fax', 'alpha');
1111 $object->email = GETPOST('email', 'email');
1112 $object->url = GETPOST('url', 'url');
1113 $object->capital = GETPOST('capital'); // can be null or 0 or a float value
1114 $paymentTermId = GETPOSTINT('cond_reglement_id'); // can be set by default values on create page and not already in get or post variables
1115 if (empty($paymentTermId) && !GETPOSTISSET('cond_reglement_id')) {
1116 $paymentTermId = getDolGlobalString('MAIN_DEFAULT_PAYMENT_TERM_ID');
1117 }
1118 $object->cond_reglement_id = $paymentTermId;
1119 $paymentTypeId = GETPOSTINT('mode_reglement_id'); // can be set by default values on create page and not already in get or post variables
1120 if (empty($paymentTypeId) && !GETPOSTISSET('mode_reglement_id')) {
1121 $paymentTypeId = getDolGlobalString('MAIN_DEFAULT_PAYMENT_TYPE_ID');
1122 }
1123 $object->mode_reglement_id = $paymentTypeId;
1124 $object->barcode = GETPOST('barcode', 'alphanohtml');
1125 $object->idprof1 = GETPOST('idprof1', 'alphanohtml');
1126 $object->idprof2 = GETPOST('idprof2', 'alphanohtml');
1127 $object->idprof3 = GETPOST('idprof3', 'alphanohtml');
1128 $object->idprof4 = GETPOST('idprof4', 'alphanohtml');
1129 $object->idprof5 = GETPOST('idprof5', 'alphanohtml');
1130 $object->idprof6 = GETPOST('idprof6', 'alphanohtml');
1131 $object->typent_id = GETPOSTINT('typent_id');
1132 $object->effectif_id = GETPOSTINT('effectif_id');
1133 $object->civility_id = GETPOST('civility_id', 'alpha');
1134
1135 $object->tva_assuj = GETPOSTINT('assujtva_value');
1136 $object->vat_reverse_charge = GETPOST('vat_reverse_charge') == 'on' ? 1 : 0;
1137 $object->status = GETPOSTINT('status');
1138
1139 //Local Taxes
1140 $object->localtax1_assuj = GETPOSTINT('localtax1assuj_value');
1141 $object->localtax2_assuj = GETPOSTINT('localtax2assuj_value');
1142
1143 $object->localtax1_value = GETPOST('lt1', 'alpha');
1144 $object->localtax2_value = GETPOST('lt2', 'alpha');
1145
1146 $object->euid = GETPOST('euid', 'alphanohtml');
1147 $object->tva_intra = GETPOST('tva_intra', 'alphanohtml');
1148
1149 $object->commercial_id = GETPOSTINT('commercial_id');
1150 $object->default_lang = GETPOST('default_lang');
1151
1152 if (GETPOSTISSET('accountancy_code_sell')) {
1153 $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
1154
1155 if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') {
1156 $object->accountancy_code_sell = '';
1157 } else {
1158 $object->accountancy_code_sell = $accountancy_code_sell;
1159 }
1160 }
1161 if (GETPOSTISSET('accountancy_code_buy')) {
1162 $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
1163
1164 if (empty($accountancy_code_buy) || $accountancy_code_buy == '-1') {
1165 $object->accountancy_code_buy = '';
1166 } else {
1167 $object->accountancy_code_buy = $accountancy_code_buy;
1168 }
1169 }
1170
1171 $object->logo = (isset($_FILES['photo']) ? dol_sanitizeFileName($_FILES['photo']['name']) : '');
1172
1173 // Company logo management
1174 $dir = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos";
1175 $file_OK = (isset($_FILES['photo']) ? is_uploaded_file($_FILES['photo']['tmp_name']) : false);
1176 if ($file_OK) {
1177 if (image_format_supported($_FILES['photo']['name'])) {
1178 dol_mkdir($dir);
1179
1180 if (@is_dir($dir)) {
1181 $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
1182 $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
1183
1184 // Note: $result is a string when the file was refused and, in PHP 8, such a string compares as greater than 0
1185 if (!is_numeric($result) || $result <= 0) {
1186 $errors[] = "ErrorFailedToSaveFile";
1187 } else {
1188 // Create thumbs
1189 $object->addThumbs($newfile);
1190 }
1191 }
1192 }
1193 }
1194
1195 // We set country_id, country_code and country for the selected country
1196 $object->country_id = GETPOST('country_id') ? GETPOST('country_id') : $mysoc->country_id;
1197 if ($object->country_id) {
1198 $tmparray = getCountry($object->country_id, 'all');
1199 $object->country_code = $tmparray['code'];
1200 $object->country = $tmparray['label'];
1201 }
1202 $object->forme_juridique_code = GETPOSTINT('forme_juridique_code');
1203 $object->birth = dol_mktime(0, 0, 0, GETPOSTINT('birthmonth'), GETPOSTINT('birthday'), GETPOSTINT('birthyear'));
1204
1205 // We set multicurrency_code if enabled
1206 if (isModEnabled("multicurrency")) {
1207 $object->multicurrency_code = GETPOST('multicurrency_code') ? GETPOST('multicurrency_code') : $conf->currency;
1208 }
1209 /* Show create form */
1210
1211 $linkback = "";
1212 print load_fiche_titre($langs->trans("NewThirdParty"), $linkback, 'building');
1213
1214 if (!empty($conf->use_javascript_ajax)) {
1215 // If option to also create a contact
1216 if (getDolGlobalString('THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION')) {
1217 print "\n".'<script type="text/javascript">';
1218 print '$(document).ready(function () {
1219 id_te_private=8;
1220 id_ef15=1;
1221 is_private=' . $private.';
1222 if (is_private) {
1223 $(".individualline").show();
1224 $(".professionalline").hide();
1225 } else {
1226 $(".individualline").hide();
1227 $(".professionalline").show();
1228 }
1229 $("#radiocompany").click(function() {
1230 $(".individualline").hide();
1231 $(".professionalline").show();
1232 $("#typent_id").val(0);
1233 $("#typent_id").change();
1234 $("#effectif_id").val(0);
1235 $("#effectif_id").change();
1236 $("#TypeName").html(document.formsoc.ThirdPartyName.value);
1237 document.formsoc.private.value=0;
1238 });
1239 $("#radioprivate").click(function() {
1240 $(".individualline").show();
1241 $(".professionalline").hide();
1242 $("#typent_id").val(id_te_private);
1243 $("#typent_id").change();
1244 $("#effectif_id").val(id_ef15);
1245 $("#effectif_id").change();
1246 /* Force to recompute the width of a select2 field when it was hidden and then shown programmatically */
1247 if ($("#civility_id").data("select2")) {
1248 $("#civility_id").select2({width: "resolve"});
1249 }
1250 $("#TypeName").html(document.formsoc.LastName.value);
1251 document.formsoc.private.value=1;
1252 });';
1253
1254 if (getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2) {
1255 print '
1256 function init_check_no_email(input) {
1257 if (input.val()!="") {
1258 $(".noemail").addClass("fieldrequired");
1259 } else {
1260 $(".noemail").removeClass("fieldrequired");
1261 }
1262 }
1263 $("#email").keyup(function() {
1264 init_check_no_email($(this));
1265 });
1266 init_check_no_email($("#email"));';
1267 }
1268 print '});';
1269 print '</script>'."\n";
1270
1271 print '<div id="selectthirdpartytype">';
1272 print '<div class="hideonsmartphone float">';
1273 print $langs->trans("ThirdPartyType").': &nbsp; &nbsp; ';
1274 print '</div>';
1275 print '<label for="radiocompany" class="radiocompany">';
1276 print '<input type="radio" id="radiocompany" class="flat" name="private" value="0"'.($private ? '' : ' checked').'>';
1277 print '&nbsp;';
1278 print $langs->trans("CreateThirdPartyOnly");
1279 print '</label>';
1280 print ' &nbsp; &nbsp; ';
1281 print '<label for="radioprivate" class="radioprivate">';
1282 $text = '<input type="radio" id="radioprivate" class="flat" name="private" value="1"'.($private ? ' checked' : '').'>';
1283 $text .= '&nbsp;';
1284 $text .= $langs->trans("CreateThirdPartyAndContact");
1285 $htmltext = $langs->trans("ToCreateContactWithSameName");
1286 print $form->textwithpicto($text, $htmltext, 1, 'help', '', 0, 3);
1287 print '</label>';
1288 print '</div>';
1289 print "<br>\n";
1290 }
1291
1292 print '<script type="text/javascript">';
1293 print '$(document).ready(function () {
1294 var canHaveCustomerCategoryIfNotCustomerProspectSupplier = ' . (!getDolGlobalString('THIRDPARTY_CAN_HAVE_CUSTOMER_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT') ? '0' : '1') . ';
1295
1296 init_customer_categ();
1297 $("#prospectinput, #customerinput").change(function() {
1298 init_customer_categ();
1299 });
1300 function init_customer_categ() {
1301 var iscustomerorprospect = jQuery("#prospectinput").is(":checked") + jQuery("#customerinput").is(":checked");
1302 console.log("is customer or prospect = "+iscustomerorprospect);
1303 if (iscustomerorprospect == 0 && !canHaveCustomerCategoryIfNotCustomerProspectSupplier) {
1304 jQuery(".visibleifcustomer").hide();
1305 } else {
1306 jQuery(".visibleifcustomer").show();
1307 }
1308 }
1309
1310 init_supplier_categ();
1311 $("#supplierinput").change(function() {
1312 init_supplier_categ();
1313 });
1314 function init_supplier_categ() {
1315 var issupplier = jQuery("#supplierinput").is(":checked");
1316 console.log("is supplier = "+issupplier);
1317 if (issupplier == 0) {
1318 jQuery(".visibleifsupplier").hide();
1319 } else {
1320 jQuery(".visibleifsupplier").show();
1321 }
1322 }
1323
1324 $("#selectcountry_id").change(function() {
1325 console.log("selectcountry_id change");
1326 document.formsoc.action.value="create";
1327 document.formsoc.submit();
1328 });
1329 });';
1330 print '</script>'."\n";
1331 }
1332
1333 dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
1334
1335 print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc" autocomplete="off" spellcheck="false">'; // Chrome ignores autocomplete
1336
1337 print '<input type="hidden" name="action" value="add">';
1338 print '<input type="hidden" name="token" value="'.newToken().'">';
1339 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1340 print '<input type="hidden" name="dol_openinpopup" value="'.$dol_openinpopup.'">';
1341 print '<input type="hidden" name="private" value='.$object->particulier.'>';
1342 print '<input type="hidden" name="type" value='.GETPOST("type", 'alpha').'>';
1343 print '<input type="hidden" name="LastName" value="'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName').'">';
1344 print '<input type="hidden" name="ThirdPartyName" value="'.$langs->trans('ThirdPartyName').'">';
1345 if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) {
1346 print '<input type="hidden" name="code_auto" value="1">';
1347 }
1348
1349 print dol_get_fiche_head(array(), 'card', '', 0, '');
1350
1351 // Call Hook tabContentCreateThirdparty
1352 $parameters = array();
1353 // Note that $action and $object may be modified by hook
1354 $reshook = $hookmanager->executeHooks('tabContentCreateThirdparty', $parameters, $object, $action);
1355 if (empty($reshook)) {
1356 print '<table class="border centpercent">';
1357
1358 // Name, firstname
1359 print '<tr class="tr-field-thirdparty-name"><td class="titlefieldcreate">';
1360 if ($object->particulier || $private) {
1361 print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName', 'name').'</span>';
1362 } else {
1363 print '<span id="TypeName" class="fieldrequired">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0).'</span>';
1364 }
1365 print '</td><td colspan="3">';
1366
1367 print '<input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.dolPrintHTMLForAttribute($object->name).'" autofocus="autofocus" spellcheck="false">';
1368 print $form->widgetForTranslation("name", $object, $permissiontoadd, 'string', 'alphanohtml', 'minwidth300'); // For some countries that need the company name in 2 languages
1369 // 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
1370 // 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.
1371 /*
1372 print '<select class="name" name="name" id="name" style="min-width:500px"></select>';
1373 print "\n".'<script type="text/javascript">';
1374 print '$(document).ready(function () {
1375 $("#name").select2({
1376 ajax: {
1377 url: "' . DOL_URL_ROOT . '/core/ajax/ajaxcompanies.php",
1378 dataType: "json",
1379 delay: 250,
1380 data: function (params) {
1381 return {
1382 newcompany: params.term // search term
1383 }
1384 },
1385 processResults: function (data, params) {
1386 return {
1387 results: data
1388 }
1389 },
1390 cache: true
1391 },
1392
1393 placeholder: "' . $langs->trans('Name of the new third party. In the meantime we check if it already exists...') . '",
1394 allowClear: true,
1395 minimumInputLength: 3,
1396 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage,
1397 containerCssClass: ":all:",
1398 selectionCssClass: ":all:",
1399 tags: true,
1400 templateResult: formatCustomer,
1401 templateSelection: formatCustomerSelection
1402 });
1403
1404 function formatCustomer (Customer) {
1405 if(Customer.label === undefined) {
1406 return Customer.text;
1407 }
1408
1409 if(Customer.logo !== null ) {
1410 logo = \'<img src="\';
1411 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";
1412 logo += \'" /></div>\';
1413 } else {
1414 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>\';
1415 }
1416
1417 var $container = $("<div class=\'select2-result-repository clearfix\'>" +
1418 "<div class=\'select2-result-repository__avatar floatleft inline-block valigntop\'>" + logo +
1419 "<div class=\'select2-result-repository__meta floatleft inline-block valigntop\'>" +
1420 "<div class=\'select2-result-repository__title\'></div>" +
1421 "<div class=\'select2-result-repository__name_alias\'></div>" +
1422 "<div class=\'select2-result-repository__code_client\'></div>" +
1423 "<div class=\'select2-result-repository__code_fournisseur\'></div>" +
1424 "<div class=\'select2-result-repository__companies_info\'>" +
1425 "<div class=\'select2-result-repository__email\'><i class=\'fa fa-at\'></i> </div>" +
1426 "<div class=\'select2-result-repository__address\'><i class=\'fa fa-flag\'></i> </div>" +
1427 "<div class=\'select2-result-repository__zip\'><i class=\'fa fa-circle-o\'></i> </div>" +
1428 "<div class=\'select2-result-repository__country\'><i class=\'fa fa-globe-americas\'></i> </div>" +
1429 "<div class=\'select2-result-repository__departement\'><i class=\'fa fa-circle-o\'></i> </div>" +
1430 "<div class=\'select2-result-repository__town\'><i class=\'fa fa-circle-o\'></i> </div>" +
1431 "<div class=\'select2-result-repository__siren\'><i class=\'fa fa-circle-o\'></i> </div>" +
1432 "<div class=\'select2-result-repository__datec\'><i class=\'fa fa-calendar\'></i> </div>" +
1433 "</div>" +
1434 "</div>" +
1435 "</div>"
1436 );
1437
1438 $container.find(".select2-result-repository__title").text(Customer.label);
1439 $container.find(".select2-result-repository__name_alias").text(Customer.name_alias ? Customer.name_alias : "");
1440 $container.find(".select2-result-repository__code_client").text(Customer.code_client ? Customer.code_client : "");
1441 $container.find(".select2-result-repository__code_fournisseur").text((Customer.code_fournisseur!==null) ? Customer.code_fournisseur : "");
1442 $container.find(".select2-result-repository__email").append("' . $langs->trans('EMail') . ': " + (Customer.email !== null ? Customer.email : ""));
1443 $container.find(".select2-result-repository__address").append("' . $langs->trans('Address') . ': " + (Customer.address !== null ? Customer.address : ""));
1444 $container.find(".select2-result-repository__country").append("' . $langs->trans('Country') . ': " + (Customer.country !== null ? Customer.country : ""));
1445 $container.find(".select2-result-repository__departement").append("' . $langs->trans('Region-State') . ': " + (Customer.departement !== null ? Customer.departement : ""));
1446 $container.find(".select2-result-repository__zip").append("' . $langs->trans('Zip') . ': " + (Customer.zip !== null ? Customer.zip : ""));
1447 $container.find(".select2-result-repository__town").append("' . $langs->trans('Town') . ': " + (Customer.town !== null ? Customer.town : ""));
1448 $container.find(".select2-result-repository__siren").append("' . $langs->trans('Siren') . ': " + (Customer.siren !== null ? Customer.siren : ""));
1449 $container.find(".select2-result-repository__datec").append("' . $langs->trans('Created') . ': " + (Customer.datec !== null ? Customer.datec : ""));
1450
1451 return $container;
1452 }
1453
1454 function formatCustomerSelection (selection) {
1455 return selection.label || selection.text;
1456 }
1457 });
1458 </script>
1459 ';
1460 */
1461 print '</td>';
1462 print '</tr>';
1463
1464 // If javascript on, we show option individual
1465 if ($conf->use_javascript_ajax) {
1466 if (getDolGlobalString('THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION')) {
1467 // Firstname
1468 print '<tr class="individualline"><td>'.$form->editfieldkey('FirstName', 'firstname', '', $object, 0).'</td>';
1469 print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="firstname" id="firstname" value="'.dolPrintHTMLForAttribute($object->firstname).'" spellcheck="false"></td>';
1470 print '</tr>';
1471
1472 // Title
1473 print '<tr class="individualline"><td>'.$form->editfieldkey('UserTitle', 'civility_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1474 print $formcompany->select_civility($object->civility_code, 'civility_id', 'maxwidth100').'</td>';
1475 print '</tr>';
1476 }
1477 }
1478
1479 // Alias names (commercial, trademark or alias names)
1480 print '<tr id="name_alias"><td>';
1481 print '<input type="hidden" name="status" value="1">';
1482 print '</td>';
1483 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>';
1484
1485 // Prospect/Customer/Supplier
1486 $selected = $object->client;
1487 $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);
1488 $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);
1489 switch ($selected) {
1490 case 1:
1491 $selectedcustomer = 1;
1492 break;
1493 case 2:
1494 $selectedprospect = 1;
1495 break;
1496 case 3:
1497 $selectedprospect = 1;
1498 $selectedcustomer = 1;
1499 break;
1500 default:
1501 break;
1502 }
1503
1504 $selectedprospect = ((GETPOSTISSET('prospect') && $action == 'create') ? GETPOSTINT('prospect') : $selectedprospect);
1505 $selectedcustomer = ((GETPOSTISSET('customer') && $action == 'create') ? GETPOSTINT('customer') : $selectedcustomer);
1506 $selectedsupplier = ((GETPOSTISSET('supplier') && $action == 'create') ? GETPOSTINT('supplier') : $object->fournisseur);
1507
1508 if ($selectedprospect && $selectedcustomer && getDolGlobalString("SOCIETE_DISABLE_PROSPECTSCUSTOMERS")) {
1509 // If both are not allowed, we reset $selectedcustomer
1510 $selectedcustomer = 0;
1511 }
1512
1513 print '<tr class="marginbottomlarge height50">';
1514 if ($conf->browser->layout != 'phone') {
1515 print '<td class="titlefieldcreate">'.$form->editfieldkey('', 'customerprospect', '', $object, 0, 'string', '', 0).'</td>';
1516 }
1517 print '<td class="maxwidthonsmartphone"'.($conf->browser->layout != 'phone' ? 'colspan="3"' : 'colspan="2"').'>';
1518
1519 if (!getDolGlobalString('SOCIETE_DISABLE_PROSPECTS')) {
1520 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>';
1521 }
1522
1523 if (!getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS')) {
1524 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>';
1525 }
1526
1527 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'))
1528 || (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire'))) {
1529 // Supplier
1530 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>';
1531 }
1532 // Add js to manage the background of nature
1533 if ($conf->use_javascript_ajax) {
1534 print '<script>
1535 function refreshNatureCss() {
1536 jQuery(".spannature").each(function( index ) {
1537 id = $(this).attr("id").split("spannature")[1];
1538 console.log(jQuery("#spannature"+(id)+" .checkforselect").is(":checked"));
1539 if (jQuery("#spannature"+(id)+" .checkforselect").is(":checked")) {
1540 if (id == 1) {
1541 jQuery("#spannature"+(id)).addClass("prospect-back").removeClass("nonature-back");
1542 }
1543 if (id == 2) {
1544 jQuery("#spannature"+(id)).addClass("customer-back").removeClass("nonature-back");
1545 }
1546 if (id == 3) {
1547 jQuery("#spannature"+(id)).addClass("vendor-back").removeClass("nonature-back");
1548 }
1549 } else {
1550 jQuery("#spannature"+(id)).removeClass("prospect-back").removeClass("customer-back").removeClass("vendor-back").addClass("nonature-back");
1551 }
1552 });
1553 }
1554
1555 function manageprospectcustomer(element) {
1556 console.log("We uncheck unwanted values on a nature");
1557 id = $(element).attr("id").split("spannature")[1];
1558 if ( id == 1){
1559 $("#spannature2 .checkforselect").prop("checked", false);
1560 }
1561 if ( id == 2){
1562 $("#spannature1 .checkforselect").prop("checked", false);
1563 }
1564 }
1565
1566 jQuery(".spannature").click(function(){
1567 console.log("We click on a nature");
1568 '.(getDolGlobalString('SOCIETE_DISABLE_PROSPECTSCUSTOMERS') ? 'manageprospectcustomer($(this));' : '').'
1569 refreshNatureCss();
1570 });
1571 refreshNatureCss();
1572 </script>';
1573 }
1574 print '</td>';
1575 print '</tr>';
1576
1577 // Customer code
1578 print '<tr>';
1579 print '<td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
1580 print '<table class="nobordernopadding"><tr><td>';
1581 $tmpcode = $object->code_client ?? '';
1582 if (empty($tmpcode) && !empty($modCodeClient->code_auto)) {
1583 $tmpcode = $modCodeClient->getNextValue($object, 0);
1584 }
1585 print '<input type="text" name="customer_code" id="customer_code" class="maxwidthonsmartphone" value="'.dolPrintHTMLForAttribute($tmpcode).'" maxlength="24" spellcheck="false">';
1586 print '</td><td>';
1587 $s = $modCodeClient->getToolTip($langs, $object, 0);
1588 print $form->textwithpicto('', $s, 1);
1589 print '</td></tr></table>';
1590 print '</td>';
1591
1592 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'))
1593 || (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire'))) {
1594 if ($conf->browser->layout == 'phone') {
1595 print '<td colspan="2"></td>';
1596 print '</tr><tr>';
1597 }
1598 print '<td>'.$form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0).'</td><td>';
1599 print '<table class="nobordernopadding"><tr><td>';
1600 $tmpcode = $object->code_fournisseur ?? '';
1601 if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) {
1602 $tmpcode = $modCodeFournisseur->getNextValue($object, 1);
1603 }
1604 print '<input type="text" name="supplier_code" id="supplier_code" class="maxwidthonsmartphone" value="'.dolPrintHTMLForAttribute($tmpcode).'" maxlength="24">';
1605 print '</td><td>';
1606 $s = $modCodeFournisseur->getToolTip($langs, $object, 1);
1607 print $form->textwithpicto('', $s, 1);
1608 print '</td></tr></table>';
1609 print '</td>';
1610 } else {
1611 print '<td colspan="2"></td>';
1612 }
1613 print '</tr>';
1614
1615 // Status
1616 /* Useless at creation
1617 print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0).'</td><td colspan="3">';
1618 print $form->selectarray('status', array('1' => $langs->trans('InActivity'), '0' => $langs->trans('ActivityCeased')), 1, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
1619 print '</td></tr>';
1620 */
1621
1622 // Default bank account
1623 if (isModEnabled('bank') && getDolGlobalString('THIRDPARTY_SUGGEST_ALSO_BANK_ACCOUNT')) {
1624 print '<tr><td>';
1625 print $langs->trans('DefaultBankAccount');
1626 print '</td>';
1627 print '<td>';
1628 $form->select_comptes(GETPOST('fk_account'), 'fk_account', 0, '', 1);
1629 print "</td>";
1630 print '</tr>';
1631 }
1632
1633 // Barcode
1634 if (isModEnabled('barcode') && getDolGlobalString('BARCODE_USE_ON_THIRDPARTY')) {
1635 print '<tr><td>'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).'</td>';
1636 print '<td colspan="3">';
1637 print img_picto('', 'barcode', 'class="pictofixedwidth"');
1638 print '<input type="text" class="minwidth200 maxwidth300 widthcentpercentminusx" name="barcode" id="barcode" value="'.dolPrintHTMLForAttribute($object->barcode).'">';
1639 print '</td></tr>';
1640 }
1641
1642 print '<tr class="tdsmallheight"><td colspan="4"></td></tr>';
1643
1644 // Address
1645 print '<tr><td class="tdtop">';
1646 print $form->editfieldkey('Address', 'address', '', $object, 0);
1647 print '</td>';
1648 print '<td colspan="3">';
1649 print '<textarea name="address" id="address" class="quatrevingtpercent" rows="'.ROWS_2.'" wrap="soft">';
1650 print dolPrintHTMLForTextArea($object->address);
1651 print '</textarea>';
1652 print $form->widgetForTranslation("address", $object, $permissiontoadd, 'textarea', 'alphanohtml', 'quatrevingtpercent');
1653 print '</td></tr>';
1654
1655 // Zip / Town
1656 print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td>';
1657 print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100');
1658 print '</td>';
1659 if ($conf->browser->layout == 'phone') {
1660 print '</tr><tr>';
1661 }
1662 print '<td class="tdtop">'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td>';
1663 print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth150 quatrevingtpercent');
1664 print $form->widgetForTranslation("town", $object, $permissiontoadd, 'string', 'alphanohtml', 'maxwidth100 quatrevingtpercent');
1665 print '</td></tr>';
1666
1667 // Country
1668 print '<tr><td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1669 print img_picto('', 'country', 'class="pictofixedwidth"');
1670 print $form->select_country((GETPOSTISSET('country_id') ? GETPOST('country_id') : $object->country_id), 'country_id', '', 0, 'minwidth200 maxwidth300 widthcentpercentminusx');
1671 if ($user->admin) {
1672 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1673 }
1674 print '</td></tr>';
1675
1676 // State
1677 if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
1678 if ((getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 || getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 2)) {
1679 print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1680 } else {
1681 print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1682 }
1683
1684 if ($object->country_id) {
1685 print img_picto('', 'state', 'class="pictofixedwidth"');
1686 print $formcompany->select_state($object->state_id, $object->country_code, 'state_id', 'minwidth200 maxwidth300 widthcentpercentminusx');
1687 } else {
1688 print $countrynotdefined;
1689 }
1690 print '</td></tr>';
1691 }
1692
1693 // Phone / Fax
1694 print '<tr><td>'.$form->editfieldkey('Phone', 'phone', '', $object, 0).'</td>';
1695 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>';
1696
1697 if ($conf->browser->layout == 'phone') {
1698 print '</tr><tr>';
1699 }
1700
1701 // Phone mobile
1702 print '<td>'.$form->editfieldkey('PhoneMobile', 'phone_mobile', '', $object, 0).'</td>';
1703 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>';
1704
1705 // Fax
1706 print '<tr>';
1707 print '<td>'.$form->editfieldkey('Fax', 'fax', '', $object, 0).'</td>';
1708 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>';
1709
1710 // URL
1711 print '<tr><td>'.$form->editfieldkey('Web', 'url', '', $object, 0).'</td>';
1712 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>';
1713
1714 // Email
1715 print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', getDolGlobalInt('SOCIETE_EMAIL_MANDATORY')).'</td>';
1716 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>';
1717
1718 // Unsubscribe
1719 if (isModEnabled('mailing')) {
1720 if ($conf->browser->layout == 'phone') {
1721 print '</tr><tr>';
1722 }
1723 if ($conf->use_javascript_ajax && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2) {
1724 print "\n".'<script type="text/javascript">'."\n";
1725 print '$(document).ready(function () {
1726 $("#email").keyup(function() {
1727 console.log("We change email content");
1728 if ($(this).val()!="") {
1729 $(".noemail").addClass("fieldrequired");
1730 } else {
1731 $(".noemail").removeClass("fieldrequired");
1732 }
1733 });
1734 })'."\n";
1735 print '</script>'."\n";
1736 }
1737 if (!GETPOSTISSET("no_email") && !empty($object->email)) {
1738 $result = $object->getNoEmail();
1739 if ($result < 0) {
1740 setEventMessages($object->error, $object->errors, 'errors');
1741 }
1742 }
1743 print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
1744 print '<td>';
1745 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);
1746 print '</td>';
1747 }
1748 print '</tr>';
1749
1750 // Refuse emailing of all contacts
1751 if (isModEnabled('mailing') && getDolGlobalString('THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION')) {
1752 print '<tr>';
1753 if ($conf->browser->layout != 'phone') {
1754 print '<td></td>';
1755 print '<td></td>';
1756 }
1757 print '<td class="individualline noemail">'.$form->editfieldkey($langs->trans('No_Email') .' ('.$langs->trans('Contact').')', 'contact_no_email', '', $object, 0).'</td>';
1758 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>';
1759 print '</tr>';
1760 }
1761
1762 $colspan = ($conf->browser->layout == 'phone' ? 2 : 4);
1763
1764 // Social networks
1765 if (isModEnabled('socialnetworks')) {
1766 $object->showSocialNetwork($socialnetworks, $colspan);
1767
1768 print '<tr><td colspan="'.$colspan.'"><hr></td></tr>';
1769 }
1770
1771 // Prof ids
1772 $i = 1;
1773 $j = 0;
1774 $NBCOLS = ($conf->browser->layout == 'phone' ? 1 : 2);
1775 $NBPROFIDMIN = getDolGlobalInt('THIRDPARTY_MIN_NB_PROF_ID', 2);
1776 $NBPROFIDMAX = getDolGlobalInt('THIRDPARTY_MAX_NB_PROF_ID', 6);
1777 while ($i <= $NBPROFIDMAX) {
1778 $idprof = $langs->transcountry('ProfId'.$i, (string) $object->country_code);
1779 if ($idprof != '-' && ($i <= $NBPROFIDMIN || !empty($langs->tab_translate['ProfId'.$i.$object->country_code]))) {
1780 $key = 'idprof'.$i;
1781
1782 if (($j % $NBCOLS) == 0) {
1783 print '<tr class="professionalline">';
1784 }
1785
1786 $idprof_mandatory = 'SOCIETE_IDPROF'.($i).'_MANDATORY';
1787 print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', (getDolGlobalString($idprof_mandatory) ? 1 : 0)).'</td><td>';
1788
1789 print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
1790 print '</td>';
1791 if (($j % $NBCOLS) == ($NBCOLS - 1)) {
1792 print '</tr>';
1793 }
1794 $j++;
1795 }
1796 $i++;
1797 }
1798 if ($NBCOLS > 1 && ($j % 2 == 1)) {
1799 print '<td colspan="2"></td></tr>';
1800 }
1801
1802 // Vat is used
1803 print '<tr><td><label for="assujtva_value">'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).'</label></td>';
1804 print '<td>';
1805 print '<input id="assujtva_value" name="assujtva_value" type="checkbox" ' . (GETPOSTISSET('assujtva_value') ? (GETPOST('assujtva_value', 'alpha') != '' ? ' checked="checked"' : '') : 'checked="checked"') . ' value="1">'; // Subject to VAT by default at creation
1806 print '</td>';
1807 if ($conf->browser->layout == 'phone') {
1808 print '</tr><tr>';
1809 }
1810 print '<td class="nowrap">'.$form->editfieldkey('VATIntra', 'intra_vat', '', $object, 0).'</td>';
1811 print '<td class="nowrap">';
1812 $s = '<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
1813
1814 if (!getDolGlobalString('MAIN_DISABLEVATCHECK') && isInEEC($object)) {
1815 $s .= ' ';
1816
1817 if (!empty($conf->use_javascript_ajax)) {
1818 $widthpopup = 600;
1819 if (!empty($conf->dol_use_jmobile)) {
1820 $widthpopup = 350;
1821 }
1822 $heightpopup = 400;
1823 print "\n";
1824 print '<script type="text/javascript">';
1825 print "function CheckVAT(a) {\n";
1826 if ($mysoc->country_code == 'GR' && $object->country_code == 'GR' && !empty($u)) {
1827 print "GRVAT(a,'{$u}','{$p}','{$myafm}');\n";
1828 } else {
1829 print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a, '".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
1830 }
1831 print "}\n";
1832 print '</script>';
1833 print "\n";
1834 $s .= '<a href="#" class="hideonsmartphone" onclick="CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
1835 $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1);
1836 } else {
1837 $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", (string) $object->country_id).'" target="_blank" rel="noopener noreferrer">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
1838 }
1839 }
1840 print $s;
1841 print '</td>';
1842 print '</tr>';
1843
1844 // VAT reverse charge by default
1845 if (getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) {
1846 print '<tr><td><label for="vat_reverse_charge">' . $form->editfieldkey('VATReverseChargeByDefault', 'vat_reverse_charge', '', $object, 0, 'string', '', 0, 0, 'id', $langs->trans('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE_DESC')) . '</label></td><td colspan="3">';
1847 print '<input type="checkbox" name="vat_reverse_charge" id="vat_reverse_charge" '.($object->vat_reverse_charge == '1' ? ' checked' : '').'>';
1848 print '</td></tr>';
1849 }
1850
1851 print '<td class="nowrap">'.$form->editfieldkey('EUIDShort', 'euid', '', $object, 0).'</td>';
1852 print '<td class="nowrap">';
1853 print '<input type="text" class="flat maxwidthonsmartphone" name="euid" id="euid" maxlength="20" value="'.$object->euid.'">';
1854 print '</td>';
1855 print '</tr>';
1856
1857 // Local Taxes
1858 // TODO: Place into a function to control showing by country or study better option
1859 if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
1860 print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
1861 print '<input id="localtax1assuj_value" name="localtax1assuj_value" type="checkbox" ' . (getDolGlobalString('THIRDPARTY_DEFAULT_USELOCALTAX1') ? 'checked="checked"' : '') . ' value="1">';
1862 print '</td>';
1863 if ($conf->browser->layout == 'phone') {
1864 print '</tr><tr>';
1865 }
1866 print '<td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
1867 print '<input id="localtax2assuj_value" name="localtax2assuj_value" type="checkbox" ' . (getDolGlobalString('THIRDPARTY_DEFAULT_USELOCALTAX2') ? 'checked="checked"' : '') . ' value="1">';
1868 print '</td></tr>';
1869 } elseif ($mysoc->localtax1_assuj == "1") {
1870 print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td colspan="3">';
1871 print '<input id="localtax1assuj_value" name="localtax1assuj_value" type="checkbox" ' . (getDolGlobalString('THIRDPARTY_DEFAULT_USELOCALTAX1') ? 'checked="checked"' : '') . ' value="1">';
1872 print '</td></tr>';
1873 } elseif ($mysoc->localtax2_assuj == "1") {
1874 print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td colspan="3">';
1875 print '<input id="localtax2assuj_value" name="localtax2assuj_value" type="checkbox" ' . (getDolGlobalString('THIRDPARTY_DEFAULT_USELOCALTAX2') ? 'checked="checked"' : '') . ' value="1">';
1876 print '</td></tr>';
1877 }
1878
1879
1880 print '<tr><td colspan="'.$colspan.'"><hr></td></tr>';
1881
1882 // Categories
1883 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1884 $langs->load('categories');
1885
1886 // Customer
1887 print '<tr class="visibleifcustomer"><td class="toptd">'.$form->editfieldkey('CustomersProspectsCategoriesShort', 'custcats', '', $object, 0).'</td><td colspan="3">';
1888 print $form->selectCategories(Categorie::TYPE_CUSTOMER, 'custcats', $object);
1889 print "</td></tr>";
1890
1891 if (getDolGlobalString('THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION')) {
1892 print '<tr class="individualline"><td class="toptd">'.$form->editfieldkey('ContactCategoriesShort', 'contcats', '', $object, 0).'</td><td colspan="3">';
1893 print $form->selectCategories(Categorie::TYPE_CONTACT, 'contcats', $object);
1894 print "</td></tr>";
1895 }
1896
1897 // Supplier
1898 if (isModEnabled("supplier_proposal") || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
1899 print '<tr class="visibleifsupplier"><td class="toptd">'.$form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0).'</td><td colspan="3">';
1900 print $form->selectCategories(Categorie::TYPE_SUPPLIER, 'suppcats', $object);
1901 print "</td></tr>";
1902 }
1903 }
1904
1905 print '<tr><td colspan="'.$colspan.'"><a class="paddingtop paddingbottom morefieldslnk onreposition" id="morefieldslnk" href="#">'.$langs->trans("More").'';
1906 $nbactive = '...';
1907 print '<span class="badge badge-secondary socialnetworklnk marginleftonly">'.$nbactive.'</span></a>';
1908 print '</td>';
1909 print '</tr>';
1910
1911 // Type - Workforce/Staff
1912 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";
1913 $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.
1914 print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 1, 0, 0, '', 0, 0, 0, $sortparam, '', 1);
1915 if ($user->admin) {
1916 print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1917 }
1918 if (!getDolGlobalString('SOCIETE_DISABLE_WORKFORCE')) {
1919 print '</td>';
1920 if ($conf->browser->layout == 'phone') {
1921 print '</tr><tr class="morefields">';
1922 }
1923 print '<td>'.$form->editfieldkey('Workforce', 'effectif_id', '', $object, 0).'</td><td class="maxwidthonsmartphone"'.($conf->browser->layout == 'phone' ? ' colspan="3"' : '').'>';
1924 print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id, 0, 0, 0, '', 0, 0, 0, '', '', 1);
1925 if ($user->admin) {
1926 print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1927 }
1928 } else {
1929 print '<input type="hidden" name="effectif_id" id="effectif_id" value="'.$object->effectif_id.'">';
1930 }
1931 print '</td></tr>';
1932
1933 // Legal Form
1934 print '<tr class="morefields"><td>'.$form->editfieldkey('JuridicalStatus', 'forme_juridique_code', '', $object, 0).'</td>';
1935 print '<td colspan="3" class="maxwidthonsmartphone">';
1936 if ($object->country_id) {
1937 print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code');
1938 } else {
1939 print $countrynotdefined;
1940 }
1941 print '</td></tr>';
1942
1943 // Date birth
1944 print '<tr class="morefields"><td>'.$form->editfieldkey('CompanyBirthDate', 'birth', '', $object, 0).'</td>';
1945 print '<td colspan="3" class="maxwidthonsmartphone">';
1946 print $form->selectDate($object->birth, 'birth', 0, 0, 1, "", 1);
1947 print '</td></tr>';
1948
1949 // Capital
1950 print '<tr class="morefields"><td>'.$form->editfieldkey('Capital', 'capital', '', $object, 0).'</td>';
1951 print '<td colspan="3"><input type="text" name="capital" id="capital" class="maxwidth100" value="'.((string) $object->capital).'"> ';
1952 if (isModEnabled("multicurrency")) {
1953 print '<span class="hideonsmartphone">';
1954 //print $langs->trans("Currency".$object->multicurrency_code);
1955 print $langs->getCurrencySymbol($object->multicurrency_code);
1956 print '</span></td></tr>';
1957 } else {
1958 print '<span class="hideonsmartphone">';
1959 print $langs->getCurrencySymbol($conf->currency);
1960 //print $langs->trans("Currency".$conf->currency);
1961 print '</span></td></tr>';
1962 }
1963 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1964 print '<tr class="morefields"><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
1965 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');
1966 print '</td>';
1967 print '</tr>';
1968 }
1969
1970 // Payment terms of the settlement
1971 print '<tr class="morefields">';
1972 print '<td>'.$form->editfieldkey('PaymentConditions', 'cond_reglement_id', '', $object, 0).'</td>';
1973 print '<td colspan="3" class="maxwidthonsmartphone">';
1974 print $form->getSelectConditionsPaiements((int) $object->cond_reglement_id, 'cond_reglement_id', 1, 1, 1, '', (float) $object->deposit_percent);
1975 print '</td></tr>';
1976
1977 // Payment mode
1978 print '<tr class="morefields">';
1979 print '<td>'.$form->editfieldkey('PaymentMode', 'mode_reglement_id', '', $object, 0).'</td>';
1980 print '<td colspan="3" class="maxwidthonsmartphone">';
1981 print $form->select_types_paiements((string) $object->mode_reglement_id, 'mode_reglement_id', '', 0, 1, 1, 0, 1);
1982 print '</td></tr>';
1983
1984 // Incoterms
1985 if (isModEnabled('incoterm')) {
1986 print '<tr class="morefields">';
1987 print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
1988 print '<td colspan="3" class="maxwidthonsmartphone">';
1989 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
1990 print '</td></tr>';
1991 }
1992
1993 // Multicurrency
1994 if (isModEnabled("multicurrency")) {
1995 print '<tr class="morefields">';
1996 print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
1997 print '<td colspan="3" class="maxwidthonsmartphone">';
1998 print img_picto('', 'currency', 'class="pictofixedwidth"');
1999 print $form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code') : ($object->multicurrency_code ? $object->multicurrency_code : $conf->currency)), 'multicurrency_code', 1, '', false, 'maxwidth150 widthcentpercentminusx');
2000 print '</td></tr>';
2001 }
2002
2003 // Other attributes
2004 $parameters = array('socid' => $socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
2005 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
2006
2007 // Parent company
2008 if (!getDolGlobalString('SOCIETE_DISABLE_PARENTCOMPANY')) {
2009 print '<tr class="morefields">';
2010 print '<td>'.$langs->trans('ParentCompany').'</td>';
2011 print '<td colspan="3" class="maxwidthonsmartphone">';
2012 print img_picto('', 'company', 'class="pictofixedwidth"');
2013 print $form->select_company(GETPOST('parent_company_id'), 'parent_company_id', '', 'SelectThirdParty', 0, 0, array(), 0, 'minwidth300 maxwidth500 widthcentpercentminusxx');
2014 print '</td></tr>';
2015 }
2016
2017 // Assign a sale representative
2018 print '<tr class="morefields">';
2019 print '<td>'.$form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0).'</td>';
2020 print '<td colspan="3" class="maxwidthonsmartphone">';
2021 // TODO Use select_doluser in multiselect mode
2022 $userlist = $form->select_dolusers($selected, '', 0, null, 0, '', '', '0', 0, 0, 'u.statut:=:1', 0, '', '', 0, 2);
2023 // 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.
2024 $selected = (GETPOSTISARRAY('commercial') ? GETPOST('commercial', 'array:int') : (GETPOSTINT('commercial') > 0 ? array(GETPOSTINT('commercial')) : array($user->id)));
2025 print img_picto('', 'user', 'class="pictofixedwidth"').$form->multiselectarray('commercial', $userlist, $selected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
2026 print '</td></tr>';
2027
2028 // Add logo
2029 print '<tr class="hideonsmartphone morefields"">';
2030 print '<td>'.$form->editfieldkey('Logo', 'photoinput', '', $object, 0).'</td>';
2031 print '<td colspan="3">';
2032 print '<input class="flat" type="file" name="photo" id="photoinput" />';
2033 print '</td>';
2034 print '</tr>';
2035
2036 print '</table>'."\n";
2037
2038 print '<script nonce="'.getNonce().'" type="text/javascript">
2039 $("document").ready(function() { toogleMoreFields(false); });
2040
2041 jQuery(".morefieldslnk").click(function() {
2042 console.log("Click on link .morefieldslnk (create)");
2043 toogleMoreFields(true);
2044 return false;
2045 });
2046
2047 function toogleMoreFields(chgCookieState) {
2048 const lnk = $("#morefieldslnk");
2049 const items = $(".morefields, .trextrafields:not(.trextrafieldsgroup)");
2050 var cookieState = document.cookie.split(";").some((item) => item.trim().startsWith("DOLUSER_MOREFIELDS_SHOW=true")) == true;
2051
2052 if (!chgCookieState) cookieState = !cookieState ;
2053
2054 if (cookieState) {
2055 items.hide();
2056 if (chgCookieState) { document.cookie = "DOLUSER_MOREFIELDS_SHOW=false; SameSite=Strict"};
2057 } else {
2058 items.show();
2059 if (chgCookieState) { document.cookie = "DOLUSER_MOREFIELDS_SHOW=true; SameSite=Strict";}
2060 }
2061 }
2062 </script>
2063 ';
2064
2065 // Accountancy codes
2066 if (getDolGlobalString('ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY')) {
2067 print '<table class="border centpercent">';
2068
2069 if (isModEnabled('accounting')) {
2071 // Accountancy_code_sell
2072 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
2073 print '<td>';
2074 $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
2075 print $formaccounting->select_account($accountancy_code_sell, 'accountancy_code_sell', 1, array(), 1, 1, '');
2076 print '</td></tr>';
2077
2078 // Accountancy_code_buy
2079 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyCode").'</td>';
2080 print '<td>';
2081 $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
2082 print $formaccounting->select_account($accountancy_code_buy, 'accountancy_code_buy', 1, array(), 1, 1, '');
2083 print '</td></tr>';
2084 } else { // For external software
2085 // Accountancy_code_sell
2086 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
2087 print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code_sell" value="'.$object->accountancy_code_sell.'">';
2088 print '</td></tr>';
2089
2090 // Accountancy_code_buy
2091 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyCode").'</td>';
2092 print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code_buy" value="'.$object->accountancy_code_buy.'">';
2093 print '</td></tr>';
2094 }
2095
2096 print '</table>';
2097 }
2098 }
2099
2100 print dol_get_fiche_end();
2101
2102 print $form->buttonsSaveCancel('AddThirdParty', 'Cancel', array(), 0, '', $dol_openinpopup);
2103
2104 print '</form>'."\n";
2105 } elseif ($action == 'edit') {
2106 //print load_fiche_titre($langs->trans("EditCompany"));
2107
2108 if ($socid) {
2109 $res = $object->fetch_optionals();
2110 //if ($res < 0) { dol_print_error($db); exit; }
2111
2112 $head = societe_prepare_head($object);
2113
2114 // Load object modCodeTiers
2115 $module = getDolGlobalString('SOCIETE_CODECLIENT_ADDON', 'mod_codeclient_leopard');
2116 if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
2117 $module = substr($module, 0, dol_strlen($module) - 4);
2118 }
2119 $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2120 foreach ($dirsociete as $dirroot) {
2121 $res = dol_include_once($dirroot.$module.'.php');
2122 if ($res) {
2123 break;
2124 }
2125 }
2126 $modCodeClient = new $module($db);
2127 '@phan-var-force ModeleThirdPartyCode $modCodeClient';
2128 // We check if the prefix tag is used
2129 if ($modCodeClient->code_auto) {
2130 $prefixCustomerIsUsed = $modCodeClient->verif_prefixIsUsed();
2131 } else {
2132 $prefixCustomerIsUsed = false;
2133 }
2134 $module = getDolGlobalString('SOCIETE_CODECLIENT_ADDON');
2135 if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
2136 $module = substr($module, 0, dol_strlen($module) - 4);
2137 }
2138 $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2139 foreach ($dirsociete as $dirroot) {
2140 $res = dol_include_once($dirroot.$module.'.php');
2141 if ($res) {
2142 break;
2143 }
2144 }
2145 $modCodeFournisseur = new $module($db);
2146 '@phan-var-force ModeleThirdPartyCode $modCodeFournisseur';
2147 // We check if the prefix tag is used
2148 if ($modCodeFournisseur->code_auto) {
2149 $prefixSupplierIsUsed = $modCodeFournisseur->verif_prefixIsUsed();
2150 } else {
2151 $prefixSupplierIsUsed = false;
2152 }
2153
2154 $object->oldcopy = clone $object; // @phan-suppress-current-line PhanTypeMismatchProperty
2155
2156 if (GETPOSTISSET('name')) {
2157 // We overwrite with values if posted
2158 $object->name = GETPOST('name', 'alphanohtml');
2159 $object->name_alias = GETPOST('name_alias', 'alphanohtml');
2160 $object->prefix_comm = GETPOST('prefix_comm', 'alphanohtml');
2161 $object->client = GETPOSTINT('client');
2162 $object->code_client = GETPOST('customer_code', 'alpha');
2163 $object->fournisseur = GETPOSTINT('fournisseur');
2164 $object->code_fournisseur = GETPOST('supplier_code', 'alpha');
2165 $object->address = GETPOST('address', 'alphanohtml');
2166 $object->zip = GETPOST('zipcode', 'alphanohtml');
2167 $object->town = GETPOST('town', 'alphanohtml');
2168 $object->country_id = GETPOST('country_id') ? GETPOSTINT('country_id') : $mysoc->country_id;
2169 $object->state_id = GETPOSTINT('state_id');
2170 $object->parent = GETPOSTINT('parent_company_id');
2171
2172 $object->socialnetworks = array();
2173 if (isModEnabled('socialnetworks')) {
2174 foreach ($socialnetworks as $key => $value) {
2175 if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
2176 $object->socialnetworks[$key] = GETPOST($key, 'alphanohtml');
2177 }
2178 }
2179 }
2180
2181 $object->phone = GETPOST('phone', 'alpha');
2182 $object->phone_mobile = (string) GETPOST('phone_mobile', 'alpha');
2183 $object->fax = GETPOST('fax', 'alpha');
2184 $object->email = GETPOST('email', 'email');
2185 $object->no_email = GETPOSTINT("no_email");
2186 $object->url = GETPOST('url', 'url');
2187 $object->capital = GETPOST('capital'); // Can be null or 0 or a float value
2188 $object->idprof1 = GETPOST('idprof1', 'alphanohtml');
2189 $object->idprof2 = GETPOST('idprof2', 'alphanohtml');
2190 $object->idprof3 = GETPOST('idprof3', 'alphanohtml');
2191 $object->idprof4 = GETPOST('idprof4', 'alphanohtml');
2192 $object->idprof5 = GETPOST('idprof5', 'alphanohtml');
2193 $object->idprof6 = GETPOST('idprof6', 'alphanohtml');
2194 $object->typent_id = GETPOSTINT('typent_id');
2195 $object->effectif_id = GETPOSTINT('effectif_id');
2196 $object->barcode = GETPOST('barcode', 'alphanohtml');
2197 $object->forme_juridique_code = GETPOSTINT('forme_juridique_code');
2198 $object->default_lang = GETPOST('default_lang', 'alpha');
2199
2200 $object->tva_assuj = GETPOSTINT('assujtva_value');
2201 $object->vat_reverse_charge = GETPOST('vat_reverse_charge') == 'on' ? 1 : 0;
2202 $object->euid = GETPOST('euid', 'alphanohtml');
2203 $object->tva_intra = GETPOST('tva_intra', 'alphanohtml');
2204 $object->status = GETPOSTINT('status');
2205
2206 // Webservices url/key
2207 $object->webservices_url = GETPOST('webservices_url', 'url');
2208 $object->webservices_key = GETPOST('webservices_key', 'password');
2209
2210 if (GETPOSTISSET('accountancy_code_sell')) {
2211 $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
2212
2213 if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') {
2214 $object->accountancy_code_sell = '';
2215 } else {
2216 $object->accountancy_code_sell = $accountancy_code_sell;
2217 }
2218 }
2219 if (GETPOSTISSET('accountancy_code_buy')) {
2220 $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
2221
2222 if (empty($accountancy_code_buy) || $accountancy_code_buy == '-1') {
2223 $object->accountancy_code_buy = '';
2224 } else {
2225 $object->accountancy_code_buy = $accountancy_code_buy;
2226 }
2227 }
2228
2229 //Incoterms
2230 if (isModEnabled('incoterm')) {
2231 $object->fk_incoterms = GETPOSTINT('incoterm_id');
2232 $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
2233 }
2234
2235 //Local Taxes
2236 $object->localtax1_assuj = GETPOSTINT('localtax1assuj_value');
2237 $object->localtax2_assuj = GETPOSTINT('localtax2assuj_value');
2238
2239 $object->localtax1_value = GETPOST('lt1');
2240 $object->localtax2_value = GETPOST('lt2');
2241
2242 // We set country_id, and country_code label of the chosen country
2243 if ($object->country_id > 0) {
2244 $tmparray = getCountry($object->country_id, 'all');
2245 $object->country_code = $tmparray['code'];
2246 $object->country = $tmparray['label'];
2247 }
2248
2249 // We set multicurrency_code if enabled
2250 if (isModEnabled("multicurrency")) {
2251 $object->multicurrency_code = GETPOST('multicurrency_code') ? GETPOST('multicurrency_code') : $object->multicurrency_code;
2252 }
2253 }
2254
2255 if ($object->localtax1_assuj == 0) {
2256 $sub = 0;
2257 } else {
2258 $sub = 1;
2259 }
2260 if ($object->localtax2_assuj == 0) {
2261 $sub2 = 0;
2262 } else {
2263 $sub2 = 1;
2264 }
2265
2266 if (!empty($conf->use_javascript_ajax)) {
2267 print "\n".'<script type="text/javascript">';
2268 print '$(document).ready(function () {
2269 var val='.$sub.';
2270 var val2='.$sub2.';
2271 if("#localtax1assuj_value".value==undefined){
2272 if(val==1){
2273 $(".cblt1").show();
2274 }else{
2275 $(".cblt1").hide();
2276 }
2277 }
2278 if("#localtax2assuj_value".value==undefined){
2279 if(val2==1){
2280 $(".cblt2").show();
2281 }else{
2282 $(".cblt2").hide();
2283 }
2284 }
2285 $("#localtax1assuj_value").change(function() {
2286 var value=document.getElementById("localtax1assuj_value").value;
2287 if(value==1){
2288 $(".cblt1").show();
2289 }else{
2290 $(".cblt1").hide();
2291 }
2292 });
2293 $("#localtax2assuj_value").change(function() {
2294 var value=document.getElementById("localtax2assuj_value").value;
2295 if(value==1){
2296 $(".cblt2").show();
2297 }else{
2298 $(".cblt2").hide();
2299 }
2300 });
2301
2302 var canHaveCustomerCategoryIfNotCustomerProspect = ' . (getDolGlobalInt('THIRDPARTY_CAN_HAVE_CUSTOMER_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT') ? '1' : '0') . ';
2303
2304 init_customer_categ();
2305 $("#prospectinput, #customerinput").change(function() {
2306 init_customer_categ();
2307 });
2308 function init_customer_categ() {
2309 var iscustomerorprospect = jQuery("#prospectinput").is(":checked") + jQuery("#customerinput").is(":checked");
2310 console.log("is customer or prospect = "+iscustomerorprospect);
2311 if (iscustomerorprospect == 0 && !canHaveCustomerCategoryIfNotCustomerProspect) {
2312 jQuery(".visibleifcustomer").hide();
2313 } else {
2314 jQuery(".visibleifcustomer").show();
2315 }
2316 }
2317
2318 init_supplier_categ();
2319 $("#supplierinput").change(function() {
2320 init_supplier_categ();
2321 });
2322 function init_supplier_categ() {
2323 var issupplier = jQuery("#supplierinput").is(":checked");
2324 console.log("is supplier = "+issupplier);
2325 if (issupplier == 0) {
2326 jQuery(".visibleifsupplier").hide();
2327 } else {
2328 jQuery(".visibleifsupplier").show();
2329 }
2330 }
2331
2332 $("#selectcountry_id").change(function() {
2333 console.log("selectcountry_id change");
2334 document.formsoc.action.value="edit";
2335 document.formsoc.submit();
2336 });
2337
2338 })';
2339 print '</script>'."\n";
2340 }
2341
2342 print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="post" name="formsoc">';
2343 print '<input type="hidden" name="action" value="update">';
2344 print '<input type="hidden" name="token" value="'.newToken().'">';
2345 print '<input type="hidden" name="socid" value="'.$object->id.'">';
2346 print '<input type="hidden" name="entity" value="'.$object->entity.'">';
2347 if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) {
2348 print '<input type="hidden" name="code_auto" value="1">';
2349 }
2350
2351
2352 print dol_get_fiche_head($head, 'card', $langs->trans("ThirdParty"), 0, 'company');
2353
2354 print '<div class="fichecenter2">';
2355
2356 // Call Hook tabContentEditThirdparty
2357 $parameters = array();
2358 // Note that $action and $object may be modified by hook
2359 $reshook = $hookmanager->executeHooks('tabContentEditThirdparty', $parameters, $object, $action);
2360 if (empty($reshook)) {
2361 print '<table class="border centpercent">';
2362
2363 // Ref/ID
2364 if (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
2365 print '<tr><td class="titlefieldcreate">'.$langs->trans("ID").'</td><td colspan="3">';
2366 print $object->id;
2367 print '</td></tr>';
2368 }
2369
2370 // Name
2371 print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0, 'string', '', 1).'</td>';
2372 print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.dolPrintHTMLForAttribute($object->name).'" autofocus="autofocus" spellcheck="false">';
2373 print $form->widgetForTranslation("name", $object, (int) $permissiontoadd, 'string', 'alphanohtml', 'minwidth300');
2374 print '</td></tr>';
2375
2376 // Alias names (commercial, trademark or alias names)
2377 print '<tr id="name_alias"><td>';
2378 //print '<label for="name_alias_input">'.$langs->trans('AliasNames').'</label>';
2379 print '</td>';
2380 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>';
2381
2382 // Prospect/Customer/Supplier
2383 $selected = $object->client;
2384 $selectedcustomer = 0;
2385 $selectedprospect = 0;
2386 switch ($selected) {
2387 case 1:
2388 $selectedcustomer = 1;
2389 break;
2390 case 2:
2391 $selectedprospect = 1;
2392 break;
2393 case 3:
2394 $selectedprospect = 1;
2395 $selectedcustomer = 1;
2396 break;
2397 default:
2398 break;
2399 }
2400
2401 // Nature of thirdparty
2402 $selectedprospect = (GETPOSTISSET('prospect') ? GETPOSTINT('prospect') : $selectedprospect);
2403 $selectedcustomer = (GETPOSTISSET('customer') ? GETPOSTINT('customer') : $selectedcustomer);
2404 print '<tr class="marginbottomlarge height50">';
2405 if ($conf->browser->layout != 'phone') {
2406 print '<td class="titlefieldcreate">'.$form->editfieldkey('', 'customerprospect', '', $object, 0, 'string', '', 0).'</td>';
2407 }
2408 print '<td class="maxwidthonsmartphone"'.($conf->browser->layout != 'phone' ? 'colspan="3"' : 'colspan="2"').'>';
2409
2410 if (!getDolGlobalString('SOCIETE_DISABLE_PROSPECTS')) {
2411 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>';
2412 }
2413
2414 if (!getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS')) {
2415 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>';
2416 }
2417 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'))
2418 || (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire'))) {
2419 // Supplier
2420 $selected = (GETPOSTISSET('supplier') ? GETPOSTINT('supplier') : $object->fournisseur);
2421 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>';
2422 }
2423
2424 // Add js to manage the background of nature
2425 if ($conf->use_javascript_ajax) {
2426 print '<script>
2427 function refreshNatureCss() {
2428 jQuery(".spannature").each(function( index ) {
2429 id = $(this).attr("id").split("spannature")[1];
2430 console.log("id="+id+" "+jQuery("#spannature"+(id)+" .checkforselect").is(":checked"));
2431 if (jQuery("#spannature"+(id)+" .checkforselect").is(":checked")) {
2432 if (id == 1) {
2433 jQuery("#spannature"+(id)).addClass("prospect-back").removeClass("nonature-back");
2434 }
2435 if (id == 2) {
2436 jQuery("#spannature"+(id)).addClass("customer-back").removeClass("nonature-back");
2437 }
2438 if (id == 3) {
2439 jQuery("#spannature"+(id)).addClass("vendor-back").removeClass("nonature-back");
2440 }
2441 } else {
2442 jQuery("#spannature"+(id)).removeClass("prospect-back").removeClass("customer-back").removeClass("vendor-back").addClass("nonature-back");
2443 }
2444 })
2445 }
2446
2447 function manageprospectcustomer(element) {
2448 console.log("We uncheck unwanted values on a nature");
2449 id = $(element).attr("id").split("spannature")[1];
2450 if ( id == 1){
2451 $("#spannature2 .checkforselect").prop("checked", false);
2452 }
2453 if ( id == 2){
2454 $("#spannature1 .checkforselect").prop("checked", false);
2455 }
2456 }
2457
2458 jQuery(".spannature").click(function(){
2459 console.log("We click on a nature");
2460 '.(getDolGlobalString('SOCIETE_DISABLE_PROSPECTSCUSTOMERS') ? 'manageprospectcustomer($(this));' : '').'
2461 refreshNatureCss();
2462 });
2463 refreshNatureCss();
2464 </script>';
2465 }
2466 print '</td>';
2467 print '</tr>';
2468
2469 $colspan = 0;
2470 if ($conf->browser->layout == 'phone') {
2471 $colspan = 3;
2472 }
2473
2474 print '<tr><td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td'.($colspan ? ' colspan="'.$colspan.'"': '').'>';
2475 print '<table class="nobordernopadding"><tr><td>';
2476 $tmpcode = $object->code_client ?? '';
2477 if (empty($tmpcode) && !empty($modCodeClient->code_auto)) {
2478 $tmpcode = $modCodeClient->getNextValue($object, 0);
2479 }
2480 print '<input type="text" name="customer_code" id="customer_code" class="maxwidthonsmartphone" value="'.dolPrintHTMLForAttribute($tmpcode).'" maxlength="24">';
2481 print '</td><td>';
2482 $s = $modCodeClient->getToolTip($langs, $object, 0);
2483 print $form->textwithpicto('', $s, 1);
2484 print '</td></tr></table>';
2485 print '</td>';
2486
2487 if ($conf->browser->layout == 'phone') {
2488 print '</tr><tr>';
2489 }
2490
2491 print '<td>'.$form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0).'</td><td'.($colspan ? ' colspan="'.$colspan.'"': '').'>';
2492
2493 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'))) {
2494 print '<table class="nobordernopadding"><tr><td>';
2495 $tmpcode = $object->code_fournisseur ?? '';
2496 if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) {
2497 $tmpcode = $modCodeFournisseur->getNextValue($object, 1);
2498 }
2499 print '<input type="text" name="supplier_code" id="supplier_code" class="maxwidthonsmartphone" value="'.dolPrintHTMLForAttribute($tmpcode).'" maxlength="24">';
2500 print '</td><td>';
2501 $s = $modCodeFournisseur->getToolTip($langs, $object, 1);
2502 print $form->textwithpicto('', $s, 1);
2503 print '</td></tr></table>';
2504 }
2505 print '</td></tr>';
2506
2507 if (isModEnabled('bank') && getDolGlobalString('THIRDPARTY_SUGGEST_ALSO_BANK_ACCOUNT')) {
2508 // TODO
2509 // Allow to edit field default bank account like we can in creation mode
2510 }
2511
2512 // Barcode
2513 if (isModEnabled('barcode') && getDolGlobalString('BARCODE_USE_ON_THIRDPARTY')) {
2514 print '<tr><td class="tdtop">'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).'</td>';
2515 print '<td colspan="3">';
2516 print img_picto('', 'barcode', 'class="pictofixedwidth"');
2517 print '<input type="text" class="minwidth100 maxwidth200 widthcentpercentminusx" name="barcode" id="barcode" value="'.dolPrintHTMLForAttribute($object->barcode).'" spellcheck="false">';
2518 print '</td></tr>';
2519 }
2520
2521 // Status
2522 print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0).'</td><td'.($conf->browser->layout == 'phone' ? '' : ' colspan="3"').'>';
2523 print $form->selectarray('status', array('0' => $langs->trans('ActivityCeased'), '1' => $langs->trans('InActivity')), $object->status, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
2524 print '</td></tr>';
2525
2526 //$colspan = ($conf->browser->layout == 'phone' ? 2 : 4);
2527 $colspan = 4;
2528 print '<tr class="tdsmallheight"><td colspan="'.$colspan.'"></td></tr>';
2529
2530 // Address
2531 print '<tr><td class="tdtop">'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
2532 print '<td colspan="3"><textarea name="address" id="address" class="quatrevingtpercent" rows="3" wrap="soft" spellcheck="false">';
2533 print dolPrintHTMLForTextArea($object->address);
2534 print '</textarea>';
2535 print $form->widgetForTranslation("address", $object, (int) $permissiontoadd, 'textarea', 'alphanohtml', 'quatrevingtpercent');
2536 print '</td></tr>';
2537
2538 // Zip / Town
2539 print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td'.($conf->browser->layout == 'phone' ? ' colspan="3"' : '').'>';
2540 print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100');
2541 print '</td>';
2542 if ($conf->browser->layout == 'phone') {
2543 print '</tr><tr>';
2544 }
2545 print '<td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td'.($conf->browser->layout == 'phone' ? ' colspan="3"' : '').'>';
2546 print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
2547 print $form->widgetForTranslation("town", $object, (int) $permissiontoadd, 'string', 'alphanohtml', 'maxwidth100 quatrevingtpercent');
2548 print '</td></tr>';
2549
2550 // Country
2551 print '<tr><td>'.$form->editfieldkey('Country', 'selectcounty_id', '', $object, 0).'</td><td colspan="3">';
2552 print img_picto('', 'globe-americas', 'class="pictofixedwidth"');
2553 print $form->select_country((GETPOSTISSET('country_id') ? GETPOST('country_id') : $object->country_id), 'country_id', '', 0, 'minwidth200 maxwidth400 widthcentpercentminusx');
2554 if ($user->admin) {
2555 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
2556 }
2557 print '</td></tr>';
2558
2559 // State
2560 if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
2561 if ((getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 || getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 2)) {
2562 print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td colspan="3">';
2563 } else {
2564 print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td colspan="3">';
2565 }
2566
2567 print img_picto('', 'state', 'class="pictofixedwidth"');
2568 print $formcompany->select_state($object->state_id, $object->country_code, 'state_id', 'minwidth200 maxwidth400 widthcentpercentminusx');
2569 print '</td></tr>';
2570 }
2571
2572 // Phone / Fax
2573 print '<tr><td>'.$form->editfieldkey('Phone', 'phone', GETPOST('phone', 'alpha'), $object, 0).'</td>';
2574 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>';
2575 if ($conf->browser->layout == 'phone') {
2576 print '</tr><tr>';
2577 }
2578 print '<td>'.$form->editfieldkey('PhoneMobile', 'phone_mobile', GETPOST('phone_mobile', 'alpha'), $object, 0).'</td>';
2579 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>';
2580
2581 print '<td>'.$form->editfieldkey('Fax', 'fax', GETPOST('fax', 'alpha'), $object, 0).'</td>';
2582 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>';
2583 print '</tr>';
2584
2585 // Web
2586 print '<tr><td>'.$form->editfieldkey('Web', 'url', GETPOST('url', 'alpha'), $object, 0).'</td>';
2587 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>';
2588
2589 // EMail
2590 print '<tr><td>'.$form->editfieldkey('EMail', 'email', GETPOST('email', 'alpha'), $object, 0, 'string', '', (getDolGlobalInt('SOCIETE_EMAIL_MANDATORY'))).'</td>';
2591 print '<td'.(($conf->browser->layout == 'phone') || !isModEnabled('mailing') ? ' colspan="3"' : '').'>';
2592 print img_picto('', 'object_email', 'class="pictofixedwidth"');
2593 print '<input type="text" name="email" id="email" class="maxwidth500 widthcentpercentminusx" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alpha') : $object->email).'" spellcheck="false">';
2594 print '</td>';
2595
2596 // Unsubscribe
2597 if (isModEnabled('mailing')) {
2598 if ($conf->browser->layout == 'phone') {
2599 print '</tr><tr>';
2600 }
2601 if ($conf->use_javascript_ajax && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2) {
2602 print "\n".'<script type="text/javascript">'."\n";
2603
2604 print '
2605 jQuery(document).ready(function () {
2606 function init_check_no_email(input) {
2607 if (input.val()!="") {
2608 $(".noemail").addClass("fieldrequired");
2609 } else {
2610 $(".noemail").removeClass("fieldrequired");
2611 }
2612 }
2613 $("#email").keyup(function() {
2614 init_check_no_email($(this));
2615 });
2616 init_check_no_email($("#email"));
2617 })'."\n";
2618 print '</script>'."\n";
2619 }
2620 if (!GETPOSTISSET("no_email") && !empty($object->email)) {
2621 $result = $object->getNoEmail();
2622 if ($result < 0) {
2623 setEventMessages($object->error, $object->errors, 'errors');
2624 }
2625 }
2626 print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
2627 print '<td>';
2628 $useempty = (int) (getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2);
2629 print $form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOSTINT("no_email") : $object->no_email), 1, 0, $useempty);
2630 print '</td>';
2631 }
2632 print '</tr>';
2633
2634 // Social network
2635 if (isModEnabled('socialnetworks')) {
2636 //$colspan = ($conf->browser->layout == 'phone' ? 2 : 4);
2637 $colspan = 4;
2638
2639 $object->showSocialNetwork($socialnetworks, $colspan);
2640
2641 print '<tr><td colspan="'.$colspan.'"><hr></td></tr>';
2642 }
2643
2644 // Prof ids
2645 $i = 1;
2646 $j = 0;
2647 $NBCOLS = ($conf->browser->layout == 'phone' ? 1 : 2);
2648 $NBPROFIDMIN = getDolGlobalInt('THIRDPARTY_MIN_NB_PROF_ID', 2);
2649 $NBPROFIDMAX = getDolGlobalInt('THIRDPARTY_MAX_NB_PROF_ID', 6);
2650 while ($i <= $NBPROFIDMAX) {
2651 $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
2652 if ($idprof != '-' && ($i <= $NBPROFIDMIN || !empty($langs->tab_translate['ProfId'.$i.$object->country_code]))) {
2653 $key = 'idprof'.$i;
2654
2655 if (($j % $NBCOLS) == 0) {
2656 print '<tr>';
2657 }
2658
2659 $idprof_mandatory = 'SOCIETE_IDPROF'.($i).'_MANDATORY';
2660 print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', (int) (getDolGlobalString($idprof_mandatory) && $object->isACompany())).'</td><td>';
2661 print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
2662 print '</td>';
2663 if (($j % $NBCOLS) == ($NBCOLS - 1)) {
2664 print '</tr>';
2665 }
2666 $j++;
2667 }
2668 $i++;
2669 }
2670 if ($NBCOLS > 0 && ($j % 2) == 1) {
2671 print '<td colspan="2"></td></tr>';
2672 }
2673
2674 // VAT is used
2675 print '<tr><td>'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).'</td><td colspan="3">';
2676 print '<input id="assujtva_value" name="assujtva_value" type="checkbox" ' . ($object->tva_assuj ? 'checked="checked"' : '') . ' value="1">';
2677 print '</td></tr>';
2678
2679 // Local Taxes
2680 //TODO: Place into a function to control showing by country or study better option
2681 if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
2682 print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td>';
2683 print '<input id="localtax1assuj_value" name="localtax1assuj_value" type="checkbox" ' . ($object->localtax1_assuj ? 'checked="checked"' : '') . ' value="1">';
2684 if (!isOnlyOneLocalTax(1)) {
2685 print '<span class="cblt1"> '.$langs->transcountry("Type", $mysoc->country_code).': ';
2686 $formcompany->select_localtax(1, (float) $object->localtax1_value, "lt1");
2687 print '</span>';
2688 }
2689 print '</td>';
2690 print '</tr><tr>';
2691 print '<td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td>';
2692 print '<input id="localtax2assuj_value" name="localtax2assuj_value" type="checkbox" ' . ($object->localtax2_assuj ? 'checked="checked"' : '') . ' value="1"></td></tr>';
2693 if (!isOnlyOneLocalTax(2)) {
2694 print '<span class="cblt2"> '.$langs->transcountry("Type", $mysoc->country_code).': ';
2695 $formcompany->select_localtax(2, (float) $object->localtax2_value, "lt2");
2696 print '</span>';
2697 }
2698 print '</td></tr>';
2699 } elseif ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj != "1") {
2700 print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td colspan="3">';
2701 print '<input id="localtax1assuj_value" name="localtax1assuj_value" type="checkbox" ' . ($object->localtax1_assuj ? 'checked="checked"' : '') . ' value="1">';
2702 if (!isOnlyOneLocalTax(1)) {
2703 print '<span class="cblt1"> '.$langs->transcountry("Type", $mysoc->country_code).': ';
2704 $formcompany->select_localtax(1, (float) $object->localtax1_value, "lt1");
2705 print '</span>';
2706 }
2707 print '</td></tr>';
2708 } elseif ($mysoc->localtax2_assuj == "1" && $mysoc->localtax1_assuj != "1") {
2709 print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td colspan="3">';
2710 print '<input id="localtax2assuj_value" name="localtax2assuj_value" type="checkbox" ' . ($object->localtax2_assuj ? 'checked="checked"' : '') . ' value="1">';
2711 if (!isOnlyOneLocalTax(2)) {
2712 print '<span class="cblt2"> '.$langs->transcountry("Type", $mysoc->country_code).': ';
2713 $formcompany->select_localtax(2, (float) $object->localtax2_value, "lt2");
2714 print '</span>';
2715 }
2716 print '</td></tr>';
2717 }
2718
2719 // VAT reverse charge by default
2720 if (getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) {
2721 print '<tr><td>' . $form->editfieldkey('VATReverseChargeByDefault', 'vat_reverse_charge', '', $object, 0) . '</td><td colspan="3">';
2722 print '<input type="checkbox" name="vat_reverse_charge" '.($object->vat_reverse_charge == '1' ? ' checked' : '').'>';
2723 print '</td></tr>';
2724 }
2725
2726 // VAT Code
2727 print '<tr><td>'.$form->editfieldkey('VATIntra', 'intra_vat', '', $object, 0).'</td>';
2728 print '<td colspan="3">';
2729 $s = '<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
2730
2731 if (!getDolGlobalString('MAIN_DISABLEVATCHECK') && isInEEC($object)) {
2732 $s .= ' &nbsp; ';
2733
2734 if ($conf->use_javascript_ajax) {
2735 $widthpopup = 600;
2736 if (!empty($conf->dol_use_jmobile)) {
2737 $widthpopup = 350;
2738 }
2739 $heightpopup = 400;
2740 print "\n";
2741 print '<script type="text/javascript">';
2742 print "function CheckVAT(a) {\n";
2743 if ($mysoc->country_code == 'GR' && $object->country_code == 'GR' && !empty($u)) {
2744 print "GRVAT(a,'{$u}','{$p}','{$myafm}');\n";
2745 } else {
2746 print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a, '".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
2747 }
2748 print "}\n";
2749 print '</script>';
2750 print "\n";
2751 $s .= '<a href="#" class="hideonsmartphone" onclick="CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
2752 $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1);
2753 } else {
2754 $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", (string) $object->country_id).'" class="hideonsmartphone" target="_blank" rel="noopener noreferrer">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
2755 }
2756 }
2757 print $s;
2758 print '</td>';
2759 print '</tr>';
2760
2761 print '<tr><td>'.$form->editfieldkey('EUIDShort', 'euid', '', $object, 0).'</td>';
2762 print '<td colspan="3">';
2763 print '<input type="text" class="flat maxwidthonsmartphone" name="euid" id="euid" maxlength="20" value="'.$object->euid.'">';
2764 print '</td>';
2765 print '</tr>';
2766
2767
2768 $colspan = 4;
2769
2770 print '<tr><td colspan="'.$colspan.'"><hr></td></tr>';
2771
2772 // Categories
2773 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
2774 // Customer
2775 print '<tr class="visibleifcustomer"><td>'.$form->editfieldkey('CustomersCategoriesShort', 'custcats', '', $object, 0).'</td>';
2776 print '<td colspan="3">';
2777 print $form->selectCategories(Categorie::TYPE_CUSTOMER, 'custcats', $object);
2778 print "</td></tr>";
2779
2780 // Supplier
2781 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'))) {
2782 print '<tr class="visibleifsupplier"><td>'.$form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0).'</td>';
2783 print '<td colspan="3">';
2784 print $form->selectCategories(Categorie::TYPE_SUPPLIER, 'suppcats', $object);
2785 print "</td></tr>";
2786 }
2787 }
2788
2789 print '<tr><td colspan="'.$colspan.'"><br><a class="paddingtop paddingbottom morefieldslnk onreposition" id="morefieldslnk" href="#">'.$langs->trans("More").'';
2790 $nbactive = '...';
2791 print '<span class="badge badge-secondary socialnetworklnk marginleftonly">'.$nbactive.'</span></a>';
2792 print '</td>';
2793 print '</tr>';
2794
2795 // Type - Workforce/Staff
2796 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"' : '').'>';
2797 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);
2798 if ($user->admin) {
2799 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
2800 }
2801 if (!getDolGlobalString('SOCIETE_DISABLE_WORKFORCE')) {
2802 print '</td>';
2803 if ($conf->browser->layout == 'phone') {
2804 print '</tr><tr class="morefields">';
2805 }
2806 print '<td>'.$form->editfieldkey('Workforce', 'effectif_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
2807 print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id, 0, 0, 0, '', 0, 0, 0, '', '', 1);
2808 if ($user->admin) {
2809 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
2810 }
2811 } else {
2812 print '<input type="hidden" name="effectif_id" id="effectif_id" value="'.$object->effectif_id.'">';
2813 }
2814 print '</td></tr>';
2815
2816 // Juridical type
2817 print '<tr class="morefields"><td>'.$form->editfieldkey('JuridicalStatus', 'forme_juridique_code', '', $object, 0).'</td>';
2818 print '<td class="maxwidthonsmartphone" colspan="3">';
2819 print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code');
2820 print '</td></tr>';
2821
2822 // Date birth
2823 print '<tr class="morefields"><td>'.$form->editfieldkey('CompanyBirthDate', 'birth', '', $object, 0).'</td>';
2824 print '<td class="maxwidthonsmartphone" colspan="3">';
2825 print $form->selectDate($object->birth, 'birth', 0, 0, 1, "", 1);
2826 print '</td></tr>';
2827
2828 // Capital
2829 print '<tr class="morefields"><td>'.$form->editfieldkey('Capital', 'capital', '', $object, 0).'</td>';
2830 print '<td colspan="3"><input type="text" name="capital" id="capital" class="width75" value="';
2831 print ($object->capital !== null ? dolPrintHTMLForAttribute(price($object->capital)) : '');
2832 if (isModEnabled("multicurrency")) {
2833 print '"> <span class="hideonsmartphone">'.$langs->trans("Currency".$object->multicurrency_code).'</span></td></tr>';
2834 } else {
2835 print '"> <span class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
2836 }
2837
2838 // Default language
2839 if (getDolGlobalInt('MAIN_MULTILANGS')) {
2840 print '<tr class="morefields"><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3">'."\n";
2841 print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language($object->default_lang, 'default_lang', 0, array(), '1', 0, 0, 'maxwidth300 widthcentpercentminusx');
2842 print '</td>';
2843 print '</tr>';
2844 }
2845
2846 // Incoterms
2847 if (isModEnabled('incoterm')) {
2848 print '<tr class="morefields">';
2849 print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
2850 print '<td colspan="3" class="maxwidthonsmartphone">';
2851 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
2852 print '</td></tr>';
2853 }
2854
2855 // Multicurrency
2856 if (isModEnabled("multicurrency")) {
2857 print '<tr class="morefields">';
2858 print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
2859 print '<td colspan="3" class="maxwidthonsmartphone">';
2860 print img_picto('', 'currency', 'class="pictofixedwidth"');
2861 print $form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code') : ($object->multicurrency_code ? $object->multicurrency_code : $conf->currency)), 'multicurrency_code', 1, '', false, 'maxwidth150 widthcentpercentminusx');
2862 print '</td></tr>';
2863 }
2864
2865 // Other attributes
2866 $parameters = array('socid' => $socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
2867 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
2868
2869 print '<tr class="morefieldsbis tdsmallheight"><td colspan="4"></td></tr>';
2870
2871 // Parent company
2872 if (!getDolGlobalString('SOCIETE_DISABLE_PARENTCOMPANY')) {
2873 print '<tr class="morefieldsbis">';
2874 print '<td>'.$langs->trans('ParentCompany').'</td>';
2875 print '<td colspan="3" class="maxwidthonsmartphone">';
2876 print img_picto('', 'company', 'class="pictofixedwidth"');
2877 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');
2878 print '</td></tr>';
2879 }
2880
2881 // Assign sale representative
2882 print '<tr class="morefieldsbis">';
2883 print '<td>'.$form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0).'</td>';
2884 print '<td colspan="3" class="maxwidthonsmartphone">';
2885 $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', '0', 0, 0, 'u.statut:=:1', 0, '', '', 0, 1);
2886 $arrayselected = GETPOST('commercial', 'array');
2887 if (empty($arrayselected)) {
2888 $arrayselected = $object->getSalesRepresentatives($user, 1);
2889 }
2890 print img_picto('', 'user', 'class="pictofixedwidth"').$form->multiselectarray('commercial', $userlist, $arrayselected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0, '', '', '', 1);
2891 print '</td></tr>';
2892
2893 // Logo
2894 print '<tr class="hideonsmartphone morefieldsbis">';
2895 print '<td>'.$form->editfieldkey('Logo', 'photoinput', '', $object, 0).'</td>';
2896 print '<td colspan="3">';
2897 if ($object->logo) {
2898 print $form->showphoto('societe', $object, 100, 0, 0, 'inline-block');
2899 }
2900 $caneditfield = 1;
2901 if ($caneditfield) {
2902 if ($object->logo) {
2903 print "<br>\n";
2904 }
2905 print '<table class="nobordernopadding">';
2906 if ($object->logo) {
2907 print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">'.$langs->trans("Delete").'</photo><br></td></tr>';
2908 }
2909 //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
2910 print '<tr><td>';
2911 $maxfilesizearray = getMaxFileSizeArray();
2912 $maxmin = $maxfilesizearray['maxmin'];
2913 if ($maxmin > 0) {
2914 print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
2915 }
2916 print '<input type="file" class="flat" name="photo" id="photoinput">';
2917 print '</td></tr>';
2918 print '</table>';
2919 }
2920 print '</td>';
2921 print '</tr>';
2922
2923 print '</table>'."\n";
2924
2925 print '<script nonce="'.getNonce().'" type="text/javascript">
2926 $("document").ready(function() { toogleMoreFields(false); });
2927
2928 jQuery(".morefieldslnk").click(function() {
2929 console.log("Click on link .morefieldslnk (edit)");
2930 toogleMoreFields(true);
2931 return false;
2932 });
2933
2934 function toogleMoreFields(chgCookieState) {
2935 const lnk = $("#morefieldslnk");
2936 const items = $(".morefields, .trextrafields:not(.trextrafieldsgroup)");
2937 var cookieState = document.cookie.split(";").some((item) => item.trim().startsWith("DOLUSER_MOREFIELDS_SHOW=true")) == true;
2938
2939 if (!chgCookieState) cookieState = !cookieState ;
2940
2941 if (cookieState) {
2942 items.hide();
2943 if (chgCookieState) { document.cookie = "DOLUSER_MOREFIELDS_SHOW=false; SameSite=Strict"};
2944 } else {
2945 items.show();
2946 if (chgCookieState) { document.cookie = "DOLUSER_MOREFIELDS_SHOW=true; SameSite=Strict";}
2947 }
2948 }
2949 </script>
2950 ';
2951
2952 if (getDolGlobalString('ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY')) {
2953 print '<br>';
2954 print '<table class="border centpercent">';
2955
2956 if (isModEnabled('accounting')) {
2958 // Accountancy_code_sell
2959 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
2960 print '<td>';
2961 print $formaccounting->select_account($object->accountancy_code_sell, 'accountancy_code_sell', 1, array(), 1, 1);
2962 print '</td></tr>';
2963
2964 // Accountancy_code_buy
2965 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyCode").'</td>';
2966 print '<td>';
2967 print $formaccounting->select_account($object->accountancy_code_buy, 'accountancy_code_buy', 1, array(), 1, 1);
2968 print '</td></tr>';
2969 } else { // For external software
2970 // Accountancy_code_sell
2971 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
2972 print '<td><input name="accountancy_code_sell" class="maxwidth200" value="'.$object->accountancy_code_sell.'">';
2973 print '</td></tr>';
2974
2975 // Accountancy_code_buy
2976 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyCode").'</td>';
2977 print '<td><input name="accountancy_code_buy" class="maxwidth200" value="'.$object->accountancy_code_buy.'">';
2978 print '</td></tr>';
2979 }
2980 print '</table>';
2981 }
2982 }
2983
2984 print '</div>';
2985
2986 print dol_get_fiche_end();
2987
2988 print $form->buttonsSaveCancel();
2989
2990 print '</form>';
2991 }
2992 } else {
2993 // View
2994 if (!empty($object->id)) {
2995 $res = $object->fetch_optionals();
2996 }
2997
2998 $head = societe_prepare_head($object);
2999
3000 print dol_get_fiche_head($head, 'card', $langs->trans("ThirdParty"), -1, 'company', 0, '', '', 0, '', 1);
3001
3002 $formconfirm = '';
3003
3004 // Confirm delete third party
3005 if ($action == 'delete' || ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))) {
3006 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("DeleteACompany"), $langs->trans("ConfirmDeleteCompany"), "confirm_delete", '', 0, "action-delete");
3007 }
3008
3009 if ($action == 'merge') {
3010 $formquestion = array(
3011 array(
3012 'name' => 'soc_origin',
3013 'label' => $langs->trans('MergeOriginThirdparty'),
3014 'type' => 'other',
3015 'value' => $form->select_company('', 'soc_origin', '', 'SelectThirdParty', 1, 0, array(), 0, 'minwidth200', '', '', 1, array(), false, array($object->id))
3016 )
3017 );
3018
3019 $formconfirm .= $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("MergeThirdparties"), $langs->trans("ConfirmMergeThirdparties"), "confirm_merge", $formquestion, 'no', 1, 300);
3020 }
3021
3022 // Clone confirmation
3023 if (($action == 'clone' && (empty($conf->use_javascript_ajax) || !empty($conf->dol_use_jmobile))) // Output when action = clone if jmobile or no js
3024 || (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) { // Always output when not jmobile nor js
3025 // Define confirmation messages
3026 $formquestionclone = array(
3027 'text' => $langs->trans("ConfirmClone"),
3028 0 => array('type' => 'text', 'name' => 'clone_name', 'label' => $langs->trans("NewSocNameForClone"), 'value' => empty($tmpcode) ? $langs->trans("CopyOf").' '.$object->nom : $tmpcode, 'morecss' => 'width250'),
3029 );
3030 $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);
3031 }
3032
3033 // Call Hook formConfirm
3034 $parameters = array('formConfirm' => $formconfirm);
3035 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3036 if (empty($reshook)) {
3037 $formconfirm .= $hookmanager->resPrint;
3038 } elseif ($reshook > 0) {
3039 $formconfirm = $hookmanager->resPrint;
3040 }
3041
3042 // Print form confirm
3043 print $formconfirm;
3044
3045 dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
3046
3047 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
3048
3049 $morehtmlref = '<a href="'.DOL_URL_ROOT.'/societe/vcard.php?id='.$object->id.'" class="refid">';
3050 $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard', 'class="valignmiddle marginleftonly paddingrightonly"');
3051 $morehtmlref .= '</a>';
3052
3053 dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom', $morehtmlref);
3054
3055 // Call Hook tabContentViewThirdparty
3056 $parameters = array();
3057 // Note that $action and $object may be modified by hook
3058 $reshook = $hookmanager->executeHooks('tabContentViewThirdparty', $parameters, $object, $action);
3059 if (empty($reshook)) {
3060 print '<div class="fichecenter">';
3061 print '<div class="fichehalfleft">';
3062
3063 print '<div class="underbanner clearboth"></div>';
3064 print '<table class="border tableforfield centpercent">';
3065
3066 // Type Prospect/Customer/Supplier
3067 print '<tr><td class="titlefieldmiddle">'.$langs->trans('NatureOfThirdParty').'</td><td>';
3068 print $object->getTypeUrl(1);
3069 print '</td></tr>';
3070
3071 // Customer code
3072 if ($object->client) {
3073 print '<tr><td>';
3074 print $langs->trans('CustomerCode');
3075 print '</td>';
3076 print '<td>';
3078 $tmpcheck = $object->check_codeclient();
3079 if ($tmpcheck != 0 && $tmpcheck != -5) {
3080 print img_warning($langs->trans("WrongCustomerCode"));
3081 }
3082 print '</td>';
3083 print '</tr>';
3084 }
3085
3086 // Supplier code
3087 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) {
3088 print '<tr><td>';
3089 print $langs->trans('SupplierCode').'</td><td>';
3091 $tmpcheck = $object->check_codefournisseur();
3092 if ($tmpcheck != 0 && $tmpcheck != -5) {
3093 print img_warning($langs->trans("WrongSupplierCode"));
3094 }
3095 print '</td>';
3096 print '</tr>';
3097 }
3098
3099 // Barcode
3100 if (isModEnabled('barcode') && getDolGlobalString('BARCODE_USE_ON_THIRDPARTY')) {
3101 print '<tr><td>';
3102 print $langs->trans('Gencod').'</td><td>'.showValueWithClipboardCPButton(dol_escape_htmltag($object->barcode));
3103 print '</td>';
3104 print '</tr>';
3105 }
3106
3107 // Prof ids
3108 $i = 1;
3109 $j = 0;
3110 $NBPROFIDMIN = getDolGlobalInt('THIRDPARTY_MIN_NB_PROF_ID', 2);
3111 $NBPROFIDMAX = getDolGlobalInt('THIRDPARTY_MAX_NB_PROF_ID', 6);
3112 while ($i <= $NBPROFIDMAX) {
3113 $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
3114 if (!empty($conf->dol_optimize_smallscreen)) {
3115 $idprof = $langs->transcountry('ProfId'.$i.'Short', $object->country_code);
3116 }
3117 if ($idprof != '-' && ($i <= $NBPROFIDMIN || !empty($langs->tab_translate['ProfId'.$i.$object->country_code]))) {
3118 print '<tr>';
3119 print '<td>'.$idprof.'</td><td>';
3120 $key = 'idprof'.$i;
3121 print dol_print_profids($object->$key, 'ProfId'.$i, $object->country_code, 1);
3122 if (!empty($object->$key)) {
3123 if ($object->id_prof_check($i) > 0) {
3124 $profidurl = $object->id_prof_url($i, $object);
3125 if (!empty($profidurl)) {
3126 print ' &nbsp; '.$profidurl;
3127 }
3128 } else {
3129 print img_warning($langs->trans("ErrorWrongValue"));
3130 }
3131 }
3132 print '</td>';
3133 print '</tr>';
3134 $j++;
3135 }
3136 $i++;
3137 }
3138
3139
3140 // 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.
3141 // We don't need them into customer profile.
3142 // Except for spain and localtax where localtax depends on buyer and not seller
3143
3144 if ($object->fournisseur) {
3145 // VAT is used
3146 print '<tr><td>';
3147 print $form->textwithpicto($langs->trans('VATIsUsed'), $langs->trans('VATIsUsedWhenSelling'));
3148 print '</td><td>';
3149 print yn($object->tva_assuj);
3150 print '</td>';
3151 print '</tr>';
3152
3153 if (getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) {
3154 // VAT reverse charge by default
3155 print '<tr><td>';
3156 print $form->textwithpicto($langs->trans('VATReverseChargeByDefault'), $langs->trans('VATReverseChargeByDefaultDesc'));
3157 print '</td><td>';
3158 print '<input type="checkbox" name="vat_reverse_charge" ' . ($object->vat_reverse_charge == '1' ? ' checked' : '') . ' disabled>';
3159 print '</td>';
3160 print '</tr>';
3161 }
3162 }
3163
3164 // Local Taxes
3165 if ($object->fournisseur || $mysoc->country_code == 'ES') {
3166 if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
3167 print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
3168 print yn($object->localtax1_assuj);
3169 print '</td></tr><tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
3170 print yn($object->localtax2_assuj);
3171 print '</td></tr>';
3172
3173 if ($object->localtax1_assuj == "1" && (!isOnlyOneLocalTax(1))) {
3174 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
3175 print '<input type="hidden" name="action" value="set_localtax1">';
3176 print '<input type="hidden" name="token" value="'.newToken().'">';
3177 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>';
3178 if ($action == 'editRE') {
3179 print '<td class="left">';
3180 $formcompany->select_localtax(1, (float) $object->localtax1_value, "lt1");
3181 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
3182 } else {
3183 print '<td>'.$object->localtax1_value.'</td>';
3184 }
3185 print '</tr></form>';
3186 }
3187 if ($object->localtax2_assuj == "1" && (!isOnlyOneLocalTax(2))) {
3188 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
3189 print '<input type="hidden" name="action" value="set_localtax2">';
3190 print '<input type="hidden" name="token" value="'.newToken().'">';
3191 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>';
3192 if ($action == 'editIRPF') {
3193 print '<td class="left">';
3194 $formcompany->select_localtax(2, (float) $object->localtax2_value, "lt2");
3195 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
3196 } else {
3197 print '<td>'.$object->localtax2_value.'</td>';
3198 }
3199 print '</tr></form>';
3200 }
3201 } elseif ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj != "1") {
3202 print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
3203 print yn($object->localtax1_assuj);
3204 print '</td></tr>';
3205 if ($object->localtax1_assuj == "1" && (!isOnlyOneLocalTax(1))) {
3206 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
3207 print '<input type="hidden" name="action" value="set_localtax1">';
3208 print '<input type="hidden" name="token" value="'.newToken().'">';
3209 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>';
3210 if ($action == 'editRE') {
3211 print '<td class="left">';
3212 $formcompany->select_localtax(1, (float) $object->localtax1_value, "lt1");
3213 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
3214 } else {
3215 print '<td>'.$object->localtax1_value.'</td>';
3216 }
3217 print '</tr></form>';
3218 }
3219 } elseif ($mysoc->localtax2_assuj == "1" && $mysoc->localtax1_assuj != "1") {
3220 print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
3221 print yn($object->localtax2_assuj);
3222 print '</td></tr>';
3223 if ($object->localtax2_assuj == "1" && (!isOnlyOneLocalTax(2))) {
3224 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
3225 print '<input type="hidden" name="action" value="set_localtax2">';
3226 print '<input type="hidden" name="token" value="'.newToken().'">';
3227 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>';
3228 if ($action == 'editIRPF') {
3229 print '<td class="left">';
3230 $formcompany->select_localtax(2, (float) $object->localtax2_value, "lt2");
3231 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
3232 } else {
3233 print '<td>'.$object->localtax2_value.'</td>';
3234 }
3235 print '</tr></form>';
3236 }
3237 }
3238 }
3239
3240 // Sale tax code (VAT code)
3241 print '<tr>';
3242 print '<td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
3243 if ($object->tva_intra) {
3244 $s = '';
3245 $s .= dol_print_profids($object->tva_intra, 'VAT', $object->country_code, 1);
3246 $s .= '<input type="hidden" id="tva_intra" name="tva_intra" maxlength="20" value="'.$object->tva_intra.'">';
3247
3248 if (!getDolGlobalString('MAIN_DISABLEVATCHECK') && isInEEC($object)) {
3249 $s .= ' &nbsp; ';
3250
3251 if ($conf->use_javascript_ajax) {
3252 $widthpopup = 600;
3253 if (!empty($conf->dol_use_jmobile)) {
3254 $widthpopup = 350;
3255 }
3256 $heightpopup = 400;
3257 print "\n";
3258 print '<script type="text/javascript">';
3259 print "function CheckVAT(a) {\n";
3260 if ($mysoc->country_code == 'GR' && $object->country_code == 'GR' && !empty($u)) {
3261 print "GRVAT(a,'{$u}','{$p}','{$myafm}');\n";
3262 } else {
3263 print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a, '".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
3264 }
3265 print "}\n";
3266 print '</script>';
3267 print "\n";
3268 $s .= '<a href="#" class="hideonsmartphone" onclick="CheckVAT(jQuery(\'#tva_intra\').val());">'.$langs->trans("VATIntraCheck").'</a>';
3269 $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1);
3270 } else {
3271 $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", (string) $object->country_id).'" class="hideonsmartphone" target="_blank" rel="noopener noreferrer">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
3272 }
3273 }
3274 print $s;
3275 } else {
3276 print '&nbsp;';
3277 }
3278 print '</td></tr>';
3279
3280 // EUID
3281 print '<tr>';
3282 print '<td class="nowrap">'.$langs->trans('EUIDShort').'</td><td>';
3283 if ($object->euid) {
3284 print dol_print_profids($object->euid, 'EUID', $object->country_code, 1);
3285 } else {
3286 print '&nbsp;';
3287 }
3288 print '</td></tr>';
3289
3290 // Warehouse
3291 if (isModEnabled('stock') && getDolGlobalString('SOCIETE_ASK_FOR_WAREHOUSE')) {
3292 $langs->load('stocks');
3293 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
3294 $formproduct = new FormProduct($db);
3295 print '<tr class="nowrap">';
3296 print '<td>';
3297 print $form->editfieldkey("Warehouse", 'warehouse', '', $object, $user->hasRight('societe', 'creer'));
3298 print '</td><td>';
3299 if ($action == 'editwarehouse') {
3300 $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, (int) $object->fk_warehouse, 'fk_warehouse', 1);
3301 } else {
3302 if ($object->fk_warehouse > 0) {
3303 print img_picto('', 'stock', 'class="paddingrightonly"');
3304 }
3305 $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, (int) $object->fk_warehouse, 'none');
3306 }
3307 print '</td>';
3308 print '</tr>';
3309 }
3310
3311 print '</table>';
3312 print '</div>';
3313
3314 print '<div class="fichehalfright">';
3315
3316 print '<div class="underbanner clearboth"></div>';
3317 print '<table class="border tableforfield centpercent">';
3318
3319 // Tags / categories
3320 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
3321 // Customer
3322 if ($object->prospect || $object->client || getDolGlobalString('THIRDPARTY_CAN_HAVE_CUSTOMER_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT')) {
3323 print '<tr><td class="titlefieldmiddle">'.$langs->trans("CustomersCategoriesShort").'</td>';
3324 print '<td>';
3325 print $form->showCategories($object->id, Categorie::TYPE_CUSTOMER, 1);
3326 print "</td></tr>";
3327 }
3328
3329 // Supplier
3330 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) {
3331 print '<tr><td class="titlefieldmiddle">'.$langs->trans("SuppliersCategoriesShort").'</td>';
3332 print '<td>';
3333 print $form->showCategories($object->id, Categorie::TYPE_SUPPLIER, 1);
3334 print "</td></tr>";
3335 }
3336 }
3337
3338
3339 // Third-Party Type
3340 print '<tr><td class="titlefieldmiddle">';
3341 print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans('ThirdPartyType').'</td>';
3342 if ($action != 'editthirdpartytype' && $user->hasRight('societe', 'creer')) {
3343 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>';
3344 }
3345 print '</tr></table>';
3346 print '</td><td>';
3347 $html_name = ($action == 'editthirdpartytype') ? 'typent_id' : 'none';
3348 $formcompany->formThirdpartyType($_SERVER['PHP_SELF'].'?socid='.$object->id, (string) $object->typent_id, $html_name, '');
3349 print '</td></tr>';
3350
3351 // Workforce/Staff
3352 if (!getDolGlobalString('SOCIETE_DISABLE_WORKFORCE')) {
3353 print '<tr><td>'.$langs->trans("Workforce").'</td><td>'.$object->effectif.'</td></tr>';
3354 }
3355
3356 // Legal
3357 print '<tr><td>'.$langs->trans('JuridicalStatus').'</td><td>'.dolPrintHTML($object->forme_juridique).'</td></tr>';
3358
3359 // Date birth
3360 print '<tr><td>'.$langs->trans('CompanyBirthDate').'</td><td>'.dol_print_date($object->birth).'</td></tr>';
3361
3362 // Capital
3363 print '<tr><td>'.$langs->trans('Capital').'</td><td>';
3364 if ($object->capital !== null) {
3365 if (isModEnabled("multicurrency") && !empty($object->multicurrency_code)) {
3366 print price($object->capital, 0, $langs, 0, -1, -1, $object->multicurrency_code);
3367 } else {
3368 print price($object->capital, 0, $langs, 0, -1, -1, $conf->currency);
3369 }
3370 }
3371 print '</td></tr>';
3372
3373 // Unsubscribe opt-out
3374 if (isModEnabled('mailing')) {
3375 $result = $object->getNoEmail();
3376 if ($result < 0) {
3377 setEventMessages($object->error, $object->errors, 'errors');
3378 }
3379 print '<tr><td>'.$langs->trans("No_Email").'</td><td>';
3380 if ($object->email) {
3381 print yn($object->no_email);
3382 } else {
3383 $langs->load("mails");
3384 print '<span class="opacitymedium">'.$langs->trans("EMailNotDefined").'</span>';
3385 }
3386
3387 $langs->load("mails");
3388 print ' &nbsp; <span class="badge badge-secondary" title="'.dolPrintHTMLForAttribute($langs->trans("NbOfEMailingsSend")).'">'.$object->getNbOfEMailings().'</span>';
3389
3390 print '</td></tr>';
3391 }
3392
3393 // Default language
3394 if (getDolGlobalInt('MAIN_MULTILANGS')) {
3395 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
3396 print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
3397 //$s=picto_from_langcode($object->default_lang);
3398 //print ($s?$s.' ':'');
3399 $langs->load("languages");
3400 $labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
3401 print picto_from_langcode($object->default_lang, 'class="paddingrightonly saturatemedium opacitylow"');
3402 print $labellang;
3403 print '</td></tr>';
3404 }
3405
3406 // Incoterms
3407 if (isModEnabled('incoterm')) {
3408 print '<tr><td>';
3409 print '<table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans('IncotermLabel').'</td>';
3410 if ($action != 'editincoterm' && $user->hasRight('societe', 'creer')) {
3411 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=editincoterm&token='.newToken().'">'.img_edit('', 1).'</a></td>';
3412 }
3413 print '</tr></table>';
3414 print '</td><td colspan="3">';
3415 if ($action != 'editincoterm') {
3416 print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
3417 } else {
3418 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?socid='.$object->id);
3419 }
3420 print '</td></tr>';
3421 }
3422
3423 // Multicurrency
3424 if (isModEnabled("multicurrency")) {
3425 print '<tr>';
3426 print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
3427 print '<td>';
3428 print !empty($object->multicurrency_code) ? currency_name($object->multicurrency_code, 1) : '';
3429 print '</td></tr>';
3430 }
3431
3432 if (getDolGlobalString('ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY')) {
3433 // Accountancy sell code
3434 print '<tr><td class="nowrap">';
3435 print $langs->trans("ProductAccountancySellCode");
3436 print '</td><td colspan="2">';
3437 if (isModEnabled('accounting')) {
3438 if (!empty($object->accountancy_code_sell)) {
3439 $accountingaccount = new AccountingAccount($db);
3440 $accountingaccount->fetch(0, $object->accountancy_code_sell, 1);
3441
3442 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
3443 }
3444 } else {
3445 print $object->accountancy_code_sell;
3446 }
3447 print '</td></tr>';
3448
3449 // Accountancy buy code
3450 print '<tr><td class="nowrap">';
3451 print $langs->trans("ProductAccountancyBuyCode");
3452 print '</td><td colspan="2">';
3453 if (isModEnabled('accounting')) {
3454 if (!empty($object->accountancy_code_buy)) {
3455 $accountingaccount2 = new AccountingAccount($db);
3456 $accountingaccount2->fetch(0, $object->accountancy_code_buy, 1);
3457
3458 print $accountingaccount2->getNomUrl(0, 1, 1, '', 1);
3459 }
3460 } else {
3461 print $object->accountancy_code_buy;
3462 }
3463 print '</td></tr>';
3464 }
3465
3466 // Other attributes
3467 $parameters = array('socid' => $socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
3468 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
3469
3470 // Parent company
3471 if (!getDolGlobalString('SOCIETE_DISABLE_PARENTCOMPANY')) {
3472 print '<tr><td>';
3473 print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans('ParentCompany').'</td>';
3474 if ($action != 'editparentcompany' && $user->hasRight('societe', 'creer')) {
3475 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>';
3476 }
3477 print '</tr></table>';
3478 print '</td><td>';
3479 $html_name = ($action == 'editparentcompany') ? 'parent_id' : 'none';
3480 $form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id, (string) $object->parent, $html_name, '', 1, 0, 0, array(), 0, array($object->id));
3481 print '</td></tr>';
3482 }
3483
3484 // Sales representative
3485 include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php';
3486
3487 // Module Adherent
3488 if (isModEnabled('member')) {
3489 $langs->load("members");
3490 print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
3491 print '<td>';
3492 $adh = new Adherent($db);
3493 $result = $adh->fetch(0, '', $object->id);
3494 if ($result > 0) {
3495 $adh->ref = $adh->getFullName($langs);
3496 print $adh->getNomUrl(-1);
3497 print ' &mdash; '.$adh->getLibStatut(0);
3498 } else {
3499 print '<span class="opacitymedium">'.$langs->trans("ThirdpartyNotLinkedToMember").'</span>';
3500 }
3501 print "</td></tr>\n";
3502 }
3503
3504 // Link user (you must create a contact to get a user)
3505 /*
3506 print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td colspan="3">';
3507 if ($object->user_id) {
3508 $dolibarr_user = new User($db);
3509 $result = $dolibarr_user->fetch($object->user_id);
3510 print $dolibarr_user->getLoginUrl(-1);
3511 } else {
3512 //print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
3513 if (!$object->user_id && $user->hasRight('user', 'user', 'creer')) {
3514 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>';
3515 }
3516 }
3517 print '</td></tr>';
3518 */
3519
3520 print '</table>';
3521 print '</div>';
3522
3523 print '</div>';
3524 print '<div class="clearboth"></div>';
3525 }
3526
3527 print dol_get_fiche_end();
3528
3529
3530 /*
3531 * Actions
3532 */
3533 if ($action != 'presend') {
3534 print '<div class="tabsAction">'."\n";
3535
3536 $parameters = array();
3537 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3538 if (empty($reshook)) {
3539 $at_least_one_email_contact = false;
3540 $TContact = $object->contact_array_objects();
3541 foreach ($TContact as &$contact) {
3542 if (!empty($contact->email)) {
3543 $at_least_one_email_contact = true;
3544 break;
3545 }
3546 }
3547
3548 if (empty($user->socid)) {
3549 $langs->load("mails");
3550 $title = '';
3551 if (empty($object->email) && !$at_least_one_email_contact) {
3552 $title = $langs->trans('NoEMail');
3553 }
3554 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);
3555 }
3556
3557 print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=edit&token='.newToken(), '', $permissiontoadd);
3558
3559 if (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile)) {
3560 $cloneSocietetUrl = '';
3561 $cloneButtonId = 'action-clone';
3562 } else {
3563 $cloneSocietetUrl = '';
3564 $cloneButtonId = '';
3565 }
3566 print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $cloneSocietetUrl, $cloneButtonId, $user->hasRight('societe', 'creer'));
3567
3568 if (isModEnabled('member')) {
3569 $adh = new Adherent($db);
3570 $result = $adh->fetch(0, '', $object->id);
3571 if ($result == 0 && ($object->client == 1 || $object->client == 3) && getDolGlobalString('MEMBER_CAN_CONVERT_CUSTOMERS_TO_MEMBERS')) {
3572 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";
3573 }
3574 }
3575
3576 print dolGetButtonAction($langs->trans('MergeThirdparties'), $langs->trans('Merge'), 'danger', $_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=merge&token='.newToken(), '', $permissiontodelete);
3577
3578 $deleteUrl = $_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=delete&token='.newToken();
3579 $buttonId = 'action-delete-no-ajax';
3580 if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)) { // We can't use preloaded confirm form with jmobile
3581 $deleteUrl = '';
3582 $buttonId = 'action-delete';
3583 }
3584 print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $deleteUrl, $buttonId, $permissiontodelete);
3585 }
3586
3587 print '</div>'."\n";
3588 }
3589
3590 //Select mail models is same action as presend
3591 if (GETPOST('modelselected')) {
3592 $action = 'presend';
3593 }
3594
3595 if ($action != 'presend') {
3596 print '<div class="fichecenter"><div class="fichehalfleft">';
3597
3598 if (!getDolGlobalString('SOCIETE_DISABLE_BUILDDOC')) {
3599 print '<a name="builddoc"></a>'; // ancre
3600
3601 /*
3602 * Generated documents
3603 */
3604 $filedir = $conf->societe->multidir_output[$object->entity ?? $conf->entity].'/'.$object->id;
3605 $urlsource = $_SERVER["PHP_SELF"]."?socid=".$object->id;
3606 $genallowed = $user->hasRight('societe', 'lire');
3607 $delallowed = $user->hasRight('societe', 'creer');
3608
3609 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);
3610 }
3611
3612 // Subsidiaries list
3613 if (!getDolGlobalString('SOCIETE_DISABLE_PARENTCOMPANY') && !getDolGlobalString('SOCIETE_DISABLE_SHOW_SUBSIDIARIES')) {
3614 print '<br>';
3615 $result = show_subsidiaries($conf, $langs, $db, $object);
3616 }
3617
3618 print '</div><div class="fichehalfright">';
3619
3620 $MAXEVENT = 10;
3621
3622 $morehtmlcenter = '<div class="nowraponall">';
3623 $morehtmlcenter .= dolGetButtonTitle($langs->trans('FullConversation'), '', 'fa fa-comments imgforviewmode', DOL_URL_ROOT.'/societe/messaging.php?socid='.$object->id);
3624 $morehtmlcenter .= dolGetButtonTitle($langs->trans('FullList'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id);
3625 $morehtmlcenter .= '</div>';
3626
3627 // List of actions on element
3628 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
3629 $formactions = new FormActions($db);
3630 $somethingshown = $formactions->showactions($object, '', $socid, 1, '', $MAXEVENT, '', $morehtmlcenter); // Show all action for thirdparty
3631
3632 print '</div></div>';
3633
3634 if (getDolGlobalString('MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD')) {
3635 // Contacts list
3636 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
3637 $result = show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
3638 }
3639 }
3640 }
3641
3642 // Presend form
3643 $modelmail = 'thirdparty';
3644 $defaulttopic = 'Information';
3645 $diroutput = $conf->societe->multidir_output[$object->entity ?? $conf->entity];
3646 $trackid = 'thi'.$object->id;
3647
3648 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
3649 }
3650}
3651
3652
3653// End of page
3654llxFooter();
3655$db->close();
3656
3657?>
3658
3659<script>
3660// Function to retrieve VAT details from the Greek Ministry of Finance GSIS SOAP web service
3661function GRVAT(a, u, p, myafm) {
3662 var afm = a.replace(/\D/g, ""); // Remove non-digit characters from 'a'
3663
3664 $.ajax({
3665 type: "GET",
3666 url: '<?php echo DOL_URL_ROOT ?>/societe/checkvat/checkVatGr.php',
3667 data: { afm }, // Set request parameters
3668 success: function(data) {
3669 var obj = data; // Parse response data as JSON
3670
3671 // Update form fields based on retrieved data
3672 if (obj.RgWsPublicBasicRt_out.afm === null) {
3673 alert(obj.pErrorRec_out.errorDescr); // Display error message if AFM is null
3674 } else {
3675 $("#name").val(obj.RgWsPublicBasicRt_out.onomasia); // Set 'name' field value
3676 $("#address").val(obj.RgWsPublicBasicRt_out.postalAddress + " " + obj.RgWsPublicBasicRt_out.postalAddressNo); // Set 'address' field value
3677 $("#zipcode").val(obj.RgWsPublicBasicRt_out.postalZipCode); // Set 'zipcode' field value
3678 $("#town").val(obj.RgWsPublicBasicRt_out.postalAreaDescription); // Set 'town' field value
3679 $("#idprof2").val(obj.RgWsPublicBasicRt_out.doyDescr); // Set 'idprof2' field value
3680 $("#name_alias_input").val(obj.RgWsPublicBasicRt_out.commerTitle); // Set 'name_alias' field value
3681
3682 if (obj.arrayOfRgWsPublicFirmActRt_out.RgWsPublicFirmActRtUser) {
3683 var firmActUser = obj.arrayOfRgWsPublicFirmActRt_out.RgWsPublicFirmActRtUser;
3684
3685 if (Array.isArray(firmActUser)) {
3686 var primaryFirmAct = firmActUser.find(item => item.firmActKindDescr === "ΚΥΡΙΑ"); // Find primary client activity
3687 if (primaryFirmAct) {
3688 $("#idprof1").val(primaryFirmAct.firmActDescr); // Set 'idprof1' field value
3689 }
3690 } else {
3691 $("#idprof1").val(firmActUser.firmActDescr); // Set 'idprof1' field value
3692 }
3693 }
3694 }
3695 }
3696 });
3697}
3698
3699</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].
recordNotFound($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Displays an error page when a record is not found.
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.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
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.
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.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
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.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
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.