rapport.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  5. * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.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. * \file htdocs/compta/paiement/rapport.php
  22. * \ingroup facture
  23. * \brief Payment reports page
  24. */
  25. // Load Dolibarr environment
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/modules/rapport/pdf_paiement.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  31. $action = GETPOST('action', 'aZ09');
  32. $socid = 0;
  33. if ($user->socid > 0) {
  34. $action = '';
  35. $socid = $user->socid;
  36. }
  37. $dir = $conf->facture->dir_output.'/payments';
  38. if (empty($user->rights->societe->client->voir) || $socid) {
  39. $dir .= '/private/'.$user->id; // If user has no permission to see all, output dir is specific to user
  40. }
  41. $year = GETPOST('year', 'int');
  42. if (!$year) {
  43. $year = date("Y");
  44. }
  45. // Security check
  46. if (empty($user->rights->facture->lire)) {
  47. accessforbidden();
  48. }
  49. /*
  50. * Actions
  51. */
  52. if ($action == 'builddoc') {
  53. $rap = new pdf_paiement($db);
  54. $outputlangs = $langs;
  55. if (GETPOST('lang_id', 'aZ09')) {
  56. $outputlangs = new Translate("", $conf);
  57. $outputlangs->setDefaultLang(GETPOST('lang_id', 'aZ09'));
  58. }
  59. // We save charset_output to restore it because write_file can change it if needed for
  60. // output format that does not support UTF8.
  61. $sav_charset_output = $outputlangs->charset_output;
  62. if ($rap->write_file($dir, GETPOST("remonth", "int"), GETPOST("reyear", "int"), $outputlangs) > 0) {
  63. $outputlangs->charset_output = $sav_charset_output;
  64. } else {
  65. $outputlangs->charset_output = $sav_charset_output;
  66. dol_print_error($db, $obj->error);
  67. }
  68. $year = GETPOST("reyear", "int");
  69. }
  70. /*
  71. * View
  72. */
  73. $formother = new FormOther($db);
  74. $formfile = new FormFile($db);
  75. llxHeader();
  76. $titre = ($year ? $langs->trans("PaymentsReportsForYear", $year) : $langs->trans("PaymentsReports"));
  77. print load_fiche_titre($titre, '', 'bill');
  78. // Formulaire de generation
  79. print '<form method="post" action="rapport.php?year='.$year.'">';
  80. print '<input type="hidden" name="token" value="'.newToken().'">';
  81. print '<input type="hidden" name="action" value="builddoc">';
  82. $cmonth = GETPOST("remonth") ?GETPOST("remonth") : date("n", time());
  83. $syear = GETPOST("reyear") ?GETPOST("reyear") : date("Y", time());
  84. print $formother->select_month($cmonth, 'remonth');
  85. print $formother->selectyear($syear, 'reyear');
  86. print '<input type="submit" class="button" value="'.$langs->trans("Create").'">';
  87. print '</form>';
  88. print '<br>';
  89. clearstatcache();
  90. // Show link on other years
  91. $year_dirs = dol_dir_list($dir, 'directories', 0, '^[0-9]{4}$', '', 'DESC');
  92. foreach ($year_dirs as $d) {
  93. print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$d['name'].'">'.$d['name'].'</a> &nbsp;';
  94. }
  95. if ($year) {
  96. if (is_dir($dir.'/'.$year)) {
  97. if (!empty($year_dirs)) print '<br>';
  98. print '<br>';
  99. print '<table width="100%" class="noborder">';
  100. print '<tr class="liste_titre">';
  101. print '<td>'.$langs->trans("Reporting").'</td>';
  102. print '<td class="right">'.$langs->trans("Size").'</td>';
  103. print '<td class="right">'.$langs->trans("Date").'</td>';
  104. print '</tr>';
  105. $files = (dol_dir_list($dir.'/'.$year, 'files', 0, '^payments-[0-9]{4}-[0-9]{2}\.pdf$', '', 'name', 'DESC', 1));
  106. foreach ($files as $f) {
  107. $relativepath = $f['level1name'].'/'.$f['name'];
  108. print '<tr class="oddeven">';
  109. print '<td><a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart=facture_paiement&amp;file='.urlencode($relativepath).'">'.img_pdf().' '.$f['name'].'</a>'.$formfile->showPreview($f['name'], 'facture_paiement', $relativepath, 0).'</td>';
  110. print '<td class="right">'.dol_print_size($f['size']).'</td>';
  111. print '<td class="right">'.dol_print_date($f['date'], "dayhour").'</td>';
  112. print '</tr>';
  113. }
  114. print '</table>';
  115. }
  116. }
  117. // End of page
  118. llxFooter();
  119. $db->close();