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