Minor change in menu and function in view_print_transaction.php
[fa-stable.git] / admin / view_print_transaction.php
1 <?php
2
3 $path_to_root="..";
4 $page_security = 5;
5
6 include_once($path_to_root . "/includes/session.inc");
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 . "/reporting/includes/reporting.inc");
13 $js = "";
14 if ($use_popup_windows)
15         $js .= get_js_open_window(800, 500);
16 page(_("View Transactions"), false, false, "", $js);
17
18 //----------------------------------------------------------------------------------------
19
20 function viewing_controls()
21 {
22     start_form(false, true);
23
24     start_table("class='tablestyle_noborder'");
25         start_row();
26
27         systypes_list_cells(_("Type:"), 'filterType', null, true);
28
29         if (!isset($_POST['FromTransNo']))
30                 $_POST['FromTransNo'] = "1";
31         if (!isset($_POST['ToTransNo']))
32                 $_POST['ToTransNo'] = "999999";
33
34     ref_cells(_("from #:"), 'FromTransNo');
35
36     ref_cells(_("to #:"), 'ToTransNo');
37
38     submit_cells('ProcessSearch', _("Search"));
39
40         end_row();
41     end_table(1);
42
43         end_form();
44 }
45
46 //----------------------------------------------------------------------------------------
47
48 function check_valid_entries()
49 {
50         if (!is_numeric($_POST['FromTransNo']) OR $_POST['FromTransNo'] <= 0)
51         {
52                 display_note(_("The starting transaction number is expected to be numeric and greater than zero."));
53                 return false;
54         }
55
56         if (!is_numeric($_POST['ToTransNo']) OR $_POST['ToTransNo'] <= 0)
57         {
58                 echo _("The ending transaction number is expected to be numeric and greater than zero.");
59                 return false;
60         }
61         if ($_POST['filterType'] == "")
62                 return false;
63
64         return true;
65 }
66
67 //----------------------------------------------------------------------------------------
68
69 function handle_search()
70 {
71         global $table_style;
72         if (check_valid_entries()==true)
73         {
74                 $db_info = get_systype_db_info($_POST['filterType']);
75
76                 if ($db_info == null)
77                         return;
78
79                 $table_name = $db_info[0];
80                 $type_name = $db_info[1];
81                 $trans_no_name = $db_info[2];
82                 $trans_ref = $db_info[3];
83
84                 $sql = "SELECT DISTINCT $trans_no_name ";
85
86                 if ($trans_ref)
87                         $sql .= " ,$trans_ref ";
88
89                 $sql .= " FROM $table_name
90                         WHERE $trans_no_name >= " . $_POST['FromTransNo']. "
91                         AND  $trans_no_name <= " . $_POST['ToTransNo'];
92
93                 if ($type_name != null)
94                         $sql .= " AND $type_name = " . $_POST['filterType'];
95
96                 $sql .= " ORDER BY $trans_no_name";
97
98                 $result = db_query($sql, "could not query transactions on $table_name");
99
100                 if (db_num_rows($result) == 0)
101                 {
102                         echo _("There are no transactions for the given parameters.");
103                         return;
104                 }
105
106                 start_table($table_style);
107                 if ($trans_ref)
108                         $th = array(_("#"), _("Reference"), _("View"), _("GL"));
109                 else
110                         $th = array(_("#"), _("View"), _("GL"));
111                 table_header($th);
112                 $k = 0;
113                 while ($line = db_fetch($result))
114                 {
115
116                         alt_table_row_color($k);
117
118                         label_cell($line[$trans_no_name]);
119                         if ($trans_ref)
120                                 label_cell($line[$trans_ref]);
121                         label_cell(get_trans_view_str($_POST['filterType'],$line[$trans_no_name], _("View")));
122                 label_cell(get_gl_view_str($_POST['filterType'], $line[$trans_no_name], _("View GL")));
123
124                 end_row();
125
126                 }
127
128                 end_table();
129         }
130 }
131
132 //----------------------------------------------------------------------------------------
133
134 if (isset($_POST['ProcessSearch']))
135 {
136         if (!check_valid_entries())
137                 unset($_POST['ProcessSearch']);
138 }
139
140 //----------------------------------------------------------------------------------------
141
142 viewing_controls();
143
144 handle_search();
145
146 br(2);
147
148 end_page();
149
150 ?>