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