Fixed initialization of company specific settings in SysPrefs.
[fa-stable.git] / includes / prefs / sysprefs.inc
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         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/gpl-3.0.html>.
11 ***********************************************************************/
12 include_once($path_to_root . "/admin/db/company_db.inc");
13
14 /*
15         System and per company prefferences.
16         Object is created only with site wide preffernces.
17         After user login refresh_company_prefs method have to be called to initialize company specific settings.
18 */
19 class sys_prefs 
20 {
21         var $prefs;
22         var $db_ok; // check whether database has been upgraded after src update.
23
24         function sys_prefs()
25         {
26                 global $path_to_root, $db_version;
27
28                 // retrieve set system wide preferences
29                 include $path_to_root.'/config.default.php';
30                 if (file_exists($path_to_root.'/config.php'))
31                         include $path_to_root.'/config.php';
32
33                 foreach(get_defined_vars() as $name => $value)
34                         $this->$name = $value;
35
36                 if (!@$this->time_zone)
37                         $this->time_zone = ini_get('date.timezone');
38
39                 if (!$this->time_zone)
40                         $this->time_zone = 'Europe/Berlin';
41
42             ini_set('date.timezone', $this->time_zone);
43         }
44
45         /*
46                 Initialize company specific preferrencies.
47         */
48         function refresh_company_prefs()
49         {
50                 global $db_version;
51
52                 $sql = "SELECT name, value FROM ".TB_PREF."sys_prefs";
53                 $result = @db_query($sql); // supress errors before 2.3 db structure upgrade
54
55                 if(!$result)
56                         return null;
57
58                 while($pref = db_fetch_assoc($result)) {
59                         $this->prefs[$pref['name']] = $pref['value'];
60                 }
61
62                 // update current db status for info in log file
63                 $this->db_ok = $this->prefs['version_id'] == $db_version;
64         }
65
66         function allow_negative_stock() 
67         {
68                 return $this->prefs['allow_negative_stock'];
69         }
70
71     /* Sherifoz 26.06.03 Proportion by which items can be received over the quantity that is specified in a purchase
72     invoice
73     The figure entered is interpreted as a percentage ie 10 means 0.1 or 10% not 10 times
74     */
75         function over_receive_allowance() 
76         {
77                 return $this->prefs['po_over_receive'];
78         }
79         
80     /* Proportion by which a purchase invoice line is an overcharge for a purchase order item received
81     is an overcharge. If the overcharge is more than this percentage then an error is reported and
82     purchase invoice line cannot be entered
83     The figure entered is interpreted as a percentage ie 20 means 0.2 or 20% not 20 times
84     */  
85         function over_charge_allowance() 
86         {
87                 return $this->prefs['po_over_charge'];
88         }
89         
90         function default_credit_limit() 
91         {
92                 return $this->prefs['default_credit_limit'];
93         }                               
94         
95         function default_wo_required_by() 
96         {
97                 return $this->prefs['default_workorder_required'];
98         }
99
100         function default_quote_valid_days() 
101         {
102                 return $this->prefs['default_quote_valid_days'];
103         }
104
105         function default_delivery_required_by() 
106         {
107                 return $this->prefs['default_delivery_required'];
108         }
109
110         function default_receival_required_by() 
111         {
112                 return $this->prefs['default_receival_required'];
113         }
114
115         function default_dimension_required_by() 
116         {
117                 return $this->prefs['default_dim_required'];
118         }       
119         
120         function auto_currency_revaluation() 
121         {
122                 return $this->prefs['auto_curr_reval'];
123         }       
124         
125         function allocation_settled_allowance()
126         {
127                 return $this->config_allocation_settled_allowance;
128         }
129
130         function no_zero_lines_amount() 
131         {
132                 return $this->prefs['no_zero_lines_amount'];
133         }
134
135         function show_po_item_codes() 
136         {
137                 return $this->prefs['show_po_item_codes'];
138         }
139
140         function accounts_alpha() 
141         {
142                 return $this->prefs['accounts_alpha'];
143         }
144
145         function loc_notification() 
146         {
147                 return $this->prefs['loc_notification'];
148         }
149
150         function print_invoice_no() 
151         {
152                 return $this->prefs['print_invoice_no'];
153         }
154
155         function allow_negative_prices() 
156         {
157                 return $this->prefs['allow_negative_prices'];
158         }
159
160         function print_item_images_on_quote() 
161         {
162                 return $this->prefs['print_item_images_on_quote'];
163         }
164
165         function alternative_tax_include_on_docs() 
166         {
167                 return $this->prefs['alternative_tax_include_on_docs'];
168         }
169
170         function suppress_tax_rates() 
171         {
172                 return $this->prefs['suppress_tax_rates'];
173         }
174
175         function backup_dir($comp=null)
176         {
177                 if (!isset($comp))
178                         $comp = user_company();
179
180                 if (isset($this->backup_path))
181                         return sprintf($this->backup_path, $comp);
182                 else
183                         return $this->comp_path.'/'.$comp."/backup/";
184         }
185 }
186