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