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 ***********************************************************************/
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(_("General Ledger Account 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"];
51 //----------------------------------------------------------------------------------------------------
53 function gl_inquiry_controls()
57 $dim = get_company_pref('use_dimension');
60 //start_table($table_style2);
61 start_table("class='tablestyle_noborder'");
64 gl_all_accounts_list_cells(_("Account:"), 'account', null);
66 date_cells(_("from:"), 'TransFromDate', '', null, -30);
67 date_cells(_("to:"), 'TransToDate');
68 submit_cells('Show',_("Show"),'','', true);
73 dimensions_list_row(_("Dimension")." 1", 'Dimension', null, true, " ", false, 1);
75 dimensions_list_row(_("Dimension")." 2", 'Dimension2', null, true, " ", false, 2);
81 //----------------------------------------------------------------------------------------------------
83 function show_results()
85 global $path_to_root, $table_style;
87 if (!isset($_POST["account"]) || $_POST["account"] == "")
89 $act_name = get_gl_account_name($_POST["account"]);
90 $dim = get_company_pref('use_dimension');
92 /*Now get the transactions */
93 if (!isset($_POST['Dimension']))
94 $_POST['Dimension'] = 0;
95 if (!isset($_POST['Dimension2']))
96 $_POST['Dimension2'] = 0;
97 $result = get_gl_transactions($_POST['TransFromDate'], $_POST['TransToDate'], -1,
98 $_POST["account"], $_POST['Dimension'], $_POST['Dimension2']);
100 $colspan = ($dim == 2 ? "6" : ($dim == 1 ? "5" : "4"));
101 div_start('trans_tbl');
102 //echo "\nDimension =". $_POST['Dimension'];
103 display_heading($_POST["account"]. " ".$act_name);
105 start_table($table_style);
107 $th = array(_("Type"), _("#"), _("Date"), _("Dimension")." 1", _("Dimension")." 2",
108 _("Person/Item"), _("Debit"), _("Credit"), _("Balance"), _("Memo"));
110 $th = array(_("Type"), _("#"), _("Date"), _("Dimension"),
111 _("Person/Item"), _("Debit"), _("Credit"), _("Balance"), _("Memo"));
113 $th = array(_("Type"), _("#"), _("Date"),
114 _("Person/Item"), _("Debit"), _("Credit"), _("Balance"), _("Memo"));
116 if (is_account_balancesheet($_POST["account"]))
120 $begin = begin_fiscalyear();
121 if (date1_greater_date2($begin, $_POST['TransFromDate']))
122 $begin = $_POST['TransFromDate'];
123 $begin = add_days($begin, -1);
126 $bfw = get_gl_balance_from_to($begin, $_POST['TransFromDate'], $_POST["account"], $_POST['Dimension'], $_POST['Dimension2']);
128 start_row("class='inquirybg'");
129 label_cell("<b>"._("Opening Balance")." - ".$_POST['TransFromDate']."</b>", "colspan=$colspan");
130 display_debit_or_credit_cells($bfw);
135 $running_total = $bfw;
137 $k = 0; //row colour counter
139 while ($myrow = db_fetch($result))
142 alt_table_row_color($k);
144 $running_total += $myrow["amount"];
146 $trandate = sql2date($myrow["tran_date"]);
148 label_cell(systypes::name($myrow["type"]));
149 label_cell(get_gl_view_str($myrow["type"], $myrow["type_no"], $myrow["type_no"], true));
150 label_cell($trandate);
152 label_cell(get_dimension_string($myrow['dimension_id'], true));
154 label_cell(get_dimension_string($myrow['dimension2_id'], true));
155 label_cell(payment_person_types::person_name($myrow["person_type_id"],$myrow["person_id"]));
156 display_debit_or_credit_cells($myrow["amount"]);
157 amount_cell($running_total);
158 label_cell($myrow['memo_']);
170 start_row("class='inquirybg'");
171 label_cell("<b>" . _("Ending Balance") ." - ".$_POST['TransToDate']. "</b>", "colspan=$colspan");
172 display_debit_or_credit_cells($running_total);
178 if (db_num_rows($result) == 0)
179 display_note(_("No general ledger transactions have been created for this account on the selected dates."), 0, 1);
183 //----------------------------------------------------------------------------------------------------
185 gl_inquiry_controls();
189 //----------------------------------------------------------------------------------------------------