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