budget.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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@inodbox.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 <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/compta/bank/budget.php
  22. * \ingroup banque
  23. * \brief Page de budget
  24. */
  25. // Load Dolibarr environment
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  28. // Load translation files required by the page
  29. $langs->loadLangs(array('banks', 'categories'));
  30. // Security check
  31. if ($user->socid) {
  32. $socid = $user->socid;
  33. }
  34. $result = restrictedArea($user, 'banque');
  35. /*
  36. * View
  37. */
  38. $companystatic = new Societe($db);
  39. $title = $langs->trans('ListTransactionsByCategory');
  40. $help_url = 'EN:Module_Banks_and_Cash|FR:Module_Banques_et_Caisses|ES:M&oacute;dulo_Bancos_y_Cajas';
  41. llxHeader('', $title, $help_url);
  42. // List movements bu category for bank transactions
  43. print load_fiche_titre($langs->trans("BankTransactionByCategories"), '', 'bank_account');
  44. print '<table class="noborder centpercent">';
  45. print "<tr class=\"liste_titre\">";
  46. print '<td>'.$langs->trans("Rubrique").'</td>';
  47. print '<td class="right">'.$langs->trans("Nb").'</td>';
  48. print '<td class="right">'.$langs->trans("Total").'</td>';
  49. print '<td class="right">'.$langs->trans("Average").'</td>';
  50. print "</tr>\n";
  51. $sql = "SELECT sum(d.amount) as somme, count(*) as nombre, c.label, c.rowid ";
  52. $sql .= " FROM ".MAIN_DB_PREFIX."bank_categ as c";
  53. $sql .= ", ".MAIN_DB_PREFIX."bank_class as l";
  54. $sql .= ", ".MAIN_DB_PREFIX."bank as d";
  55. $sql .= " WHERE c.entity = ".$conf->entity;
  56. $sql .= " AND c.rowid = l.fk_categ";
  57. $sql .= " AND d.rowid = l.lineid";
  58. $sql .= " GROUP BY c.label, c.rowid";
  59. $sql .= " ORDER BY c.label";
  60. $result = $db->query($sql);
  61. if ($result) {
  62. $num = $db->num_rows($result);
  63. $i = 0;
  64. $total = 0;
  65. $totalnb = 0;
  66. while ($i < $num) {
  67. $objp = $db->fetch_object($result);
  68. print '<tr class="oddeven">';
  69. print "<td><a href=\"".DOL_URL_ROOT."/compta/bank/bankentries_list.php?bid=$objp->rowid\">$objp->label</a></td>";
  70. print '<td class="right">'.$objp->nombre.'</td>';
  71. print '<td class="right"><span class="amount">'.price(abs($objp->somme))."</span></td>";
  72. print '<td class="right"><span class="amount">'.price(abs(price2num($objp->somme / $objp->nombre, 'MT')))."</span></td>";
  73. print "</tr>";
  74. $i++;
  75. $total += abs($objp->somme);
  76. $totalnb += $objp->nombre;
  77. }
  78. $db->free($result);
  79. print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").'</td>';
  80. print '<td class="liste_total right">'.price($total).'</td>';
  81. print '<td colspan="2" class="liste_total right">'.price($totalnb ? price2num($total / $totalnb, 'MT') : 0).'</td></tr>';
  82. } else {
  83. dol_print_error($db);
  84. }
  85. print "</table>";
  86. // End of page
  87. llxFooter();
  88. $db->close();