Fixed db_import to allow select/delete queries in upgrade files.
[fa-stable.git] / admin / gl_setup.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_GLSETUP';
13 $path_to_root="..";
14 include($path_to_root . "/includes/session.inc");
15
16 page(_($help_context = "System and General GL Setup"));
17
18 include_once($path_to_root . "/includes/date_functions.inc");
19 include_once($path_to_root . "/includes/ui.inc");
20 include_once($path_to_root . "/includes/data_checks.inc");
21
22 include_once($path_to_root . "/admin/db/company_db.inc");
23
24 //-------------------------------------------------------------------------------------------------
25
26 function can_process()
27 {
28         if (!check_num('po_over_receive', 0, 100))
29         {
30                 display_error(_("The delivery over-receive allowance must be between 0 and 100."));
31                 set_focus('po_over_receive');
32                 return false;
33         }
34
35         if (!check_num('po_over_charge', 0, 100))
36         {
37                 display_error(_("The invoice over-charge allowance must be between 0 and 100."));
38                 set_focus('po_over_charge');
39                 return false;
40         }
41
42         if (!check_num('past_due_days', 0, 100))
43         {
44                 display_error(_("The past due days interval allowance must be between 0 and 100."));
45                 set_focus('past_due_days');
46                 return false;
47         }
48
49         $grn_act = get_company_pref('grn_clearing_act');
50         $post_grn_act = get_post('grn_clearing_act');
51         if ($post_grn_act == null)
52                 $post_grn_act = 0;
53         if (($post_grn_act != $grn_act) && db_num_rows(get_grn_items(0, '', true)))
54         {
55                 display_error(_("Before GRN Clearing Account can be changed all GRNs have to be invoiced"));
56                 $_POST['grn_clearing_act'] = $grn_act;
57                 set_focus('grn_clearing_account');
58                 return false;
59         }
60         if (!is_account_balancesheet(get_post('retained_earnings_act')) || is_account_balancesheet(get_post('profit_loss_year_act')))
61         {
62                 display_error(_("The Retained Earnings Account should be a Balance Account or the Profit and Loss Year Account should be an Expense Account (preferred the last one in the Expense Class)"));
63                 return false;
64         }
65         return true;
66 }
67
68 //-------------------------------------------------------------------------------------------------
69
70 if (isset($_POST['submit']) && can_process())
71 {
72         update_company_prefs( get_post( array( 'retained_earnings_act', 'profit_loss_year_act',
73                 'debtors_act', 'pyt_discount_act', 'creditors_act', 'freight_act', 'deferred_income_act',
74                 'exchange_diff_act', 'bank_charge_act', 'default_sales_act', 'default_sales_discount_act',
75                 'default_prompt_payment_act', 'default_inventory_act', 'default_cogs_act',
76                 'default_adj_act', 'default_inv_sales_act', 'default_assembly_act', 'legal_text',
77                 'past_due_days', 'default_workorder_required', 'default_dim_required', 'default_receival_required',
78                 'default_delivery_required', 'default_quote_valid_days', 'grn_clearing_act', 'tax_algorithm',
79                 'no_zero_lines_amount', 'show_po_item_codes', 'accounts_alpha', 'loc_notification', 'print_invoice_no',
80                 'allow_negative_prices', 'print_item_images_on_quote', 
81                 'allow_negative_stock'=> 0, 'accumulate_shipping'=> 0,
82                 'po_over_receive' => 0.0, 'po_over_charge' => 0.0, 'default_credit_limit'=>0.0
83 )));
84
85         display_notification(_("The general GL setup has been updated."));
86
87 } /* end of if submit */
88
89 //-------------------------------------------------------------------------------------------------
90
91 start_form();
92
93 start_outer_table(TABLESTYLE2);
94
95 table_section(1);
96
97 $myrow = get_company_prefs();
98
99 $_POST['retained_earnings_act']  = $myrow["retained_earnings_act"];
100 $_POST['profit_loss_year_act']  = $myrow["profit_loss_year_act"];
101 $_POST['debtors_act']  = $myrow["debtors_act"];
102 $_POST['creditors_act']  = $myrow["creditors_act"];
103 $_POST['freight_act'] = $myrow["freight_act"];
104 $_POST['deferred_income_act'] = $myrow["deferred_income_act"];
105 $_POST['pyt_discount_act']  = $myrow["pyt_discount_act"];
106
107 $_POST['exchange_diff_act'] = $myrow["exchange_diff_act"];
108 $_POST['bank_charge_act'] = $myrow["bank_charge_act"];
109 $_POST['tax_algorithm'] = $myrow["tax_algorithm"];
110 $_POST['default_sales_act'] = $myrow["default_sales_act"];
111 $_POST['default_sales_discount_act']  = $myrow["default_sales_discount_act"];
112 $_POST['default_prompt_payment_act']  = $myrow["default_prompt_payment_act"];
113
114 $_POST['default_inventory_act'] = $myrow["default_inventory_act"];
115 $_POST['default_cogs_act'] = $myrow["default_cogs_act"];
116 $_POST['default_adj_act'] = $myrow["default_adj_act"];
117 $_POST['default_inv_sales_act'] = $myrow['default_inv_sales_act'];
118 $_POST['default_assembly_act'] = $myrow['default_assembly_act'];
119
120 $_POST['allow_negative_stock'] = $myrow['allow_negative_stock'];
121
122 $_POST['po_over_receive'] = percent_format($myrow['po_over_receive']);
123 $_POST['po_over_charge'] = percent_format($myrow['po_over_charge']);
124 $_POST['past_due_days'] = $myrow['past_due_days'];
125
126 $_POST['grn_clearing_act'] = $myrow['grn_clearing_act'];
127
128 $_POST['default_credit_limit'] = $myrow['default_credit_limit'];
129 $_POST['legal_text'] = $myrow['legal_text'];
130 $_POST['accumulate_shipping'] = $myrow['accumulate_shipping'];
131
132 $_POST['default_workorder_required'] = $myrow['default_workorder_required'];
133 $_POST['default_dim_required'] = $myrow['default_dim_required'];
134 $_POST['default_delivery_required'] = $myrow['default_delivery_required'];
135 $_POST['default_receival_required'] = $myrow['default_receival_required'];
136 $_POST['default_quote_valid_days'] = $myrow['default_quote_valid_days'];
137 $_POST['no_zero_lines_amount'] = $myrow['no_zero_lines_amount'];
138 $_POST['show_po_item_codes'] = $myrow['show_po_item_codes'];
139 $_POST['accounts_alpha'] = $myrow['accounts_alpha'];
140 $_POST['loc_notification'] = $myrow['loc_notification'];
141 $_POST['print_invoice_no'] = $myrow['print_invoice_no'];
142 $_POST['allow_negative_prices'] = $myrow['allow_negative_prices'];
143 $_POST['print_item_images_on_quote'] = $myrow['print_item_images_on_quote'];
144
145 //---------------
146
147
148 table_section_title(_("General GL"));
149
150 text_row(_("Past Due Days Interval:"), 'past_due_days', $_POST['past_due_days'], 6, 6, '', "", _("days"));
151
152 accounts_type_list_row(_("Accounts Type:"), 'accounts_alpha', $_POST['accounts_alpha']); 
153
154 gl_all_accounts_list_row(_("Retained Earnings:"), 'retained_earnings_act', $_POST['retained_earnings_act']);
155
156 gl_all_accounts_list_row(_("Profit/Loss Year:"), 'profit_loss_year_act', $_POST['profit_loss_year_act']);
157
158 gl_all_accounts_list_row(_("Exchange Variances Account:"), 'exchange_diff_act', $_POST['exchange_diff_act']);
159
160 gl_all_accounts_list_row(_("Bank Charges Account:"), 'bank_charge_act', $_POST['bank_charge_act']);
161
162 tax_algorithm_list_row(_("Tax Algorithm:"), 'tax_algorithm', $_POST['tax_algorithm']);
163
164 //---------------
165
166 table_section_title(_("Customers and Sales"));
167
168 text_row(_("Default Credit Limit:"), 'default_credit_limit', $_POST['default_credit_limit'], 12, 12);
169
170 yesno_list_row(_("Invoice Identification:"), 'print_invoice_no', $_POST['print_invoice_no'], $name_yes=_("Number"), $name_no=_("Reference"));
171
172 check_row(_("Accumulate batch shipping:"), 'accumulate_shipping', null);
173
174 check_row(_("Print Item Image on Quote:"), 'print_item_images_on_quote', null);
175
176 textarea_row(_("Legal Text on Invoice:"), 'legal_text', $_POST['legal_text'], 32, 4);
177
178 gl_all_accounts_list_row(_("Shipping Charged Account:"), 'freight_act', $_POST['freight_act']);
179
180 gl_all_accounts_list_row(_("Deferred Income Account:"), 'deferred_income_act', $_POST['deferred_income_act'], true, false,
181         _("Not used"), false, false, false);
182
183 //---------------
184
185 table_section_title(_("Customers and Sales Defaults"));
186 // default for customer branch
187 gl_all_accounts_list_row(_("Receivable Account:"), 'debtors_act');
188
189 gl_all_accounts_list_row(_("Sales Account:"), 'default_sales_act', null,
190         false, false, true);
191
192 gl_all_accounts_list_row(_("Sales Discount Account:"), 'default_sales_discount_act');
193
194 gl_all_accounts_list_row(_("Prompt Payment Discount Account:"), 'default_prompt_payment_act');
195
196 text_row(_("Quote Valid Days:"), 'default_quote_valid_days', $_POST['default_quote_valid_days'], 6, 6, '', "", _("days"));
197
198 text_row(_("Delivery Required By:"), 'default_delivery_required', $_POST['default_delivery_required'], 6, 6, '', "", _("days"));
199
200 //---------------
201
202 table_section(2);
203
204 table_section_title(_("Dimension Defaults"));
205
206 text_row(_("Dimension Required By After:"), 'default_dim_required', $_POST['default_dim_required'], 6, 6, '', "", _("days"));
207
208 //----------------
209
210 table_section_title(_("Suppliers and Purchasing"));
211
212 percent_row(_("Delivery Over-Receive Allowance:"), 'po_over_receive');
213
214 percent_row(_("Invoice Over-Charge Allowance:"), 'po_over_charge');
215
216 table_section_title(_("Suppliers and Purchasing Defaults"));
217
218 gl_all_accounts_list_row(_("Payable Account:"), 'creditors_act', $_POST['creditors_act']);
219
220 gl_all_accounts_list_row(_("Purchase Discount Account:"), 'pyt_discount_act', $_POST['pyt_discount_act']);
221
222 gl_all_accounts_list_row(_("GRN Clearing Account:"), 'grn_clearing_act', get_post('grn_clearing_act'), true, false, _("No postings on GRN"));
223
224 text_row(_("Receival Required By:"), 'default_receival_required', $_POST['default_receival_required'], 6, 6, '', "", _("days"));
225
226 check_row(_("Show PO item codes:"), 'show_po_item_codes', null);
227
228 table_section_title(_("Inventory"));
229
230 check_row(_("Allow Negative Inventory:"), 'allow_negative_stock', null);
231 label_row(null, _("Warning:  This may cause a delay in GL postings"), "", "class='stockmankofg' colspan=2"); 
232
233 check_row(_("No zero-amounts (Service):"), 'no_zero_lines_amount', null);
234
235 check_row(_("Location Notifications:"), 'loc_notification', null);
236
237 check_row(_("Allow Negative Prices:"), 'allow_negative_prices', null);
238
239 table_section_title(_("Items Defaults"));
240 gl_all_accounts_list_row(_("Sales Account:"), 'default_inv_sales_act', $_POST['default_inv_sales_act']);
241
242 gl_all_accounts_list_row(_("Inventory Account:"), 'default_inventory_act', $_POST['default_inventory_act']);
243 // this one is default for items and suppliers (purchase account)
244 gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'default_cogs_act', $_POST['default_cogs_act']);
245
246 gl_all_accounts_list_row(_("Inventory Adjustments Account:"), 'default_adj_act', $_POST['default_adj_act']);
247
248 gl_all_accounts_list_row(_("Item Assembly Costs Account:"), 'default_assembly_act', $_POST['default_assembly_act']);
249
250 //----------------
251
252 table_section_title(_("Manufacturing Defaults"));
253
254 text_row(_("Work Order Required By After:"), 'default_workorder_required', $_POST['default_workorder_required'], 6, 6, '', "", _("days"));
255
256 //----------------
257
258 end_outer_table(1);
259
260 submit_center('submit', _("Update"), true, '', 'default');
261
262 end_form(2);
263
264 //-------------------------------------------------------------------------------------------------
265
266 end_page();
267