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