dolibarr  7.0.0-beta
rapport.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 ATM-Consulting <support@atm-consulting.fr>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
24 require '../../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.'/core/modules/rapport/pdf_paiement_fourn.class.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
28 
29 // Security check
30 $socid='';
31 if (! empty($user->societe_id)) $socid=$user->societe_id;
32 $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
33 
34 $action=GETPOST('action','aZ09');
35 
36 $socid=0;
37 if ($user->societe_id > 0)
38 {
39  $action = '';
40  $socid = $user->societe_id;
41 }
42 
43 $dir = $conf->fournisseur->facture->dir_output.'/payments';
44 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
45 
46 $year = $_GET["year"];
47 if (! $year) { $year=date("Y"); }
48 
49 
50 /*
51  * Actions
52  */
53 
54 if ($action == 'builddoc')
55 {
56  $rap = new pdf_paiement_fourn($db);
57 
58  $outputlangs = $langs;
59  if (GETPOST('lang_id','aZ09'))
60  {
61  $outputlangs = new Translate("",$conf);
62  $outputlangs->setDefaultLang(GETPOST('lang_id','aZ09'));
63  }
64 
65  // We save charset_output to restore it because write_file can change it if needed for
66  // output format that does not support UTF8.
67  $sav_charset_output=$outputlangs->charset_output;
68  if ($rap->write_file($dir, $_POST["remonth"], $_POST["reyear"], $outputlangs) > 0)
69  {
70  $outputlangs->charset_output=$sav_charset_output;
71  }
72  else
73  {
74  $outputlangs->charset_output=$sav_charset_output;
75  dol_print_error($db,$obj->error);
76  }
77 
78  $year = $_POST["reyear"];
79 }
80 
81 
82 /*
83  * View
84  */
85 
86 $formother=new FormOther($db);
87 
88 $titre=($year?$langs->trans("PaymentsReportsForYear",$year):$langs->trans("PaymentsReports"));
89 
90 llxHeader('', $titre);
91 
92 print load_fiche_titre($titre,'','title_accountancy.png');
93 
94 // Formulaire de generation
95 print '<form method="post" action="rapport.php?year='.$year.'">';
96 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
97 print '<input type="hidden" name="action" value="builddoc">';
98 $cmonth = GETPOST("remonth")?GETPOST("remonth"):date("n", time());
99 $syear = GETPOST("reyear")?GETPOST("reyear"):date("Y", time());
100 
101 print $formother->select_month($cmonth,'remonth');
102 
103 print $formother->select_year($syear,'reyear');
104 
105 print '<input type="submit" class="button" value="'.$langs->trans("Create").'">';
106 print '</form>';
107 print '<br>';
108 
109 clearstatcache();
110 
111 // Show link on other years
112 $linkforyear=array();
113 $found=0;
114 if (is_dir($dir))
115 {
116  $handle=opendir($dir);
117  if (is_resource($handle))
118  {
119  while (($file = readdir($handle))!==false)
120  {
121  if (is_dir($dir.'/'.$file) && ! preg_match('/^\./',$file) && is_numeric($file))
122  {
123  $found=1;
124  $linkforyear[]=$file;
125  }
126  }
127  }
128 }
129 asort($linkforyear);
130 foreach($linkforyear as $cursoryear)
131 {
132  print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$cursoryear.'">'.$cursoryear.'</a> &nbsp;';
133 }
134 
135 if ($year)
136 {
137  if (is_dir($dir.'/'.$year))
138  {
139  $handle=opendir($dir.'/'.$year);
140 
141  if ($found) print '<br>';
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 align="right">'.$langs->trans("Size").'</td>';
147  print '<td align="right">'.$langs->trans("Date").'</td>';
148  print '</tr>';
149  $var=true;
150  if (is_resource($handle))
151  {
152  while (($file = readdir($handle))!==false)
153  {
154  if (preg_match('/^supplier_payment/i',$file))
155  {
156 
157  $tfile = $dir . '/'.$year.'/'.$file;
158  $relativepath = $year.'/'.$file;
159  print "<tr ".$bc[$var].">".'<td><a data-ajax="false" href="'.DOL_URL_ROOT . '/document.php?modulepart=facture_fournisseur&amp;file=payments/'.urlencode($relativepath).'">'.img_pdf().' '.$file.'</a></td>';
160  print '<td align="right">'.dol_print_size(dol_filesize($tfile)).'</td>';
161  print '<td align="right">'.dol_print_date(dol_filemtime($tfile),"dayhour").'</td></tr>';
162  }
163  }
164  closedir($handle);
165  }
166  print '</table>';
167  }
168 }
169 
170 llxFooter();
171 
172 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
Classe permettant de generer les rapports de paiement.
dol_filesize($pathoffile)
Return size of a file.
Definition: files.lib.php:516
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_pdf($titlealt= 'default', $size=3)
Show pdf logo.
Classe permettant la generation de composants html autre Only common components are here...
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
Class to manage translations.
print
Draft customers invoices.
Definition: index.php:91
dol_filemtime($pathoffile)
Return time of a file.
Definition: files.lib.php:528
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.