dolibarr  7.0.0-beta
budget.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2015 Jean-Fran├žois Ferry <jfefe@aternatik.fr>
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 <http://www.gnu.org/licenses/>.
19  */
20 
27 require('../../main.inc.php');
28 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
29 
30 $langs->load("banks");
31 $langs->load("categories");
32 
33 // Security check
34 if ($user->societe_id) $socid=$user->societe_id;
35 $result=restrictedArea($user,'banque');
36 
37 
38 /*
39  * View
40  */
41 
42 $companystatic=new Societe($db);
43 
44 llxHeader();
45 
46 // List movements bu category for bank transactions
47 print load_fiche_titre($langs->trans("BankTransactionByCategories"), '', 'title_bank.png');
48 
49 print '<table class="noborder" width="100%">';
50 print "<tr class=\"liste_titre\">";
51 print '<td>'.$langs->trans("Rubrique").'</td>';
52 print '<td align="right">'.$langs->trans("Nb").'</td>';
53 print '<td align="right">'.$langs->trans("Total").'</td>';
54 print '<td align="right">'.$langs->trans("Average").'</td>';
55 print "</tr>\n";
56 
57 $sql = "SELECT sum(d.amount) as somme, count(*) as nombre, c.label, c.rowid ";
58 $sql.= " FROM ".MAIN_DB_PREFIX."bank_categ as c";
59 $sql.= ", ".MAIN_DB_PREFIX."bank_class as l";
60 $sql.= ", ".MAIN_DB_PREFIX."bank as d";
61 $sql.= " WHERE c.entity = ".$conf->entity;
62 $sql.= " AND c.rowid = l.fk_categ";
63 $sql.= " AND d.rowid = l.lineid";
64 $sql.= " GROUP BY c.label, c.rowid";
65 $sql.= " ORDER BY c.label";
66 
67 $result = $db->query($sql);
68 if ($result)
69 {
70  $num = $db->num_rows($result);
71  $i = 0; $total = 0; $totalnb = 0;
72 
73  $var=true;
74  while ($i < $num)
75  {
76  $objp = $db->fetch_object($result);
77 
78  print '<tr class="oddeven">';
79  print "<td><a href=\"".DOL_URL_ROOT."/compta/bank/bankentries_list.php?bid=$objp->rowid\">$objp->label</a></td>";
80  print '<td align="right">'.$objp->nombre.'</td>';
81  print '<td align="right">'.price(abs($objp->somme))."</td>";
82  print '<td align="right">'.price(abs(price2num($objp->somme / $objp->nombre,'MT')))."</td>";
83  print "</tr>";
84  $i++;
85  $total += abs($objp->somme);
86  $totalnb += $objp->nombre;
87  }
88  $db->free($result);
89 
90  print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").'</td>';
91  print '<td align="right" class="liste_total">'.price($total).'</td>';
92  print '<td align="right" colspan="2" class="liste_total">'.price($totalnb?price2num($total / $totalnb, 'MT'):0).'</td></tr>';
93 }
94 else
95 {
96  dol_print_error($db);
97 }
98 print "</table>";
99 
100 llxFooter();
101 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to manage third parties objects (customers, suppliers, prospects...)
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
print
Draft customers invoices.
Definition: index.php:91
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.