*** empty log message ***
[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 page(_("View or Print Transactions"));
9
10 include_once($path_to_root . "/includes/date_functions.inc");
11 include_once($path_to_root . "/includes/ui.inc");
12 include_once($path_to_root . "/includes/data_checks.inc");
13
14 include_once($path_to_root . "/reporting/includes/reporting.inc");
15
16 //----------------------------------------------------------------------------------------
17
18 function viewing_controls()
19 {
20     start_form(false, true);
21
22     start_table("class='tablestyle_noborder'");
23         start_row();
24
25         systypes_list_cells(_("Type:"), 'filterType', null, true);
26
27     ref_cells(_("from #:"), 'FromTransNo');
28
29     ref_cells(_("to #:"), 'ToTransNo');
30
31     submit_cells('ProcessSearch', _("Search"));
32
33         end_row();
34     end_table(1);
35
36         end_form();
37 }
38
39 //----------------------------------------------------------------------------------------
40
41 function check_valid_entries()
42 {
43         if (!is_numeric($_POST['FromTransNo']) OR $_POST['FromTransNo'] <= 0)
44         {
45                 display_note(_("The starting transaction number is expected to be numeric and greater than zero."));
46                 return false;
47         }
48
49         if (!is_numeric($_POST['ToTransNo']) OR $_POST['ToTransNo'] <= 0)
50         {
51                 echo _("The ending transaction number is expected to be numeric and greater than zero.");
52                 return false;
53         }
54
55         return true;
56 }
57
58 //----------------------------------------------------------------------------------------
59
60 function handle_search()
61 {
62         global $table_style;
63         if (check_valid_entries()==true)
64         {
65                 $db_info = get_systype_db_info($_POST['filterType']);
66
67                 $table_name = $db_info[0];
68                 $type_name = $db_info[1];
69                 $trans_no_name = $db_info[2];
70                 $trans_ref = $db_info[3];
71
72                 $sql = "SELECT DISTINCT $trans_no_name ";
73
74                 if ($trans_ref)
75                         $sql .= " ,$trans_ref ";
76
77                 $sql .= " FROM $table_name
78                         WHERE $trans_no_name >= " . $_POST['FromTransNo']. "
79                         AND  $trans_no_name <= " . $_POST['ToTransNo'];
80
81                 if ($type_name != null)
82                         $sql .= " AND $type_name = " . $_POST['filterType'];
83
84                 $sql .= " ORDER BY $trans_no_name";
85
86                 $result = db_query($sql, "could not query transactions on $table_name");
87
88                 if (db_num_rows($result) == 0) 
89                 {
90                         echo _("There are no transactions for the given parameters.");
91                         return;
92                 }
93
94                 start_table($table_style);
95                 if ($trans_ref)
96                         $th = array(_("#"), _("Reference"), _("View"), _("Print"));
97                 else    
98                         $th = array(_("#"), _("View"), _("Print"));
99                 table_header($th);      
100                 $k = 0;
101                 while ($line = db_fetch($result)) 
102                 {
103
104                         alt_table_row_color($k);
105
106                         label_cell($line[$trans_no_name]);
107                         if ($trans_ref)
108                                 label_cell($line[$trans_ref]);
109                         label_cell(get_trans_view_str($_POST['filterType'],$line[$trans_no_name], _("View")));
110                 label_cell(get_gl_view_str_cell($_POST['filterType'], $line[$trans_no_name], _("View GL")));
111
112                 $forms = get_form_entries($_POST['filterType'], $line[$trans_no_name]);
113                 while ($form_item = db_fetch($forms)) 
114                 {
115
116                         $param1 = $form_item['param1'];
117                         $param2 = $form_item['param2'];
118
119                         if ($_POST['filterType'] == systypes::bank_payment()
120                                 || $_POST['filterType'] == systypes::bank_deposit()
121                                 || $_POST['filterType'] == systypes::cust_payment()
122                                 || $_POST['filterType'] == systypes::supp_payment()) 
123                         {
124                                 $param1 = payment_person_types::type_name($form_item['param1']);
125                                 $param2 = payment_person_types::person_name($form_item['param1'], $form_item['param2'], false);
126                         }
127
128                         //label_cell(printTransaction(_("Print") . " " . getFormTypeName($form_item["form_type"]), $form_item['form_id'], $form_item['form_type'], $_POST['filterType'], $line[$trans_no_name], $line[$trans_ref], $param1, $param2));
129                 }
130                 end_row();
131
132                 }
133
134                 end_table();
135         }
136 }
137
138 //----------------------------------------------------------------------------------------
139
140 if (isset($_POST['ProcessSearch']))
141 {
142         if (!check_valid_entries())
143                 unset($_POST['ProcessSearch']);
144 }
145
146 //----------------------------------------------------------------------------------------
147
148 viewing_controls();
149
150 //echo getHiddenFieldScript();
151
152 handle_search();
153
154 br(2);
155
156 end_page();
157
158 ?>