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