*** empty log message ***
[fa-stable.git] / gl / inquiry / gl_trial_balance.php
1 <?php
2
3 $page_security = 8;
4 $path_to_root="../..";
5
6 include_once($path_to_root . "/includes/session.inc");
7
8 page(_("Trial Balance"));
9
10 include_once($path_to_root . "/includes/date_functions.inc");
11 include_once($path_to_root . "/includes/ui.inc");
12 include_once($path_to_root . "/includes/data_checks.inc");
13
14 include_once($path_to_root . "/gl/includes/gl_db.inc");
15
16 //----------------------------------------------------------------------------------------------------
17
18
19 function gl_inquiry_controls()
20 {
21     start_form();
22
23     start_table("class='tablestyle_noborder'");
24
25     date_cells(_("From:"), 'TransFromDate', null, -30);
26         date_cells(_("To:"), 'TransToDate');
27         check_cells(_("No zero values"), 'NoZero', null);
28
29     submit_cells('Show',_("Show"));
30     end_table();
31     end_form();
32 }
33
34 //----------------------------------------------------------------------------------------------------
35
36 function get_balance($account, $from, $to, $from_incl=true, $to_incl=true) {
37
38         $sql = "SELECT SUM(amount) As TransactionSum FROM ".TB_PREF."gl_trans
39                 WHERE account=$account";
40
41         if ($from) 
42         {
43                 $from_date = date2sql($from);
44                 if ($from_incl)
45                         $sql .= " AND tran_date >= '$from_date'";
46                 else
47                         $sql .= " AND tran_date > '$from_date'";
48         }
49
50         if ($to) 
51         {
52                 $to_date = date2sql($to);
53                 if ($to_incl)
54                         $sql .= " AND tran_date <= '$to_date' ";
55                 else
56                         $sql .= " AND tran_date < '$to_date' ";
57         }
58
59         $result = db_query($sql,"No general ledger accounts were returned");
60
61         $row = db_fetch_row($result);
62         return $row[0];
63 }
64
65 //----------------------------------------------------------------------------------------------------
66
67 function display_trial_balance()
68 {
69         global $table_style, $path_to_root;
70
71         start_table($table_style);
72         $tableheader =  "<tr>
73         <td rowspan=2 class='tableheader'>" . _("Account") . "</td>
74         <td rowspan=2 class='tableheader'>" . _("Account Name") . "</td>
75                 <td colspan=2 class='tableheader'>" . _("Brought Forward") . "</td>
76                 <td colspan=2 class='tableheader'>" . _("This Period") . "</td>
77                 <td colspan=2 class='tableheader'>" . _("Balance") . "</td>
78                 </tr><tr>
79                 <td class='tableheader'>" . _("Debit") . "</td>
80         <td class='tableheader'>" . _("Credit") . "</td>
81                 <td class='tableheader'>" . _("Debit") . "</td>
82                 <td class='tableheader'>" . _("Credit") . "</td>
83         <td class='tableheader'>" . _("Debit") . "</td>
84         <td class='tableheader'>" . _("Credit") . "</td>
85         </tr>";
86
87     echo $tableheader;
88
89         $k = 0;
90
91         $accounts = get_gl_accounts();
92
93         while ($account = db_fetch($accounts)) 
94         {
95
96                 $prev_balance = get_balance($account["account_code"], null, $_POST['TransFromDate'], false, false);
97
98                 $curr_balance = get_balance($account["account_code"], $_POST['TransFromDate'], $_POST['TransToDate']);
99                 if (check_value("NoZero") && !$prev_balance && !$curr_balance)
100                         continue;
101                 alt_table_row_color($k);
102
103                 $url = "<a href='$path_to_root/gl/inquiry/gl_account_inquiry.php?" . SID . "TransFromDate=" . $_POST["TransFromDate"] . "&TransToDate=" . $_POST["TransToDate"] . "&account=" . $account["account_code"] . "'>" . $account["account_code"] . "</a>";
104
105                 label_cell($url);
106                 label_cell($account["account_name"]);
107
108                 display_debit_or_credit_cells($prev_balance);
109                 display_debit_or_credit_cells($curr_balance);
110                 display_debit_or_credit_cells($prev_balance + $curr_balance);
111                 end_row();
112         }
113
114         end_table(1);
115
116 }
117
118 //----------------------------------------------------------------------------------------------------
119
120 gl_inquiry_controls();
121
122 display_trial_balance();
123
124 //----------------------------------------------------------------------------------------------------
125
126 end_page();
127
128 ?>
129