dolibarr 21.0.0-alpha
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/modules/rapport/pdf_paiement.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
35
36$action = GETPOST('action', 'aZ09');
37
38$socid = 0;
39if ($user->socid > 0) {
40 $action = '';
41 $socid = $user->socid;
42}
43
44$dir = $conf->facture->dir_output.'/payments';
45if (!$user->hasRight('societe', 'client', 'voir')) {
46 $dir .= '/private/'.$user->id; // If user has no permission to see all, output dir is specific to user
47}
48
49$year = GETPOSTINT('year');
50if (!$year) {
51 $year = date("Y");
52}
53
54// Security check
55if (!$user->hasRight('facture', 'lire')) {
57}
58
59$permissiontoread = $user->hasRight('facture', 'lire');
60
61
62/*
63 * Actions
64 */
65
66if ($action == 'builddoc' && $permissiontoread) {
67 $rap = new pdf_paiement($db);
68
69 $outputlangs = $langs;
70 if (GETPOST('lang_id', 'aZ09')) {
71 $outputlangs = new Translate("", $conf);
72 $outputlangs->setDefaultLang(GETPOST('lang_id', 'aZ09'));
73 }
74
75 // We save charset_output to restore it because write_file can change it if needed for
76 // output format that does not support UTF8.
77 $sav_charset_output = $outputlangs->charset_output;
78 if ($rap->write_file($dir, GETPOSTINT("remonth"), GETPOSTINT("reyear"), $outputlangs) > 0) {
79 $outputlangs->charset_output = $sav_charset_output;
80 } else {
81 $outputlangs->charset_output = $sav_charset_output;
82 dol_print_error($db, $rap->error);
83 }
84
85 $year = GETPOSTINT("reyear");
86}
87
88
89/*
90 * View
91 */
92
93$formother = new FormOther($db);
94$formfile = new FormFile($db);
95
96llxHeader();
97
98$titre = ($year ? $langs->trans("PaymentsReportsForYear", $year) : $langs->trans("PaymentsReports"));
99print load_fiche_titre($titre, '', 'bill');
100
101// Formulaire de generation
102print '<form method="post" action="rapport.php?year='.$year.'">';
103print '<input type="hidden" name="token" value="'.newToken().'">';
104print '<input type="hidden" name="action" value="builddoc">';
105$cmonth = GETPOST("remonth") ? GETPOST("remonth") : date("n", time());
106$syear = GETPOST("reyear") ? GETPOST("reyear") : date("Y", time());
107
108print $formother->select_month($cmonth, 'remonth');
109
110print $formother->selectyear($syear, 'reyear');
111
112print '<input type="submit" class="button" value="'.$langs->trans("Create").'">';
113print '</form>';
114print '<br>';
115
116clearstatcache();
117
118// Show link on other years
119$year_dirs = dol_dir_list($dir, 'directories', 0, '^[0-9]{4}$', '', 'DESC');
120foreach ($year_dirs as $d) {
121 print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$d['name'].'">'.$d['name'].'</a> &nbsp;';
122}
123
124if ($year) {
125 if (is_dir($dir.'/'.$year)) {
126 if (!empty($year_dirs)) {
127 print '<br>';
128 }
129 print '<br>';
130 print '<table width="100%" class="noborder">';
131 print '<tr class="liste_titre">';
132 print '<td>'.$langs->trans("Reporting").'</td>';
133 print '<td class="right">'.$langs->trans("Size").'</td>';
134 print '<td class="right">'.$langs->trans("Date").'</td>';
135 print '</tr>';
136
137 $files = (dol_dir_list($dir.'/'.$year, 'files', 0, '^payments-[0-9]{4}-[0-9]{2}\.pdf$', '', 'name', SORT_DESC, 1));
138 foreach ($files as $f) {
139 $relativepath = $f['level1name'].'/'.$f['name'];
140 print '<tr class="oddeven">';
141 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>';
142 print '<td class="right">'.dol_print_size($f['size']).'</td>';
143 print '<td class="right">'.dol_print_date($f['date'], "dayhour").'</td>';
144 print '</tr>';
145 }
146 print '</table>';
147 }
148}
149
150// End of page
151llxFooter();
152$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
Class to offer components to list and upload files.
Class permettant la generation de composants html autre Only common components are here.
Class to manage translations.
Class to manage reporting of payments.
llxFooter()
Footer empty.
Definition document.php:107
dol_dir_list($utf8_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:63
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.