NEW Add a profil to import contact categories

Load roles of contact only when required
This commit is contained in:
Laurent Destailleur 2020-02-19 13:22:24 +01:00
parent 05ced30727
commit f109864670
5 changed files with 69 additions and 36 deletions

View File

@ -554,6 +554,8 @@ else
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} }
$object->fetchRoles();
// Show tabs // Show tabs
$head = contact_prepare_head($object); $head = contact_prepare_head($object);
@ -580,7 +582,7 @@ else
$object->country = $tmparray['label']; $object->country = $tmparray['label'];
} }
$title = $addcontact = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("AddContact") : $langs->trans("AddContactAddress")); $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("AddContact") : $langs->trans("AddContactAddress"));
$linkback = ''; $linkback = '';
print load_fiche_titre($title, $linkback, 'address'); print load_fiche_titre($title, $linkback, 'address');

View File

@ -802,20 +802,19 @@ class Contact extends CommonObject
/** /**
* Load object contact * Load object contact.
* *
* @param int $id id du contact * @param int $id Id of contact
* @param User $user Utilisateur (abonnes aux alertes) qui veut les alertes de ce contact * @param User $user Load also alerts of this user (subscribing to alerts) that want alerts about this contact
* @param string $ref_ext External reference, not given by Dolibarr * @param string $ref_ext External reference, not given by Dolibarr
* @param string $email Email * @param string $email Email
* @return int -1 if KO, 0 if OK but not found, 1 if OK * @param int $loadalsoroles Load also roles
* @return int >0 if OK, <0 if KO or if two records found for same ref or idprof, 0 if not found.
*/ */
public function fetch($id, $user = null, $ref_ext = '', $email = '') public function fetch($id, $user = null, $ref_ext = '', $email = '', $loadalsoroles = 0)
{ {
global $langs; global $langs;
$langs->load("dict");
dol_syslog(get_class($this)."::fetch id=".$id." ref_ext=".$ref_ext." email=".$email, LOG_DEBUG); dol_syslog(get_class($this)."::fetch id=".$id." ref_ext=".$ref_ext." email=".$email, LOG_DEBUG);
if (empty($id) && empty($ref_ext) && empty($email)) if (empty($id) && empty($ref_ext) && empty($email))
@ -824,7 +823,7 @@ class Contact extends CommonObject
return -1; return -1;
} }
$langs->load("companies"); $langs->loadLangs(array("dict", "companies"));
$sql = "SELECT c.rowid, c.entity, c.fk_soc, c.ref_ext, c.civility as civility_code, c.lastname, c.firstname,"; $sql = "SELECT c.rowid, c.entity, c.fk_soc, c.ref_ext, c.civility as civility_code, c.lastname, c.firstname,";
$sql .= " c.address, c.statut, c.zip, c.town,"; $sql .= " c.address, c.statut, c.zip, c.town,";
@ -861,7 +860,15 @@ class Contact extends CommonObject
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
if ($this->db->num_rows($resql)) $num = $this->db->num_rows($resql);
if ($num > 1)
{
$this->error = 'Fetch found several records. Rename one of contact to avoid duplicate.';
dol_syslog($this->error, LOG_ERR);
return 2;
}
elseif ($num) // $num = 1
{ {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
@ -942,7 +949,11 @@ class Contact extends CommonObject
return -1; return -1;
} }
// Charge alertes du user // Retreive all extrafield
// fetch optionals attributes and labels
$this->fetch_optionals();
// Load also alerts of this user
if ($user) if ($user)
{ {
$sql = "SELECT fk_user"; $sql = "SELECT fk_user";
@ -967,14 +978,13 @@ class Contact extends CommonObject
} }
} }
// Retreive all extrafield // Load also roles of this address
// fetch optionals attributes and labels if ($loadalsoroles) {
$this->fetch_optionals();
$resultRole = $this->fetchRoles(); $resultRole = $this->fetchRoles();
if ($resultRole < 0) { if ($resultRole < 0) {
return $resultRole; return $resultRole;
} }
}
return 1; return 1;
} }
@ -1587,7 +1597,7 @@ class Contact extends CommonObject
} }
/** /**
* Fetch Role for a contact * Fetch Roles for a contact
* *
* @return float|int * @return float|int
* @throws Exception * @throws Exception

View File

@ -425,6 +425,7 @@ class ImportCsv extends ModeleImports
// New val can be an id or ref. If it start with id: it is forced to id, if it start with ref: it is forced to ref. It not, we try to guess. // New val can be an id or ref. If it start with id: it is forced to id, if it start with ref: it is forced to ref. It not, we try to guess.
$isidorref = 'id'; $isidorref = 'id';
if (!is_numeric($newval) && $newval != '' && !preg_match('/^id:/i', $newval)) $isidorref = 'ref'; if (!is_numeric($newval) && $newval != '' && !preg_match('/^id:/i', $newval)) $isidorref = 'ref';
$newval = preg_replace('/^(id|ref):/i', '', $newval); // Remove id: or ref: that was used to force if field is id or ref $newval = preg_replace('/^(id|ref):/i', '', $newval); // Remove id: or ref: that was used to force if field is id or ref
//print 'Val is now '.$newval.' and is type '.$isidorref."<br>\n"; //print 'Val is now '.$newval.' and is type '.$isidorref."<br>\n";
@ -448,8 +449,7 @@ class ImportCsv extends ModeleImports
$classinstance = new $class($this->db); $classinstance = new $class($this->db);
// Try the fetch from code or ref // Try the fetch from code or ref
$param_array = array('', $newval); $param_array = array('', $newval);
if ($class == 'AccountingAccount') if ($class == 'AccountingAccount') {
{
//var_dump($arrayrecord[0]['val']); //var_dump($arrayrecord[0]['val']);
/*include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancysystem.class.php'; /*include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancysystem.class.php';
$tmpchartofaccount = new AccountancySystem($this->db); $tmpchartofaccount = new AccountancySystem($this->db);
@ -464,6 +464,7 @@ class ImportCsv extends ModeleImports
}*/ }*/
$param_array = array('', $newval, 0, $arrayrecord[0]['val']); // Param to fetch parent from account, in chart. $param_array = array('', $newval, 0, $arrayrecord[0]['val']); // Param to fetch parent from account, in chart.
} }
call_user_func_array(array($classinstance, $method), $param_array); call_user_func_array(array($classinstance, $method), $param_array);
// If not found, try the fetch from label // If not found, try the fetch from label
if (! ($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel') if (! ($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel')

View File

@ -470,6 +470,25 @@ class modCategorie extends DolibarrModules
'cs.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty') 'cs.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty')
); );
$this->import_examplevalues_array[$r]=array('cs.fk_categorie'=>"Imported category",'cs.fk_soc'=>"MyBigCompany"); $this->import_examplevalues_array[$r]=array('cs.fk_categorie'=>"Imported category",'cs.fk_soc'=>"MyBigCompany");
// Contacts/Addresses
$r++;
$this->import_code[$r]=$this->rights_class.'_'.$r;
$this->import_label[$r]="CatContactsLinks"; // Translation key
$this->import_icon[$r]=$this->picto;
$this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
$this->import_tables_array[$r]=array('cs'=>MAIN_DB_PREFIX.'categorie_contact');
$this->import_fields_array[$r]=array('cs.fk_categorie'=>"Category*",'cs.fk_socpeople'=>"Contact ID*");
$this->import_regex_array[$r]=array(
'cs.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=4'
//'cs.fk_socpeople'=>'rowid@'.MAIN_DB_PREFIX.'socpeople'
);
$this->import_convertvalue_array[$r]=array(
'cs.fk_categorie'=>array('rule'=>'fetchidfromref','classfile'=>'/categories/class/categorie.class.php','class'=>'Categorie','method'=>'fetch','element'=>'category')
//'cs.fk_socpeople'=>array('rule'=>'fetchidfromref','classfile'=>'/contact/class/contact.class.php','class'=>'Contact','method'=>'fetch','element'=>'Contact')
);
$this->import_examplevalues_array[$r]=array('cs.fk_categorie'=>"Imported category",'cs.fk_socpeople'=>"123");
} }
if (! empty($conf->fournisseur->enabled)) if (! empty($conf->fournisseur->enabled))

View File

@ -78,6 +78,7 @@ CatMemberList=List of members tags/categories
CatContactList=List of contact tags/categories CatContactList=List of contact tags/categories
CatSupLinks=Links between suppliers and tags/categories CatSupLinks=Links between suppliers and tags/categories
CatCusLinks=Links between customers/prospects and tags/categories CatCusLinks=Links between customers/prospects and tags/categories
CatContactsLinks=Links between contacts/addresses and tags/categories
CatProdLinks=Links between products/services and tags/categories CatProdLinks=Links between products/services and tags/categories
CatProJectLinks=Links between projects and tags/categories CatProJectLinks=Links between projects and tags/categories
DeleteFromCat=Remove from tags/category DeleteFromCat=Remove from tags/category