Bug 5187: Displaying the list of suppliers in the void part is either wrong or buggy...
[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 $page_security = 'SA_VIEWPRINTTRANSACTION';
13 $path_to_root = "..";
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 include_once($path_to_root . "/admin/db/transactions_db.inc");
22
23 include_once($path_to_root . "/reporting/includes/reporting.inc");
24 $js = "";
25 if ($SysPrefs->use_popup_windows)
26         $js .= get_js_open_window(800, 500);
27 page(_($help_context = "View or Print Transactions"), false, false, "", $js);
28
29 //----------------------------------------------------------------------------------------
30 function view_link($trans)
31 {
32         if (!isset($trans['type']))
33                 $trans['type'] = $_POST['filterType'];
34         return get_trans_view_str($trans["type"], $trans["trans_no"]);
35 }
36
37 function prt_link($row)
38 {
39         if (!isset($row['type']))
40                 $row['type'] = $_POST['filterType'];
41         if ($row['type'] == ST_PURCHORDER || $row['type'] == ST_SALESORDER || $row['type'] == ST_SALESQUOTE || 
42                 $row['type'] == ST_WORKORDER)
43                 return print_document_link($row['trans_no'], _("Print"), true, $row['type'], ICON_PRINT);
44         else    
45                 return print_document_link($row['trans_no']."-".$row['type'], _("Print"), true, $row['type'], ICON_PRINT);
46 }
47
48 function gl_view($row)
49 {
50         if (!isset($row['type']))
51                 $row['type'] = $_POST['filterType'];
52         return get_gl_view_str($row["type"], $row["trans_no"]);
53 }
54
55 function date_view($row)
56 {
57         return $row['trans_date'];
58 }
59
60 function ref_view($row)
61 {
62         return $row['ref'];
63 }
64
65 function viewing_controls()
66 {
67         display_note(_("Only documents can be printed."));
68
69     start_table(TABLESTYLE_NOBORDER);
70         start_row();
71
72         systypes_list_cells(_("Type:"), 'filterType', null, true, array(ST_CUSTOMER, ST_SUPPLIER));
73
74         if (!isset($_POST['FromTransNo']))
75                 $_POST['FromTransNo'] = "1";
76         if (!isset($_POST['ToTransNo']))
77                 $_POST['ToTransNo'] = "999999";
78
79     ref_cells(_("from #:"), 'FromTransNo');
80
81     ref_cells(_("to #:"), 'ToTransNo');
82
83     submit_cells('ProcessSearch', _("Search"), '', '', 'default');
84
85         end_row();
86     end_table(1);
87
88 }
89
90 //----------------------------------------------------------------------------------------
91
92 function check_valid_entries()
93 {
94         if (!is_numeric($_POST['FromTransNo']) OR $_POST['FromTransNo'] <= 0)
95         {
96                 display_error(_("The starting transaction number is expected to be numeric and greater than zero."));
97                 return false;
98         }
99
100         if (!is_numeric($_POST['ToTransNo']) OR $_POST['ToTransNo'] <= 0)
101         {
102                 display_error(_("The ending transaction number is expected to be numeric and greater than zero."));
103                 return false;
104         }
105
106         return true;
107 }
108
109 //----------------------------------------------------------------------------------------
110
111 function handle_search()
112 {
113         if (check_valid_entries()==true)
114         {
115                 $trans_ref = false;
116                 $sql = get_sql_for_view_transactions(get_post('filterType'), get_post('FromTransNo'), get_post('ToTransNo'), $trans_ref);
117                 if ($sql == "")
118                         return;
119
120                 $print_type = get_post('filterType');
121                 $print_out = ($print_type == ST_SALESINVOICE || $print_type == ST_CUSTCREDIT || $print_type == ST_CUSTDELIVERY ||
122                         $print_type == ST_PURCHORDER || $print_type == ST_SALESORDER || $print_type == ST_SALESQUOTE ||
123                         $print_type == ST_CUSTPAYMENT || $print_type == ST_SUPPAYMENT || $print_type == ST_WORKORDER);
124
125                 $cols = array(
126                         _("#") => array('insert'=>true, 'fun'=>'view_link'), 
127                         _("Reference") => array('fun'=>'ref_view'), 
128                         _("Date") => array('type'=>'date', 'fun'=>'date_view'),
129                         _("Print") => array('insert'=>true, 'fun'=>'prt_link'), 
130                         _("GL") => array('insert'=>true, 'fun'=>'gl_view')
131                 );
132                 if(!$print_out) {
133                         array_remove($cols, 3);
134                 }
135                 if(!$trans_ref) {
136                         array_remove($cols, 1);
137                 }
138
139                 $table =& new_db_pager('transactions', $sql, $cols);
140                 $table->width = "40%";
141                 display_db_pager($table);
142         }
143
144 }
145
146 //----------------------------------------------------------------------------------------
147
148 if (isset($_POST['ProcessSearch']))
149 {
150         if (!check_valid_entries())
151                 unset($_POST['ProcessSearch']);
152         $Ajax->activate('transactions');
153 }
154
155 //----------------------------------------------------------------------------------------
156
157 start_form(false);
158         viewing_controls();
159         handle_search();
160 end_form(2);
161
162 end_page();
163