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