From d31aadf5dab74fd1cba6f8b5fb53d34db57b01a6 Mon Sep 17 00:00:00 2001 From: wdammak <26695620+wdammak@users.noreply.github.com> Date: Fri, 15 Feb 2019 05:20:33 +0100 Subject: [PATCH 01/23] Add Default Warehouse to user --- htdocs/user/class/user.class.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index a6bc202d17f..451a5abda80 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -173,6 +173,8 @@ class User extends CommonObject public $default_c_exp_tax_cat; public $default_range; + + public $fk_warehouse; public $fields = array( 'rowid'=>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'), @@ -248,6 +250,7 @@ class User extends CommonObject $sql.= " u.weeklyhours,"; $sql.= " u.color,"; $sql.= " u.dateemployment, u.dateemploymentend,"; + $sql.= " u.fk_warehouse,"; $sql.= " u.ref_int, u.ref_ext,"; $sql.= " u.default_range, u.default_c_exp_tax_cat,"; // Expense report default mode $sql.= " c.code as country_code, c.label as country,"; @@ -368,6 +371,7 @@ class User extends CommonObject $this->default_range = $obj->default_range; $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat; + $this->fk_warehouse = $obj->fk_warehouse; // Protection when module multicompany was set, admin was set to first entity and then, the module was disabled, // in such case, this admin user must be admin for ALL entities. @@ -1482,6 +1486,7 @@ class User extends CommonObject $this->color = empty($this->color)?'':$this->color; $this->dateemployment = empty($this->dateemployment)?'':$this->dateemployment; $this->dateemploymentend = empty($this->dateemploymentend)?'':$this->dateemploymentend; + $this->fk_warehouse = trim(empty($this->fk_warehouse)?'':$this->fk_warehouse); // Check parameters if (! empty($conf->global->USER_MAIL_REQUIRED) && ! isValidEMail($this->email)) @@ -1539,6 +1544,7 @@ class User extends CommonObject $sql.= ", entity = '".$this->db->escape($this->entity)."'"; $sql.= ", default_range = ".($this->default_range > 0 ? $this->default_range : 'null'); $sql.= ", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat : 'null'); + $sql.= ", fk_warehouse = ".($this->fk_warehouse?"'".$this->db->escape($this->fk_warehouse)."'":"null"); $sql.= " WHERE rowid = ".$this->id; @@ -1977,7 +1983,7 @@ class User extends CommonObject dol_syslog(get_class($this)."::send_password changelater is on, url=".$url); } -$mailfile = new CMailFile( + $mailfile = new CMailFile( $subject, $this->email, $conf->global->MAIN_MAIL_EMAIL_FROM, From 4dc4a25bb500fb0683f61e9484b2fc0a3af454d6 Mon Sep 17 00:00:00 2001 From: wdammak <26695620+wdammak@users.noreply.github.com> Date: Fri, 15 Feb 2019 05:24:25 +0100 Subject: [PATCH 02/23] Add Default Warehouse to user card --- htdocs/user/card.php | 46 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 63a2a598d41..f4482a9e872 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -48,6 +48,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; if (! empty($conf->ldap->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php'; if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; if (! empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; $id = GETPOST('id', 'int'); $action = GETPOST('action', 'aZ09'); @@ -91,7 +92,7 @@ $result = restrictedArea($user, 'user', $id, 'user&user', $feature2); if ($user->id <> $id && ! $canreaduser) accessforbidden(); // Load translation files required by page -$langs->loadLangs(array('users', 'companies', 'ldap', 'admin', 'hrm')); +$langs->loadLangs(array('users', 'companies', 'ldap', 'admin', 'hrm', 'stocks')); $object = new User($db); $extrafields = new ExtraFields($db); @@ -237,6 +238,8 @@ if (empty($reshook)) { $dateemploymentend = dol_mktime(0, 0, 0, GETPOST('dateemploymentendmonth'), GETPOST('dateemploymentendday'), GETPOST('dateemploymentendyear')); $object->dateemploymentend = $dateemploymentend; + $object->fk_warehouse = GETPOST('fk_warehouse', 'int'); + // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels, $object); if ($ret < 0) { @@ -383,6 +386,8 @@ if (empty($reshook)) { $object->dateemployment = $dateemployment; $dateemploymentend = dol_mktime(0, 0, 0, GETPOST('dateemploymentendmonth', 'int'), GETPOST('dateemploymentendday', 'int'), GETPOST('dateemploymentendyear', 'int')); $object->dateemploymentend = $dateemploymentend; + + $object->fk_warehouse = GETPOST('fk_warehouse', 'int'); if (! empty($conf->multicompany->enabled)) { @@ -639,6 +644,7 @@ $form = new Form($db); $formother=new FormOther($db); $formcompany = new FormCompany($db); $formfile = new FormFile($db); +$formproduct = new FormProduct($db); llxHeader('', $langs->trans("UserCard")); @@ -1104,7 +1110,8 @@ if ($action == 'create' || $action == 'adduserldap') { print '' . $form->editfieldkey('Categories', 'usercats', '', $object, 0) . ''; $cate_arbo = $form->select_all_categories('user', null, 'parent', null, null, 1); - print $form->multiselectarray('usercats', $cate_arbo, GETPOST('usercats', 'array'), null, null, null, null, '90%'); + print $form->multiselectarray('usercats', $cate_arbo, GETPOST('usercats', 'array'), null, null, null, + null, '90%' ); print ""; } @@ -1165,6 +1172,10 @@ if ($action == 'create' || $action == 'adduserldap') print ''; print ''; + // Default warehouse + print ''.$langs->trans("DefaultWarehouse").''; + print $formproduct->selectWarehouses($object->fk_warehouse, 'fk_warehouse', 'warehouseopen', 1); + print ''; if ((! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read)) || (! empty($conf->hrm->enabled) && ! empty($user->rights->hrm->employee->read))) @@ -1517,6 +1528,14 @@ else print ''.$langs->trans("PostOrFunction").''; print ''.$object->job.''; print ''."\n"; + + // Default warehouse + require_once DOL_DOCUMENT_ROOT .'/product/stock/class/entrepot.class.php'; + $warehousestatic=new Entrepot($db); + $warehousestatic->fetch($object->fk_warehouse); + print ''.$langs->trans("DefaultWarehouse").''; + print $warehousestatic->getNomUrl(); + print ''; //$childids = $user->getAllChildIds(1); @@ -1611,9 +1630,9 @@ else // Categories if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) { - print '' . $langs->trans("Categories") . ''; + print '' . $langs->trans( "Categories" ) . ''; print ''; - print $form->showCategories($object->id, 'user', 1); + print $form->showCategories( $object->id, 'user', 1 ); print ''; } @@ -2378,21 +2397,21 @@ else print ''; // Categories - if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) + if (!empty( $conf->categorie->enabled ) && !empty( $user->rights->categorie->lire )) { print '' . $form->editfieldkey('Categories', 'usercats', '', $object, 0) . ''; print ''; - $cate_arbo = $form->select_all_categories(Categorie::TYPE_USER, null, null, null, null, 1); - $c = new Categorie($db); + $cate_arbo = $form->select_all_categories( Categorie::TYPE_USER, null, null, null, null, 1 ); + $c = new Categorie( $db ); $cats = $c->containing($object->id, Categorie::TYPE_USER); foreach ($cats as $cat) { $arrayselected[] = $cat->id; } if ($caneditfield) { - print $form->multiselectarray('usercats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%'); + print $form->multiselectarray( 'usercats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%' ); }else{ - print $form->showCategories($object->id, 'user', 1); + print $form->showCategories( $object->id, 'user', 1 ); } print ""; } @@ -2518,6 +2537,15 @@ else print $object->job; } print ''; + + // Default warehouse + if (! empty($conf->stock->enabled)) + { + print ''.$langs->trans("DefaultWarehouse").''; + print $formproduct->selectWarehouses($object->fk_warehouse, 'fk_warehouse', 'warehouseopen', 1); + print ' '.$langs->trans("AddWarehouse").''; + print ''; + } if ((! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read)) || (! empty($conf->hrm->enabled) && ! empty($user->rights->hrm->employee->read))) From fd4f82b1b72828d06ba3b13c77ec21edc513cb5c Mon Sep 17 00:00:00 2001 From: wdammak <26695620+wdammak@users.noreply.github.com> Date: Fri, 15 Feb 2019 05:32:01 +0100 Subject: [PATCH 03/23] Fix conflict --- htdocs/user/card.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/htdocs/user/card.php b/htdocs/user/card.php index f4482a9e872..fc6d7793330 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -1110,8 +1110,7 @@ if ($action == 'create' || $action == 'adduserldap') { print '' . $form->editfieldkey('Categories', 'usercats', '', $object, 0) . ''; $cate_arbo = $form->select_all_categories('user', null, 'parent', null, null, 1); - print $form->multiselectarray('usercats', $cate_arbo, GETPOST('usercats', 'array'), null, null, null, - null, '90%' ); + print $form->multiselectarray('usercats', $cate_arbo, GETPOST('usercats', 'array'), null, null, null, null, '90%'); print ""; } @@ -1630,9 +1629,9 @@ else // Categories if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) { - print '' . $langs->trans( "Categories" ) . ''; + print '' . $langs->trans("Categories") . ''; print ''; - print $form->showCategories( $object->id, 'user', 1 ); + print $form->showCategories($object->id, 'user', 1); print ''; } @@ -2397,21 +2396,21 @@ else print ''; // Categories - if (!empty( $conf->categorie->enabled ) && !empty( $user->rights->categorie->lire )) + if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) { print '' . $form->editfieldkey('Categories', 'usercats', '', $object, 0) . ''; print ''; - $cate_arbo = $form->select_all_categories( Categorie::TYPE_USER, null, null, null, null, 1 ); - $c = new Categorie( $db ); + $cate_arbo = $form->select_all_categories(Categorie::TYPE_USER, null, null, null, null, 1); + $c = new Categorie($db); $cats = $c->containing($object->id, Categorie::TYPE_USER); foreach ($cats as $cat) { $arrayselected[] = $cat->id; } if ($caneditfield) { - print $form->multiselectarray( 'usercats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%' ); + print $form->multiselectarray('usercats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%'); }else{ - print $form->showCategories( $object->id, 'user', 1 ); + print $form->showCategories($object->id, 'user', 1); } print ""; } From 03c5e040c59691fc532eaa36957e5c7b786fe56d Mon Sep 17 00:00:00 2001 From: wdammak <26695620+wdammak@users.noreply.github.com> Date: Fri, 15 Feb 2019 05:48:56 +0100 Subject: [PATCH 04/23] Fix backtopage url --- htdocs/user/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/user/card.php b/htdocs/user/card.php index fc6d7793330..ff4253df646 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -2542,7 +2542,7 @@ else { print ''.$langs->trans("DefaultWarehouse").''; print $formproduct->selectWarehouses($object->fk_warehouse, 'fk_warehouse', 'warehouseopen', 1); - print ' '.$langs->trans("AddWarehouse").''; + print ' '.$langs->trans("AddWarehouse").''; print ''; } From 63ffb7a87341a1024fa6b888fe78e044e0f8aae8 Mon Sep 17 00:00:00 2001 From: wdammak <26695620+wdammak@users.noreply.github.com> Date: Fri, 15 Feb 2019 06:04:58 +0100 Subject: [PATCH 05/23] Fix backtopage url --- htdocs/user/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/user/card.php b/htdocs/user/card.php index ff4253df646..84d83acf483 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -2542,7 +2542,7 @@ else { print ''.$langs->trans("DefaultWarehouse").''; print $formproduct->selectWarehouses($object->fk_warehouse, 'fk_warehouse', 'warehouseopen', 1); - print ' '.$langs->trans("AddWarehouse").''; + print ' '.$langs->trans("AddWarehouse").''; print ''; } From 8390ed346bd6d2909e18dafb660f1b0439bc25b4 Mon Sep 17 00:00:00 2001 From: wdammak <26695620+wdammak@users.noreply.github.com> Date: Fri, 15 Feb 2019 17:12:39 +0100 Subject: [PATCH 06/23] Hidden for users not using the stock module --- htdocs/user/card.php | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 84d83acf483..048ee72e688 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -48,7 +48,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; if (! empty($conf->ldap->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php'; if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; if (! empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; -require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; +if (! empty($conf->stock->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; $id = GETPOST('id', 'int'); $action = GETPOST('action', 'aZ09'); @@ -644,7 +644,7 @@ $form = new Form($db); $formother=new FormOther($db); $formcompany = new FormCompany($db); $formfile = new FormFile($db); -$formproduct = new FormProduct($db); +if (! empty($conf->stock->enabled)) $formproduct = new FormProduct($db); llxHeader('', $langs->trans("UserCard")); @@ -1172,9 +1172,12 @@ if ($action == 'create' || $action == 'adduserldap') print ''; // Default warehouse - print ''.$langs->trans("DefaultWarehouse").''; - print $formproduct->selectWarehouses($object->fk_warehouse, 'fk_warehouse', 'warehouseopen', 1); - print ''; + if (! empty($conf->stock->enabled)) + { + print ''.$langs->trans("DefaultWarehouse").''; + print $formproduct->selectWarehouses($object->fk_warehouse, 'fk_warehouse', 'warehouseopen', 1); + print ''; + } if ((! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read)) || (! empty($conf->hrm->enabled) && ! empty($user->rights->hrm->employee->read))) @@ -1529,12 +1532,15 @@ else print ''."\n"; // Default warehouse - require_once DOL_DOCUMENT_ROOT .'/product/stock/class/entrepot.class.php'; - $warehousestatic=new Entrepot($db); - $warehousestatic->fetch($object->fk_warehouse); - print ''.$langs->trans("DefaultWarehouse").''; - print $warehousestatic->getNomUrl(); - print ''; + if (! empty($conf->stock->enabled)) + { + require_once DOL_DOCUMENT_ROOT .'/product/stock/class/entrepot.class.php'; + $warehousestatic=new Entrepot($db); + $warehousestatic->fetch($object->fk_warehouse); + print ''.$langs->trans("DefaultWarehouse").''; + print $warehousestatic->getNomUrl(); + print ''; + } //$childids = $user->getAllChildIds(1); @@ -2543,7 +2549,7 @@ else print ''.$langs->trans("DefaultWarehouse").''; print $formproduct->selectWarehouses($object->fk_warehouse, 'fk_warehouse', 'warehouseopen', 1); print ' '.$langs->trans("AddWarehouse").''; - print ''; + print ''; } if ((! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read)) From 99fb702833340ccfb5070a5d5acdc9f535746889 Mon Sep 17 00:00:00 2001 From: wdammak <26695620+wdammak@users.noreply.github.com> Date: Tue, 26 Feb 2019 18:42:05 +0100 Subject: [PATCH 07/23] Add Select Establishment --- htdocs/core/class/html.form.class.php | 70 +++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 47cc9893c96..21d16f9f9ce 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -3681,6 +3681,76 @@ class Form return $num; } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + /** + * Return a HTML select list of establishment + * + * @param string $selected Id establishment pre-selected + * @param string $htmlname Name of select zone + * @param int $statut Status of searched establishment (0=open, 1=closed, 2=both) + * @param string $filtre To filter list + * @param int $useempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. + * @param string $moreattrib To add more attribute on select + * @return int <0 if error, Num of establishment found if OK (0, 1, 2, ...) + */ + function select_establishments($selected = '', $htmlname = 'entity', $statut = 0, $filtre = '', $useempty = 0, $moreattrib = '') + { + // phpcs:enable + global $langs, $conf; + + $langs->load("admin"); + $num = 0; + + $sql = "SELECT rowid, name, fk_country, status, entity"; + $sql.= " FROM ".MAIN_DB_PREFIX."establishment"; + $sql.= " WHERE 1=1"; + if ($statut != 2) $sql.= " AND status = '".$statut."'"; + if ($filtre) $sql.=" AND ".$filtre; + $sql.= " ORDER BY name"; + + dol_syslog(get_class($this)."::select_establishment", LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) + { + $num = $this->db->num_rows($result); + $i = 0; + if ($num) + { + print '"; + } + else + { + if ($statut == 0) print ''.$langs->trans("NoActiveEstablishmentDefined").''; + else print ''.$langs->trans("NoEstablishmentFound").''; + } + } + else { + dol_print_error($this->db); + } + } /** * Display form to select bank account From b79bcb25eac2e68c76e3ab1a2a1cffad4e8a449e Mon Sep 17 00:00:00 2001 From: wdammak <26695620+wdammak@users.noreply.github.com> Date: Tue, 26 Feb 2019 18:45:07 +0100 Subject: [PATCH 08/23] Add parent company --- htdocs/hrm/establishment/card.php | 2970 +++++++++++++++++++++++++---- 1 file changed, 2642 insertions(+), 328 deletions(-) diff --git a/htdocs/hrm/establishment/card.php b/htdocs/hrm/establishment/card.php index 28763f8b0f3..69f3f9b880d 100644 --- a/htdocs/hrm/establishment/card.php +++ b/htdocs/hrm/establishment/card.php @@ -1,5 +1,18 @@ +/* Copyright (C) 2001-2007 Rodolphe Quiedeville + * Copyright (C) 2003 Brian Fraval + * Copyright (C) 2004-2015 Laurent Destailleur + * Copyright (C) 2005 Eric Seigne + * Copyright (C) 2005-2017 Regis Houssin + * Copyright (C) 2008 Patrick Raguin + * Copyright (C) 2010-2016 Juanjo Menent + * Copyright (C) 2011-2013 Alexandre Spangaro + * Copyright (C) 2015 Jean-François Ferry + * Copyright (C) 2015 Marcos García + * Copyright (C) 2015 Raphaël Doursenaud + * Copyright (C) 2018 Nicolas ZABOURI + * Copyright (C) 2018 Ferran Marcet + * Copyright (C) 2018 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,403 +29,2704 @@ */ /** - * \file htdocs/hrm/establishment/card.php - * \brief Page to show an establishment + * \file htdocs/societe/card.php + * \ingroup societe + * \brief Third party card page */ -require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/hrm.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/hrm/class/establishment.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; -// Load translation files required by the page -$langs->loadLangs(array('admin', 'hrm')); +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; +require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; +require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; +if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; + +$langs->loadLangs(array("companies","commercial","bills","banks","users")); +if (! empty($conf->categorie->enabled)) $langs->load("categories"); +if (! empty($conf->incoterm->enabled)) $langs->load("incoterm"); +if (! empty($conf->notification->enabled)) $langs->load("mails"); + +$mesg=''; $error=0; $errors=array(); + +$action = (GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'); +$cancel = GETPOST('cancel', 'alpha'); +$backtopage = GETPOST('backtopage', 'alpha'); +$confirm = GETPOST('confirm', 'alpha'); + +$socid = GETPOST('socid', 'int')?GETPOST('socid', 'int'):GETPOST('id', 'int'); +if ($user->societe_id) $socid=$user->societe_id; +if (empty($socid) && $action == 'view') $action='create'; + +$object = new Societe($db); +$extrafields = new ExtraFields($db); + +// fetch optionals attributes and labels +$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); + +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context +$hookmanager->initHooks(array('thirdpartycard','globalcard')); + +if ($socid > 0) $object->fetch($socid); + +if (! ($object->id > 0) && $action == 'view') +{ + $langs->load("errors"); + print($langs->trans('ErrorRecordNotFound')); + exit; +} + +// Get object canvas (By default, this is not defined, so standard usage of dolibarr) +$object->getCanvas($socid); +$canvas = $object->canvas?$object->canvas:GETPOST("canvas"); +$objcanvas=null; +if (! empty($canvas)) +{ + require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php'; + $objcanvas = new Canvas($db, $action); + $objcanvas->getCanvas('thirdparty', 'card', $canvas); +} // Security check -if (! $user->admin) accessforbidden(); - -$error=0; - -$action = GETPOST('action', 'alpha'); -$cancel = GETPOST('cancel', 'alpha'); -$confirm = GETPOST('confirm', 'alpha'); -$id = GETPOST('id', 'int'); - -// List of status -static $tmpstatus2label=array( - '0'=>'CloseEtablishment', - '1'=>'OpenEtablishment' -); -$status2label=array(''); -foreach ($tmpstatus2label as $key => $val) $status2label[$key]=$langs->trans($val); - -$object = new Establishment($db); - -// Load object -include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once +$result = restrictedArea($user, 'societe', $socid, '&societe', '', 'fk_soc', 'rowid', $objcanvas); /* * Actions */ -if ($action == 'confirm_delete' && $confirm == "yes") -{ - $result=$object->delete($id); - if ($result >= 0) - { - header("Location: ../admin/admin_establishment.php"); - exit; - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - } -} +$parameters=array('id'=>$socid, 'objcanvas'=>$objcanvas); +$reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -elseif ($action == 'add') +if (empty($reshook)) { - if (! $cancel) + if ($cancel) { - $error=0; - - $object->name = GETPOST('name', 'alpha'); - if (empty($object->name)) + $action=''; + if (! empty($backtopage)) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Name")), null, 'errors'); + header("Location: ".$backtopage); + exit; + } + } + + if ($action == 'confirm_merge' && $confirm == 'yes' && $user->rights->societe->creer) + { + $error = 0; + $soc_origin_id = GETPOST('soc_origin', 'int'); + $soc_origin = new Societe($db); + + if ($soc_origin_id <= 0) + { + $langs->load('errors'); + $langs->load('companies'); + setEventMessages($langs->trans('ErrorThirdPartyIdIsMandatory', $langs->trans('MergeOriginThirdparty')), null, 'errors'); + } + else + { + if (!$error && $soc_origin->fetch($soc_origin_id) < 1) + { + setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors'); + $error++; + } + + if (!$error) + { + // TODO Move the merge function into class of object. + + $db->begin(); + + // Recopy some data + $object->client = $object->client | $soc_origin->client; + $object->fournisseur = $object->fournisseur | $soc_origin->fournisseur; + $listofproperties=array( + 'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'skype', 'twitter', 'facebook', 'url', 'barcode', + 'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6', + 'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'remise_supplier_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis', + 'stcomm_id', 'outstanding_limit', 'price_level', 'parent', 'default_lang', 'ref', 'ref_ext', 'import_key', 'fk_incoterms', 'fk_multicurrency', + 'code_client', 'code_fournisseur', 'code_compta', 'code_compta_fournisseur', + 'model_pdf', 'fk_projet' + ); + foreach ($listofproperties as $property) + { + if (empty($object->$property)) $object->$property = $soc_origin->$property; + } + + // Concat some data + $listofproperties=array( + 'note_public', 'note_private' + ); + foreach ($listofproperties as $property) + { + $object->$property = dol_concatdesc($object->$property, $soc_origin->$property); + } + + // Merge extrafields + if (is_array($soc_origin->array_options)) + { + foreach ($soc_origin->array_options as $key => $val) + { + if (empty($object->array_options[$key])) $object->array_options[$key] = $val; + } + } + + // Merge categories + $static_cat = new Categorie($db); + + $custcats_ori = $static_cat->containing($soc_origin->id, 'customer', 'id'); + $custcats = $static_cat->containing($object->id, 'customer', 'id'); + $custcats = array_merge($custcats, $custcats_ori); + $object->setCategories($custcats, 'customer'); + + $suppcats_ori = $static_cat->containing($soc_origin->id, 'supplier', 'id'); + $suppcats = $static_cat->containing($object->id, 'supplier', 'id'); + $suppcats = array_merge($suppcats, $suppcats_ori); + $object->setCategories($suppcats, 'supplier'); + + // If thirdparty has a new code that is same than origin, we clean origin code to avoid duplicate key from database unique keys. + if ($soc_origin->code_client == $object->code_client + || $soc_origin->code_fournisseur == $object->code_fournisseur + || $soc_origin->barcode == $object->barcode) + { + dol_syslog("We clean customer and supplier code so we will be able to make the update of target"); + $soc_origin->code_client = ''; + $soc_origin->code_fournisseur = ''; + $soc_origin->barcode = ''; + $soc_origin->update($soc_origin->id, $user, 0, 1, 1, 'merge'); + } + + // Update + $object->update($object->id, $user, 0, 1, 1, 'merge'); + if ($result < 0) + { + $error++; + } + + // Move links + if (! $error) + { + $objects = array( + 'Adherent' => '/adherents/class/adherent.class.php', + 'Societe' => '/societe/class/societe.class.php', + //'Categorie' => '/categories/class/categorie.class.php', + 'ActionComm' => '/comm/action/class/actioncomm.class.php', + 'Propal' => '/comm/propal/class/propal.class.php', + 'Commande' => '/commande/class/commande.class.php', + 'Facture' => '/compta/facture/class/facture.class.php', + 'FactureRec' => '/compta/facture/class/facture-rec.class.php', + 'LignePrelevement' => '/compta/prelevement/class/ligneprelevement.class.php', + 'Contact' => '/contact/class/contact.class.php', + 'Contrat' => '/contrat/class/contrat.class.php', + 'Expedition' => '/expedition/class/expedition.class.php', + 'Fichinter' => '/fichinter/class/fichinter.class.php', + 'CommandeFournisseur' => '/fourn/class/fournisseur.commande.class.php', + 'FactureFournisseur' => '/fourn/class/fournisseur.facture.class.php', + 'SupplierProposal' => '/supplier_proposal/class/supplier_proposal.class.php', + 'ProductFournisseur' => '/fourn/class/fournisseur.product.class.php', + 'Livraison' => '/livraison/class/livraison.class.php', + 'Product' => '/product/class/product.class.php', + 'Project' => '/projet/class/project.class.php', + 'User' => '/user/class/user.class.php', + ); + + //First, all core objects must update their tables + foreach ($objects as $object_name => $object_file) + { + require_once DOL_DOCUMENT_ROOT.$object_file; + + if (!$error && !$object_name::replaceThirdparty($db, $soc_origin->id, $object->id)) + { + $error++; + setEventMessages($db->lasterror(), null, 'errors'); + } + } + } + + // External modules should update their ones too + if (! $error) + { + $reshook = $hookmanager->executeHooks('replaceThirdparty', array( + 'soc_origin' => $soc_origin->id, + 'soc_dest' => $object->id + ), $soc_dest, $action); + + if ($reshook < 0) + { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + $error++; + } + } + + + if (! $error) + { + $object->context=array('merge'=>1, 'mergefromid'=>$soc_origin->id); + + // Call trigger + $result=$object->call_trigger('COMPANY_MODIFY', $user); + if ($result < 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + $error++; + } + // End call triggers + } + + if (!$error) + { + //We finally remove the old thirdparty + if ($soc_origin->delete($soc_origin->id, $user) < 1) + { + $error++; + } + } + + if (!$error) + { + setEventMessages($langs->trans('ThirdpartiesMergeSuccess'), null, 'mesgs'); + $db->commit(); + } + else + { + $langs->load("errors"); + setEventMessages($langs->trans('ErrorsThirdpartyMerge'), null, 'errors'); + $db->rollback(); + } + } + } + } + + if (GETPOST('getcustomercode')) + { + // We defined value code_client + $_POST["customer_code"]="Acompleter"; + } + + if (GETPOST('getsuppliercode')) + { + // We defined value code_fournisseur + $_POST["supplier_code"]="Acompleter"; + } + + if($action=='set_localtax1') + { + //obtidre selected del combobox + $value=GETPOST('lt1'); + $object->fetch($socid); + $res=$object->setValueFrom('localtax1_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY'); + } + if($action=='set_localtax2') + { + //obtidre selected del combobox + $value=GETPOST('lt2'); + $object->fetch($socid); + $res=$object->setValueFrom('localtax2_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY'); + } + + if ($action == 'update_extras') { + $object->fetch($socid); + + $object->oldcopy = dol_clone($object); + + // Fill array 'array_options' with data from update form + $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); + $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute', 'none')); + if ($ret < 0) $error++; + + if (! $error) + { + $result = $object->insertExtraFields('COMPANY_MODIFY'); + if ($result < 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + $error++; + } + } + + if ($error) $action = 'edit_extras'; + } + + // Add new or update third party + if ((! GETPOST('getcustomercode') && ! GETPOST('getsuppliercode')) + && ($action == 'add' || $action == 'update') && $user->rights->societe->creer) + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + + if (! GETPOST('name')) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdPartyName")), null, 'errors'); + $error++; + } + if (GETPOST('client') < 0) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProspectCustomer")), null, 'errors'); + $error++; + } + if (GETPOST('fournisseur') < 0) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Supplier")), null, 'errors'); $error++; } - if (empty($error)) + if (! $error) { - $object->address = GETPOST('address', 'alpha'); - $object->zip = GETPOST('zipcode', 'alpha'); - $object->town = GETPOST('town', 'alpha'); - $object->country_id = $_POST["country_id"]; - $object->status = GETPOST('status', 'int'); - $object->fk_user_author = $user->id; - $object->datec = dol_now(); + if ($action == 'update') + { + $ret=$object->fetch($socid); + $object->oldcopy = clone $object; + } + else $object->canvas=$canvas; + if (GETPOST("private") == 1) // Ask to create a contact + { + $object->particulier = GETPOST("private"); + $object->name = dolGetFirstLastname(GETPOST('firstname', 'alpha'), GETPOST('name', 'alpha')); + $object->civility_id = GETPOST('civility_id'); // Note: civility id is a code, not an int + // Add non official properties + $object->name_bis = GETPOST('name', 'alpha'); + $object->firstname = GETPOST('firstname', 'alpha'); + } + else + { + $object->name = GETPOST('name', 'alpha'); + } + $object->entity = (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity); + $object->name_alias = GETPOST('name_alias'); + $object->address = GETPOST('address'); + $object->zip = GETPOST('zipcode', 'alpha'); + $object->town = GETPOST('town', 'alpha'); + $object->country_id = GETPOST('country_id', 'int'); + $object->state_id = GETPOST('state_id', 'int'); + $object->skype = GETPOST('skype', 'alpha'); + $object->twitter = GETPOST('twitter', 'alpha'); + $object->facebook = GETPOST('facebook', 'alpha'); + $object->phone = GETPOST('phone', 'alpha'); + $object->fax = GETPOST('fax', 'alpha'); + $object->email = trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL)); + $object->url = trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL)); + $object->idprof1 = trim(GETPOST('idprof1', 'alpha')); + $object->idprof2 = trim(GETPOST('idprof2', 'alpha')); + $object->idprof3 = trim(GETPOST('idprof3', 'alpha')); + $object->idprof4 = trim(GETPOST('idprof4', 'alpha')); + $object->idprof5 = trim(GETPOST('idprof5', 'alpha')); + $object->idprof6 = trim(GETPOST('idprof6', 'alpha')); + $object->prefix_comm = GETPOST('prefix_comm', 'alpha'); + $object->code_client = GETPOSTISSET('customer_code')?GETPOST('customer_code', 'alpha'):GETPOST('code_client', 'alpha'); + $object->code_fournisseur = GETPOSTISSET('supplier_code')?GETPOST('supplier_code', 'alpha'):GETPOST('code_fournisseur', 'alpha'); + $object->capital = GETPOST('capital', 'alpha'); + $object->barcode = GETPOST('barcode', 'alpha'); - $id = $object->create($user); + $object->tva_intra = GETPOST('tva_intra', 'alpha'); + $object->tva_assuj = GETPOST('assujtva_value', 'alpha'); + $object->status = GETPOST('status', 'alpha'); - if ($id > 0) - { - header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); - exit; - } - else + // Local Taxes + $object->localtax1_assuj = GETPOST('localtax1assuj_value', 'alpha'); + $object->localtax2_assuj = GETPOST('localtax2assuj_value', 'alpha'); + + $object->localtax1_value = GETPOST('lt1', 'alpha'); + $object->localtax2_value = GETPOST('lt2', 'alpha'); + + $object->forme_juridique_code = GETPOST('forme_juridique_code', 'int'); + $object->effectif_id = GETPOST('effectif_id', 'int'); + $object->typent_id = GETPOST('typent_id', 'int'); + + $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 + + $object->client = GETPOST('client', 'int'); + $object->fournisseur = GETPOST('fournisseur', 'int'); + + $object->commercial_id = GETPOST('commercial_id', 'int'); + $object->default_lang = GETPOST('default_lang'); + + // Webservices url/key + $object->webservices_url = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL); + $object->webservices_key = GETPOST('webservices_key', 'san_alpha'); + + // Incoterms + if (!empty($conf->incoterm->enabled)) { - setEventMessages($object->error, $object->errors, 'errors'); + $object->fk_incoterms = GETPOST('incoterm_id', 'int'); + $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); } + + // Multicurrency + if (!empty($conf->multicurrency->enabled)) + { + $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha'); + } + + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + if ($ret < 0) + { + $error++; + } + + if (GETPOST('deletephoto')) $object->logo = ''; + elseif (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']); + + // Check parameters + if (! GETPOST('cancel', 'alpha')) + { + if (! empty($object->email) && ! isValidEMail($object->email)) + { + $langs->load("errors"); + $error++; + setEventMessages('', $langs->trans("ErrorBadEMail", $object->email), 'errors'); + } + if (! empty($object->url) && ! isValidUrl($object->url)) + { + $langs->load("errors"); + setEventMessages('', $langs->trans("ErrorBadUrl", $object->url), 'errors'); + } + if (! empty($object->webservices_url)) { + //Check if has transport, without any the soap client will give error + if (strpos($object->webservices_url, "http") === false) + { + $object->webservices_url = "http://".$object->webservices_url; + } + if (! isValidUrl($object->webservices_url)) { + $langs->load("errors"); + $error++; $errors[] = $langs->trans("ErrorBadUrl", $object->webservices_url); + } + } + + // We set country_id, country_code and country for the selected country + $object->country_id=GETPOST('country_id')!=''?GETPOST('country_id'):$mysoc->country_id; + if ($object->country_id) + { + $tmparray=getCountry($object->country_id, 'all'); + $object->country_code=$tmparray['code']; + $object->country=$tmparray['label']; + } + } + } + + if (! $error) + { + if ($action == 'add') + { + $error = 0; + + $db->begin(); + + if (empty($object->client)) $object->code_client=''; + if (empty($object->fournisseur)) $object->code_fournisseur=''; + + $result = $object->create($user); + + if ($result >= 0) + { + if ($object->particulier) + { + dol_syslog("We ask to create a contact/address too", LOG_DEBUG); + $result=$object->create_individual($user); + if ($result < 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + $error++; + } + } + + // Links with users + $salesreps = GETPOST('commercial', 'array'); + $result = $object->setSalesRep($salesreps); + if ($result < 0) + { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + } + + // Customer categories association + $custcats = GETPOST('custcats', 'array'); + $result = $object->setCategories($custcats, 'customer'); + if ($result < 0) + { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + } + + // Supplier categories association + $suppcats = GETPOST('suppcats', 'array'); + $result = $object->setCategories($suppcats, 'supplier'); + if ($result < 0) + { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + } + + // Logo/Photo save + $dir = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos/"; + $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']); + if ($file_OK) + { + if (image_format_supported($_FILES['photo']['name'])) + { + dol_mkdir($dir); + + if (@is_dir($dir)) + { + $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']); + $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1); + + if (! $result > 0) + { + $errors[] = "ErrorFailedToSaveFile"; + } + else + { + // Create thumbs + $object->addThumbs($newfile); + } + } + } + } + else + { + switch($_FILES['photo']['error']) + { + case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini + case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form + $errors[] = "ErrorFileSizeTooLarge"; + break; + case 3: //uploaded file was only partially uploaded + $errors[] = "ErrorFilePartiallyUploaded"; + break; + } + } + // Gestion du logo de la société + } + else + { + 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 + { + $duplicate_code_error = true; + $object->code_fournisseur = null; + $object->code_client = null; + } + + setEventMessages($object->error, $object->errors, 'errors'); + $error++; + } + + if ($result >= 0 && ! $error) + { + $db->commit(); + + if (! empty($backtopage)) + { + if (preg_match('/\?/', $backtopage)) $backtopage.='&socid='.$object->id; + header("Location: ".$backtopage); + exit; + } + else + { + $url=$_SERVER["PHP_SELF"]."?socid=".$object->id; + if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $url=DOL_URL_ROOT."/comm/card.php?socid=".$object->id; + elseif ($object->fournisseur == 1) $url=DOL_URL_ROOT."/fourn/card.php?socid=".$object->id; + + header("Location: ".$url); + exit; + } + } + else + { + $db->rollback(); + $action='create'; + } + } + + if ($action == 'update') + { + $error = 0; + + if (GETPOST('cancel', 'alpha')) + { + if (! empty($backtopage)) + { + header("Location: ".$backtopage); + exit; + } + else + { + header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid); + exit; + } + } + + // To not set code if third party is not concerned. But if it had values, we keep them. + if (empty($object->client) && empty($object->oldcopy->code_client)) $object->code_client=''; + if (empty($object->fournisseur)&& empty($object->oldcopy->code_fournisseur)) $object->code_fournisseur=''; + //var_dump($object);exit; + + $result = $object->update($socid, $user, 1, $object->oldcopy->codeclient_modifiable(), $object->oldcopy->codefournisseur_modifiable(), 'update', 0); + if ($result <= 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + $error++; + } + + // Links with users + $salesreps = GETPOST('commercial', 'array'); + $result = $object->setSalesRep($salesreps); + if ($result < 0) + { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + } + + // Prevent thirdparty's emptying if a user hasn't rights $user->rights->categorie->lire (in such a case, post of 'custcats' is not defined) + if (! $error && !empty($user->rights->categorie->lire)) + { + // Customer categories association + $categories = GETPOST( 'custcats', 'array' ); + $result = $object->setCategories($categories, 'customer'); + if ($result < 0) + { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + } + + // Supplier categories association + $categories = GETPOST('suppcats', 'array'); + $result = $object->setCategories($categories, 'supplier'); + if ($result < 0) + { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + } + } + + // Logo/Photo save + $dir = $conf->societe->multidir_output[$object->entity]."/".$object->id."/logos"; + $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']); + if (GETPOST('deletephoto') && $object->logo) + { + $fileimg=$dir.'/'.$object->logo; + $dirthumbs=$dir.'/thumbs'; + dol_delete_file($fileimg); + dol_delete_dir_recursive($dirthumbs); + } + if ($file_OK) + { + if (image_format_supported($_FILES['photo']['name']) > 0) + { + dol_mkdir($dir); + + if (@is_dir($dir)) + { + $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']); + $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1); + + if (! $result > 0) + { + $errors[] = "ErrorFailedToSaveFile"; + } + else + { + // Create thumbs + $object->addThumbs($newfile); + + // Index file in database + if (! empty($conf->global->THIRDPARTY_LOGO_ALLOW_EXTERNAL_DOWNLOAD)) + { + require_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php'; + // 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 + deleteFilesIntoDatabaseIndex(dirname($newfile), '', '', 'uploaded', 1); + // now we index the uploaded logo file + addFileIntoDatabaseIndex(dirname($newfile), basename($newfile), '', 'uploaded', 1); + } + } + } + } + else + { + $errors[] = "ErrorBadImageFormat"; + } + } + else + { + switch($_FILES['photo']['error']) + { + case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini + case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form + $errors[] = "ErrorFileSizeTooLarge"; + break; + case 3: //uploaded file was only partially uploaded + $errors[] = "ErrorFilePartiallyUploaded"; + break; + } + } + // Gestion du logo de la société + + + // Update linked member + if (! $error && $object->fk_soc > 0) + { + + $sql = "UPDATE ".MAIN_DB_PREFIX."adherent"; + $sql.= " SET fk_soc = NULL WHERE fk_soc = " . $id; + if (! $object->db->query($sql)) + { + $error++; + $object->error .= $object->db->lasterror(); + setEventMessages($object->error, $object->errors, 'errors'); + } + } + + if (! $error && ! count($errors)) + { + if (! empty($backtopage)) + { + header("Location: ".$backtopage); + exit; + } + else + { + header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid); + exit; + } + } + else + { + $object->id = $socid; + $action= "edit"; + } + } } else { - $action='create'; + $action = ($action=='add'?'create':'edit'); } } - else + + // Delete third party + if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->supprimer) { - header("Location: ../admin/admin_establishment.php"); - exit; + $object->fetch($socid); + $result = $object->delete($socid, $user); + + if ($result > 0) + { + header("Location: ".DOL_URL_ROOT."/societe/list.php?restore_lastsearch_values=1&delsoc=".urlencode($object->name)); + exit; + } + else + { + $langs->load("errors"); + setEventMessages($object->error, $object->errors, 'errors'); + $error++; + $action=''; + } } + + // Set parent company + if ($action == 'set_thirdparty' && $user->rights->societe->creer) + { + $object->fetch($socid); + $result = $object->set_parent(GETPOST('editparentcompany', 'int')); + } + + // Set incoterm + if ($action == 'set_incoterms' && !empty($conf->incoterm->enabled)) + { + $object->fetch($socid); + $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); + } + + $id=$socid; + $object->fetch($socid); + + // Actions to send emails + $trigger_name='COMPANY_SENTBYMAIL'; + $paramname='socid'; + $mode='emailfromthirdparty'; + $trackid='thi'.$object->id; + include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; + + // Actions to build doc + $id = $socid; + $upload_dir = $conf->societe->dir_output; + $permissioncreate=$user->rights->societe->creer; + include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; } -// Update record -elseif ($action == 'update') -{ - $error = 0; - - if (! $cancel) { - - $name = GETPOST('name', 'alpha'); - if (empty($name)) { - setEventMessages($langs->trans('ErrorFieldRequired', $langs->trans('Name')), null, 'errors'); - $error ++; - } - - if (empty($error)) - { - $object->name = GETPOST('name', 'alpha'); - $object->address = GETPOST('address', 'alpha'); - $object->zip = GETPOST('zipcode', 'alpha'); - $object->town = GETPOST('town', 'alpha'); - $object->country_id = GETPOST('country_id', 'int'); - $object->fk_user_mod = $user->id; - $object->status = GETPOST('status', 'int'); - - $result = $object->update($user); - - if ($result > 0) - { - header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $_POST['id']); - exit; - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - } - } - } else { - header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $_POST['id']); - exit; - } -} /* - * View + * View */ -llxHeader(); - $form = new Form($db); +$formfile = new FormFile($db); +$formadmin = new FormAdmin($db); $formcompany = new FormCompany($db); -/* - * Action create - */ -if ($action == 'create') +if ($socid > 0 && empty($object->id)) { - print load_fiche_titre($langs->trans("NewEstablishment")); - - print '
'; - print ''; - print ''; - - dol_fiche_head(); - - print ''; - - // Name - print ''; - print ''; - print ''; - print ''; - - // Address - print ''; - print ''; - print ''; - print ''; - - // Zipcode - print ''; - print ''; - print ''; - print ''; - - // Town - print ''; - print ''; - print ''; - print ''; - - // Country - print ''; - print ''; - print ''; - print ''; - - // Status - print ''; - print ''; - print ''; - - print '
'. $form->editfieldkey('Name', 'name', '', $object, 0, 'string', '', 1).'
'.$form->editfieldkey('Address', 'address', '', $object, 0).''; - print ''; - print '
'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).''; -print $formcompany->select_ziptown( - GETPOST('zipcode', 'alpha'), - 'zipcode', - array ( - 'town', - 'selectcountry_id' - ), - 6 - ); - print '
'.$form->editfieldkey('Town', 'town', '', $object, 0).''; -print $formcompany->select_ziptown(GETPOST('town', 'alpha'), 'town', array ( - 'zipcode', - 'selectcountry_id' - )); - print '
'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).''; - print $form->select_country(GETPOST('country_id', 'int')>0?GETPOST('country_id', 'int'):$mysoc->country_id, 'country_id'); - if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); - print '
'.$form->editfieldkey('Status', 'status', '', $object, 0, 'string', '', 1).''; - print $form->selectarray('status', $status2label, GETPOST('status', 'alpha')); - print '
'; - - dol_fiche_end(); - - print '
'; - print ''; - print '     '; - print ''; - print '
'; - - print '
'; + $result=$object->fetch($socid); + if ($result <= 0) dol_print_error('', $object->error); } -// Part to edit record -if (($id || $ref) && $action == 'edit') +$title=$langs->trans("ThirdParty"); +if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$langs->trans('Card'); +$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; +llxHeader('', $title, $help_url); + +$countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')'; + +if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { - $result = $object->fetch($id); - if ($result > 0) + // ----------------------------------------- + // When used with CANVAS + // ----------------------------------------- + $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates + $objcanvas->display_canvas($action); // Show template +} +else +{ + // ----------------------------------------- + // When used in standard mode + // ----------------------------------------- + if ($action == 'create') { - $head = establishment_prepare_head($object); + /* + * Creation + */ + $private=GETPOST("private", "int"); + if (! empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT) && ! isset($_GET['private']) && ! isset($_POST['private'])) $private=1; + if (empty($private)) $private=0; - if ($action == 'edit') + // Load object modCodeTiers + $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard'); + if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') { - dol_fiche_head($head, 'card', $langs->trans("Establishment"), 0, 'building'); + $module = substr($module, 0, dol_strlen($module)-4); + } + $dirsociete=array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); + foreach ($dirsociete as $dirroot) + { + $res=dol_include_once($dirroot.$module.'.php'); + if ($res) break; + } + $modCodeClient = new $module; + // Load object modCodeFournisseur + $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard'); + if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') + { + $module = substr($module, 0, dol_strlen($module)-4); + } + $dirsociete=array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); + foreach ($dirsociete as $dirroot) + { + $res=dol_include_once($dirroot.$module.'.php'); + if ($res) break; + } + $modCodeFournisseur = new $module; - print '
' . "\n"; - print ''; + // Define if customer/prospect or supplier status is set or not + if (GETPOST("type")!='f') + { + $object->client=-1; + if (! empty($conf->global->THIRDPARTY_CUSTOMERPROSPECT_BY_DEFAULT)) { $object->client=3; } + } + // Prospect / Customer + if (GETPOST("type")=='c') { + if (! empty($conf->global->THIRDPARTY_CUSTOMERTYPE_BY_DEFAULT)) { + $object->client=$conf->global->THIRDPARTY_CUSTOMERTYPE_BY_DEFAULT; + } else { + $object->client=3; + } + } + if (GETPOST("type")=='p') { $object->client=2; } + if (! empty($conf->fournisseur->enabled) && (GETPOST("type")=='f' || (GETPOST("type")=='' && ! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)))) { $object->fournisseur=1; } + + $object->name = GETPOST('name', 'alpha'); + $object->firstname = GETPOST('firstname', 'alpha'); + $object->particulier = $private; + $object->prefix_comm = GETPOST('prefix_comm'); + $object->client = GETPOST('client')?GETPOST('client'):$object->client; + + if(empty($duplicate_code_error)) { + $object->code_client = GETPOST('customer_code', 'alpha'); + $object->fournisseur = GETPOST('fournisseur')?GETPOST('fournisseur'):$object->fournisseur; + } + else { + setEventMessages($langs->trans('NewCustomerSupplierCodeProposed'), '', 'warnings'); + } + + $object->code_fournisseur = GETPOST('supplier_code', 'alpha'); + $object->address = GETPOST('address', 'alpha'); + $object->zip = GETPOST('zipcode', 'alpha'); + $object->town = GETPOST('town', 'alpha'); + $object->state_id = GETPOST('state_id', 'int'); + $object->skype = GETPOST('skype', 'alpha'); + $object->twitter = GETPOST('twitter', 'alpha'); + $object->facebook = GETPOST('facebook', 'alpha'); + $object->phone = GETPOST('phone', 'alpha'); + $object->fax = GETPOST('fax', 'alpha'); + $object->email = GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL); + $object->url = GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL); + $object->capital = GETPOST('capital', 'alpha'); + $object->barcode = GETPOST('barcode', 'alpha'); + $object->idprof1 = GETPOST('idprof1', 'alpha'); + $object->idprof2 = GETPOST('idprof2', 'alpha'); + $object->idprof3 = GETPOST('idprof3', 'alpha'); + $object->idprof4 = GETPOST('idprof4', 'alpha'); + $object->idprof5 = GETPOST('idprof5', 'alpha'); + $object->idprof6 = GETPOST('idprof6', 'alpha'); + $object->typent_id = GETPOST('typent_id', 'int'); + $object->effectif_id = GETPOST('effectif_id', 'int'); + $object->civility_id = GETPOST('civility_id', 'int'); + + $object->tva_assuj = GETPOST('assujtva_value', 'int'); + $object->status = GETPOST('status', 'int'); + + //Local Taxes + $object->localtax1_assuj = GETPOST('localtax1assuj_value', 'int'); + $object->localtax2_assuj = GETPOST('localtax2assuj_value', 'int'); + + $object->localtax1_value =GETPOST('lt1', 'int'); + $object->localtax2_value =GETPOST('lt2', 'int'); + + $object->tva_intra = GETPOST('tva_intra', 'alpha'); + + $object->commercial_id = GETPOST('commercial_id', 'int'); + $object->default_lang = GETPOST('default_lang'); + + $object->logo = (isset($_FILES['photo'])?dol_sanitizeFileName($_FILES['photo']['name']):''); + + // Gestion du logo de la société + $dir = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos"; + $file_OK = (isset($_FILES['photo'])?is_uploaded_file($_FILES['photo']['tmp_name']):false); + if ($file_OK) + { + if (image_format_supported($_FILES['photo']['name'])) + { + dol_mkdir($dir); + + if (@is_dir($dir)) + { + $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']); + $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1); + + if (! $result > 0) + { + $errors[] = "ErrorFailedToSaveFile"; + } + else + { + // Create thumbs + $object->addThumbs($newfile); + } + } + } + } + + // We set country_id, country_code and country for the selected country + $object->country_id=GETPOST('country_id')?GETPOST('country_id'):$mysoc->country_id; + if ($object->country_id) + { + $tmparray=getCountry($object->country_id, 'all'); + $object->country_code=$tmparray['code']; + $object->country=$tmparray['label']; + } + $object->forme_juridique_code=GETPOST('forme_juridique_code'); + /* Show create form */ + + $linkback=""; + print load_fiche_titre($langs->trans("NewThirdParty"), $linkback, 'title_companies.png'); + + if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION)) + { + print "\n".''."\n"; + + print '
'; + print '
'; + print $langs->trans("ThirdPartyType").':     '; + print '
'; + print ''; + print '     '; + print ''; + print '
'; + print "
\n"; + } + + dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error'); + + print ''; // Chrome ignor autocomplete + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) print ''; + + dol_fiche_head(null, 'card', '', 0, ''); + + print ''; + + // Name, firstname + print 'global->SOCIETE_USEPREFIX)?' colspan="3"':'').'>'; + print ''; + if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field + { + print ''; + } + print ''; + + // If javascript on, we show option individual + if ($conf->use_javascript_ajax) + { + print ''; + print ''; + print ''; + // Title + print ''; + print ''; + } + + // Alias names (commercial, trademark or alias names) + print ''; + print ''; + + // Prospect/Customer + print ''; + print ''; + + print ''; + + if ((! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire)) + || (! empty($conf->supplier_proposal->enabled) && ! empty($user->rights->supplier_proposal->lire))) + { + // Supplier + print ''; + print ''; + print ''; + } + + // Status + print ''; + + // Barcode + if (! empty($conf->barcode->enabled)) + { + print ''; + print ''; + } + + // Address + print ''; + print ''; + + // Zip / Town + print ''; + + // Country + print ''; + + // State + if (empty($conf->global->SOCIETE_DISABLE_STATE)) + { + 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)) + { + print ''; + } + + // Email / Web + print ''; + print ''; + print ''; + print ''; + + if (! empty($conf->socialnetworks->enabled)) + { + // Skype + if (! empty($conf->global->SOCIALNETWORKS_SKYPE)) + { + print ''; + print ''; + } + // Twitter + if (! empty($conf->global->SOCIALNETWORKS_TWITTER)) + { + print ''; + print ''; + } + // Facebook + if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK)) + { + print ''; + print ''; + } + } + + // Phone / Fax + print ''; + print ''; + print ''; + print ''; + + // Prof ids + $i=1; $j=0; + while ($i <= 6) + { + $idprof=$langs->transcountry('ProfId'.$i, $object->country_code); + if ($idprof!='-') + { + $key='idprof'.$i; + + if (($j % 2) == 0) print ''; + + $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY'; + print ''; + if (($j % 2) == 1) print ''; + $j++; + } + $i++; + } + if ($j % 2 == 1) print ''; + + // Vat is used + print ''; + print ''; + print ''; + print ''; + print ''; + + // Local Taxes + //TODO: Place into a function to control showing by country or study better option + if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1") + { + print ''; + } + elseif($mysoc->localtax1_assuj=="1") + { + print ''; + } + elseif($mysoc->localtax2_assuj=="1") + { + print ''; + } + + // Type - Size + print ''; + print ''; + + // Legal Form + print ''; + print ''; + + // Capital + print ''; + print ''; + + if (! empty($conf->global->MAIN_MULTILANGS)) + { + print ''; + print ''; + } + + // Incoterms + if (!empty($conf->incoterm->enabled)) + { + print ''; + print ''; + print ''; + } + + // Categories + if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) + { + $langs->load('categories'); + + // Customer + //if ($object->prospect || $object->client || (! $object->fournisseur && ! empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER))) { + print '"; + //} + + // Supplier + //if ($object->fournisseur) { + print '"; + //} + } + + // Multicurrency + if (! empty($conf->multicurrency->enabled)) + { + print ''; + print ''; + print ''; + } + + // Other attributes + $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3'); + $reshook=$hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + if (empty($reshook)) + { + print $object->showOptionals($extrafields, 'edit'); + } + + // Assign a sale representative + print ''; + print ''; + print ''; + + // Ajout du logo + print ''; + print ''; + print ''; + print ''; + + print '
'; + if ($object->particulier || $private) + { + print ''.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName', 'name').''; + } + else + { + print ''.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0).''; + } + print ''.$langs->trans('Prefix').'
'.$form->editfieldkey('FirstName', 'firstname', '', $object, 0).'
'.$form->editfieldkey('UserTitle', 'civility_id', '', $object, 0).''; + print $formcompany->select_civility($object->civility_id, 'civility_id', 'maxwidth100').'
'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).''; + $selected=GETPOST('client', 'int')!=''?GETPOST('client', 'int'):$object->client; + print $formcompany->selectProspectCustomerType($selected); + print ''.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).''; + print '
'; + $tmpcode=$object->code_client; + if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object, 0); + print ''; + print ''; + $s=$modCodeClient->getToolTip($langs, $object, 0); + print $form->textwithpicto('', $s, 1); + print '
'; + print '
'.$form->editfieldkey('Supplier', 'fournisseur', '', $object, 0, 'string', '', 1).''; + $default = -1; + if (! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)) $default=1; + print $form->selectyesno("fournisseur", (GETPOST('fournisseur', 'int')!=''?GETPOST('fournisseur', 'int'):(GETPOST("type", 'alpha') == '' ? $default : $object->fournisseur)), 1, 0, (GETPOST("type", 'alpha') == '' ? 1 : 0)); + print ''; + if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire)) + { + print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0); + } + print ''; + if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire)) + { + print '
'; + $tmpcode=$object->code_fournisseur; + if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object, 1); + print ''; + print ''; + $s=$modCodeFournisseur->getToolTip($langs, $object, 1); + print $form->textwithpicto('', $s, 1); + print '
'; + } + print '
'.$form->editfieldkey('Status', 'status', '', $object, 0).''; + print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'),'1'=>$langs->trans('InActivity')), 1); + print '
'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).''; + print '
'.$form->editfieldkey('Address', 'address', '', $object, 0).'
'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).''; + print $formcompany->select_ziptown($object->zip, 'zipcode', array('town','selectcountry_id','state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent'); + print ''.$form->editfieldkey('Town', 'town', '', $object, 0).''; + print $formcompany->select_ziptown($object->town, 'town', array('zipcode','selectcountry_id','state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent'); + print '
'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).''; + print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id)); + if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + print '
'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).''; + } + else + { + print '
'.$form->editfieldkey('State', 'state_id', '', $object, 0).''; + } + + if ($object->country_id) print $formcompany->select_state($object->state_id, $object->country_code); + else print $countrynotdefined; + print '
'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', $conf->global->SOCIETE_EMAIL_MANDATORY).'
'.$form->editfieldkey('Web', 'url', '', $object, 0).'
'.$form->editfieldkey('Skype', 'skype', '', $object, 0).''; + print 'skype).'">'; + print '
'.$form->editfieldkey('Twitter', 'twitter', '', $object, 0).''; + print 'twitter).'">'; + print '
'.$form->editfieldkey('Facebook', 'facebook', '', $object, 0).''; + print 'facebook).'">'; + print '
'.$form->editfieldkey('Phone', 'phone', '', $object, 0).''.$form->editfieldkey('Fax', 'fax', '', $object, 0).'
'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', (empty($conf->global->$idprof_mandatory)?0:1)).''; + + print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code); + print '
'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).''; + print $form->selectyesno('assujtva_value', GETPOSTISSET('assujtva_value')?GETPOST('assujtva_value', 'int'):1, 1); // Assujeti par defaut en creation + print ''.$form->editfieldkey('VATIntra', 'intra_vat', '', $object, 0).''; + $s = ''; + + if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object)) + { + $s.=' '; + + if (! empty($conf->use_javascript_ajax)) + { + print "\n"; + print ''; + print "\n"; + $s.=''.$langs->trans("VATIntraCheck").''; + $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->trans("VATIntraCheck")), 1); + } + else + { + $s.='country_id).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').''; + } + } + print $s; + print '
'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).''; + print $form->selectyesno('localtax1assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1:0), 1); + print ''.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).''; + print $form->selectyesno('localtax2assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0), 1); + print '
'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).''; + print $form->selectyesno('localtax1assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1:0), 1); + print '
'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).''; + print $form->selectyesno('localtax2assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0), 1); + print '
'.$form->editfieldkey('ThirdPartyType', 'typent_id', '', $object, 0).''."\n"; + $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. + print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, $sortparam); + if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + print ''.$form->editfieldkey('Staff', 'effectif_id', '', $object, 0).''; + print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id); + if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + print '
'.$form->editfieldkey('JuridicalStatus', 'forme_juridique_code', '', $object, 0).''; + if ($object->country_id) + { + print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code'); + } + else + { + print $countrynotdefined; + } + print '
'.$form->editfieldkey('Capital', 'capital', '', $object, 0).' '; + print ''.$langs->trans("Currency".$conf->currency).'
'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).''."\n"; + print $formadmin->select_language(($object->default_lang?$object->default_lang:$conf->global->MAIN_LANG_DEFAULT), 'default_lang', 0, 0, 1, 0, 0, 'maxwidth200onsmartphone'); + print '
'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).''; + print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:'')); + print '
' . $form->editfieldkey('CustomersProspectsCategoriesShort', 'custcats', '', $object, 0) . ''; + $cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, 'parent', null, null, 1); + print $form->multiselectarray('custcats', $cate_arbo, GETPOST('custcats', 'array'), null, null, null, null, "90%"); + print "
' . $form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0) . ''; + $cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, 'parent', null, null, 1); + print $form->multiselectarray('suppcats', $cate_arbo, GETPOST('suppcats', 'array'), null, null, null, null, "90%"); + print "
'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).''; + print $form->selectMultiCurrency(($object->multicurrency_code ? $object->multicurrency_code : $conf->currency), 'multicurrency_code', 1); + print '
'.$form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0).''; + $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, '', 0, '', '', 0, 1); + // Note: If user has no right to "see all thirdparties", we for selection of sale representative to him, so after creation he can see the record. + $selected = (count(GETPOST('commercial', 'array')) > 0 ? GETPOST('commercial', 'array') : (GETPOST('commercial', 'int') > 0 ? array(GETPOST('commercial', 'int')) : (empty($user->rights->societe->client->voir)?array($user->id):array()))); + print $form->multiselectarray('commercial', $userlist, $selected, null, null, null, null, "90%"); + print '
'.$form->editfieldkey('Logo', 'photoinput', '', $object, 0).''; + print ''; + print '
'."\n"; + + dol_fiche_end(); + + print '
'; + print ''; + if (! empty($backtopage)) + { + print '     '; + print ''; + } + else + { + print '     '; + print ''; + } + print '
'."\n"; + + print '
'."\n"; + } + elseif ($action == 'edit') + { + //print load_fiche_titre($langs->trans("EditCompany")); + + if ($socid) + { + $res=$object->fetch_optionals(); + //if ($res < 0) { dol_print_error($db); exit; } + + $head = societe_prepare_head($object); + + // Load object modCodeTiers + $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard'); + if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') + { + $module = substr($module, 0, dol_strlen($module)-4); + } + $dirsociete=array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); + foreach ($dirsociete as $dirroot) + { + $res=dol_include_once($dirroot.$module.'.php'); + if ($res) break; + } + $modCodeClient = new $module($db); + // We verified if the tag prefix is used + if ($modCodeClient->code_auto) + { + $prefixCustomerIsUsed = $modCodeClient->verif_prefixIsUsed(); + } + $module=$conf->global->SOCIETE_CODECLIENT_ADDON; + if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') + { + $module = substr($module, 0, dol_strlen($module)-4); + } + $dirsociete=array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); + foreach ($dirsociete as $dirroot) + { + $res=dol_include_once($dirroot.$module.'.php'); + if ($res) break; + } + $modCodeFournisseur = new $module($db); + // On verifie si la balise prefix est utilisee + if ($modCodeFournisseur->code_auto) + { + $prefixSupplierIsUsed = $modCodeFournisseur->verif_prefixIsUsed(); + } + + $object->oldcopy = clone $object; + + if (GETPOSTISSET('name')) + { + // We overwrite with values if posted + $object->name = GETPOST('name', 'alpha'); + $object->prefix_comm = GETPOST('prefix_comm', 'alpha'); + $object->client = GETPOST('client', 'int'); + $object->code_client = GETPOST('customer_code', 'alpha'); + $object->fournisseur = GETPOST('fournisseur', 'int'); + $object->code_fournisseur = GETPOST('supplier_code', 'alpha'); + $object->address = GETPOST('address', 'alpha'); + $object->zip = GETPOST('zipcode', 'alpha'); + $object->town = GETPOST('town', 'alpha'); + $object->country_id = GETPOST('country_id')?GETPOST('country_id', 'int'):$mysoc->country_id; + $object->state_id = GETPOST('state_id', 'int'); + $object->skype = GETPOST('skype', 'alpha'); + $object->twitter = GETPOST('twitter', 'alpha'); + $object->facebook = GETPOST('facebook', 'alpha'); + $object->phone = GETPOST('phone', 'alpha'); + $object->fax = GETPOST('fax', 'alpha'); + $object->email = GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL); + $object->url = GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL); + $object->capital = GETPOST('capital', 'alpha'); + $object->idprof1 = GETPOST('idprof1', 'alpha'); + $object->idprof2 = GETPOST('idprof2', 'alpha'); + $object->idprof3 = GETPOST('idprof3', 'alpha'); + $object->idprof4 = GETPOST('idprof4', 'alpha'); + $object->idprof5 = GETPOST('idprof5', 'alpha'); + $object->idprof6 = GETPOST('idprof6', 'alpha'); + $object->typent_id = GETPOST('typent_id', 'int'); + $object->effectif_id = GETPOST('effectif_id', 'int'); + $object->barcode = GETPOST('barcode', 'alpha'); + $object->forme_juridique_code = GETPOST('forme_juridique_code', 'int'); + $object->default_lang = GETPOST('default_lang', 'alpha'); + + $object->tva_assuj = GETPOST('assujtva_value', 'int'); + $object->tva_intra = GETPOST('tva_intra', 'alpha'); + $object->status = GETPOST('status', 'int'); + + // Webservices url/key + $object->webservices_url = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL); + $object->webservices_key = GETPOST('webservices_key', 'san_alpha'); + + //Incoterms + if (!empty($conf->incoterm->enabled)) + { + $object->fk_incoterms = GETPOST('incoterm_id', 'int'); + $object->location_incoterms = GETPOST('lcoation_incoterms', 'alpha'); + } + + //Local Taxes + $object->localtax1_assuj = GETPOST('localtax1assuj_value'); + $object->localtax2_assuj = GETPOST('localtax2assuj_value'); + + $object->localtax1_value =GETPOST('lt1'); + $object->localtax2_value =GETPOST('lt2'); + + // We set country_id, and country_code label of the chosen country + if ($object->country_id > 0) + { + $tmparray=getCountry($object->country_id, 'all'); + $object->country_code = $tmparray['code']; + $object->country = $tmparray['label']; + } + } + + if($object->localtax1_assuj==0){ + $sub=0; + }else{$sub=1;} + if($object->localtax2_assuj==0){ + $sub2=0; + }else{$sub2=1;} + + if ($conf->use_javascript_ajax) + { + print "\n".''."\n"; + } + + print '
'; print ''; - print ''; + print ''; + print ''; + print ''; + if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) print ''; + + dol_fiche_head($head, 'card', $langs->trans("ThirdParty"), 0, 'company'); + + print '
'; print ''; - // Ref - print ""; - print ''; + // Ref/ID + if (! empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) + { + print ''; + } // Name - print ''; + print ''; + + // Alias names (commercial, trademark or alias names) + print ''; + print ''; + + // Prefix + if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field + { + print ''; + } + + // Prospect/Customer + print ''; + print ''; + print ''; - // Address - print ''; - print ''; + // Supplier + if ((! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire)) + || (! empty($conf->supplier_proposal->enabled) && ! empty($user->rights->supplier_proposal->lire))) + { + print ''; + print ''; + print ''; + } - // Zipcode / Town - print ''; - print ''; + // Barcode + if (! empty($conf->barcode->enabled)) + { + print ''; + print ''; + } - // Country - print ''; - print ''; - print ''; + // Status + print ''; - // Status - print ''; + // Address + print ''; + print ''; + + // Zip / Town + print ''; + + // Country + print ''; + + // State + if (empty($conf->global->SOCIETE_DISABLE_STATE)) + { + 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)) + { + print ''; + } + + // EMail / Web + print ''; + print ''; + print ''; + print ''; + + if (! empty($conf->socialnetworks->enabled)) + { + // Skype + if (! empty($conf->global->SOCIALNETWORKS_SKYPE)) + { + print ''; + print ''; + } + // Twitter + if (! empty($conf->global->SOCIALNETWORKS_TWITTER)) + { + print ''; + print ''; + } + // Facebook + if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK)) + { + print ''; + print ''; + } + } + + // Phone / Fax + print ''; + print ''; + print ''; + print ''; + + // Prof ids + $i=1; $j=0; + while ($i <= 6) + { + $idprof=$langs->transcountry('ProfId'.$i, $object->country_code); + if ($idprof!='-') + { + $key='idprof'.$i; + + if (($j % 2) == 0) print ''; + + $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY'; + print ''; + if (($j % 2) == 1) print ''; + $j++; + } + $i++; + } + if ($j % 2 == 1) print ''; + + // VAT is used + print ''; + + // Local Taxes + //TODO: Place into a function to control showing by country or study better option + if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1") + { + print ''; + + print ''; + } + elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1") + { + print ''; + } + elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1") + { + print ''; + } + + // VAT Code + print ''; + print ''; + print ''; + + // Type - Size + print ''; + print ''; + + // Juridical type + print ''; + + // Capital + print ''; + print ''; + + // Default language + if (! empty($conf->global->MAIN_MULTILANGS)) + { + print ''; + print ''; + } + + // Incoterms + if (!empty($conf->incoterm->enabled)) + { + print ''; + print ''; + print ''; + } + + // Categories + if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) + { + // Customer + print ''; + print '"; + + // Supplier + print ''; + print '"; + } + + // Multicurrency + if (! empty($conf->multicurrency->enabled)) + { + print ''; + print ''; + print ''; + } + + // Other attributes + $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3'); + $reshook=$hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + if (empty($reshook)) + { + print $object->showOptionals($extrafields, 'edit'); + } + + // Webservices url/key + if (!empty($conf->syncsupplierwebservices->enabled)) { + print ''; + print ''; + print ''; + print ''; + } + + // Logo + print ''; + print ''; + print ''; + print ''; + + // Assign sale representative + print ''; + print ''; + print ''; print '
'.$langs->trans("Ref").''; - print $object->id; - print '
'.$langs->trans("ID").''; + print $object->ref; + print '
'.$form->editfieldkey('Name', 'name', '', $object, 0, 'string', '', 1).''; - print ''; + print '
'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0, 'string', '', 1).'
'.$form->editfieldkey('Prefix', 'prefix', '', $object, 0).''; + // It does not change the prefix mode using the auto numbering prefix + if (($prefixCustomerIsUsed || $prefixSupplierIsUsed) && $object->prefix_comm) + { + print ''; + print $object->prefix_comm; + } + else + { + print ''; + } + print '
'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).''; + print $formcompany->selectProspectCustomerType($object->client); + print ''.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).''; + + print '
'; + if ((!$object->code_client || $object->code_client == -1) && $modCodeClient->code_auto) + { + $tmpcode=$object->code_client; + if (empty($tmpcode) && ! empty($object->oldcopy->code_client)) $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. + if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object, 0); + print ''; + } + elseif ($object->codeclient_modifiable()) + { + print ''; + } + else + { + print $object->code_client; + print ''; + } + print ''; + $s=$modCodeClient->getToolTip($langs, $object, 0); + print $form->textwithpicto('', $s, 1); + print '
'; + print '
'.$form->editfieldkey('Address', 'address', '', $object, 0).''; - print ''; - print '
'.$form->editfieldkey('Supplier', 'fournisseur', '', $object, 0, 'string', '', 1).''; + print $form->selectyesno("fournisseur", $object->fournisseur, 1); + print ''; + if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire)) + { + print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0); + } + print ''; + if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire)) + { + print '
'; + if ((!$object->code_fournisseur || $object->code_fournisseur == -1) && $modCodeFournisseur->code_auto) + { + $tmpcode=$object->code_fournisseur; + if (empty($tmpcode) && ! empty($object->oldcopy->code_fournisseur)) $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. + if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object, 1); + print ''; + } + elseif ($object->codefournisseur_modifiable()) + { + print ''; + } + else + { + print $object->code_fournisseur; + print ''; + } + print ''; + $s=$modCodeFournisseur->getToolTip($langs, $object, 1); + print $form->textwithpicto('', $s, 1); + print '
'; + } + print '
'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).''; -print $formcompany->select_ziptown($object->zip, 'zipcode', array ( - 'town', - 'selectcountry_id' - ), 6) . '
'.$form->editfieldkey('Town', 'town', '', $object, 0).''; -print $formcompany->select_ziptown($object->town, 'town', array ( - 'zipcode', - 'selectcountry_id' - )) . '
'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).''; + print '
'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).''; - print $form->select_country($object->fk_country, 'country_id'); - if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); - print '
'.$form->editfieldkey('Status', 'status', '', $object, 0).''; + print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'),'1'=>$langs->trans('InActivity')), $object->status); + print '
'.$form->editfieldkey('Status', 'status', '', $object, 0, 'string', '', 1).''; - print $form->selectarray('status', $status2label, $object->status); - print '
'.$form->editfieldkey('Address', 'address', '', $object, 0).'
'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).''; + print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth50onsmartphone'); + print ''.$form->editfieldkey('Town', 'town', '', $object, 0).''; + print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id')); + print '
'.$form->editfieldkey('Country', 'selectcounty_id', '', $object, 0).''; + print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id), 'country_id'); + if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + print '
'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).''; + } + else + { + print '
'.$form->editfieldkey('State', 'state_id', '', $object, 0).''; + } + + print $formcompany->select_state($object->state_id, $object->country_code); + print '
'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', (! empty($conf->global->SOCIETE_EMAIL_MANDATORY))).'
'.$form->editfieldkey('Web', 'url', '', $object, 0).'
'.$form->editfieldkey('Skype', 'skype', '', $object, 0).'
'.$form->editfieldkey('Twitter', 'twitter', '', $object, 0).'
'.$form->editfieldkey('Facebook', 'facebook', '', $object, 0).'
'.$form->editfieldkey('Phone', 'phone', '', $object, 0).''.$form->editfieldkey('Fax', 'fax', '', $object, 0).'
'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', ! (empty($conf->global->$idprof_mandatory) || ! $object->isACompany())).''; + print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code); + print '
'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).''; + print $form->selectyesno('assujtva_value', $object->tva_assuj, 1); + print '
'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value', '', $object, 0).''; + print $form->selectyesno('localtax1assuj_value', $object->localtax1_assuj, 1); + if(! isOnlyOneLocalTax(1)) + { + print ' '.$langs->transcountry("Type", $mysoc->country_code).': '; + $formcompany->select_localtax(1, $object->localtax1_value, "lt1"); + print ''; + } + print ''.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value', '', $object, 0).''; + print $form->selectyesno('localtax2assuj_value', $object->localtax2_assuj, 1); + if (! isOnlyOneLocalTax(2)) + { + print ' '.$langs->transcountry("Type", $mysoc->country_code).': '; + $formcompany->select_localtax(2, $object->localtax2_value, "lt2"); + print ''; + } + print '
'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value', '', $object, 0).''; + print $form->selectyesno('localtax1assuj_value', $object->localtax1_assuj, 1); + if(! isOnlyOneLocalTax(1)) + { + print ' '.$langs->transcountry("Type", $mysoc->country_code).': '; + $formcompany->select_localtax(1, $object->localtax1_value, "lt1"); + print ''; + } + print '
'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value', '', $object, 0).''; + print $form->selectyesno('localtax2assuj_value', $object->localtax2_assuj, 1); + if(! isOnlyOneLocalTax(2)) + { + print ' '.$langs->transcountry("Type", $mysoc->country_code).': '; + $formcompany->select_localtax(2, $object->localtax2_value, "lt2"); + print ''; + } + print '
'.$form->editfieldkey('VATIntra', 'intra_vat', '', $object, 0).''; + $s =''; + + if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object)) + { + $s.='   '; + + if ($conf->use_javascript_ajax) + { + print "\n"; + print ''; + print "\n"; + $s.=''.$langs->trans("VATIntraCheck").''; + $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->trans("VATIntraCheck")), 1); + } + else + { + $s.='country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').''; + } + } + print $s; + print '
'.$form->editfieldkey('ThirdPartyType', 'typent_id', '', $object, 0).''; + print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT)); + if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + print ''.$form->editfieldkey('Staff', 'effectif_id', '', $object, 0).''; + print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id); + if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + print '
'.$form->editfieldkey('JuridicalStatus', 'forme_juridique_code', '', $object, 0).''; + print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code'); + print '
'.$form->editfieldkey('Capital', 'capital', '', $object, 0).' '.$langs->trans("Currency".$conf->currency).'
'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).''."\n"; + print $formadmin->select_language($object->default_lang, 'default_lang', 0, 0, 1); + print '
'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).''; + print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:'')); + print '
' . $form->editfieldkey('CustomersCategoriesShort', 'custcats', '', $object, 0) . ''; + $cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, null, null, null, 1); + $c = new Categorie($db); + $cats = $c->containing($object->id, Categorie::TYPE_CUSTOMER); + $arrayselected=array(); + foreach ($cats as $cat) { + $arrayselected[] = $cat->id; + } + print $form->multiselectarray('custcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%'); + print "
' . $form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0) . ''; + $cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, null, null, null, 1); + $c = new Categorie($db); + $cats = $c->containing($object->id, Categorie::TYPE_SUPPLIER); + $arrayselected=array(); + foreach ($cats as $cat) { + $arrayselected[] = $cat->id; + } + print $form->multiselectarray('suppcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%'); + print "
'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).''; + print $form->selectMultiCurrency(($object->multicurrency_code ? $object->multicurrency_code : $conf->currency), 'multicurrency_code', 1); + print '
'.$form->editfieldkey('WebServiceURL', 'webservices_url', '', $object, 0).''.$form->editfieldkey('WebServiceKey', 'webservices_key', '', $object, 0).'
'.$form->editfieldkey('Logo', 'photoinput', '', $object, 0).''; + if ($object->logo) print $form->showphoto('societe', $object); + $caneditfield=1; + if ($caneditfield) + { + if ($object->logo) print "
\n"; + print ''; + if ($object->logo) print ''; + //print ''; + print ''; + print '
'.$langs->trans("Delete").'

