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