dolibarr 24.0.1
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 * Copyright (C) 2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
6 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../main.inc.php';
30
39require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/modules/rapport/pdf_paiement_fourn.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
44
45$langs->loadLangs(array('bills'));
46
47// Security check
48$socid = '';
49if (!empty($user->socid)) {
50 $socid = $user->socid;
51}
52$result = restrictedArea($user, 'fournisseur', 0, 'facture_fourn', 'facture');
53
55
56$action = GETPOST('action', 'aZ09');
57$fileToRemove = GETPOST('removefile', 'alpha');
58
59$socid = 0;
60if ($user->socid > 0) {
61 $action = '';
62 $socid = $user->socid;
63}
64
65$dir = getMultidirOutput($object).'/payments';
66if (!$user->hasRight("societe", "client", "voir") || $socid) {
67 $dir .= '/private/'.$user->id; // If user has no permission to see all, output dir is specific to user
68}
69
70$year = GETPOSTINT("year");
71if (!$year) {
72 $year = date("Y");
73}
74
75$permissiontoread = ($user->hasRight("fournisseur", "facture", "lire") || $user->hasRight("supplier_invoice", "lire"));
76$permissiontoadd = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"));
77
78
79/*
80 * Actions
81 */
82
83if ($action == 'builddoc' && $permissiontoread) {
84 $rap = new pdf_paiement_fourn($db);
85
86 $outputlangs = $langs;
87 if (GETPOST('lang_id', 'aZ09')) {
88 $outputlangs = new Translate("", $conf);
89 $outputlangs->setDefaultLang(GETPOST('lang_id', 'aZ09'));
90 }
91
92 // We save charset_output to restore it because write_file can change it if needed for
93 // output format that does not support UTF8.
94 $sav_charset_output = $outputlangs->charset_output;
95 if ($rap->write_file($dir, GETPOSTINT("remonth"), GETPOSTINT("reyear"), $outputlangs) > 0) {
96 $outputlangs->charset_output = $sav_charset_output;
97 } else {
98 $outputlangs->charset_output = $sav_charset_output;
99 dol_print_error($db, $rap->error);
100 }
101
102 $year = GETPOSTINT("reyear");
103}
104
105// Delete file from disk
106if ($action == 'removedoc' && $permissiontoread && $fileToRemove) {
107 $fileDirectory = dirname($dir.'/'.$fileToRemove);
108 if (dol_delete_file($dir.'/'.$fileToRemove)) {
109 // Delete empty directory after file deletion
110 if (empty(dol_dir_list($fileDirectory))) {
111 dol_delete_dir($fileDirectory);
112 }
113 setEventMessages($langs->trans("FileWasRemoved", $fileToRemove), null, 'mesgs');
114 } else {
115 setEventMessages($langs->trans("ErrorFailToDeleteFile", $fileToRemove), null, 'errors');
116 }
117}
118
119
120/*
121 * View
122 */
123
124$formother = new FormOther($db);
125$formfile = new FormFile($db);
126
127$titre = ($year ? $langs->trans("PaymentsReportsForYear", $year) : $langs->trans("PaymentsReports"));
128
129llxHeader('', $titre, '', '', 0, 0, '', '', '', 'mod-fourn-facture page-rapport');
130
131print load_fiche_titre($titre, '', 'supplier_invoice');
132
133// Generation form
134print '<form method="post" action="rapport.php?year='.$year.'">';
135print '<input type="hidden" name="token" value="'.newToken().'">';
136print '<input type="hidden" name="action" value="builddoc">';
137$cmonth = GETPOST("remonth") ? GETPOST("remonth") : date("n", time());
138$syear = GETPOST("reyear") ? GETPOST("reyear") : date("Y", time());
139
140print $formother->select_month($cmonth, 'remonth');
141
142print $formother->selectyear($syear, 'reyear');
143
144print '<input type="submit" class="button" value="'.$langs->trans("Create").'">';
145print '</form>';
146print '<br>';
147
148clearstatcache();
149
150// Show link on other years
151$linkforyear = array();
152$found = 0;
153if (is_dir($dir)) {
154 $handle = opendir($dir);
155 if (is_resource($handle)) {
156 while (($file = readdir($handle)) !== false) {
157 if (is_dir($dir.'/'.$file) && !preg_match('/^\./', $file) && is_numeric($file)) {
158 $found = 1;
159 $linkforyear[] = $file;
160 }
161 }
162 }
163}
164asort($linkforyear);
165foreach ($linkforyear as $cursoryear) {
166 print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$cursoryear.'">'.$cursoryear.'</a> &nbsp;';
167}
168
169if ($year) {
170 if (is_dir($dir.'/'.$year)) {
171 $handle = opendir($dir.'/'.$year);
172
173 if ($found) {
174 print '<br>';
175 }
176 print '<br>';
177 print '<table width="100%" class="noborder">';
178 print '<tr class="liste_titre">';
179 print '<td>'.$langs->trans("Reporting").'</td>';
180 print '<td class="right">'.$langs->trans("Size").'</td>';
181 print '<td class="right">'.$langs->trans("Date").'</td>';
182 print '<td class="right"></td>';
183 print '</tr>';
184
185 if (is_resource($handle)) {
186 while (($file = readdir($handle)) !== false) {
187 if (preg_match('/^supplier_payment/i', $file)) {
188 $tfile = $dir.'/'.$year.'/'.$file;
189 $relativepath = $year.'/'.$file;
190 print '<tr class="oddeven"><td><a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart=facture_fournisseur&amp;file=payments/'.urlencode($relativepath).'">'.img_picto('', 'pdf').' '.$file.'</a>'.$formfile->showPreview(['name' => $file,'fullname' => $tfile], 'facture_fournisseur', 'payments/'.$relativepath, 0).'</td>';
191 print '<td class="right">'.dol_print_size(dol_filesize($tfile)).'</td>';
192 print '<td class="right">'.dol_print_date(dol_filemtime($tfile), "dayhour").'</td>';
193 print '<td class="right"><a href="rapport.php?removefile='.urlencode($relativepath).'&action=removedoc&token='.newToken().'">'.img_delete().'</a></td>';
194 print '</tr>';
195 }
196 }
197 closedir($handle);
198 }
199
200 print '</table>';
201 }
202}
203
204// End of page
205llxFooter();
206$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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 manage suppliers invoices.
Class to offer components to list and upload files.
Class to help generate other html components Only common components are here.
Class to manage translations.
Class permettant de generer les rapports de paiement.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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: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.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
print $langs trans('Date')." left Ref 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 Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
Definition receipt.php:487
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.