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 $page_security = 'SA_GLTRANSVIEW';
13 $path_to_root = "../..";
14 include_once($path_to_root . "/includes/session.inc");
17 include_once($path_to_root . "/includes/date_functions.inc");
18 include_once($path_to_root . "/includes/ui.inc");
19 include_once($path_to_root . "/includes/data_checks.inc");
21 include_once($path_to_root . "/gl/includes/gl_db.inc");
25 if ($use_popup_windows)
26 $js .= get_js_open_window(800, 500);
28 $js .= get_js_date_picker();
30 page(_($help_context = "General Ledger Inquiry"), false, false, '', $js);
32 //----------------------------------------------------------------------------------------------------
37 $Ajax->activate('trans_tbl');
40 if (isset($_GET["account"]))
41 $_POST["account"] = $_GET["account"];
42 if (isset($_GET["TransFromDate"]))
43 $_POST["TransFromDate"] = $_GET["TransFromDate"];
44 if (isset($_GET["TransToDate"]))
45 $_POST["TransToDate"] = $_GET["TransToDate"];
46 if (isset($_GET["Dimension"]))
47 $_POST["Dimension"] = $_GET["Dimension"];
48 if (isset($_GET["Dimension2"]))
49 $_POST["Dimension2"] = $_GET["Dimension2"];
50 if (isset($_GET["amount_min"]))
51 $_POST["amount_min"] = $_GET["amount_min"];
52 if (isset($_GET["amount_max"]))
53 $_POST["amount_max"] = $_GET["amount_max"];
55 if (!isset($_POST["amount_min"]))
56 $_POST["amount_min"] = price_format(0);
57 if (!isset($_POST["amount_max"]))
58 $_POST["amount_max"] = price_format(0);
60 //----------------------------------------------------------------------------------------------------
62 function gl_inquiry_controls()
66 $dim = get_company_pref('use_dimension');
69 start_table("class='tablestyle_noborder'");
71 gl_all_accounts_list_cells(_("Account:"), 'account', null, false, false, "All Accounts");
72 date_cells(_("from:"), 'TransFromDate', '', null, -30);
73 date_cells(_("to:"), 'TransToDate');
80 dimensions_list_cells(_("Dimension")." 1:", 'Dimension', null, true, " ", false, 1);
82 dimensions_list_cells(_("Dimension")." 2:", 'Dimension2', null, true, " ", false, 2);
84 small_amount_cells(_("Amount min:"), 'amount_min', null);
85 small_amount_cells(_("Amount max:"), 'amount_max', null);
86 submit_cells('Show',_("Show"),'','', 'default');
94 //----------------------------------------------------------------------------------------------------
96 function show_results()
98 global $path_to_root, $table_style, $systypes_array;
100 if (!isset($_POST["account"]))
101 $_POST["account"] = null;
103 $act_name = $_POST["account"] ? get_gl_account_name($_POST["account"]) : "";
104 $dim = get_company_pref('use_dimension');
106 /*Now get the transactions */
107 if (!isset($_POST['Dimension']))
108 $_POST['Dimension'] = 0;
109 if (!isset($_POST['Dimension2']))
110 $_POST['Dimension2'] = 0;
111 $result = get_gl_transactions($_POST['TransFromDate'], $_POST['TransToDate'], -1,
112 $_POST["account"], $_POST['Dimension'], $_POST['Dimension2'], null,
113 input_num('amount_min'), input_num('amount_max'));
115 $colspan = ($dim == 2 ? "6" : ($dim == 1 ? "5" : "4"));
117 if ($_POST["account"] != null)
118 display_heading($_POST["account"]. " ".$act_name);
120 // Only show balances if an account is specified AND we're not filtering by amounts
121 $show_balances = $_POST["account"] != null &&
122 input_num("amount_min") == 0 &&
123 input_num("amount_max") == 0;
125 start_table($table_style);
127 $first_cols = array(_("Type"), _("#"), _("Date"));
129 if ($_POST["account"] == null)
130 $account_col = array(_("Account"));
132 $account_col = array();
135 $dim_cols = array(_("Dimension")." 1", _("Dimension")." 2");
137 $dim_cols = array(_("Dimension"));
142 $remaining_cols = array(_("Person/Item"), _("Debit"), _("Credit"), _("Balance"), _("Memo"));
144 $remaining_cols = array(_("Person/Item"), _("Debit"), _("Credit"), _("Memo"));
146 $th = array_merge($first_cols, $account_col, $dim_cols, $remaining_cols);
149 if ($_POST["account"] != null && is_account_balancesheet($_POST["account"]))
153 $begin = begin_fiscalyear();
154 if (date1_greater_date2($begin, $_POST['TransFromDate']))
155 $begin = $_POST['TransFromDate'];
156 $begin = add_days($begin, -1);
160 if ($show_balances) {
161 $bfw = get_gl_balance_from_to($begin, $_POST['TransFromDate'], $_POST["account"], $_POST['Dimension'], $_POST['Dimension2']);
162 start_row("class='inquirybg'");
163 label_cell("<b>"._("Opening Balance")." - ".$_POST['TransFromDate']."</b>", "colspan=$colspan");
164 display_debit_or_credit_cells($bfw);
170 $running_total = $bfw;
172 $k = 0; //row colour counter
174 while ($myrow = db_fetch($result))
177 alt_table_row_color($k);
179 $running_total += $myrow["amount"];
181 $trandate = sql2date($myrow["tran_date"]);
183 label_cell($systypes_array[$myrow["type"]]);
184 label_cell(get_gl_view_str($myrow["type"], $myrow["type_no"], $myrow["type_no"], true));
185 label_cell($trandate);
187 if ($_POST["account"] == null)
188 label_cell($myrow["account"] . ' ' . get_gl_account_name($myrow["account"]));
191 label_cell(get_dimension_string($myrow['dimension_id'], true));
193 label_cell(get_dimension_string($myrow['dimension2_id'], true));
194 label_cell(payment_person_name($myrow["person_type_id"],$myrow["person_id"]));
195 display_debit_or_credit_cells($myrow["amount"]);
197 amount_cell($running_total);
198 label_cell($myrow['memo_']);
210 if ($show_balances) {
211 start_row("class='inquirybg'");
212 label_cell("<b>" . _("Ending Balance") ." - ".$_POST['TransToDate']. "</b>", "colspan=$colspan");
213 display_debit_or_credit_cells($running_total);
220 if (db_num_rows($result) == 0)
221 display_note(_("No general ledger transactions have been created for the specified criteria."), 0, 1);
225 //----------------------------------------------------------------------------------------------------
227 gl_inquiry_controls();
229 div_start('trans_tbl');
231 if (get_post('Show') || get_post('account'))
236 //----------------------------------------------------------------------------------------------------