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