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 console.log("selectcountry_id change");
1197 document.formsoc.action.value="create";
1198 document.formsoc.submit();
1199 });
1200 });';
1201 print '</script>'."\n";
1202 }
1203
1204 dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
1205
1206 print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc" autocomplete="off">'; // Chrome ignores autocomplete
1207
1208 print '<input type="hidden" name="action" value="add">';
1209 print '<input type="hidden" name="token" value="'.newToken().'">';
1210 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1211 print '<input type="hidden" name="backtopagejsfields" value="'.$backtopagejsfields.'">';
1212 print '<input type="hidden" name="dol_openinpopup" value="'.$dol_openinpopup.'">';
1213 print '<input type="hidden" name="private" value='.$object->particulier.'>';
1214 print '<input type="hidden" name="type" value='.GETPOST("type", 'alpha').'>';
1215 print '<input type="hidden" name="LastName" value="'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName').'">';
1216 print '<input type="hidden" name="ThirdPartyName" value="'.$langs->trans('ThirdPartyName').'">';
1217 if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) {
1218 print '<input type="hidden" name="code_auto" value="1">';
1219 }
1220
1221 print dol_get_fiche_head(array(), 'card', '', 0, '');
1222
1223 // Call Hook tabContentCreateThirdparty
1224 $parameters = array();
1225 // Note that $action and $object may be modified by hook
1226 $reshook = $hookmanager->executeHooks('tabContentCreateThirdparty', $parameters, $object, $action);
1227 if (empty($reshook)) {
1228 print '<table class="border centpercent">';
1229
1230 // Name, firstname
1231 print '<tr class="tr-field-thirdparty-name"><td class="titlefieldcreate">';
1232 if ($object->particulier || $private) {
1233 print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName', 'name').'</span>';
1234 } else {
1235 print '<span id="TypeName" class="fieldrequired">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0).'</span>';
1236 }
1237 print '</td><td'.(!getDolGlobalString('SOCIETE_USEPREFIX') ? ' colspan="3"' : '').'>';
1238
1239 print '<input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.dol_escape_htmltag($object->name).'" autofocus="autofocus">';
1240 print $form->widgetForTranslation("name", $object, $permissiontoadd, 'string', 'alphanohtml', 'minwidth300'); // For some countries that need the company name in 2 languages
1241 // 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
1242 // 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.
1243 /*
1244 print '<select class="name" name="name" id="name" style="min-width:500px"></select>';
1245 print "\n".'<script type="text/javascript">';
1246 print '$(document).ready(function () {
1247 $("#name").select2({
1248 ajax: {
1249 url: "' . DOL_URL_ROOT . '/core/ajax/ajaxcompanies.php",
1250 dataType: "json",
1251 delay: 250,
1252 data: function (params) {
1253 return {
1254 newcompany: params.term // search term
1255 }
1256 },
1257 processResults: function (data, params) {
1258 return {
1259 results: data
1260 }
1261 },
1262 cache: true
1263 },
1264
1265 placeholder: "' . $langs->trans('Name of the new third party. In the meantime we check if it already exists...') . '",
1266 allowClear: true,
1267 minimumInputLength: 3,
1268 language: select2arrayoflanguage,
1269 containerCssClass: ":all:",
1270 selectionCssClass: ":all:",
1271 tags: true,
1272 templateResult: formatCustomer,
1273 templateSelection: formatCustomerSelection
1274 });
1275
1276 function formatCustomer (Customer) {
1277 if(Customer.label === undefined) {
1278 return Customer.text;
1279 }
1280
1281 if(Customer.logo !== null ) {
1282 logo = \'<img src="\';
1283 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";
1284 logo += \'" /></div>\';
1285 } else {
1286 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>\';
1287 }
1288
1289 var $container = $("<div class=\'select2-result-repository clearfix\'>" +
1290 "<div class=\'select2-result-repository__avatar floatleft inline-block valigntop\'>" + logo +
1291 "<div class=\'select2-result-repository__meta floatleft inline-block valigntop\'>" +
1292 "<div class=\'select2-result-repository__title\'></div>" +
1293 "<div class=\'select2-result-repository__name_alias\'></div>" +
1294 "<div class=\'select2-result-repository__code_client\'></div>" +
1295 "<div class=\'select2-result-repository__code_fournisseur\'></div>" +
1296 "<div class=\'select2-result-repository__companies_info\'>" +
1297 "<div class=\'select2-result-repository__email\'><i class=\'fa fa-at\'></i> </div>" +
1298 "<div class=\'select2-result-repository__address\'><i class=\'fa fa-flag\'></i> </div>" +
1299 "<div class=\'select2-result-repository__zip\'><i class=\'fa fa-circle-o\'></i> </div>" +
1300 "<div class=\'select2-result-repository__country\'><i class=\'fa fa-globe-americas\'></i> </div>" +
1301 "<div class=\'select2-result-repository__departement\'><i class=\'fa fa-circle-o\'></i> </div>" +
1302 "<div class=\'select2-result-repository__town\'><i class=\'fa fa-circle-o\'></i> </div>" +
1303 "<div class=\'select2-result-repository__siren\'><i class=\'fa fa-circle-o\'></i> </div>" +
1304 "<div class=\'select2-result-repository__datec\'><i class=\'fa fa-calendar\'></i> </div>" +
1305 "</div>" +
1306 "</div>" +
1307 "</div>"
1308 );
1309
1310 $container.find(".select2-result-repository__title").text(Customer.label);
1311 $container.find(".select2-result-repository__name_alias").text(Customer.name_alias ? Customer.name_alias : "");
1312 $container.find(".select2-result-repository__code_client").text(Customer.code_client ? Customer.code_client : "");
1313 $container.find(".select2-result-repository__code_fournisseur").text((Customer.code_fournisseur!==null) ? Customer.code_fournisseur : "");
1314 $container.find(".select2-result-repository__email").append("' . $langs->trans('EMail') . ': " + (Customer.email !== null ? Customer.email : ""));
1315 $container.find(".select2-result-repository__address").append("' . $langs->trans('Address') . ': " + (Customer.address !== null ? Customer.address : ""));
1316 $container.find(".select2-result-repository__country").append("' . $langs->trans('Country') . ': " + (Customer.country !== null ? Customer.country : ""));
1317 $container.find(".select2-result-repository__departement").append("' . $langs->trans('Region-State') . ': " + (Customer.departement !== null ? Customer.departement : ""));
1318 $container.find(".select2-result-repository__zip").append("' . $langs->trans('Zip') . ': " + (Customer.zip !== null ? Customer.zip : ""));
1319 $container.find(".select2-result-repository__town").append("' . $langs->trans('Town') . ': " + (Customer.town !== null ? Customer.town : ""));
1320 $container.find(".select2-result-repository__siren").append("' . $langs->trans('Siren') . ': " + (Customer.siren !== null ? Customer.siren : ""));
1321 $container.find(".select2-result-repository__datec").append("' . $langs->trans('Created') . ': " + (Customer.datec !== null ? Customer.datec : ""));
1322
1323 return $container;
1324 }
1325
1326 function formatCustomerSelection (selection) {
1327 return selection.label || selection.text;
1328 }
1329 });
1330 </script>
1331 ';
1332 */
1333 print '</td>';
1334 if (getDolGlobalString('SOCIETE_USEPREFIX')) { // Old not used prefix field
1335 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>';
1336 }
1337 print '</tr>';
1338
1339 // If javascript on, we show option individual
1340 if ($conf->use_javascript_ajax) {
1341 if (getDolGlobalString('THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION')) {
1342 // Firstname
1343 print '<tr class="individualline"><td>'.$form->editfieldkey('FirstName', 'firstname', '', $object, 0).'</td>';
1344 print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="firstname" id="firstname" value="'.dol_escape_htmltag($object->firstname).'"></td>';
1345 print '</tr>';
1346
1347 // Title
1348 print '<tr class="individualline"><td>'.$form->editfieldkey('UserTitle', 'civility_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1349 print $formcompany->select_civility($object->civility_id, 'civility_id', 'maxwidth100').'</td>';
1350 print '</tr>';
1351 }
1352 }
1353
1354 // Alias names (commercial, trademark or alias names)
1355 print '<tr id="name_alias"><td><label for="name_alias_input">'.$langs->trans('AliasNames').'</label></td>';
1356 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>';
1357
1358 // Prospect/Customer
1359 print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).'</td>';
1360 print '<td class="maxwidthonsmartphone">';
1361 $selected = (GETPOSTISSET('client') ? GETPOSTINT('client') : $object->client);
1362 print $formcompany->selectProspectCustomerType($selected);
1363 print '</td>';
1364
1365 if ($conf->browser->layout == 'phone') {
1366 print '</tr><tr>';
1367 }
1368
1369 print '<td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
1370 print '<table class="nobordernopadding"><tr><td>';
1371 $tmpcode = $object->code_client;
1372 if (empty($tmpcode) && !empty($modCodeClient->code_auto)) {
1373 $tmpcode = $modCodeClient->getNextValue($object, 0);
1374 }
1375 print '<input type="text" name="customer_code" id="customer_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="24">';
1376 print '</td><td>';
1377 $s = $modCodeClient->getToolTip($langs, $object, 0);
1378 print $form->textwithpicto('', $s, 1);
1379 print '</td></tr></table>';
1380 print '</td></tr>';
1381
1382 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'))
1383 || (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire'))) {
1384 // Supplier
1385 print '<tr>';
1386 print '<td>'.$form->editfieldkey('Vendor', 'fournisseur', '', $object, 0, 'string', '', 1).'</td><td>';
1387 $default = -1;
1388 if (getDolGlobalString('THIRDPARTY_SUPPLIER_BY_DEFAULT')) {
1389 $default = 1;
1390 }
1391 print $form->selectyesno("fournisseur", (GETPOSTINT('fournisseur') != '' ? GETPOSTINT('fournisseur') : (GETPOST("type") == '' ? $default : $object->fournisseur)), 1, 0, (GETPOST("type") == '' ? 1 : 0), 1);
1392 print '</td>';
1393
1394
1395 if ($conf->browser->layout == 'phone') {
1396 print '</tr><tr>';
1397 }
1398
1399 print '<td>';
1400 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'))) {
1401 print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0);
1402 }
1403 print '</td><td>';
1404 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'))) {
1405 print '<table class="nobordernopadding"><tr><td>';
1406 $tmpcode = $object->code_fournisseur;
1407 if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) {
1408 $tmpcode = $modCodeFournisseur->getNextValue($object, 1);
1409 }
1410 print '<input type="text" name="supplier_code" id="supplier_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="24">';
1411 print '</td><td>';
1412 $s = $modCodeFournisseur->getToolTip($langs, $object, 1);
1413 print $form->textwithpicto('', $s, 1);
1414 print '</td></tr></table>';
1415 }
1416 print '</td></tr>';
1417 }
1418
1419 // Status
1420 print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0).'</td><td colspan="3">';
1421 print $form->selectarray('status', array('0' => $langs->trans('ActivityCeased'), '1' => $langs->trans('InActivity')), 1, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
1422 print '</td></tr>';
1423
1424 // Barcode
1425 if (isModEnabled('barcode')) {
1426 print '<tr><td>'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).'</td>';
1427 print '<td colspan="3">';
1428 print img_picto('', 'barcode', 'class="pictofixedwidth"');
1429 print '<input type="text" name="barcode" id="barcode" value="'.dol_escape_htmltag($object->barcode).'">';
1430 print '</td></tr>';
1431 }
1432
1433 // Address
1434 print '<tr><td class="tdtop">';
1435 print $form->editfieldkey('Address', 'address', '', $object, 0);
1436 print '</td>';
1437 print '<td colspan="3">';
1438 print '<textarea name="address" id="address" class="quatrevingtpercent" rows="'.ROWS_2.'" wrap="soft">';
1439 print dol_escape_htmltag($object->address, 0, 1);
1440 print '</textarea>';
1441 print $form->widgetForTranslation("address", $object, $permissiontoadd, 'textarea', 'alphanohtml', 'quatrevingtpercent');
1442 print '</td></tr>';
1443
1444 // Zip / Town
1445 print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td>';
1446 print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100');
1447 print '</td>';
1448 if ($conf->browser->layout == 'phone') {
1449 print '</tr><tr>';
1450 }
1451 print '<td class="tdtop">'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td>';
1452 print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth150 quatrevingtpercent');
1453 print $form->widgetForTranslation("town", $object, $permissiontoadd, 'string', 'alphanohtml', 'maxwidth100 quatrevingtpercent');
1454 print '</td></tr>';
1455
1456 // Country
1457 print '<tr><td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1458 print img_picto('', 'country', 'class="pictofixedwidth"');
1459 print $form->select_country((GETPOSTISSET('country_id') ? GETPOST('country_id') : $object->country_id), 'country_id', '', 0, 'minwidth200 maxwidth300 widthcentpercentminusx');
1460 if ($user->admin) {
1461 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1462 }
1463 print '</td></tr>';
1464
1465 // State
1466 if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
1467 if ((getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 || getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 2)) {
1468 print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1469 } else {
1470 print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
1471 }
1472
1473 if ($object->country_id) {
1474 print img_picto('', 'state', 'class="pictofixedwidth"');
1475 print $formcompany->select_state($object->state_id, $object->country_code, 'state_id', 'minwidth200 maxwidth300 widthcentpercentminusx');
1476 } else {
1477 print $countrynotdefined;
1478 }
1479 print '</td></tr>';
1480 }
1481
1482 // Phone / Fax
1483 print '<tr><td>'.$form->editfieldkey('Phone', 'phone', '', $object, 0).'</td>';
1484 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>';
1485
1486 if ($conf->browser->layout == 'phone') {
1487 print '</tr><tr>';
1488 }
1489
1490 // Phone mobile
1491 print '<td>'.$form->editfieldkey('PhoneMobile', 'phone_mobile', '', $object, 0).'</td>';
1492 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>';
1493
1494 // Fax
1495 print '<tr>';
1496 print '<td>'.$form->editfieldkey('Fax', 'fax', '', $object, 0).'</td>';
1497 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>';
1498
1499 // Email / Web
1500 print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', !getDolGlobalString('SOCIETE_EMAIL_MANDATORY') ? '' : $conf->global->SOCIETE_EMAIL_MANDATORY).'</td>';
1501 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>';
1502 if (isModEnabled('mailing') && getDolGlobalString('THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION')) {
1503 if ($conf->browser->layout == 'phone') {
1504 print '</tr><tr>';
1505 }
1506 print '<td class="individualline noemail">'.$form->editfieldkey($langs->trans('No_Email') .' ('.$langs->trans('Contact').')', 'contact_no_email', '', $object, 0).'</td>';
1507 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>';
1508 }
1509 print '</tr>';
1510 print '<tr><td>'.$form->editfieldkey('Web', 'url', '', $object, 0).'</td>';
1511 print '<td colspan="3">'.img_picto('', 'globe', 'class="pictofixedwidth"').' <input type="text" class="maxwidth500 widthcentpercentminusx" name="url" id="url" value="'.$object->url.'"></td></tr>';
1512
1513 // Unsubscribe
1514 if (isModEnabled('mailing')) {
1515 if ($conf->use_javascript_ajax && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2) {
1516 print "\n".'<script type="text/javascript">'."\n";
1517 print '$(document).ready(function () {
1518 $("#email").keyup(function() {
1519 if ($(this).val()!="") {
1520 $(".noemail").addClass("fieldrequired");
1521 } else {
1522 $(".noemail").removeClass("fieldrequired");
1523 }
1524 });
1525 })'."\n";
1526 print '</script>'."\n";
1527 }
1528 if (!GETPOSTISSET("no_email") && !empty($object->email)) {
1529 $result = $object->getNoEmail();
1530 if ($result < 0) {
1531 setEventMessages($object->error, $object->errors, 'errors');
1532 }
1533 }
1534 print '<tr>';
1535 print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
1536 print '<td>';
1537 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));
1538 print '</td>';
1539 print '</tr>';
1540 }
1541
1542 // Social networks
1543 if (isModEnabled('socialnetworks')) {
1544 $object->showSocialNetwork($socialnetworks, ($conf->browser->layout == 'phone' ? 2 : 4));
1545 }
1546
1547 // Prof ids
1548 $i = 1;
1549 $j = 0;
1550 $NBCOLS = ($conf->browser->layout == 'phone' ? 1 : 2);
1551 $NBPROFIDMIN = getDolGlobalInt('THIRDPARTY_MIN_NB_PROF_ID', 2);
1552 $NBPROFIDMAX = getDolGlobalInt('THIRDPARTY_MAX_NB_PROF_ID', 6);
1553 while ($i <= $NBPROFIDMAX) {
1554 $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
1555 if ($idprof != '-' && ($i <= $NBPROFIDMIN || !empty($langs->tab_translate['ProfId'.$i.$object->country_code]))) {
1556 $key = 'idprof'.$i;
1557
1558 if (($j % $NBCOLS) == 0) {
1559 print '<tr>';
1560 }
1561
1562 $idprof_mandatory = 'SOCIETE_IDPROF'.($i).'_MANDATORY';
1563 print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', (empty($conf->global->$idprof_mandatory) ? 0 : 1)).'</td><td>';
1564
1565 print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
1566 print '</td>';
1567 if (($j % $NBCOLS) == ($NBCOLS - 1)) {
1568 print '</tr>';
1569 }
1570 $j++;
1571 }
1572 $i++;
1573 }
1574 if ($NBCOLS > 1 && ($j % 2 == 1)) {
1575 print '<td colspan="2"></td></tr>';
1576 }
1577
1578 // Vat is used
1579 print '<tr><td>'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).'</td>';
1580 print '<td>';
1581 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
1582 print '</td>';
1583 if ($conf->browser->layout == 'phone') {
1584 print '</tr><tr>';
1585 }
1586 print '<td class="nowrap">'.$form->editfieldkey('VATIntra', 'intra_vat', '', $object, 0).'</td>';
1587 print '<td class="nowrap">';
1588 $s = '<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
1589
1590 if (!getDolGlobalString('MAIN_DISABLEVATCHECK') && isInEEC($object)) {
1591 $s .= ' ';
1592
1593 if (!empty($conf->use_javascript_ajax)) {
1594 $widthpopup = 600;
1595 if (!empty($conf->dol_use_jmobile)) {
1596 $widthpopup = 350;
1597 }
1598 $heightpopup = 400;
1599 print "\n";
1600 print '<script type="text/javascript">';
1601 print "function CheckVAT(a) {\n";
1602 if ($mysoc->country_code == 'GR' && $object->country_code == 'GR' && !empty($u)) {
1603 print "GRVAT(a,'{$u}','{$p}','{$myafm}');\n";
1604 } else {
1605 print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a, '".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
1606 }
1607 print "}\n";
1608 print '</script>';
1609 print "\n";
1610 $s .= '<a href="#" class="hideonsmartphone" onclick="CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
1611 $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1);
1612 } else {
1613 $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", $object->country_id).'" target="_blank" rel="noopener noreferrer">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
1614 }
1615 }
1616 print $s;
1617 print '</td>';
1618 print '</tr>';
1619
1620 // VAT reverse charge by default
1621 if (getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) {
1622 print '<tr><td>' . $form->editfieldkey('VATReverseChargeByDefault', 'vat_reverse_charge', '', $object, 0) . '</td><td colspan="3">';
1623 print '<input type="checkbox" name="vat_reverse_charge" '.($object->vat_reverse_charge == '1' ? ' checked' : '').'>';
1624 print '</td></tr>';
1625 }
1626
1627 // Local Taxes
1628 //TODO: Place into a function to control showing by country or study better option
1629 if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
1630 print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
1631 print '<input id="localtax1assuj_value" name="localtax1assuj_value" type="checkbox" ' . (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1) ? 'checked="checked"' : '') . ' value="1">';
1632 print '</td>';
1633 if ($conf->browser->layout == 'phone') {
1634 print '</tr><tr>';
1635 }
1636 print '<td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
1637 print '<input id="localtax2assuj_value" name="localtax2assuj_value" type="checkbox" ' . (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2) ? 'checked="checked"' : '') . ' value="1">';
1638 print '</td></tr>';
1639 } elseif ($mysoc->localtax1_assuj == "1") {
1640 print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td colspan="3">';
1641 print '<input id="localtax1assuj_value" name="localtax1assuj_value" type="checkbox" ' . (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1) ? 'checked="checked"' : '') . ' value="1">';
1642 print '</td></tr>';
1643 } elseif ($mysoc->localtax2_assuj == "1") {
1644 print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td colspan="3">';
1645 print '<input id="localtax2assuj_value" name="localtax2assuj_value" type="checkbox" ' . (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2) ? 'checked="checked"' : '') . ' value="1">';
1646 print '</td></tr>';
1647 }
1648
1649 // Type - Workforce/Staff
1650 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";
1651 $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.
1652 print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 1, 0, 0, '', 0, 0, 0, $sortparam, '', 1);
1653 if ($user->admin) {
1654 print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1655 }
1656 if (!getDolGlobalString('SOCIETE_DISABLE_WORKFORCE')) {
1657 print '</td>';
1658 if ($conf->browser->layout == 'phone') {
1659 print '</tr><tr>';
1660 }
1661 print '<td>'.$form->editfieldkey('Workforce', 'effectif_id', '', $object, 0).'</td><td class="maxwidthonsmartphone"'.($conf->browser->layout == 'phone' ? ' colspan="3"' : '').'>';
1662 print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id, 0, 0, 0, '', 0, 0, 0, '', '', 1);
1663 if ($user->admin) {
1664 print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1665 }
1666 } else {
1667 print '<input type="hidden" name="effectif_id" id="effectif_id" value="'.$object->effectif_id.'">';
1668 }
1669 print '</td></tr>';
1670
1671 // Legal Form
1672 print '<tr><td>'.$form->editfieldkey('JuridicalStatus', 'forme_juridique_code', '', $object, 0).'</td>';
1673 print '<td colspan="3" class="maxwidthonsmartphone">';
1674 if ($object->country_id) {
1675 print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code');
1676 } else {
1677 print $countrynotdefined;
1678 }
1679 print '</td></tr>';
1680
1681 // Capital
1682 print '<tr><td>'.$form->editfieldkey('Capital', 'capital', '', $object, 0).'</td>';
1683 print '<td colspan="3"><input type="text" name="capital" id="capital" class="maxwidth100" value="'.$object->capital.'"> ';
1684 if (isModEnabled("multicurrency")) {
1685 print '<span class="hideonsmartphone">'.$langs->trans("Currency".$object->multicurrency_code).'</span></td></tr>';
1686 } else {
1687 print '<span class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
1688 }
1689 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1690 print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
1691 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');
1692 print '</td>';
1693 print '</tr>';
1694 }
1695
1696 // Incoterms
1697 if (isModEnabled('incoterm')) {
1698 print '<tr>';
1699 print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
1700 print '<td colspan="3" class="maxwidthonsmartphone">';
1701 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
1702 print '</td></tr>';
1703 }
1704
1705 // Categories
1706 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1707 $langs->load('categories');
1708
1709 // Customer
1710 print '<tr class="visibleifcustomer"><td class="toptd">'.$form->editfieldkey('CustomersProspectsCategoriesShort', 'custcats', '', $object, 0).'</td><td colspan="3">';
1711 $cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, '', 'parent', 64, 0, 3);
1712 print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('custcats', $cate_arbo, GETPOST('custcats', 'array'), null, null, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
1713 print "</td></tr>";
1714
1715 if (getDolGlobalString('THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION')) {
1716 print '<tr class="individualline"><td class="toptd">'.$form->editfieldkey('ContactCategoriesShort', 'contcats', '', $object, 0).'</td><td colspan="3">';
1717 $cate_arbo = $form->select_all_categories(Categorie::TYPE_CONTACT, '', 'parent', 64, 0, 3);
1718 print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('contcats', $cate_arbo, GETPOST('contcats', 'array'), null, null, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
1719 print "</td></tr>";
1720 }
1721
1722 // Supplier
1723 if (isModEnabled("supplier_proposal") || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
1724 print '<tr class="visibleifsupplier"><td class="toptd">'.$form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0).'</td><td colspan="3">';
1725 $cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, '', 'parent', 64, 0, 3);
1726 print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('suppcats', $cate_arbo, GETPOST('suppcats', 'array'), null, null, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
1727 print "</td></tr>";
1728 }
1729 }
1730
1731 // Multicurrency
1732 if (isModEnabled("multicurrency")) {
1733 print '<tr>';
1734 print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
1735 print '<td colspan="3" class="maxwidthonsmartphone">';
1736 print img_picto('', 'currency', 'class="pictofixedwidth"');
1737 print $form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code') : ($object->multicurrency_code ? $object->multicurrency_code : $conf->currency)), 'multicurrency_code', 1, '', false, 'maxwidth150 widthcentpercentminusx');
1738 print '</td></tr>';
1739 }
1740
1741 // Other attributes
1742 $parameters = array('socid' => $socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
1743 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
1744
1745 // Parent company
1746 if (!getDolGlobalString('SOCIETE_DISABLE_PARENTCOMPANY')) {
1747 print '<tr>';
1748 print '<td>'.$langs->trans('ParentCompany').'</td>';
1749 print '<td colspan="3" class="maxwidthonsmartphone">';
1750 print img_picto('', 'company', 'class="paddingrightonly"');
1751 print $form->select_company(GETPOST('parent_company_id'), 'parent_company_id', '', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300 maxwidth500 widthcentpercentminusxx');
1752 print '</td></tr>';
1753 }
1754
1755 // Assign a sale representative
1756 print '<tr>';
1757 print '<td>'.$form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0).'</td>';
1758 print '<td colspan="3" class="maxwidthonsmartphone">';
1759 // TODO Use select_doluser in multiselect mode
1760 $userlist = $form->select_dolusers($selected, '', 0, null, 0, '', '', '0', 0, 0, 'AND u.statut = 1', 0, '', '', 0, 2);
1761 // 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.
1762 $selected = (GETPOSTISARRAY('commercial') ? GETPOST('commercial', 'array:int') : (GETPOSTINT('commercial') > 0 ? array(GETPOSTINT('commercial')) : array($user->id)));
1763 print img_picto('', 'user').$form->multiselectarray('commercial', $userlist, $selected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
1764 print '</td></tr>';
1765
1766 // Add logo
1767 print '<tr class="hideonsmartphone">';
1768 print '<td>'.$form->editfieldkey('Logo', 'photoinput', '', $object, 0).'</td>';
1769 print '<td colspan="3">';
1770 print '<input class="flat" type="file" name="photo" id="photoinput" />';
1771 print '</td>';
1772 print '</tr>';
1773
1774 print '</table>'."\n";
1775
1776 // Accountancy codes
1777 if (getDolGlobalString('ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY')) {
1778 print '<table class="border centpercent">';
1779
1780 if (isModEnabled('accounting')) {
1781 // Accountancy_code_sell
1782 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
1783 print '<td>';
1784 $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
1785 print $formaccounting->select_account($accountancy_code_sell, 'accountancy_code_sell', 1, null, 1, 1, '');
1786 print '</td></tr>';
1787
1788 // Accountancy_code_buy
1789 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyCode").'</td>';
1790 print '<td>';
1791 $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
1792 print $formaccounting->select_account($accountancy_code_buy, 'accountancy_code_buy', 1, null, 1, 1, '');
1793 print '</td></tr>';
1794 } else { // For external software
1795 // Accountancy_code_sell
1796 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
1797 print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code_sell" value="'.$object->accountancy_code_sell.'">';
1798 print '</td></tr>';
1799
1800 // Accountancy_code_buy
1801 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyCode").'</td>';
1802 print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code_buy" value="'.$object->accountancy_code_buy.'">';
1803 print '</td></tr>';
1804 }
1805
1806 print '</table>';
1807 }
1808 }
1809
1810 print dol_get_fiche_end();
1811
1812 print $form->buttonsSaveCancel("AddThirdParty", 'Cancel', null, 0, '', $dol_openinpopup);
1813
1814 print '</form>'."\n";
1815 } elseif ($action == 'edit') {
1816 //print load_fiche_titre($langs->trans("EditCompany"));
1817
1818 if ($socid) {
1819 $res = $object->fetch_optionals();
1820 //if ($res < 0) { dol_print_error($db); exit; }
1821
1823
1824 // Load object modCodeTiers
1825 $module = getDolGlobalString('SOCIETE_CODECLIENT_ADDON', 'mod_codeclient_leopard');
1826 if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
1827 $module = substr($module, 0, dol_strlen($module) - 4);
1828 }
1829 $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
1830 foreach ($dirsociete as $dirroot) {
1831 $res = dol_include_once($dirroot.$module.'.php');
1832 if ($res) {
1833 break;
1834 }
1835 }
1836 $modCodeClient = new $module($db);
1837 // We check if the prefix tag is used
1838 if ($modCodeClient->code_auto) {
1839 $prefixCustomerIsUsed = $modCodeClient->verif_prefixIsUsed();
1840 }
1841 $module = getDolGlobalString('SOCIETE_CODECLIENT_ADDON');
1842 if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
1843 $module = substr($module, 0, dol_strlen($module) - 4);
1844 }
1845 $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
1846 foreach ($dirsociete as $dirroot) {
1847 $res = dol_include_once($dirroot.$module.'.php');
1848 if ($res) {
1849 break;
1850 }
1851 }
1852 $modCodeFournisseur = new $module($db);
1853 // We check if the prefix tag is used
1854 if ($modCodeFournisseur->code_auto) {
1855 $prefixSupplierIsUsed = $modCodeFournisseur->verif_prefixIsUsed();
1856 }
1857
1858 $object->oldcopy = clone $object;
1859
1860 if (GETPOSTISSET('name')) {
1861 // We overwrite with values if posted
1862 $object->name = GETPOST('name', 'alphanohtml');
1863 $object->name_alias = GETPOST('name_alias', 'alphanohtml');
1864 $object->prefix_comm = GETPOST('prefix_comm', 'alphanohtml');
1865 $object->client = GETPOSTINT('client');
1866 $object->code_client = GETPOST('customer_code', 'alpha');
1867 $object->fournisseur = GETPOSTINT('fournisseur');
1868 $object->code_fournisseur = GETPOST('supplier_code', 'alpha');
1869 $object->address = GETPOST('address', 'alphanohtml');
1870 $object->zip = GETPOST('zipcode', 'alphanohtml');
1871 $object->town = GETPOST('town', 'alphanohtml');
1872 $object->country_id = GETPOST('country_id') ? GETPOSTINT('country_id') : $mysoc->country_id;
1873 $object->state_id = GETPOSTINT('state_id');
1874 $object->parent = GETPOSTINT('parent_company_id');
1875
1876 $object->socialnetworks = array();
1877 if (isModEnabled('socialnetworks')) {
1878 foreach ($socialnetworks as $key => $value) {
1879 if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
1880 $object->socialnetworks[$key] = GETPOST($key, 'alphanohtml');
1881 }
1882 }
1883 }
1884
1885 $object->phone = GETPOST('phone', 'alpha');
1886 $object->phone_mobile = (string) GETPOST('phone_mobile', 'alpha');
1887 $object->fax = GETPOST('fax', 'alpha');
1888 $object->email = GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL);
1889 $object->no_email = GETPOSTINT("no_email");
1890 $object->url = GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL);
1891 $object->capital = GETPOST('capital', 'alphanohtml');
1892 $object->idprof1 = GETPOST('idprof1', 'alphanohtml');
1893 $object->idprof2 = GETPOST('idprof2', 'alphanohtml');
1894 $object->idprof3 = GETPOST('idprof3', 'alphanohtml');
1895 $object->idprof4 = GETPOST('idprof4', 'alphanohtml');
1896 $object->idprof5 = GETPOST('idprof5', 'alphanohtml');
1897 $object->idprof6 = GETPOST('idprof6', 'alphanohtml');
1898 $object->typent_id = GETPOSTINT('typent_id');
1899 $object->effectif_id = GETPOSTINT('effectif_id');
1900 $object->barcode = GETPOST('barcode', 'alphanohtml');
1901 $object->forme_juridique_code = GETPOSTINT('forme_juridique_code');
1902 $object->default_lang = GETPOST('default_lang', 'alpha');
1903
1904 $object->tva_assuj = GETPOSTINT('assujtva_value');
1905 $object->vat_reverse_charge = GETPOST('vat_reverse_charge') == 'on' ? 1 : 0;
1906 $object->tva_intra = GETPOST('tva_intra', 'alphanohtml');
1907 $object->status = GETPOSTINT('status');
1908
1909 // Webservices url/key
1910 $object->webservices_url = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
1911 $object->webservices_key = GETPOST('webservices_key', 'san_alpha');
1912
1913 if (GETPOSTISSET('accountancy_code_sell')) {
1914 $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
1915
1916 if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') {
1917 $object->accountancy_code_sell = '';
1918 } else {
1919 $object->accountancy_code_sell = $accountancy_code_sell;
1920 }
1921 }
1922 if (GETPOSTISSET('accountancy_code_buy')) {
1923 $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
1924
1925 if (empty($accountancy_code_buy) || $accountancy_code_buy == '-1') {
1926 $object->accountancy_code_buy = '';
1927 } else {
1928 $object->accountancy_code_buy = $accountancy_code_buy;
1929 }
1930 }
1931
1932 //Incoterms
1933 if (isModEnabled('incoterm')) {
1934 $object->fk_incoterms = GETPOSTINT('incoterm_id');
1935 $object->location_incoterms = GETPOST('lcoation_incoterms', 'alpha');
1936 }
1937
1938 //Local Taxes
1939 $object->localtax1_assuj = GETPOST('localtax1assuj_value');
1940 $object->localtax2_assuj = GETPOST('localtax2assuj_value');
1941
1942 $object->localtax1_value = GETPOST('lt1');
1943 $object->localtax2_value = GETPOST('lt2');
1944
1945 // We set country_id, and country_code label of the chosen country
1946 if ($object->country_id > 0) {
1947 $tmparray = getCountry($object->country_id, 'all');
1948 $object->country_code = $tmparray['code'];
1949 $object->country = $tmparray['label'];
1950 }
1951
1952 // We set multicurrency_code if enabled
1953 if (isModEnabled("multicurrency")) {
1954 $object->multicurrency_code = GETPOST('multicurrency_code') ? GETPOST('multicurrency_code') : $object->multicurrency_code;
1955 }
1956 }
1957
1958 if ($object->localtax1_assuj == 0) {
1959 $sub = 0;
1960 } else {
1961 $sub = 1;
1962 }
1963 if ($object->localtax2_assuj == 0) {
1964 $sub2 = 0;
1965 } else {
1966 $sub2 = 1;
1967 }
1968
1969 if (!empty($conf->use_javascript_ajax)) {
1970 print "\n".'<script type="text/javascript">';
1971 print '$(document).ready(function () {
1972 var val='.$sub.';
1973 var val2='.$sub2.';
1974 if("#localtax1assuj_value".value==undefined){
1975 if(val==1){
1976 $(".cblt1").show();
1977 }else{
1978 $(".cblt1").hide();
1979 }
1980 }
1981 if("#localtax2assuj_value".value==undefined){
1982 if(val2==1){
1983 $(".cblt2").show();
1984 }else{
1985 $(".cblt2").hide();
1986 }
1987 }
1988 $("#localtax1assuj_value").change(function() {
1989 var value=document.getElementById("localtax1assuj_value").value;
1990 if(value==1){
1991 $(".cblt1").show();
1992 }else{
1993 $(".cblt1").hide();
1994 }
1995 });
1996 $("#localtax2assuj_value").change(function() {
1997 var value=document.getElementById("localtax2assuj_value").value;
1998 if(value==1){
1999 $(".cblt2").show();
2000 }else{
2001 $(".cblt2").hide();
2002 }
2003 });
2004
2005 var canHaveCustomerCategoryIfNotCustomerProspect = ' . (getDolGlobalInt('THIRDPARTY_CAN_HAVE_CUSTOMER_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT') ? '1' : '0') . ';
2006
2007 init_customer_categ();
2008 $("#customerprospect").change(function() {
2009 init_customer_categ();
2010 });
2011 function init_customer_categ() {
2012 console.log("is customer or prospect = "+jQuery("#customerprospect").val());
2013 if (jQuery("#customerprospect").val() == 0 && !canHaveCustomerCategoryIfNotCustomerProspect)
2014 {
2015 jQuery(".visibleifcustomer").hide();
2016 }
2017 else
2018 {
2019 jQuery(".visibleifcustomer").show();
2020 }
2021 }
2022
2023 init_supplier_categ();
2024 $("#fournisseur").change(function() {
2025 init_supplier_categ();
2026 });
2027 function init_supplier_categ() {
2028 console.log("is supplier = "+jQuery("#fournisseur").val());
2029 if (jQuery("#fournisseur").val() == 0)
2030 {
2031 jQuery(".visibleifsupplier").hide();
2032 }
2033 else
2034 {
2035 jQuery(".visibleifsupplier").show();
2036 }
2037 }
2038
2039 $("#selectcountry_id").change(function() {
2040 console.log("selectcountry_id change");
2041 document.formsoc.action.value="edit";
2042 document.formsoc.submit();
2043 });
2044
2045 })';
2046 print '</script>'."\n";
2047 }
2048
2049 print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="post" name="formsoc">';
2050 print '<input type="hidden" name="action" value="update">';
2051 print '<input type="hidden" name="token" value="'.newToken().'">';
2052 print '<input type="hidden" name="socid" value="'.$object->id.'">';
2053 print '<input type="hidden" name="entity" value="'.$object->entity.'">';
2054 if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) {
2055 print '<input type="hidden" name="code_auto" value="1">';
2056 }
2057
2058
2059 print dol_get_fiche_head($head, 'card', $langs->trans("ThirdParty"), 0, 'company');
2060
2061 print '<div class="fichecenter2">';
2062 // Call Hook tabContentEditThirdparty
2063 $parameters = array();
2064 // Note that $action and $object may be modified by hook
2065 $reshook = $hookmanager->executeHooks('tabContentEditThirdparty', $parameters, $object, $action);
2066 if (empty($reshook)) {
2067 print '<table class="border centpercent">';
2068
2069 // Ref/ID
2070 if (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
2071 print '<tr><td class="titlefieldcreate">'.$langs->trans("ID").'</td><td colspan="3">';
2072 print $object->ref;
2073 print '</td></tr>';
2074 }
2075
2076 // Name
2077 print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0, 'string', '', 1).'</td>';
2078 print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.dol_escape_htmltag($object->name).'" autofocus="autofocus">';
2079 print $form->widgetForTranslation("name", $object, $permissiontoadd, 'string', 'alphanohtml', 'minwidth300');
2080 print '</td></tr>';
2081
2082 // Alias names (commercial, trademark or alias names)
2083 print '<tr id="name_alias"><td><label for="name_alias_input">'.$langs->trans('AliasNames').'</label></td>';
2084 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>';
2085
2086 // Prefix
2087 if (getDolGlobalString('SOCIETE_USEPREFIX')) { // Old not used prefix field
2088 print '<tr><td>'.$form->editfieldkey('Prefix', 'prefix', '', $object, 0).'</td><td colspan="3">';
2089 // It does not change the prefix mode using the auto numbering prefix
2090 if (($prefixCustomerIsUsed || $prefixSupplierIsUsed) && $object->prefix_comm) {
2091 print '<input type="hidden" name="prefix_comm" value="'.dol_escape_htmltag($object->prefix_comm).'">';
2092 print $object->prefix_comm;
2093 } else {
2094 print '<input type="text" size="5" maxlength="5" name="prefix_comm" id="prefix" value="'.dol_escape_htmltag($object->prefix_comm).'">';
2095 }
2096 print '</td>';
2097 }
2098
2099 // Prospect/Customer
2100 print '<tr><td>'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).'</td>';
2101 print '<td class="maxwidthonsmartphone">';
2102 print $formcompany->selectProspectCustomerType($object->client);
2103 print '</td>';
2104 if ($conf->browser->layout == 'phone') {
2105 print '</tr><tr>';
2106 }
2107 print '<td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
2108
2109 print '<table class="nobordernopadding"><tr><td>';
2110 if ((!$object->code_client || $object->code_client == -1) && $modCodeClient->code_auto) {
2111 $tmpcode = $object->code_client;
2112 if (empty($tmpcode) && !empty($object->oldcopy->code_client)) {
2113 $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.
2114 }
2115 if (empty($tmpcode) && !empty($modCodeClient->code_auto)) {
2116 $tmpcode = $modCodeClient->getNextValue($object, 0);
2117 }
2118 print '<input type="text" name="customer_code" id="customer_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="24">';
2119 } elseif ($object->codeclient_modifiable()) {
2120 print '<input type="text" name="customer_code" id="customer_code" size="16" value="'.dol_escape_htmltag($object->code_client).'" maxlength="24">';
2121 } else {
2122 print $object->code_client;
2123 print '<input type="hidden" name="customer_code" value="'.dol_escape_htmltag($object->code_client).'">';
2124 }
2125 print '</td><td>';
2126 $s = $modCodeClient->getToolTip($langs, $object, 0);
2127 print $form->textwithpicto('', $s, 1);
2128 print '</td></tr></table>';
2129
2130 print '</td></tr>';
2131
2132 // Supplier
2133 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')))
2134 || (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire'))) {
2135 print '<tr>';
2136 print '<td>'.$form->editfieldkey('Supplier', 'fournisseur', '', $object, 0, 'string', '', 1).'</td>';
2137 print '<td class="maxwidthonsmartphone">';
2138 print $form->selectyesno("fournisseur", $object->fournisseur, 1, false, 0, 1);
2139 print '</td>';
2140 if ($conf->browser->layout == 'phone') {
2141 print '</tr><tr>';
2142 }
2143 print '<td>';
2144 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'))) {
2145 print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0);
2146 }
2147 print '</td>';
2148 print '<td>';
2149 print '<table class="nobordernopadding"><tr><td>';
2150 if ((!$object->code_fournisseur || $object->code_fournisseur == -1) && $modCodeFournisseur->code_auto) {
2151 $tmpcode = $object->code_fournisseur;
2152 if (empty($tmpcode) && !empty($object->oldcopy->code_fournisseur)) {
2153 $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.
2154 }
2155 if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) {
2156 $tmpcode = $modCodeFournisseur->getNextValue($object, 1);
2157 }
2158 print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="24">';
2159 } elseif ($object->codefournisseur_modifiable()) {
2160 print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.dol_escape_htmltag($object->code_fournisseur).'" maxlength="24">';
2161 } else {
2162 print $object->code_fournisseur;
2163 print '<input type="hidden" name="supplier_code" value="'.$object->code_fournisseur.'">';
2164 }
2165 print '</td><td>';
2166 $s = $modCodeFournisseur->getToolTip($langs, $object, 1);
2167 print $form->textwithpicto('', $s, 1);
2168 print '</td></tr></table>';
2169 print '</td></tr>';
2170 }
2171
2172 // Barcode
2173 if (isModEnabled('barcode')) {
2174 print '<tr><td class="tdtop">'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).'</td>';
2175 print '<td colspan="3">';
2176 print img_picto('', 'barcode', 'class="pictofixedwidth"');
2177 print '<input type="text" name="barcode" id="barcode" value="'.dol_escape_htmltag($object->barcode).'">';
2178 print '</td></tr>';
2179 }
2180
2181 // Status
2182 print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0).'</td><td colspan="3">';
2183 print $form->selectarray('status', array('0' => $langs->trans('ActivityCeased'), '1' => $langs->trans('InActivity')), $object->status, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
2184 print '</td></tr>';
2185
2186 // Address
2187 print '<tr><td class="tdtop">'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
2188 print '<td colspan="3"><textarea name="address" id="address" class="quatrevingtpercent" rows="3" wrap="soft">';
2189 print dol_escape_htmltag($object->address, 0, 1);
2190 print '</textarea>';
2191 print $form->widgetForTranslation("address", $object, $permissiontoadd, 'textarea', 'alphanohtml', 'quatrevingtpercent');
2192 print '</td></tr>';
2193
2194 // Zip / Town
2195 print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td'.($conf->browser->layout == 'phone' ? ' colspan="3"' : '').'>';
2196 print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100');
2197 print '</td>';
2198 if ($conf->browser->layout == 'phone') {
2199 print '</tr><tr>';
2200 }
2201 print '<td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td'.($conf->browser->layout == 'phone' ? ' colspan="3"' : '').'>';
2202 print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
2203 print $form->widgetForTranslation("town", $object, $permissiontoadd, 'string', 'alphanohtml', 'maxwidth100 quatrevingtpercent');
2204 print '</td></tr>';
2205
2206 // Country
2207 print '<tr><td>'.$form->editfieldkey('Country', 'selectcounty_id', '', $object, 0).'</td><td colspan="3">';
2208 print img_picto('', 'globe-americas', 'class="pictofixedwidth"');
2209 print $form->select_country((GETPOSTISSET('country_id') ? GETPOST('country_id') : $object->country_id), 'country_id', '', 0, 'minwidth300 maxwidth500 widthcentpercentminusx');
2210 if ($user->admin) {
2211 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
2212 }
2213 print '</td></tr>';
2214
2215 // State
2216 if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
2217 if ((getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 || getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 2)) {
2218 print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td colspan="3">';
2219 } else {
2220 print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td colspan="3">';
2221 }
2222
2223 print img_picto('', 'state', 'class="pictofixedwidth"');
2224 print $formcompany->select_state($object->state_id, $object->country_code);
2225 print '</td></tr>';
2226 }
2227
2228 // Phone / Fax
2229 print '<tr><td>'.$form->editfieldkey('Phone', 'phone', GETPOST('phone', 'alpha'), $object, 0).'</td>';
2230 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>';
2231 if ($conf->browser->layout == 'phone') {
2232 print '</tr><tr>';
2233 }
2234 print '<td>'.$form->editfieldkey('PhoneMobile', 'phone_mobile', GETPOST('phone_mobile', 'alpha'), $object, 0).'</td>';
2235 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>';
2236
2237 print '<td>'.$form->editfieldkey('Fax', 'fax', GETPOST('fax', 'alpha'), $object, 0).'</td>';
2238 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>';
2239 print '</tr>';
2240
2241 // Web
2242 print '<tr><td>'.$form->editfieldkey('Web', 'url', GETPOST('url', 'alpha'), $object, 0).'</td>';
2243 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>';
2244
2245 // EMail
2246 print '<tr><td>'.$form->editfieldkey('EMail', 'email', GETPOST('email', 'alpha'), $object, 0, 'string', '', (getDolGlobalString('SOCIETE_EMAIL_MANDATORY'))).'</td>';
2247 print '<td colspan="3">';
2248 print img_picto('', 'object_email', 'class="pictofixedwidth"');
2249 print '<input type="text" name="email" id="email" class="maxwidth500 widthcentpercentminusx" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alpha') : $object->email).'">';
2250 print '</td></tr>';
2251
2252 // Unsubscribe
2253 if (isModEnabled('mailing')) {
2254 if ($conf->use_javascript_ajax && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2) {
2255 print "\n".'<script type="text/javascript">'."\n";
2256
2257 print '
2258 jQuery(document).ready(function () {
2259 function init_check_no_email(input) {
2260 if (input.val()!="") {
2261 $(".noemail").addClass("fieldrequired");
2262 } else {
2263 $(".noemail").removeClass("fieldrequired");
2264 }
2265 }
2266 $("#email").keyup(function() {
2267 init_check_no_email($(this));
2268 });
2269 init_check_no_email($("#email"));
2270 })'."\n";
2271 print '</script>'."\n";
2272 }
2273 if (!GETPOSTISSET("no_email") && !empty($object->email)) {
2274 $result = $object->getNoEmail();
2275 if ($result < 0) {
2276 setEventMessages($object->error, $object->errors, 'errors');
2277 }
2278 }
2279 print '<tr>';
2280 print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
2281 print '<td>';
2282 $useempty = (getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2);
2283 print $form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOSTINT("no_email") : $object->no_email), 1, false, $useempty);
2284 print '</td>';
2285 print '</tr>';
2286 }
2287
2288 // Social network
2289 if (isModEnabled('socialnetworks')) {
2290 $object->showSocialNetwork($socialnetworks, ($conf->browser->layout == 'phone' ? 2 : 4));
2291 }
2292
2293 // Prof ids
2294 $i = 1;
2295 $j = 0;
2296 $NBCOLS = ($conf->browser->layout == 'phone' ? 1 : 2);
2297 $NBPROFIDMIN = getDolGlobalInt('THIRDPARTY_MIN_NB_PROF_ID', 2);
2298 $NBPROFIDMAX = getDolGlobalInt('THIRDPARTY_MAX_NB_PROF_ID', 6);
2299 while ($i <= $NBPROFIDMAX) {
2300 $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
2301 if ($idprof != '-' && ($i <= $NBPROFIDMIN || !empty($langs->tab_translate['ProfId'.$i.$object->country_code]))) {
2302 $key = 'idprof'.$i;
2303
2304 if (($j % $NBCOLS) == 0) {
2305 print '<tr>';
2306 }
2307
2308 $idprof_mandatory = 'SOCIETE_IDPROF'.($i).'_MANDATORY';
2309 print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', !(empty($conf->global->$idprof_mandatory) || !$object->isACompany())).'</td><td>';
2310 print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
2311 print '</td>';
2312 if (($j % $NBCOLS) == ($NBCOLS - 1)) {
2313 print '</tr>';
2314 }
2315 $j++;
2316 }
2317 $i++;
2318 }
2319 if ($NBCOLS > 0 && $j % 2 == 1) {
2320 print '<td colspan="2"></td></tr>';
2321 }
2322
2323 // VAT is used
2324 print '<tr><td>'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).'</td><td colspan="3">';
2325 print '<input id="assujtva_value" name="assujtva_value" type="checkbox" ' . ($object->tva_assuj ? 'checked="checked"' : '') . ' value="1">';
2326 print '</td></tr>';
2327
2328 // Local Taxes
2329 //TODO: Place into a function to control showing by country or study better option
2330 if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
2331 print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td>';
2332 print '<input id="localtax1assuj_value" name="localtax1assuj_value" type="checkbox" ' . ($object->localtax1_assuj ? 'checked="checked"' : '') . ' value="1">';
2333 if (!isOnlyOneLocalTax(1)) {
2334 print '<span class="cblt1"> '.$langs->transcountry("Type", $mysoc->country_code).': ';
2335 $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
2336 print '</span>';
2337 }
2338 print '</td>';
2339 print '</tr><tr>';
2340 print '<td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td>';
2341 print '<input id="localtax2assuj_value" name="localtax2assuj_value" type="checkbox" ' . ($object->localtax2_assuj ? 'checked="checked"' : '') . ' value="1"></td></tr>';
2342 if (!isOnlyOneLocalTax(2)) {
2343 print '<span class="cblt2"> '.$langs->transcountry("Type", $mysoc->country_code).': ';
2344 $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
2345 print '</span>';
2346 }
2347 print '</td></tr>';
2348 } elseif ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj != "1") {
2349 print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td colspan="3">';
2350 print '<input id="localtax1assuj_value" name="localtax1assuj_value" type="checkbox" ' . ($object->localtax1_assuj ? 'checked="checked"' : '') . ' value="1">';
2351 if (!isOnlyOneLocalTax(1)) {
2352 print '<span class="cblt1"> '.$langs->transcountry("Type", $mysoc->country_code).': ';
2353 $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
2354 print '</span>';
2355 }
2356 print '</td></tr>';
2357 } elseif ($mysoc->localtax2_assuj == "1" && $mysoc->localtax1_assuj != "1") {
2358 print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td colspan="3">';
2359 print '<input id="localtax2assuj_value" name="localtax2assuj_value" type="checkbox" ' . ($object->localtax2_assuj ? 'checked="checked"' : '') . ' value="1">';
2360 if (!isOnlyOneLocalTax(2)) {
2361 print '<span class="cblt2"> '.$langs->transcountry("Type", $mysoc->country_code).': ';
2362 $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
2363 print '</span>';
2364 }
2365 print '</td></tr>';
2366 }
2367
2368 // VAT reverse charge by default
2369 if (getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) {
2370 print '<tr><td>' . $form->editfieldkey('VATReverseChargeByDefault', 'vat_reverse_charge', '', $object, 0) . '</td><td colspan="3">';
2371 print '<input type="checkbox" name="vat_reverse_charge" '.($object->vat_reverse_charge == '1' ? ' checked' : '').'>';
2372 print '</td></tr>';
2373 }
2374
2375 // VAT Code
2376 print '<tr><td>'.$form->editfieldkey('VATIntra', 'intra_vat', '', $object, 0).'</td>';
2377 print '<td colspan="3">';
2378 $s = '<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
2379
2380 if (!getDolGlobalString('MAIN_DISABLEVATCHECK') && isInEEC($object)) {
2381 $s .= ' &nbsp; ';
2382
2383 if ($conf->use_javascript_ajax) {
2384 $widthpopup = 600;
2385 if (!empty($conf->dol_use_jmobile)) {
2386 $widthpopup = 350;
2387 }
2388 $heightpopup = 400;
2389 print "\n";
2390 print '<script type="text/javascript">';
2391 print "function CheckVAT(a) {\n";
2392 if ($mysoc->country_code == 'GR' && $object->country_code == 'GR' && !empty($u)) {
2393 print "GRVAT(a,'{$u}','{$p}','{$myafm}');\n";
2394 } else {
2395 print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a, '".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
2396 }
2397 print "}\n";
2398 print '</script>';
2399 print "\n";
2400 $s .= '<a href="#" class="hideonsmartphone" onclick="CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
2401 $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1);
2402 } else {
2403 $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", $object->country_id).'" class="hideonsmartphone" target="_blank" rel="noopener noreferrer">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
2404 }
2405 }
2406 print $s;
2407 print '</td>';
2408 print '</tr>';
2409
2410 // Type - Workforce/Staff
2411 print '<tr><td>'.$form->editfieldkey('ThirdPartyType', 'typent_id', '', $object, 0).'</td><td class="maxwidthonsmartphone"'.(($conf->browser->layout == 'phone' || getDolGlobalString('SOCIETE_DISABLE_WORKFORCE')) ? ' colspan="3"' : '').'>';
2412 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);
2413 if ($user->admin) {
2414 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
2415 }
2416 if (!getDolGlobalString('SOCIETE_DISABLE_WORKFORCE')) {
2417 print '</td>';
2418 if ($conf->browser->layout == 'phone') {
2419 print '</tr><tr>';
2420 }
2421 print '<td>'.$form->editfieldkey('Workforce', 'effectif_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
2422 print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id, 0, 0, 0, '', 0, 0, 0, '', '', 1);
2423 if ($user->admin) {
2424 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
2425 }
2426 } else {
2427 print '<input type="hidden" name="effectif_id" id="effectif_id" value="'.$object->effectif_id.'">';
2428 }
2429 print '</td></tr>';
2430
2431 // Juridical type
2432 print '<tr><td>'.$form->editfieldkey('JuridicalStatus', 'forme_juridique_code', '', $object, 0).'</td><td class="maxwidthonsmartphone" colspan="3">';
2433 print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code');
2434 print '</td></tr>';
2435
2436 // Capital
2437 print '<tr><td>'.$form->editfieldkey('Capital', 'capital', '', $object, 0).'</td>';
2438 print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="';
2439 print $object->capital != '' ? dol_escape_htmltag(price($object->capital)) : '';
2440 if (isModEnabled("multicurrency")) {
2441 print '"> <span class="hideonsmartphone">'.$langs->trans("Currency".$object->multicurrency_code).'</span></td></tr>';
2442 } else {
2443 print '"> <span class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
2444 }
2445
2446 // Default language
2447 if (getDolGlobalInt('MAIN_MULTILANGS')) {
2448 print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3">'."\n";
2449 print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language($object->default_lang, 'default_lang', 0, null, '1', 0, 0, 'maxwidth300 widthcentpercentminusx');
2450 print '</td>';
2451 print '</tr>';
2452 }
2453
2454 // Incoterms
2455 if (isModEnabled('incoterm')) {
2456 print '<tr>';
2457 print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
2458 print '<td colspan="3" class="maxwidthonsmartphone">';
2459 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
2460 print '</td></tr>';
2461 }
2462
2463 // Categories
2464 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
2465 // Customer
2466 print '<tr class="visibleifcustomer"><td>'.$form->editfieldkey('CustomersCategoriesShort', 'custcats', '', $object, 0).'</td>';
2467 print '<td colspan="3">';
2468 $cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, '', '', 64, 0, 3);
2469 $c = new Categorie($db);
2470 $cats = $c->containing($object->id, Categorie::TYPE_CUSTOMER);
2471 $arrayselected = array();
2472 foreach ($cats as $cat) {
2473 $arrayselected[] = $cat->id;
2474 }
2475 print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('custcats', $cate_arbo, $arrayselected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
2476 print "</td></tr>";
2477
2478 // Supplier
2479 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'))) {
2480 print '<tr class="visibleifsupplier"><td>'.$form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0).'</td>';
2481 print '<td colspan="3">';
2482 $cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, '', '', 64, 0, 3);
2483 $c = new Categorie($db);
2484 $cats = $c->containing($object->id, Categorie::TYPE_SUPPLIER);
2485 $arrayselected = array();
2486 foreach ($cats as $cat) {
2487 $arrayselected[] = $cat->id;
2488 }
2489 print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('suppcats', $cate_arbo, $arrayselected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
2490 print "</td></tr>";
2491 }
2492 }
2493
2494 // Multicurrency
2495 if (isModEnabled("multicurrency")) {
2496 print '<tr>';
2497 print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
2498 print '<td colspan="3" class="maxwidthonsmartphone">';
2499 print img_picto('', 'currency', 'class="pictofixedwidth"');
2500 print $form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code') : ($object->multicurrency_code ? $object->multicurrency_code : $conf->currency)), 'multicurrency_code', 1, '', false, 'maxwidth150 widthcentpercentminusx');
2501 print '</td></tr>';
2502 }
2503
2504 // Other attributes
2505 $parameters = array('socid' => $socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
2506 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
2507
2508 // Parent company
2509 if (!getDolGlobalString('SOCIETE_DISABLE_PARENTCOMPANY')) {
2510 print '<tr>';
2511 print '<td>'.$langs->trans('ParentCompany').'</td>';
2512 print '<td colspan="3" class="maxwidthonsmartphone">';
2513 print img_picto('', 'company', 'class="pictofixedwidth"');
2514 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');
2515 print '</td></tr>';
2516 }
2517
2518 // Webservices url/key
2519 if (isModEnabled('webservicesclient')) {
2520 print '<tr><td>'.$form->editfieldkey('WebServiceURL', 'webservices_url', '', $object, 0).'</td>';
2521 print '<td><input type="text" name="webservices_url" id="webservices_url" value="'.$object->webservices_url.'"></td>';
2522 print '<td>'.$form->editfieldkey('WebServiceKey', 'webservices_key', '', $object, 0).'</td>';
2523 print '<td><input type="text" name="webservices_key" id="webservices_key" value="'.$object->webservices_key.'"></td></tr>';
2524 }
2525
2526 // Logo
2527 print '<tr class="hideonsmartphone">';
2528 print '<td>'.$form->editfieldkey('Logo', 'photoinput', '', $object, 0).'</td>';
2529 print '<td colspan="3">';
2530 if ($object->logo) {
2531 print $form->showphoto('societe', $object, 100, 0, 0, 'inline-block');
2532 }
2533 $caneditfield = 1;
2534 if ($caneditfield) {
2535 if ($object->logo) {
2536 print "<br>\n";
2537 }
2538 print '<table class="nobordernopadding">';
2539 if ($object->logo) {
2540 print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">'.$langs->trans("Delete").'</photo><br></td></tr>';
2541 }
2542 //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
2543 print '<tr><td>';
2544 $maxfilesizearray = getMaxFileSizeArray();
2545 $maxmin = $maxfilesizearray['maxmin'];
2546 if ($maxmin > 0) {
2547 print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
2548 }
2549 print '<input type="file" class="flat" name="photo" id="photoinput">';
2550 print '</td></tr>';
2551 print '</table>';
2552 }
2553 print '</td>';
2554 print '</tr>';
2555
2556 // Assign sale representative
2557 print '<tr>';
2558 print '<td>'.$form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0).'</td>';
2559 print '<td colspan="3" class="maxwidthonsmartphone">';
2560 $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, 'AND u.statut = 1', 0, '', '', 0, 1);
2561 $arrayselected = GETPOST('commercial', 'array');
2562 if (empty($arrayselected)) {
2563 $arrayselected = $object->getSalesRepresentatives($user, 1);
2564 }
2565 print img_picto('', 'user', 'class="pictofixedwidth"').$form->multiselectarray('commercial', $userlist, $arrayselected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0, '', '', '', 1);
2566 print '</td></tr>';
2567
2568 print '</table>';
2569
2570 if (getDolGlobalString('ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY')) {
2571 print '<br>';
2572 print '<table class="border centpercent">';
2573
2574 if (isModEnabled('accounting')) {
2575 // Accountancy_code_sell
2576 print '<tr><td>'.$langs->trans("ProductAccountancySellCode").'</td>';
2577 print '<td>';
2578 print $formaccounting->select_account($object->accountancy_code_sell, 'accountancy_code_sell', 1, '', 1, 1);
2579 print '</td></tr>';
2580
2581 // Accountancy_code_buy
2582 print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
2583 print '<td>';
2584 print $formaccounting->select_account($object->accountancy_code_buy, 'accountancy_code_buy', 1, '', 1, 1);
2585 print '</td></tr>';
2586 } else { // For external software
2587 // Accountancy_code_sell
2588 print '<tr><td>'.$langs->trans("ProductAccountancySellCode").'</td>';
2589 print '<td><input name="accountancy_code_sell" class="maxwidth200" value="'.$object->accountancy_code_sell.'">';
2590 print '</td></tr>';
2591
2592 // Accountancy_code_buy
2593 print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
2594 print '<td><input name="accountancy_code_buy" class="maxwidth200" value="'.$object->accountancy_code_buy.'">';
2595 print '</td></tr>';
2596 }
2597 print '</table>';
2598 }
2599 }
2600
2601 print '</div>';
2602
2603 print dol_get_fiche_end();
2604
2605 print $form->buttonsSaveCancel();
2606
2607 print '</form>';
2608 }
2609 } else {
2610 /*
2611 * View
2612 */
2613
2614 if (!empty($object->id)) {
2615 $res = $object->fetch_optionals();
2616 }
2617 //if ($res < 0) { dol_print_error($db); exit; }
2618
2619
2621
2622 print dol_get_fiche_head($head, 'card', $langs->trans("ThirdParty"), -1, 'company');
2623
2624 $formconfirm = '';
2625
2626 // Confirm delete third party
2627 if ($action == 'delete' || ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))) {
2628 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("DeleteACompany"), $langs->trans("ConfirmDeleteCompany"), "confirm_delete", '', 0, "action-delete");
2629 }
2630
2631 if ($action == 'merge') {
2632 $formquestion = array(
2633 array(
2634 'name' => 'soc_origin',
2635 'label' => $langs->trans('MergeOriginThirdparty'),
2636 'type' => 'other',
2637 'value' => $form->select_company('', 'soc_origin', '', 'SelectThirdParty', 0, 0, array(), 0, 'minwidth200', '', '', 1, null, false, array($object->id))
2638 )
2639 );
2640
2641 $formconfirm .= $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("MergeThirdparties"), $langs->trans("ConfirmMergeThirdparties"), "confirm_merge", $formquestion, 'no', 1, 250);
2642 }
2643
2644 // Call Hook formConfirm
2645 $parameters = array('formConfirm' => $formconfirm);
2646 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2647 if (empty($reshook)) {
2648 $formconfirm .= $hookmanager->resPrint;
2649 } elseif ($reshook > 0) {
2650 $formconfirm = $hookmanager->resPrint;
2651 }
2652
2653 // Print form confirm
2654 print $formconfirm;
2655
2656 dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
2657
2658 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
2659
2660 dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
2661
2662 // Call Hook tabContentViewThirdparty
2663 $parameters = array();
2664 // Note that $action and $object may be modified by hook
2665 $reshook = $hookmanager->executeHooks('tabContentViewThirdparty', $parameters, $object, $action);
2666 if (empty($reshook)) {
2667 print '<div class="fichecenter">';
2668 print '<div class="fichehalfleft">';
2669
2670 print '<div class="underbanner clearboth"></div>';
2671 print '<table class="border tableforfield centpercent">';
2672
2673 // Type Prospect/Customer/Supplier
2674 print '<tr><td class="titlefieldmiddle">'.$langs->trans('NatureOfThirdParty').'</td><td>';
2675 print $object->getTypeUrl(1);
2676 print '</td></tr>';
2677
2678 // Prefix
2679 if (getDolGlobalString('SOCIETE_USEPREFIX')) { // Old not used prefix field
2680 print '<tr><td>'.$langs->trans('Prefix').'</td><td>'.dol_escape_htmltag($object->prefix_comm).'</td>';
2681 print '</tr>';
2682 }
2683
2684 // Customer code
2685 if ($object->client) {
2686 print '<tr><td>';
2687 print $langs->trans('CustomerCode');
2688 print '</td>';
2689 print '<td>';
2691 $tmpcheck = $object->check_codeclient();
2692 if ($tmpcheck != 0 && $tmpcheck != -5) {
2693 print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
2694 }
2695 print '</td>';
2696 print '</tr>';
2697 }
2698
2699 // Supplier code
2700 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) {
2701 print '<tr><td>';
2702 print $langs->trans('SupplierCode').'</td><td>';
2704 $tmpcheck = $object->check_codefournisseur();
2705 if ($tmpcheck != 0 && $tmpcheck != -5) {
2706 print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
2707 }
2708 print '</td>';
2709 print '</tr>';
2710 }
2711
2712 // Barcode
2713 if (isModEnabled('barcode')) {
2714 print '<tr><td>';
2715 print $langs->trans('Gencod').'</td><td>'.showValueWithClipboardCPButton(dol_escape_htmltag($object->barcode));
2716 print '</td>';
2717 print '</tr>';
2718 }
2719
2720 // Prof ids
2721 $i = 1;
2722 $j = 0;
2723 $NBPROFIDMIN = getDolGlobalInt('THIRDPARTY_MIN_NB_PROF_ID', 2);
2724 $NBPROFIDMAX = getDolGlobalInt('THIRDPARTY_MAX_NB_PROF_ID', 6);
2725 while ($i <= $NBPROFIDMAX) {
2726 $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
2727 if (!empty($conf->dol_optimize_smallscreen)) {
2728 $idprof = $langs->transcountry('ProfId'.$i.'Short', $object->country_code);
2729 }
2730 if ($idprof != '-' && ($i <= $NBPROFIDMIN || !empty($langs->tab_translate['ProfId'.$i.$object->country_code]))) {
2731 print '<tr>';
2732 print '<td>'.$idprof.'</td><td>';
2733 $key = 'idprof'.$i;
2734 print dol_print_profids($object->$key, 'ProfId'.$i, $object->country_code, 1);
2735 if ($object->$key) {
2736 if ($object->id_prof_check($i, $object) > 0) {
2737 if (!empty($object->id_prof_url($i, $object))) {
2738 print ' &nbsp; '.$object->id_prof_url($i, $object);
2739 }
2740 } else {
2741 print ' <span class="error">('.$langs->trans("ErrorWrongValue").')</span>';
2742 }
2743 }
2744 print '</td>';
2745 print '</tr>';
2746 $j++;
2747 }
2748 $i++;
2749 }
2750
2751
2752 // 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.
2753 // We don't need them into customer profile.
2754 // Except for spain and localtax where localtax depends on buyer and not seller
2755
2756 if ($object->fournisseur) {
2757 // VAT is used
2758 print '<tr><td>';
2759 print $form->textwithpicto($langs->trans('VATIsUsed'), $langs->trans('VATIsUsedWhenSelling'));
2760 print '</td><td>';
2761 print yn($object->tva_assuj);
2762 print '</td>';
2763 print '</tr>';
2764
2765 if (getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) {
2766 // VAT reverse charge by default
2767 print '<tr><td>';
2768 print $form->textwithpicto($langs->trans('VATReverseChargeByDefault'), $langs->trans('VATReverseChargeByDefaultDesc'));
2769 print '</td><td>';
2770 print '<input type="checkbox" name="vat_reverse_charge" ' . ($object->vat_reverse_charge == '1' ? ' checked' : '') . ' disabled>';
2771 print '</td>';
2772 print '</tr>';
2773 }
2774 }
2775
2776 // Local Taxes
2777 if ($object->fournisseur || $mysoc->country_code == 'ES') {
2778 if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
2779 print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
2780 print yn($object->localtax1_assuj);
2781 print '</td></tr><tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
2782 print yn($object->localtax2_assuj);
2783 print '</td></tr>';
2784
2785 if ($object->localtax1_assuj == "1" && (!isOnlyOneLocalTax(1))) {
2786 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2787 print '<input type="hidden" name="action" value="set_localtax1">';
2788 print '<input type="hidden" name="token" value="'.newToken().'">';
2789 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>';
2790 if ($action == 'editRE') {
2791 print '<td class="left">';
2792 $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
2793 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
2794 } else {
2795 print '<td>'.$object->localtax1_value.'</td>';
2796 }
2797 print '</tr></form>';
2798 }
2799 if ($object->localtax2_assuj == "1" && (!isOnlyOneLocalTax(2))) {
2800 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2801 print '<input type="hidden" name="action" value="set_localtax2">';
2802 print '<input type="hidden" name="token" value="'.newToken().'">';
2803 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>';
2804 if ($action == 'editIRPF') {
2805 print '<td class="left">';
2806 $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
2807 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
2808 } else {
2809 print '<td>'.$object->localtax2_value.'</td>';
2810 }
2811 print '</tr></form>';
2812 }
2813 } elseif ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj != "1") {
2814 print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
2815 print yn($object->localtax1_assuj);
2816 print '</td></tr>';
2817 if ($object->localtax1_assuj == "1" && (!isOnlyOneLocalTax(1))) {
2818 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2819 print '<input type="hidden" name="action" value="set_localtax1">';
2820 print '<input type="hidden" name="token" value="'.newToken().'">';
2821 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>';
2822 if ($action == 'editRE') {
2823 print '<td class="left">';
2824 $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
2825 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
2826 } else {
2827 print '<td>'.$object->localtax1_value.'</td>';
2828 }
2829 print '</tr></form>';
2830 }
2831 } elseif ($mysoc->localtax2_assuj == "1" && $mysoc->localtax1_assuj != "1") {
2832 print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
2833 print yn($object->localtax2_assuj);
2834 print '</td></tr>';
2835 if ($object->localtax2_assuj == "1" && (!isOnlyOneLocalTax(2))) {
2836 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2837 print '<input type="hidden" name="action" value="set_localtax2">';
2838 print '<input type="hidden" name="token" value="'.newToken().'">';
2839 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>';
2840 if ($action == 'editIRPF') {
2841 print '<td class="left">';
2842 $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
2843 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
2844 } else {
2845 print '<td>'.$object->localtax2_value.'</td>';
2846 }
2847 print '</tr></form>';
2848 }
2849 }
2850 }
2851
2852 // Sale tax code (VAT code)
2853 print '<tr>';
2854 print '<td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
2855 if ($object->tva_intra) {
2856 $s = '';
2857 $s .= dol_print_profids($object->tva_intra, 'VAT', $object->country_code, 1);
2858 $s .= '<input type="hidden" id="tva_intra" name="tva_intra" maxlength="20" value="'.$object->tva_intra.'">';
2859
2860 if (!getDolGlobalString('MAIN_DISABLEVATCHECK') && isInEEC($object)) {
2861 $s .= ' &nbsp; ';
2862
2863 if ($conf->use_javascript_ajax) {
2864 $widthpopup = 600;
2865 if (!empty($conf->dol_use_jmobile)) {
2866 $widthpopup = 350;
2867 }
2868 $heightpopup = 400;
2869 print "\n";
2870 print '<script type="text/javascript">';
2871 print "function CheckVAT(a) {\n";
2872 if ($mysoc->country_code == 'GR' && $object->country_code == 'GR' && !empty($u)) {
2873 print "GRVAT(a,'{$u}','{$p}','{$myafm}');\n";
2874 } else {
2875 print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a, '".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
2876 }
2877 print "}\n";
2878 print '</script>';
2879 print "\n";
2880 $s .= '<a href="#" class="hideonsmartphone" onclick="CheckVAT( $(\'#tva_intra\').val() );">'.$langs->trans("VATIntraCheck").'</a>';
2881 $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1);
2882 } else {
2883 $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", $object->country_id).'" class="hideonsmartphone" target="_blank" rel="noopener noreferrer">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
2884 }
2885 }
2886 print $s;
2887 } else {
2888 print '&nbsp;';
2889 }
2890 print '</td></tr>';
2891
2892 // Warehouse
2893 if (isModEnabled('stock') && getDolGlobalString('SOCIETE_ASK_FOR_WAREHOUSE')) {
2894 $langs->load('stocks');
2895 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
2896 $formproduct = new FormProduct($db);
2897 print '<tr class="nowrap">';
2898 print '<td>';
2899 print $form->editfieldkey("Warehouse", 'warehouse', '', $object, $user->hasRight('societe', 'creer'));
2900 print '</td><td>';
2901 if ($action == 'editwarehouse') {
2902 $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_warehouse, 'fk_warehouse', 1);
2903 } else {
2904 if ($object->fk_warehouse > 0) {
2905 print img_picto('', 'stock', 'class="paddingrightonly"');
2906 }
2907 $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_warehouse, 'none');
2908 }
2909 print '</td>';
2910 print '</tr>';
2911 }
2912
2913 print '</table>';
2914 print '</div>';
2915
2916 print '<div class="fichehalfright">';
2917
2918 print '<div class="underbanner clearboth"></div>';
2919 print '<table class="border tableforfield centpercent">';
2920
2921 // Tags / categories
2922 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
2923 // Customer
2924 if ($object->prospect || $object->client || getDolGlobalString('THIRDPARTY_CAN_HAVE_CUSTOMER_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT')) {
2925 print '<tr><td class="titlefieldmiddle">'.$langs->trans("CustomersCategoriesShort").'</td>';
2926 print '<td>';
2927 print $form->showCategories($object->id, Categorie::TYPE_CUSTOMER, 1);
2928 print "</td></tr>";
2929 }
2930
2931 // Supplier
2932 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) {
2933 print '<tr><td class="titlefieldmiddle">'.$langs->trans("SuppliersCategoriesShort").'</td>';
2934 print '<td>';
2935 print $form->showCategories($object->id, Categorie::TYPE_SUPPLIER, 1);
2936 print "</td></tr>";
2937 }
2938 }
2939
2940
2941 // Third-Party Type
2942 print '<tr><td class="titlefieldmiddle">';
2943 print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans('ThirdPartyType').'</td>';
2944 if ($action != 'editthirdpartytype' && $user->hasRight('societe', 'creer')) {
2945 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>';
2946 }
2947 print '</tr></table>';
2948 print '</td><td>';
2949 $html_name = ($action == 'editthirdpartytype') ? 'typent_id' : 'none';
2950 $formcompany->formThirdpartyType($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->typent_id, $html_name, '');
2951 print '</td></tr>';
2952
2953 // Workforce/Staff
2954 if (!getDolGlobalString('SOCIETE_DISABLE_WORKFORCE')) {
2955 print '<tr><td>'.$langs->trans("Workforce").'</td><td>'.$object->effectif.'</td></tr>';
2956 }
2957
2958 // Legal
2959 print '<tr><td>'.$langs->trans('JuridicalStatus').'</td><td>'.dolPrintHTML($object->forme_juridique).'</td></tr>';
2960
2961 // Capital
2962 print '<tr><td>'.$langs->trans('Capital').'</td><td>';
2963 if ($object->capital) {
2964 if (isModEnabled("multicurrency") && !empty($object->multicurrency_code)) {
2965 print price($object->capital, 0, $langs, 0, -1, -1, $object->multicurrency_code);
2966 } else {
2967 print price($object->capital, 0, $langs, 0, -1, -1, $conf->currency);
2968 }
2969 } else {
2970 print '&nbsp;';
2971 }
2972 print '</td></tr>';
2973
2974 // Unsubscribe opt-out
2975 if (isModEnabled('mailing')) {
2976 $result = $object->getNoEmail();
2977 if ($result < 0) {
2978 setEventMessages($object->error, $object->errors, 'errors');
2979 }
2980 print '<tr><td>'.$langs->trans("No_Email").'</td><td>';
2981 if ($object->email) {
2982 print yn($object->no_email);
2983 } else {
2984 $langs->load("mails");
2985 print '<span class="opacitymedium">'.$langs->trans("EMailNotDefined").'</span>';
2986 }
2987
2988 $langs->load("mails");
2989 print ' &nbsp; <span class="badge badge-secondary" title="'.dol_escape_htmltag($langs->trans("NbOfEMailingsSend")).'">'.$object->getNbOfEMailings().'</span>';
2990
2991 print '</td></tr>';
2992 }
2993
2994 // Default language
2995 if (getDolGlobalInt('MAIN_MULTILANGS')) {
2996 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2997 print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
2998 //$s=picto_from_langcode($object->default_lang);
2999 //print ($s?$s.' ':'');
3000 $langs->load("languages");
3001 $labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
3002 print picto_from_langcode($object->default_lang, 'class="paddingrightonly saturatemedium opacitylow"');
3003 print $labellang;
3004 print '</td></tr>';
3005 }
3006
3007 // Incoterms
3008 if (isModEnabled('incoterm')) {
3009 print '<tr><td>';
3010 print '<table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans('IncotermLabel').'</td>';
3011 if ($action != 'editincoterm' && $user->hasRight('societe', 'creer')) {
3012 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=editincoterm&token='.newToken().'">'.img_edit('', 1).'</a></td>';
3013 }
3014 print '</tr></table>';
3015 print '</td><td colspan="3">';
3016 if ($action != 'editincoterm') {
3017 print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
3018 } else {
3019 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?socid='.$object->id);
3020 }
3021 print '</td></tr>';
3022 }
3023
3024 // Multicurrency
3025 if (isModEnabled("multicurrency")) {
3026 print '<tr>';
3027 print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
3028 print '<td>';
3029 print !empty($object->multicurrency_code) ? currency_name($object->multicurrency_code, 1) : '';
3030 print '</td></tr>';
3031 }
3032
3033 if (getDolGlobalString('ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY')) {
3034 // Accountancy sell code
3035 print '<tr><td class="nowrap">';
3036 print $langs->trans("ProductAccountancySellCode");
3037 print '</td><td colspan="2">';
3038 if (isModEnabled('accounting')) {
3039 if (!empty($object->accountancy_code_sell)) {
3040 $accountingaccount = new AccountingAccount($db);
3041 $accountingaccount->fetch('', $object->accountancy_code_sell, 1);
3042
3043 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
3044 }
3045 } else {
3046 print $object->accountancy_code_sell;
3047 }
3048 print '</td></tr>';
3049
3050 // Accountancy buy code
3051 print '<tr><td class="nowrap">';
3052 print $langs->trans("ProductAccountancyBuyCode");
3053 print '</td><td colspan="2">';
3054 if (isModEnabled('accounting')) {
3055 if (!empty($object->accountancy_code_buy)) {
3056 $accountingaccount2 = new AccountingAccount($db);
3057 $accountingaccount2->fetch('', $object->accountancy_code_buy, 1);
3058
3059 print $accountingaccount2->getNomUrl(0, 1, 1, '', 1);
3060 }
3061 } else {
3062 print $object->accountancy_code_buy;
3063 }
3064 print '</td></tr>';
3065 }
3066
3067 // Other attributes
3068 $parameters = array('socid' => $socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
3069 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
3070
3071 // Parent company
3072 if (!getDolGlobalString('SOCIETE_DISABLE_PARENTCOMPANY')) {
3073 print '<tr><td>';
3074 print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans('ParentCompany').'</td>';
3075 if ($action != 'editparentcompany' && $user->hasRight('societe', 'creer')) {
3076 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>';
3077 }
3078 print '</tr></table>';
3079 print '</td><td>';
3080 $html_name = ($action == 'editparentcompany') ? 'parent_id' : 'none';
3081 $form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->parent, $html_name, '', 1, 0, 0, null, 0, array($object->id));
3082 print '</td></tr>';
3083 }
3084
3085 // Sales representative
3086 include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php';
3087
3088 // Module Adherent
3089 if (isModEnabled('member')) {
3090 $langs->load("members");
3091 print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
3092 print '<td>';
3093 $adh = new Adherent($db);
3094 $result = $adh->fetch('', '', $object->id);
3095 if ($result > 0) {
3096 $adh->ref = $adh->getFullName($langs);
3097 print $adh->getNomUrl(-1);
3098 } else {
3099 print '<span class="opacitymedium">'.$langs->trans("ThirdpartyNotLinkedToMember").'</span>';
3100 }
3101 print "</td></tr>\n";
3102 }
3103
3104 // Link user (you must create a contact to get a user)
3105 /*
3106 print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td colspan="3">';
3107 if ($object->user_id) {
3108 $dolibarr_user = new User($db);
3109 $result = $dolibarr_user->fetch($object->user_id);
3110 print $dolibarr_user->getLoginUrl(-1);
3111 } else {
3112 //print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
3113 if (!$object->user_id && $user->hasRight('user', 'user', 'creer')) {
3114 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>';
3115 }
3116 }
3117 print '</td></tr>';
3118 */
3119
3120 // Webservices url/key
3121 if (isModEnabled('webservicesclient')) {
3122 print '<tr><td>'.$langs->trans("WebServiceURL").'</td><td>'.dol_print_url($object->webservices_url).'</td></tr>';
3123 print '<tr><td class="nowrap">'.$langs->trans('WebServiceKey').'</td><td>'.$object->webservices_key.'</td></tr>';
3124 }
3125
3126 print '</table>';
3127 print '</div>';
3128
3129 print '</div>';
3130 print '<div class="clearboth"></div>';
3131 }
3132
3133 print dol_get_fiche_end();
3134
3135
3136 /*
3137 * Actions
3138 */
3139 if ($action != 'presend') {
3140 print '<div class="tabsAction">'."\n";
3141
3142 $parameters = array();
3143 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3144 if (empty($reshook)) {
3145 $at_least_one_email_contact = false;
3146 $TContact = $object->contact_array_objects();
3147 foreach ($TContact as &$contact) {
3148 if (!empty($contact->email)) {
3149 $at_least_one_email_contact = true;
3150 break;
3151 }
3152 }
3153
3154 if (empty($user->socid)) {
3155 $langs->load("mails");
3156 $title = '';
3157 if (empty($object->email) && !$at_least_one_email_contact) {
3158 $title = $langs->trans('NoEMail');
3159 }
3160 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);
3161 }
3162
3163 print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=edit&token='.newToken(), '', $permissiontoadd);
3164
3165 if (isModEnabled('member')) {
3166 $adh = new Adherent($db);
3167 $result = $adh->fetch('', '', $object->id);
3168 if ($result == 0 && ($object->client == 1 || $object->client == 3) && getDolGlobalString('MEMBER_CAN_CONVERT_CUSTOMERS_TO_MEMBERS')) {
3169 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";
3170 }
3171 }
3172
3173 print dolGetButtonAction($langs->trans('MergeThirdparties'), $langs->trans('Merge'), 'danger', $_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=merge&token='.newToken(), '', $permissiontodelete);
3174
3175 $deleteUrl = $_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=delete&token='.newToken();
3176 $buttonId = 'action-delete-no-ajax';
3177 if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)) { // We can't use preloaded confirm form with jmobile
3178 $deleteUrl = '';
3179 $buttonId = 'action-delete';
3180 }
3181 print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $deleteUrl, $buttonId, $permissiontodelete);
3182 }
3183
3184 print '</div>'."\n";
3185 }
3186
3187 //Select mail models is same action as presend
3188 if (GETPOST('modelselected')) {
3189 $action = 'presend';
3190 }
3191
3192 if ($action != 'presend') {
3193 print '<div class="fichecenter"><div class="fichehalfleft">';
3194
3195 if (!getDolGlobalString('SOCIETE_DISABLE_BUILDDOC')) {
3196 print '<a name="builddoc"></a>'; // ancre
3197
3198 /*
3199 * Generated documents
3200 */
3201 $filedir = $conf->societe->multidir_output[$object->entity].'/'.$object->id;
3202 $urlsource = $_SERVER["PHP_SELF"]."?socid=".$object->id;
3203 $genallowed = $user->hasRight('societe', 'lire');
3204 $delallowed = $user->hasRight('societe', 'creer');
3205
3206 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);
3207 }
3208
3209 // Subsidiaries list
3210 if (!getDolGlobalString('SOCIETE_DISABLE_PARENTCOMPANY') && !getDolGlobalString('SOCIETE_DISABLE_SHOW_SUBSIDIARIES')) {
3211 print '<br>';
3212 $result = show_subsidiaries($conf, $langs, $db, $object);
3213 }
3214
3215 print '</div><div class="fichehalfright">';
3216
3217 $MAXEVENT = 10;
3218
3219 $morehtmlcenter = '<div class="nowraponall">';
3220 $morehtmlcenter .= dolGetButtonTitle($langs->trans('FullConversation'), '', 'fa fa-comments imgforviewmode', DOL_URL_ROOT.'/societe/messaging.php?socid='.$object->id);
3221 $morehtmlcenter .= dolGetButtonTitle($langs->trans('FullList'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id);
3222 $morehtmlcenter .= '</div>';
3223
3224 // List of actions on element
3225 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
3226 $formactions = new FormActions($db);
3227 $somethingshown = $formactions->showactions($object, '', $socid, 1, '', $MAXEVENT, '', $morehtmlcenter); // Show all action for thirdparty
3228
3229 print '</div></div>';
3230
3231 if (getDolGlobalString('MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD')) {
3232 // Contacts list
3233 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
3234 $result = show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
3235 }
3236 }
3237 }
3238
3239 // Presend form
3240 $modelmail = 'thirdparty';
3241 $defaulttopic = 'Information';
3242 $diroutput = $conf->societe->multidir_output[$object->entity];
3243 $trackid = 'thi'.$object->id;
3244
3245 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
3246 }
3247}
3248
3249
3250// End of page
3251llxFooter();
3252$db->close();
3253
3254?>
3255
3256<script>
3257// Function to retrieve VAT details from the Greek Ministry of Finance GSIS SOAP web service
3258function GRVAT(a, u, p, myafm) {
3259 var afm = a.replace(/\D/g, ""); // Remove non-digit characters from 'a'
3260
3261 $.ajax({
3262 type: "GET",
3263 url: '<?php echo DOL_URL_ROOT ?>/societe/checkvat/checkVatGr.php',
3264 data: { afm }, // Set request parameters
3265 success: function(data) {
3266 var obj = data; // Parse response data as JSON
3267
3268 // Update form fields based on retrieved data
3269 if (obj.RgWsPublicBasicRt_out.afm === null) {
3270 alert(obj.pErrorRec_out.errorDescr); // Display error message if AFM is null
3271 } else {
3272 $("#name").val(obj.RgWsPublicBasicRt_out.onomasia); // Set 'name' field value
3273 $("#address").val(obj.RgWsPublicBasicRt_out.postalAddress + " " + obj.RgWsPublicBasicRt_out.postalAddressNo); // Set 'address' field value
3274 $("#zipcode").val(obj.RgWsPublicBasicRt_out.postalZipCode); // Set 'zipcode' field value
3275 $("#town").val(obj.RgWsPublicBasicRt_out.postalAreaDescription); // Set 'town' field value
3276 $("#idprof2").val(obj.RgWsPublicBasicRt_out.doyDescr); // Set 'idprof2' field value
3277 $("#name_alias_input").val(obj.RgWsPublicBasicRt_out.commerTitle); // Set 'name_alias' field value
3278
3279 if (obj.arrayOfRgWsPublicFirmActRt_out.RgWsPublicFirmActRtUser) {
3280 var firmActUser = obj.arrayOfRgWsPublicFirmActRt_out.RgWsPublicFirmActRtUser;
3281
3282 if (Array.isArray(firmActUser)) {
3283 var primaryFirmAct = firmActUser.find(item => item.firmActKindDescr === "ΚΥΡΙΑ"); // Find primary client activity
3284 if (primaryFirmAct) {
3285 $("#idprof1").val(primaryFirmAct.firmActDescr); // Set 'idprof1' field value
3286 }
3287 } else {
3288 $("#idprof1").val(firmActUser.firmActDescr); // Set 'idprof1' field value
3289 }
3290 }
3291 }
3292 }
3293 });
3294}
3295
3296</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.
dolPrintHTML($s, $allowiframe=0)
Return a string (that can be on several lines) ready to be output on a HTML page.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_url($url, $target='_blank', $max=32, $withpicto=0, $morecss='')
Show Url link.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
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:137
getMaxFileSizeArray()
Return the max allowed for file upload.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.