'.$langs->trans("PhotoFile").'
'; + } + print '
'.$form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0).''; + $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, '', 0, '', '', 0, 1); + $arrayselected = GETPOST('commercial', 'array'); + if (empty($arrayselected)) $arrayselected = $object->getSalesRepresentatives($user, 1); + print $form->multiselectarray('commercial', $userlist, $arrayselected, null, null, null, null, "90%"); + print '
'; + print '
'; - dol_fiche_end(); + dol_fiche_end(); - print '
'; - print ''; - print '     '; - print ''; + print '
'; + print ''; + print '     '; + print ''; print '
'; print ''; } } - else dol_print_error($db); -} - -if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) -{ - $res = $object->fetch_optionals(); - - $head = establishment_prepare_head($object); - dol_fiche_head($head, 'card', $langs->trans("Establishment"), -1, 'building'); - - // Confirmation to delete - if ($action == 'delete') + else { - print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("DeleteEstablishment"), $langs->trans("ConfirmDeleteEstablishment"), "confirm_delete"); + /* + * View + */ + + if (!empty($object->id)) $res=$object->fetch_optionals(); + //if ($res < 0) { dol_print_error($db); exit; } + + + $head = societe_prepare_head($object); + + dol_fiche_head($head, 'card', $langs->trans("ThirdParty"), -1, 'company'); + + // Confirm delete third party + if ($action == 'delete' || ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))) + { + print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("DeleteACompany"), $langs->trans("ConfirmDeleteCompany"), "confirm_delete", '', 0, "action-delete"); + } + + if ($action == 'merge') + { + $formquestion = array( + array( + 'name' => 'soc_origin', + 'label' => $langs->trans('MergeOriginThirdparty'), + 'type' => 'other', + 'value' => $form->select_company('', 'soc_origin', 's.rowid != '.$object->id, 'SelectThirdParty', 0, 0, array(), 0, 'minwidth200') + ) + ); + + print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("MergeThirdparties"), $langs->trans("ConfirmMergeThirdparties"), "confirm_merge", $formquestion, 'no', 1, 250); + } + + dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error'); + + $linkback = ''.$langs->trans("BackToList").''; + + dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); + + + print '
'; + print '
'; + + print '
'; + print ''; + + // Prospect/Customer + print ''; + + // Supplier + if (! empty($conf->fournisseur->enabled) || ! empty($conf->supplier_proposal->enabled)) + { + print ''; + } + + // Prefix + if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field + { + print ''; + print $htmllogobar; $htmllogobar=''; + print ''; + } + + // Customer code + if ($object->client) + { + print ''; + print $htmllogobar; $htmllogobar=''; + print ''; + } + + // Supplier code + if (! empty($conf->fournisseur->enabled) && $object->fournisseur && ! empty($user->rights->fournisseur->lire)) + { + print ''; + print $htmllogobar; $htmllogobar=''; + print ''; + } + + // Barcode + if (! empty($conf->barcode->enabled)) + { + print ''; + if ($htmllogobar) $htmllogobar.=$form->showbarcode($object); + print $htmllogobar; + $htmllogobar=''; + print ''; + } + + // Prof ids + $i=1; $j=0; + while ($i <= 6) + { + $idprof=$langs->transcountry('ProfId'.$i, $object->country_code); + if ($idprof!='-') + { + //if (($j % 2) == 0) print ''; + print ''; + print ''; + //if (($j % 2) == 1) print ''; + print ''; + $j++; + } + $i++; + } + //if ($j % 2 == 1) print ''; + + + // 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. + // We don't need them into customer profile. + // Except for spain and localtax where localtax depends on buyer and not seller + + if ($object->fournisseur) + { + // VAT is used + print ''; + print ''; + } + + // Local Taxes + if ($object->fournisseur || $mysoc->country_code=='ES') + { + if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1") + { + print ''; + + if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1))) + { + print ''; + print ''; + print ''; + print ''; + if($action == 'editRE') + { + print ''; + } + else + { + print ''; + } + print ''; + } + if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2))) + { + print ''; + print ''; + print ''; + print ''; + if($action == 'editIRPF'){ + print ''; + }else{ + print ''; + } + print ''; + } + } + elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1") + { + print ''; + if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1))) + { + print ''; + print ''; + print ''; + print ''; + if($action == 'editRE'){ + print ''; + }else{ + print ''; + } + print ''; + } + } + elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1") + { + print ''; + if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2))) + { + + print ''; + print ''; + print ''; + print ''; + if($action == 'editIRPF'){ + print ''; + }else{ + print ''; + } + print ''; + } + } + } + + // Sale tax code (VAT code) + print ''; + print ''; + print ''; + + // Type + Staff + $arr = $formcompany->typent_array(1); + $object->typent= $arr[$object->typent_code]; + print ''; + print ''; + + print '
'.$langs->trans('ProspectCustomer').''; + print $object->getLibCustProspStatut(); + print '
'.$langs->trans('Supplier').''; + print yn($object->fournisseur); + print '
'.$langs->trans('Prefix').''.$object->prefix_comm.'
'; + print $langs->trans('CustomerCode').''; + print $object->code_client; + if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')'; + print '
'; + print $langs->trans('SupplierCode').''; + print $object->code_fournisseur; + if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')'; + print '
'; + print $langs->trans('Gencod').''.$object->barcode; + print '
'.$idprof.''; + $key='idprof'.$i; + print $object->$key; + if ($object->$key) + { + if ($object->id_prof_check($i, $object) > 0) print '   '.$object->id_prof_url($i, $object); + else print ' ('.$langs->trans("ErrorWrongValue").')'; + } + print '
'; + print $form->textwithpicto($langs->trans('VATIsUsed'), $langs->trans('VATIsUsedWhenSelling')); + print ''; + print yn($object->tva_assuj); + print '
'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).''; + print yn($object->localtax1_assuj); + print '
'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).''; + print yn($object->localtax2_assuj); + print '
'.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).' id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).''; + $formcompany->select_localtax(1, $object->localtax1_value, "lt1"); + print ''.$object->localtax1_value.'
'.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).'id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).''; + $formcompany->select_localtax(2, $object->localtax2_value, "lt2"); + print ''.$object->localtax2_value.'
'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).''; + print yn($object->localtax1_assuj); + print '
'.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).'id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).''; + $formcompany->select_localtax(1, $object->localtax1_value, "lt1"); + print ''.$object->localtax1_value.'
'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).''; + print yn($object->localtax2_assuj); + print '
'.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).' id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).''; + $formcompany->select_localtax(2, $object->localtax2_value, "lt2"); + print ''.$object->localtax2_value.'
'.$langs->trans('VATIntra').''; + if ($object->tva_intra) + { + $s=''; + $s.=$object->tva_intra; + $s.=''; + + if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object)) + { + $s.='   '; + + if ($conf->use_javascript_ajax) + { + print "\n"; + print ''; + print "\n"; + $s.=''.$langs->trans("VATIntraCheck").''; + $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->trans("VATIntraCheck")), 1); + } + else + { + $s.='country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').''; + } + } + print $s; + } + else + { + print ' '; + } + print '
'.$langs->trans("ThirdPartyType").''.$object->typent.'
'.$langs->trans("Staff").''.$object->effectif.'
'; + + print '
'; + print '
'; + + print '
'; + print ''; + + // Tags / categories + if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) + { + // Customer + if ($object->prospect || $object->client || (! $object->fournisseur && ! empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER))) { + print ''; + print '"; + } + + // Supplier + if ($object->fournisseur) { + print ''; + print '"; + } + } + + // Legal + print ''; + + // Capital + print ''; + + // Default language + if (! empty($conf->global->MAIN_MULTILANGS)) + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + print ''; + } + + // Incoterms + if (!empty($conf->incoterm->enabled)) + { + print ''; + print ''; + } + + // Multicurrency + if (! empty($conf->multicurrency->enabled)) + { + print ''; + print ''; + print ''; + } + + // Other attributes + $parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3'); + include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; + + // Parent company + if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY)) + { + // Payment term + print ''; + print ''; + } + + // Sales representative + include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php'; + + // Module Adherent + if (! empty($conf->adherent->enabled)) + { + $langs->load("members"); + print ''; + print ''; + print "\n"; + } + + // Webservices url/key + if (!empty($conf->syncsupplierwebservices->enabled)) { + print ''; + print ''; + } + + print '
' . $langs->trans("CustomersCategoriesShort") . ''; + print $form->showCategories($object->id, 'customer', 1); + print "
' . $langs->trans("SuppliersCategoriesShort") . ''; + print $form->showCategories($object->id, 'supplier', 1); + print "
'.$langs->trans('JuridicalStatus').''.$object->forme_juridique.'
'.$langs->trans('Capital').''; + if ($object->capital) print price($object->capital, '', $langs, 0, -1, -1, $conf->currency); + else print ' '; + print '
'.$langs->trans("DefaultLang").''; + //$s=picto_from_langcode($object->default_lang); + //print ($s?$s.' ':''); + $langs->load("languages"); + $labellang = ($object->default_lang?$langs->trans('Language_'.$object->default_lang):''); + print $labellang; + print '
'; + print '
'; + print $langs->trans('IncotermLabel'); + print ''; + if ($user->rights->societe->creer) print ''.img_edit('', 1).''; + else print ' '; + print '
'; + print '
'; + if ($action != 'editincoterm') + { + print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1); + } + else + { + print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?socid='.$object->id); + } + print '
'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).''; + print !empty($object->multicurrency_code) ? currency_name($object->multicurrency_code, 1) : ''; + print '
'; + print ''; + if ($action != 'editparentcompany') print ''; + print '
'; + print $langs->trans('ParentCompany'); + print 'id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'
'; + print '
'; + if ($action == 'editparentcompany') + { + $form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->parent, 'editparentcompany', 's.rowid <> '.$object->id, 1); + } + else + { + $form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->parent, 'none', 's.rowid <> '.$object->id, 1); + } + print '
'.$langs->trans("LinkedToDolibarrMember").''; + $adh=new Adherent($db); + $result=$adh->fetch('', '', $object->id); + if ($result > 0) + { + $adh->ref=$adh->getFullName($langs); + print $adh->getNomUrl(1); + } + else + { + print ''.$langs->trans("ThirdpartyNotLinkedToMember").''; + } + print '
'.$langs->trans("WebServiceURL").''.dol_print_url($object->webservices_url).''.$langs->trans('WebServiceKey').''.$object->webservices_key.'
'; + print '
'; + + print '
'; + print '
'; + + dol_fiche_end(); + + + /* + * Actions + */ + if ($action != 'presend') + { + print '
'."\n"; + + $parameters=array(); + $reshook=$hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if (empty($reshook)) + { + $at_least_one_email_contact = false; + $TContact = $object->contact_array_objects(); + foreach ($TContact as &$contact) + { + if (!empty($contact->email)) + { + $at_least_one_email_contact = true; + break; + } + } + + if (! empty($object->email) || $at_least_one_email_contact) + { + $langs->load("mails"); + print ''; + } + else + { + $langs->load("mails"); + print ''; + } + + if ($user->rights->societe->creer) + { + print ''."\n"; + } + + if ($user->rights->societe->supprimer) + { + print ''; + } + + if ($user->rights->societe->supprimer) + { + if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)) // We can't use preloaded confirm form with jmobile + { + print '
'.$langs->trans('Delete').'
'."\n"; + } + else + { + print ''."\n"; + } + } + } + + print '
'."\n"; + } + + //Select mail models is same action as presend + if (GETPOST('modelselected')) { + $action = 'presend'; + } + + if ($action != 'presend') + { + print '
'; + + if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC)) + { + print ''; // ancre + + /* + * Documents generes + */ + $filedir=$conf->societe->multidir_output[$object->entity].'/'.$object->id; + $urlsource=$_SERVER["PHP_SELF"]."?socid=".$object->id; + $genallowed=$user->rights->societe->lire; + $delallowed=$user->rights->societe->creer; + + print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang); + } + + // Subsidiaries list + if (empty($conf->global->SOCIETE_DISABLE_SUBSIDIARIES)) + { + $result=show_subsidiaries($conf, $langs, $db, $object); + } + + print '
'; + + $MAXEVENT = 10; + + $morehtmlright = ''; + $morehtmlright.= $langs->trans("SeeAll"); + $morehtmlright.= ''; + + // List of actions on element + include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; + $formactions = new FormActions($db); + $somethingshown = $formactions->showactions($object, '', $socid, 1, '', $MAXEVENT, '', $morehtmlright); // Show all action for thirdparty + + print '
'; + + if (! empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD)) + { + // Contacts list + if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) + { + $result=show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id); + } + + // Addresses list + if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT)) + { + $result=show_addresses($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id); + } + } + } + + // Presend form + $modelmail='thirdparty'; + $defaulttopic='Information'; + $diroutput = $conf->societe->dir_output; + $trackid = 'thi'.$object->id; + + include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; } - - - // Object card - // ------------------------------------------------------------ - - $linkback = '' . $langs->trans("BackToList") . ''; - - $morehtmlref='
'; - $morehtmlref.='
'; - - dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', $morehtmlref); - - - print '
'; - //print '
'; - print '
'; - print ''."\n"; - - // Name - print ''; - print ''; - print ''; - print ''; - - // Address - print ''; - print ''; - print ''; - print ''; - - // Zipcode - print ''; - print ''; - print ''; - print ''; - - // Town - print ''; - print ''; - print ''; - print ''; - - // Country - print ''; - print ''; - print ''; - print ''; - - print '
'.$langs->trans("Name").''.$object->name.'
'.$langs->trans("Address").''.$object->address.'
'.$langs->trans("Zipcode").''.$object->zip.'
'.$langs->trans("Town").''.$object->town.'
'.$langs->trans("Country").''; - if ($object->country_id > 0) - { - $img=picto_from_langcode($object->country_code); - print $img?$img.' ':''; - print getCountry($object->getCountryCode(), 0, $db); - } - print '
'; - print '
'; - - print '

