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