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