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