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