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