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