Security update merged from 2.1.
[fa-stable.git] / admin / db / company_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 function update_company_gl_setup($retained_act, $profit_loss_act, $debtors_act, $pyt_discount_act, $creditors_act,
14                 $freight_act,
15                 $exchange_diff_act,
16                 $bank_charge_act,
17                 $default_sales_act,
18                 $default_sales_discount_act,
19                 $default_prompt_payment_act,
20                 $default_inventory_act,
21                 $default_cogs_act,
22                 $default_adj_act,
23                 $default_inv_sales_act,
24                 $default_assembly_act,
25                 $allow_negative_stock,
26                 $po_over_receive,
27                 $po_over_charge,
28                 $accumulate_shipping,
29                 $legal_text,
30                 $past_due_days,
31                 $default_credit_limit,
32                 $default_workorder_required,
33                 $default_dim_required,
34                 $default_delivery_required)
35 {
36         $sql = "UPDATE ".TB_PREF."company SET
37                 retained_earnings_act=".db_escape($retained_act).", profit_loss_year_act=".db_escape($profit_loss_act).",
38                 debtors_act=".db_escape($debtors_act).", pyt_discount_act=".db_escape($pyt_discount_act).",
39                 creditors_act=".db_escape($creditors_act).",
40                 freight_act=".db_escape($freight_act).",
41                 exchange_diff_act=".db_escape($exchange_diff_act).",
42                 bank_charge_act=".db_escape($bank_charge_act).",
43                 default_sales_act=".db_escape($default_sales_act).",
44                 default_sales_discount_act=".db_escape($default_sales_discount_act).",
45                 default_prompt_payment_act=".db_escape($default_prompt_payment_act).",
46                 default_inventory_act=".db_escape($default_inventory_act).",
47                 default_cogs_act=".db_escape($default_cogs_act).",
48                 default_adj_act=".db_escape($default_adj_act).",
49                 default_inv_sales_act=".db_escape($default_inv_sales_act).",
50                 default_assembly_act=".db_escape($default_assembly_act).",
51                 allow_negative_stock=$allow_negative_stock,
52                 po_over_receive=$po_over_receive,
53                 po_over_charge=$po_over_charge,
54                 accumulate_shipping=$accumulate_shipping,
55                 legal_text=".db_escape($legal_text).",
56                 past_due_days=$past_due_days,
57                 default_credit_limit=$default_credit_limit,
58                 default_workorder_required=$default_workorder_required,
59                 default_dim_required=$default_dim_required,
60                 default_delivery_required=$default_delivery_required
61                 WHERE coy_code=1";
62
63         db_query($sql, "The company gl setup could not be updated ");
64 }
65
66 function update_company_setup($coy_name, $coy_no, $gst_no, $tax_prd, $tax_last, 
67         $postal_address, $phone, $fax, $email, $coy_logo, $domicile, $Dimension, 
68         $curr_default, $f_year, $no_item_list, $no_customer_list, $no_supplier_list, 
69         $base_sales, $time_zone, $add_pct, $round_to, $login_tout)
70 {
71         if ($f_year == null)
72                 $f_year = 0;
73         $sql = "UPDATE ".TB_PREF."company SET coy_name=".db_escape($coy_name).",
74                 coy_no = ".db_escape($coy_no).",
75                 gst_no=".db_escape($gst_no).",
76                 tax_prd=$tax_prd,
77                 tax_last=$tax_last,
78                 postal_address =".db_escape($postal_address).",
79                 phone=".db_escape($phone).", fax=".db_escape($fax).",
80                 email=".db_escape($email).",
81                 coy_logo=".db_escape($coy_logo).",
82                 domicile=".db_escape($domicile).",
83                 use_dimension=$Dimension,
84                 no_item_list=$no_item_list,
85                 no_customer_list=$no_customer_list,
86                 no_supplier_list=$no_supplier_list,
87                 curr_default=".db_escape($curr_default).",
88                 f_year=$f_year,
89                 base_sales=$base_sales,
90                 time_zone=$time_zone,
91                 add_pct=$add_pct,
92                 round_to=$round_to,
93                 login_tout = ".db_escape($login_tout)."
94                 WHERE coy_code=1";
95
96         db_query($sql, "The company setup could not be updated ");
97 }
98
99 function get_company_prefs($tbpref = TB_PREF)
100 {
101         $sql = "SELECT * FROM ".$tbpref."company WHERE coy_code=1";
102         
103         $result = db_query($sql, "The company preferences could not be retrieved");
104
105         if (db_num_rows($result) == 0)
106                 display_db_error("FATAL : Could not find company prefs", $sql);
107
108         return db_fetch($result);
109 }
110
111 function get_company_pref($pref_name, $tbpref = TB_PREF)
112 {
113         $prefs = get_company_prefs($tbpref);
114         return $prefs[$pref_name];
115 }
116
117 // fiscal year routines
118 function add_fiscalyear($from_date, $to_date, $closed)
119 {
120         $from = date2sql($from_date);
121         $to = date2sql($to_date);
122
123         $sql = "INSERT INTO ".TB_PREF."fiscal_year (begin, end, closed)
124                 VALUES (".db_escape($from).",".db_escape($to).", ".db_escape($closed).")";
125
126         db_query($sql, "could not add fiscal year");
127 }
128
129 function update_fiscalyear($id, $closed)
130 {
131         $sql = "UPDATE ".TB_PREF."fiscal_year SET closed=".db_escape($closed)."
132                 WHERE id=".db_escape($id);
133
134         db_query($sql, "could not update fiscal year");
135 }
136
137 function get_all_fiscalyears()
138 {
139         $sql = "SELECT * FROM ".TB_PREF."fiscal_year ORDER BY begin";
140
141         return db_query($sql, "could not get all fiscal years");
142 }
143
144 function get_fiscalyear($id)
145 {
146         $sql = "SELECT * FROM ".TB_PREF."fiscal_year WHERE id=".db_escape($id);
147
148         $result = db_query($sql, "could not get fiscal year");
149
150         return db_fetch($result);
151 }
152
153 function get_current_fiscalyear()
154 {
155         $year = get_company_pref('f_year');
156
157         $sql = "SELECT * FROM ".TB_PREF."fiscal_year WHERE id=".db_escape($year);
158
159         $result = db_query($sql, "could not get current fiscal year");
160
161         return db_fetch($result);
162 }
163
164 function delete_fiscalyear($id)
165 {
166         begin_transaction();
167
168         $sql="DELETE FROM ".TB_PREF."fiscal_year WHERE id=".db_escape($id);
169
170         db_query($sql, "could not delete fiscal year");
171
172         commit_transaction();
173 }
174
175 function get_base_sales_type()
176 {
177         $sql = "SELECT base_sales FROM ".TB_PREF."company WHERE coy_code=1";
178
179         $result = db_query($sql, "could not get base sales type");
180         $myrow = db_fetch($result);
181         return $myrow[0];
182 }
183
184 function get_company_extensions($id = -1) {
185         global $path_to_root;
186
187         $file = $path_to_root.($id == -1 ? '' : '/company/'.$id).'/installed_extensions.php';
188         $installed_extensions = array();
189         if (is_file($file)) {
190                 include($file);
191         }
192         return $installed_extensions;
193 }
194
195
196 ?>