Changed license type to GPLv3 in top of files
[fa-stable.git] / dimensions / includes / dimensions_ui.inc
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 include_once($path_to_root . "/includes/ui.inc");
13
14 //--------------------------------------------------------------------------------------
15
16 function display_dimension_balance($id, $from, $to)
17 {
18         global $path_to_root, $table_style;
19
20         $from = date2sql($from);
21         $to = date2sql($to);
22         $sql = "SELECT account, ".TB_PREF."chart_master.account_name, sum(amount) AS amt FROM
23                 ".TB_PREF."gl_trans,".TB_PREF."chart_master WHERE
24                 ".TB_PREF."gl_trans.account = ".TB_PREF."chart_master.account_code AND
25                 (dimension_id = $id OR dimension2_id = $id) AND
26                 tran_date >= '$from' AND tran_date <= '$to' GROUP BY account";
27         $result = db_query($sql, "Transactions could not be calculated");
28
29     if (db_num_rows($result) == 0)
30     {
31         display_note(_("There are no transactions for this dimension for the selected period."));
32     }
33     else
34     {
35                 display_heading2(_("Balance for this Dimension"));
36                 br();
37                 start_table($table_style);
38                 $th = array(_("Account"), _("Debit"), _("Credit"));
39                 table_header($th);
40
41         $total = $k = 0;
42         while ($myrow = db_fetch($result))
43         {
44                         alt_table_row_color($k);
45
46                         label_cell($myrow["account"]." ".$myrow['account_name']);
47                         display_debit_or_credit_cells($myrow["amt"]);
48                         $total += $myrow["amt"];
49                         end_row();
50                 }
51                 start_row();
52                 label_cell("<b>"._("Balance")."</b>");
53                 if ($total >= 0)
54                 {
55                         amount_cell($total, true);
56                         label_cell("");
57                 }
58                 else
59                 {
60                         label_cell("");
61                         amount_cell(abs($total), true);
62                 }
63                 end_row();
64
65                 end_table();
66     }
67 }
68
69 //--------------------------------------------------------------------------------------
70
71 ?>