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