'; - - dol_fiche_end(); - - /* - * Barre d'actions - */ - - print '
'; - print ''.$langs->trans('Modify').''; - print ''.$langs->trans('Delete').''; - print '
'; } // End of page From 0e7ed6d1696998505d385d35e5ddc82d36d24d43 Mon Sep 17 00:00:00 2001 From: wdammak <26695620+wdammak@users.noreply.github.com> Date: Tue, 26 Feb 2019 18:45:53 +0100 Subject: [PATCH 09/23] Add parent company --- htdocs/hrm/class/establishment.class.php | 64 +++++++++++++++++++++++- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/htdocs/hrm/class/establishment.class.php b/htdocs/hrm/class/establishment.class.php index 5759d567761..ec579132f44 100644 --- a/htdocs/hrm/class/establishment.class.php +++ b/htdocs/hrm/class/establishment.class.php @@ -208,6 +208,7 @@ class Establishment extends CommonObject $sql .= ", fk_country = ".($this->country_id > 0 ? $this->country_id : 'null'); $sql .= ", status = ".$this->db->escape($this->status); $sql .= ", fk_user_mod = " . $user->id; + $sql .= ", entity = " . $this->entity; $sql .= " WHERE rowid = ".$this->id; dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG); @@ -230,7 +231,7 @@ class Establishment extends CommonObject */ function fetch($id) { - $sql = "SELECT e.rowid, e.name, e.address, e.zip, e.town, e.status, e.fk_country as country_id,"; + $sql = "SELECT e.rowid, e.name, e.address, e.zip, e.town, e.status, e.fk_country as country_id, e.entity,"; $sql.= ' c.code as country_code, c.label as country'; $sql.= " FROM ".MAIN_DB_PREFIX."establishment as e"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON e.fk_country = c.rowid'; @@ -249,6 +250,7 @@ class Establishment extends CommonObject $this->zip = $obj->zip; $this->town = $obj->town; $this->status = $obj->status; + $this->entity = $obj->entity; $this->country_id = $obj->country_id; $this->country_code = $obj->country_code; @@ -352,7 +354,7 @@ class Establishment extends CommonObject */ function info($id) { - $sql = 'SELECT e.rowid, e.datec, e.fk_user_author, e.tms, e.fk_user_mod'; + $sql = 'SELECT e.rowid, e.datec, e.fk_user_author, e.tms, e.fk_user_mod, e.entity'; $sql.= ' FROM '.MAIN_DB_PREFIX.'establishment as e'; $sql.= ' WHERE e.rowid = '.$id; @@ -389,6 +391,37 @@ class Establishment extends CommonObject dol_print_error($this->db); } } + + /** + * Get on record Establishment + * + * @param int $id Id of record + * @return obj + */ + function getEstablishment($id) + { + $sql = 'SELECT e.rowid, e.name, e.datec, e.fk_user_author, e.tms, e.fk_user_mod, e.entity'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'establishment as e'; + $sql.= ' WHERE e.rowid = '.$id; + + dol_syslog(get_class($this)."::fetch info", LOG_DEBUG); + $result = $this->db->query($sql); + + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + } + $this->db->free($result); + } + else + { + dol_print_error($this->db); + } + + return $obj; + } /** * Return clicable name (with picto eventually) @@ -414,6 +447,33 @@ class Establishment extends CommonObject if ($withpicto != 2) $result.=$link.$this->name.$linkend; return $result; } + + /** + * Return clicable name (with picto eventually) + * + * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto + * @return string String with URL + */ + function getNomUrlParent($id = 0, $withpicto = 0) + { + global $langs; + + $result=''; + + $obj = $this->getEstablishment(($id>0)?$id:$conf->entity); + + $link = ''; + $linkend=''; + + $picto='building'; + + $label=$langs->trans("Show").': '.$obj->name; + + if ($withpicto) $result.=($link.img_object($label, $picto).$linkend); + if ($withpicto && $withpicto != 2) $result.=' '; + if ($withpicto != 2) $result.=$link.$obj->name.$linkend; + return $result; + } /** * Return account country code From a706710f44f945c1e8c736f801fac2e6dbc32523 Mon Sep 17 00:00:00 2001 From: wdammak <26695620+wdammak@users.noreply.github.com> Date: Tue, 26 Feb 2019 18:46:30 +0100 Subject: [PATCH 10/23] Add parent company --- htdocs/hrm/admin/admin_establishment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/hrm/admin/admin_establishment.php b/htdocs/hrm/admin/admin_establishment.php index 4ea0b76a9d4..ee2f69a6d39 100644 --- a/htdocs/hrm/admin/admin_establishment.php +++ b/htdocs/hrm/admin/admin_establishment.php @@ -78,7 +78,7 @@ dol_fiche_head($head, 'establishments', $langs->trans("HRM"), -1, "user"); $sql = "SELECT e.rowid, e.name, e.address, e.zip, e.town, e.status"; $sql.= " FROM ".MAIN_DB_PREFIX."establishment as e"; -$sql.= " WHERE e.entity = ".$conf->entity; +$sql.= " WHERE 1 = 1"; $sql.= $db->order($sortfield, $sortorder); $sql.= $db->plimit($limit+1, $offset); From 672c7f8b1912202322c1fffa803766938293b10c Mon Sep 17 00:00:00 2001 From: wdammak <26695620+wdammak@users.noreply.github.com> Date: Tue, 26 Feb 2019 22:31:07 +0100 Subject: [PATCH 11/23] Fix phpcs --- htdocs/hrm/class/establishment.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/hrm/class/establishment.class.php b/htdocs/hrm/class/establishment.class.php index ec579132f44..467201940ce 100644 --- a/htdocs/hrm/class/establishment.class.php +++ b/htdocs/hrm/class/establishment.class.php @@ -451,6 +451,7 @@ class Establishment extends CommonObject /** * Return clicable name (with picto eventually) * + * @param int $id Id of record * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto * @return string String with URL */ From 0a28d062133f21ed47352383c27a088aef98e202 Mon Sep 17 00:00:00 2001 From: wdammak <26695620+wdammak@users.noreply.github.com> Date: Tue, 26 Feb 2019 22:36:53 +0100 Subject: [PATCH 12/23] Add parent company --- htdocs/hrm/establishment/card.php | 3018 ++++------------------------- 1 file changed, 362 insertions(+), 2656 deletions(-) diff --git a/htdocs/hrm/establishment/card.php b/htdocs/hrm/establishment/card.php index 69f3f9b880d..af242515a24 100644 --- a/htdocs/hrm/establishment/card.php +++ b/htdocs/hrm/establishment/card.php @@ -1,18 +1,5 @@ - * Copyright (C) 2003 Brian Fraval - * Copyright (C) 2004-2015 Laurent Destailleur - * Copyright (C) 2005 Eric Seigne - * Copyright (C) 2005-2017 Regis Houssin - * Copyright (C) 2008 Patrick Raguin - * Copyright (C) 2010-2016 Juanjo Menent - * Copyright (C) 2011-2013 Alexandre Spangaro - * Copyright (C) 2015 Jean-François Ferry - * Copyright (C) 2015 Marcos García - * Copyright (C) 2015 Raphaël Doursenaud - * Copyright (C) 2018 Nicolas ZABOURI - * Copyright (C) 2018 Ferran Marcet - * Copyright (C) 2018 Frédéric France +/* Copyright (C) 2015 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,2704 +16,423 @@ */ /** - * \file htdocs/societe/card.php - * \ingroup societe - * \brief Third party card page + * \file htdocs/hrm/establishment/card.php + * \brief Page to show an establishment */ - -require '../main.inc.php'; +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/hrm.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/hrm/class/establishment.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; -require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; -require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; -if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; -$langs->loadLangs(array("companies","commercial","bills","banks","users")); -if (! empty($conf->categorie->enabled)) $langs->load("categories"); -if (! empty($conf->incoterm->enabled)) $langs->load("incoterm"); -if (! empty($conf->notification->enabled)) $langs->load("mails"); - -$mesg=''; $error=0; $errors=array(); - -$action = (GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'); -$cancel = GETPOST('cancel', 'alpha'); -$backtopage = GETPOST('backtopage', 'alpha'); -$confirm = GETPOST('confirm', 'alpha'); - -$socid = GETPOST('socid', 'int')?GETPOST('socid', 'int'):GETPOST('id', 'int'); -if ($user->societe_id) $socid=$user->societe_id; -if (empty($socid) && $action == 'view') $action='create'; - -$object = new Societe($db); -$extrafields = new ExtraFields($db); - -// fetch optionals attributes and labels -$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); - -// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context -$hookmanager->initHooks(array('thirdpartycard','globalcard')); - -if ($socid > 0) $object->fetch($socid); - -if (! ($object->id > 0) && $action == 'view') -{ - $langs->load("errors"); - print($langs->trans('ErrorRecordNotFound')); - exit; -} - -// Get object canvas (By default, this is not defined, so standard usage of dolibarr) -$object->getCanvas($socid); -$canvas = $object->canvas?$object->canvas:GETPOST("canvas"); -$objcanvas=null; -if (! empty($canvas)) -{ - require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php'; - $objcanvas = new Canvas($db, $action); - $objcanvas->getCanvas('thirdparty', 'card', $canvas); -} +// Load translation files required by the page +$langs->loadLangs(array('admin', 'hrm')); // Security check -$result = restrictedArea($user, 'societe', $socid, '&societe', '', 'fk_soc', 'rowid', $objcanvas); +if (! $user->admin) accessforbidden(); + +$error=0; + +$action = GETPOST('action', 'alpha'); +$cancel = GETPOST('cancel', 'alpha'); +$confirm = GETPOST('confirm', 'alpha'); +$id = GETPOST('id', 'int'); + +// List of status +static $tmpstatus2label=array( + '0'=>'CloseEtablishment', + '1'=>'OpenEtablishment' +); +$status2label=array(''); +foreach ($tmpstatus2label as $key => $val) $status2label[$key]=$langs->trans($val); + +$object = new Establishment($db); + +// Load object +include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once /* * Actions */ -$parameters=array('id'=>$socid, 'objcanvas'=>$objcanvas); -$reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - -if (empty($reshook)) +if ($action == 'confirm_delete' && $confirm == "yes") { - if ($cancel) + $result=$object->delete($id); + if ($result >= 0) { - $action=''; - if (! empty($backtopage)) - { - header("Location: ".$backtopage); - exit; - } + header("Location: ../admin/admin_establishment.php"); + exit; } - - if ($action == 'confirm_merge' && $confirm == 'yes' && $user->rights->societe->creer) - { - $error = 0; - $soc_origin_id = GETPOST('soc_origin', 'int'); - $soc_origin = new Societe($db); - - if ($soc_origin_id <= 0) - { - $langs->load('errors'); - $langs->load('companies'); - setEventMessages($langs->trans('ErrorThirdPartyIdIsMandatory', $langs->trans('MergeOriginThirdparty')), null, 'errors'); - } - else - { - if (!$error && $soc_origin->fetch($soc_origin_id) < 1) - { - setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors'); - $error++; - } - - if (!$error) - { - // TODO Move the merge function into class of object. - - $db->begin(); - - // Recopy some data - $object->client = $object->client | $soc_origin->client; - $object->fournisseur = $object->fournisseur | $soc_origin->fournisseur; - $listofproperties=array( - 'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'skype', 'twitter', 'facebook', 'url', 'barcode', - 'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6', - 'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'remise_supplier_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis', - 'stcomm_id', 'outstanding_limit', 'price_level', 'parent', 'default_lang', 'ref', 'ref_ext', 'import_key', 'fk_incoterms', 'fk_multicurrency', - 'code_client', 'code_fournisseur', 'code_compta', 'code_compta_fournisseur', - 'model_pdf', 'fk_projet' - ); - foreach ($listofproperties as $property) - { - if (empty($object->$property)) $object->$property = $soc_origin->$property; - } - - // Concat some data - $listofproperties=array( - 'note_public', 'note_private' - ); - foreach ($listofproperties as $property) - { - $object->$property = dol_concatdesc($object->$property, $soc_origin->$property); - } - - // Merge extrafields - if (is_array($soc_origin->array_options)) - { - foreach ($soc_origin->array_options as $key => $val) - { - if (empty($object->array_options[$key])) $object->array_options[$key] = $val; - } - } - - // Merge categories - $static_cat = new Categorie($db); - - $custcats_ori = $static_cat->containing($soc_origin->id, 'customer', 'id'); - $custcats = $static_cat->containing($object->id, 'customer', 'id'); - $custcats = array_merge($custcats, $custcats_ori); - $object->setCategories($custcats, 'customer'); - - $suppcats_ori = $static_cat->containing($soc_origin->id, 'supplier', 'id'); - $suppcats = $static_cat->containing($object->id, 'supplier', 'id'); - $suppcats = array_merge($suppcats, $suppcats_ori); - $object->setCategories($suppcats, 'supplier'); - - // If thirdparty has a new code that is same than origin, we clean origin code to avoid duplicate key from database unique keys. - if ($soc_origin->code_client == $object->code_client - || $soc_origin->code_fournisseur == $object->code_fournisseur - || $soc_origin->barcode == $object->barcode) - { - dol_syslog("We clean customer and supplier code so we will be able to make the update of target"); - $soc_origin->code_client = ''; - $soc_origin->code_fournisseur = ''; - $soc_origin->barcode = ''; - $soc_origin->update($soc_origin->id, $user, 0, 1, 1, 'merge'); - } - - // Update - $object->update($object->id, $user, 0, 1, 1, 'merge'); - if ($result < 0) - { - $error++; - } - - // Move links - if (! $error) - { - $objects = array( - 'Adherent' => '/adherents/class/adherent.class.php', - 'Societe' => '/societe/class/societe.class.php', - //'Categorie' => '/categories/class/categorie.class.php', - 'ActionComm' => '/comm/action/class/actioncomm.class.php', - 'Propal' => '/comm/propal/class/propal.class.php', - 'Commande' => '/commande/class/commande.class.php', - 'Facture' => '/compta/facture/class/facture.class.php', - 'FactureRec' => '/compta/facture/class/facture-rec.class.php', - 'LignePrelevement' => '/compta/prelevement/class/ligneprelevement.class.php', - 'Contact' => '/contact/class/contact.class.php', - 'Contrat' => '/contrat/class/contrat.class.php', - 'Expedition' => '/expedition/class/expedition.class.php', - 'Fichinter' => '/fichinter/class/fichinter.class.php', - 'CommandeFournisseur' => '/fourn/class/fournisseur.commande.class.php', - 'FactureFournisseur' => '/fourn/class/fournisseur.facture.class.php', - 'SupplierProposal' => '/supplier_proposal/class/supplier_proposal.class.php', - 'ProductFournisseur' => '/fourn/class/fournisseur.product.class.php', - 'Livraison' => '/livraison/class/livraison.class.php', - 'Product' => '/product/class/product.class.php', - 'Project' => '/projet/class/project.class.php', - 'User' => '/user/class/user.class.php', - ); - - //First, all core objects must update their tables - foreach ($objects as $object_name => $object_file) - { - require_once DOL_DOCUMENT_ROOT.$object_file; - - if (!$error && !$object_name::replaceThirdparty($db, $soc_origin->id, $object->id)) - { - $error++; - setEventMessages($db->lasterror(), null, 'errors'); - } - } - } - - // External modules should update their ones too - if (! $error) - { - $reshook = $hookmanager->executeHooks('replaceThirdparty', array( - 'soc_origin' => $soc_origin->id, - 'soc_dest' => $object->id - ), $soc_dest, $action); - - if ($reshook < 0) - { - setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - $error++; - } - } - - - if (! $error) - { - $object->context=array('merge'=>1, 'mergefromid'=>$soc_origin->id); - - // Call trigger - $result=$object->call_trigger('COMPANY_MODIFY', $user); - if ($result < 0) - { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - } - // End call triggers - } - - if (!$error) - { - //We finally remove the old thirdparty - if ($soc_origin->delete($soc_origin->id, $user) < 1) - { - $error++; - } - } - - if (!$error) - { - setEventMessages($langs->trans('ThirdpartiesMergeSuccess'), null, 'mesgs'); - $db->commit(); - } - else - { - $langs->load("errors"); - setEventMessages($langs->trans('ErrorsThirdpartyMerge'), null, 'errors'); - $db->rollback(); - } - } - } - } - - if (GETPOST('getcustomercode')) + else { - // We defined value code_client - $_POST["customer_code"]="Acompleter"; + setEventMessages($object->error, $object->errors, 'errors'); } - - if (GETPOST('getsuppliercode')) - { - // We defined value code_fournisseur - $_POST["supplier_code"]="Acompleter"; - } - - if($action=='set_localtax1') - { - //obtidre selected del combobox - $value=GETPOST('lt1'); - $object->fetch($socid); - $res=$object->setValueFrom('localtax1_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY'); - } - if($action=='set_localtax2') - { - //obtidre selected del combobox - $value=GETPOST('lt2'); - $object->fetch($socid); - $res=$object->setValueFrom('localtax2_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY'); - } - - if ($action == 'update_extras') { - $object->fetch($socid); - - $object->oldcopy = dol_clone($object); - - // Fill array 'array_options' with data from update form - $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); - $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute', 'none')); - if ($ret < 0) $error++; - - if (! $error) - { - $result = $object->insertExtraFields('COMPANY_MODIFY'); - if ($result < 0) - { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - } - } - - if ($error) $action = 'edit_extras'; - } - - // Add new or update third party - if ((! GETPOST('getcustomercode') && ! GETPOST('getsuppliercode')) - && ($action == 'add' || $action == 'update') && $user->rights->societe->creer) - { - require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - - if (! GETPOST('name')) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdPartyName")), null, 'errors'); - $error++; - } - if (GETPOST('client') < 0) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProspectCustomer")), null, 'errors'); - $error++; - } - if (GETPOST('fournisseur') < 0) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Supplier")), null, 'errors'); - $error++; - } - - if (! $error) - { - if ($action == 'update') - { - $ret=$object->fetch($socid); - $object->oldcopy = clone $object; - } - else $object->canvas=$canvas; - - if (GETPOST("private") == 1) // Ask to create a contact - { - $object->particulier = GETPOST("private"); - - $object->name = dolGetFirstLastname(GETPOST('firstname', 'alpha'), GETPOST('name', 'alpha')); - $object->civility_id = GETPOST('civility_id'); // Note: civility id is a code, not an int - // Add non official properties - $object->name_bis = GETPOST('name', 'alpha'); - $object->firstname = GETPOST('firstname', 'alpha'); - } - else - { - $object->name = GETPOST('name', 'alpha'); - } - $object->entity = (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity); - $object->name_alias = GETPOST('name_alias'); - $object->address = GETPOST('address'); - $object->zip = GETPOST('zipcode', 'alpha'); - $object->town = GETPOST('town', 'alpha'); - $object->country_id = GETPOST('country_id', 'int'); - $object->state_id = GETPOST('state_id', 'int'); - $object->skype = GETPOST('skype', 'alpha'); - $object->twitter = GETPOST('twitter', 'alpha'); - $object->facebook = GETPOST('facebook', 'alpha'); - $object->phone = GETPOST('phone', 'alpha'); - $object->fax = GETPOST('fax', 'alpha'); - $object->email = trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL)); - $object->url = trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL)); - $object->idprof1 = trim(GETPOST('idprof1', 'alpha')); - $object->idprof2 = trim(GETPOST('idprof2', 'alpha')); - $object->idprof3 = trim(GETPOST('idprof3', 'alpha')); - $object->idprof4 = trim(GETPOST('idprof4', 'alpha')); - $object->idprof5 = trim(GETPOST('idprof5', 'alpha')); - $object->idprof6 = trim(GETPOST('idprof6', 'alpha')); - $object->prefix_comm = GETPOST('prefix_comm', 'alpha'); - $object->code_client = GETPOSTISSET('customer_code')?GETPOST('customer_code', 'alpha'):GETPOST('code_client', 'alpha'); - $object->code_fournisseur = GETPOSTISSET('supplier_code')?GETPOST('supplier_code', 'alpha'):GETPOST('code_fournisseur', 'alpha'); - $object->capital = GETPOST('capital', 'alpha'); - $object->barcode = GETPOST('barcode', 'alpha'); - - $object->tva_intra = GETPOST('tva_intra', 'alpha'); - $object->tva_assuj = GETPOST('assujtva_value', 'alpha'); - $object->status = GETPOST('status', 'alpha'); - - // Local Taxes - $object->localtax1_assuj = GETPOST('localtax1assuj_value', 'alpha'); - $object->localtax2_assuj = GETPOST('localtax2assuj_value', 'alpha'); - - $object->localtax1_value = GETPOST('lt1', 'alpha'); - $object->localtax2_value = GETPOST('lt2', 'alpha'); - - $object->forme_juridique_code = GETPOST('forme_juridique_code', 'int'); - $object->effectif_id = GETPOST('effectif_id', 'int'); - $object->typent_id = GETPOST('typent_id', 'int'); - - $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 - - $object->client = GETPOST('client', 'int'); - $object->fournisseur = GETPOST('fournisseur', 'int'); - - $object->commercial_id = GETPOST('commercial_id', 'int'); - $object->default_lang = GETPOST('default_lang'); - - // Webservices url/key - $object->webservices_url = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL); - $object->webservices_key = GETPOST('webservices_key', 'san_alpha'); - - // Incoterms - if (!empty($conf->incoterm->enabled)) - { - $object->fk_incoterms = GETPOST('incoterm_id', 'int'); - $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); - } - - // Multicurrency - if (!empty($conf->multicurrency->enabled)) - { - $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha'); - } - - // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); - if ($ret < 0) - { - $error++; - } - - if (GETPOST('deletephoto')) $object->logo = ''; - elseif (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']); - - // Check parameters - if (! GETPOST('cancel', 'alpha')) - { - if (! empty($object->email) && ! isValidEMail($object->email)) - { - $langs->load("errors"); - $error++; - setEventMessages('', $langs->trans("ErrorBadEMail", $object->email), 'errors'); - } - if (! empty($object->url) && ! isValidUrl($object->url)) - { - $langs->load("errors"); - setEventMessages('', $langs->trans("ErrorBadUrl", $object->url), 'errors'); - } - if (! empty($object->webservices_url)) { - //Check if has transport, without any the soap client will give error - if (strpos($object->webservices_url, "http") === false) - { - $object->webservices_url = "http://".$object->webservices_url; - } - if (! isValidUrl($object->webservices_url)) { - $langs->load("errors"); - $error++; $errors[] = $langs->trans("ErrorBadUrl", $object->webservices_url); - } - } - - // We set country_id, country_code and country for the selected country - $object->country_id=GETPOST('country_id')!=''?GETPOST('country_id'):$mysoc->country_id; - if ($object->country_id) - { - $tmparray=getCountry($object->country_id, 'all'); - $object->country_code=$tmparray['code']; - $object->country=$tmparray['label']; - } - } - } - - if (! $error) - { - if ($action == 'add') - { - $error = 0; - - $db->begin(); - - if (empty($object->client)) $object->code_client=''; - if (empty($object->fournisseur)) $object->code_fournisseur=''; - - $result = $object->create($user); - - if ($result >= 0) - { - if ($object->particulier) - { - dol_syslog("We ask to create a contact/address too", LOG_DEBUG); - $result=$object->create_individual($user); - if ($result < 0) - { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - } - } - - // Links with users - $salesreps = GETPOST('commercial', 'array'); - $result = $object->setSalesRep($salesreps); - if ($result < 0) - { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } - - // Customer categories association - $custcats = GETPOST('custcats', 'array'); - $result = $object->setCategories($custcats, 'customer'); - if ($result < 0) - { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } - - // Supplier categories association - $suppcats = GETPOST('suppcats', 'array'); - $result = $object->setCategories($suppcats, 'supplier'); - if ($result < 0) - { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } - - // Logo/Photo save - $dir = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos/"; - $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']); - if ($file_OK) - { - if (image_format_supported($_FILES['photo']['name'])) - { - dol_mkdir($dir); - - if (@is_dir($dir)) - { - $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']); - $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1); - - if (! $result > 0) - { - $errors[] = "ErrorFailedToSaveFile"; - } - else - { - // Create thumbs - $object->addThumbs($newfile); - } - } - } - } - else - { - switch($_FILES['photo']['error']) - { - case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini - case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form - $errors[] = "ErrorFileSizeTooLarge"; - break; - case 3: //uploaded file was only partially uploaded - $errors[] = "ErrorFilePartiallyUploaded"; - break; - } - } - // Gestion du logo de la société - } - else - { - 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 - { - $duplicate_code_error = true; - $object->code_fournisseur = null; - $object->code_client = null; - } - - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - } - - if ($result >= 0 && ! $error) - { - $db->commit(); - - if (! empty($backtopage)) - { - if (preg_match('/\?/', $backtopage)) $backtopage.='&socid='.$object->id; - header("Location: ".$backtopage); - exit; - } - else - { - $url=$_SERVER["PHP_SELF"]."?socid=".$object->id; - if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $url=DOL_URL_ROOT."/comm/card.php?socid=".$object->id; - elseif ($object->fournisseur == 1) $url=DOL_URL_ROOT."/fourn/card.php?socid=".$object->id; - - header("Location: ".$url); - exit; - } - } - else - { - $db->rollback(); - $action='create'; - } - } - - if ($action == 'update') - { - $error = 0; - - if (GETPOST('cancel', 'alpha')) - { - if (! empty($backtopage)) - { - header("Location: ".$backtopage); - exit; - } - else - { - header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid); - exit; - } - } - - // To not set code if third party is not concerned. But if it had values, we keep them. - if (empty($object->client) && empty($object->oldcopy->code_client)) $object->code_client=''; - if (empty($object->fournisseur)&& empty($object->oldcopy->code_fournisseur)) $object->code_fournisseur=''; - //var_dump($object);exit; - - $result = $object->update($socid, $user, 1, $object->oldcopy->codeclient_modifiable(), $object->oldcopy->codefournisseur_modifiable(), 'update', 0); - if ($result <= 0) - { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - } - - // Links with users - $salesreps = GETPOST('commercial', 'array'); - $result = $object->setSalesRep($salesreps); - if ($result < 0) - { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } - - // Prevent thirdparty's emptying if a user hasn't rights $user->rights->categorie->lire (in such a case, post of 'custcats' is not defined) - if (! $error && !empty($user->rights->categorie->lire)) - { - // Customer categories association - $categories = GETPOST( 'custcats', 'array' ); - $result = $object->setCategories($categories, 'customer'); - if ($result < 0) - { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } - - // Supplier categories association - $categories = GETPOST('suppcats', 'array'); - $result = $object->setCategories($categories, 'supplier'); - if ($result < 0) - { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } - } - - // Logo/Photo save - $dir = $conf->societe->multidir_output[$object->entity]."/".$object->id."/logos"; - $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']); - if (GETPOST('deletephoto') && $object->logo) - { - $fileimg=$dir.'/'.$object->logo; - $dirthumbs=$dir.'/thumbs'; - dol_delete_file($fileimg); - dol_delete_dir_recursive($dirthumbs); - } - if ($file_OK) - { - if (image_format_supported($_FILES['photo']['name']) > 0) - { - dol_mkdir($dir); - - if (@is_dir($dir)) - { - $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']); - $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1); - - if (! $result > 0) - { - $errors[] = "ErrorFailedToSaveFile"; - } - else - { - // Create thumbs - $object->addThumbs($newfile); - - // Index file in database - if (! empty($conf->global->THIRDPARTY_LOGO_ALLOW_EXTERNAL_DOWNLOAD)) - { - require_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php'; - // 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 - deleteFilesIntoDatabaseIndex(dirname($newfile), '', '', 'uploaded', 1); - // now we index the uploaded logo file - addFileIntoDatabaseIndex(dirname($newfile), basename($newfile), '', 'uploaded', 1); - } - } - } - } - else - { - $errors[] = "ErrorBadImageFormat"; - } - } - else - { - switch($_FILES['photo']['error']) - { - case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini - case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form - $errors[] = "ErrorFileSizeTooLarge"; - break; - case 3: //uploaded file was only partially uploaded - $errors[] = "ErrorFilePartiallyUploaded"; - break; - } - } - // Gestion du logo de la société - - - // Update linked member - if (! $error && $object->fk_soc > 0) - { - - $sql = "UPDATE ".MAIN_DB_PREFIX."adherent"; - $sql.= " SET fk_soc = NULL WHERE fk_soc = " . $id; - if (! $object->db->query($sql)) - { - $error++; - $object->error .= $object->db->lasterror(); - setEventMessages($object->error, $object->errors, 'errors'); - } - } - - if (! $error && ! count($errors)) - { - if (! empty($backtopage)) - { - header("Location: ".$backtopage); - exit; - } - else - { - header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid); - exit; - } - } - else - { - $object->id = $socid; - $action= "edit"; - } - } - } - else - { - $action = ($action=='add'?'create':'edit'); - } - } - - // Delete third party - if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->supprimer) - { - $object->fetch($socid); - $result = $object->delete($socid, $user); - - if ($result > 0) - { - header("Location: ".DOL_URL_ROOT."/societe/list.php?restore_lastsearch_values=1&delsoc=".urlencode($object->name)); - exit; - } - else - { - $langs->load("errors"); - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - $action=''; - } - } - - // Set parent company - if ($action == 'set_thirdparty' && $user->rights->societe->creer) - { - $object->fetch($socid); - $result = $object->set_parent(GETPOST('editparentcompany', 'int')); - } - - // Set incoterm - if ($action == 'set_incoterms' && !empty($conf->incoterm->enabled)) - { - $object->fetch($socid); - $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); - } - - $id=$socid; - $object->fetch($socid); - - // Actions to send emails - $trigger_name='COMPANY_SENTBYMAIL'; - $paramname='socid'; - $mode='emailfromthirdparty'; - $trackid='thi'.$object->id; - include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; - - // Actions to build doc - $id = $socid; - $upload_dir = $conf->societe->dir_output; - $permissioncreate=$user->rights->societe->creer; - include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; } +elseif ($action == 'add') +{ + if (! $cancel) + { + $error=0; + + $object->name = GETPOST('name', 'alpha'); + if (empty($object->name)) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Name")), null, 'errors'); + $error++; + } + + if (empty($error)) + { + $object->address = GETPOST('address', 'alpha'); + $object->zip = GETPOST('zipcode', 'alpha'); + $object->town = GETPOST('town', 'alpha'); + $object->country_id = $_POST["country_id"]; + $object->status = GETPOST('status', 'int'); + $object->fk_user_author = $user->id; + $object->datec = dol_now(); + $object->entity = GETPOST('entity', 'int')>0?GETPOST('entity', 'int'):$conf->entity; + + $id = $object->create($user); + + if ($id > 0) + { + header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + else + { + $action='create'; + } + } + else + { + header("Location: ../admin/admin_establishment.php"); + exit; + } +} + +// Update record +elseif ($action == 'update') +{ + $error = 0; + + if (! $cancel) { + + $name = GETPOST('name', 'alpha'); + if (empty($name)) { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->trans('Name')), null, 'errors'); + $error ++; + } + + if (empty($error)) + { + $object->name = GETPOST('name', 'alpha'); + $object->address = GETPOST('address', 'alpha'); + $object->zip = GETPOST('zipcode', 'alpha'); + $object->town = GETPOST('town', 'alpha'); + $object->country_id = GETPOST('country_id', 'int'); + $object->fk_user_mod = $user->id; + $object->status = GETPOST('status', 'int'); + $object->entity = GETPOST('entity', 'int')>0?GETPOST('entity', 'int'):$conf->entity; + + $result = $object->update($user); + + if ($result > 0) + { + header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $_POST['id']); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } else { + header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $_POST['id']); + exit; + } +} /* - * View + * View */ +llxHeader(); + $form = new Form($db); -$formfile = new FormFile($db); -$formadmin = new FormAdmin($db); $formcompany = new FormCompany($db); -if ($socid > 0 && empty($object->id)) +/* + * Action create + */ +if ($action == 'create') { - $result=$object->fetch($socid); - if ($result <= 0) dol_print_error('', $object->error); + print load_fiche_titre($langs->trans("NewEstablishment")); + + print '
'; + print ''; + print ''; + + dol_fiche_head(); + + print ''; + + // Name + print ''; + print ''; + print ''; + print ''; + + // Parent + print ''; + print ''; + print ''; + print ''; + + // Address + print ''; + print ''; + print ''; + print ''; + + // Zipcode + print ''; + print ''; + print ''; + print ''; + + // Town + print ''; + print ''; + print ''; + print ''; + + // Country + print ''; + print ''; + print ''; + print ''; + + // Status + print ''; + print ''; + print ''; + + print '
'. $form->editfieldkey('Name', 'name', '', $object, 0, 'string', '', 1).'
'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).''; + print $form->select_establishments(GETPOST('entity', 'int')>0?GETPOST('entity', 'int'):$conf->entity, 'entity', 1); + print '
'.$form->editfieldkey('Address', 'address', '', $object, 0).''; + print ''; + print '
'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).''; + print $formcompany->select_ziptown( + GETPOST('zipcode', 'alpha'), + 'zipcode', + array ( + 'town', + 'selectcountry_id' + ), + 6 + ); + print '
'.$form->editfieldkey('Town', 'town', '', $object, 0).''; + print $formcompany->select_ziptown(GETPOST('town', 'alpha'), 'town', array ( + 'zipcode', + 'selectcountry_id' + )); + print '
'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).''; + print $form->select_country(GETPOST('country_id', 'int')>0?GETPOST('country_id', 'int'):$mysoc->country_id, 'country_id'); + if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + print '
'.$form->editfieldkey('Status', 'status', '', $object, 0, 'string', '', 1).''; + print $form->selectarray('status', $status2label, GETPOST('status', 'alpha')); + print '
'; + + dol_fiche_end(); + + print '
'; + print ''; + print '     '; + print ''; + print '
'; + + print '
'; } -$title=$langs->trans("ThirdParty"); -if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$langs->trans('Card'); -$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; -llxHeader('', $title, $help_url); - -$countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')'; - -if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) +// Part to edit record +if (($id || $ref) && $action == 'edit') { - // ----------------------------------------- - // When used with CANVAS - // ----------------------------------------- - $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates - $objcanvas->display_canvas($action); // Show template -} -else -{ - // ----------------------------------------- - // When used in standard mode - // ----------------------------------------- - if ($action == 'create') + $result = $object->fetch($id); + if ($result > 0) { - /* - * Creation - */ - $private=GETPOST("private", "int"); - if (! empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT) && ! isset($_GET['private']) && ! isset($_POST['private'])) $private=1; - if (empty($private)) $private=0; + $head = establishment_prepare_head($object); - // Load object modCodeTiers - $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard'); - if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') + if ($action == 'edit') { - $module = substr($module, 0, dol_strlen($module)-4); - } - $dirsociete=array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) - { - $res=dol_include_once($dirroot.$module.'.php'); - if ($res) break; - } - $modCodeClient = new $module; - // Load object modCodeFournisseur - $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard'); - if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') - { - $module = substr($module, 0, dol_strlen($module)-4); - } - $dirsociete=array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) - { - $res=dol_include_once($dirroot.$module.'.php'); - if ($res) break; - } - $modCodeFournisseur = new $module; + dol_fiche_head($head, 'card', $langs->trans("Establishment"), 0, 'building'); - // Define if customer/prospect or supplier status is set or not - if (GETPOST("type")!='f') - { - $object->client=-1; - if (! empty($conf->global->THIRDPARTY_CUSTOMERPROSPECT_BY_DEFAULT)) { $object->client=3; } - } - // Prospect / Customer - if (GETPOST("type")=='c') { - if (! empty($conf->global->THIRDPARTY_CUSTOMERTYPE_BY_DEFAULT)) { - $object->client=$conf->global->THIRDPARTY_CUSTOMERTYPE_BY_DEFAULT; - } else { - $object->client=3; - } - } - if (GETPOST("type")=='p') { $object->client=2; } - if (! empty($conf->fournisseur->enabled) && (GETPOST("type")=='f' || (GETPOST("type")=='' && ! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)))) { $object->fournisseur=1; } - - $object->name = GETPOST('name', 'alpha'); - $object->firstname = GETPOST('firstname', 'alpha'); - $object->particulier = $private; - $object->prefix_comm = GETPOST('prefix_comm'); - $object->client = GETPOST('client')?GETPOST('client'):$object->client; - - if(empty($duplicate_code_error)) { - $object->code_client = GETPOST('customer_code', 'alpha'); - $object->fournisseur = GETPOST('fournisseur')?GETPOST('fournisseur'):$object->fournisseur; - } - else { - setEventMessages($langs->trans('NewCustomerSupplierCodeProposed'), '', 'warnings'); - } - - $object->code_fournisseur = GETPOST('supplier_code', 'alpha'); - $object->address = GETPOST('address', 'alpha'); - $object->zip = GETPOST('zipcode', 'alpha'); - $object->town = GETPOST('town', 'alpha'); - $object->state_id = GETPOST('state_id', 'int'); - $object->skype = GETPOST('skype', 'alpha'); - $object->twitter = GETPOST('twitter', 'alpha'); - $object->facebook = GETPOST('facebook', 'alpha'); - $object->phone = GETPOST('phone', 'alpha'); - $object->fax = GETPOST('fax', 'alpha'); - $object->email = GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL); - $object->url = GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL); - $object->capital = GETPOST('capital', 'alpha'); - $object->barcode = GETPOST('barcode', 'alpha'); - $object->idprof1 = GETPOST('idprof1', 'alpha'); - $object->idprof2 = GETPOST('idprof2', 'alpha'); - $object->idprof3 = GETPOST('idprof3', 'alpha'); - $object->idprof4 = GETPOST('idprof4', 'alpha'); - $object->idprof5 = GETPOST('idprof5', 'alpha'); - $object->idprof6 = GETPOST('idprof6', 'alpha'); - $object->typent_id = GETPOST('typent_id', 'int'); - $object->effectif_id = GETPOST('effectif_id', 'int'); - $object->civility_id = GETPOST('civility_id', 'int'); - - $object->tva_assuj = GETPOST('assujtva_value', 'int'); - $object->status = GETPOST('status', 'int'); - - //Local Taxes - $object->localtax1_assuj = GETPOST('localtax1assuj_value', 'int'); - $object->localtax2_assuj = GETPOST('localtax2assuj_value', 'int'); - - $object->localtax1_value =GETPOST('lt1', 'int'); - $object->localtax2_value =GETPOST('lt2', 'int'); - - $object->tva_intra = GETPOST('tva_intra', 'alpha'); - - $object->commercial_id = GETPOST('commercial_id', 'int'); - $object->default_lang = GETPOST('default_lang'); - - $object->logo = (isset($_FILES['photo'])?dol_sanitizeFileName($_FILES['photo']['name']):''); - - // Gestion du logo de la société - $dir = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos"; - $file_OK = (isset($_FILES['photo'])?is_uploaded_file($_FILES['photo']['tmp_name']):false); - if ($file_OK) - { - if (image_format_supported($_FILES['photo']['name'])) - { - dol_mkdir($dir); - - if (@is_dir($dir)) - { - $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']); - $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1); - - if (! $result > 0) - { - $errors[] = "ErrorFailedToSaveFile"; - } - else - { - // Create thumbs - $object->addThumbs($newfile); - } - } - } - } - - // We set country_id, country_code and country for the selected country - $object->country_id=GETPOST('country_id')?GETPOST('country_id'):$mysoc->country_id; - if ($object->country_id) - { - $tmparray=getCountry($object->country_id, 'all'); - $object->country_code=$tmparray['code']; - $object->country=$tmparray['label']; - } - $object->forme_juridique_code=GETPOST('forme_juridique_code'); - /* Show create form */ - - $linkback=""; - print load_fiche_titre($langs->trans("NewThirdParty"), $linkback, 'title_companies.png'); - - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION)) - { - print "\n".''."\n"; - - print '
'; - print '
'; - print $langs->trans("ThirdPartyType").':     '; - print '
'; - print ''; - print '     '; - print ''; - print '
'; - print "
\n"; - } - - dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error'); - - print '
'; // Chrome ignor autocomplete - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) print ''; - - dol_fiche_head(null, 'card', '', 0, ''); - - print ''; - - // Name, firstname - print 'global->SOCIETE_USEPREFIX)?' colspan="3"':'').'>'; - print ''; - if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field - { - print ''; - } - print ''; - - // If javascript on, we show option individual - if ($conf->use_javascript_ajax) - { - print ''; - print ''; - print ''; - // Title - print ''; - print ''; - } - - // Alias names (commercial, trademark or alias names) - print ''; - print ''; - - // Prospect/Customer - print ''; - print ''; - - print ''; - - if ((! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire)) - || (! empty($conf->supplier_proposal->enabled) && ! empty($user->rights->supplier_proposal->lire))) - { - // Supplier - print ''; - print ''; - print ''; - } - - // Status - print ''; - - // Barcode - if (! empty($conf->barcode->enabled)) - { - print ''; - print ''; - } - - // Address - print ''; - print ''; - - // Zip / Town - print ''; - - // Country - print ''; - - // State - if (empty($conf->global->SOCIETE_DISABLE_STATE)) - { - 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)) - { - print ''; - } - - // Email / Web - print ''; - print ''; - print ''; - print ''; - - if (! empty($conf->socialnetworks->enabled)) - { - // Skype - if (! empty($conf->global->SOCIALNETWORKS_SKYPE)) - { - print ''; - print ''; - } - // Twitter - if (! empty($conf->global->SOCIALNETWORKS_TWITTER)) - { - print ''; - print ''; - } - // Facebook - if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK)) - { - print ''; - print ''; - } - } - - // Phone / Fax - print ''; - print ''; - print ''; - print ''; - - // Prof ids - $i=1; $j=0; - while ($i <= 6) - { - $idprof=$langs->transcountry('ProfId'.$i, $object->country_code); - if ($idprof!='-') - { - $key='idprof'.$i; - - if (($j % 2) == 0) print ''; - - $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY'; - print ''; - if (($j % 2) == 1) print ''; - $j++; - } - $i++; - } - if ($j % 2 == 1) print ''; - - // Vat is used - print ''; - print ''; - print ''; - print ''; - print ''; - - // Local Taxes - //TODO: Place into a function to control showing by country or study better option - if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1") - { - print ''; - } - elseif($mysoc->localtax1_assuj=="1") - { - print ''; - } - elseif($mysoc->localtax2_assuj=="1") - { - print ''; - } - - // Type - Size - print ''; - print ''; - - // Legal Form - print ''; - print ''; - - // Capital - print ''; - print ''; - - if (! empty($conf->global->MAIN_MULTILANGS)) - { - print ''; - print ''; - } - - // Incoterms - if (!empty($conf->incoterm->enabled)) - { - print ''; - print ''; - print ''; - } - - // Categories - if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) - { - $langs->load('categories'); - - // Customer - //if ($object->prospect || $object->client || (! $object->fournisseur && ! empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER))) { - print '"; - //} - - // Supplier - //if ($object->fournisseur) { - print '"; - //} - } - - // Multicurrency - if (! empty($conf->multicurrency->enabled)) - { - print ''; - print ''; - print ''; - } - - // Other attributes - $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3'); - $reshook=$hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - if (empty($reshook)) - { - print $object->showOptionals($extrafields, 'edit'); - } - - // Assign a sale representative - print ''; - print ''; - print ''; - - // Ajout du logo - print ''; - print ''; - print ''; - print ''; - - print '
'; - if ($object->particulier || $private) - { - print ''.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName', 'name').''; - } - else - { - print ''.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0).''; - } - print ''.$langs->trans('Prefix').'
'.$form->editfieldkey('FirstName', 'firstname', '', $object, 0).'
'.$form->editfieldkey('UserTitle', 'civility_id', '', $object, 0).''; - print $formcompany->select_civility($object->civility_id, 'civility_id', 'maxwidth100').'
'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).''; - $selected=GETPOST('client', 'int')!=''?GETPOST('client', 'int'):$object->client; - print $formcompany->selectProspectCustomerType($selected); - print ''.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).''; - print '
'; - $tmpcode=$object->code_client; - if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object, 0); - print ''; - print ''; - $s=$modCodeClient->getToolTip($langs, $object, 0); - print $form->textwithpicto('', $s, 1); - print '
'; - print '
'.$form->editfieldkey('Supplier', 'fournisseur', '', $object, 0, 'string', '', 1).''; - $default = -1; - if (! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)) $default=1; - print $form->selectyesno("fournisseur", (GETPOST('fournisseur', 'int')!=''?GETPOST('fournisseur', 'int'):(GETPOST("type", 'alpha') == '' ? $default : $object->fournisseur)), 1, 0, (GETPOST("type", 'alpha') == '' ? 1 : 0)); - print ''; - if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire)) - { - print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0); - } - print ''; - if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire)) - { - print '
'; - $tmpcode=$object->code_fournisseur; - if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object, 1); - print ''; - print ''; - $s=$modCodeFournisseur->getToolTip($langs, $object, 1); - print $form->textwithpicto('', $s, 1); - print '
'; - } - print '
'.$form->editfieldkey('Status', 'status', '', $object, 0).''; - print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'),'1'=>$langs->trans('InActivity')), 1); - print '
'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).''; - print '
'.$form->editfieldkey('Address', 'address', '', $object, 0).'
'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).''; - print $formcompany->select_ziptown($object->zip, 'zipcode', array('town','selectcountry_id','state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent'); - print ''.$form->editfieldkey('Town', 'town', '', $object, 0).''; - print $formcompany->select_ziptown($object->town, 'town', array('zipcode','selectcountry_id','state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent'); - print '
'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).''; - print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id)); - if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); - print '
'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).''; - } - else - { - print '
'.$form->editfieldkey('State', 'state_id', '', $object, 0).''; - } - - if ($object->country_id) print $formcompany->select_state($object->state_id, $object->country_code); - else print $countrynotdefined; - print '
'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', $conf->global->SOCIETE_EMAIL_MANDATORY).'
'.$form->editfieldkey('Web', 'url', '', $object, 0).'
'.$form->editfieldkey('Skype', 'skype', '', $object, 0).''; - print 'skype).'">'; - print '
'.$form->editfieldkey('Twitter', 'twitter', '', $object, 0).''; - print 'twitter).'">'; - print '
'.$form->editfieldkey('Facebook', 'facebook', '', $object, 0).''; - print 'facebook).'">'; - print '
'.$form->editfieldkey('Phone', 'phone', '', $object, 0).''.$form->editfieldkey('Fax', 'fax', '', $object, 0).'
'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', (empty($conf->global->$idprof_mandatory)?0:1)).''; - - print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code); - print '
'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).''; - print $form->selectyesno('assujtva_value', GETPOSTISSET('assujtva_value')?GETPOST('assujtva_value', 'int'):1, 1); // Assujeti par defaut en creation - print ''.$form->editfieldkey('VATIntra', 'intra_vat', '', $object, 0).''; - $s = ''; - - if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object)) - { - $s.=' '; - - if (! empty($conf->use_javascript_ajax)) - { - print "\n"; - print ''; - print "\n"; - $s.=''.$langs->trans("VATIntraCheck").''; - $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->trans("VATIntraCheck")), 1); - } - else - { - $s.='country_id).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').''; - } - } - print $s; - print '
'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).''; - print $form->selectyesno('localtax1assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1:0), 1); - print ''.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).''; - print $form->selectyesno('localtax2assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0), 1); - print '
'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).''; - print $form->selectyesno('localtax1assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1:0), 1); - print '
'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).''; - print $form->selectyesno('localtax2assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0), 1); - print '
'.$form->editfieldkey('ThirdPartyType', 'typent_id', '', $object, 0).''."\n"; - $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. - print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, $sortparam); - if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); - print ''.$form->editfieldkey('Staff', 'effectif_id', '', $object, 0).''; - print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id); - if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); - print '
'.$form->editfieldkey('JuridicalStatus', 'forme_juridique_code', '', $object, 0).''; - if ($object->country_id) - { - print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code'); - } - else - { - print $countrynotdefined; - } - print '
'.$form->editfieldkey('Capital', 'capital', '', $object, 0).' '; - print ''.$langs->trans("Currency".$conf->currency).'
'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).''."\n"; - print $formadmin->select_language(($object->default_lang?$object->default_lang:$conf->global->MAIN_LANG_DEFAULT), 'default_lang', 0, 0, 1, 0, 0, 'maxwidth200onsmartphone'); - print '
'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).''; - print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:'')); - print '
' . $form->editfieldkey('CustomersProspectsCategoriesShort', 'custcats', '', $object, 0) . ''; - $cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, 'parent', null, null, 1); - print $form->multiselectarray('custcats', $cate_arbo, GETPOST('custcats', 'array'), null, null, null, null, "90%"); - print "
' . $form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0) . ''; - $cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, 'parent', null, null, 1); - print $form->multiselectarray('suppcats', $cate_arbo, GETPOST('suppcats', 'array'), null, null, null, null, "90%"); - print "
'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).''; - print $form->selectMultiCurrency(($object->multicurrency_code ? $object->multicurrency_code : $conf->currency), 'multicurrency_code', 1); - print '
'.$form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0).''; - $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, '', 0, '', '', 0, 1); - // Note: If user has no right to "see all thirdparties", we for selection of sale representative to him, so after creation he can see the record. - $selected = (count(GETPOST('commercial', 'array')) > 0 ? GETPOST('commercial', 'array') : (GETPOST('commercial', 'int') > 0 ? array(GETPOST('commercial', 'int')) : (empty($user->rights->societe->client->voir)?array($user->id):array()))); - print $form->multiselectarray('commercial', $userlist, $selected, null, null, null, null, "90%"); - print '
'.$form->editfieldkey('Logo', 'photoinput', '', $object, 0).''; - print ''; - print '
'."\n"; - - dol_fiche_end(); - - print '
'; - print ''; - if (! empty($backtopage)) - { - print '     '; - print ''; - } - else - { - print '     '; - print ''; - } - print '
'."\n"; - - print '
'."\n"; - } - elseif ($action == 'edit') - { - //print load_fiche_titre($langs->trans("EditCompany")); - - if ($socid) - { - $res=$object->fetch_optionals(); - //if ($res < 0) { dol_print_error($db); exit; } - - $head = societe_prepare_head($object); - - // Load object modCodeTiers - $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard'); - if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') - { - $module = substr($module, 0, dol_strlen($module)-4); - } - $dirsociete=array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) - { - $res=dol_include_once($dirroot.$module.'.php'); - if ($res) break; - } - $modCodeClient = new $module($db); - // We verified if the tag prefix is used - if ($modCodeClient->code_auto) - { - $prefixCustomerIsUsed = $modCodeClient->verif_prefixIsUsed(); - } - $module=$conf->global->SOCIETE_CODECLIENT_ADDON; - if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') - { - $module = substr($module, 0, dol_strlen($module)-4); - } - $dirsociete=array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) - { - $res=dol_include_once($dirroot.$module.'.php'); - if ($res) break; - } - $modCodeFournisseur = new $module($db); - // On verifie si la balise prefix est utilisee - if ($modCodeFournisseur->code_auto) - { - $prefixSupplierIsUsed = $modCodeFournisseur->verif_prefixIsUsed(); - } - - $object->oldcopy = clone $object; - - if (GETPOSTISSET('name')) - { - // We overwrite with values if posted - $object->name = GETPOST('name', 'alpha'); - $object->prefix_comm = GETPOST('prefix_comm', 'alpha'); - $object->client = GETPOST('client', 'int'); - $object->code_client = GETPOST('customer_code', 'alpha'); - $object->fournisseur = GETPOST('fournisseur', 'int'); - $object->code_fournisseur = GETPOST('supplier_code', 'alpha'); - $object->address = GETPOST('address', 'alpha'); - $object->zip = GETPOST('zipcode', 'alpha'); - $object->town = GETPOST('town', 'alpha'); - $object->country_id = GETPOST('country_id')?GETPOST('country_id', 'int'):$mysoc->country_id; - $object->state_id = GETPOST('state_id', 'int'); - $object->skype = GETPOST('skype', 'alpha'); - $object->twitter = GETPOST('twitter', 'alpha'); - $object->facebook = GETPOST('facebook', 'alpha'); - $object->phone = GETPOST('phone', 'alpha'); - $object->fax = GETPOST('fax', 'alpha'); - $object->email = GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL); - $object->url = GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL); - $object->capital = GETPOST('capital', 'alpha'); - $object->idprof1 = GETPOST('idprof1', 'alpha'); - $object->idprof2 = GETPOST('idprof2', 'alpha'); - $object->idprof3 = GETPOST('idprof3', 'alpha'); - $object->idprof4 = GETPOST('idprof4', 'alpha'); - $object->idprof5 = GETPOST('idprof5', 'alpha'); - $object->idprof6 = GETPOST('idprof6', 'alpha'); - $object->typent_id = GETPOST('typent_id', 'int'); - $object->effectif_id = GETPOST('effectif_id', 'int'); - $object->barcode = GETPOST('barcode', 'alpha'); - $object->forme_juridique_code = GETPOST('forme_juridique_code', 'int'); - $object->default_lang = GETPOST('default_lang', 'alpha'); - - $object->tva_assuj = GETPOST('assujtva_value', 'int'); - $object->tva_intra = GETPOST('tva_intra', 'alpha'); - $object->status = GETPOST('status', 'int'); - - // Webservices url/key - $object->webservices_url = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL); - $object->webservices_key = GETPOST('webservices_key', 'san_alpha'); - - //Incoterms - if (!empty($conf->incoterm->enabled)) - { - $object->fk_incoterms = GETPOST('incoterm_id', 'int'); - $object->location_incoterms = GETPOST('lcoation_incoterms', 'alpha'); - } - - //Local Taxes - $object->localtax1_assuj = GETPOST('localtax1assuj_value'); - $object->localtax2_assuj = GETPOST('localtax2assuj_value'); - - $object->localtax1_value =GETPOST('lt1'); - $object->localtax2_value =GETPOST('lt2'); - - // We set country_id, and country_code label of the chosen country - if ($object->country_id > 0) - { - $tmparray=getCountry($object->country_id, 'all'); - $object->country_code = $tmparray['code']; - $object->country = $tmparray['label']; - } - } - - if($object->localtax1_assuj==0){ - $sub=0; - }else{$sub=1;} - if($object->localtax2_assuj==0){ - $sub2=0; - }else{$sub2=1;} - - if ($conf->use_javascript_ajax) - { - print "\n".''."\n"; - } - - print '
'; - print ''; + print '' . "\n"; print ''; - print ''; - print ''; - if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) print ''; + print ''; + print ''; - - dol_fiche_head($head, 'card', $langs->trans("ThirdParty"), 0, 'company'); - - print '
'; print ''; - // Ref/ID - if (! empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) - { - print ''; - } + // Ref + print ""; + print ''; // Name - print ''; - print ''; - - // Alias names (commercial, trademark or alias names) - print ''; - print ''; - - // Prefix - if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field - { - print ''; - } - - // Prospect/Customer - print ''; - print ''; - print ''; + + // Parent + print ''; + print ''; - // Supplier - if ((! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire)) - || (! empty($conf->supplier_proposal->enabled) && ! empty($user->rights->supplier_proposal->lire))) - { - print ''; - print ''; - print ''; - } + // Address + print ''; + print ''; - // Barcode - if (! empty($conf->barcode->enabled)) - { - print ''; - print ''; - } + // Zipcode / Town + print ''; + print ''; - // Status - print ''; + // Country + print ''; + print ''; + print ''; - // Address - print ''; - print ''; - - // Zip / Town - print ''; - - // Country - print ''; - - // State - if (empty($conf->global->SOCIETE_DISABLE_STATE)) - { - 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)) - { - print ''; - } - - // EMail / Web - print ''; - print ''; - print ''; - print ''; - - if (! empty($conf->socialnetworks->enabled)) - { - // Skype - if (! empty($conf->global->SOCIALNETWORKS_SKYPE)) - { - print ''; - print ''; - } - // Twitter - if (! empty($conf->global->SOCIALNETWORKS_TWITTER)) - { - print ''; - print ''; - } - // Facebook - if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK)) - { - print ''; - print ''; - } - } - - // Phone / Fax - print ''; - print ''; - print ''; - print ''; - - // Prof ids - $i=1; $j=0; - while ($i <= 6) - { - $idprof=$langs->transcountry('ProfId'.$i, $object->country_code); - if ($idprof!='-') - { - $key='idprof'.$i; - - if (($j % 2) == 0) print ''; - - $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY'; - print ''; - if (($j % 2) == 1) print ''; - $j++; - } - $i++; - } - if ($j % 2 == 1) print ''; - - // VAT is used - print ''; - - // Local Taxes - //TODO: Place into a function to control showing by country or study better option - if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1") - { - print ''; - - print ''; - } - elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1") - { - print ''; - } - elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1") - { - print ''; - } - - // VAT Code - print ''; - print ''; - print ''; - - // Type - Size - print ''; - print ''; - - // Juridical type - print ''; - - // Capital - print ''; - print ''; - - // Default language - if (! empty($conf->global->MAIN_MULTILANGS)) - { - print ''; - print ''; - } - - // Incoterms - if (!empty($conf->incoterm->enabled)) - { - print ''; - print ''; - print ''; - } - - // Categories - if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) - { - // Customer - print ''; - print '"; - - // Supplier - print ''; - print '"; - } - - // Multicurrency - if (! empty($conf->multicurrency->enabled)) - { - print ''; - print ''; - print ''; - } - - // Other attributes - $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3'); - $reshook=$hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - if (empty($reshook)) - { - print $object->showOptionals($extrafields, 'edit'); - } - - // Webservices url/key - if (!empty($conf->syncsupplierwebservices->enabled)) { - print ''; - print ''; - print ''; - print ''; - } - - // Logo - print ''; - print ''; - print ''; - print ''; - - // Assign sale representative - print ''; - print ''; - print ''; + // Status + print ''; print '
'.$langs->trans("ID").''; - print $object->ref; - print '
'.$langs->trans("Ref").''; + print $object->id; + print '
'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0, 'string', '', 1).'
'.$form->editfieldkey('Prefix', 'prefix', '', $object, 0).''; - // It does not change the prefix mode using the auto numbering prefix - if (($prefixCustomerIsUsed || $prefixSupplierIsUsed) && $object->prefix_comm) - { - print ''; - print $object->prefix_comm; - } - else - { - print ''; - } - print '
'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).''; - print $formcompany->selectProspectCustomerType($object->client); - print ''.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).''; - - print '
'; - if ((!$object->code_client || $object->code_client == -1) && $modCodeClient->code_auto) - { - $tmpcode=$object->code_client; - if (empty($tmpcode) && ! empty($object->oldcopy->code_client)) $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. - if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object, 0); - print ''; - } - elseif ($object->codeclient_modifiable()) - { - print ''; - } - else - { - print $object->code_client; - print ''; - } - print ''; - $s=$modCodeClient->getToolTip($langs, $object, 0); - print $form->textwithpicto('', $s, 1); - print '
'; - + print '
'.$form->editfieldkey('Name', 'name', '', $object, 0, 'string', '', 1).''; + print ''; + print '
'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).''; + print $form->select_establishments($object->entity>0?$object->entity:$conf->entity, 'entity', 1); print '
'.$form->editfieldkey('Supplier', 'fournisseur', '', $object, 0, 'string', '', 1).''; - print $form->selectyesno("fournisseur", $object->fournisseur, 1); - print ''; - if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire)) - { - print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0); - } - print ''; - if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire)) - { - print '
'; - if ((!$object->code_fournisseur || $object->code_fournisseur == -1) && $modCodeFournisseur->code_auto) - { - $tmpcode=$object->code_fournisseur; - if (empty($tmpcode) && ! empty($object->oldcopy->code_fournisseur)) $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. - if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object, 1); - print ''; - } - elseif ($object->codefournisseur_modifiable()) - { - print ''; - } - else - { - print $object->code_fournisseur; - print ''; - } - print ''; - $s=$modCodeFournisseur->getToolTip($langs, $object, 1); - print $form->textwithpicto('', $s, 1); - print '
'; - } - print '
'.$form->editfieldkey('Address', 'address', '', $object, 0).''; + print ''; + print '
'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).''; - print '
'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).''; + print $formcompany->select_ziptown($object->zip, 'zipcode', array ( + 'town', + 'selectcountry_id' + ), 6) . '
'.$form->editfieldkey('Town', 'town', '', $object, 0).''; + print $formcompany->select_ziptown($object->town, 'town', array ( + 'zipcode', + 'selectcountry_id' + )) . '
'.$form->editfieldkey('Status', 'status', '', $object, 0).''; - print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'),'1'=>$langs->trans('InActivity')), $object->status); - print '
'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).''; + print $form->select_country($object->fk_country, 'country_id'); + if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + print '
'.$form->editfieldkey('Address', 'address', '', $object, 0).'
'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).''; - print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth50onsmartphone'); - print ''.$form->editfieldkey('Town', 'town', '', $object, 0).''; - print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id')); - print '
'.$form->editfieldkey('Country', 'selectcounty_id', '', $object, 0).''; - print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id), 'country_id'); - if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); - print '
'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).''; - } - else - { - print '
'.$form->editfieldkey('State', 'state_id', '', $object, 0).''; - } - - print $formcompany->select_state($object->state_id, $object->country_code); - print '
'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', (! empty($conf->global->SOCIETE_EMAIL_MANDATORY))).'
'.$form->editfieldkey('Web', 'url', '', $object, 0).'
'.$form->editfieldkey('Skype', 'skype', '', $object, 0).'
'.$form->editfieldkey('Twitter', 'twitter', '', $object, 0).'
'.$form->editfieldkey('Facebook', 'facebook', '', $object, 0).'
'.$form->editfieldkey('Phone', 'phone', '', $object, 0).''.$form->editfieldkey('Fax', 'fax', '', $object, 0).'
'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', ! (empty($conf->global->$idprof_mandatory) || ! $object->isACompany())).''; - print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code); - print '
'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).''; - print $form->selectyesno('assujtva_value', $object->tva_assuj, 1); - print '
'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value', '', $object, 0).''; - print $form->selectyesno('localtax1assuj_value', $object->localtax1_assuj, 1); - if(! isOnlyOneLocalTax(1)) - { - print ' '.$langs->transcountry("Type", $mysoc->country_code).': '; - $formcompany->select_localtax(1, $object->localtax1_value, "lt1"); - print ''; - } - print ''.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value', '', $object, 0).''; - print $form->selectyesno('localtax2assuj_value', $object->localtax2_assuj, 1); - if (! isOnlyOneLocalTax(2)) - { - print ' '.$langs->transcountry("Type", $mysoc->country_code).': '; - $formcompany->select_localtax(2, $object->localtax2_value, "lt2"); - print ''; - } - print '
'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value', '', $object, 0).''; - print $form->selectyesno('localtax1assuj_value', $object->localtax1_assuj, 1); - if(! isOnlyOneLocalTax(1)) - { - print ' '.$langs->transcountry("Type", $mysoc->country_code).': '; - $formcompany->select_localtax(1, $object->localtax1_value, "lt1"); - print ''; - } - print '
'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value', '', $object, 0).''; - print $form->selectyesno('localtax2assuj_value', $object->localtax2_assuj, 1); - if(! isOnlyOneLocalTax(2)) - { - print ' '.$langs->transcountry("Type", $mysoc->country_code).': '; - $formcompany->select_localtax(2, $object->localtax2_value, "lt2"); - print ''; - } - print '
'.$form->editfieldkey('VATIntra', 'intra_vat', '', $object, 0).''; - $s =''; - - if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object)) - { - $s.='   '; - - if ($conf->use_javascript_ajax) - { - print "\n"; - print ''; - print "\n"; - $s.=''.$langs->trans("VATIntraCheck").''; - $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->trans("VATIntraCheck")), 1); - } - else - { - $s.='country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').''; - } - } - print $s; - print '
'.$form->editfieldkey('ThirdPartyType', 'typent_id', '', $object, 0).''; - print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT)); - if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); - print ''.$form->editfieldkey('Staff', 'effectif_id', '', $object, 0).''; - print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id); - if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); - print '
'.$form->editfieldkey('JuridicalStatus', 'forme_juridique_code', '', $object, 0).''; - print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code'); - print '
'.$form->editfieldkey('Capital', 'capital', '', $object, 0).' '.$langs->trans("Currency".$conf->currency).'
'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).''."\n"; - print $formadmin->select_language($object->default_lang, 'default_lang', 0, 0, 1); - print '
'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).''; - print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:'')); - print '
' . $form->editfieldkey('CustomersCategoriesShort', 'custcats', '', $object, 0) . ''; - $cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, null, null, null, 1); - $c = new Categorie($db); - $cats = $c->containing($object->id, Categorie::TYPE_CUSTOMER); - $arrayselected=array(); - foreach ($cats as $cat) { - $arrayselected[] = $cat->id; - } - print $form->multiselectarray('custcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%'); - print "
' . $form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0) . ''; - $cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, null, null, null, 1); - $c = new Categorie($db); - $cats = $c->containing($object->id, Categorie::TYPE_SUPPLIER); - $arrayselected=array(); - foreach ($cats as $cat) { - $arrayselected[] = $cat->id; - } - print $form->multiselectarray('suppcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%'); - print "
'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).''; - print $form->selectMultiCurrency(($object->multicurrency_code ? $object->multicurrency_code : $conf->currency), 'multicurrency_code', 1); - print '
'.$form->editfieldkey('WebServiceURL', 'webservices_url', '', $object, 0).''.$form->editfieldkey('WebServiceKey', 'webservices_key', '', $object, 0).'
'.$form->editfieldkey('Logo', 'photoinput', '', $object, 0).''; - if ($object->logo) print $form->showphoto('societe', $object); - $caneditfield=1; - if ($caneditfield) - { - if ($object->logo) print "
\n"; - print ''; - if ($object->logo) print ''; - //print ''; - print ''; - print '
'.$langs->trans("Delete").'

