From 2816bdf74705b49cf72d74ed2c368fa9bef17df0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 21 Oct 2018 16:22:56 +0200 Subject: [PATCH] FIX Date into filename of FEC file. --- htdocs/accountancy/bookkeeping/list.php | 6 ++-- .../class/accountancyexport.class.php | 34 +++---------------- .../accountancy/class/bookkeeping.class.php | 3 +- htdocs/accountancy/tpl/export_journal.tpl.php | 21 +++++++++++- 4 files changed, 29 insertions(+), 35 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index 132aa4e0afa..e87c9b22aee 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -337,7 +337,7 @@ if ($action == 'delmouvconfirm') { } } -// Export into a file with format defined into setup +// Export into a file with format defined into setup (FEC, CSV, ...) if ($action == 'export_file') { $result = $object->fetchAll($sortorder, $sortfield, 0, 0, $filter); @@ -350,7 +350,9 @@ if ($action == 'export_file') { { $accountancyexport = new AccountancyExport($db); $accountancyexport->export($object->lines); - if (!empty($accountancyexport->errors)) { + + if (!empty($accountancyexport->errors)) + { setEventMessages('', $accountancyexport->errors, 'errors'); } exit; diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index 13fec3cf388..7b832976e89 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -206,7 +206,7 @@ class AccountancyExport /** - * Function who chose which export to use with the default config + * Function who chose which export to use with the default config, and make the export into a file * * @param array $TData data * @return void @@ -214,16 +214,16 @@ class AccountancyExport public function export(&$TData) { global $conf, $langs; + global $search_date_end; // Used into /accountancy/tpl/export_journal.tpl.php - + // Define name of file to save $filename = 'general_ledger-'.$this->getFormatCode($conf->global->ACCOUNTING_EXPORT_MODELCSV); + include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php'; switch ($conf->global->ACCOUNTING_EXPORT_MODELCSV) { case self::$EXPORT_TYPE_NORMAL : - /*$this->exportNormal($TData); - break;*/ case self::$EXPORT_TYPE_CONFIGURABLE : $this->exportConfigurable($TData); break; @@ -261,32 +261,6 @@ class AccountancyExport } } - /** - * Export format : Normal - * - * @param array $objectLines data - * - * @return void - */ - /* Use $EXPORT_TYPE_CONFIGURABLE instead - public function exportNormal($objectLines) - { - global $conf; - - foreach ( $objectLines as $line ) { - // Std export - $date = dol_print_date($line->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE); - print $date . $this->separator; - print $line->doc_ref . $this->separator; - print length_accountg($line->numero_compte) . $this->separator; - print length_accounta($line->subledger_account) . $this->separator; - print price($line->debit) . $this->separator; - print price($line->credit) . $this->separator; - print $line->code_journal . $this->separator; - print $this->end_line; - } - } - */ /** * Export format : CEGID diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 87d561b6add..0550fb5a438 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -1001,8 +1001,7 @@ class BookKeeping extends CommonObject } } } - $sql.= ' WHERE 1 = 1'; - $sql .= " AND entity IN (" . getEntity('accountancy') . ")"; + $sql.= ' WHERE entity IN (' . getEntity('accountancy') . ')'; if (count($sqlwhere) > 0) { $sql .= ' AND ' . implode(' ' . $filtermode . ' ', $sqlwhere); } diff --git a/htdocs/accountancy/tpl/export_journal.tpl.php b/htdocs/accountancy/tpl/export_journal.tpl.php index 1d7e7fd6f54..d0d902770c0 100644 --- a/htdocs/accountancy/tpl/export_journal.tpl.php +++ b/htdocs/accountancy/tpl/export_journal.tpl.php @@ -37,7 +37,26 @@ header('Content-Type: text/csv'); if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == "11") // Specific filename for FEC model export { - $completefilename = $siren . "FEC" . $search_date_end . $endaccountingperiod . "." . $format; + + // FEC format is defined here: https://www.legifrance.gouv.fr/affichCodeArticle.do?idArticle=LEGIARTI000027804775&cidTexte=LEGITEXT000006069583&dateTexte=20130802&oldAction=rechCodeArticle + if (empty($search_date_end)) + { + // TODO Get the max date into bookeeping table + $search_date_end = dol_now(); + } + $datetouseforfilename = $search_date_end; + $tmparray=dol_getdate($datetouseforfilename); + $fiscalmonth=empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START; + // Define end of month to use + if ($tmparray['mon'] <= $fiscalmonth) $tmparray['mon']=$fiscalmonth; + else { + $tmparray['mon'] = $fiscalmonth; + $tmparray['year']++; + } + + $endaccountingperiod = dol_print_date(dol_get_last_day($tmparray['year'], $tmparray['mon']), 'dayxcard'); + + $completefilename = $siren . "FEC" . $endaccountingperiod . "." . $format; } else {