Moved all SQL statements from PHP files into relevant *_db.inc files.
[fa-stable.git] / gl / includes / db / gl_db_currencies.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 function update_currency($curr_abrev, $symbol, $currency, $country, 
15         $hundreds_name, $auto_update)
16 {
17         $sql = "UPDATE ".TB_PREF."currencies SET currency=".db_escape($currency)
18                 .", curr_symbol=".db_escape($symbol).", country=".db_escape($country)
19                 .", hundreds_name=".db_escape($hundreds_name)
20                 .",auto_update = ".db_escape($auto_update)
21                         ." WHERE curr_abrev = ".db_escape($curr_abrev);
22
23         db_query($sql, "could not update currency for $curr_abrev");
24 }
25
26 //---------------------------------------------------------------------------------------------
27
28 function add_currency($curr_abrev, $symbol, $currency, $country, 
29         $hundreds_name, $auto_update)
30 {
31         $sql = "INSERT INTO ".TB_PREF."currencies (curr_abrev, curr_symbol, currency, 
32                         country, hundreds_name, auto_update)
33                 VALUES (".db_escape($curr_abrev).", ".db_escape($symbol).", "
34                 .db_escape($currency).", ".db_escape($country).", "
35                 .db_escape($hundreds_name).",".db_escape($auto_update).")";
36
37         db_query($sql, "could not add currency for $curr_abrev");
38 }
39
40 //---------------------------------------------------------------------------------------------
41
42 function delete_currency($curr_code)
43 {
44         $sql="DELETE FROM ".TB_PREF."currencies WHERE curr_abrev=".db_escape($curr_code);
45         db_query($sql, "could not delete currency       $curr_code");
46
47         $sql="DELETE FROM ".TB_PREF."exchange_rates WHERE curr_code='$curr_code'";
48         db_query($sql, "could not delete exchange rates for currency $curr_code");
49 }
50
51 //---------------------------------------------------------------------------------------------
52
53 function get_currency($curr_code)
54 {
55         $sql = "SELECT * FROM ".TB_PREF."currencies WHERE curr_abrev=".db_escape($curr_code);
56         $result = db_query($sql, "could not get currency $curr_code");
57
58         $row = db_fetch($result);
59         return $row;
60 }
61
62 //---------------------------------------------------------------------------------------------
63
64 function get_currencies($all=false)
65 {
66         $sql = "SELECT * FROM ".TB_PREF."currencies";
67         if (!$all) $sql .= " WHERE !inactive";
68         return db_query($sql, "could not get currencies");
69 }
70
71 //---------------------------------------------------------------------------------------------
72
73 function currency_in_debtors($curr)
74 {
75         $sql= "SELECT COUNT(*) FROM ".TB_PREF."debtors_master WHERE curr_code = $curr";
76         $result = db_query($sql);
77         $myrow = db_fetch_row($result);
78         return ($myrow[0] > 0); 
79 }
80
81 function currency_in_suppliers($curr)
82 {
83         $sql= "SELECT COUNT(*) FROM ".TB_PREF."suppliers WHERE curr_code = $curr";
84         $result = db_query($sql);
85         $myrow = db_fetch_row($result);
86         return ($myrow[0] > 0); 
87 }
88
89 function currency_in_bank_accounts($curr)
90 {
91         $sql= "SELECT COUNT(*) FROM ".TB_PREF."bank_accounts WHERE bank_curr_code = $curr";
92         $result = db_query($sql);
93         $myrow = db_fetch_row($result);
94         return ($myrow[0] > 0); 
95 }
96
97 function currency_in_company($curr)
98 {
99         $sql= "SELECT COUNT(*) FROM ".TB_PREF."company WHERE curr_default = $curr";
100         $result = db_query($sql);
101         $myrow = db_fetch_row($result);
102         return ($myrow[0] > 0); 
103 }
104 ?>