Added ajax extensions
[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 or Print Transactions"), false, false, "", $js);
17
18 //----------------------------------------------------------------------------------------
19
20 function viewing_controls()
21 {
22         display_note(_("Only documents can be printed."));
23     start_form(false, true);
24
25     start_table("class='tablestyle_noborder'");
26         start_row();
27
28         systypes_list_cells(_("Type:"), 'filterType', null, true);
29
30         if (!isset($_POST['FromTransNo']))
31                 $_POST['FromTransNo'] = "1";
32         if (!isset($_POST['ToTransNo']))
33                 $_POST['ToTransNo'] = "999999";
34
35     ref_cells(_("from #:"), 'FromTransNo');
36
37     ref_cells(_("to #:"), 'ToTransNo');
38
39     submit_cells('ProcessSearch', _("Search"), '', '', true);
40
41         end_row();
42     end_table(1);
43
44         end_form();
45 }
46
47 //----------------------------------------------------------------------------------------
48
49 function check_valid_entries()
50 {
51         if (!is_numeric($_POST['FromTransNo']) OR $_POST['FromTransNo'] <= 0)
52         {
53                 display_note(_("The starting transaction number is expected to be numeric and greater than zero."));
54                 return false;
55         }
56
57         if (!is_numeric($_POST['ToTransNo']) OR $_POST['ToTransNo'] <= 0)
58         {
59                 echo _("The ending transaction number is expected to be numeric and greater than zero.");
60                 return false;
61         }
62         if (!isset($_POST['filterType']) || $_POST['filterType'] == "")
63                 return false;
64
65         return true;
66 }
67
68 //----------------------------------------------------------------------------------------
69
70 function handle_search()
71 {
72         global $table_style;
73         if (check_valid_entries()==true)
74         {
75                 $db_info = get_systype_db_info($_POST['filterType']);
76
77                 if ($db_info == null)
78                         return;
79
80                 $table_name = $db_info[0];
81                 $type_name = $db_info[1];
82                 $trans_no_name = $db_info[2];
83                 $trans_ref = $db_info[3];
84
85                 $sql = "SELECT DISTINCT $trans_no_name ";
86
87                 if ($trans_ref)
88                         $sql .= " ,$trans_ref ";
89
90                 $sql .= " FROM $table_name
91                         WHERE $trans_no_name >= " . $_POST['FromTransNo']. "
92                         AND  $trans_no_name <= " . $_POST['ToTransNo'];
93
94                 if ($type_name != null)
95                         $sql .= " AND $type_name = " . $_POST['filterType'];
96
97                 $sql .= " ORDER BY $trans_no_name";
98
99                 $result = db_query($sql, "could not query transactions on $table_name");
100
101                 if (db_num_rows($result) == 0)
102                 {
103                         echo _("There are no transactions for the given parameters.");
104                         return;
105                 }
106                 $print_type = $_POST['filterType'];
107                 $print_out = ($print_type == 10 || $print_type == 11 || $print_type == systypes::cust_dispatch() ||
108                         $print_type == systypes::po() || $print_type == systypes::sales_order());
109                 if ($print_out)
110                 {
111                         print_hidden_script($print_type);
112                         if ($trans_ref)
113                                 $th = array(_("#"), _("Reference"), _("View"), _("Print"), _("GL"));
114                         else
115                                 $th = array(_("#"), _("View"), _("Print"), _("GL"));
116                 }
117                 else
118                 {
119                         if ($trans_ref)
120                                 $th = array(_("#"), _("Reference"), _("View"), _("GL"));
121                         else
122                                 $th = array(_("#"), _("View"), _("GL"));
123                 }
124                 div_start('transactions');
125                 start_table($table_style);
126                 table_header($th);
127                 $k = 0;
128                 while ($line = db_fetch($result))
129                 {
130
131                         alt_table_row_color($k);
132
133                         label_cell($line[$trans_no_name]);
134                         if ($trans_ref)
135                                 label_cell($line[$trans_ref]);
136                         label_cell(get_trans_view_str($_POST['filterType'],$line[$trans_no_name], _("View")));
137                         if ($print_out)
138                                 label_cell(print_document_link($line[$trans_no_name], _("Print"), true, $print_type));
139                 label_cell(get_gl_view_str($_POST['filterType'], $line[$trans_no_name], _("View GL")));
140
141                 end_row();
142
143                 }
144
145                 end_table();
146                 div_end();
147         }
148 }
149
150 //----------------------------------------------------------------------------------------
151
152 if (isset($_POST['ProcessSearch']))
153 {
154         if (!check_valid_entries())
155                 unset($_POST['ProcessSearch']);
156         $Ajax->activate('transactions');
157 }
158
159 //----------------------------------------------------------------------------------------
160
161 viewing_controls();
162
163 handle_search();
164
165 br(2);
166
167 end_page();
168
169 ?>