Merge pull request #465 from simnandez/develop

Fix: [ bug #579 ] Multi-Company and imports
This commit is contained in:
Laurent Destailleur 2012-10-26 11:00:52 -07:00
commit 833ada4732
9 changed files with 164 additions and 12 deletions

View File

@ -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);

View File

@ -2,6 +2,7 @@
/* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009-2012 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
*
* 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
@ -583,10 +584,19 @@ class ImportCsv extends ModeleImports
//var_dump($objimport->array_import_convertvalue); exit;
// Build SQL request
$sql ='INSERT INTO '.$tablename.'('.$listfields.', import_key';
if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$objimport->array_import_tables_creator[0][$alias];
$sql.=') VALUES('.$listvalues.", '".$importid."'";
if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$user->id;
if (! tablewithentity($tablename))
{
$sql ='INSERT INTO '.$tablename.'('.$listfields.', import_key';
if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$objimport->array_import_tables_creator[0][$alias];
$sql.=') VALUES('.$listvalues.", '".$importid."'";
}
else
{
$sql ='INSERT INTO '.$tablename.'('.$listfields.', import_key, entity';
if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$objimport->array_import_tables_creator[0][$alias];
$sql.=') VALUES('.$listvalues.", '".$importid."', ".$conf->entity ;
}
if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$user->id;
$sql.=')';
dol_syslog("import_csv.modules sql=".$sql);
@ -637,4 +647,34 @@ function cleansep($value)
return str_replace(',','/',$value);
};
/**
* Returns if a table contains entity column
*
* @param string $table Table name
* @return int 1 if table contains entity, 0 if not and -1 if error
*/
function tablewithentity($table)
{
global $db;
$sql = "SHOW COLUMNS FROM ".$table." LIKE 'entity'";
$resql=$db->query($sql);
if ($resql)
{
$numrows=$db->num_rows($resql);
if ($numrows)
{
return 1;
}
else
{
return 0;
}
}
else
{
return -1;
}
}
?>

View File

@ -178,6 +178,63 @@ 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]="CatProdList"; // 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");
}
if (! empty($conf->societe->enabled))
{
//Customers
$r++;
$this->import_code[$r]=$this->rights_class.'_'.$r;
$this->import_label[$r]="CatCusList"; // 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_societe');
$this->import_fields_array[$r]=array('cs.fk_categorie'=>"Category*",'cs.fk_societe'=>"ThirdParty*"
);
$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_societe'=>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_societe'=>"MyBigCompany");
}
if (! empty($conf->fournisseur->enabled))
{
// Suppliers
$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('cs'=>MAIN_DB_PREFIX.'categorie_fournisseur');
$this->import_fields_array[$r]=array('cs.fk_categorie'=>"Category*",'cs.fk_societe'=>"Supplier*"
);
$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_societe'=>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_societe'=>"MyBigCompany");
}
}

View File

@ -223,6 +223,28 @@ class modProduct extends DolibarrModules
'sp.remise_percent'=>'0'
);
}
if (! empty($conf->stock->enabled))
{
// Import stocks
$r++;
$this->import_code[$r]=$this->rights_class.'_'.$r;
$this->import_label[$r]="Stocks"; // Translation key
$this->import_icon[$r]='stock';
$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('ps'=>MAIN_DB_PREFIX.'product_stock');
$this->import_fields_array[$r]=array('ps.fk_product'=>"Product*",'ps.fk_entrepot'=>"Warehouse*",
'ps.reel'=>"Stock*",'ps.pmp'=>"PMP"
);
$this->import_convertvalue_array[$r]=array(
'ps.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'product'),
'ps.fk_entrepot'=>array('rule'=>'fetchidfromref','classfile'=>'/product/stock/class/entrepot.class.php','class'=>'Entrepot','method'=>'fetch','element'=>'label')
);
$this->import_examplevalues_array[$r]=array('ps.fk_product'=>"PREF123456",'ps.fk_entrepot'=>"ALM001",
'ps.reel'=>"10",'ps.pmp'=>"25"
);
}
}

View File

@ -772,6 +772,9 @@ 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;
ALTER TABLE llx_categorie_societe ADD COLUMN import_key varchar(14) AFTER fk_societe;
ALTER TABLE llx_categorie_fournisseur ADD COLUMN import_key varchar(14) AFTER fk_societe;
-- Export filter
ALTER TABLE llx_export_model ADD COLUMN filter text AFTER field;

View File

@ -2,6 +2,7 @@
-- Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2012 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2012 Regis Houssin <regis@dolibarr.fr>
-- Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
--
-- 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
@ -21,5 +22,6 @@
create table llx_categorie_fournisseur
(
fk_categorie integer NOT NULL,
fk_societe integer NOT NULL
fk_societe integer NOT NUL,
import_key varchar(14)
)ENGINE=innodb;

View File

@ -1,6 +1,7 @@
-- ============================================================================
-- Copyright (C) 2005 Brice Davoleau <e1davole@iu-vannes.fr>
-- Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
-- Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
-- Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
--
-- 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;

View File

@ -1,5 +1,6 @@
-- ============================================================================
-- Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
-- Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
--
-- 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
@ -19,5 +20,6 @@
create table llx_categorie_societe
(
fk_categorie integer NOT NULL,
fk_societe integer NOT NULL
fk_societe integer NOT NULL,
import_key varchar(14)
)ENGINE=innodb;

View File

@ -240,13 +240,26 @@ class Entrepot extends CommonObject
* Load warehouse data
*
* @param int $id Warehouse id
* @param string $ref Warehouse label
* @return int >0 if OK, <0 if KO
*/
function fetch($id)
function fetch($id, $ref='')
{
global $conf;
$sql = "SELECT rowid, label, description, statut, lieu, address, cp as zip, ville as town, fk_pays as country_id";
$sql .= " FROM ".MAIN_DB_PREFIX."entrepot";
$sql .= " WHERE rowid = ".$id;
if ($id)
{
$sql.= " WHERE rowid = '".$id."'";
}
else
{
$sql.= " WHERE entity = " .$conf->entity;
if ($ref) $sql.= " AND label = '".$this->db->escape($ref)."'";
}
dol_syslog(get_class($this)."::fetch sql=".$sql);
$result = $this->db->query($sql);