dolibarr  9.0.0
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  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
26 require '../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/modules/rapport/pdf_paiement.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
30 
31 // Security check
32 if (! $user->rights->facture->lire) accessforbidden();
33 
34 $action=GETPOST('action','aZ09');
35 
36 $socid=0;
37 if ($user->societe_id > 0)
38 {
39  $action = '';
40  $socid = $user->societe_id;
41 }
42 
43 $dir = $conf->facture->dir_output.'/payments';
44 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
45 
46 $year = GETPOST('year', 'int');
47 if (! $year) { $year=date("Y"); }
48 
49 
50 /*
51  * Actions
52  */
53 
54 if ($action == 'builddoc')
55 {
56  $rap = new pdf_paiement($db);
57 
58  $outputlangs = $langs;
59  if (GETPOST('lang_id','aZ09'))
60  {
61  $outputlangs = new Translate("",$conf);
62  $outputlangs->setDefaultLang(GETPOST('lang_id','aZ09'));
63  }
64 
65  // We save charset_output to restore it because write_file can change it if needed for
66  // output format that does not support UTF8.
67  $sav_charset_output=$outputlangs->charset_output;
68  if ($rap->write_file($dir, $_POST["remonth"], $_POST["reyear"], $outputlangs) > 0)
69  {
70  $outputlangs->charset_output=$sav_charset_output;
71  }
72  else
73  {
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 
88 llxHeader();
89 
90 $titre=($year?$langs->trans("PaymentsReportsForYear",$year):$langs->trans("PaymentsReports"));
91 print load_fiche_titre($titre,'','title_accountancy.png');
92 
93 // Formulaire de generation
94 print '<form method="post" action="rapport.php?year='.$year.'">';
95 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
96 print '<input type="hidden" name="action" value="builddoc">';
97 $cmonth = GETPOST("remonth")?GETPOST("remonth"):date("n", time());
98 $syear = GETPOST("reyear")?GETPOST("reyear"):date("Y", time());
99 
100 print $formother->select_month($cmonth,'remonth');
101 
102 print $formother->select_year($syear,'reyear');
103 
104 print '<input type="submit" class="button" value="'.$langs->trans("Create").'">';
105 print '</form>';
106 print '<br>';
107 
108 clearstatcache();
109 
110 // Show link on other years
111 $linkforyear=array();
112 $found=0;
113 if (is_dir($dir))
114 {
115  $handle=opendir($dir);
116  if (is_resource($handle))
117  {
118  while (($file = readdir($handle))!==false)
119  {
120  if (is_dir($dir.'/'.$file) && ! preg_match('/^\./',$file) && is_numeric($file))
121  {
122  $found=1;
123  $linkforyear[]=$file;
124  }
125  }
126  }
127 }
128 asort($linkforyear);
129 foreach($linkforyear as $cursoryear)
130 {
131  print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$cursoryear.'">'.$cursoryear.'</a> &nbsp;';
132 }
133 
134 if ($year)
135 {
136  if (is_dir($dir.'/'.$year))
137  {
138  $handle=opendir($dir.'/'.$year);
139 
140  if ($found) print '<br>';
141  print '<br>';
142  print '<table width="100%" class="noborder">';
143  print '<tr class="liste_titre">';
144  print '<td>'.$langs->trans("Reporting").'</td>';
145  print '<td align="right">'.$langs->trans("Size").'</td>';
146  print '<td align="right">'.$langs->trans("Date").'</td>';
147  print '</tr>';
148 
149  if (is_resource($handle))
150  {
151  while (($file = readdir($handle))!==false)
152  {
153  if (preg_match('/^payment/i',$file))
154  {
155 
156  $tfile = $dir . '/'.$year.'/'.$file;
157  $relativepath = $year.'/'.$file;
158  print '<tr class="oddeven">'.'<td><a data-ajax="false" href="'.DOL_URL_ROOT . '/document.php?modulepart=facture_paiement&amp;file='.urlencode($relativepath).'">'.img_pdf().' '.$file.'</a></td>';
159  print '<td align="right">'.dol_print_size(dol_filesize($tfile)).'</td>';
160  print '<td align="right">'.dol_print_date(dol_filemtime($tfile),"dayhour").'</td></tr>';
161  }
162  }
163  closedir($handle);
164  }
165  print '</table>';
166  }
167 }
168 
169 // End of page
170 llxFooter();
171 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
dol_filesize($pathoffile)
Return size of a file.
Definition: files.lib.php:552
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Classe permettant la generation de composants html autre Only common components are here...
llxHeader()
Empty header.
Definition: wrapper.php:44
Class to manage translations.
Classe permettant de generer les rapports de paiement.
img_pdf($titlealt='default', $size=3)
Show pdf logo.
dol_filemtime($pathoffile)
Return time of a file.
Definition: files.lib.php:564