diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php index 50f82e5bb56..1dfd94036da 100644 --- a/htdocs/core/modules/import/import_csv.modules.php +++ b/htdocs/core/modules/import/import_csv.modules.php @@ -31,16 +31,19 @@ require_once(DOL_DOCUMENT_ROOT ."/core/modules/import/modules_import.php"); */ class ImportCsv extends ModeleImports { - var $id; - var $error; + var $db; + var $datatoimport; + + var $error=''; var $errors=array(); - var $label; - var $extension; - var $version; + var $id; // Id of driver + var $label; // Label of driver + var $extension; // Extension of files imported by driver + var $version; // Version of driver - var $label_lib; - var $version_lib; + var $label_lib; // Label of external lib used by driver + var $version_lib; // Version of external lib used by driver var $separator; @@ -53,9 +56,10 @@ class ImportCsv extends ModeleImports /** * Constructor * - * @param DoliDB $db Database handler + * @param DoliDB $db Database handler + * @param string $datatoimport String code describing import set (ex: 'societe_1') */ - function ImportCsv($db) + function ImportCsv($db,$datatoimport) { global $conf,$langs; $this->db = $db; @@ -75,6 +79,9 @@ class ImportCsv extends ModeleImports // If driver use an external library, put its name here $this->label_lib='Dolibarr'; $this->version_lib=DOL_VERSION; + + $this->datatoimport=$datatoimport; + if (preg_match('/^societe_/',$datatoimport)) $this->thirpartyobject=new Societe($this->db); } function getDriverId() @@ -287,6 +294,7 @@ class ImportCsv extends ModeleImports function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid) { global $langs,$conf,$user; + global $thirdparty_static; // Specifi to thirdparty import $error=0; $warning=0; @@ -392,6 +400,42 @@ class ImportCsv extends ModeleImports { if (empty($newval)) $newval='0'; } + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifnull') + { + if (empty($newval) || $newval='auto') + { + $this->thirpartyobject->get_codeclient(0,0); + $newval=$this->thirpartyobject->code_client; + //print 'code_client='.$newval; + } + } + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifnull') + { + if (empty($newval) || $newval='auto') + { + $newval=$this->thirpartyobject->get_codefournisseur(0,1); + $newval=$this->thirpartyobject->code_fournisseur; + //print 'code_fournisseur='.$newval; + } + } + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifnull') + { + if (empty($newval) || $newval='auto') + { + $this->thirpartyobject->get_codecompta('customer'); + $newval=$this->thirpartyobject->code_compta; + //print 'code_compta='.$newval; + } + } + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifnull') + { + if (empty($newval) || $newval='auto') + { + $this->thirpartyobject->get_codecompta('supplier'); + $newval=$this->thirpartyobject->code_compta_fournisseur; + //print 'code_compta_fournisseur='.$newval; + } + } //print 'Val to use as insert is '.$newval.'
'; } diff --git a/htdocs/core/modules/import/modules_import.php b/htdocs/core/modules/import/modules_import.php index 171a6f91edf..4826f807a9a 100644 --- a/htdocs/core/modules/import/modules_import.php +++ b/htdocs/core/modules/import/modules_import.php @@ -26,19 +26,30 @@ require_once(DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php'); /** - * \class ModeleImports - * \brief Parent class for import file readers + * Parent class for import file readers */ class ModeleImports { + var $db; + var $datatoimport; + var $error=''; - var $driverlabel=array(); - var $driverdesc=array(); - var $driverversion=array(); + var $id; // Id of driver + var $label; // Label of driver + var $extension; // Extension of files imported by driver + var $version; // Version of driver - var $liblabel=array(); - var $libversion=array(); + var $label_lib; // Label of external lib used by driver + var $version_lib; // Version of external lib used by driver + + // Array of all drivers + var $_driverlabel=array(); + var $_driverdesc=array(); + var $_driverversion=array(); + + var $_liblabel=array(); + var $_libversion=array(); /** @@ -49,8 +60,9 @@ class ModeleImports } /** - * \brief Charge en memoire et renvoie la liste des modeles actifs - * \param db Handler de base + * Charge en memoire et renvoie la liste des modeles actifs + * + * @param DoliDB $db Handler de base */ function liste_modeles($db) { @@ -75,29 +87,31 @@ class ModeleImports $classname = "Import".ucfirst($moduleid); require_once($file); - $module = new $classname($db); + $module = new $classname($db,''); // Picto $this->picto[$module->id]=$module->picto; // Driver properties - $this->driverlabel[$module->id]=$module->getDriverLabel(); - $this->driverdesc[$module->id]=$module->getDriverDesc(); - $this->driverversion[$module->id]=$module->getDriverVersion(); + $this->_driverlabel[$module->id]=$module->getDriverLabel(); + $this->_driverdesc[$module->id]=$module->getDriverDesc(); + $this->_driverversion[$module->id]=$module->getDriverVersion(); // If use an external lib - $this->liblabel[$module->id]=$module->getLibLabel(); - $this->libversion[$module->id]=$module->getLibVersion(); + $this->_liblabel[$module->id]=$module->getLibLabel(); + $this->_libversion[$module->id]=$module->getLibVersion(); $i++; } } } - return array_keys($this->driverlabel); + return array_keys($this->_driverlabel); } /** - * \brief Return picto of import driver + * Return picto of import driver + * + * @return string */ function getPicto($key) { @@ -105,43 +119,53 @@ class ModeleImports } /** - * \brief Renvoi libelle d'un driver import + * Renvoi libelle d'un driver import + * + * @return string */ function getDriverLabel($key) { - return $this->driverlabel[$key]; + return $this->_driverlabel[$key]; } /** - * \brief Renvoi la description d'un driver import + * Renvoi la description d'un driver import + * + * @return string */ function getDriverDesc($key) { - return $this->driverdesc[$key]; + return $this->_driverdesc[$key]; } /** - * \brief Renvoi version d'un driver import + * Renvoi version d'un driver import + * + * @return string */ function getDriverVersion($key) { - return $this->driverversion[$key]; + return $this->_driverversion[$key]; } /** - * \brief Renvoi libelle de librairie externe du driver + * Renvoi libelle de librairie externe du driver + * + * @return string */ function getLibLabel($key) { - return $this->liblabel[$key]; + return $this->_liblabel[$key]; } /** - * \brief Renvoi version de librairie externe du driver + * Renvoi version de librairie externe du driver + * + * @return string */ function getLibVersion($key) { - return $this->libversion[$key]; + return $this->_libversion[$key]; } } diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php index 89241f26dca..a1471ed6f70 100644 --- a/htdocs/core/modules/modSociete.class.php +++ b/htdocs/core/modules/modSociete.class.php @@ -270,7 +270,7 @@ class modSociete extends DolibarrModules $this->import_icon[$r]='company'; $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('s'=>MAIN_DB_PREFIX.'societe','extra'=>MAIN_DB_PREFIX.'societe_extrafields'); // List of tables to insert into (insert done in same order) - $this->import_fields_array[$r]=array('s.nom'=>"Name*",'s.status'=>"Status",'s.client'=>"Customer*",'s.fournisseur'=>"Supplier*",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",'s.address'=>"Address",'s.cp'=>"Zip",'s.ville'=>"Town",'s.fk_pays'=>"CountryCode",'s.tel'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",'s.siret'=>"IdProf1",'s.siren'=>"IdProf2",'s.ape'=>"IdProf3",'s.idprof4'=>"IdProf4",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note'=>"Note",'s.fk_typent'=>"ThirdPartyType",'s.fk_effectif'=>"Effectif","s.fk_forme_juridique"=>"JuridicalStatus",'s.fk_prospectlevel'=>'ProspectLevel','s.fk_stcomm'=>'ProspectStatus','s.default_lang'=>'DefaultLanguage','s.barcode'=>'BarCode','s.datec'=>"DateCreation"); + $this->import_fields_array[$r]=array('s.nom'=>"Name*",'s.status'=>"Status",'s.client'=>"Customer*",'s.fournisseur'=>"Supplier*",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",'s.code_compta'=>"CustomerAccountancyCode",'s.code_compta_fournisseur'=>"SupplierAccountancyCode",'s.address'=>"Address",'s.cp'=>"Zip",'s.ville'=>"Town",'s.fk_pays'=>"CountryCode",'s.tel'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",'s.siret'=>"IdProf1",'s.siren'=>"IdProf2",'s.ape'=>"IdProf3",'s.idprof4'=>"IdProf4",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note'=>"Note",'s.fk_typent'=>"ThirdPartyType",'s.fk_effectif'=>"Effectif","s.fk_forme_juridique"=>"JuridicalStatus",'s.fk_prospectlevel'=>'ProspectLevel','s.fk_stcomm'=>'ProspectStatus','s.default_lang'=>'DefaultLanguage','s.barcode'=>'BarCode','s.datec'=>"DateCreation"); // Add extra fields $sql="SELECT name, label FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'company'"; $resql=$this->db->query($sql); @@ -288,11 +288,15 @@ class modSociete extends DolibarrModules $this->import_convertvalue_array[$r]=array( 's.fk_typent'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ctypent.class.php','class'=>'Ctypent','method'=>'fetch','dict'=>'DictionnaryCompanyType'), 's.fk_pays'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/cpays.class.php','class'=>'Cpays','method'=>'fetch','dict'=>'DictionnaryCountry'), - 's.fk_stcomm'=>array('rule'=>'zeroifnull') + 's.fk_stcomm'=>array('rule'=>'zeroifnull'), + 's.code_client'=>array('rule'=>'getcustomercodeifnull'), + 's.code_fournisseur'=>array('rule'=>'getsuppliercodeifnull'), + 's.code_compta'=>array('rule'=>'getcustomeraccountancycodeifnull'), + 's.code_compta_fournisseur'=>array('rule'=>'getsupplieraccountancycodeifnull') ); //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t'); $this->import_regex_array[$r]=array('s.status'=>'^[0|1]','s.client'=>'^[0|1|2|3]','s.fournisseur'=>'^[0|1]','s.fk_typent'=>'id@'.MAIN_DB_PREFIX.'c_typent','s.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$'); - $this->import_examplevalues_array[$r]=array('s.nom'=>"MyBigCompany",'s.status'=>"0 (closed) or 1 (active)",'s.client'=>'0 (no customer no prospect)/1 (customer)/2 (prospect)/3 (customer and prospect)','s.fournisseur'=>'0 or 1','s.datec'=>dol_print_date(mktime(),'%Y-%m-%d'),'s.code_client'=>"CU01-0001",'s.code_fournisseur'=>"SU01-0001",'s.address'=>"61 jump street",'s.cp'=>"123456",'s.ville'=>"Big town",'s.fk_pays'=>'US, FR, DE...','s.tel'=>"0101010101",'s.fax'=>"0101010102",'s.url'=>"http://mycompany.com",'s.email'=>"test@mycompany.com",'s.siret'=>"",'s.siren'=>"",'s.ape'=>"",'s.idprof4'=>"",'s.tva_intra'=>"FR0123456789",'s.capital'=>"10000",'s.note'=>"This is an example of note for record",'s.fk_typent'=>"2",'s.fk_effectif'=>"3","s.fk_forme_juridique"=>"1",'s.fk_prospectlevel'=>'PL_MEDIUM','s.fk_stcomm'=>'0','s.default_lang'=>'en_US','s.barcode'=>'123456789'); + $this->import_examplevalues_array[$r]=array('s.nom'=>"MyBigCompany",'s.status'=>"0 (closed) or 1 (active)",'s.client'=>'0 (no customer no prospect)/1 (customer)/2 (prospect)/3 (customer and prospect)','s.fournisseur'=>'0 or 1','s.datec'=>dol_print_date(mktime(),'%Y-%m-%d'),'s.code_client'=>"CU01-0001 or auto",'s.code_fournisseur'=>"SU01-0001 or auto",'s.address'=>"61 jump street",'s.cp'=>"123456",'s.ville'=>"Big town",'s.fk_pays'=>'US, FR, DE...','s.tel'=>"0101010101",'s.fax'=>"0101010102",'s.url'=>"http://mycompany.com",'s.email'=>"test@mycompany.com",'s.siret'=>"",'s.siren'=>"",'s.ape'=>"",'s.idprof4'=>"",'s.tva_intra'=>"FR0123456789",'s.capital'=>"10000",'s.note'=>"This is an example of note for record",'s.fk_typent'=>"2",'s.fk_effectif'=>"3","s.fk_forme_juridique"=>"1",'s.fk_prospectlevel'=>'PL_MEDIUM','s.fk_stcomm'=>'0','s.default_lang'=>'en_US','s.barcode'=>'123456789'); // Import list of contact and attributes $r++; diff --git a/htdocs/core/modules/societe/mod_codeclient_elephant.php b/htdocs/core/modules/societe/mod_codeclient_elephant.php index 3dd78144dae..3d87eef5085 100644 --- a/htdocs/core/modules/societe/mod_codeclient_elephant.php +++ b/htdocs/core/modules/societe/mod_codeclient_elephant.php @@ -73,7 +73,7 @@ class mod_codeclient_elephant extends ModeleThirdPartyCode $langs->load("companies"); $form = new Form($this->db); - + $disabled = ((! empty($mc->sharings['referent']) && $mc->sharings['referent'] != $conf->entity) ? ' disabled="disabled"' : ''); $texte = $langs->trans('GenericNumRefModelDesc')."
\n"; @@ -153,7 +153,7 @@ class mod_codeclient_elephant extends ModeleThirdPartyCode /** Return next value * * @param objsoc Object third party - * @param $type Client ou fournisseur (1:client, 2:fournisseur) + * @param $type Client ou fournisseur (0:customer, 1:supplier) * @return string Value if OK, '' if module not configured, <0 if KO */ function getNextValue($objsoc=0,$type=-1) @@ -274,7 +274,7 @@ class mod_codeclient_elephant extends ModeleThirdPartyCode { $sql = "SELECT code_client FROM ".MAIN_DB_PREFIX."societe"; $sql.= " WHERE code_client = '".$code."'"; - if ($soc->id > 0) $sql.= " AND rowid != ".$soc->id; + if ($soc->id > 0) $sql.= " AND rowid <> ".$soc->id; $resql=$db->query($sql); if ($resql) diff --git a/htdocs/core/modules/societe/mod_codeclient_monkey.php b/htdocs/core/modules/societe/mod_codeclient_monkey.php index 07c451d6eba..e0453093c39 100644 --- a/htdocs/core/modules/societe/mod_codeclient_monkey.php +++ b/htdocs/core/modules/societe/mod_codeclient_monkey.php @@ -213,12 +213,12 @@ class mod_codeclient_monkey extends ModeleThirdPartyCode function verif_dispo($db, $code, $soc) { global $conf, $mc; - + $sql = "SELECT code_client FROM ".MAIN_DB_PREFIX."societe"; $sql.= " WHERE code_client = '".$code."'"; $sql.= " AND entity IN (".getEntity('societe', 1).")"; - if ($soc->id > 0) $sql.= " AND rowid != ".$soc->id; - + if ($soc->id > 0) $sql.= " AND rowid <> ".$soc->id; + dol_syslog(get_class($this)."::verif_dispo sql=".$sql, LOG_DEBUG); $resql=$db->query($sql); if ($resql) diff --git a/htdocs/core/modules/societe/mod_codecompta_aquarium.php b/htdocs/core/modules/societe/mod_codecompta_aquarium.php index 6be49e535d2..f34b4c59d81 100644 --- a/htdocs/core/modules/societe/mod_codecompta_aquarium.php +++ b/htdocs/core/modules/societe/mod_codecompta_aquarium.php @@ -150,8 +150,8 @@ class mod_codecompta_aquarium extends ModeleAccountancyCode $sql.= " WHERE "; if ($type == 'customer') $sql.= "code_compta"; if ($type == 'supplier') $sql.= "code_compta_fournisseur"; - $sql.= " = '".$code."'"; - $sql.= " AND rowid != ".$societe->id; + $sql.= " = '".$this->db->escape($code)."'"; + if ($societe->id > 0) $sql.= " AND rowid <> ".$societe->id; $resql=$db->query($sql); if ($resql) diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php index e517c50adaa..4450c318467 100644 --- a/htdocs/imports/import.php +++ b/htdocs/imports/import.php @@ -577,7 +577,7 @@ if ($step == 4 && $datatoimport) $file = "import_".$model.".modules.php"; $classname = "Import".ucfirst($model); require_once($dir.$file); - $obj = new $classname($db); + $obj = new $classname($db,$datatoimport); // Load source fields in input file $fieldssource=array(); @@ -1040,7 +1040,7 @@ if ($step == 5 && $datatoimport) $file = "import_".$model.".modules.php"; $classname = "Import".ucfirst($model); require_once($dir.$file); - $obj = new $classname($db); + $obj = new $classname($db,$datatoimport); // Load source fields in input file $fieldssource=array(); @@ -1369,7 +1369,7 @@ if ($step == 6 && $datatoimport) $file = "import_".$model.".modules.php"; $classname = "Import".ucfirst($model); require_once($dir.$file); - $obj = new $classname($db); + $obj = new $classname($db,$datatoimport); // Load source fields in input file $fieldssource=array(); diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 8b00188877d..557f37cbb3a 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1658,9 +1658,12 @@ class Societe extends CommonObject } /** - * Attribut un code client a partir du module de controle des codes. + * Attribut un code client a partir du module de controle des codes. + * Return value is stored into this->code_client * - * @return code_client Code client automatique + * @param Societe $objsoc Object thirdparty + * @param int $type Should be 0 to say customer + * @return void */ function get_codeclient($objsoc=0,$type=0) { @@ -1684,9 +1687,12 @@ class Societe extends CommonObject } /** - * Attribut un code fournisseur a partir du module de controle des codes. + * Attribut un code fournisseur a partir du module de controle des codes. + * Return value is stored into this->code_fournisseur * - * @return code_fournisseur Code fournisseur automatique + * @param Societe $objsoc Object thirdparty + * @param int $type Should be 1 to say supplier + * @return void */ function get_codefournisseur($objsoc=0,$type=1) { @@ -1709,9 +1715,10 @@ class Societe extends CommonObject } /** - * \brief Verifie si un code client est modifiable en fonction des parametres - * du module de controle des codes. - * \return int 0=Non, 1=Oui + * Verifie si un code client est modifiable en fonction des parametres + * du module de controle des codes. + * + * @return int 0=Non, 1=Oui */ function codeclient_modifiable() { @@ -1743,8 +1750,9 @@ class Societe extends CommonObject /** - * \brief Verifie si un code fournisseur est modifiable dans configuration du module de controle des codes - * \return int 0=Non, 1=Oui + * Verifie si un code fournisseur est modifiable dans configuration du module de controle des codes + * + * @return int 0=Non, 1=Oui */ function codefournisseur_modifiable() { @@ -1776,8 +1784,9 @@ class Societe extends CommonObject /** - * \brief Check customer code - * \return int 0 if OK + * Check customer code + * + * @return int 0 if OK * -1 ErrorBadCustomerCodeSyntax * -2 ErrorCustomerCodeRequired * -3 ErrorCustomerCodeAlreadyUsed @@ -1810,8 +1819,9 @@ class Societe extends CommonObject } /** - * \brief Check supplier code - * \return int 0 if OK + * Check supplier code + * + * @return int 0 if OK * -1 ErrorBadCustomerCodeSyntax * -2 ErrorCustomerCodeRequired * -3 ErrorCustomerCodeAlreadyUsed @@ -1844,11 +1854,12 @@ class Societe extends CommonObject } /** - * \brief Renvoie un code compta, suivant le module de code compta. - * Peut etre identique a celui saisit ou genere automatiquement. - * A ce jour seule la generation automatique est implementee - * \param type Type de tiers ('customer' ou 'supplier') - * \return string Code compta si ok, 0 si aucun, <0 si ko + * Renvoie un code compta, suivant le module de code compta. + * Peut etre identique a celui saisit ou genere automatiquement. + * A ce jour seule la generation automatique est implementee + * + * @param type Type of thirdparty ('customer' or 'supplier') + * @return string Code compta si ok, 0 si aucun, <0 si ko */ function get_codecompta($type) { @@ -1864,7 +1875,6 @@ class Societe extends CommonObject } $var = $conf->global->SOCIETE_CODECOMPTA_ADDON; - $mod = new $var; // Defini code compta dans $mod->code @@ -1885,9 +1895,10 @@ class Societe extends CommonObject } /** - * \brief Defini la societe mere pour les filiales - * \param id id compagnie mere a positionner - * \return int <0 si ko, >0 si ok + * Defini la societe mere pour les filiales + * + * @param id id compagnie mere a positionner + * @return int <0 si ko, >0 si ok */ function set_parent($id) {