diff --git a/htdocs/exports/export.class.php b/htdocs/exports/export.class.php index b5b327238f4..7623bd2eceb 100644 --- a/htdocs/exports/export.class.php +++ b/htdocs/exports/export.class.php @@ -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) diff --git a/htdocs/imports/ajaximport.php b/htdocs/imports/ajaximport.php index ef75ffeb9ae..2b3da7b417f 100644 --- a/htdocs/imports/ajaximport.php +++ b/htdocs/imports/ajaximport.php @@ -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); ?> diff --git a/htdocs/imports/emptyexample.php b/htdocs/imports/emptyexample.php index a9189c32753..2c00b1e0f0d 100644 --- a/htdocs/imports/emptyexample.php +++ b/htdocs/imports/emptyexample.php @@ -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 'Export agenda cal'; } +function llxHeader() { print 'Build an import example file'; } function llxFooter() { print ''; } // Check exportkey diff --git a/htdocs/imports/import.class.php b/htdocs/imports/import.class.php index 3e1367e1972..d907e267a31 100644 --- a/htdocs/imports/import.class.php +++ b/htdocs/imports/import.class.php @@ -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; + } + } + } ?> diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php index 8721f628a9f..4ca236ffcb1 100644 --- a/htdocs/imports/import.php +++ b/htdocs/imports/import.php @@ -502,7 +502,7 @@ if ($step == 3 && $datatoimport) 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; diff --git a/htdocs/langs/en_US/compta.lang b/htdocs/langs/en_US/compta.lang index e73177c5acd..a486272252e 100644 --- a/htdocs/langs/en_US/compta.lang +++ b/htdocs/langs/en_US/compta.lang @@ -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 diff --git a/htdocs/langs/en_US/exports.lang b/htdocs/langs/en_US/exports.lang index 3f092520bbf..8c082ba6a54 100644 --- a/htdocs/langs/en_US/exports.lang +++ b/htdocs/langs/en_US/exports.lang @@ -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 \ No newline at end of file +ExampleOfImportFile=Example_of_import_file +ErrorImportDuplicateProfil=Failed to save this import profile with this name. An existing profile already exists with this name. diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 62ea083912e..9ced47a1762 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -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 diff --git a/htdocs/langs/fr_FR/exports.lang b/htdocs/langs/fr_FR/exports.lang index 261848d10e5..2175cbcc7e2 100644 --- a/htdocs/langs/fr_FR/exports.lang +++ b/htdocs/langs/fr_FR/exports.lang @@ -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 \ No newline at end of file +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. \ No newline at end of file diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang index ce07266f599..f06f50e3076 100644 --- a/htdocs/langs/fr_FR/products.lang +++ b/htdocs/langs/fr_FR/products.lang @@ -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