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