NEW Accountancy - Add hook on export filename (#35188)

* NEW Accountancy - Add hook on export filename

* FIX CI
This commit is contained in:
Alexandre SPANGARO 2025-09-03 11:54:37 +02:00 committed by GitHub
parent d4b93b662c
commit 2ec41b630e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,10 +1,10 @@
<?php
/* Copyright (C) 2015-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
* Copyright (C) 2022 Lionel Vessiller <lvessiller@open-dsi.fr>
* Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
* Copyright (C) 2022 Progiseize <a.bisotti@progiseize.fr>
/* Copyright (C) 2015-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
* Copyright (C) 2022 Lionel Vessiller <lvessiller@open-dsi.fr>
* Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
* Copyright (C) 2022 Progiseize <a.bisotti@progiseize.fr>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
*
* 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
@ -33,6 +33,7 @@
/**
* @var Conf $conf
* @var DoliDB $db
* @var HookManager $hookmanager
* @var int $formatexportset
* @var string $type_export
* @var string $filename
@ -89,6 +90,38 @@ if ((substr($accountancyexport->getFormatCode($formatexportset), 0, 3) == 'fec')
$completefilename = ($code ? $code."_" : "").($prefix ? $prefix."_" : "").$filename.($nodateexport ? "" : $date_export).".".$format;
}
// --- Hook: allow external modules to override export filename ---
if (is_object($hookmanager)) {
// Dedicated context (non-blocking if other hooks are already initialized)
$hookmanager->initHooks(array('accountancyexportfilename'));
$parameters = array(
'type_export' => $type_export ?? '',
'format' => $format ?? '',
'format_code' => $accountancyexport->getFormatCode($formatexportset),
'code' => $code ?? '',
'prefix' => $prefix ?? '',
'filename' => $filename ?? '',
'period_start' => $startaccountingperiod ?? '',
'period_end' => $endaccountingperiod ?? '',
'siren' => $siren ?? '',
'ndate_in_filename' => $nodateexport ?? 0,
'now_datetime' => $date_export,
// Value by default
'defaultfilename' => $completefilename
);
// Hook called by modules: setExportFilename
$reshook = $hookmanager->executeHooks('setExportFilename', $parameters, $accountancyexport, $action);
if ($reshook > 0) {
if (!empty($hookmanager->resArray['filename'])) {
$completefilename = $hookmanager->resArray['filename'];
} elseif ($hookmanager->resPrint !== '') {
$completefilename = $hookmanager->resPrint;
}
}
}
if (empty($downloadMode)) {
header('Content-Disposition: attachment;filename=' . $completefilename);
}