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