diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index c7ffdc63753..acf708005d3 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -63,13 +63,24 @@ class Categorie * Load category into memory from database * * @param int $id Id of category + * @param strin $label Label of category * @return int <0 if KO, >0 if OK */ - function fetch($id) + function fetch($id,$label='') { + global $conf; + $sql = "SELECT rowid, fk_parent, entity, label, description, fk_soc, visible, type"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie"; - $sql.= " WHERE rowid = ".$id; + if ($id) + { + $sql.= " WHERE rowid = '".$id."'"; + } + + else + { + if ($label) $sql.= " WHERE label = '".$this->db->escape($label)."' AND entity=".$conf->entity;; + } dol_syslog(get_class($this)."::fetch sql=".$sql); $resql = $this->db->query($sql); diff --git a/htdocs/core/modules/modCategorie.class.php b/htdocs/core/modules/modCategorie.class.php index cb5fe07ee5f..4cdc10e2357 100644 --- a/htdocs/core/modules/modCategorie.class.php +++ b/htdocs/core/modules/modCategorie.class.php @@ -178,6 +178,57 @@ class modCategorie extends DolibarrModules $this->import_regex_array[$r]=array('ca.type'=>'^[0|1|2|3]'); $this->import_examplevalues_array[$r]=array('ca.label'=>"Supplier Category",'ca.type'=>"1",'ca.description'=>"Imported category"); + + if (! empty($conf->product->enabled)) + { + //Products + $r++; + $this->import_code[$r]=$this->rights_class.'_'.$r; + $this->import_label[$r]="CatSupList"; // 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('cp'=>MAIN_DB_PREFIX.'categorie_product'); + $this->import_fields_array[$r]=array('cp.fk_categorie'=>"Category*",'cp.fk_product'=>"Product*" + ); + + $this->import_convertvalue_array[$r]=array( + 'cp.fk_categorie'=>array('rule'=>'fetchidfromref','classfile'=>'/categories/class/categorie.class.php','class'=>'Categorie','method'=>'fetch','element'=>'category'), + 'cp.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'product') + ); + $this->import_examplevalues_array[$r]=array('cp.fk_categorie'=>"Imported category",'cp.fk_product'=>"PREF123456"); + } + + //Customers + $r++; + $this->import_code[$r]=$this->rights_class.'_'.$r; + $this->import_label[$r]="Clientes por categoría"; // 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('co'=>MAIN_DB_PREFIX.'categorie_societe'); + $this->import_fields_array[$r]=array('co.fk_categorie'=>"Categorie*",'co.fk_societe'=>"Tercero*" + ); + + $this->import_convertvalue_array[$r]=array( + 'co.fk_categorie'=>array('rule'=>'fetchidfromref','classfile'=>'/categories/class/categorie.class.php','class'=>'Categorie','method'=>'fetch','element'=>'category'), + 'co.fk_societe'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty') + ); + $this->import_examplevalues_array[$r]=array('co.fk_categorie'=>"Nombre categoría",'co.fk_societe'=>"Nombre cliente"); + + // Suppliers + $r++; + $this->import_code[$r]=$this->rights_class.'_'.$r; + $this->import_label[$r]="Proveedores por categoría"; // 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('co'=>MAIN_DB_PREFIX.'categorie_fournisseur'); + $this->import_fields_array[$r]=array('co.fk_categorie'=>"Categorie*",'co.fk_societe'=>"Tercero*" + ); + + $this->import_convertvalue_array[$r]=array( + 'co.fk_categorie'=>array('rule'=>'fetchidfromref','classfile'=>'/categories/class/categorie.class.php','class'=>'Categorie','method'=>'fetch','element'=>'category'), + 'co.fk_societe'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty') + ); + $this->import_examplevalues_array[$r]=array('co.fk_categorie'=>"Nombre categoria",'co.fk_societe'=>"Nombre proveedor"); } diff --git a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql index 259726d354c..d9dd806d397 100755 --- a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql +++ b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql @@ -772,6 +772,7 @@ ALTER TABLE llx_entrepot ADD COLUMN import_key varchar(14) AFTER fk_user_author; ALTER TABLE llx_product_fournisseur_price ADD COLUMN import_key varchar(14) AFTER fk_user; ALTER TABLE llx_product_stock ADD COLUMN import_key varchar(14) AFTER pmp; ALTER TABLE llx_societe_rib ADD COLUMN import_key varchar(14) AFTER adresse_proprio; +ALTER TABLE llx_categorie_product ADD COLUMN import_key varchar(14) AFTER fk_product; -- Export filter ALTER TABLE llx_export_model ADD COLUMN filter text AFTER field; diff --git a/htdocs/install/mysql/tables/llx_categorie_product.sql b/htdocs/install/mysql/tables/llx_categorie_product.sql index f10a5e32c61..2cdcf6802e4 100644 --- a/htdocs/install/mysql/tables/llx_categorie_product.sql +++ b/htdocs/install/mysql/tables/llx_categorie_product.sql @@ -1,6 +1,7 @@ -- ============================================================================ -- Copyright (C) 2005 Brice Davoleau --- Copyright (C) 2005 Matthieu Valleton +-- Copyright (C) 2005 Matthieu Valleton +-- Copyright (C) 2012 Juanjo Menent -- -- 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 @@ -20,5 +21,6 @@ create table llx_categorie_product ( fk_categorie integer NOT NULL, - fk_product integer NOT NULL + fk_product integer NOT NULL, + import_key varchar(14) )ENGINE=innodb;