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