2
0
forked from Wavyzz/dolibarr

Work on import module

This commit is contained in:
Laurent Destailleur
2009-10-17 13:12:55 +00:00
parent 9f419a7d50
commit b8e871d97f
8 changed files with 134 additions and 125 deletions

View File

@@ -272,7 +272,7 @@ class ImportCsv extends ModeleImports
*/
function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid)
{
global $langs,$conf;
global $langs,$conf,$user;
$error=0;
$warning=0;
@@ -298,7 +298,7 @@ class ImportCsv extends ModeleImports
else
{
// For each table to insert, me make a separate insert
foreach($objimport->array_import_tables[0] as $alias=>$tablename)
foreach($objimport->array_import_tables[0] as $alias => $tablename)
{
// Build sql request
$sql='';
@@ -338,12 +338,19 @@ class ImportCsv extends ModeleImports
$errorforthistable++;
$error++;
}
// Test format
// TODO
// Other tests
// TODO...
// Test format only if field is not a missing mandatory field
else {
if (! empty($objimport->array_import_regex[0][$val]) && ! eregi($objimport->array_import_regex[0][$val],$newval))
{
$this->errors[$error]['lib']=$langs->trans('ErrorWrongValueForField',$key,$newval,$objimport->array_import_regex[0][$val]);
$this->errors[$error]['type']='REGEX';
$errorforthistable++;
$error++;
}
// Other tests
// ...
}
}
$i++;
}
@@ -351,7 +358,12 @@ class ImportCsv extends ModeleImports
{
if ($listfields)
{
$sql='INSERT INTO '.$tablename.'('.$listfields.', import_key) VALUES('.$listvalues.", '".$importid."')";
// 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;
$sql.=')';
dol_syslog("import_csv.modules sql=".$sql);
//print '> '.join(',',$arrayrecord);

View File

@@ -152,15 +152,13 @@ class modProduit extends DolibarrModules
$r++;
$this->import_code[$r]=$this->rights_class.'_'.$r;
$this->import_label[$r]="Products"; // Translation key
//$this->import_permission[$r]=array(array("societe","import"));
$this->import_tables_array[$r]=array('p'=>MAIN_DB_PREFIX.'product');
$this->import_fields_array[$r]=array('p.ref'=>"Ref*",'p.label'=>"Label*",'p.description'=>"Description",'p.note'=>"Note",'p.price'=>"SellingPriceHT",'p.price_ttc'=>"SellingPriceTTC",'p.tva_tx'=>'VAT','p.envente'=>"OnSell*",'p.duration'=>"Duration");
$this->import_entities_array[$r]=array('p.ref'=>"product",'p.label'=>"product",'p.description'=>"product",'p.note'=>"product",'p.price'=>"product",'p.price_ttc'=>"product",'p.tva_tx'=>'product','p.envente'=>"product",'p.duration'=>"product");
$this->import_examplevalues_array[$r]=array('p.ref'=>"PR123456",'p.label'=>"My product",'p.description'=>"This is a description example for record",'p.note'=>"Some note",'p.price'=>"100",'p.price_ttc'=>"110",'p.tva_tx'=>'10','p.envente'=>"0 or 1",'p.duration'=>"1y");
//$this->import_sql_start[$r]='INSERT INTO '.MAIN_DB_PREFIX.'product as p';
//$this->import_sql_end[$r] ='';
$this->import_tables_creator_array[$r]=array('p'=>'fk_user_author'); // Fields to store import user id
$this->import_fields_array[$r]=array('p.ref'=>"Ref*",'p.label'=>"Label*",'p.description'=>"Description",'p.note'=>"Note",'p.price'=>"SellingPriceHT",'p.price_ttc'=>"SellingPriceTTC",'p.tva_tx'=>'VAT','p.envente'=>"OnSell*",'p.fk_product_type'=>"Type*",'p.finished'=>'Nature','p.duration'=>"Duration",'p.weight'=>"Weight",'p.volume'=>"Volume",'p.datec'=>'DateCreation*');
//if ($conf->barcode->enabled) $this->import_fields_array[$r]=
$this->import_entities_array[$r]=array('p.ref'=>"product",'p.label'=>"product",'p.description'=>"product",'p.note'=>"product",'p.price'=>"product",'p.price_ttc'=>"product",'p.tva_tx'=>'product','p.envente'=>"product",'p.fk_product_type'=>"product",'p.finished'=>"product",'p.duration'=>"product",'p.weight'=>'product','p.volume'=>'product','p.datec'=>"product");
$this->import_regex_array[$r]=array('p.ref'=>'[^ ]','p.envente'=>'^[0|1]','p.fk_product_type'=>'^[0|1]','p.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$');
$this->import_examplevalues_array[$r]=array('p.ref'=>"PR123456",'p.label'=>"My product",'p.description'=>"This is a description example for record",'p.note'=>"Some note",'p.price'=>"100",'p.price_ttc'=>"110",'p.tva_tx'=>'10','p.envente'=>"0 or 1",'p.fk_product_type'=>"0 for product, 1 for service",'p.finished'=>'','p.duration'=>"1y",'p.datec'=>'2008-12-31');
}