export_journal.tpl.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /* Copyright (C) 2015-2018 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. // Protection to avoid direct call of template
  19. if (empty($conf) || ! is_object($conf))
  20. {
  21. print "Error, template page can't be called as URL";
  22. exit;
  23. }
  24. $code = $conf->global->MAIN_INFO_ACCOUNTANT_CODE;
  25. $prefix = $conf->global->ACCOUNTING_EXPORT_PREFIX_SPEC;
  26. $format = $conf->global->ACCOUNTING_EXPORT_FORMAT;
  27. $nodateexport = $conf->global->ACCOUNTING_EXPORT_NO_DATE_IN_FILENAME;
  28. $siren = $conf->global->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. if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == "11" && $type_export == "general_ledger") // Specific filename for FEC model export into the general ledger
  33. {
  34. // FEC format is defined here: https://www.legifrance.gouv.fr/affichCodeArticle.do?idArticle=LEGIARTI000027804775&cidTexte=LEGITEXT000006069583&dateTexte=20130802&oldAction=rechCodeArticle
  35. if (empty($search_date_end))
  36. {
  37. // TODO Get the max date into bookeeping table
  38. $search_date_end = dol_now();
  39. }
  40. $datetouseforfilename = $search_date_end;
  41. $tmparray=dol_getdate($datetouseforfilename);
  42. $fiscalmonth=empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START;
  43. // Define end of month to use
  44. if ($tmparray['mon'] <= $fiscalmonth) $tmparray['mon']=$fiscalmonth;
  45. else {
  46. $tmparray['mon'] = $fiscalmonth;
  47. $tmparray['year']++;
  48. }
  49. $endaccountingperiod = dol_print_date(dol_get_last_day($tmparray['year'], $tmparray['mon']), 'dayxcard');
  50. $completefilename = $siren . "FEC" . $endaccountingperiod . "." . $format;
  51. }
  52. else
  53. {
  54. $completefilename = ($code?$code . "_":"") . ($prefix?$prefix . "_":"") . $filename . ($nodateexport?"":$date_export) . "." . $format;
  55. }
  56. header('Content-Disposition: attachment;filename=' . $completefilename);