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['New']) || !isset($_POST['supplier_id']))
20 if (isset($_POST['SelectSupplier']))
25 if (isset($_POST['submit']))
28 //initialise no input errors assumed initially before we test
31 /* actions to take once the user has clicked the submit button
32 ie the page has called itself with some user input */
34 //first off validate inputs sensible
36 if (strlen($_POST['supp_name']) == 0 || $_POST['supp_name'] == "")
39 display_error(_("The supplier name must be entered."));
42 if ($input_error !=1 )
45 if (!isset($_POST['New']))
48 $sql = "UPDATE ".TB_PREF."suppliers SET supp_name='" . $_POST['supp_name'] . "',
49 address='" . $_POST['address'] . "',
50 email='" . $_POST['email'] . "',
51 bank_account='" . $_POST['bank_account'] . "',
52 dimension_id=" . $_POST['dimension_id'] . ",
53 dimension2_id=" . $_POST['dimension2_id'] . ",
54 curr_code='" . $_POST['curr_code'] . "',
55 payment_terms='" . $_POST['payment_terms'] . "',
56 payable_account='" . $_POST['payable_account'] . "',
57 purchase_account='" . $_POST['purchase_account'] . "',
58 payment_discount_account='" . $_POST['payment_discount_account'] . "',
59 tax_group_id=" . $_POST['tax_group_id'] . " WHERE supplier_id = '" . $_POST['supplier_id'] . "'";
61 db_query($sql,"The supplier could not be updated");
65 { //not a new supplier
67 $sql = "INSERT INTO ".TB_PREF."suppliers (supp_name, address, email, bank_account, dimension_id, dimension2_id, curr_code,
68 payment_terms, payable_account, purchase_account, payment_discount_account, tax_group_id)
69 VALUES ('" . $_POST['supp_name'] . "', '" .
70 $_POST['address'] . "', '" .
71 $_POST['email'] . "', '" .
72 $_POST['bank_account'] . "', " .
73 $_POST['dimension_id'] . ", " .
74 $_POST['dimension2_id'] . ", '" .
75 $_POST['curr_code'] . "', '" .
76 $_POST['payment_terms'] . "', '" .
77 $_POST['payable_account'] . "', '" .
78 $_POST['purchase_account'] . "', '" .
79 $_POST['payment_discount_account'] . "', " .
80 $_POST['tax_group_id'] . ")";
82 db_query($sql,"The supplier could not be added");
85 meta_forward($_SERVER['PHP_SELF']);
89 elseif (isset($_POST['delete']) && $_POST['delete'] != "")
91 //the link to delete a selected record was clicked instead of the submit button
95 // PREVENT DELETES IF DEPENDENT RECORDS IN 'supp_trans' , purch_orders
97 $sql= "SELECT COUNT(*) FROM ".TB_PREF."supp_trans WHERE supplier_id='" . $_POST['supplier_id'] . "'";
98 $result = db_query($sql,"check failed");
99 $myrow = db_fetch_row($result);
103 display_error(_("Cannot delete this supplier because there are transactions that refer to this supplier."));
108 $sql= "SELECT COUNT(*) FROM ".TB_PREF."purch_orders WHERE supplier_id='" . $_POST['supplier_id'] . "'";
109 $result = db_query($sql,"check failed");
110 $myrow = db_fetch_row($result);
114 display_error(_("Cannot delete the supplier record because purchase orders have been created against this supplier."));
118 if ($cancel_delete == 0)
120 $sql="DELETE FROM ".TB_PREF."suppliers WHERE supplier_id='" . $_POST['supplier_id']. "'";
121 db_query($sql,"check failed");
123 unset($_SESSION['supplier_id']);
124 meta_forward($_SERVER['PHP_SELF']);
125 } //end if Delete supplier
130 if (db_has_suppliers())
134 supplier_list_cells(_("Select a supplier: "), 'supplier_id', null);
135 submit_cells('SelectSupplier', _("Edit Supplier"));
141 hidden('supplier_id', $_POST['supplier_id']);
144 hyperlink_params($_SERVER['PHP_SELF'], _("Enter a new supplier"), "New=1");
147 //start_table("class='tablestyle2'", 0, 3);
148 start_table("class='tablestyle'", 3);
150 table_section_title(_("Supplier"));
152 if (isset($_POST['supplier_id']) && !isset($_POST['New']))
154 //SupplierID exists - either passed when calling the form or from the form itself
155 $myrow = get_supplier($_POST['supplier_id']);
157 $_POST['supp_name'] = $myrow["supp_name"];
158 $_POST['address'] = $myrow["address"];
159 $_POST['email'] = $myrow["email"];
160 $_POST['bank_account'] = $myrow["bank_account"];
161 $_POST['dimension_id'] = $myrow["dimension_id"];
162 $_POST['dimension2_id'] = $myrow["dimension2_id"];
163 $_POST['curr_code'] = $myrow["curr_code"];
164 $_POST['payment_terms'] = $myrow["payment_terms"];
165 $_POST['tax_group_id'] = $myrow["tax_group_id"];
166 $_POST['payable_account'] = $myrow["payable_account"];
167 $_POST['purchase_account'] = $myrow["purchase_account"];
168 $_POST['payment_discount_account'] = $myrow["payment_discount_account"];
173 // its a new supplier being added
174 hidden('New', 'Yes');
176 $company_record = get_company_prefs();
178 $_POST['payable_account'] = $company_record["creditors_act"];
179 $_POST['purchase_account'] = $company_record["default_cogs_act"];
180 $_POST['payment_discount_account'] = $company_record['pyt_discount_act'];
183 text_row(_("Supplier Name:"), 'supp_name', null, 42, 40);
184 textarea_row(_("Address:"), 'address', null, 35, 5);
185 text_row(_("Email:"), 'email', null, 42, 40);
186 text_row(_("Bank Account:"), 'bank_account', null, 42, 40);
188 // Sherifoz 23.09.03 currency can't be changed if editing
189 if (isset($_POST['supplier_id']) && !isset($_POST['New']))
191 label_row(_("Supplier's Currency:"), $_POST['curr_code']);
192 hidden('curr_code', $_POST['curr_code']);
196 currencies_list_row(_("Supplier's Currency:"), 'curr_code', null);
199 tax_groups_list_row(_("Tax Group:"), 'tax_group_id', null);
201 payment_terms_list_row(_("Payment Terms:"), 'payment_terms', null);
203 table_section_title(_("Accounts"));
205 gl_all_accounts_list_row(_("Accounts Payable Account:"), 'payable_account', $_POST['payable_account']);
207 gl_all_accounts_list_row(_("Purchase Account:"), 'purchase_account', $_POST['purchase_account']);
209 gl_all_accounts_list_row(_("Purchase Discount Account:"), 'payment_discount_account', $_POST['payment_discount_account']);
211 $dim = get_company_pref('use_dimension');
214 table_section_title(_("Dimension"));
216 dimensions_list_row(_("Dimension")." 1:", 'dimension_id', null, true, " ", false, 1);
218 dimensions_list_row(_("Dimension")." 2:", 'dimension2_id', null, true, " ", false, 2);
221 hidden('dimension_id', 0);
223 hidden('dimension2_id', 0);
227 if (!isset($_POST['New']))
229 submit_center_first('submit', _("Update Supplier"));
230 submit_center_last('delete', _("Delete Supplier"));
234 submit_center('submit', _("Add New Supplier Details"));