dolibarr 23.0.3
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.".txt";
84} elseif ($accountancyexport->getFormatCode($formatexportset) == 'ciel' && $type_export == "general_ledger" && getDolGlobalString('ACCOUNTING_EXPORT_XIMPORT_FORCE_FILENAME')) {
85 $completefilename = "XIMPORT.TXT";
86} else {
87 $completefilename = ($code ? $code."_" : "").($prefix ? $prefix."_" : "").$filename.($nodateexport ? "" : $date_export).".".$format;
88}
89
90// --- Hook: allow external modules to override export filename ---
91if (is_object($hookmanager)) {
92 // Dedicated context (non-blocking if other hooks are already initialized)
93 $hookmanager->initHooks(array('accountancyexportfilename'));
94
95 $parameters = array(
96 'type_export' => $type_export ?? '',
97 'format' => $format ?? '',
98 'format_code' => $accountancyexport->getFormatCode($formatexportset),
99 'code' => $code ?? '',
100 'prefix' => $prefix ?? '',
101 'filename' => $filename ?? '',
102 'period_start' => $startaccountingperiod,
103 'period_end' => $endaccountingperiod ?? '',
104 'siren' => $siren ?? '',
105 'ndate_in_filename' => $nodateexport ?? 0,
106 'now_datetime' => $date_export,
107 // Value by default
108 'defaultfilename' => $completefilename
109 );
110
111 // Hook called by modules: setExportFilename
112 $reshook = $hookmanager->executeHooks('setExportFilename', $parameters, $accountancyexport, $action);
113 if ($reshook > 0) {
114 if (!empty($hookmanager->resArray['filename'])) {
115 $completefilename = $hookmanager->resArray['filename'];
116 } elseif ($hookmanager->resPrint !== '') {
117 $completefilename = $hookmanager->resPrint;
118 }
119 }
120}
121
122if (empty($downloadMode)) {
123 header('Content-Type: text/csv');
124 header('Content-Disposition: attachment;filename=' . $completefilename);
125}
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:622
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.