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