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