diff --git a/htdocs/accountancy/tpl/export_journal.tpl.php b/htdocs/accountancy/tpl/export_journal.tpl.php index d7a97783a95..4176b61a242 100644 --- a/htdocs/accountancy/tpl/export_journal.tpl.php +++ b/htdocs/accountancy/tpl/export_journal.tpl.php @@ -1,10 +1,10 @@ - * Copyright (C) 2022 Lionel Vessiller - * Copyright (C) 2016 Charlie Benke - * Copyright (C) 2022 Progiseize +/* Copyright (C) 2015-2025 Alexandre Spangaro + * Copyright (C) 2022 Lionel Vessiller + * Copyright (C) 2016 Charlie Benke + * Copyright (C) 2022 Progiseize * Copyright (C) 2024-2025 MDW - * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024 Frédéric France * * 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); }