dolibarr  7.0.0-beta
stats.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
27 require('../../main.inc.php');
28 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
30 
31 $langs->load("banks");
32 $langs->load("categories");
33 $langs->load("withdrawals");
34 $langs->load("companies");
35 
36 // Security check
37 $socid = GETPOST('socid','int');
38 if ($user->societe_id) $socid=$user->societe_id;
39 $result = restrictedArea($user, 'prelevement','','','bons');
40 
41 
42 /*
43  * View
44  */
45 
46 llxHeader('',$langs->trans("WithdrawStatistics"));
47 
48 print load_fiche_titre($langs->trans("Statistics"));
49 
50 // Define total and nbtotal
51 $sql = "SELECT sum(pl.amount), count(pl.amount)";
52 $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
53 $sql.= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
54 $sql.= " WHERE pl.fk_prelevement_bons = pb.rowid";
55 $sql.= " AND pb.entity = ".$conf->entity;
56 $resql=$db->query($sql);
57 if ($resql)
58 {
59  $num = $db->num_rows($resql);
60  $i = 0;
61 
62  if ( $num > 0 )
63  {
64  $row = $db->fetch_row($resql);
65  $total = $row[0];
66  $nbtotal = $row[1];
67  }
68 }
69 
70 
71 /*
72  * Stats
73  */
74 
75 print '<br>';
76 print load_fiche_titre($langs->trans("WithdrawStatistics"), '', '');
77 
78 $ligne=new LignePrelevement($db,$user);
79 
80 $sql = "SELECT sum(pl.amount), count(pl.amount), pl.statut";
81 $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
82 $sql.= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
83 $sql.= " WHERE pl.fk_prelevement_bons = pb.rowid";
84 $sql.= " AND pb.entity = ".$conf->entity;
85 $sql.= " GROUP BY pl.statut";
86 
87 $resql=$db->query($sql);
88 if ($resql)
89 {
90  $num = $db->num_rows($resql);
91  $i = 0;
92 
93  print"\n<!-- debut table -->\n";
94  print '<table class="noborder" width="100%">';
95  print '<tr class="liste_titre">';
96  print '<td width="30%">'.$langs->trans("Status").'</td><td align="center">'.$langs->trans("Number").'</td><td align="right">%</td>';
97  print '<td align="right">'.$langs->trans("Amount").'</td><td align="right">%</td></tr>';
98 
99  while ($i < $num)
100  {
101  $row = $db->fetch_row($resql);
102 
103  print '<tr class="oddeven"><td>';
104 
105  print $ligne->LibStatut($row[2],1);
106  //print $st[$row[2]];
107  print '</td><td align="center">';
108  print $row[1];
109 
110  print '</td><td align="right">';
111  print round($row[1]/$nbtotal*100,2)." %";
112 
113  print '</td><td align="right">';
114 
115  print price($row[0]);
116 
117  print '</td><td align="right">';
118  print round($row[0]/$total*100,2)." %";
119  print '</td></tr>';
120 
121  $i++;
122  }
123 
124  print '<tr class="liste_total"><td align="right">'.$langs->trans("Total").'</td>';
125  print '<td align="center">'.$nbtotal.'</td><td>&nbsp;</td><td align="right">';
126  print price($total);
127  print '</td><td align="right">&nbsp;</td>';
128  print "</tr></table>";
129  $db->free();
130 }
131 else
132 {
133  dol_print_error($db);
134 }
135 
136 
137 /*
138  * Stats on errors
139  */
140 
141 print '<br>';
142 print load_fiche_titre($langs->trans("WithdrawRejectStatistics"), '', '');
143 
144 
145 // Define total and nbtotal
146 $sql = "SELECT sum(pl.amount), count(pl.amount)";
147 $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
148 $sql.= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
149 $sql.= " WHERE pl.fk_prelevement_bons = pb.rowid";
150 $sql.= " AND pb.entity = ".$conf->entity;
151 $sql.= " AND pl.statut = 3";
152 $resql=$db->query($sql);
153 if ($resql)
154 {
155  $num = $db->num_rows($resql);
156  $i = 0;
157 
158  if ( $num > 0 )
159  {
160  $row = $db->fetch_row($resql);
161  $total = $row[0];
162  $nbtotal = $row[1];
163  }
164 }
165 
166 /*
167  * Stats sur les rejets
168  */
169 $sql = "SELECT sum(pl.amount), count(pl.amount) as cc, pr.motif";
170 $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
171 $sql.= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
172 $sql.= ", ".MAIN_DB_PREFIX."prelevement_rejet as pr";
173 $sql.= " WHERE pl.fk_prelevement_bons = pb.rowid";
174 $sql.= " AND pb.entity = ".$conf->entity;
175 $sql.= " AND pl.statut = 3";
176 $sql.= " AND pr.fk_prelevement_lignes = pl.rowid";
177 $sql.= " GROUP BY pr.motif";
178 $sql.= " ORDER BY cc DESC";
179 
180 $resql=$db->query($sql);
181 if ($resql)
182 {
183  $num = $db->num_rows($resql);
184  $i = 0;
185 
186  print"\n<!-- debut table -->\n";
187  print '<table class="noborder" width="100%">';
188  print '<tr class="liste_titre">';
189  print '<td width="30%">'.$langs->trans("Status").'</td><td align="center">'.$langs->trans("Number").'</td>';
190  print '<td align="right">%</td><td align="right">'.$langs->trans("Amount").'</td><td align="right">%</td></tr>';
191 
192  require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php';
193  $Rejet = new RejetPrelevement($db, $user);
194 
195  while ($i < $num)
196  {
197  $row = $db->fetch_row($resql);
198 
199  print '<tr class="oddeven"><td>';
200  print $Rejet->motifs[$row[2]];
201 
202  print '</td><td align="center">'.$row[1];
203 
204  print '</td><td align="right">';
205  print round($row[1]/$nbtotal*100,2)." %";
206 
207  print '</td><td align="right">';
208  print price($row[0]);
209 
210  print '</td><td align="right">';
211  print round($row[0]/$total*100,2)." %";
212 
213  print '</td></tr>';
214 
215  $i++;
216  }
217 
218  print '<tr class="liste_total"><td align="right">'.$langs->trans("Total").'</td><td align="center">'.$nbtotal.'</td>';
219  print '<td>&nbsp;</td><td align="right">';
220  print price($total);
221  print '</td><td align="right">&nbsp;</td>';
222  print "</tr></table>";
223  $db->free($resql);
224 }
225 else
226 {
227  dol_print_error($db);
228 }
229 
230 llxFooter();
231 
232 $db->close();
233 
llxFooter()
Empty footer.
Definition: wrapper.php:58
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.
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
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
print
Draft customers invoices.
Definition: index.php:91
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
Class to manage standing orders rejects.
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.
Class to manage withdrawals.