From dee005822e3f9cf6ca3058ced12cc2e842361994 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 07:37:02 +0200 Subject: [PATCH 01/24] NEW: Accountancy REST API GET Exportdata --- .../class/api_accountancy.class.php | 276 ++++++++++++++++++ htdocs/accountancy/tpl/export_journal.tpl.php | 5 +- htdocs/core/lib/accounting.lib.php | 53 ++++ htdocs/core/lib/functions2.lib.php | 2 + htdocs/core/modules/modAccounting.class.php | 2 +- 5 files changed, 335 insertions(+), 3 deletions(-) create mode 100644 htdocs/accountancy/class/api_accountancy.class.php diff --git a/htdocs/accountancy/class/api_accountancy.class.php b/htdocs/accountancy/class/api_accountancy.class.php new file mode 100644 index 00000000000..289e17203e3 --- /dev/null +++ b/htdocs/accountancy/class/api_accountancy.class.php @@ -0,0 +1,276 @@ + + * Copyright (C) 2019 Cedric Ancelin + * Copyright (C) 2023 Lionel Vessiller + * + * 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 . + */ + +use Luracast\Restler\RestException; + +/** + * API class for accountancy + * + * @access protected + * @class DolibarrApiAccess {@requires user,external} + * + */ +class Accountancy extends DolibarrApi +{ + /** + * + * @var array $FIELDS Mandatory fields, checked when create and update object + */ + public static $FIELDS = array(); + + /** + * @var BookKeeping $bookkeeping {@type BookKeeping} + */ + public $bookkeeping; + + /** + * @var AccountancyExport $accountancy_export {@type AccountancyExport} + */ + public $accountancyexport; + + /** + * Constructor + */ + public function __construct() + { + global $db, $langs; + $this->db = $db; + + require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php'; + require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancyexport.class.php'; + + $langs->load('accountancy'); + + $this->bookkeeping = new BookKeeping($this->db); + $this->accountancyexport = new AccountancyExport($this->db); + } + + /** + * Accountancy export data + * + * @param string $period Period : 'lastmonth', 'currentmonth', 'last3months', 'last6months', 'currentyear', 'lastyear', 'fiscalyear', 'lastfiscalyear', 'actualandlastfiscalyear' or 'custom' (see above) + * @param string $date_min [=''] Start date of period if 'custom' is set in period parameter + * Date format is 'YYYY-MM-DD' + * @param string $date_max [=''] End date of period if 'custom' is set in period parameter + * Date format is 'YYYY-MM-DD' + * @param string $format [=''] by default uses '1' for 'Configurable (CSV)' for format number + * or '1000' for FEC + * or '1010' for FEC2 + * (see AccountancyExport class) + * @param int $lettering [=0] by default don't export or 1 to export lettering data (columns 'letterring_code' and 'date_lettering' returns empty or not) + * @param int $alreadyexport [=0] by default export data only if it's not yet exported or 1 already exported (always export data even if 'date_export" is set) + * @param int $notnotifiedasexport [=0] by default notified as exported or 1 not notified as exported (when the export is done, notified or not the column 'date_export') + * + * @return string + * + * @url GET exportdata + * + * @throws RestException 401 Insufficient rights + * @throws RestException 404 Accountancy export period not found + * @throws RestException 404 Accountancy export start or end date not defined + * @throws RestException 404 Accountancy export format not found + * @throws RestException 500 Error on accountancy export + */ + public function exportData($period, $date_min = '', $date_max = '', $format = '', $lettering = 0, $alreadyexport = 0, $notnotifiedasexport = 0) + { + global $conf, $langs; + + // check rights + if (!DolibarrApiAccess::$user->rights->accounting->mouvements->export) { + throw new RestException(401, 'No permission to export accounting'); + } + + // check parameters + $period_available_list = array('lastmonth', 'currentmonth', 'last3months', 'last6months', 'currentyear', 'lastyear', 'fiscalyear', 'lastfiscalyear', 'actualandlastfiscalyear', 'custom'); + if (!in_array($period, $period_available_list)) { + throw new RestException(404, 'Accountancy export period not found'); + } + if ($period == 'custom') { + if ($date_min == '' && $date_max == '') { + throw new RestException(404, 'Accountancy export start and end date for custom period not defined'); + } + } + if ($format == '') { + $format = AccountancyExport::$EXPORT_TYPE_CONFIGURABLE; // uses default + } + + // get objects + $bookkeeping = $this->bookkeeping; + $accountancyexport = $this->accountancyexport; + + // find export format code from format number + $format_number_available_list = $accountancyexport->getType(); + if (is_numeric($format)) { + $format_number = (int) $format; + } else { + $format_number = 0; + $format_label_available_list = array_flip($format_number_available_list); + if (isset($format_label_available_list[$format])) { + $format_number = $format_label_available_list[$format]; + } + } + + // get all format available and check if exists + if (!array_key_exists($format_number, $format_number_available_list)) { + throw new RestException(404, 'Accountancy export format not found'); + } + + $sortorder = 'ASC'; // by default + $sortfield = 't.piece_num, t.rowid'; // by default + + // set filter for each period available + $filter = array(); + $doc_date_start = null; + $doc_date_end= null; + $now = dol_now(); + $now_arr = dol_getdate($now); + $now_month = $now_arr['mon']; + $now_year = $now_arr['year']; + if ($period == 'custom') { + if ($date_min != '') { + $time_min = strtotime($date_min); + if ($time_min !== false) { + $doc_date_start = $time_min; + } + } + if ($date_max != '') { + $time_max = strtotime($date_max); + if ($time_max !== false) { + $doc_date_end = $time_max; + } + } + } elseif ($period == 'lastmonth') { + $prev_date_arr = dol_get_prev_month($now_month, $now_year); // get previous month and year if month is january + $doc_date_start = dol_mktime(0, 0, 0, $prev_date_arr['month'], 1, $prev_date_arr['year']); // first day of previous month + $doc_date_end = dol_get_last_day($prev_date_arr['year'], $prev_date_arr['month']); // last day of previous month + } elseif ($period == 'currentmonth') { + $doc_date_start = dol_mktime(0, 0, 0, $now_month, 1, $now_year); // first day of current month + $doc_date_end = dol_get_last_day($now_year, $now_month); // last day of current month + } elseif ($period == 'last3months' || $period == 'last6months') { + if ($period == 'last3months') { + // last 3 months + $nb_prev_month = 3; + } else { + // last 6 months + $nb_prev_month = 6; + } + $prev_month_date_list = array(); + $prev_month_date_list[] = dol_get_prev_month($now_month, $now_year); // get previous month for index = 0 + for ($i = 1; $i < $nb_prev_month; $i++) { + $prev_month_date_list[] = dol_get_prev_month($prev_month_date_list[$i-1]['month'], $prev_month_date_list[$i-1]['year']); // get i+1 previous month for index=i + } + $doc_date_start = dol_mktime(0, 0, 0, $prev_month_date_list[$nb_prev_month-1]['month'], 1, $prev_month_date_list[$nb_prev_month-1]['year']); // first day of n previous month for index=n-1 + $doc_date_end = dol_get_last_day($prev_month_date_list[0]['year'], $prev_month_date_list[0]['month']); // last day of previous month for index = 0 + } elseif ($period == 'currentyear' || $period == 'lastyear') { + $period_year = $now_year; + if ($period == 'lastyear') { + $period_year--; + } + $doc_date_start = dol_mktime(0, 0, 0, 1, 1, $period_year); // first day of year + $doc_date_end = dol_mktime(23, 59, 59, 12, 31, $period_year); // last day of year + } elseif ($period == 'fiscalyear' || $period == 'lastfiscalyear' || $period == 'actualandlastfiscalyear') { + // find actual fiscal year + $cur_fiscal_period = getCurrentPeriodOfFiscalYear($this->db, $conf); + $cur_fiscal_date_start = $cur_fiscal_period['date_start']; + $cur_fiscal_date_end = $cur_fiscal_period['date_end']; + + if ($period == 'fiscalyear') { + $doc_date_start = $cur_fiscal_date_start; + $doc_date_end = $cur_fiscal_date_end; + } else { + // get one day before current fiscal date start (to find previous fiscal period) + $prev_fiscal_date_search = dol_time_plus_duree($cur_fiscal_date_start, -1, 'd'); + + // find previous fiscal year from current fiscal year + $prev_fiscal_period = getCurrentPeriodOfFiscalYear($this->db, $conf, $prev_fiscal_date_search); + $prev_fiscal_date_start = $prev_fiscal_period['date_start']; + $prev_fiscal_date_end = $prev_fiscal_period['date_end']; + + if ($period == 'lastfiscalyear') { + $doc_date_start = $prev_fiscal_date_start; + $doc_date_end = $prev_fiscal_date_end; + } else { + // period == 'actualandlastfiscalyear' + $doc_date_start = $prev_fiscal_date_start; + $doc_date_end = $cur_fiscal_date_end; + } + } + } + if (is_numeric($doc_date_start)) { + $filter['t.doc_date>='] = $doc_date_start; + } + if (is_numeric($doc_date_end)) { + $filter['t.doc_date<='] = $doc_date_end; + } + + $result = $bookkeeping->fetchAll($sortorder, $sortfield, 0, 0, $filter, 'AND', $alreadyexport); + + if ($result < 0) { + throw new RestException(500, 'Error bookkeeping fetch all : '.$bookkeeping->errorsToString()); + } else { + // export files then exit + if (empty($lettering)) { + if (is_array($bookkeeping->lines)) { + foreach ($bookkeeping->lines as $k => $movement) { + unset($bookkeeping->lines[$k]->lettering_code); + unset($bookkeeping->lines[$k]->date_lettering); + } + } + } + + $error = 0; + $this->db->begin(); + + if (empty($notnotifiedasexport)) { + if (is_array($bookkeeping->lines)) { + foreach ($bookkeeping->lines as $movement) { + $now = dol_now(); + + $sql = " UPDATE " . MAIN_DB_PREFIX . "accounting_bookkeeping"; + $sql .= " SET date_export = '" . $this->db->idate($now) . "'"; + $sql .= " WHERE rowid = " . ((int)$movement->id); + + $result = $this->db->query($sql); + if (!$result) { + $accountancyexport->errors[] = $langs->trans('NotAllExportedMovementsCouldBeRecordedAsExportedOrValidated'); + $error++; + break; + } + } + } + } + + // export and only write file without downloading + if (!$error) { + $result = $accountancyexport->export($bookkeeping->lines, $format_number, 0, 1, 2); + if ($result < 0) { + $error++; + } + } + + if ($error) { + $this->db->rollback(); + throw new RestException(500, 'Error accountancy export : '.implode(',', $accountancyexport->errors)); + } else { + $this->db->commit(); + exit(); + } + } + } +} diff --git a/htdocs/accountancy/tpl/export_journal.tpl.php b/htdocs/accountancy/tpl/export_journal.tpl.php index 8e3c914a6f5..767f95cb252 100644 --- a/htdocs/accountancy/tpl/export_journal.tpl.php +++ b/htdocs/accountancy/tpl/export_journal.tpl.php @@ -19,6 +19,7 @@ */ // $formatexportset must be defined +// $downloadMode =0 for direct download or =1 to download after writing files or =-1 not to download files // Protection to avoid direct call of template if (empty($conf) || !is_object($conf)) { @@ -35,7 +36,7 @@ $siren = getDolGlobalString('MAIN_INFO_SIREN'); $date_export = "_".dol_print_date(dol_now(), '%Y%m%d%H%M%S'); $endaccountingperiod = dol_print_date(dol_now(), '%Y%m%d'); -if (empty($withAttachment)) { +if (empty($downloadMode)) { header('Content-Type: text/csv'); } @@ -70,6 +71,6 @@ if (($accountancyexport->getFormatCode($formatexportset) == 'fec' || $accountanc $completefilename = ($code ? $code."_" : "").($prefix ? $prefix."_" : "").$filename.($nodateexport ? "" : $date_export).".".$format; } -if (empty($withAttachment)) { +if (empty($downloadMode)) { header('Content-Disposition: attachment;filename=' . $completefilename); } diff --git a/htdocs/core/lib/accounting.lib.php b/htdocs/core/lib/accounting.lib.php index 5c1f0b078a3..38a7fefc483 100644 --- a/htdocs/core/lib/accounting.lib.php +++ b/htdocs/core/lib/accounting.lib.php @@ -331,3 +331,56 @@ function getDefaultDatesForTransfer() 'pastmonth' => $pastmonth ); } + +/** + * Get current period of fiscal year + * + * @param DoliDB $db Database handler + * @param stdClass $conf Config + * @param int $from_time [=null] Get current time or set time to find fiscal period + * @return array Period of fiscal year : [date_start, date_end] + */ +function getCurrentPeriodOfFiscalYear($db, $conf, $from_time = null) +{ + $now = dol_now(); + $now_arr = dol_getdate($now); + if ($from_time === null) { + $from_time = $now; + } + $from_db_time = $db->idate($from_time); + + $sql = "SELECT date_start, date_end FROM ".$db->prefix()."accounting_fiscalyear"; + $sql .= " WHERE date_start <= '".$from_db_time."' AND date_end >= '".$from_db_time."'"; + $sql .= $db->order('date_start', 'DESC'); + $sql .= $db->plimit(1); + $res = $db->query($sql); + if ($db->num_rows($res) > 0) { + $obj = $db->fetch_object($res); + + $date_start = $db->jdate($obj->date_start); + $date_end = $db->jdate($obj->date_end); + } else { + $month_start = 1; + $conf_fiscal_month_start = (int) $conf->global->SOCIETE_FISCAL_MONTH_START; + if ($conf_fiscal_month_start >= 1 && $conf_fiscal_month_start <= 12) { + $month_start = $conf_fiscal_month_start; + } + $year_start = $now_arr['year']; + if ($conf_fiscal_month_start > $now_arr['mon']) { + $year_start = $year_start - 1; + } + $year_end = $year_start + 1; + $month_end = $month_start - 1; + if ($month_end < 1) { + $month_end = 12; + $year_end--; + } + $date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start); + $date_end = dol_get_last_day($year_end, $month_end); + } + + return array( + 'date_start' => $date_start, + 'date_end' => $date_end, + ); +} diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index ce639624f1a..3ed3d03c527 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -2668,6 +2668,8 @@ function getModuleDirForApiClass($moduleobject) $moduledirforclass = 'fichinter'; } elseif ($moduleobject == 'mos') { $moduledirforclass = 'mrp'; + } elseif ($moduleobject == 'accounting') { + $moduledirforclass = 'accountancy'; } elseif (in_array($moduleobject, array('products', 'expensereports', 'users', 'tickets', 'boms', 'receptions'))) { $moduledirforclass = preg_replace('/s$/', '', $moduleobject); } diff --git a/htdocs/core/modules/modAccounting.class.php b/htdocs/core/modules/modAccounting.class.php index 7a4ffabd4ab..07591de93a7 100644 --- a/htdocs/core/modules/modAccounting.class.php +++ b/htdocs/core/modules/modAccounting.class.php @@ -57,7 +57,7 @@ class modAccounting extends DolibarrModules $this->picto = 'accountancy'; // Data directories to create when module is enabled - $this->dirs = array('/accounting/temp'); + $this->dirs = array('/accounting/temp', '/accounting/export'); // Config pages $this->config_page_url = array('accounting.php?mainmenu=accountancy&leftmenu=accountancy_admin'); From 84ca644888869328c265ea81c9939c7b60df66b4 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 07:40:58 +0200 Subject: [PATCH 02/24] NEW: Accountancy REST API GET Exportdata --- .../class/accountancyexport.class.php | 236 ++++++++++++------ 1 file changed, 153 insertions(+), 83 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index a3c39cb06ee..9636fe095ac 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -37,8 +37,10 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - +require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; /** * Manage the different format accountancy export @@ -313,12 +315,19 @@ class AccountancyExport /** * Function who chose which export to use with the default config, and make the export into a file * - * @param array $TData Array with data - * @param int $formatexportset Id of export format - * @param int $withAttachment [=0] Not add files or 1 to have attached in an archive (ex : Quadratus) + * @param array $TData Array with data + * @param int $formatexportset Id of export format + * @param int $withAttachment [=0] Not add files + * or 1 to have attached in an archive (ex : Quadratus) - Force output mode to write in a file (output mode = 1) + * @param int $downloadMode [=0] Direct download + * or 1 to download after writing files - Forced by default when use withAttachment = 1 + * or -1 not to download files + * @param int $outputMode [=0] Print on screen + * or 1 to write in file and uses a temp directory - Forced by default when use withAttachment = 1 + * or 2 to write in file a default export directory (accounting/export/) * @return int <0 if KO, >0 OK */ - public function export(&$TData, $formatexportset, $withAttachment = 0) + public function export(&$TData, $formatexportset, $withAttachment = 0, $downloadMode = 0, $outputMode = 0) { global $conf, $langs; global $search_date_end; // Used into /accountancy/tpl/export_journal.tpl.php @@ -332,101 +341,152 @@ class AccountancyExport $exportFile = null; $exportFileName = ''; $exportFilePath = ''; + $archiveFullName = ''; + $archivePath = ''; $archiveFileList = array(); if ($withAttachment == 1) { + if ($downloadMode == 0) { + $downloadMode = 1; // force to download after writing all files (can't use direct download) + } + if ($outputMode == 0) { + $outputMode = 1; // force to put files in a temp directory (can't use print on screen) + } + // PHP ZIP extension must be enabled if (!extension_loaded('zip')) { $langs->load('install'); $this->errors[] = $langs->trans('ErrorPHPDoesNotSupport', 'ZIP'); return -1; } - } else { - $mimetype = $this->getMimeType($formatexportset); + } + + $mimetype = $this->getMimeType($formatexportset); + if ($downloadMode == 0) { + // begin to print header for direct download top_httphead($mimetype, 1); } include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php'; - if ($withAttachment == 1 && !empty($completefilename)) { - // create export file - $tmpDir = !empty($conf->accounting->multidir_temp[$conf->entity]) ? $conf->accounting->multidir_temp[$conf->entity] : $conf->accounting->dir_temp; - $exportFileFullName = $completefilename; - $exportFileBaseName = basename($exportFileFullName); - $exportFileName = pathinfo($exportFileBaseName, PATHINFO_FILENAME); - $exportFilePath = $tmpDir.'/'.$exportFileFullName; - $exportFile = fopen($exportFilePath, 'w'); - if (!$exportFile) { - $this->errors[] = $langs->trans('ErrorFileNotFound', $exportFilePath); - return -1; - } - $archiveFileList[0] = array( - 'path' => $exportFilePath, - 'name' => $exportFileFullName, - ); + if ($outputMode == 1 || $outputMode == 2) { + if ($outputMode == 1) { + // uses temp directory by default to write files + if (!empty($conf->accounting->multidir_temp[$conf->entity])) { + $outputDir = $conf->accounting->multidir_temp[$conf->entity]; + } else { + $outputDir = $conf->accounting->dir_temp; + } + } else { + // uses default export directory "accounting/export" + if (!empty($conf->accounting->multidir_output[$conf->entity])) { + $outputDir = $conf->accounting->multidir_output[$conf->entity]; + } else { + $outputDir = $conf->accounting->dir_output; + } - // archive name and path - $archiveFullName = $exportFileName.'.zip'; - $archivePath = $tmpDir.'/'.$archiveFullName; + // directory already created when module is enabled + $outputDir .= '/export'; + $outputDir .= '/'.dol_sanitizePathName($formatexportset); + if (!dol_is_dir($outputDir)) { + if (dol_mkdir($outputDir) < 0) { + $this->errors[] = $langs->trans('ErrorCanNotCreateDir', $outputDir);; + return -1; + } + } + } + + if ($outputDir != '') { + if (!dol_is_dir($outputDir)) { + $langs->load('errors'); + $this->errors[] = $langs->trans('ErrorDirNotFound', $outputDir);; + return -1; + } + + if (!empty($completefilename)) { + // create export file + $exportFileFullName = $completefilename; + $exportFileBaseName = basename($exportFileFullName); + $exportFileName = pathinfo($exportFileBaseName, PATHINFO_FILENAME); + $exportFilePath = $outputDir . '/' . $exportFileFullName; + $exportFile = fopen($exportFilePath, 'w'); + if (!$exportFile) { + $this->errors[] = $langs->trans('ErrorFileNotFound', $exportFilePath); + return -1; + } + + if ($withAttachment == 1) { + $archiveFileList[0] = array( + 'path' => $exportFilePath, + 'name' => $exportFileFullName, + ); + + // archive name and path + $archiveFullName = $exportFileName . '.zip'; + $archivePath = $outputDir . '/' . $archiveFullName; + } + } + } } + // export file (print on screen or write in a file) and prepare archive list if with attachment is set to 1 switch ($formatexportset) { case self::$EXPORT_TYPE_CONFIGURABLE: - $this->exportConfigurable($TData); + $this->exportConfigurable($TData, $exportFile); break; case self::$EXPORT_TYPE_CEGID: - $this->exportCegid($TData); + $this->exportCegid($TData, $exportFile); break; case self::$EXPORT_TYPE_COALA: - $this->exportCoala($TData); + $this->exportCoala($TData, $exportFile); break; case self::$EXPORT_TYPE_BOB50: - $this->exportBob50($TData); + $this->exportBob50($TData, $exportFile); break; case self::$EXPORT_TYPE_CIEL: - $this->exportCiel($TData); + $this->exportCiel($TData, $exportFile); break; case self::$EXPORT_TYPE_QUADRATUS: $archiveFileList = $this->exportQuadratus($TData, $exportFile, $archiveFileList, $withAttachment); break; case self::$EXPORT_TYPE_WINFIC: - $this->exportWinfic($TData); + $this->exportWinfic($TData, $exportFile); break; case self::$EXPORT_TYPE_EBP: - $this->exportEbp($TData); + $this->exportEbp($TData, $exportFile); break; case self::$EXPORT_TYPE_COGILOG: - $this->exportCogilog($TData); + $this->exportCogilog($TData, $exportFile); break; case self::$EXPORT_TYPE_AGIRIS: - $this->exportAgiris($TData); + $this->exportAgiris($TData, $exportFile); break; case self::$EXPORT_TYPE_OPENCONCERTO: - $this->exportOpenConcerto($TData); + $this->exportOpenConcerto($TData, $exportFile); break; case self::$EXPORT_TYPE_SAGE50_SWISS: - $this->exportSAGE50SWISS($TData); + $this->exportSAGE50SWISS($TData, $exportFile); break; case self::$EXPORT_TYPE_CHARLEMAGNE: - $this->exportCharlemagne($TData); + $this->exportCharlemagne($TData, $exportFile); break; case self::$EXPORT_TYPE_LDCOMPTA: - $this->exportLDCompta($TData); + $this->exportLDCompta($TData, $exportFile); break; case self::$EXPORT_TYPE_LDCOMPTA10: - $this->exportLDCompta10($TData); + $this->exportLDCompta10($TData, $exportFile); break; case self::$EXPORT_TYPE_GESTIMUMV3: - $this->exportGestimumV3($TData); + $this->exportGestimumV3($TData, $exportFile); break; case self::$EXPORT_TYPE_GESTIMUMV5: - $this->exportGestimumV5($TData); + $this->exportGestimumV5($TData, $exportFile); break; case self::$EXPORT_TYPE_FEC: - $this->exportFEC($TData); + $this->exportFEC($TData, $exportFile); break; case self::$EXPORT_TYPE_FEC2: - $this->exportFEC2($TData); + $this->exportFEC2($TData, $exportFile); break; case self::$EXPORT_TYPE_ISUITEEXPERT : - $this->exportiSuiteExpert($TData); + $this->exportiSuiteExpert($TData, $exportFile); break; default: global $hookmanager; @@ -440,7 +500,7 @@ class AccountancyExport } // create and download export file or archive - if ($withAttachment == 1) { + if ($outputMode == 1 || $outputMode == 2) { $error = 0; // close export file @@ -448,50 +508,60 @@ class AccountancyExport fclose($exportFile); } - if (!empty($archiveFullName) && !empty($archivePath) && !empty($archiveFileList)) { - // archive files - $downloadFileMimeType = 'application/zip'; - $downloadFileFullName = $archiveFullName; - $downloadFilePath = $archivePath; + if ($withAttachment == 1) { + // create archive file + if (!empty($archiveFullName) && !empty($archivePath) && !empty($archiveFileList)) { + // archive files + $downloadFileMimeType = 'application/zip'; + $downloadFileFullName = $archiveFullName; + $downloadFilePath = $archivePath; - // create archive - $archive = new ZipArchive(); - $res = $archive->open($archivePath, ZipArchive::OVERWRITE | ZipArchive::CREATE); - if ($res !== true) { - $error++; - $this->errors[] = $langs->trans('ErrorFileNotFound', $archivePath); - } - if (!$error) { - // add files - foreach ($archiveFileList as $archiveFileArr) { - $res = $archive->addFile($archiveFileArr['path'], $archiveFileArr['name']); - if (!$res) { - $error++; - $this->errors[] = $langs->trans('ErrorArchiveAddFile', $archiveFileArr['name']); - break; + // create archive + $archive = new ZipArchive(); + $res = $archive->open($archivePath, ZipArchive::OVERWRITE | ZipArchive::CREATE); + if ($res !== true) { + $error++; + $this->errors[] = $langs->trans('ErrorFileNotFound', $archivePath); + } + if (!$error) { + // add files + foreach ($archiveFileList as $archiveFileArr) { + $res = $archive->addFile($archiveFileArr['path'], $archiveFileArr['name']); + if (!$res) { + $error++; + $this->errors[] = $langs->trans('ErrorArchiveAddFile', $archiveFileArr['name']); + break; + } } } + if (!$error) { + // close archive + $archive->close(); + } } - if (!$error) { - // close archive - $archive->close(); - } - } elseif (!empty($exportFileFullName) && !empty($exportFilePath)) { - // only one file to download - $downloadFileMimeType = 'text/csv'; - $downloadFileFullName = $exportFileFullName; - $downloadFilePath = $exportFilePath; } if (!$error) { - // download export file - if (!empty($downloadFileMimeType) && !empty($downloadFileFullName) && !empty($downloadFilePath)) { - header('Content-Type: '.$downloadFileMimeType); - header('Content-Disposition: attachment; filename='.$downloadFileFullName); - header('Cache-Control: Public, must-revalidate'); - header('Pragma: public'); - header('Content-Length: '.dol_filesize($downloadFilePath)); - readfileLowMemory($downloadFilePath); + // download after writing files + if ($downloadMode == 1) { + if ($withAttachment == 0) { + // only download exported file + if (!empty($exportFileFullName) && !empty($exportFilePath)) { + $downloadFileMimeType = $mimetype; + $downloadFileFullName = $exportFileFullName; + $downloadFilePath = $exportFilePath; + } + } + + // download export file or archive + if (!empty($downloadFileMimeType) && !empty($downloadFileFullName) && !empty($downloadFilePath)) { + header('Content-Type: ' . $downloadFileMimeType); + header('Content-Disposition: attachment; filename=' . $downloadFileFullName); + header('Cache-Control: Public, must-revalidate'); + header('Pragma: public'); + header('Content-Length: ' . dol_filesize($downloadFilePath)); + readfileLowMemory($downloadFilePath); + } } } From f94d2c2ece842df612f9ddff4ea41d8414fb49f8 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 07:42:33 +0200 Subject: [PATCH 03/24] Update Cegid Export --- .../class/accountancyexport.class.php | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index 9636fe095ac..c6e44b4dc83 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -577,25 +577,35 @@ class AccountancyExport /** * Export format : CEGID * - * @param array $objectLines data - * @return void + * @param array $objectLines data + * @param resource $exportFile [=null] File resource to export or print if null + * @return void */ - public function exportCegid($objectLines) + public function exportCegid($objectLines, $exportFile = null) { - foreach ($objectLines as $line) { - $date = dol_print_date($line->doc_date, '%d%m%Y'); - $separator = ";"; - $end_line = "\n"; + $separator = ";"; + $end_line = "\n"; - print $date.$separator; - print $line->code_journal.$separator; - print length_accountg($line->numero_compte).$separator; - print length_accounta($line->subledger_account).$separator; - print $line->sens.$separator; - print price2fec(abs($line->debit - $line->credit)).$separator; - print dol_string_unaccent($line->label_operation).$separator; - print dol_string_unaccent($line->doc_ref); - print $end_line; + foreach ($objectLines as $line) { + $date_document = dol_print_date($line->doc_date, '%d%m%Y'); + + $tab = array(); + + $tab[] = $date_document; + $tab[] = $line->code_journal; + $tab[] = length_accountg($line->numero_compte); + $tab[] = length_accounta($line->subledger_account); + $tab[] = $line->sens; + $tab[] = price2fec(abs($line->debit - $line->credit)); + $tab[] = dol_string_unaccent($line->label_operation); + $tab[] = dol_string_unaccent($line->doc_ref); + + $output = implode($separator, $tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } } } From c22d5d076e8e82d37ddbc18d7d39bd4dc80da53f Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 07:43:15 +0200 Subject: [PATCH 04/24] Update Cogilog Export --- .../class/accountancyexport.class.php | 52 +++++++++++-------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index c6e44b4dc83..48e6481106b 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -612,33 +612,43 @@ class AccountancyExport /** * Export format : COGILOG * - * @param array $objectLines data - * @return void + * @param array $objectLines data + * @param resource $exportFile [=null] File resource to export or print if null + * @return void */ - public function exportCogilog($objectLines) + public function exportCogilog($objectLines, $exportFile = null) { - foreach ($objectLines as $line) { - $date = dol_print_date($line->doc_date, '%d%m%Y'); - $separator = ";"; - $end_line = "\n"; + $separator = ";"; + $end_line = "\n"; - print $line->code_journal.$separator; - print $date.$separator; - print $line->piece_num.$separator; - print length_accountg($line->numero_compte).$separator; - print $separator; - print $line->label_operation.$separator; - print $date.$separator; + foreach ($objectLines as $line) { + $date_document = dol_print_date($line->doc_date, '%d%m%Y'); + + $tab = array(); + + $tab[] = $line->code_journal; + $tab[] = $date_document; + $tab[] = $line->piece_num; + $tab[] = length_accountg($line->numero_compte); + $tab[] = ""; + $tab[] = $line->label_operation; + $tab[] = $date_document; if ($line->sens == 'D') { - print price($line->debit).$separator; - print $separator; + $tab[] = price($line->debit); + $tab[] = ""; } elseif ($line->sens == 'C') { - print $separator; - print price($line->credit).$separator; + $tab[] = ""; + $tab[] = price($line->credit); + } + $tab[] = $line->doc_ref; + $tab[] = $line->label_operation; + + $output = implode($separator, $tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; } - print $line->doc_ref.$separator; - print $line->label_operation.$separator; - print $end_line; } } From 078be6088fb97adef4151014c718456e60e9db99 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 07:43:48 +0200 Subject: [PATCH 05/24] Update Coala Export --- .../class/accountancyexport.class.php | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index 48e6481106b..b349ea585e8 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -655,28 +655,37 @@ class AccountancyExport /** * Export format : COALA * - * @param array $objectLines data - * @return void + * @param array $objectLines data + * @param resource $exportFile [=null] File resource to export or print if null + * @return void */ - public function exportCoala($objectLines) + public function exportCoala($objectLines, $exportFile = null) { // Coala export $separator = ";"; $end_line = "\n"; foreach ($objectLines as $line) { - $date = dol_print_date($line->doc_date, '%d/%m/%Y'); + $date_document = dol_print_date($line->doc_date, '%d/%m/%Y'); - print $date.$separator; - print $line->code_journal.$separator; - print length_accountg($line->numero_compte).$separator; - print $line->piece_num.$separator; - print $line->doc_ref.$separator; - print price($line->debit).$separator; - print price($line->credit).$separator; - print 'E'.$separator; - print length_accounta($line->subledger_account).$separator; - print $end_line; + $tab = array(); + + $tab[] = $date_document; + $tab[] = $line->code_journal; + $tab[] = length_accountg($line->numero_compte); + $tab[] = $line->piece_num; + $tab[] = $line->doc_ref; + $tab[] = price($line->debit); + $tab[] = price($line->credit); + $tab[] = 'E'; + $tab[] = length_accounta($line->subledger_account); + + $output = implode($separator, $tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } } } From ca0e032a042de0bef2a9efa270bc5cfe26396f22 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 07:44:32 +0200 Subject: [PATCH 06/24] Update Bob50 Export --- .../class/accountancyexport.class.php | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index b349ea585e8..088529deded 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -692,38 +692,47 @@ class AccountancyExport /** * Export format : BOB50 * - * @param array $objectLines data - * @return void + * @param array $objectLines data + * @param resource $exportFile [=null] File resource to export or print if null + * @return void */ - public function exportBob50($objectLines) + public function exportBob50($objectLines, $exportFile = null) { - // Bob50 $separator = ";"; $end_line = "\n"; foreach ($objectLines as $line) { - print $line->piece_num.$separator; - $date = dol_print_date($line->doc_date, '%d/%m/%Y'); - print $date.$separator; + $date_document = dol_print_date($line->doc_date, '%d/%m/%Y'); + + $tab = array(); + + $tab[] = $line->piece_num; + $tab[] = $date_document; if (empty($line->subledger_account)) { - print 'G'.$separator; - print length_accounta($line->numero_compte).$separator; + $tab[] = 'G'; + $tab[] = length_accountg($line->numero_compte); } else { if (substr($line->numero_compte, 0, 3) == '411') { - print 'C'.$separator; + $tab[] = 'C'; } if (substr($line->numero_compte, 0, 3) == '401') { - print 'F'.$separator; + $tab[] = 'F'; } - print length_accountg($line->subledger_account).$separator; + $tab[] = length_accounta($line->subledger_account); } - print price($line->debit).$separator; - print price($line->credit).$separator; - print dol_trunc($line->label_operation, 32).$separator; - print $end_line; + $tab[] = price($line->debit); + $tab[] = price($line->credit); + $tab[] = dol_trunc($line->label_operation, 32); + + $output = implode($separator, $tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } } } From 226454b602b0c040c4992ac2935614e837873e03 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 07:45:09 +0200 Subject: [PATCH 07/24] Update Ciel Export --- .../class/accountancyexport.class.php | 53 ++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index 088529deded..fcb0a3d938f 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -747,41 +747,46 @@ class AccountancyExport * If you want to force filename to "XIMPORT.TXT" for automatically import file present in a directory : * use constant ACCOUNTING_EXPORT_XIMPORT_FORCE_FILENAME * - * @param array $TData data - * @return void + * @param array $objectLines data + * @param resource $exportFile [=null] File resource to export or print if null + * @return void */ - public function exportCiel(&$TData) + public function exportCiel($objectLines, $exportFile = null) { $end_line = "\r\n"; $i = 1; - foreach ($TData as $data) { - $code_compta = length_accountg($data->numero_compte); - if (!empty($data->subledger_account)) { - $code_compta = length_accounta($data->subledger_account); + foreach ($objectLines as $line) { + $code_compta = length_accountg($line->numero_compte); + if (!empty($line->subledger_account)) { + $code_compta = length_accounta($line->subledger_account); } - $date_document = dol_print_date($data->doc_date, '%Y%m%d'); - $date_echeance = dol_print_date($data->date_lim_reglement, '%Y%m%d'); + $date_document = dol_print_date($line->doc_date, '%Y%m%d'); + $date_echeance = dol_print_date($line->date_lim_reglement, '%Y%m%d'); - $Tab = array(); - $Tab['num_ecriture'] = str_pad($data->piece_num, 5); - $Tab['code_journal'] = str_pad(self::trunc($data->code_journal, 2), 2); - $Tab['date_ecriture'] = str_pad($date_document, 8, ' ', STR_PAD_LEFT); - $Tab['date_echeance'] = str_pad($date_echeance, 8, ' ', STR_PAD_LEFT); - $Tab['num_piece'] = str_pad(self::trunc($data->doc_ref, 12), 12); - $Tab['num_compte'] = str_pad(self::trunc($code_compta, 11), 11); - $Tab['libelle_ecriture'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref).dol_string_unaccent($data->label_operation), 25), 25); - $Tab['montant'] = str_pad(price2fec(abs($data->debit - $data->credit)), 13, ' ', STR_PAD_LEFT); - $Tab['type_montant'] = str_pad($data->sens, 1); - $Tab['vide'] = str_repeat(' ', 18); // Analytical accounting - Not managed in Dolibarr - $Tab['intitule_compte'] = str_pad(self::trunc(dol_string_unaccent($data->label_operation), 34), 34); - $Tab['end'] = 'O2003'; // 0 = EUR | 2003 = Format Ciel + $tab = array(); - $Tab['end_line'] = $end_line; + $tab[] = str_pad($line->piece_num, 5); + $tab[] = str_pad(self::trunc($line->code_journal, 2), 2); + $tab[] = str_pad($date_document, 8, ' ', STR_PAD_LEFT); + $tab[] = str_pad($date_echeance, 8, ' ', STR_PAD_LEFT); + $tab[] = str_pad(self::trunc($line->doc_ref, 12), 12); + $tab[] = str_pad(self::trunc($code_compta, 11), 11); + $tab[] = str_pad(self::trunc(dol_string_unaccent($line->doc_ref).dol_string_unaccent($line->label_operation), 25), 25); + $tab[] = str_pad(price2fec(abs($line->debit - $line->credit)), 13, ' ', STR_PAD_LEFT); + $tab[] = str_pad($line->sens, 1); + $tab[] = str_repeat(' ', 18); // Analytical accounting - Not managed in Dolibarr + $tab[] = str_pad(self::trunc(dol_string_unaccent($line->label_operation), 34), 34); + $tab[] = 'O2003'; // 0 = EUR | 2003 = Format Ciel - print implode($Tab); + $output = implode($tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } $i++; } } From e692919438520e63a4ee5da9f10bf83314ea4f35 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 07:46:36 +0200 Subject: [PATCH 08/24] Update Quadra Export --- .../class/accountancyexport.class.php | 186 +++++++++--------- 1 file changed, 93 insertions(+), 93 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index fcb0a3d938f..60a46e15649 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -799,13 +799,13 @@ class AccountancyExport * Help : https://docplayer.fr/20769649-Fichier-d-entree-ascii-dans-quadracompta.html * In QuadraCompta | Use menu : "Outils" > "Suivi des dossiers" > "Import ASCII(Compta)" * - * @param array $TData Data + * @param array $objectLines data * @param resource $exportFile [=null] File resource to export or print if null * @param array $archiveFileList [=array()] Archive file list : array of ['path', 'name'] * @param bool $withAttachment [=0] Not add files or 1 to have attached in an archive * @return array Archive file list : array of ['path', 'name'] */ - public function exportQuadratus(&$TData, $exportFile = null, $archiveFileList = array(), $withAttachment = 0) + public function exportQuadratus($objectLines, $exportFile = null, $archiveFileList = array(), $withAttachment = 0) { global $conf, $db; @@ -814,152 +814,152 @@ class AccountancyExport // We should use dol_now function not time however this is wrong date to transfert in accounting // $date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy // $date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy - foreach ($TData as $data) { + foreach ($objectLines as $line) { // Clean some data - $data->doc_ref = dol_string_unaccent($data->doc_ref); - $data->label_operation = dol_string_unaccent($data->label_operation); - $data->numero_compte = dol_string_unaccent($data->numero_compte); - $data->label_compte = dol_string_unaccent($data->label_compte); - $data->subledger_account = dol_string_unaccent($data->subledger_account); - $data->subledger_label = dol_string_unaccent($data->subledger_label); + $line->doc_ref = dol_string_unaccent($line->doc_ref); + $line->label_operation = dol_string_unaccent($line->label_operation); + $line->numero_compte = dol_string_unaccent($line->numero_compte); + $line->label_compte = dol_string_unaccent($line->label_compte); + $line->subledger_account = dol_string_unaccent($line->subledger_account); + $line->subledger_label = dol_string_unaccent($line->subledger_label); - $code_compta = $data->numero_compte; - if (!empty($data->subledger_account)) { - $code_compta = $data->subledger_account; + $code_compta = $line->numero_compte; + if (!empty($line->subledger_account)) { + $code_compta = $line->subledger_account; } - $Tab = array(); + $tab = array(); - if (!empty($data->subledger_account)) { - $Tab['type_ligne'] = 'C'; - $Tab['num_compte'] = str_pad(self::trunc($data->subledger_account, 8), 8); - $Tab['lib_compte'] = str_pad(self::trunc($data->subledger_label, 30), 30); + if (!empty($line->subledger_account)) { + $tab['type_ligne'] = 'C'; + $tab['num_compte'] = str_pad(self::trunc($line->subledger_account, 8), 8); + $tab['lib_compte'] = str_pad(self::trunc($line->subledger_label, 30), 30); - if ($data->doc_type == 'customer_invoice') { - $Tab['lib_alpha'] = strtoupper(str_pad('C'.self::trunc($data->subledger_label, 6), 6)); - $Tab['filler'] = str_repeat(' ', 52); - $Tab['coll_compte'] = str_pad(self::trunc($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER, 8), 8); - } elseif ($data->doc_type == 'supplier_invoice') { - $Tab['lib_alpha'] = strtoupper(str_pad('F'.self::trunc($data->subledger_label, 6), 6)); - $Tab['filler'] = str_repeat(' ', 52); - $Tab['coll_compte'] = str_pad(self::trunc($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER, 8), 8); + if ($line->doc_type == 'customer_invoice') { + $tab['lib_alpha'] = strtoupper(str_pad('C'.self::trunc(dol_string_unaccent($line->subledger_label), 6), 6)); + $tab['filler'] = str_repeat(' ', 52); + $tab['coll_compte'] = str_pad(self::trunc($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER, 8), 8); + } elseif ($line->doc_type == 'supplier_invoice') { + $tab['lib_alpha'] = strtoupper(str_pad('F'.self::trunc(dol_string_unaccent($line->subledger_label), 6), 6)); + $tab['filler'] = str_repeat(' ', 52); + $tab['coll_compte'] = str_pad(self::trunc($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER, 8), 8); } else { - $Tab['filler'] = str_repeat(' ', 59); - $Tab['coll_compte'] = str_pad(' ', 8); + $tab['filler'] = str_repeat(' ', 59); + $tab['coll_compte'] = str_pad(' ', 8); } - $Tab['filler2'] = str_repeat(' ', 110); - $Tab['Maj'] = 2; // Partial update (alpha key, label, address, collectif, RIB) + $tab['filler2'] = str_repeat(' ', 110); + $tab['Maj'] = 2; // Partial update (alpha key, label, address, collectif, RIB) - if ($data->doc_type == 'customer_invoice') { - $Tab['type_compte'] = 'C'; - } elseif ($data->doc_type == 'supplier_invoice') { - $Tab['type_compte'] = 'F'; + if ($line->doc_type == 'customer_invoice') { + $tab['type_compte'] = 'C'; + } elseif ($line->doc_type == 'supplier_invoice') { + $tab['type_compte'] = 'F'; } else { - $Tab['type_compte'] = 'G'; + $tab['type_compte'] = 'G'; } - $Tab['filler3'] = str_repeat(' ', 235); + $tab['filler3'] = str_repeat(' ', 235); - $Tab['end_line'] = $end_line; + $tab['end_line'] = $end_line; if ($exportFile) { - fwrite($exportFile, implode($Tab)); + fwrite($exportFile, implode($tab)); } else { - print implode($Tab); + print implode($tab); } } - $Tab = array(); - $Tab['type_ligne'] = 'M'; - $Tab['num_compte'] = str_pad(self::trunc($code_compta, 8), 8); - $Tab['code_journal'] = str_pad(self::trunc($data->code_journal, 2), 2); - $Tab['folio'] = '000'; + $tab = array(); + $tab['type_ligne'] = 'M'; + $tab['num_compte'] = str_pad(self::trunc($code_compta, 8), 8); + $tab['code_journal'] = str_pad(self::trunc($line->code_journal, 2), 2); + $tab['folio'] = '000'; - // We use invoice date $data->doc_date not $date_ecriture which is the transfert date + // We use invoice date $line->doc_date not $date_ecriture which is the transfert date // maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ? - //$Tab['date_ecriture'] = $date_ecriture; - $Tab['date_ecriture'] = dol_print_date($data->doc_date, '%d%m%y'); - $Tab['filler'] = ' '; - $Tab['libelle_ecriture'] = str_pad(self::trunc($data->doc_ref.' '.$data->label_operation, 20), 20); + //$tab['date_ecriture'] = $date_ecriture; + $tab['date_ecriture'] = dol_print_date($line->doc_date, '%d%m%y'); + $tab['filler'] = ' '; + $tab['libelle_ecriture'] = str_pad(self::trunc($line->doc_ref.' '.$line->label_operation, 20), 20); // Credit invoice - invert sens /* - if ($data->montant < 0) { - if ($data->sens == 'C') { - $Tab['sens'] = 'D'; + if ($line->montant < 0) { + if ($line->sens == 'C') { + $tab['sens'] = 'D'; } else { - $Tab['sens'] = 'C'; + $tab['sens'] = 'C'; } - $Tab['signe_montant'] = '-'; + $tab['signe_montant'] = '-'; } else { - $Tab['sens'] = $data->sens; // C or D - $Tab['signe_montant'] = '+'; + $tab['sens'] = $line->sens; // C or D + $tab['signe_montant'] = '+'; }*/ - $Tab['sens'] = $data->sens; // C or D - $Tab['signe_montant'] = '+'; + $tab['sens'] = $line->sens; // C or D + $tab['signe_montant'] = '+'; // The amount must be in centimes without decimal points. - $Tab['montant'] = str_pad(abs(($data->debit - $data->credit) * 100), 12, '0', STR_PAD_LEFT); - $Tab['contrepartie'] = str_repeat(' ', 8); + $tab['montant'] = str_pad(abs(($line->debit - $line->credit) * 100), 12, '0', STR_PAD_LEFT); + $tab['contrepartie'] = str_repeat(' ', 8); // Force date format : %d%m%y - if (!empty($data->date_lim_reglement)) { - //$Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, $conf->global->ACCOUNTING_EXPORT_DATE); - $Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, '%d%m%y'); // Format must be ddmmyy + if (!empty($line->date_lim_reglement)) { + //$tab['date_echeance'] = dol_print_date($line->date_lim_reglement, $conf->global->ACCOUNTING_EXPORT_DATE); + $tab['date_echeance'] = dol_print_date($line->date_lim_reglement, '%d%m%y'); // Format must be ddmmyy } else { - $Tab['date_echeance'] = '000000'; + $tab['date_echeance'] = '000000'; } // Please keep quadra named field lettrage(2) + codestat(3) instead of fake lettrage(5) - // $Tab['lettrage'] = str_repeat(' ', 5); - $Tab['lettrage'] = str_repeat(' ', 2); - $Tab['codestat'] = str_repeat(' ', 3); - $Tab['num_piece'] = str_pad(self::trunc($data->piece_num, 5), 5); + // $tab['lettrage'] = str_repeat(' ', 5); + $tab['lettrage'] = str_repeat(' ', 2); + $tab['codestat'] = str_repeat(' ', 3); + $tab['num_piece'] = str_pad(self::trunc($line->piece_num, 5), 5); // Keep correct quadra named field instead of anon filler - // $Tab['filler2'] = str_repeat(' ', 20); - $Tab['affaire'] = str_repeat(' ', 10); - $Tab['quantity1'] = str_repeat(' ', 10); - $Tab['num_piece2'] = str_pad(self::trunc($data->piece_num, 8), 8); - $Tab['devis'] = str_pad($conf->currency, 3); - $Tab['code_journal2'] = str_pad(self::trunc($data->code_journal, 3), 3); - $Tab['filler3'] = str_repeat(' ', 3); + // $tab['filler2'] = str_repeat(' ', 20); + $tab['affaire'] = str_repeat(' ', 10); + $tab['quantity1'] = str_repeat(' ', 10); + $tab['num_piece2'] = str_pad(self::trunc($line->piece_num, 8), 8); + $tab['devis'] = str_pad($conf->currency, 3); + $tab['code_journal2'] = str_pad(self::trunc($line->code_journal, 3), 3); + $tab['filler3'] = str_repeat(' ', 3); // Keep correct quadra named field instead of anon filler libelle_ecriture2 is 30 char not 32 !!!! // as we use utf8, we must remove accent to have only one ascii char instead of utf8 2 chars for specials that report wrong line size that will exceed import format spec // TODO: we should filter more than only accent to avoid wrong line size // TODO: remove invoice number doc_ref in label, // TODO: we should offer an option for customer to build the label using invoice number / name / date in accounting software - //$Tab['libelle_ecriture2'] = str_pad(self::trunc($data->doc_ref . ' ' . $data->label_operation, 30), 30); - $Tab['libelle_ecriture2'] = str_pad(self::trunc($data->label_operation, 30), 30); - $Tab['codetva'] = str_repeat(' ', 2); + //$tab['libelle_ecriture2'] = str_pad(self::trunc($line->doc_ref . ' ' . $line->label_operation, 30), 30); + $tab['libelle_ecriture2'] = str_pad(self::trunc($line->label_operation, 30), 30); + $tab['codetva'] = str_repeat(' ', 2); // We need to keep the 10 lastest number of invoice doc_ref not the beginning part that is the unusefull almost same part - // $Tab['num_piece3'] = str_pad(self::trunc($data->piece_num, 10), 10); - $Tab['num_piece3'] = substr(self::trunc($data->doc_ref, 20), -10); - $Tab['reserved'] = str_repeat(' ', 10); // position 159 - $Tab['currency_amount'] = str_repeat(' ', 13); // position 169 + // $tab['num_piece3'] = str_pad(self::trunc($line->piece_num, 10), 10); + $tab['num_piece3'] = substr(self::trunc($line->doc_ref, 20), -10); + $tab['reserved'] = str_repeat(' ', 10); // position 159 + $tab['currency_amount'] = str_repeat(' ', 13); // position 169 // get document file $attachmentFileName = ''; if ($withAttachment == 1) { - $attachmentFileKey = trim($data->piece_num); + $attachmentFileKey = trim($line->piece_num); if (!isset($archiveFileList[$attachmentFileKey])) { $objectDirPath = ''; - $objectFileName = dol_sanitizeFileName($data->doc_ref); - if ($data->doc_type == 'customer_invoice') { + $objectFileName = dol_sanitizeFileName($line->doc_ref); + if ($line->doc_type == 'customer_invoice') { $objectDirPath = !empty($conf->facture->multidir_output[$conf->entity]) ? $conf->facture->multidir_output[$conf->entity] : $conf->facture->dir_output; - } elseif ($data->doc_type == 'expense_report') { + } elseif ($line->doc_type == 'expense_report') { $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->factureexpensereport->dir_output; - } elseif ($data->doc_type == 'supplier_invoice') { + } elseif ($line->doc_type == 'supplier_invoice') { $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output; } $arrayofinclusion = array(); $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').'\.pdf$'; $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, true); if (!empty($fileFoundList)) { - $attachmentFileNameTrunc = str_pad(self::trunc($data->piece_num, 8), 8, '0', STR_PAD_LEFT); + $attachmentFileNameTrunc = str_pad(self::trunc($line->piece_num, 8), 8, '0', STR_PAD_LEFT); foreach ($fileFoundList as $fileFound) { if (strstr($fileFound['name'], $objectFileName)) { $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name']; @@ -980,17 +980,17 @@ class AccountancyExport } } if (dol_strlen($attachmentFileName) == 12) { - $Tab['attachment'] = $attachmentFileName; // position 182 + $tab['attachment'] = $attachmentFileName; // position 182 } else { - $Tab['attachment'] = str_repeat(' ', 12); // position 182 + $tab['attachment'] = str_repeat(' ', 12); // position 182 } - $Tab['filler4'] = str_repeat(' ', 38); - $Tab['end_line'] = $end_line; + $tab['filler4'] = str_repeat(' ', 38); + $tab['end_line'] = $end_line; if ($exportFile) { - fwrite($exportFile, implode($Tab)); + fwrite($exportFile, implode($tab)); } else { - print implode($Tab); + print implode($tab); } } From 40358bb12ea3d69fbb2f6b45609794c11d8fa4da Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 07:47:38 +0200 Subject: [PATCH 09/24] Update Winfic Export --- .../class/accountancyexport.class.php | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index 60a46e15649..b33ef08ba34 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -1003,11 +1003,11 @@ class AccountancyExport * * Help : https://wiki.gestan.fr/lib/exe/fetch.php?media=wiki:v15:compta:accountancy-format_winfic-ewinfic-winsiscompta.pdf * - * @param array $TData data - * - * @return void + * @param array $objectLines data + * @param resource $exportFile [=null] File resource to export or print if null + * @return void */ - public function exportWinfic(&$TData) + public function exportWinfic($objectLines, $exportFile = null) { global $conf; @@ -1020,67 +1020,67 @@ class AccountancyExport // Warning ! When truncation is necessary, no dot because 3 dots = three characters. The columns are shifted - foreach ($TData as $data) { - $code_compta = $data->numero_compte; - if (!empty($data->subledger_account)) { - $code_compta = $data->subledger_account; + foreach ($objectLines as $line) { + $code_compta = $line->numero_compte; + if (!empty($line->subledger_account)) { + $code_compta = $line->subledger_account; } - $Tab = array(); - //$Tab['type_ligne'] = 'M'; - $Tab['code_journal'] = str_pad(dol_trunc($data->code_journal, 2, 'right', 'UTF-8', 1), 2); + $tab = array(); + //$tab['type_ligne'] = 'M'; + $tab['code_journal'] = str_pad(dol_trunc($line->code_journal, 2, 'right', 'UTF-8', 1), 2); - //We use invoice date $data->doc_date not $date_ecriture which is the transfert date + //We use invoice date $line->doc_date not $date_ecriture which is the transfert date //maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ? - //$Tab['date_ecriture'] = $date_ecriture; - $Tab['date_operation'] = dol_print_date($data->doc_date, '%d%m%Y'); + //$tab['date_ecriture'] = $date_ecriture; + $tab['date_operation'] = dol_print_date($line->doc_date, '%d%m%Y'); - $Tab['folio'] = ' 1'; + $tab['folio'] = ' 1'; - $Tab['num_ecriture'] = str_pad(dol_trunc($index, 6, 'right', 'UTF-8', 1), 6, ' ', STR_PAD_LEFT); + $tab['num_ecriture'] = str_pad(dol_trunc($index, 6, 'right', 'UTF-8', 1), 6, ' ', STR_PAD_LEFT); - $Tab['jour_ecriture'] = dol_print_date($data->doc_date, '%d%m%y'); + $tab['jour_ecriture'] = dol_print_date($line->doc_date, '%d%m%y'); - $Tab['num_compte'] = str_pad(dol_trunc($code_compta, 6, 'right', 'UTF-8', 1), 6, '0'); + $tab['num_compte'] = str_pad(dol_trunc($code_compta, 6, 'right', 'UTF-8', 1), 6, '0'); - if ($data->sens == 'D') { - $Tab['montant_debit'] = str_pad(number_format($data->debit, 2, ',', ''), 13, ' ', STR_PAD_LEFT); + if ($line->sens == 'D') { + $tab['montant_debit'] = str_pad(number_format($line->debit, 2, ',', ''), 13, ' ', STR_PAD_LEFT); - $Tab['montant_crebit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT); + $tab['montant_crebit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT); } else { - $Tab['montant_debit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT); + $tab['montant_debit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT); - $Tab['montant_crebit'] = str_pad(number_format($data->credit, 2, ',', ''), 13, ' ', STR_PAD_LEFT); + $tab['montant_crebit'] = str_pad(number_format($line->credit, 2, ',', ''), 13, ' ', STR_PAD_LEFT); } - $Tab['libelle_ecriture'] = str_pad(dol_trunc(dol_string_unaccent($data->doc_ref).' '.dol_string_unaccent($data->label_operation), 30, 'right', 'UTF-8', 1), 30); + $tab['libelle_ecriture'] = str_pad(dol_trunc(dol_string_unaccent($line->doc_ref).' '.dol_string_unaccent($line->label_operation), 30, 'right', 'UTF-8', 1), 30); - $Tab['lettrage'] = str_repeat(dol_trunc($data->lettering_code, 2, 'left', 'UTF-8', 1), 2); + $tab['lettrage'] = str_repeat(dol_trunc($line->lettering_code, 2, 'left', 'UTF-8', 1), 2); - $Tab['code_piece'] = str_pad(dol_trunc($data->piece_num, 5, 'left', 'UTF-8', 1), 5, ' ', STR_PAD_LEFT); + $tab['code_piece'] = str_pad(dol_trunc($line->piece_num, 5, 'left', 'UTF-8', 1), 5, ' ', STR_PAD_LEFT); - $Tab['code_stat'] = str_repeat(' ', 4); + $tab['code_stat'] = str_repeat(' ', 4); - if (!empty($data->date_lim_reglement)) { - //$Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, $conf->global->ACCOUNTING_EXPORT_DATE); - $Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, '%d%m%Y'); + if (!empty($line->date_lim_reglement)) { + //$tab['date_echeance'] = dol_print_date($line->date_lim_reglement, $conf->global->ACCOUNTING_EXPORT_DATE); + $tab['date_echeance'] = dol_print_date($line->date_lim_reglement, '%d%m%Y'); } else { - $Tab['date_echeance'] = dol_print_date($data->doc_date, '%d%m%Y'); + $tab['date_echeance'] = dol_print_date($line->doc_date, '%d%m%Y'); } - $Tab['monnaie'] = '1'; + $tab['monnaie'] = '1'; - $Tab['filler'] = ' '; + $tab['filler'] = ' '; - $Tab['ind_compteur'] = ' '; + $tab['ind_compteur'] = ' '; - $Tab['quantite'] = '0,000000000'; + $tab['quantite'] = '0,000000000'; - $Tab['code_pointage'] = str_repeat(' ', 2); + $tab['code_pointage'] = str_repeat(' ', 2); - $Tab['end_line'] = $end_line; + $tab['end_line'] = $end_line; - print implode('|', $Tab); + print implode('|', $tab); $index++; } From 7ab189b0541853253dd1436e9f325f670f5a8827 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 07:54:53 +0200 Subject: [PATCH 10/24] Update EBP Export --- .../class/accountancyexport.class.php | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index b33ef08ba34..b7604cedd84 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -1090,34 +1090,43 @@ class AccountancyExport /** * Export format : EBP * - * @param array $objectLines data - * @return void + * @param array $objectLines data + * @param resource $exportFile [=null] File resource to export or print if null + * @return void */ - public function exportEbp($objectLines) + public function exportEbp($objectLines, $exportFile = null) { $separator = ','; $end_line = "\n"; foreach ($objectLines as $line) { - $date = dol_print_date($line->doc_date, '%d%m%Y'); + $date_document = dol_print_date($line->doc_date, '%d%m%Y'); - print $line->id.$separator; - print $date.$separator; - print $line->code_journal.$separator; + $tab = array(); + + $tab[] = $line->id; + $tab[] = $date_document; + $tab[] = $line->code_journal; if (empty($line->subledger_account)) { - print $line->numero_compte.$separator; + $tab[] = $line->numero_compte; } else { - print $line->subledger_account.$separator; + $tab[] = $line->subledger_account; } - //print substr(length_accountg($line->numero_compte), 0, 2) . $separator; - print '"'.dol_trunc($line->label_operation, 40, 'right', 'UTF-8', 1).'"'.$separator; - print '"'.dol_trunc($line->piece_num, 15, 'right', 'UTF-8', 1).'"'.$separator; - print price2num(abs($line->debit - $line->credit)).$separator; - print $line->sens.$separator; - print $date.$separator; + //$tab[] = substr(length_accountg($line->numero_compte), 0, 2) . $separator; + $tab[] = '"'.dol_trunc($line->label_operation, 40, 'right', 'UTF-8', 1).'"'; + $tab[] = '"'.dol_trunc($line->piece_num, 15, 'right', 'UTF-8', 1).'"'; + $tab[] = price2num(abs($line->debit - $line->credit)); + $tab[] = $line->sens; + $tab[] = $date_document; //print 'EUR'; - print $end_line; + + $output = implode($tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } } } From 211635ada920ae9a518b825fcc457a7cc1a5ec7c Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 08:01:12 +0200 Subject: [PATCH 11/24] Update Agiris Export --- .../class/accountancyexport.class.php | 52 +++++++++++-------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index b7604cedd84..65564061ac3 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -1121,7 +1121,7 @@ class AccountancyExport $tab[] = $date_document; //print 'EUR'; - $output = implode($tab).$end_line; + $output = implode($separator, $tab).$end_line; if ($exportFile) { fwrite($exportFile, $output); } else { @@ -1134,39 +1134,47 @@ class AccountancyExport /** * Export format : Agiris Isacompta * - * @param array $objectLines data - * @return void + * @param array $objectLines data + * @param resource $exportFile [=null] File resource to export or print if null + * @return void */ - public function exportAgiris($objectLines) + public function exportAgiris($objectLines, $exportFile = null) { - $separator = ';'; $end_line = "\n"; foreach ($objectLines as $line) { - $date = dol_print_date($line->doc_date, '%d%m%Y'); + $date_document = dol_print_date($line->doc_date, '%d%m%Y'); - print $line->piece_num.$separator; - print self::toAnsi($line->label_operation).$separator; - print $date.$separator; - print self::toAnsi($line->label_operation).$separator; + $tab = array(); + + $tab[] = $line->piece_num; + $tab[] = self::toAnsi($line->label_operation); + $tab[] = $date_document; + $tab[] = self::toAnsi($line->label_operation); if (empty($line->subledger_account)) { - print length_accountg($line->numero_compte).$separator; - print self::toAnsi($line->label_compte).$separator; + $tab[] = length_accountg($line->numero_compte); + $tab[] = self::toAnsi($line->label_compte); } else { - print length_accounta($line->subledger_account).$separator; - print self::toAnsi($line->subledger_label).$separator; + $tab[] = length_accounta($line->subledger_account); + $tab[] = self::toAnsi($line->subledger_label); } - print self::toAnsi($line->doc_ref).$separator; - print price($line->debit).$separator; - print price($line->credit).$separator; - print price(abs($line->debit - $line->credit)).$separator; - print $line->sens.$separator; - print $line->lettering_code.$separator; - print $line->code_journal; - print $end_line; + $tab[] = self::toAnsi($line->doc_ref); + $tab[] = price($line->debit); + $tab[] = price($line->credit); + $tab[] = price(abs($line->debit - $line->credit)); + $tab[] = $line->sens; + $tab[] = $line->lettering_code; + $tab[] = $line->code_journal; + + $output = implode($separator, $tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } } } From 61228c6a3cfe83f5eaf8e563cd5807709650a62a Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 08:04:00 +0200 Subject: [PATCH 12/24] Update OpenConcerto Export --- .../class/accountancyexport.class.php | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index 65564061ac3..c8323625be4 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -1181,31 +1181,38 @@ class AccountancyExport /** * Export format : OpenConcerto * - * @param array $objectLines data - * @return void + * @param array $objectLines data + * @param resource $exportFile [=null] File resource to export or print if null + * @return void */ - public function exportOpenConcerto($objectLines) + public function exportOpenConcerto($objectLines, $exportFile = null) { - $separator = ';'; $end_line = "\n"; foreach ($objectLines as $line) { - $date = dol_print_date($line->doc_date, '%d/%m/%Y'); + $date_document = dol_print_date($line->doc_date, '%d/%m/%Y'); - print $date.$separator; - print $line->code_journal.$separator; + $tab = array(); + + $tab[] = $date_document; + $tab[] = $line->code_journal; if (empty($line->subledger_account)) { - print length_accountg($line->numero_compte).$separator; + $tab[] = length_accountg($line->numero_compte); } else { - print length_accounta($line->subledger_account).$separator; + $tab[] = length_accounta($line->subledger_account); } - print $line->doc_ref.$separator; - print $line->label_operation.$separator; - print price($line->debit).$separator; - print price($line->credit).$separator; + $tab[] = $line->doc_ref; + $tab[] = $line->label_operation; + $tab[] = price($line->debit); + $tab[] = price($line->credit); - print $end_line; + $output = implode($separator, $tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } } } From 49ce12f3daf5c7c8f859b607ffd7a18f126708ab Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 08:06:17 +0200 Subject: [PATCH 13/24] Update Configurable Export --- .../class/accountancyexport.class.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index c8323625be4..beeadad2c49 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -1219,21 +1219,23 @@ class AccountancyExport /** * Export format : Configurable CSV * - * @param array $objectLines data - * @return void + * @param array $objectLines data + * @param resource $exportFile [=null] File resource to export or print if null + * @return void */ - public function exportConfigurable($objectLines) + public function exportConfigurable($objectLines, $exportFile = null) { global $conf; $separator = $this->separator; foreach ($objectLines as $line) { + $date_document = dol_print_date($line->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE); + $tab = array(); // export configurable - $date = dol_print_date($line->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE); $tab[] = $line->piece_num; - $tab[] = $date; + $tab[] = $date_document; $tab[] = $line->doc_ref; $tab[] = preg_match('/'.$separator.'/', $line->label_operation) ? "'".$line->label_operation."'" : $line->label_operation; $tab[] = length_accountg($line->numero_compte); @@ -1243,7 +1245,12 @@ class AccountancyExport $tab[] = price2num($line->debit - $line->credit); $tab[] = $line->code_journal; - print implode($separator, $tab).$this->end_line; + $output = implode($separator, $tab).$this->end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } } } From d4223c68aa1d2623ecdc73d02dfb9d963db4d449 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 08:07:07 +0200 Subject: [PATCH 14/24] Update FEC Export --- .../class/accountancyexport.class.php | 105 ++++++++++-------- 1 file changed, 60 insertions(+), 45 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index beeadad2c49..26a646f2ce0 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -1257,37 +1257,45 @@ class AccountancyExport /** * Export format : FEC * - * @param array $objectLines data - * @return void + * @param array $objectLines data + * @param resource $exportFile [=null] File resource to export or print if null + * @return void */ - public function exportFEC($objectLines) + public function exportFEC($objectLines, $exportFile = null) { global $langs; $separator = "\t"; $end_line = "\r\n"; - print "JournalCode".$separator; - print "JournalLib".$separator; - print "EcritureNum".$separator; - print "EcritureDate".$separator; - print "CompteNum".$separator; - print "CompteLib".$separator; - print "CompAuxNum".$separator; - print "CompAuxLib".$separator; - print "PieceRef".$separator; - print "PieceDate".$separator; - print "EcritureLib".$separator; - print "Debit".$separator; - print "Credit".$separator; - print "EcritureLet".$separator; - print "DateLet".$separator; - print "ValidDate".$separator; - print "Montantdevise".$separator; - print "Idevise".$separator; - print "DateLimitReglmt".$separator; - print "NumFacture"; - print $end_line; + $tab = array(); + $tab[] = "JournalCode"; + $tab[] = "JournalLib"; + $tab[] = "EcritureNum"; + $tab[] = "EcritureDate"; + $tab[] = "CompteNum"; + $tab[] = "CompteLib"; + $tab[] = "CompAuxNum"; + $tab[] = "CompAuxLib"; + $tab[] = "PieceRef"; + $tab[] = "PieceDate"; + $tab[] = "EcritureLib"; + $tab[] = "Debit"; + $tab[] = "Credit"; + $tab[] = "EcritureLet"; + $tab[] = "DateLet"; + $tab[] = "ValidDate"; + $tab[] = "Montantdevise"; + $tab[] = "Idevise"; + $tab[] = "DateLimitReglmt"; + $tab[] = "NumFacture"; + + $output = implode($separator, $tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } foreach ($objectLines as $line) { if ($line->debit == 0 && $line->credit == 0) { @@ -1316,73 +1324,80 @@ class AccountancyExport $refInvoice = $invoice->ref_supplier; } + $tab = array(); + // FEC:JournalCode - print $line->code_journal . $separator; + $tab[] = $line->code_journal; // FEC:JournalLib $labeljournal = dol_string_unaccent($langs->transnoentities($line->journal_label)); $labeljournal = dol_string_nospecial($labeljournal, ' '); - print $labeljournal . $separator; + $tab[] = $labeljournal; // FEC:EcritureNum - print $line->piece_num . $separator; + $tab[] = $line->piece_num; // FEC:EcritureDate - print $date_document . $separator; + $tab[] = $date_document; // FEC:CompteNum - print $line->numero_compte . $separator; + $tab[] = length_accountg($line->numero_compte); // FEC:CompteLib - print dol_string_unaccent($line->label_compte) . $separator; + $tab[] = dol_string_unaccent($line->label_compte); // FEC:CompAuxNum - print $line->subledger_account . $separator; + $tab[] = length_accounta($line->subledger_account); // FEC:CompAuxLib - print dol_string_unaccent($line->subledger_label) . $separator; + $tab[] = dol_string_unaccent($line->subledger_label); // FEC:PieceRef - print $line->doc_ref . $separator; + $tab[] = $line->doc_ref; // FEC:PieceDate - print dol_string_unaccent($date_creation) . $separator; + $tab[] = dol_string_unaccent($date_creation); // FEC:EcritureLib // Clean label operation to prevent problem on export with tab separator & other character $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation); - print dol_string_unaccent($line->label_operation) . $separator; + $tab[] = dol_string_unaccent($line->label_operation); // FEC:Debit - print price2fec($line->debit) . $separator; + $tab[] = price2fec($line->debit); // FEC:Credit - print price2fec($line->credit) . $separator; + $tab[] = price2fec($line->credit); // FEC:EcritureLet - print $line->lettering_code . $separator; + $tab[] = $line->lettering_code; // FEC:DateLet - print $date_lettering . $separator; + $tab[] = $date_lettering; // FEC:ValidDate - print $date_validation . $separator; + $tab[] = $date_validation; // FEC:Montantdevise - print $line->multicurrency_amount . $separator; + $tab[] = $line->multicurrency_amount; // FEC:Idevise - print $line->multicurrency_code . $separator; + $tab[] = $line->multicurrency_code; // FEC_suppl:DateLimitReglmt - print $date_limit_payment . $separator; + $tab[] = $date_limit_payment; // FEC_suppl:NumFacture // Clean ref invoice to prevent problem on export with tab separator & other character $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice); - print dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1); + $tab[] = dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1); - print $end_line; + $output = implode($separator, $tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } } } } From 6b87da93c530a328f3c47e58313cf2f47dd88bce Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 08:08:03 +0200 Subject: [PATCH 15/24] Update FEC2 Export --- .../class/accountancyexport.class.php | 106 ++++++++++-------- 1 file changed, 60 insertions(+), 46 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index 26a646f2ce0..a49535ed407 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -1405,37 +1405,45 @@ class AccountancyExport /** * Export format : FEC2 * - * @param array $objectLines data - * @return void + * @param array $objectLines data + * @param resource $exportFile [=null] File resource to export or print if null + * @return void */ - public function exportFEC2($objectLines) + public function exportFEC2($objectLines, $exportFile = null) { global $langs; $separator = "\t"; $end_line = "\r\n"; - print "JournalCode".$separator; - print "JournalLib".$separator; - print "EcritureNum".$separator; - print "EcritureDate".$separator; - print "CompteNum".$separator; - print "CompteLib".$separator; - print "CompAuxNum".$separator; - print "CompAuxLib".$separator; - print "PieceRef".$separator; - print "PieceDate".$separator; - print "EcritureLib".$separator; - print "Debit".$separator; - print "Credit".$separator; - print "EcritureLet".$separator; - print "DateLet".$separator; - print "ValidDate".$separator; - print "Montantdevise".$separator; - print "Idevise".$separator; - print "DateLimitReglmt".$separator; - print "NumFacture"; - print $end_line; + $tab = array(); + $tab[] = "JournalCode"; + $tab[] = "JournalLib"; + $tab[] = "EcritureNum"; + $tab[] = "EcritureDate"; + $tab[] = "CompteNum"; + $tab[] = "CompteLib"; + $tab[] = "CompAuxNum"; + $tab[] = "CompAuxLib"; + $tab[] = "PieceRef"; + $tab[] = "PieceDate"; + $tab[] = "EcritureLib"; + $tab[] = "Debit"; + $tab[] = "Credit"; + $tab[] = "EcritureLet"; + $tab[] = "DateLet"; + $tab[] = "ValidDate"; + $tab[] = "Montantdevise"; + $tab[] = "Idevise"; + $tab[] = "DateLimitReglmt"; + $tab[] = "NumFacture"; + + $output = implode($separator, $tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } foreach ($objectLines as $line) { if ($line->debit == 0 && $line->credit == 0) { @@ -1464,74 +1472,80 @@ class AccountancyExport $refInvoice = $invoice->ref_supplier; } + $tab = array(); + // FEC:JournalCode - print $line->code_journal . $separator; + $tab[] = $line->code_journal; // FEC:JournalLib $labeljournal = dol_string_unaccent($langs->transnoentities($line->journal_label)); $labeljournal = dol_string_nospecial($labeljournal, ' '); - print $labeljournal . $separator; + $tab[] = $labeljournal; // FEC:EcritureNum - print $line->piece_num . $separator; + $tab[] = $line->piece_num; // FEC:EcritureDate - print $date_creation . $separator; + $tab[] = $date_creation; // FEC:CompteNum - print length_accountg($line->numero_compte) . $separator; + $tab[] = length_accountg($line->numero_compte); // FEC:CompteLib - print dol_string_unaccent($line->label_compte) . $separator; + $tab[] = dol_string_unaccent($line->label_compte); // FEC:CompAuxNum - print length_accounta($line->subledger_account) . $separator; + $tab[] = length_accounta($line->subledger_account); // FEC:CompAuxLib - print dol_string_unaccent($line->subledger_label) . $separator; + $tab[] = dol_string_unaccent($line->subledger_label); // FEC:PieceRef - print $line->doc_ref . $separator; + $tab[] = $line->doc_ref; // FEC:PieceDate - print $date_document . $separator; + $tab[] = $date_document; // FEC:EcritureLib // Clean label operation to prevent problem on export with tab separator & other character $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation); - print dol_string_unaccent($line->label_operation) . $separator; + $tab[] = dol_string_unaccent($line->label_operation); // FEC:Debit - print price2fec($line->debit) . $separator; + $tab[] = price2fec($line->debit); // FEC:Credit - print price2fec($line->credit) . $separator; + $tab[] = price2fec($line->credit); // FEC:EcritureLet - print $line->lettering_code . $separator; + $tab[] = $line->lettering_code; // FEC:DateLet - print $date_lettering . $separator; + $tab[] = $date_lettering; // FEC:ValidDate - print $date_validation . $separator; + $tab[] = $date_validation; // FEC:Montantdevise - print $line->multicurrency_amount . $separator; + $tab[] = $line->multicurrency_amount; // FEC:Idevise - print $line->multicurrency_code . $separator; + $tab[] = $line->multicurrency_code; // FEC_suppl:DateLimitReglmt - print $date_limit_payment . $separator; + $tab[] = $date_limit_payment; // FEC_suppl:NumFacture // Clean ref invoice to prevent problem on export with tab separator & other character $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice); - print dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1); + $tab[] = dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1); - - print $end_line; + $output = implode($separator, $tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } } } } From 383bc8a4a7414f5b5b9300ccba3d954f179391e3 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 08:09:22 +0200 Subject: [PATCH 16/24] Update Sage50Swiss Export --- .../class/accountancyexport.class.php | 115 ++++++++++++------ 1 file changed, 75 insertions(+), 40 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index a49535ed407..c133864042c 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -1556,19 +1556,47 @@ class AccountancyExport * https://onlinehelp.sageschweiz.ch/default.aspx?tabid=19984 * http://media.topal.ch/Public/Schnittstellen/TAF/Specification/Sage50-TAF-format.pdf * - * @param array $objectLines data - * - * @return void + * @param array $objectLines data + * @param resource $exportFile [=null] File resource to export or print if null + * @return void */ - public function exportSAGE50SWISS($objectLines) + public function exportSAGE50SWISS($objectLines, $exportFile = null) { // SAGE50SWISS - $this->separator = ','; - $this->end_line = "\r\n"; + $separator = ','; + $end_line = "\r\n"; // Print header line - print "Blg,Datum,Kto,S/H,Grp,GKto,SId,SIdx,KIdx,BTyp,MTyp,Code,Netto,Steuer,FW-Betrag,Tx1,Tx2,PkKey,OpId,Flag"; - print $this->end_line; + $tab = array(); + + $tab[] = "Blg"; + $tab[] = "Datum"; + $tab[] = "Kto"; + $tab[] = "S/H"; + $tab[] = "Grp"; + $tab[] = "GKto"; + $tab[] = "SId"; + $tab[] = "SIdx"; + $tab[] = "KIdx"; + $tab[] = "BTyp"; + $tab[] = "MTyp"; + $tab[] = "Code"; + $tab[] = "Netto"; + $tab[] = "Steuer"; + $tab[] = "FW-Betrag"; + $tab[] = "Tx1"; + $tab[] = "Tx2"; + $tab[] = "PkKey"; + $tab[] = "OpId"; + $tab[] = "Flag"; + + $output = implode($separator, $tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } + $thisPieceNum = ""; $thisPieceAccountNr = ""; $aSize = count($objectLines); @@ -1586,56 +1614,58 @@ class AccountancyExport $sammelBuchung = true; } + $tab = array(); + //Blg - print $line->piece_num.$this->separator; + $tab[] = $line->piece_num; // Datum - $date = dol_print_date($line->doc_date, '%d.%m.%Y'); - print $date.$this->separator; + $date_document = dol_print_date($line->doc_date, '%d.%m.%Y'); + $tab[] = $date_document; // Kto - print length_accountg($line->numero_compte).$this->separator; + $tab[] = length_accountg($line->numero_compte); // S/H if ($line->sens == 'D') { - print 'S'.$this->separator; + $tab[] = 'S'; } else { - print 'H'.$this->separator; + $tab[] = 'H'; } - //Grp - print self::trunc($line->code_journal, 1).$this->separator; + // Grp + $tab[] = self::trunc($line->code_journal, 1); // GKto if (empty($line->code_tiers)) { if ($line->piece_num == $thisPieceNum) { - print length_accounta($thisPieceAccountNr).$this->separator; + $tab[] = length_accounta($thisPieceAccountNr); } else { - print "div".$this->separator; + $tab[] = "div"; } } else { - print length_accounta($line->code_tiers).$this->separator; + $tab[] = length_accounta($line->code_tiers); } - //SId - print $this->separator; - //SIdx - print "0".$this->separator; - //KIdx - print "0".$this->separator; - //BTyp - print "0".$this->separator; + // SId + $tab[] = $this->separator; + // SIdx + $tab[] = "0"; + // KIdx + $tab[] = "0"; + // BTyp + $tab[] = "0"; - //MTyp 1=Fibu Einzelbuchung 2=Sammebuchung + // MTyp 1=Fibu Einzelbuchung 2=Sammebuchung if ($sammelBuchung) { - print "2".$this->separator; + $tab[] = "2"; } else { - print "1".$this->separator; + $tab[] = "1"; } // Code - print '""'.$this->separator; + $tab[] = '""'; // Netto - print abs($line->debit - $line->credit).$this->separator; + $tab[] = abs($line->debit - $line->credit); // Steuer - print "0.00".$this->separator; + $tab[] = "0.00"; // FW-Betrag - print "0.00".$this->separator; + $tab[] = "0.00"; // Tx1 $line1 = self::toAnsi($line->label_compte, 29); if ($line1 == "LIQ" || $line1 == "LIQ Beleg ok" || strlen($line1) <= 3) { @@ -1651,18 +1681,23 @@ class AccountancyExport $line2 = ""; } - print '"'.self::toAnsi($line1).'"'.$this->separator; + $tab[] = '"'.self::toAnsi($line1).'"'; // Tx2 - print '"'.self::toAnsi($line2).'"'.$this->separator; + $tab[] = '"'.self::toAnsi($line2).'"'; //PkKey - print "0".$this->separator; + $tab[] = "0"; //OpId - print $this->separator; + $tab[] = $this->separator; // Flag - print "0"; + $tab[] = "0"; - print $this->end_line; + $output = implode($separator, $tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } if ($line->piece_num !== $thisPieceNum) { $thisPieceNum = $line->piece_num; From cb7d59dd1a3753429b434438de25ea171cd70c7b Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 08:10:23 +0200 Subject: [PATCH 17/24] Update LDCompta Export --- .../class/accountancyexport.class.php | 93 ++++++++++--------- 1 file changed, 50 insertions(+), 43 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index c133864042c..95a5bbf6074 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -1710,11 +1710,11 @@ class AccountancyExport * Export format : LD Compta version 9 * http://www.ldsysteme.fr/fileadmin/telechargement/np/ldcompta/Documentation/IntCptW9.pdf * - * @param array $objectLines data - * - * @return void + * @param array $objectLines data + * @param resource $exportFile [=null] File resource to export or print if null + * @return void */ - public function exportLDCompta($objectLines) + public function exportLDCompta($objectLines, $exportFile = null) { $separator = ';'; @@ -1725,21 +1725,23 @@ class AccountancyExport $date_creation = dol_print_date($line->date_creation, '%Y%m%d'); $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d'); + $tab = array(); + // TYPE $type_enregistrement = 'E'; // For write movement - print $type_enregistrement.$separator; + $tab[] = $type_enregistrement; // JNAL - print substr($line->code_journal, 0, 2).$separator; + $tab[] = substr($line->code_journal, 0, 2); // NECR - print $line->id.$separator; + $tab[] = $line->id; // NPIE - print $line->piece_num.$separator; + $tab[] = $line->piece_num; // DATP - print $date_document.$separator; + $tab[] = $date_document; // LIBE - print $line->label_operation.$separator; + $tab[] = $line->label_operation; // DATH - print $date_lim_reglement.$separator; + $tab[] = $date_lim_reglement; // CNPI if ($line->doc_type == 'supplier_invoice') { if (($line->debit - $line->credit) > 0) { @@ -1756,7 +1758,7 @@ class AccountancyExport } else { $nature_piece = ''; } - print $nature_piece.$separator; + $tab[] = $nature_piece; // RACI // if (!empty($line->subledger_account)) { // if ($line->doc_type == 'supplier_invoice') { @@ -1770,71 +1772,76 @@ class AccountancyExport $racine_subledger_account = ''; // for records of type E leave this field blank // } - print $racine_subledger_account.$separator; // deprecated CPTG & CPTA use instead + $tab[] = $racine_subledger_account; // deprecated CPTG & CPTA use instead // MONT - print price(abs($line->debit - $line->credit), 0, '', 1, 2, 2).$separator; + $tab[] = price(abs($line->debit - $line->credit), 0, '', 1, 2, 2); // CODC - print $line->sens.$separator; + $tab[] = $line->sens; // CPTG - print length_accountg($line->numero_compte).$separator; + $tab[] = length_accountg($line->numero_compte); // DATE - print $date_creation.$separator; + $tab[] = $date_creation; // CLET - print $line->lettering_code.$separator; + $tab[] = $line->lettering_code; // DATL - print $line->date_lettering.$separator; + $tab[] = $line->date_lettering; // CPTA if (!empty($line->subledger_account)) { - print length_accounta($line->subledger_account).$separator; + $tab[] = length_accounta($line->subledger_account); } else { - print $separator; + $tab[] = ""; } // CNAT if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) { - print 'F'.$separator; + $tab[] = 'F'; } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) { - print 'C'.$separator; + $tab[] = 'C'; } else { - print $separator; + $tab[] = ""; } // SECT - print $separator; + $tab[] = ""; // CTRE - print $separator; + $tab[] = ""; // NORL - print $separator; + $tab[] = ""; // DATV - print $separator; + $tab[] = ""; // REFD - print $line->doc_ref.$separator; + $tab[] = $line->doc_ref; // CODH - print $separator; + $tab[] = ""; // NSEQ - print $separator; + $tab[] = ""; // MTDV - print '0'.$separator; + $tab[] = '0'; // CODV - print $separator; + $tab[] = ""; // TXDV - print '0'.$separator; + $tab[] = '0'; // MOPM - print $separator; + $tab[] = ""; // BONP - print $separator; + $tab[] = ""; // BQAF - print $separator; + $tab[] = ""; // ECES - print $separator; + $tab[] = ""; // TXTL - print $separator; + $tab[] = ""; // ECRM - print $separator; + $tab[] = ""; // DATK - print $separator; + $tab[] = ""; // HEUK - print $separator; + $tab[] = ""; - print $end_line; + $output = implode($separator, $tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } } } From 3b8a4df235f23f953f0182b814ca7d4bbe274d75 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 08:19:21 +0200 Subject: [PATCH 18/24] Update LDCompta10 Export --- .../class/accountancyexport.class.php | 202 ++++++++++-------- 1 file changed, 108 insertions(+), 94 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index 95a5bbf6074..13b0446f00c 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -1851,11 +1851,11 @@ class AccountancyExport * * Help : http://www.ldsysteme.fr/fileadmin/telechargement/np/ldcompta/Documentation/IntCptW10.pdf * - * @param array $objectLines data - * - * @return void + * @param array $objectLines data + * @param resource $exportFile [=null] File resource to export or print if null + * @return void */ - public function exportLDCompta10($objectLines) + public function exportLDCompta10($objectLines, $exportFile = null) { require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; @@ -1889,127 +1889,136 @@ class AccountancyExport $address[2] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 82, 40); } + $tab = array(); + $type_enregistrement = 'C'; //TYPE - print $type_enregistrement.$separator; + $tab[] = $type_enregistrement; //NOCL - print $soc->code_client.$separator; + $tab[] = $soc->code_client; //NMCM - print $separator; + $tab[] = ""; //LIBI - print $separator; + $tab[] = ""; //TITR - print $separator; + $tab[] = ""; //RSSO - print $soc->nom.$separator; + $tab[] = $soc->nom; //CAD1 - print $address[0].$separator; + $tab[] = $address[0]; //CAD2 - print $address[1].$separator; + $tab[] = $address[1]; //CAD3 - print $address[2].$separator; + $tab[] = $address[2]; //COPO - print $soc->zip.$separator; + $tab[] = $soc->zip; //BUDI - print substr($soc->town, 0, 40).$separator; + $tab[] = substr($soc->town, 0, 40); //CPAY - print $separator; + $tab[] = ""; //PAYS - print substr(getCountry($soc->fk_pays), 0, 40).$separator; + $tab[] = substr(getCountry($soc->fk_pays), 0, 40); //NTEL - print $soc->phone.$separator; + $tab[] = $soc->phone; //TLEX - print $separator; + $tab[] = ""; //TLPO - print $separator; + $tab[] = ""; //TLCY - print $separator; + $tab[] = ""; //NINT - print $separator; + $tab[] = ""; //COMM - print $separator; + $tab[] = ""; //SIRE - print str_replace(" ", "", $soc->siret).$separator; + $tab[] = str_replace(" ", "", $soc->siret); //RIBP - print $separator; + $tab[] = ""; //DOBQ - print $separator; + $tab[] = ""; //IBBQ - print $separator; + $tab[] = ""; //COBQ - print $separator; + $tab[] = ""; //GUBQ - print $separator; + $tab[] = ""; //CPBQ - print $separator; + $tab[] = ""; //CLBQ - print $separator; + $tab[] = ""; //BIBQ - print $separator; + $tab[] = ""; //MOPM - print $separator; + $tab[] = ""; //DJPM - print $separator; + $tab[] = ""; //DMPM - print $separator; + $tab[] = ""; //REFM - print $separator; + $tab[] = ""; //SLVA - print $separator; + $tab[] = ""; //PLCR - print $separator; + $tab[] = ""; //ECFI - print $separator; + $tab[] = ""; //CREP - print $separator; + $tab[] = ""; //NREP - print $separator; + $tab[] = ""; //TREP - print $separator; + $tab[] = ""; //MREP - print $separator; + $tab[] = ""; //GRRE - print $separator; + $tab[] = ""; //LTTA - print $separator; + $tab[] = ""; //CACT - print $separator; + $tab[] = ""; //CODV - print $separator; + $tab[] = ""; //GRTR - print $separator; + $tab[] = ""; //NOFP - print $separator; + $tab[] = ""; //BQAF - print $separator; + $tab[] = ""; //BONP - print $separator; + $tab[] = ""; //CESC - print $separator; + $tab[] = ""; - print $end_line; + $output = implode($separator, $tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } } } + $tab = array(); + $date_document = dol_print_date($line->doc_date, '%Y%m%d'); $date_creation = dol_print_date($line->date_creation, '%Y%m%d'); $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d'); // TYPE E $type_enregistrement = 'E'; // For write movement - print $type_enregistrement.$separator; + $tab[] = $type_enregistrement; // JNAL - print substr($line->code_journal, 0, 2).$separator; + $tab[] = substr($line->code_journal, 0, 2); // NECR - print $line->id.$separator; + $tab[] = $line->id; // NPIE - print $line->piece_num.$separator; + $tab[] = $line->piece_num; // DATP - print $date_document.$separator; + $tab[] = $date_document; // LIBE - print dol_trunc($line->label_operation, 25, 'right', 'UTF-8', 1).$separator; + $tab[] = dol_trunc($line->label_operation, 25, 'right', 'UTF-8', 1); // DATH - print $date_lim_reglement.$separator; + $tab[] = $date_lim_reglement; // CNPI if ($line->doc_type == 'supplier_invoice') { if (($line->amount) < 0) { // Currently, only the sign of amount allows to know the type of invoice (standard or credit note). Other solution is to analyse debit/credit/role of account. TODO Add column doc_type_long or make amount mandatory with rule on sign. @@ -2026,7 +2035,7 @@ class AccountancyExport } else { $nature_piece = ''; } - print $nature_piece.$separator; + $tab[] = $nature_piece; // RACI // if (!empty($line->subledger_account)) { // if ($line->doc_type == 'supplier_invoice') { @@ -2040,75 +2049,80 @@ class AccountancyExport $racine_subledger_account = ''; // for records of type E leave this field blank // } - print $racine_subledger_account.$separator; // deprecated CPTG & CPTA use instead + $tab[] = $racine_subledger_account; // deprecated CPTG & CPTA use instead // MONT - print price(abs($line->debit - $line->credit), 0, '', 1, 2).$separator; + $tab[] = price(abs($line->debit - $line->credit), 0, '', 1, 2); // CODC - print $line->sens.$separator; + $tab[] = $line->sens; // CPTG - print length_accountg($line->numero_compte).$separator; + $tab[] = length_accountg($line->numero_compte); // DATE - print $date_document.$separator; + $tab[] = $date_document; // CLET - print $line->lettering_code.$separator; + $tab[] = $line->lettering_code; // DATL - print $line->date_lettering.$separator; + $tab[] = $line->date_lettering; // CPTA if (!empty($line->subledger_account)) { - print length_accounta($line->subledger_account).$separator; + $tab[] = length_accounta($line->subledger_account); } else { - print $separator; + $tab[] = ""; } // CNAT if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) { - print 'F'.$separator; + $tab[] = 'F'; } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) { - print 'C'.$separator; + $tab[] = 'C'; } else { - print $separator; + $tab[] = ""; } // CTRE - print $separator; + $tab[] = ""; // NORL - print $separator; + $tab[] = ""; // DATV - print $separator; + $tab[] = ""; // REFD - print $line->doc_ref.$separator; + $tab[] = $line->doc_ref; // NECA - print '0'.$separator; + $tab[] = '0'; // CSEC - print $separator; + $tab[] = ""; // CAFF - print $separator; + $tab[] = ""; // CDES - print $separator; + $tab[] = ""; // QTUE - print $separator; + $tab[] = ""; // MTDV - print '0'.$separator; + $tab[] = '0'; // CODV - print $separator; + $tab[] = ""; // TXDV - print '0'.$separator; + $tab[] = '0'; // MOPM - print $separator; + $tab[] = ""; // BONP - print $separator; + $tab[] = ""; // BQAF - print $separator; + $tab[] = ""; // ECES - print $separator; + $tab[] = ""; // TXTL - print $separator; + $tab[] = ""; // ECRM - print $separator; + $tab[] = ""; // DATK - print $separator; + $tab[] = ""; // HEUK - print $separator; + $tab[] = ""; - print $end_line; + $output = implode($separator, $tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } $last_codeinvoice = $line->doc_ref; } From 508e798eaea28798d834b3022d3ed6278769509a Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 08:24:13 +0200 Subject: [PATCH 19/24] Update Charlemagne Export --- .../class/accountancyexport.class.php | 89 +++++++++++-------- 1 file changed, 52 insertions(+), 37 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index 13b0446f00c..320b18096dd 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -2131,10 +2131,11 @@ class AccountancyExport /** * Export format : Charlemagne * - * @param array $objectLines data - * @return void + * @param array $objectLines data + * @param resource $exportFile [=null] File resource to export or print if null + * @return void */ - public function exportCharlemagne($objectLines) + public function exportCharlemagne($objectLines, $exportFile = null) { global $langs; $langs->load('compta'); @@ -2142,52 +2143,66 @@ class AccountancyExport $separator = "\t"; $end_line = "\n"; - /* - * Charlemagne export need header - */ - print $langs->transnoentitiesnoconv('Date').$separator; - print self::trunc($langs->transnoentitiesnoconv('Journal'), 6).$separator; - print self::trunc($langs->transnoentitiesnoconv('Account'), 15).$separator; - print self::trunc($langs->transnoentitiesnoconv('LabelAccount'), 60).$separator; - print self::trunc($langs->transnoentitiesnoconv('Piece'), 20).$separator; - print self::trunc($langs->transnoentitiesnoconv('LabelOperation'), 60).$separator; - print $langs->transnoentitiesnoconv('Amount').$separator; - print 'S'.$separator; - print self::trunc($langs->transnoentitiesnoconv('Analytic').' 1', 15).$separator; - print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 1', 60).$separator; - print self::trunc($langs->transnoentitiesnoconv('Analytic').' 2', 15).$separator; - print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 2', 60).$separator; - print self::trunc($langs->transnoentitiesnoconv('Analytic').' 3', 15).$separator; - print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 3', 60).$separator; - print $end_line; + $tab = array(); + + $tab[] = $langs->transnoentitiesnoconv('Date'); + $tab[] = self::trunc($langs->transnoentitiesnoconv('Journal'), 6); + $tab[] = self::trunc($langs->transnoentitiesnoconv('Account'), 15); + $tab[] = self::trunc($langs->transnoentitiesnoconv('LabelAccount'), 60); + $tab[] = self::trunc($langs->transnoentitiesnoconv('Piece'), 20); + $tab[] = self::trunc($langs->transnoentitiesnoconv('LabelOperation'), 60); + $tab[] = $langs->transnoentitiesnoconv('Amount'); + $tab[] = 'S'; + $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 1', 15); + $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 1', 60); + $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 2', 15); + $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 2', 60); + $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 3', 15); + $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 3', 60); + + $output = implode($separator, $tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } foreach ($objectLines as $line) { - $date = dol_print_date($line->doc_date, '%Y%m%d'); - print $date.$separator; //Date + $date_document = dol_print_date($line->doc_date, '%Y%m%d'); - print self::trunc($line->code_journal, 6).$separator; //Journal code + $tab = array(); + + $tab[] = $date_document; //Date + + $tab[] = self::trunc($line->code_journal, 6); //Journal code if (!empty($line->subledger_account)) { $account = $line->subledger_account; } else { $account = $line->numero_compte; } - print self::trunc($account, 15).$separator; //Account number + $tab[] = self::trunc($account, 15); //Account number - print self::trunc($line->label_compte, 60).$separator; //Account label - print self::trunc($line->doc_ref, 20).$separator; //Piece + $tab[] = self::trunc($line->label_compte, 60); //Account label + $tab[] = self::trunc($line->doc_ref, 20); //Piece // Clean label operation to prevent problem on export with tab separator & other character $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation); - print self::trunc($line->label_operation, 60).$separator; //Operation label - print price(abs($line->debit - $line->credit)).$separator; //Amount - print $line->sens.$separator; //Direction - print $separator; //Analytic - print $separator; //Analytic - print $separator; //Analytic - print $separator; //Analytic - print $separator; //Analytic - print $separator; //Analytic - print $end_line; + $tab[] = self::trunc($line->label_operation, 60); //Operation label + $tab[] = price(abs($line->debit - $line->credit)); //Amount + $tab[] = $line->sens; //Direction + $tab[] = ""; //Analytic + $tab[] = ""; //Analytic + $tab[] = ""; //Analytic + $tab[] = ""; //Analytic + $tab[] = ""; //Analytic + $tab[] = ""; //Analytic + + $output = implode($separator, $tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } } } From 67ceec85297964ea561d6cd73159f914d0d0ba29 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 08:33:05 +0200 Subject: [PATCH 20/24] Update GestimumV3 Export --- .../class/accountancyexport.class.php | 52 +++++++++++-------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index 320b18096dd..84490d29922 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -2209,15 +2209,16 @@ class AccountancyExport /** * Export format : Gestimum V3 * - * @param array $objectLines data - * - * @return void + * @param array $objectLines data + * @param resource $exportFile [=null] File resource to export or print if null + * @return void */ - public function exportGestimumV3($objectLines) + public function exportGestimumV3($objectLines, $exportFile = null) { global $langs; - $this->separator = ','; + $separator = ','; + $end_line = "\r\n"; $invoices_infos = array(); $supplier_invoices_infos = array(); @@ -2225,7 +2226,8 @@ class AccountancyExport if ($line->debit == 0 && $line->credit == 0) { //unset($array[$line]); } else { - $date = dol_print_date($line->doc_date, '%d/%m/%Y'); + $date_document = dol_print_date($line->doc_date, '%d/%m/%Y'); + $date_echeance = dol_print_date($line->date_lim_reglement, '%Y%m%d'); $invoice_ref = $line->doc_ref; $company_name = ""; @@ -2273,33 +2275,41 @@ class AccountancyExport } } - print $line->id . $this->separator; - print $date . $this->separator; - print substr($line->code_journal, 0, 4) . $this->separator; + $tab = array(); + + $tab[] = $line->id; + $tab[] = $date_document; + $tab[] = substr($line->code_journal, 0, 4); if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) { - print length_accountg($line->subledger_account) . $this->separator; + $tab[] = length_accountg($line->subledger_account); } else { - print substr(length_accountg($line->numero_compte), 0, 15) . $this->separator; + $tab[] = substr(length_accountg($line->numero_compte), 0, 15); } //Libellé Auto - print $this->separator; - //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"' . $this->separator; + $tab[] = ""; + //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"'; //Libellé manuel - print dol_trunc(str_replace('"', '', $invoice_ref . (!empty($company_name) ? ' - ' : '') . $company_name), 40, 'right', 'UTF-8', 1) . $this->separator; + $tab[] = dol_trunc(str_replace('"', '', $invoice_ref . (!empty($company_name) ? ' - ' : '') . $company_name), 40, 'right', 'UTF-8', 1); //Numéro de pièce - print dol_trunc(str_replace('"', '', $line->piece_num), 10, 'right', 'UTF-8', 1) . $this->separator; + $tab[] = dol_trunc(str_replace('"', '', $line->piece_num), 10, 'right', 'UTF-8', 1); //Devise - print 'EUR' . $this->separator; + $tab[] = 'EUR'; //Amount - print price2num(abs($line->debit - $line->credit)) . $this->separator; + $tab[] = price2num(abs($line->debit - $line->credit)); //Sens - print $line->sens . $this->separator; + $tab[] = $line->sens; //Code lettrage - print $this->separator; + $tab[] = ""; //Date Echéance - print $date; - print $this->end_line; + $tab[] = $date_echeance; + + $output = implode($separator, $tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } } } } From 509fbd0a320e87498c3ff89d3de39ebcffcaf8f5 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 08:36:58 +0200 Subject: [PATCH 21/24] Update GestimumV5 Export --- .../class/accountancyexport.class.php | 53 +++++++++++-------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index 84490d29922..f1f4620e830 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -2317,40 +2317,49 @@ class AccountancyExport /** * Export format : Gestimum V5 * - * @param array $objectLines data - * - * @return void + * @param array $objectLines data + * @param resource $exportFile [=null] File resource to export or print if null + * @return void */ - public function exportGestimumV5($objectLines) + public function exportGestimumV5($objectLines, $exportFile = null) { - $this->separator = ','; + $separator = ','; + $end_line = "\r\n"; foreach ($objectLines as $line) { if ($line->debit == 0 && $line->credit == 0) { //unset($array[$line]); } else { - $date = dol_print_date($line->doc_date, '%d%m%Y'); + $date_document = dol_print_date($line->doc_date, '%d%m%Y'); - print $line->id . $this->separator; - print $date . $this->separator; - print substr($line->code_journal, 0, 4) . $this->separator; + $tab = array(); + + $tab[] = $line->id; + $tab[] = $date_document; + $tab[] = substr($line->code_journal, 0, 4); if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) { // TODO No hard code value - print length_accountg($line->subledger_account) . $this->separator; + $tab[] = length_accountg($line->subledger_account); } else { - print substr(length_accountg($line->numero_compte), 0, 15) . $this->separator; + $tab[] = substr(length_accountg($line->numero_compte), 0, 15); + } + $tab[] = ""; + $tab[] = '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"'; + $tab[] = '"' . dol_trunc(str_replace('"', '', $line->doc_ref), 40, 'right', 'UTF-8', 1) . '"'; + $tab[] = '"' . dol_trunc(str_replace('"', '', $line->piece_num), 10, 'right', 'UTF-8', 1) . '"'; + $tab[] = price2num(abs($line->debit - $line->credit)); + $tab[] = $line->sens; + $tab[] = $date_document; + $tab[] = ""; + $tab[] = ""; + $tab[] = 'EUR'; + + $output = implode($separator, $tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; } - print $this->separator; - //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"' . $this->separator; - print '"' . dol_trunc(str_replace('"', '', $line->doc_ref), 40, 'right', 'UTF-8', 1) . '"' . $this->separator; - print '"' . dol_trunc(str_replace('"', '', $line->piece_num), 10, 'right', 'UTF-8', 1) . '"' . $this->separator; - print price2num(abs($line->debit - $line->credit)) . $this->separator; - print $line->sens . $this->separator; - print $date . $this->separator; - print $this->separator; - print $this->separator; - print 'EUR'; - print $this->end_line; } } } From c86f8af93f95fa6e1f3064b43c84d632937945ab Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 29 Apr 2023 08:38:34 +0200 Subject: [PATCH 22/24] Update iSuiteExpert Export --- .../class/accountancyexport.class.php | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index f1f4620e830..1045e377c1e 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -2369,14 +2369,14 @@ class AccountancyExport * * by OpenSolus [https://opensolus.fr] * - * @param array $objectLines data - * - * @return void + * @param array $objectLines data + * @param resource $exportFile [=null] File resource to export or print if null + * @return void */ - public function exportiSuiteExpert($objectLines) + public function exportiSuiteExpert($objectLines, $exportFile = null) { - $this->separator = ';'; - $this->end_line = "\r\n"; + $separator = ';'; + $end_line = "\r\n"; foreach ($objectLines as $line) { @@ -2417,8 +2417,12 @@ class AccountancyExport $tab[] = price($line->montant); $tab[] = $line->code_journal; - $separator = $this->separator; - print implode($separator, $tab) . $this->end_line; + $output = implode($separator, $tab).$end_line; + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } } } From d2b2f9980855293425017b0ce04c5cb9fe8120d3 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sat, 29 Apr 2023 06:47:41 +0000 Subject: [PATCH 23/24] Fixing style errors. --- htdocs/accountancy/class/accountancyexport.class.php | 2 +- htdocs/accountancy/class/api_accountancy.class.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index 1045e377c1e..82fda954c32 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -2344,7 +2344,7 @@ class AccountancyExport $tab[] = substr(length_accountg($line->numero_compte), 0, 15); } $tab[] = ""; - $tab[] = '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"'; + $tab[] = '"'.dol_trunc(str_replace('"', '', $line->label_operation), 40, 'right', 'UTF-8', 1).'"'; $tab[] = '"' . dol_trunc(str_replace('"', '', $line->doc_ref), 40, 'right', 'UTF-8', 1) . '"'; $tab[] = '"' . dol_trunc(str_replace('"', '', $line->piece_num), 10, 'right', 'UTF-8', 1) . '"'; $tab[] = price2num(abs($line->debit - $line->credit)); diff --git a/htdocs/accountancy/class/api_accountancy.class.php b/htdocs/accountancy/class/api_accountancy.class.php index 289e17203e3..f1870d7b8b2 100644 --- a/htdocs/accountancy/class/api_accountancy.class.php +++ b/htdocs/accountancy/class/api_accountancy.class.php @@ -244,7 +244,7 @@ class Accountancy extends DolibarrApi $sql = " UPDATE " . MAIN_DB_PREFIX . "accounting_bookkeeping"; $sql .= " SET date_export = '" . $this->db->idate($now) . "'"; - $sql .= " WHERE rowid = " . ((int)$movement->id); + $sql .= " WHERE rowid = " . ((int) $movement->id); $result = $this->db->query($sql); if (!$result) { From 15d972a542a11d3b46c60dffb6eae0ee9750e830 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sun, 30 Apr 2023 08:22:53 +0200 Subject: [PATCH 24/24] FIX Travis --- htdocs/core/lib/accounting.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/accounting.lib.php b/htdocs/core/lib/accounting.lib.php index 38a7fefc483..86f7770e27f 100644 --- a/htdocs/core/lib/accounting.lib.php +++ b/htdocs/core/lib/accounting.lib.php @@ -350,7 +350,7 @@ function getCurrentPeriodOfFiscalYear($db, $conf, $from_time = null) $from_db_time = $db->idate($from_time); $sql = "SELECT date_start, date_end FROM ".$db->prefix()."accounting_fiscalyear"; - $sql .= " WHERE date_start <= '".$from_db_time."' AND date_end >= '".$from_db_time."'"; + $sql .= " WHERE date_start <= '".$db->escape($from_db_time)."' AND date_end >= '".$db->escape($from_db_time)."'"; $sql .= $db->order('date_start', 'DESC'); $sql .= $db->plimit(1); $res = $db->query($sql);