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