dolibarr 24.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';
38require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
39require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
40require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
41
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$usercancreate = $user->hasRight('prelevement', 'bons', 'creer');
59
60
61/*
62 * View
63 */
64
65$title = $langs->trans("WithdrawalsReceipts");
66if ($type == 'bank-transfer') {
67 $title = $langs->trans("BankTransferReceipts");
68}
69
70llxHeader('', $title);
71
72$param = '&type='.urlencode($type);
73$mode = 'statistics';
74
75$newcardbutton = '';
76$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/compta/prelevement/orders_list.php?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss' => 'reposition'));
77$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', DOL_URL_ROOT.'/compta/prelevement/orders_list.php?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition'));
78$newcardbutton .= dolGetButtonTitle($langs->trans('Statistics'), '', 'fa fa-chart-bar imgforviewmode', DOL_URL_ROOT.'/compta/prelevement/stats.php?'.preg_replace('/(&|\?)*(mode|groupby)=[^&]+/', '', $param), '', ($mode == 'statistics' ? 2 : 1), array('morecss' => 'reposition'));
79if ($usercancreate) {
80 $newcardbutton .= dolGetButtonTitleSeparator();
81 $newcardbutton .= dolGetButtonTitle($langs->trans('NewStandingOrder'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php?type='.urlencode($type));
82}
83
84$massactionbutton = '';
85$limit = 0;
86
87print_barre_liste($title, 0, $_SERVER["PHP_SELF"], $param, '', '', $massactionbutton, 0, $langs->trans("Statistics"), 'generic', 0, $newcardbutton, '', $limit, 0, 0, 1);
88
89
90// Define total and nbtotal
91$sql = "SELECT sum(pb.amount) as amount, count(pb.amount) as nb";
92//$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
93$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as pb";
94$sql .= " WHERE pb.entity = ".$conf->entity;
95if ($type == 'bank-transfer') {
96 $sql .= " AND pb.type = 'bank-transfer'";
97} else {
98 $sql .= " AND pb.type = 'debit-order'";
99}
100
101$total = 0;
102$nbtotal = 0;
103$resql = $db->query($sql);
104if ($resql) {
105 $num = $db->num_rows($resql);
106 $i = 0;
107
108 if ($num > 0) {
109 $obj = $db->fetch_object($resql);
110 $total = $obj->amount;
111 $nbtotal = $obj->nb;
112 }
113}
114
115
116/*
117 * Stats
118 */
119
120print '<br>';
121print load_fiche_titre($langs->trans("ByStatus"), '', '');
122
123$bon = new BonPrelevement($db);
124$ligne = new LignePrelevement($db);
125
126$sql = "SELECT COUNT(pb.rowid) as nb, SUM(pb.amount) as amount, pb.statut as status";
127//$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
128$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as pb";
129//$sql .= " WHERE pl.fk_prelevement_bons = pb.rowid";
130$sql .= " WHERE pb.entity = ".$conf->entity;
131if ($type == 'bank-transfer') {
132 $sql .= " AND pb.type = 'bank-transfer'";
133} else {
134 $sql .= " AND pb.type = 'debit-order'";
135}
136$sql .= " GROUP BY pb.statut";
137
138$resql = $db->query($sql);
139if ($resql) {
140 $num = $db->num_rows($resql);
141 $i = 0;
142
143 print"\n<!-- debut table -->\n";
144 print '<table class="noborder centpercent">';
145 print '<tr class="liste_titre">';
146 print '<td width="30%">'.$langs->trans("Status").'</td><td align="center">'.$langs->trans("Number").'</td>';
147 //print '<td class="right">%</td>';
148 print '<td class="right">'.$langs->trans("Amount").'</td>';
149 //print '<td class="right">%</td>';
150 print '</tr>';
151
152 while ($i < $num) {
153 $obj = $db->fetch_object($resql);
154
155 print '<tr class="oddeven">';
156
157 print '<td>';
158 print $bon->LibStatut($obj->status, 1);
159 //print $st[$row[2]];
160 print '</td>';
161
162 print '<td class="center nowraponall">';
163 print $obj->nb;
164 print '</td>';
165
166 /*print '<td class="right nowraponall">';
167 print price2num($obj->amount / $nbtotal * 100, 2)." %";
168 print '</td>';*/
169
170 print '<td class="right amount nowraponall">';
171 print price($obj->amount);
172 print '</td>';
173
174 /*
175 print '<td class="right nowraponall">';
176 print price2num($row[0] / $total * 100, 2)." %";
177 print '</td>';
178 */
179
180 print '</tr>';
181
182 $i++;
183 }
184
185 print '<tr class="liste_total"><td class="right">'.$langs->trans("Total").'</td>';
186 print '<td class="center nowraponall">'.$nbtotal.'</td>';
187 //print '<td>&nbsp;</td>';
188 print '<td class="right nowraponall">';
189 print price($total);
190 print '</td>';
191 //print '<td class="right">&nbsp;</td>';
192 print "</tr></table>";
193
194 $db->free($resql);
195} else {
197}
198
199
200/*
201 * Stats on errors
202 */
203/*
204
205print '<br>';
206print load_fiche_titre($langs->trans("Rejects"), '', '');
207
208
209// Define total and nbtotal
210$sql = "SELECT sum(pl.amount), count(pl.amount)";
211$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
212$sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
213$sql .= " WHERE pl.fk_prelevement_bons = pb.rowid";
214$sql .= " AND pb.entity = ".$conf->entity;
215$sql .= " AND pl.statut = 3";
216if ($type == 'bank-transfer') {
217 $sql .= " AND pb.type = 'bank-transfer'";
218} else {
219 $sql .= " AND pb.type = 'debit-order'";
220}
221$resql = $db->query($sql);
222if ($resql) {
223 $num = $db->num_rows($resql);
224 $i = 0;
225
226 if ($num > 0) {
227 $row = $db->fetch_row($resql);
228 $total = $row[0];
229 $nbtotal = $row[1];
230 }
231}
232
233$sql = "SELECT sum(pl.amount), count(pl.amount) as cc, pr.motif";
234$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
235$sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
236$sql .= ", ".MAIN_DB_PREFIX."prelevement_rejet as pr";
237$sql .= " WHERE pl.fk_prelevement_bons = pb.rowid";
238$sql .= " AND pb.entity = ".$conf->entity;
239$sql .= " AND pl.statut = 3";
240$sql .= " AND pr.fk_prelevement_lignes = pl.rowid";
241if ($type == 'bank-transfer') {
242 $sql .= " AND pb.type = 'bank-transfer'";
243} else {
244 $sql .= " AND pb.type = 'debit-order'";
245}
246$sql .= " GROUP BY pr.motif";
247$sql .= " ORDER BY cc DESC";
248
249$resql = $db->query($sql);
250if ($resql) {
251 $num = $db->num_rows($resql);
252 $i = 0;
253
254 print"\n<!-- debut table -->\n";
255 print '<table class="noborder centpercent">';
256 print '<tr class="liste_titre">';
257 print '<td width="30%">'.$langs->trans("Status").'</td><td align="center">'.$langs->trans("Number").'</td>';
258 print '<td class="right">%</td><td class="right">'.$langs->trans("Amount").'</td><td class="right">%</td></tr>';
259
260 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php';
261 $Rejet = new RejetPrelevement($db, $user, $type);
262
263 while ($i < $num) {
264 $row = $db->fetch_row($resql);
265
266 print '<tr class="oddeven"><td>';
267 print $Rejet->motifs[$row[2]];
268 print '</td>';
269
270 print '<td class="center">'.$row[1];
271 print '</td>';
272
273 print '<td class="right">';
274 print price2num($row[1] / $nbtotal * 100, 2)." %";
275
276 print '</td><td class="right">';
277 print price($row[0]);
278
279 print '</td><td class="right">';
280 print price2num($row[0] / $total * 100, 2)." %";
281
282 print '</td></tr>';
283
284 $i++;
285 }
286
287 print '<tr class="liste_total"><td class="right">'.$langs->trans("Total").'</td><td align="center">'.$nbtotal.'</td>';
288 print '<td>&nbsp;</td><td class="right">';
289 print price($total);
290 print '</td><td class="right">&nbsp;</td>';
291 print "</tr></table>";
292 $db->free($resql);
293} else {
294 dol_print_error($db);
295}
296*/
297
298// End of page
299llxFooter();
300$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class to manage withdrawal receipts.
Class to manage withdrawals.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
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.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.