dolibarr 21.0.0-beta
rapport.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 ATM-Consulting <support@atm-consulting.fr>
3 * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.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 <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/modules/rapport/pdf_paiement_fourn.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
32
41$langs->loadLangs(array('bills'));
42
43// Security check
44$socid = '';
45if (!empty($user->socid)) {
46 $socid = $user->socid;
47}
48$result = restrictedArea($user, 'fournisseur', 0, 'facture_fourn', 'facture');
49
50$action = GETPOST('action', 'aZ09');
51$fileToRemove = GETPOST('removefile', 'alpha');
52
53$socid = 0;
54if ($user->socid > 0) {
55 $action = '';
56 $socid = $user->socid;
57}
58
59$dir = $conf->fournisseur->facture->dir_output.'/payments';
60if (!$user->hasRight("societe", "client", "voir") || $socid) {
61 $dir .= '/private/'.$user->id; // If user has no permission to see all, output dir is specific to user
62}
63
64$year = GETPOSTINT("year");
65if (!$year) {
66 $year = date("Y");
67}
68
69$permissiontoread = ($user->hasRight("fournisseur", "facture", "lire") || $user->hasRight("supplier_invoice", "lire"));
70$permissiontoadd = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"));
71
72
73/*
74 * Actions
75 */
76
77if ($action == 'builddoc' && $permissiontoread) {
78 $rap = new pdf_paiement_fourn($db);
79
80 $outputlangs = $langs;
81 if (GETPOST('lang_id', 'aZ09')) {
82 $outputlangs = new Translate("", $conf);
83 $outputlangs->setDefaultLang(GETPOST('lang_id', 'aZ09'));
84 }
85
86 // We save charset_output to restore it because write_file can change it if needed for
87 // output format that does not support UTF8.
88 $sav_charset_output = $outputlangs->charset_output;
89 if ($rap->write_file($dir, GETPOSTINT("remonth"), GETPOSTINT("reyear"), $outputlangs) > 0) {
90 $outputlangs->charset_output = $sav_charset_output;
91 } else {
92 $outputlangs->charset_output = $sav_charset_output;
93 dol_print_error($db, $obj->error);
94 }
95
96 $year = GETPOSTINT("reyear");
97}
98
99// Delete file from disk
100if ($action == 'removedoc' && $permissiontoread && $fileToRemove) {
101 $fileDirectory = dirname($dir.'/'.$fileToRemove);
102 if (dol_delete_file($dir.'/'.$fileToRemove)) {
103 // Delete empty directory after file deletion
104 if (empty(dol_dir_list($fileDirectory))) {
105 dol_delete_dir($fileDirectory);
106 }
107 setEventMessages($langs->trans("FileWasRemoved", $fileToRemove), null, 'mesgs');
108 } else {
109 setEventMessages($langs->trans("ErrorFailToDeleteFile", $fileToRemove), null, 'errors');
110 }
111}
112
113
114/*
115 * View
116 */
117
118$formother = new FormOther($db);
119$formfile = new FormFile($db);
120
121$titre = ($year ? $langs->trans("PaymentsReportsForYear", $year) : $langs->trans("PaymentsReports"));
122
123llxHeader('', $titre, '', '', 0, 0, '', '', '', 'mod-fourn-facture page-rapport');
124
125print load_fiche_titre($titre, '', 'supplier_invoice');
126
127// Formulaire de generation
128print '<form method="post" action="rapport.php?year='.$year.'">';
129print '<input type="hidden" name="token" value="'.newToken().'">';
130print '<input type="hidden" name="action" value="builddoc">';
131$cmonth = GETPOST("remonth") ? GETPOST("remonth") : date("n", time());
132$syear = GETPOST("reyear") ? GETPOST("reyear") : date("Y", time());
133
134print $formother->select_month($cmonth, 'remonth');
135
136print $formother->selectyear($syear, 'reyear');
137
138print '<input type="submit" class="button" value="'.$langs->trans("Create").'">';
139print '</form>';
140print '<br>';
141
142clearstatcache();
143
144// Show link on other years
145$linkforyear = array();
146$found = 0;
147if (is_dir($dir)) {
148 $handle = opendir($dir);
149 if (is_resource($handle)) {
150 while (($file = readdir($handle)) !== false) {
151 if (is_dir($dir.'/'.$file) && !preg_match('/^\./', $file) && is_numeric($file)) {
152 $found = 1;
153 $linkforyear[] = $file;
154 }
155 }
156 }
157}
158asort($linkforyear);
159foreach ($linkforyear as $cursoryear) {
160 print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$cursoryear.'">'.$cursoryear.'</a> &nbsp;';
161}
162
163if ($year) {
164 if (is_dir($dir.'/'.$year)) {
165 $handle = opendir($dir.'/'.$year);
166
167 if ($found) {
168 print '<br>';
169 }
170 print '<br>';
171 print '<table width="100%" class="noborder">';
172 print '<tr class="liste_titre">';
173 print '<td>'.$langs->trans("Reporting").'</td>';
174 print '<td class="right">'.$langs->trans("Size").'</td>';
175 print '<td class="right">'.$langs->trans("Date").'</td>';
176 print '<td class="right"></td>';
177 print '</tr>';
178
179 if (is_resource($handle)) {
180 while (($file = readdir($handle)) !== false) {
181 if (preg_match('/^supplier_payment/i', $file)) {
182 $tfile = $dir.'/'.$year.'/'.$file;
183 $relativepath = $year.'/'.$file;
184 print '<tr class="oddeven"><td><a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart=facture_fournisseur&amp;file=payments/'.urlencode($relativepath).'">'.img_pdf().' '.$file.'</a>'.$formfile->showPreview($file, 'facture_fournisseur', 'payments/'.$relativepath, 0).'</td>';
185 print '<td class="right">'.dol_print_size(dol_filesize($tfile)).'</td>';
186 print '<td class="right">'.dol_print_date(dol_filemtime($tfile), "dayhour").'</td>';
187 print '<td class="right"><a href="rapport.php?removefile='.urlencode($relativepath).'&action=removedoc&token='.newToken().'">'.img_delete().'</a></td>';
188 print '</tr>';
189 }
190 }
191 closedir($handle);
192 }
193
194 print '</table>';
195 }
196}
197
198// End of page
199llxFooter();
200$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:71
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 permettant de generer les rapports de paiement.
llxFooter()
Footer empty.
Definition document.php:107
dol_filemtime($pathoffile)
Return time of a file.
dol_filesize($pathoffile)
Return size of a file.
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:63
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.