rapport.php 4.6 KB

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