dolibarr  13.0.2
rapport.php
Go to the documentation of this file.
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 
27 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/modules/rapport/pdf_paiement.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
32 
33 $action = GETPOST('action', 'aZ09');
34 
35 $socid = 0;
36 if ($user->socid > 0)
37 {
38  $action = '';
39  $socid = $user->socid;
40 }
41 
42 $dir = $conf->facture->dir_output.'/payments';
43 if (!$user->rights->societe->client->voir || $socid) $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) { $year = date("Y"); }
47 
48 // Security check
49 if (empty($user->rights->facture->lire)) accessforbidden();
50 
51 
52 /*
53  * Actions
54  */
55 
56 if ($action == 'builddoc')
57 {
58  $rap = new pdf_paiement($db);
59 
60  $outputlangs = $langs;
61  if (GETPOST('lang_id', 'aZ09'))
62  {
63  $outputlangs = new Translate("", $conf);
64  $outputlangs->setDefaultLang(GETPOST('lang_id', 'aZ09'));
65  }
66 
67  // We save charset_output to restore it because write_file can change it if needed for
68  // output format that does not support UTF8.
69  $sav_charset_output = $outputlangs->charset_output;
70  if ($rap->write_file($dir, $_POST["remonth"], $_POST["reyear"], $outputlangs) > 0)
71  {
72  $outputlangs->charset_output = $sav_charset_output;
73  } else {
74  $outputlangs->charset_output = $sav_charset_output;
75  dol_print_error($db, $obj->error);
76  }
77 
78  $year = $_POST["reyear"];
79 }
80 
81 
82 /*
83  * View
84  */
85 
86 $formother = new FormOther($db);
87 $formfile = new FormFile($db);
88 
89 llxHeader();
90 
91 $titre = ($year ? $langs->trans("PaymentsReportsForYear", $year) : $langs->trans("PaymentsReports"));
92 print load_fiche_titre($titre, '', 'bill');
93 
94 // Formulaire de generation
95 print '<form method="post" action="rapport.php?year='.$year.'">';
96 print '<input type="hidden" name="token" value="'.newToken().'">';
97 print '<input type="hidden" name="action" value="builddoc">';
98 $cmonth = GETPOST("remonth") ?GETPOST("remonth") : date("n", time());
99 $syear = GETPOST("reyear") ?GETPOST("reyear") : date("Y", time());
100 
101 print $formother->select_month($cmonth, 'remonth');
102 
103 print $formother->select_year($syear, 'reyear');
104 
105 print '<input type="submit" class="button" value="'.$langs->trans("Create").'">';
106 print '</form>';
107 print '<br>';
108 
109 clearstatcache();
110 
111 // Show link on other years
112 $linkforyear = array();
113 $found = 0;
114 if (is_dir($dir))
115 {
116  $handle = opendir($dir);
117  if (is_resource($handle))
118  {
119  while (($file = readdir($handle)) !== false)
120  {
121  if (is_dir($dir.'/'.$file) && !preg_match('/^\./', $file) && is_numeric($file))
122  {
123  $found = 1;
124  $linkforyear[] = $file;
125  }
126  }
127  }
128 }
129 asort($linkforyear);
130 foreach ($linkforyear as $cursoryear)
131 {
132  print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$cursoryear.'">'.$cursoryear.'</a> &nbsp;';
133 }
134 
135 if ($year)
136 {
137  if (is_dir($dir.'/'.$year))
138  {
139  $handle = opendir($dir.'/'.$year);
140 
141  if ($found) print '<br>';
142  print '<br>';
143  print '<table width="100%" class="noborder">';
144  print '<tr class="liste_titre">';
145  print '<td>'.$langs->trans("Reporting").'</td>';
146  print '<td class="right">'.$langs->trans("Size").'</td>';
147  print '<td class="right">'.$langs->trans("Date").'</td>';
148  print '</tr>';
149 
150  if (is_resource($handle))
151  {
152  while (($file = readdir($handle)) !== false)
153  {
154  if (preg_match('/^payment/i', $file))
155  {
156  $tfile = $dir.'/'.$year.'/'.$file;
157  $relativepath = $year.'/'.$file;
158  print '<tr class="oddeven">';
159  print '<td><a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart=facture_paiement&amp;file='.urlencode($relativepath).'">'.img_pdf().' '.$file.'</a>'.$formfile->showPreview($file, 'facture_paiement', $relativepath, 0).'</td>';
160  print '<td class="right">'.dol_print_size(dol_filesize($tfile)).'</td>';
161  print '<td class="right">'.dol_print_date(dol_filemtime($tfile), "dayhour").'</td>';
162  print '</tr>';
163  }
164  }
165  closedir($handle);
166  }
167  print '</table>';
168  }
169 }
170 
171 // End of page
172 llxFooter();
173 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_filesize($pathoffile)
Return size of a file.
Definition: files.lib.php:555
llxHeader()
Empty header.
Definition: wrapper.php:45
img_pdf($titlealt= 'default', $size=3)
Show pdf logo.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
Classe permettant la generation de composants html autre Only common components are here...
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage translations.
Classe permettant de generer les rapports de paiement.
Class to offer components to list and upload files.
print
Draft customers invoices.
Definition: index.php:89
dol_filemtime($pathoffile)
Return time of a file.
Definition: files.lib.php:567
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
llxFooter()
Empty footer.
Definition: wrapper.php:59