dolibarr 25.0.0-alpha
export_journal.tpl.php
1<?php
2/* Copyright (C) 2015-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
3 * Copyright (C) 2022 Lionel Vessiller <lvessiller@open-dsi.fr>
4 * Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
5 * Copyright (C) 2022 Progiseize <a.bisotti@progiseize.fr>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23'
24@phan-var-force int $formatexportset
25@phan-var-force string $type_export
26@phan-var-force string $filename
27@phan-var-force int<-1,1> $downloadMode
28';
29
43// Protection to avoid direct call of template
44if (empty($conf) || !is_object($conf)) {
45 print "Error, template page can't be called as URL";
46 exit(1);
47}
48
49$code = getDolGlobalString('MAIN_INFO_ACCOUNTANT_CODE');
50$prefix = getDolGlobalString('ACCOUNTING_EXPORT_PREFIX_SPEC');
51$format = getDolGlobalString('ACCOUNTING_EXPORT_FORMAT');
52$nodateexport = getDolGlobalInt('ACCOUNTING_EXPORT_NO_DATE_IN_FILENAME');
53$siren = getDolGlobalString('MAIN_INFO_SIREN');
54
55$date_export = "_".dol_print_date(dol_now(), '%Y%m%d%H%M%S');
56$startaccountingperiod = '';
57$endaccountingperiod = dol_print_date(dol_now(), '%Y%m%d');
58
59
60include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancyexport.class.php';
61$accountancyexport = new AccountancyExport($db);
62
63// Specific filename for FEC model export into the general ledger
64if ((substr($accountancyexport->getFormatCode($formatexportset), 0, 3) == 'fec') && $type_export == "general_ledger") {
65 // FEC format is defined here: https://www.legifrance.gouv.fr/affichCodeArticle.do?idArticle=LEGIARTI000027804775&cidTexte=LEGITEXT000006069583&dateTexte=20130802&oldAction=rechCodeArticle
66 if (empty($search_date_end)) {
67 // TODO Get the max date into bookkeeping table
68 $search_date_end = dol_now();
69 }
70 $datetouseforfilename = $search_date_end;
71 $tmparray = dol_getdate($datetouseforfilename);
72 $fiscalmonth = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
73 // Define end of month to use
74 if ($tmparray['mon'] < $fiscalmonth || $fiscalmonth == 1) {
75 $tmparray['mon'] = $fiscalmonth == 1 ? 12 : $fiscalmonth - 1;
76 } else {
77 $tmparray['mon'] = $fiscalmonth - 1;
78 $tmparray['year']++;
79 }
80
81 $endaccountingperiod = dol_print_date(dol_get_last_day($tmparray['year'], $tmparray['mon']), 'dayxcard');
82 $siren = str_replace(" ", "", $siren);
83 $completefilename = $siren."FEC".$endaccountingperiod;
84
85 // Option: append a timestamp suffix to avoid overwriting a previous export of the same fiscal period.
86 // The strict FEC naming convention (SIRENFECAAAAMMJJ.txt) is still respected by default;
87 // this suffix is only added if the admin explicitly enables it, since some import software
88 // requires strict compliance with the official filename.
89 if (getDolGlobalInt('ACCOUNTING_EXPORT_FEC_ADD_TIMESTAMP')) {
90 $completefilename .= "_".dol_print_date(dol_now(), '%Y%m%d%H%M%S');
91 }
92
93 $completefilename .= ".txt";
94} elseif ($accountancyexport->getFormatCode($formatexportset) == 'ciel' && $type_export == "general_ledger" && getDolGlobalString('ACCOUNTING_EXPORT_XIMPORT_FORCE_FILENAME')) {
95 $completefilename = "XIMPORT.TXT";
96} else {
97 $completefilename = ($code ? $code."_" : "").($prefix ? $prefix."_" : "").$filename.($nodateexport ? "" : $date_export).".".$format;
98}
99
100// --- Hook: allow external modules to override export filename ---
101if (is_object($hookmanager)) {
102 // Dedicated context (non-blocking if other hooks are already initialized)
103 $hookmanager->initHooks(array('accountancyexportfilename'));
104
105 $parameters = array(
106 'type_export' => $type_export ?? '',
107 'format' => $format ?? '',
108 'format_code' => $accountancyexport->getFormatCode($formatexportset),
109 'code' => $code ?? '',
110 'prefix' => $prefix ?? '',
111 'filename' => $filename ?? '',
112 'period_start' => $startaccountingperiod,
113 'period_end' => $endaccountingperiod ?? '',
114 'siren' => $siren ?? '',
115 'ndate_in_filename' => $nodateexport ?? 0,
116 'now_datetime' => $date_export,
117 // Value by default
118 'defaultfilename' => $completefilename
119 );
120
121 // Hook called by modules: setExportFilename
122 $reshook = $hookmanager->executeHooks('setExportFilename', $parameters, $accountancyexport, $action);
123 if ($reshook > 0) {
124 if (!empty($hookmanager->resArray['filename'])) {
125 $completefilename = $hookmanager->resArray['filename'];
126 } elseif ($hookmanager->resPrint !== '') {
127 $completefilename = $hookmanager->resPrint;
128 }
129 }
130}
131
132if (empty($downloadMode)) {
133 header('Content-Type: text/csv');
134 header('Content-Disposition: attachment;filename=' . $completefilename);
135}
Manage the different format accountancy export.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:624
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.