dolibarr 20.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 <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
30require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
31
32// Load translation files required by the page
33$langs->loadLangs(array('banks', 'categories', 'withdrawals', 'companies'));
34
35$type = GETPOST('type', 'aZ09');
36
37// Security check
38$socid = GETPOSTINT('socid');
39if ($user->socid) {
40 $socid = $user->socid;
41}
42if ($type == 'bank-transfer') {
43 $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
44} else {
45 $result = restrictedArea($user, 'prelevement', '', '', 'bons');
46}
47
48
49/*
50 * View
51 */
52
53$title = $langs->trans("WithdrawStatistics");
54if ($type == 'bank-transfer') {
55 $title = $langs->trans("CreditTransferStatistics");
56}
57
58llxHeader('', $title);
59
60print load_fiche_titre($title);
61
62// Define total and nbtotal
63$sql = "SELECT sum(pl.amount), count(pl.amount)";
64$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
65$sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
66$sql .= " WHERE pl.fk_prelevement_bons = pb.rowid";
67if ($type == 'bank-transfer') {
68 $sql .= " AND pb.type = 'bank-transfer'";
69} else {
70 $sql .= " AND pb.type = 'debit-order'";
71}
72$sql .= " AND pb.entity = ".$conf->entity;
73$resql = $db->query($sql);
74if ($resql) {
75 $num = $db->num_rows($resql);
76 $i = 0;
77
78 if ($num > 0) {
79 $row = $db->fetch_row($resql);
80 $total = $row[0];
81 $nbtotal = $row[1];
82 }
83}
84
85
86/*
87 * Stats
88 */
89
90print '<br>';
91print load_fiche_titre($langs->trans("ByStatus"), '', '');
92
93$ligne = new LignePrelevement($db);
94
95$sql = "SELECT sum(pl.amount), count(pl.amount), pl.statut";
96$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
97$sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
98$sql .= " WHERE pl.fk_prelevement_bons = pb.rowid";
99$sql .= " AND pb.entity = ".$conf->entity;
100if ($type == 'bank-transfer') {
101 $sql .= " AND pb.type = 'bank-transfer'";
102} else {
103 $sql .= " AND pb.type = 'debit-order'";
104}
105$sql .= " GROUP BY pl.statut";
106
107$resql = $db->query($sql);
108if ($resql) {
109 $num = $db->num_rows($resql);
110 $i = 0;
111
112 print"\n<!-- debut table -->\n";
113 print '<table class="noborder centpercent">';
114 print '<tr class="liste_titre">';
115 print '<td width="30%">'.$langs->trans("Status").'</td><td align="center">'.$langs->trans("Number").'</td><td class="right">%</td>';
116 print '<td class="right">'.$langs->trans("Amount").'</td><td class="right">%</td></tr>';
117
118 while ($i < $num) {
119 $row = $db->fetch_row($resql);
120
121 print '<tr class="oddeven">';
122
123 print '<td>';
124 print $ligne->LibStatut($row[2], 1);
125 //print $st[$row[2]];
126 print '</td>';
127
128 print '<td class="center nowraponall">';
129 print $row[1];
130 print '</td>';
131
132 print '<td class="right nowraponall">';
133 print price2num($row[1] / $nbtotal * 100, 2)." %";
134 print '</td>';
135
136 print '<td class="right amount nowraponall">';
137 print price($row[0]);
138 print '</td>';
139
140 print '<td class="right nowraponall">';
141 print price2num($row[0] / $total * 100, 2)." %";
142 print '</td>';
143
144 print '</tr>';
145
146 $i++;
147 }
148
149 print '<tr class="liste_total"><td class="right">'.$langs->trans("Total").'</td>';
150 print '<td class="center nowraponall">'.$nbtotal.'</td><td>&nbsp;</td><td class="right nowraponall">';
151 print price($total);
152 print '</td><td class="right">&nbsp;</td>';
153 print "</tr></table>";
154
155 $db->free($resql);
156} else {
157 dol_print_error($db);
158}
159
160
161/*
162 * Stats on errors
163 */
164
165print '<br>';
166print load_fiche_titre($langs->trans("Rejects"), '', '');
167
168
169// Define total and nbtotal
170$sql = "SELECT sum(pl.amount), count(pl.amount)";
171$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
172$sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
173$sql .= " WHERE pl.fk_prelevement_bons = pb.rowid";
174$sql .= " AND pb.entity = ".$conf->entity;
175$sql .= " AND pl.statut = 3";
176if ($type == 'bank-transfer') {
177 $sql .= " AND pb.type = 'bank-transfer'";
178} else {
179 $sql .= " AND pb.type = 'debit-order'";
180}
181$resql = $db->query($sql);
182if ($resql) {
183 $num = $db->num_rows($resql);
184 $i = 0;
185
186 if ($num > 0) {
187 $row = $db->fetch_row($resql);
188 $total = $row[0];
189 $nbtotal = $row[1];
190 }
191}
192
193/*
194 * Stats sur les rejets
195 */
196
197$sql = "SELECT sum(pl.amount), count(pl.amount) as cc, pr.motif";
198$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
199$sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
200$sql .= ", ".MAIN_DB_PREFIX."prelevement_rejet as pr";
201$sql .= " WHERE pl.fk_prelevement_bons = pb.rowid";
202$sql .= " AND pb.entity = ".$conf->entity;
203$sql .= " AND pl.statut = 3";
204$sql .= " AND pr.fk_prelevement_lignes = pl.rowid";
205if ($type == 'bank-transfer') {
206 $sql .= " AND pb.type = 'bank-transfer'";
207} else {
208 $sql .= " AND pb.type = 'debit-order'";
209}
210$sql .= " GROUP BY pr.motif";
211$sql .= " ORDER BY cc DESC";
212
213$resql = $db->query($sql);
214if ($resql) {
215 $num = $db->num_rows($resql);
216 $i = 0;
217
218 print"\n<!-- debut table -->\n";
219 print '<table class="noborder centpercent">';
220 print '<tr class="liste_titre">';
221 print '<td width="30%">'.$langs->trans("Status").'</td><td align="center">'.$langs->trans("Number").'</td>';
222 print '<td class="right">%</td><td class="right">'.$langs->trans("Amount").'</td><td class="right">%</td></tr>';
223
224 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php';
225 $Rejet = new RejetPrelevement($db, $user, $type);
226
227 while ($i < $num) {
228 $row = $db->fetch_row($resql);
229
230 print '<tr class="oddeven"><td>';
231 print $Rejet->motifs[$row[2]];
232 print '</td>';
233
234 print '<td class="center">'.$row[1];
235 print '</td>';
236
237 print '<td class="right">';
238 print price2num($row[1] / $nbtotal * 100, 2)." %";
239
240 print '</td><td class="right">';
241 print price($row[0]);
242
243 print '</td><td class="right">';
244 print price2num($row[0] / $total * 100, 2)." %";
245
246 print '</td></tr>';
247
248 $i++;
249 }
250
251 print '<tr class="liste_total"><td class="right">'.$langs->trans("Total").'</td><td align="center">'.$nbtotal.'</td>';
252 print '<td>&nbsp;</td><td class="right">';
253 print price($total);
254 print '</td><td class="right">&nbsp;</td>';
255 print "</tr></table>";
256 $db->free($resql);
257} else {
258 dol_print_error($db);
259}
260
261// End of page
262llxFooter();
263$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage withdrawals.
Class to manage standing orders rejects.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.