Moved all SQL statements from PHP files into relevant *_db.inc files.
[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 ($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         return get_trans_view_str($trans["type"], $trans["trans_no"]);
33 }
34
35 function prt_link($row)
36 {
37         if ($row['type'] != ST_CUSTPAYMENT && $row['type'] != ST_BANKDEPOSIT) // customer payment or bank deposit printout not defined yet.
38                 return print_document_link($row['trans_no'], _("Print"), true, $row['type'], ICON_PRINT);
39 }
40
41 function gl_view($row)
42 {
43         return get_gl_view_str($row["type"], $row["trans_no"]);
44 }
45
46 function viewing_controls()
47 {
48         display_note(_("Only documents can be printed."));
49
50     start_table("class='tablestyle_noborder'");
51         start_row();
52
53         systypes_list_cells(_("Type:"), 'filterType', null, true);
54
55         if (!isset($_POST['FromTransNo']))
56                 $_POST['FromTransNo'] = "1";
57         if (!isset($_POST['ToTransNo']))
58                 $_POST['ToTransNo'] = "999999";
59
60     ref_cells(_("from #:"), 'FromTransNo');
61
62     ref_cells(_("to #:"), 'ToTransNo');
63
64     submit_cells('ProcessSearch', _("Search"), '', '', 'default');
65
66         end_row();
67     end_table(1);
68
69 }
70
71 //----------------------------------------------------------------------------------------
72
73 function check_valid_entries()
74 {
75         if (!is_numeric($_POST['FromTransNo']) OR $_POST['FromTransNo'] <= 0)
76         {
77                 display_error(_("The starting transaction number is expected to be numeric and greater than zero."));
78                 return false;
79         }
80
81         if (!is_numeric($_POST['ToTransNo']) OR $_POST['ToTransNo'] <= 0)
82         {
83                 display_error(_("The ending transaction number is expected to be numeric and greater than zero."));
84                 return false;
85         }
86
87         return true;
88 }
89
90 //----------------------------------------------------------------------------------------
91
92 function handle_search()
93 {
94         global $table_style;
95         if (check_valid_entries()==true)
96         {
97                 $trans_ref = false;
98                 $sql = get_sql_for_view_transactions($_POST['filterType'], $_POST['FromTransNo'], $_POST['ToTransNo'], $trans_ref);
99                 if ($sql == "")
100                         return;
101
102                 $print_type = $_POST['filterType'];
103                 $print_out = ($print_type == ST_SALESINVOICE || $print_type == ST_CUSTCREDIT || $print_type == ST_CUSTDELIVERY ||
104                         $print_type == ST_PURCHORDER || $print_type == ST_SALESORDER || $print_type == ST_SALESQUOTE);
105
106                 $cols = array(
107                         _("#"), 
108                         _("Reference"), 
109                         _("View") => array('insert'=>true, 'fun'=>'view_link'),
110                         _("Print") => array('insert'=>true, 'fun'=>'prt_link'), 
111                         _("GL") => array('insert'=>true, 'fun'=>'gl_view')
112                 );
113                 if(!$print_out) {
114                         array_remove($cols, 3);
115                 }
116                 if(!$trans_ref) {
117                         array_remove($cols, 1);
118                 }
119
120                 $table =& new_db_pager('transactions', $sql, $cols);
121                 $table->width = "40%";
122                 display_db_pager($table);
123         }
124
125 }
126
127 //----------------------------------------------------------------------------------------
128
129 if (isset($_POST['ProcessSearch']))
130 {
131         if (!check_valid_entries())
132                 unset($_POST['ProcessSearch']);
133         $Ajax->activate('transactions');
134 }
135
136 //----------------------------------------------------------------------------------------
137
138 start_form(false);
139         viewing_controls();
140         handle_search();
141 end_form(2);
142
143 end_page();
144
145 ?>