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");
12 include($path_to_root . "/includes/data_checks.inc");
14 check_db_has_tax_groups(_("There are no tax groups defined in the system. At least one tax group is required before proceeding."));
16 if (isset($_GET['New']) || !isset($_POST['supplier_id']))
21 if (isset($_POST['SelectSupplier']))
26 if (isset($_POST['submit']))
29 //initialise no input errors assumed initially before we test
32 /* actions to take once the user has clicked the submit button
33 ie the page has called itself with some user input */
35 //first off validate inputs sensible
37 if (strlen($_POST['supp_name']) == 0 || $_POST['supp_name'] == "")
40 display_error(_("The supplier name must be entered."));
43 if ($input_error !=1 )
46 if (!isset($_POST['New']))
49 $sql = "UPDATE ".TB_PREF."suppliers SET supp_name='" . $_POST['supp_name'] . "',
50 address='" . $_POST['address'] . "',
51 email='" . $_POST['email'] . "',
52 bank_account='" . $_POST['bank_account'] . "',
53 dimension_id=" . $_POST['dimension_id'] . ",
54 dimension2_id=" . $_POST['dimension2_id'] . ",
55 curr_code='" . $_POST['curr_code'] . "',
56 payment_terms='" . $_POST['payment_terms'] . "',
57 payable_account='" . $_POST['payable_account'] . "',
58 purchase_account='" . $_POST['purchase_account'] . "',
59 payment_discount_account='" . $_POST['payment_discount_account'] . "',
60 tax_group_id=" . $_POST['tax_group_id'] . " WHERE supplier_id = '" . $_POST['supplier_id'] . "'";
62 db_query($sql,"The supplier could not be updated");
66 { //not a new supplier
68 $sql = "INSERT INTO ".TB_PREF."suppliers (supp_name, address, email, bank_account, dimension_id, dimension2_id, curr_code,
69 payment_terms, payable_account, purchase_account, payment_discount_account, tax_group_id)
70 VALUES ('" . $_POST['supp_name'] . "', '" .
71 $_POST['address'] . "', '" .
72 $_POST['email'] . "', '" .
73 $_POST['bank_account'] . "', " .
74 $_POST['dimension_id'] . ", " .
75 $_POST['dimension2_id'] . ", '" .
76 $_POST['curr_code'] . "', '" .
77 $_POST['payment_terms'] . "', '" .
78 $_POST['payable_account'] . "', '" .
79 $_POST['purchase_account'] . "', '" .
80 $_POST['payment_discount_account'] . "', " .
81 $_POST['tax_group_id'] . ")";
83 db_query($sql,"The supplier could not be added");
86 meta_forward($_SERVER['PHP_SELF']);
90 elseif (isset($_POST['delete']) && $_POST['delete'] != "")
92 //the link to delete a selected record was clicked instead of the submit button
96 // PREVENT DELETES IF DEPENDENT RECORDS IN 'supp_trans' , purch_orders
98 $sql= "SELECT COUNT(*) FROM ".TB_PREF."supp_trans WHERE supplier_id='" . $_POST['supplier_id'] . "'";
99 $result = db_query($sql,"check failed");
100 $myrow = db_fetch_row($result);
104 display_error(_("Cannot delete this supplier because there are transactions that refer to this supplier."));
109 $sql= "SELECT COUNT(*) FROM ".TB_PREF."purch_orders WHERE supplier_id='" . $_POST['supplier_id'] . "'";
110 $result = db_query($sql,"check failed");
111 $myrow = db_fetch_row($result);
115 display_error(_("Cannot delete the supplier record because purchase orders have been created against this supplier."));
119 if ($cancel_delete == 0)
121 $sql="DELETE FROM ".TB_PREF."suppliers WHERE supplier_id='" . $_POST['supplier_id']. "'";
122 db_query($sql,"check failed");
124 unset($_SESSION['supplier_id']);
125 meta_forward($_SERVER['PHP_SELF']);
126 } //end if Delete supplier
131 if (db_has_suppliers())
135 supplier_list_cells(_("Select a supplier: "), 'supplier_id', null);
136 submit_cells('SelectSupplier', _("Edit Supplier"));
142 hidden('supplier_id', $_POST['supplier_id']);
145 hyperlink_params($_SERVER['PHP_SELF'], _("Enter a new supplier"), "New=1");
148 //start_table("class='tablestyle2'", 0, 3);
149 start_table("class='tablestyle'", 3);
151 table_section_title(_("Supplier"));
153 if (isset($_POST['supplier_id']) && !isset($_POST['New']))
155 //SupplierID exists - either passed when calling the form or from the form itself
156 $myrow = get_supplier($_POST['supplier_id']);
158 $_POST['supp_name'] = $myrow["supp_name"];
159 $_POST['address'] = $myrow["address"];
160 $_POST['email'] = $myrow["email"];
161 $_POST['bank_account'] = $myrow["bank_account"];
162 $_POST['dimension_id'] = $myrow["dimension_id"];
163 $_POST['dimension2_id'] = $myrow["dimension2_id"];
164 $_POST['curr_code'] = $myrow["curr_code"];
165 $_POST['payment_terms'] = $myrow["payment_terms"];
166 $_POST['tax_group_id'] = $myrow["tax_group_id"];
167 $_POST['payable_account'] = $myrow["payable_account"];
168 $_POST['purchase_account'] = $myrow["purchase_account"];
169 $_POST['payment_discount_account'] = $myrow["payment_discount_account"];
174 // its a new supplier being added
175 hidden('New', 'Yes');
177 $company_record = get_company_prefs();
179 $_POST['payable_account'] = $company_record["creditors_act"];
180 $_POST['purchase_account'] = $company_record["default_cogs_act"];
181 $_POST['payment_discount_account'] = $company_record['pyt_discount_act'];
184 text_row(_("Supplier Name:"), 'supp_name', null, 42, 40);
185 textarea_row(_("Address:"), 'address', null, 35, 5);
186 text_row(_("Email:"), 'email', null, 42, 40);
187 text_row(_("Bank Account:"), 'bank_account', null, 42, 40);
189 // Sherifoz 23.09.03 currency can't be changed if editing
190 if (isset($_POST['supplier_id']) && !isset($_POST['New']))
192 label_row(_("Supplier's Currency:"), $_POST['curr_code']);
193 hidden('curr_code', $_POST['curr_code']);
197 currencies_list_row(_("Supplier's Currency:"), 'curr_code', null);
200 tax_groups_list_row(_("Tax Group:"), 'tax_group_id', null);
202 payment_terms_list_row(_("Payment Terms:"), 'payment_terms', null);
204 table_section_title(_("Accounts"));
206 gl_all_accounts_list_row(_("Accounts Payable Account:"), 'payable_account', $_POST['payable_account']);
208 gl_all_accounts_list_row(_("Purchase Account:"), 'purchase_account', $_POST['purchase_account']);
210 gl_all_accounts_list_row(_("Purchase Discount Account:"), 'payment_discount_account', $_POST['payment_discount_account']);
212 $dim = get_company_pref('use_dimension');
215 table_section_title(_("Dimension"));
217 dimensions_list_row(_("Dimension")." 1:", 'dimension_id', null, true, " ", false, 1);
219 dimensions_list_row(_("Dimension")." 2:", 'dimension2_id', null, true, " ", false, 2);
222 hidden('dimension_id', 0);
224 hidden('dimension2_id', 0);
228 if (!isset($_POST['New']))
230 submit_center_first('submit', _("Update Supplier"));
231 submit_center_last('delete', _("Delete Supplier"));
235 submit_center('submit', _("Add New Supplier Details"));