From 9b65529fc716447c67efe30889010999012573f6 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Wed, 31 Mar 2021 04:59:12 +0200 Subject: [PATCH 1/3] NEW: Accountancy - Add FEC import --- .../class/accountancyimport.class.php | 99 +++++++++++++++++++ htdocs/core/modules/modAccounting.class.php | 82 +++++++++++++-- htdocs/langs/en_US/accountancy.lang | 20 ++++ 3 files changed, 195 insertions(+), 6 deletions(-) create mode 100644 htdocs/accountancy/class/accountancyimport.class.php diff --git a/htdocs/accountancy/class/accountancyimport.class.php b/htdocs/accountancy/class/accountancyimport.class.php new file mode 100644 index 00000000000..c27ff6911ed --- /dev/null +++ b/htdocs/accountancy/class/accountancyimport.class.php @@ -0,0 +1,99 @@ + + * Copyright (C) 2014 Juanjo Menent + * Copyright (C) 2015 Florian Henry + * Copyright (C) 2015 Raphaël Doursenaud + * Copyright (C) 2016 Pierre-Henry Favre + * Copyright (C) 2016-2020 Alexandre Spangaro + * Copyright (C) 2013-2017 Olivier Geffroy + * Copyright (C) 2017 Elarifr. Ari Elbaz + * Copyright (C) 2017-2019 Frédéric France + * Copyright (C) 2017 André Schild + * Copyright (C) 2020 Guillaume Alexandre + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/accountancy/class/accountancyimport.class.php + * \ingroup Accountancy (Double entries) + * \brief Class accountancy import + */ + + + +/** + * Manage the different format accountancy import + */ +class AccountancyImport +{ + /** + * Compute amount + * + * @param array $arrayrecord Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]... + * @param string $fieldname Field name with alias + * @param array $listfields Fields list to add + * @param array $listvalues Values list to add + * @return int <0 if KO, >0 if OK + */ + public function computeMontant(&$arrayrecord, $fieldname, &$listfields, &$listvalues) { + $fieldArr = explode('.', $fieldname); + if (count($fieldArr) > 0) { + $fieldname = $fieldArr[1]; + } + + $debit = trim($arrayrecord[11]['val']); + $credit = trim($arrayrecord[12]['val']); + if (!empty($debit)) { + $amount = $debit; + } else { + $amount = $credit; + } + + $listfields[] = $fieldname; + $listvalues[] = "'" . abs($amount) . "'"; + + return 1; + } + + + /** + * Compute sens + * + * @param array $arrayrecord Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]... + * @param string $fieldname Field name with alias + * @param array $listfields Fields list to add + * @param array $listvalues Values list to add + * @return int <0 if KO, >0 if OK + */ + public function computeSens(&$arrayrecord, $fieldname, &$listfields, &$listvalues) { + $fieldArr = explode('.', $fieldname); + if (count($fieldArr) > 0) { + $fieldname = $fieldArr[1]; + } + + $debit = trim($arrayrecord[11]['val']); + if (!empty($debit)) { + $sens = 'D'; + } else { + $sens = 'C'; + } + + $listfields[] = $fieldname; + $listvalues[] = "'" . $sens . "'"; + + return 1; + } +} diff --git a/htdocs/core/modules/modAccounting.class.php b/htdocs/core/modules/modAccounting.class.php index 15710d71dfa..8034f98d9a7 100644 --- a/htdocs/core/modules/modAccounting.class.php +++ b/htdocs/core/modules/modAccounting.class.php @@ -1,10 +1,10 @@ - * Copyright (C) 2013-2019 Alexandre Spangaro - * Copyright (C) 2014 Ari Elbaz (elarifr) - * Copyright (C) 2014 Florian Henry - * Copyright (C) 2016-2017 Laurent Destailleur - * Copyright (C) 2017 Open-DSI +/* Copyright (C) 2013-2014 Olivier Geffroy + * Copyright (C) 2013-2021 Alexandre Spangaro + * Copyright (C) 2014 Ari Elbaz (elarifr) + * Copyright (C) 2014 Florian Henry + * Copyright (C) 2016-2017 Laurent Destailleur + * Copyright (C) 2017-2021 Open-DSI * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -314,6 +314,76 @@ class modAccounting extends DolibarrModules 'b.sens'=>'C' // This field is still used by accounting export. We can remove it once it has been replace into accountancyexport.class.php by a detection using ->debit and ->credit ); + // General ledger - Fichier FEC + $r++; + $this->import_code[$r] = $this->rights_class.'_'.$r; + $this->import_label[$r] = 'ImportAccountingEntriesFECFormat'; + $this->import_icon[$r] = $this->picto; + $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('b'=>MAIN_DB_PREFIX.'accounting_bookkeeping'); // List of tables to insert into (insert done in same order) + $this->import_fields_array[$r] = array( + 'b.code_journal'=>'FECFormatJournalCode*', + 'b.journal_label'=>'FECFormatJournalLabel', + 'b.piece_num'=>'FECFormatEntryNum*', + 'b.doc_date'=>'FECFormatEntryDate*', + 'b.numero_compte'=>'FECFormatGeneralAccountNumber*', + 'b.label_compte'=>'FECFormatGeneralAccountLabel*', + 'b.subledger_account'=>'FECFormatSubledgerAccountNumber', + 'b.subledger_label'=>'FECFormatSubledgerAccountLabel', + 'b.doc_ref'=>'FECFormatPieceRef*', + 'b.date_creation'=>'FECFormatPieceDate', + 'b.label_operation'=>'FECFormatLabelOperation', + 'b.debit'=>'FECFormatDebit*', + 'b.credit'=>'FECFormatCredit*', + 'b.lettering_code'=>'FECFormatReconcilableCode', + 'b.date_lettering'=>'FECFormatReconcilableDate', + 'b.date_validated'=>'FECFormatValidateDate', + 'b.multicurrency_amount'=>'FECFormatMulticurrencyAmount', + 'b.multicurrency_code'=>'FECFormatMulticurrencyCode' + ); + $this->import_fieldshidden_array[$r] = array( + 'b.doc_type'=>'const-import_from_external', + 'b.fk_doc'=>'const-0', + 'b.fk_docdet'=>'const-0', + 'b.fk_user_author'=>'user->id', + 'b.montant'=>'rule-computeMontant', + 'b.sens'=>'rule-computeSens' + ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent) + $this->import_convertvalue_array[$r]=array( + 'b.montant' => array('rule' => 'compute', 'classfile' => '/accountancy/class/accountancyimport.class.php', 'class' => 'AccountancyImport', 'method' => 'computeMontant', 'element' => 'Accountancy'), + 'b.sens' => array('rule' => 'compute', 'classfile' => '/accountancy/class/accountancyimport.class.php', 'class' => 'AccountancyImport', 'method' => 'computeSens', 'element' => 'Accountancy'), + ); + $this->import_regex_array[$r] = array( + //'b.doc_date'=>'^\d{4}\d{2}\d{2}$', + 'b.doc_ref'=>'^.{1,300}$', + 'b.numero_compte'=>'^.{1,32}$', + 'b.label_compte'=>'^.{1,255}$', + 'b.subledger_compte'=>'^.{1,32}$', + 'b.subledger_label'=>'^.{1,255}$', + 'b.label_operation'=>'^.{1,255}$', + //'b.sens'=>'^[D|C]$', + ); + $this->import_examplevalues_array[$r] = array( + 'b.code_journal'=>"VT", + 'b.journal_label'=>"Sale journal", + 'b.piece_num'=>'123 (!!! use next value not already used)', + 'b.doc_date'=>dol_print_date(dol_now(), "%Y%m%d"), + 'b.numero_compte'=>"707", + 'b.label_compte'=>'Sale', + 'b.subledger_account'=>'', + 'b.subledger_label'=>'', + 'b.doc_ref'=>'My document ABC', + 'b.date_creation'=>dol_print_date(dol_now(), "%Y%m%d"), + 'b.label_operation'=>"Sale of ABC", + 'b.debit'=>"0", + 'b.credit'=>"100", + 'b.lettering_code'=>'ABC', + 'b.date_lettering'=>dol_print_date(dol_now(), "%Y%m%d"), + 'b.date_validated'=>dol_print_date(dol_now(), "%Y%m%d"), + 'b.multicurrency_amount'=>"90 (Necessary if devise is different than EUR)", + 'b.multicurrency_code'=>"US (Necessary if devise is different than EUR)", + ); + // Chart of accounts $r++; $this->import_code[$r] = $this->rights_class.'_'.$r; diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index c635809404e..380a747a53a 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -402,6 +402,26 @@ UseMenuToSetBindindManualy=Lines not yet bound, use menu %s to ## Import ImportAccountingEntries=Accounting entries +ImportAccountingEntriesFECFormat=Accounting entries - FEC format +FECFormatJournalCode=Code journal (JournalCode) +FECFormatJournalLabel=Label journal (JournalLib) +FECFormatEntryNum=Piece number (EcritureNum) +FECFormatEntryDate=Piece date (EcritureDate) +FECFormatGeneralAccountNumber=General account number (CompteNum) +FECFormatGeneralAccountLabel=General account label (CompteLib) +FECFormatSubledgerAccountNumber=Subledger account number (CompAuxNum) +FECFormatSubledgerAccountLabel=Subledger account number (CompAuxLib) +FECFormatPieceRef=Piece ref (PieceRef) +FECFormatPieceDate=Piece date creation (PieceDate) +FECFormatLabelOperation=Label operation (EcritureLib) +FECFormatDebit=Debit (Debit) +FECFormatCredit=Credit (Credit) +FECFormatReconcilableCode=Reconcilable code (EcritureLet) +FECFormatReconcilableDate=Reconcilable date (DateLet) +FECFormatValidateDate=Piece date validated (ValidDate) +FECFormatMulticurrencyAmount=Multicurrency amount (Montantdevise) +FECFormatMulticurrencyCode=Multicurrency code (Idevise) + DateExport=Date export WarningReportNotReliable=Warning, this report is not based on the Ledger, so does not contains transaction modified manually in the Ledger. If your journalization is up to date, the bookkeeping view is more accurate. ExpenseReportJournal=Expense Report Journal From dd913b2385b2387a9d216498cd059a37e377cc17 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Wed, 31 Mar 2021 20:40:26 +0200 Subject: [PATCH 2/3] Update --- htdocs/accountancy/class/accountancyimport.class.php | 4 ++-- htdocs/core/modules/modAccounting.class.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/accountancy/class/accountancyimport.class.php b/htdocs/accountancy/class/accountancyimport.class.php index c27ff6911ed..230aa392cd7 100644 --- a/htdocs/accountancy/class/accountancyimport.class.php +++ b/htdocs/accountancy/class/accountancyimport.class.php @@ -48,7 +48,7 @@ class AccountancyImport * @param array $listvalues Values list to add * @return int <0 if KO, >0 if OK */ - public function computeMontant(&$arrayrecord, $fieldname, &$listfields, &$listvalues) { + public function computeAmount(&$arrayrecord, $fieldname, &$listfields, &$listvalues) { $fieldArr = explode('.', $fieldname); if (count($fieldArr) > 0) { $fieldname = $fieldArr[1]; @@ -78,7 +78,7 @@ class AccountancyImport * @param array $listvalues Values list to add * @return int <0 if KO, >0 if OK */ - public function computeSens(&$arrayrecord, $fieldname, &$listfields, &$listvalues) { + public function computeDirection(&$arrayrecord, $fieldname, &$listfields, &$listvalues) { $fieldArr = explode('.', $fieldname); if (count($fieldArr) > 0) { $fieldname = $fieldArr[1]; diff --git a/htdocs/core/modules/modAccounting.class.php b/htdocs/core/modules/modAccounting.class.php index 8034f98d9a7..d62ede90982 100644 --- a/htdocs/core/modules/modAccounting.class.php +++ b/htdocs/core/modules/modAccounting.class.php @@ -350,8 +350,8 @@ class modAccounting extends DolibarrModules 'b.sens'=>'rule-computeSens' ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent) $this->import_convertvalue_array[$r]=array( - 'b.montant' => array('rule' => 'compute', 'classfile' => '/accountancy/class/accountancyimport.class.php', 'class' => 'AccountancyImport', 'method' => 'computeMontant', 'element' => 'Accountancy'), - 'b.sens' => array('rule' => 'compute', 'classfile' => '/accountancy/class/accountancyimport.class.php', 'class' => 'AccountancyImport', 'method' => 'computeSens', 'element' => 'Accountancy'), + 'b.montant' => array('rule' => 'compute', 'classfile' => '/accountancy/class/accountancyimport.class.php', 'class' => 'AccountancyImport', 'method' => 'computeAmount', 'element' => 'Accountancy'), + 'b.sens' => array('rule' => 'compute', 'classfile' => '/accountancy/class/accountancyimport.class.php', 'class' => 'AccountancyImport', 'method' => 'computeDirection', 'element' => 'Accountancy'), ); $this->import_regex_array[$r] = array( //'b.doc_date'=>'^\d{4}\d{2}\d{2}$', From 416a09672f2288898da42e67f10006c5d3ad9c14 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 31 Mar 2021 18:43:09 +0000 Subject: [PATCH 3/3] Fixing style errors. --- .../class/accountancyimport.class.php | 100 +++++++++--------- 1 file changed, 51 insertions(+), 49 deletions(-) diff --git a/htdocs/accountancy/class/accountancyimport.class.php b/htdocs/accountancy/class/accountancyimport.class.php index 230aa392cd7..ece843515e2 100644 --- a/htdocs/accountancy/class/accountancyimport.class.php +++ b/htdocs/accountancy/class/accountancyimport.class.php @@ -39,61 +39,63 @@ */ class AccountancyImport { - /** - * Compute amount - * - * @param array $arrayrecord Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]... - * @param string $fieldname Field name with alias - * @param array $listfields Fields list to add - * @param array $listvalues Values list to add - * @return int <0 if KO, >0 if OK - */ - public function computeAmount(&$arrayrecord, $fieldname, &$listfields, &$listvalues) { - $fieldArr = explode('.', $fieldname); - if (count($fieldArr) > 0) { - $fieldname = $fieldArr[1]; - } + /** + * Compute amount + * + * @param array $arrayrecord Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]... + * @param string $fieldname Field name with alias + * @param array $listfields Fields list to add + * @param array $listvalues Values list to add + * @return int <0 if KO, >0 if OK + */ + public function computeAmount(&$arrayrecord, $fieldname, &$listfields, &$listvalues) + { + $fieldArr = explode('.', $fieldname); + if (count($fieldArr) > 0) { + $fieldname = $fieldArr[1]; + } - $debit = trim($arrayrecord[11]['val']); - $credit = trim($arrayrecord[12]['val']); - if (!empty($debit)) { - $amount = $debit; - } else { - $amount = $credit; - } + $debit = trim($arrayrecord[11]['val']); + $credit = trim($arrayrecord[12]['val']); + if (!empty($debit)) { + $amount = $debit; + } else { + $amount = $credit; + } - $listfields[] = $fieldname; - $listvalues[] = "'" . abs($amount) . "'"; + $listfields[] = $fieldname; + $listvalues[] = "'" . abs($amount) . "'"; - return 1; - } + return 1; + } - /** - * Compute sens - * - * @param array $arrayrecord Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]... - * @param string $fieldname Field name with alias - * @param array $listfields Fields list to add - * @param array $listvalues Values list to add - * @return int <0 if KO, >0 if OK - */ - public function computeDirection(&$arrayrecord, $fieldname, &$listfields, &$listvalues) { - $fieldArr = explode('.', $fieldname); - if (count($fieldArr) > 0) { - $fieldname = $fieldArr[1]; - } + /** + * Compute sens + * + * @param array $arrayrecord Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]... + * @param string $fieldname Field name with alias + * @param array $listfields Fields list to add + * @param array $listvalues Values list to add + * @return int <0 if KO, >0 if OK + */ + public function computeDirection(&$arrayrecord, $fieldname, &$listfields, &$listvalues) + { + $fieldArr = explode('.', $fieldname); + if (count($fieldArr) > 0) { + $fieldname = $fieldArr[1]; + } - $debit = trim($arrayrecord[11]['val']); - if (!empty($debit)) { - $sens = 'D'; - } else { - $sens = 'C'; - } + $debit = trim($arrayrecord[11]['val']); + if (!empty($debit)) { + $sens = 'D'; + } else { + $sens = 'C'; + } - $listfields[] = $fieldname; - $listvalues[] = "'" . $sens . "'"; + $listfields[] = $fieldname; + $listvalues[] = "'" . $sens . "'"; - return 1; - } + return 1; + } }