'.$langs->trans("PhotoFile").'
'; - } - print '
'.$form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0).''; - $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, '', 0, '', '', 0, 1); - $arrayselected = GETPOST('commercial', 'array'); - if (empty($arrayselected)) $arrayselected = $object->getSalesRepresentatives($user, 1); - print $form->multiselectarray('commercial', $userlist, $arrayselected, null, null, null, null, "90%"); - print '
'.$form->editfieldkey('Status', 'status', '', $object, 0, 'string', '', 1).''; + print $form->selectarray('status', $status2label, $object->status); + print '
'; - print '
'; - dol_fiche_end(); + dol_fiche_end(); - print '
'; - print ''; - print '     '; - print ''; + print '
'; + print ''; + print '     '; + print ''; print '
'; print ''; } } - else + else dol_print_error($db); +} + +if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) +{ + $res = $object->fetch_optionals(); + + $head = establishment_prepare_head($object); + dol_fiche_head($head, 'card', $langs->trans("Establishment"), -1, 'building'); + + // Confirmation to delete + if ($action == 'delete') { - /* - * View - */ - - if (!empty($object->id)) $res=$object->fetch_optionals(); - //if ($res < 0) { dol_print_error($db); exit; } - - - $head = societe_prepare_head($object); - - dol_fiche_head($head, 'card', $langs->trans("ThirdParty"), -1, 'company'); - - // Confirm delete third party - if ($action == 'delete' || ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))) - { - print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("DeleteACompany"), $langs->trans("ConfirmDeleteCompany"), "confirm_delete", '', 0, "action-delete"); - } - - if ($action == 'merge') - { - $formquestion = array( - array( - 'name' => 'soc_origin', - 'label' => $langs->trans('MergeOriginThirdparty'), - 'type' => 'other', - 'value' => $form->select_company('', 'soc_origin', 's.rowid != '.$object->id, 'SelectThirdParty', 0, 0, array(), 0, 'minwidth200') - ) - ); - - print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("MergeThirdparties"), $langs->trans("ConfirmMergeThirdparties"), "confirm_merge", $formquestion, 'no', 1, 250); - } - - dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error'); - - $linkback = ''.$langs->trans("BackToList").''; - - dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); - - - print '
'; - print '
'; - - print '
'; - print ''; - - // Prospect/Customer - print ''; - - // Supplier - if (! empty($conf->fournisseur->enabled) || ! empty($conf->supplier_proposal->enabled)) - { - print ''; - } - - // Prefix - if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field - { - print ''; - print $htmllogobar; $htmllogobar=''; - print ''; - } - - // Customer code - if ($object->client) - { - print ''; - print $htmllogobar; $htmllogobar=''; - print ''; - } - - // Supplier code - if (! empty($conf->fournisseur->enabled) && $object->fournisseur && ! empty($user->rights->fournisseur->lire)) - { - print ''; - print $htmllogobar; $htmllogobar=''; - print ''; - } - - // Barcode - if (! empty($conf->barcode->enabled)) - { - print ''; - if ($htmllogobar) $htmllogobar.=$form->showbarcode($object); - print $htmllogobar; - $htmllogobar=''; - print ''; - } - - // Prof ids - $i=1; $j=0; - while ($i <= 6) - { - $idprof=$langs->transcountry('ProfId'.$i, $object->country_code); - if ($idprof!='-') - { - //if (($j % 2) == 0) print ''; - print ''; - print ''; - //if (($j % 2) == 1) print ''; - print ''; - $j++; - } - $i++; - } - //if ($j % 2 == 1) print ''; - - - // 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. - // We don't need them into customer profile. - // Except for spain and localtax where localtax depends on buyer and not seller - - if ($object->fournisseur) - { - // VAT is used - print ''; - print ''; - } - - // Local Taxes - if ($object->fournisseur || $mysoc->country_code=='ES') - { - if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1") - { - print ''; - - if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1))) - { - print ''; - print ''; - print ''; - print ''; - if($action == 'editRE') - { - print ''; - } - else - { - print ''; - } - print ''; - } - if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2))) - { - print ''; - print ''; - print ''; - print ''; - if($action == 'editIRPF'){ - print ''; - }else{ - print ''; - } - print ''; - } - } - elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1") - { - print ''; - if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1))) - { - print ''; - print ''; - print ''; - print ''; - if($action == 'editRE'){ - print ''; - }else{ - print ''; - } - print ''; - } - } - elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1") - { - print ''; - if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2))) - { - - print ''; - print ''; - print ''; - print ''; - if($action == 'editIRPF'){ - print ''; - }else{ - print ''; - } - print ''; - } - } - } - - // Sale tax code (VAT code) - print ''; - print ''; - print ''; - - // Type + Staff - $arr = $formcompany->typent_array(1); - $object->typent= $arr[$object->typent_code]; - print ''; - print ''; - - print '
'.$langs->trans('ProspectCustomer').''; - print $object->getLibCustProspStatut(); - print '
'.$langs->trans('Supplier').''; - print yn($object->fournisseur); - print '
'.$langs->trans('Prefix').''.$object->prefix_comm.'
'; - print $langs->trans('CustomerCode').''; - print $object->code_client; - if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')'; - print '
'; - print $langs->trans('SupplierCode').''; - print $object->code_fournisseur; - if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')'; - print '
'; - print $langs->trans('Gencod').''.$object->barcode; - print '
'.$idprof.''; - $key='idprof'.$i; - print $object->$key; - if ($object->$key) - { - if ($object->id_prof_check($i, $object) > 0) print '   '.$object->id_prof_url($i, $object); - else print ' ('.$langs->trans("ErrorWrongValue").')'; - } - print '
'; - print $form->textwithpicto($langs->trans('VATIsUsed'), $langs->trans('VATIsUsedWhenSelling')); - print ''; - print yn($object->tva_assuj); - print '
'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).''; - print yn($object->localtax1_assuj); - print '
'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).''; - print yn($object->localtax2_assuj); - print '
'.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).' id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).''; - $formcompany->select_localtax(1, $object->localtax1_value, "lt1"); - print ''.$object->localtax1_value.'
'.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).'id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).''; - $formcompany->select_localtax(2, $object->localtax2_value, "lt2"); - print ''.$object->localtax2_value.'
'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).''; - print yn($object->localtax1_assuj); - print '
'.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).'id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).''; - $formcompany->select_localtax(1, $object->localtax1_value, "lt1"); - print ''.$object->localtax1_value.'
'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).''; - print yn($object->localtax2_assuj); - print '
'.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).' id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).''; - $formcompany->select_localtax(2, $object->localtax2_value, "lt2"); - print ''.$object->localtax2_value.'
'.$langs->trans('VATIntra').''; - if ($object->tva_intra) - { - $s=''; - $s.=$object->tva_intra; - $s.=''; - - if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object)) - { - $s.='   '; - - if ($conf->use_javascript_ajax) - { - print "\n"; - print ''; - print "\n"; - $s.=''.$langs->trans("VATIntraCheck").''; - $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->trans("VATIntraCheck")), 1); - } - else - { - $s.='country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').''; - } - } - print $s; - } - else - { - print ' '; - } - print '
'.$langs->trans("ThirdPartyType").''.$object->typent.'
'.$langs->trans("Staff").''.$object->effectif.'
'; - - print '
'; - print '
'; - - print '
'; - print ''; - - // Tags / categories - if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) - { - // Customer - if ($object->prospect || $object->client || (! $object->fournisseur && ! empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER))) { - print ''; - print '"; - } - - // Supplier - if ($object->fournisseur) { - print ''; - print '"; - } - } - - // Legal - print ''; - - // Capital - print ''; - - // Default language - if (! empty($conf->global->MAIN_MULTILANGS)) - { - require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - print ''; - } - - // Incoterms - if (!empty($conf->incoterm->enabled)) - { - print ''; - print ''; - } - - // Multicurrency - if (! empty($conf->multicurrency->enabled)) - { - print ''; - print ''; - print ''; - } - - // Other attributes - $parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3'); - include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; - - // Parent company - if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY)) - { - // Payment term - print ''; - print ''; - } - - // Sales representative - include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php'; - - // Module Adherent - if (! empty($conf->adherent->enabled)) - { - $langs->load("members"); - print ''; - print ''; - print "\n"; - } - - // Webservices url/key - if (!empty($conf->syncsupplierwebservices->enabled)) { - print ''; - print ''; - } - - print '
' . $langs->trans("CustomersCategoriesShort") . ''; - print $form->showCategories($object->id, 'customer', 1); - print "
' . $langs->trans("SuppliersCategoriesShort") . ''; - print $form->showCategories($object->id, 'supplier', 1); - print "
'.$langs->trans('JuridicalStatus').''.$object->forme_juridique.'
'.$langs->trans('Capital').''; - if ($object->capital) print price($object->capital, '', $langs, 0, -1, -1, $conf->currency); - else print ' '; - print '
'.$langs->trans("DefaultLang").''; - //$s=picto_from_langcode($object->default_lang); - //print ($s?$s.' ':''); - $langs->load("languages"); - $labellang = ($object->default_lang?$langs->trans('Language_'.$object->default_lang):''); - print $labellang; - print '
'; - print '
'; - print $langs->trans('IncotermLabel'); - print ''; - if ($user->rights->societe->creer) print ''.img_edit('', 1).''; - else print ' '; - print '
'; - print '
'; - if ($action != 'editincoterm') - { - print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1); - } - else - { - print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?socid='.$object->id); - } - print '
'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).''; - print !empty($object->multicurrency_code) ? currency_name($object->multicurrency_code, 1) : ''; - print '
'; - print ''; - if ($action != 'editparentcompany') print ''; - print '
'; - print $langs->trans('ParentCompany'); - print 'id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'
'; - print '
'; - if ($action == 'editparentcompany') - { - $form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->parent, 'editparentcompany', 's.rowid <> '.$object->id, 1); - } - else - { - $form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->parent, 'none', 's.rowid <> '.$object->id, 1); - } - print '
'.$langs->trans("LinkedToDolibarrMember").''; - $adh=new Adherent($db); - $result=$adh->fetch('', '', $object->id); - if ($result > 0) - { - $adh->ref=$adh->getFullName($langs); - print $adh->getNomUrl(1); - } - else - { - print ''.$langs->trans("ThirdpartyNotLinkedToMember").''; - } - print '
'.$langs->trans("WebServiceURL").''.dol_print_url($object->webservices_url).''.$langs->trans('WebServiceKey').''.$object->webservices_key.'
'; - print '
'; - - print '
'; - print '
'; - - dol_fiche_end(); - - - /* - * Actions - */ - if ($action != 'presend') - { - print '
'."\n"; - - $parameters=array(); - $reshook=$hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) - { - $at_least_one_email_contact = false; - $TContact = $object->contact_array_objects(); - foreach ($TContact as &$contact) - { - if (!empty($contact->email)) - { - $at_least_one_email_contact = true; - break; - } - } - - if (! empty($object->email) || $at_least_one_email_contact) - { - $langs->load("mails"); - print ''; - } - else - { - $langs->load("mails"); - print ''; - } - - if ($user->rights->societe->creer) - { - print ''."\n"; - } - - if ($user->rights->societe->supprimer) - { - print ''; - } - - if ($user->rights->societe->supprimer) - { - if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)) // We can't use preloaded confirm form with jmobile - { - print '
'.$langs->trans('Delete').'
'."\n"; - } - else - { - print ''."\n"; - } - } - } - - print '
'."\n"; - } - - //Select mail models is same action as presend - if (GETPOST('modelselected')) { - $action = 'presend'; - } - - if ($action != 'presend') - { - print '
'; - - if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC)) - { - print ''; // ancre - - /* - * Documents generes - */ - $filedir=$conf->societe->multidir_output[$object->entity].'/'.$object->id; - $urlsource=$_SERVER["PHP_SELF"]."?socid=".$object->id; - $genallowed=$user->rights->societe->lire; - $delallowed=$user->rights->societe->creer; - - print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang); - } - - // Subsidiaries list - if (empty($conf->global->SOCIETE_DISABLE_SUBSIDIARIES)) - { - $result=show_subsidiaries($conf, $langs, $db, $object); - } - - print '
'; - - $MAXEVENT = 10; - - $morehtmlright = ''; - $morehtmlright.= $langs->trans("SeeAll"); - $morehtmlright.= ''; - - // List of actions on element - include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; - $formactions = new FormActions($db); - $somethingshown = $formactions->showactions($object, '', $socid, 1, '', $MAXEVENT, '', $morehtmlright); // Show all action for thirdparty - - print '
'; - - if (! empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD)) - { - // Contacts list - if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) - { - $result=show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id); - } - - // Addresses list - if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT)) - { - $result=show_addresses($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id); - } - } - } - - // Presend form - $modelmail='thirdparty'; - $defaulttopic='Information'; - $diroutput = $conf->societe->dir_output; - $trackid = 'thi'.$object->id; - - include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; + print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("DeleteEstablishment"), $langs->trans("ConfirmDeleteEstablishment"), "confirm_delete"); } + + + // Object card + // ------------------------------------------------------------ + + $linkback = '' . $langs->trans("BackToList") . ''; + + $morehtmlref='
'; + $morehtmlref.='
'; + + dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', $morehtmlref); + + + print '
'; + //print '
'; + print '
'; + print ''."\n"; + + // Name + print ''; + print ''; + print ''; + print ''; + + // Parent + print ''; + print ''; + print ''; + print ''; + + // Address + print ''; + print ''; + print ''; + print ''; + + // Zipcode + print ''; + print ''; + print ''; + print ''; + + // Town + print ''; + print ''; + print ''; + print ''; + + // Country + print ''; + print ''; + print ''; + print ''; + + print '
'.$langs->trans("Name").''.$object->name.'
'.$langs->trans("Parent").''.$object->getNomUrlParent($object->entity).'
'.$langs->trans("Address").''.$object->address.'
'.$langs->trans("Zipcode").''.$object->zip.'
'.$langs->trans("Town").''.$object->town.'
'.$langs->trans("Country").''; + if ($object->country_id > 0) + { + $img=picto_from_langcode($object->country_code); + print $img?$img.' ':''; + print getCountry($object->getCountryCode(), 0, $db); + } + print '
'; + print '
'; + + print '

