dolibarr  x.y.z
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 
23 // Protection to avoid direct call of template
24 if (empty($conf) || !is_object($conf)) {
25  print "Error, template page can't be called as URL";
26  exit;
27 }
28 
29 $code = getDolGlobalString('MAIN_INFO_ACCOUNTANT_CODE');
30 $prefix = getDolGlobalString('ACCOUNTING_EXPORT_PREFIX_SPEC');
31 $format = getDolGlobalString('ACCOUNTING_EXPORT_FORMAT');
32 $nodateexport = getDolGlobalInt('ACCOUNTING_EXPORT_NO_DATE_IN_FILENAME');
33 $siren = getDolGlobalString('MAIN_INFO_SIREN');
34 
35 $date_export = "_".dol_print_date(dol_now(), '%Y%m%d%H%M%S');
36 $endaccountingperiod = dol_print_date(dol_now(), '%Y%m%d');
37 
38 if (empty($withAttachment)) {
39  header('Content-Type: text/csv');
40 }
41 
42 include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancyexport.class.php';
43 $accountancyexport = new AccountancyExport($db);
44 
45 // Specific filename for FEC model export into the general ledger
46 if (($accountancyexport->getFormatCode($formatexportset) == 'fec' || $accountancyexport->getFormatCode($formatexportset) == 'fec2')
47  && $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 = empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START;
56  // Define end of month to use
57  if ($tmparray['mon'] <= $fiscalmonth) {
58  $tmparray['mon'] = $fiscalmonth;
59  } else {
60  $tmparray['mon'] = $fiscalmonth;
61  $tmparray['year']++;
62  }
63 
64  $endaccountingperiod = dol_print_date(dol_get_last_day($tmparray['year'], $tmparray['mon']), 'dayxcard');
65 
66  $completefilename = $siren."FEC".$endaccountingperiod.".txt";
67 } elseif ($accountancyexport->getFormatCode($formatexportset) == 'ciel' && $type_export == "general_ledger" && !empty($conf->global->ACCOUNTING_EXPORT_XIMPORT_FORCE_FILENAME)) {
68  $completefilename = "XIMPORT.TXT";
69 } else {
70  $completefilename = ($code ? $code."_" : "").($prefix ? $prefix."_" : "").$filename.($nodateexport ? "" : $date_export).".".$format;
71 }
72 
73 if (empty($withAttachment)) {
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: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.