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