4 include_once($path_to_root . "/includes/session.inc");
6 page(_("Supplier Purchasing Data"));
8 include_once($path_to_root . "/includes/date_functions.inc");
9 include_once($path_to_root . "/includes/ui.inc");
10 include_once($path_to_root . "/includes/manufacturing.inc");
11 include_once($path_to_root . "/includes/data_checks.inc");
13 check_db_has_purchasable_items(_("There are no purchasable inventory items defined in the system."));
14 check_db_has_suppliers(_("There are no suppliers defined in the system."));
16 //----------------------------------------------------------------------------------------
17 if ($ret = context_restore()) {
18 if(isset($ret['supplier_id']))
19 $_POST['supplier_id'] = $ret['supplier_id'];
21 if (isset($_POST['_supplier_id_editor'])) {
22 context_call($path_to_root.'/purchasing/manage/suppliers.php?supplier_id='.$_POST['supplier_id'],
23 array( 'supplier_id', 'stock_id','_stock_id_edit', 'price',
24 'suppliers_uom', 'supplier_description','conversion_factor'));
26 simple_page_mode(true);
27 //--------------------------------------------------------------------------------------------------
29 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
33 if ($_POST['stock_id'] == "" || !isset($_POST['stock_id']))
36 display_error( _("There is no item selected."));
37 set_focus('stock_id');
39 elseif (!check_num('price', 0))
42 display_error( _("The price entered was not numeric."));
45 elseif (!check_num('conversion_factor'))
48 display_error( _("The conversion factor entered was not numeric. The conversion factor is the number by which the price must be divided by to get the unit price in our unit of measure."));
49 set_focus('conversion_factor');
52 if ($input_error == 0)
54 if ($Mode == 'ADD_ITEM')
57 $sql = "INSERT INTO ".TB_PREF."purch_data (supplier_id, stock_id, price, suppliers_uom,
58 conversion_factor, supplier_description) VALUES (";
59 $sql .= "'".$_POST['supplier_id']."', '" . $_POST['stock_id'] . "', " .
60 input_num('price') . ", '" . $_POST['suppliers_uom'] . "', " .
61 input_num('conversion_factor') . ", '" . $_POST['supplier_description'] . "')";
63 db_query($sql,"The supplier purchasing details could not be added");
64 display_notification(_("This supplier purchasing data has been added."));
67 $sql = "UPDATE ".TB_PREF."purch_data SET price=" . input_num('price') . ",
68 suppliers_uom='" . $_POST['suppliers_uom'] . "',
69 conversion_factor=" . input_num('conversion_factor') . ",
70 supplier_description='" . $_POST['supplier_description'] . "'
71 WHERE stock_id='" . $_POST['stock_id'] . "' AND
72 supplier_id='$selected_id'";
73 db_query($sql,"The supplier purchasing details could not be updated");
75 display_notification(_("Supplier purchasing data has been updated."));
81 //--------------------------------------------------------------------------------------------------
83 if ($Mode == 'Delete')
86 $sql = "DELETE FROM ".TB_PREF."purch_data WHERE supplier_id='$selected_id'
87 AND stock_id='" . $_POST['stock_id'] . "'";
88 db_query($sql,"could not delete purchasing data");
90 display_notification(_("The purchasing data item has been sucessfully deleted."));
99 if (isset($_POST['_selected_id_update']) )
101 $selected_id = $_POST['selected_id'];
102 $Ajax->activate('_page_body');
105 if (list_updated('stock_id'))
106 $Ajax->activate('price_table');
107 //--------------------------------------------------------------------------------------------------
109 start_form(false, true);
111 if (!isset($_POST['stock_id']))
112 $_POST['stock_id'] = get_global_stock_item();
114 echo "<center>" . _("Item:"). " ";
115 stock_purchasable_items_list('stock_id', $_POST['stock_id'], false, true);
117 echo "<hr></center>";
119 set_global_stock_item($_POST['stock_id']);
121 $mb_flag = get_mb_flag($_POST['stock_id']);
125 display_error(_("Entered item is not defined. Please re-enter."));
126 set_focus('stock_id');
131 $sql = "SELECT ".TB_PREF."purch_data.*,".TB_PREF."suppliers.supp_name,".TB_PREF."suppliers.curr_code
132 FROM ".TB_PREF."purch_data INNER JOIN ".TB_PREF."suppliers
133 ON ".TB_PREF."purch_data.supplier_id=".TB_PREF."suppliers.supplier_id
134 WHERE stock_id = '" . $_POST['stock_id'] . "'";
136 $result = db_query($sql, "The supplier purchasing details for the selected part could not be retrieved");
137 div_start('price_table');
138 if (db_num_rows($result) == 0)
140 display_note(_("There is no purchasing data set up for the part selected"));
144 start_table("$table_style width=60%");
146 $th = array(_("Supplier"), _("Price"), _("Currency"),
147 _("Supplier's Unit"), _("Supplier's Description"), "", "");
151 $k = $j = 0; //row colour counter
153 while ($myrow = db_fetch($result))
155 alt_table_row_color($k);
157 label_cell($myrow["supp_name"]);
158 amount_cell($myrow["price"]);
159 label_cell($myrow["curr_code"]);
160 label_cell($myrow["suppliers_uom"]);
161 label_cell($myrow["supplier_description"]);
162 edit_button_cell("Edit".$myrow['supplier_id'], _("Edit"));
163 edit_button_cell("Delete".$myrow['supplier_id'], _("Delete"));
171 } //end of page full new headings
172 } //end of while loop
179 //-----------------------------------------------------------------------------------------------
184 $sql = "SELECT ".TB_PREF."purch_data.*,".TB_PREF."suppliers.supp_name FROM ".TB_PREF."purch_data
185 INNER JOIN ".TB_PREF."suppliers ON ".TB_PREF."purch_data.supplier_id=".TB_PREF."suppliers.supplier_id
186 WHERE ".TB_PREF."purch_data.supplier_id='$selected_id'
187 AND ".TB_PREF."purch_data.stock_id='" . $_POST['stock_id'] . "'";
189 $result = db_query($sql, "The supplier purchasing details for the selected supplier and item could not be retrieved");
191 $myrow = db_fetch($result);
193 $supp_name = $myrow["supp_name"];
194 $_POST['price'] = price_format($myrow["price"]);
195 $_POST['suppliers_uom'] = $myrow["suppliers_uom"];
196 $_POST['supplier_description'] = $myrow["supplier_description"];
197 $_POST['conversion_factor'] = exrate_format($myrow["conversion_factor"]);
201 hidden('selected_id', $selected_id);
202 start_table($table_style2);
206 hidden('supplier_id');
207 label_row(_("Supplier:"), $supp_name);
211 supplier_list_row(_("Supplier:"), 'supplier_id', null, false, true);
213 amount_row(_("Price:"), 'price', null,'', get_supplier_currency($selected_id));
214 text_row(_("Suppliers Unit of Measure:"), 'suppliers_uom', null, 50, 51);
216 if (!isset($_POST['conversion_factor']) || $_POST['conversion_factor'] == "")
218 $_POST['conversion_factor'] = exrate_format(1);
220 amount_row(_("Conversion Factor (to our UOM):"), 'conversion_factor',
221 exrate_format($_POST['conversion_factor']), null, null, user_exrate_dec() );
222 text_row(_("Supplier's Code or Description:"), 'supplier_description', null, 50, 51);
226 submit_add_or_update_center($selected_id == -1, '', true);