FIX Import of chart of account

This commit is contained in:
Laurent Destailleur 2019-05-24 18:14:15 +02:00
parent bad565cc64
commit c04d082ad1
3 changed files with 36 additions and 5 deletions

View File

@ -444,7 +444,22 @@ class ImportCsv extends ModeleImports
$classinstance=new $class($this->db);
// Try the fetch from code or ref
$param_array = array('', $newval);
if ($class == 'AccountingAccount') $param_array = array('', $newval, 1);
if ($class == 'AccountingAccount')
{
//var_dump($arrayrecord[0]['val']);
/*include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancysystem.class.php';
$tmpchartofaccount = new AccountancySystem($this->db);
$tmpchartofaccount->fetch($conf->global->CHARTOFACCOUNTS);
var_dump($tmpchartofaccount->ref.' - '.$arrayrecord[0]['val']);
if ((! ($conf->global->CHARTOFACCOUNTS > 0)) || $tmpchartofaccount->ref != $arrayrecord[0]['val'])
{
$this->errors[$error]['lib']=$langs->trans('ErrorImportOfChartLimitedToCurrentChart', $tmpchartofaccount->ref);
$this->errors[$error]['type']='RESTRICTONCURRENCTCHART';
$errorforthistable++;
$error++;
}*/
$param_array = array('', $newval, 0, $arrayrecord[0]['val']); // Param to fetch parent from account, in chart.
}
call_user_func_array(array($classinstance, $method), $param_array);
// If not found, try the fetch from label
if (! ($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel')
@ -462,7 +477,7 @@ class ImportCsv extends ModeleImports
{
if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldValueNotIn',$key,$newval,'code',$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
else if (!empty($objimport->array_import_convertvalue[0][$val]['element'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldRefNotIn',$key,$newval,$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element']));
else $this->errors[$error]['lib']='ErrorFieldValueNotIn';
else $this->errors[$error]['lib']='ErrorBadDefinitionOfImportProfile';
$this->errors[$error]['type']='FOREIGNKEY';
$errorforthistable++;
$error++;

View File

@ -471,7 +471,22 @@ class ImportXlsx extends ModeleImports
$classinstance=new $class($this->db);
// Try the fetch from code or ref
$param_array = array('', $newval);
if ($class == 'AccountingAccount') $param_array = array('', $newval, 1);
if ($class == 'AccountingAccount')
{
//var_dump($arrayrecord[0]['val']);
/*include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancysystem.class.php';
$tmpchartofaccount = new AccountancySystem($this->db);
$tmpchartofaccount->fetch($conf->global->CHARTOFACCOUNTS);
var_dump($tmpchartofaccount->ref.' - '.$arrayrecord[0]['val']);
if ((! ($conf->global->CHARTOFACCOUNTS > 0)) || $tmpchartofaccount->ref != $arrayrecord[0]['val'])
{
$this->errors[$error]['lib']=$langs->trans('ErrorImportOfChartLimitedToCurrentChart', $tmpchartofaccount->ref);
$this->errors[$error]['type']='RESTRICTONCURRENCTCHART';
$errorforthistable++;
$error++;
}*/
$param_array = array('', $newval, 0, $arrayrecord[0]['val']); // Param to fetch parent from account, in chart.
}
call_user_func_array(array($classinstance, $method), $param_array);
// If not found, try the fetch from label
if (! ($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel')
@ -489,7 +504,7 @@ class ImportXlsx extends ModeleImports
{
if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldValueNotIn',$key,$newval,'code',$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
else if (!empty($objimport->array_import_convertvalue[0][$val]['element'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldRefNotIn',$key,$newval,$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element']));
else $this->errors[$error]['lib']='ErrorFieldValueNotIn';
else $this->errors[$error]['lib']='ErrorBadDefinitionOfImportProfile';
$this->errors[$error]['type']='FOREIGNKEY';
$errorforthistable++;
$error++;

View File

@ -283,9 +283,10 @@ class modAccounting extends DolibarrModules
$this->import_fields_array[$r]=array('aa.fk_pcg_version'=>"Chartofaccounts*",'aa.account_number'=>"AccountAccounting*",'aa.label'=>"Label*",'aa.account_parent'=>"Accountparent","aa.fk_accounting_category"=>"AccountingCategory","aa.pcg_type"=>"Pcgtype*",'aa.pcg_subtype'=>'Pcgsubtype*','aa.active'=>'Status*','aa.datec'=>"DateCreation");
$this->import_regex_array[$r]=array('aa.fk_pcg_version'=>'pcg_version@'.MAIN_DB_PREFIX.'accounting_system','aa.account_number'=>'^.{1,32}$','aa.label'=>'^.{1,255}$','aa.account_parent'=>'^.{0,32}$','aa.fk_accounting_category'=>'rowid@'.MAIN_DB_PREFIX.'c_accounting_category','aa.pcg_type'=>'^.{1,20}$','aa.pcg_subtype'=>'^.{1,20}$','aa.active'=>'^0|1$','aa.datec'=>'^\d{4}-\d{2}-\d{2}$');
$this->import_convertvalue_array[$r]=array(
'aa.account_parent'=>array('rule'=>'fetchidfromcodeorlabel','classfile'=>'/accountancy/class/accountingaccount.class.php','class'=>'AccountingAccount','method'=>'fetch'),
'aa.account_parent'=>array('rule'=>'fetchidfromref','classfile'=>'/accountancy/class/accountingaccount.class.php','class'=>'AccountingAccount','method'=>'fetch','element'=>'AccountingAccount'),
'aa.fk_accounting_category'=>array('rule'=>'fetchidfromcodeorlabel','classfile'=>'/accountancy/class/accountancycategory.class.php','class'=>'AccountancyCategory','method'=>'fetch','dict'=>'DictionaryAccountancyCategory'),
);
$this->import_examplevalues_array[$r]=array('aa.fk_pcg_version'=>"PCG99-ABREGE",'aa.account_number'=>"707",'aa.label'=>"Product sales",'aa.account_parent'=>"ref:7 or id:1407","aa.fk_accounting_category"=>"","aa.pcg_type"=>"PROD",'aa.pcg_subtype'=>'PRODUCT','aa.active'=>'1','aa.datec'=>"2017-04-28");
$this->import_updatekeys_array[$r]=array('aa.fk_pcg_version'=>'Chartofaccounts','aa.account_number'=>'AccountAccounting');
}
}