Skip to content
Snippets Groups Projects
Commit a8846736 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Fix: A better to fix to manage automatic creation of code for import.

parent c1411e65
Branches
No related tags found
No related merge requests found
...@@ -441,45 +441,46 @@ class ImportCsv extends ModeleImports ...@@ -441,45 +441,46 @@ class ImportCsv extends ModeleImports
{ {
if (empty($newval)) $newval='0'; 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); $this->thirpartyobject->get_codeclient(0,0);
$newval=$this->thirpartyobject->code_client; $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; //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->get_codefournisseur(0,1);
$newval=$this->thirpartyobject->code_fournisseur; $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; //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'); $this->thirpartyobject->get_codecompta('customer');
$newval=$this->thirpartyobject->code_compta; $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; //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'); $this->thirpartyobject->get_codecompta('supplier');
$newval=$this->thirpartyobject->code_compta_fournisseur; $newval=$this->thirpartyobject->code_compta_fournisseur;
if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null"
//print 'code_compta_fournisseur='.$newval; //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.'<br>'; //print 'Val to use as insert is '.$newval.'<br>';
......
...@@ -401,14 +401,14 @@ class modSociete extends DolibarrModules ...@@ -401,14 +401,14 @@ class modSociete extends DolibarrModules
's.fk_typent'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ctypent.class.php','class'=>'Ctypent','method'=>'fetch','dict'=>'DictionnaryCompanyType'), '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_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_client'=>array('rule'=>'getcustomercodeifauto'),
's.code_fournisseur'=>array('rule'=>'getsuppliercodeifnull'), 's.code_fournisseur'=>array('rule'=>'getsuppliercodeifauto'),
's.code_compta'=>array('rule'=>'getcustomeraccountancycodeifnull'), 's.code_compta'=>array('rule'=>'getcustomeraccountancycodeifauto'),
's.code_compta_fournisseur'=>array('rule'=>'getsupplieraccountancycodeifnull') 's.code_compta_fournisseur'=>array('rule'=>'getsupplieraccountancycodeifauto')
); );
//$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t'); //$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_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 // Import list of contact and attributes
$r++; $r++;
......
"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)" "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
...@@ -162,7 +162,7 @@ class FilesLibTest extends PHPUnit_Framework_TestCase ...@@ -162,7 +162,7 @@ class FilesLibTest extends PHPUnit_Framework_TestCase
$file=dirname(__FILE__).'/Example_import_company_1.csv'; $file=dirname(__FILE__).'/Example_import_company_1.csv';
$result=dol_count_nb_of_line($file); $result=dol_count_nb_of_line($file);
print __METHOD__." result=".$result."\n"; print __METHOD__." result=".$result."\n";
$this->assertEquals(2,$result); $this->assertEquals(3,$result);
return $result; return $result;
} }
......
...@@ -125,7 +125,10 @@ class ImportTest extends PHPUnit_Framework_TestCase ...@@ -125,7 +125,10 @@ class ImportTest extends PHPUnit_Framework_TestCase
{ {
$file=dirname(__FILE__).'/Example_import_company_1.csv'; $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; return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment