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

View File

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

View File

@ -11,6 +11,7 @@
* Copyright (C) 2017-2019 Frédéric France <frederic.france@netlogic.fr> * Copyright (C) 2017-2019 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2017 André Schild <a.schild@aarboard.ch> * Copyright (C) 2017 André Schild <a.schild@aarboard.ch>
* Copyright (C) 2020 Guillaume Alexandre <guillaume@tag-info.fr> * 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 * 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 * 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/functions.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.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) public function __construct(DoliDB $db)
{ {
global $conf; global $conf, $hookmanager;
$this->db = $db; $this->db = $db;
$this->separator = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; $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"); $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 * @return array of type
*/ */
public static function getType() public function getType()
{ {
global $langs; global $langs;
@ -132,6 +136,10 @@ class AccountancyExport
self::$EXPORT_TYPE_ISUITEEXPERT => 'Export iSuite Expert', 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); ksort($listofexporttypes, SORT_NUMERIC);
return $listofexporttypes; return $listofexporttypes;
@ -168,7 +176,12 @@ class AccountancyExport
self::$EXPORT_TYPE_ISUITEEXPERT => 'isuiteexpert', 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 * @return array of type
*/ */
public static function getTypeConfig() public function getTypeConfig()
{ {
global $conf, $langs; global $conf, $langs;
return array( $exporttypes = array(
'param' => array( 'param' => array(
self::$EXPORT_TYPE_CONFIGURABLE => array( self::$EXPORT_TYPE_CONFIGURABLE => array(
'label' => $langs->trans('Modelcsv_configurable'), 'label' => $langs->trans('Modelcsv_configurable'),
@ -265,6 +278,11 @@ class AccountancyExport
'txt' => $langs->trans("txt") '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); $this->exportiSuiteExpert($TData);
break; break;
default: default:
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'); $this->errors[] = $langs->trans('accountancy_error_modelnotfound');
}
break; break;
} }
} }