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