Work on import module

This commit is contained in:
Laurent Destailleur 2009-09-12 02:07:25 +00:00
parent 87824d4040
commit caf52993ec
10 changed files with 170 additions and 23 deletions

View File

@ -288,8 +288,8 @@ class Export
}
/**
* \brief Create an export model in database
* \param user Objet utilisateur qui cree
* \brief Save an export model in database
* \param user Object user that save
*/
function create($user)
{
@ -359,9 +359,9 @@ class Export
/**
* \brief Delete object in database
* \brief Delete object in database
* \param user User that delete
* \param notrigger 0=launch triggers after, 1=disable triggers
* \param notrigger 0=launch triggers after, 1=disable triggers
* \return int <0 if KO, >0 if OK
*/
function delete($user, $notrigger=0)

View File

@ -36,7 +36,7 @@ set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs');
$entityCookieName = "DOLENTITYID_dolibarr";
if (isset($_COOKIE[$entityCookieName])) $_SESSION["dol_entity"] = $_COOKIE[$entityCookieName];
require('../master.inc.php');
require('../main.inc.php');
require_once(DOL_DOCUMENT_ROOT."/imports/import.class.php");
require_once(DOL_DOCUMENT_ROOT.'/includes/modules/import/modules_import.php');
@ -47,28 +47,31 @@ $colonne=$part[0];
$list=$part[1];
dol_syslog('AjaxImport column='.$colonne.' list='.$list);
// Init object $objimport that describe the predefined import
$fuser=new User($db);
$fuser->id=$_GET['userid'];
$fuser->fetch();
// Init object $objimport that describe the predefined import
$objimport=new Import($db);
$datatoimport=isset($_GET["datatoimport"])? $_GET["datatoimport"] : (isset($_POST["datatoimport"])?$_POST["datatoimport"]:'');
$objimport->load_arrays($fuser,$datatoimport);
// Init targets fields array
$fieldstarget=$objimport->array_import_fields[0];
// We redefine array_match_file_to_database
// Reinit match arrays. We redefine array_match_file_to_database
$serialized_array_match_file_to_database='';
$array_match_file_to_database=array();
$listelem=split(',',$list);
$fieldsarray=split(',',$list);
$pos=0;
foreach($listelem as $fieldnb)
foreach($fieldsarray as $fieldnb) // For each elem in list. fieldnb start from 1 to ...
{
//dol_syslog("Fieldnb in file=".$fieldnb." => keynb in targets=".$pos);
// Get name of database field at position $pos into $namefield
// Get name of database fields at position $pos and put it into $namefield
$posbis=0;$namefield='';
foreach($fieldstarget as $key => $val)
foreach($fieldstarget as $key => $val) // key: val:
{
//dol_syslog('AjaxImport key='.$key.' val='.$val);
if ($posbis < $pos)
{
$posbis++;
@ -76,16 +79,22 @@ foreach($listelem as $fieldnb)
}
// We found the key of targets that is at position pos
$namefield=$key;
//dol_syslog('AjaxImport Field name found for file field nb '.$fieldnb.'='.$namefield);
break;
}
if (! empty($fieldnb)) $array_match_file_to_database[$fieldnb]=$namefield;
if ($fieldnb && $namefield)
{
$array_match_file_to_database[$fieldnb]=$namefield;
if ($serialized_array_match_file_to_database) $serialized_array_match_file_to_database.=',';
$serialized_array_match_file_to_database.=($fieldnb.'='.$namefield);
}
$pos++;
}
// We save new matching in session
$_SESSION["dol_array_match_file_to_database"]=$array_match_file_to_database;
dol_syslog('AjaxImport dol_array_match_file_to_database='.var_export($array_match_file_to_database,true));
$_SESSION["dol_array_match_file_to_database"]=$serialized_array_match_file_to_database;
dol_syslog('AjaxImport dol_array_match_file_to_database='.$serialized_array_match_file_to_database);
?>

View File

@ -34,8 +34,10 @@ require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
require_once(DOL_DOCUMENT_ROOT."/imports/import.class.php");
require_once(DOL_DOCUMENT_ROOT.'/includes/modules/import/modules_import.php');
$langs->load("exports");
// C'est un wrapper, donc header vierge
function llxHeader() { print '<html><title>Export agenda cal</title><body>'; }
function llxHeader() { print '<html><title>Build an import example file</title><body>'; }
function llxFooter() { print '</body></html>'; }
// Check exportkey

View File

@ -193,5 +193,135 @@ class Import
return $s;
}
/**
* \brief Save an export model in database
* \param user Object user that save
*/
function create($user)
{
global $conf;
dol_syslog("Import.class.php::create");
// Check parameters
if (empty($this->model_name)) { $this->error='ErrorWrongParameters'; return -1; }
if (empty($this->datatoimport)) { $this->error='ErrorWrongParameters'; return -1; }
if (empty($this->hexa)) { $this->error='ErrorWrongParameters'; return -1; }
$this->db->begin();
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'import_model (';
$sql.= 'label, type, field)';
$sql.= " VALUES ('".$this->model_name."', '".$this->datatoimport."', '".$this->hexa."')";
dol_syslog("Import::create sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$this->db->commit();
return 1;
}
else
{
$this->error=$this->db->lasterror();
$this->errno=$this->db->lasterrno();
dol_syslog("Import::create error ".$this->error, LOG_ERR);
$this->db->rollback();
return -1;
}
}
/**
* \brief Load an import profil from database
* \param rowid id of profil to load
*/
function fetch($id)
{
$sql = 'SELECT em.rowid, em.field, em.label, em.type';
$sql.= ' FROM '.MAIN_DB_PREFIX.'import_model as em';
$sql.= ' WHERE em.rowid = '.$id;
dol_syslog("Import::fetch sql=".$sql, LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
$obj = $this->db->fetch_object($result);
if ($obj)
{
$this->id = $obj->rowid;
$this->hexa = $obj->field;
$this->model_name = $obj->label;
$this->datatoimport = $obj->type;
$this->fk_user = $obj->fk_user;
return 1;
}
else
{
$this->error="Model not found";
return -2;
}
}
else
{
dol_print_error($this->db);
return -3;
}
}
/**
* \brief Delete object in database
* \param user User that delete
* \param notrigger 0=launch triggers after, 1=disable triggers
* \return int <0 if KO, >0 if OK
*/
function delete($user, $notrigger=0)
{
global $conf, $langs;
$error=0;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."import_model";
$sql.= " WHERE rowid=".$this->id;
$this->db->begin();
dol_syslog(get_class($this)."::delete sql=".$sql);
$resql = $this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
if (! $error)
{
if (! $notrigger)
{
// Uncomment this and change MYOBJECT to your own tag if you
// want this action call a trigger.
//// Call triggers
//include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
//$interface=new Interfaces($this->db);
//$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
//if ($result < 0) { $error++; $this->errors=$interface->errors; }
//// End call triggers
}
}
// Commit or rollback
if ($error)
{
foreach($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg);
}
$this->db->rollback();
return -1*$error;
}
else
{
$this->db->commit();
return 1;
}
}
}
?>

