dolibarr 21.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@inodbox.com>
5 * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
32require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
33
42// Load translation files required by the page
43$langs->loadLangs(array('banks', 'categories', 'withdrawals', 'companies'));
44
45$type = GETPOST('type', 'aZ09');
46
47// Security check
48$socid = GETPOSTINT('socid');
49if ($user->socid) {
50 $socid = $user->socid;
51}
52if ($type == 'bank-transfer') {
53 $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
54} else {
55 $result = restrictedArea($user, 'prelevement', '', '', 'bons');
56}
57
58
59/*
60 * View
61 */
62
63$title = $langs->trans("WithdrawStatistics");
64if ($type == 'bank-transfer') {
65 $title = $langs->trans("CreditTransferStatistics");
66}
67
68llxHeader('', $title);
69
70print load_fiche_titre($title);
71
72// Define total and nbtotal
73$sql = "SELECT sum(pl.amount), count(pl.amount)";
74$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
75$sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
76$sql .= " WHERE pl.fk_prelevement_bons = pb.rowid";
77if ($type == 'bank-transfer') {
78 $sql .= " AND pb.type = 'bank-transfer'";
79} else {
80 $sql .= " AND pb.type = 'debit-order'";
81}
82$sql .= " AND pb.entity = ".$conf->entity;
83$total = 0;
84$nbtotal = 0;
85$resql = $db->query($sql);
86if ($resql) {
87 $num = $db->num_rows($resql);
88 $i = 0;
89
90 if ($num > 0) {
91 $row = $db->fetch_row($resql);
92 $total = $row[0];
93 $nbtotal = $row[1];
94 }
95}
96
97
98/*
99 * Stats
100 */
101
102print '<br>';
103print load_fiche_titre($langs->trans("ByStatus"), '', '');
104
105$ligne = new LignePrelevement($db);
106
107$sql = "SELECT sum(pl.amount), count(pl.amount), pl.statut";
108$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
109$sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
110$sql .= " WHERE pl.fk_prelevement_bons = pb.rowid";
111$sql .= " AND pb.entity = ".$conf->entity;
112if ($type == 'bank-transfer') {
113 $sql .= " AND pb.type = 'bank-transfer'";
114} else {
115 $sql .= " AND pb.type = 'debit-order'";
116}
117$sql .= " GROUP BY pl.statut";
118
119$resql = $db->query($sql);
120if ($resql) {
121 $num = $db->num_rows($resql);
122 $i = 0;
123
124 print"\n<!-- debut table -->\n";
125 print '<table class="noborder centpercent">';
126 print '<tr class="liste_titre">';
127 print '<td width="30%">'.$langs->trans("Status").'</td><td align="center">'.$langs->trans("Number").'</td><td class="right">%</td>';
128 print '<td class="right">'.$langs->trans("Amount").'</td><td class="right">%</td></tr>';
129
130 while ($i < $num) {
131 $row = $db->fetch_row($resql);
132
133 print '<tr class="oddeven">';
134
135 print '<td>';
136 print $ligne->LibStatut($row[2], 1);
137 //print $st[$row[2]];
138 print '</td>';
139
140 print '<td class="center nowraponall">';
141 print $row[1];
142 print '</td>';
143
144 print '<td class="right nowraponall">';
145 print price2num($row[1] / $nbtotal * 100, 2)." %";
146 print '</td>';
147
148 print '<td class="right amount nowraponall">';
149 print price($row[0]);
150 print '</td>';
151
152 print '<td class="right nowraponall">';
153 print price2num($row[0] / $total * 100, 2)." %";
154 print '</td>';
155
156 print '</tr>';
157
158 $i++;
159 }
160
161 print '<tr class="liste_total"><td class="right">'.$langs->trans("Total").'</td>';
162 print '<td class="center nowraponall">'.$nbtotal.'</td><td>&nbsp;</td><td class="right nowraponall">';
163 print price($total);
164 print '</td><td class="right">&nbsp;</td>';
165 print "</tr></table>";
166
167 $db->free($resql);
168} else {
169 dol_print_error($db);
170}
171
172
173/*
174 * Stats on errors
175 */
176
177print '<br>';
178print load_fiche_titre($langs->trans("Rejects"), '', '');
179
180
181// Define total and nbtotal
182$sql = "SELECT sum(pl.amount), count(pl.amount)";
183$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
184$sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
185$sql .= " WHERE pl.fk_prelevement_bons = pb.rowid";
186$sql .= " AND pb.entity = ".$conf->entity;
187$sql .= " AND pl.statut = 3";
188if ($type == 'bank-transfer') {
189 $sql .= " AND pb.type = 'bank-transfer'";
190} else {
191 $sql .= " AND pb.type = 'debit-order'";
192}
193$resql = $db->query($sql);
194if ($resql) {
195 $num = $db->num_rows($resql);
196 $i = 0;
197
198 if ($num > 0) {
199 $row = $db->fetch_row($resql);
200 $total = $row[0];
201 $nbtotal = $row[1];
202 }
203}
204
205/*
206 * Stats sur les rejets
207 */
208
209$sql = "SELECT sum(pl.amount), count(pl.amount) as cc, pr.motif";
210$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
211$sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
212$sql .= ", ".MAIN_DB_PREFIX."prelevement_rejet as pr";
213$sql .= " WHERE pl.fk_prelevement_bons = pb.rowid";
214$sql .= " AND pb.entity = ".$conf->entity;
215$sql .= " AND pl.statut = 3";
216$sql .= " AND pr.fk_prelevement_lignes = pl.rowid";
217if ($type == 'bank-transfer') {
218 $sql .= " AND pb.type = 'bank-transfer'";
219} else {
220 $sql .= " AND pb.type = 'debit-order'";
221}
222$sql .= " GROUP BY pr.motif";
223$sql .= " ORDER BY cc DESC";
224
225$resql = $db->query($sql);
226if ($resql) {
227 $num = $db->num_rows($resql);
228 $i = 0;
229
230 print"\n<!-- debut table -->\n";
231 print '<table class="noborder centpercent">';
232 print '<tr class="liste_titre">';
233 print '<td width="30%">'.$langs->trans("Status").'</td><td align="center">'.$langs->trans("Number").'</td>';
234 print '<td class="right">%</td><td class="right">'.$langs->trans("Amount").'</td><td class="right">%</td></tr>';
235
236 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php';
237 $Rejet = new RejetPrelevement($db, $user, $type);
238
239 while ($i < $num) {
240 $row = $db->fetch_row($resql);
241
242 print '<tr class="oddeven"><td>';
243 print $Rejet->motifs[$row[2]];
244 print '</td>';
245
246 print '<td class="center">'.$row[1];
247 print '</td>';
248
249 print '<td class="right">';
250 print price2num($row[1] / $nbtotal * 100, 2)." %";
251
252 print '</td><td class="right">';
253 print price($row[0]);
254
255 print '</td><td class="right">';
256 print price2num($row[0] / $total * 100, 2)." %";
257
258 print '</td></tr>';
259
260 $i++;
261 }
262
263 print '<tr class="liste_total"><td class="right">'.$langs->trans("Total").'</td><td align="center">'.$nbtotal.'</td>';
264 print '<td>&nbsp;</td><td class="right">';
265 print price($total);
266 print '</td><td class="right">&nbsp;</td>';
267 print "</tr></table>";
268 $db->free($resql);
269} else {
270 dol_print_error($db);
271}
272
273// End of page
274llxFooter();
275$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage withdrawals.
Class to manage standing orders rejects.
llxFooter()
Footer empty.
Definition document.php:107
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.