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