rapport.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. require '../../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/modules/rapport/pdf_paiement_fourn.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  28. $langs->loadLangs(array('bills'));
  29. // Security check
  30. $socid = '';
  31. if (!empty($user->socid)) {
  32. $socid = $user->socid;
  33. }
  34. $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
  35. $action = GETPOST('action', 'aZ09');
  36. $socid = 0;
  37. if ($user->socid > 0) {
  38. $action = '';
  39. $socid = $user->socid;
  40. }
  41. $dir = $conf->fournisseur->facture->dir_output.'/payments';
  42. if (empty($user->rights->societe->client->voir) || $socid) {
  43. $dir .= '/private/'.$user->id; // If user has no permission to see all, output dir is specific to user
  44. }
  45. $year = GETPOST("year", 'int');
  46. if (!$year) {
  47. $year = date("Y");
  48. }
  49. /*
  50. * Actions
  51. */
  52. if ($action == 'builddoc') {
  53. $rap = new pdf_paiement_fourn($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. $titre = ($year ? $langs->trans("PaymentsReportsForYear", $year) : $langs->trans("PaymentsReports"));
  76. llxHeader('', $titre);
  77. print load_fiche_titre($titre, '', 'supplier_invoice');
  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. $linkforyear = array();
  92. $found = 0;
  93. if (is_dir($dir)) {
  94. $handle = opendir($dir);
  95. if (is_resource($handle)) {
  96. while (($file = readdir($handle)) !== false) {
  97. if (is_dir($dir.'/'.$file) && !preg_match('/^\./', $file) && is_numeric($file)) {
  98. $found = 1;
  99. $linkforyear[] = $file;
  100. }
  101. }
  102. }
  103. }
  104. asort($linkforyear);
  105. foreach ($linkforyear as $cursoryear) {
  106. print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$cursoryear.'">'.$cursoryear.'</a> &nbsp;';
  107. }
  108. if ($year) {
  109. if (is_dir($dir.'/'.$year)) {
  110. $handle = opendir($dir.'/'.$year);
  111. if ($found) {
  112. print '<br>';
  113. }
  114. print '<br>';
  115. print '<table width="100%" class="noborder">';
  116. print '<tr class="liste_titre">';
  117. print '<td>'.$langs->trans("Reporting").'</td>';
  118. print '<td class="right">'.$langs->trans("Size").'</td>';
  119. print '<td class="right">'.$langs->trans("Date").'</td>';
  120. print '</tr>';
  121. if (is_resource($handle)) {
  122. while (($file = readdir($handle)) !== false) {
  123. if (preg_match('/^supplier_payment/i', $file)) {
  124. $tfile = $dir.'/'.$year.'/'.$file;
  125. $relativepath = $year.'/'.$file;
  126. 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>';
  127. print '<td class="right">'.dol_print_size(dol_filesize($tfile)).'</td>';
  128. print '<td class="right">'.dol_print_date(dol_filemtime($tfile), "dayhour").'</td></tr>';
  129. }
  130. }
  131. closedir($handle);
  132. }
  133. print '</table>';
  134. }
  135. }
  136. // End of page
  137. llxFooter();
  138. $db->close();