dolibarr  9.0.0
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@inodbox.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 // Load translation files required by the page
32 $langs->loadLangs(array('banks', 'categories', 'withdrawals', 'companies'));
33 
34 // Security check
35 $socid = GETPOST('socid','int');
36 if ($user->societe_id) $socid=$user->societe_id;
37 $result = restrictedArea($user, 'prelevement','','','bons');
38 
39 
40 /*
41  * View
42  */
43 
44 llxHeader('',$langs->trans("WithdrawStatistics"));
45 
46 print load_fiche_titre($langs->trans("Statistics"));
47 
48 // Define total and nbtotal
49 $sql = "SELECT sum(pl.amount), count(pl.amount)";
50 $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
51 $sql.= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
52 $sql.= " WHERE pl.fk_prelevement_bons = pb.rowid";
53 $sql.= " AND pb.entity = ".$conf->entity;
54 $resql=$db->query($sql);
55 if ($resql)
56 {
57  $num = $db->num_rows($resql);
58  $i = 0;
59 
60  if ( $num > 0 )
61  {
62  $row = $db->fetch_row($resql);
63  $total = $row[0];
64  $nbtotal = $row[1];
65  }
66 }
67 
68 
69 /*
70  * Stats
71  */
72 
73 print '<br>';
74 print load_fiche_titre($langs->trans("WithdrawStatistics"), '', '');
75 
76 $ligne=new LignePrelevement($db,$user);
77 
78 $sql = "SELECT sum(pl.amount), count(pl.amount), pl.statut";
79 $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
80 $sql.= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
81 $sql.= " WHERE pl.fk_prelevement_bons = pb.rowid";
82 $sql.= " AND pb.entity = ".$conf->entity;
83 $sql.= " GROUP BY pl.statut";
84 
85 $resql=$db->query($sql);
86 if ($resql)
87 {
88  $num = $db->num_rows($resql);
89  $i = 0;
90 
91  print"\n<!-- debut table -->\n";
92  print '<table class="noborder" width="100%">';
93  print '<tr class="liste_titre">';
94  print '<td width="30%">'.$langs->trans("Status").'</td><td align="center">'.$langs->trans("Number").'</td><td align="right">%</td>';
95  print '<td align="right">'.$langs->trans("Amount").'</td><td align="right">%</td></tr>';
96 
97  while ($i < $num)
98  {
99  $row = $db->fetch_row($resql);
100 
101  print '<tr class="oddeven"><td>';
102 
103  print $ligne->LibStatut($row[2],1);
104  //print $st[$row[2]];
105  print '</td><td align="center">';
106  print $row[1];
107 
108  print '</td><td align="right">';
109  print round($row[1]/$nbtotal*100,2)." %";
110 
111  print '</td><td align="right">';
112 
113  print price($row[0]);
114 
115  print '</td><td align="right">';
116  print round($row[0]/$total*100,2)." %";
117  print '</td></tr>';
118 
119  $i++;
120  }
121 
122  print '<tr class="liste_total"><td align="right">'.$langs->trans("Total").'</td>';
123  print '<td align="center">'.$nbtotal.'</td><td>&nbsp;</td><td align="right">';
124  print price($total);
125  print '</td><td align="right">&nbsp;</td>';
126  print "</tr></table>";
127  $db->free();
128 }
129 else
130 {
131  dol_print_error($db);
132 }
133 
134 
135 /*
136  * Stats on errors
137  */
138 
139 print '<br>';
140 print load_fiche_titre($langs->trans("WithdrawRejectStatistics"), '', '');
141 
142 
143 // Define total and nbtotal
144 $sql = "SELECT sum(pl.amount), count(pl.amount)";
145 $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
146 $sql.= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
147 $sql.= " WHERE pl.fk_prelevement_bons = pb.rowid";
148 $sql.= " AND pb.entity = ".$conf->entity;
149 $sql.= " AND pl.statut = 3";
150 $resql=$db->query($sql);
151 if ($resql)
152 {
153  $num = $db->num_rows($resql);
154  $i = 0;
155 
156  if ( $num > 0 )
157  {
158  $row = $db->fetch_row($resql);
159  $total = $row[0];
160  $nbtotal = $row[1];
161  }
162 }
163 
164 /*
165  * Stats sur les rejets
166  */
167 $sql = "SELECT sum(pl.amount), count(pl.amount) as cc, pr.motif";
168 $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
169 $sql.= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
170 $sql.= ", ".MAIN_DB_PREFIX."prelevement_rejet as pr";
171 $sql.= " WHERE pl.fk_prelevement_bons = pb.rowid";
172 $sql.= " AND pb.entity = ".$conf->entity;
173 $sql.= " AND pl.statut = 3";
174 $sql.= " AND pr.fk_prelevement_lignes = pl.rowid";
175 $sql.= " GROUP BY pr.motif";
176 $sql.= " ORDER BY cc DESC";
177 
178 $resql=$db->query($sql);
179 if ($resql)
180 {
181  $num = $db->num_rows($resql);
182  $i = 0;
183 
184  print"\n<!-- debut table -->\n";
185  print '<table class="noborder" width="100%">';
186  print '<tr class="liste_titre">';
187  print '<td width="30%">'.$langs->trans("Status").'</td><td align="center">'.$langs->trans("Number").'</td>';
188  print '<td align="right">%</td><td align="right">'.$langs->trans("Amount").'</td><td align="right">%</td></tr>';
189 
190  require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php';
191  $Rejet = new RejetPrelevement($db, $user);
192 
193  while ($i < $num)
194  {
195  $row = $db->fetch_row($resql);
196 
197  print '<tr class="oddeven"><td>';
198  print $Rejet->motifs[$row[2]];
199 
200  print '</td><td align="center">'.$row[1];
201 
202  print '</td><td align="right">';
203  print round($row[1]/$nbtotal*100,2)." %";
204 
205  print '</td><td align="right">';
206  print price($row[0]);
207 
208  print '</td><td align="right">';
209  print round($row[0]/$total*100,2)." %";
210 
211  print '</td></tr>';
212 
213  $i++;
214  }
215 
216  print '<tr class="liste_total"><td align="right">'.$langs->trans("Total").'</td><td align="center">'.$nbtotal.'</td>';
217  print '<td>&nbsp;</td><td align="right">';
218  print price($total);
219  print '</td><td align="right">&nbsp;</td>';
220  print "</tr></table>";
221  $db->free($resql);
222 }
223 else
224 {
225  dol_print_error($db);
226 }
227 
228 // End of page
229 llxFooter();
230 $db->close();
231 
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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:1053
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
llxHeader()
Empty header.
Definition: wrapper.php:44
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...
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 standing orders rejects.
Class to manage withdrawals.