dolibarr 19.0.3
export_journal.tpl.php
1<?php
2/* Copyright (C) 2015-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
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;
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 (($accountancyexport->getFormatCode($formatexportset) == 'fec' || $accountancyexport->getFormatCode($formatexportset) == 'fec2')
48 && $type_export == "general_ledger") {
49 // FEC format is defined here: https://www.legifrance.gouv.fr/affichCodeArticle.do?idArticle=LEGIARTI000027804775&cidTexte=LEGITEXT000006069583&dateTexte=20130802&oldAction=rechCodeArticle
50 if (empty($search_date_end)) {
51 // TODO Get the max date into bookkeeping table
52 $search_date_end = dol_now();
53 }
54 $datetouseforfilename = $search_date_end;
55 $tmparray = dol_getdate($datetouseforfilename);
56 $fiscalmonth = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
57 // Define end of month to use
58 if ($tmparray['mon'] < $fiscalmonth || $fiscalmonth == 1) {
59 $tmparray['mon'] = $fiscalmonth == 1 ? 12 : $fiscalmonth - 1;
60 } else {
61 $tmparray['mon'] = $fiscalmonth - 1;
62 $tmparray['year']++;
63 }
64
65 $endaccountingperiod = dol_print_date(dol_get_last_day($tmparray['year'], $tmparray['mon']), 'dayxcard');
66 $siren = str_replace(" ", "", $siren);
67 $completefilename = $siren."FEC".$endaccountingperiod.".txt";
68} elseif ($accountancyexport->getFormatCode($formatexportset) == 'ciel' && $type_export == "general_ledger" && getDolGlobalString('ACCOUNTING_EXPORT_XIMPORT_FORCE_FILENAME')) {
69 $completefilename = "XIMPORT.TXT";
70} else {
71 $completefilename = ($code ? $code."_" : "").($prefix ? $prefix."_" : "").$filename.($nodateexport ? "" : $date_export).".".$format;
72}
73
74if (empty($downloadMode)) {
75 header('Content-Disposition: attachment;filename=' . $completefilename);
76}
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.