diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php index 62967076cb00a..667d13a0f883c 100644 --- a/htdocs/core/modules/import/import_csv.modules.php +++ b/htdocs/core/modules/import/import_csv.modules.php @@ -441,45 +441,46 @@ function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$ma { if (empty($newval)) $newval='0'; } - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifnull') + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifauto') { - if (empty($newval) || strtolower($newval) == 'auto') + if (strtolower($newval) == 'auto') { $this->thirpartyobject->get_codeclient(0,0); $newval=$this->thirpartyobject->code_client; - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" //print 'code_client='.$newval; } + if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" } - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifnull') + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifauto') { - if (empty($newval) || strtolower($newval) == 'auto') + if (strtolower($newval) == 'auto') { $newval=$this->thirpartyobject->get_codefournisseur(0,1); $newval=$this->thirpartyobject->code_fournisseur; - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" //print 'code_fournisseur='.$newval; } + if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" } - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifnull') + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifauto') { - if (empty($newval) || strtolower($newval) == 'auto') + if (strtolower($newval) == 'auto') { $this->thirpartyobject->get_codecompta('customer'); $newval=$this->thirpartyobject->code_compta; - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" //print 'code_compta='.$newval; } + if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" } - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifnull') + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifauto') { - if (empty($newval) || strtolower($newval) == 'auto') + if (strtolower($newval) == 'auto') { $this->thirpartyobject->get_codecompta('supplier'); $newval=$this->thirpartyobject->code_compta_fournisseur; if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" //print 'code_compta_fournisseur='.$newval; } + if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" } //print 'Val to use as insert is '.$newval.'
'; diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php index ea3be87aaeed5..96a3ee4d31bff 100644 --- a/htdocs/core/modules/modSociete.class.php +++ b/htdocs/core/modules/modSociete.class.php @@ -401,14 +401,14 @@ function __construct($db) '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.code_client'=>array('rule'=>'getcustomercodeifnull'), - 's.code_fournisseur'=>array('rule'=>'getsuppliercodeifnull'), - 's.code_compta'=>array('rule'=>'getcustomeraccountancycodeifnull'), - 's.code_compta_fournisseur'=>array('rule'=>'getsupplieraccountancycodeifnull') + 's.code_client'=>array('rule'=>'getcustomercodeifauto'), + 's.code_fournisseur'=>array('rule'=>'getsuppliercodeifauto'), + 's.code_compta'=>array('rule'=>'getcustomeraccountancycodeifauto'), + 's.code_compta_fournisseur'=>array('rule'=>'getsupplieraccountancycodeifauto') ); //$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(dol_now(),'%Y-%m-%d'),'s.code_client'=>"CU01-0001 or auto",'s.code_fournisseur'=>"SU01-0001 or auto",'s.address'=>"61 jump street",'s.zip'=>"123456",'s.town'=>"Big town",'s.fk_pays'=>'US, FR, DE...','s.phone'=>"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_private'=>"This is an example of private note for record",'s.note_public'=>"This is an example of public 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(dol_now(),'%Y-%m-%d'),'s.code_client'=>"CU01-0001 or empty or 'auto'",'s.code_fournisseur'=>"SU01-0001 or empty or 'auto'",'s.address'=>"61 jump street",'s.zip'=>"123456",'s.town'=>"Big town",'s.fk_pays'=>'US, FR, DE...','s.phone'=>"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_private'=>"This is an example of private note for record",'s.note_public'=>"This is an example of public 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/test/phpunit/Example_import_company_1.csv b/test/phpunit/Example_import_company_1.csv index 34f99a6b728f8..7ba7a79731782 100755 --- a/test/phpunit/Example_import_company_1.csv +++ b/test/phpunit/Example_import_company_1.csv @@ -1,2 +1,3 @@ "Name* (s.nom)";"Status (s.status)";"Customer* (s.client)";"Supplier* (s.fournisseur)";"DateCreation (s.datec)";"CustomerCode (s.code_client)";"SupplierCode (s.code_fournisseur)";"Address (s.address)";"Zip (s.cp)";"Town (s.ville)";"Phone (s.tel)";"Fax (s.fax)";"Url (s.url)";"Email (s.email)";"IdProf1 (s.siret)";"IdProf2 (s.siren)";"IdProf3 (s.ape)";"IdProf4 (s.idprof4)";"VATIntraShort (s.tva_intra)";"Capital (s.capital)";"Note (s.note)";"ThirdPartyType (s.fk_typent)";"Effectif (s.fk_effectif)";"JuridicalStatus (s.fk_forme_juridique)";"ProspectLevel (s.fk_prospectlevel)";"ProspectStatus (s.fk_stcomm)";"DefaultLanguage (s.default_lang)";"BarCode (s.barcode)" -"MyBigCompanyImport1";1;3;1;01/01/00;"CU01-0001";"SU01-0001";"61 jump street";123456;"Big town";101010101;101010102;"http://mycompany.com";"test@mycompany.com";;;;;"FR0123456789";10000;"This is an example of note for record";2;3;1;"PL_MEDIUM";1;"en_US";123456789 +"MyBigCompanyImport1";1;3;1;01/01/00;"CU01-0001";"SU01-0001";"61 jump street";123456;"Big town";101010101;101010111;"http://mycompany.com";"test@mycompany.com";;;;;"FR0123456781";10000;"This is an example of note for record 1";2;3;1;"PL_MEDIUM";1;"en_US";123456781 +"MyBigCompanyImport2";1;3;1;01/01/00;"auto";;"62 jump street";123456;"Big town";101010102;101010112;"http://mycompany2.com";"test@mycompany2.com";;;;;"FR0123456782";10000;"This is an example of note for record 2";2;3;1;"PL_MEDIUM";1;"en_US";auto diff --git a/test/phpunit/FilesLibTest.php b/test/phpunit/FilesLibTest.php index d38f73326b2b2..1e8d91ed08d13 100644 --- a/test/phpunit/FilesLibTest.php +++ b/test/phpunit/FilesLibTest.php @@ -162,7 +162,7 @@ public function testDolCountNbOfLine() $file=dirname(__FILE__).'/Example_import_company_1.csv'; $result=dol_count_nb_of_line($file); print __METHOD__." result=".$result."\n"; - $this->assertEquals(2,$result); + $this->assertEquals(3,$result); return $result; } diff --git a/test/phpunit/ImportTest.php b/test/phpunit/ImportTest.php index 378031be257bb..86d23a850e176 100755 --- a/test/phpunit/ImportTest.php +++ b/test/phpunit/ImportTest.php @@ -125,7 +125,10 @@ public function testImportSample1() { $file=dirname(__FILE__).'/Example_import_company_1.csv'; - //if (! preg_match('/^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$/i','2012-03-23')) print 'eeeeeeeeeeee'; + // TODO + // Run import on file and check the record with field "auto" are filled + // according to option + return true; }