export_journal.tpl.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. // $formatexportset must be defined
  19. // Protection to avoid direct call of template
  20. if (empty($conf) || !is_object($conf)) {
  21. print "Error, template page can't be called as URL";
  22. exit;
  23. }
  24. $code = getDolGlobalString('MAIN_INFO_ACCOUNTANT_CODE');
  25. $prefix = getDolGlobalString('ACCOUNTING_EXPORT_PREFIX_SPEC');
  26. $format = getDolGlobalString('ACCOUNTING_EXPORT_FORMAT');
  27. $nodateexport = getDolGlobalInt('ACCOUNTING_EXPORT_NO_DATE_IN_FILENAME');
  28. $siren = getDolGlobalString('MAIN_INFO_SIREN');
  29. $date_export = "_".dol_print_date(dol_now(), '%Y%m%d%H%M%S');
  30. $endaccountingperiod = dol_print_date(dol_now(), '%Y%m%d');
  31. header('Content-Type: text/csv');
  32. include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancyexport.class.php';
  33. $accountancyexport = new AccountancyExport($db);
  34. // Specific filename for FEC model export into the general ledger
  35. if (($accountancyexport->getFormatCode($formatexportset) == 'fec' || $accountancyexport->getFormatCode($formatexportset) == 'fec2')
  36. && $type_export == "general_ledger") {
  37. // FEC format is defined here: https://www.legifrance.gouv.fr/affichCodeArticle.do?idArticle=LEGIARTI000027804775&cidTexte=LEGITEXT000006069583&dateTexte=20130802&oldAction=rechCodeArticle
  38. if (empty($search_date_end)) {
  39. // TODO Get the max date into bookkeeping table
  40. $search_date_end = dol_now();
  41. }
  42. $datetouseforfilename = $search_date_end;
  43. $tmparray = dol_getdate($datetouseforfilename);
  44. $fiscalmonth = empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START;
  45. // Define end of month to use
  46. if ($tmparray['mon'] <= $fiscalmonth) {
  47. $tmparray['mon'] = $fiscalmonth;
  48. } else {
  49. $tmparray['mon'] = $fiscalmonth;
  50. $tmparray['year']++;
  51. }
  52. $endaccountingperiod = dol_print_date(dol_get_last_day($tmparray['year'], $tmparray['mon']), 'dayxcard');
  53. $completefilename = $siren."FEC".$endaccountingperiod.".txt";
  54. } elseif ($accountancyexport->getFormatCode($formatexportset) == 'ciel' && $type_export == "general_ledger" && !empty($conf->global->ACCOUNTING_EXPORT_XIMPORT_FORCE_FILENAME)) {
  55. $completefilename = "XIMPORT.TXT";
  56. } else {
  57. $completefilename = ($code ? $code."_" : "").($prefix ? $prefix."_" : "").$filename.($nodateexport ? "" : $date_export).".".$format;
  58. }
  59. header('Content-Disposition: attachment;filename='.$completefilename);