dolibarr  17.0.4
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
26 require '../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/modules/rapport/pdf_paiement_fourn.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
31 
32 $langs->loadLangs(array('bills'));
33 
34 // Security check
35 $socid = '';
36 if (!empty($user->socid)) {
37  $socid = $user->socid;
38 }
39 $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
40 
41 $action = GETPOST('action', 'aZ09');
42 
43 $socid = 0;
44 if ($user->socid > 0) {
45  $action = '';
46  $socid = $user->socid;
47 }
48 
49 $dir = $conf->fournisseur->facture->dir_output.'/payments';
50 if (empty($user->rights->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 = GETPOST("year", 'int');
55 if (!$year) {
56  $year = date("Y");
57 }
58 
59 
60 /*
61  * Actions
62  */
63 
64 if ($action == 'builddoc') {
65  $rap = new pdf_paiement_fourn($db);
66 
67  $outputlangs = $langs;
68  if (GETPOST('lang_id', 'aZ09')) {
69  $outputlangs = new Translate("", $conf);
70  $outputlangs->setDefaultLang(GETPOST('lang_id', 'aZ09'));
71  }
72 
73  // We save charset_output to restore it because write_file can change it if needed for
74  // output format that does not support UTF8.
75  $sav_charset_output = $outputlangs->charset_output;
76  if ($rap->write_file($dir, GETPOST("remonth", 'int'), GETPOST("reyear", 'int'), $outputlangs) > 0) {
77  $outputlangs->charset_output = $sav_charset_output;
78  } else {
79  $outputlangs->charset_output = $sav_charset_output;
80  dol_print_error($db, $obj->error);
81  }
82 
83  $year = GETPOST("reyear", 'int');
84 }
85 
86 
87 /*
88  * View
89  */
90 
91 $formother = new FormOther($db);
92 $formfile = new FormFile($db);
93 
94 $titre = ($year ? $langs->trans("PaymentsReportsForYear", $year) : $langs->trans("PaymentsReports"));
95 
96 llxHeader('', $titre);
97 
98 print load_fiche_titre($titre, '', 'supplier_invoice');
99 
100 // Formulaire de generation
101 print '<form method="post" action="rapport.php?year='.$year.'">';
102 print '<input type="hidden" name="token" value="'.newToken().'">';
103 print '<input type="hidden" name="action" value="builddoc">';
104 $cmonth = GETPOST("remonth") ?GETPOST("remonth") : date("n", time());
105 $syear = GETPOST("reyear") ?GETPOST("reyear") : date("Y", time());
106 
107 print $formother->select_month($cmonth, 'remonth');
108 
109 print $formother->selectyear($syear, 'reyear');
110 
111 print '<input type="submit" class="button" value="'.$langs->trans("Create").'">';
112 print '</form>';
113 print '<br>';
114 
115 clearstatcache();
116 
117 // Show link on other years
118 $linkforyear = array();
119 $found = 0;
120 if (is_dir($dir)) {
121  $handle = opendir($dir);
122  if (is_resource($handle)) {
123  while (($file = readdir($handle)) !== false) {
124  if (is_dir($dir.'/'.$file) && !preg_match('/^\./', $file) && is_numeric($file)) {
125  $found = 1;
126  $linkforyear[] = $file;
127  }
128  }
129  }
130 }
131 asort($linkforyear);
132 foreach ($linkforyear as $cursoryear) {
133  print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$cursoryear.'">'.$cursoryear.'</a> &nbsp;';
134 }
135 
136 if ($year) {
137  if (is_dir($dir.'/'.$year)) {
138  $handle = opendir($dir.'/'.$year);
139 
140  if ($found) {
141  print '<br>';
142  }
143  print '<br>';
144  print '<table width="100%" class="noborder">';
145  print '<tr class="liste_titre">';
146  print '<td>'.$langs->trans("Reporting").'</td>';
147  print '<td class="right">'.$langs->trans("Size").'</td>';
148  print '<td class="right">'.$langs->trans("Date").'</td>';
149  print '</tr>';
150 
151  if (is_resource($handle)) {
152  while (($file = readdir($handle)) !== false) {
153  if (preg_match('/^supplier_payment/i', $file)) {
154  $tfile = $dir.'/'.$year.'/'.$file;
155  $relativepath = $year.'/'.$file;
156  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>';
157  print '<td class="right">'.dol_print_size(dol_filesize($tfile)).'</td>';
158  print '<td class="right">'.dol_print_date(dol_filemtime($tfile), "dayhour").'</td></tr>';
159  }
160  }
161  closedir($handle);
162  }
163 
164  print '</table>';
165  }
166 }
167 
168 // End of page
169 llxFooter();
170 $db->close();
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to offer components to list and upload files.
Classe permettant la generation de composants html autre Only common components are here.
Class to manage translations.
Classe permettant de generer les rapports de paiement.
dol_filemtime($pathoffile)
Return time of a file.
Definition: files.lib.php:597
dol_filesize($pathoffile)
Return size of a file.
Definition: files.lib.php:585
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
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.