dolibarr  19.0.0-dev
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
28 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
30 require_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 = GETPOST('socid', 'int');
39 if ($user->socid) {
40  $socid = $user->socid;
41 }
42 if ($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");
54 if ($type == 'bank-transfer') {
55  $title = $langs->trans("CreditTransferStatistics");
56 }
57 
58 llxHeader('', $title);
59 
60 print 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";
67 if ($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);
74 if ($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 
90 print '<br>';
91 print 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;
100 if ($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);
108 if ($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 align="center nowraponall">';
129  print $row[1];
130  print '</td>';
131 
132  print '<td class="right nowraponall">';
133  print round($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 round($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 
165 print '<br>';
166 print 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";
176 if ($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);
182 if ($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";
205 if ($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);
214 if ($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 
233  print '</td><td align="center">'.$row[1];
234 
235  print '</td><td class="right">';
236  print round($row[1] / $nbtotal * 100, 2)." %";
237 
238  print '</td><td class="right">';
239  print price($row[0]);
240 
241  print '</td><td class="right">';
242  print round($row[0] / $total * 100, 2)." %";
243 
244  print '</td></tr>';
245 
246  $i++;
247  }
248 
249  print '<tr class="liste_total"><td class="right">'.$langs->trans("Total").'</td><td align="center">'.$nbtotal.'</td>';
250  print '<td>&nbsp;</td><td class="right">';
251  print price($total);
252  print '</td><td class="right">&nbsp;</td>';
253  print "</tr></table>";
254  $db->free($resql);
255 } else {
256  dol_print_error($db);
257 }
258 
259 // End of page
260 llxFooter();
261 $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:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage withdrawals.
Class to manage standing orders rejects.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
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.