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