Changed API for input/lists functions, added empty hints when needed
[fa-stable.git] / gl / inquiry / gl_account_inquiry.php
1 <?php
2
3 $page_security = 8;
4 $path_to_root="../..";
5 include_once($path_to_root . "/includes/session.inc");
6
7
8 include_once($path_to_root . "/includes/date_functions.inc");
9 include_once($path_to_root . "/includes/ui.inc");
10 include_once($path_to_root . "/includes/data_checks.inc");
11
12 include_once($path_to_root . "/gl/includes/gl_db.inc");
13
14 $js = '';
15 set_focus('account');
16 if ($use_popup_windows)
17         $js .= get_js_open_window(800, 500);
18 if ($use_date_picker)
19         $js .= get_js_date_picker();
20
21 page(_("General Ledger Account Inquiry"), false, false, '', $js);
22
23 //----------------------------------------------------------------------------------------------------
24
25 if (isset($_GET["account"]))
26         $_POST["account"] = $_GET["account"];
27 if (isset($_GET["TransFromDate"]))
28         $_POST["TransFromDate"] = $_GET["TransFromDate"];
29 if (isset($_GET["TransToDate"]))
30         $_POST["TransToDate"] = $_GET["TransToDate"];
31 if (isset($_GET["Dimension"]))
32         $_POST["Dimension"] = $_GET["Dimension"];
33 if (isset($_GET["Dimension2"]))
34         $_POST["Dimension2"] = $_GET["Dimension2"];
35
36 //----------------------------------------------------------------------------------------------------
37
38 function gl_inquiry_controls()
39 {
40         global $table_style2;
41
42         $dim = get_company_pref('use_dimension');
43     start_form();
44
45     //start_table($table_style2);
46     start_table("class='tablestyle_noborder'");
47         start_row();
48
49     gl_all_accounts_list_cells(_("Account:"), 'account', null);
50
51         date_cells(_("from:"), 'TransFromDate', '', null, -30);
52         date_cells(_("to:"), 'TransToDate');
53     submit_cells('Show',_("Show"));
54
55     end_row();
56
57         if ($dim >= 1)
58                 dimensions_list_row(_("Dimension")." 1", 'Dimension', null, true, " ", false, 1);
59         if ($dim > 1)
60                 dimensions_list_row(_("Dimension")." 2", 'Dimension2', null, true, " ", false, 2);
61         end_table();
62
63     end_form();
64 }
65
66 //----------------------------------------------------------------------------------------------------
67
68 function show_results()
69 {
70         global $path_to_root, $table_style;
71
72         if (!isset($_POST["account"]) || $_POST["account"] == "")
73                 return;
74         $act_name = get_gl_account_name($_POST["account"]);
75         $dim = get_company_pref('use_dimension');
76
77     /*Now get the transactions  */
78     if (!isset($_POST['Dimension']))
79         $_POST['Dimension'] = 0;
80     if (!isset($_POST['Dimension2']))
81         $_POST['Dimension2'] = 0;
82         $result = get_gl_transactions($_POST['TransFromDate'], $_POST['TransToDate'], -1,
83         $_POST["account"], $_POST['Dimension'], $_POST['Dimension2']);
84
85         $colspan = ($dim == 2 ? "6" : ($dim == 1 ? "5" : "4"));
86         //echo "\nDimension =". $_POST['Dimension'];
87         display_heading($_POST["account"]. "&nbsp;&nbsp;&nbsp;".$act_name);
88
89         start_table($table_style);
90         if ($dim == 2)
91                 $th = array(_("Type"), _("#"), _("Date"), _("Dimension")." 1", _("Dimension")." 2",
92                         _("Person/Item"), _("Debit"), _("Credit"), _("Balance"), _("Memo"));
93         else if ($dim == 1)
94                 $th = array(_("Type"), _("#"), _("Date"), _("Dimension"),
95                         _("Person/Item"), _("Debit"), _("Credit"), _("Balance"), _("Memo"));
96         else
97                 $th = array(_("Type"), _("#"), _("Date"),
98                         _("Person/Item"), _("Debit"), _("Credit"), _("Balance"), _("Memo"));
99         table_header($th);
100         if (is_account_balancesheet($_POST["account"]))
101                 $begin = "";
102         else
103         {
104                 $begin = begin_fiscalyear();
105                 if ($_POST['TransFromDate'] < $begin)
106                         $begin = $_POST['TransFromDate'];
107                 $begin = add_days($begin, -1);
108         }
109
110     $bfw = get_gl_balance_from_to($begin, $_POST['TransFromDate'], $_POST["account"], $_POST['Dimension'], $_POST['Dimension2']);
111
112         start_row("class='inquirybg'");
113         label_cell("<b>"._("Opening Balance")." - ".$_POST['TransFromDate']."</b>", "colspan=$colspan");
114         display_debit_or_credit_cells($bfw);
115         label_cell("");
116         end_row();
117         //$running_total =0;
118         $running_total = $bfw;
119         $j = 1;
120         $k = 0; //row colour counter
121
122         while ($myrow = db_fetch($result))
123         {
124
125         alt_table_row_color($k);
126
127         $running_total += $myrow["amount"];
128
129         $trandate = sql2date($myrow["tran_date"]);
130
131         label_cell(systypes::name($myrow["type"]));
132                 label_cell(get_gl_view_str($myrow["type"], $myrow["type_no"], $myrow["type_no"], true));
133         label_cell($trandate);
134                 if ($dim >= 1)
135                         label_cell(get_dimension_string($myrow['dimension_id'], true));
136                 if ($dim > 1)
137                         label_cell(get_dimension_string($myrow['dimension2_id'], true));
138                 label_cell(payment_person_types::person_name($myrow["person_type_id"],$myrow["person_id"]));
139                 display_debit_or_credit_cells($myrow["amount"]);
140                 amount_cell($running_total);
141         label_cell($myrow['memo_']);
142         end_row();
143
144         $j++;
145         if ($j == 12)
146         {
147                 $j = 1;
148                 table_header($th);
149         }
150         }
151         //end of while loop
152
153         start_row("class='inquirybg'");
154         label_cell("<b>" . _("Ending Balance") ." - ".$_POST['TransToDate']. "</b>", "colspan=$colspan");
155         display_debit_or_credit_cells($running_total);
156         label_cell("");
157         end_row();
158
159         end_table(2);
160         if (db_num_rows($result) == 0)
161                 display_note(_("No general ledger transactions have been created for this account on the selected dates."), 0, 1);
162 }
163
164 //----------------------------------------------------------------------------------------------------
165
166 gl_inquiry_controls();
167
168 show_results();
169
170 //----------------------------------------------------------------------------------------------------
171
172 end_page();
173
174 ?>