29c1caf900da1f9159155fbdaef176fa989c69c9
[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='$debtors_act', pyt_discount_act='$pyt_discount_act',
26                 creditors_act='$creditors_act', grn_act='$grn_act',
27                 exchange_diff_act='$exchange_diff_act',
28                 purch_exchange_diff_act='$purch_exchange_diff_act',
29                 retained_earnings_act='$retained_earnings_act',
30                 freight_act='$freight_act',
31                 default_sales_act='$default_sales_act',
32                 default_sales_discount_act='$default_sales_discount_act',
33                 default_prompt_payment_act='$default_prompt_payment_act',
34                 default_inventory_act='$default_inventory_act',
35                 default_cogs_act='$default_cogs_act',
36                 default_adj_act='$default_adj_act',
37                 default_inv_sales_act='$default_inv_sales_act',
38                 default_assembly_act='$default_assembly_act',
39                 payroll_act='$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)
56 {
57         if ($f_year == null)
58                 $f_year = 0;
59         $sql = "UPDATE ".TB_PREF."company SET coy_name='$coy_name',
60                 coy_no = '$coy_no',
61                 gst_no='$gst_no',
62                 tax_prd=$tax_prd,
63                 tax_last=$tax_last,
64                 postal_address ='$postal_address',
65                 phone='$phone', fax='$fax',
66                 email='$email',
67                 coy_logo='$coy_logo',
68                 domicile='$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='$custom1_name',
74         custom2_name='$custom2_name',
75         custom3_name='$custom3_name',
76         custom1_value='$custom1_value',
77         custom2_value='$custom2_value',
78         custom3_value='$custom3_value',
79                 curr_default='$curr_default',
80                 f_year=$f_year
81                 WHERE coy_code=1";
82
83         db_query($sql, "The company setup could not be updated ");
84 }
85
86 function get_company_prefs()
87 {
88         $sql = "SELECT * FROM ".TB_PREF."company WHERE coy_code=1";
89         $result = db_query($sql, "The company preferences could not be retrieved");
90
91         if (db_num_rows($result) == 0)
92                 display_db_error("FATAL : Could not find company prefs", $sql);
93
94         return db_fetch($result);
95 }
96
97 function get_company_pref($pref_name)
98 {
99         $prefs = get_company_prefs();
100         return $prefs[$pref_name];
101 }
102
103 // fiscal year routines
104 function add_fiscalyear($from_date, $to_date, $closed)
105 {
106         $from = date2sql($from_date);
107         $to = date2sql($to_date);
108
109         $sql = "INSERT INTO ".TB_PREF."fiscal_year (begin, end, closed)
110                 VALUES ('$from', '$to', $closed)";
111
112         db_query($sql, "could not add fiscal year");
113 }
114
115 function update_fiscalyear($from_date, $closed)
116 {
117         $from = date2sql($from_date);
118
119         $sql = "UPDATE ".TB_PREF."fiscal_year SET closed=$closed
120                 WHERE begin='$from'";
121
122         db_query($sql, "could not update fiscal year");
123 }
124
125 function get_all_fiscalyears()
126 {
127         $sql = "SELECT * FROM ".TB_PREF."fiscal_year ORDER BY begin";
128
129         return db_query($sql, "could not get all fiscal years");
130 }
131
132 function get_fiscalyear($from_date)
133 {
134         $from = date2sql($from_date);
135
136         $sql = "SELECT * FROM ".TB_PREF."fiscal_year WHERE begin='$from'";
137
138         $result = db_query($sql, "could not get fiscal year");
139
140         return db_fetch($result);
141 }
142
143 function get_current_fiscalyear()
144 {
145         $year = get_company_pref('f_year');
146
147         $sql = "SELECT * FROM ".TB_PREF."fiscal_year WHERE id=$year";
148
149         $result = db_query($sql, "could not get current fiscal year");
150
151         return db_fetch($result);
152 }
153
154 function delete_fiscalyear($from_date)
155 {
156         $from = date2sql($from_date);
157         begin_transaction();
158
159         $sql="DELETE FROM ".TB_PREF."fiscal_year WHERE begin='$from'";
160
161         db_query($sql, "could not delete fiscal year");
162
163         commit_transaction();
164 }
165
166
167 ?>