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