Merging version 2.1 RC to main trunk.
[fa-stable.git] / admin / view_print_transaction.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         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/gpl-3.0.html>.
11 ***********************************************************************/
12 $path_to_root="..";
13 $page_security = 5;
14
15 include($path_to_root . "/includes/db_pager.inc");
16 include_once($path_to_root . "/includes/session.inc");
17
18 include_once($path_to_root . "/includes/date_functions.inc");
19 include_once($path_to_root . "/includes/ui.inc");
20 include_once($path_to_root . "/includes/data_checks.inc");
21
22 include_once($path_to_root . "/reporting/includes/reporting.inc");
23 $js = "";
24 if ($use_popup_windows)
25         $js .= get_js_open_window(800, 500);
26 page(_("View or Print Transactions"), false, false, "", $js);
27
28 //----------------------------------------------------------------------------------------
29 function view_link($trans)
30 {
31         return get_trans_view_str($trans["type"], $trans["trans_no"]);
32 }
33
34 function prt_link($row)
35 {
36         if ($row['type'] != 12 && $row['type'] != 2) // customer payment or bank deposit printout not defined yet.
37                 return print_document_link($row['trans_no'], _("Print"), true, $row['type'], ICON_PRINT);
38 }
39
40 function gl_view($row)
41 {
42         return get_gl_view_str($row["type"], $row["trans_no"]);
43 }
44
45 function viewing_controls()
46 {
47         display_note(_("Only documents can be printed."));
48
49     start_table("class='tablestyle_noborder'");
50         start_row();
51
52         systypes_list_cells(_("Type:"), 'filterType', null, true);
53
54         if (!isset($_POST['FromTransNo']))
55                 $_POST['FromTransNo'] = "1";
56         if (!isset($_POST['ToTransNo']))
57                 $_POST['ToTransNo'] = "999999";
58
59     ref_cells(_("from #:"), 'FromTransNo');
60
61     ref_cells(_("to #:"), 'ToTransNo');
62
63     submit_cells('ProcessSearch', _("Search"), '', '', true);
64
65         end_row();
66     end_table(1);
67
68 }
69
70 //----------------------------------------------------------------------------------------
71
72 function check_valid_entries()
73 {
74         if (!is_numeric($_POST['FromTransNo']) OR $_POST['FromTransNo'] <= 0)
75         {
76                 display_error(_("The starting transaction number is expected to be numeric and greater than zero."));
77                 return false;
78         }
79
80         if (!is_numeric($_POST['ToTransNo']) OR $_POST['ToTransNo'] <= 0)
81         {
82                 display_error(_("The ending transaction number is expected to be numeric and greater than zero."));
83                 return false;
84         }
85         if (!isset($_POST['filterType']) || $_POST['filterType'] == "")
86                 return false;
87
88         return true;
89 }
90
91 //----------------------------------------------------------------------------------------
92
93 function handle_search()
94 {
95         global $table_style;
96         if (check_valid_entries()==true)
97         {
98                 $db_info = get_systype_db_info($_POST['filterType']);
99
100                 if ($db_info == null)
101                         return;
102
103                 $table_name = $db_info[0];
104                 $type_name = $db_info[1];
105                 $trans_no_name = $db_info[2];
106                 $trans_ref = $db_info[3];
107
108                 $sql = "SELECT DISTINCT $trans_no_name as trans_no";
109
110                 if ($trans_ref)
111                         $sql .= " ,$trans_ref ";
112
113                 $sql .= ", ".$_POST['filterType']." as type FROM $table_name
114                         WHERE $trans_no_name >= " . $_POST['FromTransNo']. "
115                         AND  $trans_no_name <= " . $_POST['ToTransNo'];
116
117                 if ($type_name != null)
118                         $sql .= " AND `$type_name` = " . $_POST['filterType'];
119
120                 $sql .= " ORDER BY $trans_no_name";
121
122
123                 $print_type = $_POST['filterType'];
124                 $print_out = ($print_type == 10 || $print_type == 11 || $print_type == systypes::cust_dispatch() ||
125                         $print_type == systypes::po() || $print_type == systypes::sales_order());
126
127                 $cols = array(
128                         _("#"), 
129                         _("Reference"), 
130                         _("View") => array('insert'=>true, 'fun'=>'view_link'),
131                         _("Print") => array('insert'=>true, 'fun'=>'prt_link'), 
132                         _("GL") => array('insert'=>true, 'fun'=>'gl_view')
133                 );
134                 if(!$print_out) {
135                         array_remove($cols, 3);
136                 }
137                 if(!$trans_ref) {
138                         array_remove($cols, 1);
139                 }
140
141                 $table =& new_db_pager('transactions', $sql, $cols);
142                 if (list_updated('filterType')) {
143                         $table->set_sql($sql);
144                         $table->set_columns($cols);
145                 }
146                 $table->width = "40%";
147                 display_db_pager($table);
148         }
149
150 }
151
152 //----------------------------------------------------------------------------------------
153
154 if (isset($_POST['ProcessSearch']))
155 {
156         if (!check_valid_entries())
157                 unset($_POST['ProcessSearch']);
158         $Ajax->activate('transactions');
159 }
160
161 //----------------------------------------------------------------------------------------
162
163 start_form(false, true);
164         viewing_controls();
165         handle_search();
166 end_form(2);
167
168 end_page();
169
170 ?>