Moving 2.0 development version to main trunk.
[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 // Ajax updates
25 //
26 if (get_post('Show')) 
27 {
28         $Ajax->activate('trans_tbl');
29 }
30
31 if (isset($_GET["account"]))
32         $_POST["account"] = $_GET["account"];
33 if (isset($_GET["TransFromDate"]))
34         $_POST["TransFromDate"] = $_GET["TransFromDate"];
35 if (isset($_GET["TransToDate"]))
36         $_POST["TransToDate"] = $_GET["TransToDate"];
37 if (isset($_GET["Dimension"]))
38         $_POST["Dimension"] = $_GET["Dimension"];
39 if (isset($_GET["Dimension2"]))
40         $_POST["Dimension2"] = $_GET["Dimension2"];
41
42 //----------------------------------------------------------------------------------------------------
43
44 function gl_inquiry_controls()
45 {
46         global $table_style2;
47
48         $dim = get_company_pref('use_dimension');
49     start_form();
50
51     //start_table($table_style2);
52     start_table("class='tablestyle_noborder'");
53         start_row();
54
55     gl_all_accounts_list_cells(_("Account:"), 'account', null);
56
57         date_cells(_("from:"), 'TransFromDate', '', null, -30);
58         date_cells(_("to:"), 'TransToDate');
59         submit_cells('Show',_("Show"),'','', true);
60
61     end_row();
62
63         if ($dim >= 1)
64                 dimensions_list_row(_("Dimension")." 1", 'Dimension', null, true, " ", false, 1);
65         if ($dim > 1)
66                 dimensions_list_row(_("Dimension")." 2", 'Dimension2', null, true, " ", false, 2);
67         end_table();
68
69     end_form();
70 }
71
72 //----------------------------------------------------------------------------------------------------
73
74 function show_results()
75 {
76         global $path_to_root, $table_style;
77
78         if (!isset($_POST["account"]) || $_POST["account"] == "")
79                 return;
80         $act_name = get_gl_account_name($_POST["account"]);
81         $dim = get_company_pref('use_dimension');
82
83     /*Now get the transactions  */
84     if (!isset($_POST['Dimension']))
85         $_POST['Dimension'] = 0;
86     if (!isset($_POST['Dimension2']))
87         $_POST['Dimension2'] = 0;
88         $result = get_gl_transactions($_POST['TransFromDate'], $_POST['TransToDate'], -1,
89         $_POST["account"], $_POST['Dimension'], $_POST['Dimension2']);
90
91         $colspan = ($dim == 2 ? "6" : ($dim == 1 ? "5" : "4"));
92         div_start('trans_tbl');
93         //echo "\nDimension =". $_POST['Dimension'];
94         display_heading($_POST["account"]. "&nbsp;&nbsp;&nbsp;".$act_name);
95
96         start_table($table_style);
97         if ($dim == 2)
98                 $th = array(_("Type"), _("#"), _("Date"), _("Dimension")." 1", _("Dimension")." 2",
99                         _("Person/Item"), _("Debit"), _("Credit"), _("Balance"), _("Memo"));
100         else if ($dim == 1)
101                 $th = array(_("Type"), _("#"), _("Date"), _("Dimension"),
102                         _("Person/Item"), _("Debit"), _("Credit"), _("Balance"), _("Memo"));
103         else
104                 $th = array(_("Type"), _("#"), _("Date"),
105                         _("Person/Item"), _("Debit"), _("Credit"), _("Balance"), _("Memo"));
106         table_header($th);
107         if (is_account_balancesheet($_POST["account"]))
108                 $begin = "";
109         else
110         {
111                 $begin = begin_fiscalyear();
112                 if ($_POST['TransFromDate'] < $begin)
113                         $begin = $_POST['TransFromDate'];
114                 $begin = add_days($begin, -1);
115         }
116
117     $bfw = get_gl_balance_from_to($begin, $_POST['TransFromDate'], $_POST["account"], $_POST['Dimension'], $_POST['Dimension2']);
118
119         start_row("class='inquirybg'");
120         label_cell("<b>"._("Opening Balance")." - ".$_POST['TransFromDate']."</b>", "colspan=$colspan");
121         display_debit_or_credit_cells($bfw);
122         label_cell("");
123         end_row();
124         //$running_total =0;
125         $running_total = $bfw;
126         $j = 1;
127         $k = 0; //row colour counter
128
129         while ($myrow = db_fetch($result))
130         {
131
132         alt_table_row_color($k);
133
134         $running_total += $myrow["amount"];
135
136         $trandate = sql2date($myrow["tran_date"]);
137
138         label_cell(systypes::name($myrow["type"]));
139                 label_cell(get_gl_view_str($myrow["type"], $myrow["type_no"], $myrow["type_no"], true));
140         label_cell($trandate);
141                 if ($dim >= 1)
142                         label_cell(get_dimension_string($myrow['dimension_id'], true));
143                 if ($dim > 1)
144                         label_cell(get_dimension_string($myrow['dimension2_id'], true));
145                 label_cell(payment_person_types::person_name($myrow["person_type_id"],$myrow["person_id"]));
146                 display_debit_or_credit_cells($myrow["amount"]);
147                 amount_cell($running_total);
148         label_cell($myrow['memo_']);
149         end_row();
150
151         $j++;
152         if ($j == 12)
153         {
154                 $j = 1;
155                 table_header($th);
156         }
157         }
158         //end of while loop
159
160         start_row("class='inquirybg'");
161         label_cell("<b>" . _("Ending Balance") ." - ".$_POST['TransToDate']. "</b>", "colspan=$colspan");
162         display_debit_or_credit_cells($running_total);
163         label_cell("");
164         end_row();
165
166         end_table(2);
167         if (db_num_rows($result) == 0)
168                 display_note(_("No general ledger transactions have been created for this account on the selected dates."), 0, 1);
169         div_end();
170 }
171
172 //----------------------------------------------------------------------------------------------------
173
174 gl_inquiry_controls();
175
176 show_results();
177
178 //----------------------------------------------------------------------------------------------------
179
180 end_page();
181
182 ?>