dolibarr/htdocs/compta/bank/budget.php

105 lines
3.5 KiB
PHP
Raw Normal View History

<?php
2003-02-12 01:06:35 +01:00
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
2010-02-10 18:10:36 +01:00
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
2018-10-27 14:43:12 +02:00
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
2015-04-18 23:11:17 +02:00
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
2002-05-11 20:53:13 +02: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
* the Free Software Foundation; either version 3 of the License, or
2002-05-11 20:53:13 +02: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/>.
2002-05-11 20:53:13 +02:00
*/
/**
2009-07-15 15:50:36 +02:00
* \file htdocs/compta/bank/budget.php
* \ingroup banque
* \brief Page de budget
*/
2018-07-26 11:57:25 +02:00
require '../../main.inc.php';
2013-06-05 16:24:32 +02:00
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
2018-05-27 09:40:17 +02:00
// Load translation files required by the page
$langs->loadLangs(array('banks', 'categories'));
// Security check
2021-02-23 21:09:01 +01:00
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'banque');
2002-05-11 20:53:13 +02:00
/*
2009-08-07 20:39:01 +02:00
* View
2002-05-11 20:53:13 +02:00
*/
$companystatic = new Societe($db);
2009-07-15 15:50:36 +02:00
$title = $langs->trans('ListTransactionsByCategory');
$help_url = 'EN:Module_Banks_and_Cash|FR:Module_Banques_et_Caisses|ES:M&oacute;dulo_Bancos_y_Cajas';
llxHeader('', $title, $help_url);
// List movements bu category for bank transactions
2020-04-09 16:36:39 +02:00
print load_fiche_titre($langs->trans("BankTransactionByCategories"), '', 'bank_account');
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">';
print "<tr class=\"liste_titre\">";
print '<td>'.$langs->trans("Rubrique").'</td>';
2019-01-24 09:57:39 +01:00
print '<td class="right">'.$langs->trans("Nb").'</td>';
print '<td class="right">'.$langs->trans("Total").'</td>';
print '<td class="right">'.$langs->trans("Average").'</td>';
print "</tr>\n";
$sql = "SELECT sum(d.amount) as somme, count(*) as nombre, c.label, c.rowid ";
$sql .= " FROM ".MAIN_DB_PREFIX."bank_categ as c";
$sql .= ", ".MAIN_DB_PREFIX."bank_class as l";
$sql .= ", ".MAIN_DB_PREFIX."bank as d";
$sql .= " WHERE c.entity = ".$conf->entity;
$sql .= " AND c.rowid = l.fk_categ";
$sql .= " AND d.rowid = l.lineid";
$sql .= " GROUP BY c.label, c.rowid";
$sql .= " ORDER BY c.label";
$result = $db->query($sql);
2021-02-23 21:09:01 +01:00
if ($result) {
$num = $db->num_rows($result);
2021-03-01 20:37:16 +01:00
$i = 0;
$total = 0;
$totalnb = 0;
2021-02-23 21:09:01 +01:00
while ($i < $num) {
$objp = $db->fetch_object($result);
print '<tr class="oddeven">';
print "<td><a href=\"".DOL_URL_ROOT."/compta/bank/bankentries_list.php?bid=$objp->rowid\">$objp->label</a></td>";
2019-01-24 09:57:39 +01:00
print '<td class="right">'.$objp->nombre.'</td>';
2021-03-29 13:00:17 +02:00
print '<td class="right"><span class="amount">'.price(abs($objp->somme))."</span></td>";
print '<td class="right"><span class="amount">'.price(abs(price2num($objp->somme / $objp->nombre, 'MT')))."</span></td>";
print "</tr>";
$i++;
2009-11-07 15:01:34 +01:00
$total += abs($objp->somme);
$totalnb += $objp->nombre;
}
$db->free($result);
2002-05-11 20:53:13 +02:00
2009-11-07 15:01:34 +01:00
print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").'</td>';
2019-01-24 09:57:39 +01:00
print '<td class="liste_total right">'.price($total).'</td>';
print '<td colspan="2" class="liste_total right">'.price($totalnb ?price2num($total / $totalnb, 'MT') : 0).'</td></tr>';
2020-05-21 15:05:19 +02:00
} else {
dol_print_error($db);
2002-05-11 20:53:13 +02:00
}
print "</table>";
2002-05-11 20:53:13 +02:00
2018-07-29 19:16:28 +02:00
// End of page
llxFooter();
$db->close();