NEW #20905 add hooks for accountancy export

This commit is contained in:
priojk 2022-05-20 14:48:37 +02:00
parent fe0bbbb626
commit 03d60ec05e
3 changed files with 36 additions and 10 deletions

View File

@ -47,7 +47,8 @@ $main_option = array(
'ACCOUNTING_EXPORT_PREFIX_SPEC',
);
$configuration = AccountancyExport::getTypeConfig();
$accountancyexport = new AccountancyExport($db);
$configuration = $accountancyexport->getTypeConfig();
$listparam = $configuration['param'];
@ -117,7 +118,7 @@ if ($action == 'update') {
if (!$error) {
// reload
$configuration = AccountancyExport::getTypeConfig();
$configuration = $accountancyexport->getTypeConfig();
$listparam = $configuration['param'];
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
} else {
@ -237,7 +238,7 @@ if (!$conf->use_javascript_ajax) {
print "</td>";
} else {
print '<td>';
$listmodelcsv = AccountancyExport::getType();
$listmodelcsv = $accountancyexport->getType();
print $form->selectarray("ACCOUNTING_EXPORT_MODELCSV", $listmodelcsv, $conf->global->ACCOUNTING_EXPORT_MODELCSV, 0, 0, 0, '', 0, 0, 0, '', '', 1);
print '</td>';

View File

@ -204,7 +204,8 @@ if (empty($conf->global->ACCOUNTING_ENABLE_LETTERING)) {
unset($arrayfields['t.lettering_code']);
}
$listofformat = AccountancyExport::getType();
$accountancyexport = new AccountancyExport($db);
$listofformat = $accountancyexport->getType();
$formatexportset = $conf->global->ACCOUNTING_EXPORT_MODELCSV;
if (empty($listofformat[$formatexportset])) {
$formatexportset = 1;

View File

@ -11,6 +11,7 @@
* Copyright (C) 2017-2019 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2017 André Schild <a.schild@aarboard.ch>
* Copyright (C) 2020 Guillaume Alexandre <guillaume@tag-info.fr>
* Copyright (C) 2022 Joachim Kueter <jkueter@gmx.de>
*
* 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
@ -34,6 +35,7 @@
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');
/**
@ -93,11 +95,13 @@ class AccountancyExport
*/
public function __construct(DoliDB $db)
{
global $conf;
global $conf, $hookmanager;
$this->db = $db;
$this->separator = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
$this->end_line = empty($conf->global->ACCOUNTING_EXPORT_ENDLINE) ? "\n" : ($conf->global->ACCOUNTING_EXPORT_ENDLINE == 1 ? "\n" : "\r\n");
$hookmanager->initHooks(array('accountancyexport'));
}
/**
@ -105,7 +109,7 @@ class AccountancyExport
*
* @return array of type
*/
public static function getType()
public function getType()
{
global $langs;
@ -132,6 +136,10 @@ class AccountancyExport
self::$EXPORT_TYPE_ISUITEEXPERT => 'Export iSuite Expert',
);
// allow modules to define export formats
global $hookmanager;
$reshook = $hookmanager->executeHooks('getType', $parameters, $listofexporttypes);
ksort($listofexporttypes, SORT_NUMERIC);
return $listofexporttypes;
@ -168,7 +176,12 @@ class AccountancyExport
self::$EXPORT_TYPE_ISUITEEXPERT => 'isuiteexpert',
);
return $formatcode[$type];
global $hookmanager;
$code = $formatcode[$type];
$parameters = array('type' => $type);
$reshook = $hookmanager->executeHooks('getFormatCode', $parameters, $code);
return $code;
}
/**
@ -176,11 +189,11 @@ class AccountancyExport
*
* @return array of type
*/
public static function getTypeConfig()
public function getTypeConfig()
{
global $conf, $langs;
return array(
$exporttypes = array(
'param' => array(
self::$EXPORT_TYPE_CONFIGURABLE => array(
'label' => $langs->trans('Modelcsv_configurable'),
@ -265,6 +278,11 @@ class AccountancyExport
'txt' => $langs->trans("txt")
),
);
global $hookmanager;
$parameters = array();
$reshook = $hookmanager->executeHooks('getTypeConfig', $parameters, $exporttypes);
return $exporttypes;
}
@ -350,7 +368,13 @@ class AccountancyExport
$this->exportiSuiteExpert($TData);
break;
default:
$this->errors[] = $langs->trans('accountancy_error_modelnotfound');
global $hookmanager;
$parameters = array('format' => $formatexportset);
// file contents will be created in the hooked function via print
$reshook = $hookmanager->executeHooks('export', $parameters, $TData);
if ($reshook != 1) {
$this->errors[] = $langs->trans('accountancy_error_modelnotfound');
}
break;
}
}