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");
16 page(_($help_context = "Suppliers"), @$_REQUEST['popup']);
18 //include($path_to_root . "/includes/date_functions.inc");
20 include($path_to_root . "/includes/ui.inc");
22 check_db_has_tax_groups(_("There are no tax groups defined in the system. At least one tax group is required before proceeding."));
24 if (isset($_GET['supplier_id']))
26 $_POST['supplier_id'] = $_GET['supplier_id'];
28 $new_supplier = get_post('supplier_id') == '';
30 if (isset($_POST['submit']))
33 //initialise no input errors assumed initially before we test
36 /* actions to take once the user has clicked the submit button
37 ie the page has called itself with some user input */
39 //first off validate inputs sensible
41 if (strlen($_POST['supp_name']) == 0 || $_POST['supp_name'] == "")
44 display_error(_("The supplier name must be entered."));
45 set_focus('supp_name');
48 if (strlen($_POST['supp_ref']) == 0 || $_POST['supp_ref'] == "")
51 display_error(_("The supplier short name must be entered."));
52 set_focus('supp_ref');
55 if ($input_error !=1 )
61 $sql = "UPDATE ".TB_PREF."suppliers SET supp_name=".db_escape($_POST['supp_name']) . ",
62 supp_ref=".db_escape($_POST['supp_ref']) . ",
63 address=".db_escape($_POST['address']) . ",
64 supp_address=".db_escape($_POST['supp_address']) . ",
65 phone=".db_escape($_POST['phone']) . ",
66 phone2=".db_escape($_POST['phone2']) . ",
67 fax=".db_escape($_POST['fax']) . ",
68 gst_no=".db_escape($_POST['gst_no']) . ",
69 email=".db_escape($_POST['email']) . ",
70 website=".db_escape($_POST['website']) . ",
71 contact=".db_escape($_POST['contact']) . ",
72 supp_account_no=".db_escape($_POST['supp_account_no']) . ",
73 bank_account=".db_escape($_POST['bank_account']) . ",
74 credit_limit=".input_num('credit_limit', 0) . ",
75 dimension_id=".db_escape($_POST['dimension_id']) . ",
76 dimension2_id=".db_escape($_POST['dimension2_id']) . ",
77 curr_code=".db_escape($_POST['curr_code']).",
78 payment_terms=".db_escape($_POST['payment_terms']) . ",
79 payable_account=".db_escape($_POST['payable_account']) . ",
80 purchase_account=".db_escape($_POST['purchase_account']) . ",
81 payment_discount_account=".db_escape($_POST['payment_discount_account']) . ",
82 notes=".db_escape($_POST['notes']) . ",
83 tax_group_id=".db_escape($_POST['tax_group_id']) . " WHERE supplier_id = ".db_escape($_POST['supplier_id']);
85 db_query($sql,"The supplier could not be updated");
86 update_record_status($_POST['supplier_id'], $_POST['inactive'],
87 'suppliers', 'supplier_id');
89 $Ajax->activate('supplier_id'); // in case of status change
90 display_notification(_("Supplier has been updated."));
95 $sql = "INSERT INTO ".TB_PREF."suppliers (supp_name, supp_ref, address, supp_address, phone, phone2, fax, gst_no, email, website,
96 contact, supp_account_no, bank_account, credit_limit, dimension_id, dimension2_id, curr_code,
97 payment_terms, payable_account, purchase_account, payment_discount_account, notes, tax_group_id)
98 VALUES (".db_escape($_POST['supp_name']). ", "
99 .db_escape($_POST['supp_ref']). ", "
100 .db_escape($_POST['address']) . ", "
101 .db_escape($_POST['supp_address']) . ", "
102 .db_escape($_POST['phone']). ", "
103 .db_escape($_POST['phone2']). ", "
104 .db_escape($_POST['fax']). ", "
105 .db_escape($_POST['gst_no']). ", "
106 .db_escape($_POST['email']). ", "
107 .db_escape($_POST['website']). ", "
108 .db_escape($_POST['contact']). ", "
109 .db_escape($_POST['supp_account_no']). ", "
110 .db_escape($_POST['bank_account']). ", "
111 .input_num('credit_limit',0). ", "
112 .db_escape($_POST['dimension_id']). ", "
113 .db_escape($_POST['dimension2_id']). ", "
114 .db_escape($_POST['curr_code']). ", "
115 .db_escape($_POST['payment_terms']). ", "
116 .db_escape($_POST['payable_account']). ", "
117 .db_escape($_POST['purchase_account']). ", "
118 .db_escape($_POST['payment_discount_account']). ", "
119 .db_escape($_POST['notes']). ", "
120 .db_escape($_POST['tax_group_id']). ")";
122 db_query($sql,"The supplier could not be added");
123 $_POST['supplier_id'] = db_insert_id();
124 $new_supplier = false;
125 display_notification(_("A new supplier has been added."));
126 $Ajax->activate('_page_body');
131 elseif (isset($_POST['delete']) && $_POST['delete'] != "")
133 //the link to delete a selected record was clicked instead of the submit button
137 // PREVENT DELETES IF DEPENDENT RECORDS IN 'supp_trans' , purch_orders
139 $sql= "SELECT COUNT(*) FROM ".TB_PREF."supp_trans WHERE supplier_id=".db_escape($_POST['supplier_id']);
140 $result = db_query($sql,"check failed");
141 $myrow = db_fetch_row($result);
145 display_error(_("Cannot delete this supplier because there are transactions that refer to this supplier."));
150 $sql= "SELECT COUNT(*) FROM ".TB_PREF."purch_orders WHERE supplier_id=".db_escape($_POST['supplier_id']);
151 $result = db_query($sql,"check failed");
152 $myrow = db_fetch_row($result);
156 display_error(_("Cannot delete the supplier record because purchase orders have been created against this supplier."));
160 if ($cancel_delete == 0)
162 $sql="DELETE FROM ".TB_PREF."suppliers WHERE supplier_id=".db_escape($_POST['supplier_id']);
163 db_query($sql,"check failed");
165 unset($_SESSION['supplier_id']);
166 $new_supplier = true;
167 $Ajax->activate('_page_body');
168 } //end if Delete supplier
173 if (db_has_suppliers())
176 // start_table("class = 'tablestyle_noborder'");
178 supplier_list_cells(_("Select a supplier: "), 'supplier_id', null,
179 _('New supplier'), true, check_value('show_inactive'));
180 check_cells(_("Show inactive:"), 'show_inactive', null, true);
183 if (get_post('_show_inactive_update')) {
184 $Ajax->activate('supplier_id');
185 set_focus('supplier_id');
190 hidden('supplier_id', get_post('supplier_id'));
193 start_outer_table($table_style2, 5);
199 //SupplierID exists - either passed when calling the form or from the form itself
200 $myrow = get_supplier($_POST['supplier_id']);
202 $_POST['supp_name'] = $myrow["supp_name"];
203 $_POST['supp_ref'] = $myrow["supp_ref"];
204 $_POST['address'] = $myrow["address"];
205 $_POST['supp_address'] = $myrow["supp_address"];
206 $_POST['phone'] = $myrow["phone"];
207 $_POST['phone2'] = $myrow["phone2"];
208 $_POST['fax'] = $myrow["fax"];
209 $_POST['gst_no'] = $myrow["gst_no"];
210 $_POST['email'] = $myrow["email"];
211 $_POST['website'] = $myrow["website"];
212 $_POST['contact'] = $myrow["contact"];
213 $_POST['supp_account_no'] = $myrow["supp_account_no"];
214 $_POST['bank_account'] = $myrow["bank_account"];
215 $_POST['dimension_id'] = $myrow["dimension_id"];
216 $_POST['dimension2_id'] = $myrow["dimension2_id"];
217 $_POST['curr_code'] = $myrow["curr_code"];
218 $_POST['payment_terms'] = $myrow["payment_terms"];
219 $_POST['credit_limit'] = price_format($myrow["credit_limit"]);
220 $_POST['tax_group_id'] = $myrow["tax_group_id"];
221 $_POST['payable_account'] = $myrow["payable_account"];
222 $_POST['purchase_account'] = $myrow["purchase_account"];
223 $_POST['payment_discount_account'] = $myrow["payment_discount_account"];
224 $_POST['notes'] = $myrow["notes"];
225 $_POST['inactive'] = $myrow["inactive"];
229 $_POST['supp_name'] = $_POST['supp_ref'] = $_POST['address'] = $_POST['supp_address'] =
230 $_POST['tax_group_id'] = $_POST['website'] = $_POST['supp_account_no'] = $_POST['notes'] = '';
231 $_POST['dimension_id'] = 0;
232 $_POST['dimension2_id'] = 0;
233 $_POST['sales_type'] = -1;
234 $_POST['email'] = $_POST['phone'] = $_POST['phone2'] = $_POST['fax'] =
235 $_POST['gst_no'] = $_POST['contact'] = $_POST['bank_account'] = '';
236 $_POST['payment_terms'] = '';
237 $_POST['credit_limit'] = price_format(0);
239 $company_record = get_company_prefs();
240 $_POST['curr_code'] = $company_record["curr_default"];
241 $_POST['payable_account'] = $company_record["creditors_act"];
242 $_POST['purchase_account'] = $company_record["default_cogs_act"];
243 $_POST['payment_discount_account'] = $company_record['pyt_discount_act'];
244 $_POST['inactive'] = 0;
247 table_section_title(_("Name and Contact"));
249 text_row(_("Supplier Name:"), 'supp_name', null, 42, 40);
250 text_row(_("Supplier Short Name:"), 'supp_ref', null, 30, 30);
251 text_row(_("Contact Person:"), 'contact', null, 42, 40);
253 text_row(_("Phone Number:"), 'phone', null, 32, 30);
254 text_row(_("Secondary Phone Number:"), 'phone2', null, 32, 30);
255 text_row(_("Fax Number:"), 'fax', null, 32, 30);
257 email_row(_("E-mail:"), 'email', null, 35, 55);
258 link_row(_("Website:"), 'website', null, 35, 55);
259 text_row(_("Our Customer No:"), 'supp_account_no', null, 42, 40);
261 table_section_title(_("Addresses"));
262 textarea_row(_("Mailing Address:"), 'address', null, 35, 5);
263 textarea_row(_("Physical Address:"), 'supp_address', null, 35, 5);
267 table_section_title(_("Purchasing"));
268 text_row(_("GSTNo:"), 'gst_no', null, 42, 40);
269 text_row(_("Bank Name/Account:"), 'bank_account', null, 42, 40);
270 amount_row(_("Credit Limit:"), 'credit_limit', null);
273 label_row(_("Supplier's Currency:"), $_POST['curr_code']);
274 hidden('curr_code', $_POST['curr_code']);
278 currencies_list_row(_("Supplier's Currency:"), 'curr_code', null);
281 tax_groups_list_row(_("Tax Group:"), 'tax_group_id', null);
283 payment_terms_list_row(_("Payment Terms:"), 'payment_terms', null);
285 table_section_title(_("Accounts"));
287 gl_all_accounts_list_row(_("Accounts Payable Account:"), 'payable_account', $_POST['payable_account']);
289 gl_all_accounts_list_row(_("Purchase Account:"), 'purchase_account', $_POST['purchase_account']);
291 gl_all_accounts_list_row(_("Purchase Discount Account:"), 'payment_discount_account', $_POST['payment_discount_account']);
293 $dim = get_company_pref('use_dimension');
296 table_section_title(_("Dimension"));
298 dimensions_list_row(_("Dimension")." 1:", 'dimension_id', null, true, " ", false, 1);
300 dimensions_list_row(_("Dimension")." 2:", 'dimension2_id', null, true, " ", false, 2);
303 hidden('dimension_id', 0);
305 hidden('dimension2_id', 0);
306 table_section_title(_("General"));
307 textarea_row(_("General Notes:"), 'notes', null, 35, 5);
308 record_status_list_row(_("Supplier status:"), 'inactive');
312 div_start('controls');
315 submit_center_first('submit', _("Update Supplier"),
316 _('Update supplier data'), @$_REQUEST['popup'] ? true : 'default');
317 submit_return('select', get_post('supplier_id'), _("Select this supplier and return to document entry."));
318 submit_center_last('delete', _("Delete Supplier"),
319 _('Delete supplier data if have been never used'), true);
323 submit_center('submit', _("Add New Supplier Details"), true, '', 'default');
326 hidden('popup', @$_REQUEST['popup']);