09814938f1386bf9ed2a2af72d3f0a5c0286fff3
[fa-stable.git] / admin / db / transactions_db.inc
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
13 //--------------------------------------------------------------------------------------
14
15 function get_sql_for_view_transactions($filtertype, $from, $to, &$trans_ref)
16 {
17         $db_info = get_systype_db_info($filtertype);
18
19         if ($db_info == null)
20                 return "";
21
22         $table_name = $db_info[0];
23         $type_name = $db_info[1];
24         $trans_no_name = $db_info[2];
25         $trans_ref = $db_info[3];
26
27         $sql = "SELECT DISTINCT $trans_no_name as trans_no";
28
29         if ($trans_ref)
30                 $sql .= " ,$trans_ref ";
31
32         $sql .= ", ".$filtertype." as type FROM $table_name
33                 WHERE $trans_no_name >= ".db_escape($from). "
34                 AND  $trans_no_name <= ".db_escape($to);
35
36         if ($type_name != null)
37                 $sql .= " AND `$type_name` = ".db_escape($filtertype);
38
39         $sql .= " ORDER BY $trans_no_name";
40         return $sql;
41 }
42
43 ?>