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