Work on import module
This commit is contained in:
parent
87824d4040
commit
caf52993ec
@ -288,8 +288,8 @@ class Export
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Create an export model in database
|
* \brief Save an export model in database
|
||||||
* \param user Objet utilisateur qui cree
|
* \param user Object user that save
|
||||||
*/
|
*/
|
||||||
function create($user)
|
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 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
|
* \return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function delete($user, $notrigger=0)
|
function delete($user, $notrigger=0)
|
||||||
|
|||||||
@ -36,7 +36,7 @@ set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs');
|
|||||||
$entityCookieName = "DOLENTITYID_dolibarr";
|
$entityCookieName = "DOLENTITYID_dolibarr";
|
||||||
if (isset($_COOKIE[$entityCookieName])) $_SESSION["dol_entity"] = $_COOKIE[$entityCookieName];
|
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."/imports/import.class.php");
|
||||||
require_once(DOL_DOCUMENT_ROOT.'/includes/modules/import/modules_import.php');
|
require_once(DOL_DOCUMENT_ROOT.'/includes/modules/import/modules_import.php');
|
||||||
|
|
||||||
@ -47,28 +47,31 @@ $colonne=$part[0];
|
|||||||
$list=$part[1];
|
$list=$part[1];
|
||||||
dol_syslog('AjaxImport column='.$colonne.' list='.$list);
|
dol_syslog('AjaxImport column='.$colonne.' list='.$list);
|
||||||
|
|
||||||
// Init object $objimport that describe the predefined import
|
$fuser=new User($db);
|
||||||
$fuser->id=$_GET['userid'];
|
$fuser->id=$_GET['userid'];
|
||||||
$fuser->fetch();
|
$fuser->fetch();
|
||||||
|
|
||||||
|
// Init object $objimport that describe the predefined import
|
||||||
$objimport=new Import($db);
|
$objimport=new Import($db);
|
||||||
$datatoimport=isset($_GET["datatoimport"])? $_GET["datatoimport"] : (isset($_POST["datatoimport"])?$_POST["datatoimport"]:'');
|
$datatoimport=isset($_GET["datatoimport"])? $_GET["datatoimport"] : (isset($_POST["datatoimport"])?$_POST["datatoimport"]:'');
|
||||||
$objimport->load_arrays($fuser,$datatoimport);
|
$objimport->load_arrays($fuser,$datatoimport);
|
||||||
|
|
||||||
|
|
||||||
// Init targets fields array
|
// Init targets fields array
|
||||||
$fieldstarget=$objimport->array_import_fields[0];
|
$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();
|
$array_match_file_to_database=array();
|
||||||
$listelem=split(',',$list);
|
$fieldsarray=split(',',$list);
|
||||||
$pos=0;
|
$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 fields at position $pos and put it into $namefield
|
||||||
|
|
||||||
// Get name of database field at position $pos into $namefield
|
|
||||||
$posbis=0;$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)
|
if ($posbis < $pos)
|
||||||
{
|
{
|
||||||
$posbis++;
|
$posbis++;
|
||||||
@ -76,16 +79,22 @@ foreach($listelem as $fieldnb)
|
|||||||
}
|
}
|
||||||
// We found the key of targets that is at position pos
|
// We found the key of targets that is at position pos
|
||||||
$namefield=$key;
|
$namefield=$key;
|
||||||
|
//dol_syslog('AjaxImport Field name found for file field nb '.$fieldnb.'='.$namefield);
|
||||||
|
|
||||||
break;
|
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++;
|
$pos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We save new matching in session
|
// We save new matching in session
|
||||||
$_SESSION["dol_array_match_file_to_database"]=$array_match_file_to_database;
|
$_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);
|
||||||
dol_syslog('AjaxImport dol_array_match_file_to_database='.var_export($array_match_file_to_database,true));
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -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."/imports/import.class.php");
|
||||||
require_once(DOL_DOCUMENT_ROOT.'/includes/modules/import/modules_import.php');
|
require_once(DOL_DOCUMENT_ROOT.'/includes/modules/import/modules_import.php');
|
||||||
|
|
||||||
|
$langs->load("exports");
|
||||||
|
|
||||||
// C'est un wrapper, donc header vierge
|
// 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>'; }
|
function llxFooter() { print '</body></html>'; }
|
||||||
|
|
||||||
// Check exportkey
|
// Check exportkey
|
||||||
|
|||||||
@ -193,5 +193,135 @@ class Import
|
|||||||
|
|
||||||
return $s;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -502,7 +502,7 @@ if ($step == 3 && $datatoimport)
|
|||||||
|
|
||||||
llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones');
|
llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones');
|
||||||
|
|
||||||
$param='step=3&datatoimport='.$datatoimport.'&filetoimport='.urlencode($_GET["filetoimport"]);
|
$param='step=3&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport);
|
||||||
|
|
||||||
$h = 0;
|
$h = 0;
|
||||||
|
|
||||||
|
|||||||
@ -27,8 +27,8 @@ Debit=Debit
|
|||||||
Credit=Credit
|
Credit=Credit
|
||||||
Withdrawal=Withdrawal
|
Withdrawal=Withdrawal
|
||||||
Withdrawals=Withdrawals
|
Withdrawals=Withdrawals
|
||||||
AmountHTVATRealReceived=HT collected
|
AmountHTVATRealReceived=Net collected
|
||||||
AmountHTVATRealPaid=HT paid
|
AmountHTVATRealPaid=Net paid
|
||||||
VATToPay=VAT sells
|
VATToPay=VAT sells
|
||||||
VATReceived=VAT received
|
VATReceived=VAT received
|
||||||
VATToCollect=VAT purchases
|
VATToCollect=VAT purchases
|
||||||
|
|||||||
@ -64,4 +64,5 @@ FieldsInSourceFile=Fields in source file
|
|||||||
FieldsInTargetDatabase=Target fields in Dolibarr database
|
FieldsInTargetDatabase=Target fields in Dolibarr database
|
||||||
NoFields=No fields
|
NoFields=No fields
|
||||||
MoveField=Move field column number %s
|
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.
|
||||||
|
|||||||
@ -56,6 +56,8 @@ ProductStatusNotOnSellShort=Out of sell
|
|||||||
UpdatePrice=Update price
|
UpdatePrice=Update price
|
||||||
AppliedPricesFrom=Applied prices from
|
AppliedPricesFrom=Applied prices from
|
||||||
SellingPrice=Selling price
|
SellingPrice=Selling price
|
||||||
|
SellingPriceHT=Selling price (net of tax)
|
||||||
|
SellingPriceTTC=Selling price (inc. tax)
|
||||||
PublicPrice=Public price
|
PublicPrice=Public price
|
||||||
CurrentPrice=Current price
|
CurrentPrice=Current price
|
||||||
NewPrice=New price
|
NewPrice=New price
|
||||||
|
|||||||
@ -64,4 +64,5 @@ FieldsInSourceFile=Champs dans le fichier source
|
|||||||
FieldsInTargetDatabase=Champs cibles dans la base Dolibarr
|
FieldsInTargetDatabase=Champs cibles dans la base Dolibarr
|
||||||
NoFields=Aucun champ
|
NoFields=Aucun champ
|
||||||
MoveField=Déplacer champ colonne numéro %s
|
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.
|
||||||
@ -56,6 +56,8 @@ ProductStatusNotOnSellShort=Hors vente
|
|||||||
UpdatePrice=Changer le prix
|
UpdatePrice=Changer le prix
|
||||||
AppliedPricesFrom=Prix de vente pratiqués à partir du
|
AppliedPricesFrom=Prix de vente pratiqués à partir du
|
||||||
SellingPrice=Prix de vente
|
SellingPrice=Prix de vente
|
||||||
|
SellingPriceHT=Prix de vente HT
|
||||||
|
SellingPriceTTC=Prix de vente TTC
|
||||||
PublicPrice=Prix public
|
PublicPrice=Prix public
|
||||||
CurrentPrice=Prix actuel
|
CurrentPrice=Prix actuel
|
||||||
NewPrice=Nouveau prix
|
NewPrice=Nouveau prix
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user