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