dolibarr 21.0.0-alpha
export_journal.tpl.php
1<?php
2/* Copyright (C) 2015-2024 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 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22// $formatexportset must be defined
23// $downloadMode =0 for direct download or =1 to download after writing files or =-1 not to download files
24
25'
26@phan-var-force string $formatexportset
27@phan-var-force string $type_export
28@phan-var-force string $filename
29@phan-var-force int<-1,1> $downloadMode
30';
31
32// Protection to avoid direct call of template
33if (empty($conf) || !is_object($conf)) {
34 print "Error, template page can't be called as URL";
35 exit(1);
36}
37
38$code = getDolGlobalString('MAIN_INFO_ACCOUNTANT_CODE');
39$prefix = getDolGlobalString('ACCOUNTING_EXPORT_PREFIX_SPEC');
40$format = getDolGlobalString('ACCOUNTING_EXPORT_FORMAT');
41$nodateexport = getDolGlobalInt('ACCOUNTING_EXPORT_NO_DATE_IN_FILENAME');
42$siren = getDolGlobalString('MAIN_INFO_SIREN');
43
44$date_export = "_".dol_print_date(dol_now(), '%Y%m%d%H%M%S');
45$endaccountingperiod = dol_print_date(dol_now(), '%Y%m%d');
46
47
48if (empty($downloadMode)) {
49 header('Content-Type: text/csv');
50}
51
52include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancyexport.class.php';
53$accountancyexport = new AccountancyExport($db);
54
55// Specific filename for FEC model export into the general ledger
56if ((substr($accountancyexport->getFormatCode($formatexportset), 0, 3) == 'fec') && $type_export == "general_ledger") {
57 // FEC format is defined here: https://www.legifrance.gouv.fr/affichCodeArticle.do?idArticle=LEGIARTI000027804775&cidTexte=LEGITEXT000006069583&dateTexte=20130802&oldAction=rechCodeArticle
58 if (empty($search_date_end)) {
59 // TODO Get the max date into bookkeeping table
60 $search_date_end = dol_now();
61 }
62 $datetouseforfilename = $search_date_end;
63 $tmparray = dol_getdate($datetouseforfilename);
64 $fiscalmonth = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
65 // Define end of month to use
66 if ($tmparray['mon'] < $fiscalmonth || $fiscalmonth == 1) {
67 $tmparray['mon'] = $fiscalmonth == 1 ? 12 : $fiscalmonth - 1;
68 } else {
69 $tmparray['mon'] = $fiscalmonth - 1;
70 $tmparray['year']++;
71 }
72
73 $endaccountingperiod = dol_print_date(dol_get_last_day($tmparray['year'], $tmparray['mon']), 'dayxcard');
74 $siren = str_replace(" ", "", $siren);
75 $completefilename = $siren."FEC".$endaccountingperiod.".txt";
76} elseif ($accountancyexport->getFormatCode($formatexportset) == 'ciel' && $type_export == "general_ledger" && getDolGlobalString('ACCOUNTING_EXPORT_XIMPORT_FORCE_FILENAME')) {
77 $completefilename = "XIMPORT.TXT";
78} else {
79 $completefilename = ($code ? $code."_" : "").($prefix ? $prefix."_" : "").$filename.($nodateexport ? "" : $date_export).".".$format;
80}
81
82if (empty($downloadMode)) {
83 header('Content-Disposition: attachment;filename=' . $completefilename);
84}
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:615
dol_now($mode='auto')
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)
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.