dolibarr 21.0.0-alpha
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 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25// Load Dolibarr environment
26require '../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/core/modules/rapport/pdf_paiement_fourn.class.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
31
32$langs->loadLangs(array('bills'));
33
34// Security check
35$socid = '';
36if (!empty($user->socid)) {
37 $socid = $user->socid;
38}
39$result = restrictedArea($user, 'fournisseur', 0, 'facture_fourn', 'facture');
40
41$action = GETPOST('action', 'aZ09');
42
43$socid = 0;
44if ($user->socid > 0) {
45 $action = '';
46 $socid = $user->socid;
47}
48
49$dir = $conf->fournisseur->facture->dir_output.'/payments';
50if (!$user->hasRight("societe", "client", "voir") || $socid) {
51 $dir .= '/private/'.$user->id; // If user has no permission to see all, output dir is specific to user
52}
53
54$year = GETPOSTINT("year");
55if (!$year) {
56 $year = date("Y");
57}
58
59$permissiontoread = ($user->hasRight("fournisseur", "facture", "lire") || $user->hasRight("supplier_invoice", "lire"));
60$permissiontoadd = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"));
61
62
63/*
64 * Actions
65 */
66
67if ($action == 'builddoc' && $permissiontoread) {
68 $rap = new pdf_paiement_fourn($db);
69
70 $outputlangs = $langs;
71 if (GETPOST('lang_id', 'aZ09')) {
72 $outputlangs = new Translate("", $conf);
73 $outputlangs->setDefaultLang(GETPOST('lang_id', 'aZ09'));
74 }
75
76 // We save charset_output to restore it because write_file can change it if needed for
77 // output format that does not support UTF8.
78 $sav_charset_output = $outputlangs->charset_output;
79 if ($rap->write_file($dir, GETPOSTINT("remonth"), GETPOSTINT("reyear"), $outputlangs) > 0) {
80 $outputlangs->charset_output = $sav_charset_output;
81 } else {
82 $outputlangs->charset_output = $sav_charset_output;
83 dol_print_error($db, $obj->error);
84 }
85
86 $year = GETPOSTINT("reyear");
87}
88
89
90/*
91 * View
92 */
93
94$formother = new FormOther($db);
95$formfile = new FormFile($db);
96
97$titre = ($year ? $langs->trans("PaymentsReportsForYear", $year) : $langs->trans("PaymentsReports"));
98
99llxHeader('', $titre, '', '', 0, 0, '', '', '', 'mod-fourn-facture page-rapport');
100
101print load_fiche_titre($titre, '', 'supplier_invoice');
102
103// Formulaire de generation
104print '<form method="post" action="rapport.php?year='.$year.'">';
105print '<input type="hidden" name="token" value="'.newToken().'">';
106print '<input type="hidden" name="action" value="builddoc">';
107$cmonth = GETPOST("remonth") ? GETPOST("remonth") : date("n", time());
108$syear = GETPOST("reyear") ? GETPOST("reyear") : date("Y", time());
109
110print $formother->select_month($cmonth, 'remonth');
111
112print $formother->selectyear($syear, 'reyear');
113
114print '<input type="submit" class="button" value="'.$langs->trans("Create").'">';
115print '</form>';
116print '<br>';
117
118clearstatcache();
119
120// Show link on other years
121$linkforyear = array();
122$found = 0;
123if (is_dir($dir)) {
124 $handle = opendir($dir);
125 if (is_resource($handle)) {
126 while (($file = readdir($handle)) !== false) {
127 if (is_dir($dir.'/'.$file) && !preg_match('/^\./', $file) && is_numeric($file)) {
128 $found = 1;
129 $linkforyear[] = $file;
130 }
131 }
132 }
133}
134asort($linkforyear);
135foreach ($linkforyear as $cursoryear) {
136 print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$cursoryear.'">'.$cursoryear.'</a> &nbsp;';
137}
138
139if ($year) {
140 if (is_dir($dir.'/'.$year)) {
141 $handle = opendir($dir.'/'.$year);
142
143 if ($found) {
144 print '<br>';
145 }
146 print '<br>';
147 print '<table width="100%" class="noborder">';
148 print '<tr class="liste_titre">';
149 print '<td>'.$langs->trans("Reporting").'</td>';
150 print '<td class="right">'.$langs->trans("Size").'</td>';
151 print '<td class="right">'.$langs->trans("Date").'</td>';
152 print '</tr>';
153
154 if (is_resource($handle)) {
155 while (($file = readdir($handle)) !== false) {
156 if (preg_match('/^supplier_payment/i', $file)) {
157 $tfile = $dir.'/'.$year.'/'.$file;
158 $relativepath = $year.'/'.$file;
159 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>';
160 print '<td class="right">'.dol_print_size(dol_filesize($tfile)).'</td>';
161 print '<td class="right">'.dol_print_date(dol_filemtime($tfile), "dayhour").'</td></tr>';
162 }
163 }
164 closedir($handle);
165 }
166
167 print '</table>';
168 }
169}
170
171// End of page
172llxFooter();
173$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 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.
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...
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.