Additional conflict fixes after merge.
[fa-stable.git] / admin / view_print_transaction.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU Affero General Public License,
5         AGPL, as published by the Free Software Foundation, either version 
6         3 of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/agpl-3.0.html>.
11 ***********************************************************************/
12 $path_to_root="..";
13 $page_security = 5;
14
15 include_once($path_to_root . "/includes/session.inc");
16
17 include_once($path_to_root . "/includes/date_functions.inc");
18 include_once($path_to_root . "/includes/ui.inc");
19 include_once($path_to_root . "/includes/data_checks.inc");
20
21 include_once($path_to_root . "/reporting/includes/reporting.inc");
22 $js = "";
23 if ($use_popup_windows)
24         $js .= get_js_open_window(800, 500);
25 page(_("View or Print Transactions"), false, false, "", $js);
26
27 //----------------------------------------------------------------------------------------
28
29 function viewing_controls()
30 {
31         display_note(_("Only documents can be printed."));
32     start_form(false, true);
33
34     start_table("class='tablestyle_noborder'");
35         start_row();
36
37         systypes_list_cells(_("Type:"), 'filterType', null, true);
38
39         if (!isset($_POST['FromTransNo']))
40                 $_POST['FromTransNo'] = "1";
41         if (!isset($_POST['ToTransNo']))
42                 $_POST['ToTransNo'] = "999999";
43
44     ref_cells(_("from #:"), 'FromTransNo');
45
46     ref_cells(_("to #:"), 'ToTransNo');
47
48     submit_cells('ProcessSearch', _("Search"), '', '', true);
49
50         end_row();
51     end_table(1);
52
53         end_form();
54 }
55
56 //----------------------------------------------------------------------------------------
57
58 function check_valid_entries()
59 {
60         if (!is_numeric($_POST['FromTransNo']) OR $_POST['FromTransNo'] <= 0)
61         {
62                 display_error(_("The starting transaction number is expected to be numeric and greater than zero."));
63                 return false;
64         }
65
66         if (!is_numeric($_POST['ToTransNo']) OR $_POST['ToTransNo'] <= 0)
67         {
68                 display_error(_("The ending transaction number is expected to be numeric and greater than zero."));
69                 return false;
70         }
71         if (!isset($_POST['filterType']) || $_POST['filterType'] == "")
72                 return false;
73
74         return true;
75 }
76
77 //----------------------------------------------------------------------------------------
78
79 function handle_search()
80 {
81         global $table_style;
82         if (check_valid_entries()==true)
83         {
84                 $db_info = get_systype_db_info($_POST['filterType']);
85
86                 if ($db_info == null)
87                         return;
88
89                 $table_name = $db_info[0];
90                 $type_name = $db_info[1];
91                 $trans_no_name = $db_info[2];
92                 $trans_ref = $db_info[3];
93
94                 $sql = "SELECT DISTINCT $trans_no_name ";
95
96                 if ($trans_ref)
97                         $sql .= " ,$trans_ref ";
98
99                 $sql .= " FROM $table_name
100                         WHERE $trans_no_name >= " . $_POST['FromTransNo']. "
101                         AND  $trans_no_name <= " . $_POST['ToTransNo'];
102
103                 if ($type_name != null)
104                         $sql .= " AND $type_name = " . $_POST['filterType'];
105
106                 $sql .= " ORDER BY $trans_no_name";
107
108                 $result = db_query($sql, "could not query transactions on $table_name");
109
110                 if (db_num_rows($result) == 0)
111                 {
112                         display_notification(_("There are no transactions for the given parameters."));
113                         return;
114                 }
115                 $print_type = $_POST['filterType'];
116                 $print_out = ($print_type == 10 || $print_type == 11 || $print_type == systypes::cust_dispatch() ||
117                         $print_type == systypes::po() || $print_type == systypes::sales_order());
118                 if ($print_out)
119                 {
120                         if ($trans_ref)
121                                 $th = array(_("#"), _("Reference"), _("View"), _("Print"), _("GL"));
122                         else
123                                 $th = array(_("#"), _("View"), _("Print"), _("GL"));
124                 }
125                 else
126                 {
127                         if ($trans_ref)
128                                 $th = array(_("#"), _("Reference"), _("View"), _("GL"));
129                         else
130                                 $th = array(_("#"), _("View"), _("GL"));
131                 }
132                 div_start('transactions');
133                 start_table($table_style);
134                 table_header($th);
135                 $k = 0;
136                 while ($line = db_fetch($result))
137                 {
138
139                         alt_table_row_color($k);
140
141                         label_cell($line[$trans_no_name]);
142                         if ($trans_ref)
143                                 label_cell($line[$trans_ref]);
144                         label_cell(get_trans_view_str($_POST['filterType'],$line[$trans_no_name], _("View"), ICON_VIEW));
145                         if ($print_out)
146                                 label_cell(print_document_link($line[$trans_no_name], _("Print"), true, $print_type, ICON_PRINT));
147                 label_cell(get_gl_view_str($_POST['filterType'], $line[$trans_no_name]));
148
149                 end_row();
150
151                 }
152
153                 end_table();
154                 div_end();
155         }
156 }
157
158 //----------------------------------------------------------------------------------------
159
160 if (isset($_POST['ProcessSearch']))
161 {
162         if (!check_valid_entries())
163                 unset($_POST['ProcessSearch']);
164         $Ajax->activate('transactions');
165 }
166
167 //----------------------------------------------------------------------------------------
168
169 viewing_controls();
170
171 handle_search();
172
173 br(2);
174
175 end_page();
176
177 ?>