dolibarr  18.0.6
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 // Load Dolibarr environment
28 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/modules/rapport/pdf_paiement.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
33 
34 $action = GETPOST('action', 'aZ09');
35 
36 $socid = 0;
37 if ($user->socid > 0) {
38  $action = '';
39  $socid = $user->socid;
40 }
41 
42 $dir = $conf->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 
47 $year = GETPOST('year', 'int');
48 if (!$year) {
49  $year = date("Y");
50 }
51 
52 // Security check
53 if (!$user->hasRight('facture', 'lire')) {
55 }
56 
57 
58 /*
59  * Actions
60  */
61 
62 if ($action == 'builddoc') {
63  $rap = new pdf_paiement($db);
64 
65  $outputlangs = $langs;
66  if (GETPOST('lang_id', 'aZ09')) {
67  $outputlangs = new Translate("", $conf);
68  $outputlangs->setDefaultLang(GETPOST('lang_id', 'aZ09'));
69  }
70 
71  // We save charset_output to restore it because write_file can change it if needed for
72  // output format that does not support UTF8.
73  $sav_charset_output = $outputlangs->charset_output;
74  if ($rap->write_file($dir, GETPOST("remonth", "int"), GETPOST("reyear", "int"), $outputlangs) > 0) {
75  $outputlangs->charset_output = $sav_charset_output;
76  } else {
77  $outputlangs->charset_output = $sav_charset_output;
78  dol_print_error($db, $obj->error);
79  }
80 
81  $year = GETPOST("reyear", "int");
82 }
83 
84 
85 /*
86  * View
87  */
88 
89 $formother = new FormOther($db);
90 $formfile = new FormFile($db);
91 
92 llxHeader();
93 
94 $titre = ($year ? $langs->trans("PaymentsReportsForYear", $year) : $langs->trans("PaymentsReports"));
95 print load_fiche_titre($titre, '', 'bill');
96 
97 // Formulaire de generation
98 print '<form method="post" action="rapport.php?year='.$year.'">';
99 print '<input type="hidden" name="token" value="'.newToken().'">';
100 print '<input type="hidden" name="action" value="builddoc">';
101 $cmonth = GETPOST("remonth") ?GETPOST("remonth") : date("n", time());
102 $syear = GETPOST("reyear") ?GETPOST("reyear") : date("Y", time());
103 
104 print $formother->select_month($cmonth, 'remonth');
105 
106 print $formother->selectyear($syear, 'reyear');
107 
108 print '<input type="submit" class="button" value="'.$langs->trans("Create").'">';
109 print '</form>';
110 print '<br>';
111 
112 clearstatcache();
113 
114 // Show link on other years
115 $year_dirs = dol_dir_list($dir, 'directories', 0, '^[0-9]{4}$', '', 'DESC');
116 foreach ($year_dirs as $d) {
117  print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$d['name'].'">'.$d['name'].'</a> &nbsp;';
118 }
119 
120 if ($year) {
121  if (is_dir($dir.'/'.$year)) {
122  if (!empty($year_dirs)) print '<br>';
123  print '<br>';
124  print '<table width="100%" class="noborder">';
125  print '<tr class="liste_titre">';
126  print '<td>'.$langs->trans("Reporting").'</td>';
127  print '<td class="right">'.$langs->trans("Size").'</td>';
128  print '<td class="right">'.$langs->trans("Date").'</td>';
129  print '</tr>';
130 
131  $files = (dol_dir_list($dir.'/'.$year, 'files', 0, '^payments-[0-9]{4}-[0-9]{2}\.pdf$', '', 'name', 'DESC', 1));
132  foreach ($files as $f) {
133  $relativepath = $f['level1name'].'/'.$f['name'];
134  print '<tr class="oddeven">';
135  print '<td><a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart=facture_paiement&amp;file='.urlencode($relativepath).'">'.img_pdf().' '.$f['name'].'</a>'.$formfile->showPreview($f['name'], 'facture_paiement', $relativepath, 0).'</td>';
136  print '<td class="right">'.dol_print_size($f['size']).'</td>';
137  print '<td class="right">'.dol_print_date($f['date'], "dayhour").'</td>';
138  print '</tr>';
139  }
140  print '</table>';
141  }
142 }
143 
144 // End of page
145 llxFooter();
146 $db->close();
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to offer components to list and upload files.
Classe permettant la generation de composants html autre Only common components are here.
Class to manage translations.
Class to manage reporting of payments.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:62
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_pdf($titlealt='default', $size=3)
Show pdf logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.