5 include($path_to_root . "/includes/session.inc");
9 //include($path_to_root . "/includes/date_functions.inc");
11 include($path_to_root . "/includes/ui.inc");
13 check_db_has_tax_groups(_("There are no tax groups defined in the system. At least one tax group is required before proceeding."));
15 if (isset($_GET['supplier_id']))
17 $_POST['supplier_id'] = $_GET['supplier_id'];
19 $new_supplier = get_post('supplier_id') == '';
21 if (isset($_POST['submit']))
24 //initialise no input errors assumed initially before we test
27 /* actions to take once the user has clicked the submit button
28 ie the page has called itself with some user input */
30 //first off validate inputs sensible
32 if (strlen($_POST['supp_name']) == 0 || $_POST['supp_name'] == "")
35 display_error(_("The supplier name must be entered."));
36 set_focus('supp_name');
39 if ($input_error !=1 )
45 $sql = "UPDATE ".TB_PREF."suppliers SET supp_name=".db_escape($_POST['supp_name']) . ",
46 address=".db_escape($_POST['address']) . ",
47 supp_address=".db_escape($_POST['supp_address']) . ",
48 phone=".db_escape($_POST['phone']) . ",
49 fax=".db_escape($_POST['fax']) . ",
50 gst_no=".db_escape($_POST['gst_no']) . ",
51 email=".db_escape($_POST['email']) . ",
52 contact=".db_escape($_POST['contact']) . ",
53 bank_account=".db_escape($_POST['bank_account']) . ",
54 credit_limit=".db_escape($_POST['credit_limit']) . ",
55 dimension_id=".db_escape($_POST['dimension_id']) . ",
56 dimension2_id=".db_escape($_POST['dimension2_id']) . ",
57 curr_code=".db_escape($_POST['curr_code']).",
58 payment_terms=".db_escape($_POST['payment_terms']) . ",
59 payable_account=".db_escape($_POST['payable_account']) . ",
60 purchase_account=".db_escape($_POST['purchase_account']) . ",
61 payment_discount_account=".db_escape($_POST['payment_discount_account']) . ",
62 tax_group_id=".db_escape($_POST['tax_group_id']) . " WHERE supplier_id = '" . $_POST['supplier_id'] . "'";
64 db_query($sql,"The supplier could not be updated");
65 display_notification(_("Supplier has been updated."));
70 $sql = "INSERT INTO ".TB_PREF."suppliers (supp_name, address, supp_address, phone, fax, gst_no, email,
71 contact, bank_account, credit_limit, dimension_id, dimension2_id, curr_code,
72 payment_terms, payable_account, purchase_account, payment_discount_account, tax_group_id)
73 VALUES (".db_escape($_POST['supp_name']). ", "
74 .db_escape($_POST['address']) . ", "
75 .db_escape($_POST['supp_address']) . ", "
76 .db_escape($_POST['phone']). ", "
77 .db_escape($_POST['fax']). ", "
78 .db_escape($_POST['gst_no']). ", "
79 .db_escape($_POST['email']). ", "
80 .db_escape($_POST['contact']). ", "
81 .db_escape($_POST['bank_account']). ", "
82 .db_escape($_POST['credit_limit']). ", "
83 .db_escape($_POST['dimension_id']). ", "
84 .db_escape($_POST['dimension2_id']). ", "
85 .db_escape($_POST['curr_code']). ", "
86 .db_escape($_POST['payment_terms']). ", "
87 .db_escape($_POST['payable_account']). ", "
88 .db_escape($_POST['purchase_account']). ", "
89 .db_escape($_POST['payment_discount_account']). ", "
90 .db_escape($_POST['tax_group_id']). ")";
92 db_query($sql,"The supplier could not be added");
93 $_POST['supplier_id'] = db_insert_id();
94 $new_supplier = false;
95 display_notification(_("A new supplier has been added."));
96 $Ajax->activate('_page_body');
101 elseif (isset($_POST['delete']) && $_POST['delete'] != "")
103 //the link to delete a selected record was clicked instead of the submit button
107 // PREVENT DELETES IF DEPENDENT RECORDS IN 'supp_trans' , purch_orders
109 $sql= "SELECT COUNT(*) FROM ".TB_PREF."supp_trans WHERE supplier_id='" . $_POST['supplier_id'] . "'";
110 $result = db_query($sql,"check failed");
111 $myrow = db_fetch_row($result);
115 display_error(_("Cannot delete this supplier because there are transactions that refer to this supplier."));
120 $sql= "SELECT COUNT(*) FROM ".TB_PREF."purch_orders WHERE supplier_id='" . $_POST['supplier_id'] . "'";
121 $result = db_query($sql,"check failed");
122 $myrow = db_fetch_row($result);
126 display_error(_("Cannot delete the supplier record because purchase orders have been created against this supplier."));
130 if ($cancel_delete == 0)
132 $sql="DELETE FROM ".TB_PREF."suppliers WHERE supplier_id='" . $_POST['supplier_id']. "'";
133 db_query($sql,"check failed");
135 unset($_SESSION['supplier_id']);
136 $new_supplier = true;
137 $Ajax->activate('_page_body');
138 } //end if Delete supplier
140 elseif (isset($_POST['select']))
142 context_return(array('supplier_id' => $_POST['supplier_id']));
147 if (db_has_suppliers())
150 // start_table("class = 'tablestyle_noborder'");
151 supplier_list_row(_("Select a supplier: "), 'supplier_id', null,
152 _('New supplier'), true);
157 hidden('supplier_id', get_post('supplier_id'));
160 //start_table("class='tablestyle2'", 0, 3);
161 start_table("class='tablestyle'", 3);
163 table_section_title(_("Supplier"));
167 //SupplierID exists - either passed when calling the form or from the form itself
168 $myrow = get_supplier($_POST['supplier_id']);
170 $_POST['supp_name'] = $myrow["supp_name"];
171 $_POST['address'] = $myrow["address"];
172 $_POST['supp_address'] = $myrow["supp_address"];
173 $_POST['phone'] = $myrow["phone"];
174 $_POST['fax'] = $myrow["fax"];
175 $_POST['gst_no'] = $myrow["gst_no"];
176 $_POST['email'] = $myrow["email"];
177 $_POST['contact'] = $myrow["contact"];
178 $_POST['bank_account'] = $myrow["bank_account"];
179 $_POST['dimension_id'] = $myrow["dimension_id"];
180 $_POST['dimension2_id'] = $myrow["dimension2_id"];
181 $_POST['curr_code'] = $myrow["curr_code"];
182 $_POST['payment_terms'] = $myrow["payment_terms"];
183 $_POST['credit_limit'] = $myrow["credit_limit"];
184 $_POST['tax_group_id'] = $myrow["tax_group_id"];
185 $_POST['payable_account'] = $myrow["payable_account"];
186 $_POST['purchase_account'] = $myrow["purchase_account"];
187 $_POST['payment_discount_account'] = $myrow["payment_discount_account"];
192 $_POST['supp_name'] = $_POST['address'] = $_POST['supp_address'] = $_POST['tax_group_id'] = '';
193 $_POST['dimension_id'] = 0;
194 $_POST['dimension2_id'] = 0;
195 $_POST['sales_type'] = -1;
196 $_POST['email'] = $_POST['phone'] = $_POST['fax'] = $_POST['gst_no'] = $_POST['contact'] = $_POST['bank_account'] = '';
197 $_POST['payment_terms'] = '';
198 $_POST['credit_limit'] = price_format(sys_prefs::default_credit_limit());
200 $company_record = get_company_prefs();
201 $_POST['curr_code'] = $company_record["curr_default"];
202 $_POST['payable_account'] = $company_record["creditors_act"];
203 $_POST['purchase_account'] = $company_record["default_cogs_act"];
204 $_POST['payment_discount_account'] = $company_record['pyt_discount_act'];
207 text_row(_("Supplier Name:"), 'supp_name', null, 42, 40);
208 textarea_row(_("Postal ddress:"), 'address', null, 35, 5);
209 textarea_row(_("Physical Address:"), 'supp_address', null, 35, 5);
210 text_row(_("Phone:"), 'phone', null, 42, 40);
211 text_row(_("Fax:"), 'fax', null, 42, 40);
212 text_row(_("GSTNo:"), 'gst_no', null, 42, 40);
213 text_row(_("Email:"), 'email', null, 42, 40);
214 text_row(_("Contact:"), 'contact', null, 42, 40);
215 text_row(_("Bank Name/Account:"), 'bank_account', null, 42, 40);
216 amount_row(_("Credit Limit:"), 'credit_limit', null);
217 // Sherifoz 23.09.03 currency can't be changed if editing
220 label_row(_("Supplier's Currency:"), $_POST['curr_code']);
221 hidden('curr_code', $_POST['curr_code']);
225 currencies_list_row(_("Supplier's Currency:"), 'curr_code', null);
228 tax_groups_list_row(_("Tax Group:"), 'tax_group_id', null);
230 payment_terms_list_row(_("Payment Terms:"), 'payment_terms', null);
232 table_section_title(_("Accounts"));
234 gl_all_accounts_list_row(_("Accounts Payable Account:"), 'payable_account', $_POST['payable_account']);
236 gl_all_accounts_list_row(_("Purchase Account:"), 'purchase_account', $_POST['purchase_account']);
238 gl_all_accounts_list_row(_("Purchase Discount Account:"), 'payment_discount_account', $_POST['payment_discount_account']);
240 $dim = get_company_pref('use_dimension');
243 table_section_title(_("Dimension"));
245 dimensions_list_row(_("Dimension")." 1:", 'dimension_id', null, true, " ", false, 1);
247 dimensions_list_row(_("Dimension")." 2:", 'dimension2_id', null, true, " ", false, 2);
250 hidden('dimension_id', 0);
252 hidden('dimension2_id', 0);
255 div_start('controls');
258 submit_center_first('submit', _("Update Supplier"),
259 _('Update supplier data'), true);
260 submit_return('select', _("Return"), _("Select this supplier and return to document entry."), true);
261 submit_center_last('delete', _("Delete Supplier"),
262 _('Delete supplier data if have been never used'), true);
266 submit_center('submit', _("Add New Supplier Details"), true, '', true);