dolibarr 23.0.3
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
44$action = GETPOST('action', 'aZ09');
45$fileToRemove = GETPOST('removefile', 'alpha');
46
47$socid = 0;
48if ($user->socid > 0) {
49 $action = '';
50 $socid = $user->socid;
51}
52
53$dir = $conf->facture->dir_output.'/payments';
54if (!$user->hasRight('societe', 'client', 'voir')) {
55 $dir .= '/private/'.$user->id; // If user has no permission to see all, output dir is specific to user
56}
57
58$year = GETPOSTINT('year');
59if (!$year) {
60 $year = date("Y");
61}
62
63// Security check
64if (!$user->hasRight('facture', 'lire')) {
66}
67
68$permissiontoread = ($user->hasRight('facture', 'lire') == 1);
69
70
71/*
72 * Actions
73 */
74
75if ($action == 'builddoc' && $permissiontoread) {
76 $rap = new pdf_paiement($db);
77
78 $outputlangs = $langs;
79 if (GETPOST('lang_id', 'aZ09')) {
80 $outputlangs = new Translate("", $conf);
81 $outputlangs->setDefaultLang(GETPOST('lang_id', 'aZ09'));
82 }
83
84 // We save charset_output to restore it because write_file can change it if needed for
85 // output format that does not support UTF8.
86 $sav_charset_output = $outputlangs->charset_output;
87 if ($rap->write_file($dir, GETPOSTINT("remonth"), GETPOSTINT("reyear"), $outputlangs) > 0) {
88 $outputlangs->charset_output = $sav_charset_output;
89 } else {
90 $outputlangs->charset_output = $sav_charset_output;
91 dol_print_error($db, $rap->error);
92 }
93
94 $year = GETPOSTINT("reyear");
95}
96
97// Delete file from disk
98if ($action == 'removedoc' && $permissiontoread && $fileToRemove) {
99 $fullpathfile = dol_sanitizePathName($dir.'/'.$fileToRemove);
100 $fileDirectory = dirname($fullpathfile);
101 if (dol_delete_file($fullpathfile)) {
102 // Delete empty directory after file deletion
103 if (empty(dol_dir_list($fileDirectory))) {
104 dol_delete_dir($fileDirectory);
105 }
106 setEventMessages($langs->trans("FileWasRemoved", $fileToRemove), null, 'mesgs');
107 } else {
108 setEventMessages($langs->trans("ErrorFailToDeleteFile", $fileToRemove), null, 'errors');
109 }
110}
111
112
113/*
114 * View
115 */
116
117$formother = new FormOther($db);
118$formfile = new FormFile($db);
119
120llxHeader();
121
122$titre = ($year ? $langs->trans("PaymentsReportsForYear", $year) : $langs->trans("PaymentsReports"));
123print load_fiche_titre($titre, '', 'bill');
124
125// Formulaire de generation
126print '<form method="post" action="rapport.php?year='.$year.'">';
127print '<input type="hidden" name="token" value="'.newToken().'">';
128print '<input type="hidden" name="action" value="builddoc">';
129$cmonth = GETPOST("remonth") ? GETPOST("remonth") : date("n", time());
130$syear = GETPOST("reyear") ? GETPOST("reyear") : date("Y", time());
131
132print $formother->select_month($cmonth, 'remonth');
133
134print $formother->selectyear($syear, 'reyear');
135
136print '<input type="submit" class="button" value="'.$langs->trans("Create").'">';
137print '</form>';
138print '<br>';
139
140clearstatcache();
141
142// Show link on other years
143$year_dirs = dol_dir_list($dir, 'directories', 0, '^[0-9]{4}$', '', 'DESC');
144foreach ($year_dirs as $d) {
145 print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$d['name'].'">'.$d['name'].'</a> &nbsp;';
146}
147
148if ($year) {
149 if (is_dir($dir.'/'.$year)) {
150 if (!empty($year_dirs)) {
151 print '<br>';
152 }
153 print '<br>';
154 print '<table width="100%" class="noborder">';
155 print '<tr class="liste_titre">';
156 print '<td>'.$langs->trans("Reporting").'</td>';
157 print '<td class="right">'.$langs->trans("Size").'</td>';
158 print '<td class="right">'.$langs->trans("Date").'</td>';
159 print '<td class="right"></td>';
160 print '</tr>';
161
162 $files = (dol_dir_list($dir.'/'.$year, 'files', 0, '^payments-[0-9]{4}-[0-9]{2}\.pdf$', '', 'name', SORT_DESC, 1));
163 foreach ($files as $f) {
164 $relativepath = $f['level1name'].'/'.$f['name'];
165 print '<tr class="oddeven">';
166 print '<td><a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart=facture_paiement&amp;file='.urlencode($relativepath).'">'.img_picto('', 'pdf').' '.$f['name'].'</a>'.$formfile->showPreview($f['name'], 'facture_paiement', $relativepath, 0).'</td>';
167 print '<td class="right">'.dol_print_size($f['size']).'</td>';
168 print '<td class="right">'.dol_print_date($f['date'], "dayhour").'</td>';
169 print '<td class="right"><a href="rapport.php?removefile='.urlencode($relativepath).'&action=removedoc&token='.newToken().'">'.img_delete().'</a></td>';
170 print '</tr>';
171 }
172 print '</table>';
173 }
174}
175
176// End of page
177llxFooter();
178$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
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.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_delete_dir($dir, $nophperrors=0)
Remove a directory (not recursive, so content must be empty).
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:64
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_sanitizePathName($str, $newstr='_', $unaccent=0, $allowdash=0)
Clean a string to use it as a path name.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
Definition receipt.php:464
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.