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