'; + + dol_fiche_end(); + + /* + * Barre d'actions + */ + + print '
'; + print ''.$langs->trans('Modify').''; + print ''.$langs->trans('Delete').''; + print '
'; } // End of page From 89c2d6731bdbf8f0c3f193b5ea45eccc35328cf3 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 27 Feb 2019 00:48:13 +0100 Subject: [PATCH 13/23] ADD product document support in API --- htdocs/api/class/api_documents.class.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index 8db471855d6..f4ae79d888e 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -355,6 +355,22 @@ class Documents extends DolibarrApi $upload_dir = $conf->facture->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'invoice'); } + else if ($modulepart == 'produit' || $modulepart == 'product') + { + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; + + if (!DolibarrApiAccess::$user->rights->produit->lire) { + throw new RestException(401); + } + + $object = new Product($this->db); + $result=$object->fetch($id, $ref); + if ( ! $result ) { + throw new RestException(404, 'Product not found'); + } + + $upload_dir = $conf->product->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'invoice'); + } else if ($modulepart == 'agenda' || $modulepart == 'action' || $modulepart == 'event') { require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; From 64bd995978156bd7c791832dc35a0ccd34477876 Mon Sep 17 00:00:00 2001 From: wdammak <26695620+wdammak@users.noreply.github.com> Date: Wed, 27 Feb 2019 04:02:11 +0100 Subject: [PATCH 14/23] Fix camelCase syntax and remove disabling of phpcs --- htdocs/core/class/html.form.class.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 21d16f9f9ce..585d29e254e 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -3681,8 +3681,7 @@ class Form return $num; } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + /** * Return a HTML select list of establishment * @@ -3694,7 +3693,7 @@ class Form * @param string $moreattrib To add more attribute on select * @return int <0 if error, Num of establishment found if OK (0, 1, 2, ...) */ - function select_establishments($selected = '', $htmlname = 'entity', $statut = 0, $filtre = '', $useempty = 0, $moreattrib = '') + function selectEstablishments($selected = '', $htmlname = 'entity', $statut = 0, $filtre = '', $useempty = 0, $moreattrib = '') { // phpcs:enable global $langs, $conf; From b1782f0fc866a31df81e8a96b8c957b2c2f5fda6 Mon Sep 17 00:00:00 2001 From: wdammak <26695620+wdammak@users.noreply.github.com> Date: Wed, 27 Feb 2019 04:05:02 +0100 Subject: [PATCH 15/23] rename function select_establishments to selectEstablishments --- htdocs/hrm/establishment/card.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/hrm/establishment/card.php b/htdocs/hrm/establishment/card.php index af242515a24..37a3d7f538b 100644 --- a/htdocs/hrm/establishment/card.php +++ b/htdocs/hrm/establishment/card.php @@ -194,7 +194,7 @@ if ($action == 'create') print ''; print ''.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).''; print ''; - print $form->select_establishments(GETPOST('entity', 'int')>0?GETPOST('entity', 'int'):$conf->entity, 'entity', 1); + print $form->selectEstablishments(GETPOST('entity', 'int')>0?GETPOST('entity', 'int'):$conf->entity, 'entity', 1); print ''; print ''; @@ -295,7 +295,7 @@ if (($id || $ref) && $action == 'edit') // Parent print ''.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).''; print ''; - print $form->select_establishments($object->entity>0?$object->entity:$conf->entity, 'entity', 1); + print $form->selectEstablishments($object->entity>0?$object->entity:$conf->entity, 'entity', 1); print ''; // Address From d9300e78037b554e5d5b8e763d0b6e8a9c185a93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 27 Feb 2019 08:28:13 +0100 Subject: [PATCH 16/23] phpcs fix --- htdocs/contact/list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index 41ff8061244..897dfaf557b 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -718,7 +718,7 @@ if (! empty($arrayfields['p.phone_perso']['checked'])) print_liste_field if (! empty($arrayfields['p.phone_mobile']['checked'])) print_liste_field_titre($arrayfields['p.phone_mobile']['label'], $_SERVER["PHP_SELF"], "p.phone_mobile", $begin, $param, '', $sortfield, $sortorder); if (! empty($arrayfields['p.fax']['checked'])) print_liste_field_titre($arrayfields['p.fax']['label'], $_SERVER["PHP_SELF"], "p.fax", $begin, $param, '', $sortfield, $sortorder); if (! empty($arrayfields['p.email']['checked'])) print_liste_field_titre($arrayfields['p.email']['label'], $_SERVER["PHP_SELF"], "p.email", $begin, $param, '', $sortfield, $sortorder); -if (! empty($arrayfields['p.no_email']['checked'])) print_liste_field_titre($arrayfields['p.no_email']['label'],$_SERVER["PHP_SELF"], "p.no_email", $begin, $param, '', $sortfield, $sortorder, 'center '); +if (! empty($arrayfields['p.no_email']['checked'])) print_liste_field_titre($arrayfields['p.no_email']['label'], $_SERVER["PHP_SELF"], "p.no_email", $begin, $param, '', $sortfield, $sortorder, 'center '); if (! empty($arrayfields['p.skype']['checked'])) print_liste_field_titre($arrayfields['p.skype']['label'], $_SERVER["PHP_SELF"], "p.skype", $begin, $param, '', $sortfield, $sortorder); if (! empty($arrayfields['p.twitter']['checked'])) print_liste_field_titre($arrayfields['p.twitter']['label'], $_SERVER["PHP_SELF"], "p.twitter", $begin, $param, '', $sortfield, $sortorder); if (! empty($arrayfields['p.facebook']['checked'])) print_liste_field_titre($arrayfields['p.facebook']['label'], $_SERVER["PHP_SELF"], "p.facebook", $begin, $param, '', $sortfield, $sortorder); From 096bc4750c5fa3d7ceb71065db23fd552480f90c Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 27 Feb 2019 11:23:33 +0100 Subject: [PATCH 17/23] Update api_documents.class.php --- htdocs/api/class/api_documents.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index f4ae79d888e..7473bc5db5e 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -369,7 +369,7 @@ class Documents extends DolibarrApi throw new RestException(404, 'Product not found'); } - $upload_dir = $conf->product->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'invoice'); + $upload_dir = $conf->product->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'product'); } else if ($modulepart == 'agenda' || $modulepart == 'action' || $modulepart == 'event') { From 825705179c398693683c1d7e2f13cc41c6d69cf9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 27 Feb 2019 12:49:44 +0100 Subject: [PATCH 18/23] Fix phpcs --- htdocs/bom/bom_card.php | 8 ++++---- htdocs/bom/bom_list.php | 4 ++-- htdocs/bom/class/bom.class.php | 2 +- htdocs/contact/list.php | 2 +- htdocs/takepos/genimg/index.php | 23 +++++++++++------------ 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 2b5163bb4f2..ea5ba91c715 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -88,7 +88,7 @@ $search_all=trim(GETPOST("search_all", 'alpha')); $search=array(); foreach($object->fields as $key => $val) { - if (GETPOST('search_'.$key,'alpha')) $search[$key]=GETPOST('search_'.$key, 'alpha'); + if (GETPOST('search_'.$key, 'alpha')) $search[$key]=GETPOST('search_'.$key, 'alpha'); } if (empty($action) && empty($id) && empty($ref)) $action='view'; @@ -119,11 +119,11 @@ if (empty($reshook)) $permissiontoadd = $user->rights->bom->write; $permissiontodelete = $user->rights->bom->delete || ($permissiontoadd && $object->status == 0); - $backurlforlist = dol_buildpath('/bom/bom_list.php', 1); + $backurlforlist = dol_buildpath('/bom/bom_list.php', 1); if (empty($backtopage)) { if (empty($id)) $backtopage = $backurlforlist; - else $backtopage = dol_buildpath('/bom/bom_card.php',1).($id > 0 ? $id : '__ID__'); - } + else $backtopage = dol_buildpath('/bom/bom_card.php', 1).($id > 0 ? $id : '__ID__'); + } $triggermodname = 'BILLOFMATERIALS_BILLOFMATERIALS_MODIFY'; // Name of trigger action code to execute when we modify record // Actions cancel, add, update, delete or clone diff --git a/htdocs/bom/bom_list.php b/htdocs/bom/bom_list.php index 985241e92ff..4785d0c4598 100644 --- a/htdocs/bom/bom_list.php +++ b/htdocs/bom/bom_list.php @@ -150,7 +150,7 @@ $arrayfields = dol_sort_array($arrayfields, 'position'); * Actions */ -if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; } +if (GETPOST('cancel', 'alpha')) { $action='list'; $massaction=''; } if (! GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; } $parameters=array(); @@ -163,7 +163,7 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; // Purge search criteria - if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') ||GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers { foreach($object->fields as $key => $val) { diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index d84be3a06ad..2221da19567 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -995,7 +995,7 @@ class BillOfMaterialsLine extends CommonObject $label.= '
'; $label.= '' . $langs->trans('Ref') . ': ' . $this->ref; - $url = dol_buildpath('/bom/bomline_card.php',1).'?id='.$this->id; + $url = dol_buildpath('/bom/bomline_card.php', 1).'?id='.$this->id; if ($option != 'nolink') { diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index 41ff8061244..897dfaf557b 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -718,7 +718,7 @@ if (! empty($arrayfields['p.phone_perso']['checked'])) print_liste_field if (! empty($arrayfields['p.phone_mobile']['checked'])) print_liste_field_titre($arrayfields['p.phone_mobile']['label'], $_SERVER["PHP_SELF"], "p.phone_mobile", $begin, $param, '', $sortfield, $sortorder); if (! empty($arrayfields['p.fax']['checked'])) print_liste_field_titre($arrayfields['p.fax']['label'], $_SERVER["PHP_SELF"], "p.fax", $begin, $param, '', $sortfield, $sortorder); if (! empty($arrayfields['p.email']['checked'])) print_liste_field_titre($arrayfields['p.email']['label'], $_SERVER["PHP_SELF"], "p.email", $begin, $param, '', $sortfield, $sortorder); -if (! empty($arrayfields['p.no_email']['checked'])) print_liste_field_titre($arrayfields['p.no_email']['label'],$_SERVER["PHP_SELF"], "p.no_email", $begin, $param, '', $sortfield, $sortorder, 'center '); +if (! empty($arrayfields['p.no_email']['checked'])) print_liste_field_titre($arrayfields['p.no_email']['label'], $_SERVER["PHP_SELF"], "p.no_email", $begin, $param, '', $sortfield, $sortorder, 'center '); if (! empty($arrayfields['p.skype']['checked'])) print_liste_field_titre($arrayfields['p.skype']['label'], $_SERVER["PHP_SELF"], "p.skype", $begin, $param, '', $sortfield, $sortorder); if (! empty($arrayfields['p.twitter']['checked'])) print_liste_field_titre($arrayfields['p.twitter']['label'], $_SERVER["PHP_SELF"], "p.twitter", $begin, $param, '', $sortfield, $sortorder); if (! empty($arrayfields['p.facebook']['checked'])) print_liste_field_titre($arrayfields['p.facebook']['label'], $_SERVER["PHP_SELF"], "p.facebook", $begin, $param, '', $sortfield, $sortorder); diff --git a/htdocs/takepos/genimg/index.php b/htdocs/takepos/genimg/index.php index 546c5ed6fca..506c067790a 100644 --- a/htdocs/takepos/genimg/index.php +++ b/htdocs/takepos/genimg/index.php @@ -54,19 +54,19 @@ if ($query=="cat") $dir = $upload_dir.'/'.$pdir; foreach ($object->liste_photos($dir) as $key => $obj) + { + if ($obj['photo_vignette']) { - if ($obj['photo_vignette']) - { - $filename=$obj['photo_vignette']; - } - else - { - $filename=$obj['photo']; - } - $file=DOL_URL_ROOT.'/viewimage.php?modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$filename); - header('Location: '.$file); - exit; + $filename=$obj['photo_vignette']; } + else + { + $filename=$obj['photo']; + } + $file=DOL_URL_ROOT.'/viewimage.php?modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$filename); + header('Location: '.$file); + exit; + } header('Location: ../../public/theme/common/nophoto.png'); } elseif ($query=="pro") @@ -81,7 +81,6 @@ elseif ($query=="pro") $file = array_pop($match); if ($file=="") header('Location: ../../public/theme/common/nophoto.png'); else header('Location: '.$file); - } else { From 24a8bd12fe60ae3cb3e99d4cb84f4ff8cac32754 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 27 Feb 2019 13:33:34 +0100 Subject: [PATCH 19/23] Update admin_establishment.php --- htdocs/hrm/admin/admin_establishment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/hrm/admin/admin_establishment.php b/htdocs/hrm/admin/admin_establishment.php index ee2f69a6d39..1985926563b 100644 --- a/htdocs/hrm/admin/admin_establishment.php +++ b/htdocs/hrm/admin/admin_establishment.php @@ -78,7 +78,7 @@ dol_fiche_head($head, 'establishments', $langs->trans("HRM"), -1, "user"); $sql = "SELECT e.rowid, e.name, e.address, e.zip, e.town, e.status"; $sql.= " FROM ".MAIN_DB_PREFIX."establishment as e"; -$sql.= " WHERE 1 = 1"; +$sql.= " WHERE e.entity IN (".getEntity('establishment').')'; $sql.= $db->order($sortfield, $sortorder); $sql.= $db->plimit($limit+1, $offset); From e873608d842fabf38fc287f7920fc8920d85450e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 27 Feb 2019 13:37:53 +0100 Subject: [PATCH 20/23] Update card.php --- htdocs/user/card.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 048ee72e688..26aaa2bf98b 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -387,8 +387,11 @@ if (empty($reshook)) { $dateemploymentend = dol_mktime(0, 0, 0, GETPOST('dateemploymentendmonth', 'int'), GETPOST('dateemploymentendday', 'int'), GETPOST('dateemploymentendyear', 'int')); $object->dateemploymentend = $dateemploymentend; - $object->fk_warehouse = GETPOST('fk_warehouse', 'int'); - + if (! empty($conf->stock->enabled)) + { + $object->fk_warehouse = GETPOST('fk_warehouse', 'int'); + } + if (! empty($conf->multicompany->enabled)) { if (! empty($_POST["superadmin"])) From c4e96e9f740dd6b8e4ab5b0e6d0390cf1ac6f7b8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 27 Feb 2019 13:48:13 +0100 Subject: [PATCH 21/23] Fix language --- htdocs/langs/en_US/main.lang | 2 +- htdocs/langs/en_US/users.lang | 1 + htdocs/user/card.php | 19 +++++++++++++------ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 972712edeea..6638a4c1a04 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -885,7 +885,6 @@ LineNb=Line no. IncotermLabel=Incoterms TabLetteringCustomer=Customer lettering TabLetteringSupplier=Vendor lettering -# Week day Monday=Monday Tuesday=Tuesday Wednesday=Wednesday @@ -965,3 +964,4 @@ SelectAThirdPartyFirst=Select a third party first... YouAreCurrentlyInSandboxMode=You are currently in the %s "sandbox" mode Inventory=Inventory AnalyticCode=Analytic code +TMenuMRP=MRP \ No newline at end of file diff --git a/htdocs/langs/en_US/users.lang b/htdocs/langs/en_US/users.lang index 862d137a510..53ac720d862 100644 --- a/htdocs/langs/en_US/users.lang +++ b/htdocs/langs/en_US/users.lang @@ -109,3 +109,4 @@ UserLogoff=User logout UserLogged=User logged DateEmployment=Employment Start Date DateEmploymentEnd=Employment End Date +CantDisableYourself=You can disable your own user record \ No newline at end of file diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 3b2afd05305..46fc74626bb 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -388,12 +388,12 @@ if (empty($reshook)) { $object->dateemployment = $dateemployment; $dateemploymentend = dol_mktime(0, 0, 0, GETPOST('dateemploymentendmonth', 'int'), GETPOST('dateemploymentendday', 'int'), GETPOST('dateemploymentendyear', 'int')); $object->dateemploymentend = $dateemploymentend; - + if (! empty($conf->stock->enabled)) { $object->fk_warehouse = GETPOST('fk_warehouse', 'int'); } - + if (! empty($conf->multicompany->enabled)) { if (! empty($_POST["superadmin"])) @@ -1553,7 +1553,7 @@ else print ''.$langs->trans("PostOrFunction").''; print ''.$object->job.''; print ''."\n"; - + // Default warehouse if (! empty($conf->stock->enabled)) { @@ -1828,18 +1828,25 @@ else } } - // Activer + // Enable user if ($user->id <> $id && $candisableuser && $object->statut == 0 && ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $conf->entity == 1))) { print ''; } - // Desactiver + // Disable user if ($user->id <> $id && $candisableuser && $object->statut == 1 && ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $conf->entity == 1))) { print ''; } + else + { + if ($user->id == $id) + { + print ''; + } + } // Delete if ($user->id <> $id && $candisableuser && ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $conf->entity == 1))) @@ -2582,7 +2589,7 @@ else print $object->job; } print ''; - + // Default warehouse if (! empty($conf->stock->enabled)) { From 29cfa03fa4130e655a668e9851f1618313817fb1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 27 Feb 2019 13:54:39 +0100 Subject: [PATCH 22/23] Fix font awesome 5 regressions --- htdocs/core/lib/functions.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index d12aeb6be41..7e150fc9a7f 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3081,7 +3081,7 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $ elseif ($pictowithoutext == 'jabber') { $fakey = 'fa-comment-o'; } - elseif ($pictowithoutext == 'skype') { + elseif (in_array($pictowithoutext, array('skype', 'twitter', 'facebook', 'linkedin'))) { $fakey = 'fa-'.$pictowithoutext; if (! empty($conf->global->MAIN_USE_FONT_AWESOME_5)) $fa = 'fab'; } From 70744a8ca0734e46e0f8e1ff8951ce7accdfca52 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 27 Feb 2019 13:58:26 +0100 Subject: [PATCH 23/23] CSS --- htdocs/theme/eldy/style.css.php | 2 +- htdocs/theme/md/style.css.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index 81107d8c0d6..f4134650674 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -271,7 +271,7 @@ body { .thumbstat { font-weight: bold !important; } th a { font-weight: !important; } -a.tab { font-weight: bold !important; } +a.tab { font-weight: 500 !important; } a:link, a:visited, a:hover, a:active { font-family: ; font-weight: normal; color: rgb(); text-decoration: none; } a:hover { text-decoration: underline; color: rgb(); } diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index 85ab07bb09a..5bd5c386641 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -264,7 +264,7 @@ body { .thumbstat { font-weight: bold !important; } th a { font-weight: !important; } -a.tab { font-weight: bold !important; } +a.tab { font-weight: 500 !important; } a:link, a:visited, a:hover, a:active { font-family: ; font-weight: normal; color: rgb(); text-decoration: none; } a:hover { text-decoration: underline; color: rgb(); }