07a568689f25ee885fd4a63aab7151a67b2b66a0
[fa-stable.git] / admin / company_preferences.php
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 $page_security = 'SA_SETUPCOMPANY';
13 $path_to_root = "..";
14 include($path_to_root . "/includes/session.inc");
15
16 page(_($help_context = "Company Setup"));
17
18 include_once($path_to_root . "/includes/date_functions.inc");
19 include_once($path_to_root . "/includes/ui.inc");
20
21 include_once($path_to_root . "/admin/db/company_db.inc");
22 include_once($path_to_root . "/reporting/includes/tcpdf.php");
23 //-------------------------------------------------------------------------------------------------
24
25 if (isset($_POST['update']) && $_POST['update'] != "")
26 {
27         $input_error = 0;
28         if (!check_num('login_tout', 10))
29         {
30                 display_error(_("Login timeout must be positive number not less than 10."));
31                 set_focus('login_tout');
32                 $input_error = 1;
33         }
34         if (strlen($_POST['coy_name'])==0)
35         {
36                 $input_error = 1;
37                 display_error(_("The company name must be entered."));
38                 set_focus('coy_name');
39         }
40         if (!check_num('tax_prd', 1))
41         {
42                 display_error(_("Tax Periods must be positive number."));
43                 set_focus('tax_prd');
44                 $input_error = 1;
45         }
46         if (!check_num('tax_last', 1))
47         {
48                 display_error(_("Tax Last Periods must be positive number."));
49                 set_focus('tax_last');
50                 $input_error = 1;
51         }
52         if (!check_num('round_to', 1))
53         {
54                 display_error(_("Round Calculated field must be a positive number."));
55                 set_focus('round_to');
56                 $input_error = 1;
57         }
58         if ($_POST['add_pct'] != "" && !is_numeric($_POST['add_pct']))
59         {
60                 display_error(_("Add Price from Std Cost field must be number."));
61                 set_focus('add_pct');
62                 $input_error = 1;
63         }       
64         if (isset($_FILES['pic']) && $_FILES['pic']['name'] != '')
65         {
66     if ($_FILES['pic']['error'] == UPLOAD_ERR_INI_SIZE) {
67                         display_error(_('The file size is over the maximum allowed.'));
68                         $input_error = 1;
69     }
70     elseif ($_FILES['pic']['error'] > 0) {
71                         display_error(_('Error uploading logo file.'));
72                         $input_error = 1;
73     }
74                 $result = $_FILES['pic']['error'];
75                 $filename = company_path()."/images";
76                 if (!file_exists($filename))
77                 {
78                         mkdir($filename);
79                 }
80                 $filename .= "/".clean_file_name($_FILES['pic']['name']);
81
82                  //But check for the worst
83                 if (!in_array( substr($filename,-4), array('.jpg','.JPG','.png','.PNG')))
84                 {
85                         display_error(_('Only jpg and png files are supported - a file extension of .jpg or .png is expected'));
86                         $input_error = 1;
87                 }
88                 elseif ( $_FILES['pic']['size'] > ($SysPrefs->max_image_size * 1024))
89                 { //File Size Check
90                         display_error(_('The file size is over the maximum allowed. The maximum size allowed in KB is') . ' ' . $SysPrefs->max_image_size);
91                         $input_error = 1;
92                 }
93                 elseif ( $_FILES['pic']['type'] == "text/plain" )
94                 {  //File type Check
95                         display_error( _('Only graphics files can be uploaded'));
96                         $input_error = 1;
97                 }
98                 elseif (file_exists($filename))
99                 {
100                         $result = unlink($filename);
101                         if (!$result)
102                         {
103                                 display_error(_('The existing image could not be removed'));
104                                 $input_error = 1;
105                         }
106                 }
107
108                 if ($input_error != 1) {
109                         $result  =  move_uploaded_file($_FILES['pic']['tmp_name'], $filename);
110                         $_POST['coy_logo'] = clean_file_name($_FILES['pic']['name']);
111                         if(!$result) {
112                                 display_error(_('Error uploading logo file'));
113                                 $input_error = 1;
114                         } else {
115                                 $msg = check_image_file($filename);
116                                 if ( $msg) {
117                                         display_error( $msg);
118                                         unlink($filename);
119                                         $input_error = 1;
120                                 }
121                         }
122                 }
123         }
124         if (check_value('del_coy_logo'))
125         {
126                 $filename = company_path()."/images/".clean_file_name($_POST['coy_logo']);
127                 if (file_exists($filename))
128                 {
129                         $result = unlink($filename);
130                         if (!$result)
131                         {
132                                 display_error(_('The existing image could not be removed'));
133                                 $input_error = 1;
134                         }
135                 }
136                 $_POST['coy_logo'] = "";
137         }
138         if ($_POST['add_pct'] == "")
139                 $_POST['add_pct'] = -1;
140         if ($_POST['round_to'] <= 0)
141                 $_POST['round_to'] = 1;
142         if ($input_error != 1)
143         {
144                 update_company_prefs(
145                         get_post( array('coy_name','coy_no','gst_no','tax_prd','tax_last',
146                                 'postal_address','phone', 'fax', 'email', 'coy_logo', 'domicile',
147                                 'use_dimension', 'curr_default', 'f_year', 'shortname_name_in_list',
148                                 'no_item_list' => 0, 'no_customer_list' => 0, 'no_supplier_list' => 0, 
149                                 'base_sales', 'ref_no_auto_increase' => 0, 'dim_on_recurrent_invoice' => 0, 'long_description_invoice' => 0,
150                                 'time_zone' => 0, 'company_logo_report' => 0, 'barcodes_on_stock' => 0, 'print_dialog_direct' => 0, 
151                                 'add_pct', 'round_to', 'login_tout', 'auto_curr_reval', 'bcc_email', 'alternative_tax_include_on_docs', 
152                                 'suppress_tax_rates', 'use_manufacturing', 'use_fixed_assets'))
153                 );
154
155                 $_SESSION['wa_current_user']->timeout = $_POST['login_tout'];
156                 display_notification_centered(_("Company setup has been updated."));
157                 set_focus('coy_name');
158                 $Ajax->activate('_page_body');
159         }
160 } /* end of if submit */
161
162 start_form(true);
163
164 $myrow = get_company_prefs();
165
166 $_POST['coy_name'] = $myrow["coy_name"];
167 $_POST['gst_no'] = $myrow["gst_no"];
168 $_POST['tax_prd'] = $myrow["tax_prd"];
169 $_POST['tax_last'] = $myrow["tax_last"];
170 $_POST['coy_no']  = $myrow["coy_no"];
171 $_POST['postal_address']  = $myrow["postal_address"];
172 $_POST['phone']  = $myrow["phone"];
173 $_POST['fax']  = $myrow["fax"];
174 $_POST['email']  = $myrow["email"];
175 $_POST['coy_logo']  = $myrow["coy_logo"];
176 $_POST['domicile']  = $myrow["domicile"];
177 $_POST['use_dimension']  = $myrow["use_dimension"];
178 $_POST['base_sales']  = $myrow["base_sales"];
179 if (!isset($myrow["shortname_name_in_list"]))
180 {
181         set_company_pref("shortname_name_in_list", "setup.company", "tinyint", 1, '0');
182         $myrow["shortname_name_in_list"] = get_company_pref("shortname_name_in_list");
183 }
184 $_POST['shortname_name_in_list']  = $myrow["shortname_name_in_list"];
185 $_POST['no_item_list']  = $myrow["no_item_list"];
186 $_POST['no_customer_list']  = $myrow["no_customer_list"];
187 $_POST['no_supplier_list']  = $myrow["no_supplier_list"];
188 $_POST['curr_default']  = $myrow["curr_default"];
189 $_POST['f_year']  = $myrow["f_year"];
190 $_POST['time_zone']  = $myrow["time_zone"];
191 if (!isset($myrow["company_logo_report"]))
192 {
193         set_company_pref("company_logo_report", "setup.company", "tinyint", 1, '0');
194         $myrow["company_logo_report"] = get_company_pref("company_logo_report");
195 }
196 $_POST['company_logo_report']  = $myrow["company_logo_report"];
197 if (!isset($myrow["ref_no_auto_increase"]))
198 {
199         set_company_pref("ref_no_auto_increase", "setup.company", "tinyint", 1, '0');
200         $myrow["ref_no_auto_increase"] = get_company_pref("ref_no_auto_increase");
201 }
202 $_POST['ref_no_auto_increase']  = $myrow["ref_no_auto_increase"];
203 if (!isset($myrow["barcodes_on_stock"]))
204 {
205         set_company_pref("barcodes_on_stock", "setup.company", "tinyint", 1, '0');
206         $myrow["barcodes_on_stock"] = get_company_pref("barcodes_on_stock");
207 }
208 $_POST['barcodes_on_stock']  = $myrow["barcodes_on_stock"];
209 if (!isset($myrow["print_dialog_direct"]))
210 {
211         set_company_pref("print_dialog_direct", "setup.company", "tinyint", 1, '0');
212         $myrow["print_dialog_direct"] = get_company_pref("print_dialog_direct");
213 }
214 $_POST['print_dialog_direct']  = $myrow["print_dialog_direct"];
215 if (!isset($myrow["dim_on_recurrent_invoice"]))
216 {
217         set_company_pref("dim_on_recurrent_invoice", "setup.company", "tinyint", 1, '0');
218         $myrow["dim_on_recurrent_invoice"] = get_company_pref("dim_on_recurrent_invoice");
219 }
220 $_POST['dim_on_recurrent_invoice']  = $myrow["dim_on_recurrent_invoice"];
221 if (!isset($myrow["long_description_invoice"]))
222 {
223         set_company_pref("long_description_invoice", "setup.company", "tinyint", 1, '0');
224         $myrow["long_description_invoice"] = get_company_pref("long_description_invoice");
225 }
226 $_POST['long_description_invoice']  = $myrow["long_description_invoice"];
227 $_POST['version_id']  = $myrow["version_id"];
228 $_POST['add_pct'] = $myrow['add_pct'];
229 $_POST['login_tout'] = $myrow['login_tout'];
230 if ($_POST['add_pct'] == -1)
231         $_POST['add_pct'] = "";
232 $_POST['round_to'] = $myrow['round_to'];        
233 $_POST['auto_curr_reval'] = $myrow['auto_curr_reval'];  
234 $_POST['del_coy_logo']  = 0;
235 $_POST['bcc_email']  = $myrow["bcc_email"];
236 $_POST['alternative_tax_include_on_docs']  = $myrow["alternative_tax_include_on_docs"];
237 $_POST['suppress_tax_rates']  = $myrow["suppress_tax_rates"];
238 $_POST['use_manufacturing']  = $myrow["use_manufacturing"];
239 $_POST['use_fixed_assets']  = $myrow["use_fixed_assets"];
240
241 start_outer_table(TABLESTYLE2);
242
243 table_section(1);
244 table_section_title(_("General settings"));
245
246 text_row_ex(_("Name (to appear on reports):"), 'coy_name', 50, 50);
247 textarea_row(_("Address:"), 'postal_address', $_POST['postal_address'], 34, 5);
248 text_row_ex(_("Domicile:"), 'domicile', 25, 55);
249
250 text_row_ex(_("Phone Number:"), 'phone', 25, 55);
251 text_row_ex(_("Fax Number:"), 'fax', 25);
252 email_row_ex(_("Email Address:"), 'email', 50, 55);
253
254 email_row_ex(_("BCC Address for all outgoing mails:"), 'bcc_email', 50, 55);
255
256 text_row_ex(_("Official Company Number:"), 'coy_no', 25);
257 text_row_ex(_("GSTNo:"), 'gst_no', 25);
258 currencies_list_row(_("Home Currency:"), 'curr_default', $_POST['curr_default']);
259
260 label_row(_("Company Logo:"), $_POST['coy_logo']);
261 file_row(_("New Company Logo (.jpg)") . ":", 'pic', 'pic');
262 check_row(_("Delete Company Logo:"), 'del_coy_logo', $_POST['del_coy_logo']);
263
264 check_row(_("Time Zone on Reports"), 'time_zone', $_POST['time_zone']);
265 check_row(_("Company Logo on Reports"), 'company_logo_report', $_POST['company_logo_report']);
266 check_row(_("Use Barcodes on Stocks"), 'barcodes_on_stock', $_POST['barcodes_on_stock']);
267 check_row(_("Auto Increase of Document References"), 'ref_no_auto_increase', $_POST['ref_no_auto_increase']);
268 check_row(_("Use Dimensions on Recurrent Invoices"), 'dim_on_recurrent_invoice', $_POST['dim_on_recurrent_invoice']);
269 check_row(_("Use Long Descriptions on Invoices"), 'long_description_invoice', $_POST['long_description_invoice']);
270 label_row(_("Database Scheme Version"), $_POST['version_id']);
271
272 table_section(2);
273
274 table_section_title(_("General Ledger Settings"));
275 fiscalyears_list_row(_("Fiscal Year:"), 'f_year', $_POST['f_year']);
276 text_row_ex(_("Tax Periods:"), 'tax_prd', 10, 10, '', null, null, _('Months.'));
277 text_row_ex(_("Tax Last Period:"), 'tax_last', 10, 10, '', null, null, _('Months back.'));
278 check_row(_("Put alternative Tax Include on Docs"), 'alternative_tax_include_on_docs', null);
279 check_row(_("Suppress Tax Rates on Docs"), 'suppress_tax_rates', null);
280 check_row(_("Automatic Revaluation Currency Accounts"), 'auto_curr_reval', $_POST['auto_curr_reval']);
281
282 table_section_title(_("Sales Pricing"));
283 sales_types_list_row(_("Base for auto price calculations:"), 'base_sales', $_POST['base_sales'], false,
284     _('No base price list') );
285
286 text_row_ex(_("Add Price from Std Cost:"), 'add_pct', 10, 10, '', null, null, "%");
287 $curr = get_currency($_POST['curr_default']);
288 text_row_ex(_("Round calculated prices to nearest:"), 'round_to', 10, 10, '', null, null, $curr['hundreds_name']);
289 label_row("", "&nbsp;");
290
291
292 table_section_title(_("Optional Modules"));
293 check_row(_("Manufacturing"), 'use_manufacturing', null);
294 check_row(_("Fixed Assets"), 'use_fixed_assets', null);
295 number_list_row(_("Use Dimensions:"), 'use_dimension', null, 0, 2);
296
297 table_section_title(_("User Interface Options"));
298
299 check_row(_("Short Name and Name in List"), 'shortname_name_in_list', $_POST['shortname_name_in_list']);
300 check_row(_("Open Print Dialog Direct on Reports"), 'print_dialog_direct', null);
301 check_row(_("Search Item List"), 'no_item_list', null);
302 check_row(_("Search Customer List"), 'no_customer_list', null);
303 check_row(_("Search Supplier List"), 'no_supplier_list', null);
304 text_row_ex(_("Login Timeout:"), 'login_tout', 10, 10, '', null, null, _('seconds'));
305
306 end_outer_table(1);
307
308 hidden('coy_logo', $_POST['coy_logo']);
309 submit_center('update', _("Update"), true, '',  'default');
310
311 end_form(2);
312 //-------------------------------------------------------------------------------------------------
313
314 end_page();
315