PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/compta/paiement/rapport.php

https://github.com/asterix14/dolibarr
PHP | 189 lines | 133 code | 24 blank | 32 comment | 25 complexity | f576e652f55b2e0e75efad60e15d325d MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  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 2 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 <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/compta/paiement/rapport.php
  20. * \ingroup facture
  21. * \brief Payment reports page
  22. */
  23. require("../../main.inc.php");
  24. require_once(DOL_DOCUMENT_ROOT."/core/modules/rapport/pdf_paiement.class.php");
  25. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  26. // Security check
  27. if (! $user->rights->facture->lire)
  28. accessforbidden();
  29. $dir = $conf->facture->dir_output.'/payments';
  30. $socid=0;
  31. if ($user->societe_id > 0)
  32. {
  33. $action = '';
  34. $socid = $user->societe_id;
  35. $dir = $conf->facture->dir_output.'/payments/private/'.$user->id;
  36. }
  37. $year = $_GET["year"];
  38. if (! $year) { $year=date("Y"); }
  39. /*
  40. * Actions
  41. */
  42. if ($_POST["action"] == 'builddoc')
  43. {
  44. $rap = new pdf_paiement($db);
  45. $outputlangs = $langs;
  46. if (! empty($_REQUEST['lang_id']))
  47. {
  48. $outputlangs = new Translate("",$conf);
  49. $outputlangs->setDefaultLang($_REQUEST['lang_id']);
  50. }
  51. // We save charset_output to restore it because write_file can change it if needed for
  52. // output format that does not support UTF8.
  53. $sav_charset_output=$outputlangs->charset_output;
  54. if ($rap->write_file($dir, $_POST["remonth"], $_POST["reyear"], $outputlangs) > 0)
  55. {
  56. $outputlangs->charset_output=$sav_charset_output;
  57. }
  58. else
  59. {
  60. $outputlangs->charset_output=$sav_charset_output;
  61. dol_print_error($db,$obj->error);
  62. }
  63. $year = $_POST["reyear"];
  64. }
  65. /*
  66. * View
  67. */
  68. llxHeader();
  69. $titre=($year?$langs->trans("PaymentsReportsForYear",$year):$langs->trans("PaymentsReports"));
  70. print_fiche_titre($titre);
  71. // Formulaire de generation
  72. print '<form method="post" action="rapport.php?year='.$year.'">';
  73. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  74. print '<input type="hidden" name="action" value="builddoc">';
  75. $cmonth = GETPOST("remonth")?GETPOST("remonth"):date("n", time());
  76. $syear = GETPOST("reyear")?GETPOST("reyear"):date("Y", time());
  77. print '<select class="flat" name="remonth">';
  78. for ($month = 1 ; $month < 13 ; $month++)
  79. {
  80. if ($month == $cmonth)
  81. {
  82. print "<option value=\"$month\" selected=\"true\">" . dol_print_date(mktime(0,0,0,$month),"%B");
  83. }
  84. else
  85. {
  86. print "<option value=\"$month\">" . dol_print_date(mktime(0,0,0,$month),"%B");
  87. }
  88. }
  89. print "</select>";
  90. print '<select class="flat" name="reyear">';
  91. for ($formyear = $syear - 2; $formyear < $syear +1 ; $formyear++)
  92. {
  93. if ($formyear == $syear)
  94. {
  95. print "<option value=\"$formyear\" selected=\"true\">".$formyear."</option>";
  96. }
  97. else
  98. {
  99. print "<option value=\"$formyear\">".$formyear."</option>";
  100. }
  101. }
  102. print "</select>\n";
  103. print '<input type="submit" class="button" value="'.$langs->trans("Create").'">';
  104. print '</form>';
  105. print '<br>';
  106. clearstatcache();
  107. // Show link on other years
  108. $linkforyear=array();
  109. $found=0;
  110. if (is_dir($dir))
  111. {
  112. $handle=opendir($dir);
  113. if (is_resource($handle))
  114. {
  115. while (($file = readdir($handle))!==false)
  116. {
  117. if (is_dir($dir.'/'.$file) && ! preg_match('/^\./',$file) && is_numeric($file))
  118. {
  119. $found=1;
  120. $linkforyear[]=$file;
  121. }
  122. }
  123. }
  124. }
  125. asort($linkforyear);
  126. foreach($linkforyear as $cursoryear)
  127. {
  128. print '<a href="rapport.php?year='.$cursoryear.'">'.$cursoryear.'</a> &nbsp;';
  129. }
  130. if ($year)
  131. {
  132. if (is_dir($dir.'/'.$year))
  133. {
  134. $handle=opendir($dir.'/'.$year);
  135. if ($found) print '<br>';
  136. print '<br>';
  137. print '<table width="100%" class="noborder">';
  138. print '<tr class="liste_titre">';
  139. print '<td>'.$langs->trans("Reporting").'</td>';
  140. print '<td align="right">'.$langs->trans("Size").'</td>';
  141. print '<td align="right">'.$langs->trans("Date").'</td>';
  142. print '</tr>';
  143. $var=true;
  144. if (is_resource($handle))
  145. {
  146. while (($file = readdir($handle))!==false)
  147. {
  148. if (preg_match('/^payment/i',$file))
  149. {
  150. $var=!$var;
  151. $tfile = $dir . '/'.$year.'/'.$file;
  152. $relativepath = $year.'/'.$file;
  153. print "<tr $bc[$var]>".'<td><a href="'.DOL_URL_ROOT . '/document.php?modulepart=facture_paiement&amp;file='.urlencode($relativepath).'">'.img_pdf().' '.$file.'</a></td>';
  154. print '<td align="right">'.dol_print_size(dol_filesize($tfile)).'</td>';
  155. print '<td align="right">'.dol_print_date(dol_filemtime($tfile),"dayhour").'</td></tr>';
  156. }
  157. }
  158. closedir($handle);
  159. }
  160. print '</table>';
  161. }
  162. }
  163. $db->close();
  164. llxFooter();
  165. ?>