dolibarr  13.0.2
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 <https://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->socid) $socid = $user->socid;
37 $result = restrictedArea($user, 'prelevement', '', '', 'bons');
38 
39 $type = GETPOST('type', 'aZ09');
40 
41 
42 /*
43  * View
44  */
45 
46 $title = $langs->trans("WithdrawStatistics");
47 if ($type == 'bank-transfer') {
48  $title = $langs->trans("CreditTransferStatistics");
49 }
50 
51 llxHeader('', $title);
52 
53 print load_fiche_titre($title);
54 
55 // Define total and nbtotal
56 $sql = "SELECT sum(pl.amount), count(pl.amount)";
57 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
58 $sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
59 $sql .= " WHERE pl.fk_prelevement_bons = pb.rowid";
60 if ($type == 'bank-transfer') {
61  $sql .= " AND pb.type = 'bank-transfer'";
62 } else {
63  $sql .= " AND pb.type = 'debit-order'";
64 }
65 $sql .= " AND pb.entity = ".$conf->entity;
66 $resql = $db->query($sql);
67 if ($resql)
68 {
69  $num = $db->num_rows($resql);
70  $i = 0;
71 
72  if ($num > 0)
73  {
74  $row = $db->fetch_row($resql);
75  $total = $row[0];
76  $nbtotal = $row[1];
77  }
78 }
79 
80 
81 /*
82  * Stats
83  */
84 
85 print '<br>';
86 print load_fiche_titre($langs->trans("ByStatus"), '', '');
87 
88 $ligne = new LignePrelevement($db);
89 
90 $sql = "SELECT sum(pl.amount), count(pl.amount), pl.statut";
91 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
92 $sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
93 $sql .= " WHERE pl.fk_prelevement_bons = pb.rowid";
94 $sql .= " AND pb.entity = ".$conf->entity;
95 if ($type == 'bank-transfer') {
96  $sql .= " AND pb.type = 'bank-transfer'";
97 } else {
98  $sql .= " AND pb.type = 'debit-order'";
99 }
100 $sql .= " GROUP BY pl.statut";
101 
102 $resql = $db->query($sql);
103 if ($resql)
104 {
105  $num = $db->num_rows($resql);
106  $i = 0;
107 
108  print"\n<!-- debut table -->\n";
109  print '<table class="noborder centpercent">';
110  print '<tr class="liste_titre">';
111  print '<td width="30%">'.$langs->trans("Status").'</td><td align="center">'.$langs->trans("Number").'</td><td class="right">%</td>';
112  print '<td class="right">'.$langs->trans("Amount").'</td><td class="right">%</td></tr>';
113 
114  while ($i < $num)
115  {
116  $row = $db->fetch_row($resql);
117 
118  print '<tr class="oddeven"><td>';
119 
120  print $ligne->LibStatut($row[2], 1);
121  //print $st[$row[2]];
122  print '</td><td align="center">';
123  print $row[1];
124 
125  print '</td><td class="right">';
126  print round($row[1] / $nbtotal * 100, 2)." %";
127 
128  print '</td><td class="right">';
129 
130  print price($row[0]);
131 
132  print '</td><td class="right">';
133  print round($row[0] / $total * 100, 2)." %";
134  print '</td></tr>';
135 
136  $i++;
137  }
138 
139  print '<tr class="liste_total"><td class="right">'.$langs->trans("Total").'</td>';
140  print '<td class="center">'.$nbtotal.'</td><td>&nbsp;</td><td class="right">';
141  print price($total);
142  print '</td><td class="right">&nbsp;</td>';
143  print "</tr></table>";
144  $db->free();
145 } else {
146  dol_print_error($db);
147 }
148 
149 
150 /*
151  * Stats on errors
152  */
153 
154 print '<br>';
155 print load_fiche_titre($langs->trans("Rejects"), '', '');
156 
157 
158 // Define total and nbtotal
159 $sql = "SELECT sum(pl.amount), count(pl.amount)";
160 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
161 $sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
162 $sql .= " WHERE pl.fk_prelevement_bons = pb.rowid";
163 $sql .= " AND pb.entity = ".$conf->entity;
164 $sql .= " AND pl.statut = 3";
165 if ($type == 'bank-transfer') {
166  $sql .= " AND pb.type = 'bank-transfer'";
167 } else {
168  $sql .= " AND pb.type = 'debit-order'";
169 }
170 $resql = $db->query($sql);
171 if ($resql)
172 {
173  $num = $db->num_rows($resql);
174  $i = 0;
175 
176  if ($num > 0)
177  {
178  $row = $db->fetch_row($resql);
179  $total = $row[0];
180  $nbtotal = $row[1];
181  }
182 }
183 
184 /*
185  * Stats sur les rejets
186  */
187 
188 $sql = "SELECT sum(pl.amount), count(pl.amount) as cc, pr.motif";
189 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
190 $sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
191 $sql .= ", ".MAIN_DB_PREFIX."prelevement_rejet as pr";
192 $sql .= " WHERE pl.fk_prelevement_bons = pb.rowid";
193 $sql .= " AND pb.entity = ".$conf->entity;
194 $sql .= " AND pl.statut = 3";
195 $sql .= " AND pr.fk_prelevement_lignes = pl.rowid";
196 if ($type == 'bank-transfer') {
197  $sql .= " AND pb.type = 'bank-transfer'";
198 } else {
199  $sql .= " AND pb.type = 'debit-order'";
200 }
201 $sql .= " GROUP BY pr.motif";
202 $sql .= " ORDER BY cc DESC";
203 
204 $resql = $db->query($sql);
205 if ($resql)
206 {
207  $num = $db->num_rows($resql);
208  $i = 0;
209 
210  print"\n<!-- debut table -->\n";
211  print '<table class="noborder centpercent">';
212  print '<tr class="liste_titre">';
213  print '<td width="30%">'.$langs->trans("Status").'</td><td align="center">'.$langs->trans("Number").'</td>';
214  print '<td class="right">%</td><td class="right">'.$langs->trans("Amount").'</td><td class="right">%</td></tr>';
215 
216  require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php';
217  $Rejet = new RejetPrelevement($db, $user, $type);
218 
219  while ($i < $num)
220  {
221  $row = $db->fetch_row($resql);
222 
223  print '<tr class="oddeven"><td>';
224  print $Rejet->motifs[$row[2]];
225 
226  print '</td><td align="center">'.$row[1];
227 
228  print '</td><td class="right">';
229  print round($row[1] / $nbtotal * 100, 2)." %";
230 
231  print '</td><td class="right">';
232  print price($row[0]);
233 
234  print '</td><td class="right">';
235  print round($row[0] / $total * 100, 2)." %";
236 
237  print '</td></tr>';
238 
239  $i++;
240  }
241 
242  print '<tr class="liste_total"><td class="right">'.$langs->trans("Total").'</td><td align="center">'.$nbtotal.'</td>';
243  print '<td>&nbsp;</td><td class="right">';
244  print price($total);
245  print '</td><td class="right">&nbsp;</td>';
246  print "</tr></table>";
247  $db->free($resql);
248 } else {
249  dol_print_error($db);
250 }
251 
252 // End of page
253 llxFooter();
254 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
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.
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
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
Class to manage standing orders rejects.
Class to manage withdrawals.