Replaced the global variables for table styles to defined CSS classes.
[fa-stable.git] / purchasing / manage / suppliers.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_SUPPLIER';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/session.inc");
15
16 page(_($help_context = "Suppliers"), @$_REQUEST['popup']);
17
18 //include($path_to_root . "/includes/date_functions.inc");
19
20 include($path_to_root . "/includes/ui.inc");
21
22 check_db_has_tax_groups(_("There are no tax groups defined in the system. At least one tax group is required before proceeding."));
23
24 if (isset($_GET['supplier_id'])) 
25 {
26         $_POST['supplier_id'] = $_GET['supplier_id'];
27 }
28 $new_supplier = get_post('supplier_id') == ''; 
29
30 if (isset($_POST['submit'])) 
31 {
32
33         //initialise no input errors assumed initially before we test
34         $input_error = 0;
35
36         /* actions to take once the user has clicked the submit button
37         ie the page has called itself with some user input */
38
39         //first off validate inputs sensible
40
41         if (strlen($_POST['supp_name']) == 0 || $_POST['supp_name'] == "") 
42         {
43                 $input_error = 1;
44                 display_error(_("The supplier name must be entered."));
45                 set_focus('supp_name');
46         }
47
48         if (strlen($_POST['supp_ref']) == 0 || $_POST['supp_ref'] == "") 
49         {
50                 $input_error = 1;
51                 display_error(_("The supplier short name must be entered."));
52                 set_focus('supp_ref');
53         }
54
55         if ($input_error !=1 )
56         {
57
58                 if (!$new_supplier) 
59                 {
60                         update_supplier($_POST['supplier_id'], $_POST['supp_name'], $_POST['supp_ref'], $_POST['address'],
61                                 $_POST['supp_address'], $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['gst_no'],
62                                 $_POST['email'], $_POST['website'], $_POST['contact'], $_POST['supp_account_no'], $_POST['bank_account'], 
63                                 input_num('credit_limit', 0), $_POST['dimension_id'], $_POST['dimension2_id'], $_POST['curr_code'],
64                                 $_POST['payment_terms'], $_POST['payable_account'], $_POST['purchase_account'], $_POST['payment_discount_account'],
65                                 $_POST['notes'], $_POST['tax_group_id'], $_POST['rep_lang']);
66                         update_record_status($_POST['supplier_id'], $_POST['inactive'],
67                                 'suppliers', 'supplier_id');
68
69                         $Ajax->activate('supplier_id'); // in case of status change
70                         display_notification(_("Supplier has been updated."));
71                 } 
72                 else 
73                 {
74                         add_supplier($_POST['supp_name'], $_POST['supp_ref'], $_POST['address'], $_POST['supp_address'],
75                                 $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['gst_no'], $_POST['email'],
76                                 $_POST['website'], $_POST['contact'], $_POST['supp_account_no'], $_POST['bank_account'], 
77                                 input_num('credit_limit',0), $_POST['dimension_id'], $_POST['dimension2_id'],
78                                 $_POST['curr_code'], $_POST['payment_terms'], $_POST['payable_account'], $_POST['purchase_account'],
79                                 $_POST['payment_discount_account'], $_POST['notes'], $_POST['tax_group_id'], $_POST['rep_lang']);
80
81                         $_POST['supplier_id'] = db_insert_id();
82                         $new_supplier = false;
83                         display_notification(_("A new supplier has been added."));
84                         $Ajax->activate('_page_body');
85                 }
86         }
87
88
89 elseif (isset($_POST['delete']) && $_POST['delete'] != "") 
90 {
91         //the link to delete a selected record was clicked instead of the submit button
92
93         $cancel_delete = 0;
94
95         // PREVENT DELETES IF DEPENDENT RECORDS IN 'supp_trans' , purch_orders
96
97         if (key_in_foreign_table($_POST['supplier_id'], 'supp_trans', 'supplier_id'))
98         {
99                 $cancel_delete = 1;
100                 display_error(_("Cannot delete this supplier because there are transactions that refer to this supplier."));
101
102         } 
103         else 
104         {
105                 if (key_in_foreign_table($_POST['supplier_id'], 'purch_orders', 'supplier_id'))
106                 {
107                         $cancel_delete = 1;
108                         display_error(_("Cannot delete the supplier record because purchase orders have been created against this supplier."));
109                 }
110
111         }
112         if ($cancel_delete == 0) 
113         {
114                 delete_supplier($_POST['supplier_id']);
115
116                 unset($_SESSION['supplier_id']);
117                 $new_supplier = true;
118                 $Ajax->activate('_page_body');
119         } //end if Delete supplier
120 }
121
122 start_form();
123
124 if (db_has_suppliers()) 
125 {
126         start_table(false, "", 3);
127 //      start_table(TABLESTYLE_NOBORDER);
128         start_row();
129         supplier_list_cells(_("Select a supplier: "), 'supplier_id', null,
130                   _('New supplier'), true, check_value('show_inactive'));
131         check_cells(_("Show inactive:"), 'show_inactive', null, true);
132         end_row();
133         end_table();
134         if (get_post('_show_inactive_update')) {
135                 $Ajax->activate('supplier_id');
136                 set_focus('supplier_id');
137         }
138
139 else 
140 {
141         hidden('supplier_id', get_post('supplier_id'));
142 }
143
144 start_outer_table(TABLESTYLE2);
145
146 table_section(1);
147
148 if (!$new_supplier) 
149 {
150         //SupplierID exists - either passed when calling the form or from the form itself
151         $myrow = get_supplier($_POST['supplier_id']);
152
153         $_POST['supp_name'] = $myrow["supp_name"];
154         $_POST['supp_ref'] = $myrow["supp_ref"];
155         $_POST['address']  = $myrow["address"];
156         $_POST['supp_address']  = $myrow["supp_address"];
157         $_POST['phone']  = $myrow["phone"];
158         $_POST['phone2']  = $myrow["phone2"];
159         $_POST['fax']  = $myrow["fax"];
160         $_POST['gst_no']  = $myrow["gst_no"];
161         $_POST['email']  = $myrow["email"];
162         $_POST['website']  = $myrow["website"];
163         $_POST['contact']  = $myrow["contact"];
164         $_POST['supp_account_no']  = $myrow["supp_account_no"];
165         $_POST['bank_account']  = $myrow["bank_account"];
166         $_POST['dimension_id']  = $myrow["dimension_id"];
167         $_POST['dimension2_id']  = $myrow["dimension2_id"];
168         $_POST['curr_code']  = $myrow["curr_code"];
169         $_POST['rep_lang']  = $myrow["rep_lang"];
170         $_POST['payment_terms']  = $myrow["payment_terms"];
171         $_POST['credit_limit']  = price_format($myrow["credit_limit"]);
172         $_POST['tax_group_id'] = $myrow["tax_group_id"];
173         $_POST['payable_account']  = $myrow["payable_account"];
174         $_POST['purchase_account']  = $myrow["purchase_account"];
175         $_POST['payment_discount_account'] = $myrow["payment_discount_account"];
176         $_POST['notes']  = $myrow["notes"];
177         $_POST['inactive'] = $myrow["inactive"];
178
179 else 
180 {
181         $_POST['supp_name'] = $_POST['supp_ref'] = $_POST['address'] = $_POST['supp_address'] = 
182                 $_POST['tax_group_id'] = $_POST['website'] = $_POST['supp_account_no'] = $_POST['notes'] = '';
183         $_POST['dimension_id'] = 0;
184         $_POST['dimension2_id'] = 0;
185         $_POST['sales_type'] = -1;
186         $_POST['email'] = $_POST['phone'] = $_POST['phone2'] = $_POST['fax'] = 
187                 $_POST['gst_no'] = $_POST['contact'] = $_POST['bank_account'] = '';
188         $_POST['payment_terms']  = '';
189         $_POST['credit_limit']  = price_format(0);
190
191         $company_record = get_company_prefs();
192         $_POST['curr_code']  = $company_record["curr_default"];
193         $_POST['rep_lang']  = '';
194         $_POST['payable_account'] = $company_record["creditors_act"];
195         $_POST['purchase_account'] = $company_record["default_cogs_act"];
196         $_POST['payment_discount_account'] = $company_record['pyt_discount_act'];
197         $_POST['inactive'] = 0;
198 }
199
200 table_section_title(_("Name and Contact"));
201
202 text_row(_("Supplier Name:"), 'supp_name', null, 42, 40);
203 text_row(_("Supplier Short Name:"), 'supp_ref', null, 30, 30);
204 text_row(_("Contact Person:"), 'contact', null, 42, 40);
205
206 text_row(_("Phone Number:"), 'phone', null, 32, 30);
207 text_row(_("Secondary Phone Number:"), 'phone2', null, 32, 30);
208 text_row(_("Fax Number:"), 'fax', null, 32, 30);
209
210 email_row(_("E-mail:"), 'email', null, 35, 55);
211 link_row(_("Website:"), 'website', null, 35, 55);
212 text_row(_("Our Customer No:"), 'supp_account_no', null, 42, 40);
213
214 table_section_title(_("Addresses"));
215 textarea_row(_("Mailing Address:"), 'address', null, 35, 5);
216 textarea_row(_("Physical Address:"), 'supp_address', null, 35, 5);
217
218 table_section(2);
219
220 table_section_title(_("Purchasing"));
221 text_row(_("GSTNo:"), 'gst_no', null, 42, 40);
222 text_row(_("Bank Name/Account:"), 'bank_account', null, 42, 40);
223 amount_row(_("Credit Limit:"), 'credit_limit', null);
224 if (!$new_supplier) 
225 {
226         label_row(_("Supplier's Currency:"), $_POST['curr_code']);
227         hidden('curr_code', $_POST['curr_code']);
228
229 else 
230 {
231         currencies_list_row(_("Supplier's Currency:"), 'curr_code', null);
232 }
233
234 languages_list_row(_("Document Language:"), 'rep_lang', null, _('System default'));
235
236 tax_groups_list_row(_("Tax Group:"), 'tax_group_id', null);
237
238 payment_terms_list_row(_("Payment Terms:"), 'payment_terms', null);
239
240 table_section_title(_("Accounts"));
241
242 gl_all_accounts_list_row(_("Accounts Payable Account:"), 'payable_account', $_POST['payable_account']);
243
244 gl_all_accounts_list_row(_("Purchase Account:"), 'purchase_account', $_POST['purchase_account']);
245
246 gl_all_accounts_list_row(_("Purchase Discount Account:"), 'payment_discount_account', $_POST['payment_discount_account']);
247
248 $dim = get_company_pref('use_dimension');
249 if ($dim >= 1)
250 {
251         table_section_title(_("Dimension"));
252
253         dimensions_list_row(_("Dimension")." 1:", 'dimension_id', null, true, " ", false, 1);
254         if ($dim > 1)
255                 dimensions_list_row(_("Dimension")." 2:", 'dimension2_id', null, true, " ", false, 2);
256 }
257 if ($dim < 1)
258         hidden('dimension_id', 0);
259 if ($dim < 2)
260         hidden('dimension2_id', 0);
261 table_section_title(_("General"));
262 textarea_row(_("General Notes:"), 'notes', null, 35, 5);
263 record_status_list_row(_("Supplier status:"), 'inactive');
264
265 end_outer_table(1);
266
267 div_start('controls');
268 if (!$new_supplier) 
269 {
270         submit_center_first('submit', _("Update Supplier"), 
271           _('Update supplier data'), @$_REQUEST['popup'] ? true : 'default');
272         submit_return('select', get_post('supplier_id'), _("Select this supplier and return to document entry."));
273         submit_center_last('delete', _("Delete Supplier"), 
274           _('Delete supplier data if have been never used'), true);
275 }
276 else 
277 {
278         submit_center('submit', _("Add New Supplier Details"), true, '', 'default');
279 }
280 div_end();
281 hidden('popup', @$_REQUEST['popup']);
282 end_form();
283
284 end_page();
285
286 ?>