rapport.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /* Copyright (C) 2017 ATM-Consulting <support@atm-consulting.fr>
  3. * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr>
  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. /**
  19. * \file htdocs/fourn/facture/rapport.php
  20. * \ingroup fourn
  21. * \brief Payment reports page
  22. */
  23. // Load Dolibarr environment
  24. require '../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/modules/rapport/pdf_paiement_fourn.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  29. $langs->loadLangs(array('bills'));
  30. // Security check
  31. $socid = '';
  32. if (!empty($user->socid)) {
  33. $socid = $user->socid;
  34. }
  35. $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
  36. $action = GETPOST('action', 'aZ09');
  37. $socid = 0;
  38. if ($user->socid > 0) {
  39. $action = '';
  40. $socid = $user->socid;
  41. }
  42. $dir = $conf->fournisseur->facture->dir_output.'/payments';
  43. if (empty($user->rights->societe->client->voir) || $socid) {
  44. $dir .= '/private/'.$user->id; // If user has no permission to see all, output dir is specific to user
  45. }
  46. $year = GETPOST("year", 'int');
  47. if (!$year) {
  48. $year = date("Y");
  49. }
  50. /*
  51. * Actions
  52. */
  53. if ($action == 'builddoc') {
  54. $rap = new pdf_paiement_fourn($db);
  55. $outputlangs = $langs;
  56. if (GETPOST('lang_id', 'aZ09')) {
  57. $outputlangs = new Translate("", $conf);
  58. $outputlangs->setDefaultLang(GETPOST('lang_id', 'aZ09'));
  59. }
  60. // We save charset_output to restore it because write_file can change it if needed for
  61. // output format that does not support UTF8.
  62. $sav_charset_output = $outputlangs->charset_output;
  63. if ($rap->write_file($dir, GETPOST("remonth", 'int'), GETPOST("reyear", 'int'), $outputlangs) > 0) {
  64. $outputlangs->charset_output = $sav_charset_output;
  65. } else {
  66. $outputlangs->charset_output = $sav_charset_output;
  67. dol_print_error($db, $obj->error);
  68. }
  69. $year = GETPOST("reyear", 'int');
  70. }
  71. /*
  72. * View
  73. */
  74. $formother = new FormOther($db);
  75. $formfile = new FormFile($db);
  76. $titre = ($year ? $langs->trans("PaymentsReportsForYear", $year) : $langs->trans("PaymentsReports"));
  77. llxHeader('', $titre);
  78. print load_fiche_titre($titre, '', 'supplier_invoice');
  79. // Formulaire de generation
  80. print '<form method="post" action="rapport.php?year='.$year.'">';
  81. print '<input type="hidden" name="token" value="'.newToken().'">';
  82. print '<input type="hidden" name="action" value="builddoc">';
  83. $cmonth = GETPOST("remonth") ?GETPOST("remonth") : date("n", time());
  84. $syear = GETPOST("reyear") ?GETPOST("reyear") : date("Y", time());
  85. print $formother->select_month($cmonth, 'remonth');
  86. print $formother->selectyear($syear, 'reyear');
  87. print '<input type="submit" class="button" value="'.$langs->trans("Create").'">';
  88. print '</form>';
  89. print '<br>';
  90. clearstatcache();
  91. // Show link on other years
  92. $linkforyear = array();
  93. $found = 0;
  94. if (is_dir($dir)) {
  95. $handle = opendir($dir);
  96. if (is_resource($handle)) {
  97. while (($file = readdir($handle)) !== false) {
  98. if (is_dir($dir.'/'.$file) && !preg_match('/^\./', $file) && is_numeric($file)) {
  99. $found = 1;
  100. $linkforyear[] = $file;
  101. }
  102. }
  103. }
  104. }
  105. asort($linkforyear);
  106. foreach ($linkforyear as $cursoryear) {
  107. print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$cursoryear.'">'.$cursoryear.'</a> &nbsp;';
  108. }
  109. if ($year) {
  110. if (is_dir($dir.'/'.$year)) {
  111. $handle = opendir($dir.'/'.$year);
  112. if ($found) {
  113. print '<br>';
  114. }
  115. print '<br>';
  116. print '<table width="100%" class="noborder">';
  117. print '<tr class="liste_titre">';
  118. print '<td>'.$langs->trans("Reporting").'</td>';
  119. print '<td class="right">'.$langs->trans("Size").'</td>';
  120. print '<td class="right">'.$langs->trans("Date").'</td>';
  121. print '</tr>';
  122. if (is_resource($handle)) {
  123. while (($file = readdir($handle)) !== false) {
  124. if (preg_match('/^supplier_payment/i', $file)) {
  125. $tfile = $dir.'/'.$year.'/'.$file;
  126. $relativepath = $year.'/'.$file;
  127. print '<tr class="oddeven"><td><a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart=facture_fournisseur&amp;file=payments/'.urlencode($relativepath).'">'.img_pdf().' '.$file.'</a>'.$formfile->showPreview($file, 'facture_fournisseur', 'payments/'.$relativepath, 0).'</td>';
  128. print '<td class="right">'.dol_print_size(dol_filesize($tfile)).'</td>';
  129. print '<td class="right">'.dol_print_date(dol_filemtime($tfile), "dayhour").'</td></tr>';
  130. }
  131. }
  132. closedir($handle);
  133. }
  134. print '</table>';
  135. }
  136. }
  137. // End of page
  138. llxFooter();
  139. $db->close();