2012-08-22 23:27:53 +02:00
|
|
|
<?php
|
2009-04-27 22:37:50 +02:00
|
|
|
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2012-08-05 14:37:45 +02:00
|
|
|
* Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
2018-10-27 14:43:12 +02:00
|
|
|
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
|
2011-01-05 10:57:55 +01:00
|
|
|
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
|
2005-01-19 15:49:54 +01:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2013-01-16 15:36:08 +01:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2005-01-19 15:49:54 +01:00
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2019-09-23 21:55:30 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2005-01-19 15:49:54 +01:00
|
|
|
*/
|
2005-08-13 18:44:52 +02:00
|
|
|
|
|
|
|
|
/**
|
2012-08-05 14:37:45 +02:00
|
|
|
* \file htdocs/compta/prelevement/stats.php
|
|
|
|
|
* \ingroup prelevement
|
2014-12-09 11:19:16 +01:00
|
|
|
* \brief Page with statistics on withdrawals
|
2010-08-09 18:07:24 +02:00
|
|
|
*/
|
2005-08-13 18:44:52 +02:00
|
|
|
|
2018-07-26 11:57:25 +02:00
|
|
|
require '../../main.inc.php';
|
2012-08-22 23:11:24 +02:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
|
2013-06-05 16:24:32 +02:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
|
|
|
|
|
|
2018-05-27 09:27:09 +02:00
|
|
|
// Load translation files required by the page
|
|
|
|
|
$langs->loadLangs(array('banks', 'categories', 'withdrawals', 'companies'));
|
2005-08-13 18:44:52 +02:00
|
|
|
|
2021-10-04 04:36:58 +02:00
|
|
|
$type = GETPOST('type', 'aZ09');
|
|
|
|
|
|
2009-04-27 22:37:50 +02:00
|
|
|
// Security check
|
2019-01-27 11:55:16 +01:00
|
|
|
$socid = GETPOST('socid', 'int');
|
2021-02-23 21:09:01 +01:00
|
|
|
if ($user->socid) {
|
|
|
|
|
$socid = $user->socid;
|
|
|
|
|
}
|
2021-10-04 04:36:58 +02:00
|
|
|
if ($type == 'bank-transfer') {
|
|
|
|
|
$result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
|
|
|
|
|
} else {
|
|
|
|
|
$result = restrictedArea($user, 'prelevement', '', '', 'bons');
|
|
|
|
|
}
|
2020-05-27 20:14:11 +02:00
|
|
|
|
2005-08-13 18:44:52 +02:00
|
|
|
|
2005-03-02 11:07:20 +01:00
|
|
|
/*
|
2009-08-17 19:46:59 +02:00
|
|
|
* View
|
2005-03-02 11:07:20 +01:00
|
|
|
*/
|
|
|
|
|
|
2020-06-08 11:43:20 +02:00
|
|
|
$title = $langs->trans("WithdrawStatistics");
|
|
|
|
|
if ($type == 'bank-transfer') {
|
|
|
|
|
$title = $langs->trans("CreditTransferStatistics");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
llxHeader('', $title);
|
2009-08-17 19:46:59 +02:00
|
|
|
|
2020-06-08 11:43:20 +02:00
|
|
|
print load_fiche_titre($title);
|
2005-01-19 15:49:54 +01:00
|
|
|
|
2010-09-05 03:20:53 +02:00
|
|
|
// Define total and nbtotal
|
2005-03-03 15:03:50 +01:00
|
|
|
$sql = "SELECT sum(pl.amount), count(pl.amount)";
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
|
|
|
|
|
$sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
|
|
|
|
|
$sql .= " WHERE pl.fk_prelevement_bons = pb.rowid";
|
2020-06-08 11:43:20 +02:00
|
|
|
if ($type == 'bank-transfer') {
|
|
|
|
|
$sql .= " AND pb.type = 'bank-transfer'";
|
|
|
|
|
} else {
|
|
|
|
|
$sql .= " AND pb.type = 'debit-order'";
|
|
|
|
|
}
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= " AND pb.entity = ".$conf->entity;
|
|
|
|
|
$resql = $db->query($sql);
|
2021-02-23 21:09:01 +01:00
|
|
|
if ($resql) {
|
2020-03-23 15:54:02 +01:00
|
|
|
$num = $db->num_rows($resql);
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
2021-02-23 21:09:01 +01:00
|
|
|
if ($num > 0) {
|
2020-03-23 15:54:02 +01:00
|
|
|
$row = $db->fetch_row($resql);
|
|
|
|
|
$total = $row[0];
|
|
|
|
|
$nbtotal = $row[1];
|
|
|
|
|
}
|
2005-01-19 15:49:54 +01:00
|
|
|
}
|
|
|
|
|
|
2010-09-05 03:20:53 +02:00
|
|
|
|
2005-01-19 15:49:54 +01:00
|
|
|
/*
|
|
|
|
|
* Stats
|
|
|
|
|
*/
|
2011-06-12 20:05:30 +02:00
|
|
|
|
|
|
|
|
print '<br>';
|
2020-06-08 11:43:20 +02:00
|
|
|
print load_fiche_titre($langs->trans("ByStatus"), '', '');
|
2011-06-12 20:05:30 +02:00
|
|
|
|
2020-05-07 12:14:45 +02:00
|
|
|
$ligne = new LignePrelevement($db);
|
2011-01-05 10:57:55 +01:00
|
|
|
|
2005-03-03 15:03:50 +01:00
|
|
|
$sql = "SELECT sum(pl.amount), count(pl.amount), pl.statut";
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
|
|
|
|
|
$sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
|
|
|
|
|
$sql .= " WHERE pl.fk_prelevement_bons = pb.rowid";
|
|
|
|
|
$sql .= " AND pb.entity = ".$conf->entity;
|
2020-06-08 11:43:20 +02:00
|
|
|
if ($type == 'bank-transfer') {
|
|
|
|
|
$sql .= " AND pb.type = 'bank-transfer'";
|
|
|
|
|
} else {
|
|
|
|
|
$sql .= " AND pb.type = 'debit-order'";
|
|
|
|
|
}
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= " GROUP BY pl.statut";
|
2005-01-19 15:49:54 +01:00
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
$resql = $db->query($sql);
|
2021-02-23 21:09:01 +01:00
|
|
|
if ($resql) {
|
2010-08-09 18:07:24 +02:00
|
|
|
$num = $db->num_rows($resql);
|
|
|
|
|
$i = 0;
|
2009-08-17 19:46:59 +02:00
|
|
|
|
2010-08-09 18:07:24 +02:00
|
|
|
print"\n<!-- debut table -->\n";
|
2019-11-05 21:24:41 +01:00
|
|
|
print '<table class="noborder centpercent">';
|
2010-08-09 18:07:24 +02:00
|
|
|
print '<tr class="liste_titre">';
|
2019-02-10 16:08:03 +01:00
|
|
|
print '<td width="30%">'.$langs->trans("Status").'</td><td align="center">'.$langs->trans("Number").'</td><td class="right">%</td>';
|
|
|
|
|
print '<td class="right">'.$langs->trans("Amount").'</td><td class="right">%</td></tr>';
|
2009-08-17 19:46:59 +02:00
|
|
|
|
2021-02-23 21:09:01 +01:00
|
|
|
while ($i < $num) {
|
2010-08-09 18:07:24 +02:00
|
|
|
$row = $db->fetch_row($resql);
|
2009-08-17 19:46:59 +02:00
|
|
|
|
2017-05-10 16:41:19 +02:00
|
|
|
print '<tr class="oddeven"><td>';
|
2005-03-03 15:03:50 +01:00
|
|
|
|
2019-01-27 11:55:16 +01:00
|
|
|
print $ligne->LibStatut($row[2], 1);
|
2011-01-05 10:57:55 +01:00
|
|
|
//print $st[$row[2]];
|
2010-08-09 18:07:24 +02:00
|
|
|
print '</td><td align="center">';
|
|
|
|
|
print $row[1];
|
2005-03-03 15:03:50 +01:00
|
|
|
|
2019-02-10 16:08:03 +01:00
|
|
|
print '</td><td class="right">';
|
2020-04-10 10:59:32 +02:00
|
|
|
print round($row[1] / $nbtotal * 100, 2)." %";
|
2005-03-03 15:03:50 +01:00
|
|
|
|
2019-02-10 16:08:03 +01:00
|
|
|
print '</td><td class="right">';
|
2005-03-03 15:03:50 +01:00
|
|
|
|
2010-08-09 18:07:24 +02:00
|
|
|
print price($row[0]);
|
2009-08-17 19:46:59 +02:00
|
|
|
|
2019-02-10 16:08:03 +01:00
|
|
|
print '</td><td class="right">';
|
2020-04-10 10:59:32 +02:00
|
|
|
print round($row[0] / $total * 100, 2)." %";
|
2010-08-09 18:07:24 +02:00
|
|
|
print '</td></tr>';
|
2019-09-23 21:55:30 +02:00
|
|
|
|
2010-08-09 18:07:24 +02:00
|
|
|
$i++;
|
|
|
|
|
}
|
2005-01-19 15:49:54 +01:00
|
|
|
|
2019-02-10 16:08:03 +01:00
|
|
|
print '<tr class="liste_total"><td class="right">'.$langs->trans("Total").'</td>';
|
2019-12-12 10:31:08 +01:00
|
|
|
print '<td class="center">'.$nbtotal.'</td><td> </td><td class="right">';
|
2010-08-09 18:07:24 +02:00
|
|
|
print price($total);
|
2019-02-10 16:08:03 +01:00
|
|
|
print '</td><td class="right"> </td>';
|
2010-08-09 18:07:24 +02:00
|
|
|
print "</tr></table>";
|
2022-05-15 22:29:19 +02:00
|
|
|
|
|
|
|
|
$db->free($resql);
|
2020-05-21 15:05:19 +02:00
|
|
|
} else {
|
2010-08-09 18:07:24 +02:00
|
|
|
dol_print_error($db);
|
2009-08-17 19:46:59 +02:00
|
|
|
}
|
2008-11-04 17:58:26 +01:00
|
|
|
|
|
|
|
|
|
2005-03-02 11:07:20 +01:00
|
|
|
/*
|
2016-01-01 23:44:23 +01:00
|
|
|
* Stats on errors
|
2005-03-02 11:07:20 +01:00
|
|
|
*/
|
2016-01-01 23:44:23 +01:00
|
|
|
|
2010-03-16 00:54:37 +01:00
|
|
|
print '<br>';
|
2020-06-08 11:43:20 +02:00
|
|
|
print load_fiche_titre($langs->trans("Rejects"), '', '');
|
2005-03-02 11:07:20 +01:00
|
|
|
|
2011-06-12 20:05:30 +02:00
|
|
|
|
2010-09-05 03:20:53 +02:00
|
|
|
// Define total and nbtotal
|
2005-03-02 11:07:20 +01:00
|
|
|
$sql = "SELECT sum(pl.amount), count(pl.amount)";
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
|
|
|
|
|
$sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
|
|
|
|
|
$sql .= " WHERE pl.fk_prelevement_bons = pb.rowid";
|
|
|
|
|
$sql .= " AND pb.entity = ".$conf->entity;
|
|
|
|
|
$sql .= " AND pl.statut = 3";
|
2020-06-08 11:43:20 +02:00
|
|
|
if ($type == 'bank-transfer') {
|
|
|
|
|
$sql .= " AND pb.type = 'bank-transfer'";
|
|
|
|
|
} else {
|
|
|
|
|
$sql .= " AND pb.type = 'debit-order'";
|
|
|
|
|
}
|
2020-04-10 10:59:32 +02:00
|
|
|
$resql = $db->query($sql);
|
2021-02-23 21:09:01 +01:00
|
|
|
if ($resql) {
|
2020-03-23 15:54:02 +01:00
|
|
|
$num = $db->num_rows($resql);
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
2021-02-23 21:09:01 +01:00
|
|
|
if ($num > 0) {
|
2020-03-23 15:54:02 +01:00
|
|
|
$row = $db->fetch_row($resql);
|
|
|
|
|
$total = $row[0];
|
|
|
|
|
$nbtotal = $row[1];
|
|
|
|
|
}
|
2005-03-02 11:07:20 +01:00
|
|
|
}
|
2005-01-19 15:49:54 +01:00
|
|
|
|
2005-03-02 11:07:20 +01:00
|
|
|
/*
|
|
|
|
|
* Stats sur les rejets
|
|
|
|
|
*/
|
2020-06-08 11:43:20 +02:00
|
|
|
|
2005-03-03 14:56:28 +01:00
|
|
|
$sql = "SELECT sum(pl.amount), count(pl.amount) as cc, pr.motif";
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
|
|
|
|
|
$sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
|
|
|
|
|
$sql .= ", ".MAIN_DB_PREFIX."prelevement_rejet as pr";
|
|
|
|
|
$sql .= " WHERE pl.fk_prelevement_bons = pb.rowid";
|
|
|
|
|
$sql .= " AND pb.entity = ".$conf->entity;
|
|
|
|
|
$sql .= " AND pl.statut = 3";
|
|
|
|
|
$sql .= " AND pr.fk_prelevement_lignes = pl.rowid";
|
2020-06-08 11:43:20 +02:00
|
|
|
if ($type == 'bank-transfer') {
|
|
|
|
|
$sql .= " AND pb.type = 'bank-transfer'";
|
|
|
|
|
} else {
|
|
|
|
|
$sql .= " AND pb.type = 'debit-order'";
|
|
|
|
|
}
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= " GROUP BY pr.motif";
|
|
|
|
|
$sql .= " ORDER BY cc DESC";
|
|
|
|
|
|
|
|
|
|
$resql = $db->query($sql);
|
2021-02-23 21:09:01 +01:00
|
|
|
if ($resql) {
|
2010-08-09 18:07:24 +02:00
|
|
|
$num = $db->num_rows($resql);
|
|
|
|
|
$i = 0;
|
2009-08-17 19:46:59 +02:00
|
|
|
|
2010-08-09 18:07:24 +02:00
|
|
|
print"\n<!-- debut table -->\n";
|
2019-11-05 21:24:41 +01:00
|
|
|
print '<table class="noborder centpercent">';
|
2010-08-09 18:07:24 +02:00
|
|
|
print '<tr class="liste_titre">';
|
|
|
|
|
print '<td width="30%">'.$langs->trans("Status").'</td><td align="center">'.$langs->trans("Number").'</td>';
|
2019-02-10 16:08:03 +01:00
|
|
|
print '<td class="right">%</td><td class="right">'.$langs->trans("Amount").'</td><td class="right">%</td></tr>';
|
2009-08-17 19:46:59 +02:00
|
|
|
|
2012-08-22 23:11:24 +02:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php';
|
2020-10-22 21:29:33 +02:00
|
|
|
$Rejet = new RejetPrelevement($db, $user, $type);
|
2009-08-17 19:46:59 +02:00
|
|
|
|
2021-02-23 21:09:01 +01:00
|
|
|
while ($i < $num) {
|
2010-08-09 18:07:24 +02:00
|
|
|
$row = $db->fetch_row($resql);
|
2009-08-17 19:46:59 +02:00
|
|
|
|
2017-05-10 16:41:19 +02:00
|
|
|
print '<tr class="oddeven"><td>';
|
2010-08-09 18:07:24 +02:00
|
|
|
print $Rejet->motifs[$row[2]];
|
2005-03-02 11:07:20 +01:00
|
|
|
|
2010-08-09 18:07:24 +02:00
|
|
|
print '</td><td align="center">'.$row[1];
|
2005-01-19 15:49:54 +01:00
|
|
|
|
2019-02-10 16:08:03 +01:00
|
|
|
print '</td><td class="right">';
|
2020-04-10 10:59:32 +02:00
|
|
|
print round($row[1] / $nbtotal * 100, 2)." %";
|
2005-01-19 15:49:54 +01:00
|
|
|
|
2019-02-10 16:08:03 +01:00
|
|
|
print '</td><td class="right">';
|
2010-08-09 18:07:24 +02:00
|
|
|
print price($row[0]);
|
2005-01-19 15:49:54 +01:00
|
|
|
|
2019-02-10 16:08:03 +01:00
|
|
|
print '</td><td class="right">';
|
2020-04-10 10:59:32 +02:00
|
|
|
print round($row[0] / $total * 100, 2)." %";
|
2005-03-02 11:07:20 +01:00
|
|
|
|
2010-08-09 18:07:24 +02:00
|
|
|
print '</td></tr>';
|
2019-09-23 21:55:30 +02:00
|
|
|
|
2010-08-09 18:07:24 +02:00
|
|
|
$i++;
|
|
|
|
|
}
|
2005-01-19 15:49:54 +01:00
|
|
|
|
2019-02-10 16:08:03 +01:00
|
|
|
print '<tr class="liste_total"><td class="right">'.$langs->trans("Total").'</td><td align="center">'.$nbtotal.'</td>';
|
|
|
|
|
print '<td> </td><td class="right">';
|
2010-08-09 18:07:24 +02:00
|
|
|
print price($total);
|
2019-02-10 16:08:03 +01:00
|
|
|
print '</td><td class="right"> </td>';
|
2010-08-09 18:07:24 +02:00
|
|
|
print "</tr></table>";
|
2010-09-05 03:20:53 +02:00
|
|
|
$db->free($resql);
|
2020-05-21 15:05:19 +02:00
|
|
|
} else {
|
2010-08-09 18:07:24 +02:00
|
|
|
dol_print_error($db);
|
2009-08-17 19:46:59 +02:00
|
|
|
}
|
2005-01-19 15:49:54 +01:00
|
|
|
|
2018-08-08 12:29:36 +02:00
|
|
|
// End of page
|
2012-02-01 11:32:55 +01:00
|
|
|
llxFooter();
|
2005-01-19 15:49:54 +01:00
|
|
|
$db->close();
|