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