dolibarr 21.0.0-beta
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 * 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// $formatexportset must be defined
24// $downloadMode =0 for direct download or =1 to download after writing files or =-1 not to download files
25
26'
27@phan-var-force string $formatexportset
28@phan-var-force string $type_export
29@phan-var-force string $filename
30@phan-var-force int<-1,1> $downloadMode
31';
32
42// Protection to avoid direct call of template
43if (empty($conf) || !is_object($conf)) {
44 print "Error, template page can't be called as URL";
45 exit(1);
46}
47
48$code = getDolGlobalString('MAIN_INFO_ACCOUNTANT_CODE');
49$prefix = getDolGlobalString('ACCOUNTING_EXPORT_PREFIX_SPEC');
50$format = getDolGlobalString('ACCOUNTING_EXPORT_FORMAT');
51$nodateexport = getDolGlobalInt('ACCOUNTING_EXPORT_NO_DATE_IN_FILENAME');
52$siren = getDolGlobalString('MAIN_INFO_SIREN');
53
54$date_export = "_".dol_print_date(dol_now(), '%Y%m%d%H%M%S');
55$endaccountingperiod = dol_print_date(dol_now(), '%Y%m%d');
56
57
58if (empty($downloadMode)) {
59 header('Content-Type: text/csv');
60}
61
62include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancyexport.class.php';
63$accountancyexport = new AccountancyExport($db);
64
65// Specific filename for FEC model export into the general ledger
66if ((substr($accountancyexport->getFormatCode($formatexportset), 0, 3) == 'fec') && $type_export == "general_ledger") {
67 // FEC format is defined here: https://www.legifrance.gouv.fr/affichCodeArticle.do?idArticle=LEGIARTI000027804775&cidTexte=LEGITEXT000006069583&dateTexte=20130802&oldAction=rechCodeArticle
68 if (empty($search_date_end)) {
69 // TODO Get the max date into bookkeeping table
70 $search_date_end = dol_now();
71 }
72 $datetouseforfilename = $search_date_end;
73 $tmparray = dol_getdate($datetouseforfilename);
74 $fiscalmonth = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
75 // Define end of month to use
76 if ($tmparray['mon'] < $fiscalmonth || $fiscalmonth == 1) {
77 $tmparray['mon'] = $fiscalmonth == 1 ? 12 : $fiscalmonth - 1;
78 } else {
79 $tmparray['mon'] = $fiscalmonth - 1;
80 $tmparray['year']++;
81 }
82
83 $endaccountingperiod = dol_print_date(dol_get_last_day($tmparray['year'], $tmparray['mon']), 'dayxcard');
84 $siren = str_replace(" ", "", $siren);
85 $completefilename = $siren."FEC".$endaccountingperiod.".txt";
86} elseif ($accountancyexport->getFormatCode($formatexportset) == 'ciel' && $type_export == "general_ledger" && getDolGlobalString('ACCOUNTING_EXPORT_XIMPORT_FORCE_FILENAME')) {
87 $completefilename = "XIMPORT.TXT";
88} else {
89 $completefilename = ($code ? $code."_" : "").($prefix ? $prefix."_" : "").$filename.($nodateexport ? "" : $date_export).".".$format;
90}
91
92if (empty($downloadMode)) {
93 header('Content-Disposition: attachment;filename=' . $completefilename);
94}
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:619
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79