Fixed printing api.
[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                         if ($trans_ref)
112                                 $th = array(_("#"), _("Reference"), _("View"), _("Print"), _("GL"));
113                         else
114                                 $th = array(_("#"), _("View"), _("Print"), _("GL"));
115                 }
116                 else
117                 {
118                         if ($trans_ref)
119                                 $th = array(_("#"), _("Reference"), _("View"), _("GL"));
120                         else
121                                 $th = array(_("#"), _("View"), _("GL"));
122                 }
123                 div_start('transactions');
124                 start_table($table_style);
125                 table_header($th);
126                 $k = 0;
127                 while ($line = db_fetch($result))
128                 {
129
130                         alt_table_row_color($k);
131
132                         label_cell($line[$trans_no_name]);
133                         if ($trans_ref)
134                                 label_cell($line[$trans_ref]);
135                         label_cell(get_trans_view_str($_POST['filterType'],$line[$trans_no_name], _("View")));
136                         if ($print_out)
137                                 label_cell(print_document_link($line[$trans_no_name], _("Print"), true, $print_type));
138                 label_cell(get_gl_view_str($_POST['filterType'], $line[$trans_no_name], _("View GL")));
139
140                 end_row();
141
142                 }
143
144                 end_table();
145                 div_end();
146         }
147 }
148
149 //----------------------------------------------------------------------------------------
150
151 if (isset($_POST['ProcessSearch']))
152 {
153         if (!check_valid_entries())
154                 unset($_POST['ProcessSearch']);
155         $Ajax->activate('transactions');
156 }
157
158 //----------------------------------------------------------------------------------------
159
160 viewing_controls();
161
162 handle_search();
163
164 br(2);
165
166 end_page();
167
168 ?>