View File

@ -502,7 +502,7 @@ if ($step == 3 && $datatoimport)
llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:M&oacute;dulo_Importaciones');
$param='step=3&datatoimport='.$datatoimport.'&filetoimport='.urlencode($_GET["filetoimport"]);
$param='step=3&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport);
$h = 0;

View File

@ -27,8 +27,8 @@ Debit=Debit
Credit=Credit
Withdrawal=Withdrawal
Withdrawals=Withdrawals
AmountHTVATRealReceived=HT collected
AmountHTVATRealPaid=HT paid
AmountHTVATRealReceived=Net collected
AmountHTVATRealPaid=Net paid
VATToPay=VAT sells
VATReceived=VAT received
VATToCollect=VAT purchases

View File

@ -64,4 +64,5 @@ FieldsInSourceFile=Fields in source file
FieldsInTargetDatabase=Target fields in Dolibarr database
NoFields=No fields
MoveField=Move field column number %s
ExampleOfImportFile=Example_of_import_file
ExampleOfImportFile=Example_of_import_file
ErrorImportDuplicateProfil=Failed to save this import profile with this name. An existing profile already exists with this name.

View File

@ -56,6 +56,8 @@ ProductStatusNotOnSellShort=Out of sell
UpdatePrice=Update price
AppliedPricesFrom=Applied prices from
SellingPrice=Selling price
SellingPriceHT=Selling price (net of tax)
SellingPriceTTC=Selling price (inc. tax)
PublicPrice=Public price
CurrentPrice=Current price
NewPrice=New price

View File

@ -64,4 +64,5 @@ FieldsInSourceFile=Champs dans le fichier source
FieldsInTargetDatabase=Champs cibles dans la base Dolibarr
NoFields=Aucun champ
MoveField=Déplacer champ colonne numéro %s
ExampleOfImportFile=Exemple_de_fichier_import
ExampleOfImportFile=Exemple_de_fichier_import
ErrorImportDuplicateProfil=Impossible de sauvegarder le profil d'import sous ce nom. Un profil existant existe déjà pour ce nom.

View File

@ -56,6 +56,8 @@ ProductStatusNotOnSellShort=Hors vente
UpdatePrice=Changer le prix
AppliedPricesFrom=Prix de vente pratiqués à partir du
SellingPrice=Prix de vente
SellingPriceHT=Prix de vente HT
SellingPriceTTC=Prix de vente TTC
PublicPrice=Prix public
CurrentPrice=Prix actuel
NewPrice=Nouveau prix