Changed context help organization to enable use of central, multilanguage wiki.
[fa-stable.git] / gl / inquiry / gl_account_inquiry.php
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 $page_security = 'SA_GLTRANSVIEW';
13 $path_to_root = "../..";
14 include_once($path_to_root . "/includes/session.inc");
15
16
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");
20
21 include_once($path_to_root . "/gl/includes/gl_db.inc");
22
23 $js = '';
24 set_focus('account');
25 if ($use_popup_windows)
26         $js .= get_js_open_window(800, 500);
27 if ($use_date_picker)
28         $js .= get_js_date_picker();
29
30 page(_($help_context = "General Ledger Account Inquiry"), false, false, '', $js);
31
32 //----------------------------------------------------------------------------------------------------
33 // Ajax updates
34 //
35 if (get_post('Show')) 
36 {
37         $Ajax->activate('trans_tbl');
38 }
39
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
51 //----------------------------------------------------------------------------------------------------
52
53 function gl_inquiry_controls()
54 {
55         global $table_style2;
56
57         $dim = get_company_pref('use_dimension');
58     start_form();
59
60     //start_table($table_style2);
61     start_table("class='tablestyle_noborder'");
62         start_row();
63
64     gl_all_accounts_list_cells(_("Account:"), 'account', null);
65
66         date_cells(_("from:"), 'TransFromDate', '', null, -30);
67         date_cells(_("to:"), 'TransToDate');
68         submit_cells('Show',_("Show"),'','', 'default');
69
70     end_row();
71
72         if ($dim >= 1)
73                 dimensions_list_row(_("Dimension")." 1", 'Dimension', null, true, " ", false, 1);
74         if ($dim > 1)
75                 dimensions_list_row(_("Dimension")." 2", 'Dimension2', null, true, " ", false, 2);
76         end_table();
77
78     end_form();
79 }
80
81 //----------------------------------------------------------------------------------------------------
82
83 function show_results()
84 {
85         global $path_to_root, $table_style, $systypes_array;
86
87         if (!isset($_POST["account"]) || $_POST["account"] == "")
88                 return;
89         $act_name = get_gl_account_name($_POST["account"]);
90         $dim = get_company_pref('use_dimension');
91
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']);
99
100         $colspan = ($dim == 2 ? "6" : ($dim == 1 ? "5" : "4"));
101         div_start('trans_tbl');
102         //echo "\nDimension =". $_POST['Dimension'];
103         display_heading($_POST["account"]. "&nbsp;&nbsp;&nbsp;".$act_name);
104
105         start_table($table_style);
106         if ($dim == 2)
107                 $th = array(_("Type"), _("#"), _("Date"), _("Dimension")." 1", _("Dimension")." 2",
108                         _("Person/Item"), _("Debit"), _("Credit"), _("Balance"), _("Memo"));
109         else if ($dim == 1)
110                 $th = array(_("Type"), _("#"), _("Date"), _("Dimension"),
111                         _("Person/Item"), _("Debit"), _("Credit"), _("Balance"), _("Memo"));
112         else
113                 $th = array(_("Type"), _("#"), _("Date"),
114                         _("Person/Item"), _("Debit"), _("Credit"), _("Balance"), _("Memo"));
115         table_header($th);
116         if (is_account_balancesheet($_POST["account"]))
117                 $begin = "";
118         else
119         {
120                 $begin = begin_fiscalyear();
121                 if (date1_greater_date2($begin, $_POST['TransFromDate']))
122                         $begin = $_POST['TransFromDate'];
123                 $begin = add_days($begin, -1);
124         }
125
126     $bfw = get_gl_balance_from_to($begin, $_POST['TransFromDate'], $_POST["account"], $_POST['Dimension'], $_POST['Dimension2']);
127
128         start_row("class='inquirybg'");
129         label_cell("<b>"._("Opening Balance")." - ".$_POST['TransFromDate']."</b>", "colspan=$colspan");
130         display_debit_or_credit_cells($bfw);
131         label_cell("");
132         label_cell("");
133         end_row();
134         //$running_total =0;
135         $running_total = $bfw;
136         $j = 1;
137         $k = 0; //row colour counter
138
139         while ($myrow = db_fetch($result))
140         {
141
142         alt_table_row_color($k);
143
144         $running_total += $myrow["amount"];
145
146         $trandate = sql2date($myrow["tran_date"]);
147
148         label_cell($systypes_array[$myrow["type"]]);
149                 label_cell(get_gl_view_str($myrow["type"], $myrow["type_no"], $myrow["type_no"], true));
150         label_cell($trandate);
151                 if ($dim >= 1)
152                         label_cell(get_dimension_string($myrow['dimension_id'], true));
153                 if ($dim > 1)
154                         label_cell(get_dimension_string($myrow['dimension2_id'], true));
155                 label_cell(payment_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_']);
159         end_row();
160
161         $j++;
162         if ($j == 12)
163         {
164                 $j = 1;
165                 table_header($th);
166         }
167         }
168         //end of while loop
169
170         start_row("class='inquirybg'");
171         label_cell("<b>" . _("Ending Balance") ." - ".$_POST['TransToDate']. "</b>", "colspan=$colspan");
172         display_debit_or_credit_cells($running_total);
173         label_cell("");
174         label_cell("");
175         end_row();
176
177         end_table(2);
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);
180         div_end();
181 }
182
183 //----------------------------------------------------------------------------------------------------
184
185 gl_inquiry_controls();
186
187 show_results();
188
189 //----------------------------------------------------------------------------------------------------
190
191 end_page();
192
193 ?>